-
Notifications
You must be signed in to change notification settings - Fork 43
/
PalantirJavaFormatPluginTest.groovy
84 lines (71 loc) · 3.07 KB
/
PalantirJavaFormatPluginTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.palantir.javaformat.gradle
import nebula.test.IntegrationTestKitSpec
class PalantirJavaFormatPluginTest extends IntegrationTestKitSpec {
/** ./gradlew writeImplClasspath generates this file. */
private static final CLASSPATH_FILE = new File("build/impl.classpath").absolutePath
void setup() {
buildFile << """
plugins {
id 'java'
id 'com.palantir.java-format'
}
dependencies {
palantirJavaFormat files(file("${CLASSPATH_FILE}").text.split(':'))
}
apply plugin: 'idea'
""".stripIndent()
// Add jvm args to allow spotless and formatter gradle plugins to run with Java 16+
file('gradle.properties') << """
org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
""".stripIndent()
}
def 'formatDiff updates only lines changed in git diff'() {
when:
"git init".execute(Collections.emptyList(), projectDir).waitFor()
"git config user.name Foo".execute(Collections.emptyList(), projectDir).waitFor()
"git config user.email foo@bar.com".execute(Collections.emptyList(), projectDir).waitFor()
file('src/main/java/Main.java') << '''
class Main {
public static void crazyExistingFormatting ( String... args) {
}
}
'''.stripIndent()
"git add .".execute(Collections.emptyList(), projectDir).waitFor()
"git commit -m Commit".execute(Collections.emptyList(), projectDir).waitFor()
file('src/main/java/Main.java').text = '''
class Main {
public static void crazyExistingFormatting ( String... args) {
System.out.println("Reformat me please");
}
}
'''.stripIndent()
then:
runTasks('formatDiff')
file('src/main/java/Main.java').text == '''
class Main {
public static void crazyExistingFormatting ( String... args) {
System.out.println("Reformat me please");
}
}
'''.stripIndent()
}
}