Skip to content

Commit 3f23d04

Browse files
authored
Merge pull request #23 from scottresnik/jdt-enhancements
Jdt enhancements
2 parents 98c7a29 + 503cde4 commit 3f23d04

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java

+34
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616
package com.diffplug.gradle.oomph;
1717

1818
import java.util.HashSet;
19+
import java.util.LinkedHashMap;
20+
import java.util.List;
21+
import java.util.Map;
1922
import java.util.Set;
2023

2124
import 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
@@ -33,17 +39,22 @@
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
*/
4655
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+
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

src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java

+10
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ public void addSetupActionLazy(Action<List<SetupAction>> lazyInternalSetupAction
213213
setupActions.addLazyAction(lazyInternalSetupAction);
214214
}
215215

216+
/** Links the given target into the workspace with the given name, see [eclipse manual](http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fconcepts-13.htm). */
217+
public void linkedResource(String linkName, Object linkTarget) {
218+
final String CORE_RES_PREFS_FILE = ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs";
219+
final String WS_PATHVAR_FMT = "pathvariable.%s";
220+
workspaceProp(CORE_RES_PREFS_FILE, props -> {
221+
//Eclipse cannot handle backslashes in this value. It expects path separators to be '/'
222+
props.put(String.format(WS_PATHVAR_FMT, linkName), project.file(linkTarget).getAbsolutePath().replace("\\", "/"));
223+
});
224+
}
225+
216226
////////////////
217227
// ideSetupP2 //
218228
////////////////

0 commit comments

Comments
 (0)