Skip to content

Commit 9e86503

Browse files
committed
Apply code formatting and upgrade spotless tooling
- Upgrade spotless-maven-plugin from 2.44.5 to 3.0.0 - Upgrade palantir-java-format from 2.56.0 to 2.81.0 for Java 25 support - Run mvn spotless:apply to format code Addresses review feedback on PR #394.
1 parent 3126fe1 commit 9e86503

File tree

4 files changed

+70
-32
lines changed

4 files changed

+70
-32
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ under the License.
6464
<minimalMavenBuildVersion>3.9.0</minimalMavenBuildVersion>
6565
<minimalJavaBuildVersion>11</minimalJavaBuildVersion>
6666
<classWorldsVersion>2.6.0</classWorldsVersion>
67+
<version.spotless-maven-plugin>3.0.0</version.spotless-maven-plugin>
6768

6869
<!-- default maven version, will be overridden by maven3 profile -->
6970
<mavenVersion>4.0.0-alpha-8</mavenVersion>
@@ -427,6 +428,17 @@ under the License.
427428
</execution>
428429
</executions>
429430
</plugin>
431+
<plugin>
432+
<groupId>com.diffplug.spotless</groupId>
433+
<artifactId>spotless-maven-plugin</artifactId>
434+
<configuration>
435+
<java>
436+
<palantirJavaFormat>
437+
<version>2.81.0</version>
438+
</palantirJavaFormat>
439+
</java>
440+
</configuration>
441+
</plugin>
430442
</plugins>
431443
</build>
432444

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

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,11 @@ public void save(
534534
attachOutputs(project, state, buildStartTime);
535535
}
536536

537-
final List<org.apache.maven.artifact.Artifact> attachedArtifacts = project.getAttachedArtifacts() != null
538-
? project.getAttachedArtifacts()
539-
: Collections.emptyList();
537+
final List<org.apache.maven.artifact.Artifact> attachedArtifacts =
538+
project.getAttachedArtifacts() != null ? project.getAttachedArtifacts() : Collections.emptyList();
540539
final List<Artifact> attachedArtifactDtos = artifactDtos(attachedArtifacts, algorithm, project, state);
541-
final Artifact projectArtifactDto = hasPackagePhase ? artifactDto(project.getArtifact(), algorithm, project, state)
542-
: null;
540+
final Artifact projectArtifactDto =
541+
hasPackagePhase ? artifactDto(project.getArtifact(), algorithm, project, state) : null;
543542

544543
// CRITICAL: Don't create incomplete cache entries!
545544
// Only save cache entry if we have SOMETHING useful to restore.
@@ -576,7 +575,8 @@ public void save(
576575
}
577576
for (org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts) {
578577
if (attachedArtifact.getFile() != null) {
579-
boolean storeArtifact = isOutputArtifact(attachedArtifact.getFile().getName());
578+
boolean storeArtifact =
579+
isOutputArtifact(attachedArtifact.getFile().getName());
580580
if (storeArtifact) {
581581
localCache.saveArtifactFile(cacheResult, attachedArtifact);
582582
} else {
@@ -662,7 +662,9 @@ public void produceDiffReport(CacheResult cacheResult, Build build) {
662662
}
663663

664664
private List<Artifact> artifactDtos(
665-
List<org.apache.maven.artifact.Artifact> attachedArtifacts, HashAlgorithm digest, MavenProject project,
665+
List<org.apache.maven.artifact.Artifact> attachedArtifacts,
666+
HashAlgorithm digest,
667+
MavenProject project,
666668
ProjectCacheState state)
667669
throws IOException {
668670
List<Artifact> result = new ArrayList<>();
@@ -676,7 +678,9 @@ && isOutputArtifact(attachedArtifact.getFile().getName())) {
676678
}
677679

678680
private Artifact artifactDto(
679-
org.apache.maven.artifact.Artifact projectArtifact, HashAlgorithm algorithm, MavenProject project,
681+
org.apache.maven.artifact.Artifact projectArtifact,
682+
HashAlgorithm algorithm,
683+
MavenProject project,
680684
ProjectCacheState state)
681685
throws IOException {
682686
final Artifact dto = DtoUtils.createDto(projectArtifact);
@@ -940,15 +944,29 @@ private void restoreGeneratedSources(Artifact artifact, Path artifactFilePath, M
940944
}
941945

942946
// TODO: move to config
943-
public void attachGeneratedSources(MavenProject project, ProjectCacheState state, long buildStartTime) throws IOException {
947+
public void attachGeneratedSources(MavenProject project, ProjectCacheState state, long buildStartTime)
948+
throws IOException {
944949
final Path targetDir = Paths.get(project.getBuild().getDirectory());
945950

946951
final Path generatedSourcesDir = targetDir.resolve("generated-sources");
947-
attachDirIfNotEmpty(generatedSourcesDir, targetDir, project, state, OutputType.GENERATED_SOURCE, DEFAULT_FILE_GLOB, buildStartTime);
952+
attachDirIfNotEmpty(
953+
generatedSourcesDir,
954+
targetDir,
955+
project,
956+
state,
957+
OutputType.GENERATED_SOURCE,
958+
DEFAULT_FILE_GLOB,
959+
buildStartTime);
948960

949961
final Path generatedTestSourcesDir = targetDir.resolve("generated-test-sources");
950962
attachDirIfNotEmpty(
951-
generatedTestSourcesDir, targetDir, project, state, OutputType.GENERATED_SOURCE, DEFAULT_FILE_GLOB, buildStartTime);
963+
generatedTestSourcesDir,
964+
targetDir,
965+
project,
966+
state,
967+
OutputType.GENERATED_SOURCE,
968+
DEFAULT_FILE_GLOB,
969+
buildStartTime);
952970

953971
Set<String> sourceRoots = new TreeSet<>();
954972
if (project.getCompileSourceRoots() != null) {
@@ -964,7 +982,14 @@ public void attachGeneratedSources(MavenProject project, ProjectCacheState state
964982
&& sourceRootPath.startsWith(targetDir)
965983
&& !(sourceRootPath.startsWith(generatedSourcesDir)
966984
|| sourceRootPath.startsWith(generatedTestSourcesDir))) { // dir within target
967-
attachDirIfNotEmpty(sourceRootPath, targetDir, project, state, OutputType.GENERATED_SOURCE, DEFAULT_FILE_GLOB, buildStartTime);
985+
attachDirIfNotEmpty(
986+
sourceRootPath,
987+
targetDir,
988+
project,
989+
state,
990+
OutputType.GENERATED_SOURCE,
991+
DEFAULT_FILE_GLOB,
992+
buildStartTime);
968993
}
969994
}
970995
}
@@ -975,7 +1000,8 @@ private void attachOutputs(MavenProject project, ProjectCacheState state, long b
9751000
final Path targetDir = Paths.get(project.getBuild().getDirectory());
9761001
final Path outputDir = targetDir.resolve(dir.getValue());
9771002
if (isPathInsideProject(project, outputDir)) {
978-
attachDirIfNotEmpty(outputDir, targetDir, project, state, OutputType.EXTRA_OUTPUT, dir.getGlob(), buildStartTime);
1003+
attachDirIfNotEmpty(
1004+
outputDir, targetDir, project, state, OutputType.EXTRA_OUTPUT, dir.getGlob(), buildStartTime);
9791005
} else {
9801006
LOGGER.warn("Outside project output candidate directory discarded ({})", outputDir.normalize());
9811007
}

src/test/java/org/apache/maven/buildcache/its/CacheCompileDisabledTest.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ void compileDoesNotCacheWhenDisabled(Verifier verifier) throws VerificationExcep
6262
verifier.verifyErrorFreeLog();
6363

6464
// Verify NO cache entry was created (no buildinfo.xml in local cache)
65-
boolean hasCacheEntry = Files.walk(localCache)
66-
.anyMatch(p -> p.getFileName().toString().equals("buildinfo.xml"));
67-
assertFalse(hasCacheEntry,
68-
"Cache entry should NOT be created when maven.build.cache.cacheCompile=false");
65+
boolean hasCacheEntry =
66+
Files.walk(localCache).anyMatch(p -> p.getFileName().toString().equals("buildinfo.xml"));
67+
assertFalse(hasCacheEntry, "Cache entry should NOT be created when maven.build.cache.cacheCompile=false");
6968

7069
// Clean project and run compile again
7170
verifier.setLogFileName("../log-compile-disabled-2.txt");
@@ -78,7 +77,8 @@ void compileDoesNotCacheWhenDisabled(Verifier verifier) throws VerificationExcep
7877
// Verify cache miss (should NOT restore from cache)
7978
Path logFile = Paths.get(verifier.getBasedir()).getParent().resolve("log-compile-disabled-2.txt");
8079
String logContent = new String(Files.readAllBytes(logFile));
81-
assertFalse(logContent.contains("Found cached build, restoring"),
80+
assertFalse(
81+
logContent.contains("Found cached build, restoring"),
8282
"Should NOT restore from cache when cacheCompile was disabled");
8383
}
8484

@@ -103,10 +103,9 @@ void compileCreatesCacheEntryWhenEnabled(Verifier verifier) throws VerificationE
103103
verifier.verifyErrorFreeLog();
104104

105105
// Verify cache entry WAS created
106-
boolean hasCacheEntry = Files.walk(localCache)
107-
.anyMatch(p -> p.getFileName().toString().equals("buildinfo.xml"));
108-
assertTrue(hasCacheEntry,
109-
"Cache entry should be created when maven.build.cache.cacheCompile=true (default)");
106+
boolean hasCacheEntry =
107+
Files.walk(localCache).anyMatch(p -> p.getFileName().toString().equals("buildinfo.xml"));
108+
assertTrue(hasCacheEntry, "Cache entry should be created when maven.build.cache.cacheCompile=true (default)");
110109

111110
// Clean project and run compile again
112111
verifier.setLogFileName("../log-compile-enabled-2.txt");
@@ -123,14 +122,13 @@ void compileCreatesCacheEntryWhenEnabled(Verifier verifier) throws VerificationE
123122
private void deleteDirectory(Path directory) throws IOException {
124123
if (Files.exists(directory)) {
125124
try (Stream<Path> walk = Files.walk(directory)) {
126-
walk.sorted((a, b) -> b.compareTo(a))
127-
.forEach(path -> {
128-
try {
129-
Files.delete(path);
130-
} catch (IOException e) {
131-
// Ignore
132-
}
133-
});
125+
walk.sorted((a, b) -> b.compareTo(a)).forEach(path -> {
126+
try {
127+
Files.delete(path);
128+
} catch (IOException e) {
129+
// Ignore
130+
}
131+
});
134132
}
135133
}
136134
}

src/test/java/org/apache/maven/buildcache/its/Issue393CompileRestoreTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ void restoresAttachedOutputsAfterCompileOnlyBuild(Verifier verifier) throws Veri
4141
verifier.setLogFileName("../log-verify.txt");
4242
verifier.executeGoals(Arrays.asList("clean", "verify"));
4343
verifier.verifyErrorFreeLog();
44-
verifier.verifyTextInLog("Found cached build, restoring org.apache.maven.caching.test.jpms:issue-393-app from cache");
44+
verifier.verifyTextInLog(
45+
"Found cached build, restoring org.apache.maven.caching.test.jpms:issue-393-app from cache");
4546
verifier.verifyTextInLog("Skipping plugin execution (cached): compiler:compile");
4647

4748
verifier.verifyFilePresent("app/target/classes/module-info.class");
4849
verifier.verifyFilePresent("consumer/target/classes/module-info.class");
49-
verifier.verifyFilePresent("consumer/target/test-classes/org/apache/maven/caching/test/jpms/consumer/ConsumerTest.class");
50+
verifier.verifyFilePresent(
51+
"consumer/target/test-classes/org/apache/maven/caching/test/jpms/consumer/ConsumerTest.class");
5052
}
5153
}

0 commit comments

Comments
 (0)