Search in sources :

Example 1 with Classpath

use of org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath in project bazel-jdt-java-toolchain by salesforce.

the class Main method handleClasspath.

/*
 * External API
 */
protected ArrayList<FileSystem.Classpath> handleClasspath(ArrayList<String> classpaths, String customEncoding) {
    ArrayList<FileSystem.Classpath> initial = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
    if (classpaths != null && classpaths.size() > 0) {
        for (String path : classpaths) {
            processPathEntries(DEFAULT_SIZE_CLASSPATH, initial, path, customEncoding, false, true);
        }
    } else {
        // no user classpath specified.
        // $NON-NLS-1$
        String classProp = System.getProperty("java.class.path");
        if ((classProp == null) || (classProp.length() == 0)) {
            // $NON-NLS-1$
            addPendingErrors(this.bind("configure.noClasspath"));
            // $NON-NLS-1$
            final Classpath classpath = FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, null, this.options, this.releaseVersion);
            if (classpath != null) {
                initial.add(classpath);
            }
        } else {
            StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
            String token;
            while (tokenizer.hasMoreTokens()) {
                token = tokenizer.nextToken();
                FileSystem.Classpath currentClasspath = FileSystem.getClasspath(token, customEncoding, null, this.options, this.releaseVersion);
                if (currentClasspath != null) {
                    initial.add(currentClasspath);
                } else if (token.length() != 0) {
                    // $NON-NLS-1$
                    addPendingErrors(this.bind("configure.incorrectClasspath", token));
                }
            }
        }
    }
    ArrayList<Classpath> result = new ArrayList<>();
    HashMap<String, Classpath> knownNames = new HashMap<>();
    FileSystem.ClasspathSectionProblemReporter problemReporter = new FileSystem.ClasspathSectionProblemReporter() {

        @Override
        public void invalidClasspathSection(String jarFilePath) {
            // $NON-NLS-1$
            addPendingErrors(bind("configure.invalidClasspathSection", jarFilePath));
        }

        @Override
        public void multipleClasspathSections(String jarFilePath) {
            // $NON-NLS-1$
            addPendingErrors(bind("configure.multipleClasspathSections", jarFilePath));
        }
    };
    while (!initial.isEmpty()) {
        Classpath current = initial.remove(0);
        String currentPath = current.getPath();
        if (knownNames.get(currentPath) == null) {
            knownNames.put(currentPath, current);
            result.add(current);
            List<Classpath> linkedJars = current.fetchLinkedJars(problemReporter);
            if (linkedJars != null) {
                initial.addAll(0, linkedJars);
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StringTokenizer(java.util.StringTokenizer) Classpath(org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath) Classpath(org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath)

Example 2 with Classpath

use of org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath in project bazel-jdt-java-toolchain by salesforce.

the class Main method handleExtdirs.

/*
 * External API
 * Handle extdirs processing
 */
protected ArrayList<FileSystem.Classpath> handleExtdirs(ArrayList<String> extdirsClasspaths) {
    final File javaHome = getJavaHome();
    /*
	 * Feed extDirClasspath according to:
	 * - -extdirs first if present;
	 * - else java.ext.dirs if defined;
	 * - else default extensions directory for the platform.
	 */
    if (extdirsClasspaths == null) {
        extdirsClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
        // $NON-NLS-1$
        String extdirsStr = System.getProperty("java.ext.dirs");
        if (extdirsStr == null) {
            // $NON-NLS-1$
            extdirsClasspaths.add(javaHome.getAbsolutePath() + "/lib/ext");
        } else {
            StringTokenizer tokenizer = new StringTokenizer(extdirsStr, File.pathSeparator);
            while (tokenizer.hasMoreTokens()) extdirsClasspaths.add(tokenizer.nextToken());
        }
    }
    /*
	 * Feed extdirsClasspath with the entries found into the directories listed by
	 * extdirsNames.
	 */
    if (extdirsClasspaths.size() != 0) {
        ArrayList<FileSystem.Classpath> result = new ArrayList<>();
        File[] directoriesToCheck = new File[extdirsClasspaths.size()];
        for (int i = 0; i < directoriesToCheck.length; i++) directoriesToCheck[i] = new File(extdirsClasspaths.get(i));
        File[][] extdirsJars = getLibrariesFiles(directoriesToCheck);
        if (extdirsJars != null) {
            for (int i = 0, max = extdirsJars.length; i < max; i++) {
                File[] current = extdirsJars[i];
                if (current != null) {
                    for (int j = 0, max2 = current.length; j < max2; j++) {
                        FileSystem.Classpath classpath = FileSystem.getClasspath(current[j].getAbsolutePath(), null, null, this.options, this.releaseVersion);
                        if (classpath != null) {
                            result.add(classpath);
                        }
                    }
                } else if (directoriesToCheck[i].isFile()) {
                    addPendingErrors(this.bind(// $NON-NLS-1$
                    "configure.incorrectExtDirsEntry", directoriesToCheck[i].getAbsolutePath()));
                }
            }
        }
        return result;
    }
    return FileSystem.EMPTY_CLASSPATH;
}
Also used : StringTokenizer(java.util.StringTokenizer) Classpath(org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath) ArrayList(java.util.ArrayList) Classpath(org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath) ClassFile(org.eclipse.jdt.internal.compiler.ClassFile) File(java.io.File)

Example 3 with Classpath

use of org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath in project bazel-jdt-java-toolchain by salesforce.

the class Main method handleModuleSourcepath.

protected ArrayList<FileSystem.Classpath> handleModuleSourcepath(String arg) {
    ArrayList<String> modulePaths = processModulePathEntries(arg);
    ArrayList<FileSystem.Classpath> result = new ArrayList<>();
    if ((modulePaths != null) && (modulePaths.size() != 0)) {
        if (this.destinationPath == null) {
            // $NON-NLS-1$
            addPendingErrors(this.bind("configure.missingDestinationPath"));
        }
        String[] paths = new String[modulePaths.size()];
        modulePaths.toArray(paths);
        for (int i = 0; i < paths.length; i++) {
            File dir = new File(paths[i]);
            if (dir.isDirectory()) {
                // 1. Create FileSystem.Classpath for each module
                // 2. Iterator each module in case of directory for source files and add to this.fileNames
                List<Classpath> modules = ModuleFinder.findModules(dir, this.destinationPath, getNewParser(), this.options, false, this.releaseVersion);
                for (Classpath classpath : modules) {
                    result.add(classpath);
                    Path modLocation = Paths.get(classpath.getPath()).toAbsolutePath();
                    String destPath = classpath.getDestinationPath();
                    IModule mod = classpath.getModule();
                    String moduleName = mod == null ? null : new String(mod.name());
                    for (int j = 0; j < this.filenames.length; j++) {
                        Path filePath;
                        try {
                            // Get canonical path just as the classpath location is stored with the same.
                            // To avoid mismatch of /USER_JAY and /USE~1 in windows systems.
                            filePath = new File(this.filenames[j]).getCanonicalFile().toPath();
                            if (filePath.startsWith(modLocation)) {
                                this.modNames[j] = moduleName;
                                this.destinationPaths[j] = destPath;
                            }
                        } catch (IOException e) {
                            // Files doesn't exist and perhaps doesn't belong in a module, move on to other files
                            // Use empty module name to distinguish from missing module case
                            // $NON-NLS-1$
                            this.modNames[j] = "";
                        }
                    }
                }
            }
        }
        for (int j = 0; j < this.filenames.length; j++) {
            if (this.modNames[j] == null) {
                // $NON-NLS-1$
                throw new IllegalArgumentException(this.bind("configure.notOnModuleSourcePath", new String[] { this.filenames[j] }));
            }
        }
    }
    return result;
}
Also used : Path(java.nio.file.Path) IModule(org.eclipse.jdt.internal.compiler.env.IModule) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Classpath(org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath) ClassFile(org.eclipse.jdt.internal.compiler.ClassFile) File(java.io.File)

Example 4 with Classpath

use of org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath in project bazel-jdt-java-toolchain by salesforce.

the class ClasspathJar method fetchLinkedJars.

@Override
public List<Classpath> fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) {
    // expected to be called once only - if multiple calls desired, consider
    // using a cache
    InputStream inputStream = null;
    try {
        initialize();
        ArrayList<Classpath> result = new ArrayList<>();
        ZipEntry manifest = this.zipFile.getEntry(TypeConstants.META_INF_MANIFEST_MF);
        if (manifest != null) {
            // non-null implies regular file
            inputStream = this.zipFile.getInputStream(manifest);
            ManifestAnalyzer analyzer = new ManifestAnalyzer();
            boolean success = analyzer.analyzeManifestContents(inputStream);
            List calledFileNames = analyzer.getCalledFileNames();
            if (problemReporter != null) {
                if (!success || analyzer.getClasspathSectionsCount() == 1 && calledFileNames == null) {
                    problemReporter.invalidClasspathSection(getPath());
                } else if (analyzer.getClasspathSectionsCount() > 1) {
                    problemReporter.multipleClasspathSections(getPath());
                }
            }
            if (calledFileNames != null) {
                Iterator calledFilesIterator = calledFileNames.iterator();
                String directoryPath = getPath();
                int lastSeparator = directoryPath.lastIndexOf(File.separatorChar);
                // potentially empty (see bug 214731)
                directoryPath = directoryPath.substring(0, lastSeparator + 1);
                while (calledFilesIterator.hasNext()) {
                    result.add(new ClasspathJar(new File(directoryPath + (String) calledFilesIterator.next()), this.closeZipFileAtEnd, this.accessRuleSet, this.destinationPath));
                }
            }
        }
        return result;
    } catch (IOException | IllegalArgumentException e) {
        // linked jars
        return null;
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            // best effort
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ManifestAnalyzer(org.eclipse.jdt.internal.compiler.util.ManifestAnalyzer) Classpath(org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 5 with Classpath

use of org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath in project bazel-jdt-java-toolchain by salesforce.

the class EclipseFileManager method getDefaultBootclasspath.

Iterable<? extends File> getDefaultBootclasspath() {
    List<File> files = new ArrayList<>();
    // $NON-NLS-1$
    String javaversion = System.getProperty("java.version");
    if (javaversion.length() > 3)
        javaversion = javaversion.substring(0, 3);
    long jdkLevel = CompilerOptions.versionToJdkLevel(javaversion);
    if (jdkLevel < ClassFileConstants.JDK1_6) {
        // wrong jdk - 1.6 or above is required
        return null;
    }
    for (FileSystem.Classpath classpath : org.eclipse.jdt.internal.compiler.util.Util.collectFilesNames()) {
        files.add(new File(classpath.getPath()));
    }
    return files;
}
Also used : FileSystem(org.eclipse.jdt.internal.compiler.batch.FileSystem) ArrayList(java.util.ArrayList) Classpath(org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath) File(java.io.File)

Aggregations

Classpath (org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath)20 ArrayList (java.util.ArrayList)16 File (java.io.File)15 FileSystem (org.eclipse.jdt.internal.compiler.batch.FileSystem)9 ClassFile (org.eclipse.jdt.internal.compiler.ClassFile)6 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)3 StringTokenizer (java.util.StringTokenizer)3 CompilerOptions (org.eclipse.jdt.internal.compiler.impl.CompilerOptions)2 Parser (org.eclipse.jdt.internal.compiler.parser.Parser)2 DefaultProblemFactory (org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory)2 ProblemReporter (org.eclipse.jdt.internal.compiler.problem.ProblemReporter)2 InputStream (java.io.InputStream)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 JavaFileManager (javax.tools.JavaFileManager)1 StandardJavaFileManager (javax.tools.StandardJavaFileManager)1