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

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

Introduction

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

Prototype

int CPE_LIBRARY

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a library.

Usage

From source file:net.sf.eclipse.tomcat.TomcatProjectWebclasspathPropertyPage.java

License:Open Source License

private void getClassPathEntries(IClasspathEntry[] entries, IJavaProject prj, ArrayList data,
        IPath outputPath) {/*  w ww .ja  va2  s  .c  o m*/
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            String prjName = entry.getPath().lastSegment();
            if (!visitedProjects.contains(prjName)) {
                visitedProjects.add(prjName);
                getClassPathEntries(getJavaProject().getJavaModel().getJavaProject(prjName), data);
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            add(data, entry.getPath());
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = entry.getOutputLocation();
            if (path != null && !path.equals(outputPath)) {
                add(data, path);
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (!entry.getPath().toString().equals("org.eclipse.jdt.launching.JRE_CONTAINER")) {
                // Add container itself, as TomcatBootstrap can actually process them
                // at the moment
                // Basically, users will be able to choose b/w the whole container
                // or some artifacts enclosed by it
                add(data, entry.getPath());

                // Expand container and add its content as individual
                // elements
                IClasspathContainer container;
                try {
                    container = JavaCore.getClasspathContainer(entry.getPath(), prj);
                } catch (JavaModelException e) {
                    TomcatLauncherPlugin.log("failed to obtain classpath container '" + entry.getPath() + "'"
                            + " for project '" + prj.getProject().getName() + "'");
                    TomcatLauncherPlugin.log(e);
                    container = null;
                }

                if (container != null) {
                    getClassPathEntries(container.getClasspathEntries(), prj, data, outputPath);
                }
            }
        } else {
            add(data, entry.getPath());
        }
    }
}

From source file:net.sf.eclipsecs.core.builder.ProjectClassLoader.java

License:Open Source License

/**
 * Adds the contents of a project to list of URLs.
 * //from   w  ww  .  j  a  v  a 2  s.co  m
 * @param project the project
 * @param cpURLs the resulting list
 * @param isReferenced true if a referenced project is processed
 */
private static void addToClassPath(IProject project, List<URL> cpURLs, boolean isReferenced,
        Collection<IProject> processedProjects) {

    try {

        // this project has already been added
        if (processedProjects.contains(project)) {
            return;
        } else {
            processedProjects.add(project);
        }

        // get the java project
        IJavaProject javaProject = JavaCore.create(project);

        // get the resolved classpath of the project
        IClasspathEntry[] cpEntries = javaProject.getResolvedClasspath(true);

        // iterate over classpath to create classpath urls
        int size = cpEntries.length;
        for (int i = 0; i < size; i++) {

            int entryKind = cpEntries[i].getEntryKind();

            // handle a source path
            if (IClasspathEntry.CPE_SOURCE == entryKind) {

                handleSourcePath(project, cpURLs, cpEntries[i], javaProject);
            }
            // handle a project reference
            else if (IClasspathEntry.CPE_PROJECT == entryKind) {

                handleRefProject(cpURLs, cpEntries[i], processedProjects);
            }
            // handle a library entry
            else if (IClasspathEntry.CPE_LIBRARY == entryKind) {

                handleLibrary(project, cpURLs, cpEntries[i]);
            }
            // cannot happen since we use a resolved classpath
            else {

                // log as exception
                CheckstylePluginException ex = new CheckstylePluginException(
                        NLS.bind(Messages.errorUnknownClasspathEntry, cpEntries[i].getPath()));
                CheckstyleLog.log(ex);
            }
        }
    } catch (JavaModelException jme) {
        CheckstyleLog.log(jme);
    }
}

From source file:net.sf.fjep.fatjar.popup.actions.BuildFatJar.java

License:Open Source License

/**
 * Add all jars and class-folders referenced by jproject to jarfiles /
 * classesDirs. If exportedOnly is true, then only jars/class-folders which
 * are marked as exported will be added.
 * /*from   w  w w .  j a  v a2s .com*/
 * JRE_LIB (.../jre/lib/rt.jar) is ignored and not added to jarfiles
 * 
 * @param jproject
 * @param jarfiles
 * @param classesDirs
 * @param exportedOnly
 */
private void getClassPathJars(IJavaProject jproject, Vector jarfiles, Vector classesDirs,
        boolean exportedOnly) {

    IProject project = jproject.getProject();
    IWorkspace workspace = project.getWorkspace();
    IWorkspaceRoot workspaceRoot = workspace.getRoot();
    String rootDir = absPath(workspaceRoot.getLocation());
    IClasspathEntry[] cpes = jproject.readRawClasspath();
    // cpes = jproject.getResolvedClasspath(true);
    if (cpes != null) {
        for (int i = 0; i < cpes.length; i++) {
            IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]);
            if ((cpe != null) && (!exportedOnly || cpe.isExported())) {
                int kind = cpe.getEntryKind();
                String dir = relPath(cpe.getPath());
                if (kind == IClasspathEntry.CPE_CONTAINER) {
                    try {
                        IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject);
                        if ((container.getKind() == IClasspathContainer.K_APPLICATION)
                                || (container.getKind() == IClasspathContainer.K_SYSTEM)) {
                            IClasspathEntry[] cpes2 = container.getClasspathEntries();
                            for (int j = 0; j < cpes2.length; j++) {
                                IClasspathEntry cpe2 = cpes2[j];
                                int kind2 = cpe2.getEntryKind();
                                String dir2 = relPath(cpe2.getPath());
                                String jar2 = absOrProjectPath(workspaceRoot, dir2);
                                if (jar2 == null) {
                                    System.err.println("invalid classpath entry: " + cpe2.toString());
                                } else {
                                    File f2 = new File(jar2);
                                    if (f2.isDirectory()) {
                                        if (!classesDirs.contains(jar2)) {
                                            classesDirs.add(jar2);
                                        }
                                    } else { // assume jar file
                                        if (!jarfiles.contains(jar2)) {
                                            jarfiles.add(jar2);
                                        }
                                    }
                                }
                            }
                        }
                    } catch (JavaModelException e) {
                    }
                } else if (kind == IClasspathEntry.CPE_LIBRARY) {
                    String jar = absOrProjectPath(workspaceRoot, dir);
                    if (jar == null) {
                        System.err.println("invalid classpath entry: " + cpe.toString());
                    } else {

                        // ignore JRE_LIB
                        if (!jar.replace(File.separatorChar, '/').toLowerCase().endsWith("/jre/lib/rt.jar")) {
                            File f = new File(jar);
                            if (f.isDirectory()) {
                                if (!classesDirs.contains(jar)) {
                                    classesDirs.add(jar);
                                }
                            } else { // assume jar file
                                if (!jarfiles.contains(jar)) {
                                    jarfiles.add(jar);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:net.sf.fjep.fatjar.wizards.export.JProjectConfiguration.java

License:Open Source License

/**
 * Add all jars and class-folders referenced by jproject to jarfiles /
 * classesDirs. If exportedOnly is true, then only jars/class-folders which
 * are marked as exported will be added.
 * /*from  w w w .  j a v  a2 s.c  om*/
 * JRE_LIB (.../jre/lib/rt.jar) is ignored and not added to jarfiles
 * 
 * @param jarfiles
 * @param classesDirs
 * @param exportedOnly
 */
public void addClassPathEntries(Vector jarfiles, Vector classesDirs, Vector projects, boolean exportedOnly) {

    IClasspathEntry[] cpes = getRawClasspathEntries();
    if (cpes != null) {
        for (int i = 0; i < cpes.length; i++) {
            IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]);
            if ((cpe != null) && (!exportedOnly || cpe.isExported())) {
                int kind = cpe.getEntryKind();
                String dir = relPath(cpe.getPath());
                if (kind == IClasspathEntry.CPE_CONTAINER) {
                    try {
                        IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject);
                        if ((container.getKind() == IClasspathContainer.K_APPLICATION)
                                || (container.getKind() == IClasspathContainer.K_SYSTEM)) {
                            IClasspathEntry[] cpes2 = container.getClasspathEntries();
                            for (int j = 0; j < cpes2.length; j++) {
                                IClasspathEntry cpe2 = cpes2[j];
                                int kind2 = cpe2.getEntryKind();
                                String dir2 = relPath(cpe2.getPath());
                                String jar2 = getAbsOrProjectPath(dir2);
                                if (jar2 == null) {
                                    System.err.println("invalid classpath entry: " + cpe2.toString());
                                } else {
                                    File f2 = new File(jar2);
                                    if (f2.isDirectory()) {
                                        if (!classesDirs.contains(jar2)) {
                                            classesDirs.add(jar2);
                                        }
                                    } else { // assume jar file
                                        if (!jarfiles.contains(jar2)) {
                                            jarfiles.add(jar2);
                                        }
                                    }
                                }
                            }
                        }
                    } catch (JavaModelException e) {
                    }
                } else if (kind == IClasspathEntry.CPE_LIBRARY) {
                    String jar = getAbsOrProjectPath(dir);
                    if (jar == null) {
                        System.err.println("invalid classpath entry: " + cpe.toString());
                    } else {

                        // ignore JRE_LIB
                        if (!jar.replace(File.separatorChar, '/').toLowerCase().endsWith("/jre/lib/rt.jar")) {
                            File f = new File(jar);
                            if (f.isDirectory()) {
                                if (!classesDirs.contains(jar)) {
                                    classesDirs.add(jar);
                                }
                            } else { // assume jar file
                                if (!jarfiles.contains(jar)) {
                                    jarfiles.add(jar);
                                }
                            }
                        }
                    }
                } else if (kind == IClasspathEntry.CPE_PROJECT) {
                    if (!exportedOnly || cpe.isExported()) {
                        IJavaProject jPro = jproject.getJavaModel().getJavaProject(dir);
                        JProjectConfiguration jProCon = new JProjectConfiguration(jPro, null);
                        if (!projects.contains(jProCon)) {
                            projects.add(jProCon);
                        }
                    }
                }
            }
        }
    }
}

From source file:net.sf.fjep.fatjar.wizards.export.JProjectConfiguration.java

License:Open Source License

/**
 * Add all jars and class-folders referenced by jproject to jarfiles /
 * classesDirs. If exportedOnly is true, then only jars/class-folders which
 * are marked as exported will be added.
 * // ww w. j a  v  a2 s .c o  m
 * JRE_LIB (.../jre/lib/rt.jar) is ignored and not added to jarfiles
 * 
 * @param jarfiles
 * @param classesDirs
 * @param exportedOnly
 */
public void getClassPathJars(Vector jarfiles, Vector classesDirs, boolean exportedOnly) {

    IClasspathEntry[] cpes = getRawClasspathEntries();
    if (cpes != null) {
        for (int i = 0; i < cpes.length; i++) {
            IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]);
            if ((cpe != null) && (!exportedOnly || cpe.isExported())) {
                int kind = cpe.getEntryKind();
                String dir = relPath(cpe.getPath());
                if (kind == IClasspathEntry.CPE_CONTAINER) {
                    try {
                        IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject);
                        if ((container.getKind() == IClasspathContainer.K_APPLICATION)
                                || (container.getKind() == IClasspathContainer.K_SYSTEM)) {
                            IClasspathEntry[] cpes2 = container.getClasspathEntries();
                            for (int j = 0; j < cpes2.length; j++) {
                                IClasspathEntry cpe2 = cpes2[j];
                                int kind2 = cpe2.getEntryKind();
                                String dir2 = relPath(cpe2.getPath());
                                String jar2 = getAbsOrProjectPath(dir2);
                                if (jar2 == null) {
                                    System.err.println("invalid classpath entry: " + cpe2.toString());
                                } else {
                                    File f2 = new File(jar2);
                                    if (f2.isDirectory()) {
                                        if (!classesDirs.contains(jar2)) {
                                            classesDirs.add(jar2);
                                        }
                                    } else { // assume jar file
                                        if (!jarfiles.contains(jar2)) {
                                            jarfiles.add(jar2);
                                        }
                                    }
                                }
                            }
                        }
                    } catch (JavaModelException e) {
                    }
                } else if (kind == IClasspathEntry.CPE_LIBRARY) {
                    String jar = getAbsOrProjectPath(dir);
                    if (jar == null) {
                        System.err.println("invalid classpath entry: " + cpe.toString());
                    } else {

                        // ignore JRE_LIB
                        if (!jar.replace(File.separatorChar, '/').toLowerCase().endsWith("/jre/lib/rt.jar")) {
                            File f = new File(jar);
                            if (f.isDirectory()) {
                                if (!classesDirs.contains(jar)) {
                                    classesDirs.add(jar);
                                }
                            } else { // assume jar file
                                if (!jarfiles.contains(jar)) {
                                    jarfiles.add(jar);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:net.sf.j2s.core.builder.JavaBuilder.java

License:Open Source License

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

    ArrayList projects = new ArrayList();
    ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
    try {/* ww  w.j ava 2  s  . co m*/
        IClasspathEntry[] entries = this.javaProject.getExpandedClasspath();
        for (int i = 0, l = entries.length; i < l; i++) {
            IClasspathEntry entry = entries[i];
            IPath path = entry.getPath();
            IProject p = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT:
                p = this.workspaceRoot.getProject(path.lastSegment()); // missing projects are considered too
                if (((ClasspathEntry) entry).isOptional() && !JavaProject.hasJavaNature(p)) // except if entry is optional
                    p = null;
                break;
            case IClasspathEntry.CPE_LIBRARY:
                if (includeBinaryPrerequisites && path.segmentCount() > 0) {
                    // some binary resources on the class path can come from projects that are not included in the project references
                    IResource resource = this.workspaceRoot.findMember(path.segment(0));
                    if (resource instanceof IProject) {
                        p = (IProject) resource;
                    } else {
                        resource = externalFoldersManager.getFolder(path);
                        if (resource != null)
                            p = resource.getProject();
                    }
                }
            }
            if (p != null && !projects.contains(p))
                projects.add(p);
        }
    } catch (JavaModelException e) {
        return new IProject[0];
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:net.sf.j2s.core.builder.NameEnvironment.java

License:Open Source License

private void computeClasspathLocations(IWorkspaceRoot root, JavaProject javaProject,
        SimpleLookupTable binaryLocationsPerProject) throws CoreException {

    /* Update cycle marker */
    IMarker cycleMarker = javaProject.getCycleMarker();
    if (cycleMarker != null) {
        int severity = JavaCore.ERROR.equals(javaProject.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true))
                ? IMarker.SEVERITY_ERROR
                : IMarker.SEVERITY_WARNING;
        if (severity != cycleMarker.getAttribute(IMarker.SEVERITY, severity))
            cycleMarker.setAttribute(IMarker.SEVERITY, severity);
    }//from w  w  w .j  a  v  a  2s  .co  m

    IClasspathEntry[] classpathEntries = javaProject.getExpandedClasspath();
    ArrayList sLocations = new ArrayList(classpathEntries.length);
    ArrayList bLocations = new ArrayList(classpathEntries.length);
    nextEntry: for (int i = 0, l = classpathEntries.length; i < l; i++) {
        ClasspathEntry entry = (ClasspathEntry) classpathEntries[i];
        IPath path = entry.getPath();
        Object target = JavaModel.getTarget(path, true);
        if (target == null)
            continue nextEntry;

        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!(target instanceof IContainer))
                continue nextEntry;
            IPath outputPath = entry.getOutputLocation() != null ? entry.getOutputLocation()
                    : javaProject.getOutputLocation();
            IContainer outputFolder;
            if (outputPath.segmentCount() == 1) {
                outputFolder = javaProject.getProject();
            } else {
                outputFolder = root.getFolder(outputPath);
                if (!outputFolder.exists())
                    createOutputFolder(outputFolder);
            }
            sLocations.add(ClasspathLocation.forSourceFolder((IContainer) target, outputFolder,
                    entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars(),
                    entry.ignoreOptionalProblems()));
            continue nextEntry;

        case IClasspathEntry.CPE_PROJECT:
            if (!(target instanceof IProject))
                continue nextEntry;
            IProject prereqProject = (IProject) target;
            if (!JavaProject.hasJavaNature(prereqProject))
                continue nextEntry; // if project doesn't have java nature or is not accessible

            JavaProject prereqJavaProject = (JavaProject) JavaCore.create(prereqProject);
            IClasspathEntry[] prereqClasspathEntries = prereqJavaProject.getRawClasspath();
            ArrayList seen = new ArrayList();
            nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) {
                IClasspathEntry prereqEntry = prereqClasspathEntries[j];
                if (prereqEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    Object prereqTarget = JavaModel.getTarget(prereqEntry.getPath(), true);
                    if (!(prereqTarget instanceof IContainer))
                        continue nextPrereqEntry;
                    IPath prereqOutputPath = prereqEntry.getOutputLocation() != null
                            ? prereqEntry.getOutputLocation()
                            : prereqJavaProject.getOutputLocation();
                    IContainer binaryFolder = prereqOutputPath.segmentCount() == 1 ? (IContainer) prereqProject
                            : (IContainer) root.getFolder(prereqOutputPath);
                    if (binaryFolder.exists() && !seen.contains(binaryFolder)) {
                        seen.add(binaryFolder);
                        ClasspathLocation bLocation = ClasspathLocation.forBinaryFolder(binaryFolder, true,
                                entry.getAccessRuleSet());
                        bLocations.add(bLocation);
                        if (binaryLocationsPerProject != null) { // normal builder mode
                            ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject
                                    .get(prereqProject);
                            if (existingLocations == null) {
                                existingLocations = new ClasspathLocation[] { bLocation };
                            } else {
                                int size = existingLocations.length;
                                System.arraycopy(existingLocations, 0,
                                        existingLocations = new ClasspathLocation[size + 1], 0, size);
                                existingLocations[size] = bLocation;
                            }
                            binaryLocationsPerProject.put(prereqProject, existingLocations);
                        }
                    }
                }
            }
            continue nextEntry;

        case IClasspathEntry.CPE_LIBRARY:
            if (target instanceof IResource) {
                IResource resource = (IResource) target;
                ClasspathLocation bLocation = null;
                if (resource instanceof IFile) {
                    AccessRuleSet accessRuleSet = (JavaCore.IGNORE
                            .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
                            && JavaCore.IGNORE.equals(
                                    javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)))
                                            ? null
                                            : entry.getAccessRuleSet();
                    bLocation = ClasspathLocation.forLibrary((IFile) resource, accessRuleSet);
                } else if (resource instanceof IContainer) {
                    AccessRuleSet accessRuleSet = (JavaCore.IGNORE
                            .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
                            && JavaCore.IGNORE.equals(
                                    javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)))
                                            ? null
                                            : entry.getAccessRuleSet();
                    bLocation = ClasspathLocation.forBinaryFolder((IContainer) target, false, accessRuleSet); // is library folder not output folder
                }
                bLocations.add(bLocation);
                if (binaryLocationsPerProject != null) { // normal builder mode
                    IProject p = resource.getProject(); // can be the project being built
                    ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject
                            .get(p);
                    if (existingLocations == null) {
                        existingLocations = new ClasspathLocation[] { bLocation };
                    } else {
                        int size = existingLocations.length;
                        System.arraycopy(existingLocations, 0,
                                existingLocations = new ClasspathLocation[size + 1], 0, size);
                        existingLocations[size] = bLocation;
                    }
                    binaryLocationsPerProject.put(p, existingLocations);
                }
            } else if (target instanceof File) {
                AccessRuleSet accessRuleSet = (JavaCore.IGNORE
                        .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
                        && JavaCore.IGNORE.equals(
                                javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true))) ? null
                                        : entry.getAccessRuleSet();
                bLocations.add(ClasspathLocation.forLibrary(path.toString(), accessRuleSet));
            }
            continue nextEntry;
        }
    }

    // now split the classpath locations... place the output folders ahead of the other .class file folders & jars
    ArrayList outputFolders = new ArrayList(1);
    this.sourceLocations = new ClasspathMultiDirectory[sLocations.size()];
    if (!sLocations.isEmpty()) {
        sLocations.toArray(this.sourceLocations);

        // collect the output folders, skipping duplicates
        next: for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
            ClasspathMultiDirectory md = this.sourceLocations[i];
            IPath outputPath = md.binaryFolder.getFullPath();
            for (int j = 0; j < i; j++) { // compare against previously walked source folders
                if (outputPath.equals(this.sourceLocations[j].binaryFolder.getFullPath())) {
                    md.hasIndependentOutputFolder = this.sourceLocations[j].hasIndependentOutputFolder;
                    continue next;
                }
            }
            outputFolders.add(md);

            // also tag each source folder whose output folder is an independent folder & is not also a source folder
            for (int j = 0, m = this.sourceLocations.length; j < m; j++)
                if (outputPath.equals(this.sourceLocations[j].sourceFolder.getFullPath()))
                    continue next;
            md.hasIndependentOutputFolder = true;
        }
    }

    // combine the output folders with the binary folders & jars... place the output folders before other .class file folders & jars
    this.binaryLocations = new ClasspathLocation[outputFolders.size() + bLocations.size()];
    int index = 0;
    for (int i = 0, l = outputFolders.size(); i < l; i++)
        this.binaryLocations[index++] = (ClasspathLocation) outputFolders.get(i);
    for (int i = 0, l = bLocations.size(); i < l; i++)
        this.binaryLocations[index++] = (ClasspathLocation) bLocations.get(i);
}

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   w  ww.java2  s  . co  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.sourceforge.floggy.eclipse.builder.DefaultBuilder.java

License:Open Source License

/**
 * DOCUMENT ME!/* ww w . j  a  v a 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];
}

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

License:Open Source License

/**
 * This is where the classpool is actually set. The typical case only requires adding the required jar files
 * to the classpool (classPool and classPoolList), however if the project is dependent on other projects then
 * not only do we need the jar files from these dependencies but we also need the output folders.
 * @TODO EXPERIMENTAL - Dependencies support should be considered experimental at this time because it isn't fully tested ! 
 *///w  w  w.ja  va2 s  .c  om
private void configureClassPool(ClassPool classPool, List classPoolList, IClasspathEntry[] entries,
        IProject project, boolean isRootProject) throws NotFoundException, JavaModelException {

    IClasspathEntry classpathEntry;
    String pathName;

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

        if ((isRootProject || classpathEntry.isExported())
                && classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            pathName = getAccessablePathName(classIPath, project);
        } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            classIPath = classpathEntry.getOutputLocation();
            if (classIPath == null) {
                classIPath = JavaCore.create(project).getOutputLocation();
            }
            pathName = getAccessablePathName(classIPath, project);
        } else {
            // Currently we only add : All source folders, All libs in the root project & Exported libs in other projects
            continue;
        }

        if (pathName.contains("floggy-persistence-framework-impl.jar")) {
            continue;
        }
        if (pathName != null && !classPoolList.contains(pathName)) {
            LOG.debug(pathName + " added to classPool");
            classPoolList.add(pathName);
            classPool.appendClassPath(pathName);
        } else {
            LOG.debug(pathName + " alreaded added to classPool");
        }
    }
}