Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more CC compatibility issues #835

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repositories {
mavenCentral()
}

test {
tasks.withType(Test).configureEach {
useJUnitPlatform()

if (System.env.CI == 'true') {
Expand All @@ -39,6 +39,19 @@ test {
}

systemProperty 'java.io.tmpdir', buildDir.absolutePath

// Required to test configuration cache in tests when using withDebug()
// https://github.com/gradle/gradle/issues/22765#issuecomment-1339427241
jvmArgs(
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.util.concurrent.atomic=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens",
"java.base/java.net=ALL-UNNAMED",
)
}

// jar {
Expand Down
2 changes: 1 addition & 1 deletion src/docs/publishing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
project.shadow.component(project, publication)
}
}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class ShadowApplicationPlugin implements Plugin<Project> {
}

protected void configureInstallTask(Project project) {
project.tasks.named(SHADOW_INSTALL_TASK_NAME).configure { installTask ->
installTask.doFirst { Sync task ->
project.tasks.named(SHADOW_INSTALL_TASK_NAME, Sync).configure { task ->
Goooler marked this conversation as resolved.
Show resolved Hide resolved
task.doFirst {
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" +
Expand All @@ -104,8 +104,12 @@ class ShadowApplicationPlugin implements Plugin<Project> {
}
}
}
installTask.doLast { Sync task ->
project.ant.chmod(file: "${task.destinationDir.absolutePath}/bin/${javaApplication.applicationName}", perm: 'ugo+x')
task.doLast {
task.eachFile {
if (it.path == "bin/${javaApplication.applicationName}") {
it.mode = 0x755
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ShadowBasePlugin implements Plugin<Project> {
if (GradleVersion.current() < GradleVersion.version("8.0")) {
throw new GradleException("This version of Shadow supports Gradle 8.0+ only. Please upgrade.")
}
project.extensions.create(EXTENSION_NAME, ShadowExtension, project)
project.extensions.create(EXTENSION_NAME, ShadowExtension)
createShadowConfiguration(project)

project.tasks.register(KnowsTask.NAME, KnowsTask) { knows ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,50 @@ package com.github.jengelman.gradle.plugins.shadow
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.SelfResolvingDependency
import org.gradle.api.file.CopySpec
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.util.GradleVersion

class ShadowExtension {

CopySpec applicationDistribution
Project project

ShadowExtension(Project project) {
this.project = project
applicationDistribution = project.copySpec {}
}

void component(MavenPublication publication) {
void component(Project project, MavenPublication publication) {

if (GradleVersion.current() >= GradleVersion.version("6.6")) {
publication.artifact(project.tasks.named("shadowJar"))
} else {
publication.artifact(project.tasks.shadowJar)
}

final def allDependencies = project.provider {
project.configurations.shadow.allDependencies.collect {
if ((it instanceof ProjectDependency) || ! (it instanceof SelfResolvingDependency)) {
new Dep(it.group, it.name, it.version)
}
}
}
Goooler marked this conversation as resolved.
Show resolved Hide resolved
publication.pom { MavenPom pom ->
pom.withXml { xml ->
def dependenciesNode = xml.asNode().get('dependencies') ?: xml.asNode().appendNode('dependencies')
project.configurations.shadow.allDependencies.each {
if ((it instanceof ProjectDependency) || ! (it instanceof SelfResolvingDependency)) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'runtime')
}
allDependencies.get().each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'runtime')
}
}
}
}

private class Dep {
String group
String name
String version

Dep(String group, String name, String version) {
this.group = group
this.name = name
this.version = version
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class AppendingTransformer implements Transformer {
@Input
String resource

private ByteArrayOutputStream data = new ByteArrayOutputStream()
/**
* Defer initialization, see https://github.com/johnrengelman/shadow/issues/763
*/
private ByteArrayOutputStream data

boolean canTransformResource(FileTreeElement element) {
def path = element.relativePath.pathString
Expand All @@ -53,17 +56,25 @@ class AppendingTransformer implements Transformer {
}

void transform(TransformerContext context) {
if (data == null) {
data = new ByteArrayOutputStream()
}

IOUtil.copy(context.is, data)
data.write('\n'.bytes)

context.is.close()
}

boolean hasTransformedResource() {
return data.size() > 0
return data?.size() > 0
}

void modifyOutputStream(ZipOutputStream os, boolean preserveFileTimestamps) {
if (data == null) {
data = new ByteArrayOutputStream()
}

ZipEntry entry = new ZipEntry(resource)
entry.time = TransformerContext.getEntryTimestamp(preserveFileTimestamps, entry.time)
os.putNextEntry(entry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ApplicationSpec extends PluginSpecification {
settingsFile << "rootProject.name = 'myapp'"

when:
BuildResult result = run('runShadow', '--stacktrace')
BuildResult result = run('runShadow')

then: 'tests that runShadow executed and exited'
assert result.output.contains('TestApp: Hello World! (foo)')
Expand Down Expand Up @@ -105,7 +105,7 @@ class ApplicationSpec extends PluginSpecification {
runShadow {
args 'foo'
doFirst {
project.logger.lifecycle("Running application with JDK \${it.javaLauncher.get().metadata.languageVersion.asInt()}")
logger.lifecycle("Running application with JDK \${it.javaLauncher.get().metadata.languageVersion.asInt()}")
Goooler marked this conversation as resolved.
Show resolved Hide resolved
}
}
""".stripIndent()
Expand All @@ -120,7 +120,7 @@ class ApplicationSpec extends PluginSpecification {
""".stripIndent()

when:
BuildResult result = run('runShadow', '--stacktrace')
BuildResult result = run('runShadow')

then: 'tests that runShadow executed and exited'
assert result.output.contains('Running application with JDK 17')
Expand Down Expand Up @@ -183,7 +183,7 @@ class ApplicationSpec extends PluginSpecification {
settingsFile << "rootProject.name = 'myapp'"

when:
run('shadowDistZip', '--stacktrace')
run('shadowDistZip')

then: 'Check that the distribution zip was created'
File zip = getFile('build/distributions/myapp-shadow-1.0.zip')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ConfigurationCacheSpec extends PluginSpecification {
settingsFile << "rootProject.name = 'myapp'"

when:
run('--configuration-cache', 'shadowJar')
def result = run('--configuration-cache', 'shadowJar')
run('shadowJar')
def result = run('shadowJar')

then:
result.output.contains("Reusing configuration cache.")
Expand All @@ -65,9 +65,9 @@ class ConfigurationCacheSpec extends PluginSpecification {
""".stripIndent()

when:
run('--configuration-cache', 'shadowJar')
run('shadowJar')
output.delete()
def result = run('--configuration-cache', 'shadowJar')
def result = run('shadowJar')

then:
contains(output, ['a.properties', 'b.properties'])
Expand Down Expand Up @@ -117,9 +117,9 @@ class ConfigurationCacheSpec extends PluginSpecification {
def output = getFile('server/build/libs/server-all.jar')

when:
run('--configuration-cache', 'shadowJar', '-s')
run('shadowJar', '-s')
output.delete()
def result = run('--configuration-cache', 'shadowJar', '-s')
def result = run('shadowJar', '-s')

then:
output.exists()
Expand Down Expand Up @@ -160,8 +160,8 @@ class ConfigurationCacheSpec extends PluginSpecification {
""".stripIndent()

when:
run('--configuration-cache', 'shadowJar', '-s')
def result = run('--configuration-cache', 'shadowJar', '-s')
run('shadowJar', '-s')
def result = run('shadowJar', '-s')

then:
result.output.contains(":lib:shadowJar UP-TO-DATE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PublishingSpec extends PluginSpecification {
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
project.shadow.component(project, publication)
artifactId = 'maven-all'
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ class PublishingSpec extends PluginSpecification {
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
project.shadow.component(project, publication)
artifactId = 'maven-all'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class ShadowPluginSpec extends PluginSpecification {
File serverOutput = getFile('server/build/libs/server-all.jar')

when:
runWithDebug(':server:shadowJar', '--stacktrace')
runWithDebug(':server:shadowJar')

then:
serverOutput.exists()
Expand Down Expand Up @@ -311,7 +311,7 @@ class ShadowPluginSpec extends PluginSpecification {
File serverOutput = getFile('server/build/libs/server-all.jar')

when:
runWithDebug(':server:shadowJar', '--stacktrace')
runWithDebug(':server:shadowJar')

then:
serverOutput.exists()
Expand Down Expand Up @@ -364,7 +364,7 @@ class ShadowPluginSpec extends PluginSpecification {
File serverOutput = file('server/build/libs/server-all.jar')

when:
runWithDebug(':server:shadowJar', '--stacktrace')
runWithDebug(':server:shadowJar')

then:
contains(serverOutput, [
Expand Down Expand Up @@ -419,7 +419,7 @@ class ShadowPluginSpec extends PluginSpecification {
File serverOutput = file('server/build/libs/server-all.jar')

when:
runWithDebug(':server:shadowJar', '--stacktrace')
runWithDebug(':server:shadowJar')

then:
contains(serverOutput, [
Expand Down Expand Up @@ -472,7 +472,7 @@ class ShadowPluginSpec extends PluginSpecification {
File serverOutput = file('server/build/libs/server-all.jar')

when:
runWithDebug(':server:shadowJar', '--stacktrace')
runWithDebug(':server:shadowJar')

then:
contains(serverOutput, [
Expand Down Expand Up @@ -550,7 +550,7 @@ class ShadowPluginSpec extends PluginSpecification {
File serverOutput = getFile('impl/build/libs/impl-all.jar')

when:
runWithDebug(':impl:shadowJar', '--stacktrace')
runWithDebug(':impl:shadowJar')

then:
serverOutput.exists()
Expand Down Expand Up @@ -626,7 +626,7 @@ class ShadowPluginSpec extends PluginSpecification {
File serverOutput = getFile('impl/build/libs/impl-all.jar')

when:
runWithDebug(':impl:shadowJar', '--stacktrace')
runWithDebug(':impl:shadowJar')

then:
serverOutput.exists()
Expand Down Expand Up @@ -992,7 +992,7 @@ class ShadowPluginSpec extends PluginSpecification {
""".stripIndent()

when:
run('shadowJar', '--stacktrace')
run('shadowJar')

then:
assert output.exists()
Expand Down Expand Up @@ -1040,7 +1040,7 @@ class ShadowPluginSpec extends PluginSpecification {
File serverOutput = getFile('impl/build/libs/impl-1.0-all.jar')

when:
runWithDebug(':impl:shadowJar', '--stacktrace')
runWithDebug(':impl:shadowJar')

then:
serverOutput.exists()
Expand Down Expand Up @@ -1112,7 +1112,7 @@ class ShadowPluginSpec extends PluginSpecification {
settingsFile << "rootProject.name = 'myapp'"

when:
BuildResult result = run('runShadow', '--stacktrace')
BuildResult result = run('runShadow')

then: 'tests that runShadow executed and exited'
assert result.output.contains('TestApp: Hello World! (foo)')
Expand Down Expand Up @@ -1170,7 +1170,7 @@ class ShadowPluginSpec extends PluginSpecification {
""".stripIndent()

when:
BuildResult result = run('runShadow', '--stacktrace')
BuildResult result = run('runShadow')

then: 'tests that runShadow executed and exited'
assert result.output.contains('TestApp: Hello World! (foo)')
Expand Down Expand Up @@ -1212,7 +1212,7 @@ class ShadowPluginSpec extends PluginSpecification {
""".stripIndent()

when:
BuildResult result = run('runShadow', '--stacktrace')
BuildResult result = run('runShadow')

then: 'tests that runShadow executed and exited'
assert result.output.contains('TestApp: Hello World! (foo)')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write(
""".stripIndent()

when:
run('shadowJar', '--warning-mode=all', '--stacktrace')
run('shadowJar', '--warning-mode=all')

then:
assert output.exists()
Expand Down
Loading