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.core.builders.SourceEntryErrorReporter.java

License:Open Source License

public void initialize(ArrayList sourceEntries, ArrayList outputEntries, IClasspathEntry[] cpes,
        IProject project) {// w  w  w.  jav a  2s  . com

    fProject = project;
    IPath defaultOutputLocation = null;
    IJavaProject javaProject = JavaCore.create(fProject);
    try {
        defaultOutputLocation = javaProject.getOutputLocation();
    } catch (JavaModelException e) {
    }

    List pluginLibraryNames = new ArrayList(1);
    IMonitorModelBase pluginModel = MonitorRegistry.findModel(fProject);
    if (pluginModel != null) {
        IMonitorLibrary[] pluginLibraries = pluginModel.getMonitorBase().getLibraries();
        for (int i = 0; i < pluginLibraries.length; i++) {
            pluginLibraryNames.add(pluginLibraries[i].getName());
        }
    }
    if (!pluginLibraryNames.contains(".")) { //$NON-NLS-1$
        pluginLibraryNames.add("."); //$NON-NLS-1$)
    }
    for (int i = 0; i < cpes.length; i++) {
        if (cpes[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath sourcePath = getPath(cpes[i]);
            if (sourcePath == null)
                continue;

            IPath outputLocation = cpes[i].getOutputLocation();
            if (outputLocation == null)
                outputLocation = defaultOutputLocation;
            IPath outputPath = getPath(outputLocation);

            OutputFolder outputFolder = (OutputFolder) fOutputFolderMap.get(outputPath);
            if (outputFolder == null) {
                outputFolder = new OutputFolder(outputPath);
            }

            SourceFolder sourceFolder = (SourceFolder) fSourceFolderMap.get(sourcePath);
            if (sourceFolder == null) {
                sourceFolder = new SourceFolder(sourcePath, outputFolder);
            }

            outputFolder.addSourceFolder(sourceFolder);
            fOutputFolderMap.put(outputPath, outputFolder);
            fSourceFolderMap.put(sourcePath, sourceFolder);
        } else if (cpes[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IClasspathEntry entry = cpes[i];
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            IPath outputPath = null;
            if (roots.length == 1) { // should only be one entry for a library
                if (!roots[0].isArchive()) {
                    outputPath = getPath(entry);
                    OutputFolder outputFolder = new OutputFolder(outputPath, true);
                    fOutputFolderMap.put(outputPath, outputFolder);
                }
            }
        }
    }

    for (Iterator iterator = sourceEntries.iterator(); iterator.hasNext();) {
        IBuildEntry sourceEntry = (IBuildEntry) iterator.next();
        String libName = sourceEntry.getName().substring(PROPERTY_SOURCE_PREFIX.length());
        if (!pluginLibraryNames.contains(libName)) {
            prepareError(sourceEntry.getName(), null,
                    NLS.bind(MDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName),
                    MDEMarkerFactory.B_REMOVAL, fSrcLibSeverity, MDEMarkerFactory.CAT_OTHER);
        }
        String[] tokens = sourceEntry.getTokens();
        for (int i = 0; i < tokens.length; i++) {
            IPath path = new Path(tokens[i]).addTrailingSeparator();
            SourceFolder sourceFolder = (SourceFolder) fSourceFolderMap.get(path);
            if (sourceFolder == null) {
                sourceFolder = new SourceFolder(path, null);
                fSourceFolderMap.put(path, sourceFolder);
            }
            sourceFolder.setToken(tokens[i]);
            sourceFolder.addLib(libName);
        }
    }

    for (Iterator iterator = outputEntries.iterator(); iterator.hasNext();) {
        IBuildEntry outputEntry = (IBuildEntry) iterator.next();
        String libName = outputEntry.getName().substring(PROPERTY_OUTPUT_PREFIX.length());
        if (!pluginLibraryNames.contains(libName)) {
            prepareError(outputEntry.getName(), null,
                    NLS.bind(MDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName),
                    MDEMarkerFactory.B_REMOVAL, fOututLibSeverity, MDEMarkerFactory.CAT_OTHER);
        }
        String[] tokens = outputEntry.getTokens();
        for (int i = 0; i < tokens.length; i++) {
            IPath path = new Path(tokens[i]).addTrailingSeparator();
            if (path.segmentCount() == 1 && path.segment(0).equals(".")) { //$NON-NLS-1$
                // translate "." to root path
                path = Path.ROOT;
            }
            OutputFolder outputFolder = (OutputFolder) fOutputFolderMap.get(path);
            if (outputFolder == null) {
                outputFolder = new OutputFolder(path);
                fOutputFolderMap.put(path, outputFolder);
            }
            outputFolder.setToken(tokens[i]);
            outputFolder.addLib(libName);
        }
    }
}

From source file:com.siteview.mde.internal.core.ClasspathComputer.java

License:Open Source License

private static void addSourceAndLibraries(IProject project, IMonitorModelBase model, IBuild build,
        boolean clear, Map sourceLibraryMap, ArrayList result) throws CoreException {

    HashSet paths = new HashSet();

    // keep existing source folders
    if (!clear) {
        IClasspathEntry[] entries = JavaCore.create(project).getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                if (paths.add(entry.getPath()))
                    result.add(entry);//from ww w. ja  v a  2  s  .  c o  m
            }
        }
    }

    IClasspathAttribute[] attrs = getClasspathAttributes(project, model);
    IMonitorLibrary[] libraries = model.getMonitorBase().getLibraries();
    for (int i = 0; i < libraries.length; i++) {
        IBuildEntry buildEntry = build == null ? null : build.getEntry("source." + libraries[i].getName()); //$NON-NLS-1$
        if (buildEntry != null) {
            addSourceFolder(buildEntry, project, paths, result);
        } else {
            IPath sourceAttachment = sourceLibraryMap != null
                    ? (IPath) sourceLibraryMap.get(libraries[i].getName())
                    : null;
            if (libraries[i].getName().equals(".")) //$NON-NLS-1$
                addJARdPlugin(project, ClasspathUtilCore.getFilename(model), sourceAttachment, attrs, result);
            else
                addLibraryEntry(project, libraries[i], sourceAttachment, attrs, result);
        }
    }
    if (libraries.length == 0) {
        if (build != null) {
            IBuildEntry buildEntry = build == null ? null : build.getEntry("source.."); //$NON-NLS-1$
            if (buildEntry != null) {
                addSourceFolder(buildEntry, project, paths, result);
            }
        } else if (ClasspathUtilCore.hasBundleStructure(model)) {
            IPath sourceAttachment = sourceLibraryMap != null ? (IPath) sourceLibraryMap.get(".") : null; //$NON-NLS-1$
            addJARdPlugin(project, ClasspathUtilCore.getFilename(model), sourceAttachment, attrs, result);
        }
    }
}

From source file:com.siteview.mde.internal.core.ClasspathHelper.java

License:Open Source License

private static Map getClasspathMap(IProject project, boolean checkExcluded, boolean onlyJarsIfLinked,
        boolean absolutePaths) throws JavaModelException {
    List excluded = getFoldersToExclude(project, checkExcluded);
    IJavaProject jProject = JavaCore.create(project);
    HashMap map = new HashMap();
    IClasspathEntry[] entries = jProject.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
        // most of the paths we get will be project relative, so we need to make the paths relative
        // we will have problems adding an "absolute" path that is workspace relative
        IPath output = null, source = null;
        if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            source = entries[i].getPath();
            output = entries[i].getOutputLocation();
            if (output == null)
                output = jProject.getOutputLocation();
        } else if (entries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            source = entries[i].getPath();
            output = entries[i].getPath();
            if (source.segmentCount() == 1)
                source = new Path(DOT);
        }/* w w  w. ja  v  a2s  . c  om*/
        if (output != null && !excluded.contains(output)) {
            IResource file = project.findMember(output.removeFirstSegments(1));
            // make the path either relative or absolute
            if (file != null) {
                boolean isLinked = file.isLinked(IResource.CHECK_ANCESTORS);
                if (entries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE && !isLinked && onlyJarsIfLinked)
                    continue;
                output = (isLinked || absolutePaths) ? file.getLocation().makeAbsolute()
                        : output.makeRelative();
            } else
                continue;
            ArrayList list = (ArrayList) map.get(source);
            if (list == null)
                list = new ArrayList();
            list.add(output);
            map.put(source, list);
        }
    }
    return map;
}

From source file:com.siteview.mde.internal.core.exports.WorkspaceExportHelper.java

License:Open Source License

private Map getPluginOutputFolders(IBuildModel buildModel, IJavaProject javaProject) throws JavaModelException {
    Map outputEntries = new HashMap();

    IBuildEntry[] buildEntries = buildModel.getBuild().getBuildEntries();
    for (int i = 0; i < buildEntries.length; i++) {
        String name = buildEntries[i].getName();
        if (name.startsWith(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX)) {
            Set outputPaths = new HashSet();

            String[] sourceFolders = buildEntries[i].getTokens();
            for (int j = 0; j < sourceFolders.length; j++) {

                IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
                for (int k = 0; k < classpathEntries.length; k++) {
                    if (classpathEntries[k].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                        IPath sourcePath = classpathEntries[k].getPath().removeFirstSegments(1); // Entries include project as first segment
                        if (sourcePath.equals(new Path(sourceFolders[j]))) {
                            IPath outputPath = classpathEntries[k].getOutputLocation();
                            if (outputPath == null) {
                                outputPath = javaProject.getOutputLocation();
                            }//from   w ww .j  a  va  2 s .co  m
                            outputPaths.add(outputPath.removeFirstSegments(1)); // Entries include project as first segment
                        }
                    }
                }
            }
            if (!outputPaths.isEmpty()) {
                outputEntries.put(name.substring(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX.length()),
                        outputPaths);
            }
        }
    }
    return outputEntries;
}

From source file:com.siteview.mde.internal.core.project.BundleProjectDescription.java

License:Open Source License

/**
 * Creates and returns a bundle claspath specifications for the given source.<library> build
 * entry//from   www .  j  a  v a2s.co m
 * 
 * @param project
 * @param entry
 * @param binary whether a binary folder (<code>true</code>) or source folder (<code>false</code>)
 * @return associated bundle classpath specifications or <code>null</code> if a malformed entry
 * @throws CoreException if unable to access Java build path
 */
private IBundleClasspathEntry[] getClasspathEntries(IProject project, IBuildEntry entry, boolean binary)
        throws CoreException {
    String[] tokens = entry.getTokens();
    IPath lib = null;
    if (binary) {
        lib = new Path(entry.getName().substring(IBuildEntry.OUTPUT_PREFIX.length()));
    } else {
        lib = new Path(entry.getName().substring(IBuildEntry.JAR_PREFIX.length()));
    }
    if (tokens != null && tokens.length > 0) {
        IBundleClasspathEntry[] bces = new IBundleClasspathEntry[tokens.length];
        for (int i = 0; i < tokens.length; i++) {
            IPath path = new Path(tokens[i]);
            IBundleClasspathEntry spec = null;
            if (binary) {
                spec = getBundleProjectService().newBundleClasspathEntry(null, path, lib);
            } else {
                IJavaProject jp = JavaCore.create(project);
                IPath output = null;
                if (jp.exists()) {
                    IClasspathEntry[] rawClasspath = jp.getRawClasspath();
                    for (int j = 0; j < rawClasspath.length; j++) {
                        IClasspathEntry cpe = rawClasspath[j];
                        if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                            if (cpe.getPath().removeFirstSegments(1).equals(path)) {
                                output = cpe.getOutputLocation();
                                if (output != null) {
                                    output = output.removeFirstSegments(1);
                                }
                                break;
                            }
                        }
                    }
                }
                spec = getBundleProjectService().newBundleClasspathEntry(path, output, lib);
            }
            bces[i] = spec;
        }
        return bces;
    }
    return null;
}

From source file:com.siteview.mde.internal.launching.launcher.LaunchArgumentsHelper.java

License:Open Source License

private static String getEquinoxStartupPath(String packageName) throws CoreException {
    IMonitorModelBase model = MonitorRegistry.findModel(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER);
    if (model != null) {
        IResource resource = model.getUnderlyingResource();
        // found in the target
        if (resource == null)
            return model.getInstallLocation();

        // find it in the workspace
        IProject project = resource.getProject();
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject jProject = JavaCore.create(project);
            IClasspathEntry[] entries = jProject.getRawClasspath();
            for (int i = 0; i < entries.length; i++) {
                int kind = entries[i].getEntryKind();
                if (kind == IClasspathEntry.CPE_SOURCE || kind == IClasspathEntry.CPE_LIBRARY) {
                    IPackageFragmentRoot[] roots = jProject.findPackageFragmentRoots(entries[i]);
                    for (int j = 0; j < roots.length; j++) {
                        if (roots[j].getPackageFragment(packageName).exists()) {
                            // if source folder, find the output folder
                            if (kind == IClasspathEntry.CPE_SOURCE) {
                                IPath path = entries[i].getOutputLocation();
                                if (path == null)
                                    path = jProject.getOutputLocation();
                                path = path.removeFirstSegments(1);
                                return project.getLocation().append(path).toOSString();
                            }/*from   ww  w  .ja  v  a  2  s .  c o m*/
                            // else if is a library jar, then get the location of the jar itself
                            IResource jar = roots[j].getResource();
                            if (jar != null) {
                                return jar.getLocation().toOSString();
                            }
                        }
                    }
                }
            }
        }
    }
    Bundle bundle = Platform.getBundle(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER);
    if (bundle != null) {
        try {
            URL url = FileLocator.resolve(bundle.getEntry("/")); //$NON-NLS-1$
            url = FileLocator.toFileURL(url);
            String path = url.getFile();
            if (path.startsWith("file:")) //$NON-NLS-1$
                path = path.substring(5);
            path = new File(path).getAbsolutePath();
            if (path.endsWith("!")) //$NON-NLS-1$
                path = path.substring(0, path.length() - 1);
            return path;
        } catch (IOException e) {
        }
    }
    return null;
}

From source file:com.siteview.mde.internal.launching.launcher.LauncherUtils.java

License:Open Source License

private static String getTimeStamp(IProject project) {
    IJavaProject jp = JavaCore.create(project);
    try {//from  w w w.j  a va 2s  . c o m
        long timeStamp = 0;
        IClasspathEntry[] entries = jp.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                File file;
                IPath location = entries[i].getOutputLocation();
                if (location == null)
                    location = jp.getOutputLocation();
                IResource res = project.getWorkspace().getRoot().findMember(location);
                IPath path = res == null ? null : res.getLocation();
                if (path == null)
                    continue;
                file = path.toFile();
                Stack files = new Stack();
                files.push(file);
                while (!files.isEmpty()) {
                    file = (File) files.pop();
                    if (file.isDirectory()) {
                        File[] children = file.listFiles();
                        if (children != null) {
                            for (int j = 0; j < children.length; j++)
                                files.push(children[j]);
                        }
                    } else if (file.getName().endsWith(".class") && timeStamp < file.lastModified()) //$NON-NLS-1$
                        timeStamp = file.lastModified();
                }
            }
        }
        IFile[] otherFiles = new IFile[] { PDEProject.getManifest(project),
                PDEProject.getBuildProperties(project) };
        for (int i = 0; i < otherFiles.length; i++) {
            IFile file = otherFiles[i];
            if (file != null) {
                long fileTimeStamp = file.getRawLocation().toFile().lastModified();
                if (timeStamp < fileTimeStamp)
                    timeStamp = fileTimeStamp;
            }
        }
        return Long.toString(timeStamp);
    } catch (JavaModelException e) {
    }
    return "0"; //$NON-NLS-1$
}

From source file:com.siteview.mde.internal.ui.editor.monitor.LibrarySection.java

License:Open Source License

private void configureSourceBuildEntry(IBuildModel bmodel, String oldPath, String newPath)
        throws CoreException {
    IBuild build = bmodel.getBuild();/*from  w  ww .  ja  v a  2 s  . co m*/
    IBuildEntry entry = build.getEntry(PROPERTY_SOURCE_PREFIX + (oldPath != null ? oldPath : newPath));
    try {
        if (newPath != null) {
            if (entry == null) {
                IProject project = ((IModel) getPage().getModel()).getUnderlyingResource().getProject();
                IJavaProject jproject = JavaCore.create(project);
                ArrayList tokens = new ArrayList();
                IClasspathEntry[] entries = jproject.getRawClasspath();
                for (int i = 0; i < entries.length; i++)
                    if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE)
                        tokens.add(
                                entries[i].getPath().removeFirstSegments(1).addTrailingSeparator().toString());
                if (tokens.size() == 0)
                    return;

                entry = bmodel.getFactory().createEntry(PROPERTY_SOURCE_PREFIX + newPath);
                for (int i = 0; i < tokens.size(); i++)
                    entry.addToken((String) tokens.get(i));
                build.add(entry);
            } else
                entry.setName(PROPERTY_SOURCE_PREFIX + newPath);
        } else if (entry != null && newPath == null)
            build.remove(entry);
    } catch (JavaModelException e) {
    }
}

From source file:com.siteview.mde.internal.ui.properties.SelfHostingPropertyPage.java

License:Open Source License

private String[] getOutputFolders() {
    IProject project = (IProject) getElement().getAdapter(IProject.class);
    ArrayList list = new ArrayList();
    try {/*from w ww . j ava  2s.  c  o m*/
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject jProject = JavaCore.create(project);
            list.add(jProject.getOutputLocation().toString());
            IClasspathEntry[] entries = jProject.getRawClasspath();
            for (int i = 0; i < entries.length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                        && entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    IPath path = entry.getOutputLocation();
                    if (path != null)
                        list.add(path.toString());
                }
            }
        }
    } catch (JavaModelException e) {
    } catch (CoreException e) {
    }
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:com.siteview.mde.internal.ui.util.TemplateFileGenerator.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   w  ww  . jav a2s .  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) throws CoreException {
    IFolder sourceFolder = null;

    try {
        IJavaProject javaProject = JavaCore.create(fProject);
        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 = fProject.getFolder(path);
                break;
            }
        }
    } catch (JavaModelException e) {
    }
    return sourceFolder;
}