Skip to content

Commit fcbf0dc

Browse files
authored
Merge pull request #596 from diffplug/fix/win-git
Fix windows bug in ratchetFrom
2 parents 57eaf4f + 6a3e9ee commit fcbf0dc

File tree

6 files changed

+58
-8
lines changed

6 files changed

+58
-8
lines changed

.circleci/config.yml

+48-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
version: 2.1
2+
orbs:
3+
win: circleci/windows@2.4.0
4+
15
anchors:
26
env_gradle: &env_gradle
37
environment:
48
# java doesn't play nice with containers, it tries to hog the entire machine
59
# https://circleci.com/blog/how-to-handle-java-oom-errors/
610
# try the experimental JVM option
711
_JAVA_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
8-
GRADLE_OPTS: "-Dorg.gradle.workers.max=2" # and we're only allowed to use 2 vCPUs
12+
# and we're only allowed to use 2 vCPUs
13+
GRADLE_OPTS: "-Dorg.gradle.workers.max=2"
914
docker:
1015
- image: cimg/openjdk:8.0
1116
env_gradle_large: &env_gradle_large
1217
<< : *env_gradle
1318
resource_class: large # https://circleci.com/docs/2.0/configuration-reference/#resource_class
14-
GRADLE_OPTS: "-Dorg.gradle.workers.max=4"
19+
environment:
20+
GRADLE_OPTS: "-Dorg.gradle.workers.max=4"
1521

1622
restore_cache_wrapper: &restore_cache_wrapper
1723
restore_cache:
@@ -40,8 +46,6 @@ anchors:
4046
path: lib-extra/build/test-results/test
4147
- store_test_results:
4248
path: plugin-gradle/build/test-results/test
43-
44-
version: 2
4549
jobs:
4650
# gradlew spotlessCheck assemble testClasses
4751
assemble_testClasses:
@@ -105,6 +109,45 @@ jobs:
105109
path: plugin-maven/build/test-results/npm
106110
- store_test_results:
107111
path: plugin-gradle/build/test-results/npm
112+
test_windows:
113+
executor:
114+
name: win/default
115+
shell: cmd.exe
116+
steps:
117+
- checkout
118+
# install openjdk8
119+
- restore_cache:
120+
key: choco2-ojdkbuild8
121+
- run:
122+
name: install
123+
command: choco install ojdkbuild8
124+
- save_cache:
125+
key: choco2-ojdkbuild8
126+
paths:
127+
- ~\AppData\Local\Temp\chocolatey\ojdkbuild8
128+
# do the test
129+
- restore_cache:
130+
keys:
131+
- gradle-deps-win-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }}
132+
- gradle-deps-win-
133+
- run:
134+
name: gradlew check
135+
command: gradlew check --build-cache
136+
- store_test_results:
137+
path: testlib/build/test-results/test
138+
- store_test_results:
139+
path: lib-extra/build/test-results/test
140+
- store_test_results:
141+
path: plugin-gradle/build/test-results/test
142+
- store_test_results:
143+
path: plugin-maven/build/test-results/test
144+
- save_cache:
145+
paths:
146+
- ~/.gradle/caches
147+
- ~/.gradle/wrapper
148+
- ~/.m2
149+
- ~/project/plugin-maven/build/localMavenRepository
150+
key: gradle-deps-win-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }}
108151
changelog_print:
109152
<< : *env_gradle
110153
steps:
@@ -158,6 +201,7 @@ workflows:
158201
version: 2
159202
assemble_and_test:
160203
jobs:
204+
- test_windows
161205
- assemble_testClasses
162206
- test_justmaven_8:
163207
requires:

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This document is intended for Spotless developers.
1010
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
1111

1212
## [Unreleased]
13+
* We are now running CI on windows. ([#596](https://github.com/diffplug/spotless/pull/596))
1314
* 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))
1415
* Added `LineEnding.nativeIsWin()`, `FileSignature.pathNativeToUnix()`, and `FileSignature.pathUnixToNative()`, along with many API-invisible fixes and cleanup. ([#592](https://github.com/diffplug/spotless/pull/592))
1516

lib/src/main/java/com/diffplug/spotless/FileSignature.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public File getOnlyFile() {
112112

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

118118
/** Transforms a unix path to a native one. */

plugin-gradle/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

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

910
## [4.2.0] - 2020-06-03

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GitRatchet.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.diffplug.common.base.Errors;
4545
import com.diffplug.common.collect.HashBasedTable;
4646
import com.diffplug.common.collect.Table;
47+
import com.diffplug.spotless.FileSignature;
4748

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

5960
// TODO: should be cached-per-repo if it is thread-safe, or per-repo-per-thread if it is not
6061
DirCache dirCache = repo.readDirCache();

testlib/src/main/java/com/diffplug/spotless/JreVersion.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2020 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,10 @@ public static JreVersion thisVm() {
2727
} else if (jvmVersion.startsWith("11.")) {
2828
return _11;
2929
} else {
30-
throw new IllegalStateException("Spotless build is only supported on Java 8 and Java 11");
30+
int version = Integer.parseInt(jvmVersion.substring(0, jvmVersion.indexOf('.')));
31+
JreVersion result = version > 11 ? _11 : _8;
32+
System.err.println("WARNING: Only JRE 8 and 11 are officially supported, pretending unsupported version " + jvmVersion + " is JDK" + result.name());
33+
return result;
3134
}
3235
}
3336
}

0 commit comments

Comments
 (0)