Skip to content

Commit

Permalink
Allow licence header to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
goughy000 authored and Jack Gough committed Feb 15, 2021
1 parent e3a35d8 commit 901dfc8
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
@@ -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 Down Expand Up @@ -159,7 +159,7 @@ private Runtime(String licenseHeader, String delimiter, String yearSeparator, bo
}
// sanitize the input license
licenseHeader = LineEnding.toUnix(licenseHeader);
if (!licenseHeader.endsWith("\n")) {
if (!licenseHeader.isEmpty() && !licenseHeader.endsWith("\n")) {
licenseHeader = licenseHeader + "\n";
}
this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE);
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 Down Expand Up @@ -112,6 +112,13 @@ public void should_apply_license_containing_YEAR_token_with_custom_separator() t
.test(hasHeaderYear("not a year"), hasHeaderYear(currentYear()));
}

@Test
public void should_remove_header_when_empty() throws Throwable {
StepHarness.forStep(LicenseHeaderStep.headerDelimiter("", package_).build())
.testUnaffected(getTestResource("license/MissingLicense.test"))
.test(getTestResource("license/HasLicense.test"), getTestResource("license/MissingLicense.test"));
}

private String header(String contents) throws IOException {
return "/*\n" +
" * " + contents + "\n" +
Expand Down

0 comments on commit 901dfc8

Please sign in to comment.