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

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

Introduction

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

Prototype

IPath getOutputLocation();

Source Link

Document

Returns the full path to the specific location where the builder writes .class files generated for this source entry (entry kind #CPE_SOURCE ).

Usage

From source file:org.springsource.ide.eclipse.gradle.core.GradleProject.java

License:Open Source License

/**
 * Create an Eclipse source classpath entry from a Gradle source entry. May return null
 * if the entry looks invalid (e.g. the corresponding folder doesn't exist in the project)
 * @param oldEntries old source entries indexed by path, used to copy over exclusions and inclusions so they don't get lost.
 *///from  w ww  .j  av a 2 s  .com
private IClasspathEntry newSourceEntry(EclipseSourceDirectory gradleSourceDir,
        Map<IPath, IClasspathEntry> oldEntries) throws IllegalClassPathEntryException {
    Path gradleSourcePath = new Path(gradleSourceDir.getPath());
    try {
        IFolder srcFolder = getProject().getFolder(gradleSourcePath);
        if (!srcFolder.exists()) {
            throw new IllegalClassPathEntryException("non-existent source folder", this, gradleSourceDir);
        }
        IPath path = srcFolder.getFullPath();
        IClasspathEntry oldEntry = oldEntries.get(path);
        if (oldEntry == null) {
            return JavaCore.newSourceEntry(path);
        } else {
            return JavaCore.newSourceEntry(path, oldEntry.getInclusionPatterns(),
                    oldEntry.getExclusionPatterns(), oldEntry.getOutputLocation(),
                    oldEntry.getExtraAttributes());
        }
    } catch (IllegalClassPathEntryException e) {
        throw e;
    } catch (Throwable e) {
        throw new IllegalClassPathEntryException("illegal source folder", this, gradleSourceDir, e);
    }
}

From source file:org.summer.dsl.ui.shared.JdtHelper.java

License:Open Source License

public boolean isFromOutputPath(IResource resource) {
    IProject project = resource.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject != null && javaProject.exists()) {
        try {//from   w w  w  .ja  va 2 s .c om
            IPath defaultOutputLocation = javaProject.getOutputLocation();
            IPath resourcePath = resource.getFullPath();
            if (defaultOutputLocation != null && !defaultOutputLocation.isEmpty()
                    && defaultOutputLocation.isPrefixOf(resourcePath)) {
                return true;
            }
            IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
            for (IClasspathEntry classpathEntry : classpathEntries) {
                if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    IPath specializedOutputLocation = classpathEntry.getOutputLocation();
                    if (specializedOutputLocation != null) {
                        if (!specializedOutputLocation.equals(classpathEntry.getPath())
                                && specializedOutputLocation.isPrefixOf(resourcePath)) {
                            return true;
                        }
                    }
                }
            }
        } catch (CoreException e) {
            if (log.isDebugEnabled())
                log.debug("Error in isJavaTargetFolder():" + e.getMessage(), e);
        }
    }
    return false;
}

From source file:org.talend.designer.maven.project.CreateMavenCodeProject.java

License:Open Source License

private void changeClasspath(IProgressMonitor monitor, IProject p) {
    try {/*  w w w .j  av  a  2  s  .  c o m*/
        IJavaProject javaProject = JavaCore.create(p);
        IClasspathEntry[] rawClasspathEntries = javaProject.getRawClasspath();
        boolean changed = false;

        for (int index = 0; index < rawClasspathEntries.length; index++) {
            IClasspathEntry entry = rawClasspathEntries[index];

            IClasspathEntry newEntry = null;
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = entry.getPath();
                if (p.getFullPath().isPrefixOf(path)) {
                    path = path.removeFirstSegments(1);
                }

                // src/main/resources, in order to removing the 'excluding="**"'.
                if (MavenSystemFolders.RESOURCES.getPath().equals(path.toString())) {
                    newEntry = JavaCore.newSourceEntry(entry.getPath(), new IPath[0], new IPath[0], //
                            entry.getOutputLocation(), entry.getExtraAttributes());
                }

            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                // remove the special version of jre in container.
                IPath defaultJREContainerPath = JavaRuntime.newDefaultJREContainerPath();
                if (defaultJREContainerPath.isPrefixOf(entry.getPath())) {
                    // JavaRuntime.getDefaultJREContainerEntry(); //missing properties
                    // newEntry = JavaCore.newContainerEntry(defaultJREContainerPath, entry.getAccessRules(),
                    // entry.getExtraAttributes(), entry.isExported());
                }
            }
            if (newEntry != null) {
                rawClasspathEntries[index] = newEntry;
                changed = true;
            }

        }
        if (changed) {
            javaProject.setRawClasspath(rawClasspathEntries, monitor);
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}

From source file:org.talend.designer.maven.tools.creator.CreateMavenCodeProject.java

License:Open Source License

public static void changeClasspath(IProgressMonitor monitor, IProject p) {
    try {/*  w w  w .ja  v a 2s . c  o m*/
        IJavaProject javaProject = JavaCore.create(p);
        IClasspathEntry[] rawClasspathEntries = javaProject.getRawClasspath();
        boolean changed = false;

        for (int index = 0; index < rawClasspathEntries.length; index++) {
            IClasspathEntry entry = rawClasspathEntries[index];

            IClasspathEntry newEntry = null;
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = entry.getPath();
                if (p.getFullPath().isPrefixOf(path)) {
                    path = path.removeFirstSegments(1);
                }

                // src/main/resources, in order to removing the 'excluding="**"'.
                if (MavenSystemFolders.RESOURCES.getPath().equals(path.toString())) {
                    newEntry = JavaCore.newSourceEntry(entry.getPath(), new IPath[0], new IPath[0], //
                            entry.getOutputLocation(), entry.getExtraAttributes());
                }

                // src/test/resources, in order to removing the 'excluding="**"'.
                if (MavenSystemFolders.RESOURCES_TEST.getPath().equals(path.toString())) {
                    newEntry = JavaCore.newSourceEntry(entry.getPath(), new IPath[0], new IPath[0], //
                            entry.getOutputLocation(), entry.getExtraAttributes());
                }

            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                // remove the special version of jre in container.
                IPath defaultJREContainerPath = JavaRuntime.newDefaultJREContainerPath();
                if (defaultJREContainerPath.isPrefixOf(entry.getPath())) {
                    // JavaRuntime.getDefaultJREContainerEntry(); //missing properties
                    newEntry = JavaCore.newContainerEntry(defaultJREContainerPath, entry.getAccessRules(),
                            entry.getExtraAttributes(), entry.isExported());
                }
            }
            if (newEntry != null) {
                rawClasspathEntries[index] = newEntry;
                changed = true;
            }

        }
        if (changed) {
            javaProject.setRawClasspath(rawClasspathEntries, monitor);
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}

From source file:org.teavm.eclipse.TeaVMProjectBuilder.java

License:Apache License

private void prepareClassPath() throws CoreException {
    classPath = new URL[0];
    sourceContainers = new IContainer[0];
    sourceProviders = new SourceFileProvider[0];
    IProject project = getProject();//from  w w w . j  a v a 2 s  . com
    if (!project.hasNature(JavaCore.NATURE_ID)) {
        return;
    }
    IJavaProject javaProject = JavaCore.create(project);
    PathCollector collector = new PathCollector();
    SourcePathCollector srcCollector = new SourcePathCollector();
    SourcePathCollector binCollector = new SourcePathCollector();
    SourceFileCollector sourceFileCollector = new SourceFileCollector();
    IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
    try {
        if (javaProject.getOutputLocation() != null) {
            IContainer container = (IContainer) workspaceRoot.findMember(javaProject.getOutputLocation());
            collector.addPath(container.getLocation());
            binCollector.addContainer(container);
        }
    } catch (MalformedURLException e) {
        TeaVMEclipsePlugin.logError(e);
    }
    Queue<IJavaProject> projectQueue = new ArrayDeque<>();
    projectQueue.add(javaProject);
    Set<IJavaProject> visitedProjects = new HashSet<>();
    while (!projectQueue.isEmpty()) {
        javaProject = projectQueue.remove();
        if (!visitedProjects.add(javaProject)) {
            continue;
        }
        IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry entry : entries) {
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
                try {
                    collector.addPath(entry.getPath());
                } catch (MalformedURLException e) {
                    TeaVMEclipsePlugin.logError(e);
                }
                if (entry.getSourceAttachmentPath() != null) {
                    sourceFileCollector.addFile(entry.getSourceAttachmentPath());
                }
                break;
            case IClasspathEntry.CPE_SOURCE:
                if (entry.getOutputLocation() != null) {
                    try {
                        IResource res = workspaceRoot.findMember(entry.getOutputLocation());
                        if (res != null) {
                            collector.addPath(res.getLocation());
                        }
                    } catch (MalformedURLException e) {
                        TeaVMEclipsePlugin.logError(e);
                    }
                }
                IContainer srcContainer = (IContainer) workspaceRoot.findMember(entry.getPath());
                if (srcContainer != null) {
                    srcCollector.addContainer(srcContainer);
                    sourceFileCollector.addFile(srcContainer.getLocation());
                    try {
                        collector.addPath(srcContainer.getLocation());
                    } catch (MalformedURLException e) {
                        TeaVMEclipsePlugin.logError(e);
                    }
                }
                break;
            case IClasspathEntry.CPE_PROJECT: {
                IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
                IProject depProject = resource.getProject();
                if (!depProject.hasNature(JavaCore.NATURE_ID)) {
                    break;
                }
                IJavaProject depJavaProject = JavaCore.create(depProject);
                if (depJavaProject.getOutputLocation() != null) {
                    try {
                        IContainer container = (IContainer) workspaceRoot
                                .findMember(depJavaProject.getOutputLocation());
                        if (container != null) {
                            collector.addPath(container.getLocation());
                            binCollector.addContainer(container);
                        }
                    } catch (MalformedURLException e) {
                        TeaVMEclipsePlugin.logError(e);
                    }
                }
                projectQueue.add(depJavaProject);
                break;
            }
            }
        }
    }
    classPath = collector.getUrls();
    sourceContainers = srcCollector.getContainers();
    classFileContainers = binCollector.getContainers();
    sourceProviders = sourceFileCollector.getProviders();
}

From source file:x10dt.ui.launch.core.builder.AbstractX10Builder.java

License:Open Source License

/**
 * Returns the main generated file for the X10 file provided, i.e. for C++ back-end this should return the C++ file
 * corresponding to the X10 file in question.
 * /*from ww w .j a v  a2  s  . c  om*/
 * @param project
 *          The project containing the X10 file in question.
 * @param x10File
 *          The x10 file to consider.
 * @return A non-null file if we found one, otherwise <b>null</b>.
 * @throws CoreException
 *           Occurs if we could not access some project information or get the local file for the location identified.
 */
public File getMainGeneratedFile(final IJavaProject project, final IFile x10File) throws CoreException {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    for (final IClasspathEntry cpEntry : project.getRawClasspath()) {
        if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                && cpEntry.getPath().isPrefixOf(x10File.getFullPath())
                && !BuildPathUtils.isExcluded(x10File.getFullPath(), cpEntry)) {
            final IPath outputLocation;
            if (cpEntry.getOutputLocation() == null) {
                outputLocation = project.getOutputLocation();
            } else {
                outputLocation = cpEntry.getOutputLocation();
            }
            final StringBuilder sb = new StringBuilder();
            sb.append(File.separatorChar)
                    .append(x10File.getProjectRelativePath().removeFileExtension().toString())
                    .append(getFileExtension());
            final IPath projectRelativeFilePath = new Path(sb.toString());
            final int srcPathCount = cpEntry.getPath().removeFirstSegments(1).segmentCount();
            final IPath generatedFilePath = outputLocation
                    .append(projectRelativeFilePath.removeFirstSegments(srcPathCount));
            final IFileStore fileStore = EFS.getLocalFileSystem()
                    .getStore(URIUtils.getExpectedURI(root.getFile(generatedFilePath).getLocationURI()));
            if (fileStore.fetchInfo().exists()) {
                return fileStore.toLocalFile(EFS.NONE, null);
            }
        }
    }
    return null;
}

From source file:x10dt.ui.launch.core.builder.AbstractX10Builder.java

License:Open Source License

public static Collection<IPath> getProjectDependencies(IJavaProject project) throws JavaModelException {
    Collection<IPath> ret = new ArrayList<IPath>();
    if (project == null)
        return ret;
    for (final IClasspathEntry cpEntry : project.getRawClasspath()) {
        if (cpEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            final IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
            IJavaProject javaProject = JavaCore.create(wsRoot.getProject(cpEntry.getPath().toOSString()));
            ret.add(wsRoot.getLocation().append(javaProject.getOutputLocation()));
            for (final IClasspathEntry pEntry : javaProject.getRawClasspath()) {
                if (pEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    if (pEntry.getOutputLocation() != null) {
                        ret.add(wsRoot.getLocation().append(pEntry.getOutputLocation()));
                    }//from   w  w  w. ja  v  a2s .co  m
                }
            }
        }
    }
    return ret;
}

From source file:x10dt.ui.launch.core.utils.ProjectUtils.java

License:Open Source License

private static IPath getOutputLocation(IClasspathEntry cpEntry, IJavaProject project)
        throws JavaModelException {
    IPath specificPath = cpEntry.getOutputLocation();
    if (specificPath != null) {
        return specificPath;
    } else {/*from   w  ww . j  a  va 2  s.  c  om*/
        return project.getOutputLocation();
    }
}

From source file:x10dt.ui.launch.java.launching.X10LaunchConfigurationDelegate.java

License:Open Source License

private File getWorkingDir(final ILaunchConfiguration configuration, final IJavaProject javaProject,
        final String mainTypeName) throws CoreException {
    final IPath workDirPath = this.fLocalConfDelegate.getWorkingDirectoryPath(configuration);
    final String mainTypeFileName = mainTypeName.replace('.', File.separatorChar).concat(Constants.CLASS_EXT);
    if (workDirPath == null) {
        for (final IClasspathEntry cpEntry : javaProject.getRawClasspath()) {
            if ((cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
                    && (cpEntry.getOutputLocation() != null)) {
                final File dir = getWorkindDir(mainTypeFileName, cpEntry.getOutputLocation(), false);
                if (dir != null) {
                    return dir;
                }/*from w  w  w  .j  a  v  a2  s  . c  o  m*/
            }
        }
        return getWorkindDir(mainTypeFileName, javaProject.getOutputLocation(), true);
    } else {
        return getWorkindDir(mainTypeFileName, workDirPath, true);
    }
}