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

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

Introduction

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

Prototype

IPath getPath();

Source Link

Document

Returns the path of this classpath entry.

Usage

From source file:net.sf.jasperreports.eclipse.builder.action.ToggleNatureAction.java

License:Open Source License

/**
 * Toggles sample nature on a project/*from  w  ww.j  a  v a  2s.  c o m*/
 * 
 * @param project
 *          to have sample nature added or removed
 */
private void toggleNature(IProject project, IProgressMonitor monitor) {
    try {
        IProjectDescription description = project.getDescription();
        String[] natures = description.getNatureIds();
        IJavaProject javaProject = JavaCore.create(project);
        for (int i = 0; i < natures.length; ++i) {
            if (JasperReportsNature.NATURE_ID.equals(natures[i])) {
                // Remove the nature
                String[] newNatures = new String[natures.length - 1];
                System.arraycopy(natures, 0, newNatures, 0, i);
                System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
                description.setNatureIds(newNatures);
                project.setDescription(description, monitor);

                // Path to all libraries needed

                List<IClasspathEntry> centries = new ArrayList<IClasspathEntry>();
                IClasspathEntry[] entries = javaProject.readRawClasspath();
                Set<Path> set = JasperReportsPlugin.getClasspathContainerManager().getRemovableContainers();
                for (IClasspathEntry en : entries) {
                    if (en.getPath().equals(JRClasspathContainer.ID))
                        continue;
                    if (set.contains(en.getPath()))
                        continue;
                    centries.add(en);
                }
                javaProject.setRawClasspath(centries.toArray(new IClasspathEntry[centries.size()]), monitor);
                return;
            }
        }

        // Add the nature
        ProjectUtil.addNature(project, JasperReportsNature.NATURE_ID, monitor);
        ProjectUtil.createJRClasspathContainer(monitor, javaProject);
    } catch (CoreException e) {
        e.printStackTrace();
    }
}

From source file:net.sf.jasperreports.eclipse.classpath.container.JRClasspathContainerPage.java

License:Open Source License

@Override
public void initialize(IJavaProject project, IClasspathEntry[] currentEntries) {
    jrcc = new JRClasspathContainer(null, project);
    for (int i = 0; i < currentEntries.length; i++) {
        IClasspathEntry curr = currentEntries[i];
        if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            fUsedPaths.add(curr.getPath());
        }/*from   www.  ja  v a  2 s .  c o  m*/
    }
}

From source file:net.sf.jasperreports.eclipse.classpath.JavaProjectClassLoader.java

License:Open Source License

private ClassLoader getURLClassloader() {
    if (curlLoader == null) {
        try {//from  w  w  w.ja va  2  s .  c om
            if (calcURLS)
                return getParent();
            calcURLS = true;
            JRClasspathContainer jrcnt = (JRClasspathContainer) JavaCore
                    .getClasspathContainer(JRClasspathContainer.ID, javaProject);
            List<String> jrcntpaths = null;
            if (jrcnt != null) {
                IClasspathEntry[] ces = jrcnt.getAllClasspathEntries();
                if (ces != null && ces.length > 0) {
                    jrcntpaths = new ArrayList<String>();
                    for (IClasspathEntry en : ces)
                        jrcntpaths.add(en.getPath().toOSString());
                }
            }
            String[] classPaths = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
            Set<URL> urls = new HashSet<URL>();
            for (int i = 0; i < classPaths.length; i++)
                try {
                    if (jrcntpaths != null && jrcntpaths.contains(classPaths[i]))
                        continue;
                    urls.add(computeForURLClassLoader(classPaths[i]));
                } catch (MalformedURLException e) {
                }

            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
            resolveClasspathEntries(urls, root, entries);

            getURLClassloader(urls.toArray(new URL[urls.size()]));
            calcURLS = false;
        } catch (JavaModelException e1) {
            e1.printStackTrace();
        } catch (CoreException e1) {
            e1.printStackTrace();
        }
    }
    return curlLoader;
}

From source file:net.sf.jasperreports.eclipse.classpath.JavaProjectClassLoader.java

License:Open Source License

private void resolveClasspathEntries(Set<URL> urls, IWorkspaceRoot root, IClasspathEntry[] entries)
        throws JavaModelException {
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = entry.getPath();
            if (path.segmentCount() >= 2) {
                IFolder sourceFolder = root.getFolder(path);
                try {
                    urls.add(new URL("file:///" + sourceFolder.getRawLocation().toOSString() + "/"));
                } catch (MalformedURLException e) {
                }// w  w  w .  jav  a 2s.  co m
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath sourcePath = entry.getPath();
            covertPathToUrl(javaProject.getProject(), urls, sourcePath);
            IPath sourceOutputPath = entry.getOutputLocation();
            covertPathToUrl(javaProject.getProject(), urls, sourceOutputPath);
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (entry.getPath().equals(JRClasspathContainer.ID))
                continue;
            IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            resolveClasspathEntries(urls, root, cont.getClasspathEntries());
        }
    }
}

From source file:net.sf.jasperreports.eclipse.wizard.project.ProjectUtil.java

License:Open Source License

public static void createJRClasspathContainer(IProgressMonitor monitor, IJavaProject javaProject)
        throws JavaModelException {
    List<IClasspathEntry> centries = new ArrayList<IClasspathEntry>();
    IClasspathEntry[] entries = javaProject.readRawClasspath();
    for (IClasspathEntry en : entries) {
        if (en.getPath().equals(JRClasspathContainer.ID))
            return;
    }/*from   w  ww.ja v  a2  s  .co m*/
    centries.addAll(Arrays.asList(entries));

    createJRClasspathContainer(null, centries, javaProject);
}

From source file:net.sf.jasperreports.eclipse.wizard.project.ProjectUtil.java

License:Open Source License

public static void addFileToClasspath(IProgressMonitor monitor, IFile file) throws CoreException {
    if (file.getProject().getNature(JavaCore.NATURE_ID) != null) {
        IJavaProject jprj = JavaCore.create(file.getProject());
        List<IClasspathEntry> centries = new ArrayList<IClasspathEntry>();
        IClasspathEntry[] entries = jprj.readRawClasspath();
        for (IClasspathEntry en : entries) {
            if (en.getPath().equals(file.getFullPath()))
                return;
        }//from   w  w w . jav  a 2 s.  c  om
        centries.add(JavaCore.newLibraryEntry(file.getFullPath(), null, new Path("/")));
        centries.addAll(Arrays.asList(entries));
        jprj.setRawClasspath(centries.toArray(new IClasspathEntry[centries.size()]), monitor);
    }
}

From source file:net.sf.refactorit.eclipse.vfs.EclipseClassPath.java

License:Open Source License

public ClassPathElement[] createElements() {
    if (project == null || !project.isOpen()) {
        return new ClassPathElement[0];
    }/*from  ww  w.  j  a  v a2s . c o  m*/

    ArrayList result;

    if (options.isAutoDetect()) {
        IJavaProject jProject = JavaCore.create(project);
        try {
            IClasspathEntry[] pathEntries = jProject.getResolvedClasspath(true);
            result = new ArrayList(pathEntries.length);

            for (int i = 0; i < pathEntries.length; i++) {
                IClasspathEntry entry = pathEntries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    IPath path = entry.getPath();

                    if (debug) {
                        log.debug("creating classpath entry for path " + path);
                    }

                    File file = path.toFile();

                    if (!file.exists()) {
                        // FIXME: hack, improve
                        // lib under workspace
                        IFile f = project.getWorkspace().getRoot().getFile(path);
                        file = f.getRawLocation().toFile();
                    }

                    addClasspathElement(result, file);
                }
            }
        } catch (JavaModelException e) {
            throw new SystemException(ErrorCodes.ECLIPSE_INTERNAL_ERROR, "resolving classpath failed", e);
        }
    } else {
        log.debug("creating customized classpath elements");

        PathItem[] items = options.getClassPath().getItems();
        result = new ArrayList(items.length);

        for (int i = 0; i < items.length; i++) {
            File file = new File(items[i].getAbsolutePath());
            addClasspathElement(result, file);
        }
    }

    return (ClassPathElement[]) result.toArray(new ClassPathElement[result.size()]);
}

From source file:net.sf.refactorit.eclipse.vfs.EclipseSourcePath.java

License:Open Source License

public Source[] getAutodetectedElements() {
    final List tempList = new ArrayList();

    try {/*from  w  w w .  j av  a  2  s . co m*/
        IClasspathEntry[] sourceEntries = getSourcePathEntries();
        for (int i = 0; i < sourceEntries.length; i++) {
            IClasspathEntry entry = sourceEntries[i];
            IPath path = entry.getPath();

            if (debug) {
                log.debug("folder path = " + path.toOSString());
            }

            IContainer folder = getFolder(path);

            EclipseSource source = EclipseSource.getSource(folder);
            tempList.add(source);

            if (debug) {
                log.debug("folder = " + source.getAbsolutePath());
            }
        }
    } catch (JavaModelException e) {
        throw new RuntimeException(e);
    }

    Source autoDetectedRoots[] = (Source[]) tempList.toArray(new Source[tempList.size()]);

    return autoDetectedRoots;
}

From source file:net.sf.spindle.core.builder.EclipseBuildInfrastructure.java

License:Mozilla Public License

public IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
    if (javaProject == null || workspaceRoot == null)
        return new IProject[0];

    ArrayList<IProject> projects = new ArrayList<IProject>();
    try {//w ww. jav a 2  s .  c  o m
        IClasspathEntry[] entries = ((JavaProject) javaProject).getExpandedClasspath(true);
        for (int i = 0, length = entries.length; i < length; i++) {
            IClasspathEntry entry = JavaCore.getResolvedClasspathEntry(entries[i]);
            if (entry != null) {
                IPath path = entry.getPath();
                IProject p = null;
                if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    IProject workspaceProject = workspaceRoot.getProject(path.lastSegment());
                    if (workspaceProject.hasNature(TapestryCorePlugin.NATURE_ID))
                        p = workspaceProject;

                }
                if (p != null && !projects.contains(p))
                    projects.add(p);

            }
        }
    } catch (CoreException e) {
        return new IProject[0];
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:net.sourceforge.floggy.eclipse.builder.DefaultBuilder.java

License:Open Source License

/**
 * DOCUMENT ME!//from   www . ja va  2  s. co  m
*
* @param project DOCUMENT ME!
* @param monitor DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws Exception DOCUMENT ME!
*/
public IProject[] build(IProject project, IProgressMonitor monitor) throws Exception {
    IJavaProject javaProject = JavaCore.create(project);

    IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);

    List classpathList = new ArrayList();
    ClassPool classPool = new ClassPool();
    IClasspathEntry classpathEntry;
    String pathName;

    for (int i = 0; i < entries.length; i++) {
        classpathEntry = JavaCore.getResolvedClasspathEntry(entries[i]);
        pathName = classpathEntry.getPath().toFile().toString();

        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            if (!classpathEntry.getPath().toFile().exists()) {
                IFile pathIFile = project.getWorkspace().getRoot().getFile(classpathEntry.getPath());
                pathName = pathIFile.getLocationURI().getPath();
            }
        }

        classpathList.add(pathName);
        classPool.appendClassPath(pathName);
    }

    if (validateClasspath(project, classPool)) {
        Weaver weaver = new Weaver(classPool);
        IPath root = project.getLocation();
        File input = root.removeLastSegments(1).append(javaProject.getOutputLocation()).toFile();

        IFolder floggyTemp = project.getFolder(".floggy.tmp");

        if (!floggyTemp.exists()) {
            floggyTemp.create(IResource.DERIVED, true, monitor);
        }

        IFile configurationFile = project
                .getFile(project.getPersistentProperty(ConfigurationFileAction.PROPERTY_NAME));

        weaver.setOutputFile(floggyTemp.getLocation().toFile());
        weaver.setInputFile(input);
        weaver.setClasspath((String[]) classpathList.toArray(new String[classpathList.size()]));

        if (!configurationFile.exists()) {
            weaver.setConfiguration(createWeaverConfiguration(project));
        } else {
            weaver.setConfigurationFile(configurationFile.getLocation().toFile());
        }

        weaver.execute();

        IPath path = javaProject.getOutputLocation();

        if (path.segmentCount() > 1) {
            path = path.removeFirstSegments(1);
        }

        IFolder outputLocation = project.getFolder(path);
        floggyTemp.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        copyFiles(floggyTemp, outputLocation, monitor);
        outputLocation.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        cleanFolder(floggyTemp, monitor);
    }

    return new IProject[0];
}