Upgrade to Maven Shade Plugin 3.2.4
Closes gh-22074
This commit is contained in:
@@ -95,7 +95,7 @@ bom {
|
||||
]
|
||||
}
|
||||
}
|
||||
library("Maven Shade Plugin", "3.2.1") {
|
||||
library("Maven Shade Plugin", "3.2.4") {
|
||||
group("org.apache.maven.plugins") {
|
||||
modules = [
|
||||
"maven-shade-plugin"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,7 @@ import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
|
||||
import org.apache.maven.plugins.shade.relocation.Relocator;
|
||||
import org.apache.maven.plugins.shade.resource.ResourceTransformer;
|
||||
import org.apache.maven.plugins.shade.resource.ReproducibleResourceTransformer;
|
||||
|
||||
/**
|
||||
* Extension for the <a href="https://maven.apache.org/plugins/maven-shade-plugin/">Maven
|
||||
@@ -35,13 +35,15 @@ import org.apache.maven.plugins.shade.resource.ResourceTransformer;
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class PropertiesMergingResourceTransformer implements ResourceTransformer {
|
||||
public class PropertiesMergingResourceTransformer implements ReproducibleResourceTransformer {
|
||||
|
||||
// Set this in pom configuration with <resource>...</resource>
|
||||
private String resource;
|
||||
|
||||
private final Properties data = new Properties();
|
||||
|
||||
private long time;
|
||||
|
||||
/**
|
||||
* Return the data the properties being merged.
|
||||
* @return the data
|
||||
@@ -56,12 +58,22 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void processResource(String resource, InputStream inputStream, List<Relocator> relocators)
|
||||
throws IOException {
|
||||
processResource(resource, inputStream, relocators, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processResource(String resource, InputStream inputStream, List<Relocator> relocators, long time)
|
||||
throws IOException {
|
||||
Properties properties = new Properties();
|
||||
properties.load(inputStream);
|
||||
inputStream.close();
|
||||
properties.forEach((name, value) -> process((String) name, (String) value));
|
||||
if (time > this.time) {
|
||||
this.time = time;
|
||||
}
|
||||
}
|
||||
|
||||
private void process(String name, String value) {
|
||||
@@ -76,7 +88,9 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer
|
||||
|
||||
@Override
|
||||
public void modifyOutputStream(JarOutputStream os) throws IOException {
|
||||
os.putNextEntry(new JarEntry(this.resource));
|
||||
JarEntry jarEntry = new JarEntry(this.resource);
|
||||
jarEntry.setTime(this.time);
|
||||
os.putNextEntry(jarEntry);
|
||||
this.data.store(os, "Merged by PropertiesMergingResourceTransformer");
|
||||
os.flush();
|
||||
this.data.clear();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,10 @@ package org.springframework.boot.maven;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
import java.util.jar.JarOutputStream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -36,28 +40,38 @@ class PropertiesMergingResourceTransformerTests {
|
||||
@Test
|
||||
void testProcess() throws Exception {
|
||||
assertThat(this.transformer.hasTransformedResource()).isFalse();
|
||||
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null);
|
||||
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, 0);
|
||||
assertThat(this.transformer.hasTransformedResource()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMerge() throws Exception {
|
||||
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null);
|
||||
this.transformer.processResource("bar", new ByteArrayInputStream("foo=spam".getBytes()), null);
|
||||
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, 0);
|
||||
this.transformer.processResource("bar", new ByteArrayInputStream("foo=spam".getBytes()), null, 0);
|
||||
assertThat(this.transformer.getData().getProperty("foo")).isEqualTo("bar,spam");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOutput() throws Exception {
|
||||
this.transformer.setResource("foo");
|
||||
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null);
|
||||
long time = 1592911068000L;
|
||||
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, time);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
JarOutputStream os = new JarOutputStream(out);
|
||||
this.transformer.modifyOutputStream(os);
|
||||
os.flush();
|
||||
os.close();
|
||||
assertThat(out.toByteArray()).isNotNull();
|
||||
assertThat(out.toByteArray().length > 0).isTrue();
|
||||
byte[] bytes = out.toByteArray();
|
||||
assertThat(bytes).hasSizeGreaterThan(0);
|
||||
List<JarEntry> entries = new ArrayList<>();
|
||||
try (JarInputStream is = new JarInputStream(new ByteArrayInputStream(bytes))) {
|
||||
JarEntry entry;
|
||||
while ((entry = is.getNextJarEntry()) != null) {
|
||||
entries.add(entry);
|
||||
}
|
||||
}
|
||||
assertThat(entries).hasSize(1);
|
||||
assertThat(entries.get(0).getTime()).isEqualTo(time);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user