Skip to content

Commit

Permalink
Merge branch 'main' into feat/prepare-for-lint-take-2
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Oct 15, 2024
2 parents 33444a7 + 7aac080 commit e1a9acb
Show file tree
Hide file tree
Showing 131 changed files with 9,415 additions and 765 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/changelog-print.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ jobs:
java-version: 11
distribution: 'temurin'
- name: gradle caching
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
uses: gradle/actions/setup-gradle@v4
- run: ./gradlew changelogPrint
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ jobs:
distribution: "temurin"
java-version: 11
- name: gradle caching
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
uses: gradle/actions/setup-gradle@v4
- name: spotlessCheck
run: ./gradlew spotlessCheck
- name: assemble testClasses
Expand All @@ -43,7 +41,7 @@ jobs:
matrix:
kind: [maven, gradle]
# Test on the latest Java version once Gradle & Maven support it.
jre: [11, 17, 21]
jre: [11, 17, 21, 22]
os: [ubuntu-latest]
include:
# test windows at the diagonals of the above matrix
Expand Down Expand Up @@ -71,9 +69,7 @@ jobs:
distribution: "temurin"
java-version: ${{ matrix.jre }}
- name: gradle caching
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
uses: gradle/actions/setup-gradle@v4
- name: build (maven-only)
if: matrix.kind == 'maven'
run: ./gradlew :plugin-maven:build -x spotlessCheck
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# GH_TOKEN
# NEXUS_USER
# NEXUS_PASS64 (base64 NOTE: `base64` and `openssl base64` failed, had to use Java
# byte[] data = "{{password}}".getBytes(StandardCharsets.UTF_8);
Expand Down Expand Up @@ -29,8 +28,10 @@ jobs:
build:
runs-on: ubuntu-latest
name: deploy
permissions:
contents: write
env:
gh_token: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORG_GRADLE_PROJECT_nexus_user: ${{ secrets.NEXUS_USER }}
ORG_GRADLE_PROJECT_nexus_pass64: ${{ secrets.NEXUS_PASS64 }}
ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
Expand All @@ -43,9 +44,7 @@ jobs:
java-version: 11
distribution: 'temurin'
- name: gradle caching
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
uses: gradle/actions/setup-gradle@v4
- name: git fetch origin main
run: git fetch origin main
- name: publish all
Expand Down
91 changes: 65 additions & 26 deletions CHANGES.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ concerning what you are working on:

```shell
# Run only from test from the "lib" project
gradlew :testlib:test --tests com.diffplug.spotless.generic.IndentStepTest
./gradlew :testlib:test --tests com.diffplug.spotless.generic.IndentStepTest

# Run only one test from the "plugin-maven" project
gradlew :plugin-maven:test --tests com.diffplug.spotless.maven.pom.SortPomMavenTest
./gradlew :plugin-maven:test --tests com.diffplug.spotless.maven.pom.SortPomMavenTest

# Run only one test from the "plugin-gradle" project
gradlew :plugin-gradle:test --tests com.diffplug.gradle.spotless.FreshMarkExtensionTest
./gradlew :plugin-gradle:test --tests com.diffplug.gradle.spotless.FreshMarkExtensionTest
```

## Check and format code
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}}
lib('pom.SortPomStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('protobuf.BufStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |',
lib('rdf.RdfFormatterStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |',
lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
lib('shell.ShfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
Expand Down Expand Up @@ -157,6 +158,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
| [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`protobuf.BufStep`](lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
| [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: |
| [`rdf.RdfFormatterStep`](lib/src/main/java/com/diffplug/spotless/rdf/RdfFormatterStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: |
| [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
| [`shell.ShfmtStep`](lib/src/main/java/com/diffplug/spotless/shell/ShfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ VER_SLF4J=[1.6,2.0[

# Used in multiple places
VER_DURIAN=1.2.0
VER_JGIT=6.7.0.202309050840-r
VER_JUNIT=5.10.2
VER_ASSERTJ=3.26.0
VER_MOCKITO=5.12.0
VER_JGIT=6.10.0.202406032230-r
VER_JUNIT=5.11.2
VER_ASSERTJ=3.26.3
VER_MOCKITO=5.14.2
18 changes: 12 additions & 6 deletions gradle/changelog.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
String kind
String releaseTitle
if (project.name == 'plugin-gradle') {
kind = 'gradle'
releaseTitle = 'Gradle Plugin'
} else if (project.name == 'plugin-maven') {
kind = 'maven'
} else if (project.name.startsWith('eclipse')) {
kind = 'ext-' + project.name
releaseTitle = 'Maven Plugin'
} else {
assert project == rootProject
kind = 'lib'
releaseTitle = 'Lib'
}

// the root project and plugins have their own changelogs
Expand All @@ -20,11 +22,15 @@ spotlessChangelog {
branch 'release'
tagPrefix "${kind}/"
commitMessage "Published ${kind}/{{version}}" // {{version}} will be replaced
}
tagMessage "{{changes}}"
runAfterPush "gh release create ${kind}/{{version}} --title '${releaseTitle} v{{version}}' --notes-from-tag"

if (gradle.startParameter.projectProperties.get('com.diffplug.spotless.include.ext.nop2') == 'true') {
tasks.named('changelogPrint') {
enabled = kind.startsWith('ext-')
if (kind == 'gradle') {
forceNextVersion '7.0.0.BETA3'
} else if (kind == 'maven') {
forceNextVersion '2.44.0.BETA3'
} else {
forceNextVersion '3.0.0.BETA3'
}
}

Expand Down
9 changes: 3 additions & 6 deletions gradle/special-tests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ tasks.withType(Test).configureEach {
maxRetries = 2
maxFailures = 10
}

// There are only 2 cores in each GitHub Action Runner, we use all of them here.
maxParallelForks = Runtime.getRuntime().availableProcessors()
} else {
// https://docs.gradle.org/8.4/userguide/performance.html#execute_tests_in_parallel
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}

// https://docs.gradle.org/8.8/userguide/performance.html#execute_tests_in_parallel
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}
tasks.named('test').configure {
useJUnitPlatform {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
2 changes: 1 addition & 1 deletion lib-extra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = rootProject.spotlessChangelog.versionNext
apply from: rootProject.file('gradle/java-setup.gradle')
apply from: rootProject.file('gradle/java-publish.gradle')

String VER_SOLSTICE = '1.7.6'
String VER_SOLSTICE = '1.8.0'
dependencies {
api projects.lib
// misc useful utilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void setPreferences(Iterable<File> settingsFiles) {
this.settingsFiles = settingsFiles;
}

static class EclipseStep implements java.io.Serializable {
static class EclipseStep implements Serializable {
private static final long serialVersionUID = 1;
private final String semanticVersion;
private final String formatterStepExt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.diffplug.spotless.SerializedFunction;

import dev.equo.solstice.NestedJars;
import dev.equo.solstice.p2.CacheLocations;
import dev.equo.solstice.p2.P2ClientCache;
import dev.equo.solstice.p2.P2Model;
import dev.equo.solstice.p2.P2QueryCache;
Expand All @@ -52,6 +53,7 @@ public abstract class EquoBasedStepBuilder {
private String formatterVersion;
private Iterable<File> settingsFiles = new ArrayList<>();
private Map<String, String> p2Mirrors = Map.of();
private File cacheDirectory;

/** Initialize valid default configuration, taking latest version */
public EquoBasedStepBuilder(String formatterName, Provisioner mavenProvisioner, @Nullable String defaultVersion, SerializedFunction<State, FormatterFunc> stateToFormatter) {
Expand All @@ -77,6 +79,10 @@ public void setP2Mirrors(Collection<P2Mirror> p2Mirrors) {
this.p2Mirrors = p2Mirrors.stream().collect(toMap(P2Mirror::getPrefix, P2Mirror::getUrl));
}

public void setCacheDirectory(File cacheDirectory) {
this.cacheDirectory = cacheDirectory;
}

protected abstract P2Model model(String version);

protected void addPlatformRepo(P2Model model, String version) {
Expand All @@ -101,13 +107,16 @@ public FormatterStep build() {
var roundtrippableState = new EquoStep(formatterVersion, FileSignature.promise(settingsFiles), JarState.promise(() -> {
P2QueryResult query;
try {
if (null != cacheDirectory) {
CacheLocations.override_p2data = cacheDirectory.toPath().resolve("dev/equo/p2-data").toFile();
}
query = createModelWithMirrors().query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW);
} catch (Exception x) {
throw new IOException("Failed to load " + formatterName + ": " + x, x);
}
var classpath = new ArrayList<File>();
var mavenDeps = new ArrayList<String>();
mavenDeps.add("dev.equo.ide:solstice:1.7.6");
mavenDeps.add("dev.equo.ide:solstice:1.8.0");
mavenDeps.add("com.diffplug.durian:durian-swt.os:4.2.0");
mavenDeps.addAll(query.getJarsOnMavenCentral());
classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps));
Expand Down Expand Up @@ -143,7 +152,7 @@ private P2Model createModelWithMirrors() {
return model;
}

static class EquoStep implements java.io.Serializable {
static class EquoStep implements Serializable {
private static final long serialVersionUID = 1;
private final String semanticVersion;
private final FileSignature.Promised settingsPromise;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@ public final class EclipseCdtFormatterStep {
private EclipseCdtFormatterStep() {}

private static final String NAME = "eclipse cdt formatter";
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "10.7").add(17, "11.3");
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "10.7").add(17, "11.6");

public static String defaultVersion() {
return JVM_SUPPORT.getRecommendedFormatterVersion();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,7 +32,7 @@ public final class GrEclipseFormatterStep {
private GrEclipseFormatterStep() {}

private static final String NAME = "eclipse groovy formatter";
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "4.26").add(17, "4.29");
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "4.26").add(17, "4.32");

public static String defaultVersion() {
return JVM_SUPPORT.getRecommendedFormatterVersion();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 DiffPlug
* Copyright 2016-2024 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@ public final class EclipseJdtFormatterStep {
private EclipseJdtFormatterStep() {}

private static final String NAME = "eclipse jdt formatter";
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "4.26").add(17, "4.29");
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "4.26").add(17, "4.32");

public static String defaultVersion() {
return JVM_SUPPORT.getRecommendedFormatterVersion();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2024 DiffPlug
*
* 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.diffplug.spotless.extra.java;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.ResourceHarness;
import com.diffplug.spotless.TestProvisioner;
import com.diffplug.spotless.ThrowingEx;

public class EclipseJdtEqualityTest extends ResourceHarness {
@Test
public void test() throws Exception {
var settings1 = setFile("subfolder1/formatter.xml").toResource("java/eclipse/formatter.xml");
var settings2 = setFile("subfolder2/formatter.xml").toResource("java/eclipse/formatter.xml");
var step1 = withSettingsFile(settings1);
var step2 = withSettingsFile(settings2);

Assertions.assertTrue(step1.equals(step2));
Assertions.assertTrue(step1.hashCode() == step2.hashCode());

var serialized1 = toBytes(step1);
var serialized2 = toBytes(step2);
Assertions.assertFalse(serialized1.equals(serialized2));
}

private static FormatterStep withSettingsFile(File settingsFile) {
var builder = EclipseJdtFormatterStep.createBuilder(TestProvisioner.mavenCentral());
builder.setPreferences(List.of(settingsFile));
return builder.build();
}

private static byte[] toBytes(Serializable obj) {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
try (ObjectOutputStream objectOutput = new ObjectOutputStream(byteOutput)) {
objectOutput.writeObject(obj);
} catch (IOException e) {
throw ThrowingEx.asRuntime(e);
}
return byteOutput.toByteArray();
}
}
Loading

0 comments on commit e1a9acb

Please sign in to comment.