Skip to content

Commit

Permalink
Merge branch 'main' into feat/equo-ide
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Feb 5, 2023
2 parents a7b4da4 + e19c156 commit 0681287
Show file tree
Hide file tree
Showing 91 changed files with 1,008 additions and 816 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ jobs:
fail-fast: false
matrix:
kind: [maven, gradle]
jre: [8, 11, 17]
jre: [11, 17]
os: [ubuntu-latest]
include:
# test windows at the diagonals of the above matrix
- kind: maven
jre: 8
jre: 11
os: windows-latest
- kind: gradle
jre: 17
os: windows-latest
# npm on linux only (crazy slow on windows)
- kind: npm
jre: 8
jre: 11
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
- name: git fetch origin main
run: git fetch origin main
- name: publish all
if: "${{ github.event.inputs.to_publish == 'all' }}"
run: |
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
name: "Validate Gradle Wrapper"
on: [push, pull_request]
on:
push:
paths:
- 'gradlew'
- 'gradlew.bat'
- 'gradle/wrapper/'
pull_request:
paths:
- 'gradlew'
- 'gradlew.bat'
- 'gradle/wrapper/'

permissions:
contents: read
Expand Down
18 changes: 18 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ This document is intended for Spotless developers.
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]

## [2.34.1] - 2023-02-05
### Changes
* **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337))
### Fixed
* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546))
* `freshmark` fixed on java 15+ ([#1304](https://github.com/diffplug/spotless/pull/1304) fixes [#803](https://github.com/diffplug/spotless/issues/803))

## [2.34.0] - 2023-01-26
### Added
* `Formatter` now has a field `public static final File NO_FILE_SENTINEL` which can be used to pass string content to a Formatter or FormatterStep when there is no actual File to format. ([#1525](https://github.com/diffplug/spotless/pull/1525))

## [2.33.0] - 2023-01-26
### Added
* `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496))
* `ProcessRunner` allows to limit captured output to a certain number of bytes. ([#1511](https://github.com/diffplug/spotless/pull/1511))
Expand All @@ -18,11 +31,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Fixed
* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494)
### Changes
* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11, next release likely to bump bytecode to Java 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337))
* Rename `YamlJacksonStep` into `JacksonYamlStep` while normalizing Jackson usage ([#1492](https://github.com/diffplug/spotless/pull/1492))
* Convert `gson` integration to use a compile-only source set ([#1510](https://github.com/diffplug/spotless/pull/1510)).
* ** POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475))
* `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019.
* From now on, we will support no more than 2 breaking changes at a time.
* NpmFormatterStepStateBase delays `npm install` call until the formatter is first used. This enables better integration
with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522))
* Bump default `ktlint` version to latest `0.48.1` -> `0.48.2` ([#1529](https://github.com/diffplug/spotless/pull/1529))
* Bump default `scalafmt` version to latest `3.6.1` -> `3.7.1` ([#1529](https://github.com/diffplug/spotless/pull/1529))

## [2.32.0] - 2023-01-13
### Added
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ If it doesn't work, you can check the JitPack log at `https://jitpack.io/com/git

### Maven

Run `./gradlew publishToMavenLocal` to publish this to your local repository. The maven plugin is not published to JitPack due to [jitpack/jitpack.io#4112](https://github.com/jitpack/jitpack.io/issues/4112).
Run `./gradlew publishToMavenLocal` to publish this to your local repository. You can also use the JitPack artifacts, using the same principles as Gradle above.

## License

Expand Down
46 changes: 34 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
# <img align="left" src="_images/spotless_logo.png"> Spotless: Keep your code spotless

<!---freshmark shields
output = [
link(image('Circle CI', 'https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield'), 'https://circleci.com/gh/diffplug/spotless/tree/main'),
link(shield('Live chat', 'gitter', 'chat', 'brightgreen'), 'https://gitter.im/{{org}}/{{name}}'),
link(shield('License Apache', 'license', 'apache', 'brightgreen'), 'https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)')
].join('\n');
-->
[![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main)
[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless)
[![License Apache](https://img.shields.io/badge/license-apache-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
<!---freshmark /shields -->
[![Gradle Plugin](https://img.shields.io/gradle-plugin-portal/v/com.diffplug.spotless?color=blue&label=gradle%20plugin)](plugin-gradle)
[![Maven Plugin](https://img.shields.io/maven-central/v/com.diffplug.spotless/spotless-maven-plugin?color=blue&label=maven%20plugin)](plugin-maven)
[![SBT Plugin](https://img.shields.io/badge/sbt%20plugin-0.1.3-blue)](https://github.com/moznion/sbt-spotless)

Spotless can format &lt;antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | sql | typeScript | vue | yaml | anything> using &lt;gradle | maven | anything>.
Spotless can format &lt;antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | sql | typeScript | vue | yaml | anything> using &lt;gradle | maven | sbt | anything>.

You probably want one of the links below:

## [❇️ Spotless for Gradle](plugin-gradle) (with integrations for [VS Code](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) and [IntelliJ](https://plugins.jetbrains.com/plugin/18321-spotless-gradle))

```console
user@machine repo % ./gradlew build
:spotlessJavaCheck FAILED
The following files had format violations:
src\main\java\com\diffplug\gradle\spotless\FormatExtension.java
-\t\t····if·(targets.length·==·0)·{
+\t\tif·(targets.length·==·0)·{
Run './gradlew spotlessApply' to fix these violations.
user@machine repo % ./gradlew spotlessApply
:spotlessApply
BUILD SUCCESSFUL
user@machine repo % ./gradlew build
BUILD SUCCESSFUL
```

## [❇️ Spotless for Maven](plugin-maven)

```console
user@machine repo % mvn spotless:check
[ERROR] > The following files had format violations:
[ERROR] src\main\java\com\diffplug\gradle\spotless\FormatExtension.java
[ERROR] -\t\t····if·(targets.length·==·0)·{
[ERROR] +\t\tif·(targets.length·==·0)·{
[ERROR] Run 'mvn spotless:apply' to fix these violations.
user@machine repo % mvn spotless:apply
[INFO] BUILD SUCCESS
user@machine repo % mvn spotless:check
[INFO] BUILD SUCCESS
```

## [❇️ Spotless for SBT (external for now)](https://github.com/moznion/sbt-spotless)
## [Other build systems](CONTRIBUTING.md#how-to-add-a-new-plugin-for-a-build-system)

Expand Down
2 changes: 1 addition & 1 deletion _ext/gradle/java-setup.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apply from: rootProject.file('gradle/java-setup.gradle')
apply plugin: 'java-library'

// Show warning locations, fail on warnings
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-Xlint:unchecked"
options.compilerArgs << "-Xlint:deprecation"
options.compilerArgs << "-Werror"
Expand Down
4 changes: 2 additions & 2 deletions _ext/gradle/update-lockfile.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Use file locking
configurations.all {
configurations.configureEach {
resolutionStrategy {
activateDependencyLocking()
}
}
}
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ artifactIdMaven=spotless-maven-plugin
artifactIdGradle=spotless-plugin-gradle

# Build requirements
VER_JAVA=1.8
VER_JAVA=11
VER_SPOTBUGS=4.7.3
VER_JSR_305=3.0.2

Expand All @@ -25,7 +25,7 @@ VER_SLF4J=[1.6,2.0[

# Used in multiple places
VER_DURIAN=1.2.0
VER_JGIT=5.13.1.202206130422-r
VER_JGIT=6.4.0.202211300538-r
VER_JUNIT=5.9.2
VER_ASSERTJ=3.24.2
VER_MOCKITO=4.11.0
VER_MOCKITO=5.1.1
1 change: 1 addition & 0 deletions gradle/changelog.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ spotlessChangelog {
// need -Prelease=true in order to do a publish
appendDashSnapshotUnless_dashPrelease=true

branch 'release'
tagPrefix "${kind}/"
commitMessage "Published ${kind}/{{version}}" // {{version}} will be replaced
}
Expand Down
20 changes: 11 additions & 9 deletions gradle/java-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ model {
}
}

if (!version.endsWith('-SNAPSHOT')) {
if (System.env['JITPACK'] == 'true') {
signing {
setRequired(false)
}
} else if (!version.endsWith('-SNAPSHOT')) {
signing {
String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64')
useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase'])
Expand All @@ -186,14 +190,12 @@ if (!version.endsWith('-SNAPSHOT')) {
}
// ensures that changelog bump and push only happens if the publish was successful
def thisProj = project
afterEvaluate {
changelogTasks.named('changelogBump').configure {
dependsOn thisProj.tasks.named('publishPluginMavenPublicationToSonatypeRepository')
dependsOn rootProject.tasks.named('closeAndReleaseSonatypeStagingRepository')
// if we have a gradle plugin, we need to push it up to the plugin portal too
if (thisProj.tasks.names.contains('publishPlugins')) {
dependsOn thisProj.tasks.named('publishPlugins')
}
changelogTasks.named('changelogBump').configure {
dependsOn ":${thisProj.path}:publishPluginMavenPublicationToSonatypeRepository"
dependsOn ":closeAndReleaseSonatypeStagingRepository"
// if we have a gradle plugin, we need to push it up to the plugin portal too
if (thisProj.tasks.names.contains('publishPlugins')) {
dependsOn thisProj.tasks.named('publishPlugins')
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions gradle/java-setup.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//////////
// JAVA //
//////////
repositories { mavenCentral() }

// setup java
apply plugin: 'java'

sourceCompatibility = VER_JAVA
targetCompatibility = VER_JAVA
tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release = Integer.parseInt(VER_JAVA)
}

//////////////
// SPOTBUGS //
Expand All @@ -34,8 +33,6 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
}

tasks.named('spotbugsMain') {
// only run on Java 8 (no benefit to running twice)
enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11
reports {
html.enabled = true
}
Expand Down
1 change: 0 additions & 1 deletion gradle/special-tests.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
apply plugin: 'org.gradle.test-retry'
apply plugin: 'com.adarshr.test-logger'
def special = [
'Npm',
Expand Down
26 changes: 0 additions & 26 deletions gradle/spotless-freshmark.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@

import java.util.regex.Matcher
import java.util.regex.Pattern


def thisVm() {
String jre = System.getProperty("java.version")
if (jre.startsWith("1.8")) {
return 8
} else {
Matcher matcher = Pattern.compile("(\\d+)").matcher(jre)
if (!matcher.find()) {
throw new IllegalArgumentException("Expected " + jre + " to start with an integer")
}
int version = Integer.parseInt(matcher.group(1))
if (version <= 8) {
throw new IllegalArgumentException("Expected " + jre + " to start with an integer greater than 8")
}
return version
}
}

if (thisVm() >= 15) {
// freshmark doesn't run on JRE 15+
return
}

apply plugin: 'com.diffplug.spotless'

import com.diffplug.gradle.spotless.FreshMarkExtension
Expand Down
2 changes: 2 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jdk:
- openjdk11
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2023 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 @@ -143,18 +143,14 @@ public String getMessage() {
Objects.requireNonNull(runToFix, "runToFix");
Objects.requireNonNull(formatter, "formatter");
Objects.requireNonNull(problemFiles, "problemFiles");
DiffMessageFormatter diffFormater = new DiffMessageFormatter(this);
DiffMessageFormatter diffFormater = new DiffMessageFormatter(formatter, problemFiles);
return "The following files had format violations:\n"
+ diffFormater.buffer
+ runToFix;
} catch (IOException e) {
throw Errors.asRuntime(e);
}
}

String relativePath(File file) {
return formatter.getRootDir().relativize(file.toPath()).toString();
}
}

private static final int MAX_CHECK_MESSAGE_LINES = 50;
Expand All @@ -163,25 +159,32 @@ String relativePath(File file) {
private final StringBuilder buffer = new StringBuilder(MAX_CHECK_MESSAGE_LINES * 64);
private int numLines = 0;

private DiffMessageFormatter(Builder builder) throws IOException {
ListIterator<File> problemIter = builder.problemFiles.listIterator();
private final CleanProvider formatter;

private DiffMessageFormatter(CleanProvider formatter, List<File> problemFiles) throws IOException {
this.formatter = Objects.requireNonNull(formatter, "formatter");
ListIterator<File> problemIter = problemFiles.listIterator();
while (problemIter.hasNext() && numLines < MAX_CHECK_MESSAGE_LINES) {
File file = problemIter.next();
addFile(builder.relativePath(file) + "\n" + DiffMessageFormatter.diff(builder, file));
addFile(relativePath(file) + "\n" + diff(file));
}
if (problemIter.hasNext()) {
int remainingFiles = builder.problemFiles.size() - problemIter.nextIndex();
int remainingFiles = problemFiles.size() - problemIter.nextIndex();
if (remainingFiles >= MAX_FILES_TO_LIST) {
buffer.append("Violations also present in ").append(remainingFiles).append(" other files.\n");
} else {
buffer.append("Violations also present in:\n");
while (problemIter.hasNext()) {
addIntendedLine(NORMAL_INDENT, builder.relativePath(problemIter.next()));
addIntendedLine(NORMAL_INDENT, relativePath(problemIter.next()));
}
}
}
}

private String relativePath(File file) {
return formatter.getRootDir().relativize(file.toPath()).toString();
}

private static final int MIN_LINES_PER_FILE = 4;
private static final Splitter NEWLINE_SPLITTER = Splitter.on('\n');

Expand Down Expand Up @@ -230,10 +233,10 @@ private void addIntendedLine(String indent, String line) {
* look like if formatted using the given formatter. Does not end with any newline
* sequence (\n, \r, \r\n).
*/
private static String diff(Builder builder, File file) throws IOException {
String raw = new String(Files.readAllBytes(file.toPath()), builder.formatter.getEncoding());
private String diff(File file) throws IOException {
String raw = new String(Files.readAllBytes(file.toPath()), formatter.getEncoding());
String rawUnix = LineEnding.toUnix(raw);
String formatted = builder.formatter.getFormatted(file, rawUnix);
String formatted = formatter.getFormatted(file, rawUnix);
String formattedUnix = LineEnding.toUnix(formatted);

if (rawUnix.equals(formattedUnix)) {
Expand Down
Loading

0 comments on commit 0681287

Please sign in to comment.