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.liferay.ide.server.tomcat.core.LiferayTomcatRuntimeClasspathProvider.java

License:Open Source License

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

    IPath sourceLocation = liferayTomcatRuntime.getSourceLocation();

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

            IClasspathEntry newEntry = null;

            for (String sourceJar : JARS) {
                if (path.lastSegment().equalsIgnoreCase(sourceJar)) {
                    IPath sourcePath = existingEntry.getSourceAttachmentPath();

                    if (sourcePath == null) {
                        sourcePath = sourceLocation;
                    }//  www .  j a  v  a2  s. c o  m

                    newEntry = JavaCore.newLibraryEntry(existingEntry.getPath(), sourcePath,
                            existingEntry.getSourceAttachmentRootPath(), existingEntry.getAccessRules(),
                            existingEntry.getExtraAttributes(), existingEntry.isExported());

                    break;
                }
            }

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

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

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathContainer.java

License:Apache License

public static void runInitialize(final IPath containerPath, final IJavaProject javaProject) {
    Job job = new Job("Initializing Ceylon dependencies for project " + javaProject.getElementName()) {
        @Override/*w ww  .  ja  va2s . c  o m*/
        protected IStatus run(IProgressMonitor monitor) {
            try {

                IClasspathContainer c = getClasspathContainer(containerPath, javaProject);
                CeylonClasspathContainer container;
                if (c instanceof CeylonClasspathContainer) {
                    container = (CeylonClasspathContainer) c;
                } else {
                    IClasspathEntry entry = getCeylonClasspathEntry(containerPath, javaProject);
                    IClasspathAttribute[] attributes = entry == null ? new IClasspathAttribute[0]
                            : entry.getExtraAttributes();
                    if (c == null) {
                        container = new CeylonClasspathContainer(javaProject, containerPath,
                                new IClasspathEntry[0], attributes);
                    } else {
                        // this might be the persisted one: reuse the persisted entries
                        container = new CeylonClasspathContainer(javaProject, containerPath,
                                c.getClasspathEntries(), attributes);
                    }
                }

                final IProject p = javaProject.getProject();
                Job job = new BuildProjectAndDependenciesJob("Initial build of project " + p.getName(), p) {
                    protected boolean reallyRun() {
                        return !CeylonBuilder.isModelAvailable(p);
                    }
                };
                job.setRule(p.getWorkspace().getRoot());
                job.setPriority(Job.BUILD);
                job.schedule(3000);

                boolean changed = container.resolveClasspath(monitor, true);
                if (changed) {
                    container.refreshClasspathContainer(monitor, javaProject);
                }

                return Status.OK_STATUS;

            } catch (JavaModelException ex) {
                // unless there are issues with the JDT, this should never happen
                return new Status(IStatus.ERROR, PLUGIN_ID, "could not get container", ex);
            }
        }
    };
    job.setUser(false);
    job.setPriority(Job.BUILD);
    job.setRule(getWorkspace().getRoot());
    job.schedule();
}

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathUtil.java

License:Apache License

/**
 * Just a verbatim copy of the internal Eclipse function:
 * org.eclipse.jdt.internal.corext.javadoc
 * .JavaDocLocations#getLibraryJavadocLocation(IClasspathEntry)
 * /*  w  w w  .j a v  a 2  s .c o  m*/
 * @param entry
 * @return
 */
public static URL getLibraryJavadocLocation(IClasspathEntry entry) {
    if (entry == null) {
        throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$
    }

    int kind = entry.getEntryKind();
    if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) {
        throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or " + "CPE_VARIABLE"); //$NON-NLS-1$
    }

    IClasspathAttribute[] extraAttributes = entry.getExtraAttributes();
    for (int i = 0; i < extraAttributes.length; i++) {
        IClasspathAttribute attrib = extraAttributes[i];
        if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) {
            try {
                return new URL(attrib.getValue());
            } catch (MalformedURLException e) {
                return null;
            }
        }
    }
    return null;
}

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonProjectModulesInitializer.java

License:Apache License

/**
 * Initialize the container with the "persisted" classpath 
 * entries, and then schedule the refresh.
 *///from  w  ww.  j a v a2  s. co  m
public void initialize(IPath containerPath, final IJavaProject project) throws CoreException {
    int size = containerPath.segmentCount();
    if (size > 0) {
        if (containerPath.segment(0).equals(CeylonProjectModulesContainer.CONTAINER_ID)) {
            IClasspathContainer c = getClasspathContainer(containerPath, project);
            CeylonProjectModulesContainer container;
            if (c instanceof CeylonProjectModulesContainer) {
                container = (CeylonProjectModulesContainer) c;
            } else {
                IClasspathEntry entry = getCeylonClasspathEntry(containerPath, project);
                IClasspathAttribute[] attributes = entry == null ? new IClasspathAttribute[0]
                        : entry.getExtraAttributes();
                if (c == null) {
                    container = new CeylonProjectModulesContainer(project, containerPath,
                            new IClasspathEntry[0], attributes);
                } else {
                    // this might be the persisted one: reuse the persisted entries
                    container = new CeylonProjectModulesContainer(project, containerPath,
                            c.getClasspathEntries(), attributes);
                }
            }

            setClasspathContainer(containerPath, new IJavaProject[] { project },
                    new IClasspathContainer[] { container }, null);

            final Job initDependenciesJob = new InitDependenciesJob(
                    "Initializing dependencies for project " + project.getElementName(), container);
            initDependenciesJob.setUser(false);
            initDependenciesJob.setPriority(Job.BUILD);
            initDependenciesJob.setRule(getWorkspace().getRoot());

            // Before scheduling the InitDependenciesJob, we will wait for the end of the Java Tooling initialization Job 
            final long waitUntil = System.currentTimeMillis() + 120000;

            Job initDependenciesWhenJavaToolingIsInitialized = new Job(
                    "Waiting for the end of the Java Tooling Initialization before initializing Ceylon dependencies for project "
                            + project.getElementName() + " ...") {
                private Job initJavaToolingJob = null;

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    if (initJavaToolingJob == null) {
                        Job[] jobs = getJobManager().find(JavaUI.ID_PLUGIN);
                        for (Job job : jobs) {
                            if (job.getClass().getEnclosingClass().equals(InitializeAfterLoadJob.class)) {
                                initJavaToolingJob = job;
                            }
                        }
                    }

                    if (initJavaToolingJob != null) {
                        if (initJavaToolingJob.getState() == Job.WAITING
                                || initJavaToolingJob.getState() == Job.RUNNING) {
                            if (System.currentTimeMillis() < waitUntil) {
                                //                                    System.out.println("Waiting 1 seconde more for the end of the Java Tooling Initialization before initializing Ceylon dependencies for project " + project.getElementName() + " ...");
                                schedule(1000);
                                return Status.OK_STATUS;
                            } else {
                                //                                    System.out.println("The Java Tooling is not initialized after 2 minutes, so start initializing Ceylon dependencies for project " + project.getElementName() + " anyway !");
                            }
                        }
                    }

                    boolean shouldSchedule = true;
                    for (Job job : getJobManager().find(initDependenciesJob)) {
                        if (job.getState() == Job.WAITING) {
                            //                                System.out.println("An InitDependenciesJob for project " + project.getElementName() + " is already scheduled. Finally don't schedule a new one after the Java Tooling has initialized");
                            shouldSchedule = false;
                            break;
                        }
                    }

                    if (shouldSchedule) {
                        //                            System.out.println("Scheduling the initialization of the Ceylon dependencies for project " + project.getElementName() + " after the Java Tooling has been initialized");
                        initDependenciesJob.schedule();
                    }
                    return Status.OK_STATUS;
                }
            };

            initDependenciesWhenJavaToolingIsInitialized.setPriority(Job.BUILD);
            initDependenciesWhenJavaToolingIsInitialized.setSystem(true);
            initDependenciesWhenJavaToolingIsInitialized.schedule();
        }
    }
}

From source file:com.tasktop.dropwizard.launcher.DropwizardRuntimeClasspathProvider.java

License:Open Source License

private String getArtifactClassifier(IClasspathEntry entry) {
    IClasspathAttribute[] attributes = entry.getExtraAttributes();
    for (IClasspathAttribute attribute : attributes) {
        if (IClasspathManager.CLASSIFIER_ATTRIBUTE.equals(attribute.getName())) {
            return attribute.getValue();
        }//from  ww w  .j a v  a2 s  . com
    }
    return null;
}

From source file:de.ovgu.featureide.ahead.actions.FeatureHouseToAHEADConversion.java

License:Open Source License

/**
 * Set the source path of given <code>ClasspathEntry</code> to the current build path
 * @param e The entry to set//from  w  w w.j  a  v  a  2  s .c  om
 * @return The entry with the new source path
 */
public IClasspathEntry setSourceEntry(IClasspathEntry e) {
    return new ClasspathEntry(e.getContentKind(), e.getEntryKind(),
            featureProject.getBuildFolder().getFullPath(), e.getInclusionPatterns(), e.getExclusionPatterns(),
            e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(),
            e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes());
}

From source file:de.ovgu.featureide.aspectj.AspectJComposer.java

License:Open Source License

/**
 * Set the unselected aspect files to be excluded
 * @param e The ClasspathEntry to set//w w w .jav  a  2s .  c o  m
 * @return The set entry
 */
private IClasspathEntry setSourceEntry(IClasspathEntry e) {
    IPath[] excludedAspects = new IPath[unSelectedFeatures.size()];
    int i = 0;
    for (String f : unSelectedFeatures) {
        excludedAspects[i++] = new Path(f.replaceAll("_", "/") + ".aj");
    }
    return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), e.getPath(), e.getInclusionPatterns(),
            excludedAspects, e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(),
            e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes());
}

From source file:de.ovgu.featureide.core.builder.ComposerExtensionClass.java

License:Open Source License

/**
 * Set the source path of the given <code>ClasspathEntry</code>
 * @param buildPath The new build path/*from   w  w w . j a v  a  2s.c  o m*/
 * @param e The entry to set
 * @return The entry with the new source path
 */
public IClasspathEntry setSourceEntry(String buildPath, IClasspathEntry e) {
    return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), new Path(buildPath),
            e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
            e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(),
            e.getExtraAttributes());
}

From source file:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java

License:Open Source License

private static IPath setJavaBuildPath(JavaProject javaProject, IPath path, int index) {
    try {//w ww  . ja  va 2s.  c om
        final IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath();

        if (index >= 0) {
            final IClasspathEntry e = classpathEntrys[index];
            if (!e.getPath().equals(path)) {
                final IPath formerSourcePath = e.getPath();
                classpathEntrys[index] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path,
                        e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(),
                        e.combineAccessRules(), e.getExtraAttributes());
                javaProject.setRawClasspath(classpathEntrys, null);
                return formerSourcePath;
            }
        } else {
            final IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1];
            System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length);
            newEntrys[newEntrys.length - 1] = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE,
                    IClasspathEntry.CPE_SOURCE, path, new IPath[0], new IPath[0], null, null, null, false, null,
                    false, new IClasspathAttribute[0]);
            javaProject.setRawClasspath(newEntrys, null);
        }
    } catch (JavaModelException e) {
        MPLPlugin.getDefault().logError(e);
    }

    return null;
}

From source file:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java

License:Open Source License

private static void resetJavaBuildPath(JavaProject javaProject, IPath formerSourcePath,
        int formerSourcePathIndex) {
    try {/* ww w  .j av a 2  s  . com*/
        final IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath();

        if (formerSourcePath != null) {
            final IClasspathEntry e = classpathEntrys[formerSourcePathIndex];
            classpathEntrys[formerSourcePathIndex] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(),
                    formerSourcePath, e.getInclusionPatterns(), e.getExclusionPatterns(),
                    e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(),
                    e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes());
            javaProject.setRawClasspath(classpathEntrys, null);
        } else if (formerSourcePathIndex == -1) {
            final IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length - 1];
            System.arraycopy(classpathEntrys, 0, newEntrys, 0, newEntrys.length);
            javaProject.setRawClasspath(newEntrys, null);
        }
    } catch (JavaModelException e) {
        MPLPlugin.getDefault().logError(e);
    }
}