Example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind

List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind.

Prototype

int getEntryKind();

Source Link

Document

Returns the kind of this classpath entry.

Usage

From source file:com.android.ide.eclipse.adt.internal.wizards.exportgradle.BuildFileCreator.java

License:Open Source License

/**
 * Outputs a sourceSets block to the Android task that locates all of the various source
 * subdirectories in the project./*from  w  w w.j a  v a  2 s .com*/
 */
private void createAndroidSourceSets() {
    IFolderWrapper projectFolder = new IFolderWrapper(mModule.getProject());
    IAbstractFile mManifestFile = AndroidManifest.getManifest(projectFolder);
    if (mManifestFile == null) {
        return;
    }
    List<String> srcDirs = new ArrayList<String>();
    for (IClasspathEntry entry : mModule.getJavaProject().readRawClasspath()) {
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE
                || SdkConstants.FD_GEN_SOURCES.equals(entry.getPath().lastSegment())) {
            continue;
        }
        IPath path = entry.getPath().removeFirstSegments(1);
        srcDirs.add("'" + path.toOSString() + "'"); //$NON-NLS-1$
    }

    String srcPaths = Joiner.on(",").join(srcDirs);

    mBuildFile.append("    sourceSets {\n"); //$NON-NLS-1$
    mBuildFile.append("        main {\n"); //$NON-NLS-1$
    mBuildFile.append("            manifest.srcFile '" + SdkConstants.FN_ANDROID_MANIFEST_XML + "'\n"); //$NON-NLS-1$
    mBuildFile.append("            java.srcDirs = [" + srcPaths + "]\n"); //$NON-NLS-1$
    mBuildFile.append("            resources.srcDirs = [" + srcPaths + "]\n"); //$NON-NLS-1$
    mBuildFile.append("            aidl.srcDirs = [" + srcPaths + "]\n"); //$NON-NLS-1$
    mBuildFile.append("            renderscript.srcDirs = [" + srcPaths + "]\n"); //$NON-NLS-1$
    mBuildFile.append("            res.srcDirs = ['res']\n"); //$NON-NLS-1$
    mBuildFile.append("            assets.srcDirs = ['assets']\n"); //$NON-NLS-1$
    mBuildFile.append("        }\n"); //$NON-NLS-1$
    mBuildFile.append("\n"); //$NON-NLS-1$
    mBuildFile.append("        // Move the tests to tests/java, tests/res, etc...\n"); //$NON-NLS-1$
    mBuildFile.append("        instrumentTest.setRoot('tests')\n"); //$NON-NLS-1$
    if (srcDirs.contains("'src'")) {
        mBuildFile.append("\n"); //$NON-NLS-1$
        mBuildFile.append("        // Move the build types to build-types/<type>\n"); //$NON-NLS-1$
        mBuildFile.append(
                "        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...\n"); //$NON-NLS-1$
        mBuildFile.append(
                "        // This moves them out of them default location under src/<type>/... which would\n"); //$NON-NLS-1$
        mBuildFile.append("        // conflict with src/ being used by the main source set.\n"); //$NON-NLS-1$
        mBuildFile.append("        // Adding new build types or product flavors should be accompanied\n"); //$NON-NLS-1$
        mBuildFile.append("        // by a similar customization.\n"); //$NON-NLS-1$
        mBuildFile.append("        debug.setRoot('build-types/debug')\n"); //$NON-NLS-1$
        mBuildFile.append("        release.setRoot('build-types/release')\n"); //$NON-NLS-1$
    }
    mBuildFile.append("    }\n"); //$NON-NLS-1$
}

From source file:com.android.ide.eclipse.adt.internal.wizards.exportgradle.BuildFileCreator.java

License:Open Source License

/**
 * Outputs a sourceSets block for non-Android projects to locate the source directories.
 *///from w ww  .j a v  a2 s . c  om
private void createJavaSourceSets() {
    List<String> dirs = new ArrayList<String>();
    for (IClasspathEntry entry : mModule.getJavaProject().readRawClasspath()) {
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
            continue;
        }
        IPath path = entry.getPath().removeFirstSegments(1);
        dirs.add("'" + path.toOSString() + "'"); //$NON-NLS-1$
    }

    String srcPaths = Joiner.on(",").join(dirs);

    mBuildFile.append("sourceSets {\n"); //$NON-NLS-1$
    mBuildFile.append("    main.java.srcDirs = [" + srcPaths + "]\n"); //$NON-NLS-1$
    mBuildFile.append("    main.resources.srcDirs = [" + srcPaths + "]\n"); //$NON-NLS-1$
    mBuildFile.append("    test.java.srcDirs = ['tests/java']\n"); //$NON-NLS-1$
    mBuildFile.append("    test.resources.srcDirs = ['tests/resources']\n"); //$NON-NLS-1$
    mBuildFile.append("}\n"); //$NON-NLS-1$
}

From source file:com.android.ide.eclipse.adt.internal.wizards.exportgradle.ProjectSetupBuilder.java

License:Open Source License

@NonNull
private static List<IJavaProject> getReferencedProjects(IJavaProject javaProject)
        throws JavaModelException, InternalException {

    List<IJavaProject> projects = Lists.newArrayList();

    IClasspathEntry entries[] = javaProject.getRawClasspath();
    for (IClasspathEntry classpathEntry : entries) {
        if (classpathEntry.getContentKind() == IPackageFragmentRoot.K_SOURCE
                && classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            // found required project on build path
            String subProjectRoot = classpathEntry.getPath().toString();
            IJavaProject subProject = getJavaProject(subProjectRoot);
            // is project available in workspace?
            if (subProject != null) {
                projects.add(subProject);
            } else {
                throw new InternalException(String.format(
                        "Project '%s' is missing project dependency '%s' in Eclipse workspace.\n"
                                + "Make sure all dependencies are opened.",
                        javaProject.getProject().getName(), classpathEntry.getPath().toString()));
            }/*w  ww  .  j  a va2 s  . c  o m*/
        }
    }

    return projects;
}

From source file:com.android.ide.eclipse.adt.project.ProjectHelper.java

License:Open Source License

/**
 * Fix the project classpath entries. The method ensures that:
 * <ul>/*w w  w . j  a v  a2  s.co  m*/
 * <li>The project does not reference any old android.zip/android.jar archive.</li>
 * <li>The project does not use its output folder as a sourc folder.</li>
 * <li>The project does not reference a desktop JRE</li>
 * <li>The project references the AndroidClasspathContainer.
 * </ul>
 * @param javaProject The project to fix.
 * @throws JavaModelException
 */
public static void fixProjectClasspathEntries(IJavaProject javaProject) throws JavaModelException {

    // get the project classpath
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    IClasspathEntry[] oldEntries = entries;

    // check if the JRE is set as library
    int jreIndex = ProjectHelper.findClasspathEntryByPath(entries, JavaRuntime.JRE_CONTAINER,
            IClasspathEntry.CPE_CONTAINER);
    if (jreIndex != -1) {
        // the project has a JRE included, we remove it
        entries = ProjectHelper.removeEntryFromClasspath(entries, jreIndex);
    }

    // get the output folder
    IPath outputFolder = javaProject.getOutputLocation();

    boolean foundContainer = false;

    for (int i = 0; i < entries.length;) {
        // get the entry and kind
        IClasspathEntry entry = entries[i];
        int kind = entry.getEntryKind();

        if (kind == IClasspathEntry.CPE_SOURCE) {
            IPath path = entry.getPath();

            if (path.equals(outputFolder)) {
                entries = ProjectHelper.removeEntryFromClasspath(entries, i);

                // continue, to skip the i++;
                continue;
            }
        } else if (kind == IClasspathEntry.CPE_CONTAINER) {
            if (AndroidClasspathContainerInitializer.checkPath(entry.getPath())) {
                foundContainer = true;
            }
        }

        i++;
    }

    // if the framework container is not there, we add it
    if (foundContainer == false) {
        // add the android container to the array
        entries = ProjectHelper.addEntryToClasspath(entries,
                AndroidClasspathContainerInitializer.getContainerEntry());
    }

    // set the new list of entries to the project
    if (entries != oldEntries) {
        javaProject.setRawClasspath(entries, new NullProgressMonitor());
    }

    // If needed, check and fix compiler compliance and source compatibility
    ProjectHelper.checkAndFixCompilerCompliance(javaProject);
}

From source file:com.android.ide.eclipse.auidt.internal.build.BuildHelper.java

License:Open Source License

/**
 * Computes all the project output and dependencies that must go into building the apk.
 *
 * @param resMarker/*w  w  w.ja  v  a 2s  .c  o m*/
 * @throws CoreException
 */
private void gatherPaths(ResourceMarker resMarker) throws CoreException {
    IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();

    // get a java project for the project.
    IJavaProject javaProject = JavaCore.create(mProject);

    // get the output of the main project
    IPath path = javaProject.getOutputLocation();
    IResource outputResource = wsRoot.findMember(path);
    if (outputResource != null && outputResource.getType() == IResource.FOLDER) {
        mCompiledCodePaths.add(outputResource.getLocation().toOSString());
    }

    // we could use IJavaProject.getResolvedClasspath directly, but we actually
    // want to see the containers themselves.
    IClasspathEntry[] classpaths = javaProject.readRawClasspath();
    if (classpaths != null) {
        for (IClasspathEntry e : classpaths) {
            // ignore non exported entries, unless it's the LIBRARIES container,
            // in which case we always want it (there may be some older projects that
            // have it as non exported).
            if (e.isExported() || (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                    && e.getPath().toString().equals(AdtConstants.CONTAINER_LIBRARIES))) {
                handleCPE(e, javaProject, wsRoot, resMarker);
            }
        }
    }
}

From source file:com.android.ide.eclipse.auidt.internal.build.BuildHelper.java

License:Open Source License

private void handleCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot,
        ResourceMarker resMarker) {/*from www  . j  ava2  s.c  o m*/

    // if this is a classpath variable reference, we resolve it.
    if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
        entry = JavaCore.getResolvedClasspathEntry(entry);
    }

    if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
        IProject refProject = wsRoot.getProject(entry.getPath().lastSegment());
        try {
            // ignore if it's an Android project, or if it's not a Java Project
            if (refProject.hasNature(JavaCore.NATURE_ID)
                    && refProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) {
                IJavaProject refJavaProject = JavaCore.create(refProject);

                // get the output folder
                IPath path = refJavaProject.getOutputLocation();
                IResource outputResource = wsRoot.findMember(path);
                if (outputResource != null && outputResource.getType() == IResource.FOLDER) {
                    mCompiledCodePaths.add(outputResource.getLocation().toOSString());
                }
            }
        } catch (CoreException exception) {
            // can't query the project nature? ignore
        }

    } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        handleClasspathLibrary(entry, wsRoot, resMarker);
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        // get the container
        try {
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            // ignore the system and default_system types as they represent
            // libraries that are part of the runtime.
            if (container.getKind() == IClasspathContainer.K_APPLICATION) {
                IClasspathEntry[] entries = container.getClasspathEntries();
                for (IClasspathEntry cpe : entries) {
                    handleCPE(cpe, javaProject, wsRoot, resMarker);
                }
            }
        } catch (JavaModelException jme) {
            // can't resolve the container? ignore it.
            AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath());
        }
    }
}

From source file:com.android.ide.eclipse.auidt.internal.lint.EclipseLintClient.java

License:Open Source License

@Override
@NonNull/*from w w w  .j  a v  a  2  s  .com*/
protected ClassPathInfo getClassPath(@NonNull Project project) {
    ClassPathInfo info;
    if (mProjectInfo == null) {
        mProjectInfo = Maps.newHashMap();
        info = null;
    } else {
        info = mProjectInfo.get(project);
    }

    if (info == null) {
        List<File> sources = null;
        List<File> classes = null;
        List<File> libraries = null;

        IProject p = getProject(project);
        if (p != null) {
            try {
                IJavaProject javaProject = BaseProjectHelper.getJavaProject(p);

                // Output path
                File file = workspacePathToFile(javaProject.getOutputLocation());
                classes = Collections.singletonList(file);

                // Source path
                IClasspathEntry[] entries = javaProject.getRawClasspath();
                sources = new ArrayList<File>(entries.length);
                libraries = new ArrayList<File>(entries.length);
                for (int i = 0; i < entries.length; i++) {
                    IClasspathEntry entry = entries[i];
                    int kind = entry.getEntryKind();

                    if (kind == IClasspathEntry.CPE_VARIABLE) {
                        entry = JavaCore.getResolvedClasspathEntry(entry);
                        kind = entry.getEntryKind();
                    }

                    if (kind == IClasspathEntry.CPE_SOURCE) {
                        sources.add(workspacePathToFile(entry.getPath()));
                    } else if (kind == IClasspathEntry.CPE_LIBRARY) {
                        libraries.add(entry.getPath().toFile());
                    }
                    // Note that we ignore IClasspathEntry.CPE_CONTAINER:
                    // Normal Android Eclipse projects supply both
                    //   AdtConstants.CONTAINER_FRAMEWORK
                    // and
                    //   AdtConstants.CONTAINER_LIBRARIES
                    // here. We ignore the framework classes for obvious reasons,
                    // but we also ignore the library container because lint will
                    // process the libraries differently. When Eclipse builds a
                    // project, it gets the .jar output of the library projects
                    // from this container, which means it doesn't have to process
                    // the library sources. Lint on the other hand wants to process
                    // the source code, so instead it actually looks at the
                    // project.properties file to find the libraries, and then it
                    // iterates over all the library projects in turn and analyzes
                    // those separately (but passing the main project for context,
                    // such that the including project's manifest declarations
                    // are used for data like minSdkVersion level).
                    //
                    // Note that this container will also contain *other*
                    // libraries (Java libraries, not library projects) that we
                    // *should* include. However, we can't distinguish these
                    // class path entries from the library project jars,
                    // so instead of looking at these, we simply listFiles() in
                    // the libs/ folder after processing the classpath info
                }

                // Add in libraries
                File libs = new File(project.getDir(), FD_NATIVE_LIBS);
                if (libs.isDirectory()) {
                    File[] jars = libs.listFiles();
                    if (jars != null) {
                        for (File jar : jars) {
                            if (AdtUtils.endsWith(jar.getPath(), DOT_JAR)) {
                                libraries.add(jar);
                            }
                        }
                    }
                }
            } catch (CoreException e) {
                AdtPlugin.log(e, null);
            }
        }

        if (sources == null) {
            sources = super.getClassPath(project).getSourceFolders();
        }
        if (classes == null) {
            classes = super.getClassPath(project).getClassFolders();
        }
        if (libraries == null) {
            libraries = super.getClassPath(project).getLibraries();
        }

        info = new ClassPathInfo(sources, classes, libraries);
        mProjectInfo.put(project, info);
    }

    return info;
}

From source file:com.android.ide.eclipse.auidt.internal.project.AndroidClasspathContainerInitializer.java

License:Open Source License

@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project,
        IClasspathContainer containerSuggestion) throws CoreException {
    AdtPlugin plugin = AdtPlugin.getDefault();

    synchronized (Sdk.getLock()) {
        boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED;

        // check if the project has a valid target.
        IAndroidTarget target = null;/*w w  w .  ja  v  a2 s.c o  m*/
        if (sdkIsLoaded) {
            target = Sdk.getCurrent().getTarget(project.getProject());
        }
        if (sdkIsLoaded && target != null) {
            String[] paths = getTargetPaths(target);
            IPath android_lib = new Path(paths[CACHE_INDEX_JAR]);
            IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();
            for (int i = 0; i < entries.length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    IPath entryPath = entry.getPath();

                    if (entryPath != null) {
                        if (entryPath.equals(android_lib)) {
                            IPath entrySrcPath = entry.getSourceAttachmentPath();

                            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                            if (entrySrcPath != null) {
                                ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target),
                                        entrySrcPath.toString());
                            } else {
                                ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target), null);
                            }
                            IClasspathAttribute[] extraAttributtes = entry.getExtraAttributes();
                            if (extraAttributtes.length == 0) {
                                ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, NULL_API_URL);
                            }
                            for (int j = 0; j < extraAttributtes.length; j++) {
                                IClasspathAttribute extraAttribute = extraAttributtes[j];
                                String value = extraAttribute.getValue();
                                if ((value == null || value.trim().length() == 0)
                                        && IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME
                                                .equals(extraAttribute.getName())) {
                                    value = NULL_API_URL;
                                }
                                if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME
                                        .equals(extraAttribute.getName())) {
                                    ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, value);
                                }
                            }
                        }
                    }
                }
            }
            rebindClasspathEntries(project.getJavaModel(), containerPath);
        }
    }
}

From source file:com.android.ide.eclipse.auidt.internal.project.BaseProjectHelper.java

License:Open Source License

/**
 * returns a list of source classpath for a specified project
 * @param javaProject/* w ww  . ja  v  a  2  s  .c  o  m*/
 * @return a list of path relative to the workspace root.
 */
public static List<IPath> getSourceClasspaths(IJavaProject javaProject) {
    ArrayList<IPath> sourceList = new ArrayList<IPath>();
    IClasspathEntry[] classpaths = javaProject.readRawClasspath();
    if (classpaths != null) {
        for (IClasspathEntry e : classpaths) {
            if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                sourceList.add(e.getPath());
            }
        }
    }
    return sourceList;
}

From source file:com.android.ide.eclipse.auidt.internal.project.LibraryClasspathContainerInitializer.java

License:Open Source License

private static IClasspathContainer allocateLibraryContainer(IJavaProject javaProject) {
    final IProject iProject = javaProject.getProject();

    AdtPlugin plugin = AdtPlugin.getDefault();
    if (plugin == null) { // This is totally weird, but I've seen it happen!
        return null;
    }//from   w  ww .  ja  v a2 s . c om

    // First check that the project has a library-type container.
    try {
        IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
        IClasspathEntry[] oldRawClasspath = rawClasspath;

        boolean foundLibrariesContainer = false;
        for (IClasspathEntry entry : rawClasspath) {
            // get the entry and kind
            int kind = entry.getEntryKind();

            if (kind == IClasspathEntry.CPE_CONTAINER) {
                String path = entry.getPath().toString();
                if (AdtConstants.CONTAINER_LIBRARIES.equals(path)) {
                    foundLibrariesContainer = true;
                    break;
                }
            }
        }

        // if there isn't any, add it.
        if (foundLibrariesContainer == false) {
            // add the android container to the array
            rawClasspath = ProjectHelper.addEntryToClasspath(rawClasspath, JavaCore
                    .newContainerEntry(new Path(AdtConstants.CONTAINER_LIBRARIES), true /*isExported*/));
        }

        // set the new list of entries to the project
        if (rawClasspath != oldRawClasspath) {
            javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor());
        }
    } catch (JavaModelException e) {
        // This really shouldn't happen, but if it does, simply return null (the calling
        // method will fails as well)
        return null;
    }

    // check if the project has a valid target.
    ProjectState state = Sdk.getProjectState(iProject);
    if (state == null) {
        // getProjectState should already have logged an error. Just bail out.
        return null;
    }

    /*
     * At this point we're going to gather a list of all that need to go in the
     * dependency container.
     * - Library project outputs (direct and indirect)
     * - Java project output (those can be indirectly referenced through library projects
     *   or other other Java projects)
     * - Jar files:
     *    + inside this project's libs/
     *    + inside the library projects' libs/
     *    + inside the referenced Java projects' classpath
     */

    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();

    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

    // list of java project dependencies and jar files that will be built while
    // going through the library projects.
    Set<File> jarFiles = new HashSet<File>();
    Set<IProject> refProjects = new HashSet<IProject>();

    // process all the libraries

    List<IProject> libProjects = state.getFullLibraryProjects();
    for (IProject libProject : libProjects) {
        // get the project output
        IFolder outputFolder = BaseProjectHelper.getAndroidOutputFolder(libProject);

        if (outputFolder != null) { // can happen when closing/deleting a library)
            IFile jarIFile = outputFolder.getFile(libProject.getName().toLowerCase() + AdtConstants.DOT_JAR);

            // get the source folder for the library project
            List<IPath> srcs = BaseProjectHelper.getSourceClasspaths(libProject);
            // find the first non-derived source folder.
            IPath sourceFolder = null;
            for (IPath src : srcs) {
                IFolder srcFolder = workspaceRoot.getFolder(src);
                if (srcFolder.isDerived() == false) {
                    sourceFolder = src;
                    break;
                }
            }

            // we can directly add a CPE for this jar as there's no risk of a duplicate.
            IClasspathEntry entry = JavaCore.newLibraryEntry(jarIFile.getLocation(), sourceFolder, // source attachment path
                    null, // default source attachment root path.
                    true /*isExported*/);

            entries.add(entry);

            // process all of the library project's dependencies
            getDependencyListFromClasspath(libProject, refProjects, jarFiles, true);
            // and the content of its libs folder.
            getJarListFromLibsFolder(libProject, jarFiles);
        }
    }

    // now process this projects' referenced projects only.
    processReferencedProjects(iProject, refProjects, jarFiles);
    // and the content of its libs folder
    getJarListFromLibsFolder(iProject, jarFiles);

    // annotations support for older version of android
    if (state.getTarget() != null && state.getTarget().getVersion().getApiLevel() <= 15) {
        File annotationsJar = new File(Sdk.getCurrent().getSdkLocation(), SdkConstants.FD_TOOLS + File.separator
                + SdkConstants.FD_SUPPORT + File.separator + SdkConstants.FN_ANNOTATIONS_JAR);

        jarFiles.add(annotationsJar);
    }

    // now add a classpath entry for each Java project (this is a set so dups are already
    // removed)
    for (IProject p : refProjects) {
        entries.add(JavaCore.newProjectEntry(p.getFullPath(), true /*isExported*/));
    }

    // and process the jar files list, but first sanitize it to remove dups.
    JarListSanitizer sanitizer = new JarListSanitizer(
            iProject.getFolder(SdkConstants.FD_OUTPUT).getLocation().toFile(),
            new AndroidPrintStream(iProject, null /*prefix*/, AdtPlugin.getOutStream()));

    String errorMessage = null;

    try {
        List<File> sanitizedList = sanitizer.sanitize(jarFiles);

        for (File jarFile : sanitizedList) {
            if (jarFile instanceof CPEFile) {
                CPEFile cpeFile = (CPEFile) jarFile;
                IClasspathEntry e = cpeFile.getClasspathEntry();

                entries.add(JavaCore.newLibraryEntry(e.getPath(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), e.getAccessRules(), e.getExtraAttributes(),
                        true /*isExported*/));
            } else {
                String jarPath = jarFile.getAbsolutePath();

                IPath sourceAttachmentPath = null;
                IClasspathAttribute javaDocAttribute = null;

                File jarProperties = new File(jarPath + DOT_PROPERTIES);
                if (jarProperties.isFile()) {
                    Properties p = new Properties();
                    InputStream is = null;
                    try {
                        p.load(is = new FileInputStream(jarProperties));

                        String value = p.getProperty(ATTR_SRC);
                        if (value != null) {
                            File srcPath = getFile(jarFile, value);

                            if (srcPath.exists()) {
                                sourceAttachmentPath = new Path(srcPath.getAbsolutePath());
                            }
                        }

                        value = p.getProperty(ATTR_DOC);
                        if (value != null) {
                            File docPath = getFile(jarFile, value);
                            if (docPath.exists()) {
                                try {
                                    javaDocAttribute = JavaCore.newClasspathAttribute(
                                            IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                                            docPath.toURI().toURL().toString());
                                } catch (MalformedURLException e) {
                                    AdtPlugin.log(e, "Failed to process 'doc' attribute for %s",
                                            jarProperties.getAbsolutePath());
                                }
                            }
                        }

                    } catch (FileNotFoundException e) {
                        // shouldn't happen since we check upfront
                    } catch (IOException e) {
                        AdtPlugin.log(e, "Failed to read %s", jarProperties.getAbsolutePath());
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                                // ignore
                            }
                        }
                    }
                }

                if (javaDocAttribute != null) {
                    entries.add(JavaCore.newLibraryEntry(new Path(jarPath), sourceAttachmentPath,
                            null /*sourceAttachmentRootPath*/, new IAccessRule[0],
                            new IClasspathAttribute[] { javaDocAttribute }, true /*isExported*/));
                } else {
                    entries.add(JavaCore.newLibraryEntry(new Path(jarPath), sourceAttachmentPath,
                            null /*sourceAttachmentRootPath*/, true /*isExported*/));
                }
            }
        }
    } catch (DifferentLibException e) {
        errorMessage = e.getMessage();
        AdtPlugin.printErrorToConsole(iProject, (Object[]) e.getDetails());
    } catch (Sha1Exception e) {
        errorMessage = e.getMessage();
    }

    processError(iProject, errorMessage, AdtConstants.MARKER_DEPENDENCY, true /*outputToConsole*/);

    return new AndroidClasspathContainer(entries.toArray(new IClasspathEntry[entries.size()]),
            new Path(AdtConstants.CONTAINER_LIBRARIES), "Android Dependencies",
            IClasspathContainer.K_APPLICATION);
}