use of org.eclipse.jdt.internal.compiler.util.ManifestAnalyzer 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.util.ManifestAnalyzer in project che by eclipse.
the class ClasspathEntry method getCalledFileNames.
private static List getCalledFileNames(IPath jarPath) {
Object target = JavaModel.getTarget(jarPath, true);
if (!(target instanceof IFile || target instanceof File))
return null;
JavaModelManager manager = JavaModelManager.getJavaModelManager();
ZipFile zip = null;
InputStream inputStream = null;
List calledFileNames = null;
try {
zip = manager.getZipFile(jarPath);
//$NON-NLS-1$
ZipEntry manifest = zip.getEntry("META-INF/MANIFEST.MF");
if (manifest == null)
return null;
// non-null implies regular file
ManifestAnalyzer analyzer = new ManifestAnalyzer();
inputStream = zip.getInputStream(manifest);
boolean success = analyzer.analyzeManifestContents(inputStream);
calledFileNames = analyzer.getCalledFileNames();
if (!success || analyzer.getClasspathSectionsCount() == 1 && calledFileNames == null) {
if (JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
//$NON-NLS-1$
Util.verbose("Invalid Class-Path header in manifest of jar file: " + jarPath.toOSString());
}
return null;
} else if (analyzer.getClasspathSectionsCount() > 1) {
if (JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
//$NON-NLS-1$
Util.verbose("Multiple Class-Path headers in manifest of jar file: " + jarPath.toOSString());
}
return null;
}
} catch (CoreException e) {
// not a zip file
if (JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
//$NON-NLS-1$
Util.verbose("Could not read Class-Path header in manifest of jar file: " + jarPath.toOSString());
e.printStackTrace();
}
} catch (IOException e) {
// not a zip file
if (JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
//$NON-NLS-1$
Util.verbose("Could not read Class-Path header in manifest of jar file: " + jarPath.toOSString());
e.printStackTrace();
}
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// best effort
}
}
manager.closeZipFile(zip);
}
return calledFileNames;
}
Aggregations