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

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

Introduction

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

Prototype

void setOptions(Map<String, String> newOptions);

Source Link

Document

Sets the project custom options.

Usage

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

License:Open Source License

/**
 * Sets the compiler options to 1.4 for the given project.
 * @param project the java project/*from www.j a v a 2s  .  c om*/
 */
@SuppressWarnings("unchecked")
public static void set14CompilerOptions(IJavaProject project) {
    Map<String, String> options = project.getOptions(false);
    JavaProjectHelper.set14CompilerOptions(options);
    project.setOptions(options);
}

From source file:org.hyperic.hypclipse.internal.ClasspathComputer.java

License:Open Source License

@SuppressWarnings("unchecked")
public static void setComplianceOptions(IJavaProject project, String compliance, boolean overrideExisting) {
    Map<String, String> projectMap = project.getOptions(false);
    if (compliance == null) {
        if (overrideExisting && projectMap.size() > 0) {
            projectMap.remove(JavaCore.COMPILER_COMPLIANCE);
            projectMap.remove(JavaCore.COMPILER_SOURCE);
            projectMap.remove(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
            projectMap.remove(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER);
            projectMap.remove(JavaCore.COMPILER_PB_ENUM_IDENTIFIER);
        } else {//from ww  w .ja v a 2  s .  c  o m
            return;
        }
    } else if (JavaCore.VERSION_1_6.equals(compliance)) {
        setCompliance(projectMap, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6,
                overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR, overrideExisting);
    } else if (JavaCore.VERSION_1_5.equals(compliance)) {
        setCompliance(projectMap, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5,
                overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR, overrideExisting);
    } else if (JavaCore.VERSION_1_4.equals(compliance)) {
        setCompliance(projectMap, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2,
                overrideExisting);
        setMinimumCompliance(projectMap, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING,
                overrideExisting);
        setMinimumCompliance(projectMap, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING,
                overrideExisting);
    } else if (JavaCore.VERSION_1_3.equals(compliance)) {
        setCompliance(projectMap, JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_3, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3, overrideExisting);
        setCompliance(projectMap, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1,
                overrideExisting);
        setMinimumCompliance(projectMap, JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE,
                overrideExisting);
        setMinimumCompliance(projectMap, JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE,
                overrideExisting);
    }
    project.setOptions(projectMap);

}

From source file:org.mybatis.generator.eclipse.core.tests.callback.WorkspaceUtilities.java

License:Apache License

static IJavaProject createJavaProject(final String projectName, final String[] sourceFolders,
        final String projectOutput, final String compliance) throws CoreException {

    final IJavaProject[] result = new IJavaProject[1];
    IWorkspaceRunnable create = new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            // create project
            createProject(projectName);//from  ww w  . ja  va 2 s .co m

            // set java nature
            addJavaNature(projectName);

            // create classpath entries
            IProject project = getWorkspaceRoot().getProject(projectName);
            IPath projectPath = project.getFullPath();
            int sourceLength = sourceFolders == null ? 0 : sourceFolders.length;
            IClasspathEntry[] entries = new IClasspathEntry[sourceLength];
            for (int i = 0; i < sourceLength; i++) {
                IPath sourcePath = new Path(sourceFolders[i]);
                int segmentCount = sourcePath.segmentCount();
                if (segmentCount > 0) {
                    // create folder and its parents
                    IContainer container = project;
                    for (int j = 0; j < segmentCount; j++) {
                        IFolder folder = container.getFolder(new Path(sourcePath.segment(j)));
                        if (!folder.exists()) {
                            folder.create(true, true, null);
                        }
                        container = folder;
                    }
                }
                // create source entry
                entries[i] = JavaCore.newSourceEntry(projectPath.append(sourcePath));
            }

            // create project's output folder
            IPath outputPath = new Path(projectOutput);
            if (outputPath.segmentCount() > 0) {
                IFolder output = project.getFolder(outputPath);
                if (!output.exists()) {
                    output.create(true, true, monitor);
                }
            }

            // set classpath and output location
            IJavaProject javaProject = JavaCore.create(project);
            javaProject.setRawClasspath(entries, projectPath.append(outputPath), monitor);

            // set compliance level options
            if ("1.5".equals(compliance)) {
                Map<String, String> options = new HashMap<String, String>();
                options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
                options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
                options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
                javaProject.setOptions(options);
            } else if ("1.6".equals(compliance)) {
                Map<String, String> options = new HashMap<String, String>();
                options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
                options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
                options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
                javaProject.setOptions(options);
            } else if ("1.7".equals(compliance)) {
                Map<String, String> options = new HashMap<String, String>();
                options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
                options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
                options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
                javaProject.setOptions(options);
            } else if ("1.8".equals(compliance)) {
                Map<String, String> options = new HashMap<String, String>();
                options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
                options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
                options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
                javaProject.setOptions(options);
            }

            result[0] = javaProject;
        }
    };
    getWorkspace().run(create, null);
    return result[0];
}

From source file:repast.simphony.relogo.ide.wizards.NetlogoWizardPageTwo.java

License:Open Source License

/**
 * Called from the wizard on finish.//from w  w  w.  j  ava  2  s .  com
 * 
 * @param monitor the progress monitor
 * @throws CoreException thrown when the project creation or configuration failed
 * @throws InterruptedException thrown when the user cancelled the project creation
 */
public void performFinish(IProgressMonitor monitor) throws CoreException, InterruptedException {
    SubMonitor subMonitor = SubMonitor.convert(monitor, 3);
    subMonitor.subTask(NewWizardMessages.NewJavaProjectWizardPageTwo_operation_create);
    try {

        if (fCurrProject == null) {
            updateProject(subMonitor.newChild(1));
        }

        if (!fKeepContent) {
            String compliance = fFirstPage.getCompilerCompliance();
            if (compliance != null) {
                IJavaProject project = JavaCore.create(fCurrProject);
                Map options = project.getOptions(false);
                JavaModelUtil.setComplianceOptions(options, compliance);
                JavaModelUtil.setDefaultClassfileOptions(options, compliance); // complete compliance options
                project.setOptions(options);
            }
        } else {
        }
    } finally {
        subMonitor.worked(2);
        fCurrProject = null;
        if (fIsAutobuild != null) {
            //            CoreUtility.enableAutoBuild(fIsAutobuild.booleanValue());
            fIsAutobuild = null;
        }
    }
}