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

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

Introduction

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

Prototype

IClasspathAttribute[] getExtraAttributes();

Source Link

Document

Returns the extra classpath attributes for this classpath entry.

Usage

From source file:com.google.cloud.tools.eclipse.appengine.libraries.repository.M2RepositoryService.java

License:Apache License

@Override
public IClasspathEntry rebuildClasspathEntry(IClasspathEntry classpathEntry)
        throws LibraryRepositoryServiceException {
    MavenCoordinates mavenCoordinates = transformer.createMavenCoordinates(classpathEntry.getExtraAttributes());
    Artifact artifact = resolveArtifact(mavenCoordinates);
    return JavaCore.newLibraryEntry(new Path(artifact.getFile().getAbsolutePath()),
            classpathEntry.getSourceAttachmentPath(), null /*  sourceAttachmentRootPath */,
            classpathEntry.getAccessRules(), classpathEntry.getExtraAttributes(), true /* isExported */);
}

From source file:com.google.gwt.eclipse.core.GWTProjectUtilities.java

License:Open Source License

private static boolean isOptional(IClasspathEntry entry) {
    IClasspathAttribute[] attributes = entry.getExtraAttributes();
    for (IClasspathAttribute attribute : attributes) {
        if (IClasspathAttribute.OPTIONAL.equals(attribute.getName()) && "true".equals(attribute.getValue())) //$NON-NLS-1$
            return true;
    }/*from  ww w  .  ja  v a2 s . c o  m*/
    return false;
}

From source file:com.google.gwt.eclipse.core.runtime.GWTJarsRuntimeTest.java

License:Open Source License

public void testGetClasspathEntries() throws Exception {
    IClasspathEntry[] cpEntries = runtime.getClasspathEntries();

    // Look for the gwt-specific classpath entries
    List<IClasspathEntry> gwtCpEntries = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry cpEntry : cpEntries) {
        if (isGWTJar(runtime, cpEntry.getPath().lastSegment())) {
            gwtCpEntries.add(cpEntry);/*from  w  w w.  j  a  v  a  2s .c o m*/
        }
    }

    // Make sure that there are two of them
    assertEquals(3, gwtCpEntries.size());

    for (int i = 0; i < gwtCpEntries.size(); i++) {
        IClasspathEntry gwtClasspathEntry = gwtCpEntries.get(i);
        assertEquals(IClasspathEntry.CPE_LIBRARY, gwtClasspathEntry.getEntryKind());
        assertEquals(IPackageFragmentRoot.K_BINARY, gwtClasspathEntry.getContentKind());

        // Verify that our classpath entries point at the GWT javadoc.
        IClasspathAttribute[] extraAttributes = gwtClasspathEntry.getExtraAttributes();
        assertTrue("No extra attributes seen for classpath entry: " + gwtClasspathEntry,
                extraAttributes.length > 0);
        assertEquals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, extraAttributes[0].getName());

        /*
         * Entries should have their javadoc location point at a directory with "index.html".
         * Strangely, the values of these classpath attributes are specified as "file://" urls.
         */
        File jdLocation = new File(new URL(extraAttributes[0].getValue()).getFile());
        assertTrue("Javadoc file does not exist", jdLocation.exists());
        List<String> files1 = Arrays.asList(jdLocation.list());
        assertTrue("Javadoc file is not an index.html file.", files1.contains("index.html"));
    }
}

From source file:com.google.gwt.eclipse.core.runtime.GWTRuntimeContainerInitializerTest.java

License:Open Source License

/**
 * TODO: We need to revisit this test. Since we don't allow container updates
 * right now, it is not clear that the test is sufficiently strong.
 *///from  www.  j a  v  a2s .co m
public void testRequestClasspathContainerUpdate() throws CoreException {
    IJavaProject testProject = getTestProject();

    IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(defaultRuntimePath, testProject);

    final List<IClasspathEntry> newClasspathEntries = new ArrayList<IClasspathEntry>();
    IClasspathEntry[] classpathEntries = classpathContainer.getClasspathEntries();
    for (IClasspathEntry classpathEntry : classpathEntries) {

        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IClasspathAttribute[] extraAttributes = classpathEntry.getExtraAttributes();
            List<IClasspathAttribute> newAttributes = new ArrayList<IClasspathAttribute>();
            for (IClasspathAttribute extraAttribute : extraAttributes) {
                String attributeName = extraAttribute.getName();
                if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attributeName)) {
                    String attributeValue = extraAttribute.getValue() + "modified";
                    extraAttribute = JavaCore.newClasspathAttribute(attributeName, attributeValue);
                }

                newAttributes.add(extraAttribute);
            }

            IPath sourceAttachmentPath = new Path("/sourceAttachmentPath");
            IPath sourceAttachmentRootPath = new Path("sourceAttachmentRootPath");

            classpathEntry = JavaCore.newLibraryEntry(classpathEntry.getPath(), sourceAttachmentPath,
                    sourceAttachmentRootPath, classpathEntry.getAccessRules(),
                    newAttributes.toArray(new IClasspathAttribute[0]), classpathEntry.isExported());
        }

        newClasspathEntries.add(classpathEntry);
    }

    // Update the classpath container
    initializer.requestClasspathContainerUpdate(defaultRuntimePath, testProject,
            new ClasspathContainerAdapter(classpathContainer) {
                @Override
                public IClasspathEntry[] getClasspathEntries() {
                    return newClasspathEntries.toArray(new IClasspathEntry[0]);
                }
            });

    // Check that the modifications took effect
    IClasspathContainer updatedContainer = JavaCore.getClasspathContainer(defaultRuntimePath, testProject);
    for (IClasspathEntry classpathEntry : updatedContainer.getClasspathEntries()) {
        if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_LIBRARY) {
            // Ignore all non-library entries
            continue;
        }

        for (IClasspathAttribute attribute : classpathEntry.getExtraAttributes()) {
            if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attribute.getName())) {
                String value = attribute.getValue();
                assertTrue(value.endsWith("modified"));
            }
        }

        IPath sourceAttachmentPath = classpathEntry.getSourceAttachmentPath();
        assertEquals(new Path("/sourceAttachmentPath"), sourceAttachmentPath);

        IPath sourceAttachmentRootPath = classpathEntry.getSourceAttachmentRootPath();
        assertEquals(new Path("sourceAttachmentRootPath"), sourceAttachmentRootPath);
    }
}

From source file:com.liferay.ide.project.core.PluginClasspathContainerInitializer.java

License:Open Source License

@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project,
        IClasspathContainer containerSuggestion) throws CoreException {

    final String key = PluginClasspathContainer.getDecorationManagerKey(project.getProject(),
            containerPath.toString());// w w  w  .  j  a  v a2 s  .  c  o  m

    final IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();

    cpDecorations.clearAllDecorations(key);

    for (int i = 0; i < entries.length; i++) {
        final IClasspathEntry entry = entries[i];

        final IPath srcpath = entry.getSourceAttachmentPath();
        final IPath srcrootpath = entry.getSourceAttachmentRootPath();
        final IClasspathAttribute[] attrs = entry.getExtraAttributes();

        if (srcpath != null || attrs.length > 0) {
            final String eid = entry.getPath().toString();
            final ClasspathDecorations dec = new ClasspathDecorations();

            dec.setSourceAttachmentPath(srcpath);
            dec.setSourceAttachmentRootPath(srcrootpath);
            dec.setExtraAttributes(attrs);

            cpDecorations.setDecorations(key, eid, dec);
        }
    }

    cpDecorations.save();

    IPath portalDir = null;
    String javadocURL = null;
    IPath sourceLocation = null;

    if (containerSuggestion instanceof PluginClasspathContainer) {
        portalDir = ((PluginClasspathContainer) containerSuggestion).getPortalDir();
        javadocURL = ((PluginClasspathContainer) containerSuggestion).getJavadocURL();
        sourceLocation = ((PluginClasspathContainer) containerSuggestion).getSourceLocation();
    } else {
        portalDir = ServerUtil.getPortalDir(project);

        try {
            ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(project.getProject());

            if (liferayRuntime != null) {
                javadocURL = liferayRuntime.getJavadocURL();

                sourceLocation = liferayRuntime.getSourceLocation();
            }
        } catch (Exception e) {
            ProjectCore.logError(e);
        }
    }

    if (portalDir != null) {
        IClasspathContainer newContainer = getCorrectContainer(containerPath, containerPath.segment(1), project,
                portalDir, javadocURL, sourceLocation);

        JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project },
                new IClasspathContainer[] { newContainer }, null);
    }
}

From source file:com.liferay.ide.project.core.SDKClasspathContainerInitializer.java

License:Open Source License

@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project,
        IClasspathContainer containerSuggestion) throws CoreException {
    final String key = SDKClasspathContainer.getDecorationManagerKey(project.getProject(),
            containerPath.toString());/*from   w  ww  .j a  v a  2 s  .c  om*/

    final IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();

    cpDecorations.clearAllDecorations(key);

    for (int i = 0; i < entries.length; i++) {
        final IClasspathEntry entry = entries[i];

        final IPath srcpath = entry.getSourceAttachmentPath();
        final IPath srcrootpath = entry.getSourceAttachmentRootPath();
        final IClasspathAttribute[] attrs = entry.getExtraAttributes();

        if (srcpath != null || attrs.length > 0) {
            final String eid = entry.getPath().toString();
            final ClasspathDecorations dec = new ClasspathDecorations();

            dec.setSourceAttachmentPath(srcpath);
            dec.setSourceAttachmentRootPath(srcrootpath);
            dec.setExtraAttributes(attrs);

            cpDecorations.setDecorations(key, eid, dec);
        }
    }

    cpDecorations.save();

    IPath portalDir = null;
    IPath portalGlobalDir = null;
    String javadocURL = null;
    IPath sourceLocation = null;
    IPath bundleDir = null;
    IPath[] bundleDependencyJarPaths = null;

    PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject());

    boolean containerChanged = true;

    if (containerSuggestion instanceof SDKClasspathContainer) {
        portalDir = ((SDKClasspathContainer) containerSuggestion).getPortalDir();
        bundleDir = ((SDKClasspathContainer) containerSuggestion).getBundleDir();
        portalGlobalDir = ((SDKClasspathContainer) containerSuggestion).getPortalGlobalDir();
        javadocURL = ((SDKClasspathContainer) containerSuggestion).getJavadocURL();
        sourceLocation = ((SDKClasspathContainer) containerSuggestion).getSourceLocation();
        bundleDependencyJarPaths = ((SDKClasspathContainer) containerSuggestion).getBundleLibDependencyPath();

        if (bundle != null && bundle.getAppServerPortalDir().equals(portalDir)) {
            containerChanged = false;
        }
    }

    if (containerChanged == true) {
        if (bundle == null) {
            return;
        }

        portalDir = bundle.getAppServerPortalDir();
        portalGlobalDir = bundle.getAppServerLibGlobalDir();
        bundleDependencyJarPaths = bundle.getBundleDependencyJars();
    }

    IPath[] sdkDependencyPaths = getSDKDependencies(project);

    if (portalDir != null && portalGlobalDir != null) {
        IClasspathContainer newContainer = new SDKClasspathContainer(containerPath, project, portalDir,
                javadocURL, sourceLocation, portalGlobalDir, bundleDir, bundleDependencyJarPaths,
                sdkDependencyPaths);

        JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project },
                new IClasspathContainer[] { newContainer }, null);
    }
}

From source file:com.liferay.ide.project.core.util.ProjectUtil.java

License:Open Source License

private static void fixExtProjectClasspathEntries(IProject project) {
    try {//from  w  ww .j av  a2 s .com
        boolean fixedAttr = false;

        IJavaProject javaProject = JavaCore.create(project);

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

        IClasspathEntry[] entries = javaProject.getRawClasspath();

        for (IClasspathEntry entry : entries) {
            IClasspathEntry newEntry = null;

            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                List<IClasspathAttribute> newAttrs = new ArrayList<IClasspathAttribute>();

                IClasspathAttribute[] attrs = entry.getExtraAttributes();

                if (!CoreUtil.isNullOrEmpty(attrs)) {
                    for (IClasspathAttribute attr : attrs) {
                        IClasspathAttribute newAttr = null;

                        if ("owner.project.facets".equals(attr.getName()) && //$NON-NLS-1$
                                "liferay.plugin".equals(attr.getValue())) //$NON-NLS-1$
                        {
                            newAttr = JavaCore.newClasspathAttribute(attr.getName(), "liferay.ext"); //$NON-NLS-1$
                            fixedAttr = true;
                        } else {
                            newAttr = attr;
                        }

                        newAttrs.add(newAttr);
                    }

                    newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                            entry.getExclusionPatterns(), entry.getOutputLocation(),
                            newAttrs.toArray(new IClasspathAttribute[0]));
                }
            }

            if (newEntry == null) {
                newEntry = entry;
            }

            newEntries.add(newEntry);
        }

        if (fixedAttr) {
            IProgressMonitor monitor = new NullProgressMonitor();

            javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), monitor);

            try {
                javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
            } catch (Exception e) {
                ProjectCore.logError(e);
            }
        }

        fixExtProjectSrcFolderLinks(project);
    } catch (Exception ex) {
        ProjectCore.logError("Exception trying to fix Ext project classpath entries.", ex); //$NON-NLS-1$
    }
}

From source file:com.liferay.ide.sdk.ui.SDKProjectRenameParticipant.java

License:Open Source License

@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    final String newName = this.getArguments().getNewName();

    return new Change() {
        @Override//from  www. j ava  2  s .  c  o m
        public String getName() {
            return "Update Ivy classpath entry"; //$NON-NLS-1$
        }

        @Override
        public void initializeValidationData(IProgressMonitor pm) {
            System.out.println();
        }

        @Override
        public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
            return new RefactoringStatus();
        }

        @Override
        public Change perform(IProgressMonitor pm) throws CoreException {
            final RenameJavaProjectProcessor rjpp = (RenameJavaProjectProcessor) getProcessor();
            final IJavaProject newJavaProject = (IJavaProject) rjpp.getNewElement();
            final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(
                    newJavaProject, ISDKConstants.IVY_XML_FILE, true);

            IClasspathEntry oldEntry = null;

            for (IClasspathEntry cpEntry : newJavaProject.getRawClasspath()) {
                if (cpEntry.getPath().segment(0).equals(IvyClasspathContainer.CONTAINER_ID)) {
                    oldEntry = cpEntry;
                    break;
                }
            }

            IvyClasspathContainerConfAdapter.load(conf, oldEntry.getPath(), oldEntry.getExtraAttributes());

            final String oldIvySettingsPath = conf.getIvySettingsSetup().getRawIvySettingsPath();
            final String oldIvyUserDir = conf.getIvySettingsSetup().getRawIvyUserDir();

            conf.setProject(newJavaProject);
            conf.getIvySettingsSetup().setIvySettingsPath(oldIvySettingsPath.replaceAll(oldName, newName));
            conf.getIvySettingsSetup().setIvyUserDir(oldIvyUserDir.replaceAll(oldName, newName));

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

            for (IClasspathEntry cpEntry : newJavaProject.getRawClasspath()) {
                if (!cpEntry.getPath().segment(0).equals(IvyClasspathContainer.CONTAINER_ID)) {
                    newEntries.add(cpEntry);
                }
            }

            IPath newIvyPath = IvyClasspathContainerConfAdapter.getPath(conf);

            newJavaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), pm);

            IClasspathEntry ivyEntry = JavaCore.newContainerEntry(newIvyPath, null,
                    oldEntry.getExtraAttributes(), false);

            IvyClasspathContainer ivycp = new IvyClasspathContainer(newJavaProject, newIvyPath,
                    new IClasspathEntry[0], new IClasspathAttribute[0]);
            JavaCore.setClasspathContainer(newIvyPath, new IJavaProject[] { newJavaProject },
                    new IClasspathContainer[] { ivycp }, pm);

            IClasspathEntry[] entries = newJavaProject.getRawClasspath();

            newEntries.add(ivyEntry);
            entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
            newJavaProject.setRawClasspath(entries, newJavaProject.getOutputLocation(), pm);

            JavaCore.getClasspathContainerInitializer(IvyClasspathContainer.CONTAINER_ID)
                    .requestClasspathContainerUpdate(newIvyPath, newJavaProject, ivycp);

            ivycp.launchResolve(false, pm);

            return null;
        }

        @Override
        public Object getModifiedElement() {
            return null;
        }
    };
}

From source file:com.liferay.ide.server.remote.ModuleTraverser.java

License:Open Source License

private static IClasspathAttribute checkForComponentDependencyAttribute(final IClasspathEntry entry,
        final int attributeType) {
    if (entry == null) {
        return null;
    }//  w ww. j  ava2s. co m
    final IClasspathAttribute[] attributes = entry.getExtraAttributes();
    for (int i = 0; i < attributes.length; i++) {
        final IClasspathAttribute attribute = attributes[i];
        final String name = attribute.getName();
        if (name.equals(CLASSPATH_COMPONENT_DEPENDENCY)) {
            if (attributeType == DEPENDECYATTRIBUTETYPE_DEPENDENCY_OR_NONDEPENDENCY
                    || attributeType == DEPENDECYATTRIBUTETYPE_CLASSPATH_COMPONENT_DEPENDENCY) {
                return attribute;
            }
        } else if (name.equals(CLASSPATH_COMPONENT_NON_DEPENDENCY)) {
            if (attributeType == DEPENDECYATTRIBUTETYPE_DEPENDENCY_OR_NONDEPENDENCY
                    || attributeType == DEPENDECYATTRIBUTETYPE_CLASSPATH_COMPONENT_NONDEPENDENCY) {
                return attribute;
            }
        }
    }
    return null;
}

From source file:com.liferay.ide.server.tomcat.core.LiferayTomcatRuntimeClasspathProvider.java

License:Open Source License

private IClasspathEntry[] getUpdatedJavadocEntries(IClasspathEntry[] entries,
        ILiferayTomcatRuntime liferayTomcatRuntime) {
    List<IClasspathEntry> updatedEntries = new ArrayList<IClasspathEntry>();

    String javadocURL = liferayTomcatRuntime.getJavadocURL();

    if (javadocURL != null) {
        for (IClasspathEntry existingEntry : entries) {
            IPath path = existingEntry.getPath();

            IClasspathEntry newEntry = null;

            for (String javadocJar : JARS) {
                if (path.lastSegment().equalsIgnoreCase(javadocJar)) {
                    IClasspathAttribute[] extraAttrs = existingEntry.getExtraAttributes();

                    List<IClasspathAttribute> newExtraAttrs = new ArrayList<IClasspathAttribute>();

                    IClasspathAttribute javadocAttr = newJavadocAttr(javadocURL);

                    newExtraAttrs.add(javadocAttr);

                    if (!CoreUtil.isNullOrEmpty(extraAttrs)) {
                        for (IClasspathAttribute attr : extraAttrs) {
                            if (!attr.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME)) {
                                newExtraAttrs.add(attr);
                            }//www. j a  va2 s .c  o  m
                        }
                    }

                    newEntry = JavaCore.newLibraryEntry(existingEntry.getPath(),
                            existingEntry.getSourceAttachmentPath(),
                            existingEntry.getSourceAttachmentRootPath(), existingEntry.getAccessRules(),
                            newExtraAttrs.toArray(new IClasspathAttribute[0]), existingEntry.isExported());
                    break;
                }
            }

            if (newEntry != null) {
                updatedEntries.add(newEntry);
            } else {
                updatedEntries.add(existingEntry);
            }
        }
    } else {
        Collections.addAll(updatedEntries, entries);
    }

    return updatedEntries.toArray(new IClasspathEntry[0]);
}