Skip to content

Commit c9aaacb

Browse files
authored
Some minor cleanup fixing IDE warnings (#172)
Signed-off-by: Olivier Lamy <[email protected]>
1 parent 4c0e754 commit c9aaacb

9 files changed

+23
-39
lines changed

src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class BuildCacheMojosExecutionStrategy implements MojosExecutionStrategy
7979
private final MojoParametersListener mojoListener;
8080
private final LifecyclePhasesHelper lifecyclePhasesHelper;
8181
private final MavenPluginManager mavenPluginManager;
82-
private MojoExecutionScope mojoExecutionScope;
82+
private final MojoExecutionScope mojoExecutionScope;
8383

8484
@Inject
8585
public BuildCacheMojosExecutionStrategy(
@@ -434,6 +434,6 @@ private static String normalizedPath(Path path, Path baseDirPath) {
434434
private enum CacheRestorationStatus {
435435
SUCCESS,
436436
FAILURE,
437-
FAILURE_NEEDS_CLEAN;
437+
FAILURE_NEEDS_CLEAN
438438
}
439439
}

src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public class CacheControllerImpl implements CacheController {
137137
* (ex : generated source basedir).
138138
* Used to link the resource to its path on disk
139139
*/
140-
private Map<String, Path> attachedResourcesPathsById = new HashMap<>();
140+
private final Map<String, Path> attachedResourcesPathsById = new HashMap<>();
141141

142142
private int attachedResourceCounter = 0;
143143

@@ -467,7 +467,7 @@ private Future<File> createDownloadTask(
467467
if (!Files.exists(artifactFile)) {
468468
throw new FileNotFoundException("Missing file for cached build, cannot restore. File: " + artifactFile);
469469
}
470-
LOGGER.debug("Downloaded artifact " + artifact.getArtifactId() + " to: " + artifactFile);
470+
LOGGER.debug("Downloaded artifact {} to: {}", artifact.getArtifactId(), artifactFile);
471471
return restoreArtifactHandler
472472
.adjustArchiveArtifactVersion(project, originalVersion, artifactFile)
473473
.toFile();

src/main/java/org/apache/maven/buildcache/DefaultMultiModuleSupport.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.File;
2525
import java.util.ArrayList;
2626
import java.util.Collections;
27+
import java.util.HashSet;
2728
import java.util.LinkedHashSet;
2829
import java.util.List;
2930
import java.util.Map;
@@ -132,7 +133,7 @@ private synchronized void buildModel(MavenSession session) {
132133
File multiModulePomFile = getMultiModulePomFile(session);
133134

134135
ProjectBuildingRequest projectBuildingRequest = currentProject.getProjectBuildingRequest();
135-
boolean profilesMatched = projectBuildingRequest.getActiveProfileIds().containsAll(scanProfiles);
136+
boolean profilesMatched = new HashSet<>(projectBuildingRequest.getActiveProfileIds()).containsAll(scanProfiles);
136137

137138
// we are building from root with the same profiles, no need to re-scan the whole multi-module project
138139
if (currentProject.getFile().getAbsolutePath().equals(multiModulePomFile.getAbsolutePath())

src/main/java/org/apache/maven/buildcache/DefaultRestoredArtifactHandler.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
import java.io.BufferedOutputStream;
2626
import java.io.File;
27-
import java.io.FileOutputStream;
2827
import java.io.IOException;
2928
import java.io.InputStream;
3029
import java.nio.charset.StandardCharsets;
30+
import java.nio.file.Files;
3131
import java.nio.file.Path;
3232
import java.nio.file.Paths;
3333
import java.util.Enumeration;
@@ -96,7 +96,7 @@ public Path adjustArchiveArtifactVersion(MavenProject project, String originalAr
9696
String pomPropsVersion = "version=" + currentVersion;
9797
try (JarFile jarFile = new JarFile(artifactFile.toFile())) {
9898
try (JarOutputStream jos =
99-
new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tmpJarFile)))) {
99+
new JarOutputStream(new BufferedOutputStream(Files.newOutputStream(tmpJarFile.toPath())))) {
100100
// Copy original jar file to the temporary one.
101101
Enumeration<JarEntry> jarEntries = jarFile.entries();
102102
byte[] buffer = new byte[1024];
@@ -140,7 +140,7 @@ public Path adjustArchiveArtifactVersion(MavenProject project, String originalAr
140140
private static void replaceEntry(
141141
JarFile jarFile, JarEntry entry, String toReplace, String replacement, JarOutputStream jos)
142142
throws IOException {
143-
String fullManifest = IOUtils.toString(jarFile.getInputStream(entry), StandardCharsets.UTF_8.name());
143+
String fullManifest = IOUtils.toString(jarFile.getInputStream(entry), StandardCharsets.UTF_8);
144144
String modified = fullManifest.replaceAll(toReplace, replacement);
145145

146146
byte[] bytes = modified.getBytes(StandardCharsets.UTF_8);

src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryNoOp.java

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public boolean getArtifactContent(
5858
return false;
5959
}
6060

61-
@Nonnull
6261
@Override
6362
public String getResourceUrl(CacheContext context, String filename) {
6463
return null;

src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
import org.apache.maven.model.Resource;
8383
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
8484
import org.apache.maven.project.MavenProject;
85-
import org.codehaus.plexus.util.IOUtil;
8685
import org.codehaus.plexus.util.WriterFactory;
8786
import org.eclipse.aether.RepositorySystem;
8887
import org.eclipse.aether.artifact.DefaultArtifactType;
@@ -344,19 +343,13 @@ private boolean checkItemMatchesBaseline(ProjectsInputInfo baselineBuild, Digest
344343
private String getEffectivePom(Model prototype) throws IOException {
345344
ByteArrayOutputStream output = new ByteArrayOutputStream();
346345

347-
Writer writer = null;
348-
try {
349-
writer = WriterFactory.newXmlWriter(output);
346+
try (Writer writer = WriterFactory.newXmlWriter(output)) {
350347
new MavenXpp3Writer().write(writer, prototype);
351348

352349
// normalize env specifics
353350
final String[] searchList = {baseDirPath.toString(), "\\", "windows", "linux"};
354351
final String[] replacementList = {"", "/", "os.classifier", "os.classifier"};
355-
356352
return replaceEachRepeatedly(output.toString(), searchList, replacementList);
357-
358-
} finally {
359-
IOUtil.close(writer);
360353
}
361354
}
362355

@@ -520,7 +513,7 @@ public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes basicFil
520513
return FileVisitResult.SKIP_SUBTREE;
521514
}
522515

523-
walkDirectoryFiles(path, collectedFiles, key.getGlob(), entry -> exclusionResolver.excludesPath(entry));
516+
walkDirectoryFiles(path, collectedFiles, key.getGlob(), exclusionResolver::excludesPath);
524517

525518
if (!key.isRecursive()) {
526519
LOGGER.debug("Skipping subtree (non recursive): {}", path);

src/main/java/org/apache/maven/buildcache/checksum/exclude/Exclusion.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ public boolean excludesPath(Path parentPath, Path path) {
146146

147147
public enum MatcherType {
148148
FILENAME,
149-
PATH;
149+
PATH
150150
}
151151

152152
public enum EntryType {
153153
FILE,
154154
DIRECTORY,
155-
ALL;
155+
ALL
156156
}
157157
}

src/main/java/org/apache/maven/buildcache/hash/CloseableBuffer.java

+7-17
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@
3434
*/
3535
public class CloseableBuffer implements AutoCloseable {
3636

37-
private static final Cleaner CLEANER = doPrivileged(new PrivilegedAction<Cleaner>() {
38-
39-
@Override
40-
public Cleaner run() {
41-
final String jsv = System.getProperty("java.specification.version", "9");
42-
if (jsv.startsWith("1.")) {
43-
return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner();
44-
} else {
45-
return UnsafeCleaner.isSupported() ? new UnsafeCleaner() : new NoopCleaner();
46-
}
37+
private static final Cleaner CLEANER = doPrivileged((PrivilegedAction<Cleaner>) () -> {
38+
final String jsv = System.getProperty("java.specification.version", "9");
39+
if (jsv.startsWith("1.")) {
40+
return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner();
41+
} else {
42+
return UnsafeCleaner.isSupported() ? new UnsafeCleaner() : new NoopCleaner();
4743
}
4844
});
4945

@@ -75,13 +71,7 @@ public ByteBuffer getBuffer() {
7571
@Override
7672
public void close() {
7773
// Java 8: () -> CLEANER.clean(buffer)
78-
boolean done = doPrivileged(new PrivilegedAction<Boolean>() {
79-
80-
@Override
81-
public Boolean run() {
82-
return CLEANER.clean(buffer);
83-
}
84-
});
74+
boolean done = doPrivileged((PrivilegedAction<Boolean>) () -> CLEANER.clean(buffer));
8575
if (done) {
8676
buffer = null;
8777
}

src/main/java/org/apache/maven/buildcache/xml/CacheConfigImpl.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ public CacheState initialize() {
138138
final boolean enabled = getProperty(CACHE_ENABLED_PROPERTY_NAME, true);
139139

140140
if (!rtInfo.isMavenVersion("[3.9.0,)")) {
141-
LOGGER.warn("Cache requires Maven >= 3.9, but version is " + rtInfo.getMavenVersion()
142-
+ ". Disabling cache.");
141+
LOGGER.warn(
142+
"Cache requires Maven >= 3.9, but version is {}. Disabling cache.",
143+
rtInfo.getMavenVersion());
143144
state = CacheState.DISABLED;
144145
} else if (!enabled) {
145146
LOGGER.info("Cache disabled by command line flag, project will be built fully and not cached");

0 commit comments

Comments
 (0)