Skip to content

Commit

Permalink
GP-3111: Enforcing maximum supported Gradle version
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmkurtz committed Apr 20, 2023
1 parent 8242c31 commit 50a3bc3
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
44 changes: 37 additions & 7 deletions Ghidra/RuntimeScripts/Common/support/buildExtension.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}

1 change: 1 addition & 0 deletions Ghidra/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 36 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion gradle/support/loadApplicationProperties.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 50a3bc3

Please sign in to comment.