Skip to content

Commit

Permalink
[examples] Ensure that the JDK used for creating the example projects…
Browse files Browse the repository at this point in the history
… is compliant with the minimum JDK for SARL.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Dec 9, 2020
1 parent 41983c5 commit 8678e8d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Expand Up @@ -58,6 +58,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.intro.IIntroManager;
import org.eclipse.ui.intro.IIntroPart;
import org.eclipse.xtext.util.JavaVersion;
import org.eclipse.xtext.util.RuntimeIOException;
import org.eclipse.xtext.util.StringInputStream;
import org.osgi.framework.Version;
Expand All @@ -84,6 +85,8 @@
*/
public class SarlExampleInstallerWizard extends ExampleInstallerWizard {

private static final int MIN_JDK_VERSION = 9;

private ConfigurationPage configurationPage;

private List<ConfigurationToLaunch> configurationsToLaunch;
Expand Down Expand Up @@ -149,6 +152,26 @@ protected void installProject(ProjectDescriptor projectDescriptor, IProgressMoni
postProjectInstallation(projectDescriptor, mon.newChild(1));
}

private JavaVersion parseVersion(AbstractVMInstall vmInstall, String minVersion) {
final String vmVersion = vmInstall.getJavaVersion();
final JavaVersion minJversion = JavaVersion.fromQualifier(minVersion);
JavaVersion jversion = JavaVersion.fromQualifier(vmVersion);
if (jversion == null) {
final Version vers = Version.parseVersion(vmVersion);
// This is a hard-coded support for the different version formats (1.x or x)
// when using Java 9 or higher.
if (vers.getMajor() >= MIN_JDK_VERSION) {
jversion = JavaVersion.fromQualifier(Integer.toString(vers.getMajor()));
} else {
jversion = JavaVersion.fromQualifier(vers.getMajor() + "." + vers.getMinor());
}
}
if (jversion != null && minJversion != null && !jversion.isAtLeast(minJversion)) {
jversion = minJversion;
}
return jversion;
}

/** Post process the given project.
*
* @param projectDescriptor the descriptor of the project.
Expand All @@ -169,8 +192,10 @@ protected void postProjectInstallation(ProjectDescriptor projectDescriptor, IPro
final IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
if (vmInstall instanceof AbstractVMInstall) {
final AbstractVMInstall jvmInstall = (AbstractVMInstall) vmInstall;
final Version vers = Version.parseVersion(jvmInstall.getJavaVersion());
compliance = vers.getMajor() + "." + vers.getMinor();
final JavaVersion jversion = parseVersion(jvmInstall, compliance);
if (jversion != null) {
compliance = jversion.getQualifier();
}
}
updatePomContent(pomFile, compliance);
}
Expand Down
6 changes: 3 additions & 3 deletions main/externalmaven/io.sarl.javafx/pom.xml
Expand Up @@ -151,7 +151,7 @@
<property>
<name>!env.OPENJFX_LIB_PATH</name>
</property>
<jdk>[1.8,1.11)</jdk>
<jdk>[1.8,11)</jdk>
<os>
<family>unix</family>
<name>linux</name>
Expand All @@ -173,7 +173,7 @@
<property>
<name>!env.OPENJFX_LIB_PATH</name>
</property>
<jdk>[1.8,1.11)</jdk>
<jdk>[1.8,11)</jdk>
<os>
<family>mac</family>
</os>
Expand All @@ -194,7 +194,7 @@
<property>
<name>!env.OPENJFX_LIB_PATH</name>
</property>
<jdk>[1.8,1.11)</jdk>
<jdk>[1.8,11)</jdk>
<os>
<family>windows</family>
</os>
Expand Down

0 comments on commit 8678e8d

Please sign in to comment.