From 52125340343d8e01f112821e0973caf7371d3df8 Mon Sep 17 00:00:00 2001 From: Scott Resnik Date: Wed, 23 Nov 2016 10:50:00 -0600 Subject: [PATCH 1/6] Added setup task to add installed jre/jdk's to the Eclipse workspace --- build.gradle | 2 + .../diffplug/gradle/oomph/ConventionJdt.java | 9 ++ .../diffplug/gradle/oomph/InstalledJre.java | 77 +++++++++++++++ .../com/diffplug/gradle/oomph/JreAdder.java | 52 ++++++++++ .../gradle/oomph/JreAdderInternal.java | 97 +++++++++++++++++++ .../gradle/oomph/OomphIdeExtension.java | 6 ++ 6 files changed, 243 insertions(+) create mode 100644 src/main/java/com/diffplug/gradle/oomph/InstalledJre.java create mode 100644 src/main/java/com/diffplug/gradle/oomph/JreAdder.java create mode 100644 src/main/java/com/diffplug/gradle/oomph/JreAdderInternal.java diff --git a/build.gradle b/build.gradle index 52bf371c6..7e126e437 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,8 @@ dependencies { compileOnly 'p2:org.eclipse.equinox.common:3.7.0.v20150402-1709' compileOnly 'p2:org.eclipse.ui.workbench:3.107.1.v20160120-2131' compileOnly 'p2:org.eclipse.pde.core:3.10.102.v20160128-0556' + compileOnly 'p2:org.eclipse.jdt.launching:3.8.0.v20150527-0946' + compileOnly 'p2:org.eclipse.emf.ecore:2.11.2.v20160208-0816' // testing testCompile "junit:junit:${VER_JUNIT}" } diff --git a/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java b/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java index 0ff6352a6..a6f56a6c2 100644 --- a/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java +++ b/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java @@ -15,10 +15,19 @@ */ package com.diffplug.gradle.oomph; +import org.gradle.api.Action; + public class ConventionJdt extends OomphConvention { ConventionJdt(OomphIdeExtension extension) { super(extension); requireIUs(IUs.IDE, IUs.JDT, IUs.ERROR_LOG); setPerspectiveOver(Perspectives.JAVA, Perspectives.RESOURCES); } + + /** Adds an installed JRE with the given content. */ + void installedJre(Action action) { + InstalledJre instance = new InstalledJre(); + action.execute(instance); + extension.installedJres.add(instance); + } } diff --git a/src/main/java/com/diffplug/gradle/oomph/InstalledJre.java b/src/main/java/com/diffplug/gradle/oomph/InstalledJre.java new file mode 100644 index 000000000..3babbbeb9 --- /dev/null +++ b/src/main/java/com/diffplug/gradle/oomph/InstalledJre.java @@ -0,0 +1,77 @@ +/* + * Copyright 2016 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.oomph; + +import java.io.File; +import java.io.Serializable; +import java.util.List; + +/** + * Simple representation of a JRE + */ +public class InstalledJre + implements Serializable { + + private static final long serialVersionUID = 8530657374964977698L; + + private String version; + private File installedLocation; + private boolean markDefault; + private List executionEnvironments; + + /** + * + */ + public InstalledJre() {} + + protected InstalledJre(String name, File location) { + super(); + this.version = name; + this.installedLocation = location; + } + + public String getVersion() { + return version; + } + + public void setVersion(String name) { + this.version = name; + } + + public File getInstalledLocation() { + return installedLocation; + } + + public void setInstalledLocation(File location) { + this.installedLocation = location; + } + + public boolean isMarkDefault() { + return markDefault; + } + + public void setMarkDefault(boolean markDefault) { + this.markDefault = markDefault; + } + + public List getExecutionEnvironments() { + return executionEnvironments; + } + + public void setExecutionEnvironments(List executionEnvironments) { + this.executionEnvironments = executionEnvironments; + } +} diff --git a/src/main/java/com/diffplug/gradle/oomph/JreAdder.java b/src/main/java/com/diffplug/gradle/oomph/JreAdder.java new file mode 100644 index 000000000..a2c858b1d --- /dev/null +++ b/src/main/java/com/diffplug/gradle/oomph/JreAdder.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.oomph; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.diffplug.gradle.OrderingConstraints; + +/** + * Used for adding JRE/JDK installations to an Eclipse install + */ +public class JreAdder + extends SetupAction { + + private static final long serialVersionUID = -7101059764345094433L; + + List installedJres; + + protected JreAdder(Collection jresToAdd) { + super("com.diffplug.gradle.oomph.JreAdderInternal"); + installedJres = new ArrayList<>(jresToAdd); + } + + @Override + protected void populateOrdering(OrderingConstraints> ordering) { + // we must add installed jre(s) before importing projects + ordering.before(ProjectImporter.class); + } + + /** + * @see com.diffplug.gradle.oomph.SetupAction#getDescription() + */ + @Override + public String getDescription() { + return "adding installed JRE's"; + } +} diff --git a/src/main/java/com/diffplug/gradle/oomph/JreAdderInternal.java b/src/main/java/com/diffplug/gradle/oomph/JreAdderInternal.java new file mode 100644 index 000000000..3e533fe96 --- /dev/null +++ b/src/main/java/com/diffplug/gradle/oomph/JreAdderInternal.java @@ -0,0 +1,97 @@ +/* + * Copyright 2016 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.oomph; + +import java.io.File; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jdt.launching.IVMInstall; +import org.eclipse.jdt.launching.IVMInstallType; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jdt.launching.VMStandin; +import org.eclipse.jdt.launching.environments.IExecutionEnvironment; + +import com.diffplug.gradle.oomph.SetupAction.Internal; + +public class JreAdderInternal extends Internal { + + JreAdderInternal(JreAdder host) { + super(host); + } + + @Override + protected void runWithinEclipse() throws Throwable { + IVMInstallType[] types = JavaRuntime.getVMInstallTypes(); + for (IVMInstallType type : types) { + if ("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType".equals(type.getId())) { + for (InstalledJre jreToAdd : host.installedJres) { + if (isNeeded(jreToAdd.getVersion(), jreToAdd.getInstalledLocation())) { + IVMInstall realVM = addInstalledJre(type, jreToAdd); + if (jreToAdd.isMarkDefault()) { + JavaRuntime.setDefaultVMInstall(realVM, new NullProgressMonitor()); + } + linkWithExecutionEnvironments(realVM, jreToAdd); + } + } + } + } + } + + protected IVMInstall addInstalledJre(IVMInstallType type, InstalledJre jreToAdd) throws CoreException { + IStatus validationStatus = type.validateInstallLocation(jreToAdd.getInstalledLocation()); + if (!validationStatus.isOK()) { + throw new CoreException(validationStatus); + } + VMStandin vmStandin = new VMStandin(type, EcoreUtil.generateUUID()); + vmStandin.setInstallLocation(jreToAdd.getInstalledLocation()); + vmStandin.setName("JRE for " + jreToAdd.getVersion()); + IVMInstall realVM = vmStandin.convertToRealVM(); + return realVM; + } + + protected void linkWithExecutionEnvironments(IVMInstall installedVm, InstalledJre jreToAdd) { + if (jreToAdd.getExecutionEnvironments().isEmpty()) { + return; + } else { + Set execEnvsToAdd = new HashSet<>(jreToAdd.getExecutionEnvironments()); + IExecutionEnvironment[] executionEnvironments = JavaRuntime.getExecutionEnvironmentsManager() + .getExecutionEnvironments(); + for (IExecutionEnvironment iExecutionEnvironment : executionEnvironments) { + if (execEnvsToAdd.contains(iExecutionEnvironment.getId())) { + iExecutionEnvironment.setDefaultVM(installedVm); + } + } + } + } + + private boolean isNeeded(String version, File location) throws Exception { + for (IVMInstallType vmInstallType : JavaRuntime.getVMInstallTypes()) { + for (IVMInstall vmInstall : vmInstallType.getVMInstalls()) { + File installLocation = vmInstall.getInstallLocation(); + if (location.equals(installLocation)) { + return false; + } + } + } + + return true; + } +} diff --git a/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java b/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java index 2f9d66da9..e91a10669 100644 --- a/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java +++ b/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java @@ -20,10 +20,12 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.function.Supplier; @@ -65,6 +67,7 @@ public class OomphIdeExtension implements P2Declarative { final Project project; final WorkspaceRegistry workspaceRegistry; final SortedSet projectFiles = new TreeSet<>(); + final Set installedJres = new HashSet<>(); final Map> workspaceToContent = new HashMap<>(); final P2Model p2 = new P2Model(); final Lazyable> setupActions = Lazyable.ofList(); @@ -344,6 +347,9 @@ void ideSetupWorkspace() throws Exception { private void internalSetup(File ideDir) throws IOException { // get the user setup actions List list = setupActions.getResult(); + // add installed jres + if (!installedJres.isEmpty()) + list.add(new JreAdder(installedJres)); // add the project importer list.add(new ProjectImporter(projectFiles)); // order the actions From 7a8898f20ee0ff03422b313509ee2b81e9e8ccd4 Mon Sep 17 00:00:00 2001 From: Scott Resnik Date: Wed, 23 Nov 2016 11:51:23 -0600 Subject: [PATCH 2/6] Renamed setup action to be clearer. --- .../gradle/oomph/{JreAdder.java => InstalledJreAdder.java} | 4 ++-- .../{JreAdderInternal.java => InstalledJreAdderInternal.java} | 4 ++-- .../java/com/diffplug/gradle/oomph/OomphIdeExtension.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/main/java/com/diffplug/gradle/oomph/{JreAdder.java => InstalledJreAdder.java} (93%) rename src/main/java/com/diffplug/gradle/oomph/{JreAdderInternal.java => InstalledJreAdderInternal.java} (96%) diff --git a/src/main/java/com/diffplug/gradle/oomph/JreAdder.java b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java similarity index 93% rename from src/main/java/com/diffplug/gradle/oomph/JreAdder.java rename to src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java index a2c858b1d..f59c91019 100644 --- a/src/main/java/com/diffplug/gradle/oomph/JreAdder.java +++ b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java @@ -24,14 +24,14 @@ /** * Used for adding JRE/JDK installations to an Eclipse install */ -public class JreAdder +public class InstalledJreAdder extends SetupAction { private static final long serialVersionUID = -7101059764345094433L; List installedJres; - protected JreAdder(Collection jresToAdd) { + protected InstalledJreAdder(Collection jresToAdd) { super("com.diffplug.gradle.oomph.JreAdderInternal"); installedJres = new ArrayList<>(jresToAdd); } diff --git a/src/main/java/com/diffplug/gradle/oomph/JreAdderInternal.java b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdderInternal.java similarity index 96% rename from src/main/java/com/diffplug/gradle/oomph/JreAdderInternal.java rename to src/main/java/com/diffplug/gradle/oomph/InstalledJreAdderInternal.java index 3e533fe96..8f111559e 100644 --- a/src/main/java/com/diffplug/gradle/oomph/JreAdderInternal.java +++ b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdderInternal.java @@ -31,9 +31,9 @@ import com.diffplug.gradle.oomph.SetupAction.Internal; -public class JreAdderInternal extends Internal { +public class InstalledJreAdderInternal extends Internal { - JreAdderInternal(JreAdder host) { + InstalledJreAdderInternal(InstalledJreAdder host) { super(host); } diff --git a/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java b/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java index e91a10669..6ed2b2048 100644 --- a/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java +++ b/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java @@ -349,7 +349,7 @@ private void internalSetup(File ideDir) throws IOException { List list = setupActions.getResult(); // add installed jres if (!installedJres.isEmpty()) - list.add(new JreAdder(installedJres)); + list.add(new InstalledJreAdder(installedJres)); // add the project importer list.add(new ProjectImporter(projectFiles)); // order the actions From f78cf7a8144892130e4aed447e1e31423a075cf1 Mon Sep 17 00:00:00 2001 From: Scott Resnik Date: Wed, 23 Nov 2016 20:33:50 -0600 Subject: [PATCH 3/6] Fix for default JDK, and action rename. Updated docs. --- README.md | 10 ++++- .../gradle/oomph/InstalledJreAdder.java | 2 +- .../oomph/InstalledJreAdderInternal.java | 38 ++++++++++--------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 73d560316..dde36f390 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,15 @@ When you run `gradlew ide`, it builds and downloads an IDE into `build/oomphIde` apply plugin: 'com.diffplug.gradle.oomph.ide' oomphIde { repoEclipseLatest() - jdt {} + jdt { + //Some *optional* older (or newer) JRE/JDK + installedJre({ jre -> + jre.version = '1.6.0_45' + jre.installedLocation = new File('C:/jdk1.6.0_45') + jre.markDefault = true // or false + jre.executionEnvironments = ['JavaSE-1.6'] //any or as many execution environments can be specified here. + }) + } eclipseIni { vmargs('-Xmx2g') // IDE can have up to 2 gigs of RAM } diff --git a/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java index f59c91019..695f5e038 100644 --- a/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java +++ b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java @@ -32,7 +32,7 @@ public class InstalledJreAdder List installedJres; protected InstalledJreAdder(Collection jresToAdd) { - super("com.diffplug.gradle.oomph.JreAdderInternal"); + super("com.diffplug.gradle.oomph.InstalledJreAdderInternal"); installedJres = new ArrayList<>(jresToAdd); } diff --git a/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdderInternal.java b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdderInternal.java index 8f111559e..8d2b1f2e6 100644 --- a/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdderInternal.java +++ b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdderInternal.java @@ -43,28 +43,30 @@ protected void runWithinEclipse() throws Throwable { for (IVMInstallType type : types) { if ("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType".equals(type.getId())) { for (InstalledJre jreToAdd : host.installedJres) { - if (isNeeded(jreToAdd.getVersion(), jreToAdd.getInstalledLocation())) { - IVMInstall realVM = addInstalledJre(type, jreToAdd); - if (jreToAdd.isMarkDefault()) { - JavaRuntime.setDefaultVMInstall(realVM, new NullProgressMonitor()); - } - linkWithExecutionEnvironments(realVM, jreToAdd); + IVMInstall realVM = addInstalledJre(type, jreToAdd); + if (jreToAdd.isMarkDefault()) { + JavaRuntime.setDefaultVMInstall(realVM, new NullProgressMonitor()); } + linkWithExecutionEnvironments(realVM, jreToAdd); } } } } - protected IVMInstall addInstalledJre(IVMInstallType type, InstalledJre jreToAdd) throws CoreException { - IStatus validationStatus = type.validateInstallLocation(jreToAdd.getInstalledLocation()); - if (!validationStatus.isOK()) { - throw new CoreException(validationStatus); + protected IVMInstall addInstalledJre(IVMInstallType type, InstalledJre jreToAdd) throws Exception { + IVMInstall retVal = findJre(jreToAdd.getVersion(), jreToAdd.getInstalledLocation()); + if (retVal == null) { + IStatus validationStatus = type.validateInstallLocation(jreToAdd.getInstalledLocation()); + if (!validationStatus.isOK()) { + throw new CoreException(validationStatus); + } + VMStandin vmStandin = new VMStandin(type, EcoreUtil.generateUUID()); + vmStandin.setInstallLocation(jreToAdd.getInstalledLocation()); + vmStandin.setName("JRE for " + jreToAdd.getVersion()); + IVMInstall realVM = vmStandin.convertToRealVM(); + retVal = realVM; } - VMStandin vmStandin = new VMStandin(type, EcoreUtil.generateUUID()); - vmStandin.setInstallLocation(jreToAdd.getInstalledLocation()); - vmStandin.setName("JRE for " + jreToAdd.getVersion()); - IVMInstall realVM = vmStandin.convertToRealVM(); - return realVM; + return retVal; } protected void linkWithExecutionEnvironments(IVMInstall installedVm, InstalledJre jreToAdd) { @@ -82,16 +84,16 @@ protected void linkWithExecutionEnvironments(IVMInstall installedVm, InstalledJr } } - private boolean isNeeded(String version, File location) throws Exception { + private IVMInstall findJre(String version, File location) throws Exception { for (IVMInstallType vmInstallType : JavaRuntime.getVMInstallTypes()) { for (IVMInstall vmInstall : vmInstallType.getVMInstalls()) { File installLocation = vmInstall.getInstallLocation(); if (location.equals(installLocation)) { - return false; + return vmInstall; } } } - return true; + return null; } } From d620c475787a6fb83ba70ee5f9cb228e05c9caf8 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Wed, 23 Nov 2016 22:23:03 -0800 Subject: [PATCH 4/6] Minor formatting tweaks. --- .../diffplug/gradle/oomph/InstalledJre.java | 139 ++++++++---------- .../gradle/oomph/InstalledJreAdder.java | 10 +- .../gradle/oomph/OomphIdeExtension.java | 3 +- 3 files changed, 67 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/diffplug/gradle/oomph/InstalledJre.java b/src/main/java/com/diffplug/gradle/oomph/InstalledJre.java index 3babbbeb9..5b54b8fef 100644 --- a/src/main/java/com/diffplug/gradle/oomph/InstalledJre.java +++ b/src/main/java/com/diffplug/gradle/oomph/InstalledJre.java @@ -1,77 +1,62 @@ -/* - * Copyright 2016 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.gradle.oomph; - -import java.io.File; -import java.io.Serializable; -import java.util.List; - -/** - * Simple representation of a JRE - */ -public class InstalledJre - implements Serializable { - - private static final long serialVersionUID = 8530657374964977698L; - - private String version; - private File installedLocation; - private boolean markDefault; - private List executionEnvironments; - - /** - * - */ - public InstalledJre() {} - - protected InstalledJre(String name, File location) { - super(); - this.version = name; - this.installedLocation = location; - } - - public String getVersion() { - return version; - } - - public void setVersion(String name) { - this.version = name; - } - - public File getInstalledLocation() { - return installedLocation; - } - - public void setInstalledLocation(File location) { - this.installedLocation = location; - } - - public boolean isMarkDefault() { - return markDefault; - } - - public void setMarkDefault(boolean markDefault) { - this.markDefault = markDefault; - } - - public List getExecutionEnvironments() { - return executionEnvironments; - } - - public void setExecutionEnvironments(List executionEnvironments) { - this.executionEnvironments = executionEnvironments; - } -} +/* + * Copyright 2016 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.oomph; + +import java.io.File; +import java.io.Serializable; +import java.util.List; + +/** Simple representation of a JRE */ +public class InstalledJre implements Serializable { + private static final long serialVersionUID = 8530657374964977698L; + + private String version; + private File installedLocation; + private boolean markDefault; + private List executionEnvironments; + + public String getVersion() { + return version; + } + + public void setVersion(String name) { + this.version = name; + } + + public File getInstalledLocation() { + return installedLocation; + } + + public void setInstalledLocation(File location) { + this.installedLocation = location; + } + + public boolean isMarkDefault() { + return markDefault; + } + + public void setMarkDefault(boolean markDefault) { + this.markDefault = markDefault; + } + + public List getExecutionEnvironments() { + return executionEnvironments; + } + + public void setExecutionEnvironments(List executionEnvironments) { + this.executionEnvironments = executionEnvironments; + } +} diff --git a/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java index 695f5e038..496e25257 100644 --- a/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java +++ b/src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java @@ -21,15 +21,11 @@ import com.diffplug.gradle.OrderingConstraints; -/** - * Used for adding JRE/JDK installations to an Eclipse install - */ -public class InstalledJreAdder - extends SetupAction { - +/** Used for adding JRE/JDK installations to an Eclipse install. */ +public class InstalledJreAdder extends SetupAction { private static final long serialVersionUID = -7101059764345094433L; - List installedJres; + final List installedJres; protected InstalledJreAdder(Collection jresToAdd) { super("com.diffplug.gradle.oomph.InstalledJreAdderInternal"); diff --git a/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java b/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java index 6ed2b2048..8d08881b8 100644 --- a/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java +++ b/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java @@ -348,8 +348,9 @@ private void internalSetup(File ideDir) throws IOException { // get the user setup actions List list = setupActions.getResult(); // add installed jres - if (!installedJres.isEmpty()) + if (!installedJres.isEmpty()) { list.add(new InstalledJreAdder(installedJres)); + } // add the project importer list.add(new ProjectImporter(projectFiles)); // order the actions From 0b59b6c503755d68c333336a7cf8f5aea8ca9fea Mon Sep 17 00:00:00 2001 From: travis-ci Date: Wed, 23 Nov 2016 22:36:23 -0800 Subject: [PATCH 5/6] Took ConventionJdt's installedJre logic out of OomphIdeExtension and contained it within ConventionJdt. This required adding a method to OomphConvention for specifying that the block is closed, so that values which have been accumulated can be flushed into actions. --- .../diffplug/gradle/oomph/ConventionJdt.java | 17 ++++++++++++-- .../gradle/oomph/OomphConvention.java | 12 +++++++++- .../gradle/oomph/OomphIdeExtension.java | 22 ++++++++----------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java b/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java index a6f56a6c2..928551875 100644 --- a/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java +++ b/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java @@ -15,6 +15,9 @@ */ package com.diffplug.gradle.oomph; +import java.util.HashSet; +import java.util.Set; + import org.gradle.api.Action; public class ConventionJdt extends OomphConvention { @@ -24,10 +27,20 @@ public class ConventionJdt extends OomphConvention { setPerspectiveOver(Perspectives.JAVA, Perspectives.RESOURCES); } + final Set installedJres = new HashSet<>(); + /** Adds an installed JRE with the given content. */ - void installedJre(Action action) { + public void installedJre(Action action) { InstalledJre instance = new InstalledJre(); action.execute(instance); - extension.installedJres.add(instance); + installedJres.add(instance); + } + + @Override + public void close() { + // add installed jres + if (!installedJres.isEmpty()) { + extension.addSetupAction(new InstalledJreAdder(installedJres)); + } } } diff --git a/src/main/java/com/diffplug/gradle/oomph/OomphConvention.java b/src/main/java/com/diffplug/gradle/oomph/OomphConvention.java index fb56148eb..507f6eff5 100644 --- a/src/main/java/com/diffplug/gradle/oomph/OomphConvention.java +++ b/src/main/java/com/diffplug/gradle/oomph/OomphConvention.java @@ -21,7 +21,7 @@ * Base class for implementing a DSL * around a specific part of the IDE. */ -public class OomphConvention { +public class OomphConvention implements AutoCloseable { protected final OomphIdeExtension extension; OomphConvention(OomphIdeExtension extension) { @@ -45,4 +45,14 @@ protected void setPerspectiveOver(String toSet, String... toTrump) { extension.perspective(toSet); } } + + /** + * This is called when the convention block ends. + * + * Usually it can just be empty, but if you've been accumulating + * values, this is your chance to smush them down into + * a setup action (see {@link ConventionJdt}. + */ + @Override + public void close() {} } diff --git a/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java b/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java index 8d08881b8..5ad995e26 100644 --- a/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java +++ b/src/main/java/com/diffplug/gradle/oomph/OomphIdeExtension.java @@ -20,12 +20,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.function.Supplier; @@ -67,7 +65,6 @@ public class OomphIdeExtension implements P2Declarative { final Project project; final WorkspaceRegistry workspaceRegistry; final SortedSet projectFiles = new TreeSet<>(); - final Set installedJres = new HashSet<>(); final Map> workspaceToContent = new HashMap<>(); final P2Model p2 = new P2Model(); final Lazyable> setupActions = Lazyable.ofList(); @@ -347,10 +344,6 @@ void ideSetupWorkspace() throws Exception { private void internalSetup(File ideDir) throws IOException { // get the user setup actions List list = setupActions.getResult(); - // add installed jres - if (!installedJres.isEmpty()) { - list.add(new InstalledJreAdder(installedJres)); - } // add the project importer list.add(new ProjectImporter(projectFiles)); // order the actions @@ -386,19 +379,22 @@ void ideClean() { ///////////////// /** Convenience methods for setting the style. */ public void style(Action action) { - ConventionStyle convention = new ConventionStyle(this); - action.execute(convention); + try (ConventionStyle convention = new ConventionStyle(this)) { + action.execute(convention); + } } /** Adds the java development tools. */ public void jdt(Action action) { - ConventionJdt convention = new ConventionJdt(this); - action.execute(convention); + try (ConventionJdt convention = new ConventionJdt(this)) { + action.execute(convention); + } } /** Adds the plugin-development environment, @see ConventionPde. */ public void pde(Action action) { - ConventionPde convention = new ConventionPde(this); - action.execute(convention); + try (ConventionPde convention = new ConventionPde(this)) { + action.execute(convention); + } } } From e86e016a08c866e57b7e87fe2ecacccae72f1f17 Mon Sep 17 00:00:00 2001 From: travis-ci Date: Wed, 23 Nov 2016 22:59:54 -0800 Subject: [PATCH 6/6] Reorganized docs to be a tad more hierarchical. Show the basics first, and give links to the more detailed stuff later. --- README.md | 19 ++------------- .../diffplug/gradle/oomph/ConventionJdt.java | 23 +++++++++++++++++++ .../diffplug/gradle/oomph/ConventionPde.java | 21 +++++++++++++++++ .../diffplug/gradle/oomph/OomphIdePlugin.java | 11 +++------ 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index dde36f390..3545cc85d 100644 --- a/README.md +++ b/README.md @@ -36,15 +36,7 @@ When you run `gradlew ide`, it builds and downloads an IDE into `build/oomphIde` apply plugin: 'com.diffplug.gradle.oomph.ide' oomphIde { repoEclipseLatest() - jdt { - //Some *optional* older (or newer) JRE/JDK - installedJre({ jre -> - jre.version = '1.6.0_45' - jre.installedLocation = new File('C:/jdk1.6.0_45') - jre.markDefault = true // or false - jre.executionEnvironments = ['JavaSE-1.6'] //any or as many execution environments can be specified here. - }) - } + jdt {} eclipseIni { vmargs('-Xmx2g') // IDE can have up to 2 gigs of RAM } @@ -55,14 +47,7 @@ oomphIde { } ``` -See the [plugin's javadoc](https://diffplug.github.io/goomph/javadoc/3.4.0/com/diffplug/gradle/oomph/OomphIdePlugin.html) for more details. - -Examples (submit a PR with yours here!) - -- [Gradle and Eclipse RCP talk](https://github.com/diffplug/gradle_and_eclipse_rcp/blob/master/ide/build.gradle) (multi-project Eclipse RCP project) -- [ls-api](https://github.com/TypeFox/ls-api/blob/61a3089569acbe159f043534f282401452a34bc3/ide/build.gradle) (xtend IDE example) -- [Spotless](https://github.com/diffplug/spotless/blob/master/build.gradle) (single-project Gradle plugin) -- (your example here) +See the [plugin's javadoc](https://diffplug.github.io/goomph/javadoc/3.4.0/com/diffplug/gradle/oomph/OomphIdePlugin.html) for a quickstart, and [HOW_TO_AUTOMATE_IDE.md](HOW_TO_AUTOMATE_IDE.md) for examples and more in-depth details. ## Blog posts diff --git a/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java b/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java index 928551875..c9a5455f3 100644 --- a/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java +++ b/src/main/java/com/diffplug/gradle/oomph/ConventionJdt.java @@ -20,6 +20,29 @@ import org.gradle.api.Action; +/** + * Adding the JDT convention to your project + * adds the following features: + * + * - `org.eclipse.platform.ide` + * - `org.eclipse.jdt` + * - `org.eclipse.ui.views.log` + * + * You can set the installed JRE as follows: + * + * ```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. + * } + * } + * } + * ``` + */ public class ConventionJdt extends OomphConvention { ConventionJdt(OomphIdeExtension extension) { super(extension); diff --git a/src/main/java/com/diffplug/gradle/oomph/ConventionPde.java b/src/main/java/com/diffplug/gradle/oomph/ConventionPde.java index ac4ef2948..5a3769cc8 100644 --- a/src/main/java/com/diffplug/gradle/oomph/ConventionPde.java +++ b/src/main/java/com/diffplug/gradle/oomph/ConventionPde.java @@ -23,6 +23,27 @@ import com.diffplug.gradle.OrderingConstraints; +/** + * Adding the PDE convention to your project + * adds the following features: + * + * - `org.eclipse.platform.ide` + * - `org.eclipse.jdt` + * - `org.eclipse.pde` + * + * You can set the targetplatform as follows: + * + * ```gradle + * oomphIde { + * pde { + * targetplatform { + * it.installation '../target.maven/build' + * it.installation '../target.p2/build/p2asmaven/p2runnable/eclipse-deps' + * } + * } + * } + * ``` + */ public class ConventionPde extends OomphConvention { ConventionPde(OomphIdeExtension extension) { super(extension); diff --git a/src/main/java/com/diffplug/gradle/oomph/OomphIdePlugin.java b/src/main/java/com/diffplug/gradle/oomph/OomphIdePlugin.java index 05e0085eb..bdb633d9e 100644 --- a/src/main/java/com/diffplug/gradle/oomph/OomphIdePlugin.java +++ b/src/main/java/com/diffplug/gradle/oomph/OomphIdePlugin.java @@ -31,7 +31,7 @@ * * - `gradlew ide` launches the IDE, after running any required setup tasks. * - * To create an IDE for java projects: + * To create an IDE for java projects (see {@link ConventionJdt} for more JDT options). * * ```groovy * apply plugin: 'com.diffplug.gradle.oomph.ide' @@ -41,17 +41,12 @@ * } * ``` * - * For an Eclipse Plugin project with a target platform: + * For an Eclipse Plugin project (see {@link ConventionPde} for more JDT options). * * ```groovy * oomphIde { * repoEclipse '4.5.2' - * pde { - * targetplatform { - * installation 'target.maven/build' - * installation 'target.p2/build/p2asmaven/p2' - * } - * } + * pde {} * } * ``` *