Skip to content

Commit e6c5aa2

Browse files
committed
its WORKING
1 parent c3b617d commit e6c5aa2

4 files changed

Lines changed: 115 additions & 15 deletions

File tree

gradle-palantir-java-format/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ dependencies {
2828
testImplementation 'org.assertj:assertj-core'
2929

3030
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
31+
32+
pluginClasspath 'com.diffplug.spotless:spotless-plugin-gradle'
3133
}
3234

3335
gradlePlugin {

gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/ConfigurationCacheTest.groovy

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.palantir.javaformat.gradle
1717

1818
import nebula.test.IntegrationTestKitSpec
1919
import nebula.test.functional.internal.classpath.ClasspathAddingInitScriptBuilder
20+
import org.gradle.api.invocation.Gradle
2021
import spock.lang.Unroll
2122

2223
import java.nio.charset.StandardCharsets
@@ -26,9 +27,15 @@ import java.util.stream.Collectors
2627
import java.util.stream.Stream
2728

2829
class ConfigurationCacheTest extends IntegrationTestKitSpec {
30+
GradlewExecutor executor
31+
32+
private static final CLASSPATH_FILE = new File("build/impl.classpath").absolutePath
33+
34+
2935
def setup() {
3036
definePluginOutsideOfPluginBlock = true
3137
keepFiles = true
38+
executor = new GradlewExecutor(projectDir)
3239
}
3340

3441
def "can run classes"() {
@@ -38,20 +45,21 @@ class ConfigurationCacheTest extends IntegrationTestKitSpec {
3845
repositories {
3946
mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
4047
gradlePluginPortal() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
48+
mavenLocal()
4149
}
4250
dependencies {
43-
classpath 'com.palantir.baseline:gradle-baseline-java:6.32.0'
51+
classpath 'com.palantir.baseline:gradle-baseline-java:6.3.2'
4452
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.34.0'
4553
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.22.0'
4654
}
4755
}
4856
4957
apply plugin: 'com.palantir.baseline'
5058
apply plugin: 'com.palantir.consistent-versions'
59+
apply plugin: 'com.palantir.baseline-java-versions'
5160
5261
allprojects {
5362
apply plugin: 'com.palantir.java-format'
54-
apply plugin: 'java'
5563
5664
repositories {
5765
mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
@@ -64,22 +72,20 @@ class ConfigurationCacheTest extends IntegrationTestKitSpec {
6472
file("versions.props")
6573
file("versions.lock")
6674

67-
68-
file('gradle.properties') << """
69-
org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
70-
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
71-
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
72-
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
73-
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
74-
palantir.jdk.setup.enabled=true
75-
""".stripIndent(true)
7675
runTasks('wrapper')
7776

78-
when:
79-
def result = runTasks('build')
77+
buildFile << """
78+
dependencies {
79+
palantirJavaFormat files(file("${CLASSPATH_FILE}").text.split(':'))
80+
}
81+
""".stripIndent()
8082

83+
when:
84+
def result = executor.runGradlewTasks('build', '--configuration-cache', '--info')
8185

8286
then:
83-
result.output.contains('BUILD SUCCESSFUL')
87+
assert result.success
88+
println(result.standardOutput)
89+
result.standardOutput.contains('BUILD SUCCESSFUL')
8490
}
85-
}
91+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* (c) Copyright 2025 Palantir Technologies Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.palantir.javaformat.gradle
18+
19+
import nebula.test.functional.internal.classpath.ClasspathAddingInitScriptBuilder
20+
21+
import java.nio.charset.StandardCharsets
22+
import java.nio.file.Path
23+
import java.util.concurrent.TimeUnit
24+
import java.util.stream.Collectors
25+
import java.util.stream.Stream
26+
27+
class GradlewExecutor {
28+
File projectDir
29+
30+
GradlewExecutor(File projectDir) {
31+
this.projectDir = projectDir
32+
}
33+
34+
private static Iterable<File> getBuildPluginClasspathInjector() {
35+
return getPluginClasspathInjector(Path.of("../gradle-palantir-java-format/build/pluginUnderTestMetadata/plugin-under-test-metadata.properties"))
36+
}
37+
38+
private static Iterable<File> getPluginClasspathInjector(Path path) {
39+
File propertiesFile = path.toFile()
40+
Properties properties = new Properties()
41+
propertiesFile.withInputStream { inputStream ->
42+
properties.load(inputStream)
43+
}
44+
String classpath = properties.getProperty('implementation-classpath')
45+
return classpath.split(File.pathSeparator).collect { new File(it) }
46+
}
47+
48+
GradlewExecutionResult runGradlewTasks(String... tasks) {
49+
ProcessBuilder processBuilder = getProcessBuilder(tasks)
50+
Process process = processBuilder.start()
51+
String output = readAllInput(process.getInputStream())
52+
process.waitFor(1, TimeUnit.MINUTES)
53+
GradlewExecutionResult result = new GradlewExecutionResult(process.exitValue(), output)
54+
return result
55+
}
56+
57+
final class GradlewExecutionResult {
58+
59+
final Boolean success
60+
final String standardOutput
61+
final Throwable failure
62+
63+
GradlewExecutionResult(int exitValue, String output) {
64+
this.success = exitValue == 0
65+
this.standardOutput = output
66+
this.failure = exitValue != 0 ? new RuntimeException(String.format("Build failed with exitCode %s", exitValue)) : null
67+
}
68+
}
69+
70+
static String readAllInput(InputStream inputStream) {
71+
try (Stream<String> lines =
72+
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines()) {
73+
return lines.collect(Collectors.joining("\n"));
74+
}
75+
}
76+
77+
private ProcessBuilder getProcessBuilder(String... tasks) {
78+
File initScript = new File(projectDir, "init.gradle")
79+
ClasspathAddingInitScriptBuilder.build(initScript, getBuildPluginClasspathInjector().toList())
80+
List<String> arguments = ["./gradlew", "--init-script", initScript.toPath().toString()]
81+
Arrays.asList(tasks).forEach(arguments::add)
82+
ProcessBuilder processBuilder = new ProcessBuilder()
83+
.command(arguments)
84+
.directory(projectDir)
85+
.redirectErrorStream(true)
86+
return processBuilder
87+
}
88+
89+
}

gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatSpotlessPluginTest.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class PalantirJavaFormatSpotlessPluginTest extends IntegrationTestKitSpec {
3434
@Unroll
3535
def "formats with spotless when spotless is applied"(String extraGradleProperties, String javaVersion, String expectedOutput) {
3636
def extraDependencies = extraGradleProperties.isEmpty() ? "" : NATIVE_CONFIG
37+
38+
// language=Gradle
3739
settingsFile << """
3840
buildscript {
3941
repositories {
@@ -47,6 +49,7 @@ class PalantirJavaFormatSpotlessPluginTest extends IntegrationTestKitSpec {
4749
apply plugin: 'com.palantir.jdks.settings'
4850
""".stripIndent(true)
4951

52+
// language=Gradle
5053
buildFile << """
5154
buildscript {
5255
repositories {

0 commit comments

Comments
 (0)