diff --git a/.editorconfig b/.editorconfig index 97c1b8453..a348d9bab 100755 --- a/.editorconfig +++ b/.editorconfig @@ -7,8 +7,10 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[*.{groovy,java}] +[*.{java,groovy}] indent_size = 4 +ij_java_class_count_to_use_import_on_demand = 999 +ij_groovy_class_count_to_use_import_on_demand = 999 [*.{kt,kts}] ij_kotlin_imports_layout = * diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce18159a0..b87f3d960 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,17 +3,26 @@ name: CI on: push: branches: - - main + - 8.x pull_request: + branches: + - 8.x workflow_dispatch: jobs: build: + name: OS=${{ matrix.os }}, Java=${{ matrix.java }}, Gradle=${{ matrix.gradle }} strategy: matrix: os: [ ubuntu-latest, windows-latest ] - # Always test on the latest version and all LTS. - java: [ 11, 17, 21, 23 ] + # Always test on the latest version and some LTS. + java: [ 17, 21, 24 ] + # Test on the minimum Gradle version and the latest. + gradle: [ 8.3, current ] + exclude: + # Gradle 8.3 doesn't support Java 24. + - gradle: 8.3 + java: 24 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -22,10 +31,26 @@ jobs: distribution: 'zulu' java-version: ${{ matrix.java }} - uses: gradle/actions/setup-gradle@v4 - - run: ./gradlew build + - run: ./gradlew build --info "-PtestGradleVersion=${{ matrix.gradle }}" + + # Status check that is required in branch protection rules. + build-status: + needs: + - build + runs-on: ubuntu-24.04-arm + if: always() + steps: + - name: Check + run: | + results=$(tr -d '\n' <<< '${{ toJSON(needs.*.result) }}') + if ! grep -q -v -E '(failure|cancelled)' <<< "$results"; then + echo "One or more required jobs failed" + exit 1 + fi + echo "All required jobs completed successfully." publish-snapshot: - needs: build + needs: build-status runs-on: ubuntu-latest if: github.repository == 'GradleUp/shadow' && github.ref == 'refs/heads/main' steps: @@ -38,7 +63,7 @@ jobs: with: cache-read-only: true # Disable CC due to https://github.com/gradle/gradle/issues/22779 - - run: ./gradlew publish --no-configuration-cache + - run: ./gradlew publishToMavenCentral --no-configuration-cache env: - ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USER }} - ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.CENTRAL_PORTAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.CENTRAL_PORTAL_PASSWORD }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e2a1b6a10..77d6da030 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,30 +20,21 @@ jobs: - uses: gradle/actions/setup-gradle@v4 with: cache-read-only: true - - uses: actions/setup-node@v4 - with: - # Due to some limitations of https://github.com/node-gradle/gradle-node-plugin. - node-version: '16' # Disable CC due to https://github.com/gradle/gradle/issues/22779 - - run: ./gradlew release --no-configuration-cache + - run: ./gradlew publishToMavenCentral publishPlugins --no-configuration-cache env: GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_KEY }} GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_SECRET }} - # We must declare repository_owner as the user, workaround for https://github.com/ajoberstar/gradle-git-publish/issues/109. - GRGIT_USER: ${{ github.repository_owner }} - # https://ajoberstar.org/grgit/main/grgit-authentication.html#_environment_variables - GRGIT_PASS: ${{ secrets.GITHUB_TOKEN }} - ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USER }} - ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.CENTRAL_PORTAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.CENTRAL_PORTAL_PASSWORD }} ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }} ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_KEY_PASSWORD }} - name: Extract release notes - # TODO: replace this after https://github.com/ffurrer2/extract-release-notes/pull/355 is merged. - uses: Goooler/extract-release-notes@6e686e7a607d03716b7cff561371a82065b22c33 + uses: ffurrer2/extract-release-notes@v2 with: changelog_file: src/docs/changes/README.md release_notes_file: RELEASE_NOTES.md - name: Create release - run: gh release create ${{ github.ref_name }} --notes-file RELEASE_NOTES.md + run: gh release create ${{ github.ref_name }} --latest=false --notes-file RELEASE_NOTES.md env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index b9c94e745..0c4475b66 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,42 @@ -# Gradle Shadow +# Shadow Gradle plugin for creating fat/uber JARs with support for package relocation. > [!NOTE]\ -> Previously this plugin was developed by [@johnrengelman](https://github.com/johnrengelman) and published under the ID [`com.github.johnrengelman.shadow`](https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow) -> before maintenance was transferred to the [GradleUp organization](https://github.com/GradleUp) to ensure future development, see [#908](https://github.com/GradleUp/shadow/issues/908). +> Previously this plugin was developed by [@johnrengelman](https://github.com/johnrengelman) and published under the +> ID [`com.github.johnrengelman.shadow`][johnrengelman's] +> before maintenance was transferred to the [GradleUp organization](https://github.com/GradleUp) to ensure future +> development, see [#908](https://github.com/GradleUp/shadow/issues/908). > -> If you are still using the old plugin ID in your build script, we recommend to switch to the new plugin ID [`com.gradleup.shadow`](https://plugins.gradle.org/plugin/com.gradleup.shadow) +> If you are still using the old plugin ID in your build script, we recommend to switch to the new plugin ID [ +`com.gradleup.shadow`][gradleup's] > and update to the latest version to receive all the latest bug fixes and improvements. ## Documentation -Read the [User Guide](https://gradleup.com/shadow/)! +- [User Guide](https://gradleup.com/shadow/) +- [Change Log](src/docs/changes/README.md) ## Current Status [![Maven Central](https://img.shields.io/maven-central/v/com.gradleup.shadow/shadow-gradle-plugin)](https://central.sonatype.com/artifact/com.gradleup.shadow/shadow-gradle-plugin) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/com.gradleup.shadow/shadow-gradle-plugin?&server=https://oss.sonatype.org/)](https://oss.sonatype.org/content/repositories/snapshots/com/gradleup/shadow/) [![Plugin Portal](https://img.shields.io/gradle-plugin-portal/v/com.gradleup.shadow)](https://plugins.gradle.org/plugin/com.gradleup.shadow) -[![CI](https://github.com/GradleUp/shadow/actions/workflows/ci.yml/badge.svg?branch=main&event=push)](https://github.com/GradleUp/shadow/actions/workflows/ci.yml?query=branch:main+event:push) +[![CI](https://github.com/GradleUp/shadow/actions/workflows/build.yml/badge.svg?branch=main&event=push)](https://github.com/GradleUp/shadow/actions/workflows/build.yml?query=branch:main+event:push) [![License](https://img.shields.io/github/license/GradleUp/shadow.svg)](LICENSE) -## Latest Test Compatibility +## Compatibility Matrix -| Gradle Version | Shadow Version | -|----------------|----------------| -| 5.x | 5.2.0 - 6.0.0 | -| 6.x | 5.2.0 - 6.1.0 | -| 7.x | 7.0.0+ | -| 8.0 - 8.2.x | 8.0.0 - 8.1.1 | -| 8.3+ | 8.3.0+ | +| Shadow Version | Min Gradle Version | Min Java Version | Plugin ID | +|----------------|--------------------|------------------|------------------------------------------------------| +| 5.2.0 - 6.1.0 | 5.x - 6.x | 7 | [`com.github.johnrengelman.shadow`][johnrengelman's] | +| 6.1.0+ | 6.x | 8 | [`com.github.johnrengelman.shadow`][johnrengelman's] | +| 7.0.0+ | 7.x | 8 | [`com.github.johnrengelman.shadow`][johnrengelman's] | +| 8.0.0+ | 8.0 | 8 | [`com.github.johnrengelman.shadow`][johnrengelman's] | +| 8.3.0+ | 8.3 | 8 | [`com.gradleup.shadow`][gradleup's] | +| 9.0.0+ | 8.3 | 11 | [`com.gradleup.shadow`][gradleup's] | -**NOTE**: Shadow v5.+ is compatible with Gradle 5.x - 6.x and Java 7 - 15 _only_, v6.1.0+ requires Java 8+. + + +[johnrengelman's]: https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow +[gradleup's]: https://plugins.gradle.org/plugin/com.gradleup.shadow diff --git a/RELEASING.md b/RELEASING.md index 8cd3e99a3..d2e3438fc 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -7,33 +7,30 @@ 2. Add a link URL to ensure the header link works. 3. Add a new `Unreleased` section to the top. -3. Update the `README.md` so the "Download" section reflects the new release version and the - snapshot section reflects the next "SNAPSHOT" version. +3. Commit -4. Commit - - ``` - $ git commit -am "Prepare version X.Y.Z" + ```sh + git commit -am "Prepare version X.Y.Z" ``` -5. Tag +4. Tag - ``` - $ git tag -am "Version X.Y.Z" X.Y.Z + ```sh + git tag -am "Version X.Y.Z" X.Y.Z ``` -6. Update the `VERSION_NAME` in `gradle.properties` to the next "SNAPSHOT" version. +5. Update the `VERSION_NAME` in `gradle.properties` to the next "SNAPSHOT" version. -7. Commit +6. Commit - ``` - $ git commit -am "Prepare next development version" + ```sh + git commit -am "Prepare next development version" ``` -8. Push! +7. Push! - ``` - $ git push && git push --tags + ```sh + git push && git push --tags ``` This will trigger a GitHub Action workflow which will create a GitHub release and upload the diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts deleted file mode 100644 index 1622a3797..000000000 --- a/build-logic/build.gradle.kts +++ /dev/null @@ -1,15 +0,0 @@ -plugins { - `kotlin-dsl` -} - -repositories { - mavenCentral() - gradlePluginPortal() -} - -dependencies { - implementation("com.gradle.publish:plugin-publish-plugin:1.3.0") - implementation("com.vanniktech:gradle-maven-publish-plugin:0.30.0") - implementation("org.ajoberstar.git-publish:gradle-git-publish:4.2.2") - implementation("com.github.node-gradle:gradle-node-plugin:7.1.0") -} diff --git a/build-logic/src/main/kotlin/shadow.convention.deploy.gradle.kts b/build-logic/src/main/kotlin/shadow.convention.deploy.gradle.kts deleted file mode 100644 index 98c7b1ebe..000000000 --- a/build-logic/src/main/kotlin/shadow.convention.deploy.gradle.kts +++ /dev/null @@ -1,37 +0,0 @@ -import org.apache.tools.ant.filters.ReplaceTokens - -plugins { - id("org.ajoberstar.git-publish") - id("com.github.node-gradle.node") -} - -gitPublish { - repoUri = "https://github.com/GradleUp/shadow.git" - branch = "gh-pages" - contents { - from("build/site") - into("api") { - from(tasks.named("groovydoc")) - } - filter( - "tokens" to mapOf( - "version" to version, - "snapshot-version" to "$version-SNAPSHOT", - ), - ) - } -} - -node { - yarnVersion = "1.5.1" -} - -val yarnBuild = tasks.named("yarn_build") { - inputs.files(fileTree("src/docs")) - outputs.dir(file("build/site")) - dependsOn(tasks.yarn) -} - -tasks.gitPublishCopy { - dependsOn(yarnBuild, tasks.named("groovydoc")) -} diff --git a/build-logic/src/main/kotlin/shadow.convention.publish.gradle.kts b/build-logic/src/main/kotlin/shadow.convention.publish.gradle.kts deleted file mode 100644 index 6282e8c30..000000000 --- a/build-logic/src/main/kotlin/shadow.convention.publish.gradle.kts +++ /dev/null @@ -1,78 +0,0 @@ -plugins { - id("com.gradle.plugin-publish") - id("com.vanniktech.maven.publish") -} - -version = providers.gradleProperty("VERSION_NAME").get() -group = providers.gradleProperty("GROUP").get() -description = providers.gradleProperty("POM_DESCRIPTION").get() - -java { - withSourcesJar() - withJavadocJar() -} - -gradlePlugin { - website = providers.gradleProperty("POM_URL") - vcsUrl = providers.gradleProperty("POM_URL") - - plugins { - create("shadowPlugin") { - id = "com.gradleup.shadow" - implementationClass = "com.github.jengelman.gradle.plugins.shadow.ShadowPlugin" - displayName = providers.gradleProperty("POM_NAME").get() - description = providers.gradleProperty("POM_DESCRIPTION").get() - tags = listOf("onejar", "shade", "fatjar", "uberjar") - } - } -} - -tasks.publishPlugins { - doFirst { - if (version.toString().endsWith("SNAPSHOT")) { - error("Cannot publish SNAPSHOT versions to Plugin Portal!") - } - } - notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/21283") -} - -tasks.withType().configureEach { - (options as? StandardJavadocDocletOptions)?.let { - it.links( - "https://docs.oracle.com/en/java/javase/17/docs/api/", - "https://docs.groovy-lang.org/2.4.7/html/gapi/", - ) - it.addStringOption("Xdoclint:none", "-quiet") - } -} - -configurations { - listOf( - apiElements, - runtimeElements, - named("javadocElements"), - named("sourcesElements"), - ).forEach { - it.configure { - outgoing { - // Main/current capability - capability("com.gradleup.shadow:shadow-gradle-plugin:$version") - - // Historical capabilities - capability("io.github.goooler.shadow:shadow-gradle-plugin:$version") - capability("com.github.johnrengelman:shadow:$version") - capability("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:$version") - capability("gradle.plugin.com.github.johnrengelman:shadow:$version") - capability("com.github.jengelman.gradle.plugins:shadow:$version") - } - } - } -} - -publishing.publications.withType().configureEach { - // We don't care about capabilities being unmappable to Maven - suppressPomMetadataWarningsFor("apiElements") - suppressPomMetadataWarningsFor("runtimeElements") - suppressPomMetadataWarningsFor("javadocElements") - suppressPomMetadataWarningsFor("sourcesElements") -} diff --git a/build.gradle.kts b/build.gradle.kts index 1055e210d..4ec1095f0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,62 +1,106 @@ +import org.gradle.api.plugins.JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME +import org.gradle.api.plugins.JavaPlugin.JAVADOC_ELEMENTS_CONFIGURATION_NAME +import org.gradle.api.plugins.JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME +import org.gradle.api.plugins.JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME + plugins { groovy `java-gradle-plugin` - id("shadow.convention.publish") - id("shadow.convention.deploy") - id("com.diffplug.spotless") version "7.0.0.BETA4" + id("com.gradle.plugin-publish") version "1.3.1" + id("com.vanniktech.maven.publish") version "0.34.0" + id("com.diffplug.spotless") version "7.2.1" } +version = providers.gradleProperty("VERSION_NAME").get() +group = providers.gradleProperty("GROUP").get() +description = providers.gradleProperty("POM_DESCRIPTION").get() + java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } +gradlePlugin { + website = providers.gradleProperty("POM_URL") + vcsUrl = providers.gradleProperty("POM_URL") + + plugins { + create("shadowPlugin") { + id = "com.gradleup.shadow" + implementationClass = "com.github.jengelman.gradle.plugins.shadow.ShadowPlugin" + displayName = providers.gradleProperty("POM_NAME").get() + description = providers.gradleProperty("POM_DESCRIPTION").get() + tags = listOf("onejar", "shade", "fatjar", "uberjar") + } + } +} + spotless { kotlinGradle { ktlint() - target("**/*.kts") - targetExclude("build-logic/build/**") } } -dependencies { - compileOnly(localGroovy()) +configurations.configureEach { + when (name) { + API_ELEMENTS_CONFIGURATION_NAME, + RUNTIME_ELEMENTS_CONFIGURATION_NAME, + JAVADOC_ELEMENTS_CONFIGURATION_NAME, + SOURCES_ELEMENTS_CONFIGURATION_NAME, + -> { + outgoing { + // Main/current capability. + capability("com.gradleup.shadow:shadow-gradle-plugin:$version") + + // Historical capabilities. + capability("io.github.goooler.shadow:shadow-gradle-plugin:$version") + capability("com.github.johnrengelman:shadow:$version") + capability("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:$version") + capability("gradle.plugin.com.github.johnrengelman:shadow:$version") + capability("com.github.jengelman.gradle.plugins:shadow:$version") + } + } + } +} +publishing.publications.withType().configureEach { + // We don't care about capabilities being unmappable to Maven. + suppressPomMetadataWarningsFor(API_ELEMENTS_CONFIGURATION_NAME) + suppressPomMetadataWarningsFor(RUNTIME_ELEMENTS_CONFIGURATION_NAME) + suppressPomMetadataWarningsFor(JAVADOC_ELEMENTS_CONFIGURATION_NAME) + suppressPomMetadataWarningsFor(SOURCES_ELEMENTS_CONFIGURATION_NAME) +} + +dependencies { + api("org.apache.ant:ant:1.10.15") // Types from Ant are exposed in the public API. implementation("org.jdom:jdom2:2.0.6.1") - implementation("org.ow2.asm:asm-commons:9.7.1") - implementation("commons-io:commons-io:2.17.0") - implementation("org.apache.ant:ant:1.10.15") + implementation("org.ow2.asm:asm-commons:9.8") + implementation("commons-io:commons-io:2.19.0") implementation("org.codehaus.plexus:plexus-utils:4.0.2") - implementation("org.codehaus.plexus:plexus-xml:4.0.4") + implementation("org.codehaus.plexus:plexus-xml:4.1.0") implementation("org.apache.logging.log4j:log4j-core:2.24.1") - implementation("org.vafer:jdependency:2.11") + implementation("org.vafer:jdependency:2.13") - testImplementation("org.spockframework:spock-core:2.3-groovy-3.0") { + testImplementation("org.spockframework:spock-core:2.3-groovy-4.0") { exclude(group = "org.codehaus.groovy") exclude(group = "org.hamcrest") } - testImplementation("org.xmlunit:xmlunit-legacy:2.10.0") + testImplementation("org.xmlunit:xmlunit-legacy:2.10.2") testImplementation("org.apache.commons:commons-lang3:3.17.0") testImplementation("com.google.guava:guava:33.3.1-jre") - testImplementation(platform("org.junit:junit-bom:5.11.3")) + testImplementation(platform("org.junit:junit-bom:5.13.1")) testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.junit.platform:junit-platform-suite-engine") } -val isCI = providers.environmentVariable("CI").isPresent - tasks.withType().configureEach { useJUnitPlatform() - maxParallelForks = Runtime.getRuntime().availableProcessors() - - if (isCI) { - testLogging.showStandardStreams = true - minHeapSize = "1g" - maxHeapSize = "1g" + val testGradleVersion = providers.gradleProperty("testGradleVersion").orNull.let { + if (it == null || it == "current") GradleVersion.current().version else it } - - systemProperty("shadowVersion", version) + logger.lifecycle("Using test Gradle version: $testGradleVersion") + systemProperty("TEST_GRADLE_VERSION", testGradleVersion) // Required to test configuration cache in tests when using withDebug() // https://github.com/gradle/gradle/issues/22765#issuecomment-1339427241 @@ -71,11 +115,3 @@ tasks.withType().configureEach { "java.base/java.net=ALL-UNNAMED", ) } - -tasks.register("release") { - dependsOn( - tasks.publish, - tasks.publishPlugins, - tasks.gitPublishPush, - ) -} diff --git a/gradle.properties b/gradle.properties index e8d2c2537..04e7e3b4f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,21 @@ -org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx4g -XX:MaxMetaspaceSize=2g -org.gradle.parallel=true +# Omit automatic compile dependency on kotlin-stdlib +# https://kotlinlang.org/docs/gradle.html#dependency-on-the-standard-library +kotlin.stdlib.default.dependency=false + org.gradle.caching=true org.gradle.configuration-cache=true org.gradle.configuration-cache.parallel=true - +org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx4g -XX:MaxMetaspaceSize=2g +org.gradle.kotlin.dsl.allWarningsAsErrors=true +org.gradle.parallel=true GROUP=com.gradleup.shadow POM_ARTIFACT_ID=shadow-gradle-plugin -VERSION_NAME=8.3.6-SNAPSHOT +VERSION_NAME=8.3.10-SNAPSHOT -SONATYPE_AUTOMATIC_RELEASE=true -SONATYPE_HOST=DEFAULT -RELEASE_SIGNING_ENABLED=true +mavenCentralAutomaticPublishing=true +mavenCentralPublishing=true +signAllPublications=true POM_NAME=Shadow Gradle Plugin POM_DESCRIPTION=Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin. diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index a4b76b953..8bdaf60c7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 94113f200..2a84e188b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index f5feea6d6..ef07e0162 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -86,8 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s -' "$PWD" ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -115,7 +114,7 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -206,7 +205,7 @@ fi DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # and any embedded shellness will be escaped. # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # treated as '${Hostname}' itself on the command line. @@ -214,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index 9b42019c7..5eed7ee84 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -70,11 +70,11 @@ goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/settings.gradle.kts b/settings.gradle.kts index 87569ed1f..7583111ca 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,12 +3,10 @@ pluginManagement { mavenCentral() gradlePluginPortal() } - - includeBuild("build-logic") } plugins { - id("com.gradle.develocity") version "3.18.2" + id("com.gradle.develocity") version "4.0.2" } develocity { diff --git a/src/docs/changes/README.md b/src/docs/changes/README.md index d1d7af7c7..cfba8f9bd 100644 --- a/src/docs/changes/README.md +++ b/src/docs/changes/README.md @@ -3,9 +3,53 @@ ## [Unreleased] -**Removed** +**Changed** + +- Stop using start script templates bundled in Shadow. ([#1750](https://github.com/GradleUp/shadow/pull/1750)) + +**Fixed** + +- Fix resolving BOM dependencies when `minimize` is enabled. ([#1638](https://github.com/GradleUp/shadow/pull/1638)) + +## [v8.3.9] (2025-08-05) + +> [!WARNING] +> Only Gradle 9 support is being backported to this version. No additional features or crucial bug fixes will be included in the 8.x line. Please migrate to Shadow 9 as soon as possible. + +**Changed** + +- Use `BufferedOutputStream` when writing the Zip file to improve performance. ([#1579](https://github.com/GradleUp/shadow/pull/1579)) + + +## [v8.3.8] (2025-07-01) + +> [!WARNING] +> Only Gradle 9 support is being backported to this version. No additional features or crucial bug fixes will be included in the 8.x line. Please migrate to Shadow 9 as soon as possible. + +**Fixed** + +- Fix the regression of `PropertiesFileTransformer` in `8.3.7`. ([#1493](https://github.com/GradleUp/shadow/pull/1493)) + +**Changed** + +- Expose Ant as `compile` scope. ([#1488](https://github.com/GradleUp/shadow/pull/1488)) + + +## [v8.3.7] (2025-06-24) + +> [!WARNING] +> Only Gradle 9 support is being backported to this version. No additional features or crucial bug fixes will be included in the 8.x line. Please migrate to Shadow 9 as soon as possible. + +**Fixed** + +- Fix compatibility for Gradle 9.0.0 RC1. ([#1470](https://github.com/GradleUp/shadow/pull/1470)) + + +## [v8.3.6] (2025-02-02) + +**Added** -- **BREAKING CHANGE:** Remove Develocity integration. ([#1013](https://github.com/GradleUp/shadow/pull/1013)) +- Support Java 24. ([#1222](https://github.com/GradleUp/shadow/pull/1222)) ## [v8.3.5] (2024-11-03) @@ -419,7 +463,11 @@ Instead, use the `enableRelocation = true` and `relocationPrefix = " { protected void addCreateScriptsTask(Project project) { project.tasks.register(SHADOW_SCRIPTS_TASK_NAME, CreateStartScripts) { startScripts -> - startScripts.unixStartScriptGenerator.template = project.resources.text.fromString(this.class.getResource("internal/unixStartScript.txt").text) - startScripts.windowsStartScriptGenerator.template = project.resources.text.fromString(this.class.getResource("internal/windowsStartScript.txt").text) startScripts.description = 'Creates OS specific scripts to run the project as a JVM application using the shadow jar' startScripts.group = ApplicationPlugin.APPLICATION_GROUP startScripts.classpath = project.files(jar) - startScripts.conventionMapping.mainClassName = { javaApplication.mainClass.get() } + startScripts.mainClass.set(javaApplication.mainClass) startScripts.conventionMapping.applicationName = { javaApplication.applicationName } startScripts.conventionMapping.outputDir = { new File(project.layout.buildDirectory.asFile.get(), 'scriptsShadow') } startScripts.conventionMapping.defaultJvmOpts = { javaApplication.applicationDefaultJvmArgs } @@ -98,8 +96,8 @@ class ShadowApplicationPlugin implements Plugin { if (task.destinationDir.directory) { if (task.destinationDir.listFiles().size() != 0 && (!new File(task.destinationDir, 'lib').directory || !new File(task.destinationDir, 'bin').directory)) { throw new GradleException("The specified installation directory '${task.destinationDir}' is neither empty nor does it contain an installation for '${javaApplication.applicationName}'.\n" + - "If you really want to install to this directory, delete it and run the install task again.\n" + - "Alternatively, choose a different installation directory." + "If you really want to install to this directory, delete it and run the install task again.\n" + + "Alternatively, choose a different installation directory." ) } } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy index 7a904a218..47a81c9db 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy @@ -97,8 +97,8 @@ class ShadowJavaPlugin implements Plugin { } shadow.from(sourceSets.main.output) shadow.configurations = [ - project.configurations.findByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) ?: - project.configurations.runtime, + project.configurations.findByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) ?: + project.configurations.runtime, ] shadow.exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'module-info.class') } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.groovy index 63db72aab..b3e8b88ea 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPlugin.groovy @@ -25,6 +25,33 @@ class ShadowPlugin implements Plugin { // etc. if the user applies shadow before those plugins. However, this is fine, because this was also // the behavior with the old plugin when applying in that order. plugins.apply(LegacyShadowPlugin) + + boolean enableDevelocityIntegration = providers.gradleProperty( + "com.gradleup.shadow.enableDevelocityIntegration" + ).map { it.toBoolean() }.getOrElse(false) + if (enableDevelocityIntegration) { + // Legacy build scan support for Gradle Enterprise, users should migrate to develocity plugin. + rootProject.plugins.withId('com.gradle.enterprise') { + configureBuildScan(rootProject) + } + rootProject.plugins.withId('com.gradle.develocity') { + configureBuildScan(rootProject) + } + } + } + } + + private void configureBuildScan(Project rootProject) { + rootProject.buildScan.buildFinished { + def shadowTasks = tasks.withType(ShadowJar) + shadowTasks.each { task -> + if (task.didWork) { + task.stats.buildScanData.each { k, v -> + rootProject.buildScan.value "shadow.${task.path}.${k}", v.toString() + } + rootProject.buildScan.value "shadow.${task.path}.configurations", task.configurations*.name.join(", ") + } + } } } } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowStats.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowStats.groovy index 8813dc61b..31cc56ee9 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowStats.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowStats.groovy @@ -19,7 +19,7 @@ class ShadowStats { String getRelocationString() { def maxLength = relocations.keySet().collect { it.length() }.max() - relocations.collect { k, v -> "${k} ${separator(k, maxLength)} ${v}"}.sort().join("\n") + relocations.collect { k, v -> "${k} ${separator(k, maxLength)} ${v}" }.sort().join("\n") } static String separator(String key, int max) { @@ -60,7 +60,7 @@ class ShadowStats { double getAverageTimeSecsPerJar() { averageTimePerJar / 1000 } - + String toString() { StringBuilder sb = new StringBuilder() sb.append "*******************\n" @@ -74,8 +74,8 @@ class ShadowStats { Map getBuildScanData() { [ - dependencies: jarCount, - relocations : relocationString, + dependencies: jarCount, + relocations : relocationString, ] as Map } } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.groovy index 5e23269e4..31fafab21 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.groovy @@ -24,6 +24,7 @@ import com.github.jengelman.gradle.plugins.shadow.relocation.RelocateClassContex import com.github.jengelman.gradle.plugins.shadow.relocation.RelocatePathContext import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction.RelativeArchivePath +import groovy.transform.CompileStatic import org.objectweb.asm.commons.Remapper import java.util.regex.Matcher @@ -34,6 +35,7 @@ import java.util.regex.Pattern * * @author John Engelman */ +@CompileStatic class RelocatorRemapper extends Remapper { private final Pattern classPattern = Pattern.compile("(\\[*)?L(.+)") diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/AbstractDependencyFilter.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/AbstractDependencyFilter.groovy index 3232a9af9..2e401301b 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/AbstractDependencyFilter.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/AbstractDependencyFilter.groovy @@ -105,8 +105,8 @@ abstract class AbstractDependencyFilter implements DependencyFilter { Spec dependency(Dependency dependency) { this.dependency({ ResolvedDependency it -> (!dependency.group || it.moduleGroup.matches(dependency.group)) && - (!dependency.name || it.moduleName.matches(dependency.name)) && - (!dependency.version || it.moduleVersion.matches(dependency.version)) + (!dependency.name || it.moduleName.matches(dependency.name)) && + (!dependency.version || it.moduleVersion.matches(dependency.version)) }) } @@ -117,7 +117,7 @@ abstract class AbstractDependencyFilter implements DependencyFilter { */ @Override Spec dependency(Closure spec) { - return Specs.convertClosureToSpec(spec) + return Specs. convertClosureToSpec(spec) } protected boolean isIncluded(ResolvedDependency dependency) { diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/CleanProperties.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/CleanProperties.groovy index b54b5271b..b94a779cc 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/CleanProperties.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/CleanProperties.groovy @@ -1,5 +1,8 @@ package com.github.jengelman.gradle.plugins.shadow.internal +import groovy.transform.CompileStatic + +@CompileStatic class CleanProperties extends Properties { private static class StripCommentsWithTimestampBufferedWriter extends BufferedWriter { @@ -22,8 +25,8 @@ class CleanProperties extends Properties { private boolean couldBeCommentWithTimestamp(final String str) { return str != null && - str.startsWith("#") && - str.length() == lengthOfExpectedTimestamp + str.startsWith("#") && + str.length() == lengthOfExpectedTimestamp } } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy index a2248e6a2..103d46de3 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy @@ -17,13 +17,12 @@ package com.github.jengelman.gradle.plugins.shadow.internal import org.apache.tools.zip.Zip64Mode import org.apache.tools.zip.ZipOutputStream -import org.gradle.api.UncheckedIOException class DefaultZipCompressor implements ZipCompressor { private final int entryCompressionMethod private final Zip64Mode zip64Mode - DefaultZipCompressor(boolean allowZip64Mode, int entryCompressionMethod) { + DefaultZipCompressor(boolean allowZip64Mode, int entryCompressionMethod) { this.entryCompressionMethod = entryCompressionMethod zip64Mode = allowZip64Mode ? Zip64Mode.AsNeeded : Zip64Mode.Never } @@ -31,7 +30,10 @@ class DefaultZipCompressor implements ZipCompressor { @Override ZipOutputStream createArchiveOutputStream(File destination) { try { - ZipOutputStream zipOutputStream = new ZipOutputStream(destination) + ZipOutputStream zipOutputStream = entryCompressionMethod == ZipOutputStream.STORED ? + new ZipOutputStream(destination) : + // It is not possible to do this with STORED entries as the implementation requires a RandomAccessFile to update the CRC after write. + new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(destination))) zipOutputStream.setUseZip64(zip64Mode) zipOutputStream.setMethod(entryCompressionMethod) return zipOutputStream diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/JavaJarExec.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/JavaJarExec.groovy index 2affa9fbe..28ed02308 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/JavaJarExec.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/JavaJarExec.groovy @@ -4,7 +4,7 @@ import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.TaskAction -class JavaJarExec extends JavaExec { +abstract class JavaJarExec extends JavaExec { @InputFile File jarFile diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/MinimizeDependencyFilter.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/MinimizeDependencyFilter.groovy index 4853c3a77..d38d40ae2 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/MinimizeDependencyFilter.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/MinimizeDependencyFilter.groovy @@ -6,7 +6,7 @@ import org.gradle.api.artifacts.ResolvedDependency @Slf4j class MinimizeDependencyFilter extends AbstractDependencyFilter { - + MinimizeDependencyFilter(Project project) { super(project) } @@ -26,4 +26,4 @@ class MinimizeDependencyFilter extends AbstractDependencyFilter { private static boolean isParentExcluded(Set excludedDependencies, ResolvedDependency dependency) { excludedDependencies.any { dependency.parents.contains(it) } } -} \ No newline at end of file +} diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/RelocationUtil.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/RelocationUtil.groovy index f94ab89ed..43d1b855f 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/RelocationUtil.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/RelocationUtil.groovy @@ -1,6 +1,7 @@ package com.github.jengelman.gradle.plugins.shadow.internal import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + import java.util.jar.JarFile class RelocationUtil { @@ -12,7 +13,10 @@ class RelocationUtil { JarFile jf = new JarFile(jar) jf.entries().each { entry -> if (entry.name.endsWith(".class") && entry.name != "module-info.class") { - packages << entry.name[0..entry.name.lastIndexOf('/') - 1].replaceAll('/', '.') + def i = entry.name.lastIndexOf('/') + if (i != -1) { + packages << entry.name.take(i).replaceAll('/', '.') + } } } jf.close() diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/UnusedTracker.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/UnusedTracker.groovy index fcfbe6ea1..16968b9c0 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/UnusedTracker.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/UnusedTracker.groovy @@ -3,10 +3,11 @@ package com.github.jengelman.gradle.plugins.shadow.internal import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Dependency +import org.gradle.api.artifacts.FileCollectionDependency import org.gradle.api.artifacts.ProjectDependency -import org.gradle.api.artifacts.SelfResolvingDependency import org.gradle.api.file.FileCollection import org.gradle.api.tasks.InputFiles +import org.gradle.util.GradleVersion import org.vafer.jdependency.Clazz import org.vafer.jdependency.Clazzpath import org.vafer.jdependency.ClazzpathUnit @@ -52,7 +53,7 @@ class UnusedTracker { def dependencyName = dep.name return (fileName == "${dependencyName}.jar") || - (fileName.startsWith("${dependencyName}-") && fileName.endsWith('.jar')) + (fileName.startsWith("${dependencyName}-") && fileName.endsWith('.jar')) } private static void addJar(Configuration config, Dependency dep, List result) { @@ -70,16 +71,29 @@ class UnusedTracker { def apiJars = new LinkedList() apiDependencies.each { dep -> if (dep instanceof ProjectDependency) { - apiJars.addAll(getApiJarsFromProject(dep.dependencyProject)) + apiJars.addAll(getApiJarsFromProject(dependencyProjectCompat(dep, project))) addJar(runtimeConfiguration, dep, apiJars) - } else if (dep instanceof SelfResolvingDependency) { - apiJars.addAll(dep.resolve()) + } else if (dep instanceof FileCollectionDependency) { + apiJars.addAll(dep.files) } else { addJar(runtimeConfiguration, dep, apiJars) - apiJars.add(runtimeConfiguration.find { it.name.startsWith("${dep.name}-") } as File) + def jarFile = runtimeConfiguration.find { it.name.startsWith("${dep.name}-") } + if (jarFile != null) { + apiJars.add(jarFile) + } } } return project.files(apiJars) } + + /** + * TODO: this could be removed after bumping the min Gradle requirement to 8.11 or above. + */ + private static dependencyProjectCompat(ProjectDependency projectDependency, Project project) { + if (GradleVersion.current() >= GradleVersion.version("8.11")) { + return project.project(projectDependency.path) + } + return projectDependency.dependencyProject + } } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocator.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocator.groovy index 4f4ec7688..90e3e7234 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocator.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocator.groovy @@ -46,7 +46,7 @@ class SimpleRelocator implements Relocator { private final Set includes private final Set excludes - + private final boolean rawString SimpleRelocator() { @@ -58,7 +58,7 @@ class SimpleRelocator implements Relocator { } SimpleRelocator(String patt, String shadedPattern, List includes, List excludes, - boolean rawString) { + boolean rawString) { this.rawString = rawString if (rawString) { @@ -170,7 +170,7 @@ class SimpleRelocator implements Relocator { // Allow for annoying option of an extra / on the front of a path. See MSHADE-119 comes from getClass().getResource("/a/b/c.properties"). boolean pathStartsWithPattern = - path.charAt(0) == '/' ? path.startsWith(pathPattern, 1) : path.startsWith(pathPattern) + path.charAt(0) == '/' ? path.startsWith(pathPattern, 1) : path.startsWith(pathPattern) if (pathStartsWithPattern) { return isIncluded(path) && !isExcluded(path) } @@ -180,8 +180,8 @@ class SimpleRelocator implements Relocator { @Override boolean canRelocateClass(String className) { return !rawString && - className.indexOf('/') < 0 && - canRelocatePath(className.replace('.', '/')) + className.indexOf('/') < 0 && + canRelocatePath(className.replace('.', '/')) } @Override diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy index 128dc3cce..3fb9eaef4 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy @@ -17,7 +17,6 @@ import org.apache.tools.zip.ZipFile import org.apache.tools.zip.ZipOutputStream import org.gradle.api.Action import org.gradle.api.GradleException -import org.gradle.api.UncheckedIOException import org.gradle.api.file.FileCopyDetails import org.gradle.api.file.FilePermissions import org.gradle.api.file.FileTreeElement @@ -460,7 +459,7 @@ class ShadowCopyAction implements CopyAction { return null } else { //Parent is always a directory so add / to the end of the path - String path = segments[0..-2].join('/') + '/' + String path = segments.take(segments.length - 1).join('/') + '/' return new RelativeArchivePath(setArchiveTimes(new ZipEntry(path))) } } @@ -528,7 +527,9 @@ class ShadowCopyAction implements CopyAction { return archivePath } - @Override + /** + * This method should be annotated with @Override, but the parent has been removed from Gradle 9. + */ int getMode() { return archivePath.entry.unixMode } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java index dc4cfe9e3..bc25af4f7 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.java @@ -1,11 +1,22 @@ package com.github.jengelman.gradle.plugins.shadow.tasks; import com.github.jengelman.gradle.plugins.shadow.ShadowStats; -import com.github.jengelman.gradle.plugins.shadow.internal.*; +import com.github.jengelman.gradle.plugins.shadow.internal.DefaultDependencyFilter; +import com.github.jengelman.gradle.plugins.shadow.internal.DependencyFilter; +import com.github.jengelman.gradle.plugins.shadow.internal.GradleVersionUtil; +import com.github.jengelman.gradle.plugins.shadow.internal.MinimizeDependencyFilter; +import com.github.jengelman.gradle.plugins.shadow.internal.RelocationUtil; +import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker; +import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor; import com.github.jengelman.gradle.plugins.shadow.relocation.CacheableRelocator; import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator; import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator; -import com.github.jengelman.gradle.plugins.shadow.transformers.*; +import com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer; +import com.github.jengelman.gradle.plugins.shadow.transformers.CacheableTransformer; +import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer; +import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer; +import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer; + import org.gradle.api.Action; import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.DuplicatesStrategy; @@ -13,7 +24,18 @@ import org.gradle.api.internal.DocumentationRegistry; import org.gradle.api.internal.file.FileResolver; import org.gradle.api.internal.file.copy.CopyAction; -import org.gradle.api.tasks.*; +import org.gradle.api.tasks.CacheableTask; +import org.gradle.api.tasks.Classpath; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFiles; +import org.gradle.api.tasks.Internal; +import org.gradle.api.tasks.Nested; +import org.gradle.api.tasks.Optional; +import org.gradle.api.tasks.PathSensitive; +import org.gradle.api.tasks.PathSensitivity; +import org.gradle.api.tasks.SourceSet; +import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.bundling.Jar; import org.gradle.api.tasks.util.PatternSet; import org.jetbrains.annotations.NotNull; @@ -25,7 +47,7 @@ import java.util.concurrent.Callable; @CacheableTask -public class ShadowJar extends Jar implements ShadowSpec { +public abstract class ShadowJar extends Jar implements ShadowSpec { private List transformers; private List relocators; @@ -107,16 +129,16 @@ protected CopyAction createCopyAction() { DocumentationRegistry documentationRegistry = getServices().get(DocumentationRegistry.class); final UnusedTracker unusedTracker = minimizeJar ? UnusedTracker.forProject(getApiJars(), getSourceSetsClassesDirs().getFiles(), getToMinimize()) : null; return new ShadowCopyAction(getArchiveFile().get().getAsFile(), getInternalCompressor(), documentationRegistry, - this.getMetadataCharset(), transformers, relocators, getRootPatternSet(), shadowStats, - isPreserveFileTimestamps(), minimizeJar, unusedTracker); + this.getMetadataCharset(), transformers, relocators, getRootPatternSet(), shadowStats, + isPreserveFileTimestamps(), minimizeJar, unusedTracker); } @Classpath FileCollection getToMinimize() { if (toMinimize == null) { toMinimize = minimizeJar - ? dependencyFilterForMinimize.resolve(configurations).minus(getApiJars()) - : getProject().getObjects().fileCollection(); + ? dependencyFilterForMinimize.resolve(configurations).minus(getApiJars()) + : getProject().getObjects().fileCollection(); } return toMinimize; } @@ -126,8 +148,8 @@ FileCollection getToMinimize() { FileCollection getApiJars() { if (apiJars == null) { apiJars = minimizeJar - ? UnusedTracker.getApiJarsFromProject(getProject()) - : getProject().getObjects().fileCollection(); + ? UnusedTracker.getApiJarsFromProject(getProject()) + : getProject().getObjects().fileCollection(); } return apiJars; } @@ -209,7 +231,7 @@ public ShadowJar transform(Class clazz) throws Instantiat * Add a Transformer instance for modifying JAR resources and configure. * * @param clazz the transformer class to add. Must have no-arg constructor - * @param c the configuration for the transformer + * @param c the configuration for the transformer * @return this */ @Override @@ -321,7 +343,7 @@ public ShadowJar append(final String resourcePath) { /** * Add a class relocator that maps each class in the pattern to the provided destination. * - * @param pattern the source pattern to relocate + * @param pattern the source pattern to relocate * @param destination the destination package * @return this */ @@ -333,9 +355,9 @@ public ShadowJar relocate(String pattern, String destination) { /** * Add a class relocator that maps each class in the pattern to the provided destination. * - * @param pattern the source pattern to relocate + * @param pattern the source pattern to relocate * @param destination the destination package - * @param configure the configuration of the relocator + * @param configure the configuration of the relocator * @return this */ @Override @@ -380,7 +402,7 @@ private void addRelocator(R relocator, Action configure * Add a relocator of the provided class and configure. * * @param relocatorClass the relocator class to add. Must have a no-arg constructor - * @param configure the configuration for the relocator + * @param configure the configuration for the relocator * @return this */ @Override @@ -412,7 +434,8 @@ public void setRelocators(List relocators) { this.relocators = relocators; } - @Classpath @Optional + @Classpath + @Optional public List getConfigurations() { return this.configurations; } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.java b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.java index cc86e4e5c..0d1d853b7 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.java +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowSpec.java @@ -6,6 +6,7 @@ import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator; import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer; import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer; + import org.gradle.api.Action; import org.gradle.api.file.CopySpec; diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheLicenseResourceTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheLicenseResourceTransformer.groovy index 569066ae1..42d16e2bd 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheLicenseResourceTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheLicenseResourceTransformer.groovy @@ -39,7 +39,7 @@ class ApacheLicenseResourceTransformer implements Transformer { boolean canTransformResource(FileTreeElement element) { def path = element.relativePath.pathString return LICENSE_PATH.equalsIgnoreCase(path) || - LICENSE_TXT_PATH.regionMatches(true, 0, path, 0, LICENSE_TXT_PATH.length()) + LICENSE_TXT_PATH.regionMatches(true, 0, path, 0, LICENSE_TXT_PATH.length()) } @Override diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformer.groovy index 77ef87fbc..f7a8add39 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformer.groovy @@ -49,8 +49,8 @@ class ApacheNoticeResourceTransformer implements Transformer { @Input String preamble1 = "// ------------------------------------------------------------------\n" + - "// NOTICE file corresponding to the section 4d of The Apache License,\n" + - "// Version 2.0, in this case for " + "// NOTICE file corresponding to the section 4d of The Apache License,\n" + + "// Version 2.0, in this case for " @Input String preamble2 = "\n// ------------------------------------------------------------------\n" @@ -130,7 +130,7 @@ class ApacheNoticeResourceTransformer implements Transformer { if (trimedLine.startsWith("- ")) { //resource-bundle 1.3 mode if (lineCount == 1 - && sb.toString().indexOf("This product includes/uses software(s) developed by") != -1) { + && sb.toString().indexOf("This product includes/uses software(s) developed by") != -1) { currentOrg = organizationEntries.get(sb.toString().trim()) if (currentOrg == null) { currentOrg = new TreeSet() diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ComponentsXmlResourceTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ComponentsXmlResourceTransformer.groovy index 58483d3cf..f0024c68e 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ComponentsXmlResourceTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ComponentsXmlResourceTransformer.groovy @@ -57,7 +57,7 @@ class ComponentsXmlResourceTransformer implements Transformer { try { BufferedInputStream bis = new BufferedInputStream(context.is) { void close() - throws IOException { + throws IOException { // leave ZIP open } } @@ -136,7 +136,7 @@ class ComponentsXmlResourceTransformer implements Transformer { } private byte[] getTransformedResource() - throws IOException { + throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024 * 4) try (Writer writer = new XmlStreamWriter(baos)) { diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer.groovy index 62255f3df..d378a9cd3 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer.groovy @@ -43,9 +43,9 @@ import org.gradle.api.file.FileTreeElement class GroovyExtensionModuleTransformer implements Transformer { private static final GROOVY_LEGACY_EXTENSION_MODULE_DESCRIPTOR_PATH = - "META-INF/services/org.codehaus.groovy.runtime.ExtensionModule" + "META-INF/services/org.codehaus.groovy.runtime.ExtensionModule" private static final GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH = - "META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule" + "META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule" private static final MODULE_NAME_KEY = 'moduleName' private static final MODULE_VERSION_KEY = 'moduleVersion' diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.groovy index 044e3dbaa..a8e5dc58c 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.groovy @@ -136,7 +136,10 @@ class PropertiesFileTransformer implements Transformer { String charset = 'ISO_8859_1' @Internal - Closure keyTransformer = IDENTITY + Closure keyTransformer = new Closure("") { + String doCall(Object arguments) { arguments } + // We can't use Closure#IDENTITY instead, as it is not compatible with Groovy 3 and 4. + } @Override boolean canTransformResource(FileTreeElement element) { @@ -192,6 +195,9 @@ class PropertiesFileTransformer implements Transformer { } private Properties transformKeys(Properties properties) { + if (keyTransformer == null) { + throw new IllegalStateException("keyTransformer must not be null.") + } if (keyTransformer == IDENTITY) { return properties } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformer.groovy index b2153a3f9..7c19c1ae5 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformer.groovy @@ -23,12 +23,12 @@ import com.github.jengelman.gradle.plugins.shadow.relocation.RelocateClassContex import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction import org.apache.tools.zip.ZipEntry import org.apache.tools.zip.ZipOutputStream +import org.codehaus.plexus.util.IOUtil import org.gradle.api.file.FileTreeElement import org.gradle.api.specs.Spec import org.gradle.api.tasks.Input import org.gradle.api.tasks.util.PatternFilterable import org.gradle.api.tasks.util.PatternSet -import org.codehaus.plexus.util.IOUtil /** * Modified from org.apache.maven.plugins.shade.resource.ServiceResourceTransformer.java @@ -49,12 +49,12 @@ class ServiceFileTransformer implements Transformer, PatternFilterable { private static final String SERVICES_PATTERN = "META-INF/services/**" private static final String GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATTERN = - "META-INF/services/org.codehaus.groovy.runtime.ExtensionModule" + "META-INF/services/org.codehaus.groovy.runtime.ExtensionModule" private Map serviceEntries = [:].withDefault { new ServiceStream() } private final PatternSet patternSet = - new PatternSet().include(SERVICES_PATTERN).exclude(GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATTERN) + new PatternSet().include(SERVICES_PATTERN).exclude(GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATTERN) void setPath(String path) { patternSet.setIncludes(["${path}/**"]) @@ -70,7 +70,7 @@ class ServiceFileTransformer implements Transformer, PatternFilterable { void transform(TransformerContext context) { def lines = context.is.readLines() def targetPath = context.path - context.relocators.each {rel -> + context.relocators.each { rel -> if (rel.canRelocateClass(new File(targetPath).name)) { targetPath = rel.relocateClass(RelocateClassContext.builder().className(targetPath).stats(context.stats).build()) } @@ -81,7 +81,7 @@ class ServiceFileTransformer implements Transformer, PatternFilterable { } } } - lines.each {line -> serviceEntries[targetPath].append(new ByteArrayInputStream(line.getBytes()))} + lines.each { line -> serviceEntries[targetPath].append(new ByteArrayInputStream(line.getBytes())) } } @Override @@ -102,12 +102,12 @@ class ServiceFileTransformer implements Transformer, PatternFilterable { static class ServiceStream extends ByteArrayOutputStream { - ServiceStream(){ - super( 1024 ) + ServiceStream() { + super(1024) } - void append(InputStream is ) throws IOException { - if ( super.count > 0 && super.buf[super.count - 1] != '\n' && super.buf[super.count - 1] != '\r' ) { + void append(InputStream is) throws IOException { + if (super.count > 0 && super.buf[super.count - 1] != '\n' && super.buf[super.count - 1] != '\r') { byte[] newline = '\n'.bytes write(newline, 0, newline.length) } @@ -115,7 +115,7 @@ class ServiceFileTransformer implements Transformer, PatternFilterable { } InputStream toInputStream() { - return new ByteArrayInputStream( super.buf, 0, super.count ) + return new ByteArrayInputStream(super.buf, 0, super.count) } } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer.groovy index 76e12f06d..4d7efad8e 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer.groovy @@ -76,7 +76,7 @@ class XmlAppendingTransformer implements Transformer { if (ignoreDtd) { builder.setEntityResolver(new EntityResolver() { InputSource resolveEntity(String publicId, String systemId) - throws SAXException, IOException { + throws SAXException, IOException { return new InputSource(new StringReader("")) } }) diff --git a/src/main/resources/com/github/jengelman/gradle/plugins/shadow/internal/unixStartScript.txt b/src/main/resources/com/github/jengelman/gradle/plugins/shadow/internal/unixStartScript.txt deleted file mode 100644 index 83526b7f4..000000000 --- a/src/main/resources/com/github/jengelman/gradle/plugins/shadow/internal/unixStartScript.txt +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -## -## ${applicationName} start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: \$0 may be a link -PRG="\$0" -# Need this for relative symlinks. -while [ -h "\$PRG" ] ; do - ls=`ls -ld "\$PRG"` - link=`expr "\$ls" : '.*-> \\(.*\\)\$'` - if expr "\$link" : '/.*' > /dev/null; then - PRG="\$link" - else - PRG=`dirname "\$PRG"`"/\$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"\$PRG\"`/${appHomeRelativePath}" >/dev/null -APP_HOME="`pwd -P`" -cd "\$SAVED" >/dev/null - -APP_NAME="${applicationName}" -APP_BASE_NAME=`basename "\$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script. -DEFAULT_JVM_OPTS=${defaultJvmOpts} - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "\$*" -} - -die () { - echo - echo "\$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$classpath - -# Determine the Java command to use to start the JVM. -if [ -n "\$JAVA_HOME" ] ; then - if [ -x "\$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="\$JAVA_HOME/jre/sh/java" - else - JAVACMD="\$JAVA_HOME/bin/java" - fi - if [ ! -x "\$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: \$JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "\$cygwin" = "false" -a "\$darwin" = "false" -a "\$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ \$? -eq 0 ] ; then - if [ "\$MAX_FD" = "maximum" -o "\$MAX_FD" = "max" ] ; then - MAX_FD="\$MAX_FD_LIMIT" - fi - ulimit -n \$MAX_FD - if [ \$? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: \$MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: \$MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if \$darwin; then - GRADLE_OPTS="\$GRADLE_OPTS \\"-Xdock:name=\$APP_NAME\\" \\"-Xdock:icon=\$APP_HOME/media/gradle.icns\\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "\$cygwin" = "true" -o "\$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "\$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "\$CLASSPATH"` - JAVACMD=`cygpath --unix "\$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in \$ROOTDIRSRAW ; do - ROOTDIRS="\$ROOTDIRS\$SEP\$dir" - SEP="|" - done - OURCYGPATTERN="(^(\$ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "\$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="\$OURCYGPATTERN|(\$GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "\$@" ; do - CHECK=`echo "\$arg"|egrep -c "\$OURCYGPATTERN" -` - CHECK2=`echo "\$arg"|egrep -c "^-"` ### Determine if an option - - if [ \$CHECK -ne 0 ] && [ \$CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args\$i`=`cygpath --path --ignore --mixed "\$arg"` - else - eval `echo args\$i`="\"\$arg\"" - fi - i=`expr \$i + 1` - done - case \$i in - 0) set -- ;; - 1) set -- "\$args0" ;; - 2) set -- "\$args0" "\$args1" ;; - 3) set -- "\$args0" "\$args1" "\$args2" ;; - 4) set -- "\$args0" "\$args1" "\$args2" "\$args3" ;; - 5) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" ;; - 6) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" ;; - 7) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" ;; - 8) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" "\$args7" ;; - 9) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" "\$args7" "\$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\\\n "\$i" | sed "s/'/'\\\\\\\\''/g;1s/^/'/;\\\$s/\\\$/' \\\\\\\\/" ; done - echo " " -} -APP_ARGS=`save "\$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- \$DEFAULT_JVM_OPTS \$JAVA_OPTS \$${optsEnvironmentVar} <% if ( appNameSystemProperty ) { %>"\"-D${appNameSystemProperty}=\$APP_BASE_NAME\"" <% } %>-jar "\"\$CLASSPATH\"" "\$APP_ARGS" - -exec "\$JAVACMD" "\$@" \ No newline at end of file diff --git a/src/main/resources/com/github/jengelman/gradle/plugins/shadow/internal/windowsStartScript.txt b/src/main/resources/com/github/jengelman/gradle/plugins/shadow/internal/windowsStartScript.txt deleted file mode 100644 index 71f72e7e3..000000000 --- a/src/main/resources/com/github/jengelman/gradle/plugins/shadow/internal/windowsStartScript.txt +++ /dev/null @@ -1,85 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem ${applicationName} startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=.\ - -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME%${appHomeRelativePath} - -@rem Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script. -set DEFAULT_JVM_OPTS=${defaultJvmOpts} - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=$classpath - -@rem Execute ${applicationName} -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %${optsEnvironmentVar}% <% if ( appNameSystemProperty ) { %>"-D${appNameSystemProperty}=%APP_BASE_NAME%"<% } %> -jar "%CLASSPATH%" %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable ${exitEnvironmentVar} if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%${exitEnvironmentVar}%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega \ No newline at end of file diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy index 00f2c51fc..724d74e2e 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ApplicationSpec.groovy @@ -13,9 +13,9 @@ class ApplicationSpec extends PluginSpecification { def 'integration with application plugin'() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() file('src/main/java/myapp/Main.java') << """ package myapp; @@ -32,11 +32,11 @@ class ApplicationSpec extends PluginSpecification { application { mainClass = 'myapp.Main' } - + dependencies { implementation 'shadow:a:1.0' } - + runShadow { args 'foo' } @@ -66,7 +66,6 @@ class ApplicationSpec extends PluginSpecification { File startScript = getFile('build/install/myapp-shadow/bin/myapp') assert startScript.exists() assert startScript.text.contains("CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar") - assert startScript.text.contains("-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"") assert startScript.text.contains("exec \"\$JAVACMD\" \"\$@\"") cleanup: @@ -76,9 +75,9 @@ class ApplicationSpec extends PluginSpecification { def 'integration with application plugin and java toolchains'() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() file('src/main/java/myapp/Main.java') << """ package myapp; @@ -91,35 +90,35 @@ class ApplicationSpec extends PluginSpecification { buildFile << """ apply plugin: 'application' - + application { mainClass = 'myapp.Main' } - + dependencies { implementation 'shadow:a:1.0' } - + java { toolchain { languageVersion = JavaLanguageVersion.of(17) } } - + runShadow { args 'foo' doFirst { logger.lifecycle("Running application with JDK \${it.javaLauncher.get().metadata.languageVersion.asInt()}") } - } + } """.stripIndent() - settingsFile.write """ + settingsFile.write """ plugins { // https://docs.gradle.org/8.0.1/userguide/toolchains.html#sub:download_repositories id("org.gradle.toolchains.foojay-resolver-convention") version("0.7.0") } - + rootProject.name = 'myapp' """.stripIndent() @@ -146,7 +145,6 @@ class ApplicationSpec extends PluginSpecification { File startScript = getFile('build/install/myapp-shadow/bin/myapp') assert startScript.exists() assert startScript.text.contains("CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar") - assert startScript.text.contains("-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"") assert startScript.text.contains("exec \"\$JAVACMD\" \"\$@\"") cleanup: @@ -157,9 +155,9 @@ class ApplicationSpec extends PluginSpecification { def 'shadow application distributions should use shadow jar'() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() file('src/main/java/myapp/Main.java') << """ package myapp; @@ -176,11 +174,11 @@ class ApplicationSpec extends PluginSpecification { application { mainClass = 'myapp.Main' } - + dependencies { shadow 'shadow:a:1.0' } - + runShadow { args 'foo' } @@ -209,9 +207,9 @@ class ApplicationSpec extends PluginSpecification { def 'installShadow does not execute dependent shadow task'() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() file('src/main/java/myapp/Main.java') << """ package myapp; @@ -228,11 +226,11 @@ class ApplicationSpec extends PluginSpecification { application { mainClass = 'myapp.Main' } - + dependencies { implementation 'shadow:a:1.0' } - + runShadow { args 'foo' } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.groovy index f05a6170b..9bb5ef2a0 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.groovy @@ -7,12 +7,12 @@ class ConfigurationCacheSpec extends PluginSpecification { @Override def setup() { repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() + .insertFile('b.properties', 'b') + .publish() buildFile << """ dependencies { @@ -39,11 +39,11 @@ class ConfigurationCacheSpec extends PluginSpecification { application { mainClass = 'myapp.Main' } - + dependencies { implementation 'shadow:a:1.0' } - + runShadow { args 'foo' } @@ -93,7 +93,7 @@ class ConfigurationCacheSpec extends PluginSpecification { """.stripIndent() file('client/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' } """.stripIndent() @@ -112,7 +112,7 @@ class ConfigurationCacheSpec extends PluginSpecification { } } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':client') } """.stripIndent() @@ -127,8 +127,8 @@ class ConfigurationCacheSpec extends PluginSpecification { then: output.exists() contains(output, [ - 'server/Server.class', - 'junit/framework/Test.class' + 'server/Server.class', + 'junit/framework/Test.class' ]) doesNotContain(output, ['client/Client.class']) @@ -151,7 +151,7 @@ class ConfigurationCacheSpec extends PluginSpecification { apply plugin: 'java' apply plugin: 'com.gradleup.shadow' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation "junit:junit:3.8.2" } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigureShadowRelocationSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigureShadowRelocationSpec.groovy index bcb1a6981..2c5af9c15 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigureShadowRelocationSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ConfigureShadowRelocationSpec.groovy @@ -9,7 +9,7 @@ class ConfigureShadowRelocationSpec extends PluginSpecification { given: buildFile << """ tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { - enableRelocation true + enableRelocation = true } dependencies { @@ -22,22 +22,22 @@ class ConfigureShadowRelocationSpec extends PluginSpecification { then: contains(output, [ - 'META-INF/MANIFEST.MF', - 'shadow/junit/textui/ResultPrinter.class', - 'shadow/junit/textui/TestRunner.class', - 'shadow/junit/framework/Assert.class', - 'shadow/junit/framework/AssertionFailedError.class', - 'shadow/junit/framework/ComparisonCompactor.class', - 'shadow/junit/framework/ComparisonFailure.class', - 'shadow/junit/framework/Protectable.class', - 'shadow/junit/framework/Test.class', - 'shadow/junit/framework/TestCase.class', - 'shadow/junit/framework/TestFailure.class', - 'shadow/junit/framework/TestListener.class', - 'shadow/junit/framework/TestResult$1.class', - 'shadow/junit/framework/TestResult.class', - 'shadow/junit/framework/TestSuite$1.class', - 'shadow/junit/framework/TestSuite.class' + 'META-INF/MANIFEST.MF', + 'shadow/junit/textui/ResultPrinter.class', + 'shadow/junit/textui/TestRunner.class', + 'shadow/junit/framework/Assert.class', + 'shadow/junit/framework/AssertionFailedError.class', + 'shadow/junit/framework/ComparisonCompactor.class', + 'shadow/junit/framework/ComparisonFailure.class', + 'shadow/junit/framework/Protectable.class', + 'shadow/junit/framework/Test.class', + 'shadow/junit/framework/TestCase.class', + 'shadow/junit/framework/TestFailure.class', + 'shadow/junit/framework/TestListener.class', + 'shadow/junit/framework/TestResult$1.class', + 'shadow/junit/framework/TestResult.class', + 'shadow/junit/framework/TestSuite$1.class', + 'shadow/junit/framework/TestSuite.class' ]) } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy index 7958c3656..970e33e8b 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/FilteringSpec.groovy @@ -11,12 +11,12 @@ class FilteringSpec extends PluginSpecification { @Override def setup() { repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() + .insertFile('b.properties', 'b') + .publish() buildFile << """ dependencies { @@ -58,19 +58,19 @@ class FilteringSpec extends PluginSpecification { def "exclude dependency"() { given: repo.module('shadow', 'c', '1.0') - .insertFile('c.properties', 'c') - .publish() + .insertFile('c.properties', 'c') + .publish() repo.module('shadow', 'd', '1.0') - .insertFile('d.properties', 'd') - .dependsOn('c') - .publish() + .insertFile('d.properties', 'd') + .dependsOn('c') + .publish() buildFile << ''' // tag::excludeDep[] dependencies { implementation 'shadow:d:1.0' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { dependencies { exclude(dependency('shadow:d:1.0')) @@ -93,19 +93,19 @@ class FilteringSpec extends PluginSpecification { def "exclude dependency using wildcard syntax"() { given: repo.module('shadow', 'c', '1.0') - .insertFile('c.properties', 'c') - .publish() + .insertFile('c.properties', 'c') + .publish() repo.module('shadow', 'd', '1.0') - .insertFile('d.properties', 'd') - .dependsOn('c') - .publish() + .insertFile('d.properties', 'd') + .dependsOn('c') + .publish() buildFile << ''' // tag::excludeDepWildcard[] dependencies { implementation 'shadow:d:1.0' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { dependencies { exclude(dependency('shadow:d:.*')) @@ -129,18 +129,18 @@ class FilteringSpec extends PluginSpecification { def "dependency exclusions affect UP-TO-DATE check"() { given: repo.module('shadow', 'c', '1.0') - .insertFile('c.properties', 'c') - .publish() + .insertFile('c.properties', 'c') + .publish() repo.module('shadow', 'd', '1.0') - .insertFile('d.properties', 'd') - .dependsOn('c') - .publish() + .insertFile('d.properties', 'd') + .dependsOn('c') + .publish() buildFile << ''' dependencies { implementation 'shadow:d:1.0' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { dependencies { exclude(dependency('shadow:d:1.0')) @@ -159,7 +159,7 @@ class FilteringSpec extends PluginSpecification { when: 'Update build file shadowJar dependency exclusion' buildFile.text = buildFile.text.replace('exclude(dependency(\'shadow:d:1.0\'))', - 'exclude(dependency(\'shadow:c:1.0\'))') + 'exclude(dependency(\'shadow:c:1.0\'))') BuildResult result = run('shadowJar') @@ -178,18 +178,18 @@ class FilteringSpec extends PluginSpecification { def "project exclusions affect UP-TO-DATE check"() { given: repo.module('shadow', 'c', '1.0') - .insertFile('c.properties', 'c') - .publish() + .insertFile('c.properties', 'c') + .publish() repo.module('shadow', 'd', '1.0') - .insertFile('d.properties', 'd') - .dependsOn('c') - .publish() + .insertFile('d.properties', 'd') + .dependsOn('c') + .publish() buildFile << ''' dependencies { implementation 'shadow:d:1.0' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { dependencies { exclude(dependency('shadow:d:1.0')) @@ -228,12 +228,12 @@ class FilteringSpec extends PluginSpecification { def "include dependency, excluding all others"() { given: repo.module('shadow', 'c', '1.0') - .insertFile('c.properties', 'c') - .publish() + .insertFile('c.properties', 'c') + .publish() repo.module('shadow', 'd', '1.0') - .insertFile('d.properties', 'd') - .dependsOn('c') - .publish() + .insertFile('d.properties', 'd') + .dependsOn('c') + .publish() file('src/main/java/shadow/Passed.java') << ''' package shadow; @@ -244,7 +244,7 @@ class FilteringSpec extends PluginSpecification { dependencies { implementation 'shadow:d:1.0' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { dependencies { include(dependency('shadow:d:1.0')) @@ -293,7 +293,7 @@ class FilteringSpec extends PluginSpecification { dependencies { implementation project(':client') } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { dependencies { exclude(project(':client')) @@ -310,7 +310,7 @@ class FilteringSpec extends PluginSpecification { then: serverOutput.exists() doesNotContain(serverOutput, [ - 'client/Client.class', + 'client/Client.class', ]) and: @@ -364,13 +364,13 @@ class FilteringSpec extends PluginSpecification { then: serverOutput.exists() doesNotContain(serverOutput, [ - 'junit/framework/Test.class' + 'junit/framework/Test.class' ]) and: contains(serverOutput, [ - 'client/Client.class', - 'server/Server.class']) + 'client/Client.class', + 'server/Server.class']) } //http://mail-archives.apache.org/mod_mbox/ant-user/200506.mbox/%3C001d01c57756$6dc35da0$dc00a8c0@CTEGDOMAIN.COM%3E @@ -400,19 +400,19 @@ class FilteringSpec extends PluginSpecification { def "handle exclude with circular dependency"() { given: repo.module('shadow', 'c', '1.0') - .insertFile('c.properties', 'c') - .dependsOn('d') - .publish() + .insertFile('c.properties', 'c') + .dependsOn('d') + .publish() repo.module('shadow', 'd', '1.0') - .insertFile('d.properties', 'd') - .dependsOn('c') - .publish() + .insertFile('d.properties', 'd') + .dependsOn('c') + .publish() buildFile << ''' dependencies { implementation 'shadow:d:1.0' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { dependencies { exclude(dependency('shadow:d:1.0')) diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PropertiesFileTransformerSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PropertiesFileTransformerSpec.groovy new file mode 100644 index 000000000..34ace1f52 --- /dev/null +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PropertiesFileTransformerSpec.groovy @@ -0,0 +1,212 @@ +package com.github.jengelman.gradle.plugins.shadow + +import com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer +import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification +import spock.lang.Issue +import spock.lang.Unroll + +class PropertiesFileTransformerSpec extends PluginSpecification { + + @Unroll + def 'merge properties with different strategies: #mergeStrategy'() { + given: + File one = buildJar('one.jar') + .insertFile('test.properties', + 'key1=one\nkey2=one').write() + + File two = buildJar('two.jar') + .insertFile('test.properties', + 'key2=two\nkey3=two').write() + + buildFile << """ + import ${PropertiesFileTransformer.name} + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + from('${escapedPath(one)}') + from('${escapedPath(two)}') + } + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + transform(PropertiesFileTransformer) { + paths = ['test.properties'] + mergeSeparator = ";" + mergeStrategy = '${mergeStrategy}' + } + } + """.stripIndent() + + when: + run('shadowJar') + + then: + assert output.exists() + + and: + String text = getJarFileContents(output, 'test.properties') + def lines = text.replace('#', '').trim().split("\\r?\\n").toList() + assert lines.size() == 3 + switch (mergeStrategy) { + case 'first': + assert lines.containsAll(['key1=one', 'key2=one', 'key3=two']) + break + case 'latest': + assert lines.containsAll(['key1=one', 'key2=two', 'key3=two']) + break + case 'append': + assert lines.containsAll(['key1=one', 'key2=one;two', 'key3=two']) + break + default: + assert false: "Unknown mergeStrategy: $mergeStrategy" + } + + where: + mergeStrategy << ['first', 'latest', 'append'] + } + + def 'merge properties with key transformer'() { + given: + File one = buildJar('one.jar') + .insertFile('META-INF/test.properties', 'foo=bar') + .write() + + File two = buildJar('two.jar') + .insertFile('META-INF/test.properties', 'FOO=baz') + .write() + + buildFile << """ + import ${PropertiesFileTransformer.name} + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + from('${escapedPath(one)}') + from('${escapedPath(two)}') + } + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + transform(PropertiesFileTransformer) { + paths = ['META-INF/test.properties'] + mergeStrategy = 'append' + keyTransformer = { key -> key.toUpperCase() } + } + } + """.stripIndent() + + when: + run('shadowJar') + + then: + output.exists() + String text = getJarFileContents(output, 'META-INF/test.properties') + text.contains('FOO=bar,baz') + } + + def 'merge properties with specified charset'() { + given: + File one = buildJar('one.jar') + .insertFile('META-INF/utf8.properties', 'foo=第一') + .write() + + File two = buildJar('two.jar') + .insertFile('META-INF/utf8.properties', 'foo=第二') + .write() + + buildFile << """ + import ${PropertiesFileTransformer.name} + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + from('${escapedPath(one)}') + from('${escapedPath(two)}') + } + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + transform(PropertiesFileTransformer) { + paths = ['META-INF/utf8.properties'] + mergeStrategy = 'append' + charset = 'UTF-8' + } + } + """.stripIndent() + + when: + run('shadowJar') + + then: + output.exists() + String text = getJarFileContents(output, 'META-INF/utf8.properties') + text.contains('foo=第一,第二') + } + + def 'merge properties with mappings'() { + given: + File one = buildJar('one.jar') + .insertFile('META-INF/foo.properties', 'foo=1') + .insertFile('META-INF/bar.properties', 'bar=2') + .write() + + File two = buildJar('two.jar') + .insertFile('META-INF/foo.properties', 'foo=3') + .insertFile('META-INF/bar.properties', 'bar=4') + .write() + + buildFile << """ + import ${PropertiesFileTransformer.name} + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + from('${escapedPath(one)}') + from('${escapedPath(two)}') + } + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + transform(PropertiesFileTransformer) { + mappings = [ + 'META-INF/foo.properties': [mergeStrategy: 'append', mergeSeparator: ';'], + 'META-INF/bar.properties': [mergeStrategy: 'latest'] + ] + } + } + """.stripIndent() + + when: + run('shadowJar') + + then: + output.exists() + + and: + String fooText = getJarFileContents(output, 'META-INF/foo.properties') + fooText.contains('foo=1;3') + + and: + String barText = getJarFileContents(output, 'META-INF/bar.properties') + barText.contains('bar=4') + } + + @Issue( + ['https://github.com/GradleUp/shadow/issues/622', + 'https://github.com/GradleUp/shadow/issues/856' + ] + ) + def 'merged properties dont contain date comment'() { + given: + File one = buildJar('one.jar') + .insertFile('META-INF/test.properties', 'foo=one') + .write() + + File two = buildJar('two.jar') + .insertFile('META-INF/test.properties', 'foo=two') + .write() + + buildFile << """ + import ${PropertiesFileTransformer.name} + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + from('${escapedPath(one)}') + from('${escapedPath(two)}') + } + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { + transform(PropertiesFileTransformer) { + paths = ['META-INF/test.properties'] + mergeStrategy = 'append' + } + } + """.stripIndent() + + when: + run('shadowJar') + + then: + output.exists() + String text = getJarFileContents(output, 'META-INF/test.properties') + text.replace('#', '').trim() == 'foo=one,two' + } +} diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy index d79a07c68..6ce01faff 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/PublishingSpec.groovy @@ -20,12 +20,12 @@ class PublishingSpec extends PluginSpecification { def "publish shadow jar with maven-publish plugin"() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() + .insertFile('b.properties', 'b') + .publish() settingsFile << "rootProject.name = 'maven'" buildFile << """ @@ -35,12 +35,12 @@ class PublishingSpec extends PluginSpecification { implementation 'shadow:a:1.0' shadow 'shadow:b:1.0' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { archiveClassifier = '' archiveBaseName = 'maven-all' } - + publishing { publications { shadow(MavenPublication) { @@ -50,7 +50,7 @@ class PublishingSpec extends PluginSpecification { } repositories { maven { - url "${publishingRepo.uri}" + url = "${publishingRepo.uri}" } } } @@ -81,18 +81,18 @@ class PublishingSpec extends PluginSpecification { } @Issue([ - "https://github.com/GradleUp/shadow/issues/860", - "https://github.com/GradleUp/shadow/issues/945", + "https://github.com/GradleUp/shadow/issues/860", + "https://github.com/GradleUp/shadow/issues/945", ]) def "publish shadow jar with maven-publish plugin using custom classifier and extension"() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() + .insertFile('b.properties', 'b') + .publish() settingsFile << "rootProject.name = 'maven'" buildFile << """ @@ -102,7 +102,7 @@ class PublishingSpec extends PluginSpecification { implementation 'shadow:a:1.0' shadow 'shadow:b:1.0' } - + publishing { publications { shadow(MavenPublication) { publication -> @@ -112,11 +112,11 @@ class PublishingSpec extends PluginSpecification { } repositories { maven { - url "${publishingRepo.uri}" + url = "${publishingRepo.uri}" } } } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { archiveClassifier = 'my-classifier' archiveExtension = 'my-ext' @@ -149,12 +149,12 @@ class PublishingSpec extends PluginSpecification { version = "1.0" group = 'shadow' - - repositories { maven { url "${repo.uri}" } } + + repositories { maven { url = "${repo.uri}" } } publishing { repositories { maven { - url "${publishingRepo.uri}" + url = "${publishingRepo.uri}" } } } @@ -184,7 +184,7 @@ class PublishingSpec extends PluginSpecification { plugins { id 'com.gradleup.shadow' } - + dependencies { implementation project(':a') shadow project(':b') @@ -194,7 +194,7 @@ class PublishingSpec extends PluginSpecification { archiveClassifier = '' archiveBaseName = 'maven-all' } - + publishing { publications { shadow(MavenPublication) { @@ -232,12 +232,12 @@ class PublishingSpec extends PluginSpecification { def "publish shadow jar with maven-publish plugin and Gradle metadata"() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() + .insertFile('b.properties', 'b') + .publish() settingsFile << """ rootProject.name = 'maven' @@ -263,7 +263,7 @@ class PublishingSpec extends PluginSpecification { } repositories { maven { - url "${publishingRepo.uri}" + url = "${publishingRepo.uri}" } } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/RelocationSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/RelocationSpec.groovy index b9f522345..a72008197 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/RelocationSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/RelocationSpec.groovy @@ -16,7 +16,7 @@ class RelocationSpec extends PluginSpecification { dependencies { implementation 'junit:junit:3.8.2' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { relocate 'junit.textui', 'a' relocate 'junit.framework', 'b' @@ -31,41 +31,41 @@ class RelocationSpec extends PluginSpecification { then: contains(output, [ - 'META-INF/MANIFEST.MF', - 'a/ResultPrinter.class', - 'a/TestRunner.class', - 'b/Assert.class', - 'b/AssertionFailedError.class', - 'b/ComparisonCompactor.class', - 'b/ComparisonFailure.class', - 'b/Protectable.class', - 'b/Test.class', - 'b/TestCase.class', - 'b/TestFailure.class', - 'b/TestListener.class', - 'b/TestResult$1.class', - 'b/TestResult.class', - 'b/TestSuite$1.class', - 'b/TestSuite.class' + 'META-INF/MANIFEST.MF', + 'a/ResultPrinter.class', + 'a/TestRunner.class', + 'b/Assert.class', + 'b/AssertionFailedError.class', + 'b/ComparisonCompactor.class', + 'b/ComparisonFailure.class', + 'b/Protectable.class', + 'b/Test.class', + 'b/TestCase.class', + 'b/TestFailure.class', + 'b/TestListener.class', + 'b/TestResult$1.class', + 'b/TestResult.class', + 'b/TestSuite$1.class', + 'b/TestSuite.class' ]) and: doesNotContain(output, [ - 'junit/textui/ResultPrinter.class', - 'junit/textui/TestRunner.class', - 'junit/framework/Assert.class', - 'junit/framework/AssertionFailedError.class', - 'junit/framework/ComparisonCompactor.class', - 'junit/framework/ComparisonFailure.class', - 'junit/framework/Protectable.class', - 'junit/framework/Test.class', - 'junit/framework/TestCase.class', - 'junit/framework/TestFailure.class', - 'junit/framework/TestListener.class', - 'junit/framework/TestResult$1.class', - 'junit/framework/TestResult.class', - 'junit/framework/TestSuite$1.class', - 'junit/framework/TestSuite.class' + 'junit/textui/ResultPrinter.class', + 'junit/textui/TestRunner.class', + 'junit/framework/Assert.class', + 'junit/framework/AssertionFailedError.class', + 'junit/framework/ComparisonCompactor.class', + 'junit/framework/ComparisonFailure.class', + 'junit/framework/Protectable.class', + 'junit/framework/Test.class', + 'junit/framework/TestCase.class', + 'junit/framework/TestFailure.class', + 'junit/framework/TestListener.class', + 'junit/framework/TestResult$1.class', + 'junit/framework/TestResult.class', + 'junit/framework/TestSuite$1.class', + 'junit/framework/TestSuite.class' ]) and: 'Test that manifest file exists with contents' @@ -81,7 +81,7 @@ class RelocationSpec extends PluginSpecification { dependencies { implementation 'junit:junit:3.8.2' } - + // tag::relocateFilter[] tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { relocate('junit.textui', 'a') { @@ -99,35 +99,35 @@ class RelocationSpec extends PluginSpecification { then: contains(output, [ - 'a/ResultPrinter.class', - 'b/Test.class', - 'b/TestCase.class', - 'b/TestFailure.class', - 'b/TestListener.class', - 'b/TestResult$1.class', - 'b/TestResult.class', - 'b/TestSuite$1.class', - 'b/TestSuite.class' + 'a/ResultPrinter.class', + 'b/Test.class', + 'b/TestCase.class', + 'b/TestFailure.class', + 'b/TestListener.class', + 'b/TestResult$1.class', + 'b/TestResult.class', + 'b/TestSuite$1.class', + 'b/TestSuite.class' ]) and: doesNotContain(output, [ - 'a/TestRunner.class', - 'b/Assert.class', - 'b/AssertionFailedError.class', - 'b/ComparisonCompactor.class', - 'b/ComparisonFailure.class', - 'b/Protectable.class' + 'a/TestRunner.class', + 'b/Assert.class', + 'b/AssertionFailedError.class', + 'b/ComparisonCompactor.class', + 'b/ComparisonFailure.class', + 'b/Protectable.class' ]) and: contains(output, [ - 'junit/textui/TestRunner.class', - 'junit/framework/Assert.class', - 'junit/framework/AssertionFailedError.class', - 'junit/framework/ComparisonCompactor.class', - 'junit/framework/ComparisonFailure.class', - 'junit/framework/Protectable.class' + 'junit/textui/TestRunner.class', + 'junit/framework/Assert.class', + 'junit/framework/AssertionFailedError.class', + 'junit/framework/ComparisonCompactor.class', + 'junit/framework/ComparisonFailure.class', + 'junit/framework/Protectable.class' ]) } @@ -138,7 +138,7 @@ class RelocationSpec extends PluginSpecification { dependencies { implementation 'junit:junit:3.8.2' } - + // tag::relocate[] tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { relocate 'junit.framework', 'shadow.junit' @@ -148,7 +148,7 @@ class RelocationSpec extends PluginSpecification { file('src/main/java/shadow/ShadowTest.java') << ''' package shadow; - + import junit.framework.Test; import junit.framework.TestResult; public class ShadowTest implements Test { @@ -162,21 +162,21 @@ class RelocationSpec extends PluginSpecification { then: contains(output, [ - 'shadow/ShadowTest.class', - 'shadow/junit/Test.class', - 'shadow/junit' + 'shadow/ShadowTest.class', + 'shadow/junit/Test.class', + 'shadow/junit' ]) and: doesNotContain(output, [ - 'junit/framework', - 'junit/framework/Test.class' + 'junit/framework', + 'junit/framework/Test.class' ]) and: 'check that the class can be loaded. If the file was not relocated properly, we should get a NoDefClassFound' // Isolated class loader with only the JVM system jars and the output jar from the test project URLClassLoader classLoader = new URLClassLoader([output.toURI().toURL()] as URL[], - ClassLoader.systemClassLoader.parent) + ClassLoader.systemClassLoader.parent) classLoader.loadClass('shadow.ShadowTest') } @@ -185,8 +185,8 @@ class RelocationSpec extends PluginSpecification { given: 'Core project with dependency and resource' file('core/build.gradle') << """ apply plugin: 'java-library' - - repositories { maven { url "${repo.uri}" } } + + repositories { maven { url = "${repo.uri}" } } dependencies { api 'junit:junit:3.8.2' } """.stripIndent() @@ -194,9 +194,9 @@ class RelocationSpec extends PluginSpecification { file('core/src/main/resources/test.properties') << 'name=test' file('core/src/main/java/core/Core.java') << ''' package core; - + import junit.framework.Test; - + public class Core {} '''.stripIndent() @@ -204,10 +204,10 @@ class RelocationSpec extends PluginSpecification { file('app/build.gradle') << """ apply plugin: 'java' apply plugin: 'com.gradleup.shadow' - - repositories { maven { url "${repo.uri}" } } + + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':core') } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { relocate 'core', 'app.core' relocate 'junit.framework', 'app.junit.framework' @@ -217,10 +217,10 @@ class RelocationSpec extends PluginSpecification { file('app/src/main/resources/APP-TEST') << 'APP TEST RESOURCE' file('app/src/main/java/app/App.java') << ''' package app; - + import core.Core; import junit.framework.Test; - + public class App {} '''.stripIndent() @@ -238,12 +238,12 @@ class RelocationSpec extends PluginSpecification { and: contains(appOutput, [ - 'TEST', - 'APP-TEST', - 'test.properties', - 'app/core/Core.class', - 'app/App.class', - 'app/junit/framework/Test.class' + 'TEST', + 'APP-TEST', + 'test.properties', + 'app/core/Core.class', + 'app/App.class', + 'app/junit/framework/Test.class' ]) } @@ -251,11 +251,11 @@ class RelocationSpec extends PluginSpecification { def "relocate resource files"() { given: repo.module('shadow', 'dep', '1.0') - .insertFile('foo/dep.properties', 'c') - .publish() + .insertFile('foo/dep.properties', 'c') + .publish() file('src/main/java/foo/Foo.java') << ''' package foo; - + class Foo {} '''.stripIndent() file('src/main/resources/foo/foo.properties') << 'name=foo' @@ -264,7 +264,7 @@ class RelocationSpec extends PluginSpecification { dependencies { implementation 'shadow:dep:1.0' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { relocate 'foo', 'bar' } @@ -275,16 +275,16 @@ class RelocationSpec extends PluginSpecification { then: contains(output, [ - 'bar/Foo.class', - 'bar/foo.properties', - 'bar/dep.properties' + 'bar/Foo.class', + 'bar/foo.properties', + 'bar/dep.properties' ]) and: doesNotContain(output, [ - 'foo/Foo.class', - 'foo/foo.properties', - 'foo/dep.properties' + 'foo/Foo.class', + 'foo/foo.properties', + 'foo/dep.properties' ]) } @@ -296,7 +296,7 @@ class RelocationSpec extends PluginSpecification { repositories { mavenCentral() maven { - url 'https://repository.mapr.com/nexus/content/groups/mapr-public/releases' + url = 'https://repository.mapr.com/nexus/content/groups/mapr-public/releases' } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy index a19284e5a..fda372688 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowPluginSpec.groovy @@ -63,10 +63,10 @@ class ShadowPluginSpec extends PluginSpecification { def 'Compatible with Gradle #version'() { given: File one = buildJar('one.jar').insertFile('META-INF/services/shadow.Shadow', - 'one # NOTE: No newline terminates this line/file').write() + 'one # NOTE: No newline terminates this line/file').write() repo.module('shadow', 'two', '1.0').insertFile('META-INF/services/shadow.Shadow', - 'two # NOTE: No newline terminates this line/file').publish() + 'two # NOTE: No newline terminates this line/file').publish() buildFile << """ dependencies { @@ -175,7 +175,7 @@ class ShadowPluginSpec extends PluginSpecification { file('client/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' } """.stripIndent() @@ -191,7 +191,7 @@ class ShadowPluginSpec extends PluginSpecification { apply plugin: 'java' apply plugin: 'com.gradleup.shadow' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':client') } """.stripIndent() @@ -204,9 +204,9 @@ class ShadowPluginSpec extends PluginSpecification { then: serverOutput.exists() contains(serverOutput, [ - 'client/Client.class', - 'server/Server.class', - 'junit/framework/Test.class' + 'client/Client.class', + 'server/Server.class', + 'junit/framework/Test.class' ]) } @@ -227,7 +227,7 @@ class ShadowPluginSpec extends PluginSpecification { file('client/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' } """.stripIndent() @@ -249,7 +249,7 @@ class ShadowPluginSpec extends PluginSpecification { minimize() } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':client') } """.stripIndent() @@ -261,8 +261,8 @@ class ShadowPluginSpec extends PluginSpecification { then: serverOutput.exists() contains(serverOutput, [ - 'client/Client.class', - 'server/Server.class' + 'client/Client.class', + 'server/Server.class' ]) doesNotContain(serverOutput, ['junit/framework/Test.class']) } @@ -285,7 +285,7 @@ class ShadowPluginSpec extends PluginSpecification { file('client/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' } """.stripIndent() @@ -304,7 +304,7 @@ class ShadowPluginSpec extends PluginSpecification { } } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':client') } """.stripIndent() @@ -316,8 +316,8 @@ class ShadowPluginSpec extends PluginSpecification { then: serverOutput.exists() contains(serverOutput, [ - 'server/Server.class', - 'junit/framework/Test.class' + 'server/Server.class', + 'junit/framework/Test.class' ]) doesNotContain(serverOutput, ['client/Client.class']) } @@ -339,7 +339,7 @@ class ShadowPluginSpec extends PluginSpecification { file('client/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } """.stripIndent() file('server/src/main/java/server/Server.java') << """ @@ -357,7 +357,7 @@ class ShadowPluginSpec extends PluginSpecification { } } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':client') } """.stripIndent() @@ -368,8 +368,8 @@ class ShadowPluginSpec extends PluginSpecification { then: contains(serverOutput, [ - 'client/Client.class', - 'server/Server.class' + 'client/Client.class', + 'server/Server.class' ]) } @@ -387,13 +387,13 @@ class ShadowPluginSpec extends PluginSpecification { package client; import junit.framework.TestCase; public class Client extends TestCase { - public static void main(String[] args) {} + public static void main(String[] args) {} } """.stripIndent() file('client/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' } """.stripIndent() @@ -412,7 +412,7 @@ class ShadowPluginSpec extends PluginSpecification { } } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':client') } """.stripIndent() @@ -423,9 +423,9 @@ class ShadowPluginSpec extends PluginSpecification { then: contains(serverOutput, [ - 'client/Client.class', - 'server/Server.class', - 'junit/framework/TestCase.class' + 'client/Client.class', + 'server/Server.class', + 'junit/framework/TestCase.class' ]) } @@ -446,7 +446,7 @@ class ShadowPluginSpec extends PluginSpecification { file('client/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' } """.stripIndent() @@ -465,7 +465,7 @@ class ShadowPluginSpec extends PluginSpecification { } } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':client') } """.stripIndent() @@ -476,9 +476,9 @@ class ShadowPluginSpec extends PluginSpecification { then: contains(serverOutput, [ - 'client/Client.class', - 'server/Server.class', - 'junit/framework/TestCase.class' + 'client/Client.class', + 'server/Server.class', + 'junit/framework/TestCase.class' ]) } @@ -506,7 +506,7 @@ class ShadowPluginSpec extends PluginSpecification { file('lib/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } """.stripIndent() file('api/src/main/java/api/Entity.java') << """ @@ -522,7 +522,7 @@ class ShadowPluginSpec extends PluginSpecification { file('api/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' implementation project(':lib') @@ -543,7 +543,7 @@ class ShadowPluginSpec extends PluginSpecification { minimize() } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { api project(':api') } """.stripIndent() @@ -555,10 +555,10 @@ class ShadowPluginSpec extends PluginSpecification { then: serverOutput.exists() contains(serverOutput, [ - 'impl/SimpleEntity.class', - 'api/Entity.class', - 'api/UnusedEntity.class', - 'lib/LibEntity.class', + 'impl/SimpleEntity.class', + 'api/Entity.class', + 'api/UnusedEntity.class', + 'lib/LibEntity.class', ]) doesNotContain(serverOutput, ['junit/framework/Test.class', 'lib/UnusedLibEntity.class']) } @@ -585,7 +585,7 @@ class ShadowPluginSpec extends PluginSpecification { file('lib/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } """.stripIndent() file('api/src/main/java/api/Entity.java') << """ @@ -601,7 +601,7 @@ class ShadowPluginSpec extends PluginSpecification { file('api/build.gradle') << """ apply plugin: 'java-library' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { api project(':lib') } """.stripIndent() @@ -619,7 +619,7 @@ class ShadowPluginSpec extends PluginSpecification { minimize() } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { api project(':api') } """.stripIndent() @@ -631,11 +631,11 @@ class ShadowPluginSpec extends PluginSpecification { then: serverOutput.exists() contains(serverOutput, [ - 'impl/SimpleEntity.class', - 'api/Entity.class', - 'api/UnusedEntity.class', - 'lib/LibEntity.class', - 'lib/UnusedLibEntity.class' + 'impl/SimpleEntity.class', + 'api/Entity.class', + 'api/UnusedEntity.class', + 'lib/LibEntity.class', + 'lib/UnusedLibEntity.class' ]) } @@ -653,7 +653,7 @@ class ShadowPluginSpec extends PluginSpecification { file('client/build.gradle') << """ apply plugin: 'java' apply plugin: 'com.gradleup.shadow' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' } tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { @@ -673,7 +673,7 @@ class ShadowPluginSpec extends PluginSpecification { file('server/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(path: ':client', configuration: 'shadow') } """.stripIndent() @@ -685,14 +685,14 @@ class ShadowPluginSpec extends PluginSpecification { then: serverOutput.exists() contains(serverOutput, [ - 'server/Server.class' + 'server/Server.class' ]) and: doesNotContain(serverOutput, [ - 'client/Client.class', - 'junit/framework/Test.class', - 'client/junit/framework/Test.class' + 'client/Client.class', + 'junit/framework/Test.class', + 'client/junit/framework/Test.class' ]) } @@ -710,7 +710,7 @@ class ShadowPluginSpec extends PluginSpecification { file('client/build.gradle') << """ apply plugin: 'java' apply plugin: 'com.gradleup.shadow' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' } tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { @@ -731,7 +731,7 @@ class ShadowPluginSpec extends PluginSpecification { apply plugin: 'java' apply plugin: 'com.gradleup.shadow' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(path: ':client', configuration: 'shadow') } """.stripIndent() @@ -743,27 +743,27 @@ class ShadowPluginSpec extends PluginSpecification { then: serverOutput.exists() contains(serverOutput, [ - 'client/Client.class', - 'client/junit/framework/Test.class', - 'server/Server.class', + 'client/Client.class', + 'client/junit/framework/Test.class', + 'server/Server.class', ]) and: doesNotContain(serverOutput, [ - 'junit/framework/Test.class' + 'junit/framework/Test.class' ]) } def "exclude INDEX.LIST, *.SF, *.DSA, and *.RSA by default"() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('META-INF/INDEX.LIST', 'JarIndex-Version: 1.0') - .insertFile('META-INF/a.SF', 'Signature File') - .insertFile('META-INF/a.DSA', 'DSA Signature Block') - .insertFile('META-INF/a.RSA', 'RSA Signature Block') - .insertFile('META-INF/a.properties', 'key=value') - .publish() + .insertFile('a.properties', 'a') + .insertFile('META-INF/INDEX.LIST', 'JarIndex-Version: 1.0') + .insertFile('META-INF/a.SF', 'Signature File') + .insertFile('META-INF/a.DSA', 'DSA Signature Block') + .insertFile('META-INF/a.RSA', 'RSA Signature Block') + .insertFile('META-INF/a.properties', 'key=value') + .publish() file('src/main/java/shadow/Passed.java') << ''' package shadow; @@ -787,12 +787,12 @@ class ShadowPluginSpec extends PluginSpecification { def "include runtime configuration by default"() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .publish() + .insertFile('a.properties', 'a') + .publish() repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() + .insertFile('b.properties', 'b') + .publish() buildFile << """ dependencies { @@ -814,21 +814,21 @@ class ShadowPluginSpec extends PluginSpecification { def "include java-library configurations by default"() { given: repo.module('shadow', 'api', '1.0') - .insertFile('api.properties', 'api') - .publish() + .insertFile('api.properties', 'api') + .publish() repo.module('shadow', 'implementation-dep', '1.0') - .insertFile('implementation-dep.properties', 'implementation-dep') - .publish() + .insertFile('implementation-dep.properties', 'implementation-dep') + .publish() repo.module('shadow', 'implementation', '1.0') - .insertFile('implementation.properties', 'implementation') - .dependsOn('implementation-dep') - .publish() + .insertFile('implementation.properties', 'implementation') + .dependsOn('implementation-dep') + .publish() repo.module('shadow', 'runtimeOnly', '1.0') - .insertFile('runtimeOnly.properties', 'runtimeOnly') - .publish() + .insertFile('runtimeOnly.properties', 'runtimeOnly') + .publish() buildFile.text = getDefaultBuildScript('java-library') buildFile << """ @@ -850,12 +850,12 @@ class ShadowPluginSpec extends PluginSpecification { def "doesn't include compileOnly configuration by default"() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .publish() + .insertFile('a.properties', 'a') + .publish() repo.module('shadow', 'b', '1.0') - .insertFile('b.properties', 'b') - .publish() + .insertFile('b.properties', 'b') + .publish() buildFile << """ dependencies { @@ -877,12 +877,12 @@ class ShadowPluginSpec extends PluginSpecification { def "default copying strategy"() { given: repo.module('shadow', 'a', '1.0') - .insertFile('META-INF/MANIFEST.MF', 'MANIFEST A') - .publish() + .insertFile('META-INF/MANIFEST.MF', 'MANIFEST A') + .publish() repo.module('shadow', 'b', '1.0') - .insertFile('META-INF/MANIFEST.MF', 'MANIFEST B') - .publish() + .insertFile('META-INF/MANIFEST.MF', 'MANIFEST B') + .publish() buildFile << """ dependencies { @@ -982,7 +982,7 @@ class ShadowPluginSpec extends PluginSpecification { dependencies { shadow 'junit:junit:3.8.2' } tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { - zip64 true + zip64 = true entryCompression = org.gradle.api.tasks.bundling.ZipEntryCompression.STORED } """.stripIndent() @@ -1004,7 +1004,7 @@ class ShadowPluginSpec extends PluginSpecification { file('lib/build.gradle') << """ apply plugin: 'java' version = '1.0' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } """.stripIndent() file('api/src/main/java/api/UnusedEntity.java') << """ @@ -1015,7 +1015,7 @@ class ShadowPluginSpec extends PluginSpecification { file('api/build.gradle') << """ apply plugin: 'java' version = '1.0' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' implementation project(':lib') @@ -1027,9 +1027,9 @@ class ShadowPluginSpec extends PluginSpecification { apply plugin: 'com.gradleup.shadow' version = '1.0' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { api project(':api') } - + shadowJar.minimize() """.stripIndent() @@ -1041,7 +1041,7 @@ class ShadowPluginSpec extends PluginSpecification { then: serverOutput.exists() contains(serverOutput, [ - 'api/UnusedEntity.class', + 'api/UnusedEntity.class', ]) } @@ -1050,9 +1050,9 @@ class ShadowPluginSpec extends PluginSpecification { def "check large zip files with zip64 enabled"() { given: repo.module('shadow', 'a', '1.0') - .insertFile('a.properties', 'a') - .insertFile('a2.properties', 'a2') - .publish() + .insertFile('a.properties', 'a') + .insertFile('a2.properties', 'a2') + .publish() file('src/main/java/myapp/Main.java') << """ package myapp; @@ -1126,7 +1126,7 @@ class ShadowPluginSpec extends PluginSpecification { buildscript { repositories { maven { - url "https://maven.eveoh.nl/content/repositories/releases" + url = "https://maven.eveoh.nl/content/repositories/releases" } } @@ -1247,8 +1247,4 @@ class ShadowPluginSpec extends PluginSpecification { JarFile jar = new JarFile(output) assert jar.entries().collect().findAll { it.name.endsWith('.class') }.size() == 1 } - - private String escapedPath(File file) { - file.path.replaceAll('\\\\', '\\\\\\\\') - } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy index 2835108e8..7bed060ce 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy @@ -16,16 +16,16 @@ class TransformerSpec extends PluginSpecification { def 'service resource transformer'() { given: File one = buildJar('one.jar') - .insertFile('META-INF/services/org.apache.maven.Shade', - 'one # NOTE: No newline terminates this line/file') - .insertFile('META-INF/services/com.acme.Foo', 'one') - .write() + .insertFile('META-INF/services/org.apache.maven.Shade', + 'one # NOTE: No newline terminates this line/file') + .insertFile('META-INF/services/com.acme.Foo', 'one') + .write() File two = buildJar('two.jar') - .insertFile('META-INF/services/org.apache.maven.Shade', - 'two # NOTE: No newline terminates this line/file') - .insertFile('META-INF/services/com.acme.Foo', 'two') - .write() + .insertFile('META-INF/services/org.apache.maven.Shade', + 'two # NOTE: No newline terminates this line/file') + .insertFile('META-INF/services/com.acme.Foo', 'two') + .write() buildFile << """ import ${ServiceFileTransformer.name} @@ -50,7 +50,7 @@ class TransformerSpec extends PluginSpecification { String text1 = getJarFileContents(output, 'META-INF/services/org.apache.maven.Shade') assert text1.split("\\r?\\n").size() == 2 assert text1 == -'''one # NOTE: No newline terminates this line/file + '''one # NOTE: No newline terminates this line/file two # NOTE: No newline terminates this line/file'''.stripIndent() and: @@ -61,13 +61,13 @@ two # NOTE: No newline terminates this line/file'''.stripIndent() def 'service resource transformer alternate path'() { given: - File one = buildJar('one.jar').insertFile('META-INF/foo/org.apache.maven.Shade', - 'one # NOTE: No newline terminates this line/file').write() + File one = buildJar('one.jar').insertFile('META-INF/foo/org.apache.maven.Shade', + 'one # NOTE: No newline terminates this line/file').write() - File two = buildJar('two.jar').insertFile('META-INF/foo/org.apache.maven.Shade', - 'two # NOTE: No newline terminates this line/file').write() + File two = buildJar('two.jar').insertFile('META-INF/foo/org.apache.maven.Shade', + 'two # NOTE: No newline terminates this line/file').write() - buildFile << """ + buildFile << """ import ${ServiceFileTransformer.name} tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { from('${escapedPath(one)}') @@ -81,32 +81,32 @@ two # NOTE: No newline terminates this line/file'''.stripIndent() """.stripIndent() when: - run('shadowJar') + run('shadowJar') then: - assert output.exists() + assert output.exists() and: - String text = getJarFileContents(output, 'META-INF/foo/org.apache.maven.Shade') - assert text.split("\\r?\\n").size() == 2 - assert text == -'''one # NOTE: No newline terminates this line/file + String text = getJarFileContents(output, 'META-INF/foo/org.apache.maven.Shade') + assert text.split("\\r?\\n").size() == 2 + assert text == + '''one # NOTE: No newline terminates this line/file two # NOTE: No newline terminates this line/file'''.stripIndent() } def 'service resource transformer short syntax'() { given: - File one = buildJar('one.jar') - .insertFile('META-INF/services/org.apache.maven.Shade', - 'one # NOTE: No newline terminates this line/file') - .insertFile('META-INF/services/com.acme.Foo', 'one') - .write() - - File two = buildJar('two.jar') - .insertFile('META-INF/services/org.apache.maven.Shade', - 'two # NOTE: No newline terminates this line/file') - .insertFile('META-INF/services/com.acme.Foo', 'two') - .write() + File one = buildJar('one.jar') + .insertFile('META-INF/services/org.apache.maven.Shade', + 'one # NOTE: No newline terminates this line/file') + .insertFile('META-INF/services/com.acme.Foo', 'one') + .write() + + File two = buildJar('two.jar') + .insertFile('META-INF/services/org.apache.maven.Shade', + 'two # NOTE: No newline terminates this line/file') + .insertFile('META-INF/services/com.acme.Foo', 'two') + .write() buildFile << """ tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { @@ -127,39 +127,39 @@ two # NOTE: No newline terminates this line/file'''.stripIndent() assert output.exists() and: - String text1 = getJarFileContents(output, 'META-INF/services/org.apache.maven.Shade') - assert text1.split("\\r?\\n").size() == 2 - assert text1 == -'''one # NOTE: No newline terminates this line/file + String text1 = getJarFileContents(output, 'META-INF/services/org.apache.maven.Shade') + assert text1.split("\\r?\\n").size() == 2 + assert text1 == + '''one # NOTE: No newline terminates this line/file two # NOTE: No newline terminates this line/file'''.stripIndent() and: - String text2 = getJarFileContents(output, 'META-INF/services/com.acme.Foo') - assert text2.split("\\r?\\n").size() == 1 - assert text2 == 'one' + String text2 = getJarFileContents(output, 'META-INF/services/com.acme.Foo') + assert text2.split("\\r?\\n").size() == 1 + assert text2 == 'one' } def 'service resource transformer short syntax relocation'() { given: File one = buildJar('one.jar') - .insertFile('META-INF/services/java.sql.Driver', -'''oracle.jdbc.OracleDriver + .insertFile('META-INF/services/java.sql.Driver', + '''oracle.jdbc.OracleDriver org.apache.hive.jdbc.HiveDriver'''.stripIndent()) - .insertFile('META-INF/services/org.apache.axis.components.compiler.Compiler', + .insertFile('META-INF/services/org.apache.axis.components.compiler.Compiler', 'org.apache.axis.components.compiler.Javac') - .insertFile('META-INF/services/org.apache.commons.logging.LogFactory', + .insertFile('META-INF/services/org.apache.commons.logging.LogFactory', 'org.apache.commons.logging.impl.LogFactoryImpl') - .write() + .write() File two = buildJar('two.jar') - .insertFile('META-INF/services/java.sql.Driver', -'''org.apache.derby.jdbc.AutoloadedDriver + .insertFile('META-INF/services/java.sql.Driver', + '''org.apache.derby.jdbc.AutoloadedDriver com.mysql.jdbc.Driver'''.stripIndent()) - .insertFile('META-INF/services/org.apache.axis.components.compiler.Compiler', + .insertFile('META-INF/services/org.apache.axis.components.compiler.Compiler', 'org.apache.axis.components.compiler.Jikes') - .insertFile('META-INF/services/org.apache.commons.logging.LogFactory', + .insertFile('META-INF/services/org.apache.commons.logging.LogFactory', 'org.mortbay.log.Factory') - .write() + .write() buildFile << """ tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { @@ -185,7 +185,7 @@ com.mysql.jdbc.Driver'''.stripIndent()) String text1 = getJarFileContents(output, 'META-INF/services/java.sql.Driver') assert text1.split("\\r?\\n").size() == 4 assert text1 == -'''oracle.jdbc.OracleDriver + '''oracle.jdbc.OracleDriver myapache.hive.jdbc.HiveDriver myapache.derby.jdbc.AutoloadedDriver com.mysql.jdbc.Driver'''.stripIndent() @@ -194,26 +194,26 @@ com.mysql.jdbc.Driver'''.stripIndent() String text2 = getJarFileContents(output, 'META-INF/services/myapache.axis.components.compiler.Compiler') assert text2.split("\\r?\\n").size() == 2 assert text2 == -'''myapache.axis.components.compiler.Javac + '''myapache.axis.components.compiler.Javac org.apache.axis.components.compiler.Jikes'''.stripIndent() and: String text3 = getJarFileContents(output, 'META-INF/services/org.apache.commons.logging.LogFactory') assert text3.split("\\r?\\n").size() == 2 assert text3 == -'''myapache.commons.logging.impl.LogFactoryImpl + '''myapache.commons.logging.impl.LogFactoryImpl org.mortbay.log.Factory'''.stripIndent() } def 'service resource transformer short syntax alternate path'() { given: - File one = buildJar('one.jar').insertFile('META-INF/foo/org.apache.maven.Shade', - 'one # NOTE: No newline terminates this line/file').write() + File one = buildJar('one.jar').insertFile('META-INF/foo/org.apache.maven.Shade', + 'one # NOTE: No newline terminates this line/file').write() - File two = buildJar('two.jar').insertFile('META-INF/foo/org.apache.maven.Shade', - 'two # NOTE: No newline terminates this line/file').write() + File two = buildJar('two.jar').insertFile('META-INF/foo/org.apache.maven.Shade', + 'two # NOTE: No newline terminates this line/file').write() - buildFile << """ + buildFile << """ tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { from('${escapedPath(one)}') from('${escapedPath(two)}') @@ -224,16 +224,16 @@ org.mortbay.log.Factory'''.stripIndent() """.stripIndent() when: - run('shadowJar') + run('shadowJar') then: - assert output.exists() + assert output.exists() and: - String text = getJarFileContents(output, 'META-INF/foo/org.apache.maven.Shade') - assert text.split("\\r?\\n").size() == 2 - assert text == -'''one # NOTE: No newline terminates this line/file + String text = getJarFileContents(output, 'META-INF/foo/org.apache.maven.Shade') + assert text.split("\\r?\\n").size() == 2 + assert text == + '''one # NOTE: No newline terminates this line/file two # NOTE: No newline terminates this line/file'''.stripIndent() } @@ -241,24 +241,24 @@ two # NOTE: No newline terminates this line/file'''.stripIndent() def 'apply transformers to project resources'() { given: File one = buildJar('one.jar').insertFile('META-INF/services/shadow.Shadow', - 'one # NOTE: No newline terminates this line/file').write() + 'one # NOTE: No newline terminates this line/file').write() repo.module('shadow', 'two', '1.0').insertFile('META-INF/services/shadow.Shadow', - 'two # NOTE: No newline terminates this line/file').publish() + 'two # NOTE: No newline terminates this line/file').publish() buildFile << """ dependencies { implementation 'shadow:two:1.0' implementation files('${escapedPath(one)}') } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { mergeServiceFiles() } """.stripIndent() file('src/main/resources/META-INF/services/shadow.Shadow') << - 'three # NOTE: No newline terminates this line/file' + 'three # NOTE: No newline terminates this line/file' when: run('shadowJar') @@ -270,7 +270,7 @@ two # NOTE: No newline terminates this line/file'''.stripIndent() String text = getJarFileContents(output, 'META-INF/services/shadow.Shadow') assert text.split("\\r?\\n").size() == 3 assert text == -'''three # NOTE: No newline terminates this line/file + '''three # NOTE: No newline terminates this line/file one # NOTE: No newline terminates this line/file two # NOTE: No newline terminates this line/file'''.stripIndent() } @@ -278,10 +278,10 @@ two # NOTE: No newline terminates this line/file'''.stripIndent() def 'appending transformer'() { given: File one = buildJar('one.jar').insertFile('test.properties', - 'one # NOTE: No newline terminates this line/file').write() + 'one # NOTE: No newline terminates this line/file').write() File two = buildJar('two.jar').insertFile('test.properties', - 'two # NOTE: No newline terminates this line/file').write() + 'two # NOTE: No newline terminates this line/file').write() buildFile << """ import ${AppendingTransformer.name} @@ -306,7 +306,7 @@ two # NOTE: No newline terminates this line/file'''.stripIndent() String text = getJarFileContents(output, 'test.properties') assert text.split("\\r?\\n").size() == 2 assert text == -'''one # NOTE: No newline terminates this line/file + '''one # NOTE: No newline terminates this line/file two # NOTE: No newline terminates this line/file '''.stripIndent() } @@ -314,10 +314,10 @@ two # NOTE: No newline terminates this line/file def 'appending transformer short syntax'() { given: File one = buildJar('one.jar').insertFile('test.properties', - 'one # NOTE: No newline terminates this line/file').write() + 'one # NOTE: No newline terminates this line/file').write() File two = buildJar('two.jar').insertFile('test.properties', - 'two # NOTE: No newline terminates this line/file').write() + 'two # NOTE: No newline terminates this line/file').write() buildFile << """ tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { @@ -339,7 +339,7 @@ two # NOTE: No newline terminates this line/file String text = getJarFileContents(output, 'test.properties') assert text.split("\\r?\\n").size() == 2 assert text == -'''one # NOTE: No newline terminates this line/file + '''one # NOTE: No newline terminates this line/file two # NOTE: No newline terminates this line/file '''.stripIndent() } @@ -349,9 +349,9 @@ two # NOTE: No newline terminates this line/file File main = file('src/main/java/shadow/Main.java') main << ''' package shadow; - + public class Main { - + public static void main(String[] args) { } } '''.stripIndent() @@ -386,9 +386,9 @@ two # NOTE: No newline terminates this line/file File main = file('src/main/java/shadow/Main.java') main << ''' package shadow; - + public class Main { - + public static void main(String[] args) { } } '''.stripIndent() @@ -400,7 +400,7 @@ two # NOTE: No newline terminates this line/file attributes 'Test-Entry': 'FAILED' } } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { manifest { attributes 'Test-Entry': 'PASSED' @@ -429,8 +429,8 @@ two # NOTE: No newline terminates this line/file def 'append xml files'() { given: File xml1 = buildJar('xml1.jar').insertFile('properties.xml', -''' - + ''' + val1 @@ -438,8 +438,8 @@ two # NOTE: No newline terminates this line/file ).write() File xml2 = buildJar('xml2.jar').insertFile('properties.xml', -''' - + ''' + val2 @@ -470,7 +470,7 @@ two # NOTE: No newline terminates this line/file and: String text = getJarFileContents(output, 'properties.xml') assert text.replaceAll('\r\n', '\n') == -''' + ''' val1 @@ -485,9 +485,9 @@ two # NOTE: No newline terminates this line/file File main = file('src/main/java/shadow/Main.java') main << ''' package shadow; - + public class Main { - + public static void main(String[] args) { } } '''.stripIndent() @@ -499,7 +499,7 @@ two # NOTE: No newline terminates this line/file attributes 'Test-Entry': 'FAILED' } } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { manifest { attributes 'Test-Entry': 'PASSED' @@ -545,9 +545,9 @@ two # NOTE: No newline terminates this line/file File main = file('src/main/java/shadow/Main.java') main << ''' package shadow; - + public class Main { - + public static void main(String[] args) { } } '''.stripIndent() @@ -559,7 +559,7 @@ two # NOTE: No newline terminates this line/file attributes 'Test-Entry': 'FAILED' } } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { manifest { attributes 'Test-Entry': 'PASSED' @@ -601,21 +601,21 @@ two # NOTE: No newline terminates this line/file def 'Groovy extension module transformer'() { given: - def one = buildJar('one.jar') - .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', -'''moduleName=foo + def one = buildJar('one.jar') + .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', + '''moduleName=foo moduleVersion=1.0.5 extensionClasses=com.acme.foo.FooExtension,com.acme.foo.BarExtension staticExtensionClasses=com.acme.foo.FooStaticExtension'''.stripIndent()).write() - def two = buildJar('two.jar') - .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', -'''moduleName=bar + def two = buildJar('two.jar') + .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', + '''moduleName=bar moduleVersion=2.3.5 extensionClasses=com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write() - buildFile << """ + buildFile << """ import ${GroovyExtensionModuleTransformer.name} tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { from('${escapedPath(one)}') @@ -628,38 +628,38 @@ staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write( """.stripIndent() when: - run('shadowJar') + run('shadowJar') then: - assert output.exists() + assert output.exists() and: - def text = getJarFileContents(output, 'META-INF/services/org.codehaus.groovy.runtime.ExtensionModule') - def props = new Properties() - props.load(new StringReader(text)) - assert props.getProperty('moduleName') == 'MergedByShadowJar' - assert props.getProperty('moduleVersion') == '1.0.0' - assert props.getProperty('extensionClasses') == 'com.acme.foo.FooExtension,com.acme.foo.BarExtension,com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension' - assert props.getProperty('staticExtensionClasses') == 'com.acme.foo.FooStaticExtension,com.acme.bar.SomeStaticExtension' + def text = getJarFileContents(output, 'META-INF/services/org.codehaus.groovy.runtime.ExtensionModule') + def props = new Properties() + props.load(new StringReader(text)) + assert props.getProperty('moduleName') == 'MergedByShadowJar' + assert props.getProperty('moduleVersion') == '1.0.0' + assert props.getProperty('extensionClasses') == 'com.acme.foo.FooExtension,com.acme.foo.BarExtension,com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension' + assert props.getProperty('staticExtensionClasses') == 'com.acme.foo.FooStaticExtension,com.acme.bar.SomeStaticExtension' } def 'Groovy extension module transformer works for Groovy2_5+'() { given: - def one = buildJar('one.jar') - .insertFile('META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule', -'''moduleName=foo + def one = buildJar('one.jar') + .insertFile('META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule', + '''moduleName=foo moduleVersion=1.0.5 extensionClasses=com.acme.foo.FooExtension,com.acme.foo.BarExtension staticExtensionClasses=com.acme.foo.FooStaticExtension'''.stripIndent()).write() - def two = buildJar('two.jar') - .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', -'''moduleName=bar + def two = buildJar('two.jar') + .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', + '''moduleName=bar moduleVersion=2.3.5 extensionClasses=com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write() - buildFile << """ + buildFile << """ import ${GroovyExtensionModuleTransformer.name} tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { from('${escapedPath(one)}') @@ -672,39 +672,39 @@ staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write( """.stripIndent() when: - run('shadowJar') + run('shadowJar') then: - output.exists() + output.exists() and: - def text = getJarFileContents(output, 'META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule') - def props = new Properties() - props.load(new StringReader(text)) - props.getProperty('moduleName') == 'MergedByShadowJar' - props.getProperty('moduleVersion') == '1.0.0' - props.getProperty('extensionClasses') == 'com.acme.foo.FooExtension,com.acme.foo.BarExtension,com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension' - props.getProperty('staticExtensionClasses') == 'com.acme.foo.FooStaticExtension,com.acme.bar.SomeStaticExtension' - doesNotContain(output, ['META-INF/services/org.codehaus.groovy.runtime.ExtensionModule']) + def text = getJarFileContents(output, 'META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule') + def props = new Properties() + props.load(new StringReader(text)) + props.getProperty('moduleName') == 'MergedByShadowJar' + props.getProperty('moduleVersion') == '1.0.0' + props.getProperty('extensionClasses') == 'com.acme.foo.FooExtension,com.acme.foo.BarExtension,com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension' + props.getProperty('staticExtensionClasses') == 'com.acme.foo.FooStaticExtension,com.acme.bar.SomeStaticExtension' + doesNotContain(output, ['META-INF/services/org.codehaus.groovy.runtime.ExtensionModule']) } def 'Groovy extension module transformer short syntax'() { given: - def one = buildJar('one.jar') - .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', -'''moduleName=foo + def one = buildJar('one.jar') + .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', + '''moduleName=foo moduleVersion=1.0.5 extensionClasses=com.acme.foo.FooExtension,com.acme.foo.BarExtension staticExtensionClasses=com.acme.foo.FooStaticExtension'''.stripIndent()).write() - def two = buildJar('two.jar') - .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', -'''moduleName=bar + def two = buildJar('two.jar') + .insertFile('META-INF/services/org.codehaus.groovy.runtime.ExtensionModule', + '''moduleName=bar moduleVersion=2.3.5 extensionClasses=com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write() - buildFile << """ + buildFile << """ tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { from('${escapedPath(one)}') from('${escapedPath(two)}') @@ -715,19 +715,19 @@ staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write( """.stripIndent() when: - run('shadowJar') + run('shadowJar') then: - assert output.exists() + assert output.exists() and: - def text = getJarFileContents(output, 'META-INF/services/org.codehaus.groovy.runtime.ExtensionModule') - def props = new Properties() - props.load(new StringReader(text)) - assert props.getProperty('moduleName') == 'MergedByShadowJar' - assert props.getProperty('moduleVersion') == '1.0.0' - assert props.getProperty('extensionClasses') == 'com.acme.foo.FooExtension,com.acme.foo.BarExtension,com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension' - assert props.getProperty('staticExtensionClasses') == 'com.acme.foo.FooStaticExtension,com.acme.bar.SomeStaticExtension' + def text = getJarFileContents(output, 'META-INF/services/org.codehaus.groovy.runtime.ExtensionModule') + def props = new Properties() + props.load(new StringReader(text)) + assert props.getProperty('moduleName') == 'MergedByShadowJar' + assert props.getProperty('moduleVersion') == '1.0.0' + assert props.getProperty('extensionClasses') == 'com.acme.foo.FooExtension,com.acme.foo.BarExtension,com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension' + assert props.getProperty('staticExtensionClasses') == 'com.acme.foo.FooStaticExtension,com.acme.bar.SomeStaticExtension' } @Unroll @@ -762,12 +762,7 @@ staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write( 'Log4j2PluginsCacheFileTransformer' | '' 'ManifestAppenderTransformer' | '' 'ManifestResourceTransformer' | '' - 'PropertiesFileTransformer' | '{ keyTransformer = { it.toLowerCase() } }' 'ServiceFileTransformer' | '' 'XmlAppendingTransformer' | '' } - - private String escapedPath(File file) { - file.path.replaceAll('\\\\', '\\\\\\\\') - } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/AbstractCachingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/AbstractCachingSpec.groovy index bd33ca03d..3c0ed8c9b 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/AbstractCachingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/AbstractCachingSpec.groovy @@ -12,7 +12,8 @@ import static org.gradle.testkit.runner.TaskOutcome.FROM_CACHE import static org.gradle.testkit.runner.TaskOutcome.SUCCESS abstract class AbstractCachingSpec extends PluginSpecification { - @TempDir Path alternateDir + @TempDir + Path alternateDir @Override def setup() { @@ -33,22 +34,18 @@ abstract class AbstractCachingSpec extends PluginSpecification { } BuildResult runWithCacheEnabled(String... arguments) { - List cacheArguments = [ '--build-cache' ] + List cacheArguments = ['--build-cache'] cacheArguments.addAll(arguments) return run(cacheArguments) } BuildResult runInAlternateDirWithCacheEnabled(String... arguments) { - List cacheArguments = [ '--build-cache' ] + List cacheArguments = ['--build-cache'] cacheArguments.addAll(arguments) // TODO: Use PluginSpecification.run here to reuse flags, but cache tests failed for now, need to investigate. return runner.withProjectDir(alternateDir.toFile()).withArguments(cacheArguments).build() } - private String escapedPath(File file) { - file.path.replaceAll('\\\\', '\\\\\\\\') - } - void assertShadowJarHasResult(TaskOutcome expectedOutcome) { def result = runWithCacheEnabled(shadowJarTask) assert result.task(shadowJarTask).outcome == expectedOutcome diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/MinimizationCachingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/MinimizationCachingSpec.groovy index a20ffdf74..460fcc108 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/MinimizationCachingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/MinimizationCachingSpec.groovy @@ -20,7 +20,7 @@ class MinimizationCachingSpec extends AbstractCachingSpec { file('client/build.gradle') << """ apply plugin: 'java' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation 'junit:junit:3.8.2' } """.stripIndent() @@ -33,7 +33,7 @@ class MinimizationCachingSpec extends AbstractCachingSpec { apply plugin: 'java' apply plugin: 'com.gradleup.shadow' - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':client') } """.stripIndent() @@ -45,9 +45,9 @@ class MinimizationCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'junit/framework/Test.class', - 'client/Client.class' + 'server/Server.class', + 'junit/framework/Test.class', + 'client/Client.class' ]) when: @@ -61,7 +61,7 @@ class MinimizationCachingSpec extends AbstractCachingSpec { } } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } dependencies { implementation project(':client') } """.stripIndent() assertShadowJarExecutes() @@ -69,8 +69,8 @@ class MinimizationCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'junit/framework/Test.class' + 'server/Server.class', + 'junit/framework/Test.class' ]) doesNotContain(output, ['client/Client.class']) @@ -80,8 +80,8 @@ class MinimizationCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'junit/framework/Test.class' + 'server/Server.class', + 'junit/framework/Test.class' ]) doesNotContain(output, ['client/Client.class']) } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingSpec.groovy index c0a75c537..9a43e7270 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingSpec.groovy @@ -24,8 +24,8 @@ class RelocationCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'junit/framework/Test.class' + 'server/Server.class', + 'junit/framework/Test.class' ]) when: @@ -41,13 +41,13 @@ class RelocationCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/junit/framework/Test.class' + 'server/Server.class', + 'foo/junit/framework/Test.class' ]) and: doesNotContain(output, [ - 'junit/framework/Test.class' + 'junit/framework/Test.class' ]) when: @@ -56,13 +56,13 @@ class RelocationCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/junit/framework/Test.class' + 'server/Server.class', + 'foo/junit/framework/Test.class' ]) and: doesNotContain(output, [ - 'junit/framework/Test.class' + 'junit/framework/Test.class' ]) } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingSpec.groovy index 0d6a2d741..def98418c 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingSpec.groovy @@ -84,7 +84,7 @@ class ShadowJarCachingSpec extends AbstractCachingSpec { given: buildFile << """ dependencies { implementation 'junit:junit:3.8.2' } - + tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { exclude 'junit/*' } @@ -112,8 +112,8 @@ class ShadowJarCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'server/Util.class' + 'server/Server.class', + 'server/Util.class' ]) when: @@ -130,13 +130,13 @@ class ShadowJarCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) and: doesNotContain(output, [ - 'server/Util.class', - 'junit/framework/Test.class' + 'server/Util.class', + 'junit/framework/Test.class' ]) when: @@ -145,13 +145,13 @@ class ShadowJarCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) and: doesNotContain(output, [ - 'server/Util.class', - 'junit/framework/Test.class' + 'server/Util.class', + 'junit/framework/Test.class' ]) } @@ -178,8 +178,8 @@ class ShadowJarCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'junit/framework/Test.class' + 'server/Server.class', + 'junit/framework/Test.class' ]) when: @@ -197,12 +197,12 @@ class ShadowJarCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) and: doesNotContain(output, [ - 'junit/framework/Test.class' + 'junit/framework/Test.class' ]) when: @@ -211,12 +211,12 @@ class ShadowJarCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) and: doesNotContain(output, [ - 'junit/framework/Test.class' + 'junit/framework/Test.class' ]) } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/TransformCachingSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/TransformCachingSpec.groovy index 93cf1477a..a8507c9af 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/TransformCachingSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/caching/TransformCachingSpec.groovy @@ -23,26 +23,26 @@ class TransformCachingSpec extends AbstractCachingSpec { import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext import org.apache.tools.zip.ZipOutputStream import org.gradle.api.file.FileTreeElement - + class CustomTransformer implements Transformer { @Override boolean canTransformResource(FileTreeElement element) { return false } - + @Override void transform(TransformerContext context) { - + } - + @Override boolean hasTransformedResource() { return false } - + @Override void modifyOutputStream(ZipOutputStream jos, boolean preserveFileTimestamps) { - + } } @@ -58,7 +58,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) when: @@ -67,7 +67,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) } @@ -89,7 +89,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) when: @@ -106,7 +106,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) when: @@ -115,7 +115,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) when: @@ -132,7 +132,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) when: @@ -141,7 +141,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) } @@ -164,7 +164,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) when: @@ -181,8 +181,8 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/bar.properties' + 'server/Server.class', + 'foo/bar.properties' ]) when: @@ -191,8 +191,8 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/bar.properties' + 'server/Server.class', + 'foo/bar.properties' ]) when: @@ -211,8 +211,8 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/baz.properties' + 'server/Server.class', + 'foo/baz.properties' ]) when: @@ -221,8 +221,8 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/baz.properties' + 'server/Server.class', + 'foo/baz.properties' ]) } @@ -245,7 +245,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) when: @@ -262,8 +262,8 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/bar.xml' + 'server/Server.class', + 'foo/bar.xml' ]) when: @@ -272,8 +272,8 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/bar.xml' + 'server/Server.class', + 'foo/bar.xml' ]) when: @@ -292,8 +292,8 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/baz.xml' + 'server/Server.class', + 'foo/baz.xml' ]) when: @@ -302,8 +302,8 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class', - 'foo/baz.xml' + 'server/Server.class', + 'foo/baz.xml' ]) } @@ -325,7 +325,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) when: @@ -340,7 +340,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) when: @@ -349,7 +349,7 @@ class TransformCachingSpec extends AbstractCachingSpec { then: output.exists() contains(output, [ - 'server/Server.class' + 'server/Server.class' ]) } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/ManualCodeSnippetTests.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/ManualCodeSnippetTests.groovy index 76173de2e..b937059aa 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/ManualCodeSnippetTests.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/ManualCodeSnippetTests.groovy @@ -8,6 +8,7 @@ import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.TestCod import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.executer.SnippetExecuter import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.fixture.GroovyScriptFixture import com.google.common.base.StandardSystemProperty +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.DynamicTest import org.junit.jupiter.api.TestFactory import org.junit.jupiter.api.io.TempDir @@ -16,11 +17,12 @@ import java.nio.file.Path class ManualCodeSnippetTests { public static final LinkedHashMap FIXTURES = [ - "groovy": new GradleBuildExecuter("build.gradle", new GroovyDslFixture(), new GroovyDslFixture.ImportsExtractor()), - "groovy no-plugins": new GradleBuildExecuter("build.gradle", new GroovyScriptFixture(), new GroovyDslFixture.ImportsExtractor()), - "groovy no-run": new NoopExecuter() + "groovy" : new GradleBuildExecuter("build.gradle", new GroovyDslFixture(), new GroovyDslFixture.ImportsExtractor()), + "groovy no-plugins": new GradleBuildExecuter("build.gradle", new GroovyScriptFixture(), new GroovyDslFixture.ImportsExtractor()), + "groovy no-run" : new NoopExecuter() ] + @Disabled("We have to run doc tests on main branch only") @TestFactory List provideDynamicTests(@TempDir Path tempDir) { File cwd = new File(StandardSystemProperty.USER_DIR.value()) diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/executer/GradleBuildExecuter.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/executer/GradleBuildExecuter.groovy index 5e5bfd63e..d727eb562 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/executer/GradleBuildExecuter.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/executer/GradleBuildExecuter.groovy @@ -54,7 +54,11 @@ include 'api', 'main' buildFile.text = replaceTokens(fullSnippet) - GradleRunner runner = GradleRunner.create().withProjectDir(tempDir).withPluginClasspath().forwardOutput() + GradleRunner runner = GradleRunner.create() + .withGradleVersion(PluginSpecification.TEST_GRADLE_VERSION) + .withProjectDir(tempDir) + .withPluginClasspath() + .forwardOutput() runner.withArguments(":main:build", "-m").build() @@ -78,6 +82,6 @@ repositories { } private static String replaceTokens(String snippet) { - return snippet.replaceAll("@version@", PluginSpecification.SHADOW_VERSION + '-SNAPSHOT') + return snippet.replaceAll("@version@", 'latest') } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/extractor/ManualSnippetExtractor.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/extractor/ManualSnippetExtractor.groovy index 99d84ca20..7f1f85aa1 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/extractor/ManualSnippetExtractor.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/extractor/ManualSnippetExtractor.groovy @@ -26,7 +26,7 @@ class ManualSnippetExtractor { private static void addSnippets(Path tempDir, List snippets, File file, Pattern snippetBlockPattern, SnippetExecuter executer) { def source = file.text - String testName = file.parentFile.name + "/" +file.name + String testName = file.parentFile.name + "/" + file.name Map snippetsByLine = findSnippetsByLine(source, snippetBlockPattern) snippetsByLine.each { lineNumber, snippet -> diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/Block.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/Block.java index 6be5676e3..133d8cdf4 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/Block.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/Block.java @@ -2,10 +2,10 @@ public interface Block { - /** - * Execute the action. - * - * @throws Exception any - */ - void execute() throws Exception; -} \ No newline at end of file + /** + * Execute the action. + * + * @throws Exception any + */ + void execute() throws Exception; +} diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/TestCodeSnippet.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/TestCodeSnippet.java index e3539c1cb..50ad397ab 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/TestCodeSnippet.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/TestCodeSnippet.java @@ -2,6 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.executer.ExceptionTransformer; import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.executer.SnippetExecuter; + import org.junit.jupiter.api.function.Executable; import java.nio.file.Path; diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/CompileException.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/CompileException.java index 90768b3f3..eeab7a2d4 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/CompileException.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/CompileException.java @@ -2,17 +2,17 @@ public class CompileException extends RuntimeException { - private static final long serialVersionUID = 0; + private static final long serialVersionUID = 0; - private final int lineNo; + private final int lineNo; - public CompileException(Throwable cause, int lineNo) { - super(cause); - this.lineNo = lineNo; - } + public CompileException(Throwable cause, int lineNo) { + super(cause); + this.lineNo = lineNo; + } - public int getLineNo() { - return lineNo; - } + public int getLineNo() { + return lineNo; + } -} \ No newline at end of file +} diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/ExceptionTransformer.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/ExceptionTransformer.groovy index cee765c2c..15331d0ef 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/ExceptionTransformer.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/ExceptionTransformer.groovy @@ -2,38 +2,38 @@ package com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.execut class ExceptionTransformer { - final String sourceClassName - final String sourceFileName - final Integer lineNumber + final String sourceClassName + final String sourceFileName + final Integer lineNumber - ExceptionTransformer(String sourceClassName, String sourceFileName, Integer lineNumber) { - this.sourceClassName = sourceClassName - this.sourceFileName = sourceFileName - this.lineNumber = lineNumber - } + ExceptionTransformer(String sourceClassName, String sourceFileName, Integer lineNumber) { + this.sourceClassName = sourceClassName + this.sourceFileName = sourceFileName + this.lineNumber = lineNumber + } - Throwable transform(Throwable throwable, Integer offset) throws Exception { - def errorLine = 0 + Throwable transform(Throwable throwable, Integer offset) throws Exception { + def errorLine = 0 - if (throwable instanceof CompileException) { - errorLine = throwable.lineNo - } else { - def frame = throwable.getStackTrace().find { it.fileName == sourceClassName } - if (frame) { - errorLine = frame.lineNumber - } else { - frame = throwable.getStackTrace().find { it.fileName == "Example.java" } - if (frame) { - errorLine = frame.lineNumber + if (throwable instanceof CompileException) { + errorLine = throwable.lineNo + } else { + def frame = throwable.getStackTrace().find { it.fileName == sourceClassName } + if (frame) { + errorLine = frame.lineNumber + } else { + frame = throwable.getStackTrace().find { it.fileName == "Example.java" } + if (frame) { + errorLine = frame.lineNumber + } + } } - } + errorLine = errorLine - offset + StackTraceElement[] stack = throwable.getStackTrace() + List newStack = new ArrayList(stack.length + 1) + newStack.add(new StackTraceElement(sourceClassName, "javadoc", sourceFileName, lineNumber + errorLine)) + newStack.addAll(stack) + throwable.setStackTrace(newStack as StackTraceElement[]) + throwable } - errorLine = errorLine - offset - StackTraceElement[] stack = throwable.getStackTrace() - List newStack = new ArrayList(stack.length + 1) - newStack.add(new StackTraceElement(sourceClassName, "javadoc", sourceFileName, lineNumber + errorLine)) - newStack.addAll(stack) - throwable.setStackTrace(newStack as StackTraceElement[]) - throwable - } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/SnippetExecuter.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/SnippetExecuter.java index 1276fb9ae..a78fc8ab8 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/SnippetExecuter.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/executer/SnippetExecuter.java @@ -1,14 +1,14 @@ package com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.executer; -import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.fixture.SnippetFixture; import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.TestCodeSnippet; +import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.fixture.SnippetFixture; import java.io.File; public interface SnippetExecuter { - SnippetFixture getFixture(); + SnippetFixture getFixture(); - void execute(File tempDir, TestCodeSnippet snippet) throws Exception; + void execute(File tempDir, TestCodeSnippet snippet) throws Exception; } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/fixture/GroovyScriptFixture.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/fixture/GroovyScriptFixture.groovy index deff8e9f0..04fdccd67 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/fixture/GroovyScriptFixture.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/fixture/GroovyScriptFixture.groovy @@ -2,9 +2,9 @@ package com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.fixtur class GroovyScriptFixture extends SnippetFixture { - @Override - String post() { - "\n;0;" - } + @Override + String post() { + "\n;0;" + } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/fixture/SnippetFixture.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/fixture/SnippetFixture.java index b59402d40..cf29db97c 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/fixture/SnippetFixture.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/fixture/SnippetFixture.java @@ -4,24 +4,24 @@ public class SnippetFixture { - public void around(Block action) throws Exception { - action.execute(); - } + public void around(Block action) throws Exception { + action.execute(); + } - public String transform(String text) { - return text; - } + public String transform(String text) { + return text; + } - public String pre() { - return ""; - } + public String pre() { + return ""; + } - public String post() { - return ""; - } + public String post() { + return ""; + } - public Integer getOffset() { - return pre().split("\n").length; - } + public Integer getOffset() { + return pre().split("\n").length; + } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorParameterTest.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorParameterTest.groovy index c757308e9..87a8ea0e2 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorParameterTest.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorParameterTest.groovy @@ -21,7 +21,7 @@ package com.github.jengelman.gradle.plugins.shadow.relocation import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.* +import static org.junit.jupiter.api.Assertions.fail /** diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.groovy index 18c7911ab..ba04bfb51 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.groovy @@ -23,7 +23,7 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowStats import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.* +import static org.junit.jupiter.api.Assertions.assertEquals /** * Test for {@link SimpleRelocator}. @@ -42,7 +42,7 @@ class SimpleRelocatorTest { @BeforeEach void setUp() { - stats = new ShadowStats() + stats = new ShadowStats() } @Test @@ -64,7 +64,7 @@ class SimpleRelocatorTest { assertEquals(false, relocator.canRelocatePath("/org/Foo/Class.class")) relocator = new SimpleRelocator("org.foo", null, null, Arrays.asList( - [ "org.foo.Excluded", "org.foo.public.*", "org.foo.recurse.**", "org.foo.Public*Stuff" ] as String[])) + ["org.foo.Excluded", "org.foo.public.*", "org.foo.recurse.**", "org.foo.Public*Stuff"] as String[])) assertEquals(true, relocator.canRelocatePath("org/foo/Class")) assertEquals(true, relocator.canRelocatePath("org/foo/Class.class")) assertEquals(true, relocator.canRelocatePath("org/foo/excluded")) @@ -99,8 +99,8 @@ class SimpleRelocatorTest { assertEquals(true, relocator.canRelocatePath("/org/f")) // equal to path pattern with / } - @Test - void testCanRelocatePathWithRegex() { + @Test + void testCanRelocatePathWithRegex() { SimpleRelocator relocator // Include with Regex @@ -126,12 +126,12 @@ class SimpleRelocatorTest { // Include with Regex and normal pattern relocator = new SimpleRelocator("org.foo", null, - Arrays.asList("%regex[org/foo/.*Factory[0-9].*]", "org.foo.public.*"), null) + Arrays.asList("%regex[org/foo/.*Factory[0-9].*]", "org.foo.public.*"), null) assertEquals(true, relocator.canRelocatePath("org/foo/Factory1.class")) assertEquals(true, relocator.canRelocatePath("org/foo/public/Bar.class")) assertEquals(false, relocator.canRelocatePath("org/foo/Factory.class")) assertEquals(false, relocator.canRelocatePath("org/foo/R.class")) - } + } @Test void testCanRelocateClass() { @@ -144,7 +144,7 @@ class SimpleRelocatorTest { assertEquals(false, relocator.canRelocateClass("org.Foo.Class")) relocator = new SimpleRelocator("org.foo", null, null, Arrays.asList( - [ "org.foo.Excluded", "org.foo.public.*", "org.foo.recurse.**", "org.foo.Public*Stuff" ] as String[])) + ["org.foo.Excluded", "org.foo.public.*", "org.foo.recurse.**", "org.foo.Public*Stuff"] as String[])) assertEquals(true, relocator.canRelocateClass("org.foo.Class")) assertEquals(true, relocator.canRelocateClass("org.foo.excluded")) assertEquals(false, relocator.canRelocateClass("org.foo.Excluded")) diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheLicenseResourceTransformerTest.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheLicenseResourceTransformerTest.groovy index 59a6c62dc..bd2a7b04c 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheLicenseResourceTransformerTest.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheLicenseResourceTransformerTest.groovy @@ -22,7 +22,8 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.* +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertTrue /** * Test for {@link ApacheLicenseResourceTransformer}. diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerParameterTests.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerParameterTests.groovy index 7f93dca88..221bdeb9b 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerParameterTests.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerParameterTests.groovy @@ -24,7 +24,7 @@ import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.* +import static org.junit.jupiter.api.Assertions.fail /** * Tests {@link ApacheLicenseResourceTransformer} parameters. @@ -77,7 +77,7 @@ class ApacheNoticeResourceTransformerParameterTests extends TransformerTestSuppo processAndFailOnNullPointer("\n") } - private static void processAndFailOnNullPointer(final String noticeText) { + private void processAndFailOnNullPointer(final String noticeText) { try { final ByteArrayInputStream noticeInputStream = new ByteArrayInputStream(noticeText.getBytes()) final List emptyList = Collections.emptyList() diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerTest.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerTest.groovy index 65778420c..0b2646aa8 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerTest.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformerTest.groovy @@ -22,7 +22,8 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.* +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertTrue /** * Test for {@link ApacheNoticeResourceTransformer}. diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.groovy index 3797bc85a..dc18c3611 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.groovy @@ -22,7 +22,8 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.* +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertTrue /** * Test for {@link AppendingTransformer}. diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ComponentsXmlResourceTransformerTest.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ComponentsXmlResourceTransformerTest.groovy index b62fd1bc8..aac341cbd 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ComponentsXmlResourceTransformerTest.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ComponentsXmlResourceTransformerTest.groovy @@ -20,12 +20,11 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import com.github.jengelman.gradle.plugins.shadow.ShadowStats - +import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator +import org.codehaus.plexus.util.IOUtil import org.custommonkey.xmlunit.Diff import org.custommonkey.xmlunit.XMLAssert import org.custommonkey.xmlunit.XMLUnit -import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator -import org.codehaus.plexus.util.IOUtil import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -52,22 +51,22 @@ class ComponentsXmlResourceTransformerTest extends TransformerTestSupport emptyList()) - .stats(stats) - .build()) + TransformerContext.builder() + .path("components-1.xml") + .is(getClass().getResourceAsStream("/components-1.xml")) + .relocators(Collections. emptyList()) + .stats(stats) + .build()) transformer.transform( - TransformerContext.builder() - .path("components-1.xml") - .is(getClass().getResourceAsStream("/components-2.xml")) - .relocators(Collections. emptyList()) - .stats(stats) - .build()) + TransformerContext.builder() + .path("components-1.xml") + .is(getClass().getResourceAsStream("/components-2.xml")) + .relocators(Collections. emptyList()) + .stats(stats) + .build()) Diff diff = XMLUnit.compareXML( - IOUtil.toString(getClass().getResourceAsStream("/components-expected.xml"), "UTF-8"), - IOUtil.toString(transformer.getTransformedResource(), "UTF-8")) + IOUtil.toString(getClass().getResourceAsStream("/components-expected.xml"), "UTF-8"), + IOUtil.toString(transformer.getTransformedResource(), "UTF-8")) //assertEquals( IOUtil.toString( getClass().getResourceAsStream( "/components-expected.xml" ), "UTF-8" ), // IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ).replaceAll("\r\n", "\n") ) XMLAssert.assertXMLIdentical(diff, true) diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformerSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformerSpec.groovy index becdaf25e..a9659a85e 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformerSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformerSpec.groovy @@ -7,7 +7,6 @@ import org.apache.logging.log4j.core.config.plugins.processor.PluginCache import org.apache.tools.zip.ZipOutputStream import spock.lang.Specification - import static java.util.Collections.singletonList import static org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformerTest.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformerTest.groovy index b99a4fb39..1da4856ae 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformerTest.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestAppenderTransformerTest.groovy @@ -72,7 +72,7 @@ class ManifestAppenderTransformerTest extends TransformerTestSupportemptyList(), new ShadowStats())) + transform(new TransformerContext(MANIFEST_NAME, getResourceStream(MANIFEST_NAME), Collections. emptyList(), new ShadowStats())) } def testableZipFile = File.createTempFile("testable-zip-file-", ".jar") @@ -104,7 +104,7 @@ class ManifestAppenderTransformerTest extends TransformerTestSupportemptyList(), new ShadowStats())) + transformer.transform(new TransformerContext(MANIFEST_NAME, getResourceStream(MANIFEST_NAME), Collections. emptyList(), new ShadowStats())) def testableZipFile = File.createTempFile("testable-zip-file-", ".jar") def fileOutputStream = new FileOutputStream(testableZipFile) diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerSpec.groovy index 333048ac4..578d4a1df 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerSpec.groovy @@ -158,7 +158,7 @@ class PropertiesFileTransformerSpec extends TransformerSpecSupport { output == toMap(transformer.propertiesEntries[path]) where: - path | charset | input || output - 'utf8.properties' | 'utf-8' | ['foo': '传傳磨宿说説'] || ['foo': '传傳磨宿说説'] + path | charset | input || output + 'utf8.properties' | 'utf-8' | ['foo': '传傳磨宿说説'] || ['foo': '传傳磨宿说説'] } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerTest.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerTest.groovy index 2d186a00e..c322029ad 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerTest.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformerTest.groovy @@ -35,7 +35,7 @@ final class PropertiesFileTransformerTest extends TransformerTestSupportemptyList(), new ShadowStats())) + transformer.transform(new TransformerContext(MANIFEST_NAME, getResourceStream(MANIFEST_NAME), Collections. emptyList(), new ShadowStats())) def testableZipFile = doTransformAndGetTransformedFile(transformer, false) def targetLines = readFrom(testableZipFile, MANIFEST_NAME) @@ -47,7 +47,7 @@ final class PropertiesFileTransformerTest extends TransformerTestSupportemptyList(), new ShadowStats())) + transformer.transform(new TransformerContext(MANIFEST_NAME, getResourceStream(MANIFEST_NAME), Collections. emptyList(), new ShadowStats())) def firstRunTransformedFile = doTransformAndGetTransformedFile(transformer, true) def firstRunTargetLines = readFrom(firstRunTransformedFile, MANIFEST_NAME) @@ -60,7 +60,7 @@ final class PropertiesFileTransformerTest extends TransformerTestSupport { - protected static T transformer + protected T transformer protected static FileTreeElement getFileElement(String path) { return new DefaultFileTreeElement(null, RelativePath.parse(true, path), null, null) diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.groovy index ff38997c9..a33cb56d8 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.groovy @@ -22,7 +22,8 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import static org.junit.jupiter.api.Assertions.* +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertTrue /** * Test for {@link XmlAppendingTransformer}. diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.java index c3c41596d..f92bae511 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/HashUtil.java @@ -1,13 +1,14 @@ package com.github.jengelman.gradle.plugins.shadow.util; -import org.gradle.api.UncheckedIOException; import org.gradle.internal.UncheckedException; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index d33e95530..92e53591b 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -14,9 +14,10 @@ import java.util.jar.JarFile abstract class PluginSpecification extends Specification { - @TempDir Path dir + @TempDir + Path dir - public static final String SHADOW_VERSION = System.getProperty("shadowVersion") + public static final String TEST_GRADLE_VERSION = System.getProperty("TEST_GRADLE_VERSION") AppendableMavenFileRepository repo @@ -39,7 +40,7 @@ abstract class PluginSpecification extends Specification { return """ plugins { id '${javaPlugin}' - id 'com.gradleup.shadow' version '${SHADOW_VERSION}' + id 'com.gradleup.shadow' } version = "1.0" @@ -49,15 +50,16 @@ abstract class PluginSpecification extends Specification { integTest } - repositories { maven { url "${repo.uri}" } } + repositories { maven { url = "${repo.uri}" } } """.stripIndent() } GradleRunner getRunner() { GradleRunner.create() - .withProjectDir(dir.toFile()) - .forwardOutput() - .withPluginClasspath() + .withGradleVersion(TEST_GRADLE_VERSION) + .withProjectDir(dir.toFile()) + .forwardOutput() + .withPluginClasspath() } GradleRunner runner(Collection tasks) { @@ -92,7 +94,7 @@ abstract class PluginSpecification extends Specification { static boolean containsDeprecationWarning(String output) { output.contains("has been deprecated and is scheduled to be removed in Gradle") || - output.contains("has been deprecated. This is scheduled to be removed in Gradle") + output.contains("has been deprecated. This is scheduled to be removed in Gradle") } File getBuildFile() { @@ -177,6 +179,10 @@ abstract class PluginSpecification extends Specification { return new File(this.class.classLoader.getResource(name).toURI()) } + protected String escapedPath(File file) { + file.path.replaceAll('\\\\', '\\\\\\\\') + } + static File getTestKitDir() { def gradleUserHome = System.getenv("GRADLE_USER_HOME") if (!gradleUserHome) { diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java index c18966cda..90ce4ecf4 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFile.java @@ -16,7 +16,11 @@ package com.github.jengelman.gradle.plugins.shadow.util.file; -import groovy.lang.Closure; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.commons.io.FileUtils; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -25,17 +29,29 @@ import org.apache.tools.ant.types.EnumeratedAttribute; import org.codehaus.groovy.runtime.ResourceGroovyMethods; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectStreamException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.Charset; import java.security.MessageDigest; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Formatter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; import java.util.jar.JarFile; import java.util.jar.Manifest; -import static org.junit.jupiter.api.Assertions.*; +import groovy.lang.Closure; public class TestFile extends File { private boolean useNativeTools; @@ -203,7 +219,7 @@ public void copyTo(File target) { FileUtils.copyDirectory(this, target); } catch (IOException e) { throw new RuntimeException(String.format("Could not copy test directory '%s' to '%s'", this, - target), e); + target), e); } } else { try { @@ -394,7 +410,7 @@ public TestFile createDir() { return this; } throw new AssertionError("Problems creating dir: " + this - + ". Diagnostics: exists=" + this.exists() + ", isFile=" + this.isFile() + ", isDirectory=" + this.isDirectory()); + + ". Diagnostics: exists=" + this.exists() + ", isFile=" + this.isFile() + ", isDirectory=" + this.isDirectory()); } public TestFile createDir(Object path) { @@ -408,6 +424,7 @@ public TestFile deleteDir() { /** * Attempts to delete this directory, ignoring failures to do so. + * * @return this */ public TestFile maybeDeleteDir() { @@ -444,7 +461,7 @@ public TestFile createZip(Object path) { return zipFile; } - public TestFile zipTo(TestFile zipFile){ + public TestFile zipTo(TestFile zipFile) { new TestFileHelper(this).zipTo(zipFile, useNativeTools); return this; } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFileHelper.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFileHelper.groovy index c9c9db88f..414f09132 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFileHelper.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestFileHelper.groovy @@ -10,7 +10,7 @@ import org.apache.tools.ant.taskdefs.Zip import java.util.zip.ZipInputStream -import static org.junit.jupiter.api.Assertions.* +import static org.junit.jupiter.api.Assertions.assertTrue class TestFileHelper { TestFile file @@ -21,7 +21,7 @@ class TestFileHelper { void unzipTo(File target, boolean nativeTools) { // Check that each directory in hierarchy is present - file.withInputStream {InputStream instr -> + file.withInputStream { InputStream instr -> def dirs = [] as Set def zipStr = new ZipInputStream(instr) def entry diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestWorkspaceBuilder.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestWorkspaceBuilder.groovy index 34ca1ff23..2af22f3e9 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestWorkspaceBuilder.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestWorkspaceBuilder.groovy @@ -31,8 +31,7 @@ class TestWorkspaceBuilder { def methodMissing(String name, Object args) { if (args.length == 1 && args[0] instanceof Closure) { baseDir.file(name).create(args[0]) - } - else { + } else { throw new MissingMethodException(name, getClass(), args) } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy index c9aa10403..16a2fffd6 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/AbstractMavenModule.groovy @@ -4,6 +4,7 @@ import com.github.jengelman.gradle.plugins.shadow.util.file.TestFile import com.github.jengelman.gradle.plugins.shadow.util.repo.AbstractModule import groovy.xml.MarkupBuilder import groovy.xml.XmlParser + import java.text.SimpleDateFormat abstract class AbstractMavenModule extends AbstractModule implements MavenModule { @@ -166,7 +167,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule for (name in artifactNames) { assert actual.remove(name) - if(publishesHashFiles()) { + if (publishesHashFiles()) { assert actual.remove("${name}.md5" as String) assert actual.remove("${name}.sha1" as String) } @@ -299,7 +300,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule } } else { versions { - allVersions.each {currVersion -> + allVersions.each { currVersion -> version(currVersion) } } @@ -339,5 +340,6 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule } protected abstract boolean publishesMetaDataFile() + protected abstract boolean publishesHashFiles() } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/DefaultMavenMetaData.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/DefaultMavenMetaData.groovy index ab2ab217f..bccdb40f1 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/DefaultMavenMetaData.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/DefaultMavenMetaData.groovy @@ -5,7 +5,7 @@ import groovy.xml.XmlParser /** * http://maven.apache.org/ref/3.0.1/maven-repository-metadata/repository-metadata.html */ -class DefaultMavenMetaData implements MavenMetaData{ +class DefaultMavenMetaData implements MavenMetaData { String text diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPom.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPom.groovy index 4838f4ab8..9aa3d1ba4 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPom.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenPom.groovy @@ -11,7 +11,7 @@ class MavenPom { final Map scopes = [:] MavenPom(File pomFile) { - if (pomFile.exists()){ + if (pomFile.exists()) { def pom = new XmlParser().parse(pomFile) groupId = pom.groupId[0]?.text() @@ -29,11 +29,11 @@ class MavenPom { scopes[scopeName] = scope } MavenDependency mavenDependency = new MavenDependency( - groupId: dep.groupId.text(), - artifactId: dep.artifactId.text(), - version: dep.version.text(), - classifier: dep.classifier ? dep.classifier.text() : null, - type: dep.type ? dep.type.text() : null + groupId: dep.groupId.text(), + artifactId: dep.artifactId.text(), + version: dep.version.text(), + classifier: dep.classifier ? dep.classifier.text() : null, + type: dep.type ? dep.type.text() : null ) def key = "${mavenDependency.groupId}:${mavenDependency.artifactId}:${mavenDependency.version}" key += mavenDependency.classifier ? ":${mavenDependency.classifier}" : ""