Skip to content

Commit

Permalink
Consolidate skip behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jherico committed Oct 14, 2021
1 parent 1a6568f commit d83eee2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 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
* [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.

## [2.17.1] - 2021-10-13
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
@Component
private ResourceManager resourceManager;

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

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

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

Expand Down Expand Up @@ -147,6 +153,11 @@ public final void execute() throws MojoExecutionException {
}

private void execute(FormatterFactory formatterFactory) throws MojoExecutionException {
if (skip) {
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
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,6 @@

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;
Expand All @@ -30,16 +29,9 @@
*/
@Mojo(name = "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
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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 @@ -36,16 +35,8 @@
@Mojo(name = "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

0 comments on commit d83eee2

Please sign in to comment.