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

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

Introduction

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

Prototype

IClasspathEntry[] getRawClasspath() throws JavaModelException;

Source Link

Document

Returns the raw classpath for the project, as a list of classpath entries.

Usage

From source file:com.siteview.mde.internal.ui.wizards.plugin.NewProjectCreationOperation.java

License:Open Source License

private void addAllSourcePackages(IProject project, Set list) {
    try {/*from   w w  w . j  av  a2  s  .  c  o  m*/
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] classpath = javaProject.getRawClasspath();
        for (int i = 0; i < classpath.length; i++) {
            IClasspathEntry entry = classpath[i];
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = entry.getPath().removeFirstSegments(1);
                if (path.segmentCount() > 0) {
                    IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(project.getFolder(path));
                    IJavaElement[] children = root.getChildren();
                    for (int j = 0; j < children.length; j++) {
                        IPackageFragment frag = (IPackageFragment) children[j];
                        if (frag.getChildren().length > 0 || frag.getNonJavaResources().length > 0)
                            list.add(children[j].getElementName());
                    }
                }
            }
        }
    } catch (JavaModelException e) {
    }
}

From source file:com.siteview.mde.internal.ui.wizards.tools.ConvertProjectToPluginOperation.java

License:Open Source License

private void loadClasspathEntries(IProject project, IProgressMonitor monitor) {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] currentClassPath = new IClasspathEntry[0];
    ArrayList sources = new ArrayList();
    ArrayList libraries = new ArrayList();
    try {/* www.  ja v a  2  s  . c om*/
        currentClassPath = javaProject.getRawClasspath();
    } catch (JavaModelException e) {
    }
    for (int i = 0; i < currentClassPath.length; i++) {
        int contentType = currentClassPath[i].getEntryKind();
        if (contentType == IClasspathEntry.CPE_SOURCE) {
            String relativePath = getRelativePath(currentClassPath[i], project);
            if (relativePath.equals("")) { //$NON-NLS-1$
                sources.add("."); //$NON-NLS-1$
            } else {
                sources.add(relativePath + "/"); //$NON-NLS-1$
            }
        } else if (contentType == IClasspathEntry.CPE_LIBRARY) {
            String path = getRelativePath(currentClassPath[i], project);
            if (path.length() > 0)
                libraries.add(path);
            else
                libraries.add("."); //$NON-NLS-1$
        }
    }
    fSrcEntries = (String[]) sources.toArray(new String[sources.size()]);
    fLibEntries = (String[]) libraries.toArray(new String[libraries.size()]);

    IClasspathEntry[] classPath = new IClasspathEntry[currentClassPath.length + 1];
    System.arraycopy(currentClassPath, 0, classPath, 0, currentClassPath.length);
    classPath[classPath.length - 1] = ClasspathComputer.createContainerEntry();
    try {
        javaProject.setRawClasspath(classPath, monitor);
    } catch (JavaModelException e) {
    }
}

From source file:com.siteview.mde.ui.templates.AbstractTemplateSection.java

License:Open Source License

/**
 * Returns the folder with Java files in the target project. The default
 * implementation looks for source folders in the classpath of the target
 * folders and picks the first one encountered. Subclasses may override this
 * behaviour.//from ww  w  .  j a  v  a  2  s .c  om
 * 
 * @param monitor
 *            progress monitor to use
 * @return source folder that will be used to generate Java files or
 *         <samp>null </samp> if none found.
 */

protected IFolder getSourceFolder(IProgressMonitor monitor) {
    IFolder sourceFolder = null;

    try {
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] classpath = javaProject.getRawClasspath();
        for (int i = 0; i < classpath.length; i++) {
            IClasspathEntry entry = classpath[i];
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = entry.getPath().removeFirstSegments(1);
                if (path.segmentCount() > 0)
                    sourceFolder = project.getFolder(path);
                break;
            }
        }
    } catch (JavaModelException e) {
        MDEPlugin.logException(e);
    }
    return sourceFolder;
}

From source file:com.tasktop.dropwizard.launcher.DropwizardRuntimeClasspathProvider.java

License:Open Source License

protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier,
        ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(path.segment(0));

    IMavenProjectFacade projectFacade = projectManager.create(project, monitor);
    if (projectFacade == null) {
        return;//ww  w .jav  a2s.c om
    }

    ResolverConfiguration configuration = projectFacade.getResolverConfiguration();
    if (configuration == null) {
        return;
    }

    IJavaProject javaProject = JavaCore.create(project);

    boolean projectResolved = false;

    for (IClasspathEntry entry : javaProject.getRawClasspath()) {
        IRuntimeClasspathEntry rce = null;
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!projectResolved) {

                IMavenClassifierManager mavenClassifierManager = MavenJdtPlugin.getDefault()
                        .getMavenClassifierManager();
                IClassifierClasspathProvider classifierClasspathProvider = mavenClassifierManager
                        .getClassifierClasspathProvider(projectFacade, classifier);

                if (IClasspathManager.CLASSPATH_TEST == scope) {
                    classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor);
                } else {
                    classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor);
                }

                projectResolved = true;
            }
            break;
        case IClasspathEntry.CPE_CONTAINER:
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            if (container != null && !MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) {
                switch (container.getKind()) {
                case IClasspathContainer.K_APPLICATION:
                    rce = JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(),
                            IRuntimeClasspathEntry.USER_CLASSES, javaProject);
                    break;
                default:
                    break;
                }
            }
            break;
        case IClasspathEntry.CPE_LIBRARY:
            rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath());
            break;
        case IClasspathEntry.CPE_VARIABLE:
            if (!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) {
                rce = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath());
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            IProject res = root.getProject(entry.getPath().segment(0));
            if (res != null) {
                IJavaProject otherProject = JavaCore.create(res);
                if (otherProject != null) {
                    rce = JavaRuntime.newDefaultProjectClasspathEntry(otherProject);
                }
            }
            break;
        default:
            break;
        }
        if (rce != null) {
            addStandardClasspathEntries(resolved, rce, launchConfiguration);
        }
    }
}

From source file:com.technophobia.substeps.junit.launcher.SubstepsLaunchConfigurationDelegate.java

License:Open Source License

private Callback1<IJavaProject> addSubstepsToClasspath() {
    return new Callback1<IJavaProject>() {

        @Override//w  ww  . jav  a 2 s.  com
        public void doCallback(final IJavaProject project) {

            try {
                final List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>(
                        Arrays.asList(project.getRawClasspath()));

                final List<String> jarFiles = new SubstepJarProvider().junitRunnerJars();
                for (final String jarFile : jarFiles) {
                    newClasspath.add(JavaCore.newLibraryEntry(new Path(jarFile), null, null));
                }
                project.setRawClasspath(newClasspath.toArray(new IClasspathEntry[newClasspath.size()]), null);
            } catch (final JavaModelException ex) {
                FeatureRunnerPlugin.error("Could not add substeps jars to classpath", ex);
            }
        }
    };
}

From source file:com.technophobia.substeps.junit.launcher.SubstepsLaunchConfigurationDelegate.java

License:Open Source License

private Callback1<IJavaProject> removeSubstepsFromClasspath() {
    return new Callback1<IJavaProject>() {

        @Override//from w w w  .  j a  v a 2s. co m
        public void doCallback(final IJavaProject project) {
            try {
                final List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>(
                        Arrays.asList(project.getRawClasspath()));

                final List<String> jarFiles = new SubstepJarProvider().junitRunnerJars();
                for (final String jarFile : jarFiles) {
                    newClasspath.remove(JavaCore.newLibraryEntry(new Path(jarFile), null, null));
                }
                project.setRawClasspath(newClasspath.toArray(new IClasspathEntry[newClasspath.size()]), null);
            } catch (final JavaModelException ex) {
                FeatureRunnerPlugin.error("Could not remove substeps jars from classpath", ex);
            }
        }
    };
}

From source file:com.technophobia.substeps.syntax.ProjectToSyntaxTransformer.java

License:Open Source License

private Set<String> outputFoldersForProject(final IJavaProject project) {
    final Set<String> outputFolders = new HashSet<String>();
    final IPath projectLocation = projectLocationPath(project);

    try {/*from  w w  w .  j  a  va 2  s.c om*/
        final IPath defaultOutputLocation = project.getOutputLocation();
        if (defaultOutputLocation != null) {
            final IPath fullPath = appendPathTo(projectLocation, defaultOutputLocation);
            if (fullPath.toFile().exists()) {
                outputFolders.add(fullPath.toOSString());
            }
        }
        for (final IClasspathEntry entry : project.getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                final IPath outputLocation = entry.getOutputLocation();
                if (outputLocation != null) {
                    final IPath fullPath = appendPathTo(projectLocation, outputLocation);
                    if (fullPath.toFile().exists()) {
                        outputFolders.add(fullPath.toOSString());
                    }
                }
            }
        }
    } catch (final JavaModelException ex) {
        FeatureEditorPlugin.instance()
                .warn("Could not get output folder location for project " + project.getElementName());
    }

    return outputFolders;
}

From source file:com.temenos.ds.op.xtext.ui.internal.se.JdtBasedProcessorProvider.java

License:Open Source License

private List<URL> getOutputFolders(final IJavaProject javaProject) {
    try {// w  w w .j  av  a  2  s. co m
        final List<URL> result = CollectionLiterals.<URL>newArrayList();
        IPath _outputLocation = javaProject.getOutputLocation();
        IPath path = _outputLocation.addTrailingSeparator();
        String _string = path.toString();
        org.eclipse.emf.common.util.URI _createPlatformResourceURI = org.eclipse.emf.common.util.URI
                .createPlatformResourceURI(_string, true);
        String _string_1 = _createPlatformResourceURI.toString();
        URL url = new URL(_string_1);
        result.add(url);
        IClasspathEntry[] _rawClasspath = javaProject.getRawClasspath();
        for (final IClasspathEntry entry : _rawClasspath) {
            int _entryKind = entry.getEntryKind();
            switch (_entryKind) {
            case IClasspathEntry.CPE_SOURCE:
                IPath _outputLocation_1 = entry.getOutputLocation();
                path = _outputLocation_1;
                boolean _notEquals = (!Objects.equal(path, null));
                if (_notEquals) {
                    IPath _addTrailingSeparator = path.addTrailingSeparator();
                    String _string_2 = _addTrailingSeparator.toString();
                    org.eclipse.emf.common.util.URI _createPlatformResourceURI_1 = org.eclipse.emf.common.util.URI
                            .createPlatformResourceURI(_string_2, true);
                    String _string_3 = _createPlatformResourceURI_1.toString();
                    URL _uRL = new URL(_string_3);
                    url = _uRL;
                    result.add(url);
                }
                break;
            }
        }
        return result;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}

From source file:com.testify.ecfeed.ui.common.EclipseModelImplementer.java

License:Open Source License

private IPackageFragmentRoot createNewSourceFolder(String name) throws CoreException {
    IProject project = fFileInfoProvider.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    IFolder srcFolder = project.getFolder(name);
    int i = 0;/*from  www. ja v  a2 s.  c o m*/
    while (srcFolder.exists()) {
        String newName = name + i++;
        srcFolder = project.getFolder(newName);
    }
    srcFolder.create(false, true, null);
    IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(srcFolder);

    IClasspathEntry[] entries = javaProject.getRawClasspath();
    IClasspathEntry[] updated = new IClasspathEntry[entries.length + 1];
    System.arraycopy(entries, 0, updated, 0, entries.length);
    updated[entries.length] = JavaCore.newSourceEntry(root.getPath());
    javaProject.setRawClasspath(updated, null);
    return root;
}

From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java

License:LGPL

/**
 * Gets a classpath container from a project. (Assumes that the path is only
 * used once.)/* w  ww.j a  va 2  s  .  c om*/
 * 
 * @param project
 *        The project
 * @param path
 *        The path
 * @return The classpath container or null
 * @throws JavaModelException
 *         In case of an Eclipse JDT error
 */
public static IClasspathContainer getClasspathContainer(IJavaProject project, IPath path)
        throws JavaModelException {
    IClasspathEntry[] entries = project.getRawClasspath();
    for (IClasspathEntry entry : entries)
        if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path)))
            return (IClasspathContainer) entry;
    return null;
}