Commit 79e658fa authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Add contingency for using ECJ if it is available and we are using a very new version of Java.

parent 0a99f156
Pipeline #108389 passed with stages
in 5 minutes and 38 seconds
......@@ -253,3 +253,10 @@ the behavior:
suite path.
* Same format as the `-classpath` argument. On Windows this will use `;`
as separators, while other systems will use `:`.
# New Java Version Contingency
With regard to <https://github.com/SquirrelJME/SquirrelJME/issues/6> if in
the event this occurs, building with Gradle will attempt to use the
Eclipse Java Compiler to compile the project. It may be forced by passing
to Gradle `-Dforce.ecj=true`.
......@@ -23,7 +23,12 @@ static VersionNumber normalizeMavenVersion(Object __inVersion) {
// Every sub-project needs SquirrelJME specific pieces
subprojects {
//apply plugin: "de.set.ecj"
// Apply ECJ for compilation? (Such as too new of Java)
if (project.hasProperty("squirreljmeEcjEnabled") &&
project.squirreljmeEcjEnabled) {
apply plugin: "de.set.ecj"
}
apply plugin: "java-library"
apply plugin: "cc.squirreljme.plugin"
apply plugin: "idea"
......@@ -42,6 +47,16 @@ subprojects {
}
}
// Disable native header generation when using ECJ as it does not have
// the -h option. See:
// https://github.com/gradle/gradle/issues/12904#issuecomment-619212927
if (project.hasProperty("squirreljmeEcjEnabled") &&
project.squirreljmeEcjEnabled) {
tasks.withType(JavaCompile) {
options.headerOutputDirectory.convention((Directory)null)
}
}
// Configure the compiler
java {
// Java ME 8 is effectively Java 7
......
import java.nio.file.Paths
import java.nio.file.Files
import java.util.regex.Pattern
import java.util.stream.Collectors
// If we have a really high Java version being used then the parameters
// for -source and -target were likely removed, so as such we cannot rely on
// the project being able to be built in such versions.
if (JavaVersion.current() >= JavaVersion.VERSION_HIGHER ||
Boolean.getBoolean("force.ecj")) {
// Emit a warning to indicate that the version is quite new
logger.warn("The current Java version is quite new, " +
"if Eclipse Java Compiler (ECJ) exists on the system " +
"then it will be used to compile the modules instead.")
// Fallback to ECJ on newer Java versions, if available
def envRawPathProperty = System.getenv("PATH")
def envPath = (envRawPathProperty != null ?
Arrays.asList(
envRawPathProperty.split(Pattern.quote(File.pathSeparator)))
.stream().<java.nio.file.Path>map({it -> Paths.get(it)})
.collect(Collectors.toList()) : null)
// Does ECJ exist in the class path?
def foundEcjBinary = false
for (java.nio.file.Path path : envPath) {
if (Files.exists(path.resolve("ecj"))) {
foundEcjBinary = true
}
}
// If we have the binary, use it
if (foundEcjBinary) {
logger.lifecycle("Found ECJ binary, using it!")
gradle.beforeProject({proj ->
proj.ext.squirreljmeEcjEnabled = true
})
} else {
logger.warn("Could not find ECJ, build may fail!")
}
}
// Modules and available platforms
include "modules"
include "emulators"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment