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:de.ovgu.featureide.aspectj.AspectJComposer.java

License:Open Source License

/**
 * Set the unselected aspect files to be excluded
 * @param e The ClasspathEntry to set//  www .j  a va2 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//  www.j  a  va  2s. c o m
 * @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 a2 s .  com*/
        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 {/*  w w  w .ja v a2 s  .c  om*/
        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 ww.  j ava2  s  .c om
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 ww  w .j  av a2s.  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);
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private void updatePathElement(List<IClasspathEntry> ents, Element xml) {
    IClasspathEntry oent = null;
    int id = IvyXml.getAttrInt(xml, "ID", 0);
    if (id != 0) {
        for (IClasspathEntry ent : ents) {
            if (ent.hashCode() == id) {
                oent = ent;//w w w  .  jav a  2 s. c  om
                break;
            }
        }
    }

    BedrockPlugin.logD("UPDATE PATH ELEMENT " + oent + " " + IvyXml.convertXmlToString(xml));

    if (IvyXml.getAttrString(xml, "TYPE").equals("LIBRARY")) {
        if (IvyXml.getAttrBool(xml, "DELETE")) {
            ents.remove(oent);
        } else if (IvyXml.getAttrBool(xml, "MODIFIED") || IvyXml.getAttrBool(xml, "NEW")) {
            String f = IvyXml.getTextElement(xml, "BINARY");
            IPath bin = (f == null ? null : Path.fromOSString(f));
            f = IvyXml.getTextElement(xml, "SOURCE");
            IPath src = (f == null ? null : Path.fromOSString(f));
            boolean optfg = IvyXml.getAttrBool(xml, "OPTIONAL");
            boolean export = IvyXml.getAttrBool(xml, "EXPORTED");
            IAccessRule[] rls = null;
            URL docu = null;
            String doc = IvyXml.getTextElement(xml, "JAVADOC");
            if (doc != null) {
                try {
                    docu = new URL(doc);
                } catch (MalformedURLException e) {
                }
                if (docu == null) {
                    try {
                        docu = new URL("file://" + doc);
                    } catch (MalformedURLException e) {
                    }
                }
            }
            if (oent != null) {
                rls = oent.getAccessRules();
            }

            IClasspathAttribute[] xatts = null;
            List<IClasspathAttribute> els = new ArrayList<IClasspathAttribute>();
            if (optfg)
                els.add(JavaCore.newClasspathAttribute(IClasspathAttribute.OPTIONAL, "true"));
            if (docu != null) {
                els.add(JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                        docu.toString()));
            }
            if (!els.isEmpty()) {
                xatts = new IClasspathAttribute[els.size()];
                xatts = els.toArray(xatts);
            }

            IClasspathEntry nent = null;
            if (bin != null)
                nent = JavaCore.newLibraryEntry(bin, src, null, rls, xatts, export);
            else
                nent = JavaCore.newSourceEntry(src, null, null, null, xatts);

            if (IvyXml.getAttrBool(xml, "MODIFIED") && oent != null) {
                int idx = ents.indexOf(oent);
                ents.set(idx, nent);
            } else {
                ents.add(nent);
            }
        }
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private void addPath(IvyXmlWriter xw, IJavaProject jp, IClasspathEntry ent, boolean nest) {
    IPath p = ent.getPath();/*from ww  w  .  ja  v  a2  s  .  co  m*/
    IPath op = ent.getOutputLocation();
    IPath sp = ent.getSourceAttachmentPath();
    IProject ip = jp.getProject();

    String jdp = null;
    boolean opt = false;
    IClasspathAttribute[] atts = ent.getExtraAttributes();
    for (IClasspathAttribute att : atts) {
        if (att.getName().equals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME))
            jdp = att.getValue();
        else if (att.getName().equals(IClasspathAttribute.OPTIONAL)) {
            String v = att.getValue();
            if (v.equals("true"))
                opt = true;
        }
    }

    if (p == null && op == null)
        return;
    File f1 = null;
    if (p != null) {
        f1 = BedrockUtil.getFileForPath(p, ip);
        if (!f1.exists()) {
            BedrockPlugin.logD("Path file " + p + " not found as " + f1);
            // f1 = null;
        }
    }
    File f2 = null;
    if (op != null) {
        f2 = BedrockUtil.getFileForPath(op, ip);
        if (!f2.exists()) {
            BedrockPlugin.logD("Path file " + op + " not found");
            f2 = null;
        }
    }
    File f3 = null;
    if (sp != null) {
        f3 = BedrockUtil.getFileForPath(sp, ip);
        if (!f3.exists()) {
            BedrockPlugin.logD("Path file " + sp + " not found");
            f3 = null;
        }
    }
    if (f1 == null && f2 == null)
        return;

    // references to nested projects are handled in addClassPaths
    if (ent.getEntryKind() == IClasspathEntry.CPE_PROJECT)
        return;

    xw.begin("PATH");
    xw.field("ID", ent.hashCode());
    if (nest)
        xw.field("NESTED", "TRUE");

    switch (ent.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE:
        xw.field("TYPE", "SOURCE");
        f3 = f1;
        f1 = null;
        break;
    case IClasspathEntry.CPE_PROJECT:
        xw.field("TYPE", "BINARY");
        break;
    case IClasspathEntry.CPE_LIBRARY:
        xw.field("TYPE", "LIBRARY");
        break;
    }
    if (ent.isExported())
        xw.field("EXPORTED", true);
    if (opt)
        xw.field("OPTIONAL", true);

    if (f1 != null)
        xw.textElement("BINARY", f1.getAbsolutePath());
    if (f2 != null)
        xw.textElement("OUTPUT", f2.getAbsolutePath());
    if (f3 != null)
        xw.textElement("SOURCE", f3.getAbsolutePath());
    if (jdp != null)
        xw.textElement("JAVADOC", jdp);

    IAccessRule[] rls = ent.getAccessRules();
    for (IAccessRule ar : rls) {
        xw.begin("ACCESS");
        xw.field("KIND", ar.getKind());
        xw.field("PATTERN", ar.getPattern().toString());
        xw.field("IGNOREIFBETTER", ar.ignoreIfBetter());
        xw.end("ACCESS");
    }

    xw.end("PATH");
}

From source file:me.gladwell.eclipse.m2e.android.configuration.JavadocsEntryAttacher.java

License:Open Source License

public IClasspathEntry attach(IClasspathEntry entry, Artifact docs) {
    try {/*from w  ww.  ja v a2 s  .  c o m*/
        ClasspathAttributes attributes = new ClasspathAttributes(entry.getExtraAttributes());
        attributes.set(newClasspathAttribute(JAVADOC_LOCATION_ATTRIBUTE_NAME, getJavaDocUrl(docs.getFile())));

        IClasspathEntry entryWithDocs = JavaCore.newLibraryEntry(entry.getPath(),
                entry.getSourceAttachmentPath(), null, entry.getAccessRules(), attributes.toArray(),
                entry.isExported());

        return entryWithDocs;
    } catch (Exception e) {
        throw new ProjectConfigurationException(e);
    }
}

From source file:me.gladwell.eclipse.m2e.android.configuration.SourcesEntryAttacher.java

License:Open Source License

public IClasspathEntry attach(IClasspathEntry entry, Artifact sources) {
    return JavaCore.newLibraryEntry(entry.getPath(), Path.fromOSString(sources.getFile().getAbsolutePath()),
            null, entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
}