Skip to content

Commit 1bb69e7

Browse files
authored
Fix nativeImageClassPath for Intellij configuration (palantir#1217)
Fix nativeImageClassPath for Intellij configuration
1 parent b131bfa commit 1bb69e7

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: fix
2+
fix:
3+
description: Fix nativeImageClassPath for Intellij configuration
4+
links:
5+
- https://github.com/palantir/palantir-java-format/pull/1217

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ class ConfigureJavaFormatterXml {
3030
listItems.appendNode('option', [value: uri])
3131
}
3232
// configure nativeImageClasspath
33-
nativeImageUri.ifPresent { URI uri ->
33+
nativeImageUri.ifPresentOrElse({ URI uri ->
3434
matchOrCreateChild(settings, 'option', [name: 'nativeImageClassPath']).attributes().put('value', uri)
35-
}
35+
}, {
36+
matchChild(settings, 'option', [name: 'nativeImageClassPath']).ifPresent { it.parent().remove(it) }
37+
})
3638
}
3739

3840
static void configureExternalDependencies(Node rootNode) {

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ConfigureJavaFormatterXmlTest extends Specification {
3131
<option value="aldfjh://barz" />
3232
</list>
3333
</option>
34+
<option name="nativeImageClassPath" value="nativeFoo"/>
3435
</component>
3536
</root>
3637
""".stripIndent()
@@ -62,6 +63,21 @@ class ConfigureJavaFormatterXmlTest extends Specification {
6263
</component>
6364
</root>
6465
""".stripIndent()
66+
67+
public static final String EXPECTED_WITHOUT_NATIVE = """\
68+
<root>
69+
<component name="PalantirJavaFormatSettings">
70+
<option name="enabled" value="true"/>
71+
<option name="implementationClassPath">
72+
<list>
73+
<option value="foo"/>
74+
<option value="bar"/>
75+
</list>
76+
</option>
77+
</component>
78+
</root>
79+
""".stripIndent()
80+
6581
public static final ArrayList<String> ACTIONS_ON_SAVE = ['Format', 'Optimize']
6682

6783
void testConfigure_missingEntireBlock_added() {
@@ -108,6 +124,16 @@ class ConfigureJavaFormatterXmlTest extends Specification {
108124
xmlToString(node) == EXPECTED
109125
}
110126

127+
void testConfigure_noNativeImageClassPath_removal() {
128+
def node = new XmlParser().parseText(EXISTING_CLASS_PATH)
129+
130+
when:
131+
ConfigureJavaFormatterXml.configureJavaFormat(node, ['foo', 'bar'].collect { URI.create(it) }, Optional.empty())
132+
133+
then:
134+
xmlToString(node) == EXPECTED_WITHOUT_NATIVE
135+
}
136+
111137
@Unroll
112138
void 'adds #action OnSave block where none exists'(action) {
113139
// language=xml

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class PalantirJavaFormatPluginTest extends IntegrationTestKitSpec {
7171
class Main {
7272
public static void crazyExistingFormatting ( String... args) {
7373
System.out.println("Reformat me please");
74+
// some comments
75+
System.out.println("Reformat me again please");
7476
}
7577
}
7678
'''.stripIndent()
@@ -84,6 +86,8 @@ class PalantirJavaFormatPluginTest extends IntegrationTestKitSpec {
8486
class Main {
8587
public static void crazyExistingFormatting ( String... args) {
8688
System.out.println("Reformat me please");
89+
// some comments
90+
System.out.println("Reformat me again please");
8791
}
8892
}
8993
'''.stripIndent()

0 commit comments

Comments
 (0)