diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index 163816c1a4..3782167343 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.extra.glue.groovy; +import static java.lang.System.lineSeparator; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -143,7 +145,7 @@ public String toString() { } for (Throwable error : errors) { error.printStackTrace(); - string.append(System.lineSeparator()); + string.append(lineSeparator()); string.append(error.getMessage()); } diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index 3e8339644a..de8105ac56 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package com.diffplug.spotless; +import static java.lang.System.lineSeparator; + import java.io.File; import java.util.Arrays; import java.util.Comparator; @@ -255,7 +257,7 @@ private String buildUpgradeFormatterMessage(V fmtVersion) { public String toString() { return String.format("%s alternatives:%n", fmtName) + jvm2fmtMaxVersion.entrySet().stream().map( - e -> String.format("- Version %s requires JVM %d+", e.getValue(), e.getKey())).collect(Collectors.joining(System.lineSeparator())); + e -> String.format("- Version %s requires JVM %d+", e.getValue(), e.getKey())).collect(Collectors.joining(lineSeparator())); } @SuppressFBWarnings("SE_COMPARATOR_SHOULD_BE_SERIALIZABLE") diff --git a/lib/src/main/java/com/diffplug/spotless/LineEnding.java b/lib/src/main/java/com/diffplug/spotless/LineEnding.java index 5b44b81889..e3e258ddd4 100644 --- a/lib/src/main/java/com/diffplug/spotless/LineEnding.java +++ b/lib/src/main/java/com/diffplug/spotless/LineEnding.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package com.diffplug.spotless; +import static java.lang.System.lineSeparator; + import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -151,7 +153,7 @@ static String getEndingFor(Reader reader) throws IOException { private static final Policy UNIX_POLICY = new ConstantLineEndingPolicy(UNIX.str()); private static final Policy MAC_CLASSIC_POLICY = new ConstantLineEndingPolicy(MAC_CLASSIC.str()); private static final Policy PRESERVE_POLICY = new PreserveLineEndingPolicy(); - private static final String _platformNative = System.getProperty("line.separator"); + private static final String _platformNative = lineSeparator(); private static final Policy _platformNativePolicy = new ConstantLineEndingPolicy(_platformNative); private static final boolean nativeIsWin = _platformNative.equals(WINDOWS.str()); diff --git a/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java b/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java index 6dc3185ef6..87efb30cdb 100644 --- a/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 DiffPlug + * Copyright 2023-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.groovy; +import static java.lang.System.lineSeparator; + import java.io.BufferedReader; import java.io.Serializable; import java.io.StringReader; @@ -51,7 +53,7 @@ FormatterFunc toFormatter() { String line; while ((line = reader.readLine()) != null) { result.append(removeSemicolon(line)); - result.append(System.lineSeparator()); + result.append(lineSeparator()); } return result.toString(); } diff --git a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java index 08a0308178..f4b87983fd 100644 --- a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java +++ b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2024 DiffPlug + * Copyright 2021-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.pom; +import static java.lang.System.lineSeparator; + import java.io.Serializable; // Class and members must be public, otherwise we get failed to access class com.diffplug.spotless.pom.SortPomInternalState from class com.diffplug.spotless.pom.SortPomFormatterFunc (com.diffplug.spotless.pom.SortPomInternalState is in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @682bd3c4; com.diffplug.spotless.pom.SortPomFormatterFunc is in unnamed module of loader com.diffplug.spotless.pom.DelegatingClassLoader @573284a5) @@ -25,7 +27,7 @@ public class SortPomCfg implements Serializable { public String encoding = "UTF-8"; - public String lineSeparator = System.getProperty("line.separator"); + public String lineSeparator = lineSeparator(); public boolean expandEmptyElements = true; diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java index 01f0fd759e..645200c7ee 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.sql.dbeaver; +import static java.lang.System.lineSeparator; + import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -67,7 +69,7 @@ public String format(final String argSql) { } if (isSqlEndsWithNewLine) { - after.append(getDefaultLineSeparator()); + after.append(lineSeparator()); } return after.toString(); @@ -388,15 +390,11 @@ private boolean isFunction(String name) { return sqlDialect.getKeywordType(name) == DBPKeywordType.FUNCTION; } - private static String getDefaultLineSeparator() { - return System.getProperty("line.separator", "\n"); - } - private int insertReturnAndIndent(final List argList, final int argIndex, final int argIndent) { if (functionBracket.contains(Boolean.TRUE)) return 0; try { - final String defaultLineSeparator = getDefaultLineSeparator(); + final String defaultLineSeparator = lineSeparator(); StringBuilder s = new StringBuilder(defaultLineSeparator); for (int index = 0; index < argIndent; index++) { s.append(formatterCfg.getIndentString());