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:com.ibm.wala.ide.util.JavaEclipseProjectPath.java

License:Open Source License

@Override
protected void resolveProjectClasspathEntries(IJavaProject project, boolean includeSource) {
    try {/*from w w w.j a  v a  2s .c  o  m*/
        resolveClasspathEntries(project, Arrays.asList(project.getRawClasspath()), Loader.EXTENSION,
                includeSource, true);
        File output = makeAbsolute(project.getOutputLocation()).toFile();
        if (!includeSource) {
            if (output.exists()) {
                List<Module> s = MapUtil.findOrCreateList(modules, Loader.APPLICATION);
                s.add(new BinaryDirectoryTreeModule(output));
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
        Assertions.UNREACHABLE();
    }
}

From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java

License:Open Source License

private void addJavaProject(IJavaProject project) throws CoreException {
    if (project != null) {
        final Map<File, IPackageFragmentRoot> classpath = new LinkedHashMap<File, IPackageFragmentRoot>();
        for (IPackageFragmentRoot fragment : project.getPackageFragmentRoots()) {
            if (fragment.getKind() == IPackageFragmentRoot.K_BINARY
                    && fragment.getSourceAttachmentPath() != null) {
                File classpathLocation;
                if (fragment.isExternal()) {
                    classpathLocation = fragment.getPath().toFile();
                } else {
                    classpathLocation = toFile(fragment.getPath());
                }/* www  .  ja v a 2s  .  com*/
                if (classpathLocation != null) {
                    classpath.put(classpathLocation, fragment);
                }
            }
        }

        final JavaProjectInfo projectInfo = new JavaProjectInfo(project, classpath);

        final Set<File> projectLocations = new HashSet<File>();

        final String jarLocation = project.getProject().getPersistentProperty(BinaryProjectPlugin.QNAME_JAR);
        if (jarLocation != null) {
            // maven binary project
            projectLocations.add(new File(jarLocation));
        } else {
            // regular project
            projectLocations.add(toFile(project.getOutputLocation()));
            for (IClasspathEntry cpe : project.getRawClasspath()) {
                if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    projectLocations.add(toFile(cpe.getOutputLocation()));
                }
            }
        }

        synchronized (lock) {
            projects.put(project, projectLocations);
            for (File projectLocation : projectLocations) {
                locations.put(projectLocation, projectInfo);
            }
        }
    }
}

From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java

License:Open Source License

/**
 * Get all the resolved classpath entries for a specific project. The entries 
 * with ID JRClasspathContainer.ID and JavaRuntime.JRE_CONTAINER are not resolved
 * or included in the result. At also add the source and output folder provided with the 
 * project//  ww  w . j  a v a 2 s  .  c  o m
 * 
 * @param project the project where the file to compile is contained, must be not null
 * @return a not null list of string that contains the classpath to include in the compilation project
 */
private List<String> getClasspaths(IProject project) {
    IJavaProject jprj = JavaCore.create(project);
    List<String> classpath = new ArrayList<String>();
    IWorkspaceRoot wsRoot = project.getWorkspace().getRoot();
    if (jprj != null) {
        try {
            IClasspathEntry[] entries = jprj.getRawClasspath();

            //Add the default output folder if any
            IPath defaultLocationPath = jprj.getOutputLocation();
            if (defaultLocationPath != null) {
                IFolder entryOutputFolder = wsRoot.getFolder(defaultLocationPath);
                classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
            }

            for (IClasspathEntry en : entries) {
                if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    String containerPath = en.getPath().toString();
                    //Don't add the eclipse runtime and the classpath extension defined in the exclusion list
                    if (!containerPath.startsWith(JavaRuntime.JRE_CONTAINER)
                            && !classpathExclusionSet.contains(containerPath)) {
                        addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(),
                                classpath, jprj);
                    }
                } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    classpath.add(wsRoot.findMember(en.getPath()).getLocation().toOSString() + File.separator);
                } else if (en.getEntryKind() == IClasspathEntry.CPE_SOURCE
                        && en.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    //check if is a source folder and if it has a custom output folder to add them also to the classpath
                    IPath entryOutputLocation = en.getOutputLocation();
                    if (entryOutputLocation != null) {
                        IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation);
                        classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
                    }
                } else {
                    //It is a jar check if it is internal to the workspace of external
                    IPath location = wsRoot.getFile(en.getPath()).getLocation();
                    if (location == null) {
                        //The location could not be resolved from the root of the workspace, it is external
                        classpath.add(en.getPath().toOSString());
                    } else {
                        //The location has been resolved from the root of the workspace, it is internal
                        classpath.add(location.toOSString());
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return classpath;
}

From source file:com.javadude.antxr.eclipse.smapinstaller.SMapInstallerBuilder.java

License:Open Source License

/**
 * Installs the modified smap into a generated classfile
 * @param resource//  w  ww  .  j a  va 2 s  .c om
 * @throws JavaModelException
 */
protected void installSmap(IResource resource) throws JavaModelException {
    // We only work on smap files -- skip everything else
    if (!(resource instanceof IFile)) {
        return;
    }
    IFile smapIFile = (IFile) resource;
    if (!"smap".equalsIgnoreCase(smapIFile.getFileExtension())) {
        return;
    }
    IJavaProject javaProject = JavaCore.create(smapIFile.getProject());

    // get the name of the corresponding java source file
    IPath smapPath = smapIFile.getFullPath();

    IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classpathEntries) {
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
            continue;
        }
        if (!entry.getPath().isPrefixOf(smapPath)) {
            continue;
        }

        // found the right source container
        IPath outputLocation = entry.getOutputLocation();
        if (outputLocation == null) {
            outputLocation = javaProject.getOutputLocation();
        }
        // strip the source dir and .smap suffix
        String sourceDir = entry.getPath().toString();
        String smapName = smapPath.toString();
        String javaSourceName = smapName.substring(0, smapName.length() - 5) + ".java";
        String className = smapName.substring(sourceDir.length(), smapName.length() - 5) + ".class";
        IPath path = outputLocation.append(className);
        IPath workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation();
        IPath classFileLocation = workspaceLoc.append(path);
        IResource classResource = ResourcesPlugin.getWorkspace().getRoot().findMember(javaSourceName);

        File classFile = classFileLocation.toFile();
        File smapFile = smapIFile.getLocation().toFile();
        try {
            String installSmap = classResource.getPersistentProperty(AntxrBuilder.INSTALL_SMAP);
            if ("true".equals(installSmap)) {
                SDEInstaller.install(classFile, smapFile);
            }
        } catch (CoreException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.javapathfinder.vjp.DefaultProperties.java

License:Open Source License

/**
 * append all relevant paths from the target project settings to the vm.classpath 
 *///from   w w w  .  j a va  2 s  .c  o m
private static void appendProjectClassPaths(IJavaProject project, StringBuilder cp) {
    try {
        // we need to maintain order
        LinkedHashSet<IPath> paths = new LinkedHashSet<IPath>();

        // append the default output folder
        IPath defOutputFolder = project.getOutputLocation();
        if (defOutputFolder != null) {
            paths.add(defOutputFolder);
        }
        // look for libraries and source root specific output folders
        for (IClasspathEntry e : project.getResolvedClasspath(true)) {
            IPath ePath = null;

            switch (e.getContentKind()) {
            case IClasspathEntry.CPE_LIBRARY:
                ePath = e.getPath();
                break;
            case IClasspathEntry.CPE_SOURCE:
                ePath = e.getOutputLocation();
                break;
            }

            if (ePath != null && !paths.contains(ePath)) {

                paths.add(ePath);
            }
        }

        for (IPath path : paths) {
            String absPath = getAbsolutePath(project, path).toOSString();

            //        if (cp.length() > 0) {
            //          cp.append(Config.LIST_SEPARATOR);
            //        }
            // only add classes that are found in bin
            if (absPath.contains("/bin"))
                cp.append(absPath);
        }
        System.out.println("cp is" + cp);
    } catch (JavaModelException jme) {
        VJP.logError("Could not append Project classpath", jme);
    }
}

From source file:com.legstar.eclipse.plugin.cixscom.wizards.AbstractCixsGeneratorWizardPage.java

License:Open Source License

/**
 * From a Java nature Eclipse project, this utility method retrieves either
 * a java source folder or an associated java output folder for binaries.
 * <p/>//ww  w.  j av a2  s  .c o  m
 * The algorithm stops at the first source directory encountered.
 * 
 * @param project the current Eclipse project
 * @param source true if we are looking for a source folder, false for an
 *            output folder
 * @return a java folder (either source or output)
 */
protected File getJavaDir(final IProject project, final boolean source) {
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject != null) {
        IPath rootPath = javaProject.getProject().getLocation().removeLastSegments(1);

        /*
         * If this is a java project, get first Java source and output
         * folders.
         */
        try {
            IClasspathEntry[] cpe = javaProject.getRawClasspath();
            for (int i = 0; i < cpe.length; i++) {
                if (cpe[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    if (source) {
                        return rootPath.append(cpe[i].getPath()).toFile();
                    } else {
                        if (cpe[i].getOutputLocation() == null) {
                            return rootPath.append(javaProject.getOutputLocation()).toFile();
                        } else {
                            return rootPath.append(cpe[i].getOutputLocation()).toFile();
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
            AbstractWizard.errorDialog(getShell(), Messages.generate_error_dialog_title, getPluginId(),
                    Messages.java_location_lookup_failure_msg,
                    NLS.bind(Messages.invalid_java_project_msg, project.getName(), e.getMessage()));
            AbstractWizard.logCoreException(e, getPluginId());
        }
    }
    /*
     * If everything else failed, assume generated artifacts will go to the
     * project root.
     */
    return project.getLocation().toFile();
}

From source file:com.legstar.eclipse.plugin.coxbgen.wizards.CoxbGenWizardPage.java

License:Open Source License

/**
 * Check if a relative path name is a valid java source directory. Also sets
 * the target binary folder.//w  w w.  ja v a  2  s .  c o m
 * 
 * @param relativePathName the path name
 * @return true if this is a valid java source folder
 */
protected boolean isJavaSrcDir(final String relativePathName) {
    IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(relativePathName));
    if (resource != null) {
        IJavaProject jproject = JavaCore.create(resource.getProject());
        if (jproject != null) {
            try {
                IClasspathEntry[] cpe = jproject.getRawClasspath();
                /* Lookup the pathname */
                for (int i = 0; i < cpe.length; i++) {
                    if (cpe[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                        if (relativePathName.equals(cpe[i].getPath().toOSString())) {
                            if (cpe[i].getOutputLocation() != null) {
                                _targetBinDirLabel.setText(cpe[i].getOutputLocation().toOSString());
                            } else {
                                _targetBinDirLabel.setText(jproject.getOutputLocation().toOSString());
                            }
                            return true;
                        }
                    }
                }
            } catch (JavaModelException e) {
                return false;
            }
        }
    }
    return false;
}

From source file:com.legstar.eclipse.plugin.schemagen.wizards.JavaToXsdWizardPage.java

License:Open Source License

/**
 * Given classpath entries from a java project, populate a list of
 * collections./*from  w  ww  . j a va 2  s  .  c o m*/
 * 
 * @param selectedPathElementsLocations the output path locations
 * @param classPathEntries the java project class path entries
 * @param javaProject the java project
 * @throws JavaModelException if invalid classpath
 */
private void addPathElements(final List<String> selectedPathElementsLocations,
        final IClasspathEntry[] classPathEntries, final IJavaProject javaProject) throws JavaModelException {

    IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry();
    IPath projectPath = javaProject.getProject().getLocation();

    for (int i = 0; i < classPathEntries.length; i++) {
        IClasspathEntry classpathEntry = classPathEntries[i];
        String pathElementLocation = null;
        switch (classpathEntry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            pathElementLocation = classpathEntry.getPath().toOSString();
            break;
        case IClasspathEntry.CPE_CONTAINER:
            /* No need for the default jre */
            if (classpathEntry.equals(jreEntry)) {
                break;
            }
            /* Resolve container into class path entries */
            IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(classpathEntry.getPath(),
                    javaProject);
            addPathElements(selectedPathElementsLocations, classpathContainer.getClasspathEntries(),
                    javaProject);
            break;
        case IClasspathEntry.CPE_VARIABLE:
            pathElementLocation = JavaCore.getResolvedVariablePath(classpathEntry.getPath()).toOSString();
            break;
        case IClasspathEntry.CPE_SOURCE:
            /*
             * If source has no specific output, use the project default
             * one
             */
            IPath outputLocation = classpathEntry.getOutputLocation();
            if (outputLocation == null) {
                outputLocation = javaProject.getOutputLocation();
            }
            pathElementLocation = projectPath.append(outputLocation.removeFirstSegments(1)).toOSString();
            break;
        default:
            break;
        }

        if (pathElementLocation != null && !selectedPathElementsLocations.contains(pathElementLocation)) {
            selectedPathElementsLocations.add(pathElementLocation);
        }
    }
}

From source file:com.liferay.ide.project.core.facet.PluginFacetInstall.java

License:Open Source License

protected void setupDefaultOutputLocation() throws CoreException {
    IJavaProject jProject = JavaCore.create(this.project);
    IFolder folder = this.project.getFolder(getDefaultOutputLocation());

    if (folder.getParent().exists()) {
        CoreUtil.prepareFolder(folder);// w w w  . j a v  a 2 s  .  co m

        IPath oldOutputLocation = jProject.getOutputLocation();
        IFolder oldOutputFolder = CoreUtil.getWorkspaceRoot().getFolder(oldOutputLocation);
        jProject.setOutputLocation(folder.getFullPath(), null);

        try {
            if (!folder.equals(oldOutputFolder) && oldOutputFolder.exists()) {
                IContainer outputParent = oldOutputFolder.getParent();
                oldOutputFolder.delete(true, null);

                if (outputParent.members().length == 0 && outputParent.getName().equals("build")) //$NON-NLS-1$
                {
                    outputParent.delete(true, null);
                }
            }
        } catch (Exception e) {
            // best effort
        }
    }
}

From source file:com.liferay.ide.project.ui.IvyUtil.java

License:Open Source License

public static IvyClasspathContainer addIvyLibrary(IProject project, IProgressMonitor monitor) {
    final String projectName = project.getName();
    final IJavaProject javaProject = JavaCore.create(project);

    final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(javaProject,
            ISDKConstants.IVY_XML_FILE, true);
    final ClasspathSetup classpathSetup = new ClasspathSetup();

    conf.setAdvancedProjectSpecific(false);
    conf.setClasspathSetup(classpathSetup);
    conf.setClassthProjectSpecific(false);
    conf.setConfs(Collections.singletonList("*")); //$NON-NLS-1$
    conf.setMappingProjectSpecific(false);
    conf.setSettingsProjectSpecific(true);

    SDK sdk = SDKUtil.getSDK(project);//w  w  w. j a  v  a  2  s  . c o  m
    final SettingsSetup settingsSetup = new SettingsSetup();

    if (sdk.getLocation().append(ISDKConstants.IVY_SETTINGS_XML_FILE).toFile().exists()) {
        StringBuilder builder = new StringBuilder();
        builder.append("${"); //$NON-NLS-1$
        builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
        builder.append(":"); //$NON-NLS-1$
        builder.append(projectName);
        builder.append("}/"); //$NON-NLS-1$
        builder.append(ISDKConstants.IVY_SETTINGS_XML_FILE);
        settingsSetup.setIvySettingsPath(builder.toString());
    }

    StringBuilder builder = new StringBuilder();
    builder.append("${"); //$NON-NLS-1$
    builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
    builder.append(":"); //$NON-NLS-1$
    builder.append(projectName);
    builder.append("}/.ivy"); //$NON-NLS-1$

    settingsSetup.setIvyUserDir(builder.toString());
    conf.setIvySettingsSetup(settingsSetup);

    final IPath path = conf.getPath();
    final IClasspathAttribute[] atts = conf.getAttributes();

    final IClasspathEntry ivyEntry = JavaCore.newContainerEntry(path, null, atts, false);

    final IVirtualComponent virtualComponent = ComponentCore.createComponent(project);

    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(Arrays.asList(entries));

        IPath runtimePath = getDefaultRuntimePath(virtualComponent, ivyEntry);

        // add the deployment assembly config to deploy ivy container to /WEB-INF/lib
        final IClasspathEntry cpeTagged = modifyDependencyPath(ivyEntry, runtimePath);

        newEntries.add(cpeTagged);
        entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        javaProject.setRawClasspath(entries, javaProject.getOutputLocation(), monitor);

        IvyClasspathContainer ivycp = IvyClasspathContainerHelper.getContainer(path, javaProject);

        return ivycp;
    } catch (JavaModelException e) {
        ProjectUI.logError("Unable to add Ivy library container", e); //$NON-NLS-1$
    }

    return null;
}