Skip to content

Commit

Permalink
Configurable failOnDryRunResults (#52)
Browse files Browse the repository at this point in the history
* prevent dryRun from caching output so output generation always produces an actionable result
  • Loading branch information
aegershman authored May 6, 2021
1 parent 43b17b1 commit a1e6453
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class AbstractRewriteTask extends DefaultTask implements Rewrite

private final Configuration configuration;
private final SourceSet sourceSet;
private final RewriteExtension extension;
protected final RewriteExtension extension;
private final RewriteReflectiveFacade rewrite;

public AbstractRewriteTask(Configuration configuration, SourceSet sourceSet, RewriteExtension extension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package org.openrewrite.gradle;

import org.gradle.api.GradleException;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.specs.Specs;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskAction;
Expand All @@ -43,6 +45,7 @@ public RewriteDryRunTask(Configuration configuration, SourceSet sourceSet, Rewri
super(configuration, sourceSet, extension);
setGroup("rewrite");
setDescription("Dry run the active refactoring recipes to sources within the " + sourceSet.getName() + " SourceSet. No results will be made.");
getOutputs().upToDateWhen(Specs.SATISFIES_NONE);
}

@Override
Expand Down Expand Up @@ -108,6 +111,10 @@ public void run() {
getLog().warn("Report available:");
getLog().warn(indent(1, patchFile.normalize().toString()));
getLog().warn("Run 'mvn rewrite:run' to apply the recipes.");

if (extension.getFailOnDryRunResults()) {
throw new GradleException("Applying recipes would make changes. See logs for more details.");
}
}
}
}
11 changes: 11 additions & 0 deletions plugin/src/main/java/org/openrewrite/gradle/RewriteExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class RewriteExtension extends CodeQualityExtension {
*/
private boolean failOnInvalidActiveRecipes = false;

private boolean failOnDryRunResults = false;

@SuppressWarnings("unused")
public RewriteExtension(Project project) {
this.project = project;
Expand Down Expand Up @@ -139,4 +141,13 @@ public boolean getFailOnInvalidActiveRecipes() {
public void setFailOnInvalidActiveRecipes(boolean failOnInvalidActiveRecipes) {
this.failOnInvalidActiveRecipes = failOnInvalidActiveRecipes;
}

public boolean getFailOnDryRunResults() {
return this.failOnDryRunResults;
}

public void setFailOnDryRunResults(boolean failOnDryRunResults) {
this.failOnDryRunResults = failOnDryRunResults;
}

}

0 comments on commit a1e6453

Please sign in to comment.