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.seasar.diigu.eclipse.util.JavaProjectClassLoader.java

License:Apache License

protected void addClasspathEntries(IJavaProject project, Set already, boolean atFirst) {
    already.add(project);/* w  w w .j  a v a  2s .co  m*/

    try {
        IContainer workspaceroot = project.getProject().getParent();
        IPath path = project.getOutputLocation();
        addURL(toURL(workspaceroot.getFolder(path).getLocation()));

        IClasspathEntry[] entries = project.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_SOURCE:
                IPath dist = entry.getOutputLocation();
                if (dist != null) {
                    addURL(toURL(workspaceroot.getFolder(dist).getLocation()));
                }
                break;
            case IClasspathEntry.CPE_LIBRARY:
            case IClasspathEntry.CPE_CONTAINER:
            case IClasspathEntry.CPE_VARIABLE:
                IPath p = entry.getPath();
                if (p.toFile().exists()) {
                    addURL(toURL(p));
                } else {
                    addURL(toURL(workspaceroot.getFile(p).getLocation()));
                }
                break;
            case IClasspathEntry.CPE_PROJECT:
                IJavaProject proj = ProjectUtils.getJavaProject(entry.getPath().segment(0));
                if (proj != null && proj.exists() && already.contains(proj) == false
                        && (atFirst || entry.isExported())) {
                    addClasspathEntries(proj, already, false);
                }
                break;
            default:
                break;
            }
        }
    } catch (Exception e) {
        DiiguPlugin.log(e);
    }
}

From source file:org.seasar.diigu.eclipse.util.ProjectUtils.java

License:Apache License

public static IPath[] getOutputLocations(IJavaProject project) throws CoreException {
    List result = new ArrayList();
    result.add(project.getOutputLocation());
    IClasspathEntry[] entries = project.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = entry.getOutputLocation();
            if (path != null) {
                result.add(path);/*  w w  w . jav a2 s .c  om*/
            }
        }
    }

    return (IPath[]) result.toArray(new IPath[result.size()]);
}

From source file:org.seasar.eclipse.common.util.ProjectUtil.java

License:Apache License

public static IPath[] getOutputLocations(IJavaProject project) throws CoreException {
    List<IPath> result = new ArrayList<IPath>();
    result.add(project.getOutputLocation());
    IClasspathEntry[] entries = project.getRawClasspath();
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            result.add(entry.getOutputLocation());
        }// w ww.  j a v a  2 s  .c om
    }

    return result.toArray(new IPath[result.size()]);
}

From source file:org.seasar.kijimuna.core.util.JavaProjectClassLoader.java

License:Apache License

protected void addClasspathEntries(IJavaProject project, Set already, boolean atFirst) {
    already.add(project);/*ww  w .ja va 2s. c  o  m*/

    try {
        IContainer workspaceroot = project.getProject().getParent();
        IPath path = project.getOutputLocation();
        addURL(toURL(workspaceroot.getFolder(path).getLocation()));

        IClasspathEntry[] entries = project.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_SOURCE:
                IPath dist = entry.getOutputLocation();
                if (dist != null) {
                    addURL(toURL(workspaceroot.getFolder(dist).getLocation()));
                }
                break;
            case IClasspathEntry.CPE_LIBRARY:
            case IClasspathEntry.CPE_CONTAINER:
            case IClasspathEntry.CPE_VARIABLE:
                IPath p = entry.getPath();
                if (p.toFile().exists()) {
                    addURL(toURL(p));
                } else {
                    addURL(toURL(workspaceroot.getFile(p).getLocation()));
                }
                break;
            case IClasspathEntry.CPE_PROJECT:
                IJavaProject proj = JavaCore.create(ProjectUtils.getProject(entry.getPath().segment(0)));
                if (proj != null && proj.exists() && already.contains(proj) == false
                        && (atFirst || entry.isExported())) {
                    addClasspathEntries(proj, already, false);
                }
                break;
            default:
                break;
            }
        }
    } catch (Exception e) {
        KijimunaCore.reportException(e);
    }
}

From source file:org.seasar.kvasir.plust.KvasirPlugin.java

void cleanTestFolder(IProject project, boolean cleanConfiguration, IFolder folder, IProgressMonitor monitor)
        throws CoreException {
    monitor.beginTask("Cleaning folder", IProgressMonitor.UNKNOWN);
    try {//  ww w  . jav a2  s .  c  o  m
        Set<IPath> exclusiveSet = new HashSet<IPath>();
        if (!cleanConfiguration) {
            IFolder configuration = project.getFolder(IKvasirProject.TEST_CONFIGURATION_PATH);
            if (configuration != null) {
                exclusiveSet.add(configuration.getFullPath());
            }
            IFolder rtwork = project.getFolder(IKvasirProject.TEST_RTWORK_PATH);
            if (rtwork != null) {
                exclusiveSet.add(rtwork.getFullPath());
            }
        }
        IJavaProject javaProject = JavaCore.create(project);
        exclusiveSet.add(javaProject.getOutputLocation());
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IPath outputLocation = entries[i].getOutputLocation();
            if (outputLocation != null) {
                exclusiveSet.add(outputLocation);
            }
        }

        cleanFolder(folder, exclusiveSet, monitor);
    } finally {
        monitor.done();
    }
}

From source file:org.seasar.kvasir.plust.ProjectClassLoader.java

License:Apache License

private void getClassPaths(IJavaProject project) {
    if (project == null) {
        throw new NullPointerException();
    }/*  w w  w  .jav a2  s .  c  o m*/
    try {
        IClasspathEntry[] entries = project.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            int kind = entries[i].getEntryKind();
            URL url = null;
            if (kind == IClasspathEntry.CPE_SOURCE) {
                try {
                    IPath outputLocation = entries[i].getOutputLocation();
                    if (outputLocation == null) {
                        outputLocation = project.getOutputLocation();
                        if (outputLocation == null) {
                            // TODO ????????
                            KvasirPlugin.getDefault().log(
                                    "Can't construct URL for classLoader because default output location is null: entry="
                                            + entries[i].getPath(),
                                    null);
                            continue;
                        }
                    }

                    url = ClassUtils.getURLForURLClassLoader(
                            project.getProject().getParent().getFolder(outputLocation).getLocation().toFile());
                } catch (RuntimeException e1) {
                    KvasirPlugin.getDefault()
                            .log("Can't construct URL for classLoader: entry=" + entries[i].getPath(), e1);
                    continue;
                }
            } else {
                url = ClassUtils.getURLForURLClassLoader(entries[i].getPath().toFile());
                //                    "jar:file:///" + entries[i].getPath().toString()
                //                        + "!/";
            }
            this.monitor.subTask(Messages.getString("KvasirProject.3") + ":" + url);
            addURL(url);
        }
    } catch (JavaModelException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.seasar.s2daoplugin.util.JavaProjectUtil.java

License:Apache License

public static IPackageFragmentRoot[] findPackageFragmentRootsSharedOutputLocation(IPackageFragmentRoot root) {
    if (root == null) {
        return new IPackageFragmentRoot[0];
    }/*from  w  ww . j a va 2  s  . com*/
    IJavaProject project = root.getJavaProject();
    Set result = new HashSet();
    try {
        IPath output1 = root.getRawClasspathEntry().getOutputLocation();
        if (output1 == null) {
            output1 = project.getOutputLocation();
        }
        IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
        for (int i = 0; i < roots.length; i++) {
            if (roots[i].getKind() == IPackageFragmentRoot.K_BINARY) {
                continue;
            }
            IPath output2 = roots[i].getRawClasspathEntry().getOutputLocation();
            if (output2 == null) {
                output2 = project.getOutputLocation();
            }
            if (output1.equals(output2)) {
                result.add(roots[i]);
            }
        }
    } catch (JavaModelException e) {
        S2DaoPlugin.log(e);
    }
    return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]);
}

From source file:org.seasar.s2daoplugin.util.JavaUtil.java

License:Apache License

private static IPath[] getOutputLocationPaths(IJavaProject project) {
    IPackageFragmentRoot[] roots;// w  w  w .j a va 2 s  . c om
    try {
        roots = project.getPackageFragmentRoots();
    } catch (JavaModelException e) {
        return null;
    }
    Set ret = new HashSet();
    try {
        ret.add(project.getOutputLocation());
    } catch (JavaModelException e) {
        return new IPath[0];
    }
    for (int i = 0; i < roots.length; i++) {
        if (roots[i].isArchive()) {
            continue;
        }
        try {
            IPath output = roots[i].getRawClasspathEntry().getOutputLocation();
            if (output != null) {
                ret.add(output);
            }
        } catch (JavaModelException ignore) {
        }
    }
    return (IPath[]) ret.toArray(new IPath[ret.size()]);
}

From source file:org.sonar.ide.eclipse.internal.jdt.JavaProjectConfigurator.java

License:Open Source License

private void configureJavaProject(IJavaProject javaProject, ProjectDefinition sonarProject) {
    Properties properties = sonarProject.getProperties();
    String javaSource = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
    String javaTarget = javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true);

    properties.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, Java.KEY);
    properties.setProperty("sonar.java.source", javaSource);
    LOG.info("Source Java version: {}", javaSource);
    properties.setProperty("sonar.java.target", javaTarget);
    LOG.info("Target Java version: {}", javaTarget);

    try {//w w  w  .  j a  v a 2 s.c om
        IClasspathEntry[] classPath = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry entry : classPath) {
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_SOURCE:
                if (isSourceExcluded(entry)) {
                    break;
                }
                String srcDir = getAbsolutePath(javaProject, entry.getPath());
                LOG.debug("Source directory: {}", srcDir);
                sonarProject.addSourceDir(srcDir);
                if (entry.getOutputLocation() != null) {
                    String binDir = getAbsolutePath(javaProject, entry.getOutputLocation());
                    LOG.debug("Binary directory: {}", binDir);
                    sonarProject.addBinaryDir(binDir);
                }
                break;

            case IClasspathEntry.CPE_LIBRARY:
                String libDir = entry.getPath().toOSString();
                LOG.debug("Library: {}", libDir);
                sonarProject.addLibrary(libDir);
                break;

            default:
                LOG.warn("Unhandled ClassPathEntry : {}", entry);
                break;
            }
        }

        String binDir = getAbsolutePath(javaProject, javaProject.getOutputLocation());
        LOG.debug("Default binary directory: {}", binDir);
        sonarProject.addBinaryDir(binDir);
    } catch (JavaModelException e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:org.sonar.ide.eclipse.jdt.internal.JavaProjectConfigurator.java

License:Open Source License

/**
 * Adds the classpath of an eclipse project to the sonarProject recursively, i.e
 * it iterates all dependent projects. Libraries and output folders of dependent projects
 * are added, but no source folders./*from ww w  .  j  a va  2s  .  com*/
 * @param javaProject the eclipse project to get the classpath from
 * @param sonarProjectProperties the sonar project properties to add the classpath to
 * @param context
 * @param topProject indicate we are working on the project to be analysed and not on a dependent project
 * @throws JavaModelException see {@link IJavaProject#getResolvedClasspath(boolean)}
 */
private void addClassPathToSonarProject(IJavaProject javaProject, JavaProjectConfiguration context,
        boolean topProject) throws JavaModelException {
    IClasspathEntry[] classPath = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classPath) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!isSourceExcluded(entry)) {
                processSourceEntry(entry, javaProject, context, topProject);
            }
            break;
        case IClasspathEntry.CPE_LIBRARY:
            if (topProject || entry.isExported()) {
                final String libDir = resolveLibrary(javaProject, entry);
                if (libDir != null) {
                    LOG.debug("Library: {}", libDir);
                    context.libraries().add(libDir);
                }
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            IJavaModel javaModel = javaProject.getJavaModel();
            IJavaProject referredProject = javaModel.getJavaProject(entry.getPath().segment(0));
            if (!context.dependentProjects().contains(referredProject)) {
                LOG.debug("Adding project: {}", referredProject.getProject().getName());
                addClassPathToSonarProject(referredProject, context, false);
                context.dependentProjects().add(referredProject);
            }
            break;
        default:
            LOG.warn("Unhandled ClassPathEntry : {}", entry);
            break;
        }
    }

    processOutputDir(javaProject.getOutputLocation(), context, topProject);
}