Skip to content

Commit 5e7917e

Browse files
committed
Upgrade to Maven Shade Plugin 3.2.4
Closes gh-22074
1 parent 66b84ac commit 5e7917e

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

spring-boot-project/spring-boot-parent/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ bom {
9595
]
9696
}
9797
}
98-
library("Maven Shade Plugin", "3.2.1") {
98+
library("Maven Shade Plugin", "3.2.4") {
9999
group("org.apache.maven.plugins") {
100100
modules = [
101101
"maven-shade-plugin"

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/PropertiesMergingResourceTransformer.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
2424
import java.util.jar.JarOutputStream;
2525

2626
import org.apache.maven.plugins.shade.relocation.Relocator;
27-
import org.apache.maven.plugins.shade.resource.ResourceTransformer;
27+
import org.apache.maven.plugins.shade.resource.ReproducibleResourceTransformer;
2828

2929
/**
3030
* Extension for the <a href="https://maven.apache.org/plugins/maven-shade-plugin/">Maven
@@ -35,13 +35,15 @@
3535
* @author Andy Wilkinson
3636
* @since 1.0.0
3737
*/
38-
public class PropertiesMergingResourceTransformer implements ResourceTransformer {
38+
public class PropertiesMergingResourceTransformer implements ReproducibleResourceTransformer {
3939

4040
// Set this in pom configuration with <resource>...</resource>
4141
private String resource;
4242

4343
private final Properties data = new Properties();
4444

45+
private long time;
46+
4547
/**
4648
* Return the data the properties being merged.
4749
* @return the data
@@ -56,12 +58,22 @@ public boolean canTransformResource(String resource) {
5658
}
5759

5860
@Override
61+
@Deprecated
5962
public void processResource(String resource, InputStream inputStream, List<Relocator> relocators)
6063
throws IOException {
64+
processResource(resource, inputStream, relocators, 0);
65+
}
66+
67+
@Override
68+
public void processResource(String resource, InputStream inputStream, List<Relocator> relocators, long time)
69+
throws IOException {
6170
Properties properties = new Properties();
6271
properties.load(inputStream);
6372
inputStream.close();
6473
properties.forEach((name, value) -> process((String) name, (String) value));
74+
if (time > this.time) {
75+
this.time = time;
76+
}
6577
}
6678

6779
private void process(String name, String value) {
@@ -76,7 +88,9 @@ public boolean hasTransformedResource() {
7688

7789
@Override
7890
public void modifyOutputStream(JarOutputStream os) throws IOException {
79-
os.putNextEntry(new JarEntry(this.resource));
91+
JarEntry jarEntry = new JarEntry(this.resource);
92+
jarEntry.setTime(this.time);
93+
os.putNextEntry(jarEntry);
8094
this.data.store(os, "Merged by PropertiesMergingResourceTransformer");
8195
os.flush();
8296
this.data.clear();

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/PropertiesMergingResourceTransformerTests.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,10 @@
1818

1919
import java.io.ByteArrayInputStream;
2020
import java.io.ByteArrayOutputStream;
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
import java.util.jar.JarEntry;
24+
import java.util.jar.JarInputStream;
2125
import java.util.jar.JarOutputStream;
2226

2327
import org.junit.jupiter.api.Test;
@@ -36,28 +40,38 @@ class PropertiesMergingResourceTransformerTests {
3640
@Test
3741
void testProcess() throws Exception {
3842
assertThat(this.transformer.hasTransformedResource()).isFalse();
39-
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null);
43+
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, 0);
4044
assertThat(this.transformer.hasTransformedResource()).isTrue();
4145
}
4246

4347
@Test
4448
void testMerge() throws Exception {
45-
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null);
46-
this.transformer.processResource("bar", new ByteArrayInputStream("foo=spam".getBytes()), null);
49+
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, 0);
50+
this.transformer.processResource("bar", new ByteArrayInputStream("foo=spam".getBytes()), null, 0);
4751
assertThat(this.transformer.getData().getProperty("foo")).isEqualTo("bar,spam");
4852
}
4953

5054
@Test
5155
void testOutput() throws Exception {
5256
this.transformer.setResource("foo");
53-
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null);
57+
long time = 1592911068000L;
58+
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, time);
5459
ByteArrayOutputStream out = new ByteArrayOutputStream();
5560
JarOutputStream os = new JarOutputStream(out);
5661
this.transformer.modifyOutputStream(os);
5762
os.flush();
5863
os.close();
59-
assertThat(out.toByteArray()).isNotNull();
60-
assertThat(out.toByteArray().length > 0).isTrue();
64+
byte[] bytes = out.toByteArray();
65+
assertThat(bytes).hasSizeGreaterThan(0);
66+
List<JarEntry> entries = new ArrayList<>();
67+
try (JarInputStream is = new JarInputStream(new ByteArrayInputStream(bytes))) {
68+
JarEntry entry;
69+
while ((entry = is.getNextJarEntry()) != null) {
70+
entries.add(entry);
71+
}
72+
}
73+
assertThat(entries).hasSize(1);
74+
assertThat(entries.get(0).getTime()).isEqualTo(time);
6175
}
6276

6377
}

0 commit comments

Comments
 (0)