Giter Site home page Giter Site logo

mathieucarbou / license-maven-plugin Goto Github PK

View Code? Open in Web Editor NEW
237.0 237.0 86.0 3.93 MB

Manage license headers in your source files

Home Page: https://oss.carbou.me/license-maven-plugin/

License: Apache License 2.0

Java 93.52% JavaScript 0.10% PHP 0.02% Ruby 0.06% FreeMarker 0.29% Dockerfile 0.15% Groovy 2.64% Classic ASP 0.36% VBA 0.28% Batchfile 0.30% Pascal 0.28% E 0.01% ColdFusion 0.29% Emacs Lisp 0.29% Fortran 0.27% Forth 0.01% Fluent 0.29% Haml 0.28% Lua 0.29% Mustache 0.28%

license-maven-plugin's Introduction

License Maven Plugin

Quick Links

Quick Tip

Often necessary to exclude a number of files that would otherwise grow the exclusion list on setup and do not fit with the default exclusions provided by this plugin. To exclude complete sections, please into a special folder to do exactly that.

**/unlicensed/**

license-maven-plugin's People

Contributors

adamretter avatar ankon avatar christopherlakey avatar ctubbsii avatar dbwiddis avatar dependabot[bot] avatar djaytan avatar eincs avatar frank-wagner-ibm avatar hazendaz avatar hgschmie avatar jdhoek avatar jfim avatar jgerken avatar liry avatar masakimu avatar mathieucarbou avatar mcculls avatar mcfoggy avatar michael-simons avatar mirabilos avatar peterlynch avatar ppalaga avatar renovate[bot] avatar scordio avatar sebhoss avatar shane-hp avatar teabot avatar uyw4687 avatar yoosiba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

license-maven-plugin's Issues

The plugin is too eater with content immediatelly after the header on a properties file

https://code.google.com/p/maven-license-plugin/issues/detail?id=118

Reported by [email protected], Feb 18, 2013
I detected many case, this for instance:

https://code.google.com/p/lmf/source/diff?spec=svn8fc59b6223775d1d5a53af9bd45ec96adb34f38c&name=8fc59b622377&r=8fc59b6223775d1d5a53af9bd45ec96adb34f38c&format=side&path=/kiwi/kiwi-triplestore/src/main/resources/org/apache/marmotta/kiwi/persistence/h2/statements.properties

Where the plugin removes some actual lines of the file when they are immediately after the header of a properties file.

An empty line solves the problem, but this is quite dangerous.

Use pom 2

  • property to generate other urls and so on
  • New license plugin
  • Fix SCM
  • Maven reports / site
  • Issue tracking
  • Ci Management

The year property is not taken into account

As per the documentation, this is possible to set the year:

<properties>
    <owner>Mycila</owner>
    <year>${project.inceptionYear}</year>
    <email>[email protected]</email>
</properties>

However, the ${project.inceptionYear} value is always taken into account even if the year property is specified.

tests are failing on windows

On windows some tests are failing as exemple RemoveMojoTest#test_remove_script_style.

The errors are mainly because loaded files contain \r\n whereas the test itself checks against \n.
Of course changing the tested string to r\n corrects the behavior, but why the hell is it working under linux boxes of travis-ci?

Add removeTrailingSpaces option

https://code.google.com/p/maven-license-plugin/issues/detail?id=93

Reported by [email protected], Feb 3, 2011

Blank lines in the header files are never indented. Thus, one always gets the following (spaces denoted by '.'):

/**
.*.You.may.obtain.a.copy.of.the.License.at
.*
.*...http://www.apache.org/licenses/LICENSE-2.0
.*/

Its impossible to obtain the following (note the extra '.' on the otherwise blank line):

/**
.*.You.may.obtain.a.copy.of.the.License.at
.*.
.*...http://www.apache.org/licenses/LICENSE-2.0
.*/

This is the case even if the line is just blank, but not empty, i.e., if it does contain some whitespace; the whitespace is always stripped.

Probably an option like would be useful, in addition to preserving all whitespace found in the header file.

Feb 3, 2011 Delete comment Project Member 1 mathieu.carbou

Hi,
This is something that has been added after an issue request because a lot of IDEs are removing unused spaces at the end of the lines. Thus the second header may be transformed by your IDE in the first header. That's why unused spaces are removed.

Feb 3, 2011 Delete comment 3 [email protected]

For the record and the benefit of others: issue 32 requested removal of trailing whitespaces. That being said, it would be great if this were configurable (with true being the default).

Feb 3, 2011 Delete comment Project Member 4 mathieu.carbou

Yes good idea. An option would be the best. I fear I won't have any time this week to check all issues. If you have a patch ready it would accelerate it.
Mat'

HeaderSection is not documented

The HeaderSection config class is not documented in the generated documentation nor does it appear in the mojo configuration (so my IDE can't autocomplete or validate it).

put header instide a pom.xml to support multi module projects and "path" to the header

In multi modules pom there is no easy way to use license-maven-plugin.

The problem is that placing the header in a file inside the root module, is accessible only from the root project. Only adding a property which refers to the root like this:

< headerUrl >${basedir}/..< / headerUrl >

for each child modules solves the problem.

My proposition is to add tag which allows placing CDATA string header inside the xml instead of file, then all child poms would have the same header. So no additional configuration in child poms would be necessary.

Provide a update-goal parameter: add if missing

Suppose you have a year mentioned in your header and your project is long lasting which means the code is produced over years.
If you change the year in your header, all files will be changed - not only the new ones. I understand this behaviour is needed in some use cases but is unwanted in the one described above.

skipLinePattern: bug or missundertsanding

Hi,

trying to define my own style for some proprietary file formats, I could not skip correctly first lines of my file.
Then I started to debug HeaderParser#findBeginPosition and found the line
while (line != null && !headerDefinition.isSkipLine(line))
why is there a negation before isSkipLine? shouldn't it be the exact opposite, in pseudo code while ( current line has to be skipped ) read next line

Did I incorrectly understood the usage of this skipLinePattern value, or is it a real bug?

Problem is easy to reproduce : for example in doc/doc9.xml duplicate the first line and relaunch HeaderParserTest. test_parsing_xml6() will now fail being unable to detect correctly the header because the 2 first lines where not correctly skipped.

Formatting not working at all!

For me, the formatting won't work at all! This is the output at the beginning of every java file. Am I doing something wrong?

/*
 * #%L
 * [...]
 * %%
 * Copyright (C) 2015 [...]
 * %%
 * 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%
 */

Configuration:

            <!-- License plugin -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <version>1.8</version>
                <configuration>
                    <roots>
                        <root>src/main/java</root>
                        <root>src/test</root>
                    </roots>
                    <licenseName>apache_v2</licenseName>
                    <inceptionYear>2015</inceptionYear>
                    <projectName>${project.name}</projectName>
                    <properties>
                        <owner>[...]</owner>
                        <email>[...]</email>
                    </properties>
                    <excludes>
                        <exclude>**/README</exclude>
                        <exclude>src/test/resources/**</exclude>
                        <exclude>src/main/resources/**</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>first</id>
                        <goals>
                            <goal>update-file-header</goal>
                        </goals>
                        <phase>process-sources</phase>
                    </execution>
                </executions>
            </plugin>

mvn license:remove NullPointerException

[ERROR] Failed to execute goal com.mycila:license-maven-plugin:2.5:remove (defau
lt-cli) on project macula-plugins-dist: Execution default-cli of goal com.mycila
:license-maven-plugin:2.5:remove failed. NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal c
om.mycila:license-maven-plugin:2.5:remove (default-cli) on project macula-plugin
s-dist: Execution default-cli of goal com.mycila:license-maven-plugin:2.5:remove
failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:224)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
ild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:318)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:414)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
357)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-c
li of goal com.mycila:license-maven-plugin:2.5:remove failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:115)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:208)
... 19 more
Caused by: java.lang.NullPointerException
at com.mycila.maven.plugin.license.header.HeaderParser.hasHeader(HeaderP
arser.java:141)
at com.mycila.maven.plugin.license.header.HeaderParser.(HeaderPars
er.java:62)
at com.mycila.maven.plugin.license.document.Document.parseHeader(Documen
t.java:130)
at com.mycila.maven.plugin.license.LicenseRemoveMojo.remove(LicenseRemov
eMojo.java:54)
at com.mycila.maven.plugin.license.LicenseRemoveMojo.access$0(LicenseRem
oveMojo.java:53)
at com.mycila.maven.plugin.license.LicenseRemoveMojo$1.onHeaderNotFound(
LicenseRemoveMojo.java:42)
at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run(AbstractLic
enseMojo.java:285)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutio
nException

Check goal not executed as expected

Hi,

I use the following config in my pom:

<plugin>
    <groupId>com.mycila.maven-license-plugin</groupId>
    <artifactId>maven-license-plugin</artifactId>
    <configuration>
        <header>./header.txt</header>
        <aggregate>true</aggregate>
        <excludes>
            <exclude>**/src/test/resources/**</exclude>
            <exclude>**/*.csv</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <id>check-headers</id>
            <phase>verify</phase>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

However, when I run mvn verify no check is performed. Am I missing something?

Text File License

I am trying to use this plugin for license files. I have successfully set it up to look over all my *.java files and ensure the license info is in the header. My project requirements also dictate that I have a LICENSE.txt file in the bundle as well. I am having a difficult time getting your plugin to see this file.

I believe I have the structure set up properly,

project
    -->src
    -->META-INF
    pom.xml
    LICENSE.txt

If I change the file to LICENSE.java, an error is returned (I have a poorly formatted file explicitly to cause the error so I can track its status). But when I change it back to the LICENSE.txt, no errors are produced. Is there something special I need to do to get the plugin to recognize a .txt file? is there a better format to use?

I have the following in the POM.xml

<configuration>
    <header>src-license.txt[/header>
    <strictCheck>true[/strictCheck>
    <includes>
        <include>**/*.java[/include>
        <include>**/LICENSE.txt[/include>
     </includes>
     <excludes>
         <exclude>**/misc/[/exclude>
        <exclude>**/docs/[/exclude>
         ....(more files paths)
     </excludes>
</configuration>

I am also using Version 1.9. If that is the source of the error that would be good to know as well. I wasnt on the project when that version got picked, but I can make the appropriate changes if this resolves in a higher version. I have however tried versions 2.3 and 2.5 to no avail. They both ignore the excludes fields, and print a warning to add 'strictCheck' to my pom.

Thank you for your assistance.

Handling of headers not on first line is inconsistent

Reported by sam.hendley, Oct 9, 2011

Intellij has issues refactoring scala code and this causes it to move the header text below the package definition line. This is an intellij issue clearly but it highlights some odd behaviors in the headers plugin. Basically the issue boils down to this, the "header detector" will find the header and consider the file "good" if the license is not the first lines in the file. However the remover and updater will not remove the old license. So while the license is static theres not much of an issue except the license text is not before the package statement. As soon as the text changes all of the misformatted files will end up getting duplicated headers (because it doesn't correctly delete the old header).

An intresting upshot of this bug is that we can use the license:remove goal to detect and manually fix these files. If we run "license:remove" twice, the first time it removes the licenses from all the correctly formatted files (and claims its removing the badly formatted licenses as well). If we run "license:remove" again it will detect all of the files with badly formatted headers and report that it is "Removing license header from: ..." but it will never actually remove the header.

I took a look at the code base, but it wasn't clear to me where the best place to fix this, maybe just a failure when the file is badly formatted in the "strictCheck" mode would help.

Example:

package org.test.scala;

/** HEADER_TEXT */

Error configuring includes

I tried setting a pattern for includes but the plugin doesn't seem to like it.

It throws the following error:
Cannot assign configuration entry 'includes' with value '*_/_java' of type java.lang.String to property of type java.lang.String[]

maven plugin config snippet:

*_/_java

The plugin doesn't support parallel build

Running:

mvn clean install -T 2C

Build failed with:

[ERROR] Failed to execute goal com.mycila:license-maven-plugin:2.6:check (default) on project XYZ: Execution default of goal com.mycila:license-maven-plugin:2.6:check failed: Error creating XMLDoc. Please verify that the input source can be read and is well formed: FWK005 parse may not be called while parsing. -> [Help 1]

Plugin doesn't work with Java 1.6

I just tried to include the plugin into the pom and run it with java 1.6 and I get this error:

ERROR] Failed to execute goal com.mycila:license-maven-plugin:2.5:check (default-cli) on project elasticsearch: Execution default-cli of goal com.mycila:license-maven-plugin:2.5:check failed: An API incompatibility was encountered while executing com.mycila:license-maven-plugin:2.5:check: java.lang.UnsupportedClassVersionError: com/mycila/xmltool/CallBack : Unsupported major.minor version 51.0

I tried version 2.3 as well as 2.4 and 2.5 and they all have the same problem. Its kind of a bummer though since we have minimum version of 1.6 in the project. I wonder if you can rebuild the package and redeploy a new version that works with 1.6? I assume you build with 1.7 which will produce incompatible class files... Running with 1.7 works just fine.

Access to current file name as property in header file

FROM: https://code.google.com/p/maven-license-plugin/issues/detail?id=67

In my company we use license header that has a name of the file in it. In
the end the license looks like:

// ******************************************************************
//
// SecretWorldHegemonyService.java
// Copyright 2010 XXX. All rights reserved.
// XXX PROPRIETARY/CONFIDENTIAL. Use is subject to license terms
//
// *****************************************************************

To my knowledge of Maven and license-plugin it's not possible to check or
generate such headers for all verified files. It could be great to use
variable in header's file, e.g. ${file_name} for that.

Encoding not used for reading license files.

https://code.google.com/p/maven-license-plugin/issues/detail?id=115

The specified encoding is only used to load and save project files that are updated with the license header. The header file itself is, however, loaded without using the encoding. In our case, this results in German umlauts not being displayed correctly.

Index: src/main/java/com/google/code/mojo/license/AbstractLicenseMojo.java
===================================================================
--- src/main/java/com/google/code/mojo/license/AbstractLicenseMojo.java (revision 470)
+++ src/main/java/com/google/code/mojo/license/AbstractLicenseMojo.java (working copy)
@@ -31,8 +31,10 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
+import org.xml.sax.InputSource;

 import java.io.File;
+import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -225,13 +227,13 @@
             }
             finder.setPluginClassPath(getClass().getClassLoader());

-            final Header h = new Header(finder.findResource(this.header), mergeProperties(), headerSections);
+            final Header h = new Header(finder.findResource(this.header), encoding, mergeProperties(), headerSections);
             debug("Header %s:\n%s", h.getLocation(), h);

             if (this.validHeaders == null) this.validHeaders = new String[0];
             final List<Header> validHeaders = new ArrayList<Header>(this.validHeaders.length);
             for (String validHeader : this.validHeaders)
-                validHeaders.add(new Header(finder.findResource(validHeader), mergeProperties(), headerSections));
+                validHeaders.add(new Header(finder.findResource(validHeader), encoding, mergeProperties(), headerSections));

             final DocumentFactory documentFactory = new DocumentFactory(basedir, buildMapping(), buildHeaderDefinitions(), encoding, keywords);

@@ -359,10 +361,16 @@
         final Map<String, HeaderDefinition> headers = new HashMap<String, HeaderDefinition>(HeaderType.defaultDefinitions());
         // and then override them with those provided in properties file
         for (String resource : headerDefinitions) {
-            final AdditionalHeaderDefinition fileDefinitions = new AdditionalHeaderDefinition(XMLDoc.from(finder.findResource(resource), true));
-            final Map<String, HeaderDefinition> map = fileDefinitions.getDefinitions();
-            debug("%d header definitions loaded from '%s'", map.size(), resource);
-            headers.putAll(map);
+            try {
+                InputSource source = new InputSource(finder.findResource(resource).openStream());
+                source.setEncoding(encoding);
+                final AdditionalHeaderDefinition fileDefinitions = new AdditionalHeaderDefinition(XMLDoc.from(source, true));
+                final Map<String, HeaderDefinition> map = fileDefinitions.getDefinitions();
+                debug("%d header definitions loaded from '%s'", map.size(), resource);
+                headers.putAll(map);
+            } catch (IOException ex) {
+                throw new MojoFailureException("Error reading header definition: " + resource, ex);
+            }
         }
         // force inclusion of unknow item to manage unknown files
         headers.put(HeaderType.UNKNOWN.getDefinition().getType(), HeaderType.UNKNOWN.getDefinition());
Index: src/main/java/com/google/code/mojo/license/header/Header.java
===================================================================
--- src/main/java/com/google/code/mojo/license/header/Header.java   (revision 470)
+++ src/main/java/com/google/code/mojo/license/header/Header.java   (working copy)
@@ -55,7 +55,7 @@
      * @throws IllegalArgumentException If the header file location is null or if an error occurred while reading the
      *                                  file content.
      */
-    public Header(URL location, Map<String, String> properties, HeaderSection[] sections) {
+    public Header(URL location, String encoding, Map<String, String> properties, HeaderSection[] sections) {
         if (location == null) {
             throw new IllegalArgumentException("Cannot read license template header file with a null location");
         }
@@ -65,7 +65,7 @@
         this.location = location;
         this.sections = sections;
         try {
-            this.headerContent = read(location, properties);
+            this.headerContent = read(location, encoding, properties);
             lines = headerContent.replace("\r", "").split("\n");
             headerContentOneLine = remove(headerContent, " ", "\t", "\r", "\n");
         }
Index: src/main/java/com/google/code/mojo/license/util/FileUtils.java
===================================================================
--- src/main/java/com/google/code/mojo/license/util/FileUtils.java  (revision 470)
+++ src/main/java/com/google/code/mojo/license/util/FileUtils.java  (working copy)
@@ -51,8 +51,8 @@
         }
     }

-    public static String read(URL location, Map<String, String> properties) throws IOException {
-        Reader reader = new InterpolationFilterReader(new BufferedReader(new InputStreamReader(location.openStream())), properties);
+    public static String read(URL location, String encoding, Map<String, String> properties) throws IOException {
+        Reader reader = new InterpolationFilterReader(new BufferedReader(new InputStreamReader(location.openStream(), encoding)), properties);
         try {
             return IOUtil.toString(reader);
         } finally {
Index: src/test/java/com/google/code/mojo/license/document/DocumentTest.java
===================================================================
--- src/test/java/com/google/code/mojo/license/document/DocumentTest.java   (revision 470)
+++ src/test/java/com/google/code/mojo/license/document/DocumentTest.java   (working copy)
@@ -39,7 +39,7 @@
     public void setup() throws MalformedURLException {
         Map<String, String> props = new HashMap<String, String>();
         props.put("year", "2008");
-        header = new Header(new File("src/test/resources/test-header1.txt").toURI().toURL(), props, null);
+        header = new Header(new File("src/test/resources/test-header1.txt").toURI().toURL(), "UTF-8", props, null);
     }

     @Test
Index: src/test/java/com/google/code/mojo/license/header/AdditionalHeaderDefinitionTest.java
===================================================================
--- src/test/java/com/google/code/mojo/license/header/AdditionalHeaderDefinitionTest.java   (revision 470)
+++ src/test/java/com/google/code/mojo/license/header/AdditionalHeaderDefinitionTest.java   (working copy)
@@ -54,7 +54,7 @@

         Map<String, String> props = new HashMap<String, String>();
         props.put("year", "2008");
-        Header header = new Header(getClass().getResource("/test-header1.txt"), props, null);
+        Header header = new Header(getClass().getResource("/test-header1.txt"), "UTF-8", props, null);

         //FileUtils.write(new File("src/test/resources/test-header3.txt"), header.buildForDefinition(loader.getDefinitions().get("xquery")));

@@ -81,7 +81,7 @@

         Map<String, String> props = new HashMap<String, String>();
         props.put("year", "2008");
-        Header header = new Header(getClass().getResource("/check/header.txt"), props, null);
+        Header header = new Header(getClass().getResource("/check/header.txt"), "UTF-8", props, null);

         System.out.println(header.buildForDefinition(loader.getDefinitions().get("text"), false));
     }
@@ -102,7 +102,7 @@

         Map<String, String> props = new HashMap<String, String>();
         props.put("year", "2008");
-        Header header = new Header(getClass().getResource("/test-header1.txt"), props, null);
+        Header header = new Header(getClass().getResource("/test-header1.txt"), "UTF-8", props, null);

         //FileUtils.write(new File("src/test/resources/test-header4.txt"), header.buildForDefinition(loader.getDefinitions().get("csregion"), false), System.getProperty("file.encoding"));

Index: src/test/java/com/google/code/mojo/license/header/DefaultHeaderDefinitionTest.java
===================================================================
--- src/test/java/com/google/code/mojo/license/header/DefaultHeaderDefinitionTest.java  (revision 470)
+++ src/test/java/com/google/code/mojo/license/header/DefaultHeaderDefinitionTest.java  (working copy)
@@ -34,7 +34,7 @@
     public void test_styles() throws Exception {
         Map<String, String> props = new HashMap<String, String>();
         props.put("year", "2008");
-        Header header = new Header(getClass().getResource("/test-header1.txt"), props, null);
+        Header header = new Header(getClass().getResource("/test-header1.txt"), "UTF-8", props, null);
         for (HeaderDefinition definition : HeaderType.defaultDefinitions().values()) {
             final String content = FileUtils.read(new File(format("src/test/resources/styles/%s.txt", definition.getType())), System.getProperty("file.encoding"));
             assertEquals(content, header.buildForDefinition(definition, content.indexOf("\n") == -1),
Index: src/test/java/com/google/code/mojo/license/header/HeaderTest.java
===================================================================
--- src/test/java/com/google/code/mojo/license/header/HeaderTest.java   (revision 470)
+++ src/test/java/com/google/code/mojo/license/header/HeaderTest.java   (working copy)
@@ -39,7 +39,7 @@
     public void test() throws Exception {
         Map<String, String> props = new HashMap<String, String>();
         props.put("year", "2008");
-        Header header = new Header(getClass().getResource("/test-header1.txt"), props, null);
+        Header header = new Header(getClass().getResource("/test-header1.txt"), "UTF-8", props, null);
         assertEquals(header.getLineCount(), 13);
         assertTrue(header.asOneLineString().contains("2008"));
         assertEquals(header.getLocation(), getClass().getResource("/test-header1.txt"));
@@ -62,7 +62,7 @@
         HeaderSection[] sections = { section };

         Map<String, String> props = Collections.emptyMap();
-        Header header = new Header(getClass().getResource("/test-header5.txt"), props, sections);
+        Header header = new Header(getClass().getResource("/test-header5.txt"), "UTF-8", props, sections);

         HeaderDefinition headerDefinition = HeaderType.JAVADOC_STYLE.getDefinition();

@@ -125,7 +125,7 @@
         HeaderSection[] sections = { sectionA, sectionB };

         Map<String, String> props = Collections.emptyMap();
-        Header header = new Header(getClass().getResource("/test-header6.txt"), props, sections);
+        Header header = new Header(getClass().getResource("/test-header6.txt"), "UTF-8", props, sections);

         HeaderDefinition headerDefinition = HeaderType.JAVADOC_STYLE.getDefinition();

@@ -181,7 +181,7 @@
         HeaderSection[] sections = { section };

         Map<String, String> props = Collections.emptyMap();
-        Header header = new Header(getClass().getResource("/test-header5.txt"), props, sections);
+        Header header = new Header(getClass().getResource("/test-header5.txt"), "UTF-8", props, sections);

         HeaderDefinition headerDefinition = HeaderType.JAVADOC_STYLE.getDefinition();


Support Yaml

Yaml files get "[WARNING] Unknown file extension" now but could probably be supported.

Support extension-less files in <mapping>

With <Dockerfile>SCRIPT_STYLE</Dockerfile> in <mapping> I still get

Unknown file extension: [...]/Dockerfile

The fix should probably happen around https://github.com/mycila/license-maven-plugin/blob/master/src/main/java/com/mycila/maven/plugin/license/document/DocumentFactory.java#L51
e.g. by replacing

if (file.toLowerCase().endsWith("." + entry.getKey().toLowerCase())) {

with

if (file.toLowerCase().endsWith("." + entry.getKey().toLowerCase())
         || file.toLowerCase().equals(entry.getKey().toLowerCase())) {

I am going to try it.

Add support for single line doubleslash style

We are using a sinlge line notice looking like this:

//Copyright © 2015 Acme Inc. All Rights Reserved.
package com.acme;

class AcmeClass{

It took me some time to figure out the correct configuration:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<additionalHeaders>
    <doubleslash_single_style> 
        <beforeEachLine>//</beforeEachLine> 
        <firstLineDetectionPattern>(\s|\t)*//.*$</firstLineDetectionPattern>
        <lastLineDetectionPattern>(\s|\t)*//.*$</lastLineDetectionPattern>
        <allowBlankLines>false</allowBlankLines>
        <isMultiline>false</isMultiline>
        <padLines>false</padLines>
    </doubleslash_single_style>
</additionalHeaders>

I'd send you a pull request but I can't find where to add it in the source

aggregate plugin uses codehaus version

Hi thanks for the project,

My root aggregate pom contains the configuration below. When I run it with: mvn license:check -- mvn starts trying to download the codehaus similarly named version of this plugin and then fails.

How can I make it stop trying to use the other version of the codehaus plugin - and why is it trying that?

Is it possible to define the configuration of this plugin once at the root pom and have it add the license to all the matching files in child projects? I'm only specifying child sub modules in poms of packaging "pom". My child poms do not set the "parent" element.

Thanks!

  <packaging>pom</packaging>
  <modules>
    <module>myModule</module>
  </modules>
  <build>
    <plugins>
      <plugin>
          <groupId>com.mycila</groupId>
          <artifactId>license-maven-plugin</artifactId>
          <version>2.8</version>
          <inherited>false</inherited>
          <configuration>
              <header>MyLicense.txt</header>
              <aggregate>true</aggregate>
              <includes>
                <include>**/*.java</include>
                <include>**/*.xml</include>
              </includes>
          </configuration>
      </plugin>
    </plugins>
  </build>

license:remove is not working

The remove goal does not remove file headers despite the log messages saying the headers are removed.

My plugin configuration:

<plugin>
    <groupId>com.mycila</groupId>
    <artifactId>license-maven-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <header>com/mycila/maven/plugin/license/templates/GPL-3.txt</header>
        <excludes>
            <exclude>**/README</exclude>
            <exclude>src/test/resources/**</exclude>
            <exclude>src/main/resources/**</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The command I execute is mvn license:remove.

The (shortened) log:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building XXX 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- license-maven-plugin:2.5:remove (default-cli) @ XXX ---
[INFO] Removing license headers...
[INFO] Removing license header from: XXXXXX.java
.
.
.
[INFO] Removing license header from: XXXXXX.java

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.379 s
[INFO] Finished at: 2014-06-09T14:11:58+00:00
[INFO] Final Memory: 9M/182M
[INFO] ------------------------------------------------------------------------

I have enabled -X and no exceptions are being thrown by the plugin.
Any clues?

Many thanks

support files that use a "byte order mark" aka BOM

https://code.google.com/p/maven-license-plugin/issues/detail?id=107

Reported by [email protected], Feb 14, 2012
http://en.wikipedia.org/wiki/Byte_order_mark

What steps will reproduce the problem?

  1. Using the plugin on a file that contains a BOM as the first byte

What is the expected output?
The license header should be placed after the BOM.

What do you see instead?
The license header is inserted before the BOM. This causes issues since an otherwise plain text file now has the BOM (U+FEFF) somewhere besides the first byte.

What version of the product are you using?

This is version 1.9.0 of the plugin

Request for a skip check goal.

Hi,

I was wondering if you can include some kind of skip check goal to override doing any checks. This would be useful for development purposes. Alternatively if you can recommend a way I can skip the checks I would appreciate it. I'm working on a number of projects that use this plugin but also some that don't and my builds are failing due to missing headers. I don't want to alter the pom's explicitly at this point so to be able to simply skip them would be useful.

Thanks,
Sal.

mvn clean install BUILD FAILURE

when i was pulling code from master and building it, a bug occured. :

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.146 s
[INFO] Finished at: 2014-11-28T10:23:31+07:00
[INFO] Final Memory: 26M/217M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.mycila:license-maven-plugin:2.5:check (default) on project mayocat-parent: Execution default of goal com.mycila:license-maven-plugin:2.5:check failed: Plugin com.mycila:license-maven-plugin:2.5 or one of its dependencies could not be resolved: Failure to find org.mayocat.tools:mpl-license-header:jar:1.0 in http://repository-mayocat.forge.cloudbees.com/release/ was cached in the local repository, resolution will not be reattempted until the update interval of mayocat-cloudbees-release has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

can anyone help me fix this bug?

Can't define a mapping for xyz.apt.vm files

I have tried to configure the plugin like this:

<mapping>
  <g>DOUBLESLASH_STYLE</g>
  <apt.vm>DOUBLETILDE_STYLE</apt.vm>
  <apt>DOUBLETILDE_STYLE</apt>
</mapping>

but the apt.vm seemed to be not working.
Does exist an other possibility to configure the plugin to recognize the extension .apt.vm ?

enforce project EOL to be correct regardless of user GIT settings

We should find a way to enforce some rules at project level so that whatever the default global git configuration of a user is, the project works as expected.

Today (commit dbc060a5297228055ce791ad2af4027da6e37a95), if you are on a windows machine and you applied different GIT recommandations (GIT SCM book, Github documentation) by setting git config --global core.autocrlf true
then the project does not build correctly: tests in UpdateMojoTest & RemoveMojoTest are failing because they rely on specific \n line ending.

At least we should investigate if we could not enforce, using git functionnalities, project specific rules that would override user settings.

Automatically pick up license header based on pom.licenses

It would be great if license headers could be automatically picked up based on the information contained in the licenses section from the pom.xml .

A possible algorithm is:

  • if pom.licenses exists and has just one license element
  • if the license.name ( or URL? ) matches those from the embedded licenses
  • then automatically pick up that header

For instance, if my pom.xml contains

<licenses>
  <license>
    <name>The Apache Software License, Version 2.0</name>
    <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  </license>
</licenses>

then it should automatically infer

<header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>

License headers shouldn't be in Javadoc style

In most open source java libraries the header looks like:

/*
 * The header
 */

This plugin uses a javadoc style:

/**
 * The header
 */

This becomes a problem when generating javadocs, because the license header content gets into all your documentation.

Set Java version to 1.6

Please set the Java target version to at least 1.6.

Currently it's not possible to use the plugin with any Java lower than version 7.

You can achieve this by using the maven-compiler-plugin

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>

Running this maven plugin twice on XML files adds an extra line

Here's an input example:

<?xml version="1.0" encoding="UTF-8"?>

<xwikidoc>

After running the plugin once, I get:

<?xml version="1.0" encoding="UTF-8"?>
<!--

    See the NOTICE file distributed with this work for additional
    information regarding copyright ownership.

    This is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as
    published by the Free Software Foundation; either version 2.1 of
    the License, or (at your option) any later version.

    This software is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this software; if not, write to the Free
    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    02110-1301 USA, or see the FSF site: http://www.fsf.org.

-->

<xwikidoc>

And running it again addes an extra new line just after the first line:

<?xml version="1.0" encoding="UTF-8"?>

<!--

    See the NOTICE file distributed with this work for additional
    information regarding copyright ownership.

    This is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as
    published by the Free Software Foundation; either version 2.1 of
    the License, or (at your option) any later version.

    This software is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this software; if not, write to the Free
    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    02110-1301 USA, or see the FSF site: http://www.fsf.org.

-->

<xwikidoc>

It's not normal than running the plugin twice generates a change.

Thanks

Copyright years based on git history

We have recently introduced a custom PropertiesProvider in our project that adds two new properties:

  • license.copyrightLastYear - the year of the last change of the present file as seen in git history
  • license.copyrightYears - the combination of project.inceptionYear and license.copyrightLastYear delimited by a dash, or just project.inceptionYear if project.inceptionYear is eqal to license.copyrightLastYear

In this way we are able to comply with the requirement of our legal department to update the copyright range anytime the given file is changed without too much manual work. Because this kind of requirement is certainly quite common, we are looking for a way to share our code.

To contribute our code to license plugin seems to be the first natural choice. However our code depends on jGit and you probabaly will not be wanting to introduce the jGit dependency to license plugin itself.
Maybe a submodule of license plugin would be better? That submodule would build to a jar that could optionally be used by license plugin at runtime. WDYT?

Insert the license one line after the package

Is it possible to insert the license after the package? Such as for example:

package com.foo

/**
 * Copyright (C) 2014 My Org ([email protected])
 *
 * 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.
 */

Instead of it being above the package name...?
If not, would it be too hard to implement and what part of the code would need changes?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.