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:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java

License:Open Source License

public static CPListElement create(Object parent, IClasspathEntry curr, boolean newElement,
        IJavaProject project) {/*from w w w .  ja va2s.  c  o m*/
    IPath path = curr.getPath();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    // get the resource
    IResource res = null;
    boolean isMissing = false;
    IPath linkTarget = null;

    switch (curr.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        try {
            isMissing = project != null && (JavaCore.getClasspathContainer(path, project) == null);
        } catch (JavaModelException e) {
            isMissing = true;
        }
        break;
    case IClasspathEntry.CPE_VARIABLE:
        IPath resolvedPath = JavaCore.getResolvedVariablePath(path);
        isMissing = root.findMember(resolvedPath) == null && !resolvedPath.toFile().exists();
        break;
    case IClasspathEntry.CPE_LIBRARY:
        res = root.findMember(path);
        if (res == null) {
            if (!ArchiveFileFilter.isArchivePath(path, true)) {
                if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()
                        && root.getProject(path.segment(0)).exists()) {
                    res = root.getFolder(path);
                }
            }

            IPath rawPath = path;
            if (project != null) {
                IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(curr);
                if (roots.length == 1)
                    rawPath = roots[0].getPath();
            }
            isMissing = !rawPath.toFile().exists(); // look for external JARs and folders
        } else if (res.isLinked()) {
            linkTarget = res.getLocation();
        }
        break;
    case IClasspathEntry.CPE_SOURCE:
        path = path.removeTrailingSeparator();
        res = root.findMember(path);
        if (res == null) {
            if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) {
                res = root.getFolder(path);
            }
            isMissing = true;
        } else if (res.isLinked()) {
            linkTarget = res.getLocation();
        }
        break;
    case IClasspathEntry.CPE_PROJECT:
        res = root.findMember(path);
        isMissing = (res == null);
        break;
    }
    CPListElement elem = new CPListElement(parent, project, curr.getEntryKind(), path, newElement, res,
            linkTarget);
    elem.setExported(curr.isExported());
    elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath());
    elem.setAttribute(OUTPUT, curr.getOutputLocation());
    elem.setAttribute(EXCLUSION, curr.getExclusionPatterns());
    elem.setAttribute(INCLUSION, curr.getInclusionPatterns());
    elem.setAttribute(ACCESSRULES, curr.getAccessRules());
    elem.setAttribute(COMBINE_ACCESSRULES, new Boolean(curr.combineAccessRules()));

    IClasspathAttribute[] extraAttributes = curr.getExtraAttributes();
    for (int i = 0; i < extraAttributes.length; i++) {
        IClasspathAttribute attrib = extraAttributes[i];
        CPListElementAttribute attribElem = elem.findAttributeElement(attrib.getName());
        if (attribElem == null) {
            elem.createAttributeElement(attrib.getName(), attrib.getValue(), false);
        } else {
            attribElem.setValue(attrib.getValue());
        }
    }

    elem.setIsMissing(isMissing);
    return elem;
}

From source file:com.github.caofangkun.bazelipse.classpath.BazelClasspathContainer.java

License:Open Source License

private boolean isSourcePath(String path) throws JavaModelException, BackingStoreException {
    Path pp = new File(instance.getWorkspaceRoot().toString() + File.separator + path).toPath();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    for (IClasspathEntry entry : project.getRawClasspath()) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IResource res = root.findMember(entry.getPath());
            if (res != null) {
                String file = res.getLocation().toOSString();
                if (!file.isEmpty() && pp.startsWith(file)) {
                    IPath[] inclusionPatterns = entry.getInclusionPatterns();
                    if (!matchPatterns(pp, entry.getExclusionPatterns()) && (inclusionPatterns == null
                            || inclusionPatterns.length == 0 || matchPatterns(pp, inclusionPatterns))) {
                        return true;
                    }/*from  www . j a  v  a2  s .com*/
                }
            }
        }
    }
    return false;
}

From source file:com.liferay.ide.project.core.util.ProjectUtil.java

License:Open Source License

private static void fixExtProjectClasspathEntries(IProject project) {
    try {/*from   w  w  w .jav  a2  s.co m*/
        boolean fixedAttr = false;

        IJavaProject javaProject = JavaCore.create(project);

        List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();

        IClasspathEntry[] entries = javaProject.getRawClasspath();

        for (IClasspathEntry entry : entries) {
            IClasspathEntry newEntry = null;

            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                List<IClasspathAttribute> newAttrs = new ArrayList<IClasspathAttribute>();

                IClasspathAttribute[] attrs = entry.getExtraAttributes();

                if (!CoreUtil.isNullOrEmpty(attrs)) {
                    for (IClasspathAttribute attr : attrs) {
                        IClasspathAttribute newAttr = null;

                        if ("owner.project.facets".equals(attr.getName()) && //$NON-NLS-1$
                                "liferay.plugin".equals(attr.getValue())) //$NON-NLS-1$
                        {
                            newAttr = JavaCore.newClasspathAttribute(attr.getName(), "liferay.ext"); //$NON-NLS-1$
                            fixedAttr = true;
                        } else {
                            newAttr = attr;
                        }

                        newAttrs.add(newAttr);
                    }

                    newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                            entry.getExclusionPatterns(), entry.getOutputLocation(),
                            newAttrs.toArray(new IClasspathAttribute[0]));
                }
            }

            if (newEntry == null) {
                newEntry = entry;
            }

            newEntries.add(newEntry);
        }

        if (fixedAttr) {
            IProgressMonitor monitor = new NullProgressMonitor();

            javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), monitor);

            try {
                javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
            } catch (Exception e) {
                ProjectCore.logError(e);
            }
        }

        fixExtProjectSrcFolderLinks(project);
    } catch (Exception ex) {
        ProjectCore.logError("Exception trying to fix Ext project classpath entries.", ex); //$NON-NLS-1$
    }
}

From source file:de.ovgu.featureide.ahead.actions.FeatureHouseToAHEADConversion.java

License:Open Source License

/**
 * Set the source path of given <code>ClasspathEntry</code> to the current build path
 * @param e The entry to set//w w  w . ja v  a  2s. c o  m
 * @return The entry with the new source path
 */
public IClasspathEntry setSourceEntry(IClasspathEntry e) {
    return new ClasspathEntry(e.getContentKind(), e.getEntryKind(),
            featureProject.getBuildFolder().getFullPath(), e.getInclusionPatterns(), e.getExclusionPatterns(),
            e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(),
            e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes());
}

From source file:de.ovgu.featureide.aspectj.AspectJComposer.java

License:Open Source License

/**
 * Set the unselected aspect files to be excluded
 * @param e The ClasspathEntry to set//from  w  w  w  .ja  va  2 s . c  o  m
 * @return The set entry
 */
private IClasspathEntry setSourceEntry(IClasspathEntry e) {
    IPath[] excludedAspects = new IPath[unSelectedFeatures.size()];
    int i = 0;
    for (String f : unSelectedFeatures) {
        excludedAspects[i++] = new Path(f.replaceAll("_", "/") + ".aj");
    }
    return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), e.getPath(), e.getInclusionPatterns(),
            excludedAspects, e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(),
            e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes());
}

From source file:de.ovgu.featureide.core.builder.ComposerExtensionClass.java

License:Open Source License

/**
 * Set the source path of the given <code>ClasspathEntry</code>
 * @param buildPath The new build path/*from  www .  j  a  v  a 2s. c  om*/
 * @param e The entry to set
 * @return The entry with the new source path
 */
public IClasspathEntry setSourceEntry(String buildPath, IClasspathEntry e) {
    return new ClasspathEntry(e.getContentKind(), e.getEntryKind(), new Path(buildPath),
            e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(),
            e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(),
            e.getExtraAttributes());
}

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  w w.j  a  v a 2  s .c  om
        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.  j a  v  a 2  s .com*/
        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
 *//*w  w  w.j a va2 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 w w .  ja  v a2  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);
    }
}