Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows bug in ratchetFrom #596

Merged
merged 5 commits into from
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
version: 2.1
orbs:
win: circleci/windows@2.4.0

anchors:
env_gradle: &env_gradle
environment:
# java doesn't play nice with containers, it tries to hog the entire machine
# https://circleci.com/blog/how-to-handle-java-oom-errors/
# try the experimental JVM option
_JAVA_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
GRADLE_OPTS: "-Dorg.gradle.workers.max=2" # and we're only allowed to use 2 vCPUs
# and we're only allowed to use 2 vCPUs
GRADLE_OPTS: "-Dorg.gradle.workers.max=2"
docker:
- image: cimg/openjdk:8.0
env_gradle_large: &env_gradle_large
<< : *env_gradle
resource_class: large # https://circleci.com/docs/2.0/configuration-reference/#resource_class
GRADLE_OPTS: "-Dorg.gradle.workers.max=4"
environment:
GRADLE_OPTS: "-Dorg.gradle.workers.max=4"

restore_cache_wrapper: &restore_cache_wrapper
restore_cache:
@@ -40,8 +46,6 @@ anchors:
path: lib-extra/build/test-results/test
- store_test_results:
path: plugin-gradle/build/test-results/test

version: 2
jobs:
# gradlew spotlessCheck assemble testClasses
assemble_testClasses:
@@ -105,6 +109,45 @@ jobs:
path: plugin-maven/build/test-results/npm
- store_test_results:
path: plugin-gradle/build/test-results/npm
test_windows:
executor:
name: win/default
shell: cmd.exe
steps:
- checkout
# install openjdk8
- restore_cache:
key: choco2-ojdkbuild8
- run:
name: install
command: choco install ojdkbuild8
- save_cache:
key: choco2-ojdkbuild8
paths:
- ~\AppData\Local\Temp\chocolatey\ojdkbuild8
# do the test
- restore_cache:
keys:
- gradle-deps-win-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }}
- gradle-deps-win-
- run:
name: gradlew check
command: gradlew check --build-cache
- store_test_results:
path: testlib/build/test-results/test
- store_test_results:
path: lib-extra/build/test-results/test
- store_test_results:
path: plugin-gradle/build/test-results/test
- store_test_results:
path: plugin-maven/build/test-results/test
- save_cache:
paths:
- ~/.gradle/caches
- ~/.gradle/wrapper
- ~/.m2
- ~/project/plugin-maven/build/localMavenRepository
key: gradle-deps-win-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }}
changelog_print:
<< : *env_gradle
steps:
@@ -158,6 +201,7 @@ workflows:
version: 2
assemble_and_test:
jobs:
- test_windows
- assemble_testClasses
- test_justmaven_8:
requires:
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ 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]
* We are now running CI on windows. ([#596](https://github.com/diffplug/spotless/pull/596))
* We are now dogfooding `ratchetFrom` and `licenseHeader` with a `$YEAR` token to ensure that Spotless copyright headers stay up-to-date without adding noise to file history. ([#595](https://github.com/diffplug/spotless/pull/595))
* Added `LineEnding.nativeIsWin()`, `FileSignature.pathNativeToUnix()`, and `FileSignature.pathUnixToNative()`, along with many API-invisible fixes and cleanup. ([#592](https://github.com/diffplug/spotless/pull/592))

2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/FileSignature.java
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ public File getOnlyFile() {

/** Transforms a native path to a unix one. */
public static String pathNativeToUnix(String pathNative) {
return LineEnding.nativeIsWin() ? pathNative : pathNative.replace('\\', '/');
return LineEnding.nativeIsWin() ? pathNative.replace('\\', '/') : pathNative;
}

/** Transforms a unix path to a native one. */
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Fixed
* `ratchetFrom` incorrectly marked every file as though it were clean on Windows.
* Improved the warning message for `paddedCell` deprecation, along with many API-invisible fixes and cleanup. ([#592](https://github.com/diffplug/spotless/pull/592))

## [4.2.0] - 2020-06-03
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@
import com.diffplug.common.base.Errors;
import com.diffplug.common.collect.HashBasedTable;
import com.diffplug.common.collect.Table;
import com.diffplug.spotless.FileSignature;

class GitRatchet implements AutoCloseable {
/**
@@ -54,7 +55,7 @@ class GitRatchet implements AutoCloseable {
*/
public boolean isClean(Project project, ObjectId treeSha, File file) throws IOException {
Repository repo = repositoryFor(project);
String path = repo.getWorkTree().toPath().relativize(file.toPath()).toString();
String path = FileSignature.pathNativeToUnix(repo.getWorkTree().toPath().relativize(file.toPath()).toString());

// TODO: should be cached-per-repo if it is thread-safe, or per-repo-per-thread if it is not
DirCache dirCache = repo.readDirCache();
7 changes: 5 additions & 2 deletions testlib/src/main/java/com/diffplug/spotless/JreVersion.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2020 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,10 @@ public static JreVersion thisVm() {
} else if (jvmVersion.startsWith("11.")) {
return _11;
} else {
throw new IllegalStateException("Spotless build is only supported on Java 8 and Java 11");
int version = Integer.parseInt(jvmVersion.substring(0, jvmVersion.indexOf('.')));
JreVersion result = version > 11 ? _11 : _8;
System.err.println("WARNING: Only JRE 8 and 11 are officially supported, pretending unsupported version " + jvmVersion + " is JDK" + result.name());
return result;
}
}
}