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

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

Introduction

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

Prototype

IPath getSourceAttachmentRootPath();

Source Link

Document

Returns the path within the source archive or folder where package fragments are located.

Usage

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 ww  . j  ava 2s.  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 {//from   ww w.  j  a  va 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
 *///from  w  w w .j a v  a2  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 w w  w  .j av a2  s .  com*/
 */
// 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:net.rim.ejde.internal.model.ui.VMLibraryBlock.java

License:Open Source License

/**
 * Open the javadoc location dialog or the source location dialog, and set the result to the selected libraries.
 *///from  w w  w  .  jav a2s .  c o m
private void edit(IStructuredSelection selection, int type) {
    Object obj = selection.getFirstElement();
    LibraryStandin standin = null;
    if (obj instanceof LibraryStandin) {
        standin = (LibraryStandin) obj;
    } else if (obj instanceof SubElement) {
        SubElement sub = (SubElement) obj;
        standin = sub.getParent();
    }
    if (standin != null) {
        LibraryLocation library = standin.toLibraryLocation();
        if (type == SubElement.JAVADOC_URL) {
            URL[] urls = BuildPathDialogAccess.configureJavadocLocation(fLibraryViewer.getControl().getShell(),
                    library.getSystemLibraryPath().toOSString(), library.getJavadocLocation());
            if (urls != null) {
                fLibraryContentProvider.setJavadoc(urls[0], selection);
            }
        } else if (type == SubElement.SOURCE_PATH) {
            IRuntimeClasspathEntry entry = JavaRuntime
                    .newArchiveRuntimeClasspathEntry(library.getSystemLibraryPath());
            entry.setSourceAttachmentPath(library.getSystemLibrarySourcePath());
            entry.setSourceAttachmentRootPath(library.getPackageRootPath());
            IClasspathEntry classpathEntry = BuildPathDialogAccess.configureSourceAttachment(
                    fLibraryViewer.getControl().getShell(), entry.getClasspathEntry());
            if (classpathEntry != null) {
                fLibraryContentProvider.setSourcePath(classpathEntry.getSourceAttachmentPath(),
                        classpathEntry.getSourceAttachmentRootPath(), selection);
            }
        }
    }
}

From source file:org.apache.felix.sigil.eclipse.model.util.JavaHelper.java

License:Apache License

private static Collection<IClasspathEntry> newProjectEntry(ISigilProjectModel n, IAccessRule[] rules,
        IClasspathAttribute[] attributes, boolean export) throws CoreException {
    ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
    entries.add(JavaCore.newProjectEntry(n.getProject().getFullPath(), rules, false, attributes, export));
    for (IClasspathEntry e : n.getJavaModel().getRawClasspath()) {
        String encoded = n.getJavaModel().encodeClasspathEntry(e);
        if (n.getBundle().getClasspathEntrys().contains(encoded)) {
            switch (e.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
                entries.add(JavaCore.newLibraryEntry(e.getPath(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), rules, attributes, export));
                break;
            case IClasspathEntry.CPE_VARIABLE:
                IPath path = JavaCore.getResolvedVariablePath(e.getPath());
                if (path != null) {
                    IPath spath = e.getSourceAttachmentPath();
                    if (spath != null) {
                        spath = JavaCore.getResolvedVariablePath(spath);
                    }/*  w  ww .  j  a v  a2s.  c  o  m*/

                    entries.add(JavaCore.newLibraryEntry(path, spath, e.getSourceAttachmentRootPath(), rules,
                            attributes, export));
                }
                break;
            }
        }
    }

    return entries;
}

From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyAttachementManager.java

License:Apache License

public void updateAttchements(IJavaProject project, IPath containerPath,
        IClasspathContainer containerSuggestion) {
    IvyDEMessage.verbose("Updating attachements on the container " + containerPath);

    Properties newProps = new Properties();

    IClasspathEntry[] newEntries = containerSuggestion.getClasspathEntries();
    for (int i = 0; i < newEntries.length; i++) {
        IClasspathEntry entry = newEntries[i];
        if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) {
            String path = entry.getPath().toPortableString();
            if (entry.getSourceAttachmentPath() != null) {
                newProps.put(path + SRC_SUFFIX, entry.getSourceAttachmentPath().toPortableString());
            }/*from   w  w w . j  a va2 s.  c o  m*/
            if (entry.getSourceAttachmentRootPath() != null) {
                newProps.put(path + SRCROOT_SUFFIX, entry.getSourceAttachmentRootPath().toPortableString());
            }
            String javadocUrl = getJavadocLocation(entry);
            if (javadocUrl != null) {
                newProps.put(path + DOC_SUFFIX, javadocUrl);
            }
        }
    }

    IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) IvyClasspathContainerHelper
            .getContainer(containerPath, project);
    if (ivycp == null) {
        IvyDEMessage.error("The IvyDE container could not be found. Aborting updating attachements.");
        // something wrong happened, give up
        return;
    }
    IClasspathEntry[] existingEntries = ivycp.getClasspathEntries();
    for (int i = 0; i < existingEntries.length; i++) {
        IClasspathEntry entry = existingEntries[i];
        if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind()) {
            String path = entry.getPath().toPortableString();
            String value = (String) prop.get(path + SRC_SUFFIX);
            if (value != null && entry.getSourceAttachmentPath() != null
                    && value.equals(entry.getSourceAttachmentPath().toPortableString())) {
                newProps.remove(path + SRC_SUFFIX);
            }
            value = (String) prop.get(path + SRCROOT_SUFFIX);
            if (value != null && entry.getSourceAttachmentRootPath() != null
                    && value.equals(entry.getSourceAttachmentRootPath().toPortableString())) {
                newProps.remove(path + SRCROOT_SUFFIX);
            }
        }
    }

    // copy the actually new overrided properties
    prop.putAll(newProps);

    // now update the ivyde container for real
    ivycp.updateClasspathEntries(newEntries);

    // store the global result
    IvyDEMessage.verbose("Saving attachement properties");
    try {
        FileOutputStream out = new FileOutputStream(containersAttachementFile);
        try {
            prop.store(out, "");
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                // don't care
            }
        }
    } catch (IOException ioe) {
        IvyPlugin.logWarn("IvyDE attachement properties could not be saved", ioe);
    }
}

From source file:org.continuousassurance.swamp.eclipse.ImprovedClasspathHandler.java

License:Apache License

/**
 * Handles a library entry in the classpath
 * @param entry the classpath entry//from w w  w  .  ja va  2s . c  o m
 * @param root the workspace root
 * @throws IOException
 */
private void handleLibrary(IClasspathEntry entry, IWorkspaceRoot root) throws IOException {
    // 3 types of library entries: internal (this project), internal (another project), and external
    // (1) Rooted absolute path
    // (2) Rooted absolute path (but with different project directory) --> Need to copy this to swampbin
    // (3) Actual absolute path to somewhere else on the filesystem --> Need to copy this to swampbin
    System.out.println("\n\n\n\n");
    System.out.println("Library absolute path: " + entry.getPath().makeAbsolute());
    //System.out.println("First segment: " + entry.getPath().segment(0));
    IFile file = root.getFile(entry.getPath());
    System.out.println("File project: " + file.getProject().getName());

    if (file.getProject().equals(this.project.getProject())) {
        System.out.println("Is inside project");
        libs.add(entry);
    } else {
        System.out.println("Is outside project");
        IFile libFile = root.getFile(entry.getPath());
        IProject libProject = libFile.getProject();
        String filename = getLibraryFileName(entry.getPath());
        IPath destPath;
        if (libProject.exists()) {
            if (libProject.isOpen()) {
                try {
                    System.out.println("Local project");
                    destPath = copyWorkspacePathIntoBinDir(libFile, filename, SWAMPBIN_PATH);
                } catch (Exception e) {
                    System.out.println("Local project that failed");
                    String srcPath = getProjectLibraryLocation(libProject, entry.getPath());
                    destPath = copyAbsolutePathIntoBinDir(srcPath, filename, SWAMPBIN_PATH);
                }
            } else {
                System.out.println("Local project that's closed");
                String srcPath = getProjectLibraryLocation(libProject, entry.getPath());
                destPath = copyAbsolutePathIntoBinDir(srcPath, filename, SWAMPBIN_PATH);
            }
        } else {
            System.out.println("Not a project - just an absolute path");
            destPath = copyAbsolutePathIntoBinDir(entry.getPath().toOSString(), filename, SWAMPBIN_PATH);
        }
        hasSwampbinDependencies = true;
        System.out.println("SWAMPBIN path: " + destPath);
        IClasspathEntry newEntry = JavaCore.newLibraryEntry(destPath, entry.getSourceAttachmentPath(),
                entry.getSourceAttachmentRootPath());
        System.out.println("New entry path: " + newEntry.getPath());
        libs.add(newEntry);
        if (entry.isExported()) {
            exportedEntries.add(newEntry);
        }
    }
}

From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java

License:Open Source License

/**
 * Firstly, add library to the Java build path if it's not there already,
 * then mark the entry as being on the aspect path
 * @param project/*from   ww w  .  j a va 2s .  c  o m*/
 * @param path
 */
private static void addAttribute(IProject project, String jarPath, int eKind, IClasspathAttribute attribute) {
    IJavaProject jp = JavaCore.create(project);

    try {
        IClasspathEntry[] cp = jp.getRawClasspath();
        int cpIndex = getIndexInBuildPathEntry(cp, jarPath);
        if (cpIndex >= 0) { // already on classpath
            // add attribute to classpath entry
            // if it doesn't already exist
            IClasspathEntry pathAdd = cp[cpIndex];
            // only add attribute if this element is not already on the path
            if (isAspectPathAttribute(attribute) ? !isOnAspectpath(pathAdd) : !isOnInpath(pathAdd)) {
                IClasspathAttribute[] attributes = pathAdd.getExtraAttributes();
                IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1];
                System.arraycopy(attributes, 0, newattrib, 0, attributes.length);
                newattrib[attributes.length] = attribute;
                switch (pathAdd.getEntryKind()) {
                case IClasspathEntry.CPE_LIBRARY:
                    pathAdd = JavaCore.newLibraryEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(),
                            pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib,
                            pathAdd.isExported());
                    break;

                case IClasspathEntry.CPE_VARIABLE:
                    pathAdd = JavaCore.newVariableEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(),
                            pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib,
                            pathAdd.isExported());
                    break;

                case IClasspathEntry.CPE_CONTAINER:
                    pathAdd = JavaCore.newContainerEntry(pathAdd.getPath(), pathAdd.getAccessRules(), newattrib,
                            pathAdd.isExported());
                    break;

                case IClasspathEntry.CPE_PROJECT:
                    pathAdd = JavaCore.newProjectEntry(pathAdd.getPath(), pathAdd.getAccessRules(), true,
                            newattrib, pathAdd.isExported());
                    break;
                }

                cp[cpIndex] = pathAdd;
                jp.setRawClasspath(cp, null);
            }
        } else {
            addEntryToJavaBuildPath(jp, attribute, jarPath, eKind);
        }
    } catch (JavaModelException e) {
    }
}

From source file:org.eclipse.andmore.internal.project.LibraryClasspathContainerInitializer.java

License:Open Source License

private static List<IClasspathEntry> convertJarsToClasspathEntries(final IProject iProject,
        Set<File> jarFiles) {
    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(jarFiles.size());

    // and process the jar files list, but first sanitize it to remove dups.
    JarListSanitizer sanitizer = new JarListSanitizer(
            iProject.getFolder(SdkConstants.FD_OUTPUT).getLocation().toFile(),
            new AndroidPrintStream(iProject, null /*prefix*/, AndmoreAndroidPlugin.getOutStream()));

    String errorMessage = null;//from w w  w  .  ja  v  a2  s .  c o  m

    try {
        List<File> sanitizedList = sanitizer.sanitize(jarFiles);

        for (File jarFile : sanitizedList) {
            if (jarFile instanceof CPEFile) {
                CPEFile cpeFile = (CPEFile) jarFile;
                IClasspathEntry e = cpeFile.getClasspathEntry();

                entries.add(JavaCore.newLibraryEntry(e.getPath(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), e.getAccessRules(), e.getExtraAttributes(),
                        true /*isExported*/));
            } else {
                String jarPath = jarFile.getAbsolutePath();

                IPath sourceAttachmentPath = null;
                IClasspathAttribute javaDocAttribute = null;

                File jarProperties = new File(jarPath + DOT_PROPERTIES);
                if (jarProperties.isFile()) {
                    Properties p = new Properties();
                    InputStream is = null;
                    try {
                        p.load(is = new FileInputStream(jarProperties));

                        String value = p.getProperty(ATTR_SRC);
                        if (value != null) {
                            File srcPath = getFile(jarFile, value);

                            if (srcPath.exists()) {
                                sourceAttachmentPath = new Path(srcPath.getAbsolutePath());
                            }
                        }

                        value = p.getProperty(ATTR_DOC);
                        if (value != null) {
                            File docPath = getFile(jarFile, value);
                            if (docPath.exists()) {
                                try {
                                    javaDocAttribute = JavaCore.newClasspathAttribute(
                                            IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                                            docPath.toURI().toURL().toString());
                                } catch (MalformedURLException e) {
                                    AndmoreAndroidPlugin.log(e, "Failed to process 'doc' attribute for %s",
                                            jarProperties.getAbsolutePath());
                                }
                            }
                        }

                    } catch (FileNotFoundException e) {
                        // shouldn't happen since we check upfront
                    } catch (IOException e) {
                        AndmoreAndroidPlugin.log(e, "Failed to read %s", jarProperties.getAbsolutePath());
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                                // ignore
                            }
                        }
                    }
                }

                if (javaDocAttribute != null) {
                    entries.add(JavaCore.newLibraryEntry(new Path(jarPath), sourceAttachmentPath,
                            null /*sourceAttachmentRootPath*/, new IAccessRule[0],
                            new IClasspathAttribute[] { javaDocAttribute }, true /*isExported*/));
                } else {
                    entries.add(JavaCore.newLibraryEntry(new Path(jarPath), sourceAttachmentPath,
                            null /*sourceAttachmentRootPath*/, true /*isExported*/));
                }
            }
        }
    } catch (DifferentLibException e) {
        errorMessage = e.getMessage();
        AndmoreAndroidPlugin.printErrorToConsole(iProject, (Object[]) e.getDetails());
    } catch (Sha1Exception e) {
        errorMessage = e.getMessage();
    }

    processError(iProject, errorMessage, AndmoreAndroidConstants.MARKER_DEPENDENCY, true /*outputToConsole*/);

    return entries;
}