diff --git a/src/functionalTest/groovy/org/cadixdev/gradle/licenser/LicenserPluginFunctionalTest.groovy b/src/functionalTest/groovy/org/cadixdev/gradle/licenser/LicenserPluginFunctionalTest.groovy index afb9943..a54a06a 100644 --- a/src/functionalTest/groovy/org/cadixdev/gradle/licenser/LicenserPluginFunctionalTest.groovy +++ b/src/functionalTest/groovy/org/cadixdev/gradle/licenser/LicenserPluginFunctionalTest.groovy @@ -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: diff --git a/src/main/groovy/org/cadixdev/gradle/licenser/header/PreparedCommentHeader.groovy b/src/main/groovy/org/cadixdev/gradle/licenser/header/PreparedCommentHeader.groovy index 2850705..f1b415d 100644 --- a/src/main/groovy/org/cadixdev/gradle/licenser/header/PreparedCommentHeader.groovy +++ b/src/main/groovy/org/cadixdev/gradle/licenser/header/PreparedCommentHeader.groovy @@ -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() } @@ -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)