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:me.gladwell.eclipse.m2e.android.configuration.Classpaths.java

License:Open Source License

public static IClasspathEntry findSourceEntry(IClasspathEntry[] classpath, final String path) {
    return matchEntry(classpath, and(entryOfType(IClasspathEntry.CPE_SOURCE), new Predicate<IClasspathEntry>() {
        public boolean apply(IClasspathEntry entry) {
            return entry.getPath().toOSString().endsWith(path);
        }/*from   w w w  .  j  a  v a2 s  .c o  m*/
    }));
}

From source file:me.gladwell.eclipse.m2e.android.configuration.Classpaths.java

License:Open Source License

public static IClasspathEntryDescriptor findSourceEntryDescriptor(IClasspathDescriptor classpath, String path) {
    for (IClasspathEntryDescriptor entry : classpath.getEntryDescriptors()) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().toString().endsWith(path)) {
            return entry;
        }/*  w  w  w .  j  a v a2 s .c o  m*/
    }
    return null;
}

From source file:me.gladwell.eclipse.m2e.android.configuration.MavenAndroidClasspathConfigurer.java

License:Open Source License

public void modifySourceFolderOutput(IJavaProject javaProject, AndroidProject project,
        IClasspathDescriptor classpath) {
    for (IClasspathEntry entry : classpath.getEntries()) {
        if (entry.getOutputLocation() != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                && !entry.getOutputLocation().equals(javaProject.getPath().append(ANDROID_CLASSES_FOLDER))) {
            classpath.removeEntry(entry.getPath());
            classpath.addSourceEntry(entry.getPath(), javaProject.getPath().append(ANDROID_CLASSES_FOLDER),
                    false);/*  ww  w . j  a va 2 s .  co m*/
        }
    }
}

From source file:me.gladwell.eclipse.m2e.android.project.EclipseClasspath.java

License:Open Source License

public Iterable<SourceEntry> getSourceEntries() {
    List<SourceEntry> entries = new ArrayList<SourceEntry>();
    for (IClasspathEntryDescriptor entry : classpath.getEntryDescriptors()) {
        if (entry.getOutputLocation() != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            entries.add(new EclipseSourceEntry(project.getProject(), entry));
        }//from   w ww  .  j  a v a  2 s  . c om
    }
    return entries;
}

From source file:me.gladwell.eclipse.m2e.android.project.MavenEclipseClasspath.java

License:Open Source License

public Iterable<SourceEntry> getSourceEntries() {
    List<SourceEntry> entries = new ArrayList<SourceEntry>();
    for (IClasspathEntryDescriptor entry : classpath.getEntryDescriptors()) {
        if (entry.getOutputLocation() != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            entries.add(new EclipseSourceEntry(project, classpath, entry));
        }//from  w ww  .  j  a  v a  2  s .co m
    }
    return entries;
}

From source file:monolipse.core.internal.BooNature.java

License:Open Source License

private Map<IClasspathEntry, IClasspathEntry> addExclusionPatternsTo(IClasspathEntry[] classpath) {
    Map<IClasspathEntry, IClasspathEntry> modified = new HashMap<IClasspathEntry, IClasspathEntry>();
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE)
            continue;

        IPath[] exclusionPatterns = entry.getExclusionPatterns();
        IPath[] newExclusionPatterns = addExclusionPatternsTo(exclusionPatterns);
        if (exclusionPatterns == newExclusionPatterns)
            continue;

        IClasspathEntry newSourceEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                newExclusionPatterns, entry.getOutputLocation(), entry.getExtraAttributes());

        modified.put(entry, newSourceEntry);
    }//from   w w  w  . j  a  v a2 s. c  o  m
    return modified;
}

From source file:net.kbserve.pyjdt.properties.models.CPEAbstractContainer.java

License:Open Source License

/**
 * Update the list of children to include the ICPEType contains the giveb IClasspathEntry
 * //  w ww . ja va  2s .  c  o m
 * @param child
 *            the child
 * @param project
 *            the project
 * @return the iCPE type
 */
public synchronized ICPEType updateChild(IClasspathEntry child, IProject project) {

    String stringPath = makeStringPath(child.getPath());
    ICPEType icp = getChild(stringPath);
    if (icp == null) {
        switch (child.getEntryKind()) {
        case (IClasspathEntry.CPE_CONTAINER):
            icp = new CPEContainer();
            break;
        case (IClasspathEntry.CPE_LIBRARY):
            icp = new CPELibrary();
            break;
        case (IClasspathEntry.CPE_PROJECT):
            icp = new CPEProject();
            break;
        case (IClasspathEntry.CPE_SOURCE):
            icp = new CPESource();
            break;
        case (IClasspathEntry.CPE_VARIABLE):
            icp = new CPEVariable();
            break;
        default:
            throw new UnsupportedOperationException(
                    "Unsupported IClasspathEntry.getEntryKind() = '" + child.getEntryKind() + "' on " + child);
        }
        children.add(icp);
        icp.setPath(stringPath);
        icp.setParent(this.getPath());
    }

    return icp;
}

From source file:net.rim.ejde.internal.core.BasicClasspathElementChangedListener.java

License:Open Source License

/**
 * Checks if all source files are existing. If not, create them.
 *
 * @param javaProj// w  w  w.  j  a  v a 2  s  .  c  o  m
 */
private void checkSourceFolders(final IJavaProject javaProj) {
    if (javaProj == null)
        return;
    if (javaProj.exists()) {
        try {
            if (!javaProj.isOpen()) {
                javaProj.open(new NullProgressMonitor());
            }
            IClasspathEntry[] entries = javaProj.getRawClasspath();
            for (IClasspathEntry entry : entries) {
                if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) {
                    IPath path = entry.getPath();
                    final IPath folderPath = path.removeFirstSegments(1);
                    if (!folderPath.isEmpty()) {
                        Display.getDefault().asyncExec(new Runnable() {
                            public void run() {
                                try {
                                    ImportUtils.createFolders(javaProj.getProject(), folderPath,
                                            IResource.FORCE);
                                } catch (CoreException e) {
                                    _log.error(e.getMessage());
                                }
                            }
                        });
                    }
                }
            }
        } catch (JavaModelException e) {
            _log.error("findProjectSources: Could not retrieve project sources:", e); //$NON-NLS-1$
        }
    }
}

From source file:net.rim.ejde.internal.core.RimIDEUtil.java

License:Open Source License

/**
 * Gets a file that exists in an Eclipse project.
 * <p>/*from   w  ww .  ja  v  a  2s .com*/
 * TODO: Someone can probably optimize this method better. Like using some of the IWorkspaceRoot.find*() methods...
 *
 * @param project
 *            the Eclipse project the file belongs to
 * @param file
 *            the File which is in the Eclipse project
 * @return the Eclipse resource file associated with the file
 */
public static IResource getResource(IProject project, File file) {
    IJavaProject javaProject = JavaCore.create(project);
    IPath filePath = new Path(file.getAbsolutePath());
    try {
        IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true);

        IFile input = null;
        // Look for a source folder
        for (IClasspathEntry classpathEntry : classpathEntries) {
            if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {

                // Try to resolve the source container
                IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
                IResource resource = workspaceRoot.findMember(classpathEntry.getPath());
                if (resource instanceof IContainer) {
                    try {
                        IContainer sourceContainer = (IContainer) resource;
                        File sourceContainerFile = EFS.getStore(resource.getLocationURI()).toLocalFile(EFS.NONE,
                                null);
                        IPath sourceFolderPath = new Path(sourceContainerFile.getAbsolutePath());

                        // See if the file path is within this source folder
                        // path
                        if (sourceFolderPath.isPrefixOf(filePath)) {
                            int segmentCount = sourceFolderPath.segmentCount();
                            IPath relativePath = filePath.removeFirstSegments(segmentCount);
                            input = sourceContainer.getFile(relativePath);

                            break;
                        }
                    } catch (CoreException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
        return input;
    } catch (JavaModelException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:net.rim.ejde.internal.util.ImportUtils.java

License:Open Source License

/**
 * Get the set of output paths of the given <code>IJavaProject</code>.
 *
 * @param javaProject//from w ww. j  a va  2 s.c o  m
 * @return
 * @throws JavaModelException
 */
static public Set<IPath> getOutputPathSet(IJavaProject javaProject) {
    HashSet<IPath> outputPathSet = new HashSet<IPath>();

    try {
        // get the output folder path of the project
        IPath outputFolderPath = javaProject.getOutputLocation();
        if (outputFolderPath != null) {
            outputPathSet.add(outputFolderPath);
        }

        IClasspathEntry[] _classPathEntries = javaProject.getRawClasspath();

        IClasspathEntry entry;

        for (int i = 0; i < _classPathEntries.length; i++) {
            entry = _classPathEntries[i];
            if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) {
                // get the output folder of the entry
                outputFolderPath = entry.getOutputLocation();
                if (outputFolderPath != null) {
                    outputPathSet.add(outputFolderPath);
                }
            }
        }
    } catch (JavaModelException e) {
        _log.debug(e.getMessage(), e);
    }

    return outputPathSet;
}