Skip to content

Commit

Permalink
Rewrote LicenseHeaderStep in terms of FormatterStep.Strict.
Browse files Browse the repository at this point in the history
Note that in the case where the license header and delimiter are supplied as strings, it makes sense to store the state eagerly, whereas when the license header is supplied in a file, we load that file lazily, only if we actually need to.
  • Loading branch information
nedtwigg committed Nov 1, 2016
1 parent c1357f5 commit 51f0531
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ public void indentWithTabs() {
* Spotless will look for a line that starts with this to know what the "top" is.
*/
public void licenseHeader(String licenseHeader, String delimiter) {
customLazy(LicenseHeaderStep.NAME, () -> new LicenseHeaderStep(licenseHeader, delimiter)::format);
steps.add(FormatterStep.create(LicenseHeaderStep.NAME,
new LicenseHeaderStep(licenseHeader, delimiter),
LicenseHeaderStep::format));
}

/**
Expand All @@ -273,7 +275,9 @@ public void licenseHeader(String licenseHeader, String delimiter) {
* Spotless will look for a line that starts with this to know what the "top" is.
*/
public void licenseHeaderFile(Object licenseHeaderFile, String delimiter) {
customLazy(LicenseHeaderStep.NAME, () -> new LicenseHeaderStep(getProject().file(licenseHeaderFile), getEncoding(), delimiter)::format);
steps.add(FormatterStep.createLazy(LicenseHeaderStep.NAME,
() -> new LicenseHeaderStep(getProject().file(licenseHeaderFile), getEncoding(), delimiter),
LicenseHeaderStep::format));
}

/** Sets up a format task according to the values in this extension. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -26,7 +27,9 @@
import org.gradle.api.GradleException;

/** Prefixes a license header before the package statement. */
public class LicenseHeaderStep {
public class LicenseHeaderStep implements Serializable {
private static final long serialVersionUID = 1L;

public static final String NAME = "LicenseHeader";

private final String license;
Expand Down

0 comments on commit 51f0531

Please sign in to comment.