Skip to content

Commit

Permalink
Upgrade to Eclipse 4.30.0
Browse files Browse the repository at this point in the history
This newer Eclipse release requires Java 17 or better.  However, we
still prefer to keep most of WALA compatible with Java 11.  Therefore,
this Eclipse upgrade adds nontrivial build infrastructure to let us use
a newer Java release only where Eclipse dependencies require it.

A new `com.ibm.wala.jdk-version` property in `gradle.properties` allows
setting the default Java version used throughout WALA.  If this property
is set to 17 or higher, then that same version is used both for
Eclipse-dependent and Eclipse-independent WALA components.  However, if
this property is set to 16 or earlier, then it is only used for WALA's
Eclipse-independent components; the Eclipse-dependent components will
override this and use Java 17 instead.

In a default configuration, most of WALA will be compiled with (and
for) Java 11, with the Eclipse-dependent components using Java 17
instead.

Resolves #1354.
  • Loading branch information
liblit committed Jan 14, 2024
1 parent b04124b commit bad0b1d
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
gradle-executable: xvfb-gradle.sh
arguments: aggregatedJavadocs build publishAllPublicationsToFakeRemoteRepository shellcheck --no-configuration-cache
arguments: aggregatedJavadocs build publishAllPublicationsToFakeRemoteRepository shellcheck --no-configuration-cache -Pcom.ibm.wala.jdk-version=${{ matrix.java }}
# testing ECJ compilation on any one OS is sufficient; we choose Linux arbitrarily
if: runner.os == 'Linux'
- name: Build and test using Gradle but without ECJ
uses: gradle/gradle-build-action@v2
with:
arguments: aggregatedJavadocs javadoc build -PskipJavaUsingEcjTasks --no-configuration-cache
arguments: aggregatedJavadocs javadoc build -PskipJavaUsingEcjTasks --no-configuration-cache -Pcom.ibm.wala.jdk-version=${{ matrix.java }}
if: runner.os != 'Linux'
- name: Check for Git cleanliness after build and test
run: ./check-git-cleanliness.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.ibm.wala.gradle

import javax.inject.Inject
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Provider
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.kotlin.dsl.the

/**
* The earliest Java version that is compatible with bytecode used in Eclipse dependencies.
*
* When changing `eclipse` in the `versions` section of `gradle/libs.versions.toml`, consider
* whether this value needs to be changed as well.
*/
private const val MINIMUM_ECLIPSE_COMPATIBLE_JAVA_VERSION = 17

/**
* A Gradle [Project] extension providing details about Eclipse-compatible Java toolchains.
*
* @constructor Creates an extension instance that will be attached to the given [project].
* @property project The project to which this extension instance is attached.
* @property languageVersion A Java language version that is compatible with WALA's Eclipse
* dependencies.
* @property launcher Provides a Java JVM launcher (i.e., `java` command) that is compatible with
* WALA's Eclipse dependencies.
*/
open class EclipseCompatibleJavaExtension @Inject constructor(private val project: Project) {

val languageVersion: JavaLanguageVersion by lazy {
project.run {
val projectVersion = the<JavaPluginExtension>().toolchain.languageVersion.get()
val minimumVersion = JavaLanguageVersion.of(MINIMUM_ECLIPSE_COMPATIBLE_JAVA_VERSION)
if (projectVersion.canCompileOrRun(minimumVersion)) projectVersion else minimumVersion
}
}

val launcher: Provider<JavaLauncher> by lazy {
project.the<JavaToolchainService>().launcherFor {
languageVersion.set(this@EclipseCompatibleJavaExtension.languageVersion)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.io.File
import javax.inject.Inject
import org.gradle.api.Project
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.CompileClasspath
import org.gradle.api.tasks.InputFile
Expand All @@ -14,6 +15,7 @@ import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.the
import org.gradle.process.ExecOperations

/**
Expand All @@ -35,6 +37,16 @@ abstract class JavaCompileUsingEcj : JavaCompile() {

@get:Inject abstract val execOperations: ExecOperations

/**
* The path to the Java launcher executable used for running the Eclipse Java compiler (ECJ).
*
* @see EclipseCompatibleJavaExtension.launcher
*/
@InputFile
@PathSensitive(PathSensitivity.NONE)
val javaLauncherPath: Provider<RegularFile> =
project.the<EclipseCompatibleJavaExtension>().launcher.map { it.executablePath }

init {
options.compilerArgumentProviders.run {
add {
Expand All @@ -54,6 +66,7 @@ abstract class JavaCompileUsingEcj : JavaCompile() {
fun compile() {
execOperations.javaexec {
classpath(ecjJar.absolutePath)
executable(javaLauncherPath.get())
args(options.allCompilerArgs)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ibm.wala.gradle

plugins { java }

// Make Eclipse-compatible Java information available as `project.eclipseCompatibleJava`.
extensions.create<EclipseCompatibleJavaExtension>("eclipseCompatibleJava")
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import com.diffplug.gradle.eclipse.MavenCentralExtension.ReleaseConfigurer
import com.diffplug.gradle.eclipse.MavenCentralPlugin
import com.diffplug.gradle.pde.EclipseRelease

plugins { id("com.diffplug.eclipse.mavencentral") }
plugins {
id("com.diffplug.eclipse.mavencentral")
id("com.ibm.wala.gradle.eclipse-compatible-java")
id("com.ibm.wala.gradle.java")
}

// This subproject uses one or more Eclipse dependencies. Eensure that it is using an
// Eclipse-compatible Java toolchain. That toolchain might be newer than the Java toolchain that
// WALA uses elsewhere.
java.toolchain.languageVersion = the<EclipseCompatibleJavaExtension>().languageVersion

/**
* WALA-specialized adaptation of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
`maven-publish`
signing
id("com.diffplug.spotless")
id("com.ibm.wala.gradle.eclipse-compatible-java")
id("com.ibm.wala.gradle.javadoc")
id("com.ibm.wala.gradle.subproject")
id("net.ltgt.errorprone")
Expand All @@ -24,6 +25,9 @@ repositories {
maven { url = uri("https://storage.googleapis.com/r8-releases/raw") }
}

java.toolchain.languageVersion =
JavaLanguageVersion.of(property("com.ibm.wala.jdk-version") as String)

base.archivesName = "com.ibm.wala${project.path.replace(':', '.')}"

configurations {
Expand Down
2 changes: 1 addition & 1 deletion cast/java/test/data/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=error
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=error
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Preferred JDK version to use for compiling WALA and running WALA tests. WALA's Eclipse-dependent
# components may override this with something newer; see `MINIMUM_ECLIPSE_COMPATIBLE_JAVA_VERSION`
# in `build-logic/src/main/kotlin/com/ibm/wala/gradle/EclipseCompatibleJavaExtension.kt`.
com.ibm.wala.jdk-version=11

org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
eclipse = "4.21.0"
eclipse = "4.30.0"
eclipse-wst-jsdt = "1.0.201.v2010012803"
google-java-format = "1.17.0"
ktfmt = "0.44"
Expand Down
5 changes: 4 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
buildscript { dependencies { classpath("com.diffplug.spotless:spotless-lib-extra:2.43.1") } }

plugins { id("com.diffplug.configuration-cache-for-platform-specific-build") version "3.44.0" }
plugins {
id("com.diffplug.configuration-cache-for-platform-specific-build") version "3.44.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}

enableFeaturePreview("STABLE_CONFIGURATION_CACHE")

Expand Down

0 comments on commit bad0b1d

Please sign in to comment.