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

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

Introduction

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

Prototype

boolean isExported();

Source Link

Document

Returns whether this entry is exported to dependent projects.

Usage

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);
                            }//from   w w w  . j a v  a  2 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]);
}

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;
                    }//ww  w .j a va2 s. com

                    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.microsoft.javapkgbuild.Tasks.java

License:MIT License

public static void exportReferences(String projectName, String outputFileName) throws JavaModelException {
    try {/*www  . j a v  a  2  s. c o m*/
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        IProject project = workspaceRoot.getProject(projectName);
        IJavaProject javaProject = JavaCore.create(project);

        DocumentBuilderFactory xFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = xFactory.newDocumentBuilder();
        Document doc = builder.newDocument();

        Element mainRoot = doc.createElement("classpath");
        mainRoot.setAttribute("projectName", projectName);
        doc.appendChild(mainRoot);

        IClasspathEntry[] classPathList = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry cp : classPathList) {
            Element cpNode = doc.createElement("classpathentry");
            cpNode.setAttribute("path", cp.getPath().toOSString());
            cpNode.setAttribute("kind", getClassPathType(cp));
            cpNode.setAttribute("exported", Boolean.toString(cp.isExported()));

            IPath sourceFolder = cp.getSourceAttachmentPath();
            if (cp.getEntryKind() == IClasspathEntry.CPE_LIBRARY && sourceFolder != null)
                cpNode.setAttribute("sourcepath", sourceFolder.toOSString());

            mainRoot.appendChild(cpNode);
        }

        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(doc);

        FileOutputStream fos = new FileOutputStream(outputFileName);
        StreamResult outFile = new StreamResult(fos);
        transformer.transform(source, outFile);
        fos.close();

        System.out.println("Output file is: " + outputFileName);
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

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

License:Apache License

private IClasspathEntry[] constructModifiedClasspath(IJavaProject javaProject) throws JavaModelException {
    IClasspathEntry newEntry = JavaCore.newContainerEntry(path, null, new IClasspathAttribute[0], false);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(asList(entries));
    int index = 0;
    boolean mustReplace = false;
    boolean projectModulesEntryWasExported = false;
    for (IClasspathEntry entry : newEntries) {
        if (entry.getPath().equals(newEntry.getPath())) {
            mustReplace = true;//from   w w w .j a  v  a2  s  . c  om
            projectModulesEntryWasExported = entry.isExported();
            break;
        }
        index++;
    }

    newEntry = JavaCore.newContainerEntry(path, null, new IClasspathAttribute[0],
            projectModulesEntryWasExported);
    if (mustReplace) {
        newEntries.set(index, newEntry);
    } else {
        newEntries.add(newEntry);
    }
    return (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
}

From source file:com.siteview.mde.internal.ui.wizards.plugin.NewLibraryPluginCreationOperation.java

License:Open Source License

private static void updateRequiredPlugins(IJavaProject javaProject, IProgressMonitor monitor,
        IMonitorModelBase model) throws CoreException {
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    List classpath = new ArrayList();
    List requiredProjects = new ArrayList();
    for (int i = 0; i < entries.length; i++) {
        if (isPluginProjectEntry(entries[i])) {
            requiredProjects.add(entries[i]);
        } else {//  ww w  .j  av a2s. com
            classpath.add(entries[i]);
        }
    }
    if (requiredProjects.size() <= 0)
        return;
    IFile file = PDEProject.getManifest(javaProject.getProject());
    try {
        // TODO format manifest
        Manifest manifest = new Manifest(file.getContents());
        String value = manifest.getMainAttributes().getValue(Constants.REQUIRE_BUNDLE);
        StringBuffer sb = value != null ? new StringBuffer(value) : new StringBuffer();
        if (sb.length() > 0)
            sb.append(","); //$NON-NLS-1$
        for (int i = 0; i < requiredProjects.size(); i++) {
            IClasspathEntry entry = (IClasspathEntry) requiredProjects.get(i);
            if (i > 0)
                sb.append(","); //$NON-NLS-1$
            sb.append(entry.getPath().segment(0));
            if (entry.isExported())
                sb.append(";visibility:=reexport"); // TODO is there a //$NON-NLS-1$
            // constant?
        }
        manifest.getMainAttributes().putValue(Constants.REQUIRE_BUNDLE, sb.toString());
        ByteArrayOutputStream content = new ByteArrayOutputStream();
        manifest.write(content);
        file.setContents(new ByteArrayInputStream(content.toByteArray()), true, false, monitor);
        // now update .classpath
        javaProject.setRawClasspath(
                (IClasspathEntry[]) classpath.toArray(new IClasspathEntry[classpath.size()]), monitor);
        //         ClasspathComputer.setClasspath(javaProject.getProject(), model);
    } catch (IOException e) {
    } catch (CoreException e) {
    }
}

From source file:com.siteview.mde.internal.ui.wizards.plugin.NewLibraryPluginCreationOperation.java

License:Open Source License

/**
 * @return updated classpath or null if there were no changes
 *///from w  w w.  j a  v a2  s.  c  om
private IClasspathEntry[] getUpdatedClasspath(IClasspathEntry[] cp, IJavaProject currentProject) {
    boolean exposed = false;
    int refIndex = -1;
    List result = new ArrayList();
    Set manifests = new HashSet();
    for (int i = 0; i < fData.getLibraryPaths().length; ++i) {
        try {
            manifests.add(new JarFile(fData.getLibraryPaths()[i]).getManifest());
        } catch (IOException e) {
            MDEPlugin.log(e);
        }
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    for (int i = 0; i < cp.length; ++i) {
        IClasspathEntry cpe = cp[i];
        switch (cpe.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            String path = null;
            IPath location = root.getFile(cpe.getPath()).getLocation();
            if (location != null) {
                path = location.toString();
            }
            //try maybe path is absolute
            if (path == null) {
                path = cpe.getPath().toString();
            }
            try {
                JarFile jarFile = new JarFile(path);
                if (manifests.contains(jarFile.getManifest())) {
                    if (refIndex < 0) {
                        // allocate slot
                        refIndex = result.size();
                        result.add(null);
                    }
                    exposed |= cpe.isExported();
                } else {
                    result.add(cpe);
                }
            } catch (IOException e) {
                MDEPlugin.log(e);
            }
            break;
        default:
            result.add(cpe);
            break;
        }
    }
    if (refIndex >= 0) {
        result.set(refIndex, JavaCore.newProjectEntry(currentProject.getPath(), exposed));
        return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]);
    }
    return null;
}

From source file:com.windowtester.codegen.util.BuildPathUtil.java

License:Open Source License

/**
 * Appends target project build path with source project build path.
 * /*from   w w  w .ja  va  2s  .c  o m*/
 * @param targetProject the target project
 * @param sourceProject the source project
 * @throws CoreException
 */
public static void appendProjectBuildPath(IJavaProject targetProject, IJavaProject sourceProject)
        throws CoreException {
    try {
        // copy required entries to target
        IClasspathEntry[] srcEntries = sourceProject.getRawClasspath();
        for (int i = 0; i < srcEntries.length; i++) {
            IClasspathEntry entry = srcEntries[i];
            if (entry.isExported() || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
                continue;
            addToClasspath(targetProject, entry);
        }
        // add the source project as a project entry
        IClasspathEntry srcPrjEntry = JavaCore.newProjectEntry(sourceProject.getPath());
        addToClasspath(targetProject, srcPrjEntry);
    } catch (JavaModelException e) {
        // we interested only in core exceptions
        if (e.getCause() instanceof CoreException) {
            throw (CoreException) e.getCause();
        }
    }
}

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   ww  w . ja  v a  2s  .  c  o m
 * @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 ww.ja va 2  s. c  om
 * @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/* w  w w  . j a  v a  2s.  c  om*/
 * @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());
}