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.eclipse.virgo.ide.facet.core.FacetUtils.java

License:Open Source License

/**
 * Gets all the plan files found in the given project.
 *
 * @param project/*from  w w  w.  jav  a  2 s.c  o  m*/
 * @return
 */
public static Collection<IFile> getPlansInPlanProject(IProject project) {
    if (!isPlanProject(project)) {
        return Collections.emptyList();
    }

    final List<IFile> planFiles = new ArrayList<IFile>();

    // Collect output locations if java project
    final Set<IPath> outputLocations = new HashSet<IPath>();
    try {
        if (FacetUtils.hasNature(project, JavaCore.NATURE_ID)) {
            IJavaProject je = JavaCore.create(project);
            try {
                outputLocations.add(je.getOutputLocation());
                for (IClasspathEntry entry : je.getRawClasspath()) {
                    if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                        if (entry.getOutputLocation() != null) {
                            outputLocations.add(entry.getOutputLocation());
                        }
                    }
                }
            } catch (JavaModelException e) {
                // safe to ignore
            }
        }
        project.accept(new IResourceVisitor() {

            public boolean visit(IResource resource) throws CoreException {
                if (resource.isTeamPrivateMember() || resource.isDerived()) {
                    return false;
                }
                if (resource instanceof IFile && "plan".equals(resource.getFileExtension())) {
                    planFiles.add((IFile) resource);
                } else if (resource instanceof IContainer) {
                    IPath path = ((IContainer) resource).getFullPath();
                    for (IPath outputLocation : outputLocations) {
                        if (outputLocation.isPrefixOf(path)) {
                            return false;
                        }
                    }
                    return true;
                }
                return true;
            }
        });
    } catch (CoreException e) {
        // TODO CD log exception
    }

    return planFiles;
}

From source file:org.eclipse.virgo.ide.jdt.internal.ui.properties.TestSourceFolderPreferencePage.java

License:Open Source License

public boolean performOk() {
    if (!modified) {
        return true;
    }//  ww  w  .j  a  va 2  s.  co  m

    try {
        List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry entry : JavaCore.create(project).getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                Set<IClasspathAttribute> attrs = new HashSet<IClasspathAttribute>();
                for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                    if (!attr.getName().equals(ServerModuleDelegate.TEST_CLASSPATH_ENTRY_ATTRIBUTE)) {
                        attrs.add(attr);
                    }
                }
                attrs.add(getClasspathAttribute(entry));

                entries.add(JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                        entry.getExclusionPatterns(), entry.getOutputLocation(),
                        (IClasspathAttribute[]) attrs.toArray(new IClasspathAttribute[attrs.size()])));
            } else {
                entries.add(entry);
            }
        }

        JavaCore.create(project).setRawClasspath(
                (IClasspathEntry[]) entries.toArray(new IClasspathEntry[entries.size()]),
                new NullProgressMonitor());
    } catch (JavaModelException e) {
    }

    return true;
}

From source file:org.eclipse.virgo.ide.module.core.ServerModuleDelegate.java

License:Open Source License

/**
 * Get all resources from project's output locations
 *///  www . j a  v a  2s .co  m
private Set<IModuleResource> getMembers(IProject project, IPath moduleRelativePath)
        throws JavaModelException, CoreException {
    Set<IModuleResource> resources = new LinkedHashSet<IModuleResource>();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IJavaProject javaProject = JavaCore.create(project);

    // Add default output location
    IResource defaultBinFolder = root.findMember(javaProject.getOutputLocation());
    if (defaultBinFolder instanceof IContainer) {
        resources.addAll(Arrays.asList(getModuleResources(moduleRelativePath, (IContainer) defaultBinFolder)));
    }

    // Add output for every source entry
    for (IClasspathEntry entry : getSourceClasspathEntries(project, false)) {
        IResource binFolder = root.findMember(entry.getOutputLocation());
        if (binFolder instanceof IContainer && !(binFolder instanceof IWorkspaceRoot)) {
            resources.addAll(
                    Arrays.asList(getModuleResources(moduleRelativePath, (IContainer) defaultBinFolder)));
        }
    }

    // Add Bundle-ClassPath entries
    BundleManifest manifest = BundleManifestCorePlugin.getBundleManifestManager()
            .getBundleManifest(javaProject);
    if (manifest != null) {
        List<String> bundleClassPathEntries = manifest.getBundleClasspath();
        if (bundleClassPathEntries != null) {
            // remove the . for the class folder from the bundle classpath entries
            bundleClassPathEntries.remove(".");

            // get all resources that match the given Bundle-ClassPath header
            resources.addAll(Arrays.asList(
                    getModuleResources(moduleRelativePath, javaProject.getProject(), bundleClassPathEntries)));
        }
    }
    return resources;
}

From source file:org.eclipse.virgo.ide.module.core.ServerModuleFactoryDelegate.java

License:Open Source License

/**
 * {@inheritDoc}/*from ww w .  j  a v  a2  s .  co  m*/
 */
@Override
protected IModule[] createModules(final IProject project) {
    final Set<IModule> modules = new HashSet<IModule>();
    if (FacetUtils.isBundleProject(project)) {

        // Add module for bundle deployment
        modules.add(createModule(project.getName(), project.getName(), FacetCorePlugin.BUNDLE_FACET_ID, "1.0",
                project));

        // Add module for par deployment
        for (IProject parProject : FacetUtils.getParProjects(project)) {
            modules.add(createModule(parProject.getName() + "$" + project.getName(), project.getName(),
                    FacetCorePlugin.BUNDLE_FACET_ID, "1.0", project));
        }

    } else if (FacetUtils.isParProject(project)) {
        modules.add(createModule(project.getName(), project.getName(), FacetCorePlugin.PAR_FACET_ID, "1.0",
                project));
    }

    // Every project can also be a plan project
    if (FacetUtils.isPlanProject(project)) {

        // Collect output locations if java project
        final Set<IPath> outputLocations = new HashSet<IPath>();
        if (JdtUtils.isJavaProject(project)) {
            IJavaProject je = JdtUtils.getJavaProject(project);
            try {
                outputLocations.add(je.getOutputLocation());
                for (IClasspathEntry entry : je.getRawClasspath()) {
                    if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                        if (entry.getOutputLocation() != null) {
                            outputLocations.add(entry.getOutputLocation());
                        }
                    }
                }
            } catch (JavaModelException e) {
            }
        }

        try {
            project.accept(new IResourceVisitor() {

                public boolean visit(IResource resource) throws CoreException {
                    if (resource instanceof IFile && resource.getName().endsWith(".plan")) {
                        modules.add(createModule(resource.getFullPath().toString(),
                                resource.getProject().getName() + "/"
                                        + resource.getProjectRelativePath().toString(),
                                FacetCorePlugin.PLAN_FACET_ID, "2.0", project));
                    } else if (resource instanceof IContainer) {
                        IPath path = ((IContainer) resource).getFullPath();
                        for (IPath outputLocation : outputLocations) {
                            if (outputLocation.isPrefixOf(path)) {
                                return false;
                            }
                        }
                        return true;
                    }
                    return true;
                }
            });
        } catch (CoreException e) {
            // TODO CD log exception
        }
    }
    return (IModule[]) modules.toArray(new IModule[modules.size()]);
}

From source file:org.eclipse.virgo.ide.pde.core.internal.Helper.java

License:Open Source License

/**
 * Gets the output location of the project. Either returns the global output location or the first output location
 * found for a source folder.//  w w  w .j  a v a2s . c om
 *
 * @return
 * @throws CoreException
 */
/* package */ static IPath getOutputLocation(IProject project) throws CoreException {
    IJavaProject jp = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
    IPath outputLocation = jp.getOutputLocation();

    if (outputLocation == null) {
        IClasspathEntry[] entries = jp.getRawClasspath();

        for (IClasspathEntry iClasspathEntry : entries) {
            if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                outputLocation = iClasspathEntry.getOutputLocation();
                if (outputLocation != null) {
                    break;
                }
            }
        }
    }

    if (outputLocation == null) {
        throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, Messages.Helper_BinFolderError));
    }
    return outputLocation;
}

From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java

License:Open Source License

/**
 * Adds absolute locations (in file system) of output folders for given and required projects.
 *//*from ww  w .  j a  v a  2s. com*/
public static void addOutputLocations(Set<IProject> visitedProjects, List<String> locations, IProject project)
        throws Exception {
    // may be not exists
    if (!project.exists()) {
        return;
    }
    // check for recursion
    if (visitedProjects.contains(project)) {
        return;
    }
    visitedProjects.add(project);
    // add output folders for IJavaProject
    {
        IJavaProject javaProject = JavaCore.create(project);
        if (javaProject.exists()) {
            // default output location
            {
                IPath outputPath = javaProject.getOutputLocation();
                addAbsoluteLocation(locations, outputPath);
            }
            // source folder specific output locations
            for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    IPath outputPath = entry.getOutputLocation();
                    addAbsoluteLocation(locations, outputPath);
                }
            }
        }
    }
    // process required projects
    IProject[] referencedProjects = project.getReferencedProjects();
    for (IProject referencedProject : referencedProjects) {
        addOutputLocations(visitedProjects, locations, referencedProject);
    }
}

From source file:org.eclipse.xtend.ide.macro.JdtBasedProcessorProvider.java

License:Open Source License

protected void collectClasspathURLs(final IJavaProject projectToUse, final LinkedHashSet<URL> result,
        final boolean includeOutputFolder, final Set<IJavaProject> visited) throws JavaModelException {
    try {/*ww  w. j  a  va2  s. co m*/
        if (((!projectToUse.getProject().isAccessible()) || (!visited.add(projectToUse)))) {
            return;
        }
        if (includeOutputFolder) {
            IPath path = projectToUse.getOutputLocation().addTrailingSeparator();
            String _string = URI.createPlatformResourceURI(path.toString(), true).toString();
            URL url = new URL(_string);
            result.add(url);
        }
        final IClasspathEntry[] resolvedClasspath = projectToUse.getResolvedClasspath(true);
        for (final IClasspathEntry entry : resolvedClasspath) {
            {
                URL url_1 = null;
                int _entryKind = entry.getEntryKind();
                switch (_entryKind) {
                case IClasspathEntry.CPE_SOURCE:
                    if (includeOutputFolder) {
                        final IPath path_1 = entry.getOutputLocation();
                        if ((path_1 != null)) {
                            String _string_1 = URI
                                    .createPlatformResourceURI(path_1.addTrailingSeparator().toString(), true)
                                    .toString();
                            URL _uRL = new URL(_string_1);
                            url_1 = _uRL;
                        }
                    }
                    break;
                case IClasspathEntry.CPE_PROJECT:
                    IPath path_2 = entry.getPath();
                    final IResource project = this.getWorkspaceRoot(projectToUse).findMember(path_2);
                    final IJavaProject referencedProject = JavaCore.create(project.getProject());
                    this.collectClasspathURLs(referencedProject, result, true, visited);
                    break;
                case IClasspathEntry.CPE_LIBRARY:
                    IPath path_3 = entry.getPath();
                    final IResource library = this.getWorkspaceRoot(projectToUse).findMember(path_3);
                    URL _xifexpression = null;
                    if ((library != null)) {
                        URL _xblockexpression = null;
                        {
                            final java.net.URI locationUri = library.getLocationURI();
                            URL _xifexpression_1 = null;
                            String _scheme = null;
                            if (locationUri != null) {
                                _scheme = locationUri.getScheme();
                            }
                            boolean _equals = Objects.equal(EFS.SCHEME_FILE, _scheme);
                            if (_equals) {
                                java.net.URI _rawLocationURI = library.getRawLocationURI();
                                URL _uRL_1 = null;
                                if (_rawLocationURI != null) {
                                    _uRL_1 = _rawLocationURI.toURL();
                                }
                                _xifexpression_1 = _uRL_1;
                            } else {
                                _xifexpression_1 = null;
                            }
                            _xblockexpression = _xifexpression_1;
                        }
                        _xifexpression = _xblockexpression;
                    } else {
                        _xifexpression = path_3.toFile().toURI().toURL();
                    }
                    url_1 = _xifexpression;
                    break;
                default: {
                    IPath path_4 = entry.getPath();
                    url_1 = path_4.toFile().toURI().toURL();
                }
                    break;
                }
                if ((url_1 != null)) {
                    result.add(url_1);
                }
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}

From source file:org.eclipse.xtext.builder.JDTAwareEclipseResourceFileSystemAccess2.java

License:Open Source License

/**
 * @param prototype settings will be copied from the prototype and the new entry is inserted after that one.
 */// w  ww  . j  a  v a2  s. co  m
private void insertClasspathEntry(IContainer folder, IClasspathEntry prototype, IJavaProject project)
        throws JavaModelException {
    IClasspathEntry newEntry = JavaCore.newSourceEntry(folder.getFullPath(), prototype.getInclusionPatterns(),
            prototype.getExclusionPatterns(), prototype.getOutputLocation(), prototype.getExtraAttributes());
    IClasspathEntry[] classPath = project.getRawClasspath();
    IClasspathEntry[] newClassPath = new IClasspathEntry[classPath.length + 1];
    int i = 0;
    for (IClasspathEntry entry : classPath) {
        newClassPath[i++] = entry;
        if (entry.equals(prototype)) {
            newClassPath[i++] = newEntry;
        }
    }
    // should not happen, but to be sure
    if (i == newClassPath.length - 1 && newClassPath[i] == null) {
        LOG.warn("Cannot find classpath entry '" + prototype + "'");
        newClassPath[i] = newEntry;
    }
    project.setRawClasspath(newClassPath, getMonitor());
}

From source file:org.eclipse.xtext.ui.shared.JdtHelper.java

License:Open Source License

@Override
public boolean isFromOutputPath(IResource resource) {
    IProject project = resource.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject != null && javaProject.exists()) {
        try {//from   w w w .jav a 2 s . c o  m
            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.eclipse.xtext.xbase.ui.editor.XbaseEditorInputRedirector.java

License:Open Source License

/**
 * @param an input//w ww.j av a  2s  .com
 * 
 * @return the original source for an editor input that points to an Xtext resource copied to the output folder, the given input otherwise
 */
public IEditorInput findOriginalSourceForOuputFolderCopy(final IEditorInput input) {
    try {
        final IFile resource = ResourceUtil.getFile(input);
        if ((resource != null)) {
            boolean _isValid = this.fileExtensionProvider.isValid(resource.getFullPath().getFileExtension());
            if (_isValid) {
                final IJavaProject project = JavaCore.create(resource.getProject());
                boolean _exists = project.exists();
                if (_exists) {
                    boolean _isPrefixOf = project.getOutputLocation().isPrefixOf(resource.getFullPath());
                    if (_isPrefixOf) {
                        final IPath relative = resource.getFullPath()
                                .removeFirstSegments(project.getOutputLocation().segmentCount());
                        final Function1<IPackageFragmentRoot, Boolean> _function = (
                                IPackageFragmentRoot it) -> {
                            try {
                                int _kind = it.getKind();
                                return Boolean.valueOf((_kind == IPackageFragmentRoot.K_SOURCE));
                            } catch (Throwable _e) {
                                throw Exceptions.sneakyThrow(_e);
                            }
                        };
                        Iterable<IPackageFragmentRoot> _filter = IterableExtensions
                                .<IPackageFragmentRoot>filter(((Iterable<IPackageFragmentRoot>) Conversions
                                        .doWrapArray(project.getPackageFragmentRoots())), _function);
                        for (final IPackageFragmentRoot source : _filter) {
                            {
                                final IPath fullPath = source.getCorrespondingResource()
                                        .getProjectRelativePath().append(relative);
                                final IFile newFile = resource.getProject().getFile(fullPath);
                                boolean _exists_1 = newFile.exists();
                                if (_exists_1) {
                                    return new FileEditorInput(newFile);
                                }
                            }
                        }
                    }
                    final Function1<IClasspathEntry, Boolean> _function_1 = (IClasspathEntry it) -> {
                        int _entryKind = it.getEntryKind();
                        return Boolean.valueOf((_entryKind == IClasspathEntry.CPE_SOURCE));
                    };
                    Iterable<IClasspathEntry> _filter_1 = IterableExtensions.<IClasspathEntry>filter(
                            ((Iterable<IClasspathEntry>) Conversions.doWrapArray(project.getRawClasspath())),
                            _function_1);
                    for (final IClasspathEntry sourceFolder : _filter_1) {
                        if (((sourceFolder.getOutputLocation() != null)
                                && sourceFolder.getOutputLocation().isPrefixOf(resource.getFullPath()))) {
                            final IPath relative_1 = resource.getFullPath()
                                    .removeFirstSegments(sourceFolder.getOutputLocation().segmentCount());
                            final IPackageFragmentRoot source_1 = IterableExtensions
                                    .<IPackageFragmentRoot>head(((Iterable<IPackageFragmentRoot>) Conversions
                                            .doWrapArray(project.findPackageFragmentRoots(sourceFolder))));
                            final IPath fullPath = source_1.getCorrespondingResource().getProjectRelativePath()
                                    .append(relative_1);
                            final IFile newFile = resource.getProject().getFile(fullPath);
                            boolean _exists_1 = newFile.exists();
                            if (_exists_1) {
                                return new FileEditorInput(newFile);
                            }
                        }
                    }
                }
            }
        }
        return input;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}