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

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

Introduction

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

Prototype

IPath getOutputLocation() throws JavaModelException;

Source Link

Document

Returns the default output location for this project as a workspace- relative absolute path.

Usage

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 2 s  . c  o m*/
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.wst.xml.search.editor.util.JdtUtils.java

License:Open Source License

public static IFolder getJavaProjectOutputFolder(IProject project) {
    IJavaProject javaProject = getJavaProject(project);
    if (javaProject != null) {
        try {/*from  w w w .ja v a 2 s .  c o m*/
            return ResourcesPlugin.getWorkspace().getRoot().getFolder(javaProject.getOutputLocation());
        } catch (JavaModelException e) {
            Trace.trace(Trace.SEVERE, (new StringBuilder("Error getting Java project output for project '"))
                    .append(project.getName()).append("'").toString(), e);
        }
    }
    return null;
}

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 {//from  www .  jav a2  s  .  c om
        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.xtend.shared.ui.test.TestEnvironment.java

License:Open Source License

/**
 * Return output location for a project.
 */// ww w .j a v  a 2  s  .c  om
public IPath getOutputLocation(final IPath projectPath) {
    try {
        final IJavaProject javaProject = JavaCore.create(getProject(projectPath));
        return javaProject.getOutputLocation();
    } catch (final CoreException e) {
        // ignore
    }
    return null;
}

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   ww  w  .  ja  va2 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//from   ww  w  .j a  v  a  2 s  . co m
 * 
 * @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);
    }
}

From source file:org.eclipse.xtext.xtext.ecoreInference.ProjectAwareXtendXtext2EcorePostProcessor.java

License:Open Source License

private List<URL> getOutputFolders(IJavaProject javaProject) throws CoreException, MalformedURLException {
    List<URL> result = Lists.newArrayListWithExpectedSize(1);
    IPath path = javaProject.getOutputLocation().addTrailingSeparator();
    URL url = new URL(URI.createPlatformResourceURI(path.toString(), true).toString());
    result.add(url);/*from   w w w  . j  a  v  a 2  s . c  o m*/
    for (IClasspathEntry entry : javaProject.getRawClasspath()) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            path = entry.getOutputLocation();
            if (path != null) {
                url = new URL(
                        URI.createPlatformResourceURI(path.addTrailingSeparator().toString(), true).toString());
                result.add(url);
            }
            break;
        default:
            break;
        }
    }
    return result;
}

From source file:org.eclipselabs.jar2uml.JarToUML.java

License:Open Source License

/**
 * Adds all relevant class file paths for javaProject
 * @param javaProject/*from   w w w.  j a v  a 2s . c  om*/
 * @param includeWorkspaceReferences Include referenced projects and jar files in workspace
 * @throws JavaModelException 
 * @throws IOException 
 */
public void addPaths(IJavaProject javaProject, boolean includeWorkspaceReferences)
        throws JavaModelException, IOException {
    for (IClasspathEntry cpe : javaProject.getResolvedClasspath(true)) {
        IPath cpePath;
        switch (cpe.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            cpePath = cpe.getOutputLocation();
            if (cpePath == null) {
                cpePath = javaProject.getOutputLocation();
            }
            IContainer container = (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(cpePath);
            addPath(container);
            break;
        case IClasspathEntry.CPE_LIBRARY:
            cpePath = cpe.getPath();
            IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(cpePath);
            if ((resource != null)
                    && (includeWorkspaceReferences || javaProject.getProject().equals(resource.getProject()))) {
                if (resource instanceof IFile) {
                    addCpJar(new JarFile(resource.getLocation().toFile()));
                } else if (resource instanceof IContainer) {
                    addCpPath((IContainer) resource);
                } else {
                    throw new IOException(String
                            .format(JarToUMLResources.getString("JarToUML.unexpectedResourceKind"), resource)); //$NON-NLS-1$
                }
            }
            break;
        }
    }
    if (includeWorkspaceReferences) {
        Set<IJavaProject> refs = new HashSet<IJavaProject>();
        findJavaProjectReferences(javaProject, refs);
        for (IJavaProject ref : refs) {
            addPaths(ref, includeWorkspaceReferences);
        }
    }
}

From source file:org.eclipselabs.jar2uml.test.J2UTestCase.java

License:Open Source License

/**
 * Copies the class file to the right place in the given project.
 * @param clazz/*from  www .  ja v  a 2  s.c  o  m*/
 * @param project Must be a Java project!
 * @return The target file.
 * @throws CoreException
 * @throws IOException
 */
public static IFile copyClassToJavaProject(final Class<?> clazz, final IProject project)
        throws CoreException, IOException {
    String path = classFilePath(clazz);
    JarToUMLResources.logger.info("copying class file: " + path);
    IJavaProject jproject = JarToUML.getJavaProject(project.getFullPath());
    IPath outPath = jproject.getOutputLocation();
    JarToUMLResources.logger.info("class file path: " + outPath);
    IPath classFilePath = outPath.append(path);
    final IFile classFile = ResourcesPlugin.getWorkspace().getRoot().getFile(classFilePath);
    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            if (!classFile.exists()) {
                createPath((IFolder) classFile.getParent());
                try {
                    classFile.create(getClassContents(clazz), true, null);
                    JarToUMLResources.logger.info("created file: " + classFile);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }, null);
    return classFile;
}

From source file:org.eclipselabs.jar2uml.test.JarToUMLTest.java

License:Open Source License

/**
 * Test method for {@link JarToUML#addPaths(IJavaProject, boolean)}.
 * @throws IOException //from w w  w .ja  v a  2s. c om
 * @throws JavaModelException 
 */
public void testAddPaths() throws JavaModelException, IOException {
    //
    // Retrieve Java projects
    //
    IProject project = getProject(javatestProject);
    IJavaProject jproject = JarToUML.getJavaProject(project.getFullPath());
    IProject projectref = getProject(javatestReferredProject);
    IJavaProject jprojectref = JarToUML.getJavaProject(projectref.getFullPath());
    //
    // Retrieve output locations for Java projects
    //
    IResource projectOutput = ResourcesPlugin.getWorkspace().getRoot().findMember(jproject.getOutputLocation());
    IResource projectrefOutput = ResourcesPlugin.getWorkspace().getRoot()
            .findMember(jprojectref.getOutputLocation());
    //
    // Test without workspace references
    //
    JarToUML jar2uml = new JarToUML();
    jar2uml.addPaths(jproject, false);
    jar2uml.addPaths(jproject, false); //try to break stuff
    List<IContainer> paths = jar2uml.getPaths();
    assertFalse(paths.isEmpty());
    assertTrue(paths.contains(projectOutput));
    assertFalse(paths.contains(projectrefOutput));
    assertTrue(hasUniqueEntries(paths));
    assertTrue(jar2uml.getJars().isEmpty());
    assertTrue(jar2uml.getCpJars().isEmpty());
    assertTrue(jar2uml.getCpPaths().isEmpty());
    assertTrue(intersection(jar2uml.getPaths(), jar2uml.getCpPaths()).isEmpty());
    //
    // Test with workspace references
    //
    jar2uml = new JarToUML();
    jar2uml.addPaths(jproject, true);
    jar2uml.addPaths(jproject, true); //try to break stuff
    paths = jar2uml.getPaths();
    assertFalse(paths.isEmpty());
    assertTrue(paths.contains(projectOutput));
    assertTrue(paths.contains(projectrefOutput));
    assertTrue(hasUniqueEntries(paths));
    assertTrue(jar2uml.getJars().isEmpty());
    assertTrue(jar2uml.getCpJars().isEmpty());
    assertTrue(jar2uml.getCpPaths().isEmpty());
    assertTrue(intersection(jar2uml.getPaths(), jar2uml.getCpPaths()).isEmpty());
}