KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > tool > EclipseFileManager


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.tool;
12
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.URI JavaDoc;
17 import java.net.URISyntaxException JavaDoc;
18 import java.net.URL JavaDoc;
19 import java.net.URLClassLoader JavaDoc;
20 import java.nio.charset.Charset JavaDoc;
21 import java.text.MessageFormat JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Locale JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.MissingResourceException JavaDoc;
29 import java.util.ResourceBundle JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.StringTokenizer JavaDoc;
32 import java.util.zip.ZipException JavaDoc;
33
34 import javax.tools.FileObject;
35 import javax.tools.JavaFileObject;
36 import javax.tools.StandardJavaFileManager;
37 import javax.tools.StandardLocation;
38 import javax.tools.JavaFileObject.Kind;
39
40 import org.eclipse.jdt.core.compiler.IProblem;
41 import org.eclipse.jdt.core.compiler.InvalidInputException;
42 import org.eclipse.jdt.internal.compiler.batch.FileSystem;
43 import org.eclipse.jdt.internal.compiler.batch.Main;
44 import org.eclipse.jdt.internal.compiler.batch.Main.ResourceBundleFactory;
45 import org.eclipse.jdt.internal.compiler.env.AccessRule;
46 import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
47
48 /**
49  * Implementation of the Standard Java File Manager
50  */

51 public class EclipseFileManager implements StandardJavaFileManager {
52     private static final String JavaDoc NO_EXTENSION = "";//$NON-NLS-1$
53
static final int HAS_EXT_DIRS = 1;
54     static final int HAS_BOOTCLASSPATH = 2;
55     static final int HAS_ENDORSED_DIRS = 4;
56     static final int HAS_PROCESSORPATH = 8;
57
58     Map JavaDoc<File JavaDoc, Archive> archivesCache;
59     Charset JavaDoc charset;
60     Locale JavaDoc locale;
61     Map JavaDoc<String JavaDoc, Iterable JavaDoc<? extends File JavaDoc>> locations;
62     int flags;
63     public ResourceBundle JavaDoc bundle;
64
65     public EclipseFileManager(Locale JavaDoc locale, Charset JavaDoc charset) {
66         this.locale = locale == null ? Locale.getDefault() : locale;
67         this.charset = charset == null ? Charset.defaultCharset() : charset;
68         this.locations = new HashMap JavaDoc<String JavaDoc, Iterable JavaDoc<? extends File JavaDoc>>();
69         this.archivesCache = new HashMap JavaDoc<File JavaDoc, Archive>();
70         try {
71             this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath());
72             Iterable JavaDoc<? extends File JavaDoc> defaultClasspath = getDefaultClasspath();
73             this.setLocation(StandardLocation.CLASS_PATH, defaultClasspath);
74             this.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, defaultClasspath);
75         } catch (IOException JavaDoc e) {
76             // ignore
77
}
78         try {
79             this.bundle = ResourceBundleFactory.getBundle(this.locale);
80         } catch(MissingResourceException JavaDoc e) {
81             System.err.println("Missing resource : " + Main.bundleName.replace('.', '/') + ".properties for locale " + locale); //$NON-NLS-1$//$NON-NLS-2$
82
throw e;
83         }
84     }
85
86     private void addFiles(File JavaDoc[][] jars, ArrayList JavaDoc<File JavaDoc> files) {
87         if (jars != null) {
88             for (File JavaDoc[] currentJars : jars) {
89                 if (currentJars != null) {
90                     for (File JavaDoc currentJar : currentJars) {
91                         if (currentJar.exists()) {
92                             files.add(currentJar);
93                         }
94                     }
95                 }
96             }
97         }
98     }
99
100
101     private void addFilesFrom(File JavaDoc javaHome, String JavaDoc propertyName, String JavaDoc defaultPath, ArrayList JavaDoc<File JavaDoc> files) {
102         String JavaDoc extdirsStr = System.getProperty(propertyName);
103         File JavaDoc[] directoriesToCheck = null;
104         if (extdirsStr == null) {
105             if (javaHome != null) {
106                 directoriesToCheck = new File JavaDoc[] { new File JavaDoc(javaHome, defaultPath) };
107             }
108         } else {
109             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(extdirsStr, File.pathSeparator);
110             ArrayList JavaDoc<String JavaDoc> paths = new ArrayList JavaDoc<String JavaDoc>();
111             while (tokenizer.hasMoreTokens()) {
112                 paths.add(tokenizer.nextToken());
113             }
114             if (paths.size() != 0) {
115                 directoriesToCheck = new File JavaDoc[paths.size()];
116                 for (int i = 0; i < directoriesToCheck.length; i++) {
117                     directoriesToCheck[i] = new File JavaDoc(paths.get(i));
118                 }
119             }
120         }
121         if (directoriesToCheck != null) {
122             addFiles(Main.getLibrariesFiles(directoriesToCheck), files);
123         }
124
125     }
126
127     /* (non-Javadoc)
128      * @see javax.tools.JavaFileManager#close()
129      */

130     public void close() throws IOException JavaDoc {
131         this.locations = null;
132         for (Archive archive : archivesCache.values()) {
133             archive.close();
134         }
135     }
136
137     private void collectAllMatchingFiles(File JavaDoc file, String JavaDoc normalizedPackageName, Set JavaDoc<Kind> kinds, boolean recurse, ArrayList JavaDoc<JavaFileObject> collector) {
138         if (!isArchive(file)) {
139             // we must have a directory
140
File JavaDoc currentFile = new File JavaDoc(file, normalizedPackageName);
141             if (!currentFile.exists()) return;
142             String JavaDoc path;
143             try {
144                 path = currentFile.getCanonicalPath();
145             } catch (IOException JavaDoc e) {
146                 return;
147             }
148             if (File.separatorChar == '/') {
149                 if (!path.endsWith(normalizedPackageName)) return;
150             } else if (!path.endsWith(normalizedPackageName.replace('/', File.separatorChar))) return;
151             File JavaDoc[] files = currentFile.listFiles();
152             if (files != null) {
153                 // this was a directory
154
for (File JavaDoc f : files) {
155                     if (f.isDirectory() && recurse) {
156                         collectAllMatchingFiles(file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector);
157                     } else {
158                         final Kind kind = getKind(f);
159                         if (kinds.contains(kind)) {
160                             collector.add(new EclipseFileObject(normalizedPackageName + currentFile.getName(), currentFile.toURI(), kind, this.charset));
161                         }
162                     }
163                 }
164             }
165             // currentFile is not a directory
166
// check if it matches the criteria
167
final Kind kind = getKind(file);
168             if (kinds.contains(kind)) {
169                 collector.add(new EclipseFileObject(normalizedPackageName + currentFile.getName(), currentFile.toURI(), kind, this.charset));
170             }
171         } else {
172             Archive archive = this.getArchive(file);
173             String JavaDoc key = normalizedPackageName;
174             if (!normalizedPackageName.endsWith("/")) {//$NON-NLS-1$
175
key += '/';
176             }
177             // we have an archive file
178
if (recurse) {
179                 for (String JavaDoc packageName : archive.allPackages()) {
180                     if (packageName.startsWith(key)) {
181                         ArrayList JavaDoc<String JavaDoc> types = archive.getTypes(packageName);
182                         if (types != null) {
183                             for (String JavaDoc typeName : types) {
184                                 final Kind kind = getKind(getExtension(typeName));
185                                 if (kinds.contains(kind)) {
186                                     collector.add(archive.getArchiveFileObject(packageName + typeName, this.charset));
187                                 }
188                             }
189                         }
190                     }
191                 }
192             } else {
193                 ArrayList JavaDoc<String JavaDoc> types = archive.getTypes(key);
194                 if (types != null) {
195                     for (String JavaDoc typeName : types) {
196                         final Kind kind = getKind(typeName);
197                         if (kinds.contains(kind)) {
198                             collector.add(archive.getArchiveFileObject(normalizedPackageName + typeName, this.charset));
199                         }
200                     }
201                 }
202             }
203         }
204     }
205
206     private Iterable JavaDoc<? extends File JavaDoc> concatFiles(Iterable JavaDoc<? extends File JavaDoc> iterable, Iterable JavaDoc<? extends File JavaDoc> iterable2) {
207         ArrayList JavaDoc<File JavaDoc> list = new ArrayList JavaDoc<File JavaDoc>();
208         if (iterable2 == null) return iterable;
209         for (Iterator JavaDoc<? extends File JavaDoc> iterator = iterable.iterator(); iterator.hasNext(); ) {
210             list.add(iterator.next());
211         }
212         for (Iterator JavaDoc<? extends File JavaDoc> iterator = iterable2.iterator(); iterator.hasNext(); ) {
213             list.add(iterator.next());
214         }
215         return list;
216     }
217
218     /* (non-Javadoc)
219      * @see javax.tools.JavaFileManager#flush()
220      */

221     public void flush() throws IOException JavaDoc {
222         for (Archive archive : archivesCache.values()) {
223             archive.flush();
224         }
225     }
226
227     private Archive getArchive(File JavaDoc f) {
228         // check the archive (jar/zip) cache
229
Archive archive = this.archivesCache.get(f);
230         if (archive == null) {
231             // create a new archive
232
if (f.exists()) {
233                 try {
234                     archive = new Archive(f);
235                 } catch (ZipException JavaDoc e) {
236                     // ignore
237
} catch (IOException JavaDoc e) {
238                     // ignore
239
}
240                 if (archive != null) {
241                     this.archivesCache.put(f, archive);
242                 } else {
243                     this.archivesCache.put(f, Archive.UNKNOWN_ARCHIVE);
244                 }
245             } else {
246                 this.archivesCache.put(f, Archive.UNKNOWN_ARCHIVE);
247             }
248         }
249         return archive;
250     }
251
252     /* (non-Javadoc)
253      * @see javax.tools.JavaFileManager#getClassLoader(javax.tools.JavaFileManager.Location)
254      */

255     public ClassLoader JavaDoc getClassLoader(Location location) {
256         Iterable JavaDoc<? extends File JavaDoc> files = getLocation(location);
257         if (files == null) {
258             // location is unknown
259
return null;
260         }
261         ArrayList JavaDoc<URL JavaDoc> allURLs = new ArrayList JavaDoc<URL JavaDoc>();
262         for (File JavaDoc f : files) {
263             try {
264                 allURLs.add(f.toURI().toURL());
265             } catch (MalformedURLException JavaDoc e) {
266                 // the url is malformed - this should not happen
267
throw new RuntimeException JavaDoc(e);
268             }
269         }
270         URL JavaDoc[] result = new URL JavaDoc[allURLs.size()];
271         return new URLClassLoader JavaDoc(allURLs.toArray(result), getClass().getClassLoader());
272     }
273
274     private Iterable JavaDoc<? extends File JavaDoc> getPathsFrom(String JavaDoc path) {
275         ArrayList JavaDoc<FileSystem.Classpath> paths = new ArrayList JavaDoc<FileSystem.Classpath>();
276         ArrayList JavaDoc<File JavaDoc> files = new ArrayList JavaDoc<File JavaDoc>();
277         try {
278             this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.toString(), false, false);
279         } catch (InvalidInputException e) {
280             return null;
281         }
282         for (FileSystem.Classpath classpath : paths) {
283             files.add(new File JavaDoc(classpath.getPath()));
284         }
285         return files;
286     }
287
288     Iterable JavaDoc<? extends File JavaDoc> getDefaultBootclasspath() {
289         ArrayList JavaDoc<File JavaDoc> files = new ArrayList JavaDoc<File JavaDoc>();
290         String JavaDoc javaversion = System.getProperty("java.version");//$NON-NLS-1$
291
if (javaversion != null && !javaversion.startsWith("1.6")) { //$NON-NLS-1$
292
// wrong jdk - 1.6 is required
293
return null;
294         }
295
296         /*
297          * Handle >= JDK 1.6
298          */

299         String JavaDoc javaHome = System.getProperty("java.home"); //$NON-NLS-1$
300
File JavaDoc javaHomeFile = null;
301         if (javaHome != null) {
302             javaHomeFile = new File JavaDoc(javaHome);
303             if (!javaHomeFile.exists())
304                 javaHomeFile = null;
305         }
306
307         addFilesFrom(javaHomeFile, "java.endorsed.dirs", "/lib/endorsed", files);//$NON-NLS-1$//$NON-NLS-2$
308
if (javaHomeFile != null) {
309             File JavaDoc[] directoriesToCheck = null;
310             if (System.getProperty("os.name").startsWith("Mac")) {//$NON-NLS-1$//$NON-NLS-2$
311
directoriesToCheck = new File JavaDoc[] { new File JavaDoc(javaHomeFile, "../Classes"), //$NON-NLS-1$
312
};
313             } else {
314                 directoriesToCheck = new File JavaDoc[] { new File JavaDoc(javaHomeFile, "lib") //$NON-NLS-1$
315
};
316             }
317             File JavaDoc[][] jars = Main.getLibrariesFiles(directoriesToCheck);
318             addFiles(jars, files);
319         }
320         addFilesFrom(javaHomeFile, "java.ext.dirs", "/lib/ext", files);//$NON-NLS-1$//$NON-NLS-2$
321
return files;
322     }
323
324     Iterable JavaDoc<? extends File JavaDoc> getDefaultClasspath() {
325         // default classpath
326
ArrayList JavaDoc<File JavaDoc> files = new ArrayList JavaDoc<File JavaDoc>();
327         String JavaDoc classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
328
if ((classProp == null) || (classProp.length() == 0)) {
329             return null;
330         } else {
331             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(classProp, File.pathSeparator);
332             String JavaDoc token;
333             while (tokenizer.hasMoreTokens()) {
334                 token = tokenizer.nextToken();
335                 File JavaDoc file = new File JavaDoc(token);
336                 if (file.exists()) {
337                     files.add(file);
338                 }
339             }
340         }
341         return files;
342     }
343
344     private Iterable JavaDoc<? extends File JavaDoc> getEndorsedDirsFrom(String JavaDoc path) {
345         ArrayList JavaDoc<FileSystem.Classpath> paths = new ArrayList JavaDoc<FileSystem.Classpath>();
346         ArrayList JavaDoc<File JavaDoc> files = new ArrayList JavaDoc<File JavaDoc>();
347         try {
348             this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.toString(), false, false);
349         } catch (InvalidInputException e) {
350             return null;
351         }
352         for (FileSystem.Classpath classpath : paths) {
353             files.add(new File JavaDoc(classpath.getPath()));
354         }
355         return files;
356     }
357
358     private Iterable JavaDoc<? extends File JavaDoc> getExtdirsFrom(String JavaDoc path) {
359         ArrayList JavaDoc<FileSystem.Classpath> paths = new ArrayList JavaDoc<FileSystem.Classpath>();
360         ArrayList JavaDoc<File JavaDoc> files = new ArrayList JavaDoc<File JavaDoc>();
361         try {
362             this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.toString(), false, false);
363         } catch (InvalidInputException e) {
364             return null;
365         }
366         for (FileSystem.Classpath classpath : paths) {
367             files.add(new File JavaDoc(classpath.getPath()));
368         }
369         return files;
370     }
371
372     private String JavaDoc getExtension(File JavaDoc file) {
373         String JavaDoc name = file.getName();
374         return getExtension(name);
375     }
376     private String JavaDoc getExtension(String JavaDoc name) {
377         int index = name.lastIndexOf('.');
378         if (index == -1) {
379             return NO_EXTENSION;
380         }
381         return name.substring(index);
382     }
383
384     /* (non-Javadoc)
385      * @see javax.tools.JavaFileManager#getFileForInput(javax.tools.JavaFileManager.Location, java.lang.String, java.lang.String)
386      */

387     public FileObject getFileForInput(Location location, String JavaDoc packageName, String JavaDoc relativeName) throws IOException JavaDoc {
388         Iterable JavaDoc<? extends File JavaDoc> files = getLocation(location);
389         if (files == null) {
390             throw new IllegalArgumentException JavaDoc("Unknown location : " + location);//$NON-NLS-1$
391
}
392         String JavaDoc normalizedFileName = normalized(packageName) + '/' + relativeName.replace('\\', '/');
393         for (File JavaDoc file : files) {
394             if (file.isDirectory()) {
395                 // handle directory
396
File JavaDoc f = new File JavaDoc(file, normalizedFileName);
397                 if (f.exists()) {
398                     return new EclipseFileObject(packageName + File.separator + relativeName, f.toURI(), getKind(f), this.charset);
399                 } else {
400                     continue; // go to next entry in the location
401
}
402             } else if (isArchive(file)) {
403                 // handle archive file
404
Archive archive = getArchive(file);
405                 if (archive != Archive.UNKNOWN_ARCHIVE) {
406                     if (archive.contains(normalizedFileName)) {
407                         return archive.getArchiveFileObject(normalizedFileName, this.charset);
408                     }
409                 }
410             }
411         }
412         return null;
413     }
414
415     /* (non-Javadoc)
416      * @see javax.tools.JavaFileManager#getFileForOutput(javax.tools.JavaFileManager.Location, java.lang.String, java.lang.String, javax.tools.FileObject)
417      */

418     public FileObject getFileForOutput(Location location, String JavaDoc packageName, String JavaDoc relativeName, FileObject sibling)
419             throws IOException JavaDoc {
420         Iterable JavaDoc<? extends File JavaDoc> files = getLocation(location);
421         if (files == null) {
422             throw new IllegalArgumentException JavaDoc("Unknown location : " + location);//$NON-NLS-1$
423
}
424         final Iterator JavaDoc<? extends File JavaDoc> iterator = files.iterator();
425         if (iterator.hasNext()) {
426             File JavaDoc file = iterator.next();
427             String JavaDoc normalizedFileName = normalized(packageName) + '/' + relativeName.replace('\\', '/');
428             File JavaDoc f = new File JavaDoc(file, normalizedFileName);
429             return new EclipseFileObject(packageName + File.separator + relativeName, f.toURI(), getKind(f), this.charset);
430         } else {
431             throw new IllegalArgumentException JavaDoc("location is empty : " + location);//$NON-NLS-1$
432
}
433     }
434
435     /* (non-Javadoc)
436      * @see javax.tools.JavaFileManager#getJavaFileForInput(javax.tools.JavaFileManager.Location, java.lang.String, javax.tools.JavaFileObject.Kind)
437      */

438     public JavaFileObject getJavaFileForInput(Location location, String JavaDoc className, Kind kind) throws IOException JavaDoc {
439         if (kind != Kind.CLASS && kind != Kind.SOURCE) {
440             throw new IllegalArgumentException JavaDoc("Invalid kind : " + kind);//$NON-NLS-1$
441
}
442         Iterable JavaDoc<? extends File JavaDoc> files = getLocation(location);
443         if (files == null) {
444             throw new IllegalArgumentException JavaDoc("Unknown location : " + location);//$NON-NLS-1$
445
}
446         String JavaDoc normalizedFileName = normalized(className);
447         normalizedFileName += kind.extension;
448         for (File JavaDoc file : files) {
449             if (file.isDirectory()) {
450                 // handle directory
451
File JavaDoc f = new File JavaDoc(file, normalizedFileName);
452                 if (f.exists()) {
453                     return new EclipseFileObject(className, f.toURI(), kind, this.charset);
454                 } else {
455                     continue; // go to next entry in the location
456
}
457             } else if (isArchive(file)) {
458                 // handle archive file
459
Archive archive = getArchive(file);
460                 if (archive != Archive.UNKNOWN_ARCHIVE) {
461                     if (archive.contains(normalizedFileName)) {
462                         return archive.getArchiveFileObject(normalizedFileName, this.charset);
463                     }
464                 }
465             }
466         }
467         return null;
468     }
469
470     /* (non-Javadoc)
471      * @see javax.tools.JavaFileManager#getJavaFileForOutput(javax.tools.JavaFileManager.Location, java.lang.String, javax.tools.JavaFileObject.Kind, javax.tools.FileObject)
472      */

473     public JavaFileObject getJavaFileForOutput(Location location, String JavaDoc className, Kind kind, FileObject sibling)
474             throws IOException JavaDoc {
475         if (kind != Kind.CLASS && kind != Kind.SOURCE) {
476             throw new IllegalArgumentException JavaDoc("Invalid kind : " + kind);//$NON-NLS-1$
477
}
478         Iterable JavaDoc<? extends File JavaDoc> files = getLocation(location);
479         if (files == null) {
480             if (!location.equals(StandardLocation.CLASS_OUTPUT)
481                     && !location.equals(StandardLocation.SOURCE_OUTPUT))
482                 throw new IllegalArgumentException JavaDoc("Unknown location : " + location);//$NON-NLS-1$
483
// we will use either the sibling or user.dir
484
if (sibling != null) {
485                 String JavaDoc normalizedFileName = normalized(className);
486                 int index = normalizedFileName.lastIndexOf('/');
487                 if (index != -1) {
488                     normalizedFileName = normalizedFileName.substring(index + 1);
489                 }
490                 normalizedFileName += kind.extension;
491                 URI JavaDoc uri = sibling.toUri();
492                 URI JavaDoc uri2 = null;
493                 try {
494                     String JavaDoc path = uri.getPath();
495                     index = path.lastIndexOf('/');
496                     if (index != -1) {
497                         path = path.substring(0, index + 1);
498                         path += normalizedFileName;
499                     }
500                     uri2 = new URI JavaDoc(uri.getScheme(), uri.getHost(), path, uri.getFragment());
501                 } catch (URISyntaxException JavaDoc e) {
502                     throw new IllegalArgumentException JavaDoc("invalid sibling");//$NON-NLS-1$
503
}
504                 return new EclipseFileObject(className, uri2, kind, this.charset);
505             } else {
506                 String JavaDoc normalizedFileName = normalized(className);
507                 int index = normalizedFileName.lastIndexOf('/');
508                 if (index != -1) {
509                     normalizedFileName = normalizedFileName.substring(index + 1);
510                 }
511                 normalizedFileName += kind.extension;
512                 File JavaDoc f = new File JavaDoc(System.getProperty("user.dir"), normalizedFileName);//$NON-NLS-1$
513
return new EclipseFileObject(className, f.toURI(), kind, this.charset);
514             }
515         }
516         final Iterator JavaDoc<? extends File JavaDoc> iterator = files.iterator();
517         if (iterator.hasNext()) {
518             File JavaDoc file = iterator.next();
519             String JavaDoc normalizedFileName = normalized(className);
520             normalizedFileName += kind.extension;
521             File JavaDoc f = new File JavaDoc(file, normalizedFileName);
522             return new EclipseFileObject(className, f.toURI(), kind, this.charset);
523         } else {
524             throw new IllegalArgumentException JavaDoc("location is empty : " + location);//$NON-NLS-1$
525
}
526     }
527
528     /* (non-Javadoc)
529      * @see javax.tools.StandardJavaFileManager#getJavaFileObjects(java.io.File[])
530      */

531     public Iterable JavaDoc<? extends JavaFileObject> getJavaFileObjects(File JavaDoc... files) {
532         return getJavaFileObjectsFromFiles(Arrays.asList(files));
533     }
534
535     /* (non-Javadoc)
536      * @see javax.tools.StandardJavaFileManager#getJavaFileObjects(java.lang.String[])
537      */

538     public Iterable JavaDoc<? extends JavaFileObject> getJavaFileObjects(String JavaDoc... names) {
539         return getJavaFileObjectsFromStrings(Arrays.asList(names));
540     }
541
542     /* (non-Javadoc)
543      * @see javax.tools.StandardJavaFileManager#getJavaFileObjectsFromFiles(java.lang.Iterable)
544      */

545     public Iterable JavaDoc<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable JavaDoc<? extends File JavaDoc> files) {
546         ArrayList JavaDoc<JavaFileObject> javaFileArrayList = new ArrayList JavaDoc<JavaFileObject>();
547         for (File JavaDoc f : files) {
548             javaFileArrayList.add(new EclipseFileObject(f.getAbsolutePath(), f.toURI(), getKind(f), this.charset));
549         }
550         return javaFileArrayList;
551     }
552
553     /* (non-Javadoc)
554      * @see javax.tools.StandardJavaFileManager#getJavaFileObjectsFromStrings(java.lang.Iterable)
555      */

556     public Iterable JavaDoc<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable JavaDoc<String JavaDoc> names) {
557         ArrayList JavaDoc<File JavaDoc> files = new ArrayList JavaDoc<File JavaDoc>();
558         for (String JavaDoc name : names) {
559             files.add(new File JavaDoc(name));
560         }
561         return getJavaFileObjectsFromFiles(files);
562     }
563
564     public Kind getKind(File JavaDoc f) {
565         return getKind(getExtension(f));
566     }
567
568     private Kind getKind(String JavaDoc extension) {
569         if (Kind.CLASS.extension.equals(extension)) {
570             return Kind.CLASS;
571         } else if (Kind.SOURCE.extension.equals(extension)) {
572             return Kind.SOURCE;
573         } else if (Kind.HTML.extension.equals(extension)) {
574             return Kind.HTML;
575         }
576         return Kind.OTHER;
577     }
578
579     /* (non-Javadoc)
580      * @see javax.tools.StandardJavaFileManager#getLocation(javax.tools.JavaFileManager.Location)
581      */

582     public Iterable JavaDoc<? extends File JavaDoc> getLocation(Location location) {
583         if (this.locations == null) return null;
584         return this.locations.get(location.getName());
585     }
586
587     private Iterable JavaDoc<? extends File JavaDoc> getOutputDir(String JavaDoc string) {
588         if ("none".equals(string)) {//$NON-NLS-1$
589
return null;
590         }
591         File JavaDoc file = new File JavaDoc(string);
592         if (file.exists() && !file.isDirectory()) {
593             throw new IllegalArgumentException JavaDoc("file : " + file.getAbsolutePath() + " is not a directory");//$NON-NLS-1$//$NON-NLS-2$
594
}
595         ArrayList JavaDoc<File JavaDoc> list = new ArrayList JavaDoc<File JavaDoc>(1);
596         list.add(file);
597         return list;
598     }
599
600     /* (non-Javadoc)
601      * @see javax.tools.JavaFileManager#handleOption(java.lang.String, java.util.Iterator)
602      */

603     public boolean handleOption(String JavaDoc current, Iterator JavaDoc<String JavaDoc> remaining) {
604         try {
605             if ("-bootclasspath".equals(current)) {//$NON-NLS-1$
606
remaining.remove(); // remove the current option
607
if (remaining.hasNext()) {
608                     final Iterable JavaDoc<? extends File JavaDoc> bootclasspaths = getPathsFrom(remaining.next());
609                     if (bootclasspaths != null) {
610                         Iterable JavaDoc<? extends File JavaDoc> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
611                         if ((this.flags & HAS_ENDORSED_DIRS) == 0
612                                 && (this.flags & HAS_EXT_DIRS) == 0) {
613                             // override default bootclasspath
614
setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootclasspaths);
615                         } else if ((this.flags & HAS_ENDORSED_DIRS) != 0) {
616                             // endorseddirs have been processed first
617
setLocation(StandardLocation.PLATFORM_CLASS_PATH,
618                                     concatFiles(iterable, bootclasspaths));
619                         } else {
620                             // extdirs have been processed first
621
setLocation(StandardLocation.PLATFORM_CLASS_PATH,
622                                     prependFiles(iterable, bootclasspaths));
623                         }
624                     }
625                     remaining.remove();
626                     this.flags |= HAS_BOOTCLASSPATH;
627                     return true;
628                 } else {
629                     throw new IllegalArgumentException JavaDoc();
630                 }
631             }
632             if ("-classpath".equals(current) || "-cp".equals(current)) {//$NON-NLS-1$//$NON-NLS-2$
633
remaining.remove(); // remove the current option
634
if (remaining.hasNext()) {
635                     final Iterable JavaDoc<? extends File JavaDoc> classpaths = getPathsFrom(remaining.next());
636                     if (classpaths != null) {
637                         setLocation(StandardLocation.CLASS_PATH, classpaths);
638                         if ((this.flags & HAS_PROCESSORPATH) == 0) {
639                             setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, classpaths);
640                         }
641                     }
642                     remaining.remove();
643                     return true;
644                 } else {
645                     throw new IllegalArgumentException JavaDoc();
646                 }
647             }
648             if ("-encoding".equals(current)) {//$NON-NLS-1$
649
remaining.remove(); // remove the current option
650
if (remaining.hasNext()) {
651                     this.charset = Charset.forName(remaining.next());
652                     remaining.remove();
653                     return true;
654                 } else {
655                     throw new IllegalArgumentException JavaDoc();
656                 }
657             }
658             if ("-sourcepath".equals(current)) {//$NON-NLS-1$
659
remaining.remove(); // remove the current option
660
if (remaining.hasNext()) {
661                     final Iterable JavaDoc<? extends File JavaDoc> sourcepaths = getPathsFrom(remaining.next());
662                     if (sourcepaths != null) setLocation(StandardLocation.SOURCE_PATH, sourcepaths);
663                     remaining.remove();
664                     return true;
665                 } else {
666                     throw new IllegalArgumentException JavaDoc();
667                 }
668             }
669             if ("-extdirs".equals(current)) {//$NON-NLS-1$
670
remaining.remove(); // remove the current option
671
if (remaining.hasNext()) {
672                     Iterable JavaDoc<? extends File JavaDoc> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
673                     setLocation(StandardLocation.PLATFORM_CLASS_PATH,
674                             concatFiles(iterable, getExtdirsFrom(remaining.next())));
675                     remaining.remove();
676                     this.flags |= HAS_EXT_DIRS;
677                     return true;
678                 } else {
679                     throw new IllegalArgumentException JavaDoc();
680                 }
681             }
682             if ("-endorseddirs".equals(current)) {//$NON-NLS-1$
683
remaining.remove(); // remove the current option
684
if (remaining.hasNext()) {
685                     Iterable JavaDoc<? extends File JavaDoc> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
686                     setLocation(StandardLocation.PLATFORM_CLASS_PATH,
687                             prependFiles(iterable, getEndorsedDirsFrom(remaining.next())));
688                     remaining.remove();
689                     this.flags |= HAS_ENDORSED_DIRS;
690                     return true;
691                 } else {
692                     throw new IllegalArgumentException JavaDoc();
693                 }
694             }
695             if ("-d".equals(current)) { //$NON-NLS-1$
696
remaining.remove(); // remove the current option
697
if (remaining.hasNext()) {
698                     final Iterable JavaDoc<? extends File JavaDoc> outputDir = getOutputDir(remaining.next());
699                     if (outputDir != null) {
700                         setLocation(StandardLocation.CLASS_OUTPUT, outputDir);
701                     }
702                     remaining.remove();
703                     return true;
704                 } else {
705                     throw new IllegalArgumentException JavaDoc();
706                 }
707             }
708             if ("-s".equals(current)) { //$NON-NLS-1$
709
remaining.remove(); // remove the current option
710
if (remaining.hasNext()) {
711                     final Iterable JavaDoc<? extends File JavaDoc> outputDir = getOutputDir(remaining.next());
712                     if (outputDir != null) {
713                         setLocation(StandardLocation.SOURCE_OUTPUT, outputDir);
714                     }
715                     remaining.remove();
716                     return true;
717                 } else {
718                     throw new IllegalArgumentException JavaDoc();
719                 }
720             }
721             if ("-processorpath".equals(current)) {//$NON-NLS-1$
722
remaining.remove(); // remove the current option
723
if (remaining.hasNext()) {
724                     final Iterable JavaDoc<? extends File JavaDoc> processorpaths = getPathsFrom(remaining.next());
725                     if (processorpaths != null) {
726                         setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, processorpaths);
727                     }
728                     remaining.remove();
729                     this.flags |= HAS_PROCESSORPATH;
730                     return true;
731                 } else {
732                     throw new IllegalArgumentException JavaDoc();
733                 }
734             }
735         } catch (IOException JavaDoc e) {
736             // ignore
737
}
738         return false;
739     }
740
741     /* (non-Javadoc)
742      * @see javax.tools.JavaFileManager#hasLocation(javax.tools.JavaFileManager.Location)
743      */

744     public boolean hasLocation(Location location) {
745         return this.locations != null && this.locations.containsKey(location.getName());
746     }
747
748     /* (non-Javadoc)
749      * @see javax.tools.JavaFileManager#inferBinaryName(javax.tools.JavaFileManager.Location, javax.tools.JavaFileObject)
750      */

751     public String JavaDoc inferBinaryName(Location location, JavaFileObject file) {
752         String JavaDoc name = file.getName();
753         JavaFileObject javaFileObject = null;
754         int index = name.lastIndexOf('.');
755         if (index != -1) {
756             name = name.substring(0, index);
757         }
758         try {
759             javaFileObject = getJavaFileForInput(location, name, file.getKind());
760         } catch (IOException JavaDoc e) {
761             // ignore
762
}
763         if (javaFileObject == null) {
764             return null;
765         }
766         return normalized(name);
767     }
768
769     private boolean isArchive(File JavaDoc f) {
770         String JavaDoc extension = getExtension(f);
771         return extension.equalsIgnoreCase(".jar") || extension.equalsIgnoreCase(".zip");//$NON-NLS-1$//$NON-NLS-2$
772
}
773
774     /* (non-Javadoc)
775      * @see javax.tools.StandardJavaFileManager#isSameFile(javax.tools.FileObject, javax.tools.FileObject)
776      */

777     public boolean isSameFile(FileObject fileObject1, FileObject fileObject2) {
778         // EclipseFileManager creates only EcliseFileObject
779
if (!(fileObject1 instanceof EclipseFileObject)) throw new IllegalArgumentException JavaDoc("Unsupported file object class : " + fileObject1.getClass());//$NON-NLS-1$
780
if (!(fileObject2 instanceof EclipseFileObject)) throw new IllegalArgumentException JavaDoc("Unsupported file object class : " + fileObject2.getClass());//$NON-NLS-1$
781
return fileObject1.equals(fileObject2);
782     }
783     /* (non-Javadoc)
784      * @see javax.tools.OptionChecker#isSupportedOption(java.lang.String)
785      */

786     public int isSupportedOption(String JavaDoc option) {
787         return Options.processOptionsFileManager(option);
788     }
789
790     /* (non-Javadoc)
791      * @see javax.tools.JavaFileManager#list(javax.tools.JavaFileManager.Location, java.lang.String, java.util.Set, boolean)
792      */

793     public Iterable JavaDoc<JavaFileObject> list(Location location, String JavaDoc packageName, Set JavaDoc<Kind> kinds, boolean recurse)
794             throws IOException JavaDoc {
795
796         Iterable JavaDoc<? extends File JavaDoc> allFilesInLocations = getLocation(location);
797         if (allFilesInLocations == null) {
798             throw new IllegalArgumentException JavaDoc("Unknown location : " + location);//$NON-NLS-1$
799
}
800
801         ArrayList JavaDoc<JavaFileObject> collector = new ArrayList JavaDoc<JavaFileObject>();
802         String JavaDoc normalizedPackageName = normalized(packageName);
803         for (File JavaDoc file : allFilesInLocations) {
804             collectAllMatchingFiles(file, normalizedPackageName, kinds, recurse, collector);
805         }
806         return collector;
807     }
808
809     private String JavaDoc normalized(String JavaDoc className) {
810         char[] classNameChars = className.toCharArray();
811         for (int i = 0, max = classNameChars.length; i < max; i++) {
812             switch(classNameChars[i]) {
813                 case '\\' :
814                     classNameChars[i] = '/';
815                     break;
816                 case '.' :
817                     classNameChars[i] = '/';
818             }
819         }
820         return new String JavaDoc(classNameChars);
821     }
822
823     private Iterable JavaDoc<? extends File JavaDoc> prependFiles(Iterable JavaDoc<? extends File JavaDoc> iterable,
824             Iterable JavaDoc<? extends File JavaDoc> iterable2) {
825         if (iterable2 == null) return iterable;
826         ArrayList JavaDoc<File JavaDoc> list = new ArrayList JavaDoc<File JavaDoc>();
827         for (Iterator JavaDoc<? extends File JavaDoc> iterator = iterable2.iterator(); iterator.hasNext(); ) {
828             list.add(iterator.next());
829         }
830         for (Iterator JavaDoc<? extends File JavaDoc> iterator = iterable.iterator(); iterator.hasNext(); ) {
831             list.add(iterator.next());
832         }
833         return list;
834     }
835
836     /* (non-Javadoc)
837      * @see javax.tools.StandardJavaFileManager#setLocation(javax.tools.JavaFileManager.Location, java.lang.Iterable)
838      */

839     public void setLocation(Location location, Iterable JavaDoc<? extends File JavaDoc> path) throws IOException JavaDoc {
840         if (path != null) {
841             if (location.isOutputLocation()) {
842                 // output location
843
int count = 0;
844                 for (Iterator JavaDoc<? extends File JavaDoc> iterator = path.iterator(); iterator.hasNext(); ) {
845                     iterator.next();
846                     count++;
847                 }
848                 if (count != 1) {
849                     throw new IllegalArgumentException JavaDoc("output location can only have one path");//$NON-NLS-1$
850
}
851             }
852             this.locations.put(location.getName(), path);
853         }
854     }
855
856     public void setLocale(Locale JavaDoc locale) {
857         this.locale = locale == null ? Locale.getDefault() : locale;
858         try {
859             this.bundle = ResourceBundleFactory.getBundle(this.locale);
860         } catch(MissingResourceException JavaDoc e) {
861             System.err.println("Missing resource : " + Main.bundleName.replace('.', '/') + ".properties for locale " + locale); //$NON-NLS-1$//$NON-NLS-2$
862
throw e;
863         }
864     }
865
866     @SuppressWarnings JavaDoc("unchecked")
867     public void processPathEntries(final int defaultSize, final ArrayList JavaDoc paths,
868             final String JavaDoc currentPath, String JavaDoc customEncoding, boolean isSourceOnly,
869             boolean rejectDestinationPathOnJars)
870         throws InvalidInputException {
871         String JavaDoc currentClasspathName = null;
872         String JavaDoc currentDestinationPath = null;
873         ArrayList JavaDoc currentRuleSpecs = new ArrayList JavaDoc(defaultSize);
874         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(currentPath,
875                 File.pathSeparator + "[]", true); //$NON-NLS-1$
876
ArrayList JavaDoc tokens = new ArrayList JavaDoc();
877         while (tokenizer.hasMoreTokens()) {
878             tokens.add(tokenizer.nextToken());
879         }
880         // state machine
881
final int start = 0;
882         final int readyToClose = 1;
883         // 'path' 'path1[rule];path2'
884
final int readyToCloseEndingWithRules = 2;
885         // 'path[rule]' 'path1;path2[rule]'
886
final int readyToCloseOrOtherEntry = 3;
887         // 'path[rule];' 'path;' 'path1;path2;'
888
final int rulesNeedAnotherRule = 4;
889         // 'path[rule1;'
890
final int rulesStart = 5;
891         // 'path[' 'path1;path2['
892
final int rulesReadyToClose = 6;
893         // 'path[rule' 'path[rule1;rule2'
894
final int destinationPathReadyToClose = 7;
895         // 'path[-d bin'
896
final int readyToCloseEndingWithDestinationPath = 8;
897         // 'path[-d bin]' 'path[rule][-d bin]'
898
final int destinationPathStart = 9;
899         // 'path[rule]['
900
final int bracketOpened = 10;
901         // '.*[.*'
902
final int bracketClosed = 11;
903         // '.*([.*])+'
904

905         final int error = 99;
906         int state = start;
907         String JavaDoc token = null;
908         int cursor = 0, tokensNb = tokens.size(), bracket = -1;
909         while (cursor < tokensNb && state != error) {
910             token = (String JavaDoc) tokens.get(cursor++);
911             if (token.equals(File.pathSeparator)) {
912                 switch (state) {
913                 case start:
914                 case readyToCloseOrOtherEntry:
915                 case bracketOpened:
916                     break;
917                 case readyToClose:
918                 case readyToCloseEndingWithRules:
919                 case readyToCloseEndingWithDestinationPath:
920                     state = readyToCloseOrOtherEntry;
921                     addNewEntry(paths, currentClasspathName, currentRuleSpecs,
922                             customEncoding, currentDestinationPath, isSourceOnly,
923                             rejectDestinationPathOnJars);
924                     currentRuleSpecs.clear();
925                     break;
926                 case rulesReadyToClose:
927                     state = rulesNeedAnotherRule;
928                     break;
929                 case destinationPathReadyToClose:
930                     throw new InvalidInputException(
931                             this.bind("configure.incorrectDestinationPathEntry", //$NON-NLS-1$
932
currentPath));
933                 case bracketClosed:
934                     cursor = bracket + 1;
935                     state = rulesStart;
936                     break;
937                 default:
938                     state = error;
939                 }
940             } else if (token.equals("[")) { //$NON-NLS-1$
941
switch (state) {
942                 case start:
943                     currentClasspathName = ""; //$NON-NLS-1$
944
case readyToClose:
945                     bracket = cursor - 1;
946                 case bracketClosed:
947                     state = bracketOpened;
948                     break;
949                 case readyToCloseEndingWithRules:
950                     state = destinationPathStart;
951                     break;
952                 case readyToCloseEndingWithDestinationPath:
953                     state = rulesStart;
954                     break;
955                 case bracketOpened:
956                 default:
957                     state = error;
958                 }
959             } else if (token.equals("]")) { //$NON-NLS-1$
960
switch (state) {
961                 case rulesReadyToClose:
962                     state = readyToCloseEndingWithRules;
963                     break;
964                 case destinationPathReadyToClose:
965                     state = readyToCloseEndingWithDestinationPath;
966                     break;
967                 case bracketOpened:
968                     state = bracketClosed;
969                     break;
970                 case bracketClosed:
971                 default:
972                     state = error;
973                 }
974             } else {
975                 // regular word
976
switch (state) {
977                 case start:
978                 case readyToCloseOrOtherEntry:
979                     state = readyToClose;
980                     currentClasspathName = token;
981                     break;
982                 case rulesStart:
983                     if (token.startsWith("-d ")) { //$NON-NLS-1$
984
if (currentDestinationPath != null) {
985                             throw new InvalidInputException(
986                                     this.bind("configure.duplicateDestinationPathEntry", //$NON-NLS-1$
987
currentPath));
988                         }
989                         currentDestinationPath = token.substring(3).trim();
990                         state = destinationPathReadyToClose;
991                         break;
992                     } // else we proceed with a rule
993
case rulesNeedAnotherRule:
994                     if (currentDestinationPath != null) {
995                         throw new InvalidInputException(
996                                 this.bind("configure.accessRuleAfterDestinationPath", //$NON-NLS-1$
997
currentPath));
998                     }
999                     state = rulesReadyToClose;
1000                    currentRuleSpecs.add(token);
1001                    break;
1002                case destinationPathStart:
1003                    if (!token.startsWith("-d ")) { //$NON-NLS-1$
1004
state = error;
1005                    } else {
1006                        currentDestinationPath = token.substring(3).trim();
1007                        state = destinationPathReadyToClose;
1008                    }
1009                    break;
1010                case bracketClosed:
1011                    for (int i = bracket; i < cursor ; i++) {
1012                        currentClasspathName += (String JavaDoc) tokens.get(i);
1013                    }
1014                    state = readyToClose;
1015                    break;
1016                case bracketOpened:
1017                    break;
1018                default:
1019                    state = error;
1020                }
1021            }
1022            if (state == bracketClosed && cursor == tokensNb) {
1023                cursor = bracket + 1;
1024                state = rulesStart;
1025            }
1026        }
1027        switch(state) {
1028            case readyToCloseOrOtherEntry:
1029                break;
1030            case readyToClose:
1031            case readyToCloseEndingWithRules:
1032            case readyToCloseEndingWithDestinationPath:
1033                addNewEntry(paths, currentClasspathName, currentRuleSpecs,
1034                    customEncoding, currentDestinationPath, isSourceOnly,
1035                    rejectDestinationPathOnJars);
1036                break;
1037            case bracketOpened:
1038            case bracketClosed:
1039            default :
1040                // we go on anyway
1041
}
1042    }
1043    @SuppressWarnings JavaDoc("unchecked")
1044    protected void addNewEntry(ArrayList JavaDoc paths, String JavaDoc currentClasspathName,
1045            ArrayList JavaDoc currentRuleSpecs, String JavaDoc customEncoding,
1046            String JavaDoc destPath, boolean isSourceOnly,
1047            boolean rejectDestinationPathOnJars) throws InvalidInputException {
1048
1049        int rulesSpecsSize = currentRuleSpecs.size();
1050        AccessRuleSet accessRuleSet = null;
1051        if (rulesSpecsSize != 0) {
1052            AccessRule[] accessRules = new AccessRule[currentRuleSpecs.size()];
1053            boolean rulesOK = true;
1054            Iterator JavaDoc i = currentRuleSpecs.iterator();
1055            int j = 0;
1056            while (i.hasNext()) {
1057                String JavaDoc ruleSpec = (String JavaDoc) i.next();
1058                char key = ruleSpec.charAt(0);
1059                String JavaDoc pattern = ruleSpec.substring(1);
1060                if (pattern.length() > 0) {
1061                    switch (key) {
1062                        case '+':
1063                            accessRules[j++] = new AccessRule(pattern
1064                                    .toCharArray(), 0);
1065                            break;
1066                        case '~':
1067                            accessRules[j++] = new AccessRule(pattern
1068                                    .toCharArray(),
1069                                    IProblem.DiscouragedReference);
1070                            break;
1071                        case '-':
1072                            accessRules[j++] = new AccessRule(pattern
1073                                    .toCharArray(),
1074                                    IProblem.ForbiddenReference);
1075                            break;
1076                        case '?':
1077                            accessRules[j++] = new AccessRule(pattern
1078                                    .toCharArray(),
1079                                    IProblem.ForbiddenReference, true/*keep looking for accessible type*/);
1080                            break;
1081                        default:
1082                            rulesOK = false;
1083                    }
1084                } else {
1085                    rulesOK = false;
1086                }
1087            }
1088            if (rulesOK) {
1089                String JavaDoc templates[] = new String JavaDoc[AccessRuleSet.MESSAGE_TEMPLATES_LENGTH];
1090                templates[0] = this.bind(
1091                        "template.restrictedAccess.type", //$NON-NLS-1$
1092
new String JavaDoc[] {"{0}", currentClasspathName}); //$NON-NLS-1$
1093
templates[1] = this.bind(
1094                        "template.restrictedAccess.constructor", //$NON-NLS-1$
1095
new String JavaDoc[] {"{0}", currentClasspathName}); //$NON-NLS-1$
1096
templates[2] = this.bind(
1097                        "template.restrictedAccess.method", //$NON-NLS-1$
1098
new String JavaDoc[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$
1099
templates[3] = this.bind(
1100                        "template.restrictedAccess.field", //$NON-NLS-1$
1101
new String JavaDoc[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$
1102
accessRuleSet = new AccessRuleSet(accessRules, templates);
1103            } else {
1104                return;
1105            }
1106        }
1107        if (Main.NONE.equals(destPath)) {
1108            destPath = Main.NONE; // keep == comparison valid
1109
}
1110        if (rejectDestinationPathOnJars && destPath != null &&
1111                (currentClasspathName.endsWith(".jar") || //$NON-NLS-1$
1112
currentClasspathName.endsWith(".zip"))) { //$NON-NLS-1$
1113
throw new InvalidInputException(
1114                    this.bind("configure.unexpectedDestinationPathEntryFile", //$NON-NLS-1$
1115
currentClasspathName));
1116            }
1117        FileSystem.Classpath currentClasspath = FileSystem.getClasspath(
1118                currentClasspathName,
1119                customEncoding,
1120                isSourceOnly,
1121                accessRuleSet,
1122                destPath);
1123        if (currentClasspath != null) {
1124            paths.add(currentClasspath);
1125        }
1126    }
1127    /*
1128     * Lookup the message with the given ID in this catalog and bind its
1129     * substitution locations with the given string.
1130     */

1131    private String JavaDoc bind(String JavaDoc id, String JavaDoc binding) {
1132        return bind(id, new String JavaDoc[] { binding });
1133    }
1134
1135    /*
1136     * Lookup the message with the given ID in this catalog and bind its
1137     * substitution locations with the given string values.
1138     */

1139    private String JavaDoc bind(String JavaDoc id, String JavaDoc[] arguments) {
1140        if (id == null)
1141            return "No message available"; //$NON-NLS-1$
1142
String JavaDoc message = null;
1143        try {
1144            message = this.bundle.getString(id);
1145        } catch (MissingResourceException JavaDoc e) {
1146            // If we got an exception looking for the message, fail gracefully by just returning
1147
// the id we were looking for. In most cases this is semi-informative so is not too bad.
1148
return "Missing message: " + id + " in: " + Main.bundleName; //$NON-NLS-2$ //$NON-NLS-1$
1149
}
1150        return MessageFormat.format(message, (Object JavaDoc[]) arguments);
1151    }
1152}
1153
Popular Tags