List of usage examples for org.eclipse.jdt.core IJavaProject setOptions
void setOptions(Map<String, String> newOptions);
From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java
License:Open Source License
public static IPackageFragmentRoot addRTJar13(IJavaProject jproject) throws CoreException { IPath[] rtJarPath = findRtJar(RT_STUBS_13); Map options = jproject.getOptions(false); JavaProjectHelper.set13CompilerOptions(options); jproject.setOptions(options); return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]); }
From source file:org.eclipse.che.jdt.testplugin.TestOptions.java
License:Open Source License
public static void initializeProjectOptions(IJavaProject project) { Map options = new HashMap(); JavaProjectHelper.set15CompilerOptions(options); project.setOptions(options); }
From source file:org.eclipse.che.plugin.java.server.rest.CompilerSetupService.java
License:Open Source License
/** * Set java compiler preferences {@code changedParameters} for project by not empty path {@code projectpath}. If {@code projectpath} * is empty then java compiler preferences will be set for current workspace. * * @param projectPath project path/*from ww w . j a va 2 s . co m*/ * @param changedParameters java compiler preferences */ @POST @Path("/set") @Consumes(APPLICATION_JSON) public void setParameters(@QueryParam("projectpath") String projectPath, @NotNull Map<String, String> changedParameters) { if (projectPath == null || projectPath.isEmpty()) { JavaCore.setOptions(new Hashtable<>(changedParameters)); return; } IJavaProject project = JAVA_MODEL.getJavaProject(projectPath); project.setOptions(changedParameters); }
From source file:org.eclipse.imp.java.hosted.wizards.NewProjectWizardSecondPage.java
License:Open Source License
/** * Called from the wizard on finish.//www . j av a 2 s .c o m */ public void performFinish(IProgressMonitor monitor) throws CoreException, InterruptedException { try { //monitor.beginTask(NewWizardMessages.JavaProjectWizardSecondPage_operation_create, 3); // <= 3.3 //monitor.beginTask(NewWizardMessages.NewJavaProjectWizardPageTwo_operation_create, 3); // >= 3.4 monitor.beginTask("Creating project...", 3); if (fCurrProject == null) { updateProject(new SubProgressMonitor(monitor, 1)); } configureJavaProject(new SubProgressMonitor(monitor, 2)); String compliance = fFirstPage.getJRECompliance(); if (compliance != null) { IJavaProject project = JavaCore.create(fCurrProject); Map<String, String> options = project.getOptions(false); JavaCore.setComplianceOptions(compliance, options); project.setOptions(options); } } finally { monitor.done(); fCurrProject = null; if (fIsAutobuild != null) { enableAutoBuild(fIsAutobuild.booleanValue()); fIsAutobuild = null; } } }
From source file:org.eclipse.jst.common.project.facet.core.internal.JavaFacetUtil.java
License:Open Source License
public static void setCompilerLevel(final IProject project, final String level) throws CoreException { final IJavaProject jproj = JavaCore.create(project); final Map<String, String> options = jproj.getOptions(false); JavaCore.setComplianceOptions(level, options); jproj.setOptions(options); }
From source file:org.eclipse.m2m.internal.qvt.oml.ui.wizards.project.NewProjectCreationOperation.java
License:Open Source License
@SuppressWarnings("unchecked") private static void setComplianceOptions(IJavaProject project, String eeId, boolean overrideExisting) { Map<String, String> projectMap = project.getOptions(false); IExecutionEnvironment ee = null;//from www.ja v a 2 s . c om Map<String, String> options = null; if (eeId != null) { ee = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeId); if (ee != null) { options = ee.getComplianceOptions(); } } if (options == 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 { return; } } else { String compliance = options.get(JavaCore.COMPILER_COMPLIANCE); Iterator<?> iterator = options.entrySet().iterator(); while (iterator.hasNext()) { Entry<?, ?> entry = (Entry<?, ?>) iterator.next(); String option = (String) entry.getKey(); String value = (String) entry.getValue(); if (JavaCore.VERSION_1_3.equals(compliance) || JavaCore.VERSION_1_4.equals(compliance)) { if (JavaCore.COMPILER_PB_ASSERT_IDENTIFIER.equals(option) || JavaCore.COMPILER_PB_ENUM_IDENTIFIER.equals(option)) { // for 1.3 & 1.4 projects, only override the existing setting if the default setting // is a greater severity than the existing setting setMinimumCompliance(projectMap, option, value, overrideExisting); } else { setCompliance(projectMap, option, value, overrideExisting); } } else { setCompliance(projectMap, option, value, overrideExisting); } } } project.setOptions(projectMap); }
From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java
License:Open Source License
protected void setUpProjectCompliance(IJavaProject javaProject, String compliance) throws JavaModelException, IOException { // Look for version to set and return if that's already done String version = compliance; // assume that the values of CompilerOptions.VERSION_* are used if (version.equals(javaProject.getOption(CompilerOptions.OPTION_Compliance, false))) { return;//from w w w .jav a 2 s .c o m } String jclLibString; String newJclLibString; String newJclSrcString; if (compliance.charAt(2) > '4') { jclLibString = "JCL_LIB"; newJclLibString = "JCL15_LIB"; newJclSrcString = "JCL15_SRC"; } else { jclLibString = "JCL15_LIB"; newJclLibString = "JCL_LIB"; newJclSrcString = "JCL_SRC"; } // ensure variables are set setUpJCLClasspathVariables(compliance); // set options Map options = new HashMap(); options.put(CompilerOptions.OPTION_Compliance, version); options.put(CompilerOptions.OPTION_Source, version); options.put(CompilerOptions.OPTION_TargetPlatform, version); javaProject.setOptions(options); // replace JCL_LIB with JCL15_LIB, and JCL_SRC with JCL15_SRC IClasspathEntry[] classpath = javaProject.getRawClasspath(); IPath jclLib = new Path(jclLibString); for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getPath().equals(jclLib)) { classpath[i] = JavaCore.newVariableEntry(new Path(newJclLibString), new Path(newJclSrcString), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), new IClasspathAttribute[0], entry.isExported()); break; } } javaProject.setRawClasspath(classpath, null); }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
@SuppressWarnings("unchecked") // options in a raw map public void testLocalInRoFi() throws CoreException, InterruptedException { try {//w w w. j a v a 2 s. c o m // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); // set compliance to 1.6 to force generated of a stack map attribute. Map options = p.getOptions(true); options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); p.setOptions(options); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setNatureIds(OTDTPlugin.createProjectNatures(prjDesc)); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); OTREContainer.initializeOTJProject(project); this.createFile("/P/Plain.java", "public class Plain {\n" + " public Object getVal() {\n" + " return \"Plain\";\n" + " }\n" + "}\n"); String sourceTeam = "public team class Foo {\n" + " String foo, blub, bar, dings, wurgs, zork;\n" + " public static void main(String[] args) {\n" + " new Foo().new Role().test();\n" + " }\n" + "}\n"; this.createFile("/P/Foo.java", sourceTeam); this.createFolder("/P/Foo"); String sourceRole1 = "team package Foo;\n" + "@SuppressWarnings(\"unused\")\n" + "public class Role1 {\n" + " String s1, s2, s3, s4, s5, s6;\n" + "}\n"; this.createFile("/P/Foo/Role1.java", sourceRole1); String sourceRole2 = "team package Foo;\n" + "@SuppressWarnings(\"unused\")\n" + "public class Role2 extends Role1 {\n" + " protected void test() {\n" + " Plain isub = new Plain() {\n" + " public Object getVal() {\n" + " Object edits = super.getVal();\n" + " if (edits instanceof String) {\n" + " String string = (String)edits;\n" + " int l = string.length();\n" + " }\n" + " return edits;\n" + " }\n" + " };\n" + " Object v = isub.getVal();\n" + " }\n" + "}\n"; this.createFile("/P/Foo/Role2.java", sourceRole2); char[] sourceChars = sourceRole2.toCharArray(); this.problemRequestor.initialize(sourceChars); ICompilationUnit wc = getCompilationUnit("/P/Foo/Role2.java").getWorkingCopy(this.wcOwner, null); wc.reconcile(AST.JLS3, ICompilationUnit.FORCE_PROBLEM_DETECTION | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.ENABLE_BINDINGS_RECOVERY, wc.getOwner(), null); assertProblems("Unexpected problems", "----------\n" + "----------\n" + "----------\n" + "----------\n"); } finally { deleteProject("P"); } }
From source file:org.eclipse.objectteams.otdt.tests.otmodel.OTReconcilerTests.java
License:Open Source License
@SuppressWarnings("unchecked") // options in a raw map public void testRemoveRole() throws CoreException, InterruptedException, UnsupportedEncodingException { try {//from w ww . j av a 2s .com // Resources creation IJavaProject p = createOTJavaProject("P", new String[] { "" }, new String[] { "JCL15_LIB" }, "bin"); // set compliance to 1.6 to force generated of a stack map attribute. Map options = p.getOptions(true); options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); p.setOptions(options); IProject project = p.getProject(); IProjectDescription prjDesc = project.getDescription(); prjDesc.setNatureIds(OTDTPlugin.createProjectNatures(prjDesc)); prjDesc.setBuildSpec(OTDTPlugin.createProjectBuildCommands(prjDesc)); project.setDescription(prjDesc, null); OTREContainer.initializeOTJProject(project); String sourceTeam = "public team class Foo {\n" + " public class Role1 {\n" + " String s1, s2, s3, s4, s5, s6;\n" + " }\n" + " String foo, blub, bar, dings, wurgs, zork;\n" + " public static void main(String[] args) {\n" + " new Foo().new Role1().test();\n" + " }\n" + "}\n"; this.createFile("/P/Foo.java", sourceTeam); this.problemRequestor.initialize(sourceTeam.toCharArray()); ICompilationUnit wc = getCompilationUnit("/P/Foo.java").getWorkingCopy(this.wcOwner, null); IType itype = wc.getType("Foo"); IOTType ottype = OTModelManager.getOTElement(itype); IType rt = ottype.getRoleType("Role1"); IOTType roleType = OTModelManager.getOTElement(rt); // this caches the role type assertTrue("Role should initially exist", rt.exists()); assertTrue("RoleType should initially exist", roleType.exists()); // delete Role1 wc.applyTextEdit(new DeleteEdit(("public team class Foo {\n").length(), (" public class Role1 {\n" + " String s1, s2, s3, s4, s5, s6;\n" + " }\n").length()), null); wc.reconcile(AST.JLS3, ICompilationUnit.FORCE_PROBLEM_DETECTION | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.ENABLE_BINDINGS_RECOVERY, wc.getOwner(), null); // watch that // ... the JavaElement no longer exists: rt = itype.getType("Role1"); assertFalse("Role should no longer exist", rt.exists()); // ... and OTModel no longer has a RoleType: ottype = OTModelManager.getOTElement(itype); rt = ottype.getRoleType("Role1"); assertNull("Role should be null", rt); } finally { deleteProject("P"); } }
From source file:org.eclipse.pde.api.tools.builder.tests.ApiTestingEnvironment.java
License:Open Source License
/** * Sets the given compliance on the given project. * /* w ww . ja va2 s .co m*/ * @param project * @param compliance */ public void setProjectCompliance(IJavaProject project, String compliance) { int requiredComplianceFlag = 0; String compilerVersion = null; if (JavaCore.VERSION_1_4.equals(compliance)) { requiredComplianceFlag = AbstractCompilerTest.F_1_4; compilerVersion = JavaCore.VERSION_1_4; } else if (JavaCore.VERSION_1_5.equals(compliance)) { requiredComplianceFlag = AbstractCompilerTest.F_1_5; compilerVersion = JavaCore.VERSION_1_5; } else if (JavaCore.VERSION_1_6.equals(compliance)) { requiredComplianceFlag = AbstractCompilerTest.F_1_6; compilerVersion = JavaCore.VERSION_1_6; } else if (JavaCore.VERSION_1_7.equals(compliance)) { requiredComplianceFlag = AbstractCompilerTest.F_1_7; compilerVersion = JavaCore.VERSION_1_7; } else if (JavaCore.VERSION_1_8.equals(compliance)) { requiredComplianceFlag = AbstractCompilerTest.F_1_8; compilerVersion = JavaCore.VERSION_1_8; } else if (!JavaCore.VERSION_1_4.equals(compliance) && !JavaCore.VERSION_1_3.equals(compliance)) { throw new UnsupportedOperationException( "Test framework doesn't support compliance level: " + compliance); //$NON-NLS-1$ } if (requiredComplianceFlag != 0) { if ((AbstractCompilerTest.getPossibleComplianceLevels() & requiredComplianceFlag) == 0) { throw new RuntimeException("This test requires a " + compliance + " JRE"); //$NON-NLS-1$ //$NON-NLS-2$ } HashMap<String, String> options = new HashMap<String, String>(); options.put(JavaCore.COMPILER_COMPLIANCE, compilerVersion); options.put(JavaCore.COMPILER_SOURCE, compilerVersion); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, compilerVersion); project.setOptions(options); } }