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

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

Introduction

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

Prototype

void setOutputLocation(IPath path, IProgressMonitor monitor) throws JavaModelException;

Source Link

Document

Sets the default output location of this project to the location described by the given workspace-relative absolute path.

Usage

From source file:org.fornax.cartridges.sculptor.wizard.util.EclipseHelper.java

License:Apache License

public static IProject createRichClientProject(final String projectName,
        final List<IProject> referencedProjects, final Set<String> requiredBundles,
        final IProgressMonitor progressMonitor, final Shell theShell) {
    IProject project = null;/*  w  ww  .  j av  a2  s. co  m*/
    try {
        progressMonitor.beginTask("", 10);
        progressMonitor.subTask("Creating project " + projectName);
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        project = workspace.getRoot().getProject(projectName);

        // Clean up any old project information.
        if (project.exists()) {
            final boolean[] result = new boolean[1];
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
                public void run() {
                    result[0] = MessageDialog.openQuestion(theShell, "Existing project " + projectName + "?",
                            "Do you want to overwrite the project '" + projectName
                                    + "' \nNote that everything inside the project '" + projectName
                                    + "' will be deleted if you confirm this dialog.");
                }
            });
            if (result[0]) {
                project.delete(true, true, new SubProgressMonitor(progressMonitor, 1));
            } else {
                return null;
            }
        }

        IJavaProject javaProject = JavaCore.create(project);
        IProjectDescription projectDescription = ResourcesPlugin.getWorkspace()
                .newProjectDescription(projectName);
        projectDescription.setLocation(null);
        project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1));
        List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
        if (referencedProjects.size() != 0) {
            projectDescription
                    .setReferencedProjects(referencedProjects.toArray(new IProject[referencedProjects.size()]));
            for (IProject referencedProject : referencedProjects) {
                IClasspathEntry referencedProjectClasspathEntry = JavaCore
                        .newProjectEntry(referencedProject.getFullPath());
                classpathEntries.add(referencedProjectClasspathEntry);
            }
        }

        projectDescription.setNatureIds(new String[] { JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature" });

        ICommand java = projectDescription.newCommand();
        java.setBuilderName(JavaCore.BUILDER_ID);

        ICommand manifest = projectDescription.newCommand();
        manifest.setBuilderName("org.eclipse.pde.ManifestBuilder");

        ICommand schema = projectDescription.newCommand();
        schema.setBuilderName("org.eclipse.pde.SchemaBuilder");

        projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema });

        project.open(new SubProgressMonitor(progressMonitor, 1));
        project.setDescription(projectDescription, new SubProgressMonitor(progressMonitor, 1));

        addSrcFolders(progressMonitor, project, classpathEntries);

        classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")));
        classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));

        javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
                new SubProgressMonitor(progressMonitor, 1));

        javaProject.setOutputLocation(new Path("/" + projectName + "/target/classes"),
                new SubProgressMonitor(progressMonitor, 1));
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        progressMonitor.done();
    }

    return project;
}

From source file:org.grails.ide.eclipse.commands.GrailsCommandUtils.java

License:Open Source License

/**
 * (Re)sets a given grails project's output folder to the default.
 *//*from w w w .  j av  a2  s.c om*/
public static void setDefaultOutputFolder(IJavaProject javaProject) throws JavaModelException {
    IProject project = javaProject.getProject();
    IFolder binDir = project.getFolder(DEFAULT_GRAILS_OUTPUT_FOLDER);
    IPath binPath = binDir.getFullPath();
    javaProject.setOutputLocation(binPath, null);
}

From source file:org.gw4e.eclipse.test.fwk.ProjectHelper.java

License:Open Source License

public static IJavaProject createProject(String name) throws CoreException {

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(name);
    if (!project.exists()) {
        project.create(new NullProgressMonitor());
    } else {//  w w  w  .j  a  v  a 2  s. co m
        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    }

    if (!project.isOpen()) {
        project.open(new NullProgressMonitor());
    }

    IFolder binFolder = project.getFolder("bin");
    if (!binFolder.exists()) {
        createFolder(binFolder, false, true, new NullProgressMonitor());
    }
    IPath outputLocation = binFolder.getFullPath();

    addNatureToProject(project, JavaCore.NATURE_ID, new NullProgressMonitor());

    IJavaProject jproject = JavaCore.create(project);
    jproject.setOutputLocation(outputLocation, new NullProgressMonitor());

    IClasspathEntry[] entries = PreferenceConstants.getDefaultJRELibrary();

    jproject.setRawClasspath(entries, new NullProgressMonitor());

    return jproject;
}

From source file:org.hibernate.eclipse.console.test.project.xpl.JavaProjectHelper.java

License:Open Source License

/**
 * Creates a IJavaProject./*w w w  .  jav a 2  s  . c o m*/
 * @param projectName The name of the project
 * @param binFolderName Name of the output folder
 * @return Returns the Java project handle
 * @throws CoreException Project creation failed
 */
public static IJavaProject createJavaProject(String projectName, String binFolderName) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) {
        project.create(null);
    } else {
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    }

    if (!project.isOpen()) {
        project.open(null);
    }

    IPath outputLocation;
    if (binFolderName != null && binFolderName.length() > 0) {
        IFolder binFolder = project.getFolder(binFolderName);
        if (!binFolder.exists()) {
            CoreUtility.createFolder(binFolder, false, true, null);
        }
        outputLocation = binFolder.getFullPath();
    } else {
        outputLocation = project.getFullPath();
    }

    if (!project.hasNature(JavaCore.NATURE_ID)) {
        addNatureToProject(project, JavaCore.NATURE_ID, null);
    }

    IJavaProject jproject = JavaCore.create(project);

    jproject.setOutputLocation(outputLocation, null);
    jproject.setRawClasspath(new IClasspathEntry[0], null);

    return jproject;
}

From source file:org.hyperic.hypclipse.internal.wizards.project.NewProjectCreationOperation.java

License:Open Source License

/**
 * Sets project classpath.// w w w  . jav  a2s .c  o m
 * 
 * @param project
 * @param data
 * @throws JavaModelException
 * @throws CoreException
 */
private void setClasspath(IProject project, IFieldData data) throws JavaModelException, CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    // Set output folder
    if (data.getOutputFolderName() != null) {
        IPath path = project.getFullPath().append(data.getOutputFolderName());
        javaProject.setOutputLocation(path, null);
    }
    IClasspathEntry[] entries = getClassPathEntries(javaProject, data);
    javaProject.setRawClasspath(entries, null);
}

From source file:org.jboss.tools.gwt.core.GWTInstallFacetDelegate.java

License:Open Source License

private void configureOutputFolder(IPath webContentProjectPath, final IJavaProject javaProject,
        IProgressMonitor monitor) throws CoreException, JavaModelException {
    IProject project = javaProject.getProject();
    monitor.subTask("Configuring output folder");
    IPath outputFolderProjectPath = webContentProjectPath
            .append(new Path(IGoogleEclipsePluginConstants.OUTPUT_FOLDER_DEFAULTVALUE));
    final IFolder outputWorkspaceFolder = project.getWorkspace().getRoot().getFolder(outputFolderProjectPath);
    project.getWorkspace().run(new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            if (!outputWorkspaceFolder.exists()) {
                ResourceUtils.create(outputWorkspaceFolder, monitor);
            }/*www.j a v  a2s  .c  om*/
            javaProject.setOutputLocation(outputWorkspaceFolder.getFullPath(), monitor);
        }
    }, monitor);
}

From source file:org.jboss.tools.jst.web.kb.test.validation.KbCapabilitiesTest.java

License:Open Source License

private static void addJavaNature(IProject project, IPath outputLocation, IPath srcLocation, IProject denendsOn,
        IProgressMonitor monitor) throws Exception {
    IProjectDescription description = project.getDescription();
    description.setNatureIds(new String[] { JavaCore.NATURE_ID });
    ICommand builderCmd = project.getDescription().newCommand();
    builderCmd.setBuilderName(JavaCore.BUILDER_ID);
    description.setBuildSpec(new ICommand[] { builderCmd });
    project.setDescription(description, monitor);

    IJavaProject javaProject = JavaCore.create(project);
    project.getFolder(outputLocation).create(IFolder.FORCE, true, monitor);
    project.getFolder(srcLocation).create(IFolder.FORCE, true, monitor);

    IClasspathEntry srcEntry = JavaCore.newSourceEntry(project.getFullPath().append(srcLocation));
    IClasspathEntry jreEntry = JavaCore.newContainerEntry(new Path(JavaRuntime.JRE_CONTAINER));
    IClasspathEntry projectEntry = denendsOn == null ? null : JavaCore.newProjectEntry(denendsOn.getFullPath());
    if (projectEntry == null) {
        javaProject.setRawClasspath(new IClasspathEntry[] { srcEntry, jreEntry }, monitor);
    } else {/*from  w w w .j  a v  a2  s.co m*/
        javaProject.setRawClasspath(new IClasspathEntry[] { srcEntry, jreEntry, projectEntry }, monitor);
    }
    javaProject.setOutputLocation(project.getFullPath().append(outputLocation), monitor);
    javaProject.save(monitor, true);
}

From source file:org.jboss.tools.seam.internal.core.project.facet.WtpUtils.java

License:Open Source License

public static void addJavaNature(IProject project, IPath outputLocation, IPath srcLocation,
        IProgressMonitor monitor) {//from  ww w .  ja  va 2 s. co  m
    try {
        IProjectDescription newDescr = project.getDescription();
        newDescr.setNatureIds(new String[] { JavaCore.NATURE_ID });
        ICommand builderCmd = project.getDescription().newCommand();
        builderCmd.setBuilderName(JavaCore.BUILDER_ID);
        newDescr.setBuildSpec(new ICommand[] { builderCmd });
        project.setDescription(newDescr, monitor);
        IJavaProject newJavaPr = JavaCore.create(project);
        project.getFolder(outputLocation).create(IFolder.FORCE, true, monitor);
        project.getFolder(srcLocation).create(IFolder.FORCE, true, monitor);

        newJavaPr
                .setRawClasspath(new IClasspathEntry[] { JavaCore.newSourceEntry(Path.ROOT.append(srcLocation)),
                        JavaCore.newContainerEntry(new Path(JavaRuntime.JRE_CONTAINER)) }, monitor);
        newJavaPr.setOutputLocation(outputLocation, monitor);
        newJavaPr.save(monitor, true);
    } catch (JavaModelException e) {
        SeamCorePlugin.getPluginLog().logError(e);
    } catch (CoreException e) {
        SeamCorePlugin.getPluginLog().logError(e);
    }
}

From source file:org.jbpm.eclipse.wizard.project.NewJBPMMavenProjectWizard.java

License:Apache License

private void createOutputLocation(IJavaProject project, IProgressMonitor monitor)
        throws JavaModelException, CoreException {
    IFolder folder = project.getProject().getFolder("target/classes");
    createFolder(folder, monitor);/*w  w  w  .  ja  va 2s . c  om*/
    IPath path = folder.getFullPath();
    project.setOutputLocation(path, null);
}

From source file:org.jbpm.gd.jpdl.wizard.NewProcessProjectWizard.java

License:Open Source License

private void createOutputLocation(IJavaProject javaProject) throws JavaModelException, CoreException {
    IFolder binFolder = javaProject.getProject().getFolder("bin");
    createFolder(binFolder);// w w  w  .j  a va 2s.co  m
    IPath outputLocation = binFolder.getFullPath();
    javaProject.setOutputLocation(outputLocation, null);
}