2525import java .io .StringWriter ;
2626import java .net .URI ;
2727import java .util .List ;
28- import java .util .Optional ;
2928import java .util .stream .Stream ;
3029import org .intellij .lang .annotations .Language ;
3130import org .junit .jupiter .api .Test ;
@@ -68,22 +67,6 @@ final class ConfigureJavaFormatterXmlTest {
6867
6968 @ Language ("xml" )
7069 private static final String EXPECTED = """
71- <root>
72- <component name="PalantirJavaFormatSettings">
73- <option name="enabled" value="true"/>
74- <option name="implementationClassPath">
75- <list>
76- <option value="foo"/>
77- <option value="bar"/>
78- </list>
79- </option>
80- <option name="nativeImageClassPath" value="nativeFoo"/>
81- </component>
82- </root>
83- """ ;
84-
85- @ Language ("xml" )
86- private static final String EXPECTED_WITHOUT_NATIVE = """
8770 <root>
8871 <component name="PalantirJavaFormatSettings">
8972 <option name="enabled" value="true"/>
@@ -105,8 +88,7 @@ static Stream<String> actionsOnSave() {
10588 void configure_missingEntireBlock_added () {
10689 Node node = parseXml (MISSING_ENTIRE_BLOCK );
10790
108- ConfigureJavaFormatterXml .configureJavaFormat (
109- node , List .of (URI .create ("foo" ), URI .create ("bar" )), Optional .of (URI .create ("nativeFoo" )));
91+ ConfigureJavaFormatterXml .configureJavaFormat (node , List .of (URI .create ("foo" ), URI .create ("bar" )));
11092
11193 assertThat (xmlToString (node )).isEqualTo (EXPECTED );
11294 }
@@ -115,8 +97,7 @@ void configure_missingEntireBlock_added() {
11597 void configure_missingClassPath_added () {
11698 Node node = parseXml (MISSING_CLASS_PATH );
11799
118- ConfigureJavaFormatterXml .configureJavaFormat (
119- node , List .of (URI .create ("foo" ), URI .create ("bar" )), Optional .of (URI .create ("nativeFoo" )));
100+ ConfigureJavaFormatterXml .configureJavaFormat (node , List .of (URI .create ("foo" ), URI .create ("bar" )));
120101
121102 String expected = """
122103 <root>
@@ -129,7 +110,6 @@ void configure_missingClassPath_added() {
129110 <option value="bar"/>
130111 </list>
131112 </option>
132- <option name="nativeImageClassPath" value="nativeFoo"/>
133113 </component>
134114 </root>
135115 """ ;
@@ -138,23 +118,32 @@ void configure_missingClassPath_added() {
138118 }
139119
140120 @ Test
141- void configure_existingClassPath_modified () {
121+ void configure_existingClassPath_modified_andTheNativeImageOfEarlierVersionsRemoved () {
122+ // Up to 21.0.1 the plugin wrote nativeImageClassPath for openjavaformat.native.formatter=true. The IDE plugin
123+ // switches the native binary on by a setting of its own now, and no longer reads it.
142124 Node node = parseXml (EXISTING_CLASS_PATH );
143125
144- ConfigureJavaFormatterXml .configureJavaFormat (
145- node , List .of (URI .create ("foo" ), URI .create ("bar" )), Optional .of (URI .create ("nativeFoo" )));
126+ ConfigureJavaFormatterXml .configureJavaFormat (node , List .of (URI .create ("foo" ), URI .create ("bar" )));
146127
147128 assertThat (xmlToString (node )).isEqualTo (EXPECTED );
148129 }
149130
150131 @ Test
151- void configure_noNativeImageClassPath_removal () {
152- Node node = parseXml (EXISTING_CLASS_PATH );
132+ void configure_leavesTheIdePluginsNativeBinarySettingsAlone () {
133+ Node node = parseXml ("""
134+ <root>
135+ <component name="PalantirJavaFormatSettings">
136+ <option name="useNativeImage" value="true"/>
137+ <option name="nativeImagePath" value="/opt/open-java-format"/>
138+ </component>
139+ </root>
140+ """ );
153141
154- ConfigureJavaFormatterXml .configureJavaFormat (
155- node , List .of (URI .create ("foo" ), URI .create ("bar" )), Optional .empty ());
142+ ConfigureJavaFormatterXml .configureJavaFormat (node , List .of (URI .create ("foo" )));
156143
157- assertThat (xmlToString (node )).isEqualTo (EXPECTED_WITHOUT_NATIVE );
144+ assertThat (xmlToString (node ))
145+ .contains ("<option name=\" useNativeImage\" value=\" true\" />" )
146+ .contains ("<option name=\" nativeImagePath\" value=\" /opt/open-java-format\" />" );
158147 }
159148
160149 @ ParameterizedTest
0 commit comments