-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from scottresnik/add-installed-jre
Add installed jre
- Loading branch information
Showing
10 changed files
with
301 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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<String> 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<String> getExecutionEnvironments() { | ||
return executionEnvironments; | ||
} | ||
|
||
public void setExecutionEnvironments(List<String> executionEnvironments) { | ||
this.executionEnvironments = executionEnvironments; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/diffplug/gradle/oomph/InstalledJreAdder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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 InstalledJreAdder extends SetupAction { | ||
private static final long serialVersionUID = -7101059764345094433L; | ||
|
||
final List<InstalledJre> installedJres; | ||
|
||
protected InstalledJreAdder(Collection<InstalledJre> jresToAdd) { | ||
super("com.diffplug.gradle.oomph.InstalledJreAdderInternal"); | ||
installedJres = new ArrayList<>(jresToAdd); | ||
} | ||
|
||
@Override | ||
protected void populateOrdering(OrderingConstraints<Class<? extends SetupAction>> 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"; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/com/diffplug/gradle/oomph/InstalledJreAdderInternal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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 InstalledJreAdderInternal extends Internal<InstalledJreAdder> { | ||
|
||
InstalledJreAdderInternal(InstalledJreAdder 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) { | ||
IVMInstall realVM = addInstalledJre(type, jreToAdd); | ||
if (jreToAdd.isMarkDefault()) { | ||
JavaRuntime.setDefaultVMInstall(realVM, new NullProgressMonitor()); | ||
} | ||
linkWithExecutionEnvironments(realVM, jreToAdd); | ||
} | ||
} | ||
} | ||
} | ||
|
||
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; | ||
} | ||
return retVal; | ||
} | ||
|
||
protected void linkWithExecutionEnvironments(IVMInstall installedVm, InstalledJre jreToAdd) { | ||
if (jreToAdd.getExecutionEnvironments().isEmpty()) { | ||
return; | ||
} else { | ||
Set<String> execEnvsToAdd = new HashSet<>(jreToAdd.getExecutionEnvironments()); | ||
IExecutionEnvironment[] executionEnvironments = JavaRuntime.getExecutionEnvironmentsManager() | ||
.getExecutionEnvironments(); | ||
for (IExecutionEnvironment iExecutionEnvironment : executionEnvironments) { | ||
if (execEnvsToAdd.contains(iExecutionEnvironment.getId())) { | ||
iExecutionEnvironment.setDefaultVM(installedVm); | ||
} | ||
} | ||
} | ||
} | ||
|
||
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 vmInstall; | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.