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.google.gwt.eclipse.core.runtime.GWTProjectsRuntime.java

License:Open Source License

@Override
public File getDevJar() throws SdkException /* throws Exception */, JavaModelException {

    IStringVariableManager variableManager = getVariableManager();
    IValueVariable valueVariable = variableManager.getValueVariable("gwt_devjar");
    if (valueVariable != null) {
        String value = valueVariable.getValue();
        if (value != null) {
            IPath path = new Path(value);
            File file = path.toFile();
            if (!file.exists()) {
                throw new SdkException("gwt_devjar Run/Debug variable points to a non-existent jar: " + value);
            }//from ww  w.j a  va  2 s  .c  o  m

            return file;
        }
    }

    // We're going to have to search down the trunk to find the built gwt-dev
    // .jar. This assumes that the user has built the trunk at least once

    // TODO: can we remove the check for gwt.devjar from applicationCreator?

    IProject userProject = ResourcesPlugin.getWorkspace().getRoot().getProject(GWT_USER_PROJECT_NAME);
    if (!userProject.exists()) {
        throw new SdkException("The project ' " + userProject.getName() + "' does not exist in the workspace.");
    }

    IJavaProject javaUserProject = JavaCore.create(userProject);

    if (!javaUserProject.exists()) {
        throw new SdkException("The project ' " + userProject.getName() + "' is not a Java project.");
    }

    IClasspathEntry[] rawClasspaths = javaUserProject.getRawClasspath();

    File stagingDir = null;
    IPath stagingPathLocation = null;

    for (IClasspathEntry rawClasspath : rawClasspaths) {
        if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_SOURCE) {

            IPath sourcePathLocation = getAbsoluteLocation(rawClasspath.getPath(), userProject);
            stagingPathLocation = sourcePathLocation.removeLastSegments(2)
                    .append(STAGING_FOLDER_RELATIVE_LOCATION);

            stagingDir = stagingPathLocation.toFile();
            if (stagingDir.exists()) {
                break;
            }
        }
    }

    if (stagingPathLocation == null) {
        throw new SdkException("Contributor SDK build directory not found; Project '" + userProject.getName()
                + "' does not have any source folders.");
    }

    if (stagingDir == null || !stagingDir.exists()) {
        throw new SdkException("Contributor SDK build directory not found (expected at "
                + stagingPathLocation.toString() + ")");
    }

    // Find the staging output directory: gwt-<platform>-<version>
    final File[] buildDirs = stagingDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File file) {
            return (file.isDirectory() && file.getName().startsWith("gwt-"));
        }
    });
    if (buildDirs.length == 0) {
        throw new SdkException("Contributor SDK build directory not found (expected at " + stagingDir.toString()
                + File.separator + "gwt-<platform>-<version>)");
    }

    // Find the gwt-dev .jar
    File[] gwtDevJars = buildDirs[0].listFiles(new FileFilter() {
        @Override
        public boolean accept(File file) {
            String name = file.getName();
            IPath sdkLocationPath = Path.fromOSString(buildDirs[0].getAbsolutePath());
            return (name.equalsIgnoreCase(Util.getDevJarName(sdkLocationPath)));
        }
    });
    if (gwtDevJars.length == 0) {
        throw new SdkException("Contributor SDK build directory missing required JAR files");
    }

    return gwtDevJars[0];
}

From source file:com.google.inject.tools.ideplugin.eclipse.EclipseJavaProject.java

License:Apache License

private List<String> expandClasspath(IClasspathEntry[] entries, String projectName, String projectLocation)
        throws Exception {
    final List<String> args = new ArrayList<String>();
    IResource presource;/*from w  ww  .  jav a 2 s  . c  o m*/
    String resourceLocation;
    String path;
    for (IClasspathEntry entry : entries) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_CONTAINER:
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project);
            args.addAll(expandClasspath(container.getClasspathEntries(), projectName, projectLocation));
            break;
        case IClasspathEntry.CPE_SOURCE:
            IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            path = resource.getLocation().makeAbsolute().toOSString();
            if (path.startsWith("/" + projectName)) {
                args.add(path.replaceFirst("/" + projectName, projectLocation));
            } else {
                args.add(path);
            }
            break;
        case IClasspathEntry.CPE_LIBRARY:
            path = entry.getPath().makeAbsolute().toOSString();
            if (path.startsWith("/" + projectName)) {
                args.add(path.replaceFirst("/" + projectName, projectLocation));
            } else {
                args.add(path);
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            presource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            resourceLocation = presource.getLocation().makeAbsolute().toOSString();
            String outputLocation = resourceLocation;
            args.add(outputLocation.replaceFirst(presource.getName(), resourceLocation));
            break;
        case IClasspathEntry.CPE_VARIABLE:
            break;
        default:
            //never happens
        }
    }
    return args;
}

From source file:com.halware.nakedide.eclipse.core.util.JavaCoreUtils.java

License:Open Source License

public final static List<IClasspathEntry> getSourceFolders(IJavaProject javaProject) throws JavaModelException {
    IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(false);
    List<IClasspathEntry> sourceFolders = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry classpathEntry : classpathEntries) {
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            sourceFolders.add(classpathEntry);
        }/*from   ww w. ja va2 s.c  o m*/
    }
    return sourceFolders;
}

From source file:com.ibm.wala.ide.util.JavaEclipseProjectPath.java

License:Open Source License

@Override
protected void resolveClasspathEntry(IJavaProject project, IClasspathEntry entry, ILoader loader,
        boolean includeSource, boolean cpeFromMainProject) {
    entry = JavaCore.getResolvedClasspathEntry(entry);
    switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE: {
        resolveSourcePathEntry(includeSource ? JavaSourceLoader.SOURCE : Loader.APPLICATION, includeSource,
                cpeFromMainProject, entry.getPath(), entry.getOutputLocation(), entry.getExclusionPatterns(),
                "java");
        break;//from w  w  w  . ja  v a2  s  .  c o  m
    }
    case IClasspathEntry.CPE_LIBRARY: {
        resolveLibraryPathEntry(loader, entry.getPath());
        break;
    }
    case IClasspathEntry.CPE_PROJECT: {
        resolveProjectPathEntry(loader, includeSource, entry.getPath());
        break;
    }
    case IClasspathEntry.CPE_CONTAINER: {
        try {
            IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), project);
            IClasspathEntry[] entries = cont.getClasspathEntries();
            resolveClasspathEntries(project, Arrays.asList(entries),
                    cont.getKind() == IClasspathContainer.K_APPLICATION ? loader : Loader.PRIMORDIAL,
                    includeSource, false);
        } catch (CoreException e) {
            System.err.println(e);
            Assertions.UNREACHABLE();
        }
    }
    }
}

From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java

License:Open Source License

private void addJavaProject(IJavaProject project) throws CoreException {
    if (project != null) {
        final Map<File, IPackageFragmentRoot> classpath = new LinkedHashMap<File, IPackageFragmentRoot>();
        for (IPackageFragmentRoot fragment : project.getPackageFragmentRoots()) {
            if (fragment.getKind() == IPackageFragmentRoot.K_BINARY
                    && fragment.getSourceAttachmentPath() != null) {
                File classpathLocation;
                if (fragment.isExternal()) {
                    classpathLocation = fragment.getPath().toFile();
                } else {
                    classpathLocation = toFile(fragment.getPath());
                }//from  w  ww.  java2  s.  c o m
                if (classpathLocation != null) {
                    classpath.put(classpathLocation, fragment);
                }
            }
        }

        final JavaProjectInfo projectInfo = new JavaProjectInfo(project, classpath);

        final Set<File> projectLocations = new HashSet<File>();

        final String jarLocation = project.getProject().getPersistentProperty(BinaryProjectPlugin.QNAME_JAR);
        if (jarLocation != null) {
            // maven binary project
            projectLocations.add(new File(jarLocation));
        } else {
            // regular project
            projectLocations.add(toFile(project.getOutputLocation()));
            for (IClasspathEntry cpe : project.getRawClasspath()) {
                if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    projectLocations.add(toFile(cpe.getOutputLocation()));
                }
            }
        }

        synchronized (lock) {
            projects.put(project, projectLocations);
            for (File projectLocation : projectLocations) {
                locations.put(projectLocation, projectInfo);
            }
        }
    }
}

From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java

License:Open Source License

static ISourceContainer getProjectSourceContainer(IJavaProject javaProject) {
    List<ISourceContainer> containers = new ArrayList<ISourceContainer>();

    boolean hasSources = false;

    try {//from w  w w  .ja  v  a2 s. c o  m
        for (IClasspathEntry cpe : javaProject.getRawClasspath()) {
            switch (cpe.getEntryKind()) {
            case IClasspathEntry.CPE_SOURCE:
                hasSources = true;
                break;
            case IClasspathEntry.CPE_LIBRARY:
                IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                IResource lib = workspaceRoot.findMember(cpe.getPath());
                IPackageFragmentRoot fragmentRoot;
                if (lib != null) {
                    fragmentRoot = javaProject.getPackageFragmentRoot(lib);
                } else {
                    fragmentRoot = javaProject.getPackageFragmentRoot(cpe.getPath().toOSString());
                }
                containers.add(new PackageFragmentRootSourceContainer(fragmentRoot));
                break;
            }
        }
    } catch (JavaModelException e) {
        // ignore... maybe log
    }

    if (hasSources) {
        containers.add(0, new JavaProjectSourceContainer(javaProject));
    }

    if (containers.isEmpty()) {
        return null;
    }

    if (containers.size() == 1) {
        return containers.get(0);
    }

    return new CompositeSourceContainer(containers);
}

From source file:com.iw.plugins.spindle.ui.wizards.project.BaseNewTapestryProjectJavaPage.java

License:Mozilla Public License

/**
 * @param entries/*from   w ww . j av a 2s .  c  o  m*/
 * @return
 */
private IClasspathEntry[] checkEntries(IClasspathEntry[] entries) throws CoreException {

    if (entries == null) {
        createSrcFolder();
        return new IClasspathEntry[] { createSrcClasspathEntry(), TapestryProjectInstallData.TAPESTRY_FRAMEWORK,
                JavaRuntime.getDefaultJREContainerEntry() };

    }

    boolean hasSrcEntry = false;
    boolean hasTapestryEntry = false;
    boolean hasDefaultJREEntry = false;
    List allEntries = Arrays.asList(entries);
    for (Iterator iter = allEntries.iterator(); iter.hasNext();) {
        IClasspathEntry element = (IClasspathEntry) iter.next();
        if (!hasSrcEntry && element.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            hasSrcEntry = true;
        } else if (element.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (!hasTapestryEntry)
                hasTapestryEntry = element.getPath().segment(0).equals(TapestryCore.CORE_CONTAINER);
            if (!hasDefaultJREEntry)
                hasDefaultJREEntry = element.getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER);
        }
    }

    if (!hasSrcEntry) {
        createSrcFolder();
        allEntries.add(createSrcClasspathEntry());

    }

    if (!hasTapestryEntry)
        allEntries.add(TapestryProjectInstallData.TAPESTRY_FRAMEWORK);

    if (!hasDefaultJREEntry)
        allEntries.add(JavaRuntime.getDefaultJREContainerEntry());

    return (IClasspathEntry[]) allEntries.toArray(new IClasspathEntry[allEntries.size()]);
}

From source file:com.iw.plugins.spindle.ui.wizards.project.BaseNewTapestryProjectJavaPage.java

License:Mozilla Public License

protected void updateStatus(IStatus status) {
    super.updateStatus(status);
    if (status.isOK()) {
        IClasspathEntry[] classpath = getRawClassPath();
        boolean hasSrcEntry = false;
        boolean hasTapestryFramework = false;
        for (int i = 0; i < classpath.length; i++) {
            if (!hasSrcEntry && classpath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                hasSrcEntry = true;//from  ww w  .j  a  v  a 2 s . c om

            } else if (!hasTapestryFramework && classpath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = classpath[i].getPath();
                if (path.segment(0).equals(TapestryCore.CORE_CONTAINER)) {
                    hasTapestryFramework = true;
                }
            }

        }
        IStatus tapStatus = null;
        if (!hasSrcEntry) {

            tapStatus = new Status(IStatus.ERROR, TapestryCore.PLUGIN_ID, 0,
                    UIPlugin.getString("new-project-wizard-must-have-src-folder"), null);
        }

        if (tapStatus != null)
            super.updateStatus(tapStatus);
    }
}

From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java

License:Open Source License

/**
 * Get all the resolved classpath entries for a specific project. The entries 
 * with ID JRClasspathContainer.ID and JavaRuntime.JRE_CONTAINER are not resolved
 * or included in the result. At also add the source and output folder provided with the 
 * project//from   www.j ava2  s .co m
 * 
 * @param project the project where the file to compile is contained, must be not null
 * @return a not null list of string that contains the classpath to include in the compilation project
 */
private List<String> getClasspaths(IProject project) {
    IJavaProject jprj = JavaCore.create(project);
    List<String> classpath = new ArrayList<String>();
    IWorkspaceRoot wsRoot = project.getWorkspace().getRoot();
    if (jprj != null) {
        try {
            IClasspathEntry[] entries = jprj.getRawClasspath();

            //Add the default output folder if any
            IPath defaultLocationPath = jprj.getOutputLocation();
            if (defaultLocationPath != null) {
                IFolder entryOutputFolder = wsRoot.getFolder(defaultLocationPath);
                classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
            }

            for (IClasspathEntry en : entries) {
                if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    String containerPath = en.getPath().toString();
                    //Don't add the eclipse runtime and the classpath extension defined in the exclusion list
                    if (!containerPath.startsWith(JavaRuntime.JRE_CONTAINER)
                            && !classpathExclusionSet.contains(containerPath)) {
                        addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(),
                                classpath, jprj);
                    }
                } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    classpath.add(wsRoot.findMember(en.getPath()).getLocation().toOSString() + File.separator);
                } else if (en.getEntryKind() == IClasspathEntry.CPE_SOURCE
                        && en.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    //check if is a source folder and if it has a custom output folder to add them also to the classpath
                    IPath entryOutputLocation = en.getOutputLocation();
                    if (entryOutputLocation != null) {
                        IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation);
                        classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
                    }
                } else {
                    //It is a jar check if it is internal to the workspace of external
                    IPath location = wsRoot.getFile(en.getPath()).getLocation();
                    if (location == null) {
                        //The location could not be resolved from the root of the workspace, it is external
                        classpath.add(en.getPath().toOSString());
                    } else {
                        //The location has been resolved from the root of the workspace, it is internal
                        classpath.add(location.toOSString());
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return classpath;
}

From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java

License:Open Source License

/**
 * Add an array of classpath entry to the result set. If an entry is a classpath container 
 * then it is resolved and the resulting entries are added recursively
 * /*from   w  w  w  . ja va  2s  .  c  o  m*/
 * @param entries the entries to add
 * @param classpath the current result
 * @param jprj the current java project
 */
private void addEntries(IClasspathEntry[] entries, List<String> classpath, IJavaProject jprj) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    for (IClasspathEntry en : entries) {
        if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            try {
                addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(), classpath,
                        jprj);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT
                || en.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            classpath.add(workspace.getRoot().findMember(en.getPath()).getLocation().toOSString()
                    + File.separator + "*"); //$NON-NLS-1$
        } else {
            classpath.add(en.getPath().toOSString());
        }
    }
}