Skip to content

Commit

Permalink
Merge pull request #596 from diffplug/fix/win-git
Browse files Browse the repository at this point in the history
Fix windows bug in ratchetFrom
  • Loading branch information
nedtwigg authored Jun 4, 2020
2 parents 57eaf4f + 6a3e9ee commit fcbf0dc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
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/[email protected]

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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -158,6 +201,7 @@ workflows:
version: 2
assemble_and_test:
jobs:
- test_windows
- assemble_testClasses
- test_justmaven_8:
requires:
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
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
Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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();
Expand Down
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.
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit fcbf0dc

Please sign in to comment.