Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ protected String preHookTemplate(Executor executor, String commandCheck, String
private String executorPath(Executor executor) {
final var wrapper = executorWrapperFile(executor);
if (wrapper.exists()) {
return "./" + wrapper.getName();
return wrapper.getAbsolutePath().replace("\\", "/");
}

logger.info("Local %s wrapper (%s) not found, falling back to global command '%s'",
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Changes
* Bump default `ktfmt` version to latest `0.58` -> `0.59`. ([#2681](https://github.com/diffplug/spotless/pull/2681)
* Use absolute path in the git pre push hook
### Fixed
- palantirJavaFormat is no longer arbitrarily set to outdated versions on Java 17, latest available version is always used ([#2686](https://github.com/diffplug/spotless/pull/2686) fixes [#2685](https://github.com/diffplug/spotless/issues/2685))

Expand Down
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Changes
* Bump default `ktfmt` version to latest `0.58` -> `0.59`. ([#2681](https://github.com/diffplug/spotless/pull/2681)
* Use absolute path in the git pre push hook
### Fixed
- palantirJavaFormat is no longer arbitrarily set to outdated versions on Java 17, latest available version is always used ([#2686](https://github.com/diffplug/spotless/pull/2686) fixes [#2685](https://github.com/diffplug/spotless/issues/2685))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ private void writePomWithJavaLicenseHeaderStep() throws IOException {

private String getHookContent(String resourceFile) {
final var executorFile = executorWrapperFile();
final var executorPath = executorFile.exists() ? executorFile.getName() : "mvn";
final var executorPath = executorFile.exists() ? executorFile.getAbsolutePath().replace("\\", "/") : "mvn";
return getTestResource(resourceFile)
.replace("${executor}", "./" + executorPath)
.replace("${executor}", executorPath)
.replace("${checkCommand}", "spotless:check")
.replace("${applyCommand}", "spotless:apply");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -251,7 +252,7 @@ public void should_use_global_maven_when_maven_wrapper_is_not_installed() throws
public void should_use_maven_bat_wrapper_when_exists_for_windows() {
// given
System.setProperty("os.name", "Windows 10");
setFile("mvnw.bat").toContent("");
final var batFile = setFile("mvnw.bat").toContent("");
setFile("mvnw.cmd").toContent("");

final var gradle = new GitPrePushHookInstallerMaven(logger, rootFolder());
Expand All @@ -260,22 +261,22 @@ public void should_use_maven_bat_wrapper_when_exists_for_windows() {
final var hook = gradle.preHookTemplate(MAVEN, "spotless:check", "spotless:apply");

// then
assertThat(hook).contains("SPOTLESS_EXECUTOR=./mvnw.bat");
assertThat(hook).contains("SPOTLESS_EXECUTOR=" + fileAbsolutePath(batFile));
}

@Test
public void should_use_maven_cmd_wrapper_when_exists_for_windows() {
// given
System.setProperty("os.name", "Windows 10");
setFile("mvnw.cmd").toContent("");
final var executorFile = setFile("mvnw.cmd").toContent("");

final var gradle = new GitPrePushHookInstallerMaven(logger, rootFolder());

// when
final var hook = gradle.preHookTemplate(MAVEN, "spotless:check", "spotless:apply");

// then
assertThat(hook).contains("SPOTLESS_EXECUTOR=./mvnw.cmd");
assertThat(hook).contains("SPOTLESS_EXECUTOR=" + fileAbsolutePath(executorFile));
}

@Test
Expand All @@ -297,7 +298,7 @@ public void should_use_maven_global_when_bat_and_cmd_files_not_exists_for_window
public void should_use_gradle_bat_wrapper_when_exists_for_windows() {
// given
System.setProperty("os.name", "Windows 10");
setFile("gradlew.bat").toContent("");
final var executorFile = setFile("gradlew.bat").toContent("");
setFile("gradlew.cmd").toContent("");
setFile("gradlew").toContent("");

Expand All @@ -307,14 +308,14 @@ public void should_use_gradle_bat_wrapper_when_exists_for_windows() {
final var hook = gradle.preHookTemplate(GRADLE, "spotlessCheck", "spotlessApply");

// then
assertThat(hook).contains("SPOTLESS_EXECUTOR=./gradlew.bat");
assertThat(hook).contains("SPOTLESS_EXECUTOR=" + fileAbsolutePath(executorFile));
}

@Test
public void should_use_gradle_cmd_wrapper_when_exists_for_windows() {
// given
System.setProperty("os.name", "Windows 10");
setFile("gradlew.cmd").toContent("");
final var executorFile = setFile("gradlew.cmd").toContent("");
setFile("gradlew").toContent("");

final var gradle = new GitPrePushHookInstallerMaven(logger, rootFolder());
Expand All @@ -323,7 +324,7 @@ public void should_use_gradle_cmd_wrapper_when_exists_for_windows() {
final var hook = gradle.preHookTemplate(GRADLE, "spotlessCheck", "spotlessApply");

// then
assertThat(hook).contains("SPOTLESS_EXECUTOR=./gradlew.cmd");
assertThat(hook).contains("SPOTLESS_EXECUTOR=" + fileAbsolutePath(executorFile));
}

@Test
Expand Down Expand Up @@ -366,18 +367,22 @@ public void should_handle_parallel_installation() {

private String gradleHookContent(String resourcePath, ExecutorType executorType) {
return getTestResource(resourcePath)
.replace("${executor}", executorType == ExecutorType.WRAPPER ? "./" + newFile("gradlew").getName() : "gradle")
.replace("${executor}", executorType == ExecutorType.WRAPPER ? fileAbsolutePath(newFile("gradlew")) : "gradle")
.replace("${checkCommand}", "spotlessCheck")
.replace("${applyCommand}", "spotlessApply");
}

private String mavenHookContent(String resourcePath, ExecutorType executorType) {
return getTestResource(resourcePath)
.replace("${executor}", executorType == ExecutorType.WRAPPER ? "./" + newFile("mvnw").getName() : "mvn")
.replace("${executor}", executorType == ExecutorType.WRAPPER ? fileAbsolutePath(newFile("mvnw")) : "mvn")
.replace("${checkCommand}", "spotless:check")
.replace("${applyCommand}", "spotless:apply");
}

private String fileAbsolutePath(File file) {
return file.getAbsolutePath().replace("\\", "/");
}

private void parallelRun(ThrowableRun runnable) {
IntStream.range(0, 5)
.mapToObj(i -> new Thread(() -> {
Expand Down
Loading