Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trimHeaderLine removes empty lines from license text in html files #347

Open
heapifyman opened this issue Jul 29, 2019 · 6 comments
Open

Comments

@heapifyman
Copy link
Contributor

Assume your license text looks like this (with a blank line somewhere in the middle):

first line of license

second line
third line

If you set trimHeaderLine=true license-maven-plugin will correctly trim trailing white spaces in Java files (and all other file types where each line of the resulting license header is starting with a comment symbol), e.g.:

/*-
 * #%L
 * foo
 * %%
 * Copyright (C) 2018 - 2019 bar
 * %%
 * first line of license
 * 
 * second line
 * third line
 * #L%
 */

But in html files, the blank line will be removed when running the update-file-header goal a second time.

Result of first run - no trailing white spaces, blank line still included:

<!--
  #%L
  foo
  %%
  Copyright (C) 2018 - 2019 bar
  %%
  first line of license

  second line
  third line
  #L%
  -->

Result of second run - no trailing white spaces, but blank line is removed:

<!--
  #%L
  foo
  %%
  Copyright (C) 2018 - 2019 bar
  %%
  first line of license
  second line
  third line
  #L%
  -->

When setting trimHeaderLine=false, the license header will not change between runs for html files.
Unfortunately, then you get a trailing whitespace at the empty line in the license header of java files. And then checkstyle complains...

@ppalaga
Copy link
Contributor

ppalaga commented Jul 29, 2019

It would be highly welcome if a volunteer could extend update-file-header-test-mojo integration test to reproduce the named scenario:

  • Add an HTML file to the test project
  • Add an execution to the plugin config so that the mojo is run twice on the same HTML file.
  • Add an appropriate assertion to postbuild.groovy

@heapifyman
Copy link
Contributor Author

I could not reproduce the bug in the integration test.

But I attach here a minimal example project license-test.zip, which demonstrates it. Just unzip and run mvn clean compile.

It seems that the issue is somehow related to the setting canUpdateDescription because when I comment out that setting, the bug does not manifest itself.

@heapifyman
Copy link
Contributor Author

I could not reproduce the bug in the integration test.

Meaning, I am not familiar enough with this project's test framework. I am not really sure what needs to be changed to create the necessary tests and assertions.

Any hints?

@wildcart
Copy link

I am currently integrating this plugin into our build pipeline to update license headers and create the THIRD-PARTY file when I came across the same issue affecting XML files.

I decided to comment on this issue rather than creating a new issue because it is the exact same issue. I can open a new issue if needed.

Thanks for your work, providing this plugin.

@wildcart
Copy link

I found another affect related to this issue: I set copyrightStringFormat in the plugin's configuration adding a single character prefix before Copyright, the character added to prefix Copyright doesn't matter. With above settings, the single character prefix will be removed when the update-file-header is run a second time.

The Complete plugin configuration. It's an empty project (packaging: jar) and the POM includes/configures only this single plugin, no dependencies or other plugins. The project contain a single properties file in src/main/resources:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>license-maven-plugin</artifactId>
    <version>2.3.0</version>
    <executions>
        <execution>
            <id>update-file-license-header</id>
            <goals>
                <goal>update-file-header</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <licenseName>apache_v2</licenseName>
                <trimHeaderLine>true</trimHeaderLine>
                <canUpdateCopyright>true</canUpdateCopyright>
                <canUpdateDescription>true</canUpdateDescription>
                <canUpdateLicense>true</canUpdateLicense>
                <copyrightStringFormat>
                     - Copyright (C) %1$s %2$s
                </copyrightStringFormat>
            </configuration>
        </execution>
    </executions>
</plugin>

This is the complete plugin configuration I am using and changing canUpdateDescription to false fixes the issue. Changing trimHeaderLine does not have any effect.

License header in a properties file after the first run:

###
# #%L
# projectName
# %%
# - Copyright (C) 2023 copyrightHolder
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# #L%
###

License header in the same properties file after the second run (notice the missing - before Copyright in line 5:

###
# #%L
# projectName
# %%
# Copyright (C) 2023 copyrightHolder
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# #L%
###

@wildcart
Copy link

I've found a similar issue related to copyrightStringFormat when the header.txt of a custom license is updated. In this case, the values of canUpdateDescription and trimHeaderLine don't have any affect on the observed behavior. This leads me to believe that the issues are not connected and I will create a new issue to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants