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.bonitasoft.studio.common.repository.Repository.java

License:Open Source License

protected void refreshClasspath(IJavaProject javaProject, List<CPListElement> classPathElementList,
        IProgressMonitor monitor) throws JavaModelException, CoreException {
    if (classPathElementList == null) {
        CPListElement[] existingCPElement = CPListElement.createFromExisting(javaProject);
        classPathElementList = Arrays.asList(existingCPElement);
    }// w ww .ja  v  a 2s. c om
    BuildPathsBlock.flush(classPathElementList, javaProject.getOutputLocation(), javaProject, null, monitor);
}

From source file:org.checkthread.plugin.eclipse.CheckThreadRunner.java

License:Open Source License

private static void loadDirFromProject(HashMap<IProject, Boolean> projectSearchMap, boolean isrecursed,
        IProject project, ArrayList<IPath> srcDirList, ArrayList<URI> targetFileList,
        ArrayList<URI> classPathList) {

    // if we already searched this project
    if (projectSearchMap.get(project) != null) {
        return;/*from  w  w w.ja v  a 2s .c o  m*/

        // we haven't searched this project yet
    } else {
        // add to cache
        projectSearchMap.put(project, true);
    }

    // recursive traverse referenced projects
    // stopping condition: project already searched
    try {
        IProject[] projectList = project.getReferencedProjects();
        for (IProject p : projectList) {
            loadDirFromProject(projectSearchMap, true, p, srcDirList, targetFileList, classPathList);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    IJavaProject javaProject = JavaCore.create(project);
    IPath defaultOutputLocationRelative = null;

    try {
        defaultOutputLocationRelative = javaProject.getOutputLocation();
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    sLogger.info("DEFAULT OUTPUT LOCATION RELATIVE: " + defaultOutputLocationRelative);

    IPath projectLocationAbsolute = project.getLocation();
    sLogger.info("PROJECT LOCATION: " + projectLocationAbsolute);

    // Make path absolute
    IPath defaultOutputLocationAbsolute = projectLocationAbsolute
            .append(defaultOutputLocationRelative.removeFirstSegments(1));
    sLogger.info("DEFAULT OUTPUT LOCATION ABSOLUTE: " + defaultOutputLocationAbsolute);

    // Work around, stomp over target java files. Instead, just give the
    // root directory
    sLogger.info("WORKAROUND: IGNORE CHANGED CLASS FILES< RECHECK EVERYTHING");

    if (!isrecursed) {
        URI uri = defaultOutputLocationAbsolute.toFile().toURI();
        if (uri != null) {
            targetFileList.add(uri);
        }
    }

    // Add to input
    URI cURI = defaultOutputLocationAbsolute.toFile().toURI();
    if (cURI != null) {
        classPathList.add(cURI);
    }

    // Loop through classpath entries and get src directory list
    IClasspathEntry[] rawClassPathList = null;
    try {
        rawClassPathList = javaProject.getRawClasspath();
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

    if (rawClassPathList != null) {
        for (IClasspathEntry classPathEntry : rawClassPathList) {
            switch (classPathEntry.getEntryKind()) {

            // Source Directory
            case IClasspathEntry.CPE_SOURCE: {
                if (!isrecursed) {
                    IPath p = classPathEntry.getPath().removeFirstSegments(1);
                    if (p != null) {
                        srcDirList.add(p);
                        sLogger.info("CPE_SOURCE: " + p);
                    }
                }
                break;
            }

            // external libraries used
            case IClasspathEntry.CPE_LIBRARY: {

                File file = classPathEntry.getPath().toFile();
                IPath p;
                // The entry may be a relative path to the project root
                // or it could be an absolute path to a library.
                if (file.isFile() || file.isDirectory()) {
                    p = classPathEntry.getPath();
                } else {
                    p = projectLocationAbsolute.append(classPathEntry.getPath().removeFirstSegments(1));
                }

                URI uri = p.toFile().toURI();
                if (uri != null) {
                    classPathList.add(uri);
                }
                sLogger.info("CPE_LIBRARY: " + uri);
                break;
            }

            // ignore
            case IClasspathEntry.CPE_CONTAINER:
                sLogger.info("CPE_CONTAINER: " + classPathEntry);
                break;

            //ignore
            case IClasspathEntry.CPE_PROJECT:
                sLogger.info("CPE_PROJECT: " + classPathEntry);
                break;
            }
        }
    }
}

From source file:org.cloudfoundry.ide.eclipse.server.ui.internal.CloudRebelUIHandler.java

License:Open Source License

protected List<String> getClasspathSourceOutputPaths(IProject project) {

    IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project);
    List<String> outputPaths = new ArrayList<String>();
    if (javaProject != null) {
        try {/* www.  j  a  v  a  2  s .  c o m*/
            IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true);

            if (classpath != null) {
                for (IClasspathEntry entry : classpath) {
                    if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                        String outputPath = entry.getOutputLocation() != null
                                ? entry.getOutputLocation().toString()
                                : null;
                        if (outputPath != null && !outputPaths.contains(outputPath)
                                && !outputPath.contains("target/test-classes")) {//$NON-NLS-1$
                            outputPaths.add(outputPath);
                        }
                    }
                }
            }

            String outputPath = javaProject.getOutputLocation() != null
                    ? javaProject.getOutputLocation().toString()
                    : null;
            if (outputPath != null && !outputPaths.contains(outputPath)) {
                outputPaths.add(outputPath);
            }
        } catch (JavaModelException e) {
            CloudFoundryPlugin.logError(e);
        }
    }

    return outputPaths;
}

From source file:org.codehaus.aspectwerkz.ide.eclipse.core.AwCorePlugin.java

License:Open Source License

/**
 * Build the list of URL for the given project
 * Resolve container (ie JRE jars) and dependancies and project output folder
 * //from  w  w  w.  ja va  2  s. c  o m
 * @param project
 * @return
 */
public List getProjectClassPathURLs(IJavaProject project) {
    List paths = new ArrayList();
    try {
        // configured classpath
        IClasspathEntry classpath[] = project.getResolvedClasspath(false);
        for (int i = 0; i < classpath.length; i++) {
            IClasspathEntry path = classpath[i];
            URL urlEntry = null;

            if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                Object target = JavaModel.getTarget(workspaceRoot, path.getPath(), false);
                if (target != null) {
                    // inside the workspace
                    if (target instanceof IResource) {
                        urlEntry = ((IResource) target).getLocation().toFile().toURL();
                    } else if (target instanceof File) {
                        urlEntry = ((File) target).toURL();
                    }
                }
            } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath outPath = path.getOutputLocation();
                if (outPath != null) {
                    //TODO : don't know if I ll have absolute path here
                    urlEntry = outPath.toFile().toURL();
                }
            }
            if (urlEntry != null) {
                paths.add(urlEntry);
            } else {
                AwLog.logTrace("project loader - ignored " + path.toString());
            }
        }
        // project build output
        IPath location = getProjectLocation(project.getProject());
        IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1));
        paths.add(outputPath.toFile().toURL());
    } catch (Exception e) {
        AwLog.logError("Could not build project path", e);
    }
    return paths;
}

From source file:org.codehaus.groovy.eclipse.launchers.AbstractGroovyLaunchShortcut.java

License:Apache License

/**
 * Need to recursively walk the classpath and visit all dependent projects
 * Not looking at classpath containers yet.
 *
 * @param javaProject/*from w w w .  ja va2 s  . c  om*/
 * @param entries
 */
private void addClasspathEntriesForProject(IJavaProject javaProject, SortedSet<String> sourceEntries,
        SortedSet<String> binEntries) {
    List<IJavaProject> dependingProjects = new ArrayList<IJavaProject>();
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (IClasspathEntry entry : entries) {
            int kind = entry.getEntryKind();
            switch (kind) {
            case IClasspathEntry.CPE_LIBRARY:
                IPath libPath = entry.getPath();
                if (!isPathInWorkspace(libPath)) {
                    sourceEntries.add(libPath.toOSString());
                    break;
                }
                //$FALL-THROUGH$
            case IClasspathEntry.CPE_SOURCE:
                IPath srcPath = entry.getPath();
                String sloc = getProjectLocation(srcPath);
                if (srcPath.segmentCount() > 1) {
                    sloc += File.separator + srcPath.removeFirstSegments(1).toOSString();
                }
                sourceEntries.add(sloc);

                IPath outPath = entry.getOutputLocation();
                if (outPath != null) {
                    String bloc = getProjectLocation(outPath);
                    if (outPath.segmentCount() > 1) {
                        bloc += File.separator + outPath.removeFirstSegments(1).toOSString();
                    }
                    binEntries.add(bloc);
                }
                break;

            case IClasspathEntry.CPE_PROJECT:
                dependingProjects.add(javaProject.getJavaModel().getJavaProject(entry.getPath().lastSegment()));
                break;
            }
        }
        IPath defaultOutPath = javaProject.getOutputLocation();
        if (defaultOutPath != null) {
            String bloc = getProjectLocation(javaProject);
            if (defaultOutPath.segmentCount() > 1) {
                bloc += File.separator + defaultOutPath.removeFirstSegments(1).toOSString();
            }
            binEntries.add(bloc);
        }
    } catch (JavaModelException e) {
        GroovyCore.logException("Exception generating classpath for launching groovy script", e);
    }
    // recur through dependent projects
    for (IJavaProject dependingProject : dependingProjects) {
        if (dependingProject.getProject().isAccessible()) {
            addClasspathEntriesForProject(dependingProject, sourceEntries, binEntries);
        }
    }
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ScriptFolderCompilationParticipant.java

License:Open Source License

private Map<IContainer, IContainer> generateSourceToOut(IJavaProject project) throws JavaModelException {
    IProject p = project.getProject();//from ww w . ja  v a2  s  .  c o  m
    IWorkspaceRoot root = (IWorkspaceRoot) p.getParent();
    IClasspathEntry[] cp = project.getRawClasspath();

    // determine default out folder
    IPath defaultOutPath = project.getOutputLocation();
    IContainer defaultOutContainer;
    if (defaultOutPath.segmentCount() > 1) {
        defaultOutContainer = root.getFolder(defaultOutPath);
    } else {
        defaultOutContainer = p;
    }

    Map<IContainer, IContainer> sourceToOut = new TreeMap<IContainer, IContainer>(comparator);
    for (IClasspathEntry cpe : cp) {
        if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {

            // determine source folder
            IContainer sourceContainer;
            IPath sourcePath = cpe.getPath();
            if (sourcePath.segmentCount() > 1) {
                sourceContainer = root.getFolder(sourcePath);
            } else {
                sourceContainer = p;
            }

            // determine out folder
            IPath outPath = cpe.getOutputLocation();
            IContainer outContainer;
            if (outPath == null) {
                outContainer = defaultOutContainer;
            } else if (outPath.segmentCount() > 1) {
                outContainer = root.getFolder(outPath);
            } else {
                outContainer = p;
            }

            // if the two containers are equal, that means no copying should be done
            // do not add to map
            if (!sourceContainer.equals(outContainer)) {
                sourceToOut.put(sourceContainer, outContainer);
            }
        }

    }
    return sourceToOut;
}

From source file:org.compiere.mfg_scm.eclipse.db.DbfBootstrap.java

License:Apache License

private void getClassPathEntries(IJavaProject prj, ArrayList data, List selectedPaths,
        ArrayList visitedProjects) {
    IClasspathEntry[] entries = null;//from ww  w  .j  av  a  2s.  c  om

    IPath outputPath = null;
    try {
        outputPath = prj.getOutputLocation();
        if (selectedPaths.contains(outputPath.toFile().toString().replace('\\', '/'))) {
            add(data, prj.getProject().getWorkspace().getRoot().findMember(outputPath));
        }
        entries = prj.getRawClasspath();
    } catch (JavaModelException e) {
        DbfLauncherPlugin.log(e);
    }
    if (entries == null)
        return;
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        IPath path = entry.getPath();
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            path = entry.getOutputLocation();
            if (path == null)
                continue;
        }
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            String prjName = entry.getPath().lastSegment();
            if (!visitedProjects.contains(prjName)) {
                visitedProjects.add(prjName);
                getClassPathEntries(prj.getJavaModel().getJavaProject(prjName), data, selectedPaths,
                        visitedProjects);
            }
            continue;
        } else if (!selectedPaths.contains(path.toFile().toString().replace('\\', '/')))
            continue;

        IClasspathEntry[] tmpEntry = null;
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            try {
                tmpEntry = JavaCore.getClasspathContainer(path, prj).getClasspathEntries();
            } catch (JavaModelException e1) {
                DbfLauncherPlugin.log(e1);
                continue;
            }
        } else {
            tmpEntry = new IClasspathEntry[1];
            tmpEntry[0] = JavaCore.getResolvedClasspathEntry(entry);
        }

        for (int j = 0; j < tmpEntry.length; j++) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IResource res = prj.getProject().getWorkspace().getRoot().findMember(tmpEntry[j].getPath());
                if (res != null)
                    add(data, res);
                else
                    add(data, tmpEntry[j].getPath());
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath srcPath = entry.getOutputLocation();
                if (srcPath != null && !srcPath.equals(outputPath)) {
                    add(data, prj.getProject().getWorkspace().getRoot().findMember(srcPath));
                }
            } else {
                add(data, tmpEntry[j].getPath());
            }
        }
    }
}

From source file:org.datanucleus.ide.eclipse.jobs.LaunchUtilities.java

License:Open Source License

/**
 * Utility method to obtain the default output dir for the given. Does not support linked resources
 * <code>IJavaProject</code>.
 * @param javaProject The current <code>IJavaProject</code>
 * @return The default output directory for the given
 * <code>IJavaProject</code>
 *///from   w w w . j ava2s  . c  om
public static String getWorkingDir(IJavaProject javaProject) {
    String outputDir = "";

    try {
        IPath relativeOutLocation = javaProject.getOutputLocation();
        IWorkspaceRoot root = javaProject.getProject().getWorkspace().getRoot();
        if (javaProject.getPath().equals(relativeOutLocation)) {
            outputDir = javaProject.getProject().getLocation().toOSString();
        } else {
            IFolder outputFolder1 = root.getFolder(relativeOutLocation);
            outputDir = outputFolder1.getRawLocation().toOSString();
        }
    } catch (JavaModelException e) {
        e.printStackTrace();// TODO
    }
    return outputDir;
}

From source file:org.deved.antlride.integration.jdt.AntlrJavaTargetService.java

License:Open Source License

public boolean accept(IResource resource) {
    boolean accept = false;
    try {/*from  w  w  w.j a  v a2  s.c om*/
        IProject project = resource.getProject();
        IJavaProject javaProject = JavaCore.create(project);
        if (javaProject.exists()) {
            IPath resourcePath = new Path(project.getName()).append(resource.getProjectRelativePath());
            IPath outputLocation = javaProject.getOutputLocation();
            if (resourcePath.segmentCount() >= outputLocation.segmentCount()) {
                for (int segmentIndex = 0; segmentIndex < outputLocation.segmentCount(); segmentIndex++) {
                    if (!outputLocation.segment(segmentIndex).equals(resourcePath.segment(segmentIndex))) {
                        accept = true;
                        break;
                    }
                }
            }
        } else {
            accept = true;
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    // if (!accept) {
    // System.out.println("Excluding " + resource);
    // }
    return accept;
}

From source file:org.drools.eclipse.builder.DroolsBuilder.java

License:Apache License

protected boolean parseResource(IResource res, boolean clean) {
    try {//from  w  ww  .  j a  v a  2  s. com
        // exclude .guvnorinfo files
        if (".guvnorinfo".equals(res.getName())) {
            return false;
        }
        IJavaProject project = JavaCore.create(res.getProject());
        // exclude files that are located in the output directory,
        // unless the ouput directory is the same as the project location
        if (!project.getOutputLocation().equals(project.getPath())
                && project.getOutputLocation().isPrefixOf(res.getFullPath())) {
            return false;
        }
    } catch (JavaModelException e) {
        // do nothing
    }

    if (!res.exists()) {
        removeProblemsFor(res);
        DroolsEclipsePlugin.getDefault().invalidateResource(res);
        return false;
    }

    if (res instanceof IFile && ("drl".equals(res.getFileExtension()) || "dslr".equals(res.getFileExtension())
            || ".package".equals(res.getName()))) {
        removeProblemsFor(res);
        try {
            if (clean) {
                DroolsEclipsePlugin.getDefault().invalidateResource(res);
            }
            DroolsBuildMarker[] markers = parseDRLFile((IFile) res,
                    new String(Util.getResourceContentsAsCharArray((IFile) res)));
            for (int i = 0; i < markers.length; i++) {
                createMarker(res, markers[i].getText(), markers[i].getLine());
            }
        } catch (Throwable t) {
            DroolsEclipsePlugin.log(t);
            createMarker(res, t.getMessage(), -1);
        }
        return false;
    } else if (res instanceof IFile && "xls".equals(res.getFileExtension())) {
        removeProblemsFor(res);
        try {
            if (clean) {
                DroolsEclipsePlugin.getDefault().invalidateResource(res);
            }
            DroolsBuildMarker[] markers = parseXLSFile((IFile) res);
            for (int i = 0; i < markers.length; i++) {
                createMarker(res, markers[i].getText(), markers[i].getLine());
            }
        } catch (Throwable t) {
            createMarker(res, t.getMessage(), -1);
        }
        return false;
    } else if (res instanceof IFile && "csv".equals(res.getFileExtension())) {
        removeProblemsFor(res);
        try {
            if (clean) {
                DroolsEclipsePlugin.getDefault().invalidateResource(res);
            }
            DroolsBuildMarker[] markers = parseCSVFile((IFile) res);
            for (int i = 0; i < markers.length; i++) {
                createMarker(res, markers[i].getText(), markers[i].getLine());
            }
        } catch (Throwable t) {
            createMarker(res, t.getMessage(), -1);
        }
        return false;
    } else if (res instanceof IFile && "brl".equals(res.getFileExtension())) {
        removeProblemsFor(res);
        try {
            if (clean) {
                DroolsEclipsePlugin.getDefault().invalidateResource(res);
            }
            DroolsBuildMarker[] markers = parseBRLFile((IFile) res);
            for (int i = 0; i < markers.length; i++) {
                createMarker(res, markers[i].getText(), markers[i].getLine());
            }
        } catch (Throwable t) {
            createMarker(res, t.getMessage(), -1);
        }
        return false;
    } else if (res instanceof IFile && "rf".equals(res.getFileExtension())) {
        removeProblemsFor(res);
        try {
            if (clean) {
                DroolsEclipsePlugin.getDefault().invalidateResource(res);
            }
            DroolsBuildMarker[] markers = parseRuleFlowFile((IFile) res);
            for (int i = 0; i < markers.length; i++) {
                createMarker(res, markers[i].getText(), markers[i].getLine());
            }
        } catch (Throwable t) {
            createMarker(res, t.getMessage(), -1);
        }
        return false;
    } else if (res instanceof IFile
            && ("bpmn".equals(res.getFileExtension()) || "bpmn2".equals(res.getFileExtension()))) {
        removeProblemsFor(res);
        try {
            if (clean) {
                DroolsEclipsePlugin.getDefault().invalidateResource(res);
            }
            DroolsBuildMarker[] markers = parseRuleFlowFile((IFile) res);
            for (int i = 0; i < markers.length; i++) {
                createMarker(res, markers[i].getText(), markers[i].getLine());
            }
        } catch (Throwable t) {
            createMarker(res, t.getMessage(), -1);
        }
        return false;
    }

    return true;
}