Example usage for org.eclipse.jdt.core IJavaProject decodeClasspathEntry

List of usage examples for org.eclipse.jdt.core IJavaProject decodeClasspathEntry

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject decodeClasspathEntry.

Prototype

IClasspathEntry decodeClasspathEntry(String encodedEntry);

Source Link

Document

Decodes the classpath entry that has been encoded in the given string in the context of this project.

Usage

From source file:it.wallgren.android.platform.AndroidClasspathContainerInitializer.java

License:Apache License

private AndroidClasspathContainer loadClasspathContainer(IJavaProject project, IPath containerPath) {
    final AndroidClasspathContainer container = new AndroidClasspathContainer(containerPath);
    final LinkedList<IClasspathEntry> entries = new LinkedList<IClasspathEntry>();
    IClasspathEntry entry = null;//  w w  w . j a v  a2s. c o m
    int i = 0;
    try {
        do {
            final QualifiedName qname = new QualifiedName(container.getPath().toString(),
                    "IClasspathEntry." + i);
            entry = project.decodeClasspathEntry(
                    ResourcesPlugin.getWorkspace().getRoot().getPersistentProperty(qname));
            if (entry != null) {
                entries.add(entry);
            }
            i++;
        } while (entry != null);
        if (entries.size() > 0) {
            container.setEntries(entries.toArray(new IClasspathEntry[entries.size()]));
        }
    } catch (final CoreException e) {
        // We'll recreate the paths later, but manual classpath changes will
        // be lost (like source and javadoc attachments)
        e.printStackTrace();
    }
    return container;
}

From source file:net.ssehub.easy.producer.ui.project_management.EASyJavaConfigurator.java

License:Apache License

@Override
public void configure(IProject project, IProject parentProject) {
    JavaCapabilityConfigurationPage jcpage = new JavaCapabilityConfigurationPage();
    IJavaProject javaProject = JavaCore.create(project);
    IJavaProject javaParentProject = JavaCore.create(parentProject);

    jcpage.init(javaProject, null, null, false);
    try {//from  w  ww.ja v a2s. c o  m
        jcpage.configureJavaProject(null);
    } catch (CoreException e1) {
        EASyLoggerFactory.INSTANCE.getLogger(EASyJavaConfigurator.class, Activator.PLUGIN_ID).exception(e1);
    } catch (InterruptedException e1) {
        EASyLoggerFactory.INSTANCE.getLogger(EASyJavaConfigurator.class, Activator.PLUGIN_ID).exception(e1);
    }

    // Try to copy settings from parent
    try {
        IClasspathEntry[] parrentEntries = javaParentProject.getRawClasspath();
        IClasspathEntry[] newEntries = new IClasspathEntry[parrentEntries.length];

        // Copy Classpath Entries
        for (int i = 0; i < newEntries.length; i++) {
            IClasspathEntry parentEntry = parrentEntries[i];
            newEntries[i] = javaProject
                    .decodeClasspathEntry(javaParentProject.encodeClasspathEntry(parentEntry));

            try {
                IPath entryPath = newEntries[i].getPath().makeAbsolute();
                if (project.getFullPath().matchingFirstSegments(entryPath) > 0) {
                    File entryFile = entryPath.toFile();
                    IFolder folder = project.getFolder(entryFile.getName());
                    if (!folder.exists()) {
                        folder.create(false, true, null);
                    }
                }
            } catch (CoreException e) {
                EASyLoggerFactory.INSTANCE.getLogger(EASyJavaConfigurator.class, Activator.PLUGIN_ID)
                        .exception(e);
            }
        }
        javaProject.setRawClasspath(newEntries, null);
    } catch (CoreException e) {
        EASyLoggerFactory.INSTANCE.getLogger(EASyJavaConfigurator.class, Activator.PLUGIN_ID).exception(e);
    }

}

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

License:Apache License

public static Collection<IClasspathEntry> findClasspathEntries(ISigilBundle bundle) {
    LinkedList<IClasspathEntry> cp = new LinkedList<IClasspathEntry>();

    ISigilProjectModel sp = bundle.getAncestor(ISigilProjectModel.class);

    if (sp != null) {
        IJavaProject p = sp.getJavaModel();

        for (String enc : bundle.getClasspathEntrys()) {
            IClasspathEntry e = p.decodeClasspathEntry(enc);
            if (e != null) {
                cp.add(e);/*from  w w w. j a va  2  s  .  c  o m*/
            }
        }
    }

    return cp;
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.classpath.SigilClassPathContainer.java

License:Apache License

private static IClasspathEntry readClassPath(IJavaProject javaModel, File entry) throws IOException {
    FileInputStream in = new FileInputStream(entry);

    try {//  w  w  w .  j  a v  a2s  .  c o m
        ByteArrayOutputStream buf = new ByteArrayOutputStream();

        byte[] b = new byte[1024];

        for (;;) {
            int r = in.read(b);
            if (r == -1)
                break;
            buf.write(b, 0, r);
        }

        String enc = buf.toString();
        return javaModel.decodeClasspathEntry(enc);
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            SigilCore.warn("Failed to close stream to " + entry, e);
        }
    }
}

From source file:org.jsweet.plugin.builder.JSweetBuilder.java

License:Apache License

private static void autoFillClassPath(IProject project) throws CoreException {
    if (project.isNatureEnabled("org.eclipse.jdt.core.javanature")) {
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] cp = javaProject.getRawClasspath();
        File processed = project.getLocation().append(JSweetTranspiler.TMP_WORKING_DIR_NAME + File.separator
                + CandiesProcessor.CANDIES_PROCESSED_DIR_NAME).toFile();
        IClasspathEntry e = javaProject.decodeClasspathEntry(
                "<classpathentry kind=\"lib\" path=\"" + JSweetTranspiler.TMP_WORKING_DIR_NAME + File.separator
                        + CandiesProcessor.CANDIES_PROCESSED_DIR_NAME + "\" sourcepath=\""
                        + JSweetTranspiler.TMP_WORKING_DIR_NAME + File.separator
                        + CandiesProcessor.CANDIES_SOURCES_DIR_NAME + "\" />");
        if (project.isNatureEnabled(JSweetNature.ID)) {
            if (!processed.exists()) {
                processed.mkdirs();/*ww w.j a v a 2 s. c  o m*/
                project.refreshLocal(IResource.DEPTH_INFINITE, null);
            }
            if (!ArrayUtils.contains(cp, e)) {
                Log.info("adding " + e + " to build path");
                cp = ArrayUtils.add(cp, 0, e);
                javaProject.setRawClasspath(cp, true, null);
            }
        } else {
            if (ArrayUtils.contains(cp, e)) {
                Log.info("removing " + e + " from build path");
                cp = ArrayUtils.remove(cp, ArrayUtils.indexOf(cp, e));
                javaProject.setRawClasspath(cp, true, null);
            }
        }
    }
}

From source file:org.org.eclipse.dws.core.internal.bridges.ProjectInteractionHelper.java

License:Open Source License

/**
 * Removes the from raw classpath./* w  w w .ja  v  a2s  .  co m*/
 * 
 * @param classpathEntries the classpath entries
 * @param project the project
 * @param monitor the monitor
 */
private static void removeFromRawClasspath(Collection<DWSClasspathEntryDescriptor> classpathEntries,
        IProject project, IProgressMonitor monitor) {
    monitor.beginTask("Removing libraries from the classpath of project :" + project.getName(),
            classpathEntries.size() + 1);
    IJavaProject javaProject = JavaCore.create(project);
    List<IClasspathEntry> formerEntries = JavaProjectClasspathHelper.getRawClasspathAsList(javaProject);
    List<IPath> entriesToRemove = new LinkedList<IPath>();
    List<IClasspathEntry> newEntries = new LinkedList<IClasspathEntry>();
    for (DWSClasspathEntryDescriptor classpathEntryDescriptor : classpathEntries) {
        ClasspathHelper.removeFromClasspath(javaProject, formerEntries, entriesToRemove,
                javaProject.decodeClasspathEntry(classpathEntryDescriptor.getEncodedClasspathEntry()), monitor);
    }
    JavaProjectClasspathHelper.updateRawClasspath(javaProject, formerEntries, newEntries, monitor);
    monitor.beginTask("Removing files from project :" + project.getName(), entriesToRemove.size());
    ClasspathHelper.removeFilesFromProject(project, entriesToRemove, monitor);
}