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

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

Introduction

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

Prototype

IClasspathEntry[] readRawClasspath();

Source Link

Document

Returns the raw classpath for the project as defined by its .classpath file from disk, or null if unable to read the file.

Usage

From source file:org.eclipse.jst.pagedesigner.utils.JavaUtil.java

License:Open Source License

/**
 * /*from   w  ww.  ja va2 s . com*/
 * @param javaProject
 * @param parent
 * @return the path in javaProject or new Path("") if not found on a class path
 * @author mengbo
 */
public static IPath getPathOnClasspath(IJavaProject javaProject, Object parent) {
    IPath result = null;
    if (javaProject == null || parent == null) {
        return new Path(""); //$NON-NLS-1$
    }
    IClasspathEntry[] entries = javaProject.readRawClasspath();
    IPath classPath = null;
    if (parent instanceof IResource) {
        if (((javaProject != null) && !javaProject.isOnClasspath((IResource) parent))) {
            return new Path(""); //$NON-NLS-1$
        }
        if (parent instanceof IFile) {
            IPath elementPath = ((IFile) parent).getFullPath();
            if (((IFile) parent).getFileExtension().equalsIgnoreCase(IFileFolderConstants.EXT_PROPERTIES)) {
                int machings = 0;
                try {
                    for (int i = 0; i < entries.length; i++) {
                        // Determine whether on this classentry's path
                        machings = entries[i].getPath().matchingFirstSegments(elementPath);
                        if (machings > 0) {
                            // Get package name
                            classPath = elementPath.removeFirstSegments(machings).removeLastSegments(1);
                            break;
                        }
                    }
                    // Not on the classpath?
                    if (classPath == null) {
                        return null;
                    } else if (classPath.segmentCount() > 0)
                        result = javaProject.findElement(classPath).getPath().removeFirstSegments(machings)
                                .append(((IFile) parent).getName());
                    else
                        result = ((IFile) parent).getFullPath().removeFirstSegments(machings);
                } catch (Exception e) {
                    // Error.DesignerPropertyTool.NatureQuerying = Error in
                    // project java nature querying
                    PDPlugin.getLogger(JavaUtil.class).error("Error.DesignerPropertyTool.NatureQuerying", e); //$NON-NLS-1$
                    return null;
                }
            }
        }
    } else if (parent instanceof IJarEntryResource) {
        IPath elementPath = ((IJarEntryResource) parent).getFullPath();
        if (elementPath.getFileExtension().equalsIgnoreCase(IFileFolderConstants.EXT_PROPERTIES)) {
            result = elementPath;
        }
    }
    if (result != null) {
        return result;
    }
    return new Path(""); //$NON-NLS-1$
}

From source file:org.jboss.ide.eclipse.as.wtp.core.vcf.VCFClasspathCommand.java

License:Open Source License

/**
 * This can add any container path to a project
 * @param project The project to add the path to
 * @param path A container classpath path
 * @return/*w  w  w. j  a va  2  s .c  o  m*/
 */
public static IStatus addContainerClasspathEntry(IProject project, IPath path) {
    IStatus status = Status.OK_STATUS;
    try {

        IClasspathEntry newClasspath = JavaCore.newContainerEntry(path);
        IJavaProject javaProject = JavaCore.create(project);

        IClasspathEntry[] oldClasspathEntries = javaProject.readRawClasspath();

        boolean isContainerInClassPathAlready = false;
        for (int i = 0; i < oldClasspathEntries.length && !isContainerInClassPathAlready; i++) {
            if (oldClasspathEntries[i].getPath().equals(newClasspath.getPath())) {
                isContainerInClassPathAlready = true;
                break;
            }
        }

        if (!isContainerInClassPathAlready) {

            IClasspathEntry[] newClasspathEntries = new IClasspathEntry[oldClasspathEntries.length + 1];
            for (int i = 0; i < oldClasspathEntries.length; i++) {
                newClasspathEntries[i] = oldClasspathEntries[i];
            }
            newClasspathEntries[oldClasspathEntries.length] = newClasspath;
            javaProject.setRawClasspath(newClasspathEntries, new NullProgressMonitor());
        }
    } catch (JavaModelException e) {
        status = new Status(IStatus.ERROR, ASWTPToolsPlugin.PLUGIN_ID, e.getLocalizedMessage(), e);
        return status;
    }

    return status;
}

From source file:org.jboss.ide.eclipse.as.wtp.core.vcf.VCFClasspathCommand.java

License:Open Source License

/**
 * This can remove any container path from a project
 * @param project The project to remove the path from
 * @param path A container classpath path
 * @return// www.j a  v  a  2  s  . com
 */
public static IStatus removeContainerClasspathEntry(IProject project, IPath path) {
    IStatus status = Status.OK_STATUS;
    try {

        IClasspathEntry toRemove = JavaCore.newContainerEntry(path);
        IJavaProject javaProject = JavaCore.create(project);

        IClasspathEntry[] oldClasspathEntries = javaProject.readRawClasspath();

        IClasspathEntry found = null;
        for (int i = 0; i < oldClasspathEntries.length && found == null; i++) {
            if (oldClasspathEntries[i].getPath().equals(toRemove.getPath())) {
                found = oldClasspathEntries[i];
            }
        }

        if (found != null) {
            // We found the entry; now remove it
            ArrayList<IClasspathEntry> list = new ArrayList<IClasspathEntry>();
            list.addAll(Arrays.asList(oldClasspathEntries));
            list.remove(found);

            IClasspathEntry[] newClasspathEntries = list.toArray(new IClasspathEntry[list.size()]);
            javaProject.setRawClasspath(newClasspathEntries, new NullProgressMonitor());
        }
    } catch (JavaModelException e) {
        status = new Status(IStatus.ERROR, ASWTPToolsPlugin.PLUGIN_ID, e.getLocalizedMessage(), e);
        return status;
    }

    return status;
}

From source file:org.jboss.tools.esb.core.facet.UninstallJBossClassPathCommand.java

License:Open Source License

public IStatus removeClassPath(IProject project, String segment) {
    IStatus status = Status.OK_STATUS;/*from  www  . j  a va  2s  .  c o m*/
    try {
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] oldClasspathEntries = javaProject.readRawClasspath();

        boolean isFolderInClassPathAlready = false;
        List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
        for (int i = 0; i < oldClasspathEntries.length && !isFolderInClassPathAlready; i++) {
            if (!oldClasspathEntries[i].getPath()
                    .equals(new Path(JBossRuntimeClassPathInitializer.JBOSS_ESB_RUNTIME_CLASSPATH_CONTAINER_ID)
                            .append(segment))) {
                classpathEntries.add(oldClasspathEntries[i]);
            }
        }
        if (classpathEntries.size() < oldClasspathEntries.length) {
            javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
                    new NullProgressMonitor());
        }
    } catch (JavaModelException e) {
        status = StatusUtils.errorStatus(NLS.bind(JBossFacetCoreMessages.Error_Remove_Facet_JBossESB,
                new String[] { e.getLocalizedMessage() }), e);
        return status;
    }

    return status;
}

From source file:org.jboss.tools.ws.core.command.JBossWSClassPathCommand.java

License:Open Source License

public IStatus addClassPath(IProject project, String segment, boolean isDeployed) {
    IStatus status = Status.OK_STATUS;/*from   w  w w  .  jav  a2s  . co m*/
    try {

        IClasspathEntry newClasspath;
        IJavaProject javaProject = JavaCore.create(project);

        if (isDeployed) {
            IClasspathAttribute depAttrib = JavaCore.newClasspathAttribute(
                    IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY,
                    ClasspathDependencyUtil.getDefaultRuntimePath(true).toString());
            newClasspath = JavaCore.newContainerEntry(
                    new Path(JBossWSCoreMessages.JBossWS_Runtime_Lib).append(segment), null,
                    new IClasspathAttribute[] { depAttrib }, true);
        } else {
            newClasspath = JavaCore
                    .newContainerEntry(new Path(JBossWSCoreMessages.JBossWS_Runtime_Lib).append(segment));
        }

        IClasspathEntry[] oldClasspathEntries = javaProject.readRawClasspath();

        boolean isFolderInClassPathAlready = false;
        for (int i = 0; i < oldClasspathEntries.length && !isFolderInClassPathAlready; i++) {
            if (oldClasspathEntries[i].getPath().equals(newClasspath.getPath())) {
                isFolderInClassPathAlready = true;
                break;
            }
        }

        if (!isFolderInClassPathAlready) {

            IClasspathEntry[] newClasspathEntries = new IClasspathEntry[oldClasspathEntries.length + 1];
            for (int i = 0; i < oldClasspathEntries.length; i++) {
                newClasspathEntries[i] = oldClasspathEntries[i];
            }
            newClasspathEntries[oldClasspathEntries.length] = newClasspath;

            javaProject.setRawClasspath(newClasspathEntries, new NullProgressMonitor());
        }
    } catch (JavaModelException e) {
        status = StatusUtils.errorStatus(
                NLS.bind(JBossWSCoreMessages.Error_Copy, new String[] { e.getLocalizedMessage() }), e);
        return status;
    }

    return status;
}

From source file:org.jboss.tools.ws.core.command.UninstallJBossWSClassPathCommand.java

License:Open Source License

public IStatus removeClassPath(IProject project, String segment) {
    IStatus status = Status.OK_STATUS;//from w w w . j a va 2  s.  c  o m
    if (segment == null || "".equals(segment)) { //$NON-NLS-1$
        return status;
    }

    try {
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] oldClasspathEntries = javaProject.readRawClasspath();

        boolean isFolderInClassPathAlready = false;
        List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
        for (int i = 0; i < oldClasspathEntries.length && !isFolderInClassPathAlready; i++) {
            if (!oldClasspathEntries[i].getPath()
                    .equals(new Path(JBossWSCoreMessages.JBossWS_Runtime_Lib).append(segment))) {
                classpathEntries.add(oldClasspathEntries[i]);
            }
        }
        if (classpathEntries.size() < oldClasspathEntries.length) {
            javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
                    new NullProgressMonitor());
        }
    } catch (JavaModelException e) {
        status = StatusUtils.errorStatus(NLS.bind(JBossWSCoreMessages.Error_Remove_Facet_JBossWS,
                new String[] { e.getLocalizedMessage() }), e);
        return status;
    }

    return status;
}

From source file:org.jboss.tools.ws.jaxws.core.commands.JBossWSClassPathCommand.java

License:Open Source License

public IStatus addClassPath(IProject project, String segment, boolean isDeployed) {
    IStatus status = Status.OK_STATUS;/*from   ww  w .  j  a v  a 2 s .  c  o m*/
    try {

        IClasspathEntry newClasspath;
        IJavaProject javaProject = JavaCore.create(project);

        if (isDeployed) {
            IClasspathAttribute depAttrib = JavaCore.newClasspathAttribute(
                    IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY,
                    ClasspathDependencyUtil.getDefaultRuntimePath(true).toString());
            newClasspath = JavaCore.newContainerEntry(
                    new Path(JBossJAXWSCoreMessages.JBossWS_Runtime_Lib).append(segment), null,
                    new IClasspathAttribute[] { depAttrib }, true);
        } else {
            newClasspath = JavaCore
                    .newContainerEntry(new Path(JBossJAXWSCoreMessages.JBossWS_Runtime_Lib).append(segment));
        }

        IClasspathEntry[] oldClasspathEntries = javaProject.readRawClasspath();

        boolean isFolderInClassPathAlready = false;
        for (int i = 0; i < oldClasspathEntries.length && !isFolderInClassPathAlready; i++) {
            if (oldClasspathEntries[i].getPath().equals(newClasspath.getPath())) {
                isFolderInClassPathAlready = true;
                break;
            }
        }

        if (!isFolderInClassPathAlready) {

            IClasspathEntry[] newClasspathEntries = new IClasspathEntry[oldClasspathEntries.length + 1];
            for (int i = 0; i < oldClasspathEntries.length; i++) {
                newClasspathEntries[i] = oldClasspathEntries[i];
            }
            newClasspathEntries[oldClasspathEntries.length] = newClasspath;

            javaProject.setRawClasspath(newClasspathEntries, new NullProgressMonitor());
        }
    } catch (JavaModelException e) {
        status = StatusUtils.errorStatus(
                NLS.bind(JBossJAXWSCoreMessages.Error_Copy, new String[] { e.getLocalizedMessage() }), e);
        return status;
    }

    return status;
}

From source file:org.jboss.tools.ws.jaxws.core.commands.UninstallJBossWSClassPathCommand.java

License:Open Source License

public IStatus removeClassPath(IProject project, String segment) {
    IStatus status = Status.OK_STATUS;//from www.j a  v  a  2  s .  co m
    if (segment == null || "".equals(segment)) { //$NON-NLS-1$
        return status;
    }

    try {
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] oldClasspathEntries = javaProject.readRawClasspath();

        boolean isFolderInClassPathAlready = false;
        List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
        for (int i = 0; i < oldClasspathEntries.length && !isFolderInClassPathAlready; i++) {
            if (!oldClasspathEntries[i].getPath()
                    .equals(new Path(JBossJAXWSCoreMessages.JBossWS_Runtime_Lib).append(segment))) {
                classpathEntries.add(oldClasspathEntries[i]);
            }
        }
        if (classpathEntries.size() < oldClasspathEntries.length) {
            javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
                    new NullProgressMonitor());
        }
    } catch (JavaModelException e) {
        status = StatusUtils.errorStatus(NLS.bind(JBossJAXWSCoreMessages.Error_Remove_Facet_JBossWS,
                new String[] { e.getLocalizedMessage() }), e);
        return status;
    }

    return status;
}

From source file:org.limy.eclipse.qalab.common.LimyQalabUtils.java

License:Open Source License

/**
 * v?WFNgS?o?pX results ?B/*from  w ww .  j a v a 2 s. c o m*/
 * @param project 
 * @param results i[?
 */
public static void appendProjectBinPaths(IJavaProject project, Collection<IPath> results) {

    results.add(project.readOutputLocation());
    // v?WFNg\?[XfBNg?[v
    for (IClasspathEntry entry : project.readRawClasspath()) {
        IPath location = entry.getOutputLocation();
        if (location != null) {
            // \?[XfBNgL?ofBNgw??
            results.add(location);
        }
    }
}