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 2b054ce
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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

0 comments on commit 2b054ce

Please sign in to comment.