Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jdt enhancements #23

Merged
merged 6 commits into from
Dec 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
package com.diffplug.gradle.oomph;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.gradle.api.Action;
import org.gradle.api.JavaVersion;

import com.diffplug.common.collect.ImmutableList;

/**
* Adding the JDT convention to your project
Expand All @@ -33,17 +39,22 @@
* ```gradle
* oomphIde {
* jdt {
*
* installedJre {
* version = '1.6.0_45'
* installedLocation = new File('C:/jdk1.6.0_45')
* markDefault = true // or false
* executionEnvironments = ['JavaSE-1.6'] // any execution environments can be specified here.
* }
* compilerComplianceLevel('1.6')
* classpathVariable('myClasspath', '/var/lib/repo')
* }
* }
* ```
*/
public class ConventionJdt extends OomphConvention {
final static String JDT_CORE_PREFS = ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs";

ConventionJdt(OomphIdeExtension extension) {
super(extension);
requireIUs(IUs.IDE, IUs.JDT, IUs.ERROR_LOG);
Expand All @@ -59,6 +70,29 @@ public void installedJre(Action<InstalledJre> action) {
installedJres.add(instance);
}

/** Sets default compliance level */
public void compilerComplianceLevel(String compilerComplianceLevel) {
List<String> JDT_COMPLIANCE_PROPS = ImmutableList.of(
"org.eclipse.jdt.core.compiler.codegen.targetPlatform",
"org.eclipse.jdt.core.compiler.compliance",
"org.eclipse.jdt.core.compiler.source");
extension.workspaceProp(JDT_CORE_PREFS, props -> {
JDT_COMPLIANCE_PROPS.forEach(p -> props.put(p, compilerComplianceLevel.toString()));
//Use default compliance settings.
props.put("org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode", "enabled");
props.put("org.eclipse.jdt.core.compiler.problem.assertIdentifier", "error");
props.put("org.eclipse.jdt.core.compiler.problem.enumIdentifier", "error");
});
}

/** Adds a compiler class path variable. */
public void classpathVariable(String name, String value) {
String JDT_CLASSPATH_VAR_FMT = "org.eclipse.jdt.core.classpathVariable.%s";
extension.workspaceProp(JDT_CORE_PREFS, props -> {
props.put(String.format(JDT_CLASSPATH_VAR_FMT, name), value);
});
}

@Override
public void close() {
// add installed jres
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ public void addSetupActionLazy(Action<List<SetupAction>> lazyInternalSetupAction
setupActions.addLazyAction(lazyInternalSetupAction);
}

/** 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). */
public void linkedResource(String linkName, Object linkTarget) {
final String CORE_RES_PREFS_FILE = ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.resources.prefs";
final String WS_PATHVAR_FMT = "pathvariable.%s";
workspaceProp(CORE_RES_PREFS_FILE, props -> {
//Eclipse cannot handle backslashes in this value. It expects path separators to be '/'
props.put(String.format(WS_PATHVAR_FMT, linkName), project.file(linkTarget).getAbsolutePath().replace("\\", "/"));
});
}

////////////////
// ideSetupP2 //
////////////////
Expand Down