16
16
package com .diffplug .gradle .oomph ;
17
17
18
18
import java .util .HashSet ;
19
+ import java .util .LinkedHashMap ;
20
+ import java .util .List ;
21
+ import java .util .Map ;
19
22
import java .util .Set ;
20
23
21
24
import org .gradle .api .Action ;
25
+ import org .gradle .api .JavaVersion ;
26
+
27
+ import com .diffplug .common .collect .ImmutableList ;
22
28
23
29
/**
24
30
* Adding the JDT convention to your project
33
39
* ```gradle
34
40
* oomphIde {
35
41
* jdt {
42
+ *
36
43
* installedJre {
37
44
* version = '1.6.0_45'
38
45
* installedLocation = new File('C:/jdk1.6.0_45')
39
46
* markDefault = true // or false
40
47
* executionEnvironments = ['JavaSE-1.6'] // any execution environments can be specified here.
41
48
* }
49
+ * compilerComplianceLevel('1.6')
50
+ * classpathVariable('myClasspath', '/var/lib/repo')
42
51
* }
43
52
* }
44
53
* ```
45
54
*/
46
55
public class ConventionJdt extends OomphConvention {
56
+ final static String JDT_CORE_PREFS = ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" ;
57
+
47
58
ConventionJdt (OomphIdeExtension extension ) {
48
59
super (extension );
49
60
requireIUs (IUs .IDE , IUs .JDT , IUs .ERROR_LOG );
@@ -59,6 +70,29 @@ public void installedJre(Action<InstalledJre> action) {
59
70
installedJres .add (instance );
60
71
}
61
72
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
+
62
96
@ Override
63
97
public void close () {
64
98
// add installed jres
0 commit comments