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

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

Introduction

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

Prototype

IPath getSourceAttachmentPath();

Source Link

Document

Returns the path to the source archive or folder associated with this classpath entry, or null if this classpath entry has no source attachment.

Usage

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  ww w.  jav a2s.c o m
        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
 *//*from w  w  w. jav a2s  .  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/*  w  w  w  .j  a  va 2s . 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 addPath(IvyXmlWriter xw, IJavaProject jp, IClasspathEntry ent, boolean nest) {
    IPath p = ent.getPath();/*www  .ja va  2  s.c  o 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:fede.workspace.eclipse.composition.copy.exporter.JavaClassRefExporter.java

License:Apache License

protected Map<IPath, FolderExportedContent> findLocations(FolderExportedContent folderContent,
        String exporterType) throws JavaModelException, CoreException {
    IJavaProject javaProject = JavaProjectManager.getJavaProject(getItem());

    Map<IPath, FolderExportedContent> outputLocations = new HashMap<IPath, FolderExportedContent>();
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();

    if (exporterType.equals(JAVA_REF_EXPORTER_TYPE)) {
        for (IClasspathEntry entry : rawClasspath) {
            if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE)
                continue;

            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath outputPath = entry.getOutputLocation();
                if (outputPath == null)
                    outputPath = javaProject.getOutputLocation();

                outputLocations.put(getRelativePath(outputPath), folderContent);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath outputPath = entry.getPath();
                if (outputPath != null)
                    outputLocations.put(getRelativePath(outputPath), folderContent);
            }/* w  w  w  . jav  a2s .  co  m*/
        }
    } else {
        for (IClasspathEntry entry : rawClasspath) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath outputPath = entry.getPath();
                if (outputPath != null)
                    outputLocations.put(getRelativePath(outputPath), folderContent);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath outputPath = entry.getSourceAttachmentPath();
                if (outputPath != null)
                    outputLocations.put(getRelativePath(outputPath), folderContent);
            }
        }
    }
    return outputLocations;
}

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.j a  v a  2s  . 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 boolean isAttached(IClasspathEntry entry) {
    return entry.getSourceAttachmentPath() != null;
}

From source file:me.gladwell.eclipse.m2e.android.test.DownloadSourcesAndJavadocTest.java

License:Open Source License

@Test
public void testSourcesAttached() throws Exception {
    IProject project = importAndroidProject(PROJECT_NAME);
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry entry = getClasspathEntry(javaProject, CONTAINER_NONRUNTIME_DEPENDENCIES,
            "mockito-core-1.9.5.jar");
    assertNotNull(entry.getSourceAttachmentPath());
}

From source file:me.gladwell.eclipse.m2e.android.test.DownloadSourcesAndJavadocTest.java

License:Open Source License

@Test
public void testCustomSourcesAttached() throws Exception {
    IProject project = importAndroidProject(PROJECT_NAME);
    IJavaProject javaProject = JavaCore.create(project);

    setCustomSourceAttachment(javaProject);

    IClasspathEntry entry = getClasspathEntry(javaProject, CONTAINER_NONRUNTIME_DEPENDENCIES,
            "mockito-core-1.9.5.jar");

    assertEquals(CUSTOM_PATH, entry.getSourceAttachmentPath());
}

From source file:me.gladwell.eclipse.m2e.android.test.DownloadSourcesAndJavadocTest.java

License:Open Source License

public void testUpdatingMavenProjectWithEntryWithCustomSourceAttachmentNotOverrideAttachment()
        throws Exception {
    IProject project = importAndroidProject(PROJECT_NAME);
    IJavaProject javaProject = JavaCore.create(project);

    setCustomSourceAttachment(javaProject);
    updateMavenProject(project);//from   w w w  .ja va2 s . c om

    IClasspathEntry entry = getClasspathEntry(javaProject, CONTAINER_NONRUNTIME_DEPENDENCIES,
            "mockito-core-1.9.5.jar");

    assertEquals(CUSTOM_PATH, entry.getSourceAttachmentPath());
}