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:org.eclipse.m2e.tests.jdt.internal.ClasspathEntryDescriptorTest.java

License:Open Source License

@Test
public void testArtifactKeyDeserialization() throws Exception {
    final ArtifactKey key = new ArtifactKey("g", "a", "v", "c");

    ClasspathEntryDescriptor original = new ClasspathEntryDescriptor(IClasspathEntry.CPE_LIBRARY,
            new Path("/path"));
    original.setArtifactKey(key);/*from   w w  w .  j  a  va2s  . c  o m*/

    ClasspathEntryDescriptor deserelized = new ClasspathEntryDescriptor(original.toClasspathEntry());

    Assert.assertEquals(key, deserelized.getArtifactKey());
}

From source file:org.eclipse.m2e.tests.jdt.internal.MavenClasspathContainerSaveHelperTest.java

License:Open Source License

public void testClasspathContainerSace() throws Exception {
    IClasspathEntry[] entries = new IClasspathEntry[2];

    {//from  w w w. j a va2s  . c om
        IAccessRule[] accessRules = new IAccessRule[1];
        accessRules[0] = JavaCore.newAccessRule(new Path("aa/**"), IAccessRule.K_ACCESSIBLE);

        IClasspathAttribute[] attributes = new IClasspathAttribute[2];
        attributes[0] = JavaCore.newClasspathAttribute("foo", "11");
        attributes[1] = JavaCore.newClasspathAttribute("moo", "22");

        entries[0] = JavaCore.newProjectEntry(new Path("/foo"), accessRules, true, attributes, false);
    }

    {
        IAccessRule[] accessRules = new IAccessRule[1];
        accessRules[0] = JavaCore.newAccessRule(new Path("bb/**"), IAccessRule.K_DISCOURAGED);

        IClasspathAttribute[] attributes = new IClasspathAttribute[1];
        attributes[0] = JavaCore.newClasspathAttribute("foo", "aa");

        entries[1] = JavaCore.newLibraryEntry(new Path("/foo/moo.jar"), new Path("/foo/moo-sources.jar"),
                new Path("/foo/moo-javadoc.jar"), accessRules, attributes, false);
    }

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    helper.writeContainer(new MavenClasspathContainer(new Path(IClasspathManager.CONTAINER_ID), entries), os);
    os.close();

    IClasspathContainer container = helper.readContainer(new ByteArrayInputStream(os.toByteArray()));

    assertEquals(IClasspathManager.CONTAINER_ID, container.getPath().toString());

    IClasspathEntry[] classpathEntries = container.getClasspathEntries();
    assertEquals(2, classpathEntries.length);

    {
        IClasspathEntry entry = classpathEntries[0];
        assertEquals(IClasspathEntry.CPE_PROJECT, entry.getEntryKind());
        assertEquals("/foo", entry.getPath().toString());
        assertEquals(false, entry.isExported());
        assertEquals(true, entry.combineAccessRules());

        IAccessRule[] accessRules = entry.getAccessRules();
        assertEquals(1, accessRules.length);
        assertEquals(IAccessRule.K_ACCESSIBLE, accessRules[0].getKind());
        assertEquals("aa/**", accessRules[0].getPattern().toString());

        IClasspathAttribute[] attributes = entry.getExtraAttributes();
        assertEquals(2, attributes.length);
        assertEquals("foo", attributes[0].getName());
        assertEquals("11", attributes[0].getValue());
        assertEquals("moo", attributes[1].getName());
        assertEquals("22", attributes[1].getValue());
    }

    {
        IClasspathEntry entry = classpathEntries[1];
        assertEquals(IClasspathEntry.CPE_LIBRARY, entry.getEntryKind());
        assertEquals("/foo/moo.jar", entry.getPath().toString());
        assertEquals(false, entry.isExported());

        IAccessRule[] accessRules = entry.getAccessRules();
        assertEquals(1, accessRules.length);
        assertEquals(IAccessRule.K_DISCOURAGED, accessRules[0].getKind());
        assertEquals("bb/**", accessRules[0].getPattern().toString());

        IClasspathAttribute[] attributes = entry.getExtraAttributes();
        assertEquals(1, attributes.length);
        assertEquals("foo", attributes[0].getName());
        assertEquals("aa", attributes[0].getValue());
    }
}

From source file:org.eclipse.osee.framework.ui.ws.AJavaProject.java

License:Open Source License

public static ArrayList<File> getJavaProjectProjectDependancies(IJavaProject javaProject) {
    ArrayList<File> urls = new ArrayList<File>();
    try {//from  ww  w.  j a v  a2 s  .com
        IClasspathEntry[] paths = localGetResolvedClasspath(javaProject);
        for (int i = 0; i < paths.length; i++) {
            if (paths[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                if (paths[i].getPath().toFile().exists()) {
                    //          urls.add(paths[i].getPath().toFile());
                } else {
                    File file = null;
                    file = new File(AWorkspace.getWorkspacePath().concat(paths[i].getPath().toOSString()));
                    if (file.exists()) {
                        urls.add(file);
                    }
                }
            } else if (paths[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                urls.add(new File(AWorkspace.getWorkspacePath().concat(paths[i].getPath().toFile().getPath()
                        .concat(File.separator + "bin" + File.separator))));
            } else if (paths[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                File projectlocation = javaProject.getProject().getLocation().toFile();
                File projecttricky = javaProject.getProject().getFullPath().toFile();
                IPath output = paths[i].getOutputLocation();
                File fileLocation;
                if (output == null) {
                    fileLocation = new File(paths[i].getPath().toFile().getPath().replace("src", "bin"));
                } else {
                    fileLocation = paths[i].getOutputLocation().toFile();
                }
                String realLocation = fileLocation.toString().replace(projecttricky.toString(),
                        projectlocation.toString());
                urls.add(new File(realLocation));
            }
        }

    } catch (JavaModelException ex) {
        ex.printStackTrace();
    }
    return urls;
}

From source file:org.eclipse.pde.api.tools.internal.builder.ApiAnalysisBuilder.java

License:Open Source License

/**
 * Returns the complete listing of required projects from the classpath of
 * the backing project/*from w  ww .j  a v a 2  s.c om*/
 * 
 * @param includeBinaryPrerequisites
 * @return the list of projects required
 * @throws CoreException
 */
IProject[] getRequiredProjects(boolean includebinaries) throws CoreException {
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    if (this.currentproject == null || workspaceRoot == null) {
        return new IProject[0];
    }
    ArrayList<IProject> projects = new ArrayList<IProject>();
    try {
        IJavaProject javaProject = JavaCore.create(this.currentproject);
        HashSet<IPath> blocations = new HashSet<IPath>();
        blocations.add(javaProject.getOutputLocation());
        this.output_locs.put(this.currentproject, blocations);
        HashSet<IPath> slocations = new HashSet<IPath>();
        IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
        for (int i = 0; i < roots.length; i++) {
            if (roots[i].isArchive()) {
                continue;
            }
            slocations.add(roots[i].getPath());
        }
        this.src_locs.put(this.currentproject, slocations);
        IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
        for (int i = 0, l = entries.length; i < l; i++) {
            IClasspathEntry entry = entries[i];
            IPath path = entry.getPath();
            IProject p = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT: {
                p = workspaceRoot.getProject(path.lastSegment()); // missing
                // projects
                // are
                // considered
                // too
                if (isOptional(entry) && !p.hasNature(ApiPlugin.NATURE_ID)) {// except
                    // if
                    // entry
                    // is
                    // optional
                    p = null;
                }
                break;
            }
            case IClasspathEntry.CPE_LIBRARY: {
                if (includebinaries && path.segmentCount() > 1) {
                    // some binary resources on the class path can come
                    // from projects that are not included in the
                    // project references
                    IResource resource = workspaceRoot.findMember(path.segment(0));
                    if (resource instanceof IProject) {
                        p = (IProject) resource;
                    }
                }
                break;
            }
            case IClasspathEntry.CPE_SOURCE: {
                IPath entrypath = entry.getOutputLocation();
                if (entrypath != null) {
                    blocations.add(entrypath);
                }
                break;
            }
            default: {
                break;
            }
            }
            if (p != null && !projects.contains(p)) {
                projects.add(p);
                // try to derive all of the output locations for each of the
                // projects
                javaProject = JavaCore.create(p);
                HashSet<IPath> bins = new HashSet<IPath>();
                HashSet<IPath> srcs = new HashSet<IPath>();
                if (javaProject.exists()) {
                    bins.add(javaProject.getOutputLocation());
                    IClasspathEntry[] source = javaProject.getRawClasspath();
                    IPath entrypath = null;
                    for (int j = 0; j < source.length; j++) {
                        if (source[j].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                            srcs.add(source[j].getPath());
                            entrypath = source[j].getOutputLocation();
                            if (entrypath != null) {
                                bins.add(entrypath);
                            }
                        }
                    }
                    this.output_locs.put(p, bins);
                    this.src_locs.put(p, srcs);
                }
            }
        }
    } catch (JavaModelException e) {
        return new IProject[0];
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:org.eclipse.pde.api.tools.internal.model.ProjectComponent.java

License:Open Source License

@Override
protected synchronized List<IApiTypeContainer> createApiTypeContainers() throws CoreException {
    // first populate build.properties cache so we can create class file
    // containers
    // from bundle classpath entries
    fPathToOutputContainers = new HashMap<String, IApiTypeContainer>(4);
    fOutputLocationToContainer = new HashMap<IPath, IApiTypeContainer>(4);
    if (fProject.exists() && fProject.getProject().isOpen()) {
        IPluginModelBase model = PluginRegistry.findModel(fProject.getProject());
        if (model != null) {
            IBuildModel buildModel = PluginRegistry.createBuildModel(model);
            if (buildModel != null) {
                IBuild build = buildModel.getBuild();
                IBuildEntry entry = build.getEntry(ENTRY_CUSTOM);
                if (entry != null) {
                    String[] tokens = entry.getTokens();
                    if (tokens.length == 1 && tokens[0].equals("true")) { //$NON-NLS-1$
                        // hack : add the current output location for each
                        // classpath entries
                        IClasspathEntry[] classpathEntries = fProject.getRawClasspath();
                        List<IApiTypeContainer> containers = new ArrayList<IApiTypeContainer>();
                        for (int i = 0; i < classpathEntries.length; i++) {
                            IClasspathEntry classpathEntry = classpathEntries[i];
                            switch (classpathEntry.getEntryKind()) {
                            case IClasspathEntry.CPE_SOURCE:
                                String containerPath = classpathEntry.getPath().removeFirstSegments(1)
                                        .toString();
                                IApiTypeContainer container = getApiTypeContainer(containerPath, this);
                                if (container != null && !containers.contains(container)) {
                                    containers.add(container);
                                }/*from w  w w.  ja v  a  2  s  .c o m*/
                                break;
                            case IClasspathEntry.CPE_VARIABLE:
                                classpathEntry = JavaCore.getResolvedClasspathEntry(classpathEntry);
                                //$FALL-THROUGH$
                            case IClasspathEntry.CPE_LIBRARY:
                                IPath path = classpathEntry.getPath();
                                if (Util.isArchive(path.lastSegment())) {
                                    IResource resource = ResourcesPlugin.getWorkspace().getRoot()
                                            .findMember(path);
                                    if (resource != null) {
                                        // jar inside the workspace
                                        containers.add(new ArchiveApiTypeContainer(this,
                                                resource.getLocation().toOSString()));
                                    } else {
                                        // external jar
                                        containers.add(new ArchiveApiTypeContainer(this, path.toOSString()));
                                    }
                                }
                                break;
                            default:
                                break;
                            }
                        }
                        if (!containers.isEmpty()) {
                            IApiTypeContainer cfc = null;
                            if (containers.size() == 1) {
                                cfc = containers.get(0);
                            } else {
                                cfc = new CompositeApiTypeContainer(this, containers);
                            }
                            fPathToOutputContainers.put(".", cfc); //$NON-NLS-1$
                        }
                    }
                } else {
                    IBuildEntry[] entries = build.getBuildEntries();
                    int length = entries.length;
                    for (int i = 0; i < length; i++) {
                        IBuildEntry buildEntry = entries[i];
                        String name = buildEntry.getName();
                        if (name.startsWith(IBuildEntry.JAR_PREFIX)) {
                            retrieveContainers(name, IBuildEntry.JAR_PREFIX, buildEntry);
                        } else if (name.startsWith(EXTRA_PREFIX)) {
                            retrieveContainers(name, EXTRA_PREFIX, buildEntry);
                        }
                    }
                }
            }
        }
        return super.createApiTypeContainers();
    }
    return Collections.EMPTY_LIST;
}

From source file:org.eclipse.pde.api.tools.internal.ProjectApiDescription.java

License:Open Source License

@Override
protected ManifestNode createNode(ManifestNode parentNode, IElementDescriptor element) {
    switch (element.getElementType()) {
    case IElementDescriptor.PACKAGE:
        try {/*  w w w  . j a va 2 s. c o  m*/
            IPackageDescriptor pkg = (IPackageDescriptor) element;
            IPackageFragmentRoot[] roots = getJavaProject().getPackageFragmentRoots();
            List<IPackageFragment> fragments = new ArrayList<IPackageFragment>(1);
            for (int i = 0; i < roots.length; i++) {
                IPackageFragmentRoot root = roots[i];
                IClasspathEntry entry = root.getRawClasspathEntry();
                switch (entry.getEntryKind()) {
                case IClasspathEntry.CPE_SOURCE:
                case IClasspathEntry.CPE_LIBRARY:
                    IPackageFragment fragment = root.getPackageFragment(pkg.getName());
                    if (fragment.exists()) {
                        fragments.add(fragment);
                    }
                    break;
                default:
                    if (!root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) {
                        // class file folder
                        fragment = root.getPackageFragment(pkg.getName());
                        if (fragment.exists()) {
                            fragments.add(fragment);
                        }
                    }
                }
            }
            if (fragments.isEmpty()) {
                return null;
            } else {
                return newPackageNode(fragments.toArray(new IPackageFragment[fragments.size()]), parentNode,
                        element, VisibilityModifiers.PRIVATE, RestrictionModifiers.NO_RESTRICTIONS);
            }

        } catch (CoreException e) {
            return null;
        }
    case IElementDescriptor.TYPE:
        IReferenceTypeDescriptor descriptor = (IReferenceTypeDescriptor) element;
        try {
            IType type = null;
            String name = descriptor.getName();
            if (parentNode instanceof PackageNode) {
                IPackageFragment[] fragments = ((PackageNode) parentNode).fFragments;
                for (int i = 0; i < fragments.length; i++) {
                    IPackageFragment fragment = fragments[i];
                    if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) {
                        ICompilationUnit unit = fragment.getCompilationUnit(name + ".java"); //$NON-NLS-1$
                        try {
                            IResource resource = unit.getUnderlyingResource();
                            if (resource != null) {
                                type = unit.getType(name);
                            }
                        } catch (JavaModelException jme) {
                            // exception if the resource does not exist
                            if (!jme.getJavaModelStatus().isDoesNotExist()) {
                                throw jme;
                            }
                        }
                    } else {
                        IClassFile file = fragment.getClassFile(name + ".class"); //$NON-NLS-1$
                        if (file.exists()) {
                            type = file.getType();
                        }
                    }
                }
            } else if (parentNode instanceof TypeNode) {
                type = ((TypeNode) parentNode).fType.getType(name);
            }
            if (type != null) {
                return newTypeNode(type, parentNode, element, VISIBILITY_INHERITED,
                        RestrictionModifiers.NO_RESTRICTIONS);
            }
        } catch (CoreException e) {
            return null;
        }
        return null;
    default:
        break;
    }
    return super.createNode(parentNode, element);
}

From source file:org.eclipse.pde.internal.core.builders.SourceEntryErrorReporter.java

License:Open Source License

public void initialize(ArrayList<?> sourceEntries, ArrayList<?> outputEntries, IClasspathEntry[] cpes,
        IProject project) {//ww w .  j  a  v a 2s.  c  o m

    fProject = project;
    IPath defaultOutputLocation = null;
    IJavaProject javaProject = JavaCore.create(fProject);
    try {
        defaultOutputLocation = javaProject.getOutputLocation();
    } catch (JavaModelException e) {
    }

    List<String> pluginLibraryNames = new ArrayList<String>(1);
    IPluginModelBase pluginModel = PluginRegistry.findModel(fProject);
    if (pluginModel != null) {
        IPluginLibrary[] pluginLibraries = pluginModel.getPluginBase().getLibraries();
        for (int i = 0; i < pluginLibraries.length; i++) {
            pluginLibraryNames.add(pluginLibraries[i].getName());
        }
    }
    if (!pluginLibraryNames.contains(".")) { //$NON-NLS-1$
        pluginLibraryNames.add("."); //$NON-NLS-1$)
    }
    for (int i = 0; i < cpes.length; i++) {
        if (cpes[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath sourcePath = getPath(cpes[i]);
            if (sourcePath == null)
                continue;

            IPath outputLocation = cpes[i].getOutputLocation();
            if (outputLocation == null)
                outputLocation = defaultOutputLocation;
            IPath outputPath = getPath(outputLocation);

            OutputFolder outputFolder = fOutputFolderMap.get(outputPath);
            if (outputFolder == null) {
                outputFolder = new OutputFolder(outputPath);
            }

            SourceFolder sourceFolder = fSourceFolderMap.get(sourcePath);
            if (sourceFolder == null) {
                sourceFolder = new SourceFolder(sourcePath, outputFolder);
            }

            outputFolder.addSourceFolder(sourceFolder);
            fOutputFolderMap.put(outputPath, outputFolder);
            fSourceFolderMap.put(sourcePath, sourceFolder);
        } else if (cpes[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IClasspathEntry entry = cpes[i];
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            IPath outputPath = null;
            if (roots.length == 1) { // should only be one entry for a library
                if (!roots[0].isArchive()) {
                    outputPath = getPath(entry);
                    OutputFolder outputFolder = new OutputFolder(outputPath, true);
                    fOutputFolderMap.put(outputPath, outputFolder);
                }
            }
        }
    }

    for (Iterator<?> iterator = sourceEntries.iterator(); iterator.hasNext();) {
        IBuildEntry sourceEntry = (IBuildEntry) iterator.next();
        String libName = sourceEntry.getName().substring(PROPERTY_SOURCE_PREFIX.length());
        if (!pluginLibraryNames.contains(libName)) {
            prepareError(sourceEntry.getName(), null,
                    NLS.bind(PDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName),
                    PDEMarkerFactory.B_REMOVAL, fSrcLibSeverity, PDEMarkerFactory.CAT_OTHER);
        }
        String[] tokens = sourceEntry.getTokens();
        for (int i = 0; i < tokens.length; i++) {
            IPath path = new Path(tokens[i]).addTrailingSeparator();
            SourceFolder sourceFolder = fSourceFolderMap.get(path);
            if (sourceFolder == null) {
                sourceFolder = new SourceFolder(path, null);
                fSourceFolderMap.put(path, sourceFolder);
            }
            sourceFolder.setToken(tokens[i]);
            sourceFolder.addLib(libName);
        }
    }

    for (Iterator<?> iterator = outputEntries.iterator(); iterator.hasNext();) {
        IBuildEntry outputEntry = (IBuildEntry) iterator.next();
        String libName = outputEntry.getName().substring(PROPERTY_OUTPUT_PREFIX.length());
        if (!pluginLibraryNames.contains(libName)) {
            prepareError(outputEntry.getName(), null,
                    NLS.bind(PDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName),
                    PDEMarkerFactory.B_REMOVAL, fOututLibSeverity, PDEMarkerFactory.CAT_OTHER);
        }
        String[] tokens = outputEntry.getTokens();
        for (int i = 0; i < tokens.length; i++) {
            IPath path = new Path(tokens[i]).addTrailingSeparator();
            if (path.segmentCount() == 1 && path.segment(0).equals(".")) { //$NON-NLS-1$
                // translate "." to root path
                path = Path.ROOT;
            }
            OutputFolder outputFolder = fOutputFolderMap.get(path);
            if (outputFolder == null) {
                outputFolder = new OutputFolder(path);
                fOutputFolderMap.put(path, outputFolder);
            }
            outputFolder.setToken(tokens[i]);
            outputFolder.addLib(libName);
        }
    }
}

From source file:org.eclipse.pde.internal.core.ClasspathHelper.java

License:Open Source License

private static Map<IPath, ArrayList<IPath>> getClasspathMap(IProject project, boolean checkExcluded,
        boolean absolutePaths) throws JavaModelException {
    List<Path> excluded = getFoldersToExclude(project, checkExcluded);
    IJavaProject jProject = JavaCore.create(project);
    HashMap<IPath, ArrayList<IPath>> map = new HashMap<IPath, ArrayList<IPath>>();
    IClasspathEntry[] entries = jProject.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
        // most of the paths we get will be project relative, so we need to make the paths relative
        // we will have problems adding an "absolute" path that is workspace relative
        IPath output = null, source = null;
        if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            source = entries[i].getPath();
            output = entries[i].getOutputLocation();
            if (output == null)
                output = jProject.getOutputLocation();
        } else if (entries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            source = entries[i].getPath();
            output = entries[i].getPath();
            if (source.segmentCount() == 1)
                source = new Path(DOT);
        }//from  w w w  .  ja v  a2 s. c o  m
        if (output != null && !excluded.contains(output)) {
            IResource file = project.findMember(output.removeFirstSegments(1));
            // make the path either relative or absolute
            if (file != null) {
                boolean isLinked = file.isLinked(IResource.CHECK_ANCESTORS);
                if (isLinked || absolutePaths) {
                    IPath location = file.getLocation();
                    if (location != null) {
                        output = location.makeAbsolute();
                    } else {
                        PDECore.log(new Status(IStatus.ERROR, PDECore.PLUGIN_ID,
                                NLS.bind(PDECoreMessages.ClasspathHelper_BadFileLocation, file.getFullPath())));
                        continue;
                    }
                } else {
                    output = output.makeRelative();
                }
            } else
                continue;
            ArrayList<IPath> list = map.get(source);
            if (list == null)
                list = new ArrayList<IPath>();
            list.add(output);
            map.put(source, list);
        }
    }

    // Add additional entries from contributed bundle classpath resolvers
    IBundleClasspathResolver[] resolvers = PDECore.getDefault().getClasspathContainerResolverManager()
            .getBundleClasspathResolvers(project);
    for (int i = 0; i < resolvers.length; i++) {
        Map<IPath, Collection<IPath>> resolved = resolvers[i].getAdditionalClasspathEntries(jProject);
        Iterator<Entry<IPath, Collection<IPath>>> resolvedIter = resolved.entrySet().iterator();
        while (resolvedIter.hasNext()) {
            Map.Entry<IPath, Collection<IPath>> resolvedEntry = resolvedIter.next();
            IPath ceSource = resolvedEntry.getKey();
            ArrayList<IPath> list = map.get(ceSource);
            if (list == null) {
                list = new ArrayList<IPath>();
                map.put(ceSource, list);
            }
            list.addAll(resolvedEntry.getValue());
        }
    }

    return map;
}

From source file:org.eclipse.pde.internal.launching.launcher.LaunchArgumentsHelper.java

License:Open Source License

/**
 * Returns the path to the equinox launcher jar.  If the launcher is available
 * in the workspace, the packageName will be used to determine the expected output
 * location.//from w  ww .  j a v a2s.  c o  m
 * 
 * @param packageName name of the launcher package, typically {@link IPDEBuildConstants#BUNDLE_EQUINOX_LAUNCHER}
 * @return the path to the equinox launcher jar or <code>null</code> 
 * @throws CoreException
 */
private static String getEquinoxStartupPath(String packageName) throws CoreException {
    // See if PDE has the launcher in the workspace or target
    IPluginModelBase model = PluginRegistry.findModel(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER);
    if (model != null) {
        IResource resource = model.getUnderlyingResource();
        if (resource == null) {
            // Found in the target
            String installLocation = model.getInstallLocation();
            if (installLocation == null) {
                return null;
            }

            File bundleFile = new File(installLocation);
            if (!bundleFile.isDirectory()) {
                // The launcher bundle is usually jarred, just return the bundle root
                return installLocation;
            }

            // Unjarred bundle, search for the built jar at the root of the folder
            File[] files = bundleFile.listFiles(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.indexOf(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER) >= 0;
                }
            });
            for (int i = 0; i < files.length; i++) {
                if (files[i].isFile()) {
                    return files[i].getPath();
                }
            }

            // Source bundle from git://git.eclipse.org/gitroot/equinox/rt.equinox.framework.git
            File binFolder = new File(bundleFile, "bin"); //$NON-NLS-1$
            if (binFolder.isDirectory()) {
                return binFolder.getPath();
            }
            return null;
        }

        // Found in the workspace
        IProject project = resource.getProject();
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject jProject = JavaCore.create(project);
            IClasspathEntry[] entries = jProject.getRawClasspath();
            for (int i = 0; i < entries.length; i++) {
                int kind = entries[i].getEntryKind();
                if (kind == IClasspathEntry.CPE_SOURCE || kind == IClasspathEntry.CPE_LIBRARY) {
                    IPackageFragmentRoot[] roots = jProject.findPackageFragmentRoots(entries[i]);
                    for (int j = 0; j < roots.length; j++) {
                        if (roots[j].getPackageFragment(packageName).exists()) {
                            // if source folder, find the output folder
                            if (kind == IClasspathEntry.CPE_SOURCE) {
                                IPath path = entries[i].getOutputLocation();
                                if (path == null)
                                    path = jProject.getOutputLocation();
                                path = path.removeFirstSegments(1);
                                return project.getLocation().append(path).toOSString();
                            }
                            // else if is a library jar, then get the location of the jar itself
                            IResource jar = roots[j].getResource();
                            if (jar != null) {
                                return jar.getLocation().toOSString();
                            }
                        }
                    }
                }
            }
        }
    }

    // No PDE model, see if the launcher bundle is installed
    Bundle bundle = Platform.getBundle(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER);
    if (bundle != null) {
        try {
            URL url = FileLocator.resolve(bundle.getEntry("/")); //$NON-NLS-1$
            url = FileLocator.toFileURL(url);
            String path = url.getFile();
            if (path.startsWith("file:")) //$NON-NLS-1$
                path = path.substring(5);
            path = new File(path).getAbsolutePath();
            if (path.endsWith("!")) //$NON-NLS-1$
                path = path.substring(0, path.length() - 1);
            return path;
        } catch (IOException e) {
        }
    }
    return null;
}

From source file:org.eclipse.pde.internal.ui.editor.plugin.LibrarySection.java

License:Open Source License

private void updateJavaClasspathLibs(String[] oldPaths, String[] newPaths) {
    IProject project = ((IModel) getPage().getModel()).getUnderlyingResource().getProject();
    IJavaProject jproject = JavaCore.create(project);
    try {/*from w  w w.  j a va2 s  .  c om*/
        IClasspathEntry[] entries = jproject.getRawClasspath();
        ArrayList<IClasspathEntry> toBeAdded = new ArrayList<IClasspathEntry>();
        int index = -1;
        entryLoop: for (int i = 0; i < entries.length; i++) {
            if (entries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                if (index == -1)
                    index = i;
                // do not add the old paths (handling deletion/renaming)
                IPath path = entries[i].getPath().removeFirstSegments(1).removeTrailingSeparator();
                for (int j = 0; j < oldPaths.length; j++)
                    if (oldPaths[j] != null && path.equals(new Path(oldPaths[j]).removeTrailingSeparator()))
                        continue entryLoop;
            } else if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER)
                if (index == -1)
                    index = i;
            toBeAdded.add(entries[i]);
        }
        if (index == -1)
            index = entries.length;

        // add paths
        for (int i = 0; i < newPaths.length; i++) {
            if (newPaths[i] == null)
                continue;
            IClasspathEntry entry = JavaCore.newLibraryEntry(project.getFullPath().append(newPaths[i]), null,
                    null, true);
            if (!toBeAdded.contains(entry))
                toBeAdded.add(index++, entry);
        }

        if (toBeAdded.size() == entries.length)
            return;

        IClasspathEntry[] updated = toBeAdded.toArray(new IClasspathEntry[toBeAdded.size()]);
        jproject.setRawClasspath(updated, null);
    } catch (JavaModelException e) {
    }
}