Skip to content

Commit 42ddb77

Browse files
Excavator: Format Java files (#1605)
1 parent 8d152b9 commit 42ddb77

4 files changed

Lines changed: 34 additions & 31 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ buildscript {
1919
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.75.0'
2020
classpath 'com.palantir.gradle.jdkslatest:gradle-jdks-latest:0.26.0'
2121
classpath 'com.palantir.gradle.plugintesting:gradle-plugin-testing:0.54.0'
22-
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.88.0'
22+
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.89.0'
2323
classpath 'com.palantir.suppressible-error-prone:gradle-suppressible-error-prone:2.28.0'
2424
classpath 'me.champeau.jmh:jmh-gradle-plugin:0.7.3'
2525
classpath 'org.revapi:gradle-revapi:1.8.0'

gradle-palantir-java-format/src/main/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatIdeaPlugin.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,18 @@ public void apply(Project rootProject) {
6161
.getByName(PalantirJavaFormatProviderPlugin.CONFIGURATION_NAME));
6262
maybeGetNativeImplConfiguration().ifPresent(config -> {
6363
task.getNativeImageConfig().from(config);
64-
task.getNativeImageOutputFile().fileProvider(rootProject.provider(() -> rootProject
65-
.getGradle()
66-
.getGradleUserHomeDir()
67-
.toPath()
68-
.resolve("palantir-java-format-caches/")
69-
.resolve(Paths.get(task.getNativeImageConfig()
70-
.getSingleFile()
71-
.toURI())
72-
.getFileName()
73-
.toString())
74-
.toFile()));
64+
task.getNativeImageOutputFile()
65+
.fileProvider(rootProject.provider(() -> rootProject
66+
.getGradle()
67+
.getGradleUserHomeDir()
68+
.toPath()
69+
.resolve("palantir-java-format-caches/")
70+
.resolve(Paths.get(task.getNativeImageConfig()
71+
.getSingleFile()
72+
.toURI())
73+
.getFileName()
74+
.toString())
75+
.toFile()));
7576
});
7677
});
7778

gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/PalantirJavaFormatSpotlessPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public void apply(Project project) {
3737

3838
SpotlessInterop spotlessInterop = rootProject.getObjects().newInstance(SpotlessInterop.class, memoizedService);
3939
project.getPluginManager().withPlugin("java", _javaPlugin -> {
40-
SPOTLESS_PLUGINS.forEach(
41-
spotlessPluginId -> project.getPluginManager().withPlugin(spotlessPluginId, _spotlessPlugin -> {
40+
SPOTLESS_PLUGINS.forEach(spotlessPluginId -> project.getPluginManager()
41+
.withPlugin(spotlessPluginId, _spotlessPlugin -> {
4242
SpotlessExtension spotlessExtension =
4343
project.getExtensions().getByType(SpotlessExtension.class);
4444
spotlessExtension.java(spotlessInterop);

idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,25 @@ Optional<String> getImplementationVersion() {
115115
}
116116

117117
Optional<String> computeFormatterVersion() {
118-
return getImplementationClassPath().map(classpath -> classpath.stream()
119-
.flatMap(uri -> {
120-
try {
121-
JarFile jar = new JarFile(uri.getPath());
122-
// Identify the implementation jar by the service it produces.
123-
if (jar.getEntry("META-INF/services/" + FormatterService.class.getName()) != null) {
124-
String implementationVersion =
125-
jar.getManifest().getMainAttributes().getValue("Implementation-Version");
126-
return Stream.of(implementationVersion);
127-
}
128-
return Stream.empty();
129-
} catch (IOException e) {
130-
throw new UncheckedIOException(e);
131-
}
132-
})
133-
.findFirst()
134-
.orElseThrow(() -> new RuntimeException("Couldn't find implementation JAR")));
118+
return getImplementationClassPath()
119+
.map(classpath -> classpath.stream()
120+
.flatMap(uri -> {
121+
try {
122+
JarFile jar = new JarFile(uri.getPath());
123+
// Identify the implementation jar by the service it produces.
124+
if (jar.getEntry("META-INF/services/" + FormatterService.class.getName()) != null) {
125+
String implementationVersion = jar.getManifest()
126+
.getMainAttributes()
127+
.getValue("Implementation-Version");
128+
return Stream.of(implementationVersion);
129+
}
130+
return Stream.empty();
131+
} catch (IOException e) {
132+
throw new UncheckedIOException(e);
133+
}
134+
})
135+
.findFirst()
136+
.orElseThrow(() -> new RuntimeException("Couldn't find implementation JAR")));
135137
}
136138

137139
enum EnabledState {

0 commit comments

Comments
 (0)