Skip to content

Commit a190ba8

Browse files
Spotlessppkarwasz
authored andcommitted
Reformat using Palantir formatter
1 parent b3444bd commit a190ba8

File tree

22 files changed

+268
-240
lines changed

22 files changed

+268
-240
lines changed

log4j-transform-maven-plugin/src/main/java/org/apache/logging/log4j/transform/maven/LocationMojo.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.List;
3232
import java.util.Set;
3333
import java.util.stream.Collectors;
34-
3534
import org.apache.logging.log4j.transform.maven.scan.ClassFileInclusionScanner;
3635
import org.apache.logging.log4j.transform.maven.scan.SimpleInclusionScanner;
3736
import org.apache.logging.log4j.weaver.LocationCacheGenerator;
@@ -52,7 +51,10 @@
5251
/**
5352
* Generates location information for use with Log4j2.
5453
*/
55-
@Mojo(name = "process-classes", defaultPhase = LifecyclePhase.PROCESS_CLASSES, threadSafe = true,
54+
@Mojo(
55+
name = "process-classes",
56+
defaultPhase = LifecyclePhase.PROCESS_CLASSES,
57+
threadSafe = true,
5658
requiresDependencyResolution = ResolutionScope.COMPILE)
5759
public class LocationMojo extends AbstractMojo {
5860

@@ -64,7 +66,7 @@ public class LocationMojo extends AbstractMojo {
6466
/**
6567
* The Maven project.
6668
*/
67-
@Parameter( defaultValue = "${project}", readonly = true, required = true )
69+
@Parameter(defaultValue = "${project}", readonly = true, required = true)
6870
private MavenProject project;
6971

7072
/**
@@ -112,8 +114,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
112114
final LocationClassConverter converter = new LocationClassConverter(getProjectDependencies());
113115

114116
try {
115-
final Set<Path> staleClassFiles = getClassFileInclusionScanner().getIncludedClassFiles(sourceDirectory,
116-
outputDirectory);
117+
final Set<Path> staleClassFiles =
118+
getClassFileInclusionScanner().getIncludedClassFiles(sourceDirectory, outputDirectory);
117119
staleClassFiles.stream()
118120
.collect(Collectors.groupingBy(LocationCacheGenerator::getCacheClassFile))
119121
.values()
@@ -126,8 +128,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
126128
}
127129
}
128130

129-
private void convertClassfiles(List<Path> classFiles, LocationClassConverter converter,
130-
LocationCacheGenerator locationCache) {
131+
private void convertClassfiles(
132+
List<Path> classFiles, LocationClassConverter converter, LocationCacheGenerator locationCache) {
131133
final Path sourceDirectory = this.sourceDirectory.toPath();
132134
classFiles.sort(Path::compareTo);
133135
final ByteArrayOutputStream buf = new ByteArrayOutputStream();
@@ -185,12 +187,10 @@ private static class WrappedIOException extends RuntimeException {
185187
private WrappedIOException(IOException cause) {
186188
super(cause);
187189
}
188-
189190
}
190191

191192
private void validateLog4jVersion() throws MojoExecutionException {
192-
Artifact log4jApi = project.getArtifacts()
193-
.stream()
193+
Artifact log4jApi = project.getArtifacts().stream()
194194
.filter(a -> LOG4J_GROUP_ID.equals(a.getGroupId()) && LOG4J_API_ARTIFACT_ID.equals(a.getArtifactId()))
195195
.findAny()
196196
.orElseThrow(() -> new MojoExecutionException("Missing `log4j-api` dependency."));
@@ -221,5 +221,4 @@ private ClassLoader getProjectDependencies() throws MojoExecutionException {
221221
}
222222
return new URLClassLoader(urls.toArray(EMPTY_URL_ARRAY));
223223
}
224-
225224
}

log4j-transform-maven-plugin/src/main/java/org/apache/logging/log4j/transform/maven/scan/ClassFileInclusionScanner.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.nio.file.Path;
2020
import java.util.Set;
21-
2221
import org.apache.logging.log4j.weaver.Constants;
2322

2423
public interface ClassFileInclusionScanner {
@@ -34,5 +33,4 @@ public interface ClassFileInclusionScanner {
3433
* @return a set of relative paths to file in {@code sourceDir}
3534
*/
3635
Set<Path> getIncludedClassFiles(Path sourceDir, Path targetDir);
37-
3836
}

log4j-transform-maven-plugin/src/main/java/org/apache/logging/log4j/transform/maven/scan/SimpleInclusionScanner.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Set;
2626
import java.util.stream.Collectors;
2727
import java.util.stream.Stream;
28-
2928
import org.apache.logging.log4j.weaver.LocationCacheGenerator;
3029
import org.apache.maven.plugin.logging.Log;
3130
import org.codehaus.plexus.util.DirectoryScanner;
@@ -40,12 +39,15 @@ public class SimpleInclusionScanner implements ClassFileInclusionScanner {
4039
private final Log log;
4140

4241
public SimpleInclusionScanner(long lastUpdateWithinMsecs, Log log) {
43-
this(lastUpdateWithinMsecs, Collections.singleton(DEFAULT_INCLUSION_PATTERN),
44-
Collections.singleton(DEFAULT_EXCLUSION_PATTERN), log);
42+
this(
43+
lastUpdateWithinMsecs,
44+
Collections.singleton(DEFAULT_INCLUSION_PATTERN),
45+
Collections.singleton(DEFAULT_EXCLUSION_PATTERN),
46+
log);
4547
}
4648

47-
public SimpleInclusionScanner(long lastUpdateWithinMsecs, Set<String> sourceIncludes, Set<String> sourceExcludes,
48-
Log log) {
49+
public SimpleInclusionScanner(
50+
long lastUpdateWithinMsecs, Set<String> sourceIncludes, Set<String> sourceExcludes, Log log) {
4951
this.lastUpdatedWithinMsecs = lastUpdateWithinMsecs;
5052
this.sourceIncludes = new HashSet<>(sourceIncludes);
5153
this.sourceExcludes = new HashSet<>(sourceExcludes);
@@ -56,7 +58,8 @@ public SimpleInclusionScanner(long lastUpdateWithinMsecs, Set<String> sourceIncl
5658
public Set<Path> getIncludedClassFiles(Path sourceDir, Path targetDir) {
5759
final Set<Path> potentialSources = scanForSources(sourceDir, sourceIncludes, sourceExcludes);
5860

59-
return potentialSources.stream().filter(source -> isLocationCacheStale(sourceDir, targetDir, source))
61+
return potentialSources.stream()
62+
.filter(source -> isLocationCacheStale(sourceDir, targetDir, source))
6063
.collect(Collectors.toSet());
6164
}
6265

@@ -70,9 +73,7 @@ private static Set<Path> scanForSources(Path sourceDir, Set<String> sourceInclud
7073
scanner.setExcludes(sourceExcludes.toArray(EMPTY_ARRAY));
7174
scanner.scan();
7275

73-
return Stream.of(scanner.getIncludedFiles())
74-
.map(sourceDir::resolve)
75-
.collect(Collectors.toSet());
76+
return Stream.of(scanner.getIncludedFiles()).map(sourceDir::resolve).collect(Collectors.toSet());
7677
}
7778

7879
private boolean isLocationCacheStale(Path sourceDir, Path targetDir, Path source) {
@@ -90,5 +91,4 @@ private boolean isLocationCacheStale(Path sourceDir, Path targetDir, Path source
9091
}
9192
return false;
9293
}
93-
9494
}

log4j-transform-maven-shade-plugin-extensions/src/main/java/org/apache/logging/log4j/maven/plugins/shade/transformer/CloseShieldOutputStream.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
*/
1717
package org.apache.logging.log4j.maven.plugins.shade.transformer;
1818

19+
import static org.apache.commons.io.output.ClosedOutputStream.CLOSED_OUTPUT_STREAM;
1920

2021
import java.io.IOException;
2122
import java.io.OutputStream;
22-
2323
import org.apache.commons.io.output.ProxyOutputStream;
2424

25-
import static org.apache.commons.io.output.ClosedOutputStream.CLOSED_OUTPUT_STREAM;
26-
2725
/**
2826
* Suppress the close of underlying output stream.
2927
*/
@@ -36,7 +34,6 @@ final class CloseShieldOutputStream extends ProxyOutputStream {
3634
super(out);
3735
}
3836

39-
4037
@Override
4138
public void close() throws IOException {
4239
out.flush();

log4j-transform-maven-shade-plugin-extensions/src/main/java/org/apache/logging/log4j/maven/plugins/shade/transformer/Log4j2PluginCacheFileTransformer.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
package org.apache.logging.log4j.maven.plugins.shade.transformer;
1818

19+
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
20+
import static org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE;
21+
1922
import java.io.IOException;
2023
import java.io.InputStream;
2124
import java.net.MalformedURLException;
@@ -32,21 +35,15 @@
3235
import java.util.Map.Entry;
3336
import java.util.jar.JarEntry;
3437
import java.util.jar.JarOutputStream;
35-
3638
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache;
3739
import org.apache.logging.log4j.core.config.plugins.processor.PluginEntry;
3840
import org.apache.maven.plugins.shade.relocation.Relocator;
3941
import org.apache.maven.plugins.shade.resource.ReproducibleResourceTransformer;
4042

41-
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
42-
43-
import static org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE;
44-
4543
/**
4644
* 'log4j-maven-shade-plugin' transformer implementation.
4745
*/
48-
public class Log4j2PluginCacheFileTransformer
49-
implements ReproducibleResourceTransformer {
46+
public class Log4j2PluginCacheFileTransformer implements ReproducibleResourceTransformer {
5047

5148
/**
5249
* Log4j config files to share across the transformation stages.
@@ -61,7 +58,6 @@ public class Log4j2PluginCacheFileTransformer
6158
*/
6259
private long youngestTime = 0;
6360

64-
6561
/**
6662
* Default constructor, initializing internal state.
6763
*/
@@ -93,10 +89,9 @@ public void processResource(String resource, InputStream is, List<Relocator> rel
9389
* @throws IOException thrown by file writing errors
9490
*/
9591
@Override
96-
public void processResource(final String resource,
97-
final InputStream resourceInput,
98-
final List<Relocator> relocators,
99-
final long time) throws IOException {
92+
public void processResource(
93+
final String resource, final InputStream resourceInput, final List<Relocator> relocators, final long time)
94+
throws IOException {
10095
final Path tempFile = Files.createTempFile("Log4j2Plugins", "dat");
10196
Files.copy(resourceInput, tempFile, REPLACE_EXISTING);
10297
tempFiles.add(tempFile);
@@ -115,24 +110,21 @@ public boolean hasTransformedResource() {
115110
return tempFiles.size() > 0;
116111
}
117112

118-
119113
/**
120114
* Stores all previously collected log4j-cache-files to the target jar.
121115
*
122116
* @param jos jar output
123117
* @throws IOException When the IO blows up
124118
*/
125119
@Override
126-
public void modifyOutputStream(final JarOutputStream jos)
127-
throws IOException {
120+
public void modifyOutputStream(final JarOutputStream jos) throws IOException {
128121
try {
129122
final PluginCache aggregator = new PluginCache();
130123
aggregator.loadCacheFiles(getUrls());
131124
relocatePlugin(tempRelocators, aggregator.getAllCategories());
132125
putJarEntry(jos);
133126
// prevent the aggregator to close the jar output
134-
final CloseShieldOutputStream outputStream =
135-
new CloseShieldOutputStream(jos);
127+
final CloseShieldOutputStream outputStream = new CloseShieldOutputStream(jos);
136128
aggregator.writeCache(outputStream);
137129
} finally {
138130
deleteTempFiles();
@@ -154,29 +146,25 @@ private Enumeration<URL> getUrls() throws MalformedURLException {
154146
* @param relocators relocators.
155147
* @param aggregatorCategories all categories of the aggregator
156148
*/
157-
/* default */ void relocatePlugin(final List<Relocator> relocators,
158-
Map<String, Map<String, PluginEntry>> aggregatorCategories) {
159-
for (final Entry<String, Map<String, PluginEntry>> categoryEntry
160-
: aggregatorCategories.entrySet()) {
161-
for (final Entry<String, PluginEntry> pluginMapEntry
162-
: categoryEntry.getValue().entrySet()) {
149+
/* default */ void relocatePlugin(
150+
final List<Relocator> relocators, Map<String, Map<String, PluginEntry>> aggregatorCategories) {
151+
for (final Entry<String, Map<String, PluginEntry>> categoryEntry : aggregatorCategories.entrySet()) {
152+
for (final Entry<String, PluginEntry> pluginMapEntry :
153+
categoryEntry.getValue().entrySet()) {
163154
final PluginEntry pluginEntry = pluginMapEntry.getValue();
164155
final String originalClassName = pluginEntry.getClassName();
165156

166-
final Relocator matchingRelocator = findFirstMatchingRelocator(
167-
originalClassName, relocators);
157+
final Relocator matchingRelocator = findFirstMatchingRelocator(originalClassName, relocators);
168158

169159
if (matchingRelocator != null) {
170-
final String newClassName = matchingRelocator
171-
.relocateClass(originalClassName);
160+
final String newClassName = matchingRelocator.relocateClass(originalClassName);
172161
pluginEntry.setClassName(newClassName);
173162
}
174163
}
175164
}
176165
}
177166

178-
private Relocator findFirstMatchingRelocator(final String originalClassName,
179-
final List<Relocator> relocators) {
167+
private Relocator findFirstMatchingRelocator(final String originalClassName, final List<Relocator> relocators) {
180168
Relocator result = null;
181169
for (final Relocator relocator : relocators) {
182170
if (relocator.canRelocateClass(originalClassName)) {

log4j-transform-maven-shade-plugin-extensions/src/test/java/org/apache/logging/log4j/maven/plugins/shade/transformer/Log4j2PluginCacheFileTransformerTest.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
*/
1717
package org.apache.logging.log4j.maven.plugins.shade.transformer;
1818

19+
import static java.util.Collections.enumeration;
20+
import static java.util.Collections.singletonList;
21+
import static org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.fail;
26+
1927
import java.io.ByteArrayInputStream;
2028
import java.io.ByteArrayOutputStream;
2129
import java.io.IOException;
@@ -26,7 +34,6 @@
2634
import java.util.jar.JarEntry;
2735
import java.util.jar.JarInputStream;
2836
import java.util.jar.JarOutputStream;
29-
3037
import org.apache.commons.io.IOUtils;
3138
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache;
3239
import org.apache.logging.log4j.core.config.plugins.processor.PluginEntry;
@@ -36,16 +43,6 @@
3643
import org.junit.jupiter.api.BeforeAll;
3744
import org.junit.jupiter.api.Test;
3845

39-
import static java.util.Collections.enumeration;
40-
import static java.util.Collections.singletonList;
41-
42-
import static org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE;
43-
import static org.junit.jupiter.api.Assertions.assertEquals;
44-
import static org.junit.jupiter.api.Assertions.assertFalse;
45-
import static org.junit.jupiter.api.Assertions.assertTrue;
46-
import static org.junit.jupiter.api.Assertions.fail;
47-
48-
4946
final class Log4j2PluginCacheFileTransformerTest {
5047

5148
private static URL pluginUrl;
@@ -55,7 +52,6 @@ public static void setUp() {
5552
pluginUrl = Log4j2PluginCacheFileTransformerTest.class.getClassLoader().getResource(PLUGIN_CACHE_FILE);
5653
}
5754

58-
5955
@Test
6056
public void testCanTransformResource() {
6157
final Log4j2PluginCacheFileTransformer transformer = new Log4j2PluginCacheFileTransformer();
@@ -74,14 +70,15 @@ public void test() throws Exception {
7470
assertFalse(transformer.hasTransformedResource());
7571

7672
long expectedYoungestResourceTime = 1605922127000L; // Sat Nov 21 2020 01:28:47
77-
try (InputStream log4jCacheFileInputStream = getClass().getClassLoader()
78-
.getResourceAsStream(PLUGIN_CACHE_FILE)) {
79-
transformer.processResource(PLUGIN_CACHE_FILE, log4jCacheFileInputStream, null, expectedYoungestResourceTime);
73+
try (InputStream log4jCacheFileInputStream =
74+
getClass().getClassLoader().getResourceAsStream(PLUGIN_CACHE_FILE)) {
75+
transformer.processResource(
76+
PLUGIN_CACHE_FILE, log4jCacheFileInputStream, null, expectedYoungestResourceTime);
8077
}
8178
assertTrue(transformer.hasTransformedResource());
8279

83-
try (InputStream log4jCacheFileInputStream = getClass().getClassLoader()
84-
.getResourceAsStream(PLUGIN_CACHE_FILE)) {
80+
try (InputStream log4jCacheFileInputStream =
81+
getClass().getClassLoader().getResourceAsStream(PLUGIN_CACHE_FILE)) {
8582
transformer.processResource(PLUGIN_CACHE_FILE, log4jCacheFileInputStream, null, 2000L);
8683
}
8784
assertTrue(transformer.hasTransformedResource());
@@ -92,18 +89,19 @@ public void test() throws Exception {
9289
private void assertTransformedCacheFile(
9390
@SuppressWarnings("SameParameterValue") Log4j2PluginCacheFileTransformer transformer,
9491
@SuppressWarnings("SameParameterValue") long expectedTime,
95-
@SuppressWarnings("SameParameterValue") long expectedHash) throws IOException {
92+
@SuppressWarnings("SameParameterValue") long expectedHash)
93+
throws IOException {
9694
final ByteArrayOutputStream jarBuff = new ByteArrayOutputStream();
97-
try(final JarOutputStream out = new JarOutputStream(jarBuff)) {
95+
try (final JarOutputStream out = new JarOutputStream(jarBuff)) {
9896
transformer.modifyOutputStream(out);
9997
}
10098

101-
try(JarInputStream in = new JarInputStream(new ByteArrayInputStream(jarBuff.toByteArray()))) {
102-
for (;;) {
99+
try (JarInputStream in = new JarInputStream(new ByteArrayInputStream(jarBuff.toByteArray()))) {
100+
for (; ; ) {
103101
final JarEntry jarEntry = in.getNextJarEntry();
104-
if(jarEntry == null) {
102+
if (jarEntry == null) {
105103
fail("No expected resource in the output jar");
106-
} else if(jarEntry.getName().equals(PLUGIN_CACHE_FILE)) {
104+
} else if (jarEntry.getName().equals(PLUGIN_CACHE_FILE)) {
107105
assertEquals(expectedTime, jarEntry.getTime());
108106
assertEquals(expectedHash, Arrays.hashCode(IOUtils.toByteArray(in)));
109107
break;
@@ -112,7 +110,6 @@ private void assertTransformedCacheFile(
112110
}
113111
}
114112

115-
116113
@Test
117114
public void testRelocation() throws IOException {
118115
// test with matching relocator
@@ -130,7 +127,8 @@ private void testRelocation(final String src, final String pattern, final String
130127

131128
transformer.relocatePlugin(singletonList(log4jRelocator), aggregator.getAllCategories());
132129

133-
for (final Map<String, PluginEntry> pluginEntryMap : aggregator.getAllCategories().values()) {
130+
for (final Map<String, PluginEntry> pluginEntryMap :
131+
aggregator.getAllCategories().values()) {
134132
for (final PluginEntry entry : pluginEntryMap.values()) {
135133
assertTrue(entry.getClassName().startsWith(target));
136134
}

0 commit comments

Comments
 (0)