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

Make Spock tests run again #672

Merged
merged 1 commit into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ repositories {
}

test {
useJUnitPlatform()

if (System.env.CI == 'true') {
testLogging.showStandardStreams = true
minHeapSize "1g"
maxHeapSize "1g"
}

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

Expand Down
4 changes: 2 additions & 2 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ dependencies {
exclude group: 'org.ow2.asm'
}

testImplementation("org.spockframework:spock-core:2.0-M4-groovy-3.0") {
testImplementation('org.spockframework:spock-core:2.0-groovy-3.0') {
exclude group: 'org.codehaus.groovy'
}
testImplementation "org.spockframework:spock-junit4:2.0-M4-groovy-3.0"
testImplementation 'org.spockframework:spock-junit4:2.0-groovy-3.0'
testImplementation 'xmlunit:xmlunit:1.6'
testImplementation 'org.apache.commons:commons-lang3:3.12.0'
testImplementation 'com.google.guava:guava:30.1.1-jre'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository
import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification
import org.apache.tools.zip.ZipFile
import org.gradle.testkit.runner.BuildResult
Expand All @@ -11,14 +10,6 @@ import java.util.jar.JarFile

class ApplicationSpec extends PluginSpecification {

AppendableMavenFileRepository repo
AppendableMavenFileRepository publishingRepo

def setup() {
repo = repo()
publishingRepo = repo('remote_repo')
}

def 'integration with application plugin'() {
given:
repo.module('shadow', 'a', '1.0')
Expand Down Expand Up @@ -124,7 +115,7 @@ class ApplicationSpec extends PluginSpecification {
ZipFile zipFile = new ZipFile(zip)
println zipFile.entries.collect { it.name }
assert zipFile.entries.find { it.name == 'myapp-shadow-1.0/lib/myapp-1.0-all.jar' }
assert zipFile.entries.find { it.name == 'myapp-shadow-1.0/lib/a-1.0.jar'}
assert zipFile.entries.find { it.name == 'myapp-shadow-1.0/lib/a-1.0.jar' }

cleanup:
zipFile?.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,157 +3,18 @@ package com.github.jengelman.gradle.plugins.shadow
import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository
import com.github.jengelman.gradle.plugins.shadow.util.PluginSpecification
import groovy.json.JsonSlurper
import groovy.xml.XmlSlurper
import org.gradle.api.attributes.Bundling
import org.gradle.api.attributes.Usage
import spock.lang.Issue

class PublishingSpec extends PluginSpecification {

AppendableMavenFileRepository repo
AppendableMavenFileRepository publishingRepo

def setup() {
repo = repo()
publishingRepo = repo('remote_repo')
}

def "publish shadow jar with maven plugin"() {
given:
repo.module('shadow', 'a', '1.0')
.insertFile('a.properties', 'a')
.insertFile('a2.properties', 'a2')
.publish()
repo.module('shadow', 'b', '1.0')
.insertFile('b.properties', 'b')
.publish()

settingsFile << "rootProject.name = 'maven'"
buildFile << """
apply plugin: 'maven'

dependencies {
implementation 'shadow:a:1.0'
shadow 'shadow:b:1.0'
}

shadowJar {
archiveBaseName = 'maven-all'
archiveClassifier = null
archiveClassifier.convention(null)
}

uploadShadow {
repositories {
mavenDeployer {
repository(url: "${publishingRepo.uri}")
}
}
}
""".stripIndent()

when:
runWithDeprecationWarnings('uploadShadow')

then: 'Check that shadow artifact exists'
File publishedFile = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.jar').canonicalFile
assert publishedFile.exists()

and: 'Check contents of shadow artifact'
contains(publishedFile, ['a.properties', 'a2.properties'])

and: 'Check that shadow artifact pom exists and contents'
File pom = publishingRepo.rootDir.file('shadow/maven-all/1.0/maven-all-1.0.pom').canonicalFile
assert pom.exists()

def contents = new XmlSlurper().parse(pom)
assert contents.dependencies.size() == 1
assert contents.dependencies[0].dependency.size() == 1

def dependency = contents.dependencies[0].dependency[0]
assert dependency.groupId.text() == 'shadow'
assert dependency.artifactId.text() == 'b'
assert dependency.version.text() == '1.0'
}

def "exclude api and implementation dependencies when publishing shadow jar with maven plugin"() {
given:
repo.module('shadow', 'a', '1.0')
.insertFile('a.properties', 'a')
.insertFile('a2.properties', 'a2')
.publish()
repo.module('shadow', 'b', '1.0')
.insertFile('b.properties', 'b')
.publish()

settingsFile << "rootProject.name = 'maven'"
buildFile << """
apply plugin: 'java-library'
apply plugin: 'maven'

dependencies {
api 'shadow:a:1.0'
implementation 'shadow:b:1.0'
}

uploadShadow {
repositories {
mavenDeployer {
repository(url: "${publishingRepo.uri}")
}
}
}
""".stripIndent()

when:
runWithDeprecationWarnings('uploadShadow')

then: 'Check that shadow artifact exists'
File publishedFile = publishingRepo.rootDir.file('shadow/maven/1.0/maven-1.0-all.jar').canonicalFile
assert publishedFile.exists()

and: 'Check contents of shadow artifact'
contains(publishedFile, ['a.properties', 'a2.properties'])

and: 'Check that shadow artifact pom exists and contents'
File pom = publishingRepo.rootDir.file('shadow/maven/1.0/maven-1.0.pom').canonicalFile
assert pom.exists()

def contents = new XmlSlurper().parse(pom)
assert contents.dependencies.size() == 0
}

@Issue('SHADOW-347')
def "maven install with application plugin"() {
given:
repo.module('shadow', 'a', '1.0')
.insertFile('a.properties', 'a')
.insertFile('a2.properties', 'a2')
.publish()
repo.module('shadow', 'b', '1.0')
.insertFile('b.properties', 'b')
.publish()

settingsFile << "rootProject.name = 'maven'"
buildFile << """
apply plugin: 'maven'
apply plugin: 'application'

mainClassName = 'my.App'

dependencies {
implementation 'shadow:a:1.0'
shadow 'shadow:b:1.0'
}
""".stripIndent()

when:
// The Maven plugin is deprecated
runWithDeprecationWarnings('install')

then:
noExceptionThrown()
}

def "publish shadow jar with maven-publish plugin"() {
given:
repo.module('shadow', 'a', '1.0')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ class RelocationSpec extends PluginSpecification {
def "relocate does not drop dependency resources"() {
given: 'Core project with dependency and resource'
file('core/build.gradle') << """
apply plugin: 'java'
apply plugin: 'java-library'

repositories { maven { url "${repo.uri}" } }
dependencies { implementation 'junit:junit:3.8.2' }
dependencies { api 'junit:junit:3.8.2' }
""".stripIndent()

file('core/src/main/resources/TEST') << 'TEST RESOURCE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ class ShadowPluginSpec extends PluginSpecification {
assert output.exists()

where:
version << ['6.0', '6.1', '6.2']
version << ['7.0']
}

def 'Error in Gradle versions < 6.0'() {
def 'Error in Gradle versions < 7.0'() {
given:
GradleRunner versionRunner = GradleRunner.create()
.withGradleVersion('5.5')
.withGradleVersion('6.9')
.withArguments('--stacktrace')
.withProjectDir(dir.root)
.forwardOutput()
Expand Down Expand Up @@ -796,7 +796,7 @@ class ShadowPluginSpec extends PluginSpecification {

buildFile << """
dependencies {
runtime 'shadow:a:1.0'
runtimeOnly 'shadow:a:1.0'
shadow 'shadow:b:1.0'
}
""".stripIndent()
Expand Down Expand Up @@ -830,25 +830,15 @@ class ShadowPluginSpec extends PluginSpecification {
.dependsOn('implementation-dep')
.publish()

repo.module('shadow', 'compile', '1.0')
.insertFile('compile.properties', 'compile')
.publish()

repo.module('shadow', 'runtime', '1.0')
.insertFile('runtime.properties', 'runtime')
.publish()

repo.module('shadow', 'runtimeOnly', '1.0')
.insertFile('runtimeOnly.properties', 'runtimeOnly')
.publish()

buildFile.text = defaultBuildScript.replace('java', 'java-library')
buildFile.text = getDefaultBuildScript('java-library')
buildFile << """
dependencies {
api 'shadow:api:1.0'
implementation 'shadow:implementation:1.0'
compile 'shadow:compile:1.0'
runtime 'shadow:runtime:1.0'
runtimeOnly 'shadow:runtimeOnly:1.0'
}
""".stripIndent()
Expand All @@ -857,8 +847,8 @@ class ShadowPluginSpec extends PluginSpecification {
versionRunner.withArguments('shadowJar').build()

then:
contains(output, ['api.properties', 'implementation.properties', 'compile.properties',
'runtime.properties', 'runtimeOnly.properties', 'implementation-dep.properties'])
contains(output, ['api.properties', 'implementation.properties',
'runtimeOnly.properties', 'implementation-dep.properties'])
}

def "doesn't include compileOnly configuration by default"() {
Expand All @@ -873,7 +863,7 @@ class ShadowPluginSpec extends PluginSpecification {

buildFile << """
dependencies {
runtime 'shadow:a:1.0'
runtimeOnly 'shadow:a:1.0'
compileOnly 'shadow:b:1.0'
}
""".stripIndent()
Expand All @@ -900,8 +890,8 @@ class ShadowPluginSpec extends PluginSpecification {

buildFile << """
dependencies {
runtime 'shadow:a:1.0'
runtime 'shadow:b:1.0'
runtimeOnly 'shadow:a:1.0'
runtimeOnly 'shadow:b:1.0'
}
""".stripIndent()

Expand All @@ -917,7 +907,7 @@ class ShadowPluginSpec extends PluginSpecification {
given:

buildFile << """
dependencies { compile 'junit:junit:3.8.2' }
dependencies { implementation 'junit:junit:3.8.2' }
""".stripIndent()

when:
Expand Down Expand Up @@ -988,26 +978,6 @@ class ShadowPluginSpec extends PluginSpecification {

}

@Issue('SHADOW-256')
def "allow configuration of non-maven projects with uploads"() {
given:
buildFile << """
configurations.each { configuration ->
def upload = project.getTasks().getByName(configuration.getUploadTaskName())
upload.repositories.ivy {
layout 'ivy'
url "\$buildDir/repo"
}
}
"""

when:
run('shadowJar')

then:
assert output.exists()
}

@Issue('SHADOW-203')
def "support ZipCompression.STORED"() {
given:
Expand Down Expand Up @@ -1103,7 +1073,7 @@ class ShadowPluginSpec extends PluginSpecification {
mainClassName = 'myapp.Main'

dependencies {
compile 'shadow:a:1.0'
implementation 'shadow:a:1.0'
}

def generatedResourcesDir = new File(project.buildDir, "generated-resources")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RelocationCachingSpec extends AbstractCachingSpec {
def 'shadowJar is cached correctly when relocation is added'() {
given:
buildFile << """
dependencies { compile 'junit:junit:3.8.2' }
dependencies { implementation 'junit:junit:3.8.2' }
""".stripIndent()

file('src/main/java/server/Server.java') << """
Expand All @@ -30,7 +30,7 @@ class RelocationCachingSpec extends AbstractCachingSpec {

when:
changeConfigurationTo """
dependencies { compile 'junit:junit:3.8.2' }
dependencies { implementation 'junit:junit:3.8.2' }

shadowJar {
relocate 'junit.framework', 'foo.junit.framework'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ShadowJarCachingSpec extends AbstractCachingSpec {

when:
changeConfigurationTo """
dependencies { compile 'junit:junit:3.8.2' }
dependencies { implementation 'junit:junit:3.8.2' }

shadowJar {
dependencies {
Expand Down
Loading