Skip to content

Commit

Permalink
Merge pull request #227 from rpalcolea/remove-project-convention-usage
Browse files Browse the repository at this point in the history
Upgrade to Gradle 7.1 and remove usage of Gradle deprecated APIs
  • Loading branch information
sghill authored Nov 17, 2023
2 parents b36aa16 + 6b0931b commit 508ec98
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
gradle_version: ["6.3", "6.4.1", "7.4"]
gradle_version: ["7.1.1", "7.4"]
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Plugins not hosted by the Jenkins infra team (internal-only plugins) are not imp

## Compatibility with Gradle versions

The latest version of the JPI plugin requires **Gradle 6.3 or later** to make use of advanced dependency management features.
The latest version of the JPI plugin requires **Gradle 7.1 or later** to make use of modern Gradle APIs.

For Gradle versions 6.3-6.9.x, please use version `0.50.0` of the JPI plugin.

For Gradle versions 6.0-6.2.1, please use version `0.46.0` of the JPI plugin.

Expand Down
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
testCompileOnly("junit:junit:4.13") {
because("used for generated tests with javapoet")
}
testImplementation("org.spockframework:spock-core:2.1-groovy-2.5")
testImplementation("org.spockframework:spock-core:2.1-groovy-3.0")
testImplementation("org.xmlunit:xmlunit-core:2.8.3")
testImplementation("org.apache.commons:commons-text:1.10.0")
testImplementation("com.squareup:javapoet:1.13.0")
Expand Down Expand Up @@ -170,11 +170,11 @@ tasks.withType<Test>().configureEach {

codenarc {
toolVersion = "1.1"
configFile = file("config/codenarc/rules.groovy")
configFile = rootProject.file("config/codenarc/rules.groovy")
}

tasks.codenarcTest {
configFile = file("config/codenarc/rules-test.groovy")
configFile = rootProject.file("config/codenarc/rules-test.groovy")
}

group = "org.jenkins-ci.tools"
Expand Down Expand Up @@ -208,8 +208,8 @@ tasks.register("shadeLatestVersionNumber") {
if (!response.isSuccessful) {
throw GradleException("${response.code} attempting to fetch latest hudson.util.VersionNumber")
}
val convention = project.convention.getPlugin(JavaPluginConvention::class)
val main = convention.sourceSets.getByName("main")
val extension = project.extensions.getByType(JavaPluginExtension::class)
val main = extension.sourceSets.getByName("main")
val srcMainJava = main.java.srcDirs.single().toPath()
val dest = srcMainJava.resolve("shaded/hudson/util/VersionNumber.java")
val sink = dest.sink(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING).buffer()
Expand Down
214 changes: 214 additions & 0 deletions gradle/verification-metadata.xml

Large diffs are not rendered by default.

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=3e240228538de9f18772a574e99a0ba959e83d6ef351014381acd9631781389a
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.4-bin.zip
distributionSha256Sum=2debee19271e1b82c6e41137d78e44e6e841035230a1a169ca47fd3fb09ed87b
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
25 changes: 18 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand All @@ -205,6 +210,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package org.jenkinsci.gradle.plugins.jpi

import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logger
import org.gradle.util.ConfigureUtil
import org.jenkinsci.gradle.plugins.jpi.internal.ConfigureUtil

/**
* Information on a single developer for the <developer> tag in the output POM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import groovy.transform.CompileStatic
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.model.ReplacedBy
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.plugins.quality.Checkstyle
import org.gradle.api.plugins.quality.CheckstyleExtension
import org.gradle.api.plugins.quality.CheckstylePlugin
Expand Down Expand Up @@ -460,15 +460,15 @@ class JpiExtension implements JpiExtensionBridge {
*/
@Deprecated
SourceSet mainSourceTree() {
project.convention.getPlugin(JavaPluginConvention).sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
project.extensions.getByType(JavaPluginExtension).sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
}

/**
* @deprecated To be removed in 1.0.0
*/
@Deprecated
SourceSet testSourceTree() {
project.convention.getPlugin(JavaPluginConvention).sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME)
project.extensions.getByType(JavaPluginExtension).sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME)
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package org.jenkinsci.gradle.plugins.jpi

import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logger
import org.gradle.util.ConfigureUtil
import org.jenkinsci.gradle.plugins.jpi.internal.ConfigureUtil

/**
* Information on a single license for the <license> tag in the output POM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import org.gradle.api.plugins.BasePlugin
import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.plugins.JavaLibraryPlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
Expand Down Expand Up @@ -101,6 +100,9 @@ class JpiPlugin implements Plugin<Project>, PluginDependencyProvider {
} else if (current < GradleVersion.version('6.3')) {
throw new GradleException('This version of the JPI plugin requires Gradle 6.3 or later.' +
'For older Gradle versions, please use version 0.46.0 of the JPI plugin.')
} else if (current < GradleVersion.version('7.1')) {
throw new GradleException('This version of the JPI plugin requires Gradle 6.3 or later.' +
'For older Gradle versions, please use version 0.46.0 of the JPI plugin.')
}
UnsupportedGradleConfigurationVerifier.configureDeprecatedConfigurations(gradleProject)

Expand Down Expand Up @@ -147,8 +149,8 @@ class JpiPlugin implements Plugin<Project>, PluginDependencyProvider {
t.group = LifecycleBasePlugin.VERIFICATION_GROUP
t.description = 'Validate '

def javaPluginConvention = project.convention.getPlugin(JavaPluginConvention)
def classDirs = javaPluginConvention.sourceSets.getByName(MAIN_SOURCE_SET_NAME).output.classesDirs
def javaPluginExtension = project.extensions.getByType(JavaPluginExtension)
def classDirs = javaPluginExtension.sourceSets.getByName(MAIN_SOURCE_SET_NAME).output.classesDirs
t.classesDirs.set(classDirs)
t.outputFile.set(project.layout.buildDirectory.file('check-overlap/discovered.txt'))
t.dependsOn(gradleProject.tasks.getByName('classes'))
Expand Down Expand Up @@ -391,7 +393,7 @@ class JpiPlugin implements Plugin<Project>, PluginDependencyProvider {
project.dependencies.components.all(JpiVariantRule)
project.dependencies.components.withModule(JenkinsWarRule.JENKINS_WAR_COORDINATES, JenkinsWarRule)

JavaPluginConvention javaConvention = project.convention.getPlugin(JavaPluginConvention)
JavaPluginExtension javaPluginExtension = project.extensions.getByType(JavaPluginExtension)
AdhocComponentWithVariants component = project.components.java

Configuration jenkinsServer =
Expand Down Expand Up @@ -432,7 +434,7 @@ class JpiPlugin implements Plugin<Project>, PluginDependencyProvider {
it.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
project.objects.named(LibraryElements, JPI))
it.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE,
javaConvention.targetCompatibility.majorVersion.toInteger())
javaPluginExtension.targetCompatibility.majorVersion.toInteger())
}
runtimeElements.outgoing.capabilities.each {
runtimeElementsJenkins.outgoing.capability(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.jenkinsci.gradle.plugins.jpi

import org.gradle.internal.deprecation.DeprecationLogger

import java.util.jar.JarFile
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
Expand Down Expand Up @@ -94,7 +96,10 @@ class ServerTask extends DefaultTask {
// copy the resolved HPI/JPI files to the plugins directory
def workDir = project.extensions.getByType(JpiExtension).workDir
artifacts.findAll { it.extension in ['hpi', 'jpi'] }.each {
GFileUtils.copyFile(it.file, new File(workDir, "plugins/${it.name}.${it.extension}"))
// Disable the deprecation since this artifact is already deprecated anyway
DeprecationLogger.whileDisabled {
GFileUtils.copyFile(it.file, new File(workDir, "plugins/${it.name}.${it.extension}"))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jenkinsci.gradle.plugins.jpi

import org.gradle.api.artifacts.Configuration
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.Copy

Expand All @@ -22,8 +22,8 @@ class TestDependenciesTask extends Copy {
include('*.jpi')

into {
JavaPluginConvention javaConvention = project.convention.getPlugin(JavaPluginConvention)
new File(javaConvention.sourceSets.test.output.resourcesDir, 'test-dependencies')
JavaPluginExtension javaPluginExtension = project.extensions.getByType(JavaPluginExtension)
new File(javaPluginExtension.sourceSets.test.output.resourcesDir, 'test-dependencies')
}

rename { mapping[it] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jenkinsci.gradle.plugins.jpi

import org.gradle.api.DefaultTask
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskAction
Expand All @@ -22,8 +22,8 @@ class TestInsertionTask extends DefaultTask {
@TaskAction
void generateInjectedTest() {
JpiExtension jpiExtension = project.extensions.getByType(JpiExtension)
JavaPluginConvention javaConvention = project.convention.getPlugin(JavaPluginConvention)
SourceSet mainSourceSet = javaConvention.sourceSets.getByName(MAIN_SOURCE_SET_NAME)
JavaPluginExtension javaPluginExtension = project.extensions.getByType(JavaPluginExtension)
SourceSet mainSourceSet = javaPluginExtension.sourceSets.getByName(MAIN_SOURCE_SET_NAME)

testSuite.parentFile.mkdirs()
testSuite.text = """import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jenkinsci.gradle.plugins.jpi.internal

import org.codehaus.groovy.runtime.GeneratedClosure
import org.gradle.internal.metaobject.ConfigureDelegate
import org.gradle.util.Configurable
import org.gradle.util.internal.ClosureBackedAction
import javax.annotation.Nullable

class ConfigureUtil {
static <T> T configure(@Nullable Closure configureClosure, T target) {
if (configureClosure == null) {
target
} else {
if (target instanceof Configurable) {
((Configurable)target).configure(configureClosure)
} else {
configureTarget(configureClosure, target, new ConfigureDelegate(configureClosure, target))
}

target
}
}

private static <T> void configureTarget(Closure configureClosure, T target, ConfigureDelegate closureDelegate) {
if (configureClosure instanceof GeneratedClosure) {
Closure withNewOwner = configureClosure.rehydrate(target, closureDelegate, configureClosure.thisObject)
(new ClosureBackedAction(withNewOwner, 2, false)).execute(target)
} else {
(new ClosureBackedAction(configureClosure, 1, false)).execute(target)
}
}
}

0 comments on commit 508ec98

Please sign in to comment.