protected void initialize(File javahome) throws IOException { if (this.isOnJvm9) { this.jrtSystem = new JrtFileSystem(javahome); this.archivesCache.put(javahome, this.jrtSystem); this.jrtHome = javahome; this.locationHandler.newSystemLocation(StandardLocation.SYSTEM_MODULES, this.jrtSystem); } else { this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath()); } Iterable<? extends File> defaultClasspath = getDefaultClasspath(); this.setLocation(StandardLocation.CLASS_PATH, defaultClasspath); // No annotation module path by default this.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, defaultClasspath); }
private String bind(String id, String binding) { return bind(id, new String[] { binding }); }
public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException { Iterable<? extends File> allFilesInLocations = getLocation(location); if (allFilesInLocations == null) { throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$ } ArrayList<JavaFileObject> collector = new ArrayList<JavaFileObject>(); String normalizedPackageName = normalized(packageName); for (File file : allFilesInLocations) { collectAllMatchingFiles(file, normalizedPackageName, kinds, recurse, collector); } return collector; }
@Override public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException { validateNonModuleLocation(location); Iterable<? extends File> allFilesInLocations = getLocation(location); if (allFilesInLocations == null) { throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$ } ArrayList<JavaFileObject> collector = new ArrayList<>(); String normalizedPackageName = normalized(packageName); for (File file : allFilesInLocations) { collectAllMatchingFiles(location, file, normalizedPackageName, kinds, recurse, collector); } return collector; }
if ("-bootclasspath".equals(current)) {//$NON-NLS-1$ if (remaining.hasNext()) { final Iterable<? extends File> bootclasspaths = getPathsFrom(remaining.next()); if (bootclasspaths != null) { Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH); if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) == 0 && (this.flags & EclipseFileManager.HAS_EXT_DIRS) == 0) { setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootclasspaths); } else if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) != 0) { setLocation(StandardLocation.PLATFORM_CLASS_PATH, concatFiles(iterable, bootclasspaths)); } else { setLocation(StandardLocation.PLATFORM_CLASS_PATH, prependFiles(iterable, bootclasspaths)); final Iterable<? extends File> classpaths = getPathsFrom(remaining.next()); if (classpaths != null) { Iterable<? extends File> iterable = getLocation(StandardLocation.CLASS_PATH); if (iterable != null) { setLocation(StandardLocation.CLASS_PATH, concatFiles(iterable, classpaths)); } else { setLocation(StandardLocation.CLASS_PATH, classpaths); setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, classpaths);
public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { Iterable<? extends File> files = getLocation(location); if (files == null) { throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$ } String normalizedFileName = normalized(packageName) + '/' + relativeName.replace('\\', '/'); for (File file : files) { if (file.isDirectory()) { // handle directory File f = new File(file, normalizedFileName); if (f.exists()) { return new EclipseFileObject(packageName + File.separator + relativeName, f.toURI(), getKind(f), this.charset); } else { continue; // go to next entry in the location } } else if (isArchive(file)) { // handle archive file Archive archive = getArchive(file); if (archive != Archive.UNKNOWN_ARCHIVE) { if (archive.contains(normalizedFileName)) { return archive.getArchiveFileObject(normalizedFileName, this.charset); } } } } return null; }
private void collectAllMatchingFiles(File file, String normalizedPackageName, Set<Kind> kinds, boolean recurse, ArrayList<JavaFileObject> collector) { if (!isArchive(file)) { collectAllMatchingFiles(file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector); } else { final Kind kind = getKind(f); if (kinds.contains(kind)) { collector.add(new EclipseFileObject(normalizedPackageName + f.getName(), f.toURI(), kind, this.charset)); Archive archive = this.getArchive(file); if (archive == Archive.UNKNOWN_ARCHIVE) return; String key = normalizedPackageName; if (types != null) { for (String typeName : types) { final Kind kind = getKind(getExtension(typeName)); if (kinds.contains(kind)) { collector.add(archive.getArchiveFileObject(packageName + typeName, this.charset)); if (types != null) { for (String typeName : types) { final Kind kind = getKind(getExtension(typeName)); if (kinds.contains(kind)) { collector.add(archive.getArchiveFileObject(key + typeName, this.charset));
@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { validateNonModuleLocation(location); Iterable<? extends File> files = getLocation(location); if (files == null) { throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$ } String normalizedFileName = normalizedFileName(packageName, relativeName); for (File file : files) { if (file.isDirectory()) { // handle directory File f = new File(file, normalizedFileName); if (f.exists()) { return new EclipseFileObject(packageName + File.separator + relativeName, f.toURI(), getKind(f), this.charset); } else { continue; // go to next entry in the location } } else if (isArchive(file)) { // handle archive file Archive archive = getArchive(file); if (archive != Archive.UNKNOWN_ARCHIVE) { if (archive.contains(normalizedFileName)) { return archive.getArchiveFileObject(normalizedFileName, null, this.charset); } } } } return null; }
case readyToCloseEndingWithDestinationPath: state = readyToCloseOrOtherEntry; addNewEntry(paths, currentClasspathName, currentRuleSpecs, customEncoding, currentDestinationPath, isSourceOnly, rejectDestinationPathOnJars); case destinationPathReadyToClose: throw new IllegalArgumentException( this.bind("configure.incorrectDestinationPathEntry", //$NON-NLS-1$ currentPath)); case bracketClosed: if (currentDestinationPath != null) { throw new IllegalArgumentException( this.bind("configure.duplicateDestinationPathEntry", //$NON-NLS-1$ currentPath)); if (currentDestinationPath != null) { throw new IllegalArgumentException( this.bind("configure.accessRuleAfterDestinationPath", //$NON-NLS-1$ currentPath)); case readyToCloseEndingWithRules: case readyToCloseEndingWithDestinationPath: addNewEntry(paths, currentClasspathName, currentRuleSpecs, customEncoding, currentDestinationPath, isSourceOnly, rejectDestinationPathOnJars);
try { if (!isProcNone()) { fileManager = new EclipseFileManager(null, getSourceEncoding()); fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, processorpath); fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(getOutputDirectory())); fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(getGeneratedSourcesDirectory())); } finally { if (fileManager != null) { fileManager.flush(); fileManager.close();
@Override public boolean contains(Location location, FileObject fo) throws IOException { validateFileObject(fo); Iterable<? extends File> files = getLocation(location); if (files == null) { throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$ } for (File file : files) { if (file.isDirectory()) { if (fo instanceof EclipseFileObject) { Path filepath = ((EclipseFileObject) fo).f.toPath(); if (filepath.startsWith(Paths.get(file.toURI()).toAbsolutePath())) { return true; } } } else if (isArchive(file)) { if (fo instanceof ArchiveFileObject) { Archive archive = getArchive(file); if (archive != Archive.UNKNOWN_ARCHIVE) { if (archive.contains(((ArchiveFileObject) fo ).entryName)) { return true; } } } } } return false; }
String encoding = (String) batchCompiler.options.get(CompilerOptions.OPTION_Encoding); Charset charset = encoding != null ? Charset.forName(encoding) : null; JavaFileManager manager = new EclipseFileManager(batchCompiler.compilerLocale, charset); ArrayList<String> options = new ArrayList<>(); for (String argument : commandLineArguments) {
@Override public void setLocationFromPaths(Location location, Collection<? extends Path> paths) throws IOException { setLocation(location, getFiles(paths)); if (location == StandardLocation.MODULE_PATH) { // FIXME: same for module source path? Map<String, String> options = new HashMap<>(); // FIXME: Find a way to get the options from the EclipseCompiler and pass it to the parser. // FIXME: need to be the latest and not hardcoded value options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_9); options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); CompilerOptions compilerOptions = new CompilerOptions(options); ProblemReporter problemReporter = new ProblemReporter( DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, new DefaultProblemFactory()); for (Path path : paths) { List<Classpath> mp = ModuleFinder.findModules(path.toFile(), null, new Parser(problemReporter, true), null, true, this.releaseVersion); for (Classpath cp : mp) { Collection<String> moduleNames = cp.getModuleNames(null); for (String string : moduleNames) { Path p = Paths.get(cp.getPath()); setLocationForModule(StandardLocation.MODULE_PATH, string, Collections.singletonList(p)); } } } } }
if ("-bootclasspath".equals(current)) {//$NON-NLS-1$ if (remaining.hasNext()) { final Iterable<? extends File> bootclasspaths = getPathsFrom(remaining.next()); if (bootclasspaths != null) { Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH); if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) == 0 && (this.flags & EclipseFileManager.HAS_EXT_DIRS) == 0) { setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootclasspaths); } else if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) != 0) { setLocation(StandardLocation.PLATFORM_CLASS_PATH, concatFiles(iterable, bootclasspaths)); } else { setLocation(StandardLocation.PLATFORM_CLASS_PATH, prependFiles(iterable, bootclasspaths)); final Iterable<? extends File> classpaths = getPathsFrom(remaining.next()); if (classpaths != null) { Iterable<? extends File> iterable = getLocation(StandardLocation.CLASS_PATH); if (iterable != null) { setLocation(StandardLocation.CLASS_PATH, concatFiles(iterable, classpaths)); } else { setLocation(StandardLocation.CLASS_PATH, classpaths); setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, classpaths);
public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { Iterable<? extends File> files = getLocation(location); if (files == null) { throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$ } String normalizedFileName = normalized(packageName) + '/' + relativeName.replace('\\', '/'); for (File file : files) { if (file.isDirectory()) { // handle directory File f = new File(file, normalizedFileName); if (f.exists()) { return new EclipseFileObject(packageName + File.separator + relativeName, f.toURI(), getKind(f), this.charset); } else { continue; // go to next entry in the location } } else if (isArchive(file)) { // handle archive file Archive archive = getArchive(file); if (archive != Archive.UNKNOWN_ARCHIVE) { if (archive.contains(normalizedFileName)) { return archive.getArchiveFileObject(normalizedFileName, this.charset); } } } } return null; }
List<JrtFileObject> list = this.jrtSystem.list((ModuleLocationWrapper) location, normalizedPackageName, kinds, recurse, this.charset); for (JrtFileObject fo : list) { Kind kind = getKind(getExtension(fo.entryName)); if (kinds.contains(kind)) { collector.add(fo); } else if (isArchive(file)) { Archive archive = this.getArchive(file); if (archive == Archive.UNKNOWN_ARCHIVE) return; String key = normalizedPackageName; if (types != null) { for (String[] entry : types) { final Kind kind = getKind(getExtension(entry[0])); if (kinds.contains(kind)) { collector.add(archive.getArchiveFileObject(packageName + entry[0], entry[1], this.charset)); if (types != null) { for (String[] entry : types) { final Kind kind = getKind(getExtension(entry[0])); if (kinds.contains(kind)) { collector.add(archive.getArchiveFileObject(key + entry[0], entry[1], this.charset)); collectAllMatchingFiles(location, file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector); } else { final Kind kind = getKind(f); if (kinds.contains(kind)) { collector.add(new EclipseFileObject(normalizedPackageName + f.getName(), f.toURI(), kind, this.charset));
@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { Iterable<? extends File> files = getLocation(location); if (files == null) { throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$ } String normalizedFileName = normalizedFileName(packageName, relativeName); for (File file : files) { if (file.isDirectory()) { // handle directory File f = new File(file, normalizedFileName); if (f.exists()) { return new EclipseFileObject(packageName + File.separator + relativeName, f.toURI(), getKind(f), this.charset); } else { continue; // go to next entry in the location } } else if (isArchive(file)) { // handle archive file Archive archive = getArchive(file); if (archive != Archive.UNKNOWN_ARCHIVE) { if (archive.contains(normalizedFileName)) { return archive.getArchiveFileObject(normalizedFileName, this.charset); } } } } return null; }
case readyToCloseEndingWithDestinationPath: state = readyToCloseOrOtherEntry; addNewEntry(paths, currentClasspathName, currentRuleSpecs, customEncoding, currentDestinationPath, isSourceOnly, rejectDestinationPathOnJars); case destinationPathReadyToClose: throw new IllegalArgumentException( this.bind("configure.incorrectDestinationPathEntry", //$NON-NLS-1$ currentPath)); case bracketClosed: if (currentDestinationPath != null) { throw new IllegalArgumentException( this.bind("configure.duplicateDestinationPathEntry", //$NON-NLS-1$ currentPath)); if (currentDestinationPath != null) { throw new IllegalArgumentException( this.bind("configure.accessRuleAfterDestinationPath", //$NON-NLS-1$ currentPath)); case readyToCloseEndingWithRules: case readyToCloseEndingWithDestinationPath: addNewEntry(paths, currentClasspathName, currentRuleSpecs, customEncoding, currentDestinationPath, isSourceOnly, rejectDestinationPathOnJars);
try { if (!isProcNone()) { fileManager = new EclipseFileManager(null, getSourceEncoding()); fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, processorpath); fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(getOutputDirectory())); fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(getGeneratedSourcesDirectory())); } finally { if (fileManager != null) { fileManager.flush(); fileManager.close();
String encoding = (String) batchCompiler.options.get(CompilerOptions.OPTION_Encoding); Charset charset = encoding != null ? Charset.forName(encoding) : null; JavaFileManager manager = new EclipseFileManager(batchCompiler.compilerLocale, charset); ArrayList<String> options = new ArrayList<String>(); for (String argument : commandLineArguments) {