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

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

Introduction

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

Prototype

int CPE_LIBRARY

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a library.

Usage

From source file:com.android.ide.eclipse.adt.internal.build.PostCompilerHelper.java

License:Open Source License

/**
 * Returns an array of external jar files used by the project.
 * @return an array of OS-specific absolute file paths
 *//*from w w  w. j  a va  2 s  .  co m*/
private final String[] getExternalJars() {
    // get a java project from it
    IJavaProject javaProject = JavaCore.create(mProject);

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

    ArrayList<String> oslibraryList = new ArrayList<String>();
    IClasspathEntry[] classpaths = javaProject.readRawClasspath();
    if (classpaths != null) {
        for (IClasspathEntry e : classpaths) {
            if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                    || e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                // if this is a classpath variable reference, we resolve it.
                if (e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                    e = JavaCore.getResolvedClasspathEntry(e);
                }

                // get the IPath
                IPath path = e.getPath();

                // check the name ends with .jar
                if (AndroidConstants.EXT_JAR.equalsIgnoreCase(path.getFileExtension())) {
                    IResource resource = wsRoot.findMember(path);
                    if (resource != null && resource.exists() && resource.getType() == IResource.FILE) {
                        oslibraryList.add(resource.getLocation().toOSString());
                    } else {
                        // if the jar path doesn't match a workspace resource,
                        // then we get an OSString and check if this links to a valid file.
                        String osFullPath = path.toOSString();

                        File f = new File(osFullPath);
                        if (f.exists()) {
                            oslibraryList.add(osFullPath);
                        } else {
                            String message = String.format(Messages.Couldnt_Locate_s_Error, path);
                            AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, mProject, message);

                            // Also put a warning marker on the project
                            BaseProjectHelper.markResource(mProject, AndroidConstants.MARKER_PACKAGING, message,
                                    IMarker.SEVERITY_WARNING);
                        }
                    }
                }
            }
        }
    }

    return oslibraryList.toArray(new String[oslibraryList.size()]);
}

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

License:Open Source License

@Override
@NonNull/*  w w w  .  java 2  s.c  o m*/
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);
                        if (entry == null) {
                            // It's possible that the variable is no longer valid; ignore
                            continue;
                        }
                        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 (SdkUtils.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();
        }

        // No test folders in Eclipse:
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=224708
        List<File> tests = Collections.emptyList();

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

    return info;
}

From source file:com.android.ide.eclipse.adt.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;//from w w  w  .java  2  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.adt.internal.project.LibraryClasspathContainerInitializer.java

License:Open Source License

/**
 * Processes a {@link IClasspathEntry} and add it to one of the list if applicable.
 * @param entry the entry to process//from  w  ww .  j a v a  2 s  .  co m
 * @param javaProject the {@link IJavaProject} from which this entry came.
 * @param wsRoot the {@link IWorkspaceRoot}
 * @param projects the project list to add to
 * @param jarFiles the jar list to add to
 * @param includeJarFiles whether to include jar files or just projects. This is useful when
 *           calling on an Android project (value should be <code>false</code>)
 */
private static void processCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot,
        Set<IProject> projects, Set<File> jarFiles, boolean includeJarFiles) {

    // 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) {
                // add this project to the list
                projects.add(refProject);

                // also get the dependency from this project.
                getDependencyListFromClasspath(refProject, projects, jarFiles, true /*includeJarFiles*/);
            }
        } catch (CoreException exception) {
            // can't query the project nature? ignore
        }
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        if (includeJarFiles) {
            handleClasspathLibrary(entry, wsRoot, jarFiles);
        }
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        // get the container and its content
        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 != null && container.getKind() == IClasspathContainer.K_APPLICATION) {
                IClasspathEntry[] entries = container.getClasspathEntries();
                for (IClasspathEntry cpe : entries) {
                    processCPE(cpe, javaProject, wsRoot, projects, jarFiles, includeJarFiles);
                }
            }
        } 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.adt.internal.resources.manager.ProjectClassLoader.java

License:Open Source License

/**
 * Returns an array of external jar files used by the project.
 * @return an array of OS-specific absolute file paths
 *//*from ww w .  j  a v a  2  s  .com*/
private final URL[] getExternalJars() {
    // get a java project from it
    IJavaProject javaProject = JavaCore.create(mJavaProject.getProject());

    ArrayList<URL> oslibraryList = new ArrayList<URL>();
    IClasspathEntry[] classpaths = javaProject.readRawClasspath();
    if (classpaths != null) {
        for (IClasspathEntry e : classpaths) {
            if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                    || e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                // if this is a classpath variable reference, we resolve it.
                if (e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                    e = JavaCore.getResolvedClasspathEntry(e);
                }

                handleClassPathEntry(e, oslibraryList);
            } else if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                // get the container.
                try {
                    IClasspathContainer container = JavaCore.getClasspathContainer(e.getPath(), javaProject);
                    // ignore the system and default_system types as they represent
                    // libraries that are part of the runtime.
                    if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) {
                        IClasspathEntry[] entries = container.getClasspathEntries();
                        for (IClasspathEntry entry : entries) {
                            // TODO: Xav -- is this necessary?
                            if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                                entry = JavaCore.getResolvedClasspathEntry(entry);
                            }

                            handleClassPathEntry(entry, oslibraryList);
                        }
                    }
                } catch (JavaModelException jme) {
                    // can't resolve the container? ignore it.
                    AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", e.getPath());
                }
            }
        }
    }

    return oslibraryList.toArray(new URL[oslibraryList.size()]);
}

From source file:com.android.ide.eclipse.adt.internal.sourcelookup.AdtSourceLookupDirector.java

License:Open Source License

@Override
public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
    dispose();/*from   ww w .  j  a  va 2 s  .  com*/
    setLaunchConfiguration(configuration);
    String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
    if (projectName != null && projectName.length() > 0) {
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        if (project != null && project.isOpen()) {
            ProjectState state = Sdk.getProjectState(project);
            if (state == null) {
                initDefaults();
                return;
            }
            IAndroidTarget target = state.getTarget();
            if (target == null) {
                initDefaults();
                return;
            }
            String path = target.getPath(IAndroidTarget.ANDROID_JAR);
            if (path == null) {
                initDefaults();
                return;
            }
            IJavaProject javaProject = JavaCore.create(project);
            if (javaProject != null && javaProject.isOpen()) {
                IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
                IClasspathEntry androidEntry = null;
                for (int i = 0; i < entries.length; i++) {
                    IClasspathEntry entry = entries[i];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                            && path.equals(entry.getPath().toString())) {
                        androidEntry = entry;
                        break;
                    }
                }
                if (androidEntry != null) {
                    IPath sourceAttachmentPath = androidEntry.getSourceAttachmentPath();
                    if (sourceAttachmentPath != null) {
                        String androidSrc = sourceAttachmentPath.toString();
                        if (androidSrc != null && androidSrc.trim().length() > 0) {
                            File srcFile = new File(androidSrc);
                            ISourceContainer adtContainer = null;
                            if (srcFile.isFile()) {
                                adtContainer = new ExternalArchiveSourceContainer(androidSrc, true);
                            }
                            if (srcFile.isDirectory()) {
                                adtContainer = new DirectorySourceContainer(srcFile, false);
                            }
                            if (adtContainer != null) {
                                ISourceContainer defaultContainer = new DefaultSourceContainer();
                                setSourceContainers(new ISourceContainer[] { adtContainer, defaultContainer });
                                initializeParticipants();
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    initDefaults();
}

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 w w w  .j a  v a  2s.  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  ww .ja va2 s .co  m*/
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;//from w w  w  .j av a 2 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.sourcelookup.AdtSourceLookupDirector.java

License:Open Source License

@Override
public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException {
    dispose();/*from   ww  w  . j  ava2 s .co  m*/
    setLaunchConfiguration(configuration);
    String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$
    if (projectName != null && projectName.length() > 0) {
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        if (project != null && project.isOpen()) {
            ProjectState state = Sdk.getProjectState(project);
            if (state == null) {
                initDefaults();
                return;
            }
            IAndroidTarget target = state.getTarget();
            if (target == null) {
                initDefaults();
                return;
            }
            //                String path = target.getPath(IAndroidTarget.ANDROID_JAR);
            String path = AdtPlugin.getAuidtJar();

            if (path == null) {
                initDefaults();
                return;
            }
            IJavaProject javaProject = JavaCore.create(project);
            if (javaProject != null && javaProject.isOpen()) {
                IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
                IClasspathEntry androidEntry = null;
                for (int i = 0; i < entries.length; i++) {
                    IClasspathEntry entry = entries[i];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                            && path.equals(entry.getPath().toString())) {
                        androidEntry = entry;
                        break;
                    }
                }
                if (androidEntry != null) {
                    IPath sourceAttachmentPath = androidEntry.getSourceAttachmentPath();
                    if (sourceAttachmentPath != null) {
                        String androidSrc = sourceAttachmentPath.toString();
                        if (androidSrc != null && androidSrc.trim().length() > 0) {
                            File srcFile = new File(androidSrc);
                            ISourceContainer adtContainer = null;
                            if (srcFile.isFile()) {
                                adtContainer = new ExternalArchiveSourceContainer(androidSrc, true);
                            }
                            if (srcFile.isDirectory()) {
                                adtContainer = new DirectorySourceContainer(srcFile, false);
                            }
                            if (adtContainer != null) {
                                ISourceContainer defaultContainer = new DefaultSourceContainer();
                                setSourceContainers(new ISourceContainer[] { adtContainer, defaultContainer });
                                initializeParticipants();
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    initDefaults();
}