diff --git a/src/docs/changes/README.md b/src/docs/changes/README.md index 9b00ab0f0..de09fb3c4 100644 --- a/src/docs/changes/README.md +++ b/src/docs/changes/README.md @@ -20,6 +20,9 @@ - Fix skipStringConstants per-relocator behavior in mapName. ([#1968](https://github.com/GradleUp/shadow/pull/1968)) - Fix excluding dependencies whose versions contain `+`. ([#1597](https://github.com/GradleUp/shadow/pull/1597)) - Fix relocation exclusion for file patterns like `kotlin/kotlin.kotlin_builtins`. ([#1313](https://github.com/GradleUp/shadow/pull/1313)) +- Fix formatting and copyright handling in `ApacheNoticeResourceTransformer`. ([#1623](https://github.com/GradleUp/shadow/pull/1623), [#1627](https://github.com/GradleUp/shadow/pull/1627), [#1628](https://github.com/GradleUp/shadow/pull/1628)) +- Fix ShadowJar not being re-executed after includes or excludes are changed. ([#1200](https://github.com/GradleUp/shadow/pull/1200)) +- Respect `executableDir` in application extension when configuring start scripts and distribution. ([#1738](https://github.com/GradleUp/shadow/pull/1738)) **Deprecated** 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 9fdc54bc8..e5d7dfd43 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 @@ -94,7 +94,7 @@ class ShadowApplicationPlugin implements Plugin { project.tasks.named(SHADOW_INSTALL_TASK_NAME, Sync).configure { task -> task.doFirst { if (task.destinationDir.directory) { - if (task.destinationDir.listFiles().size() != 0 && (!new File(task.destinationDir, 'lib').directory || !new File(task.destinationDir, 'bin').directory)) { + if (task.destinationDir.listFiles().size() != 0 && (!new File(task.destinationDir, 'lib').directory || !new File(task.destinationDir, javaApplication.executableDir).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." @@ -104,7 +104,7 @@ class ShadowApplicationPlugin implements Plugin { } task.doLast { task.eachFile { - if (it.path == "bin/${javaApplication.applicationName}") { + if (it.path == "${javaApplication.executableDir}/${javaApplication.applicationName}") { it.mode = 0x755 } } @@ -122,7 +122,7 @@ class ShadowApplicationPlugin implements Plugin { from(jar) from(project.configurations.shadow) } - into("bin") { + into({ javaApplication.executableDir }) { from(startScripts) filePermissions { it.unix(493) } } 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 1d3c26fb7..dcc522a49 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 @@ -44,6 +44,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.concurrent.Callable; @CacheableTask @@ -81,6 +82,9 @@ public ShadowJar() { relocators = new ArrayList<>(); configurations = new ArrayList<>(); + this.getInputs().property("minimize", (Callable) () -> minimizeJar); + this.getInputs().property("includes", (Callable>) () -> getIncludes()); + this.getInputs().property("excludes", (Callable>) () -> getExcludes()); this.getOutputs().doNotCacheIf("Has one or more transforms or relocators that are not cacheable", task -> { for (Transformer transformer : transformers) { if (!isCacheableTransform(transformer.getClass())) { 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 f7a8add39..11e22fbde 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 @@ -71,6 +71,8 @@ class ApacheNoticeResourceTransformer implements Transformer { @Input String copyright + private String fallbackCopyright + /** * The file encoding of the NOTICE file. */ @@ -148,7 +150,7 @@ class ApacheNoticeResourceTransformer implements Transformer { } else { String ent = sb.toString() if (ent.startsWith(projectName) && ent.indexOf("Copyright ") != -1) { - copyright = ent + fallbackCopyright = ent } if (currentOrg == null) { entries.add(ent) @@ -183,42 +185,40 @@ class ApacheNoticeResourceTransformer implements Transformer { zipEntry.time = TransformerContext.getEntryTimestamp(preserveFileTimestamps, zipEntry.time) os.putNextEntry(zipEntry) - Writer pow - if (StringUtils.isNotEmpty(encoding)) { - pow = new OutputStreamWriter(os, encoding) - } else { - pow = new OutputStreamWriter(os) - } - PrintWriter writer = new PrintWriter(pow) + String actualCopyright = copyright ?: fallbackCopyright + StringBuilder sb = new StringBuilder() int count = 0 for (String line : entries) { ++count - if (line == copyright && count != 2) { + if (line == actualCopyright && count != 2) { continue } - if (count == 2 && copyright != null) { - writer.print(copyright) - writer.print('\n') + if (count == 2 && actualCopyright != null) { + sb.append(actualCopyright).append('\n') } else { - writer.print(line) - writer.print('\n') + sb.append(line).append('\n') } if (count == 3) { //do org stuff for (Map.Entry> entry : organizationEntries.entrySet()) { - writer.print(entry.getKey()) - writer.print('\n') + sb.append(entry.getKey()).append('\n') for (String l : entry.getValue()) { - writer.print(l) + sb.append(l) } - writer.print('\n') + sb.append('\n') } } } - writer.flush() + byte[] bytes + if (StringUtils.isNotEmpty(encoding)) { + bytes = sb.toString().stripTrailing().getBytes(encoding) + } else { + bytes = sb.toString().stripTrailing().getBytes() + } + os.write(bytes) entries.clear() }