Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jan 5, 2025
1 parent e1fbac2 commit d1d98fe
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.containsAtLeast
import assertk.assertions.exists
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEmpty
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
Expand Down Expand Up @@ -47,6 +48,7 @@ class ApplicationTest : BasePluginTest() {
.isEqualTo("myapp.Main")

path("build/install/myapp-shadow/bin/myapp").let { startScript ->
assertThat(startScript).exists()
assertThat(startScript.readText()).contains("CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar")
assertThat(startScript.readText()).contains("-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"")
assertThat(startScript.readText()).contains("exec \"\$JAVACMD\" \"\$@\"")
Expand All @@ -66,6 +68,8 @@ class ApplicationTest : BasePluginTest() {
run("shadowDistZip")

val zip = path("build/distributions/myapp-shadow-1.0.zip")
assertThat(zip).exists()

val entries = ZipFile(zip.toFile()).entries.toList().map { it.name }
assertThat(entries).containsAtLeast(
"myapp-shadow-1.0/lib/myapp-1.0-all.jar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEmpty
import assertk.assertions.isNotNull
import assertk.assertions.isNull
import assertk.assertions.isTrue
Expand Down Expand Up @@ -69,6 +70,8 @@ class ShadowPluginTest : BasePluginTest() {
run(shadowJarTask) {
it.withGradleVersion("8.3")
}

assertThat(outputShadowJar.entries().toList()).isNotEmpty()
}

@Test
Expand All @@ -94,6 +97,8 @@ class ShadowPluginTest : BasePluginTest() {
)

run(shadowJarTask)

assertThat(outputShadowJar.entries().toList()).isNotEmpty()
}

@Test
Expand Down Expand Up @@ -510,8 +515,7 @@ class ShadowPluginTest : BasePluginTest() {

run(shadowJarTask)

val attributes = outputShadowJar.manifest.mainAttributes
assertThat(attributes.getValue("Class-Path")).isNull()
assertThat(outputShadowJar.manifest.mainAttributes.getValue("Class-Path")).isNull()
}

@Issue(
Expand All @@ -534,8 +538,8 @@ class ShadowPluginTest : BasePluginTest() {

run(shadowJarTask)

val attributes = outputShadowJar.manifest.mainAttributes
assertThat(attributes.getValue("Class-Path")).isEqualTo("/libs/a.jar junit-3.8.2.jar")
assertThat(outputShadowJar.manifest.mainAttributes.getValue("Class-Path"))
.isEqualTo("/libs/a.jar junit-3.8.2.jar")
}

@Issue(
Expand Down Expand Up @@ -575,6 +579,8 @@ class ShadowPluginTest : BasePluginTest() {
)

run(shadowJarTask)

assertThat(outputShadowJar.entries().toList()).isNotEmpty()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ class ServiceFileTransformerTest : BaseTransformerTest() {

run(shadowJarTask)

val text1 = outputShadowJar.getContent(ENTRY_SERVICES_SHADE)
assertThat(text1).isEqualTo(CONTENT_ONE_TWO)

val text2 = outputShadowJar.getContent(ENTRY_SERVICES_FOO)
assertThat(text2).isEqualTo("one")
assertThat(outputShadowJar.getContent(ENTRY_SERVICES_SHADE)).isEqualTo(CONTENT_ONE_TWO)
assertThat(outputShadowJar.getContent(ENTRY_SERVICES_FOO)).isEqualTo("one")
}

@Test
Expand All @@ -48,8 +45,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() {

run(shadowJarTask)

val text = outputShadowJar.getContent(ENTRY_FOO_SHADE)
assertThat(text).isEqualTo(CONTENT_ONE_TWO)
assertThat(outputShadowJar.getContent(ENTRY_FOO_SHADE)).isEqualTo(CONTENT_ONE_TWO)
}

@Test
Expand All @@ -67,11 +63,8 @@ class ServiceFileTransformerTest : BaseTransformerTest() {

run(shadowJarTask)

val text1 = outputShadowJar.getContent(ENTRY_SERVICES_SHADE)
assertThat(text1).isEqualTo(CONTENT_ONE_TWO)

val text2 = outputShadowJar.getContent(ENTRY_SERVICES_FOO)
assertThat(text2).isEqualTo("one")
assertThat(outputShadowJar.getContent(ENTRY_SERVICES_SHADE)).isEqualTo(CONTENT_ONE_TWO)
assertThat(outputShadowJar.getContent(ENTRY_SERVICES_FOO)).isEqualTo("one")
}

@Test
Expand Down Expand Up @@ -163,8 +156,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() {

run(shadowJarTask)

val text = outputShadowJar.getContent(ENTRY_FOO_SHADE)
assertThat(text).isEqualTo(CONTENT_ONE_TWO)
assertThat(outputShadowJar.getContent(ENTRY_FOO_SHADE)).isEqualTo(CONTENT_ONE_TWO)
}

@Issue(
Expand Down Expand Up @@ -196,7 +188,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() {

run(shadowJarTask)

val text = outputShadowJar.getContent(servicesShadowEntry)
assertThat(text).isEqualTo(CONTENT_THREE + "\n" + CONTENT_ONE_TWO)
assertThat(outputShadowJar.getContent(servicesShadowEntry))
.isEqualTo(CONTENT_THREE + "\n" + CONTENT_ONE_TWO)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class TransformersTest : BaseTransformerTest() {

run(shadowJarTask)

val text = outputShadowJar.getContent(ENTRY_TEST_PROPERTIES)
assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO)
assertThat(outputShadowJar.getContent(ENTRY_TEST_PROPERTIES).trimIndent())
.isEqualTo(CONTENT_ONE_TWO)
}

@Test
Expand All @@ -57,8 +57,8 @@ class TransformersTest : BaseTransformerTest() {

run(shadowJarTask)

val text = outputShadowJar.getContent(ENTRY_TEST_PROPERTIES)
assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO)
assertThat(outputShadowJar.getContent(ENTRY_TEST_PROPERTIES).trimIndent())
.isEqualTo(CONTENT_ONE_TWO)
}

@Test
Expand Down Expand Up @@ -150,8 +150,7 @@ class TransformersTest : BaseTransformerTest() {

run(shadowJarTask)

val text = outputShadowJar.getContent(propertiesXml)
assertThat(text.trimIndent()).isEqualTo(
assertThat(outputShadowJar.getContent(propertiesXml).trimIndent()).isEqualTo(
"""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class JarPath(val path: Path) :
}
}

fun Assert<JarPath>.containsEntries(entries: Iterable<String>) = transform {
fun Assert<JarPath>.containsEntries(entries: Iterable<String>) = transform { actual ->
entries.forEach { entry ->
it.getEntry(entry) ?: fail("Jar file ${it.path} does not contain entry $entry")
actual.getEntry(entry) ?: fail("Jar file ${actual.path} does not contain entry $entry")
}
}

fun Assert<JarPath>.doesNotContainEntries(entries: Iterable<String>) = transform {
fun Assert<JarPath>.doesNotContainEntries(entries: Iterable<String>) = transform { actual ->
entries.forEach { entry ->
it.getEntry(entry) ?: return@forEach
fail("Jar file ${it.path} contains entry $entry")
actual.getEntry(entry) ?: return@forEach
fail("Jar file ${actual.path} contains entry $entry")
}
}

0 comments on commit d1d98fe

Please sign in to comment.