Skip to content

Commit

Permalink
Spotless formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik committed Sep 24, 2020
1 parent 2c80368 commit d9cf50a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.diffplug.spotless.maven;

import static java.util.stream.Collectors.toList;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
Expand Down Expand Up @@ -60,8 +62,6 @@
import com.diffplug.spotless.maven.sql.Sql;
import com.diffplug.spotless.maven.typescript.Typescript;

import static java.util.stream.Collectors.toList;

public abstract class AbstractSpotlessMojo extends AbstractMojo {

private static final String DEFAULT_ENCODING = "UTF-8";
Expand Down Expand Up @@ -180,22 +180,22 @@ private List<File> collectFiles(FormatterFactory formatterFactory, FormatterConf

private List<File> collectFilesFromGit(FormatterFactory formatterFactory, String ratchetFrom) throws MojoExecutionException {
MatchPatterns includePatterns = MatchPatterns.from(
withNormalizedFileSeparators(getIncludes(formatterFactory)));
withNormalizedFileSeparators(getIncludes(formatterFactory)));
MatchPatterns excludePatterns = MatchPatterns.from(
withNormalizedFileSeparators(getExcludes(formatterFactory)));
withNormalizedFileSeparators(getExcludes(formatterFactory)));

Iterable<String> dirtyFiles;
try {
dirtyFiles = GitRatchetMaven
.instance().getDirtyFiles(baseDir, ratchetFrom);
.instance().getDirtyFiles(baseDir, ratchetFrom);
} catch (IOException e) {
throw new MojoExecutionException("Unable to scan file tree rooted at " + baseDir, e);
} catch (GitAPIException e) {
throw new MojoExecutionException("Error getting diff against 'ratchetFrom' setting '" + ratchetFrom + "'", e);
}

List<File> result = new ArrayList<>();
for (String file: withNormalizedFileSeparators(dirtyFiles)) {
for (String file : withNormalizedFileSeparators(dirtyFiles)) {
if (includePatterns.matches(file, true)) {
if (!excludePatterns.matches(file, true)) {
result.add(Paths.get(baseDir.getPath(), file).toFile());
Expand All @@ -215,9 +215,9 @@ private List<File> collectFilesFromFormatterFactory(FormatterFactory formatterFa

private Iterable<String> withNormalizedFileSeparators(Iterable<String> patterns) {
return StreamSupport.stream(patterns.spliterator(), true)
.map(pattern -> pattern.replace('/', File.separatorChar))
.map(pattern -> pattern.replace('\\', File.separatorChar))
.collect(Collectors.toSet());
.map(pattern -> pattern.replace('/', File.separatorChar))
.map(pattern -> pattern.replace('\\', File.separatorChar))
.collect(Collectors.toSet());
}

private static String withTrailingSeparator(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ Iterable<String> getDirtyFiles(File baseDir, String ratchetFrom)

Git git = new Git(repository);
List<DiffEntry> diffs = git.diff()
.setShowNameAndStatusOnly(true)
.setOldTree(oldTree)
.call();
.setShowNameAndStatusOnly(true)
.setOldTree(oldTree)
.call();

String workTreePath = repository.getWorkTree().getPath();
Path baseDirPath = Paths.get(baseDir.getPath());

return diffs.stream()
.map(DiffEntry::getNewPath)
.map(path -> Paths.get(workTreePath, path))
.map(path -> baseDirPath.relativize(path).toString())
.collect(Collectors.toList());
.map(DiffEntry::getNewPath)
.map(path -> Paths.get(workTreePath, path))
.map(path -> baseDirPath.relativize(path).toString())
.collect(Collectors.toList());
}
}

0 comments on commit d9cf50a

Please sign in to comment.