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

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

Introduction

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

Prototype

int CPE_SOURCE

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

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a folder containing package fragments with source code to be compiled.

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 {//w w w.j a  va 2s  .  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 {//  ww w . j  av a  2  s  .  co m
        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 www  . j av a  2s.co m*/
 * 
 * @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.sympedia.genfw.util.ClasspathHelper.java

License:Open Source License

public static void collectClasspathURLs(IJavaProject javaProject, List<URL> urls) {
    try {//from w  w  w.  j a va 2  s .  c o m
        collectClasspathUrlOutput(javaProject.getOutputLocation(), urls);

        IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry entry : resolvedClasspath) {
            try {
                switch (entry.getEntryKind()) {
                case IClasspathEntry.CPE_SOURCE:
                    collectClasspathUrlOutput(entry.getOutputLocation(), urls);
                    break;

                case IClasspathEntry.CPE_LIBRARY:
                    File libFile = new File(entry.getPath().toString());
                    URL url = libFile.toURL();
                    if (!urls.contains(url)) {
                        //              System.out.println("LIB: " + url);
                        urls.add(url);
                    }
                    break;

                case IClasspathEntry.CPE_PROJECT:
                    String projectName = entry.getPath().segment(0);
                    IJavaProject requiredProject = getJavaProject(projectName);
                    collectClasspathURLs(requiredProject, urls);
                    break;

                default:
                    throw new RuntimeException();
                }
            } catch (MalformedURLException ex) {
                ex.printStackTrace();
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

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.j  a  v  a 2  s  . com
    }

    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.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  2s .  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

protected URLClassLoader createClassLoaderForJavaProject(final IJavaProject projectToUse) {
    try {/*from   w ww.jav  a 2s  .  c om*/
        final IClasspathEntry[] resolvedClasspath = projectToUse.getResolvedClasspath(true);
        final List<URL> urls = CollectionLiterals.<URL>newArrayList();
        List<URL> _outputFolders = this.getOutputFolders(projectToUse);
        urls.addAll(_outputFolders);
        for (final IClasspathEntry entry : resolvedClasspath) {
            {
                URL url = null;
                int _entryKind = entry.getEntryKind();
                switch (_entryKind) {
                case IClasspathEntry.CPE_SOURCE:
                    break;
                case IClasspathEntry.CPE_PROJECT:
                    IPath path = entry.getPath();
                    IWorkspaceRoot _workspaceRoot = this.getWorkspaceRoot(projectToUse);
                    final IResource project = _workspaceRoot.findMember(path);
                    IProject _project = project.getProject();
                    IJavaProject _create = JavaCore.create(_project);
                    List<URL> _outputFolders_1 = this.getOutputFolders(_create);
                    urls.addAll(_outputFolders_1);
                    break;
                case IClasspathEntry.CPE_LIBRARY:
                    IPath path_1 = entry.getPath();
                    IWorkspaceRoot _workspaceRoot_1 = this.getWorkspaceRoot(projectToUse);
                    final IResource library = _workspaceRoot_1.findMember(path_1);
                    URL _xifexpression = null;
                    boolean _notEquals = (!Objects.equal(library, null));
                    if (_notEquals) {
                        URI _rawLocationURI = library.getRawLocationURI();
                        _xifexpression = _rawLocationURI.toURL();
                    } else {
                        File _file = path_1.toFile();
                        URI _uRI = _file.toURI();
                        _xifexpression = _uRI.toURL();
                    }
                    url = _xifexpression;
                    break;
                default: {
                    IPath path_2 = entry.getPath();
                    File _file_1 = path_2.toFile();
                    URI _uRI_1 = _file_1.toURI();
                    URL _uRL = _uRI_1.toURL();
                    url = _uRL;
                }
                    break;
                }
                boolean _notEquals_1 = (!Objects.equal(url, null));
                if (_notEquals_1) {
                    urls.add(url);
                }
            }
        }
        ClassLoader _parentClassLoader = this.getParentClassLoader();
        return new URLClassLoader(((URL[]) Conversions.unwrapArray(urls, URL.class)), _parentClassLoader);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}

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  a2  s .  c  o 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.windowtester.codegen.util.BuildPathUtil.java

License:Open Source License

/**
 * Appends target project build path with source project build path.
 * //  w  w  w.  j av  a2s. c o  m
 * @param targetProject the target project
 * @param sourceProject the source project
 * @throws CoreException
 */
public static void appendProjectBuildPath(IJavaProject targetProject, IJavaProject sourceProject)
        throws CoreException {
    try {
        // copy required entries to target
        IClasspathEntry[] srcEntries = sourceProject.getRawClasspath();
        for (int i = 0; i < srcEntries.length; i++) {
            IClasspathEntry entry = srcEntries[i];
            if (entry.isExported() || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
                continue;
            addToClasspath(targetProject, entry);
        }
        // add the source project as a project entry
        IClasspathEntry srcPrjEntry = JavaCore.newProjectEntry(sourceProject.getPath());
        addToClasspath(targetProject, srcPrjEntry);
    } catch (JavaModelException e) {
        // we interested only in core exceptions
        if (e.getCause() instanceof CoreException) {
            throw (CoreException) e.getCause();
        }
    }
}

From source file:com.windowtester.eclipse.ui.convert.WTAPIUsage.java

License:Open Source License

private void collectPluginsReferencedByClasspathEntry(PrintWriter writer, Collection<String> pluginIds,
        IJavaProject proj, IClasspathEntry entry) throws IOException {
    IPath path = entry.getPath();/*  w ww.ja  va2 s  . c om*/
    switch (entry.getEntryKind()) {

    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
        for (int i = path.segmentCount() - 1; i >= 0; i--) {
            String segment = path.segment(i);
            if (segment.startsWith("com.windowtester.")) {
                String id = segment;
                i++;
                while (i < path.segmentCount())
                    id += "/" + path.segment(i++);
                pluginIds.add(id);
                break;
            }
        }
        break;

    case IClasspathEntry.CPE_CONTAINER:
        if (path.segmentCount() >= 1 && path.segment(0).equals("org.eclipse.pde.core.requiredPlugins"))
            collectPluginsReferencedInManifest(pluginIds, proj);
        break;

    case IClasspathEntry.CPE_SOURCE:
    case IClasspathEntry.CPE_PROJECT:
        // ignored
        break;

    default:
        pluginIds.add("unknown " + entry.getEntryKind() + " - " + entry);
        break;
    }
}