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

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

Introduction

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

Prototype

IAccessRule[] getAccessRules();

Source Link

Document

Returns the possibly empty list of access rules for this entry.

Usage

From source file:org.jboss.tools.common.jdt.core.buildpath.MaterializeLibraryJob.java

License:Open Source License

private IClasspathEntry getNewClasspathEntry(IClasspathEntry entry, IPath destinationFilePath)
        throws CoreException {
    try {/*from   w ww  .j  a  v a  2 s . co m*/
        return JavaCore.newLibraryEntry(destinationFilePath,
                (keepSourceAttachments) ? entry.getSourceAttachmentPath() : null,
                (keepSourceAttachments) ? entry.getSourceAttachmentRootPath() : null, entry.getAccessRules(),
                entry.getExtraAttributes(), entry.isExported());
    } catch (Exception e) {
        IStatus status = new Status(IStatus.ERROR, JDTExtActivator.PLUGIN_ID,
                NLS.bind(Messages.MaterializeLibraryJob_Error_creating_classpath_entry, e.getMessage()), e);
        throw new CoreException(status);
    }
}

From source file:org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.java

License:Open Source License

public static boolean removeReferencedLibrarySourceAttachment(IJavaProject javaProject, String name,
        IProgressMonitor progressMonitor)
        throws OperationCanceledException, CoreException, InterruptedException {
    IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
    boolean found = false;
    for (int i = 0; i < classpathEntries.length; i++) {
        IClasspathEntry classpathEntry = classpathEntries[i];
        IPath path = classpathEntry.getPath();
        if (path.toFile().getAbsolutePath().contains(name)) {
            if (!path.isAbsolute()) {
                path = JavaCore.getClasspathVariable("M2_REPO")
                        .append(path.makeRelativeTo(new Path("M2_REPO")));
            }/*from  www  .j  a v  a2  s  . co  m*/
            classpathEntries[i] = JavaCore.newLibraryEntry(path, null, null, classpathEntry.getAccessRules(),
                    classpathEntry.getExtraAttributes(), classpathEntry.isExported());
            found = true;
        }
    }
    javaProject.setRawClasspath(classpathEntries, progressMonitor);
    // refresh/build project
    WorkbenchTasks.buildProject(javaProject.getProject(), progressMonitor);
    return found;
}

From source file:org.maven.ide.eclipse.scala.ScalaProjectConfigurator.java

License:Open Source License

private static void addDeployableAttribute(IJavaProject javaProject, IClasspathAttribute deployableAttribute,
        IProgressMonitor monitor) throws JavaModelException, CoreException {
    if (javaProject == null)
        return;//from   ww  w . jav  a 2 s . c om
    ClasspathContainerInitializer scalaInitializer = JavaCore
            .getClasspathContainerInitializer(SCALA_CONTAINER_PATH);
    if (scalaInitializer == null)
        return;
    IPath scalaContainerPath = Path.fromPortableString(SCALA_CONTAINER_PATH);
    Boolean updateAble = scalaInitializer.canUpdateClasspathContainer(scalaContainerPath, javaProject);
    final IClasspathContainer scalaLibrary = JavaCore.getClasspathContainer(scalaContainerPath, javaProject);
    final IClasspathEntry[] cpEntries = scalaLibrary.getClasspathEntries();

    for (int i = 0; i < cpEntries.length; i++) {
        IClasspathEntry cpe = cpEntries[i];
        LinkedHashMap<String, IClasspathAttribute> attrs = new LinkedHashMap<String, IClasspathAttribute>();
        for (IClasspathAttribute attr : cpe.getExtraAttributes()) {
            //Keep all existing attributes except the non_deployable key
            if (!attr.getName().equals(NON_DEPLOYABLE_KEY)) {
                attrs.put(attr.getName(), attr);
            }
        }
        attrs.put(deployableAttribute.getName(), deployableAttribute);
        IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]);
        cpEntries[i] = JavaCore.newLibraryEntry(cpe.getPath(), cpe.getSourceAttachmentPath(),
                cpe.getSourceAttachmentRootPath(), cpe.getAccessRules(), newAttrs, cpe.isExported());
    }

    IClasspathContainer candidateScalaContainer = new IClasspathContainer() {
        public IPath getPath() {
            return scalaLibrary.getPath();
        }

        public IClasspathEntry[] getClasspathEntries() {
            return cpEntries;
        }

        public String getDescription() {
            return scalaLibrary.getDescription();
        }

        public int getKind() {
            return scalaLibrary.getKind();
        }
    };

    if (updateAble) {
        scalaInitializer.requestClasspathContainerUpdate(scalaContainerPath, javaProject,
                candidateScalaContainer);
    } else {
        IJavaProject[] jPArray = { javaProject };
        IClasspathContainer[] cpArray = { candidateScalaContainer };
        JavaCore.setClasspathContainer(scalaContainerPath, jPArray, cpArray, null);
    }
}

From source file:org.springsource.ide.eclipse.commons.frameworks.core.legacyconversion.LegacyProjectConverter.java

License:Open Source License

private static void convertGradleProject(IProject project, SubMonitor sub) throws Exception {
    // nature/* w  w w . j a v  a2 s  .  co m*/
    IProjectDescription description = project.getDescription();
    String[] ids = description.getNatureIds();
    List<String> newIds = new ArrayList<String>(ids.length);
    for (int i = 0; i < ids.length; i++) {
        if (!ids[i].equals(GRADLE_OLD_NATURE) && !ids[i].equals(GRADLE_NEW_NATURE)) {
            newIds.add(ids[i]);
        } else {
            newIds.add(GRADLE_NEW_NATURE);
        }
    }
    description.setNatureIds(newIds.toArray(new String[0]));
    project.setDescription(description, sub);

    // project preferences
    // DO NOTHING: gradle tooling handles these itself by reading in both old and new locations.

    // classpath container
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>();
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            String path = entry.getPath().toString();
            if (path.contains(GRADLE_OLD_PREFIX)) {
                entry = JavaCore.newContainerEntry(new Path(path.replace(GRADLE_OLD_PREFIX, GRADLE_NEW_PREFIX)),
                        entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
            }
        }
        newClasspath.add(entry);
    }
    javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[0]), sub);
}

From source file:org.talend.designer.maven.tools.creator.CreateMavenCodeProject.java

License:Open Source License

public static void changeClasspath(IProgressMonitor monitor, IProject p) {
    try {/*from w  w w  . j  av  a2 s .  c  o  m*/
        IJavaProject javaProject = JavaCore.create(p);
        IClasspathEntry[] rawClasspathEntries = javaProject.getRawClasspath();
        boolean changed = false;

        for (int index = 0; index < rawClasspathEntries.length; index++) {
            IClasspathEntry entry = rawClasspathEntries[index];

            IClasspathEntry newEntry = null;
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = entry.getPath();
                if (p.getFullPath().isPrefixOf(path)) {
                    path = path.removeFirstSegments(1);
                }

                // src/main/resources, in order to removing the 'excluding="**"'.
                if (MavenSystemFolders.RESOURCES.getPath().equals(path.toString())) {
                    newEntry = JavaCore.newSourceEntry(entry.getPath(), new IPath[0], new IPath[0], //
                            entry.getOutputLocation(), entry.getExtraAttributes());
                }

                // src/test/resources, in order to removing the 'excluding="**"'.
                if (MavenSystemFolders.RESOURCES_TEST.getPath().equals(path.toString())) {
                    newEntry = JavaCore.newSourceEntry(entry.getPath(), new IPath[0], new IPath[0], //
                            entry.getOutputLocation(), entry.getExtraAttributes());
                }

            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                // remove the special version of jre in container.
                IPath defaultJREContainerPath = JavaRuntime.newDefaultJREContainerPath();
                if (defaultJREContainerPath.isPrefixOf(entry.getPath())) {
                    // JavaRuntime.getDefaultJREContainerEntry(); //missing properties
                    newEntry = JavaCore.newContainerEntry(defaultJREContainerPath, entry.getAccessRules(),
                            entry.getExtraAttributes(), entry.isExported());
                }
            }
            if (newEntry != null) {
                rawClasspathEntries[index] = newEntry;
                changed = true;
            }

        }
        if (changed) {
            javaProject.setRawClasspath(rawClasspathEntries, monitor);
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}

From source file:org.talend.designer.maven.utils.MavenProjectUtils.java

License:Open Source License

public static void changeClasspath(IProgressMonitor monitor, IProject p, ProjectSystemFolder[] folders) {
    try {//w w  w  .  j  a  va 2  s .co  m
        if (!p.hasNature(JavaCore.NATURE_ID)) {
            JavaUtils.addJavaNature(p, monitor);
        }
        IJavaProject javaProject = JavaCore.create(p);
        IClasspathEntry[] rawClasspathEntries = javaProject.getRawClasspath();

        List<IClasspathEntry> list = new LinkedList<>();
        ClasspathAttribute attribute = new ClasspathAttribute("maven.pomderived", Boolean.TRUE.toString());
        for (ProjectSystemFolder psf : folders) {
            IFolder resources = p.getFolder(psf.getPath());
            if (resources.exists()) { // add the condition mostly for routines, since the resources folder might not exist
                IFolder output = p.getFolder(psf.getOutputPath());
                IClasspathEntry newEntry = JavaCore.newSourceEntry(resources.getFullPath(), new IPath[0],
                        new IPath[0], output.getFullPath(), new IClasspathAttribute[] { attribute });
                list.add(newEntry);
            }
        }
        IPath defaultJREContainerPath = JavaRuntime.newDefaultJREContainerPath();

        IClasspathEntry newEntry = JavaCore.newContainerEntry(defaultJREContainerPath, new IAccessRule[] {},
                new IClasspathAttribute[] { attribute }, false);
        list.add(newEntry);

        newEntry = JavaCore.newContainerEntry(new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"),
                newEntry.getAccessRules(), new IClasspathAttribute[] { attribute }, newEntry.isExported());
        list.add(newEntry);

        if (!Arrays.equals(rawClasspathEntries, list.toArray(new IClasspathEntry[] {}))
                || !p.getFile(".classpath").exists()) {
            rawClasspathEntries = list.toArray(new IClasspathEntry[] {});
            javaProject.setRawClasspath(rawClasspathEntries, monitor);
            javaProject.setOutputLocation(p.getFolder(MavenSystemFolders.JAVA.getOutputPath()).getFullPath(),
                    monitor);
        }
    } catch (

    CoreException e) {
        ExceptionHandler.process(e);
    }
}