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.asup.dk.source.jdt.JDTProjectUtil.java

License:Open Source License

public static IJavaProject convertToJavaPluginProject(IProject project) throws CoreException {

    IJavaProject javaProject = JavaCore.create(project);

    IProjectDescription projectDescription = project.getDescription();
    List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
    classpathEntries.addAll(Arrays.asList(javaProject.getRawClasspath()));

    ICommand[] builders = projectDescription.getBuildSpec();
    if (builders == null) {
        builders = new ICommand[0];
    }//from ww  w  .  j a  va  2s. c o m
    boolean hasManifestBuilder = false;
    boolean hasSchemaBuilder = false;
    for (int i = 0; i < builders.length; ++i) {
        if (PDE_MANIFEST_BUILDER.equals(builders[i].getBuilderName())) {
            hasManifestBuilder = true;
        }
        if (PDE_SCHEMA_BUILDER.equals(builders[i].getBuilderName())) {
            hasSchemaBuilder = true;
        }
    }
    if (!hasManifestBuilder) {
        ICommand[] oldBuilders = builders;
        builders = new ICommand[oldBuilders.length + 1];
        System.arraycopy(oldBuilders, 0, builders, 0, oldBuilders.length);
        builders[oldBuilders.length] = projectDescription.newCommand();
        builders[oldBuilders.length].setBuilderName(PDE_MANIFEST_BUILDER);
    }
    if (!hasSchemaBuilder) {
        ICommand[] oldBuilders = builders;
        builders = new ICommand[oldBuilders.length + 1];
        System.arraycopy(oldBuilders, 0, builders, 0, oldBuilders.length);
        builders[oldBuilders.length] = projectDescription.newCommand();
        builders[oldBuilders.length].setBuilderName(PDE_SCHEMA_BUILDER);
    }
    projectDescription.setBuildSpec(builders);

    project.setDescription(projectDescription, null);

    // classpath
    List<IClasspathEntry> classpath = new ArrayList<IClasspathEntry>();
    // jre
    IClasspathEntry jreClasspathEntry = JavaCore.newContainerEntry(new Path(JRE_CONTAINER_ID));
    classpath.add(jreClasspathEntry);
    // pde
    IClasspathEntry pdeClasspathEntry = JavaCore.newContainerEntry(new Path(PDE_CONTAINER_ID));
    classpath.add(pdeClasspathEntry);
    // source folder 
    IClasspathEntry classpathEntry = JavaCore.newSourceEntry(javaProject.getPath().append(JAVA_SRC_DIRECTORY));
    classpath.add(classpathEntry);

    IClasspathEntry[] classpathEntryArray = classpath.toArray(new IClasspathEntry[classpath.size()]);
    javaProject.setRawClasspath(classpathEntryArray, null);
    // compilation output
    javaProject.setOutputLocation(javaProject.getPath().append(JAVA_CLASSES_DIRECTORY), null);

    return javaProject;
}

From source file:org.autorefactor.refactoring.rules.JavaCoreHelper.java

License:Open Source License

public static IJavaProject createJavaProject(String projectName, String binFolderName) throws Exception {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) {
        project.create(null);/*from  ww  w.j a  v  a 2  s  .co m*/
    } else {
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    }

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

    final IFolder binFolder = project.getFolder(binFolderName);
    createFolder(binFolder);

    addNatureToProject(project, JavaCore.NATURE_ID);

    final IJavaProject javaProject = JavaCore.create(project);
    javaProject.setOutputLocation(binFolder.getFullPath(), null);
    javaProject.setRawClasspath(new IClasspathEntry[0], null);
    return javaProject;
}

From source file:org.cubictest.ui.wizards.NewCubicTestProjectWizard.java

License:Open Source License

private IProject createProject(IProgressMonitor monitor, boolean launchNewTestWizard) {

    try {/*from w  w w .j a  va  2 s  . co  m*/
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IProject project = root.getProject(namePage.getProjectName());

        IProjectDescription description = ResourcesPlugin.getWorkspace()
                .newProjectDescription(project.getName());

        if (!Platform.getLocation().equals(namePage.getLocationPath()))
            description.setLocation(namePage.getLocationPath());

        description.setNatureIds(new String[] { JavaCore.NATURE_ID });
        ICommand buildCommand = description.newCommand();
        buildCommand.setBuilderName(JavaCore.BUILDER_ID);
        description.setBuildSpec(new ICommand[] { buildCommand });
        project.create(description, monitor);
        project.open(monitor);

        IJavaProject javaProject = JavaCore.create(project);
        Map<?, ?> java15options = javaProject.getOptions(true);
        JavaCore.setComplianceOptions("1.5", java15options);
        javaProject.setOptions(java15options);

        IFolder testFolder = project.getFolder(TESTS_FOLDER_NAME);
        testFolder.create(false, true, monitor);

        IFolder suiteFolder = project.getFolder(TEST_SUITES_FOLDER_NAME);
        suiteFolder.create(false, true, monitor);

        project.getFolder("src").create(false, true, monitor);
        project.getFolder("src/main").create(false, true, monitor);
        project.getFolder("src/test").create(false, true, monitor);

        IFolder javaSrcFolder = project.getFolder("src/main/java");
        javaSrcFolder.create(false, true, monitor);

        IFolder javaTestFolder = project.getFolder("src/test/java");
        javaTestFolder.create(false, true, monitor);

        IFolder customTestSuites = project.getFolder("src/test/java/customTestSuites");
        customTestSuites.create(false, true, monitor);

        IFolder binFolder = project.getFolder("bin");
        binFolder.create(false, true, monitor);

        IFolder libFolder = project.getFolder("lib");
        libFolder.create(false, true, monitor);

        WizardUtils.copyPom(project.getLocation().toFile());
        WizardUtils.copySampleCustomTestSuite(customTestSuites.getRawLocation().toFile());
        WizardUtils.copySettings(project.getLocation().toFile());

        //construct build path for the new project
        List<IClasspathEntry> classpathlist = new ArrayList<IClasspathEntry>();
        classpathlist.add(JavaCore.newSourceEntry(javaSrcFolder.getFullPath()));
        classpathlist.add(JavaCore.newSourceEntry(javaTestFolder.getFullPath()));
        classpathlist.add(JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")));

        javaProject.setOutputLocation(binFolder.getFullPath(), monitor);

        javaProject.setRawClasspath(classpathlist.toArray(new IClasspathEntry[classpathlist.size()]),
                binFolder.getFullPath(), monitor);

        ResourceNavigator navigator = null;
        IViewPart viewPart = workbench.getActiveWorkbenchWindow().getActivePage().getViewReferences()[0]
                .getView(false);

        if (viewPart instanceof ResourceNavigator) {
            navigator = (ResourceNavigator) viewPart;
        }

        if (launchNewTestWizard) {
            launchNewTestWizard(testFolder);
            if (navigator != null && testFolder.members().length > 0) {
                navigator.selectReveal(new StructuredSelection(testFolder.members()[0]));
            }
        }

        handlePluginBuildPathSupporters(javaProject, libFolder, classpathlist);

        project.refreshLocal(IResource.DEPTH_INFINITE, null);

        return project;

    } catch (Exception e) {
        ErrorHandler.logAndShowErrorDialogAndRethrow(e);
        return null;
    }
}

From source file:org.drools.eclipse.wizard.project.NewDroolsProjectWizard.java

License:Apache License

private void createOutputLocation(IJavaProject project, IProgressMonitor monitor)
        throws JavaModelException, CoreException {
    IFolder folder = project.getProject().getFolder("bin");
    createFolder(folder, monitor);/*  www. j  ava 2  s .  c o m*/
    IPath path = folder.getFullPath();
    project.setOutputLocation(path, null);
}

From source file:org.dslforge.xtext.generator.DynamicWebProjectFactory.java

License:Open Source License

public void convertToJava(IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    try {/*from  ww w. java2 s .c  o  m*/
        IProject project = this.configuration.getProject();
        IJavaProject javaProject = JavaCore.create(project);
        javaProject.setOutputLocation(project.getFolder(BIN).getFullPath(), progress.newChild(1));
        IClasspathEntry[] entries = new IClasspathEntry[5];
        ClasspathComputer.setComplianceOptions(javaProject, JRE_VERSION);
        entries[0] = ClasspathComputer.createJREEntry(JRE_VERSION);
        entries[1] = ClasspathComputer.createContainerEntry();
        entries[2] = JavaCore.newSourceEntry(project.getFolder(SRC).getFullPath());
        entries[3] = JavaCore.newSourceEntry(project.getFolder(SRC_GEN).getFullPath());
        entries[4] = JavaCore.newSourceEntry(project.getFolder(SRC_JS).getFullPath());
        javaProject.setRawClasspath(entries, progress.newChild(1));
    } catch (CoreException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.ebayopensource.turmeric.eclipse.errorlibrary.buildsystem.core.ErrorLibraryBuildSystemConfigurer.java

License:Open Source License

/**
 * Adds the java support.//  ww w.  j  a v  a  2s.  co m
 *
 * @param errorLibraryProject the error library project
 * @param outputLocation the output location
 * @param monitor the monitor
 * @throws CoreException the core exception
 */
public static void addJavaSupport(SOAErrorLibraryProject errorLibraryProject, String outputLocation,
        IProgressMonitor monitor) throws CoreException {
    final IProject project = errorLibraryProject.getProject();
    boolean changedClasspath = false;
    if (JDTUtil.addJavaNature(project, monitor)) {
        changedClasspath = true;
    }
    // Configuring the Java Project
    final IJavaProject javaProject = JavaCore.create(project);
    final List<IClasspathEntry> classpath = JDTUtil.rawClasspath(javaProject, true);
    final List<IClasspathEntry> classpathContainers = new ArrayList<IClasspathEntry>();
    // TODO Lets see if we need this
    if (outputLocation.equals(javaProject.getOutputLocation()) == false) {
        final IFolder outputDirClasses = project.getFolder(outputLocation);
        javaProject.setOutputLocation(outputDirClasses.getFullPath(), monitor);
        changedClasspath = true;
    }

    // Dealing with the case where the root of the project is set to be the
    // src and bin destinations... bad... bad...
    for (final Iterator<IClasspathEntry> iterator = classpath.iterator(); iterator.hasNext();) {
        final IClasspathEntry entry = iterator.next();
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            classpathContainers.add(entry);
        }
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE
                || !entry.getPath().equals(new Path("/" + project.getName())))
            continue;
        iterator.remove();
        changedClasspath |= true;
    }
    for (final SOAProjectSourceDirectory dir : errorLibraryProject.getSourceDirectories()) {
        if (!WorkspaceUtil.isDotDirectory(dir.getLocation())) {
            final IFolder source = project.getFolder(dir.getLocation());
            // If the Java project existed previously, checking if
            // directories
            // already exist in
            // its classpath.
            boolean found = false;
            for (final IClasspathEntry entry : classpath) {
                if (!entry.getPath().equals(source.getFullPath()))
                    continue;
                found = true;
                break;
            }
            if (found)
                continue;
            changedClasspath |= true;
            IPath[] excludePatterns = ClasspathEntry.EXCLUDE_NONE;
            if (dir.getExcludePatterns() != null) {
                int length = dir.getExcludePatterns().length;
                excludePatterns = new Path[length];
                for (int i = 0; i < length; i++) {
                    excludePatterns[i] = new Path(dir.getExcludePatterns()[i]);
                }
            }
            IPath outputPath = dir.getOutputLocation() != null
                    ? project.getFolder(dir.getOutputLocation()).getFullPath()
                    : null;
            final IClasspathEntry entry = JavaCore.newSourceEntry(source.getFullPath(), excludePatterns,
                    outputPath);
            classpath.add(entry);
        }
    }
    ProgressUtil.progressOneStep(monitor);
    // Adding the runtime library
    boolean found = false;
    for (final IClasspathEntry entry : classpath) {
        // All JRE Containers should have a prefix of
        // org.eclipse.jdt.launching.JRE_CONTAINER
        if (JavaRuntime.newDefaultJREContainerPath().isPrefixOf(entry.getPath())
                && JavaRuntime.newDefaultJREContainerPath().equals(entry.getPath())) {
            found = true;
            break;
        }
    }
    if (!found) {
        changedClasspath = true;
        classpath.add(JavaRuntime.getDefaultJREContainerEntry());
    }
    // we want all classpath containers to be the end of .classpath file
    classpath.removeAll(classpathContainers);
    classpath.addAll(classpathContainers);

    ProgressUtil.progressOneStep(monitor);
    // Configuring the classpath of the Java Project
    if (changedClasspath) {
        javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[0]), null);
    }
}

From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil.java

License:Open Source License

/**
 * Adds the java support to eclipse project.
 * ie soa nature is added here./*from   w w  w  .j  a va2 s  .  c  o m*/
 * Class Path container related linking etc..
 *
 * @param project the project
 * @param sourceDirectories the source directories
 * @param defaultCompilerLevel the default compiler level
 * @param outputLocation the output location
 * @param monitor the monitor
 * @throws CoreException the core exception
 */
public static void addJavaSupport(IProject project, List<String> sourceDirectories, String defaultCompilerLevel,
        String outputLocation, IProgressMonitor monitor) throws CoreException {

    boolean changedClasspath = false;
    if (addJavaNature(project, monitor)) {
        changedClasspath = true;
    }
    // Configuring the Java Project
    final IJavaProject javaProject = JavaCore.create(project);
    final List<IClasspathEntry> classpath = JDTUtil.rawClasspath(javaProject, true);
    if (outputLocation.equals(javaProject.getOutputLocation()) == false) {
        final IFolder outputDirClasses = project.getFolder(outputLocation);
        javaProject.setOutputLocation(outputDirClasses.getFullPath(), monitor);
        changedClasspath = true;
    }

    // Dealing with the case where the root of the project is set to be the
    // src and bin destinations... bad... bad...
    for (final Iterator<IClasspathEntry> iterator = classpath.iterator(); iterator.hasNext();) {
        final IClasspathEntry entry = iterator.next();
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE
                || !entry.getPath().equals(new Path("/" + project.getName())))
            continue;
        iterator.remove();
        changedClasspath |= true;
    }
    for (final String dir : sourceDirectories) {

        final IFolder source = project.getFolder(dir);
        // If the Java project existed previously, checking if directories
        // already exist in
        // its classpath.
        boolean found = false;
        for (final IClasspathEntry entry : classpath) {
            if (!entry.getPath().equals(source.getFullPath()))
                continue;
            found = true;
            break;
        }
        if (found)
            continue;
        changedClasspath |= true;
        classpath.add(JavaCore.newSourceEntry(source.getFullPath()));
    }
    ProgressUtil.progressOneStep(monitor, 10);
    // Adding the runtime library
    boolean found = false;
    for (final IClasspathEntry entry : classpath) {
        // All JRE Containers should have a prefix of
        // org.eclipse.jdt.launching.JRE_CONTAINER
        if (JavaRuntime.newDefaultJREContainerPath().isPrefixOf(entry.getPath())
                && JavaRuntime.newDefaultJREContainerPath().equals(entry.getPath())) {
            found = true;
            break;
        }
    }
    if (!found) {
        changedClasspath = true;
        classpath.add(JavaRuntime.getDefaultJREContainerEntry());
    }
    ProgressUtil.progressOneStep(monitor);
    // Configuring the classpath of the Java Project
    if (changedClasspath) {
        javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[0]), null);
    }

    IProjectFacetVersion projectFacetVersion = JavaFacetUtils.JAVA_60;
    if (StringUtils.isNotBlank(defaultCompilerLevel)) {
        try {
            projectFacetVersion = JavaFacetUtils.compilerLevelToFacet(defaultCompilerLevel);
        } catch (Exception e) {
            Logger.getLogger(JDTUtil.class.getName()).throwing(JDTUtil.class.getName(), "addJavaSupport", e);
        }
    }

    JavaFacetUtils.setCompilerLevel(project, projectFacetVersion);
}

From source file:org.eclim.plugin.jdt.project.JavaProjectManager.java

License:Open Source License

/**
 * Creates a new project.//www .j  a v  a  2s .co m
 *
 * @param project The project.
 * @param depends Comma separated project names this project depends on.
 */
protected void create(IProject project, String depends) throws Exception {
    // with scala-ide installed, apparently this needs to be explicitly done
    IProjectDescription desc = project.getDescription();
    if (!desc.hasNature(PluginResources.NATURE)) {
        String[] natures = desc.getNatureIds();
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = PluginResources.NATURE;
        desc.setNatureIds(newNatures);
        project.setDescription(desc, new NullProgressMonitor());
    }

    IJavaProject javaProject = JavaCore.create(project);
    ((JavaProject) javaProject).configure();

    if (!project.getFile(CLASSPATH).exists()) {
        ArrayList<IClasspathEntry> classpath = new ArrayList<IClasspathEntry>();
        boolean source = false;
        boolean container = false;

        ClassPathDetector detector = new ClassPathDetector(project, null);
        for (IClasspathEntry entry : detector.getClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                source = true;
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                container = true;
            }
            classpath.add(entry);
        }

        // default source folder
        if (!source) {
            IResource src;
            IPreferenceStore store = PreferenceConstants.getPreferenceStore();
            String name = store.getString(PreferenceConstants.SRCBIN_SRCNAME);
            boolean srcBinFolders = store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ);
            if (srcBinFolders && name.length() > 0) {
                src = javaProject.getProject().getFolder(name);
            } else {
                src = javaProject.getProject();
            }

            classpath.add(new CPListElement(javaProject, IClasspathEntry.CPE_SOURCE, src.getFullPath(), src)
                    .getClasspathEntry());

            File srcPath = new File(ProjectUtils.getFilePath(project, src.getFullPath().toString()));
            if (!srcPath.exists()) {
                srcPath.mkdirs();
            }
        }

        // default containers
        if (!container) {
            for (IClasspathEntry entry : PreferenceConstants.getDefaultJRELibrary()) {
                classpath.add(entry);
            }
        }

        // dependencies on other projects
        for (IClasspathEntry entry : createOrUpdateDependencies(javaProject, depends)) {
            classpath.add(entry);
        }

        javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[classpath.size()]), null);

        // output location
        IPath output = detector.getOutputLocation();
        if (output == null) {
            output = BuildPathsBlock.getDefaultOutputLocation(javaProject);
        }
        javaProject.setOutputLocation(output, null);
    }
    javaProject.makeConsistent(null);
    javaProject.save(null, false);
}

From source file:org.eclipse.acceleo.internal.ide.ui.wizards.project.AcceleoProjectWizard.java

License:Open Source License

/**
 * Convert the empty project to an Acceleo project.
 * //from   w w  w  . jav a  2 s.co m
 * @param project
 *            The newly created project.
 * @param selectedJVM
 *            The name of the selected JVM (J2SE-1.5 or JavaSE-1.6 recommended).
 * @param allModules
 *            The description of the module that need to be created.
 * @param shouldGenerateModules
 *            Indicates if we should generate the modules in the project or not. The wizard container to
 *            display the progress monitor
 * @param monitor
 *            The monitor.
 */
public static void convert(IProject project, String selectedJVM, List<AcceleoModule> allModules,
        boolean shouldGenerateModules, IProgressMonitor monitor) {
    String generatorName = computeGeneratorName(project.getName());
    AcceleoProject acceleoProject = AcceleowizardmodelFactory.eINSTANCE.createAcceleoProject();
    acceleoProject.setName(project.getName());
    acceleoProject.setGeneratorName(generatorName);

    // Default JRE value
    acceleoProject.setJre(selectedJVM);
    if (acceleoProject.getJre() == null || acceleoProject.getJre().length() == 0) {
        acceleoProject.setJre("J2SE-1.5"); //$NON-NLS-1$         
    }

    if (shouldGenerateModules) {
        for (AcceleoModule acceleoModule : allModules) {
            String parentFolder = acceleoModule.getParentFolder();
            IProject moduleProject = ResourcesPlugin.getWorkspace().getRoot()
                    .getProject(acceleoModule.getProjectName());
            if (moduleProject.exists() && moduleProject.isAccessible()
                    && acceleoModule.getModuleElement() != null
                    && acceleoModule.getModuleElement().isIsMain()) {
                IPath parentFolderPath = new Path(parentFolder);
                IFolder folder = moduleProject.getFolder(parentFolderPath.removeFirstSegments(1));
                acceleoProject.getExportedPackages()
                        .add(folder.getProjectRelativePath().removeFirstSegments(1).toString().replaceAll("/", //$NON-NLS-1$
                                "\\.")); //$NON-NLS-1$
            }
            // Calculate project dependencies
            List<String> metamodelURIs = acceleoModule.getMetamodelURIs();
            for (String metamodelURI : metamodelURIs) {
                // Find the project containing this metamodel and add a dependency to it.
                EPackage ePackage = AcceleoPackageRegistry.INSTANCE.getEPackage(metamodelURI);
                if (ePackage != null && !(ePackage instanceof EcorePackage)) {
                    Bundle bundle = AcceleoWorkspaceUtil.getBundle(ePackage.getClass());
                    acceleoProject.getPluginDependencies().add(bundle.getSymbolicName());
                }
            }
        }
    }

    try {
        IProjectDescription description = project.getDescription();
        description.setNatureIds(new String[] { JavaCore.NATURE_ID, IBundleProjectDescription.PLUGIN_NATURE,
                IAcceleoConstants.ACCELEO_NATURE_ID, });
        project.setDescription(description, monitor);

        IJavaProject iJavaProject = JavaCore.create(project);

        // Compute the JRE
        List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
        IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime
                .getExecutionEnvironmentsManager();
        IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager.getExecutionEnvironments();
        for (IExecutionEnvironment iExecutionEnvironment : executionEnvironments) {
            if (acceleoProject.getJre().equals(iExecutionEnvironment.getId())) {
                entries.add(JavaCore.newContainerEntry(JavaRuntime.newJREContainerPath(iExecutionEnvironment)));
                break;
            }
        }

        // PDE Entry (will not be generated anymore)
        entries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); //$NON-NLS-1$

        // Sets the input / output folders
        IFolder target = project.getFolder("src"); //$NON-NLS-1$
        if (!target.exists()) {
            target.create(true, true, monitor);
        }

        IFolder classes = project.getFolder("bin"); //$NON-NLS-1$
        if (!classes.exists()) {
            classes.create(true, true, monitor);
        }

        iJavaProject.setOutputLocation(classes.getFullPath(), monitor);
        IPackageFragmentRoot packageRoot = iJavaProject.getPackageFragmentRoot(target);
        entries.add(JavaCore.newSourceEntry(packageRoot.getPath(), new Path[] {}, new Path[] {},
                classes.getFullPath()));

        iJavaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
        iJavaProject.open(monitor);

        AcceleoProjectUtils.generateFiles(acceleoProject, allModules, project, shouldGenerateModules, monitor);

        // Default settings
        AcceleoBuilderSettings settings = new AcceleoBuilderSettings(project);
        settings.setCompilationKind(AcceleoBuilderSettings.COMPILATION_PLATFORM_RESOURCE);
        settings.setResourceKind(AcceleoBuilderSettings.BUILD_XMI_RESOURCE);
        settings.save();
    } catch (CoreException e) {
        AcceleoUIActivator.log(e, true);
    }
}

From source file:org.eclipse.ajdt.core.tests.builder.AJBuilderTest2.java

License:Open Source License

/**
 * Part of Bug 91420 - if the output folder has changed then need to do a
 * build//  w w w. ja  v  a2  s  .c  o  m
 */
public void testChangeInOutputDirCausesReBuild() throws Exception {
    IProject project = createPredefinedProject("bug91420"); //$NON-NLS-1$
    IJavaProject javaProject = JavaCore.create(project);
    IPath origOutput = javaProject.getOutputLocation();

    IPath newOutput = new Path("/bug91420/newBin"); //$NON-NLS-1$
    assertFalse("should be setting output dir to new place", //$NON-NLS-1$
            origOutput.toString().equals(newOutput.toString()));

    TestLogger testLog = new TestLogger();
    AspectJPlugin.getDefault().setAJLogger(testLog);
    javaProject.setOutputLocation(newOutput, null);

    joinBackgroudActivities();

    assertNotSame("should have set output directory to new place", origOutput, newOutput); //$NON-NLS-1$

    List log = testLog.getMostRecentEntries(3);
    // print log to the screen for test case development purposes
    testLog.printLog();

    assertTrue("output dir has changed so should have spent time in AJDE", //$NON-NLS-1$
            testLog.containsMessage("Total time spent in AJDE")); //$NON-NLS-1$  
    assertTrue("output dir has changed so should have spent time in AJBuilder.build()", //$NON-NLS-1$
            testLog.containsMessage("Total time spent in AJBuilder.build()")); //$NON-NLS-1$

    // reset the output dir back to its original setting
    javaProject.setOutputLocation(origOutput, null);
    waitForAutoBuild();
    assertEquals("should have reset the output directory", origOutput.toString(), //$NON-NLS-1$
            javaProject.getOutputLocation().toString());
}