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;
}
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;
}
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;
}
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
}
}
}
}
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;
}
Aggregations