Skip to content

Commit d216989

Browse files
committed
Allow whitespaces in new line
1 parent 6e73b6b commit d216989

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/functionalTest/groovy/org/cadixdev/gradle/licenser/LicenserPluginFunctionalTest.groovy

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,47 @@ class LicenserPluginFunctionalTest extends Specification {
125125
[gradleVersion, _, extraArgs] << testMatrix
126126
}
127127
128+
@Unroll
129+
def "allow spaces in new line at checkLicenses task (gradle #gradleVersion)"() {
130+
given:
131+
def projectDir = temporaryFolder.newFolder()
132+
def sourceDir = projectDir.toPath().resolve(Paths.get("src", "main", "java", "com", "example")).toFile()
133+
sourceDir.mkdirs()
134+
new File(projectDir, "header.txt") << "Copyright header"
135+
new File(projectDir, "settings.gradle") << ""
136+
new File(projectDir, "build.gradle") << """
137+
plugins {
138+
id('java')
139+
id('org.cadixdev.licenser')
140+
}
141+
142+
license {
143+
lineEnding = '\\n'
144+
header = project.file('header.txt')
145+
}
146+
""".stripIndent()
147+
148+
new File(sourceDir, "MyClass.java") << String.join("\n",
149+
"/*",
150+
" * Copyright header",
151+
" */",
152+
" ", // allow spaces
153+
"package com.example;",
154+
"",
155+
"class MyClass {}",
156+
""
157+
)
158+
159+
when:
160+
def result = runner(projectDir, gradleVersion, extraArgs + "checkLicenses").build()
161+
162+
then:
163+
result.task(":checkLicenses").outcome == TaskOutcome.SUCCESS
164+
165+
where:
166+
[gradleVersion, _, extraArgs] << testMatrix
167+
}
168+
128169
@Unroll
129170
def "skips existing headers in updateLicenses task (gradle #gradleVersion)"() {
130171
given:

src/main/groovy/org/cadixdev/gradle/licenser/header/PreparedCommentHeader.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class PreparedCommentHeader implements PreparedHeader {
4949
if (result) {
5050
def line = reader.readLine()
5151
if (header.newLine.get()) {
52-
result = line != null && line.isEmpty()
52+
result = line != null && line.trim().isEmpty()
5353
} else if (line != null) {
5454
result = !line.isEmpty()
5555
}
@@ -215,7 +215,7 @@ class PreparedCommentHeader implements PreparedHeader {
215215
if (valid) {
216216
if (header.newLine.get()) {
217217
// Only valid if next line is empty
218-
valid = last != null && last.isEmpty()
218+
valid = last != null && last.trim().isEmpty()
219219
} else if (last != null) {
220220
// Only valid if next line is NOT empty
221221
valid = !HeaderHelper.isBlank(last)

0 commit comments

Comments
 (0)