From e19bc6739c12c440e1b850bfba8e8b0876f6148d Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Fri, 30 Dec 2022 11:44:58 +0100 Subject: [PATCH 1/8] add support for skipping first few lines matching a pattern --- .../spotless/generic/LicenseHeaderStep.java | 69 ++++++++++++++----- .../gradle/spotless/FormatExtension.java | 6 ++ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 6a34c0882..5345adc15 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -51,7 +51,7 @@ public static LicenseHeaderStep headerDelimiter(String header, String delimiter) } public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier headerLazy, String delimiter) { - return new LicenseHeaderStep(null, null, headerLazy, delimiter, DEFAULT_YEAR_DELIMITER, () -> YearMode.PRESERVE); + return new LicenseHeaderStep(null, null, headerLazy, delimiter, DEFAULT_YEAR_DELIMITER, () -> YearMode.PRESERVE, null); } final String name; @@ -60,14 +60,16 @@ public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier head final String delimiter; final String yearSeparator; final Supplier yearMode; + final @Nullable String skipLinesPattern; - private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode) { + private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode, @Nullable String skipLinesPattern) { this.name = sanitizeName(name); - this.contentPattern = sanitizeContentPattern(contentPattern); + this.contentPattern = sanitizePattern(contentPattern); this.headerLazy = Objects.requireNonNull(headerLazy); this.delimiter = Objects.requireNonNull(delimiter); this.yearSeparator = Objects.requireNonNull(yearSeparator); this.yearMode = Objects.requireNonNull(yearMode); + this.skipLinesPattern = sanitizePattern(skipLinesPattern); } public String getName() { @@ -75,11 +77,11 @@ public String getName() { } public LicenseHeaderStep withName(String name) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withContentPattern(String contentPattern) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withHeaderString(String header) { @@ -87,15 +89,15 @@ public LicenseHeaderStep withHeaderString(String header) { } public LicenseHeaderStep withHeaderLazy(ThrowingEx.Supplier headerLazy) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withDelimiter(String delimiter) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withYearSeparator(String yearSeparator) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withYearMode(YearMode yearMode) { @@ -103,7 +105,11 @@ public LicenseHeaderStep withYearMode(YearMode yearMode) { } public LicenseHeaderStep withYearModeLazy(Supplier yearMode) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + } + + public LicenseHeaderStep withSkipLinesPattern(String skipLinesPattern) { + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public FormatterStep build() { @@ -112,7 +118,7 @@ public FormatterStep build() { if (yearMode.get() == YearMode.SET_FROM_GIT) { formatterStep = FormatterStep.createNeverUpToDateLazy(name, () -> { boolean updateYear = false; // doesn't matter - Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear); + Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); return FormatterFunc.needsFile(runtime::setLicenseHeaderYearsFromGitHistory); }); } else { @@ -130,7 +136,7 @@ public FormatterStep build() { default: throw new IllegalStateException(yearMode.toString()); } - return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear); + return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); }, step -> step::format); } @@ -156,18 +162,18 @@ private String sanitizeName(@Nullable String name) { } @Nullable - private String sanitizeContentPattern(@Nullable String contentPattern) { - if (contentPattern == null) { - return contentPattern; + private String sanitizePattern(@Nullable String pattern) { + if (pattern == null) { + return pattern; } - contentPattern = contentPattern.trim(); + pattern = pattern.trim(); - if (contentPattern.isEmpty()) { + if (pattern.isEmpty()) { return null; } - return contentPattern; + return pattern; } private static final String DEFAULT_NAME_PREFIX = LicenseHeaderStep.class.getName(); @@ -195,6 +201,7 @@ private static class Runtime implements Serializable { private static final long serialVersionUID = 1475199492829130965L; private final Pattern delimiterPattern; + private final @Nullable Pattern skipLinesPattern; private final String yearSepOrFull; private final @Nullable String yearToday; private final @Nullable String beforeYear; @@ -203,7 +210,7 @@ private static class Runtime implements Serializable { private final boolean licenseHeaderWithRange; /** The license that we'd like enforced. */ - private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest) { + private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest, @Nullable String skipLinesPattern) { if (delimiter.contains("\n")) { throw new IllegalArgumentException("The delimiter must not contain any newlines."); } @@ -213,6 +220,7 @@ private Runtime(String licenseHeader, String delimiter, String yearSeparator, bo licenseHeader = licenseHeader + "\n"; } this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE); + this.skipLinesPattern = skipLinesPattern == null ? null : Pattern.compile(skipLinesPattern); Optional yearToken = getYearToken(licenseHeader); if (yearToken.isPresent()) { @@ -254,6 +262,31 @@ private static Optional getYearToken(String licenseHeader) { /** Formats the given string. */ private String format(String raw) { + if (skipLinesPattern == null) { + return addOrUpdateLicenseHeader(raw); + } else { + String[] lines = raw.split("\n"); + StringBuilder skippedLinesBuilder = new StringBuilder(); + StringBuilder remainingLinesBuilder = new StringBuilder(); + boolean lastMatched = true; + for (String line : lines) { + if (lastMatched) { + Matcher matcher = skipLinesPattern.matcher(line); + if (matcher.find()) { + skippedLinesBuilder.append(line).append('\n'); + } else { + remainingLinesBuilder.append(line).append('\n'); + lastMatched = false; + } + } else { + remainingLinesBuilder.append(line).append('\n'); + } + } + return skippedLinesBuilder + addOrUpdateLicenseHeader(remainingLinesBuilder.toString()); + } + } + + private String addOrUpdateLicenseHeader(String raw) { Matcher contentMatcher = delimiterPattern.matcher(raw); if (!contentMatcher.find()) { throw new IllegalArgumentException("Unable to find delimiter regex " + delimiterPattern); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index de0313eab..84690bf06 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -462,6 +462,12 @@ public LicenseHeaderConfig yearSeparator(String yearSeparator) { return this; } + public LicenseHeaderConfig skipLinesPattern(String skipLinesPattern) { + builder = builder.withSkipLinesPattern(skipLinesPattern); + replaceStep(createStep()); + return this; + } + /** * @param updateYearWithLatest * Will turn {@code 2004} into {@code 2004-2020}, and {@code 2004-2019} into {@code 2004-2020} From 50e7cb01e05019c671e1411fb7c56f8bd7314f52 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Mon, 2 Jan 2023 19:34:54 +0100 Subject: [PATCH 2/8] apply license header updates --- .../java/com/diffplug/spotless/generic/LicenseHeaderStep.java | 2 +- .../main/java/com/diffplug/gradle/spotless/FormatExtension.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 5345adc15..d1fdf86e3 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 84690bf06..9c1e239d3 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From cf8bc0853f7cfa1364a12d076368bc099f9a9ef2 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Wed, 4 Jan 2023 21:15:57 +0100 Subject: [PATCH 3/8] =?UTF-8?q?rename=20skipLinesPattern=20to=20skip=C3=85?= =?UTF-8?q?LinesMatching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spotless/generic/LicenseHeaderStep.java | 36 +++++++++---------- .../gradle/spotless/FormatExtension.java | 4 +-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index d1fdf86e3..8a46e08bd 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -60,16 +60,16 @@ public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier head final String delimiter; final String yearSeparator; final Supplier yearMode; - final @Nullable String skipLinesPattern; + final @Nullable String skipLinesMatching; - private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode, @Nullable String skipLinesPattern) { + private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode, @Nullable String skipLinesMatching) { this.name = sanitizeName(name); this.contentPattern = sanitizePattern(contentPattern); this.headerLazy = Objects.requireNonNull(headerLazy); this.delimiter = Objects.requireNonNull(delimiter); this.yearSeparator = Objects.requireNonNull(yearSeparator); this.yearMode = Objects.requireNonNull(yearMode); - this.skipLinesPattern = sanitizePattern(skipLinesPattern); + this.skipLinesMatching = sanitizePattern(skipLinesMatching); } public String getName() { @@ -77,11 +77,11 @@ public String getName() { } public LicenseHeaderStep withName(String name) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withContentPattern(String contentPattern) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withHeaderString(String header) { @@ -89,15 +89,15 @@ public LicenseHeaderStep withHeaderString(String header) { } public LicenseHeaderStep withHeaderLazy(ThrowingEx.Supplier headerLazy) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withDelimiter(String delimiter) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withYearSeparator(String yearSeparator) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withYearMode(YearMode yearMode) { @@ -105,11 +105,11 @@ public LicenseHeaderStep withYearMode(YearMode yearMode) { } public LicenseHeaderStep withYearModeLazy(Supplier yearMode) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } - public LicenseHeaderStep withSkipLinesPattern(String skipLinesPattern) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + public LicenseHeaderStep withSkipLinesMatching(String skipLinesMatching) { + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public FormatterStep build() { @@ -118,7 +118,7 @@ public FormatterStep build() { if (yearMode.get() == YearMode.SET_FROM_GIT) { formatterStep = FormatterStep.createNeverUpToDateLazy(name, () -> { boolean updateYear = false; // doesn't matter - Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); + Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesMatching); return FormatterFunc.needsFile(runtime::setLicenseHeaderYearsFromGitHistory); }); } else { @@ -136,7 +136,7 @@ public FormatterStep build() { default: throw new IllegalStateException(yearMode.toString()); } - return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); + return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesMatching); }, step -> step::format); } @@ -201,7 +201,7 @@ private static class Runtime implements Serializable { private static final long serialVersionUID = 1475199492829130965L; private final Pattern delimiterPattern; - private final @Nullable Pattern skipLinesPattern; + private final @Nullable Pattern skipLinesMatching; private final String yearSepOrFull; private final @Nullable String yearToday; private final @Nullable String beforeYear; @@ -210,7 +210,7 @@ private static class Runtime implements Serializable { private final boolean licenseHeaderWithRange; /** The license that we'd like enforced. */ - private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest, @Nullable String skipLinesPattern) { + private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest, @Nullable String skipLinesMatching) { if (delimiter.contains("\n")) { throw new IllegalArgumentException("The delimiter must not contain any newlines."); } @@ -220,7 +220,7 @@ private Runtime(String licenseHeader, String delimiter, String yearSeparator, bo licenseHeader = licenseHeader + "\n"; } this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE); - this.skipLinesPattern = skipLinesPattern == null ? null : Pattern.compile(skipLinesPattern); + this.skipLinesMatching = skipLinesMatching == null ? null : Pattern.compile(skipLinesMatching); Optional yearToken = getYearToken(licenseHeader); if (yearToken.isPresent()) { @@ -262,7 +262,7 @@ private static Optional getYearToken(String licenseHeader) { /** Formats the given string. */ private String format(String raw) { - if (skipLinesPattern == null) { + if (skipLinesMatching == null) { return addOrUpdateLicenseHeader(raw); } else { String[] lines = raw.split("\n"); @@ -271,7 +271,7 @@ private String format(String raw) { boolean lastMatched = true; for (String line : lines) { if (lastMatched) { - Matcher matcher = skipLinesPattern.matcher(line); + Matcher matcher = skipLinesMatching.matcher(line); if (matcher.find()) { skippedLinesBuilder.append(line).append('\n'); } else { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 9c1e239d3..b8344c385 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -462,8 +462,8 @@ public LicenseHeaderConfig yearSeparator(String yearSeparator) { return this; } - public LicenseHeaderConfig skipLinesPattern(String skipLinesPattern) { - builder = builder.withSkipLinesPattern(skipLinesPattern); + public LicenseHeaderConfig skipLinesMatching(String skipLinesMatching) { + builder = builder.withSkipLinesMatching(skipLinesMatching); replaceStep(createStep()); return this; } From 3a3583b836815c6b431fdce0ddd9a9ea3af03a81 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Wed, 4 Jan 2023 22:16:49 +0100 Subject: [PATCH 4/8] add maven support --- .../java/com/diffplug/spotless/generic/LicenseHeaderStep.java | 2 +- .../com/diffplug/spotless/maven/generic/LicenseHeader.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 8a46e08bd..46312ca07 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -108,7 +108,7 @@ public LicenseHeaderStep withYearModeLazy(Supplier yearMode) { return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } - public LicenseHeaderStep withSkipLinesMatching(String skipLinesMatching) { + public LicenseHeaderStep withSkipLinesMatching(@Nullable String skipLinesMatching) { return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java index ee2ae4fda..22386c689 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java @@ -37,6 +37,9 @@ public class LicenseHeader implements FormatterStepFactory { @Parameter private String delimiter; + @Parameter + private String skipLinesMatching; + @Override public final FormatterStep newFormatterStep(FormatterStepConfig config) { String delimiterString = delimiter != null ? delimiter : config.getLicenseHeaderDelimiter(); @@ -53,6 +56,7 @@ public final FormatterStep newFormatterStep(FormatterStepConfig config) { } return LicenseHeaderStep.headerDelimiter(() -> readFileOrContent(config), delimiterString) .withYearMode(yearMode) + .withSkipLinesMatching(skipLinesMatching) .build() .filterByFile(LicenseHeaderStep.unsupportedJvmFilesFilter()); } else { From 8e1fb53059778d37e67d8814c3eb4e7f8fabbc2f Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sat, 7 Jan 2023 21:50:46 +0100 Subject: [PATCH 5/8] add test for skipLinesMatching setting of license header step --- testlib/src/main/resources/license/SkipLines.test | 9 +++++++++ .../main/resources/license/SkipLinesHasLicense.test | 13 +++++++++++++ .../spotless/generic/LicenseHeaderStepTest.java | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 testlib/src/main/resources/license/SkipLines.test create mode 100644 testlib/src/main/resources/license/SkipLinesHasLicense.test diff --git a/testlib/src/main/resources/license/SkipLines.test b/testlib/src/main/resources/license/SkipLines.test new file mode 100644 index 000000000..4048868ac --- /dev/null +++ b/testlib/src/main/resources/license/SkipLines.test @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/testlib/src/main/resources/license/SkipLinesHasLicense.test b/testlib/src/main/resources/license/SkipLinesHasLicense.test new file mode 100644 index 000000000..f645c5b2e --- /dev/null +++ b/testlib/src/main/resources/license/SkipLinesHasLicense.test @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java index 137937beb..785c1c528 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java @@ -122,6 +122,13 @@ void should_remove_header_when_empty() throws Throwable { .test(getTestResource("license/HasLicense.test"), getTestResource("license/MissingLicense.test")); } + @Test + void should_skip_lines_matching_predefined_pattern() throws Throwable { + StepHarness.forStep(LicenseHeaderStep.headerDelimiter("", "^(?!", "^(?!