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.eclipse.amp.escape.ide.ProjectWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    try {//www .j a  v  a  2 s  . c o m
        IJavaProject javaProject = JavaCore.create(getProject());
        final IProjectDescription projectDescription = ResourcesPlugin.getWorkspace()
                .newProjectDescription(projectPage.getProjectName());
        if (projectPage.useDefaults()) {
            projectDescription.setLocation(null);
        } else {
            projectDescription.setLocation(projectPage.getLocationPath());
        }

        getProject().create(projectDescription, null);

        projectDescription.setNatureIds(getNatures().toArray(new String[0]));

        List<String> builderIDs = getBuilders();
        ICommand[] buildCMDS = new ICommand[builderIDs.size()];
        int i = 0;
        for (String builderID : builderIDs) {
            ICommand build = projectDescription.newCommand();
            build.setBuilderName(builderID);
            buildCMDS[i++] = build;
        }
        projectDescription.setBuildSpec(buildCMDS);
        getProject().open(null);
        getProject().setDescription(projectDescription, null);

        List<IClasspathEntry> classpathEntries = getClasspathsEntries();
        javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
                null);
        javaProject.setOutputLocation(new Path("/" + projectPage.getProjectName() + "/bin"), null);

        createFiles();
        return true;
    } catch (Exception exception) {
        StatusManager.getManager().handle(new Status(IStatus.ERROR, getCurrentPluginID(),
                "Problem creating " + getProjectTypeName() + " project. Ignoring.", exception));
        try {
            getProject().delete(true, null);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return false;
    }
}

From source file:org.eclipse.andmore.android.model.ProjectCreationSupport.java

License:Apache License

/**
 * Create android project./*from   w w w.  ja v  a  2 s . c  om*/
 * 
 * @param project
 * @param androidProject
 * @param description
 * @param monitor
 * @param parameters
 * @param stringDictionary
 * @throws InvocationTargetException
 */
protected static void createProjectAsync(IProject project, AndroidProject androidProject,
        IProjectDescription description, IProgressMonitor monitor, Map<String, Object> parameters,
        Map<String, String> stringDictionary) throws InvocationTargetException {
    monitor.beginTask(AndroidNLS.UI_ProjectCreationSupport_CopyingSamplesMonitorTaskTitle, 1000);
    try {
        // Create project and open it
        project.create(description, new SubProgressMonitor(monitor, 100));
        if (monitor.isCanceled()) {
            undoProjectCreation(project);
            throw new OperationCanceledException();
        }
        project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 100));

        ProjectUtils.setupAndroidNatures(project, monitor);

        // Create folders in the project if they don't already exist
        createDefaultDir(project, IAndroidConstants.WS_ROOT, BIN_DIR, new SubProgressMonitor(monitor, 40));
        createDefaultDir(project, IAndroidConstants.WS_ROOT, RES_DIR, new SubProgressMonitor(monitor, 40));
        createDefaultDir(project, IAndroidConstants.WS_ROOT, ASSETS_DIR, new SubProgressMonitor(monitor, 40));
        createDefaultDir(project, IAndroidConstants.WS_ROOT, GEN_DIR, new SubProgressMonitor(monitor, 40));

        switch (androidProject.getSourceType()) {
        case NEW:
            // Create the source folders in the project if they don't
            // already exist
            List<String> sourceFolders = androidProject.getSourceFolders();
            for (String sourceFolder : sourceFolders) {
                createDefaultDir(project, IAndroidConstants.WS_ROOT, sourceFolder,
                        new SubProgressMonitor(monitor, 40));
            }

            // Create the resource folders in the project if they don't
            // already exist.
            int apiLevel = androidProject.getSdkTarget().getVersion().getApiLevel();
            if (apiLevel < 4) {
                createDefaultDir(project, RES_DIR, DRAWABLE_DIR + File.separator,
                        new SubProgressMonitor(monitor, 40));
            } else {
                for (String dpi : DPIS) {
                    createDefaultDir(project, RES_DIR, DRAWABLE_DIR + "-" + dpi + File.separator,
                            new SubProgressMonitor(monitor, 40));
                }
            }
            createDefaultDir(project, RES_DIR, LAYOUT_DIR, new SubProgressMonitor(monitor, 40));
            createDefaultDir(project, RES_DIR, VALUES_DIR, new SubProgressMonitor(monitor, 40));

            // Create files in the project if they don't already exist
            createManifest(project, parameters, stringDictionary, new SubProgressMonitor(monitor, 80));
            // add the default app icon
            addIcon(project, apiLevel, new SubProgressMonitor(monitor, 100));
            // Create the default package components
            String primarySrcFolder = IAndroidConstants.FD_SOURCES;
            if (!sourceFolders.contains(IAndroidConstants.FD_SOURCES)) {
                primarySrcFolder = sourceFolders.get(0);
            }
            addInitialCode(project, primarySrcFolder, parameters, stringDictionary,
                    new SubProgressMonitor(monitor, 200));
            // add the string definition file if needed
            if (stringDictionary.size() > 0) {
                DictionaryUtils.createOrUpdateDictionaryFile(project, stringDictionary, null,
                        new SubProgressMonitor(monitor, 100));
            }

            break;
        case EXISTING:
            createDefaultDir(project, IAndroidConstants.WS_ROOT, GEN_DIR, new SubProgressMonitor(monitor, 650));
            break;
        case SAMPLE:
            monitor.setTaskName(AndroidNLS.UI_ProjectCreationSupport_CopyingSamplesMonitorMessage);
            FileUtil.copyDir(androidProject.getSample().getFolder(), project.getLocation().toFile());
            project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 650));
            break;
        case WIDGET:
            // Create the source folders in the project if they don't
            // already exist
            List<String> widgetSourceFolders = androidProject.getSourceFolders();
            for (String sourceFolder : widgetSourceFolders) {
                createDefaultDir(project, IAndroidConstants.WS_ROOT, sourceFolder,
                        new SubProgressMonitor(monitor, 40));
            }

            // Create the resource folders in the project if they don't
            // already exist.
            int widgetApiLevel = androidProject.getSdkTarget().getVersion().getApiLevel();
            if (widgetApiLevel < 4) {
                createDefaultDir(project, RES_DIR, DRAWABLE_DIR + File.separator,
                        new SubProgressMonitor(monitor, 40));
            } else {
                for (String dpi : DPIS) {
                    createDefaultDir(project, RES_DIR, DRAWABLE_DIR + "-" + dpi + File.separator,
                            new SubProgressMonitor(monitor, 40));
                }
            }
            createDefaultDir(project, RES_DIR, LAYOUT_DIR, new SubProgressMonitor(monitor, 40));
            createDefaultDir(project, RES_DIR, VALUES_DIR, new SubProgressMonitor(monitor, 40));
            createDefaultDir(project, RES_DIR, XML_DIR, new SubProgressMonitor(monitor, 40));

            // Create files in the project if they don't already exist
            createWidgetManifest(project, parameters, stringDictionary, new SubProgressMonitor(monitor, 80));
            // add the default app icon
            addIcon(project, widgetApiLevel, new SubProgressMonitor(monitor, 100));
            // Create the default package components
            String widgetPrimarySrcFolder = IAndroidConstants.FD_SOURCES;
            if (!widgetSourceFolders.contains(IAndroidConstants.FD_SOURCES)) {
                primarySrcFolder = widgetSourceFolders.get(0);
            }
            addInitialWidgetCode(project, widgetPrimarySrcFolder, parameters, stringDictionary,
                    new SubProgressMonitor(monitor, 200));
            // add the string definition file if needed
            if (stringDictionary.size() > 0) {
                DictionaryUtils.createOrUpdateDictionaryFile(project, stringDictionary, null,
                        new SubProgressMonitor(monitor, 100));
            }

            break;
        }

        // Setup class path
        IJavaProject javaProject = JavaCore.create(project);
        setupSourceFolders(javaProject, androidProject.getSourceFolders(), new SubProgressMonitor(monitor, 40));

        // Set output location
        javaProject.setOutputLocation(project.getFolder(BIN_DIR).getFullPath(),
                new SubProgressMonitor(monitor, 40));
        SdkUtils.associate(project, androidProject.getSdkTarget());
        ProjectUtils.fixProject(project);
    } catch (CoreException e) {
        undoProjectCreation(project);
        throw new InvocationTargetException(e);
    } catch (IOException e) {
        undoProjectCreation(project);
        throw new InvocationTargetException(e);
    } finally {
        monitor.done();
    }
}

From source file:org.eclipse.andmore.internal.build.builders.ResourceManagerBuilder.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w ww. j  a va 2s  . c  o  m*/
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
    // Get the project.
    final IProject project = getProject();
    IJavaProject javaProject = JavaCore.create(project);

    // Clear the project of the generic markers
    removeMarkersFromContainer(project, AndmoreAndroidConstants.MARKER_ADT);

    // check for existing target marker, in which case we abort.
    // (this means: no SDK, no target, or unresolvable target.)
    try {
        abortOnBadSetup(javaProject, null);
    } catch (AbortBuildException e) {
        return null;
    }

    // Check the compiler compliance level, displaying the error message
    // since this is the first builder.
    Pair<Integer, String> result = ProjectHelper.checkCompilerCompliance(project);
    String errorMessage = null;
    switch (result.getFirst().intValue()) {
    case ProjectHelper.COMPILER_COMPLIANCE_LEVEL:
        errorMessage = Messages.Requires_Compiler_Compliance_s;
        break;
    case ProjectHelper.COMPILER_COMPLIANCE_SOURCE:
        errorMessage = Messages.Requires_Source_Compatibility_s;
        break;
    case ProjectHelper.COMPILER_COMPLIANCE_CODEGEN_TARGET:
        errorMessage = Messages.Requires_Class_Compatibility_s;
        break;
    }

    if (errorMessage != null) {
        errorMessage = String.format(errorMessage,
                result.getSecond() == null ? "(no value)" : result.getSecond());

        if (JavaCore.VERSION_1_7.equals(result.getSecond())) {
            // If the user is trying to target 1.7 but compiling with something older,
            // the error message can be a bit misleading; instead point them in the
            // direction of updating the project's build target.
            Sdk currentSdk = Sdk.getCurrent();
            if (currentSdk != null) {
                IAndroidTarget target = currentSdk.getTarget(project.getProject());
                if (target != null && target.getVersion().getApiLevel() < 19) {
                    errorMessage = "Using 1.7 requires compiling with Android 4.4 "
                            + "(KitKat); currently using " + target.getVersion();
                }

                ProjectState projectState = Sdk.getProjectState(project);
                if (projectState != null) {
                    BuildToolInfo buildToolInfo = projectState.getBuildToolInfo();
                    if (buildToolInfo == null) {
                        buildToolInfo = currentSdk.getLatestBuildTool();
                    }
                    if (buildToolInfo != null && buildToolInfo.getRevision().getMajor() < 19) {
                        errorMessage = "Using 1.7 requires using Android Build Tools "
                                + "version 19 or later; currently using " + buildToolInfo.getRevision();
                    }
                }
            }
        }

        markProject(AndmoreAndroidConstants.MARKER_ADT, errorMessage, IMarker.SEVERITY_ERROR);
        AndmoreAndroidPlugin.printErrorToConsole(project, errorMessage);

        return null;
    }

    // Check that the SDK directory has been setup.
    String osSdkFolder = AndmoreAndroidPlugin.getOsSdkFolder();

    if (osSdkFolder == null || osSdkFolder.length() == 0) {
        AndmoreAndroidPlugin.printErrorToConsole(project, Messages.No_SDK_Setup_Error);
        markProject(AndmoreAndroidConstants.MARKER_ADT, Messages.No_SDK_Setup_Error, IMarker.SEVERITY_ERROR);

        return null;
    }

    // check the 'gen' source folder is present
    boolean hasGenSrcFolder = false; // whether the project has a 'gen' source folder setup

    IClasspathEntry[] classpaths = javaProject.readRawClasspath();
    if (classpaths != null) {
        for (IClasspathEntry e : classpaths) {
            if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath path = e.getPath();
                if (path.segmentCount() == 2 && path.segment(1).equals(SdkConstants.FD_GEN_SOURCES)) {
                    hasGenSrcFolder = true;
                    break;
                }
            }
        }
    }

    boolean genFolderPresent = false; // whether the gen folder actually exists
    IResource resource = project.findMember(SdkConstants.FD_GEN_SOURCES);
    genFolderPresent = resource != null && resource.exists();

    if (hasGenSrcFolder == false && genFolderPresent) {
        // No source folder setup for 'gen' in the project, but there's already a
        // 'gen' resource (file or folder).
        String message;
        if (resource.getType() == IResource.FOLDER) {
            // folder exists already! This is an error. If the folder had been created
            // by the NewProjectWizard, it'd be a source folder.
            message = String.format(
                    "%1$s already exists but is not a source folder. Convert to a source folder or rename it.",
                    resource.getFullPath().toString());
        } else {
            // resource exists but is not a folder.
            message = String.format(
                    "Resource %1$s is in the way. ADT needs a source folder called 'gen' to work. Rename or delete resource.",
                    resource.getFullPath().toString());
        }

        AndmoreAndroidPlugin.printErrorToConsole(project, message);
        markProject(AndmoreAndroidConstants.MARKER_ADT, message, IMarker.SEVERITY_ERROR);

        return null;
    } else if (hasGenSrcFolder == false || genFolderPresent == false) {
        // either there is no 'gen' source folder in the project (older SDK),
        // or the folder does not exist (was deleted, or was a fresh svn checkout maybe.)

        // In case we are migrating from an older SDK, we go through the current source
        // folders and delete the generated Java files.
        List<IPath> sourceFolders = BaseProjectHelper.getSourceClasspaths(javaProject);
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        for (IPath path : sourceFolders) {
            IResource member = root.findMember(path);
            if (member != null) {
                removeDerivedResources(member, monitor);
            }
        }

        // create the new source folder, if needed
        IFolder genFolder = project.getFolder(SdkConstants.FD_GEN_SOURCES);
        if (genFolderPresent == false) {
            AndmoreAndroidPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, project,
                    "Creating 'gen' source folder for generated Java files");
            genFolder.create(true /* force */, true /* local */, new SubProgressMonitor(monitor, 10));
        }

        // add it to the source folder list, if needed only (or it will throw)
        if (hasGenSrcFolder == false) {
            IClasspathEntry[] entries = javaProject.getRawClasspath();
            entries = ProjectHelper.addEntryToClasspath(entries,
                    JavaCore.newSourceEntry(genFolder.getFullPath()));
            javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10));
        }

        // refresh specifically the gen folder first, as it may break the build
        // if it doesn't arrive in time then refresh the whole project as usual.
        genFolder.refreshLocal(IResource.DEPTH_ZERO, new SubProgressMonitor(monitor, 10));
        project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 10));

        // it seems like doing this fails to properly rebuild the project. the Java builder
        // running right after this builder will not see the gen folder, and will not be
        // restarted after this build. Therefore in this particular case, we start another
        // build asynchronously so that it's rebuilt after this build.
        launchJob(new Job("rebuild") {
            @Override
            protected IStatus run(IProgressMonitor m) {
                try {
                    project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, m);
                    return Status.OK_STATUS;
                } catch (CoreException e) {
                    return e.getStatus();
                }
            }
        });

    }

    // convert older projects which use bin as the eclipse output folder into projects
    // using bin/classes
    IFolder androidOutput = BaseProjectHelper.getAndroidOutputFolder(project);
    IFolder javaOutput = BaseProjectHelper.getJavaOutputFolder(project);
    if (androidOutput.exists() == false || javaOutput == null
            || javaOutput.getParent().equals(androidOutput) == false) {
        // get what we want as the new java output.
        IFolder newJavaOutput = androidOutput.getFolder(SdkConstants.FD_CLASSES_OUTPUT);

        if (androidOutput.exists() == false) {
            androidOutput.create(true /*force*/, true /*local*/, monitor);
        }

        if (newJavaOutput.exists() == false) {
            newJavaOutput.create(true /*force*/, true /*local*/, monitor);
        }

        // set the java output to this project.
        javaProject.setOutputLocation(newJavaOutput.getFullPath(), monitor);

        // need to do a full build. Can't build while we're already building, so launch a
        // job to build it right after this build
        launchJob(new Job("rebuild") {
            @Override
            protected IStatus run(IProgressMonitor jobMonitor) {
                try {
                    project.build(IncrementalProjectBuilder.CLEAN_BUILD, jobMonitor);
                    return Status.OK_STATUS;
                } catch (CoreException e) {
                    return e.getStatus();
                }
            }
        });
    }

    // check that we have bin/res/
    IFolder binResFolder = androidOutput.getFolder(SdkConstants.FD_RESOURCES);
    if (binResFolder.exists() == false) {
        binResFolder.create(true /* force */, true /* local */, new SubProgressMonitor(monitor, 10));
        project.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(monitor, 10));
    }

    // Check the preference to be sure we are supposed to refresh
    // the folders.
    if (AdtPrefs.getPrefs().getBuildForceResResfresh()) {
        AndmoreAndroidPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, project, Messages.Refreshing_Res);

        // refresh the res folder.
        IFolder resFolder = project.getFolder(AndmoreAndroidConstants.WS_RESOURCES);
        resFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor);

        // Also refresh the assets folder to make sure the ApkBuilder
        // will now it's changed and will force a new resource packaging.
        IFolder assetsFolder = project.getFolder(AndmoreAndroidConstants.WS_ASSETS);
        assetsFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
    }

    return null;
}

From source file:org.eclipse.andmore.internal.wizards.newproject.NewProjectCreator.java

License:Open Source License

/**
 * Creates the actual project, sets its nature and adds the required folders
 * and files to it. This is run asynchronously in a different thread.
 *
 * @param monitor An existing monitor.//from   w w  w  .  j  a  v a 2  s  . c o  m
 * @param project The project to create.
 * @param description A description of the project.
 * @param parameters Template parameters.
 * @param dictionary String definition.
 * @param isAndroidProject true if the project is to be set up as a full Android project; false
 * for a plain Java project.
 * @return The project newly created
 * @throws StreamException
 */
private IProject createEclipseProject(@NonNull IProgressMonitor monitor, @NonNull IProject project,
        @NonNull IProjectDescription description, @NonNull Map<String, Object> parameters,
        @Nullable Map<String, String> dictionary, @Nullable ProjectPopulator projectPopulator,
        boolean isAndroidProject) throws CoreException, IOException, StreamException {

    // get the project target
    IAndroidTarget target = (IAndroidTarget) parameters.get(PARAM_SDK_TARGET);
    boolean legacy = isAndroidProject && target.getVersion().getApiLevel() < 4;

    // Create project and open it
    project.create(description, new SubProgressMonitor(monitor, 10));
    if (monitor.isCanceled())
        throw new OperationCanceledException();

    project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 10));

    // Add the Java and android nature to the project
    AndroidNature.setupProjectNatures(project, monitor, isAndroidProject);

    // Create folders in the project if they don't already exist
    addDefaultDirectories(project, AndmoreAndroidConstants.WS_ROOT, DEFAULT_DIRECTORIES, monitor);
    String[] sourceFolders;
    if (isAndroidProject) {
        sourceFolders = new String[] { (String) parameters.get(PARAM_SRC_FOLDER), GEN_SRC_DIRECTORY };
    } else {
        sourceFolders = new String[] { (String) parameters.get(PARAM_SRC_FOLDER) };
    }
    addDefaultDirectories(project, AndmoreAndroidConstants.WS_ROOT, sourceFolders, monitor);

    // Create the resource folders in the project if they don't already exist.
    if (legacy) {
        addDefaultDirectories(project, RES_DIRECTORY, RES_DIRECTORIES, monitor);
    } else {
        addDefaultDirectories(project, RES_DIRECTORY, RES_DENSITY_ENABLED_DIRECTORIES, monitor);
    }

    if (projectPopulator != null) {
        try {
            projectPopulator.populate(project);
        } catch (InvocationTargetException ite) {
            AndmoreAndroidPlugin.log(ite, null);
        }
    }

    // Setup class path: mark folders as source folders
    IJavaProject javaProject = JavaCore.create(project);
    setupSourceFolders(javaProject, sourceFolders, monitor);

    if (((Boolean) parameters.get(PARAM_IS_NEW_PROJECT)).booleanValue()) {
        // Create files in the project if they don't already exist
        addManifest(project, parameters, dictionary, monitor);

        // add the default app icon
        addIcon(project, legacy, monitor);

        // Create the default package components
        addSampleCode(project, sourceFolders[0], parameters, dictionary, monitor);

        // add the string definition file if needed
        if (dictionary != null && dictionary.size() > 0) {
            addStringDictionaryFile(project, dictionary, monitor);
        }

        // add the default proguard config
        //            File libFolder = new File((String) parameters.get(PARAM_SDK_TOOLS_DIR),
        //                    SdkConstants.FD_LIB);
        File libFolder = new File(Sdk.getCurrent().getSdkFileLocation(),
                SdkConstants.FD_TOOLS + File.separator + SdkConstants.FD_PROGUARD);

        //            addLocalFile(project,
        //                    new File(libFolder, SdkConstants.FN_PROJECT_PROGUARD_FILE),
        //                    // Write ProGuard config files with the extension .pro which
        //                    // is what is used in the ProGuard documentation and samples
        //                    SdkConstants.FN_PROJECT_PROGUARD_FILE,
        //                    monitor);

        // Set output location
        javaProject.setOutputLocation(project.getFolder(BIN_CLASSES_DIRECTORY).getFullPath(), monitor);
    }

    File sampleDir = (File) parameters.get(PARAM_SAMPLE_LOCATION);

    if (sampleDir != null) {
        // Copy project
        copySampleCode(project, sampleDir, parameters, dictionary, monitor);
    }

    // Create the reference to the target project
    if (parameters.containsKey(PARAM_REFERENCE_PROJECT)) {
        IProject refProject = (IProject) parameters.get(PARAM_REFERENCE_PROJECT);
        if (refProject != null) {
            IProjectDescription desc = project.getDescription();

            // Add out reference to the existing project reference.
            // We just created a project with no references so we don't need to expand
            // the currently-empty current list.
            desc.setReferencedProjects(new IProject[] { refProject });

            project.setDescription(desc, IResource.KEEP_HISTORY, new SubProgressMonitor(monitor, 10));

            IClasspathEntry entry = JavaCore.newProjectEntry(refProject.getFullPath(), //path
                    new IAccessRule[0], //accessRules
                    false, //combineAccessRules
                    new IClasspathAttribute[0], //extraAttributes
                    false //isExported

            );
            ProjectHelper.addEntryToClasspath(javaProject, entry);
        }
    }

    if (isAndroidProject) {
        Sdk.getCurrent().initProject(project, target);
    }

    // Fix the project to make sure all properties are as expected.
    // Necessary for existing projects and good for new ones to.
    ProjectHelper.fixProject(project);

    Boolean isLibraryProject = (Boolean) parameters.get(PARAM_IS_LIBRARY);
    if (isLibraryProject != null && isLibraryProject.booleanValue() && Sdk.getCurrent() != null
            && project.isOpen()) {
        ProjectState state = Sdk.getProjectState(project);
        if (state != null) {
            // make a working copy of the properties
            ProjectPropertiesWorkingCopy properties = state.getProperties().makeWorkingCopy();

            properties.setProperty(PROPERTY_LIBRARY, Boolean.TRUE.toString());
            try {
                properties.save();
                IResource projectProp = project.findMember(FN_PROJECT_PROPERTIES);
                if (projectProp != null) {
                    projectProp.refreshLocal(DEPTH_ZERO, new NullProgressMonitor());
                }
            } catch (Exception e) {
                String msg = String.format("Failed to save %1$s for project %2$s",
                        SdkConstants.FN_PROJECT_PROPERTIES, project.getName());
                AndmoreAndroidPlugin.log(e, msg);
            }
        }
    }

    return project;
}

From source file:org.eclipse.birt.report.designer.ui.ide.wizards.NewReportProjectWizard.java

License:Open Source License

private void setClasspath(IProject project) throws JavaModelException, CoreException {
    IJavaProject javaProject = JavaCore.create(project);

    if (outputText.getText() != null && outputText.getText().trim().length() > 0) {
        IPath path = project.getFullPath().append(outputText.getText());
        javaProject.setOutputLocation(path, null);
    }//from w w  w  .j  a  v a  2s .c  om

    IClasspathEntry[] entries = getClassPathEntries(project);
    javaProject.setRawClasspath(entries, null);
}

From source file:org.eclipse.birt.report.designer.ui.samples.ide.action.IDEOpenSampleReportAction.java

License:Open Source License

private void setClasspath(IProject project) throws JavaModelException, CoreException {
    IJavaProject javaProject = JavaCore.create(project);

    IPath path = project.getFullPath().append("bin"); //$NON-NLS-1$
    javaProject.setOutputLocation(path, null);

    IClasspathEntry[] entries = getClassPathEntries(project);
    javaProject.setRawClasspath(entries, null);
}

From source file:org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceOperations.java

License:Open Source License

@Override
public IJavaProject createJavaProject(IProject project, ClasspathDefinition classpath,
        IProgressMonitor monitor) {// w  ww .j av  a  2 s  .c o m
    // validate arguments
    Preconditions.checkNotNull(project);
    Preconditions.checkNotNull(classpath);
    Preconditions.checkArgument(project.isAccessible(), "Project must be open.");

    monitor = MoreObjects.firstNonNull(monitor, new NullProgressMonitor());
    monitor.beginTask(String.format("Create Eclipse Java project %s", project.getName()), 17);
    try {
        // add Java nature
        addNature(project, JavaCore.NATURE_ID, new SubProgressMonitor(monitor, 2));

        // create the Eclipse Java project from the plain Eclipse project
        IJavaProject javaProject = JavaCore.create(project);
        monitor.worked(5);

        // set up resources (sources and classpath)
        setSourcesAndClasspathOnProject(javaProject, classpath, new SubProgressMonitor(monitor, 5));

        // set up output location
        IFolder outputFolder = createOutputFolder(project, new SubProgressMonitor(monitor, 1));
        javaProject.setOutputLocation(outputFolder.getFullPath(), new SubProgressMonitor(monitor, 1));

        // avoid out-of-sync messages when the content of the .gradle folder changes upon running a Gradle build
        markDotGradleFolderAsDerived(project, new SubProgressMonitor(monitor, 1));

        // save the project configuration
        javaProject.save(new SubProgressMonitor(monitor, 2), true);

        // return the created Java project
        return javaProject;
    } catch (Exception e) {
        String message = String.format("Cannot create Eclipse Java project %s.", project.getName());
        CorePlugin.logger().error(message, e);
        throw new GradlePluginsRuntimeException(message, e);
    } finally {
        monitor.done();
    }
}

From source file:org.eclipse.buildship.core.workspace.internal.OutputLocationUpdater.java

License:Open Source License

public static void update(IJavaProject project, Optional<OmniEclipseOutputLocation> outputLocation,
        IProgressMonitor monitor) throws CoreException {
    if (outputLocation.isPresent()) {
        IPath projectPath = project.getProject().getFullPath();
        String outputPath = outputLocation.get().getPath();
        project.setOutputLocation(projectPath.append(outputPath), monitor);
    }//from   w w w  .j av  a 2 s .c o  m
}

From source file:org.eclipse.capra.testsuite.TestHelper.java

License:Open Source License

public static IType createJavaProjectWithASingleJavaClass(String projectName) throws CoreException {
    IProject project = getProject(projectName);

    // Create project
    IProgressMonitor progressMonitor = new NullProgressMonitor();
    project.create(progressMonitor);/* ww  w. ja v  a  2  s.co  m*/
    project.open(progressMonitor);

    // Add Java nature
    IProjectDescription description = project.getDescription();
    description.setNatureIds(new String[] { JavaCore.NATURE_ID });
    project.setDescription(description, null);

    // Create as Java project and set up build path etc.
    IJavaProject javaProject = JavaCore.create(project);
    IFolder binFolder = project.getFolder("bin");
    binFolder.create(false, true, null);
    javaProject.setOutputLocation(binFolder.getFullPath(), null);
    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
    IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
    LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
    for (LibraryLocation element : locations)
        entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));

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

    // Create a src file
    IFolder sourceFolder = project.getFolder("src");
    sourceFolder.create(false, true, null);
    IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder);
    IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
    IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
    System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
    newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath());
    javaProject.setRawClasspath(newEntries, null);

    IPackageFragment pack = javaProject.getPackageFragmentRoot(sourceFolder)
            .createPackageFragment("org.amalthea.test", false, null);

    StringBuffer buffer = new StringBuffer();
    buffer.append("package " + pack.getElementName() + ";\n");
    buffer.append("\n");
    buffer.append("public class TestClass {}");

    ICompilationUnit icu = pack.createCompilationUnit("TestClass.java", buffer.toString(), false, null);
    return icu.getType("TestClass");
}

From source file:org.eclipse.dltk.freemarker.internal.ui.wizards.FreemarkerNewProjectWizard.java

License:Open Source License

private void setClasspath(IProject project) throws JavaModelException, CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    // Set output folder
    //if (data.getOutputFolderName() != null) {
    IPath path = project.getFullPath().append("bin");
    javaProject.setOutputLocation(path, null);
    //}//w  w w.  j  a  va  2s . c  o m
    IClasspathEntry[] entries = getClassPathEntries(javaProject);
    javaProject.setRawClasspath(entries, null);
}