Skip to content

Commit

Permalink
Allow whitespaces in new line
Browse files Browse the repository at this point in the history
  • Loading branch information
sdorra committed Nov 5, 2021
1 parent 6e73b6b commit d216989
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,47 @@ class LicenserPluginFunctionalTest extends Specification {
[gradleVersion, _, extraArgs] << testMatrix
}
@Unroll
def "allow spaces in new line at checkLicenses task (gradle #gradleVersion)"() {
given:
def projectDir = temporaryFolder.newFolder()
def sourceDir = projectDir.toPath().resolve(Paths.get("src", "main", "java", "com", "example")).toFile()
sourceDir.mkdirs()
new File(projectDir, "header.txt") << "Copyright header"
new File(projectDir, "settings.gradle") << ""
new File(projectDir, "build.gradle") << """
plugins {
id('java')
id('org.cadixdev.licenser')
}

license {
lineEnding = '\\n'
header = project.file('header.txt')
}
""".stripIndent()
new File(sourceDir, "MyClass.java") << String.join("\n",
"/*",
" * Copyright header",
" */",
" ", // allow spaces
"package com.example;",
"",
"class MyClass {}",
""
)
when:
def result = runner(projectDir, gradleVersion, extraArgs + "checkLicenses").build()
then:
result.task(":checkLicenses").outcome == TaskOutcome.SUCCESS
where:
[gradleVersion, _, extraArgs] << testMatrix
}
@Unroll
def "skips existing headers in updateLicenses task (gradle #gradleVersion)"() {
given:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PreparedCommentHeader implements PreparedHeader {
if (result) {
def line = reader.readLine()
if (header.newLine.get()) {
result = line != null && line.isEmpty()
result = line != null && line.trim().isEmpty()
} else if (line != null) {
result = !line.isEmpty()
}
Expand Down Expand Up @@ -215,7 +215,7 @@ class PreparedCommentHeader implements PreparedHeader {
if (valid) {
if (header.newLine.get()) {
// Only valid if next line is empty
valid = last != null && last.isEmpty()
valid = last != null && last.trim().isEmpty()
} else if (last != null) {
// Only valid if next line is NOT empty
valid = !HeaderHelper.isBlank(last)
Expand Down

0 comments on commit d216989

Please sign in to comment.