Skip to content

Commit 13a0e42

Browse files
authored
Merge pull request #969 from jherico/brad_fix-skip
2 parents 1a6568f + d83eee2 commit 13a0e42

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

plugin-maven/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
44

55
## [Unreleased]
6+
### Fixed
7+
* [skip bug](https://github.com/diffplug/spotless/issues/968) if ratchetFrom is specified, the build will still fail in if no Git repository is found, even if `skip` is true.
68

79
## [2.17.1] - 2021-10-13
810
### Fixed

plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
7373
@Component
7474
private ResourceManager resourceManager;
7575

76+
@Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true)
77+
private String goal;
78+
79+
@Parameter(property = "spotless.check.skip", defaultValue = "false")
80+
private boolean skip;
81+
7682
@Parameter(defaultValue = "${repositorySystemSession}", required = true, readonly = true)
7783
private RepositorySystemSession repositorySystemSession;
7884

@@ -147,6 +153,11 @@ public final void execute() throws MojoExecutionException {
147153
}
148154

149155
private void execute(FormatterFactory formatterFactory) throws MojoExecutionException {
156+
if (skip) {
157+
getLog().info(String.format("Spotless %s skipped", goal));
158+
return;
159+
}
160+
150161
FormatterConfig config = getFormatterConfig();
151162
List<File> files = collectFiles(formatterFactory, config);
152163

plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 DiffPlug
2+
* Copyright 2016-2021 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.
@@ -20,7 +20,6 @@
2020

2121
import org.apache.maven.plugin.MojoExecutionException;
2222
import org.apache.maven.plugins.annotations.Mojo;
23-
import org.apache.maven.plugins.annotations.Parameter;
2423

2524
import com.diffplug.spotless.Formatter;
2625
import com.diffplug.spotless.PaddedCell;
@@ -30,16 +29,9 @@
3029
*/
3130
@Mojo(name = "apply", threadSafe = true)
3231
public class SpotlessApplyMojo extends AbstractSpotlessMojo {
33-
@Parameter(property = "spotless.apply.skip", defaultValue = "false")
34-
private boolean skip;
3532

3633
@Override
3734
protected void process(Iterable<File> files, Formatter formatter) throws MojoExecutionException {
38-
if (skip) {
39-
getLog().info("Spotless apply skipped");
40-
return;
41-
}
42-
4335
for (File file : files) {
4436
try {
4537
PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file);

plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessCheckMojo.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 DiffPlug
2+
* Copyright 2016-2021 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.
@@ -23,7 +23,6 @@
2323
import org.apache.maven.plugin.MojoExecutionException;
2424
import org.apache.maven.plugins.annotations.LifecyclePhase;
2525
import org.apache.maven.plugins.annotations.Mojo;
26-
import org.apache.maven.plugins.annotations.Parameter;
2726

2827
import com.diffplug.spotless.Formatter;
2928
import com.diffplug.spotless.PaddedCell;
@@ -36,16 +35,8 @@
3635
@Mojo(name = "check", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true)
3736
public class SpotlessCheckMojo extends AbstractSpotlessMojo {
3837

39-
@Parameter(property = "spotless.check.skip", defaultValue = "false")
40-
private boolean skip;
41-
4238
@Override
4339
protected void process(Iterable<File> files, Formatter formatter) throws MojoExecutionException {
44-
if (skip) {
45-
getLog().info("Spotless check skipped");
46-
return;
47-
}
48-
4940
List<File> problemFiles = new ArrayList<>();
5041
for (File file : files) {
5142
try {

0 commit comments

Comments
 (0)