Skip to content

Commit

Permalink
Fix spotlessFiles parameter tests for plugin-maven on windows (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Nov 17, 2020
2 parents b4b7d04 + e3b4e10 commit d9474fb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Fixed
* Fix broken test for spotlessFiles parameter on windows ([#737](https://github.com/diffplug/spotless/pull/737))

## [2.6.1] - 2020-11-16
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,30 @@
package com.diffplug.spotless.maven;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Test;

public class SpecificFilesTest extends MavenIntegrationHarness {
private String testFile(int number, boolean absolute) throws IOException {
String rel = "src/main/java/test" + number + ".java";
Path path;
if (absolute) {
return rootFolder() + "/" + rel;
path = Paths.get(rootFolder().getAbsolutePath(), rel);
} else {
return rel;
path = Paths.get(rel);
}
String result = path.toString();
if (!isOnWindows()) {
return result;
} else {
return result.replace("\\", "\\\\");
}
}

private boolean isOnWindows() {
return System.getProperty("os.name").startsWith("Windows");
}

private String testFile(int number) throws IOException {
Expand Down Expand Up @@ -73,6 +86,11 @@ public void multiFile() throws IOException, InterruptedException {

@Test
public void regexp() throws IOException, InterruptedException {
integration(".*/src/main/java/test\\(1\\|3\\).java", true, false, true);
String pattern;
if (isOnWindows())
pattern = "\".*\\\\src\\\\main\\\\java\\\\test(1|3).java\"";
else
pattern = "'.*/src/main/java/test(1|3).java'";
integration(pattern, true, false, true);
}
}

0 comments on commit d9474fb

Please sign in to comment.