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

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

Introduction

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

Prototype

IPath[] getInclusionPatterns();

Source Link

Document

Returns the set of patterns used to explicitly define resources or classes to be included with this classpath entry.

Usage

From source file:org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor.java

License:Open Source License

private void setClasspathEntry(IClasspathEntry entry) {
    this.entryKind = entry.getEntryKind();
    this.path = entry.getPath();
    this.exported = entry.isExported();
    this.outputLocation = entry.getOutputLocation();

    this.accessRules = new ArrayList<IAccessRule>();
    for (IAccessRule rule : entry.getAccessRules()) {
        this.accessRules.add(rule);
    }/*  ww w  .  j  av  a  2 s  .c  om*/

    this.attributes = new LinkedHashMap<String, String>();
    for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
        attributes.put(attribute.getName(), attribute.getValue());
    }

    this.sourceAttachmentPath = entry.getSourceAttachmentPath();
    this.sourceAttachmentRootPath = entry.getSourceAttachmentRootPath();
    setInclusionPatterns(entry.getInclusionPatterns());
    setExclusionPatterns(entry.getExclusionPatterns());
    this.combineAccessRules = entry.combineAccessRules();
}

From source file:org.eclipse.m2e.tests.BuildPathManagerTest.java

License:Open Source License

public void testMNGECLIPSE_696_compiler_includes_excludes() throws Exception {
    final String projectName = "MNGECLIPSE-696";

    deleteProject(projectName);//from   w  w  w.j  a  va  2s  .  c  o  m

    final ResolverConfiguration configuration = new ResolverConfiguration();
    final IProject project = importProject("projects/" + projectName + "/pom.xml", configuration);
    waitForJobsToComplete();

    WorkspaceHelpers.assertNoErrors(project);

    final IJavaProject javaProject = JavaCore.create(project);
    final IClasspathEntry[] cp = javaProject.getRawClasspath();
    final IClasspathEntry cpMain = cp[0];
    final IClasspathEntry cpTest = cp[1];

    assertEquals(new Path("/" + projectName + "/src/main/java"), cpMain.getPath());
    assertEquals(new Path("/" + projectName + "/src/test/java"), cpTest.getPath());

    final IPath[] inclusionsMain = cpMain.getInclusionPatterns();
    assertEquals(2, inclusionsMain.length);
    assertEquals(new Path("org/apache/maven/"), inclusionsMain[0]);
    assertEquals(new Path("org/maven/ide/eclipse/"), inclusionsMain[1]);

    final IPath[] exclusionsMain = cpMain.getExclusionPatterns();
    assertEquals(1, exclusionsMain.length);
    assertEquals(new Path("org/maven/ide/eclipse/tests/"), exclusionsMain[0]);

    final IPath[] inclusionsTest = cpTest.getInclusionPatterns();
    assertEquals(1, inclusionsTest.length);
    assertEquals(new Path("org/apache/maven/tests/"), inclusionsTest[0]);

    final IPath[] exclusionsTest = cpTest.getExclusionPatterns();
    assertEquals(1, exclusionsTest.length);
    assertEquals(new Path("org/apache/maven/tests/Excluded.java"), exclusionsTest[0]);
}

From source file:org.eclipse.virgo.ide.jdt.internal.ui.properties.TestSourceFolderPreferencePage.java

License:Open Source License

public boolean performOk() {
    if (!modified) {
        return true;
    }/*from  w  ww  . ja  v a 2 s. c o m*/

    try {
        List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry entry : JavaCore.create(project).getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                Set<IClasspathAttribute> attrs = new HashSet<IClasspathAttribute>();
                for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                    if (!attr.getName().equals(ServerModuleDelegate.TEST_CLASSPATH_ENTRY_ATTRIBUTE)) {
                        attrs.add(attr);
                    }
                }
                attrs.add(getClasspathAttribute(entry));

                entries.add(JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                        entry.getExclusionPatterns(), entry.getOutputLocation(),
                        (IClasspathAttribute[]) attrs.toArray(new IClasspathAttribute[attrs.size()])));
            } else {
                entries.add(entry);
            }
        }

        JavaCore.create(project).setRawClasspath(
                (IClasspathEntry[]) entries.toArray(new IClasspathEntry[entries.size()]),
                new NullProgressMonitor());
    } catch (JavaModelException e) {
    }

    return true;
}

From source file:org.eclipse.virgo.ide.pde.core.internal.cmd.SetupProjectOperation.java

License:Open Source License

private IPath configureWABClasspath(IProject project) throws CoreException, JavaModelException {
    IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
    javaProject.setOutputLocation(project.getFullPath().append(BIN), null);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry iClasspathEntry = entries[i];
        if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                && iClasspathEntry.getPath().lastSegment().equals(SRC)) {
            IClasspathEntry newEntry = JavaCore.newSourceEntry(iClasspathEntry.getPath(),
                    iClasspathEntry.getInclusionPatterns(), iClasspathEntry.getExclusionPatterns(),
                    project.getFullPath().append(BIN_WEB_INF_CLASSES));
            newEntries[i] = newEntry;/* www  .  j a  v  a 2  s  .  co m*/
            break;
        } else {
            newEntries[i] = entries[i];
        }
    }

    IPath webContentPath = project.getFullPath().append(WEB_CONTENT_FOLDER);
    newEntries[entries.length] = JavaCore.newLibraryEntry(webContentPath, null, null);

    javaProject.setRawClasspath(newEntries, null);
    return webContentPath;
}

From source file:org.eclipse.xtext.builder.JDTAwareEclipseResourceFileSystemAccess2.java

License:Open Source License

/**
 * @param prototype settings will be copied from the prototype and the new entry is inserted after that one.
 *//*from   w  ww. j  ava  2s  .  co m*/
private void insertClasspathEntry(IContainer folder, IClasspathEntry prototype, IJavaProject project)
        throws JavaModelException {
    IClasspathEntry newEntry = JavaCore.newSourceEntry(folder.getFullPath(), prototype.getInclusionPatterns(),
            prototype.getExclusionPatterns(), prototype.getOutputLocation(), prototype.getExtraAttributes());
    IClasspathEntry[] classPath = project.getRawClasspath();
    IClasspathEntry[] newClassPath = new IClasspathEntry[classPath.length + 1];
    int i = 0;
    for (IClasspathEntry entry : classPath) {
        newClassPath[i++] = entry;
        if (entry.equals(prototype)) {
            newClassPath[i++] = newEntry;
        }
    }
    // should not happen, but to be sure
    if (i == newClassPath.length - 1 && newClassPath[i] == null) {
        LOG.warn("Cannot find classpath entry '" + prototype + "'");
        newClassPath[i] = newEntry;
    }
    project.setRawClasspath(newClassPath, getMonitor());
}

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

License:Open Source License

private void removeExclusionPatterns(IJavaProject javaProject, IProgressMonitor monitor)
        throws JavaModelException {
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    ArrayList<IClasspathEntry> newEntriesList = new ArrayList<IClasspathEntry>(entries.length);
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath[] newExclusionPatterns = getExclusionPatterns(entry.getExclusionPatterns());
            IClasspathEntry newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                    newExclusionPatterns, entry.getOutputLocation(), entry.getExtraAttributes());
            newEntriesList.add(newEntry);
        } else {/*from  w w w .j a v  a2  s .c  om*/
            newEntriesList.add(entry);
        }
    }

    IClasspathEntry[] newEntries = new IClasspathEntry[newEntriesList.size()];
    newEntriesList.toArray(newEntries);
    javaProject.setRawClasspath(newEntries, monitor);
}

From source file:org.springsource.ide.eclipse.gradle.core.GradleProject.java

License:Open Source License

/**
 * Create an Eclipse source classpath entry from a Gradle source entry. May return null
 * if the entry looks invalid (e.g. the corresponding folder doesn't exist in the project)
 * @param oldEntries old source entries indexed by path, used to copy over exclusions and inclusions so they don't get lost.
 *///from   w  w w. ja v a 2 s .com
private IClasspathEntry newSourceEntry(EclipseSourceDirectory gradleSourceDir,
        Map<IPath, IClasspathEntry> oldEntries) throws IllegalClassPathEntryException {
    Path gradleSourcePath = new Path(gradleSourceDir.getPath());
    try {
        IFolder srcFolder = getProject().getFolder(gradleSourcePath);
        if (!srcFolder.exists()) {
            throw new IllegalClassPathEntryException("non-existent source folder", this, gradleSourceDir);
        }
        IPath path = srcFolder.getFullPath();
        IClasspathEntry oldEntry = oldEntries.get(path);
        if (oldEntry == null) {
            return JavaCore.newSourceEntry(path);
        } else {
            return JavaCore.newSourceEntry(path, oldEntry.getInclusionPatterns(),
                    oldEntry.getExclusionPatterns(), oldEntry.getOutputLocation(),
                    oldEntry.getExtraAttributes());
        }
    } catch (IllegalClassPathEntryException e) {
        throw e;
    } catch (Throwable e) {
        throw new IllegalClassPathEntryException("illegal source folder", this, gradleSourceDir, e);
    }
}