Example usage for org.eclipse.jdt.internal.compiler.util ManifestAnalyzer getCalledFileNames

List of usage examples for org.eclipse.jdt.internal.compiler.util ManifestAnalyzer getCalledFileNames

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.util ManifestAnalyzer getCalledFileNames.

Prototype

public List getCalledFileNames() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java

License:Open Source License

private static List getCalledFileNames(IPath jarPath) {
    Object target = JavaModel.getTarget(jarPath,
            true/*check existence, otherwise the manifest cannot be read*/);
    if (!(target instanceof IFile || target instanceof File))
        return null;
    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    ZipFile zip = null;//from  w ww. java 2  s .  c  om
    InputStream inputStream = null;
    List calledFileNames = null;
    try {
        zip = manager.getZipFile(jarPath);
        ZipEntry manifest = zip.getEntry("META-INF/MANIFEST.MF"); //$NON-NLS-1$
        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) {
                Util.verbose("Invalid Class-Path header in manifest of jar file: " + jarPath.toOSString()); //$NON-NLS-1$
            }
            return null;
        } else if (analyzer.getClasspathSectionsCount() > 1) {
            if (JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
                Util.verbose("Multiple Class-Path headers in manifest of jar file: " + jarPath.toOSString()); //$NON-NLS-1$
            }
            return null;
        }
    } catch (CoreException e) {
        // not a zip file
        if (JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
            Util.verbose("Could not read Class-Path header in manifest of jar file: " + jarPath.toOSString()); //$NON-NLS-1$
            e.printStackTrace();
        }
    } catch (IOException e) {
        // not a zip file
        if (JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
            Util.verbose("Could not read Class-Path header in manifest of jar file: " + jarPath.toOSString()); //$NON-NLS-1$
            e.printStackTrace();
        }
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                // best effort
            }
        }
        manager.closeZipFile(zip);
    }
    return calledFileNames;
}