1 19 20 package org.netbeans.modules.projectimport.eclipse; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.logging.Logger ; 28 import org.netbeans.modules.projectimport.LoggerFactory; 29 30 35 final class ClassPath { 36 37 40 private static final Logger logger = 41 LoggerFactory.getDefault().createLogger(ClassPath.class); 42 43 44 45 static class Link { 46 public static final int TYPE_INVALID = 0; 47 public static final int TYPE_FILE = 1; 48 public static final int TYPE_FOLDER = 2; 49 50 private String name; 51 private int type = TYPE_INVALID; 52 private String location; 53 54 String getName() { 55 return name; 56 } 57 58 void setName(String name) { 59 this.name = name; 60 } 61 62 int getType() { 63 return type; 64 } 65 66 void setType(int type) { 67 this.type = type; 68 } 69 70 String getLocation() { 71 return location; 72 } 73 74 void setLocation(String location) { 75 this.location = location; 76 } 77 78 public String toString() { 79 return name + " = " + location + " (type: " + type + ")"; } 81 82 public boolean equals(Object obj) { 83 if (this == obj) return true; 84 if (!(obj instanceof Link)) return false; 85 final Link link = (Link) obj; 86 if (type != link.type) return false; 87 if (name != null ? !name.equals(link.name) : link.name != null) 88 return false; 89 if (location != null ? !location.equals(link.location) : link.location != null) 90 return false; 91 return true; 92 } 93 94 public int hashCode() { 95 int result = 17; 96 result = 37 * result + type; 97 result = 37 * result + System.identityHashCode(name); 98 result = 37 * result + System.identityHashCode(location); 99 return result; 100 } 101 } 102 103 private static final String USER_LIBRARY_PREFIX 104 = "org.eclipse.jdt.USER_LIBRARY/"; private static final int USER_LIBRARY_PREFIX_LENGTH = USER_LIBRARY_PREFIX.length(); 106 107 private ClassPathEntry output; 108 private Collection pathEntries = Collections.EMPTY_LIST; 109 110 private String jreContainer; 111 private Collection sourceRoots; 112 private Collection externalSourceRoots; 113 private Collection libraries; 114 private Collection externalLibraries; 115 private Collection projects; 116 private Collection variables; 117 private Collection userLibraries; 118 119 123 void addEntry(ClassPathEntry entry) { 124 if (entry != null){ 125 if (entry.getType() == ClassPathEntry.TYPE_OUTPUT) { 126 output = entry; 127 } else { 128 addSource(entry); 129 } 130 } 131 } 132 133 private void addSource(ClassPathEntry path) { 134 if (pathEntries == Collections.EMPTY_LIST) { 135 pathEntries = new ArrayList (); 136 } 137 pathEntries.add(path); 138 } 139 140 ClassPathEntry getOutput() { 141 return output; 142 } 143 144 Collection getEntries() { 145 return pathEntries; 146 } 147 148 private Collection getEntriesByType(ClassPathEntry.Type type) { 149 Collection entries = new ArrayList (); 150 for (Iterator it = pathEntries.iterator(); it.hasNext(); ) { 151 ClassPathEntry entry = (ClassPathEntry) it.next(); 152 if (entry.getType() == type) { 153 entries.add(entry); 154 } 155 } 156 return entries; 157 } 158 159 164 Collection getSourceRoots() { 165 if (sourceRoots == null) { 167 sourceRoots = getEntriesByType(ClassPathEntry.TYPE_SOURCE); 168 } 169 return sourceRoots; 170 } 171 172 177 String getJREContainer() { 178 if (jreContainer == null) { 180 Collection col = getEntriesByType(ClassPathEntry.TYPE_CONTAINER); 181 for (Iterator it = col.iterator(); it.hasNext(); ) { 182 ClassPathEntry cpe = (ClassPathEntry) it.next(); 183 if (cpe.getRawPath().startsWith(Workspace.DEFAULT_JRE_CONTAINER)) { 184 jreContainer = cpe.getRawPath(); 185 logger.finest("jreContainer found: " + jreContainer); break; 187 } 188 } 189 if (jreContainer == null) { 190 logger.fine("jreContainer wasn't found in classpath entries!"); logger.fine("Classpath entries: " + this.getEntries()); } 193 } 194 return jreContainer; 195 } 196 197 202 Collection getExternalSourceRoots() { 203 if (externalSourceRoots == null) { 205 externalSourceRoots = getEntriesByType(ClassPathEntry.TYPE_LINK); 206 } 207 return externalSourceRoots; 208 } 209 210 215 Collection getLibraries() { 216 if (libraries == null) { 218 libraries = getEntriesByType(ClassPathEntry.TYPE_LIBRARY); 219 } 220 return libraries; 221 } 222 223 228 Collection getExternalLibraries() { 229 if (externalLibraries == null) { 231 externalLibraries = getEntriesByType(ClassPathEntry.TYPE_EXTERNAL_LIBRARY); 232 } 233 return externalLibraries; 234 } 235 236 239 Collection getUserLibraries() { 240 if (userLibraries == null) { 242 Collection col = getEntriesByType(ClassPathEntry.TYPE_CONTAINER); 243 userLibraries = new HashSet (); 244 for (Iterator it = col.iterator(); it.hasNext(); ) { 245 ClassPathEntry cpe = (ClassPathEntry) it.next(); 246 String rawPath = cpe.getRawPath(); 247 if (rawPath.startsWith(USER_LIBRARY_PREFIX)) { 248 userLibraries.add(rawPath.substring(USER_LIBRARY_PREFIX_LENGTH)); 249 } 250 } 251 } 252 return userLibraries; 253 } 254 255 260 Collection getProjects() { 261 if (projects == null) { 263 projects = getEntriesByType(ClassPathEntry.TYPE_PROJECT); 264 } 265 return projects; 266 } 267 268 273 Collection getVariables() { 274 if (variables == null) { 276 variables = getEntriesByType(ClassPathEntry.TYPE_VARIABLE); 277 } 278 return variables; 279 } 280 } 281 | Popular Tags |