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

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

Introduction

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

Prototype

IPath[] getExclusionPatterns();

Source Link

Document

Returns the set of patterns used to exclude resources or classes associated with this classpath entry.

Usage

From source file:org.eclipse.imp.java.hosted.BuildPathUtils.java

License:Open Source License

/**
 * @param filePath/*from   ww w. j a  v a 2 s.  co m*/
 * @param srcEntry
 * @return true if the given file is excluded from the given IClasspathEntry
 */
public static boolean isExcluded(final IPath filePath, final IClasspathEntry srcEntry) {
    final IPath relFilePath = filePath.makeRelativeTo(srcEntry.getPath());
    final IPath[] inclusionPatterns = srcEntry.getInclusionPatterns();
    if (inclusionPatterns != null && inclusionPatterns.length != 0) {
        boolean foundMatch = false;
        for (IPath pattern : inclusionPatterns) {
            if (matches(relFilePath, pattern)) {
                foundMatch = true;
                break;
            }
        }
        if (!foundMatch) {
            return true;
        }
    }
    final IPath[] exclusionPatterns = srcEntry.getExclusionPatterns();
    if (exclusionPatterns != null && exclusionPatterns.length != 0) {
        for (IPath pattern : exclusionPatterns) {
            if (matches(relFilePath, pattern)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.eclipse.jst.common.project.facet.core.internal.ClasspathUtil.java

License:Open Source License

private static IClasspathEntry setOwners(final IClasspathEntry cpe, final String owners) {
    final List<IClasspathAttribute> attrs = new ArrayList<IClasspathAttribute>();

    for (IClasspathAttribute attr : cpe.getExtraAttributes()) {
        if (!attr.getName().equals(OWNER_PROJECT_FACETS_ATTR)) {
            attrs.add(attr);/*  www  . ja  v a2s  . c o m*/
        }
    }

    if (owners != null) {
        attrs.add(JavaCore.newClasspathAttribute(OWNER_PROJECT_FACETS_ATTR, owners));
    }

    return new ClasspathEntry(cpe.getContentKind(), cpe.getEntryKind(), cpe.getPath(),
            cpe.getInclusionPatterns(), cpe.getExclusionPatterns(), cpe.getSourceAttachmentPath(),
            cpe.getSourceAttachmentRootPath(), cpe.getOutputLocation(), cpe.isExported(), cpe.getAccessRules(),
            cpe.combineAccessRules(), attrs.toArray(new IClasspathAttribute[attrs.size()]));
}

From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java

License:Open Source License

public static IClasspathEntry modifyDependencyPath(IClasspathEntry entry, IPath dependencyPath) {
    IClasspathEntry newEntry = null;/* w w w. jav  a  2s  .  c  o  m*/
    IClasspathAttribute[] newAttributes = modifyDependencyPath(entry.getExtraAttributes(), dependencyPath);

    switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        newEntry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), newAttributes,
                entry.isExported());
        break;
    case IClasspathEntry.CPE_LIBRARY:
        newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(),
                entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported());
        break;
    case IClasspathEntry.CPE_VARIABLE:
        newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(),
                entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported());
        break;
    case IClasspathEntry.CPE_PROJECT:
        newEntry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(),
                newAttributes, entry.isExported());
        break;
    case IClasspathEntry.CPE_SOURCE:
        newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                entry.getExclusionPatterns(), entry.getOutputLocation(), newAttributes);
        break;
    }
    return newEntry;
}

From source file:org.eclipse.jst.j2ee.internal.classpathdep.UpdateClasspathAttributesOperation.java

License:Open Source License

/**
 * Updates the specified Java project so that only the specified classpath entries have
 * the WTP component dependency attribute.
 * @param javaProject Target Java project.
 * @param entries Classpath entries that should have the component dependency attribute. Map from IClasspathEntry
 * to the IClasspathAttribute for the WTP classpath component dependency.
 * @param modifyComponentDep True if modifying the dependency attribute, false if modifying the non-dependency attribute.
 * @throws CoreException Thrown if an error is encountered.
 *//*from  w  w  w  .  j a  v  a 2 s.  c  o m*/
private void updateDependencyAttributes(final IJavaProject javaProject, final Map entriesWithAttrib,
        final boolean modifyComponentDep, final boolean isLegacyJ2EE) throws CoreException {
    if (javaProject == null || !javaProject.getProject().isAccessible()) {
        return;
    }

    final List updatedClasspath = new ArrayList();
    final IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    boolean needToUpdateClasspath = false;
    IClasspathAttribute attrib = UpdateClasspathAttributeUtil.createDependencyAttribute();
    if (!modifyComponentDep) {
        attrib = UpdateClasspathAttributeUtil.createNonDependencyAttribute();
    }
    for (int i = 0; i < rawClasspath.length; i++) {
        IClasspathEntry entry = rawClasspath[i];
        final int kind = entry.getEntryKind();
        boolean hasAttribute = ClasspathDependencyUtil
                .checkForComponentDependencyAttribute(entry,
                        modifyComponentDep ? DependencyAttributeType.CLASSPATH_COMPONENT_DEPENDENCY
                                : DependencyAttributeType.CLASSPATH_COMPONENT_NONDEPENDENCY,
                        isLegacyJ2EE) != null;
        boolean shouldHaveAttribute = entriesWithAttrib.containsKey(entry);
        boolean updateAttributes = false;
        IClasspathAttribute[] updatedAttributes = null;
        if (shouldHaveAttribute) {
            if (!hasAttribute) {
                // should have the attribute and currently missing it
                attrib = (IClasspathAttribute) entriesWithAttrib.get(entry);
                updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, true);
                needToUpdateClasspath = true;
                updateAttributes = true;
            }
        } else if (hasAttribute) {
            // should not have the attribute and currently has it
            updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, false);
            needToUpdateClasspath = true;
            updateAttributes = true;
        }

        if (updateAttributes) {
            switch (kind) {
            case IClasspathEntry.CPE_CONTAINER:
                entry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), updatedAttributes,
                        entry.isExported());
                break;
            case IClasspathEntry.CPE_LIBRARY:
                entry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(),
                        entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes,
                        entry.isExported());
                break;
            case IClasspathEntry.CPE_VARIABLE:
                entry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(),
                        entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes,
                        entry.isExported());
                break;
            case IClasspathEntry.CPE_PROJECT: // although project entries are not yet supported, allow the attribute here and let the validator flag as an error
                entry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(),
                        entry.combineAccessRules(), updatedAttributes, entry.isExported());
                break;
            case IClasspathEntry.CPE_SOURCE: // although source entries are not supported, allow the attribute here and let the validator flag as an error
                entry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                        entry.getExclusionPatterns(), entry.getOutputLocation(), updatedAttributes);
                break;
            }
        }

        updatedClasspath.add(entry);
    }
    if (needToUpdateClasspath) {
        final IClasspathEntry[] updatedCPArray = (IClasspathEntry[]) updatedClasspath
                .toArray(new IClasspathEntry[updatedClasspath.size()]);
        javaProject.setRawClasspath(updatedCPArray, null);
    }
}

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);
    }// w w  w .j av  a2  s .c  o m

    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 . ja  va  2 s  . c  om

    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.m2e.tests.ProjectConfigurationManagerTest.java

License:Open Source License

public void test447460MultipleUpdateConfiguration() throws Exception {
    // the project import already performs a configuration !!!
    IProject project = importProject("projects/447460_MultipleUpdateConfiguration/pom.xml");
    IJavaProject javaProject = JavaCore.create(project);
    // check whether everything has been imported correctly
    List<IClasspathEntry> cpEntries = filterClasspath(javaProject.getRawClasspath(),
            IClasspathEntry.CPE_SOURCE);
    assertNotNull(cpEntries);/*ww w . j  ava2  s.c o m*/
    assertEquals("Invalid number of classpath entries", 4, cpEntries.size());
    for (IClasspathEntry cpEntry : cpEntries) {
        String[] path = cpEntry.getPath().segments();
        if ("java".equals(path[path.length - 1])) {
            // sources
            IPath[] exclusions = cpEntry.getExclusionPatterns();
            assertNotNull(exclusions);
            assertEquals("Classpath source entry isn't supposed to contain any exclusion pattern.", 0,
                    exclusions.length);
        } else {
            // resources
            IPath[] exclusions = cpEntry.getExclusionPatterns();
            assertNotNull(exclusions);
            assertEquals("Classpath resource entry contains more or less than one exclusion pattern.", 1,
                    exclusions.length);
            assertEquals("Exclusion pattern is supposed to be '**' !", new Path("**"), exclusions[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 va  2s .com

    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;/*from   w  w  w  .jav a2s . c o  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.xtend.ide.XtendResourceUiServiceProvider.java

License:Open Source License

private char[][] getExclusionPatterns(IClasspathEntry entry) {
    if (entry instanceof ClasspathEntry) {
        ClasspathEntry classpathEntry = (ClasspathEntry) entry;
        return classpathEntry.fullExclusionPatternChars();
    }/*from w w  w  . jav  a  2 s  . com*/
    return toFullPatternChars(entry, entry.getExclusionPatterns());
}