diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 405a2b306..e18701c6e 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -1,10 +1,20 @@ name: "Validate Gradle Wrapper" -on: [push, pull_request] +on: + push: + paths: + - 'gradlew' + - 'gradlew.bat' + - 'gradle/wrapper/' + pull_request: + paths: + - 'gradlew' + - 'gradlew.bat' + - 'gradle/wrapper/' jobs: validation: name: "Validation" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: gradle/wrapper-validation-action@v1 diff --git a/README.md b/README.md index 5518409b9..6056f4f62 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,9 @@ Read the [User Guide](https://imperceptiblethoughts.com/shadow/)! | 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+ | +| 5.x | 5.2.0 - 6.0.0 | +| 6.x | 5.2.0 - 6.1.0 | +| 7.x | 7.0.0+ | +| 8.x | 8.0.0+ | **NOTE**: Shadow v5.+ is compatible with Gradle 5.x - 6.x and Java 7 - 15 _only_, v6.1.0+ requires Java 8+. diff --git a/build.gradle b/build.gradle index c3cc3f203..f2927abb2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,23 +1,15 @@ +import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation -buildscript { - repositories { - gradlePluginPortal() - mavenCentral() - } - dependencies { - classpath "com.gradle.publish:plugin-publish-plugin:0.16.0" - classpath 'org.ajoberstar:gradle-git-publish:3.0.0' - classpath "com.github.node-gradle:gradle-node-plugin:3.1.1" - } -} - plugins { id 'groovy' id 'project-report' id 'idea' id 'java-gradle-plugin' id 'signing' + id 'com.gradle.plugin-publish' version '1.1.0' + id 'org.ajoberstar.git-publish' version '4.1.1' + id 'com.github.node-gradle.node' version '3.5.1' } // Remove the gradleApi so it isn't merged into the jar file. @@ -25,11 +17,7 @@ configurations.named(JavaPlugin.API_CONFIGURATION_NAME) { dependencies.remove(project.dependencies.gradleApi()) } -gradlePlugin { - automatedPublishing = false -} - -apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: ShadowPlugin apply from: file('gradle/docs.gradle') apply from: file('gradle/publish.gradle') @@ -74,29 +62,29 @@ idea { sourceCompatibility = '1.8' targetCompatibility = '1.8' -task downloadDependencies(type: Exec) { +tasks.register('downloadDependencies', Exec) { dependsOn configurations.testRuntimeClasspath commandLine 'echo', 'Downloaded all dependencies' } -tasks.build.dependsOn tasks.shadowJar +tasks.named('build') { dependsOn tasks.named('shadowJar') } -project.tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { // This will be the default in Gradle 5.0 if (!options.compilerArgs.contains("-processor")) { options.compilerArgs << '-proc:none' } } -project.tasks.withType(GroovyCompile) { +tasks.withType(GroovyCompile).configureEach { // This will be the default in Gradle 5.0 if (!options.compilerArgs.contains("-processor")) { options.compilerArgs << '-proc:none' } } -task relocateShadowJar(type: ConfigureShadowRelocation) { +tasks.register('relocateShadowJar', ConfigureShadowRelocation) { target = tasks.shadowJar } -tasks.shadowJar.dependsOn tasks.relocateShadowJar +tasks.named('shadowJar') { dependsOn tasks.relocateShadowJar } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 395af0a91..689ee9bcc 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -53,14 +53,14 @@ sourceSets { } } -project.tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { // This will be the default in Gradle 5.0 if (!options.compilerArgs.contains("-processor")) { options.compilerArgs << '-proc:none' } } -project.tasks.withType(GroovyCompile) { +tasks.withType(GroovyCompile).configureEach { // This will be the default in Gradle 5.0 if (!options.compilerArgs.contains("-processor")) { options.compilerArgs << '-proc:none' diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index be08708bd..46d57b906 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -8,20 +8,20 @@ dependencies { implementation 'org.ow2.asm:asm:9.4' implementation 'org.ow2.asm:asm-commons:9.4' implementation 'commons-io:commons-io:2.11.0' - implementation 'org.apache.ant:ant:1.10.12' - implementation 'org.codehaus.plexus:plexus-utils:3.4.2' - implementation "org.apache.logging.log4j:log4j-core:2.18.0" + implementation 'org.apache.ant:ant:1.10.13' + implementation 'org.codehaus.plexus:plexus-utils:3.5.0' + implementation "org.apache.logging.log4j:log4j-core:2.20.0" implementation('org.vafer:jdependency:2.8.0') { exclude group: 'org.ow2.asm' } - testImplementation('org.spockframework:spock-core:2.1-groovy-3.0') { + testImplementation('org.spockframework:spock-core:2.3-groovy-3.0') { exclude group: 'org.codehaus.groovy' } - testImplementation 'org.spockframework:spock-junit4:2.1-groovy-3.0' + testImplementation 'org.spockframework:spock-junit4:2.3-groovy-3.0' testImplementation 'xmlunit:xmlunit:1.6' testImplementation 'org.apache.commons:commons-lang3:3.12.0' testImplementation 'com.google.guava:guava:31.1-jre' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.9.0' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2' + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.9.2' } diff --git a/gradle/docs.gradle b/gradle/docs.gradle index 47d49c055..10c1eaaff 100644 --- a/gradle/docs.gradle +++ b/gradle/docs.gradle @@ -1,7 +1,7 @@ -def javaApiUrl = 'http://docs.oracle.com/javase/17/docs/api' -def groovyApiUrl = "http://docs.groovy-lang.org/2.4.7/html/gapi/" +def javaApiUrl = 'https://docs.oracle.com/javase/17/docs/api' +def groovyApiUrl = "https://docs.groovy-lang.org/2.4.7/html/gapi/" -tasks.withType(Javadoc) { +tasks.withType(Javadoc).configureEach { classpath += project.configurations.shadow options.links(javaApiUrl, groovyApiUrl) if (JavaVersion.current().java8Compatible) { @@ -9,18 +9,19 @@ tasks.withType(Javadoc) { } } -task javadocJar(type: Jar, dependsOn: javadoc) { +tasks.register('javadocJar', Jar) { + dependsOn javadoc archiveClassifier.set('javadoc') from 'build/docs/javadoc' } -task sourcesJar(type: Jar) { +tasks.register('sourcesJar', Jar) { archiveClassifier.set('sources') from sourceSets.main.allSource } -project.tasks.groovydoc { +tasks.named('groovydoc') { classpath += project.configurations.shadow } -build.dependsOn javadocJar, sourcesJar +tasks.named('build') { dependsOn javadocJar, sourcesJar } diff --git a/gradle/ghPages.gradle b/gradle/ghPages.gradle index 2910f2ef1..fa1526860 100644 --- a/gradle/ghPages.gradle +++ b/gradle/ghPages.gradle @@ -3,7 +3,7 @@ import org.apache.tools.ant.filters.ReplaceTokens apply plugin: 'org.ajoberstar.git-publish' if (project.hasProperty('githubToken')) { - System.setProperty('org.ajoberstar.grgit.auth.username', project.githubToken) + System.setProperty('org.ajoberstar.grgit.auth.username', project.githubToken) } gitPublish { @@ -23,5 +23,5 @@ gitPublish { } } -tasks.gitPublishCopy.dependsOn yarn_build -tasks.gitPublishCopy.dependsOn groovydoc +tasks.named('gitPublishCopy') { dependsOn yarn_build } +tasks.named('gitPublishCopy') { dependsOn groovydoc } diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 4a946ba00..db1d66455 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -1,98 +1,40 @@ -apply plugin: 'maven-publish' apply plugin: "com.gradle.plugin-publish" group = 'com.github.johnrengelman' -def versionString = file('src/main/resources/shadow-version.txt').text.trim() if (System.env.CIRCLE_TAG && System.env.CIRCLE_TAG =~ /^\d\.\d\.\d$/) { version = System.env.CIRCLE_TAG } else { - version = versionString + version = file('src/main/resources/shadow-version.txt').text.trim() if (!version.endsWith("-SNAPSHOT")) { version = version + "-SNAPSHOT" } } -ext.isSnapshot = version.endsWith("SNAPSHOT") - -def pomConfig = { - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - developers { - developer { - id 'jengelman' - name 'John Engelman' - email 'john.r.engelman@gmail.com' - } - } -} - -publishing { - publications { - plugin(MavenPublication) { - shadow.component(it) - artifact sourcesJar - artifact javadocJar - - pom.withXml { - def root = asNode() - root.appendNode('description', 'Gradle plugin to combine/relocate dependencies in a single Jar.') - root.children().last() + pomConfig - } - } - } -} - -// Workaround for configuring the artifact that publish-plugins uses: https://github.com/JLLeitschuh/ktlint-gradle/blob/master/plugin/build.gradle.kts -// Need to move publishing configuration into afterEvaluate {} -// to override changes done by "com.gradle.plugin-publish" plugin in afterEvaluate {} block -// See PublishPlugin class for details -afterEvaluate { - publishing { - publications { - withType(MavenPublication) { - // Special workaround to publish shadow jar instead of normal one. Name to override peeked here: - // https://github.com/gradle/gradle/blob/master/subprojects/plugin-development/src/main/java/org/gradle/plugin/devel/plugins/MavenPluginPublishPlugin.java#L73 - if (name == "pluginMaven") { - setArtifacts([ - tasks.shadowJar, - tasks.sourcesJar, - tasks.javadocJar - ]) - } - } - } - } -} - -tasks.whenTaskAdded { +tasks.configureEach { if (name == "publishPluginJar" || name == "generateMetadataFileForPluginMavenPublication") { dependsOn(tasks.named("shadowJar")) } } -pluginBundle { +gradlePlugin { website = 'https://github.com/johnrengelman/shadow' vcsUrl = 'https://github.com/johnrengelman/shadow' - tags = ['onejar', 'shade', 'fatjar', 'uberjar'] plugins { shadowPlugin { id = 'com.github.johnrengelman.shadow' + implementationClass = 'com.github.jengelman.gradle.plugins.shadow.ShadowPlugin' displayName = 'Shadow Plugin' 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." + tags.set(['onejar', 'shade', 'fatjar', 'uberjar']) } } } -publishPlugins { task -> +tasks.named('publishPlugins') { doFirst { - if (isSnapshot) { + if (version.endsWith("SNAPSHOT")) { throw new GradleException('Cannot publish SNAPSHOT versions to Plugin Portal!') } } @@ -105,12 +47,10 @@ signing { def signingPassword = findProperty("signingPassword") useInMemoryPgpKeys(signingKey, signingPassword) } - required { - gradle.taskGraph.hasTask("artifactoryPublish") - } - sign publishing.publications.plugin + required = gradle.taskGraph.hasTask("artifactoryPublish") + sign(publishing.publications) } -task release() { +tasks.register('release') { dependsOn 'assemble', 'publishPlugins', 'gitPublishPush' } diff --git a/gradle/vuepress.gradle b/gradle/vuepress.gradle index de87a4a16..da01b2f1c 100644 --- a/gradle/vuepress.gradle +++ b/gradle/vuepress.gradle @@ -4,5 +4,7 @@ node { yarnVersion = '1.5.1' } -tasks.yarn_build.inputs.files project.fileTree('src/docs') -tasks.yarn_build.outputs.dir project.file('build/site') \ No newline at end of file +tasks.named('yarn_build') { + inputs.files project.fileTree('src/docs') + outputs.dir project.file('build/site') +} \ No newline at end of file diff --git a/renovate.json b/renovate.json new file mode 100644 index 000000000..39a2b6e9a --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} diff --git a/settings.gradle b/settings.gradle index 1d59b7d5f..5d3598e3e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,10 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } +} + plugins { id 'com.gradle.enterprise' version '3.12.3' } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy index d0000a6b0..cc60e8649 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy @@ -32,7 +32,7 @@ class ShadowApplicationPlugin implements Plugin { this.project = project this.javaApplication = project.extensions.getByType(JavaApplication) - DistributionContainer distributions = project.extensions.getByName("distributions") + DistributionContainer distributions = project.extensions.getByName("distributions") as DistributionContainer Distribution distribution = distributions.create("shadow") addRunTask(project) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy index b367957d7..1f7a3a7d4 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowBasePlugin.groovy @@ -25,7 +25,7 @@ class ShadowBasePlugin implements Plugin { } } - private void createShadowConfiguration(Project project) { + private static void createShadowConfiguration(Project project) { project.configurations.create(CONFIGURATION_NAME) } } 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 09a147d93..22f791066 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 @@ -18,7 +18,7 @@ class ShadowJavaPlugin implements Plugin { public static final String SHADOW_JAR_TASK_NAME = 'shadowJar' public static final String SHADOW_GROUP = 'Shadow' - private final ProjectConfigurationActionContainer configurationActionContainer; + private final ProjectConfigurationActionContainer configurationActionContainer @Inject ShadowJavaPlugin(ProjectConfigurationActionContainer configurationActionContainer) { @@ -54,7 +54,7 @@ class ShadowJavaPlugin implements Plugin { } } - protected void configureShadowTask(Project project) { + protected static void configureShadowTask(Project project) { SourceSetContainer sourceSets = project.extensions.getByType(SourceSetContainer) project.tasks.register(SHADOW_JAR_TASK_NAME, ShadowJar) { shadow -> shadow.group = SHADOW_GROUP 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 4cfdb23c5..2e7815d82 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 @@ -22,7 +22,7 @@ class ShadowStats { relocations.collect { k, v -> "${k} ${separator(k, maxLength)} ${v}"}.sort().join("\n") } - String separator(String key, int max) { + static String separator(String key, int max) { return "→" } 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 f81b64a2b..5bed7a56d 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 @@ -15,11 +15,11 @@ class CleanProperties extends Properties { @Override void write(final int b) throws IOException { if (firstLineSeen) { - super.write(b); + super.write(b) } else if (b == '\n') { - super.write(b); + super.write(b) - firstLineSeen = true; + firstLineSeen = true } } diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/GradleVersionUtil.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/GradleVersionUtil.groovy index 4e54a32cd..91606a31d 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/GradleVersionUtil.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/GradleVersionUtil.groovy @@ -9,17 +9,11 @@ import org.gradle.util.GradleVersion class GradleVersionUtil { - private final GradleVersion version - - GradleVersionUtil(String version) { - this.version = GradleVersion.version(version) - } - - PatternSet getRootPatternSet(CopySpecInternal mainSpec) { + static PatternSet getRootPatternSet(CopySpecInternal mainSpec) { return mainSpec.buildRootResolver().getPatternSet() } - ZipCompressor getInternalCompressor(ZipEntryCompression entryCompression, Jar jar) { + static ZipCompressor getInternalCompressor(ZipEntryCompression entryCompression, Jar jar) { switch (entryCompression) { case ZipEntryCompression.DEFLATED: return new DefaultZipCompressor(jar.zip64, ZipOutputStream.DEFLATED) 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 890b3fb82..2affa9fbe 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 @@ -11,7 +11,7 @@ class JavaJarExec extends JavaExec { @Override @TaskAction - public void exec() { + void exec() { List allArgs = [getJarFile().path] + getArgs() setArgs(allArgs) super.exec() 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 762005ffc..4853c3a77 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 @@ -23,7 +23,7 @@ class MinimizeDependencyFilter extends AbstractDependencyFilter { } } - private boolean isParentExcluded(Set excludedDependencies, ResolvedDependency dependency) { + 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/ZipCompressor.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/ZipCompressor.groovy index 5bd6a5055..b93be9ff3 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/ZipCompressor.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/ZipCompressor.groovy @@ -18,7 +18,7 @@ package com.github.jengelman.gradle.plugins.shadow.internal import org.apache.tools.zip.ZipOutputStream import org.gradle.api.internal.file.archive.compression.ArchiveOutputStreamFactory -public interface ZipCompressor extends ArchiveOutputStreamFactory { +interface ZipCompressor extends ArchiveOutputStreamFactory { ZipOutputStream createArchiveOutputStream(File destination) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy index 59aab7207..a215d49fa 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/DefaultInheritManifest.groovy @@ -59,7 +59,7 @@ class DefaultInheritManifest implements InheritManifest { } @Override - public DefaultManifest getEffectiveManifest() { + DefaultManifest getEffectiveManifest() { DefaultManifest base = new DefaultManifest(fileResolver) inheritMergeSpecs.each { base = it.merge(base, fileResolver) 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 3b7747085..69f8f129d 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 @@ -53,14 +53,13 @@ class ShadowCopyAction implements CopyAction { private final PatternSet patternSet private final ShadowStats stats private final String encoding - private final GradleVersionUtil versionUtil private final boolean preserveFileTimestamps private final boolean minimizeJar private final UnusedTracker unusedTracker ShadowCopyAction(File zipFile, ZipCompressor compressor, DocumentationRegistry documentationRegistry, String encoding, List transformers, List relocators, - PatternSet patternSet, ShadowStats stats, GradleVersionUtil util, + PatternSet patternSet, ShadowStats stats, boolean preserveFileTimestamps, boolean minimizeJar, UnusedTracker unusedTracker) { this.zipFile = zipFile @@ -71,7 +70,6 @@ class ShadowCopyAction implements CopyAction { this.patternSet = patternSet this.stats = stats this.encoding = encoding - this.versionUtil = util this.preserveFileTimestamps = preserveFileTimestamps this.minimizeJar = minimizeJar this.unusedTracker = unusedTracker @@ -154,7 +152,7 @@ class ShadowCopyAction implements CopyAction { } catch(Throwable t) { try { resource.close() - } catch (IOException e) { + } catch (IOException ignored) { // Ignored } throw UncheckedException.throwAsUncheckedException(t) @@ -373,7 +371,7 @@ class ShadowCopyAction implements CopyAction { zipOutStr.putNextEntry(archiveEntry) IOUtils.copyLarge(bis, zipOutStr) zipOutStr.closeEntry() - } catch (ZipException e) { + } catch (ZipException ignored) { log.warn("We have a duplicate " + mappedName + " in source project") } finally { bis.close() 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 1b42c6b94..2f32f1672 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 @@ -7,18 +7,16 @@ import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator; import com.github.jengelman.gradle.plugins.shadow.transformers.*; import org.gradle.api.Action; -import org.gradle.api.Task; -import org.gradle.api.artifacts.Configuration; import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.DuplicatesStrategy; import org.gradle.api.file.FileCollection; 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.specs.Spec; import org.gradle.api.tasks.*; import org.gradle.api.tasks.bundling.Jar; import org.gradle.api.tasks.util.PatternSet; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.lang.reflect.InvocationTargetException; @@ -35,18 +33,17 @@ public class ShadowJar extends Jar implements ShadowSpec { private transient DependencyFilter dependencyFilter; private boolean minimizeJar; - private transient DependencyFilter dependencyFilterForMinimize; + private final transient DependencyFilter dependencyFilterForMinimize; private FileCollection toMinimize; private FileCollection apiJars; private FileCollection sourceSetsClassesDirs; private final ShadowStats shadowStats = new ShadowStats(); - private final GradleVersionUtil versionUtil; private final ConfigurableFileCollection includedDependencies = getProject().files(new Callable() { @Override - public FileCollection call() throws Exception { + public FileCollection call() { return dependencyFilter.resolve(configurations); } }); @@ -54,7 +51,6 @@ public FileCollection call() throws Exception { public ShadowJar() { super(); setDuplicatesStrategy(DuplicatesStrategy.INCLUDE); //shadow filters out files later. This was the default behavior in Gradle < 6.x - versionUtil = new GradleVersionUtil(getProject().getGradle().getGradleVersion()); dependencyFilter = new DefaultDependencyFilter(getProject()); dependencyFilterForMinimize = new MinimizeDependencyFilter(getProject()); setManifest(new DefaultInheritManifest(getServices().get(FileResolver.class))); @@ -62,27 +58,19 @@ public ShadowJar() { relocators = new ArrayList<>(); configurations = new ArrayList<>(); - this.getInputs().property("minimize", new Callable() { - @Override - public Boolean call() throws Exception { - return minimizeJar; - } - }); - this.getOutputs().doNotCacheIf("Has one or more transforms or relocators that are not cacheable", new Spec() { - @Override - public boolean isSatisfiedBy(Task task) { - for (Transformer transformer : transformers) { - if (!isCacheableTransform(transformer.getClass())) { - return true; - } + this.getInputs().property("minimize", (Callable) () -> minimizeJar); + this.getOutputs().doNotCacheIf("Has one or more transforms or relocators that are not cacheable", task -> { + for (Transformer transformer : transformers) { + if (!isCacheableTransform(transformer.getClass())) { + return true; } - for (Relocator relocator : relocators) { - if (!isCacheableRelocator(relocator.getClass())) { - return true; - } + } + for (Relocator relocator : relocators) { + if (!isCacheableRelocator(relocator.getClass())) { + return true; } - return false; } + return false; }); } @@ -111,12 +99,13 @@ public InheritManifest getManifest() { } @Override + @NotNull 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, - versionUtil, isPreserveFileTimestamps(), minimizeJar, unusedTracker); + isPreserveFileTimestamps(), minimizeJar, unusedTracker); } @Classpath @@ -152,19 +141,14 @@ FileCollection getSourceSetsClassesDirs() { allClassesDirs.from(classesDirs); } } - sourceSetsClassesDirs = allClassesDirs.filter(new Spec() { - @Override - public boolean isSatisfiedBy(File file) { - return file.isDirectory(); - } - }); + sourceSetsClassesDirs = allClassesDirs.filter(File::isDirectory); } return sourceSetsClassesDirs; } @Internal protected ZipCompressor getInternalCompressor() { - return versionUtil.getInternalCompressor(getEntryCompression(), this); + return GradleVersionUtil.getInternalCompressor(getEntryCompression(), this); } @TaskAction @@ -186,7 +170,7 @@ public FileCollection getIncludedDependencies() { */ @Internal protected PatternSet getRootPatternSet() { - return versionUtil.getRootPatternSet(getMainSpec()); + return GradleVersionUtil.getRootPatternSet(getMainSpec()); } /** @@ -256,10 +240,8 @@ private void addTransform(T transformer, Action c) { public ShadowJar mergeServiceFiles() { try { transform(ServiceFileTransformer.class); - } catch (IllegalAccessException e) { - } catch (InstantiationException e) { - } catch (NoSuchMethodException e) { - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | + InstantiationException ignored) { } return this; } @@ -271,17 +253,9 @@ public ShadowJar mergeServiceFiles() { */ public ShadowJar mergeServiceFiles(final String rootPath) { try { - transform(ServiceFileTransformer.class, new Action() { - - @Override - public void execute(ServiceFileTransformer serviceFileTransformer) { - serviceFileTransformer.setPath(rootPath); - } - }); - } catch (IllegalAccessException e) { - } catch (InstantiationException e) { - } catch (NoSuchMethodException e) { - } catch (InvocationTargetException e) { + transform(ServiceFileTransformer.class, serviceFileTransformer -> serviceFileTransformer.setPath(rootPath)); + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | + InstantiationException ignored) { } return this; } @@ -294,10 +268,8 @@ public void execute(ServiceFileTransformer serviceFileTransformer) { public ShadowJar mergeServiceFiles(Action configureClosure) { try { transform(ServiceFileTransformer.class, configureClosure); - } catch (IllegalAccessException e) { - } catch (InstantiationException e) { - } catch (NoSuchMethodException e) { - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | + InstantiationException ignored) { } return this; } @@ -310,10 +282,8 @@ public ShadowJar mergeServiceFiles(Action configureClosu public ShadowJar mergeGroovyExtensionModules() { try { transform(GroovyExtensionModuleTransformer.class); - } catch (IllegalAccessException e) { - } catch (InstantiationException e) { - } catch (NoSuchMethodException e) { - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | + InstantiationException ignored) { } return this; } @@ -325,16 +295,9 @@ public ShadowJar mergeGroovyExtensionModules() { */ public ShadowJar append(final String resourcePath) { try { - transform(AppendingTransformer.class, new Action() { - @Override - public void execute(AppendingTransformer transformer) { - transformer.setResource(resourcePath); - } - }); - } catch (IllegalAccessException e) { - } catch (InstantiationException e) { - } catch (NoSuchMethodException e) { - } catch (InvocationTargetException e) { + transform(AppendingTransformer.class, transformer -> transformer.setResource(resourcePath)); + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | + InstantiationException ignored) { } return this; } @@ -359,7 +322,7 @@ public ShadowJar relocate(String pattern, String destination) { * @return this */ public ShadowJar relocate(String pattern, String destination, Action configure) { - SimpleRelocator relocator = new SimpleRelocator(pattern, destination, new ArrayList(), new ArrayList()); + SimpleRelocator relocator = new SimpleRelocator(pattern, destination, new ArrayList<>(), new ArrayList<>()); addRelocator(relocator, configure); return this; } 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 1db0f3fd1..0daf571a2 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 @@ -94,7 +94,7 @@ class ApacheNoticeResourceTransformer implements Transformer { void transform(TransformerContext context) { if (entries.isEmpty()) { String year = new SimpleDateFormat("yyyy").format(new Date()) - if (!inceptionYear.equals(year)) { + if (inceptionYear != year) { year = inceptionYear + "-" + year } @@ -190,7 +190,7 @@ class ApacheNoticeResourceTransformer implements Transformer { int count = 0 for (String line : entries) { ++count - if (line.equals(copyright) && count != 2) { + if (line == copyright && count != 2) { continue } 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 0c91e8fb9..788d0530b 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 @@ -46,7 +46,7 @@ class ComponentsXmlResourceTransformer implements Transformer { boolean canTransformResource(FileTreeElement element) { def path = element.relativePath.pathString - return COMPONENTS_XML_PATH.equals(path) + return COMPONENTS_XML_PATH == path } void transform(TransformerContext context) { diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer.groovy index 14dabee7b..3980ee1f5 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer.groovy @@ -36,7 +36,7 @@ import org.gradle.api.tasks.PathSensitivity * * @author John Engelman */ -public class IncludeResourceTransformer implements Transformer { +class IncludeResourceTransformer implements Transformer { @InputFile @PathSensitive(PathSensitivity.NONE) @@ -45,19 +45,19 @@ public class IncludeResourceTransformer implements Transformer { @Input String resource - public boolean canTransformResource(FileTreeElement element) { + boolean canTransformResource(FileTreeElement element) { return false } - public void transform(TransformerContext context) { + void transform(TransformerContext context) { // no op } - public boolean hasTransformedResource() { + boolean hasTransformedResource() { return file != null ? file.exists() : false } - public void modifyOutputStream(ZipOutputStream os, boolean preserveFileTimestamps) { + void modifyOutputStream(ZipOutputStream os, boolean preserveFileTimestamps) { ZipEntry entry = new ZipEntry(resource) entry.time = TransformerContext.getEntryTimestamp(preserveFileTimestamps, entry.time) os.putNextEntry(entry) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformer.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformer.groovy index 7f90dff1b..69bf20d2f 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformer.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformer.groovy @@ -30,7 +30,7 @@ import org.apache.tools.zip.ZipEntry import org.apache.tools.zip.ZipOutputStream import org.gradle.api.file.FileTreeElement -import static org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE; +import static org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE /** * Modified from the maven equivalent to work with gradle 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 37a1a4450..b2153a3f9 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 @@ -102,11 +102,11 @@ class ServiceFileTransformer implements Transformer, PatternFilterable { static class ServiceStream extends ByteArrayOutputStream { - public ServiceStream(){ + ServiceStream(){ super( 1024 ) } - public void append( InputStream is ) throws IOException { + 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) @@ -114,7 +114,7 @@ class ServiceFileTransformer implements Transformer, PatternFilterable { IOUtil.copy(is, this) } - public InputStream toInputStream() { + InputStream toInputStream() { return new ByteArrayInputStream( super.buf, 0, super.count ) } } diff --git a/src/main/resources/META-INF/gradle-plugins/com.github.johnrengelman.shadow.properties b/src/main/resources/META-INF/gradle-plugins/com.github.johnrengelman.shadow.properties deleted file mode 100644 index e77803a7e..000000000 --- a/src/main/resources/META-INF/gradle-plugins/com.github.johnrengelman.shadow.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2011 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 -# -# http://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. -# -implementation-class=com.github.jengelman.gradle.plugins.shadow.ShadowPlugin 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 2768ac347..9267366a9 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 @@ -23,7 +23,6 @@ class ConfigureShadowRelocationSpec extends PluginSpecification { when: run('shadowJar', '-s') - then: then: contains(output, [ 'META-INF/MANIFEST.MF', 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 493794264..f8ce6e65a 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 @@ -65,7 +65,7 @@ include 'api', 'main' } - private void addSubProject(File dir) { + private static void addSubProject(File dir) { File api = new File(dir, "api") api.mkdirs() File build = new File(api, "build.gradle") diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/DefaultCodeSnippetTests.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/DefaultCodeSnippetTests.groovy index ec613c8e4..45cde6580 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/DefaultCodeSnippetTests.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/internal/snippets/DefaultCodeSnippetTests.groovy @@ -1,6 +1,6 @@ package com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets -import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.junit.SnippetRunner; +import com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.junit.SnippetRunner import org.junit.runner.Runner class DefaultCodeSnippetTests implements CodeSnippetTests { 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 2bd9dd765..deff8e9f0 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 @@ -1,4 +1,4 @@ -package com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.fixture; +package com.github.jengelman.gradle.plugins.shadow.docs.internal.snippets.fixture class GroovyScriptFixture extends SnippetFixture { 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 7cd0eec4c..730e351d8 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 @@ -42,11 +42,11 @@ class SimpleRelocatorParameterTest extends TestCase { constructThenFailOnNullPointerException("", null) } - private void constructThenFailOnNullPointerException(String pattern, String shadedPattern) { + private static void constructThenFailOnNullPointerException(String pattern, String shadedPattern) { try { new SimpleRelocator(pattern, shadedPattern, Collections. emptyList(), Collections. emptyList()) } - catch (NullPointerException e) { + catch (NullPointerException ignored) { fail("Constructor should not throw null pointer exceptions") } } 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 055ed8503..df38dc5cf 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 @@ -74,7 +74,7 @@ class ApacheNoticeResourceTransformerParameterTests extends TestCase { final List emptyList = Collections.emptyList() subject.transform(TransformerContext.builder().path(NOTICE_RESOURCE).is(noticeInputStream).relocators(emptyList).stats(stats).build()) } - catch (NullPointerException e) { + catch (NullPointerException ignored) { fail("Null pointer should not be thrown when no parameters are set.") } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileModule.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileModule.groovy index 7d6040058..0a4414128 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileModule.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/AppendableMavenFileModule.groovy @@ -48,7 +48,7 @@ class AppendableMavenFileModule extends MavenFileModule { return artifactFile } - void writeJar(OutputStream os, Map contents) { + static void writeJar(OutputStream os, Map contents) { if (contents) { JarBuilder builder = new JarBuilder(os) contents.each { path, content -> diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestDirectoryProvider.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestDirectoryProvider.java index 179781612..9aacdbd8a 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestDirectoryProvider.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestDirectoryProvider.java @@ -2,7 +2,7 @@ /** * Implementations provide a working space to be used in tests. - * + *

* The client is not responsible for removing any files. */ public interface TestDirectoryProvider { 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 b6d395d90..5e1254b38 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 @@ -106,7 +106,7 @@ public TestFile file(Object... path) { } public List files(Object... paths) { - List files = new ArrayList(); + List files = new ArrayList<>(); for (Object path : paths) { files.add(file(path)); } @@ -163,16 +163,13 @@ public Map getProperties() { assertIsFile(); Properties properties = new Properties(); try { - FileInputStream inStream = new FileInputStream(this); - try { + try (FileInputStream inStream = new FileInputStream(this)) { properties.load(inStream); - } finally { - inStream.close(); } } catch (IOException e) { throw new RuntimeException(e); } - Map map = new HashMap(); + Map map = new HashMap<>(); for (Object key : properties.keySet()) { map.put(key.toString(), properties.getProperty(key.toString())); } @@ -182,11 +179,8 @@ public Map getProperties() { public Manifest getManifest() { assertIsFile(); try { - JarFile jarFile = new JarFile(this); - try { + try (JarFile jarFile = new JarFile(this)) { return jarFile.getManifest(); - } finally { - jarFile.close(); } } catch (IOException e) { throw new RuntimeException(e); @@ -195,9 +189,8 @@ public Manifest getManifest() { public List linesThat(Matcher matcher) { try { - BufferedReader reader = new BufferedReader(new FileReader(this)); - try { - List lines = new ArrayList(); + try (BufferedReader reader = new BufferedReader(new FileReader(this))) { + List lines = new ArrayList<>(); String line; while ((line = reader.readLine()) != null) { if (matcher.matches(line)) { @@ -205,8 +198,6 @@ public List linesThat(Matcher matcher) { } } return lines; - } finally { - reader.close(); } } catch (IOException e) { throw new RuntimeException(e); @@ -383,14 +374,14 @@ public int getMode() { * Asserts that this file contains exactly the given set of descendants. */ public TestFile assertHasDescendants(String... descendants) { - Set actual = new TreeSet(); + Set actual = new TreeSet<>(); assertIsDir(); visit(actual, "", this); - Set expected = new TreeSet(Arrays.asList(descendants)); + Set expected = new TreeSet<>(Arrays.asList(descendants)); - Set extras = new TreeSet(actual); + Set extras = new TreeSet<>(actual); extras.removeAll(expected); - Set missing = new TreeSet(expected); + Set missing = new TreeSet<>(expected); missing.removeAll(actual); assertEquals(String.format("For dir: %s, extra files: %s, missing files: %s, expected: %s", this, extras, missing, expected), expected, actual); @@ -544,11 +535,8 @@ public void writeProperties(Map properties) { Properties props = new Properties(); props.putAll(properties); try { - FileOutputStream stream = new FileOutputStream(this); - try { + try (FileOutputStream stream = new FileOutputStream(this)) { props.store(stream, "comment"); - } finally { - stream.close(); } } catch (IOException e) { throw new RuntimeException(e); 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 c1515095f..03dc96c9f 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 @@ -1,4 +1,4 @@ -package com.github.jengelman.gradle.plugins.shadow.util.file; +package com.github.jengelman.gradle.plugins.shadow.util.file import org.apache.commons.io.FileUtils import org.apache.commons.lang3.StringUtils @@ -81,7 +81,7 @@ class TestFileHelper { untar.execute() } - private boolean isUnix() { + private static boolean isUnix() { return !System.getProperty('os.name').toLowerCase().contains('windows') } @@ -119,7 +119,7 @@ class TestFileHelper { } } - private int toMode(String permissions) { + private static int toMode(String permissions) { int m = [6, 3, 0].inject(0) { mode, pos -> mode |= permissions[9 - pos - 3] == 'r' ? 4 << pos : 0 mode |= permissions[9 - pos - 2] == 'w' ? 2 << pos : 0 @@ -142,7 +142,7 @@ class TestFileHelper { throw new RuntimeException("Could not delete '$file': $error") } } else { - FileUtils.deleteQuietly(file); + FileUtils.deleteQuietly(file) } } @@ -170,32 +170,32 @@ class TestFileHelper { return new ExecOutput(output, error) } - public void zipTo(TestFile zipFile, boolean nativeTools) { + void zipTo(TestFile zipFile, boolean nativeTools) { if (nativeTools && isUnix()) { def process = ['zip', zipFile.absolutePath, "-r", file.name].execute(null, zipFile.parentFile) process.consumeProcessOutput(System.out, System.err) assert process.waitFor() == 0 } else { - Zip zip = new Zip(); - zip.setBasedir(file); - zip.setDestFile(zipFile); - zip.setProject(new Project()); + Zip zip = new Zip() + zip.setBasedir(file) + zip.setDestFile(zipFile) + zip.setProject(new Project()) def whenEmpty = new Zip.WhenEmpty() whenEmpty.setValue("create") - zip.setWhenempty(whenEmpty); - zip.execute(); + zip.setWhenempty(whenEmpty) + zip.execute() } } - public void tarTo(TestFile tarFile, boolean nativeTools) { + void tarTo(TestFile tarFile, boolean nativeTools) { if (nativeTools && isUnix()) { def process = ['tar', "-cf", tarFile.absolutePath, file.name].execute(null, tarFile.parentFile) process.consumeProcessOutput(System.out, System.err) assert process.waitFor() == 0 } else { - Tar tar = new Tar(); - tar.setBasedir(file); - tar.setDestFile(tarFile); + Tar tar = new Tar() + tar.setBasedir(file) + tar.setDestFile(tarFile) tar.setProject(new Project()) tar.execute() } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestNameTestDirectoryProvider.java b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestNameTestDirectoryProvider.java index 59f9642a8..8af8fd1ec 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestNameTestDirectoryProvider.java +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/file/TestNameTestDirectoryProvider.java @@ -2,6 +2,7 @@ import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import org.junit.rules.MethodRule; import org.junit.rules.TestRule; import org.junit.runner.Description; @@ -17,8 +18,8 @@ public class TestNameTestDirectoryProvider implements MethodRule, TestRule, TestDirectoryProvider { private TestFile dir; private String prefix; - private static TestFile root; - private static AtomicInteger testCounter = new AtomicInteger(1); + private static final TestFile root; + private static final AtomicInteger testCounter = new AtomicInteger(1); static { // NOTE: the space in the directory name is intentional @@ -47,7 +48,7 @@ public void evaluate() throws Throwable { }; } - public Statement apply(final Statement base, Description description) { + public Statement apply(final @NotNull Statement base, Description description) { init(description.getMethodName(), description.getTestClass().getSimpleName()); return new Statement() { @Override @@ -101,14 +102,14 @@ public TestFile getTestDirectory() { } public TestFile file(Object... path) { - return getTestDirectory().file((Object[]) path); + return getTestDirectory().file(path); } public TestFile createFile(Object... path) { - return file((Object[]) path).createFile(); + return file(path).createFile(); } public TestFile createDir(Object... path) { - return file((Object[]) path).createDir(); + return file(path).createDir(); } } 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 ef54d933a..34ca1ff23 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 @@ -6,9 +6,9 @@ package com.github.jengelman.gradle.plugins.shadow.util.file * Should be inner class of TestFile, but can't because Groovy has issues with inner classes as delegates. */ class TestWorkspaceBuilder { - def TestFile baseDir + TestFile baseDir - def TestWorkspaceBuilder(TestFile baseDir) { + TestWorkspaceBuilder(TestFile baseDir) { this.baseDir = baseDir } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy index ff62a315c..ea5504ec7 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/AbstractModule.groovy @@ -47,34 +47,34 @@ abstract class AbstractModule { protected abstract onPublish(TestFile file) - TestFile getSha1File(TestFile file) { + static TestFile getSha1File(TestFile file) { getHashFile(file, "sha1") } - TestFile sha1File(TestFile file) { + static TestFile sha1File(TestFile file) { hashFile(file, "sha1", 40) } - TestFile getMd5File(TestFile file) { + static TestFile getMd5File(TestFile file) { getHashFile(file, "md5") } - TestFile md5File(TestFile file) { + static TestFile md5File(TestFile file) { hashFile(file, "md5", 32) } - private TestFile hashFile(TestFile file, String algorithm, int len) { + private static TestFile hashFile(TestFile file, String algorithm, int len) { def hashFile = getHashFile(file, algorithm) def hash = getHash(file, algorithm) hashFile.text = String.format("%0${len}x", hash) return hashFile } - private TestFile getHashFile(TestFile file, String algorithm) { + private static TestFile getHashFile(TestFile file, String algorithm) { file.parentFile.file("${file.name}.${algorithm}") } - protected BigInteger getHash(TestFile file, String algorithm) { + private static BigInteger getHash(TestFile file, String algorithm) { HashUtil.createHash(file, algorithm.toUpperCase()).asBigInteger() } } \ No newline at end of file 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 837755074..6d0ff135a 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 @@ -228,7 +228,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule } publish(pomFile) { Writer writer -> - def pomPackaging = packaging ?: type; + def pomPackaging = packaging ?: type writer << """ @@ -271,7 +271,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule private void updateRootMavenMetaData(TestFile rootMavenMetaData) { def allVersions = rootMavenMetaData.exists() ? new XmlParser().parseText(rootMavenMetaData.text).versioning.versions.version*.value().flatten() : [] - allVersions << version; + allVersions << version publish(rootMavenMetaData) { Writer writer -> def builder = new MarkupBuilder(writer) builder.metadata { diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenDependency.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenDependency.groovy index 789251310..56db25320 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenDependency.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenDependency.groovy @@ -13,7 +13,7 @@ class MavenDependency { } @Override - public String toString() { + String toString() { return String.format("MavenDependency %s:%s:%s:%s@%s", groupId, artifactId, version, classifier, type) } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy index 7696ee177..064e53a7f 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenFileModule.groovy @@ -3,7 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven import com.github.jengelman.gradle.plugins.shadow.util.file.TestFile class MavenFileModule extends AbstractMavenModule { - private boolean uniqueSnapshots = true; + private boolean uniqueSnapshots = true MavenFileModule(TestFile moduleDir, String groupId, String artifactId, String version) { super(moduleDir, groupId, artifactId, version) @@ -14,8 +14,8 @@ class MavenFileModule extends AbstractMavenModule { } MavenModule withNonUniqueSnapshots() { - uniqueSnapshots = false; - return this; + uniqueSnapshots = false + return this } @Override diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenMetaData.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenMetaData.groovy index bdceb46f6..0a3b49b11 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenMetaData.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/repo/maven/MavenMetaData.groovy @@ -1,6 +1,6 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven -public interface MavenMetaData { +interface MavenMetaData { List getVersions(); }