Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate skip behavior (take two) #973

Merged
merged 2 commits into from
Oct 20, 2021
Merged
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
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Added support and bump Eclipse formatter default versions to `4.21` for `eclipse-groovy`. Change is only applied for JVM 11+.
### Fixed
* Revert change from 2.17.2 regarding [skip bug](https://github.com/diffplug/spotless/pull/969) because fixing the skip bug caused inconsistent behavior between `check.skip` and `apply.skip`.
* [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 (new fix).

## [2.17.2] - 2021-10-14
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,24 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {

private static final String DEFAULT_ENCODING = "UTF-8";
private static final String DEFAULT_LINE_ENDINGS = "GIT_ATTRIBUTES";
static final String GOAL_CHECK = "check";
static final String GOAL_APPLY = "apply";

@Component
private RepositorySystem repositorySystem;

@Component
private ResourceManager resourceManager;

@Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true)
private String goal;

@Parameter(property = "spotless.apply.skip", defaultValue = "false")
private boolean applySkip;

@Parameter(property = "spotless.check.skip", defaultValue = "false")
private boolean checkSkip;

@Parameter(defaultValue = "${repositorySystemSession}", required = true, readonly = true)
private RepositorySystemSession repositorySystemSession;

Expand Down Expand Up @@ -146,7 +157,24 @@ public final void execute() throws MojoExecutionException {
}
}

private boolean shouldSkip() {
switch (goal) {
case GOAL_CHECK:
return checkSkip;
case GOAL_APPLY:
return applySkip;
default:
break;
}
return false;
}

private void execute(FormatterFactory formatterFactory) throws MojoExecutionException {
if (shouldSkip()) {
getLog().info(String.format("Spotless %s skipped", goal));
return;
}

FormatterConfig config = getFormatterConfig();
List<File> files = collectFiles(formatterFactory, config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,18 @@

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import com.diffplug.spotless.Formatter;
import com.diffplug.spotless.PaddedCell;

/**
* Performs formatting of all source files according to configured formatters.
*/
@Mojo(name = "apply", threadSafe = true)
@Mojo(name = AbstractSpotlessMojo.GOAL_APPLY, threadSafe = true)
public class SpotlessApplyMojo extends AbstractSpotlessMojo {
@Parameter(property = "spotless.apply.skip", defaultValue = "false")
private boolean skip;

@Override
protected void process(Iterable<File> files, Formatter formatter) throws MojoExecutionException {
if (skip) {
getLog().info("Spotless apply skipped");
return;
}

for (File file : files) {
try {
PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import com.diffplug.spotless.Formatter;
import com.diffplug.spotless.PaddedCell;
Expand All @@ -33,19 +32,11 @@
* Performs code formatting analysis and prints all violations to the console.
* Fails the build if violations are discovered.
*/
@Mojo(name = "check", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true)
@Mojo(name = AbstractSpotlessMojo.GOAL_CHECK, defaultPhase = LifecyclePhase.VERIFY, threadSafe = true)
public class SpotlessCheckMojo extends AbstractSpotlessMojo {

@Parameter(property = "spotless.check.skip", defaultValue = "false")
private boolean skip;

@Override
protected void process(Iterable<File> files, Formatter formatter) throws MojoExecutionException {
if (skip) {
getLog().info("Spotless check skipped");
return;
}

List<File> problemFiles = new ArrayList<>();
for (File file : files) {
try {
Expand Down