001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.projectimport.eclipse;
043:
044: import java.io.File;
045: import org.openide.ErrorManager;
046:
047: /**
048: * Represents one classpath entry of an Eclipse project's .classpath file.
049: *
050: * @author mkrauskopf
051: */
052: public final class ClassPathEntry {
053:
054: /** Serves for type-safe enumeration of types */
055: static class Type {
056: String desc;
057:
058: private Type(String desc) {
059: this .desc = desc;
060: }
061:
062: public String toString() {
063: return desc;
064: }
065: }
066:
067: static final Type TYPE_OUTPUT = new Type("output"); // NOI18N
068: static final Type TYPE_LIBRARY = new Type("lib"); // NOI18N
069: static final Type TYPE_EXTERNAL_LIBRARY = new Type("lib-ext"); // NOI18N
070: static final Type TYPE_CONTAINER = new Type("con"); // NOI18N
071: static final Type TYPE_VARIABLE = new Type("var"); // NOI18N
072: static final Type TYPE_SOURCE = new Type("src"); // NOI18N
073: static final Type TYPE_PROJECT = new Type("src-prj"); // NOI18N
074: static final Type TYPE_LINK = new Type("src-link"); // NOI18N
075: static final Type TYPE_UNKNOWN = new Type("unkown"); // NOI18N
076:
077: private Type type;
078: private String rawPath;
079: private String absolutePath;
080:
081: ClassPathEntry(String type, String rawPath) {
082: this .rawPath = rawPath;
083: setTypeFromRawtype(type);
084: }
085:
086: void setType(ClassPathEntry.Type type) {
087: this .type = type;
088: }
089:
090: private void setTypeFromRawtype(String rawType) {
091: if ("output".equals(rawType)) { // NOI18N
092: this .type = TYPE_OUTPUT;
093: } else if ("src".equals(rawType)) { // NOI18N
094: // raw path for project entries starts with slash (on all platforms)
095: if (rawPath.startsWith("/")) { // NOI18N
096: this .type = TYPE_PROJECT;
097: } else {
098: this .type = TYPE_SOURCE;
099: }
100: } else if ("lib".equals(rawType)) { // NOI18N
101: if (isRawPathRelative()) {
102: this .type = TYPE_LIBRARY;
103: } else {
104: this .type = TYPE_EXTERNAL_LIBRARY;
105: }
106: } else if ("con".equals(rawType)) { // NOI18N
107: this .type = TYPE_CONTAINER;
108: } else if ("var".equals(rawType)) { // NOI18N
109: this .type = TYPE_VARIABLE;
110: } else {
111: ErrorManager.getDefault().log(
112: ErrorManager.WARNING,
113: "Unkown type encountered in "
114: + // NOI18N
115: "ClassPathEntry.setTypeFromRawtype(): "
116: + rawType); // NOI18N
117: this .type = TYPE_UNKNOWN;
118: }
119: }
120:
121: Type getType() {
122: return type;
123: }
124:
125: public String getRawPath() {
126: return rawPath;
127: }
128:
129: public String getAbsolutePath() {
130: return absolutePath;
131: }
132:
133: void setAbsolutePath(String absolutePath) {
134: this .absolutePath = absolutePath;
135: }
136:
137: boolean isRawPathRelative() {
138: return !(new File(rawPath).isAbsolute());
139: }
140:
141: public String toString() {
142: return type + " = \"" + rawPath + "\"" + // NOI18N
143: " (absolutePath: " + absolutePath + ")"; // NOI18N
144: }
145: }
|