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:edu.washington.cs.cupid.scripting.java.wizards.JavaCapabilityWizard.java

License:Open Source License

private boolean inClasspath(final List<IClasspathEntry> classpath, final IPath query) {
    for (IClasspathEntry entry : classpath) {
        if (entry.getPath().equals(query)) {
            return true;
        }/*  w  ww.j  a v a 2 s  .  c  o m*/
    }
    return false;
}

From source file:egovframework.hdev.imp.ide.common.DeviceAPIIdeUtils.java

License:Apache License

/**
 * ?  /*from w w w.  ja v a 2  s . com*/
 * @param project
 * @throws CoreException
 */
public static void removeClasspathEntry(IProject project, IClasspathEntry classpathEntry) throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);

    if ((javaProject == null) || (!javaProject.exists()))
        return;

    try {
        IClasspathEntry[] classpath;
        ArrayList<IClasspathEntry> entries;

        classpath = javaProject.getRawClasspath();
        entries = new ArrayList<IClasspathEntry>(Arrays.asList(classpath));

        for (int i = 0; i < entries.size(); i++) {

            if (entries.get(i).getPath().toString().compareTo(classpathEntry.getPath().toString()) == 0) {

                entries.remove(i);
            }
        }

        classpath = entries.toArray(new IClasspathEntry[entries.size()]);
        javaProject.setRawClasspath(classpath, null);
    } catch (JavaModelException e) {
        DeviceAPIIdeLog.logError(e);
    }
}

From source file:es.bsc.servicess.ide.PackagingUtils.java

License:Apache License

/** Get the classpath of the project
 * @param project//from w ww . j a  va  2 s. co  m
 * @return
 * @throws JavaModelException
 */
public static String getClasspath(IJavaProject project) throws JavaModelException {
    String classpath = new String();
    IPath path = project.getProject().getWorkspace().getRoot().getLocation();
    boolean first = true;
    for (IClasspathEntry e : project.getResolvedClasspath(true)) {
        if (!first) {
            classpath = classpath.concat(":");

        } else {
            first = false;
        }
        if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath entryPath = e.getPath();
            path.isPrefixOf(entryPath);
            classpath = classpath.concat(path.append(entryPath.makeRelative()).toOSString());
        } else {
            classpath = classpath.concat(e.getPath().toOSString());
        }
    }
    return classpath;
}

From source file:es.optsicom.res.client.util.ProjectDependenciesResolver.java

License:Eclipse Public License

private void calculateDependencies(IClasspathEntry[] cpe, IProject project)
        throws DependenciesResolverException {
    try {//  w w w . j av  a  2s  . co m

        IWorkspace workspace = project.getWorkspace();
        IPath workspacePath = workspace.getRoot().getLocation();
        String nombreWorkspace = workspacePath.toString();
        IJavaProject jp = JavaCore.create(project);

        if (!dependencies.contains(project.getLocation().toString())) {
            // Aadimos la carpeta bin
            classpathFiles.add(workspacePath.append(jp.getOutputLocation()).toFile());
            classpath.add(jp.getOutputLocation().toString());
        }

        for (IClasspathEntry cpEntry : cpe) {

            String path = cpEntry.getPath().toString();
            String dependency = nombreWorkspace.concat(path);

            if (!dependencies.contains(dependency)) {
                RESClientPlugin.log("Adding dependency: " + dependency);
                dependencies.add(dependency);

                if (cpEntry.getOutputLocation() != null) {
                    RESClientPlugin.log("Binarios: " + cpEntry.getOutputLocation().toString());
                    classpath.add(cpEntry.getOutputLocation().makeRelativeTo(workspacePath).toString());
                    classpathFiles.add(cpEntry.getOutputLocation().toFile());
                }

                int tipo = cpEntry.getEntryKind();

                //Si la dependencia es de una libreria(

                if (tipo == IClasspathEntry.CPE_LIBRARY) {

                    String dep = cpEntry.getPath().makeRelativeTo(workspacePath).toString();
                    //mgarcia: Optsicom res Evolution
                    if (new File(workspacePath.toFile(), cpEntry.getPath().toOSString()).exists()) {
                        classpathFiles.add(new File(workspacePath.toFile(), cpEntry.getPath().toOSString()));

                        //Aadimos las dependencias a las properties
                        RESClientPlugin.log("Adding library: " + dep);
                        classpath.add(cpEntry.getPath().toString());
                    } else {
                        throw new DependenciesResolverException();
                    }

                } else if (tipo == IClasspathEntry.CPE_PROJECT) {

                    //                  File[] files = new File(dependency).listFiles();
                    //                  for (File f : files){
                    //                     lista.add(f);
                    //                     String dep = f.getPath();
                    //                     RESClientPlugin.log("Adding dependency: " + dep);
                    //                     dependencies.add(dep);
                    //                  }

                    IProject p = workspace.getRoot().getProject(cpEntry.getPath().lastSegment());
                    IJavaProject projectDependency = JavaCore.create(p);
                    IClasspathEntry[] cp = projectDependency.getRawClasspath();

                    classpathFiles.add(workspacePath.append(projectDependency.getOutputLocation()).toFile());
                    classpath.add(projectDependency.getOutputLocation().toString());

                    RESClientPlugin.log("Populating files from: " + p.getName());
                    calculateDependencies(cp, p);

                } else if (tipo == IClasspathEntry.CPE_SOURCE) {

                    File f = new File(dependency);
                    classpathFiles.add(f);
                    RESClientPlugin.log("Adding source: " + dependency);

                } else if (tipo == IClasspathEntry.CPE_VARIABLE) {

                    IClasspathEntry[] clpe = new IClasspathEntry[1];
                    clpe[0] = JavaCore.getResolvedClasspathEntry(cpEntry);
                    if (clpe[0] != null) {
                        RESClientPlugin.log("Populating files from: " + clpe[0].getPath().toOSString());
                        calculateDependencies(clpe, project);
                    }

                } else if (tipo == IClasspathEntry.CPE_CONTAINER) {

                    if (cpEntry.getPath().toOSString().contains("JRE_CONTAINER")
                            || cpEntry.getPath().toOSString().contains("requiredPlugins")) {
                        continue;
                    }

                    IClasspathContainer cc = JavaCore.getClasspathContainer(cpEntry.getPath(), jp);
                    IClasspathEntry[] entradas = cc.getClasspathEntries();

                    RESClientPlugin.log("Populating files from: " + cc.getPath().toOSString());
                    calculateDependencies(entradas, project);

                }
            }
        }
    } catch (JavaModelException e) {
        RESClientPlugin.log(e);
    }

    for (String path : classpath) {
        RESClientPlugin.log("Classpath: " + path);
    }
    for (File file : classpathFiles) {
        RESClientPlugin.log("Classpath file: " + file.getAbsolutePath());
    }
}

From source file:fede.workspace.ant.GetPath.java

License:Apache License

private void addLibClasspath(IClasspathEntry entry) {
    File f = entry.getPath().toFile();
    add(new Path(getProject(), f.getAbsolutePath()));
}

From source file:fede.workspace.dependencies.eclipse.java.ItemDependenciesClasspathEntry.java

License:Apache License

public IClasspathEntry[] getClasspathEntries() {

    if (id == null && _pdeClasspath != null) {
        return _pdeClasspath.getClasspathEntries();
    }/*from   w  w w .  j  a v  a2s.c  o m*/

    CadseDomain wd = CadseCore.getCadseDomain();
    if (wd == null) {
        return _previousdependencies;
    }
    LogicalWorkspace logicalWorkspace = wd.getLogicalWorkspace();
    if (id == null && item == null) {
        WSJavaPlugin.getDefault().log(new Status(Status.ERROR, WSJavaPlugin.PLUGIN_ID, 0,
                label + " : cannot find item from a null id for the item dependencies classpath.", null));
        return _previousdependencies;
    }
    if (logicalWorkspace == null) {
        return _previousdependencies;
    }
    if (logicalWorkspace.getState() != WSModelState.RUN) {
        return _previousdependencies;
    }
    ;
    if (item == null || !item.isResolved()) {
        item = logicalWorkspace.getItem(id);
    }
    if (item == null || !item.isResolved()) {
        WSJavaPlugin.getDefault().log(new Status(Status.ERROR, WSJavaPlugin.PLUGIN_ID, 0,
                label + " : cannot find item " + id + " for the item dependencies classpath ", null));
        return _previousdependencies;
    }
    if (_dependencies == null) {
        MultiStatus ms = new MultiStatus(WSJavaPlugin.PLUGIN_ID, 0,
                label + " : cannot compute the item dependencies classpath ", null);

        try {
            final Set<IClasspathEntry> calculateDependencies = JavaProjectManager.calculateDependencies(item,
                    ms);
            _dependencies = calculateDependencies.toArray(new IClasspathEntry[calculateDependencies.size()]);
            Arrays.sort(_dependencies, new Comparator<IClasspathEntry>() {
                public int compare(IClasspathEntry o1, IClasspathEntry o2) {
                    return o1.getPath().toPortableString().compareTo(o2.getPath().toPortableString());
                }
            });
        } catch (CoreException e) {
            MultiStatus ms2 = new MultiStatus(WSJavaPlugin.PLUGIN_ID, 0,
                    "Cannot compute the item dependencies classpath ", e);
            ms2.add(e.getStatus());
            ms2.addAll(ms);
            ms = ms2;
            if (!ms.isOK()) {
                WSJavaPlugin.getDefault().log(ms);
            }
            return _previousdependencies;
        }
        if (!ms.isOK()) {
            WSJavaPlugin.getDefault().log(ms);
        }
    }
    return _dependencies;
}

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);
            }/*from   ww w.  j ava 2  s  .c o  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:fede.workspace.eclipse.java.JavaProjectManager.java

License:Apache License

/**
 * Replace project classpath./*from www .  j a  v  a  2s .c o  m*/
 * 
 * @param ce
 *            the ce
 * @param project
 *            the project
 * @param progressMonitor
 *            the progress monitor
 * 
 * @return the i classpath entry
 * 
 * @throws JavaModelException
 *             the java model exception
 */
static public IClasspathEntry replaceProjectClasspath(IClasspathEntry ce, IJavaProject project,
        IProgressMonitor progressMonitor) throws JavaModelException {
    if (project == null) {
        return null;
    }

    IClasspathEntry[] classpath = project.getRawClasspath();
    boolean find = false;
    IPath rootPath = ce.getPath();

    int cpLength = classpath.length;
    int newCPIndex = -1;
    IClasspathEntry findentry = null;
    for (int j = 0; j < cpLength; j++) {
        IClasspathEntry entry = classpath[j];
        if (rootPath.equals(entry.getPath())) {
            if (!find) {
                find = true;
                newCPIndex = j;
                classpath[newCPIndex++] = ce;
                findentry = entry;
            }
        } else if (find) {
            classpath[newCPIndex++] = entry;
        }
    }

    if (find) {
        if (newCPIndex == cpLength) {
            project.setRawClasspath(classpath, progressMonitor);
        } else {
            IClasspathEntry[] newClasspath = new IClasspathEntry[newCPIndex];
            System.arraycopy(classpath, 0, newClasspath, 0, newCPIndex);
            project.setRawClasspath(newClasspath, progressMonitor);
        }
    } else {
        IClasspathEntry[] newClasspath = new IClasspathEntry[cpLength + 1];
        System.arraycopy(classpath, 0, newClasspath, 0, cpLength);
        newClasspath[cpLength] = ce;
        project.setRawClasspath(newClasspath, progressMonitor);
    }
    return findentry;
}

From source file:fede.workspace.eclipse.java.JavaProjectManager.java

License:Apache License

/**
 * Removes the project classpath.//from  w  ww .j a va 2 s  . c  o m
 * 
 * @param rootPath
 *            the root path
 * @param project
 *            the project
 * @param progressMonitor
 *            the progress monitor
 * 
 * @return the i classpath entry
 * 
 * @throws JavaModelException
 *             the java model exception
 */
static public IClasspathEntry removeProjectClasspath(IPath rootPath, IJavaProject project,
        IProgressMonitor progressMonitor) throws JavaModelException {
    if (project == null) {
        return null;
    }

    IClasspathEntry[] classpath = project.getRawClasspath();
    boolean find = false;
    int cpLength = classpath.length;
    int newCPIndex = -1;
    IClasspathEntry findentry = null;
    for (int j = 0; j < cpLength; j++) {
        IClasspathEntry entry = classpath[j];
        if (rootPath.equals(entry.getPath())) {
            if (!find) {
                find = true;
                newCPIndex = j;
                findentry = entry;
            }
        } else if (find) {
            classpath[newCPIndex++] = entry;
        }
    }
    if (find) {
        IClasspathEntry[] newClasspath = new IClasspathEntry[newCPIndex];
        System.arraycopy(classpath, 0, newClasspath, 0, newCPIndex);
        project.setRawClasspath(newClasspath, progressMonitor);
    }
    return findentry;
}

From source file:fede.workspace.eclipse.java.JavaProjectManager.java

License:Apache License

/**
 * Adds the project classpath.//w ww .  ja v a2 s. c o  m
 * 
 * @param project
 *            the project
 * @param ce
 *            the ce
 * @param progressMonitor
 *            the progress monitor
 * @param overwrite
 *            true si force le classpath
 * 
 * @throws JavaModelException
 *             the java model exception
 */
static public void addProjectClasspath(IJavaProject project, IClasspathEntry ce,
        IProgressMonitor progressMonitor, boolean overwrite) throws JavaModelException {
    if (project == null) {
        return;
    }

    IClasspathEntry[] classpath = project.getRawClasspath();
    int cpLength = classpath.length;
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getPath().equals(ce.getPath())) {
            if (overwrite) {
                classpath[i] = ce;
                project.setRawClasspath(classpath, progressMonitor);
            }
            return;
        }
    }

    IClasspathEntry[] newClasspath = new IClasspathEntry[cpLength + 1];
    ;
    System.arraycopy(classpath, 0, newClasspath, 0, cpLength);
    newClasspath[cpLength] = ce;
    project.setRawClasspath(newClasspath, progressMonitor);
}