Skip to content

Commit cfb87f7

Browse files
committed
Merge master into release/1.15.x
Conflicts: pom.xml src/changes/changes.xml src/main/resources/de/funfried/netbeans/plugins/external/formatter/Bundle.properties
2 parents 732ab99 + 9c4704f commit cfb87f7

29 files changed

Lines changed: 837 additions & 396 deletions

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This plugin helps you to apply to a common code style in a team of Eclipse,
2020
IntelliJ and NetBeans IDE users. You can use several external code formatters
2121
inside the NetBeans IDE (see below), depending on whatever your co-workers use.
2222
The original formatting engine of Eclipse, the Google Code Formatter, the Spring
23-
Java Formatter or any other are embedded and allow you to format the source code
23+
Java Formatter and others are embedded and allow you to format the source code
2424
the same way as e.g. your co-workers do with their Eclipse IDE.
2525

2626
![Global settings](/src/site/resources/imgs/global.png)
@@ -106,4 +106,7 @@ The history of this project
106106

107107
Support
108108
---------
109-
Keep this project alive by supporting it: one-time [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=926F5XBCTK2LQ&source=url) or [![Patreon!](/src/site/resources/imgs/logos/become_a_patron_button.png)](https://www.patreon.com/funfried) or just [![Buy me a drink](https://img.buymeacoffee.com/button-api/?text=Buy%20me%20a%20drink&emoji=%F0%9F%A5%83&slug=funfried&button_colour=5F7FFF&font_colour=ffffff&font_family=Cookie&outline_colour=000000&coffee_colour=FFDD00)](https://www.buymeacoffee.com/funfried)
109+
Keep this project alive by supporting it:
110+
one-time [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=926F5XBCTK2LQ&source=url) or [![Patreon!](/src/site/resources/imgs/logos/become_a_patron_button.png)](https://www.patreon.com/funfried) or just [![Buy me a drink](https://img.buymeacoffee.com/button-api/?text=Buy%20me%20a%20drink&emoji=%F0%9F%A5%83&slug=funfried&button_colour=5F7FFF&font_colour=ffffff&font_family=Cookie&outline_colour=000000&coffee_colour=FFDD00)](https://www.buymeacoffee.com/funfried)
111+
112+
If you can't or don't want to spend money you can also [![say thanks](https://img.shields.io/static/v1?label=say&message=thanks&color=green&style=for-the-badge&logo=handshake)](https://saythanks.io/to/funfried)

nb-configuration.xml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
-->
99
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
1010
<!--
11-
Properties that influence various parts of the IDE, especially code formatting and the like.
11+
Properties that influence various parts of the IDE, especially code formatting and the like.
1212
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
1313
That way multiple projects can share the same settings (useful for formatting rules for example).
1414
Any value defined here will override the pom.xml file value but is only applicable to the current project.
1515
-->
1616
<netbeans.hint.licensePath>${project.basedir}/licenseheader.txt</netbeans.hint.licensePath>
1717
<de-funfried-netbeans-plugins-externalcodeformatter.overrideTabSizeValue>4</de-funfried-netbeans-plugins-externalcodeformatter.overrideTabSizeValue>
18-
<de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_JSON>netbeans-formatter</de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_JSON>
19-
<de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_XML>netbeans-formatter</de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_XML>
18+
<de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_JSON>jackson-json-formatter</de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_JSON>
2019
<de-funfried-netbeans-plugins-externalcodeformatter.eclipseFormatterActiveProfile>EclipseCodeFormatterForNetBeans</de-funfried-netbeans-plugins-externalcodeformatter.eclipseFormatterActiveProfile>
2120
<de-funfried-netbeans-plugins-externalcodeformatter.useProjectPref>true</de-funfried-netbeans-plugins-externalcodeformatter.useProjectPref>
2221
<de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_JAVA>eclipse-java-formatter</de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_JAVA>
@@ -26,7 +25,22 @@
2625
<de-funfried-netbeans-plugins-externalcodeformatter.useProjectSettings>true</de-funfried-netbeans-plugins-externalcodeformatter.useProjectSettings>
2726
<de-funfried-netbeans-plugins-externalcodeformatter.enableIndentationSettings>true</de-funfried-netbeans-plugins-externalcodeformatter.enableIndentationSettings>
2827
<de-funfried-netbeans-plugins-externalcodeformatter.linefeed/>
29-
<de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_JAVASCRIPT>netbeans-formatter</de-funfried-netbeans-plugins-externalcodeformatter.enabledFormatter_2e_JAVASCRIPT>
3028
<de-funfried-netbeans-plugins-externalcodeformatter.overrideTabSize>true</de-funfried-netbeans-plugins-externalcodeformatter.overrideTabSize>
29+
<de-funfried-netbeans-plugins-externalcodeformatter.jsoupXmlLinefeed/>
30+
<de-funfried-netbeans-plugins-externalcodeformatter.jsoupXmlIndentSize>2</de-funfried-netbeans-plugins-externalcodeformatter.jsoupXmlIndentSize>
31+
<de-funfried-netbeans-plugins-externalcodeformatter.jsoupXmlPrettyPrint>true</de-funfried-netbeans-plugins-externalcodeformatter.jsoupXmlPrettyPrint>
32+
<de-funfried-netbeans-plugins-externalcodeformatter.jsoupXmlOutline>false</de-funfried-netbeans-plugins-externalcodeformatter.jsoupXmlOutline>
33+
<de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlSplitMultiAttrs>false</de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlSplitMultiAttrs>
34+
<de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlWellFormedValidation>WARN</de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlWellFormedValidation>
35+
<de-funfried-netbeans-plugins-externalcodeformatter.jacksonJsonIndentSize>4</de-funfried-netbeans-plugins-externalcodeformatter.jacksonJsonIndentSize>
36+
<de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlTabWidth>4</de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlTabWidth>
37+
<de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlMaxLineLength>120</de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlMaxLineLength>
38+
<de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlTabInsteadOfSpaces>true</de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlTabInsteadOfSpaces>
39+
<de-funfried-netbeans-plugins-externalcodeformatter.jacksonJsonSpaceBeforeSeparator>false</de-funfried-netbeans-plugins-externalcodeformatter.jacksonJsonSpaceBeforeSeparator>
40+
<de-funfried-netbeans-plugins-externalcodeformatter.jacksonJsonSpacesPerTab>4</de-funfried-netbeans-plugins-externalcodeformatter.jacksonJsonSpacesPerTab>
41+
<de-funfried-netbeans-plugins-externalcodeformatter.jacksonJsonLinefeed/>
42+
<de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlLinefeed/>
43+
<de-funfried-netbeans-plugins-externalcodeformatter.jacksonJsonExpandTabsToSpaces>false</de-funfried-netbeans-plugins-externalcodeformatter.jacksonJsonExpandTabsToSpaces>
44+
<de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlWrapLongLines>false</de-funfried-netbeans-plugins-externalcodeformatter.revelcXmlWrapLongLines>
3145
</properties>
3246
</project-shared-configuration>

pom.xml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@
113113
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
114114
<project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
115115
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
116-
<google-java-format.version>1.13.0</google-java-format.version>
116+
<google-java-format.version>1.14.0</google-java-format.version>
117117
<xml-formatter.version>0.2.2</xml-formatter.version>
118118
<commons-lang.version>3.12.0</commons-lang.version>
119119
<netbeans.version>RELEASE120</netbeans.version>
120120
<jackson.version>2.13.1</jackson.version>
121121
<jsoup.version>1.14.3</jsoup.version>
122+
<argLine></argLine>
122123
</properties>
123124

124125
<dependencies>
@@ -165,7 +166,7 @@
165166
<dependency>
166167
<groupId>io.spring.javaformat</groupId>
167168
<artifactId>spring-javaformat-formatter</artifactId>
168-
<version>0.0.29</version>
169+
<version>0.0.31</version>
169170
</dependency>
170171

171172
<!-- Google Formatter -->
@@ -179,13 +180,13 @@
179180
<dependency>
180181
<groupId>com.palantir.javaformat</groupId>
181182
<artifactId>palantir-java-format</artifactId>
182-
<version>2.16.0</version>
183+
<version>2.17.0</version>
183184
</dependency>
184185

185186
<dependency>
186187
<groupId>com.palantir.javaformat</groupId>
187188
<artifactId>palantir-java-format-spi</artifactId>
188-
<version>2.16.0</version>
189+
<version>2.17.0</version>
189190
<exclusions>
190191
<exclusion>
191192
<groupId>com.fasterxml.jackson.core</groupId>
@@ -198,7 +199,7 @@
198199
<dependency>
199200
<groupId>com.diffplug.spotless</groupId>
200201
<artifactId>spotless-lib</artifactId>
201-
<version>2.22.0</version>
202+
<version>2.22.2</version>
202203
</dependency>
203204

204205
<!-- XML Formatter -->
@@ -432,7 +433,7 @@
432433
<plugin>
433434
<groupId>org.apache.maven.plugins</groupId>
434435
<artifactId>maven-compiler-plugin</artifactId>
435-
<version>3.9.0</version>
436+
<version>3.10.0</version>
436437
</plugin>
437438
<plugin>
438439
<groupId>org.apache.maven.plugins</groupId>
@@ -472,7 +473,7 @@
472473
<plugin>
473474
<groupId>org.sonatype.plugins</groupId>
474475
<artifactId>nexus-staging-maven-plugin</artifactId>
475-
<version>1.6.8</version>
476+
<version>1.6.10</version>
476477
<configuration>
477478
<serverId>sonatype-nexus-staging</serverId>
478479
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
@@ -527,12 +528,12 @@
527528
<plugin>
528529
<groupId>org.apache.maven.plugins</groupId>
529530
<artifactId>maven-project-info-reports-plugin</artifactId>
530-
<version>3.1.2</version>
531+
<version>3.2.1</version>
531532
</plugin>
532533
<plugin>
533534
<groupId>org.apache.maven.plugins</groupId>
534535
<artifactId>maven-javadoc-plugin</artifactId>
535-
<version>3.3.1</version>
536+
<version>3.3.2</version>
536537
<configuration>
537538
<quiet>true</quiet>
538539
<doclint>all,-missing</doclint>
@@ -559,7 +560,7 @@
559560
<plugin>
560561
<groupId>org.codehaus.mojo</groupId>
561562
<artifactId>versions-maven-plugin</artifactId>
562-
<version>2.8.1</version>
563+
<version>2.9.0</version>
563564
</plugin>
564565
<plugin>
565566
<groupId>org.codehaus.mojo</groupId>
@@ -587,7 +588,7 @@
587588
<plugin>
588589
<groupId>org.apache.maven.plugins</groupId>
589590
<artifactId>maven-surefire-plugin</artifactId>
590-
<version>2.22.2</version>
591+
<version>3.0.0-M5</version>
591592
</plugin>
592593
<plugin>
593594
<groupId>org.apache.maven.plugins</groupId>
@@ -636,7 +637,7 @@
636637
<plugin>
637638
<groupId>org.sonatype.ossindex.maven</groupId>
638639
<artifactId>ossindex-maven-plugin</artifactId>
639-
<version>3.1.0</version>
640+
<version>3.2.0</version>
640641
</plugin>
641642
</plugins>
642643
</pluginManagement>
@@ -751,8 +752,10 @@
751752
<groupId>org.apache.maven.plugins</groupId>
752753
<artifactId>maven-surefire-plugin</artifactId>
753754
<configuration>
755+
<forkCount>3</forkCount>
756+
<reuseForks>true</reuseForks>
754757
<argLine>
755-
${argLine} -Xmx1024m
758+
@{argLine} -Xmx1024m
756759
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
757760
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
758761
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED

src/changes/changes.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<document xmlns="http://maven.apache.org/changes/1.0.0"
23
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
34
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/xsd/changes-1.0.0.xsd">
@@ -14,6 +15,27 @@
1415
</action>
1516
</release>
1617

18+
<release version="1.14.5" date="2022-02-24" description="Bug fix release">
19+
<action dev="bahlef" type="fix">
20+
Fixed editor issues when using revelc.net XML formatter
21+
</action>
22+
<action dev="bahlef" type="fix">
23+
Fixed editor behavior when using JSoup XML formatter
24+
</action>
25+
<action dev="bahlef" type="fix">
26+
Fixed usage of JSON formatters
27+
</action>
28+
</release>
29+
30+
<release version="1.14.4" date="2022-02-07" description="Bug fix release">
31+
<action dev="bahlef" type="fix" issue="191">
32+
Erroneous formatting with Eclipse when "Override Tab Size" is active
33+
</action>
34+
<action dev="bahlef" type="fix" issue="190">
35+
Fixed issue in Google formatter when there were blank lines at the end of the Java file
36+
</action>
37+
</release>
38+
1739
<release version="1.14.3" date="2022-01-22" description="Bug fix release">
1840
<action dev="bahlef" type="fix" issue="152">
1941
Erroneous formatting with Eclipse

src/main/java/de/funfried/netbeans/plugins/external/formatter/AbstractFormatJob.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import javax.swing.text.StyledDocument;
2121

2222
import org.apache.commons.collections4.CollectionUtils;
23-
import org.apache.commons.lang3.StringUtils;
2423
import org.apache.commons.lang3.mutable.MutableInt;
2524
import org.apache.commons.lang3.tuple.Pair;
2625
import org.netbeans.api.annotations.common.NonNull;
@@ -154,7 +153,15 @@ protected boolean setFormattedCode(String code, String formattedContent) throws
154153
* @return The content of the {@code document}
155154
*/
156155
protected String getCode() {
157-
return StringUtils.trim(DocumentUtilities.getText(document).toString());
156+
try {
157+
// returns the actual content of the document
158+
return document.getText(0, document.getLength());
159+
} catch (BadLocationException ex) {
160+
log.log(Level.WARNING, "Could not fetch text, falling back to utility method", ex);
161+
162+
// returns only the trimmed content of the document
163+
return DocumentUtilities.getText(document).toString();
164+
}
158165
}
159166

160167
/**

src/main/java/de/funfried/netbeans/plugins/external/formatter/java/eclipse/EclipseJavaFormatterService.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public Integer getContinuationIndentSize(Document document) {
9595

9696
Integer indentSize = getIndentSize(document);
9797
if (indentSize != null) {
98-
ret = Integer.valueOf(value) * indentSize;
98+
ret *= indentSize;
9999
}
100100
}
101101
}
@@ -117,17 +117,14 @@ public Integer getIndentSize(Document document) {
117117

118118
Preferences preferences = Settings.getActivePreferences(document);
119119
if (isUseFormatterIndentationSettings(preferences)) {
120-
String value;
121-
122120
String tabChar = getEclipseFormatterProperty(preferences, document, "org.eclipse.jdt.core.formatter.tabulation.char");
123121
if (Objects.equals(tabChar, "mixed")) {
124-
value = getEclipseFormatterProperty(preferences, document, "org.eclipse.jdt.core.formatter.indentation.size");
122+
String value = getEclipseFormatterProperty(preferences, document, "org.eclipse.jdt.core.formatter.indentation.size");
123+
if (value != null) {
124+
ret = Integer.valueOf(value);
125+
}
125126
} else {
126-
value = getEclipseFormatterProperty(preferences, document, "org.eclipse.jdt.core.formatter.tabulation.size");
127-
}
128-
129-
if (value != null) {
130-
ret = Integer.valueOf(value);
127+
ret = getSpacesPerTab(document);
131128
}
132129
}
133130

src/main/java/de/funfried/netbeans/plugins/external/formatter/java/google/GoogleJavaFormatterWrapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public final class GoogleJavaFormatterWrapper {
4040
* Formats the given {@code code} with the given configurations and returns
4141
* the formatted code.
4242
*
43-
* @param code the unformatted code
44-
* @param codeStyle the code {@link JavaFormatterOptions.Style} to use,
45-
* if {@code null} the {@link JavaFormatterOptions.Style#GOOGLE}
46-
* style will be used
43+
* @param code the unformatted code
44+
* @param codeStyle the code {@link JavaFormatterOptions.Style} to use,
45+
* if {@code null} the {@link JavaFormatterOptions.Style#GOOGLE}
46+
* style will be used
4747
* @param changedElements a {@link SortedSet} containing ranges as {@link Pair}
48-
* objects defining the offsets which should be formatted
48+
* objects defining the offsets which should be formatted
4949
*
5050
* @return the formatted code
5151
*

src/main/java/de/funfried/netbeans/plugins/external/formatter/java/spring/SpringJavaFormatterService.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import de.funfried.netbeans.plugins.external.formatter.java.spring.ui.SpringJavaFormatterOptionsPanel;
3535
import de.funfried.netbeans.plugins.external.formatter.ui.options.FormatterOptionsPanel;
3636
import de.funfried.netbeans.plugins.external.formatter.ui.options.Settings;
37-
import io.spring.javaformat.formatter.Formatter;
37+
import io.spring.javaformat.formatter.eclipse.EclipseCodeFormatter;
3838

3939
/**
4040
* Spring implementation of the {@link AbstractJavaFormatterService}.
@@ -95,11 +95,16 @@ public Integer getContinuationIndentSize(Document document) {
9595

9696
Preferences preferences = Settings.getActivePreferences(document);
9797
if (isUseFormatterIndentationSettings(preferences)) {
98-
String propKey = "org.eclipse.jdt.core.formatter.continuation_indentation";
98+
String propKey = "core.formatter.continuation_indentation";
9999
String prop = this.getSpringFormatterProperty(propKey);
100100
if (prop != null) {
101101
try {
102102
ret = Integer.parseInt(prop);
103+
104+
Integer indentSize = getIndentSize(document);
105+
if (indentSize != null) {
106+
ret *= indentSize;
107+
}
103108
} catch (NumberFormatException ex) {
104109
log.log(Level.WARNING, "Property '" + propKey + "' is not an integer: " + prop, ex);
105110
}
@@ -127,14 +132,19 @@ public Integer getIndentSize(Document document) {
127132

128133
Preferences preferences = Settings.getActivePreferences(document);
129134
if (isUseFormatterIndentationSettings(preferences)) {
130-
String propKey = "org.eclipse.jdt.core.formatter.indentation.size";
131-
String prop = this.getSpringFormatterProperty(propKey);
132-
if (prop != null) {
133-
try {
134-
ret = Integer.parseInt(prop);
135-
} catch (NumberFormatException ex) {
136-
log.log(Level.WARNING, "Property '" + propKey + "' is not an integer: " + prop, ex);
135+
String tabChar = getSpringFormatterProperty("core.formatter.tabulation.char");
136+
if (Objects.equals(tabChar, "mixed")) {
137+
String propKey = "core.formatter.indentation.size";
138+
String prop = this.getSpringFormatterProperty(propKey);
139+
if (prop != null) {
140+
try {
141+
ret = Integer.parseInt(prop);
142+
} catch (NumberFormatException ex) {
143+
log.log(Level.WARNING, "Property '" + propKey + "' is not an integer: " + prop, ex);
144+
}
137145
}
146+
} else {
147+
ret = getSpacesPerTab(document);
138148
}
139149

140150
if (ret == null) {
@@ -157,7 +167,7 @@ public Integer getRightMargin(Document document) {
157167

158168
Integer ret = 120;
159169

160-
String propKey = "org.eclipse.jdt.core.formatter.lineSplit";
170+
String propKey = "core.formatter.lineSplit";
161171
String prop = this.getSpringFormatterProperty(propKey);
162172
if (prop != null) {
163173
try {
@@ -195,7 +205,7 @@ public Integer getSpacesPerTab(Document document) {
195205
if (preferences.getBoolean(Settings.OVERRIDE_TAB_SIZE, true)) {
196206
ret = preferences.getInt(Settings.OVERRIDE_TAB_SIZE_VALUE, 4);
197207
} else {
198-
String propKey = "org.eclipse.jdt.core.formatter.tabulation.size";
208+
String propKey = "core.formatter.tabulation.size";
199209
String prop = this.getSpringFormatterProperty(propKey);
200210
if (prop != null) {
201211
try {
@@ -225,7 +235,7 @@ public Integer getSpacesPerTab(Document document) {
225235
*/
226236
private String getSpringFormatterProperty(String key) {
227237
Properties props = new Properties();
228-
try (InputStream is = Formatter.class.getResourceAsStream("formatter.prefs")) {
238+
try (InputStream is = EclipseCodeFormatter.class.getResourceAsStream("formatter.prefs")) {
229239
props.load(is);
230240
} catch (IOException ex) {
231241
log.log(Level.SEVERE, "Could not read internal Spring formatter configuration", ex);
@@ -248,7 +258,7 @@ public Boolean isExpandTabToSpaces(Document document) {
248258

249259
Preferences preferences = Settings.getActivePreferences(document);
250260
if (isUseFormatterIndentationSettings(preferences)) {
251-
String propKey = "org.eclipse.jdt.core.formatter.tabulation.size";
261+
String propKey = "core.formatter.tabulation.char";
252262
String prop = this.getSpringFormatterProperty(propKey);
253263
if (prop != null) {
254264
ret = Objects.equals(prop, "space");

0 commit comments

Comments
 (0)