mathieucarbou / license-maven-plugin

Manage license headers in your source files
https://oss.carbou.me/license-maven-plugin/
Apache License 2.0
240 stars 86 forks source link

Duplicated header in POM.xml after run format #153

Open cvgaviao opened 5 years ago

cvgaviao commented 5 years ago

I've set the license-maven-plugin in a profile in order to work with a custom header:

                        <inlineHeader>
======================================================================
Copyright © ${license.git.copyrightYears}, ${owner}.

All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html

=======================================================================
                        </inlineHeader>

I also set the mapping for pom.xml:

                        <mapping>
                            <pom.xml>XML_PER_LINE</pom.xml>
                            <xml>XML_STYLE</xml>
                            <store>TXT_STYLE</store>
                        </mapping>

But when I try to use it I'm ending with a duplicating header. In the example below I just changed the owner:


<!-- ======================================================================    -->
<!-- Copyright © 2015-2019, Cristiano V. Gavião.                      -->
<!--                                                                           -->
<!-- All rights reserved. This program and the accompanying materials          -->
<!-- are made available under the terms of the Eclipse Public License v1.0     -->
<!-- which accompanies this distribution, and is available at                  -->
<!-- http://www.eclipse.org/legal/epl-v10.html                                 -->
<!--                                                                           -->
<!-- =======================================================================   -->

<!-- ======================================================================    -->
<!-- Copyright © 2015-2019, Cristiano Gavião, C8 Technology ME.                      -->
<!--                                                                           -->
<!-- All rights reserved. This program and the accompanying materials          -->
<!-- are made available under the terms of the Eclipse Public License v1.0     -->
<!-- which accompanies this distribution, and is available at                  -->
<!-- http://www.eclipse.org/legal/epl-v10.html                                 -->
<!--                                                                           -->
<!-- =======================================================================   -->
mathieucarbou commented 3 years ago

not an issue: plugin is copying teh exact same number of space character from the inlineHeader section. We do not dynamically compute the number of space characters to add. This is given by the user config.

oscarbrookssynacor commented 5 months ago

I think this is an issue actually, I don't think the OP meant the problem was with the number of spaces. Why does the plugin generate duplicate licenses? It does this even when using <skipExistingHeaders>true</skipExistingHeaders>. It seems like the issue is with detecting whether the license already exists when using <inlineHeader>

hazendaz commented 5 months ago

@oscarbrookssynacor Can you make a small reproducible build for the issue?

oscarbrookssynacor commented 5 months ago

Hi, thanks for the quick reply, I will work on one, but in the meantime, maybe this will suffice. Simply adding the following to the pom

        <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <!-- https://mvnrepository.com/artifact/com.mycila/license-maven-plugin -->
        <version>4.3</version>
        <configuration>
            <properties>
                <license.owner>Sample Owner</license.owner>
                <license.years>2024</license.years>
                <beginBlock>***** BEGIN LICENSE BLOCK *****${line.separator}</beginBlock>
                <product>Sample Product.${line.separator}</product>
                <copyright>Copyright (C) ${license.years} ${license.owner} </copyright>
                <rights>All Rights Reserved.${line.separator}</rights>
                <endBlock>***** END LICENSE BLOCK *****</endBlock>
            </properties>
            <skipExistingHeaders>true</skipExistingHeaders>
            <licenseSets>
                <licenseSet>
                    <inlineHeader>
                        <![CDATA[${beginBlock} ${product} ${copyright} ${rights} ${endBlock}]]>
                    </inlineHeader>
                    <includes>
                        <include>src/*/java/**/*.java</include>
                    </includes>
                </licenseSet>
            </licenseSets>

        </configuration>
        <executions>
            <execution>
                <id>first</id>
                <goals>
                    <goal>format</goal>
                </goals>
                <phase>generate-sources</phase>
            </execution>
        </executions>
    </plugin>

, running mvn install and then changing anything about the license, such as the year for example <license.years>2025</license.years> will result in a duplicate license. Running the same thing with a .txt file based license does not.

oscarbrookssynacor commented 5 months ago

or to simplify further,

<plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>4.3</version>
        <configuration>
            <properties>
                <license.owner>Sample Owner</license.owner>
                <license.years>2024</license.years>
            </properties>
            <skipExistingHeaders>true</skipExistingHeaders>
            <licenseSets>
                <licenseSet>
                    <inlineHeader>testInlineLicense</inlineHeader>
                    <includes>
                        <include>src/*/java/**/*.java</include>
                    </includes>
                </licenseSet>
            </licenseSets>

        </configuration>
        <executions>
            <execution>
                <id>first</id>
                <goals>
                    <goal>format</goal>
                </goals>
                <phase>generate-sources</phase>
            </execution>
        </executions>
    </plugin>

mvn install followed by updating the string to <inlineHeader>testInlineLicense**2**</inlineHeader> or any different string and reruningmvn install