1616package com .diffplug .gradle .oomph ;
1717
1818import java .util .HashSet ;
19+ import java .util .LinkedHashMap ;
20+ import java .util .List ;
21+ import java .util .Map ;
1922import java .util .Set ;
2023
2124import org .gradle .api .Action ;
25+ import org .gradle .api .JavaVersion ;
26+
27+ import com .diffplug .common .collect .ImmutableList ;
2228
2329/**
2430 * Adding the JDT convention to your project
3339 * ```gradle
3440 * oomphIde {
3541 * jdt {
42+ *
3643 * installedJre {
3744 * version = '1.6.0_45'
3845 * installedLocation = new File('C:/jdk1.6.0_45')
3946 * markDefault = true // or false
4047 * executionEnvironments = ['JavaSE-1.6'] // any execution environments can be specified here.
4148 * }
49+ * compilerComplianceLevel('1.6')
50+ * classpathVariable('myClasspath', '/var/lib/repo')
4251 * }
4352 * }
4453 * ```
4554 */
4655public class ConventionJdt extends OomphConvention {
56+ final static String JDT_CORE_PREFS = ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" ;
57+
4758 ConventionJdt (OomphIdeExtension extension ) {
4859 super (extension );
4960 requireIUs (IUs .IDE , IUs .JDT , IUs .ERROR_LOG );
@@ -59,6 +70,29 @@ public void installedJre(Action<InstalledJre> action) {
5970 installedJres .add (instance );
6071 }
6172
73+ /** Sets default compliance level */
74+ public void compilerComplianceLevel (String compilerComplianceLevel ) {
75+ List <String > JDT_COMPLIANCE_PROPS = ImmutableList .of (
76+ "org.eclipse.jdt.core.compiler.codegen.targetPlatform" ,
77+ "org.eclipse.jdt.core.compiler.compliance" ,
78+ "org.eclipse.jdt.core.compiler.source" );
79+ extension .workspaceProp (JDT_CORE_PREFS , props -> {
80+ JDT_COMPLIANCE_PROPS .forEach (p -> props .put (p , compilerComplianceLevel .toString ()));
81+ //Use default compliance settings.
82+ props .put ("org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" , "enabled" );
83+ props .put ("org.eclipse.jdt.core.compiler.problem.assertIdentifier" , "error" );
84+ props .put ("org.eclipse.jdt.core.compiler.problem.enumIdentifier" , "error" );
85+ });
86+ }
87+
88+ /** Adds a compiler class path variable. */
89+ public void classpathVariable (String name , String value ) {
90+ String JDT_CLASSPATH_VAR_FMT = "org.eclipse.jdt.core.classpathVariable.%s" ;
91+ extension .workspaceProp (JDT_CORE_PREFS , props -> {
92+ props .put (String .format (JDT_CLASSPATH_VAR_FMT , name ), value );
93+ });
94+ }
95+
6296 @ Override
6397 public void close () {
6498 // add installed jres
0 commit comments