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.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.
 */// ww w.j  a va 2  s .c  o 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.grails.ide.eclipse.commands.test.GrailsCommandUtilTest.java

License:Open Source License

private void assertExclusions(IClasspathEntry entry, String... expecteds) {
    IPath[] actuals = entry.getExclusionPatterns();
    String[] actualStr = new String[actuals.length];
    for (int i = 0; i < actualStr.length; i++) {
        actualStr[i] = actuals[i].toString();
    }/* ww  w.j a  v a 2 s.  c o  m*/
    Arrays.sort(actualStr);
    Arrays.sort(expecteds);
    assertArrayEquals(expecteds, actualStr);
}

From source file:org.grails.ide.eclipse.commands.test.GrailsCommandUtilTest.java

License:Open Source License

private void assertNoExclusions(IClasspathEntry entry) {
    IPath[] exclusions = entry.getExclusionPatterns();
    if (exclusions == null || exclusions.length == 0) {
        return; //OK
    } else { //Problem
        StringBuilder msg = new StringBuilder("Expected no exclusions but found:\n");
        for (IPath iPath : exclusions) {
            msg.append(iPath + "\n");
        }//from   ww  w  . j  a  v a 2 s  .  c om
        fail(msg.toString());
    }
}

From source file:org.gw4e.eclipse.facade.ClasspathManager.java

License:Open Source License

/**
 * Manage source folders exclusion/* ww w . ja  v a  2  s  .co m*/
 * 
 * @param project
 * @param rootSrcEntry
 * @param relative
 * @return
 * @throws JavaModelException
 */
private static IClasspathEntry ensureExcludedPath(IProject project, IClasspathEntry rootSrcEntry,
        String relative) throws JavaModelException {
    if (rootSrcEntry == null)
        return rootSrcEntry;
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    IPath[] excluded = rootSrcEntry.getExclusionPatterns();
    boolean entryFound = false;
    for (int i = 0; i < excluded.length; i++) {
        if (excluded[i].toString().equalsIgnoreCase(relative)) {
            entryFound = true;
            break;
        }
    }
    if (!entryFound) {
        IPath rootSrcPath = javaProject.getPath().append("src");
        IPath[] newEntries = new IPath[excluded.length + 1];
        System.arraycopy(excluded, 0, newEntries, 0, excluded.length);
        newEntries[excluded.length] = new Path(relative);
        rootSrcEntry = JavaCore.newSourceEntry(rootSrcPath, newEntries);
        entries = javaProject.getRawClasspath();
        List<IClasspathEntry> temp = new ArrayList<IClasspathEntry>();
        temp.add(rootSrcEntry);
        for (int i = 0; i < entries.length; i++) {
            if (!(entries[i].getPath().equals(rootSrcPath))) {
                temp.add(entries[i]);
            }
        }
        IClasspathEntry[] array = new IClasspathEntry[temp.size()];
        temp.toArray(array);
        javaProject.setRawClasspath(array, null);
    }
    return rootSrcEntry;
}

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 ww  .j  av a2s  .  co  m
            newEntriesList.add(entry);
        }
    }

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

From source file:org.sonar.ide.eclipse.internal.jdt.JavaProjectConfigurator.java

License:Open Source License

/**
 * Allows to determine directories with resources to exclude them from analysis, otherwise analysis might fail due to SONAR-791.
 * This is a kind of workaround, which is based on the fact that M2Eclipse configures exclusion pattern "**" for directories with resources.
 *///w  w  w  .j  a  v a 2 s. c  o  m
private boolean isSourceExcluded(IClasspathEntry entry) {
    IPath[] exclusionPatterns = entry.getExclusionPatterns();
    if (exclusionPatterns != null) {
        for (IPath exclusionPattern : exclusionPatterns) {
            if ("**".equals(exclusionPattern.toString())) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.sonarlint.eclipse.jdt.internal.JavaProjectConfigurator.java

License:Open Source License

/**
 * Allows to determine directories with resources to exclude them from analysis, otherwise analysis might fail due to SONAR-791.
 * This is a kind of workaround, which is based on the fact that M2Eclipse configures exclusion pattern "**" for directories with resources.
 *//*from   ww w  . j ava 2s. co m*/
private static boolean isSourceExcluded(IClasspathEntry entry) {
    IPath[] exclusionPatterns = entry.getExclusionPatterns();
    if (exclusionPatterns != null) {
        for (IPath exclusionPattern : exclusionPatterns) {
            if ("**".equals(exclusionPattern.toString())) {
                return true;
            }
        }
    }
    return false;
}

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.
 */// w ww .  j a v  a2s . c  om
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);
    }
}

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

License:Open Source License

/** 
 * Import preserves existing source folder exclusion filters?
 *//* w  ww  .  j  ava  2 s .  c  o  m*/
public void testSTS2205PreserveSourceFolderExclusions() throws Exception {
    String projectName = "sts_2205";
    File projectLoc = getTestProjectCopy(projectName);
    GradleImportOperation importOp = importTestProjectOperation(projectLoc);

    //Check that the import operation has the expected default options
    assertTrue(importOp.getDoBeforeTasks());
    assertTrue(importOp.getDoAfterTasks());
    assertArrayEquals(new String[] { "cleanEclipse", "eclipse" }, importOp.getBeforeTasks());
    assertArrayEquals(new String[] { "afterEclipseImport" }, importOp.getAfterTasks());

    importOp.perform(defaultTestErrorHandler(), new NullProgressMonitor());
    assertProjects(projectName);

    //Check expected source folder has expected exclusions
    GradleProject gp = getGradleProject(projectName);
    ClassPath classpath = gp.getClassPath();
    IClasspathEntry[] srcFolders = classpath.getSourceFolders();
    assertEquals("Source folder count", 1, srcFolders.length);
    IClasspathEntry entry = srcFolders[0];
    IPath[] exclusions = entry.getExclusionPatterns();
    assertArrayEquals(new IPath[] { new Path("testb2/**/*") }, exclusions);
}