Skip to content

Commit

Permalink
Add BasePluginTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Dec 26, 2024
1 parent 53adc48 commit 4f98736
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 108 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ dependencies {
intiTestImplementation(libs.okio)
intiTestImplementation(libs.apache.maven.modelBuilder)
intiTestImplementation(libs.apache.maven.repositoryMetadata)
// TODO: this will be removed after we migrated all functional tests to Kotlin.
intiTestImplementation(sourceSets.main.get().output)

lintChecks(libs.androidx.gradlePluginLints)
lintChecks(libs.assertk.lint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ApplicationSpec extends BasePluginSpecification {
assert installedJar.exists()

and: 'And that jar file as the correct files in it'
contains(installedJar, ['a.properties', 'a2.properties', 'myapp/Main.class'])
assertContains(installedJar, ['a.properties', 'a2.properties', 'myapp/Main.class'])

and: 'Check the manifest attributes in the jar file are correct'
JarFile jar = new JarFile(installedJar)
Expand Down Expand Up @@ -134,7 +134,7 @@ class ApplicationSpec extends BasePluginSpecification {
assert installedJar.exists()

and: 'And that jar file as the correct files in it'
contains(installedJar, ['a.properties', 'a2.properties', 'myapp/Main.class'])
assertContains(installedJar, ['a.properties', 'a2.properties', 'myapp/Main.class'])

and: 'Check the manifest attributes in the jar file are correct'
JarFile jar = new JarFile(installedJar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ abstract class BasePluginSpecification extends Specification {
new AppendableMavenFileRepository(dir.resolve(path))
}

void assertJarFileContentsEqual(File f, String path, String contents) {
assert getJarFileContents(f, path) == contents
}

String getJarFileContents(File f, String path) {
JarFile jf = new JarFile(f)
def is = jf.getInputStream(new JarEntry(path))
Expand All @@ -155,15 +151,15 @@ abstract class BasePluginSpecification extends Specification {
return sw.toString()
}

void contains(File f, List<String> paths) {
void assertContains(File f, List<String> paths) {
JarFile jar = new JarFile(f)
paths.each { path ->
assert jar.getJarEntry(path), "${f.path} does not contain [$path]"
}
jar.close()
}

void doesNotContain(File f, List<String> paths) {
void assertDoesNotContain(File f, List<String> paths) {
JarFile jar = new JarFile(f)
paths.each { path ->
assert !jar.getJarEntry(path), "${f.path} contains [$path]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class ConfigurationCacheSpec extends BasePluginSpecification {
def result = run('shadowJar')

then:
contains(output, ['a.properties', 'b.properties'])
assertContains(output, ['a.properties', 'b.properties'])

and:
doesNotContain(output, ['a2.properties'])
assertDoesNotContain(output, ['a2.properties'])
result.output.contains("Reusing configuration cache.")
}

Expand Down Expand Up @@ -122,11 +122,11 @@ class ConfigurationCacheSpec extends BasePluginSpecification {

then:
output.exists()
contains(output, [
assertContains(output, [
'server/Server.class',
'junit/framework/Test.class'
])
doesNotContain(output, ['client/Client.class'])
assertDoesNotContain(output, ['client/Client.class'])

and:
result.output.contains("Reusing configuration cache.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FilteringSpec extends BasePluginSpecification {
run('shadowJar')

then:
contains(output, ['a.properties', 'a2.properties', 'b.properties'])
assertContains(output, ['a.properties', 'a2.properties', 'b.properties'])
}

def 'exclude files'() {
Expand All @@ -45,10 +45,10 @@ class FilteringSpec extends BasePluginSpecification {
run('shadowJar')

then:
contains(output, ['a.properties', 'b.properties'])
assertContains(output, ['a.properties', 'b.properties'])

and:
doesNotContain(output, ['a2.properties'])
assertDoesNotContain(output, ['a2.properties'])
}

def "exclude dependency"() {
Expand Down Expand Up @@ -77,10 +77,10 @@ class FilteringSpec extends BasePluginSpecification {
run('shadowJar')

then:
contains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])
assertContains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])

and:
doesNotContain(output, ['d.properties'])
assertDoesNotContain(output, ['d.properties'])
}

@Issue('https://github.com/GradleUp/shadow/issues/83')
Expand Down Expand Up @@ -110,10 +110,10 @@ class FilteringSpec extends BasePluginSpecification {
run('shadowJar')

then:
contains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])
assertContains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])

and:
doesNotContain(output, ['d.properties'])
assertDoesNotContain(output, ['d.properties'])
}

@Issue("https://github.com/GradleUp/shadow/issues/54")
Expand Down Expand Up @@ -143,10 +143,10 @@ class FilteringSpec extends BasePluginSpecification {
run('shadowJar')

then:
contains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])
assertContains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])

and:
doesNotContain(output, ['d.properties'])
assertDoesNotContain(output, ['d.properties'])

when: 'Update build file shadowJar dependency exclusion'
buildFile.text = buildFile.text.replace('exclude(dependency(\'shadow:d:1.0\'))',
Expand All @@ -158,10 +158,10 @@ class FilteringSpec extends BasePluginSpecification {
assert result.task(':shadowJar').outcome == TaskOutcome.SUCCESS

and:
contains(output, ['a.properties', 'a2.properties', 'b.properties', 'd.properties'])
assertContains(output, ['a.properties', 'a2.properties', 'b.properties', 'd.properties'])

and:
doesNotContain(output, ['c.properties'])
assertDoesNotContain(output, ['c.properties'])
}

@Issue("https://github.com/GradleUp/shadow/issues/62")
Expand Down Expand Up @@ -191,10 +191,10 @@ class FilteringSpec extends BasePluginSpecification {
run('shadowJar')

then:
contains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])
assertContains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])

and:
doesNotContain(output, ['d.properties'])
assertDoesNotContain(output, ['d.properties'])

when: 'Update build file shadowJar dependency exclusion'
buildFile.text = buildFile.text.replace('exclude(dependency(\'shadow:d:1.0\'))',
Expand All @@ -206,10 +206,10 @@ class FilteringSpec extends BasePluginSpecification {
assert result.task(':shadowJar').outcome == TaskOutcome.SUCCESS

and:
contains(output, ['a2.properties', 'b.properties', 'c.properties', 'd.properties'])
assertContains(output, ['a2.properties', 'b.properties', 'c.properties', 'd.properties'])

and:
doesNotContain(output, ['a.properties'])
assertDoesNotContain(output, ['a.properties'])
}

def "include dependency, excluding all others"() {
Expand Down Expand Up @@ -243,10 +243,10 @@ class FilteringSpec extends BasePluginSpecification {
run('shadowJar')

then:
contains(output, ['d.properties', 'shadow/Passed.class'])
assertContains(output, ['d.properties', 'shadow/Passed.class'])

and:
doesNotContain(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])
assertDoesNotContain(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])
}

def 'filter project dependencies'() {
Expand Down Expand Up @@ -294,12 +294,12 @@ class FilteringSpec extends BasePluginSpecification {

then:
serverOutput.exists()
doesNotContain(serverOutput, [
assertDoesNotContain(serverOutput, [
'client/Client.class',
])

and:
contains(serverOutput, ['server/Server.class', 'junit/framework/Test.class'])
assertContains(serverOutput, ['server/Server.class', 'junit/framework/Test.class'])
}

def 'exclude a transitive project dependency'() {
Expand Down Expand Up @@ -346,12 +346,12 @@ class FilteringSpec extends BasePluginSpecification {

then:
serverOutput.exists()
doesNotContain(serverOutput, [
assertDoesNotContain(serverOutput, [
'junit/framework/Test.class'
])

and:
contains(serverOutput, [
assertContains(serverOutput, [
'client/Client.class',
'server/Server.class'])
}
Expand All @@ -371,10 +371,10 @@ class FilteringSpec extends BasePluginSpecification {
run('shadowJar')

then:
contains(output, ['a.properties', 'b.properties'])
assertContains(output, ['a.properties', 'b.properties'])

and:
doesNotContain(output, ['a2.properties'])
assertDoesNotContain(output, ['a2.properties'])
}

@Issue("https://github.com/GradleUp/shadow/issues/69")
Expand Down Expand Up @@ -405,10 +405,10 @@ class FilteringSpec extends BasePluginSpecification {
run('shadowJar')

then:
contains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])
assertContains(output, ['a.properties', 'a2.properties', 'b.properties', 'c.properties'])

and:
doesNotContain(output, ['d.properties'])
assertDoesNotContain(output, ['d.properties'])
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PublishingSpec extends BasePluginSpecification {
assert publishedFile.exists()

and:
contains(publishedFile, ['a.properties', 'a2.properties'])
assertContains(publishedFile, ['a.properties', 'a2.properties'])

and:
File pom = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.pom').toFile().canonicalFile
Expand Down Expand Up @@ -211,7 +211,7 @@ class PublishingSpec extends BasePluginSpecification {
assert publishedFile.exists()

and:
contains(publishedFile, ['a.properties', 'a2.properties'])
assertContains(publishedFile, ['a.properties', 'a2.properties'])

and:
File pom = publishingRepo.rootDir.resolve('shadow/maven-all/1.0/maven-all-1.0.pom').toFile().canonicalFile
Expand Down Expand Up @@ -277,7 +277,7 @@ class PublishingSpec extends BasePluginSpecification {
assert shadowJar.exists()

and:
contains(shadowJar, ['a.properties', 'a2.properties'])
assertContains(shadowJar, ['a.properties', 'a2.properties'])

and: "publishes both a POM file and a Gradle metadata file"
File pom = publishingRepo.rootDir.resolve('com/acme/maven/1.0/maven-1.0.pom').toFile().canonicalFile
Expand Down Expand Up @@ -328,7 +328,7 @@ class PublishingSpec extends BasePluginSpecification {
assertions {
shadowJar = publishingRepo.rootDir.resolve('com/acme/maven-all/1.0/maven-all-1.0-all.jar').toFile().canonicalFile
assert shadowJar.exists()
contains(shadowJar, ['a.properties', 'a2.properties'])
assertContains(shadowJar, ['a.properties', 'a2.properties'])
}

assertions {
Expand Down
Loading

0 comments on commit 4f98736

Please sign in to comment.