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:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java

License:Open Source License

private static IPath setJavaBuildPath(JavaProject javaProject, IPath path, int index) {
    try {/*from   w  ww.  ja va 2  s . c o m*/
        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 {//from   w  w w.  ja  v a2s.c  o m
        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);
    }
}

From source file:de.ovgu.featureide.featurehouse.FeatureHouseComposer.java

License:Open Source License

/**
 * Sets the Java build path to the folder at the build folder, named like the current configuration.
 * @param buildPath The name of the current configuration
 *//*www.j  av  a 2 s . c  o  m*/
private void setJavaBuildPath(String buildPath) {
    try {
        JavaProject javaProject = new JavaProject(featureProject.getProject(), null);
        IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath();

        int i = 0;
        for (IClasspathEntry e : classpathEntrys) {
            if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = featureProject.getBuildFolder().getFolder(buildPath).getFullPath();

                /** return if nothing has to be changed **/
                if (e.getPath().equals(path)) {
                    return;
                }

                /** change the actual source entry to the new build path **/
                ClasspathEntry changedEntry = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path,
                        e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(),
                        e.combineAccessRules(), e.getExtraAttributes());
                classpathEntrys[i] = changedEntry;
                javaProject.setRawClasspath(classpathEntrys, null);
                return;
            }
            i++;
        }

        /** case: there is no source entry at the class path
         *       add the source entry to the classpath **/
        IFolder folder = featureProject.getBuildFolder().getFolder(buildPath);
        ClasspathEntry sourceEntry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE,
                IClasspathEntry.CPE_SOURCE, folder.getFullPath(), new IPath[0], new IPath[0], null, null, null,
                false, null, false, new IClasspathAttribute[0]);
        IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1];
        System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length);
        newEntrys[newEntrys.length - 1] = sourceEntry;
        javaProject.setRawClasspath(newEntrys, null);
    } catch (JavaModelException e) {
        FeatureHouseCorePlugin.getDefault().logError(e);
    }
}

From source file:de.ovgu.featureide.ui.actions.generator.Generator.java

License:Open Source License

/**
 * Sets the classpath entries for the newly created project
 * @param p The new project//from   w  ww . jav  a 2  s  .c  o m
 */
// TODO remove redundant calculations for each configuration
// TODO copy settings
private void setClassPath(IProject p) {
    JavaProject baseProject = new JavaProject(builder.featureProject.getProject(), null);
    JavaProject newProject = new JavaProject(p, null);
    try {
        IClasspathEntry[] entries = baseProject.getRawClasspath().clone();
        for (int i = 0; i < entries.length; i++) {
            // set source entry to "src"
            IClasspathEntry e = entries[i];
            if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                entries[i] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), new Path("src"),
                        e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(),
                        e.combineAccessRules(), e.getExtraAttributes());
            } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                // set the library entries and copy the libraries 
                // which are direct at the old projects folder  
                IPath path = e.getPath().removeFirstSegments(1);
                IProject project = builder.featureProject.getProject();
                IFile file = project.getFile(path);
                if (!file.exists()) {
                    path = e.getPath();
                    file = project.getFile(path);
                    if (!file.exists()) {
                        continue;
                    }
                }
                createLibFolder(p.getFile(path).getParent());
                file.copy(p.getFile(e.getPath().removeFirstSegments(1)).getFullPath(), true, null);
                entries[i] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(),
                        e.getPath().removeFirstSegments(1), e.getInclusionPatterns(), e.getExclusionPatterns(),
                        e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(),
                        e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes());
            }
        }
        newProject.setRawClasspath(entries, null);
    } catch (JavaModelException e) {
        UIPlugin.getDefault().logError(e);
    } catch (CoreException e) {
        UIPlugin.getDefault().logError(e);
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private void addPath(IvyXmlWriter xw, IJavaProject jp, IClasspathEntry ent, boolean nest) {
    IPath p = ent.getPath();/*from  www .j a v  a2  s . c  o m*/
    IPath op = ent.getOutputLocation();
    IPath sp = ent.getSourceAttachmentPath();
    IProject ip = jp.getProject();

    String jdp = null;
    boolean opt = false;
    IClasspathAttribute[] atts = ent.getExtraAttributes();
    for (IClasspathAttribute att : atts) {
        if (att.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME))
            jdp = att.getValue();
        else if (att.getName().equals(IClasspathAttribute.OPTIONAL)) {
            String v = att.getValue();
            if (v.equals("true"))
                opt = true;
        }
    }

    if (p == null && op == null)
        return;
    File f1 = null;
    if (p != null) {
        f1 = BedrockUtil.getFileForPath(p, ip);
        if (!f1.exists()) {
            BedrockPlugin.logD("Path file " + p + " not found as " + f1);
            // f1 = null;
        }
    }
    File f2 = null;
    if (op != null) {
        f2 = BedrockUtil.getFileForPath(op, ip);
        if (!f2.exists()) {
            BedrockPlugin.logD("Path file " + op + " not found");
            f2 = null;
        }
    }
    File f3 = null;
    if (sp != null) {
        f3 = BedrockUtil.getFileForPath(sp, ip);
        if (!f3.exists()) {
            BedrockPlugin.logD("Path file " + sp + " not found");
            f3 = null;
        }
    }
    if (f1 == null && f2 == null)
        return;

    // references to nested projects are handled in addClassPaths
    if (ent.getEntryKind() == IClasspathEntry.CPE_PROJECT)
        return;

    xw.begin("PATH");
    xw.field("ID", ent.hashCode());
    if (nest)
        xw.field("NESTED", "TRUE");

    switch (ent.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE:
        xw.field("TYPE", "SOURCE");
        f3 = f1;
        f1 = null;
        break;
    case IClasspathEntry.CPE_PROJECT:
        xw.field("TYPE", "BINARY");
        break;
    case IClasspathEntry.CPE_LIBRARY:
        xw.field("TYPE", "LIBRARY");
        break;
    }
    if (ent.isExported())
        xw.field("EXPORTED", true);
    if (opt)
        xw.field("OPTIONAL", true);

    if (f1 != null)
        xw.textElement("BINARY", f1.getAbsolutePath());
    if (f2 != null)
        xw.textElement("OUTPUT", f2.getAbsolutePath());
    if (f3 != null)
        xw.textElement("SOURCE", f3.getAbsolutePath());
    if (jdp != null)
        xw.textElement("JAVADOC", jdp);

    IAccessRule[] rls = ent.getAccessRules();
    for (IAccessRule ar : rls) {
        xw.begin("ACCESS");
        xw.field("KIND", ar.getKind());
        xw.field("PATTERN", ar.getPattern().toString());
        xw.field("IGNOREIFBETTER", ar.ignoreIfBetter());
        xw.end("ACCESS");
    }

    xw.end("PATH");
}

From source file:jasima_gui.EclipseProjectClassLoader.java

License:Open Source License

protected Resource findResource(final String name, IJavaProject proj, boolean onlyExported)
        throws CoreException {
    IClasspathEntry[] classpath = proj.getResolvedClasspath(true);

    byte[] content;

    content = readResource(proj.getOutputLocation().makeRelative(), name);
    if (content != null) {
        return new Resource(proj.getOutputLocation().makeRelative(), content);
    }/*ww w  .j a  va  2s . co  m*/

    for (IClasspathEntry entry : classpath) {
        if (onlyExported && !entry.isExported())
            continue;

        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            content = readResource(entry.getPath(), name);
            if (content != null) {
                return new Resource(entry.getPath(), content);
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            IProject projEntry = (IProject) ResourcesPlugin.getWorkspace().getRoot()
                    .findMember(entry.getPath());
            Resource result = findResource(name, JavaCore.create(projEntry), true);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}

From source file:me.gladwell.eclipse.m2e.android.configuration.JavadocsEntryAttacher.java

License:Open Source License

public IClasspathEntry attach(IClasspathEntry entry, Artifact docs) {
    try {/*from  w  w  w. j  a v  a  2 s.  co m*/
        ClasspathAttributes attributes = new ClasspathAttributes(entry.getExtraAttributes());
        attributes.set(newClasspathAttribute(JAVADOC_LOCATION_ATTRIBUTE_NAME, getJavaDocUrl(docs.getFile())));

        IClasspathEntry entryWithDocs = JavaCore.newLibraryEntry(entry.getPath(),
                entry.getSourceAttachmentPath(), null, entry.getAccessRules(), attributes.toArray(),
                entry.isExported());

        return entryWithDocs;
    } catch (Exception e) {
        throw new ProjectConfigurationException(e);
    }
}

From source file:me.gladwell.eclipse.m2e.android.configuration.SourcesEntryAttacher.java

License:Open Source License

public IClasspathEntry attach(IClasspathEntry entry, Artifact sources) {
    return JavaCore.newLibraryEntry(entry.getPath(), Path.fromOSString(sources.getFile().getAbsolutePath()),
            null, entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
}

From source file:me.gladwell.eclipse.m2e.android.test.ApplicationAndroidMavenPluginTest.java

License:Open Source License

public void testConfigureMarksMavenContainerExported() throws Exception {
    IClasspathEntry mavenContainer = getClasspathContainer(javaProject, IClasspathManager.CONTAINER_ID);
    assertTrue(mavenContainer.isExported());
}

From source file:net.rim.ejde.internal.packaging.PackagingManager.java

License:Open Source License

static private void getCompileImportsRecusively(IClasspathEntry[] entries, IJavaProject jProject,
        Vector<ImportedJar> imports, boolean isMainProject) throws CoreException {
    if (imports == null) {
        imports = new Vector<ImportedJar>();
    }/*from  w w w.ja  va  2  s.co m*/
    // Workspace imports; if there aren't any specified, default to
    // using the runtime libraries.
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    // String jarPathString;
    try {
        BlackBerryProperties properties = null;
        boolean needAddBBJar = false;
        IPath jarPath = null;
        ImportedJar importedJar = null;
        for (IClasspathEntry entry : entries) {
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_CONTAINER: {
                // libraries
                IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
                        jProject.getJavaProject());
                if (container == null) {
                    continue;
                }

                IVMInstall containerVM;
                if (!(container instanceof JREContainer)) {
                    // We need to verify the type of the container because the path of Maven container only has one
                    // segment and JavaRuntime.getVMInstall(IPath) return the default VM install if the entry path has one
                    // segment.
                    containerVM = null;
                } else {
                    containerVM = JavaRuntime.getVMInstall(entry.getPath());
                }

                try {
                    if (containerVM != null) {
                        if (containerVM.getVMInstallType().getId().equals(BlackBerryVMInstallType.VM_ID)) {
                            if (isMainProject) {
                                // Add jars to a list
                                IClasspathEntry[] classpathEntries = container.getClasspathEntries();
                                if (classpathEntries != null && classpathEntries.length > 0) {
                                    getCompileImportsRecusively(classpathEntries, jProject, imports, false);
                                }
                            }
                        } else {
                            if (!jProject.getProject().hasNature(BlackBerryProjectCoreNature.NATURE_ID)) {
                                needAddBBJar = true;
                                continue;
                            }
                        }
                    } else {
                        // Add jars to a list
                        IClasspathEntry[] classpathEntries = container.getClasspathEntries();
                        if (classpathEntries != null && classpathEntries.length > 0) {
                            getCompileImportsRecusively(classpathEntries, jProject, imports, false);
                        }
                    }
                } catch (CoreException e) {
                    _log.error(e.getMessage());
                    continue;
                }
                break;
            }
            case IClasspathEntry.CPE_LIBRARY: {
                // imported jars
                jarPath = PackageUtils.getAbsoluteEntryPath(entry);
                // the jar path can be null if the jar file does not exist
                if (jarPath == null) {
                    throw new CoreException(StatusFactory.createErrorStatus(
                            NLS.bind(Messages.PackagingManager_Entry_Not_Found_MSG, entry.getPath())));
                }
                if (jarPath.lastSegment().equals(IConstants.RIM_API_JAR) && needAddBBJar) {
                    needAddBBJar = false;
                }

                importedJar = null;
                if (PackagingUtils.getPackagExportedJar()) {
                    if (entry.isExported()) {
                        if (isMainProject) {
                            // if the exported jar is not in the main project but a dependent project, the classes it
                            // contains are packaged into the dependent project jar. We don't add it to classpath.
                            importedJar = new ImportedJar(jarPath.toOSString(), true,
                                    getJarFileType(jarPath.toFile()));
                        }
                    } else {
                        importedJar = new ImportedJar(jarPath.toOSString(), false,
                                getJarFileType(jarPath.toFile()));
                    }
                } else {
                    importedJar = new ImportedJar(jarPath.toOSString(), false,
                            getJarFileType(jarPath.toFile()));
                }
                if (importedJar != null && !existingJar(imports, importedJar)) {
                    imports.add(importedJar);
                }
                break;
            }
            case IClasspathEntry.CPE_PROJECT: {
                // dependency projects
                IProject project = workspaceRoot.getProject(entry.getPath().toString());
                IJavaProject javaProject = JavaCore.create(project);
                try {
                    if (project.hasNature(BlackBerryProjectCoreNature.NATURE_ID)) {
                        properties = ContextManager.PLUGIN.getBBProperties(javaProject.getProject().getName(),
                                false);
                        if (properties == null) {
                            _log.error("BlackBerry properties is null");
                            break;
                        }
                    } else {
                        properties = BlackBerryPropertiesFactory.createBlackBerryProperties(javaProject);
                    }
                } catch (CoreException e) {
                    _log.error(e.getMessage());
                    continue;
                }
                if (PackagingManager.getProjectTypeID(properties._application.getType()) == Project.LIBRARY) {
                    IPath absoluteJarPath = PackagingUtils
                            .getAbsoluteStandardOutputFilePath(new BlackBerryProject(javaProject, properties));
                    File jarFile = new File(
                            absoluteJarPath.toOSString() + IConstants.DOT_MARK + IConstants.JAR_EXTENSION);
                    importedJar = new ImportedJar(jarFile.getAbsolutePath(), false, getJarFileType(jarFile));
                    if (!existingJar(imports, importedJar)) {
                        imports.add(importedJar);
                    }
                    IClasspathEntry[] subEntries = javaProject.getRawClasspath();
                    if (subEntries != null && subEntries.length > 0) {
                        getCompileImportsRecusively(subEntries, javaProject, imports, false);
                    }
                }
                break;
            }
            case IClasspathEntry.CPE_VARIABLE: {
                // variables
                String e = entry.getPath().toString();
                int index = e.indexOf('/');
                if (index == -1) {
                    index = e.indexOf('\\');
                }
                String variable = e;
                IPath cpvar = JavaCore.getClasspathVariable(variable);
                if (cpvar == null) {
                    String msg = NLS.bind(Messages.PackagingManager_Variable_Not_Defined_MSG, variable);
                    throw new CoreException(StatusFactory.createErrorStatus(msg));
                }
                if (cpvar.lastSegment().equals(IConstants.RIM_API_JAR) && needAddBBJar) {
                    needAddBBJar = false;
                }
                // TODO RAPC does not support a class folder. We may support it later on
                if (cpvar.lastSegment().endsWith("." + IConstants.JAR_EXTENSION)) {
                    importedJar = new ImportedJar(cpvar.toOSString(), false, getJarFileType(cpvar.toFile()));
                    if (!existingJar(imports, importedJar)) {
                        imports.add(importedJar);
                    }
                }
                break;
            }
            }
        }
        if (needAddBBJar && isMainProject) {
            // insert the default BB jre lib if needed
            IVMInstall bbVM = VMUtils.getDefaultBBVM();
            if (bbVM != null) {
                LibraryLocation[] libLocations = bbVM.getLibraryLocations();
                if (libLocations != null) {
                    for (LibraryLocation location : libLocations) {
                        importedJar = new ImportedJar(location.getSystemLibraryPath().toOSString(), false,
                                getJarFileType(location.getSystemLibraryPath().toFile()));
                        if (!existingJar(imports, importedJar)) {
                            imports.add(importedJar);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        _log.error(e.getMessage());
    }
}