Skip to content

Commit 63a0235

Browse files
committed
Fix formats
1 parent e6f79f9 commit 63a0235

2 files changed

Lines changed: 72 additions & 57 deletions

File tree

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/SpringBootTransformerTest.kt

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ class SpringBootTransformerTest : BaseTransformerTest() {
2828

2929
runWithSuccess(shadowJarPath)
3030

31-
val content = outputShadowedJar.use { it.getContent(SpringBootTransformer.PATH_SPRING_FACTORIES) }
32-
assertThat(content).isEqualTo(
33-
"org.springframework.boot.autoconfigure.EnableAutoConfiguration=" +
34-
"com.example.FooAutoConfiguration,com.example.BarAutoConfiguration\n",
35-
)
31+
val content =
32+
outputShadowedJar.use { it.getContent(SpringBootTransformer.PATH_SPRING_FACTORIES) }
33+
assertThat(content)
34+
.isEqualTo(
35+
"org.springframework.boot.autoconfigure.EnableAutoConfiguration=" +
36+
"com.example.FooAutoConfiguration,com.example.BarAutoConfiguration\n"
37+
)
3638
}
3739

3840
@Test
@@ -57,13 +59,15 @@ class SpringBootTransformerTest : BaseTransformerTest() {
5759

5860
runWithSuccess(shadowJarPath)
5961

60-
val content = outputShadowedJar.use { it.getContent(SpringBootTransformer.PATH_SPRING_FACTORIES) }
61-
assertThat(content).isEqualTo(
62-
"org.springframework.boot.autoconfigure.EnableAutoConfiguration=" +
63-
"com.example.FooAutoConfiguration,com.example.BarAutoConfiguration\n" +
64-
"org.springframework.context.ApplicationListener=" +
65-
"com.example.FooListener,com.example.BarListener\n",
66-
)
62+
val content =
63+
outputShadowedJar.use { it.getContent(SpringBootTransformer.PATH_SPRING_FACTORIES) }
64+
assertThat(content)
65+
.isEqualTo(
66+
"org.springframework.boot.autoconfigure.EnableAutoConfiguration=" +
67+
"com.example.FooAutoConfiguration,com.example.BarAutoConfiguration\n" +
68+
"org.springframework.context.ApplicationListener=" +
69+
"com.example.FooListener,com.example.BarListener\n"
70+
)
6771
}
6872

6973
@Test
@@ -86,12 +90,14 @@ class SpringBootTransformerTest : BaseTransformerTest() {
8690

8791
runWithSuccess(shadowJarPath)
8892

89-
val content = outputShadowedJar.use {
90-
it.getContent("META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports")
91-
}
92-
assertThat(content).isEqualTo(
93-
"com.example.FooAutoConfiguration\ncom.example.BarAutoConfiguration",
94-
)
93+
val content =
94+
outputShadowedJar.use {
95+
it.getContent(
96+
"META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports"
97+
)
98+
}
99+
assertThat(content)
100+
.isEqualTo("com.example.FooAutoConfiguration\ncom.example.BarAutoConfiguration")
95101
}
96102

97103
@Test
@@ -114,12 +120,16 @@ class SpringBootTransformerTest : BaseTransformerTest() {
114120

115121
runWithSuccess(shadowJarPath)
116122

117-
val content = outputShadowedJar.use {
118-
it.getContent("META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports")
119-
}
120-
assertThat(content).isEqualTo(
121-
"com.example.FooAutoConfiguration\ncom.example.BarAutoConfiguration\ncom.example.BazAutoConfiguration",
122-
)
123+
val content =
124+
outputShadowedJar.use {
125+
it.getContent(
126+
"META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports"
127+
)
128+
}
129+
assertThat(content)
130+
.isEqualTo(
131+
"com.example.FooAutoConfiguration\ncom.example.BarAutoConfiguration\ncom.example.BazAutoConfiguration"
132+
)
123133
}
124134

125135
@Test
@@ -142,11 +152,13 @@ class SpringBootTransformerTest : BaseTransformerTest() {
142152

143153
runWithSuccess(shadowJarPath)
144154

145-
val content = outputShadowedJar.use { it.getContent(SpringBootTransformer.PATH_SPRING_HANDLERS) }
146-
assertThat(content).isEqualTo(
147-
"http\\://www.example.com/schema/bar=com.example.BarNamespaceHandler\n" +
148-
"http\\://www.example.com/schema/foo=com.example.FooNamespaceHandler\n",
149-
)
155+
val content =
156+
outputShadowedJar.use { it.getContent(SpringBootTransformer.PATH_SPRING_HANDLERS) }
157+
assertThat(content)
158+
.isEqualTo(
159+
"http\\://www.example.com/schema/bar=com.example.BarNamespaceHandler\n" +
160+
"http\\://www.example.com/schema/foo=com.example.FooNamespaceHandler\n"
161+
)
150162
}
151163

152164
@Test
@@ -172,10 +184,10 @@ class SpringBootTransformerTest : BaseTransformerTest() {
172184

173185
runWithSuccess(shadowJarPath)
174186

175-
val content = outputShadowedJar.use { it.getContent(SpringBootTransformer.PATH_SPRING_FACTORIES) }
176-
assertThat(content).isEqualTo(
177-
"shadow.example.SomeInterface=shadow.example.SomeImplementation\n",
178-
)
187+
val content =
188+
outputShadowedJar.use { it.getContent(SpringBootTransformer.PATH_SPRING_FACTORIES) }
189+
assertThat(content)
190+
.isEqualTo("shadow.example.SomeInterface=shadow.example.SomeImplementation\n")
179191
}
180192

181193
@Test
@@ -201,9 +213,12 @@ class SpringBootTransformerTest : BaseTransformerTest() {
201213

202214
runWithSuccess(shadowJarPath)
203215

204-
val content = outputShadowedJar.use {
205-
it.getContent("META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports")
206-
}
216+
val content =
217+
outputShadowedJar.use {
218+
it.getContent(
219+
"META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports"
220+
)
221+
}
207222
assertThat(content).isEqualTo("shadow.example.FooAutoConfiguration")
208223
}
209224
}

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/SpringBootTransformer.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ import org.gradle.api.model.ObjectFactory
1313
import org.gradle.api.tasks.Internal
1414

1515
/**
16-
* A resource transformer that handles Spring Boot configuration files to enable proper merging
17-
* when creating a shadow JAR.
16+
* A resource transformer that handles Spring Boot configuration files to enable proper merging when
17+
* creating a shadow JAR.
1818
*
1919
* The following Spring Boot resource files are handled:
20-
* - `META-INF/spring.factories`: Properties file with comma-separated class name values,
21-
* merged by appending values with a comma separator.
22-
* - `META-INF/spring.handlers`: Properties file with class name values, merged by appending
23-
* with a comma separator.
20+
* - `META-INF/spring.factories`: Properties file with comma-separated class name values, merged by
21+
* appending values with a comma separator.
22+
* - `META-INF/spring.handlers`: Properties file with class name values, merged by appending with a
23+
* comma separator.
2424
* - `META-INF/spring.schemas`: Properties file with schema URL-to-path mappings, merged by
2525
* appending with a comma separator.
26-
* - `META-INF/spring.tooling`: Properties file with tooling metadata, merged by appending
27-
* with a comma separator.
26+
* - `META-INF/spring.tooling`: Properties file with tooling metadata, merged by appending with a
27+
* comma separator.
2828
* - `META-INF/spring-autoconfigure-metadata.properties`: Properties file with autoconfiguration
2929
* metadata, merged by appending with a comma separator.
30-
* - `META-INF/spring/*.imports`: Line-based files where each line is a fully qualified class
30+
* - `META-INF/spring/`*`.imports`: Line-based files where each line is a fully qualified class
3131
* name; lines are deduplicated and merged across JAR files.
3232
*
3333
* Class relocation is applied to both the keys and values of properties files (using path-based
@@ -40,11 +40,9 @@ import org.gradle.api.tasks.Internal
4040
public open class SpringBootTransformer
4141
@Inject
4242
constructor(final override val objectFactory: ObjectFactory) : ResourceTransformer {
43-
@get:Internal
44-
internal val propertiesEntries = mutableMapOf<String, ReproducibleProperties>()
43+
@get:Internal internal val propertiesEntries = mutableMapOf<String, ReproducibleProperties>()
4544

46-
@get:Internal
47-
internal val importsEntries = mutableMapOf<String, LinkedHashSet<String>>()
45+
@get:Internal internal val importsEntries = mutableMapOf<String, LinkedHashSet<String>>()
4846

4947
override fun canTransformResource(element: FileTreeElement): Boolean {
5048
val path = element.path
@@ -64,12 +62,14 @@ constructor(final override val objectFactory: ObjectFactory) : ResourceTransform
6462
.forEach { entries.add(it) }
6563
} else {
6664
val props = propertiesEntries.getOrPut(path) { ReproducibleProperties() }
67-
val incoming = Properties().apply { load(context.inputStream.bufferedReader(PROPERTIES_CHARSET)) }
65+
val incoming =
66+
Properties().apply { load(context.inputStream.bufferedReader(PROPERTIES_CHARSET)) }
6867
incoming.forEach { rawKey, rawValue ->
6968
val key = context.relocators.relocateClass(rawKey as String)
70-
val value = (rawValue as String).splitToSequence(",").joinToString(",") { part ->
71-
context.relocators.relocateValue(part.trim())
72-
}
69+
val value =
70+
(rawValue as String).splitToSequence(",").joinToString(",") { part ->
71+
context.relocators.relocateValue(part.trim())
72+
}
7373
val existing = props.getProperty(key)
7474
if (existing != null) {
7575
props[key] = "$existing,$value"
@@ -121,10 +121,10 @@ constructor(final override val objectFactory: ObjectFactory) : ResourceTransform
121121
path.startsWith(SPRING_IMPORTS_PREFIX) && path.endsWith(".imports")
122122

123123
/**
124-
* Relocates a value that may be either a dot-notation class name (e.g.,
125-
* `com.example.MyClass`) or a slash-notation resource path (e.g.,
126-
* `com/example/schema.xsd`). Path-notation values are relocated using
127-
* [Iterable.relocatePath], and class-notation values using [Iterable.relocateClass].
124+
* Relocates a value that may be either a dot-notation class name (e.g., `com.example.MyClass`)
125+
* or a slash-notation resource path (e.g., `com/example/schema.xsd`). Path-notation values are
126+
* relocated using [Iterable.relocatePath], and class-notation values using
127+
* [Iterable.relocateClass].
128128
*/
129129
private fun Iterable<Relocator>.relocateValue(value: String): String {
130130
return if (value.contains('/')) relocatePath(value) else relocateClass(value)

0 commit comments

Comments
 (0)