Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3111: Enforcing maximum supported Gradle version

Ryan Kurtz50a3bc30d258
diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/framework/ApplicationProperties.java b/Ghidra/Framework/Utility/src/main/java/ghidra/framework/ApplicationProperties.java
index 81eac06658..9648fd3abc 100644
--- a/Ghidra/Framework/Utility/src/main/java/ghidra/framework/ApplicationProperties.java
+++ b/Ghidra/Framework/Utility/src/main/java/ghidra/framework/ApplicationProperties.java
@@ -58,14 +58,23 @@ public class ApplicationProperties extends Properties {
public static final String APPLICATION_GRADLE_MIN_PROPERTY = "application.gradle.min";
/**
- * The minimum major version of Java required to run the application. For example, "8".
+ * The earliest version of gradle after {@link #APPLICATION_GRADLE_MIN_PROPERTY} that is
+ * unsupported.
+ * <p>
+ * If all versions of Gradle greater than or equal to {@link #APPLICATION_GRADLE_MIN_PROPERTY}
+ * are supported, this property should not be set.
+ */
+ public static final String APPLICATION_GRADLE_MAX_PROPERTY = "application.gradle.max";
+
+ /**
+ * The minimum major version of Java required to run the application.
*/
public static final String APPLICATION_JAVA_MIN_PROPERTY = "application.java.min";
/**
- * The maximum major version of Java the application will run under. For example, "8".
+ * The maximum major version of Java the application will run under.
* <p>
- * If all versions of Java greater than {@link #APPLICATION_JAVA_MIN_PROPERTY} are
+ * If all versions of Java greater than or equal to {@link #APPLICATION_JAVA_MIN_PROPERTY} are
* supported, this property should not be set.
*/
public static final String APPLICATION_JAVA_MAX_PROPERTY = "application.java.max";
diff --git a/Ghidra/RuntimeScripts/Common/support/buildExtension.gradle b/Ghidra/RuntimeScripts/Common/support/buildExtension.gradle
index fcf9cb9729..94b971aecc 100644
--- a/Ghidra/RuntimeScripts/Common/support/buildExtension.gradle
+++ b/Ghidra/RuntimeScripts/Common/support/buildExtension.gradle
@@ -33,17 +33,14 @@ file(ghidraDir + "/application.properties").withReader { reader ->
project.ext.ghidra_version = ghidraProps.getProperty('application.version')
project.ext.RELEASE_NAME = ghidraProps.getProperty('application.release.name')
project.ext.DISTRO_PREFIX = "ghidra_${ghidra_version}"
- project.ext.GRADLE_MINIMUM_VERSION = ghidraProps.getProperty('application.gradle.min')
+ project.ext.GRADLE_MIN = ghidraProps.getProperty('application.gradle.min')
+ project.ext.GRADLE_MAX = ghidraProps.getProperty('application.gradle.max')
}
/***************************************************************************************
- * Make sure the correct version of gradle is being used
+ * Make sure a supported version of Gradle is being used
***************************************************************************************/
-import org.gradle.util.GradleVersion;
-final GradleVersion minimum_version = GradleVersion.version("${GRADLE_MINIMUM_VERSION}")
-if (GradleVersion.current() < minimum_version) {
- throw new GradleException("Requires at least $minimum_version, but was run with $gradle.gradleVersion")
-}
+checkGradleVersion()
configurations {
helpPath
@@ -331,3 +328,36 @@ def getCurrentDate() {
return formattedDate
}
+/*********************************************************************************
+ * Throws a GradleException if the current Gradle version is outside of the supported
+ * Gradle version range defined in application.properties
+ *********************************************************************************/
+import org.gradle.util.GradleVersion;
+def checkGradleVersion() {
+ GradleVersion min = null;
+ GradleVersion max = null;
+ try {
+ min = GradleVersion.version("${rootProject.GRADLE_MIN}")
+ }
+ catch (IllegalArgumentException e) {
+ String defaultMin = "1.0"
+ println "Invalid minimum Gradle version specified in application.properties...using ${defaultMin}"
+ min = GradleVersion.version(defaultMin)
+ }
+ try {
+ if (rootProject.GRADLE_MAX) {
+ max = GradleVersion.version("${rootProject.GRADLE_MAX}")
+ }
+ }
+ catch (IllegalArgumentException e) {
+ println "Invalid maximum Gradle version specified in application.properties...ignoring"
+ }
+ String gradleRange = "at least ${min}"
+ if (max) {
+ gradleRange += " and less than ${max}"
+ }
+ if (GradleVersion.current() < min || (max && GradleVersion.current() >= max)) {
+ throw new GradleException("Requires ${gradleRange}, but was run with $gradle.gradleVersion")
+ }
+}
+
diff --git a/Ghidra/application.properties b/Ghidra/application.properties
index 7f6d72b722..77ef3769f7 100644
--- a/Ghidra/application.properties
+++ b/Ghidra/application.properties
@@ -3,6 +3,7 @@ application.version=10.3
application.release.name=DEV
application.layout.version=1
application.gradle.min=7.3
+application.gradle.max=
application.java.min=17
application.java.max=
application.java.compiler=17
diff --git a/build.gradle b/build.gradle
index c4cf06b221..b0c717fb1e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -25,10 +25,7 @@ apply from: "gradle/support/loadApplicationProperties.gradle"
***************************************************************************************/
import org.gradle.util.GradleVersion;
println "Gradle: " + GradleVersion.current().version
-final GradleVersion minimum_version = GradleVersion.version("${rootProject.GRADLE_MINIMUM_VERSION}")
-if (GradleVersion.current() < minimum_version) {
- throw new GradleException("Requires at least $minimum_version, but was run with $gradle.gradleVersion")
-}
+checkGradleVersion()
/***************************************************************************************
* Define the location of JAVA_HOME
@@ -113,6 +110,41 @@ clean {
delete "$buildDir"
}
+/*********************************************************************************
+ * Throws a GradleException if the current Gradle version is outside of the supported
+ * Gradle version range defined in application.properties.
+ *
+ * NOTE: This function is duplicated in buildExtension.gradle
+ *********************************************************************************/
+import org.gradle.util.GradleVersion;
+def checkGradleVersion() {
+ GradleVersion min = null;
+ GradleVersion max = null;
+ try {
+ min = GradleVersion.version("${rootProject.GRADLE_MIN}")
+ }
+ catch (IllegalArgumentException e) {
+ String defaultMin = "1.0"
+ println "Invalid minimum Gradle version specified in application.properties...using ${defaultMin}"
+ min = GradleVersion.version(defaultMin)
+ }
+ try {
+ if (rootProject.GRADLE_MAX) {
+ max = GradleVersion.version("${rootProject.GRADLE_MAX}")
+ }
+ }
+ catch (IllegalArgumentException e) {
+ println "Invalid maximum Gradle version specified in application.properties...ignoring"
+ }
+ String gradleRange = "at least ${min}"
+ if (max) {
+ gradleRange += " and less than ${max}"
+ }
+ if (GradleVersion.current() < min || (max && GradleVersion.current() >= max)) {
+ throw new GradleException("Requires ${gradleRange}, but was run with $gradle.gradleVersion")
+ }
+}
+
/******************************************************************************************
*
* Utility methods used by multiple build.gradle files
diff --git a/gradle/support/loadApplicationProperties.gradle b/gradle/support/loadApplicationProperties.gradle
index 39d52bbb5f..b20831c428 100644
--- a/gradle/support/loadApplicationProperties.gradle
+++ b/gradle/support/loadApplicationProperties.gradle
@@ -26,7 +26,8 @@ file("Ghidra/application.properties").withReader { reader ->
project.ext.RELEASE_VERSION = version
project.ext.RELEASE_NAME = ghidraProps.getProperty('application.release.name')
project.ext.JAVA_COMPILER = ghidraProps.getProperty('application.java.compiler')
- project.ext.GRADLE_MINIMUM_VERSION = ghidraProps.getProperty('application.gradle.min')
+ project.ext.GRADLE_MIN = ghidraProps.getProperty('application.gradle.min')
+ project.ext.GRADLE_MAX = ghidraProps.getProperty('application.gradle.max')
project.ext.DISTRO_PREFIX = "ghidra_${version}_${RELEASE_NAME}"
// Build dates may or may not be already present in the application.properties file.