This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/maven-build-cache-extension.git
The following commit(s) were added to refs/heads/master by this push:
new f91d584 Simplify code (#435)
f91d584 is described below
commit f91d584c161d25c1c8caacd64afb42eff82d2769
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Sat Jan 17 17:50:01 2026 -0500
Simplify code (#435)
---
.../maven/buildcache/checksum/MavenProjectInput.java | 5 ++---
.../maven/buildcache/LifecyclePhasesHelperTest.java | 14 +++++---------
.../java/org/apache/maven/buildcache/its/Issue74Test.java | 2 +-
.../buildcache/its/StaleMultimoduleArtifactTest.java | 7 ++++---
.../org/apache/maven/buildcache/util/LogFileUtils.java | 9 ++++-----
.../apache/maven/buildcache/xml/CacheConfigImplTest.java | 15 +++++++--------
6 files changed, 23 insertions(+), 29 deletions(-)
diff --git
a/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
b/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
index 5cc53d8..4f05eb3 100644
--- a/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
+++ b/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
@@ -806,13 +806,12 @@ private SortedMap<String, String>
getMutableDependenciesHashes(String keyPrefix,
projectInputCalculator.calculateInput(dependencyProject).getChecksum();
} else // this is a snapshot dependency
{
- DigestItem resolved = null;
try {
- resolved = resolveArtifact(dependency);
+ DigestItem resolved = resolveArtifact(dependency);
+ projectHash = resolved.getHash();
} catch (ArtifactResolutionException |
InvalidVersionSpecificationException e) {
throw new IOException(e);
}
- projectHash = resolved.getHash();
}
result.put(
keyPrefix +
KeyUtils.getVersionlessArtifactKey(createDependencyArtifact(dependency)),
projectHash);
diff --git
a/src/test/java/org/apache/maven/buildcache/LifecyclePhasesHelperTest.java
b/src/test/java/org/apache/maven/buildcache/LifecyclePhasesHelperTest.java
index 17e63c6..79f7fed 100644
--- a/src/test/java/org/apache/maven/buildcache/LifecyclePhasesHelperTest.java
+++ b/src/test/java/org/apache/maven/buildcache/LifecyclePhasesHelperTest.java
@@ -158,17 +158,13 @@ void isLaterPhase() {
assertFalse(lifecyclePhasesHelper.isLaterPhase("test", "site"));
assertFalse(lifecyclePhasesHelper.isLaterPhase("clean", "site"));
- assertThrows(IllegalArgumentException.class, () -> {
- lifecyclePhasesHelper.isLaterPhase("install", null);
- });
+ assertThrows(IllegalArgumentException.class, () ->
lifecyclePhasesHelper.isLaterPhase("install", null));
- assertThrows(IllegalArgumentException.class, () -> {
- lifecyclePhasesHelper.isLaterPhase("install", "unknown phase");
- });
+ assertThrows(
+ IllegalArgumentException.class, () ->
lifecyclePhasesHelper.isLaterPhase("install", "unknown phase"));
- assertThrows(IllegalArgumentException.class, () -> {
- lifecyclePhasesHelper.isLaterPhase("unknown phase", "install");
- });
+ assertThrows(
+ IllegalArgumentException.class, () ->
lifecyclePhasesHelper.isLaterPhase("unknown phase", "install"));
}
@Test
diff --git a/src/test/java/org/apache/maven/buildcache/its/Issue74Test.java
b/src/test/java/org/apache/maven/buildcache/its/Issue74Test.java
index d124433..5beb361 100644
--- a/src/test/java/org/apache/maven/buildcache/its/Issue74Test.java
+++ b/src/test/java/org/apache/maven/buildcache/its/Issue74Test.java
@@ -87,7 +87,7 @@ private static void verifyBuildCacheEntries(final Verifier
verifier, long expect
}
List<Path> entries =
- Files.list(projectPathInCache).filter(p ->
Files.isDirectory(p)).collect(Collectors.toList());
+
Files.list(projectPathInCache).filter(Files::isDirectory).collect(Collectors.toList());
Assertions.assertEquals(
expectedBuilds,
diff --git
a/src/test/java/org/apache/maven/buildcache/its/StaleMultimoduleArtifactTest.java
b/src/test/java/org/apache/maven/buildcache/its/StaleMultimoduleArtifactTest.java
index 70c5bbc..d3a481c 100644
---
a/src/test/java/org/apache/maven/buildcache/its/StaleMultimoduleArtifactTest.java
+++
b/src/test/java/org/apache/maven/buildcache/its/StaleMultimoduleArtifactTest.java
@@ -31,6 +31,7 @@
import org.apache.maven.it.Verifier;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -92,14 +93,14 @@ void staleMultimoduleDirectoriesCorrectlyStaged(Verifier
verifier) throws Verifi
"Compiler should have recompiled stale class (new timestamp: "
+ newTime + ", old timestamp: " + oldTime
+ ")");
- // Verify that staging directory was cleaned up after restore
+ // Verify that staging directory was cleaned up after restore.
// After a successful build, all files should be either:
// 1. Restored (moved back to original location) - for unchanged files
// 2. Discarded (deleted from staging) - for rebuilt files
// So the staging directory should be empty or deleted
Path stagingDir =
basedir.resolve("target/maven-build-cache-extension");
- assertTrue(
- !Files.exists(stagingDir),
+ assertFalse(
+ Files.exists(stagingDir),
"Staging directory should be deleted after all files are
restored or discarded");
}
}
diff --git a/src/test/java/org/apache/maven/buildcache/util/LogFileUtils.java
b/src/test/java/org/apache/maven/buildcache/util/LogFileUtils.java
index c7ac884..6a81948 100644
--- a/src/test/java/org/apache/maven/buildcache/util/LogFileUtils.java
+++ b/src/test/java/org/apache/maven/buildcache/util/LogFileUtils.java
@@ -45,10 +45,9 @@ private LogFileUtils() {
public static String findFirstLineContainingTextsInLogs(final Verifier
verifier, final String... texts)
throws VerificationException {
List<String> lines = verifier.loadFile(verifier.getBasedir(),
verifier.getLogFileName(), false);
- Iterator it = lines.iterator();
- while (it.hasNext()) {
- String line = verifier.stripAnsi((String) it.next());
+ for (String s : lines) {
+ String line = Verifier.stripAnsi(s);
boolean matches = true;
Iterator<String> toMatchIterator = Arrays.stream(texts).iterator();
while (matches && toMatchIterator.hasNext()) {
@@ -73,8 +72,8 @@ public static List<String>
findLinesContainingTextsInLogs(final Verifier verifie
throws VerificationException {
List<String> lines = verifier.loadFile(verifier.getBasedir(),
verifier.getLogFileName(), false);
return lines.stream()
- .map(s -> verifier.stripAnsi(s))
- .filter(s -> Arrays.stream(texts).allMatch(text ->
s.contains(text)))
+ .map(s -> Verifier.stripAnsi(s))
+ .filter(s -> Arrays.stream(texts).allMatch(s::contains))
.collect(Collectors.toList());
}
}
diff --git
a/src/test/java/org/apache/maven/buildcache/xml/CacheConfigImplTest.java
b/src/test/java/org/apache/maven/buildcache/xml/CacheConfigImplTest.java
index 721e7cc..668aa8a 100644
--- a/src/test/java/org/apache/maven/buildcache/xml/CacheConfigImplTest.java
+++ b/src/test/java/org/apache/maven/buildcache/xml/CacheConfigImplTest.java
@@ -59,6 +59,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doThrow;
@@ -144,9 +145,7 @@ private static void deepMockConfigFile(File mockFile,
boolean exists) throws IOE
.findAny();
if (methodToMock.isPresent()) {
Class<?>[] paramTypes = methodToMock.get().getParameterTypes();
- Object[] params = Arrays.stream(paramTypes)
- .map(paramType -> Mockito.any(paramType))
- .toArray();
+ Object[] params =
Arrays.stream(paramTypes).map(Mockito::any).toArray();
try {
Mockito.when(methodToMock.get().invoke(mockProvider,
params)).thenReturn(exists);
} catch (IllegalAccessException | InvocationTargetException e) {
@@ -179,9 +178,9 @@ private void assertDefaults(Map<String, Runnable>
overrides) {
asserts.put("getExcludePatterns", () ->
assertEquals(Collections.emptyList(), testObject.getExcludePatterns()));
asserts.put(
"getExecutionDirScanConfig",
- () -> assertTrue(
-
testObject.getExecutionDirScanConfig(mock(Plugin.class),
mock(PluginExecution.class))
- instanceof DefaultPluginScanConfig));
+ () -> assertInstanceOf(
+ DefaultPluginScanConfig.class,
+
testObject.getExecutionDirScanConfig(mock(Plugin.class),
mock(PluginExecution.class))));
asserts.put(
"getGlobalExcludePaths",
() -> assertEquals(Collections.emptyList(),
testObject.getGlobalExcludePaths()));
@@ -201,8 +200,8 @@ private void assertDefaults(Map<String, Runnable>
overrides) {
() -> assertEquals(Collections.emptyList(),
testObject.getNologProperties(mock(MojoExecution.class))));
asserts.put(
"getPluginDirScanConfig",
- () -> assertTrue(
- testObject.getPluginDirScanConfig(mock(Plugin.class))
instanceof DefaultPluginScanConfig));
+ () -> assertInstanceOf(
+ DefaultPluginScanConfig.class,
testObject.getPluginDirScanConfig(mock(Plugin.class))));
asserts.put(
"getTrackedProperties",
() -> assertEquals(