Skip to content

Commit

Permalink
Fix #219 - Replacing a step no longer triggers early evaluation (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Feb 10, 2019
1 parent 0ab6802 commit 220b374
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Provided eclipse-wtp formatters in generic formatter extension. ([#325](https://github.com/diffplug/spotless/pull/325)). This change obsoletes the CSS and XML extensions.
* Improved configuration times for large projects (thanks to @oehme for finding [#348](https://github.com/diffplug/spotless/pull/348)).
* Updated default google-java-format from 1.5 to 1.7 ([#335](https://github.com/diffplug/spotless/issues/335)).
* Replacing a step no longer triggers early evaluation ([#219](https://github.com/diffplug/spotless/issues/219)).

### Version 3.17.0 - December 13th 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.17.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.17.0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,29 +209,39 @@ private static void relativizeIfSubdir(List<String> relativePaths, File root, Fi
/** Adds a new step. */
public void addStep(FormatterStep newStep) {
Objects.requireNonNull(newStep);
FormatterStep existing = getExistingStep(newStep.getName());
if (existing != null) {
int existingIdx = getExistingStepIdx(newStep.getName());
if (existingIdx != -1) {
throw new GradleException("Multiple steps with name '" + newStep.getName() + "' for spotless format '" + formatName() + "'");
}
steps.add(newStep);
}

/** Returns the existing step with the given name, if any. */
@Deprecated
protected @Nullable FormatterStep getExistingStep(String stepName) {
return steps.stream() //
.filter(step -> stepName.equals(step.getName())) //
.findFirst() //
.orElse(null);
}

/** Returns the index of the existing step with the given name, or -1 if no such step exists. */
protected int getExistingStepIdx(String stepName) {
for (int i = 0; i < steps.size(); ++i) {
if (steps.get(i).getName().equals(stepName)) {
return i;
}
}
return -1;
}

/** Replaces the given step. */
protected void replaceStep(FormatterStep replacementStep) {
FormatterStep existing = getExistingStep(replacementStep.getName());
if (existing == null) {
int existingIdx = getExistingStepIdx(replacementStep.getName());
if (existingIdx == -1) {
throw new GradleException("Cannot replace step '" + replacementStep.getName() + "' for spotless format '" + formatName() + "' because it hasn't been added yet.");
}
int index = steps.indexOf(existing);
steps.set(index, replacementStep);
steps.set(existingIdx, replacementStep);
}

/** Clears all of the existing steps. */
Expand Down

0 comments on commit 220b374

Please sign in to comment.