Author: tchemit Date: 2010-10-16 19:05:40 +0200 (Sat, 16 Oct 2010) New Revision: 1846 Url: http://nuiton.org/repositories/revision/maven-license-plugin/1846 Log: Anomalie #938: licenseName should be expression license.licenseName Anomalie #939: When license name is not found, a NPE occurs, it should be a nicer message Anomalie #947: Files to update are not found in a multi-module project Anomalie #954: Some parameters for the UpdateFileHeader mojo were placed on the wrong place Evolution #952: Must be able to add more extensions to match header comment style Evolution #955: Improve code to make easier the deletion of the project file descriptor Added: trunk/src/it/ano-816/README.txt trunk/src/it/ano-947/ trunk/src/it/ano-947/README.txt trunk/src/it/ano-947/child1/ trunk/src/it/ano-947/child1/pom.xml trunk/src/it/ano-947/child1/src/ trunk/src/it/ano-947/child1/src/files/ trunk/src/it/ano-947/child1/src/files/apt/ trunk/src/it/ano-947/child1/src/files/apt/index.apt trunk/src/it/ano-947/child1/src/files/apt/index2.apt trunk/src/it/ano-947/child1/src/files/properties/ trunk/src/it/ano-947/child1/src/files/properties/test.properties trunk/src/it/ano-947/child1/src/files/properties/test2.properties trunk/src/it/ano-947/child1/src/files/rst/ trunk/src/it/ano-947/child1/src/files/rst/index.rst trunk/src/it/ano-947/child1/src/files/rst/index2.rst trunk/src/it/ano-947/child1/src/files/xml/ trunk/src/it/ano-947/child1/src/files/xml/test.xml trunk/src/it/ano-947/child1/src/files/xml/test2.xml trunk/src/it/ano-947/child1/src/main/ trunk/src/it/ano-947/child1/src/main/java/ trunk/src/it/ano-947/child1/src/main/java/org/ trunk/src/it/ano-947/child1/src/main/java/org/nuiton/ trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/ trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/ trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/ trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean.java trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean2.java trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean3.java trunk/src/it/ano-947/invoker.properties trunk/src/it/ano-947/pom.xml trunk/src/it/ano-947/verify.groovy trunk/src/it/evol-818/README.txt trunk/src/it/evol-884/README.txt trunk/src/it/evol-952/ trunk/src/it/evol-952/LICENSE.txt trunk/src/it/evol-952/README.txt trunk/src/it/evol-952/changelog.txt trunk/src/it/evol-952/invoker.properties trunk/src/it/evol-952/pom.xml trunk/src/it/evol-952/src/ trunk/src/it/evol-952/src/files/ trunk/src/it/evol-952/src/files/apt/ trunk/src/it/evol-952/src/files/apt/index.apt trunk/src/it/evol-952/src/files/apt/index.apt2 trunk/src/it/evol-952/src/files/apt/index2.apt trunk/src/it/evol-952/src/files/apt/index2.apt2 trunk/src/it/evol-952/src/files/properties/ trunk/src/it/evol-952/src/files/properties/test.properties trunk/src/it/evol-952/src/files/properties/test.properties2 trunk/src/it/evol-952/src/files/properties/test2.properties trunk/src/it/evol-952/src/files/properties/test2.properties2 trunk/src/it/evol-952/src/files/rst/ trunk/src/it/evol-952/src/files/rst/index.rst trunk/src/it/evol-952/src/files/rst/index.rst2 trunk/src/it/evol-952/src/files/rst/index2.rst trunk/src/it/evol-952/src/files/rst/index2.rst2 trunk/src/it/evol-952/src/files/xml/ trunk/src/it/evol-952/src/files/xml/test.xml trunk/src/it/evol-952/src/files/xml/test.xml2 trunk/src/it/evol-952/src/files/xml/test2.xml trunk/src/it/evol-952/src/files/xml/test2.xml2 trunk/src/it/evol-952/src/main/ trunk/src/it/evol-952/src/main/java/ trunk/src/it/evol-952/src/main/java/org/ trunk/src/it/evol-952/src/main/java/org/nuiton/ trunk/src/it/evol-952/src/main/java/org/nuiton/license/ trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/ trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/ trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean.java trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean.java2 trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean2.java trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean2.java2 trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean3.java trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean3.java2 trunk/src/it/evol-952/verify.groovy Modified: trunk/pom.xml trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseWithDescriptorMojo.java trunk/src/main/java/org/nuiton/license/plugin/UpdateFileHeaderMojo.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AptFileHeaderTransformer.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/JavaFileHeaderTransformer.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/PropertiesFileHeaderTransformer.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/RstFileHeaderTransformer.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/pom.xml 2010-10-16 17:05:40 UTC (rev 1846) @@ -437,19 +437,21 @@ <artifactId>maven-invoker-plugin</artifactId> <configuration> <pomIncludes> - <pomInclude>evol-818/excluded-included</pomInclude> - <pomInclude>evol-818/multimodule-filters/pom.xml</pomInclude> - <pomInclude>ano-816/pom.xml</pomInclude> - <pomInclude>add-third-party/no-encoding/pom.xml</pomInclude> - <pomInclude>aggregate-add-third-party/pom.xml</pomInclude> - <pomInclude>add-third-party/merge-licenses/pom.xml</pomInclude> - <pomInclude>add-third-party/no-deps/pom.xml</pomInclude> - <pomInclude>add-third-party/with-deps/pom.xml</pomInclude> - <pomInclude>update-file-header/pom.xml</pomInclude> - <pomInclude>update-project-license/pom.xml</pomInclude> - <pomInclude>evol-884/update-project-license/pom.xml</pomInclude> - <pomInclude>evol-884/update-file-header/pom.xml</pomInclude> - <pomInclude>evol-884/update-file-header-specific/pom.xml</pomInclude> + <!--<pomInclude>ano-816/pom.xml</pomInclude>--> + <!--<pomInclude>ano-947/pom.xml</pomInclude>--> + <pomInclude>evol-952/pom.xml</pomInclude> + <!--<pomInclude>evol-818/excluded-included/pom.xml</pomInclude>--> + <!--<pomInclude>evol-818/multimodule-filters/pom.xml</pomInclude>--> + <!--<pomInclude>evol-884/update-project-license/pom.xml</pomInclude>--> + <!--<pomInclude>evol-884/update-file-header/pom.xml</pomInclude>--> + <!--<pomInclude>evol-884/update-file-header-specific/pom.xml</pomInclude>--> + <!--<pomInclude>add-third-party/no-encoding/pom.xml</pomInclude>--> + <!--<pomInclude>aggregate-add-third-party/pom.xml</pomInclude>--> + <!--<pomInclude>add-third-party/merge-licenses/pom.xml</pomInclude>--> + <!--<pomInclude>add-third-party/no-deps/pom.xml</pomInclude>--> + <!--<pomInclude>add-third-party/with-deps/pom.xml</pomInclude>--> + <!--<pomInclude>update-file-header/pom.xml</pomInclude>--> + <!--<pomInclude>update-project-license/pom.xml</pomInclude>--> </pomIncludes> <postBuildHookScript>verify</postBuildHookScript> <localRepositoryPath>${basedir}/target/local-repo</localRepositoryPath> Added: trunk/src/it/ano-816/README.txt =================================================================== --- trunk/src/it/ano-816/README.txt (rev 0) +++ trunk/src/it/ano-816/README.txt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,3 @@ +To authorized when a license is not well formed (and in such case ignore it). + +See http://nuiton.org/issues/show/816 \ No newline at end of file Added: trunk/src/it/ano-947/README.txt =================================================================== --- trunk/src/it/ano-947/README.txt (rev 0) +++ trunk/src/it/ano-947/README.txt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,3 @@ +To test that files in the module are also treated by the mojo update-file-header. + +See http://nuiton.org/issues/show/947 \ No newline at end of file Added: trunk/src/it/ano-947/child1/pom.xml =================================================================== --- trunk/src/it/ano-947/child1/pom.xml (rev 0) +++ trunk/src/it/ano-947/child1/pom.xml 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.nuiton.license.test</groupId> + <artifactId>test-it-947</artifactId> + <version>1.0</version> + </parent> + <artifactId>test-it-947-child1</artifactId> + + <licenses> + <license> + <name><!--fake license with no name--></name> + </license> + <license> + <name> </name> + </license> + <license> + <name> </name> + <url><!-- fake license with no name nor url--></url> + </license> + <license> + <name> </name> + <url> </url> + </license> + </licenses> + <name>License Test :: ano-947 - child 1</name> + +</project> + + Added: trunk/src/it/ano-947/child1/src/files/apt/index.apt =================================================================== --- trunk/src/it/ano-947/child1/src/files/apt/index.apt (rev 0) +++ trunk/src/it/ano-947/child1/src/files/apt/index.apt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +My file Added: trunk/src/it/ano-947/child1/src/files/apt/index2.apt =================================================================== --- trunk/src/it/ano-947/child1/src/files/apt/index2.apt (rev 0) +++ trunk/src/it/ano-947/child1/src/files/apt/index2.apt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,25 @@ +~~~ +~~ #%L +~~ License Test :: update-file-header +~~ +~~ $Id: index2.apt 1832 2010-09-29 13:49:21Z ymartel $ +~~ $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ +~~ %% +~~ Copyright (C) 2012 License Test +~~ %% +~~ This program is free software: you can redistribute it and/or modify +~~ it under the terms of the GNU General Public License as +~~ published by the Free Software Foundation, either version 3 of the +~~ License, or (at your option) any later version. +~~ +~~ This program 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 General Public License for more details. +~~ +~~ You should have received a copy of the GNU General Public +~~ License along with this program. If not, see +~~ <http://www.gnu.org/licenses/gpl-3.0.html>. +~~ #L% +~~~ +My file Added: trunk/src/it/ano-947/child1/src/files/properties/test.properties =================================================================== --- trunk/src/it/ano-947/child1/src/files/properties/test.properties (rev 0) +++ trunk/src/it/ano-947/child1/src/files/properties/test.properties 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +my.key=true \ No newline at end of file Added: trunk/src/it/ano-947/child1/src/files/properties/test2.properties =================================================================== --- trunk/src/it/ano-947/child1/src/files/properties/test2.properties (rev 0) +++ trunk/src/it/ano-947/child1/src/files/properties/test2.properties 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,26 @@ +### +# #%L +# License Test :: update-file-header +# +# $Id: test2.properties 1832 2010-09-29 13:49:21Z ymartel $ +# $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ +# %% +# Copyright (C) 2012 License Test +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### + +my.key=true \ No newline at end of file Added: trunk/src/it/ano-947/child1/src/files/rst/index.rst =================================================================== --- trunk/src/it/ano-947/child1/src/files/rst/index.rst (rev 0) +++ trunk/src/it/ano-947/child1/src/files/rst/index.rst 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +My File \ No newline at end of file Added: trunk/src/it/ano-947/child1/src/files/rst/index2.rst =================================================================== --- trunk/src/it/ano-947/child1/src/files/rst/index2.rst (rev 0) +++ trunk/src/it/ano-947/child1/src/files/rst/index2.rst 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,26 @@ +My file + +.. - +.. * #%L +.. * Maven License Plugin +.. * +.. * $Id: index2.rst 1832 2010-09-29 13:49:21Z ymartel $ +.. * $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ +.. * %% +.. * Copyright (C) 2008 - 2010 CodeLutin +.. * %% +.. * This program 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 3 of the +.. * License, or (at your option) any later version. +.. * +.. * This program 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 General Lesser Public License for more details. +.. * +.. * You should have received a copy of the GNU General Lesser Public +.. * License along with this program. If not, see +.. * <http://www.gnu.org/licenses/lgpl-3.0.html>. +.. * #L% +.. \ No newline at end of file Added: trunk/src/it/ano-947/child1/src/files/xml/test.xml =================================================================== --- trunk/src/it/ano-947/child1/src/files/xml/test.xml (rev 0) +++ trunk/src/it/ano-947/child1/src/files/xml/test.xml 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<yo/> \ No newline at end of file Added: trunk/src/it/ano-947/child1/src/files/xml/test2.xml =================================================================== --- trunk/src/it/ano-947/child1/src/files/xml/test2.xml (rev 0) +++ trunk/src/it/ano-947/child1/src/files/xml/test2.xml 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,27 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + #%L + License Test :: update-file-header + + $Id: test2.xml 1832 2010-09-29 13:49:21Z ymartel $ + $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ + %% + Copyright (C) 2012 License Test + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> + +<yo/> \ No newline at end of file Added: trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean.java =================================================================== --- trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean.java (rev 0) +++ trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,10 @@ +package org.nuiton.license.plugin.test; + +/** + * this class has no license, a new default one will be added. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +public class MyBean { +} Added: trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean2.java =================================================================== --- trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean2.java (rev 0) +++ trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean2.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,20 @@ +/* + * #%L + * License Test :: do NOT update! + * %% + * Copyright (C) 2010 Tony + * %% + * Fake to be removed! + * #L% + */ + +/** + * this class owns a header, only license will be updated. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +package org.nuiton.license.plugin.test; + +public class MyBean2 { +} Added: trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean3.java =================================================================== --- trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean3.java (rev 0) +++ trunk/src/it/ano-947/child1/src/main/java/org/nuiton/license/plugin/test/MyBean3.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,18 @@ +/* + * %%Ignore-License + * + * yet another license + * + * Copyright (C) 2000 Codelutin Do not update! + */ + +/** + * this class owns a ignore license header and will not be updated. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +package org.nuiton.license.plugin.test; + +public class MyBean3 { +} Added: trunk/src/it/ano-947/invoker.properties =================================================================== --- trunk/src/it/ano-947/invoker.properties (rev 0) +++ trunk/src/it/ano-947/invoker.properties 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,21 @@ +# A comma or space separated list of goals/phases to execute, may +# specify an empty list to execute the default goal of the IT project +invoker.goals=clean install + +# Optionally, a list of goals to run during further invocations of Maven +#invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:run + +# A comma or space separated list of profiles to activate +#invoker.profiles=run-all run-once + +# The value for the environment variable MAVEN_OPTS +#invoker.mavenOpts=-Dfile.encoding=UTF-16 -Xms32m -Xmx256m + +# Possible values are "fail-fast" (default), "fail-at-end" and "fail-never" +invoker.failureBehavior=fail-fast + +# The expected result of the build, possible values are "success" (default) and "failure" +#invoker.buildResult=success + +# A boolean value controlling the -N flag, defaults to "false" +#invoker.nonRecursive=false Added: trunk/src/it/ano-947/pom.xml =================================================================== --- trunk/src/it/ano-947/pom.xml (rev 0) +++ trunk/src/it/ano-947/pom.xml 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.nuiton.license.test</groupId> + <artifactId>test-it-947</artifactId> + <version>1.0</version> + + <modules> + <module>child1</module> + </modules> + + <name>License Test :: ano-947</name> + + <packaging>pom</packaging> + + <organization> + <name>License Test</name> + </organization> + + <inceptionYear>2012</inceptionYear> + + <url>no-url</url> + <properties> + + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <license.verbose>true</license.verbose> + <license.licenseName>gpl_v3</license.licenseName> + <license.addSvnKeyWords>true</license.addSvnKeyWords> + </properties> + + <build> + + <plugins> + + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin</artifactId> + <executions> + <execution> + <id>first</id> + <goals> + <goal>update-file-header</goal> + </goals> + <phase>process-sources</phase> + </execution> + </executions> + </plugin> + </plugins> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin</artifactId> + <version>@pom.version@</version> + </plugin> + </plugins> + </pluginManagement> + </build> + +</project> + + Added: trunk/src/it/ano-947/verify.groovy =================================================================== --- trunk/src/it/ano-947/verify.groovy (rev 0) +++ trunk/src/it/ano-947/verify.groovy 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,111 @@ + +file = new File(basedir, 'child1/src/main/java/org/nuiton/license/plugin/test/MyBean.java'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C) 2012 License Test' ); + +file = new File(basedir, 'child1/src/main/java/org/nuiton/license/plugin/test/MyBean2.java'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C) 2010 Tony' ); +assert content.contains( 'do NOT update!' ); +assert !content.contains( 'Fake to be removed!' ); + +file = new File(basedir, 'child1/src/main/java/org/nuiton/license/plugin/test/MyBean3.java'); +assert file.exists(); + +content = file.text; +assert content.contains( ' * %%Ignore-License' ); +assert content.contains( ' * yet another license' ); +assert content.contains( ' * Copyright (C) 2000 Codelutin Do not update!' ); + +file = new File(basedir, 'child1/src/files/apt/index.apt'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '~~ #%L' ); +assert content.contains( '~~ #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '~~ ~~'); + + +file = new File(basedir, 'child1/src/files/apt/index2.apt'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '~~ #%L' ); +assert content.contains( '~~ #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '~~ ~~'); + + +file = new File(basedir, 'child1/src/files/rst/index.rst'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '.. * #%L' ); +assert content.contains( '.. * #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '.. * .. *'); + + +file = new File(basedir, 'child1/src/files/rst/index2.rst'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '.. * #%L' ); +assert content.contains( '.. * #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '.. * .. *'); + + +file = new File(basedir, 'child1/src/files/xml/test.xml'); +assert file.exists(); + +content = file.text; +assert content.startsWith( "<?xml version='1.0' encoding='UTF-8'?>" ); +assert content.contains( 'Copyright (C)' ); +assert content.contains( '#%L' ); +assert content.contains( '#L%' ); +assert content.contains( '$Id' ); + + +file = new File(basedir, 'child1/src/files/xml/test2.xml'); +assert file.exists(); + +content = file.text; +assert content.startsWith( "<?xml version='1.0' encoding='UTF-8'?>" ); +assert content.contains( 'Copyright (C)' ); +assert content.contains( '#%L' ); +assert content.contains( '#L%' ); +assert content.contains( '$Id' ); + +file = new File(basedir, 'child1/src/files/properties/test.properties'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '# #%L' ); +assert content.contains( '# #L%' ); +assert !content.contains( '# # \n' ); +assert content.contains( '$Id' ); + + +file = new File(basedir, 'child1/src/files/properties/test2.properties'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '# #%L' ); +assert content.contains( '# #L%' ); +assert content.contains( '# #%L' ); +assert !content.contains( '# # \n' ); +assert content.contains( '$Id' ); + +return true; Added: trunk/src/it/evol-818/README.txt =================================================================== --- trunk/src/it/evol-818/README.txt (rev 0) +++ trunk/src/it/evol-818/README.txt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,3 @@ +To test Filter libraries to exclude/include when using add-third-party like mojos. + +See http://nuiton.org/issues/show/818 \ No newline at end of file Added: trunk/src/it/evol-884/README.txt =================================================================== --- trunk/src/it/evol-884/README.txt (rev 0) +++ trunk/src/it/evol-884/README.txt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,3 @@ +To test the new mode without any project file descriptor in update-file-header mojo. + +See http://nuiton.org/issues/show/884 \ No newline at end of file Added: trunk/src/it/evol-952/LICENSE.txt =================================================================== --- trunk/src/it/evol-952/LICENSE.txt (rev 0) +++ trunk/src/it/evol-952/LICENSE.txt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Added: trunk/src/it/evol-952/README.txt =================================================================== --- trunk/src/it/evol-952/README.txt (rev 0) +++ trunk/src/it/evol-952/README.txt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,3 @@ +To test extraExtension mecanism. + +See http://nuiton.org/issues/show/952 \ No newline at end of file Added: trunk/src/it/evol-952/changelog.txt =================================================================== --- trunk/src/it/evol-952/changelog.txt (rev 0) +++ trunk/src/it/evol-952/changelog.txt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +see the changelog of org.nuiton:i18n project. \ No newline at end of file Added: trunk/src/it/evol-952/invoker.properties =================================================================== --- trunk/src/it/evol-952/invoker.properties (rev 0) +++ trunk/src/it/evol-952/invoker.properties 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,21 @@ +# A comma or space separated list of goals/phases to execute, may +# specify an empty list to execute the default goal of the IT project +invoker.goals=clean process-sources + +# Optionally, a list of goals to run during further invocations of Maven +#invoker.goals.2=${project.groupId}:${project.artifactId}:${project.version}:run + +# A comma or space separated list of profiles to activate +#invoker.profiles=run-all run-once + +# The value for the environment variable MAVEN_OPTS +#invoker.mavenOpts=-Dfile.encoding=UTF-16 -Xms32m -Xmx256m + +# Possible values are "fail-fast" (default), "fail-at-end" and "fail-never" +invoker.failureBehavior=fail-fast + +# The expected result of the build, possible values are "success" (default) and "failure" +#invoker.buildResult=success + +# A boolean value controlling the -N flag, defaults to "false" +#invoker.nonRecursive=false Added: trunk/src/it/evol-952/pom.xml =================================================================== --- trunk/src/it/evol-952/pom.xml (rev 0) +++ trunk/src/it/evol-952/pom.xml 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.nuiton.license.test</groupId> + <artifactId>test-evol-952</artifactId> + <version>@pom.version@</version> + + <name>License Test :: evol-952</name> + + <inceptionYear>2012</inceptionYear> + + <organization> + <name>License Test</name> + </organization> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <license.verbose>true</license.verbose> + <license.licenseName>gpl_v3</license.licenseName> + <license.addSvnKeyWords>true</license.addSvnKeyWords> + </properties> + <build> + + <plugins> + + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin</artifactId> + <executions> + <execution> + <id>default-update-file-header</id> + <goals> + <goal>update-file-header</goal> + </goals> + <phase>process-sources</phase> + <configuration> + <extraExtensions> + <apt2>apt</apt2> + <java2>java</java2> + <properties2>properties</properties2> + <rst2>rst</rst2> + <xml2>xml</xml2> + </extraExtensions> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin</artifactId> + <version>@pom.version@</version> + </plugin> + </plugins> + </pluginManagement> + </build> + +</project> + + Added: trunk/src/it/evol-952/src/files/apt/index.apt =================================================================== --- trunk/src/it/evol-952/src/files/apt/index.apt (rev 0) +++ trunk/src/it/evol-952/src/files/apt/index.apt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +My file Added: trunk/src/it/evol-952/src/files/apt/index.apt2 =================================================================== --- trunk/src/it/evol-952/src/files/apt/index.apt2 (rev 0) +++ trunk/src/it/evol-952/src/files/apt/index.apt2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +My file Added: trunk/src/it/evol-952/src/files/apt/index2.apt =================================================================== --- trunk/src/it/evol-952/src/files/apt/index2.apt (rev 0) +++ trunk/src/it/evol-952/src/files/apt/index2.apt 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,25 @@ +~~~ +~~ #%L +~~ License Test :: update-file-header +~~ +~~ $Id: index2.apt 1832 2010-09-29 13:49:21Z ymartel $ +~~ $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ +~~ %% +~~ Copyright (C) 2012 License Test +~~ %% +~~ This program is free software: you can redistribute it and/or modify +~~ it under the terms of the GNU General Public License as +~~ published by the Free Software Foundation, either version 3 of the +~~ License, or (at your option) any later version. +~~ +~~ This program 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 General Public License for more details. +~~ +~~ You should have received a copy of the GNU General Public +~~ License along with this program. If not, see +~~ <http://www.gnu.org/licenses/gpl-3.0.html>. +~~ #L% +~~~ +My file Added: trunk/src/it/evol-952/src/files/apt/index2.apt2 =================================================================== --- trunk/src/it/evol-952/src/files/apt/index2.apt2 (rev 0) +++ trunk/src/it/evol-952/src/files/apt/index2.apt2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,25 @@ +~~~ +~~ #%L +~~ License Test :: update-file-header +~~ +~~ $Id: index2.apt 1832 2010-09-29 13:49:21Z ymartel $ +~~ $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ +~~ %% +~~ Copyright (C) 2012 License Test +~~ %% +~~ This program is free software: you can redistribute it and/or modify +~~ it under the terms of the GNU General Public License as +~~ published by the Free Software Foundation, either version 3 of the +~~ License, or (at your option) any later version. +~~ +~~ This program 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 General Public License for more details. +~~ +~~ You should have received a copy of the GNU General Public +~~ License along with this program. If not, see +~~ <http://www.gnu.org/licenses/gpl-3.0.html>. +~~ #L% +~~~ +My file Added: trunk/src/it/evol-952/src/files/properties/test.properties =================================================================== --- trunk/src/it/evol-952/src/files/properties/test.properties (rev 0) +++ trunk/src/it/evol-952/src/files/properties/test.properties 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +my.key=true \ No newline at end of file Added: trunk/src/it/evol-952/src/files/properties/test.properties2 =================================================================== --- trunk/src/it/evol-952/src/files/properties/test.properties2 (rev 0) +++ trunk/src/it/evol-952/src/files/properties/test.properties2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +my.key=true \ No newline at end of file Added: trunk/src/it/evol-952/src/files/properties/test2.properties =================================================================== --- trunk/src/it/evol-952/src/files/properties/test2.properties (rev 0) +++ trunk/src/it/evol-952/src/files/properties/test2.properties 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,26 @@ +### +# #%L +# License Test :: update-file-header +# +# $Id: test2.properties 1832 2010-09-29 13:49:21Z ymartel $ +# $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ +# %% +# Copyright (C) 2012 License Test +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### + +my.key=true \ No newline at end of file Added: trunk/src/it/evol-952/src/files/properties/test2.properties2 =================================================================== --- trunk/src/it/evol-952/src/files/properties/test2.properties2 (rev 0) +++ trunk/src/it/evol-952/src/files/properties/test2.properties2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,26 @@ +### +# #%L +# License Test :: update-file-header +# +# $Id: test2.properties 1832 2010-09-29 13:49:21Z ymartel $ +# $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ +# %% +# Copyright (C) 2012 License Test +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### + +my.key=true \ No newline at end of file Added: trunk/src/it/evol-952/src/files/rst/index.rst =================================================================== --- trunk/src/it/evol-952/src/files/rst/index.rst (rev 0) +++ trunk/src/it/evol-952/src/files/rst/index.rst 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +My File \ No newline at end of file Added: trunk/src/it/evol-952/src/files/rst/index.rst2 =================================================================== --- trunk/src/it/evol-952/src/files/rst/index.rst2 (rev 0) +++ trunk/src/it/evol-952/src/files/rst/index.rst2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1 @@ +My File \ No newline at end of file Added: trunk/src/it/evol-952/src/files/rst/index2.rst =================================================================== --- trunk/src/it/evol-952/src/files/rst/index2.rst (rev 0) +++ trunk/src/it/evol-952/src/files/rst/index2.rst 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,26 @@ +My file + +.. - +.. * #%L +.. * Maven License Plugin +.. * +.. * $Id: index2.rst 1832 2010-09-29 13:49:21Z ymartel $ +.. * $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ +.. * %% +.. * Copyright (C) 2008 - 2010 CodeLutin +.. * %% +.. * This program 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 3 of the +.. * License, or (at your option) any later version. +.. * +.. * This program 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 General Lesser Public License for more details. +.. * +.. * You should have received a copy of the GNU General Lesser Public +.. * License along with this program. If not, see +.. * <http://www.gnu.org/licenses/lgpl-3.0.html>. +.. * #L% +.. \ No newline at end of file Added: trunk/src/it/evol-952/src/files/rst/index2.rst2 =================================================================== --- trunk/src/it/evol-952/src/files/rst/index2.rst2 (rev 0) +++ trunk/src/it/evol-952/src/files/rst/index2.rst2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,26 @@ +My file + +.. - +.. * #%L +.. * Maven License Plugin +.. * +.. * $Id: index2.rst 1832 2010-09-29 13:49:21Z ymartel $ +.. * $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ +.. * %% +.. * Copyright (C) 2008 - 2010 CodeLutin +.. * %% +.. * This program 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 3 of the +.. * License, or (at your option) any later version. +.. * +.. * This program 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 General Lesser Public License for more details. +.. * +.. * You should have received a copy of the GNU General Lesser Public +.. * License along with this program. If not, see +.. * <http://www.gnu.org/licenses/lgpl-3.0.html>. +.. * #L% +.. \ No newline at end of file Added: trunk/src/it/evol-952/src/files/xml/test.xml =================================================================== --- trunk/src/it/evol-952/src/files/xml/test.xml (rev 0) +++ trunk/src/it/evol-952/src/files/xml/test.xml 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<yo/> \ No newline at end of file Added: trunk/src/it/evol-952/src/files/xml/test.xml2 =================================================================== --- trunk/src/it/evol-952/src/files/xml/test.xml2 (rev 0) +++ trunk/src/it/evol-952/src/files/xml/test.xml2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,2 @@ +<?xml version='1.0' encoding='UTF-8'?> +<yo/> \ No newline at end of file Added: trunk/src/it/evol-952/src/files/xml/test2.xml =================================================================== --- trunk/src/it/evol-952/src/files/xml/test2.xml (rev 0) +++ trunk/src/it/evol-952/src/files/xml/test2.xml 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,27 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + #%L + License Test :: update-file-header + + $Id: test2.xml 1832 2010-09-29 13:49:21Z ymartel $ + $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ + %% + Copyright (C) 2012 License Test + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> + +<yo/> \ No newline at end of file Added: trunk/src/it/evol-952/src/files/xml/test2.xml2 =================================================================== --- trunk/src/it/evol-952/src/files/xml/test2.xml2 (rev 0) +++ trunk/src/it/evol-952/src/files/xml/test2.xml2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,27 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + #%L + License Test :: update-file-header + + $Id: test2.xml 1832 2010-09-29 13:49:21Z ymartel $ + $HeadURL: http://svn.nuiton.org/svn/maven-license-plugin/trunk/src/it/evol-884/update-... $ + %% + Copyright (C) 2012 License Test + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> + +<yo/> \ No newline at end of file Added: trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean.java =================================================================== --- trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean.java (rev 0) +++ trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,10 @@ +package org.nuiton.license.plugin.test; + +/** + * this class has no license, a new default one will be added. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +public class MyBean { +} Added: trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean.java2 =================================================================== --- trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean.java2 (rev 0) +++ trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean.java2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,10 @@ +package org.nuiton.license.plugin.test; + +/** + * this class has no license, a new default one will be added. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +public class MyBean { +} Added: trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean2.java =================================================================== --- trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean2.java (rev 0) +++ trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean2.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,20 @@ +/* + * #%L + * License Test :: do NOT update! + * %% + * Copyright (C) 2010 Tony + * %% + * Fake to be removed! + * #L% + */ + +/** + * this class owns a header, only license will be updated. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +package org.nuiton.license.plugin.test; + +public class MyBean2 { +} Added: trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean2.java2 =================================================================== --- trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean2.java2 (rev 0) +++ trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean2.java2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,20 @@ +/* + * #%L + * License Test :: do NOT update! + * %% + * Copyright (C) 2010 Tony + * %% + * Fake to be removed! + * #L% + */ + +/** + * this class owns a header, only license will be updated. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +package org.nuiton.license.plugin.test; + +public class MyBean2 { +} Added: trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean3.java =================================================================== --- trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean3.java (rev 0) +++ trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean3.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,18 @@ +/* + * %%Ignore-License + * + * yet another license + * + * Copyright (C) 2000 Codelutin Do not update! + */ + +/** + * this class owns a ignore license header and will not be updated. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +package org.nuiton.license.plugin.test; + +public class MyBean3 { +} Added: trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean3.java2 =================================================================== --- trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean3.java2 (rev 0) +++ trunk/src/it/evol-952/src/main/java/org/nuiton/license/plugin/test/MyBean3.java2 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,18 @@ +/* + * %%Ignore-License + * + * yet another license + * + * Copyright (C) 2000 Codelutin Do not update! + */ + +/** + * this class owns a ignore license header and will not be updated. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +package org.nuiton.license.plugin.test; + +public class MyBean3 { +} Added: trunk/src/it/evol-952/verify.groovy =================================================================== --- trunk/src/it/evol-952/verify.groovy (rev 0) +++ trunk/src/it/evol-952/verify.groovy 2010-10-16 17:05:40 UTC (rev 1846) @@ -0,0 +1,227 @@ + +file = new File(basedir, 'src/main/java/org/nuiton/license/plugin/test/MyBean.java'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C) 2012 License Test' ); + +file = new File(basedir, 'src/main/java/org/nuiton/license/plugin/test/MyBean2.java'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C) 2010 Tony' ); +assert content.contains( 'do NOT update!' ); +assert !content.contains( 'Fake to be removed!' ); + +file = new File(basedir, 'src/main/java/org/nuiton/license/plugin/test/MyBean3.java'); +assert file.exists(); + +content = file.text; +assert content.contains( ' * %%Ignore-License' ); +assert content.contains( ' * yet another license' ); +assert content.contains( ' * Copyright (C) 2000 Codelutin Do not update!' ); + +file = new File(basedir, 'src/files/apt/index.apt'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '~~ #%L' ); +assert content.contains( '~~ #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '~~ ~~'); + + +file = new File(basedir, 'src/files/apt/index2.apt'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '~~ #%L' ); +assert content.contains( '~~ #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '~~ ~~'); + + +file = new File(basedir, 'src/files/rst/index.rst'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '.. * #%L' ); +assert content.contains( '.. * #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '.. * .. *'); + + +file = new File(basedir, 'src/files/rst/index2.rst'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '.. * #%L' ); +assert content.contains( '.. * #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '.. * .. *'); + + +file = new File(basedir, 'src/files/xml/test.xml'); +assert file.exists(); + +content = file.text; +assert content.startsWith( "<?xml version='1.0' encoding='UTF-8'?>" ); +assert content.contains( 'Copyright (C)' ); +assert content.contains( '#%L' ); +assert content.contains( '#L%' ); +assert content.contains( '$Id' ); + + +file = new File(basedir, 'src/files/xml/test2.xml'); +assert file.exists(); + +content = file.text; +assert content.startsWith( "<?xml version='1.0' encoding='UTF-8'?>" ); +assert content.contains( 'Copyright (C)' ); +assert content.contains( '#%L' ); +assert content.contains( '#L%' ); +assert content.contains( '$Id' ); + +file = new File(basedir, 'src/files/properties/test.properties'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '# #%L' ); +assert content.contains( '# #L%' ); +assert !content.contains( '# # \n' ); +assert content.contains( '$Id' ); + + +file = new File(basedir, 'src/files/properties/test2.properties'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '# #%L' ); +assert content.contains( '# #L%' ); +assert content.contains( '# #%L' ); +assert !content.contains( '# # \n' ); +assert content.contains( '$Id' ); + + + + + + +// test with extra mapping + +file = new File(basedir, 'src/main/java/org/nuiton/license/plugin/test/MyBean.java2'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C) 2012 License Test' ); + +file = new File(basedir, 'src/main/java/org/nuiton/license/plugin/test/MyBean2.java2'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C) 2010 Tony' ); +assert content.contains( 'do NOT update!' ); +assert !content.contains( 'Fake to be removed!' ); + +file = new File(basedir, 'src/main/java/org/nuiton/license/plugin/test/MyBean3.java2'); +assert file.exists(); + +content = file.text; +assert content.contains( ' * %%Ignore-License' ); +assert content.contains( ' * yet another license' ); +assert content.contains( ' * Copyright (C) 2000 Codelutin Do not update!' ); + +file = new File(basedir, 'src/files/apt/index.apt2'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '~~ #%L' ); +assert content.contains( '~~ #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '~~ ~~'); + + +file = new File(basedir, 'src/files/apt/index2.apt2'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '~~ #%L' ); +assert content.contains( '~~ #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '~~ ~~'); + + +file = new File(basedir, 'src/files/rst/index.rst2'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '.. * #%L' ); +assert content.contains( '.. * #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '.. * .. *'); + + +file = new File(basedir, 'src/files/rst/index2.rst2'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '.. * #%L' ); +assert content.contains( '.. * #L%' ); +assert content.contains( '$Id' ); +assert ! content.contains( '.. * .. *'); + + +file = new File(basedir, 'src/files/xml/test.xml2'); +assert file.exists(); + +content = file.text; +assert content.startsWith( "<?xml version='1.0' encoding='UTF-8'?>" ); +assert content.contains( 'Copyright (C)' ); +assert content.contains( '#%L' ); +assert content.contains( '#L%' ); +assert content.contains( '$Id' ); + + +file = new File(basedir, 'src/files/xml/test2.xml2'); +assert file.exists(); + +content = file.text; +assert content.startsWith( "<?xml version='1.0' encoding='UTF-8'?>" ); +assert content.contains( 'Copyright (C)' ); +assert content.contains( '#%L' ); +assert content.contains( '#L%' ); +assert content.contains( '$Id' ); + +file = new File(basedir, 'src/files/properties/test.properties2'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '# #%L' ); +assert content.contains( '# #L%' ); +assert !content.contains( '# # \n' ); +assert content.contains( '$Id' ); + + +file = new File(basedir, 'src/files/properties/test2.properties2'); +assert file.exists(); + +content = file.text; +assert content.contains( 'Copyright (C)' ); +assert content.contains( '# #%L' ); +assert content.contains( '# #L%' ); +assert content.contains( '# #%L' ); +assert !content.contains( '# # \n' ); +assert content.contains( '$Id' ); + +return true; Modified: trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseWithDescriptorMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseWithDescriptorMojo.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseWithDescriptorMojo.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -28,31 +28,15 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; -import org.nuiton.license.plugin.header.FileHeader; -import org.nuiton.license.plugin.header.transformer.AptFileHeaderTransformer; -import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer; -import org.nuiton.license.plugin.header.transformer.JavaFileHeaderTransformer; -import org.nuiton.license.plugin.header.transformer.PropertiesFileHeaderTransformer; -import org.nuiton.license.plugin.header.transformer.RstFileHeaderTransformer; -import org.nuiton.license.plugin.header.transformer.XmlFileHeaderTransformer; import org.nuiton.license.plugin.model.License; import org.nuiton.license.plugin.model.LicenseStore; -import org.nuiton.license.plugin.model.descriptor.FileSet; -import org.nuiton.license.plugin.model.descriptor.Header; import org.nuiton.license.plugin.model.descriptor.LicenseProjectDescriptor; import org.nuiton.license.plugin.model.descriptor.io.xpp3.LicenseProjectDescriptorXpp3Reader; import org.nuiton.plugin.PluginWithEncoding; import java.io.File; import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; /** * Abstract mojo which using {@link #descriptor} file and owns a @@ -77,11 +61,15 @@ /** * The project license descriptor file. + * <p/> + * <b>Note:</b> This parameter is no more required as it will be removed in + * version 3. * * @parameter expression="${license.descriptor}" default-value="src/license/project.xml" - * @required * @since 2.1 + * @deprecated since 2.4.1, in version 3 we will no more use descriptor */ + @Deprecated private File descriptor; /** @@ -102,73 +90,24 @@ private boolean keepBackup; /** - * All available header transformers. + * Name of the license to use in the project. * - * @component role="org.nuiton.license.plugin.header.transformer.FileHeaderTransformer" - * @since 2.1 - */ - private Map<String, FileHeaderTransformer> transformers; - - /** - * Name of the license to use for files. - * * @parameter expression="${license.licenseName}" * @since 2.4 */ - protected String licenseName; + private String licenseName; - /** - * To specify the base dir from which we apply the license. - * Should be on form "root1,root2,rootn". - * By default, the main root is "src". - * - * @parameter expression="${license.roots}" - * @since 2.4 - */ - protected String[] roots; + /** store of licenses */ + private LicenseStore licenseStore; /** - * Specific files to includes, separated by a comma. By default, it is "** /*". + * descriptor of project. * - * @parameter expression="${license.includes}" - * @since 2.4 + * @deprecated since 2.4.1, in version 3 we will no more use a descriptor file to describe project license. */ - protected String[] includes; - - /** - * Specific files to excludes, separated by a comma. - * By default, thoses file type are excluded: - * <ul> - * <li>modelisation</li> - * <li>images</li> - * <li>i18n properties</li> - * </ul> - * - * @parameter expression="${license.excludes}" - * @since 2.4 - */ - protected String[] excludes; - - /** store of licenses */ - private LicenseStore licenseStore; - - /** descriptor of project */ + @Deprecated private LicenseProjectDescriptor licenseProjectDescriptor; - /** Map that contains each files indexed by their CommentStyle */ - private Map<String, List<File>> universe; - - public static final String[] DEFAULT_INCLUDES = new String[]{"**/*"}; - - public static final String[] DEFAULT_EXCLUDES = new String[]{ - "**/*.zargo", "**/*.uml", "**/*.umldi", "**/*.xmi", /* modelisation */ - "**/*.img", "**/*.png", "**/*.jpg", "**/*.jpeg", "**/*.gif", /* images */ - "**/i18n/*.properties", - "**/*.zip" - }; - - public static final String[] DEFAULT_ROOTS = new String[]{"src"}; - /** * When is sets to {@code true}, will skip execution. * <p/> @@ -230,61 +169,21 @@ } if (!descriptorFile.exists()) { + // No descriptor File: use no descriptor // check licenseName exists checkLicense(licenseName); - // Map that will contain all the files, grouped by root directory - Map<File, String[]> filesToTreat = new HashMap<File, String[]>(); - - // Init default value for roots and includes - if (roots == null || roots.length == 0) { - roots = DEFAULT_ROOTS; - getLog().info("Will use default roots " + - Arrays.toString(roots)); - } -// List<String> rootsList = Arrays.asList(getRoots()); - List<String> rootsList = new ArrayList<String>(roots.length); - for (String root : roots) { - File f = new File(root); - if (f.isAbsolute()) { - rootsList.add(f.getAbsolutePath()); - } else { - rootsList.add(new File(getProject().getBasedir(), root).getAbsolutePath()); - } - } - - if (includes == null || includes.length == 0) { - includes = DEFAULT_INCLUDES; - getLog().info("Will use default includes " + - Arrays.toString(includes)); - } - - if (excludes == null || excludes.length == 0) { - excludes = DEFAULT_EXCLUDES; - getLog().info("Will use default excludes" + - Arrays.toString(excludes)); - } - - // Get all files ordered by roots - getFilesToTreateForRoots(includes, excludes, rootsList, - filesToTreat, null); - - // we got all files: treat them - treatFilesByCommentStyle(filesToTreat, - licenseStore, - getTransformers()); - return; } // Will use the deprecated license project descriptor getLog().warn("\n"); - getLog().warn("-------------------------------------------------------------------------"); - getLog().warn("The use of Descriptor File is deprecated and will be removed in version 3"); - getLog().warn("-------------------------------------------------------------------------"); + getLog().warn("-----------------------------------------------------------------------------------"); + getLog().warn("The usage of License descriptor file is deprecated and will be removed in version 3"); + getLog().warn("-----------------------------------------------------------------------------------"); getLog().warn("\n"); getLog().info("Loading descriptor " + descriptorFile); @@ -294,6 +193,7 @@ licenseProject = new LicenseProjectDescriptorXpp3Reader().read(reader); setLicenseProjectDescriptor(licenseProject); + } finally { reader.close(); } @@ -301,134 +201,27 @@ // check that license project is sane (known licenses + header types) // + populate default license name in LicenseSet (with main License) if // none given for licenseSet - validateLicenseProjectDescriptor(licenseProject, - licenseStore, - getTransformers() - ); + validateLicenseProjectDescriptor(licenseProject); } - @Override - public final String getEncoding() { - return encoding; - } + @Deprecated + protected void validateLicenseProjectDescriptor(LicenseProjectDescriptor licenseProjectDescriptor) throws MojoFailureException { + String mainLicense = licenseProjectDescriptor.getMainLicense(); - @Override - public final void setEncoding(String encoding) { - this.encoding = encoding; - } + checkLicense(mainLicense); - public File getDescriptor() { - return descriptor; + setLicenseName(mainLicense); } - public boolean isKeepBackup() { - return keepBackup; - } - - public Map<String, FileHeaderTransformer> getTransformers() { - return transformers; - } - - public String getLicenseName() { - return licenseName; - } - - public String[] getRoots() { - return roots; - } - - public String[] getIncludes() { - return includes; - } - - public String[] getExcludes() { - return excludes; - } - - public String getLicenseResolver() { - return licenseResolver; - } - - public LicenseStore getLicenseStore() { - return licenseStore; - } - - public LicenseProjectDescriptor getLicenseProjectDescriptor() { - return licenseProjectDescriptor; - } - - public Map<String, List<File>> getUniverse() { - return universe; - } - - public void setKeepBackup(boolean keepBackup) { - this.keepBackup = keepBackup; - } - - public void setDescriptor(File descriptor) { - this.descriptor = descriptor; - } - - public void setLicenseResolver(String licenseResolver) { - this.licenseResolver = licenseResolver; - } - - public void setTransformers( - Map<String, FileHeaderTransformer> transformers) { - this.transformers = transformers; - } - - public void setLicenseName(String licenseName) { - this.licenseName = licenseName; - } - - public void setRoots(String[] roots) { - this.roots = roots; - } - - public void setRoots(String roots) { - this.roots = roots.split(","); - } - - public void setIncludes(String[] includes) { - this.includes = includes; - } - - public void setIncludes(String includes) { - this.includes = includes.split(","); - } - - public void setExcludes(String[] excludes) { - this.excludes = excludes; - } - - public void setExcludes(String excludes) { - this.excludes = excludes.split(","); - } - - public void setLicenseStore(LicenseStore licenseStore) { - this.licenseStore = licenseStore; - } - - - public void setLicenseProjectDescriptor( - LicenseProjectDescriptor licenseProjectDescriptor) { - this.licenseProjectDescriptor = licenseProjectDescriptor; - } - - public void setUniverse(Map<String, List<File>> universe) { - this.universe = universe; - } - public License getMainLicense() throws IllegalArgumentException, IllegalStateException, MojoFailureException { - LicenseProjectDescriptor licenseProject = getLicenseProjectDescriptor(); - if (licenseProject != null) { +// LicenseProjectDescriptor licenseProject = getLicenseProjectDescriptor(); +// if (licenseProject != null) { +// +// // use the main license from the license project descriptor +// licenseName = licenseProject.getMainLicense(); +// } - // use the main license from the license project descriptor - licenseName = licenseProject.getMainLicense(); - } - // check license exists checkLicense(licenseName); @@ -451,179 +244,7 @@ return mainLicense; } - public FileHeaderTransformer getTransformer(String transformerName) - throws IllegalArgumentException, IllegalStateException { - if (StringUtils.isEmpty(transformerName)) { - throw new IllegalArgumentException( - "transformerName can not be null, nor empty!"); - } - Map<String, FileHeaderTransformer> transformers = getTransformers(); - if (transformers == null) { - throw new IllegalStateException("No transformers initialized!"); - } - FileHeaderTransformer transformer = - transformers.get(transformerName); - return transformer; - } - /** - * Build a default header given the parameters. - * - * @param license the license type ot use in header - * @param projectName project name as header description - * @param inceptionYear first year of copyright - * @param copyrightHolder holder of copyright - * @param encoding encoding used to read or write files - * @param addSvnKeyWords a flag to add in description section svn keywords - * @return the new file header - * @throws IOException if any problem while creating file header - */ - protected FileHeader buildDefaultFileHeader( - License license, - String projectName, - String inceptionYear, - String copyrightHolder, - boolean addSvnKeyWords, - String encoding) throws IOException { - FileHeader result = new FileHeader(); - - StringBuilder buffer = new StringBuilder(); - buffer.append(projectName); - if (addSvnKeyWords) { - // add svn keyworks - char ls = FileHeaderTransformer.LINE_SEPARATOR; - buffer.append(ls); - - // breaks the keyword otherwise svn will update them here - //TC-20100415 : do not generate thoses redundant keywords -// buffer.append(ls).append("$" + "Author$"); -// buffer.append(ls).append("$" + "LastChangedDate$"); -// buffer.append(ls).append("$" + "LastChangedRevision$"); - buffer.append(ls).append("$" + "Id$"); - buffer.append(ls).append("$" + "HeadURL$"); - - } - result.setDescription(buffer.toString()); - if (getLog().isDebugEnabled()) { - getLog().debug("header description : " + result.getDescription()); - } - - String licenseContent = license.getHeaderContent(encoding); - result.setLicense(licenseContent); - - Integer firstYear = Integer.valueOf(inceptionYear); - result.setCopyrightFirstYear(firstYear); - - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - Integer lastYear = cal.get(Calendar.YEAR); - if (firstYear < lastYear) { - result.setCopyrightLastYear(lastYear); - } - result.setCopyrightHolder(copyrightHolder); - return result; - } - - protected void validateLicenseProjectDescriptor( - LicenseProjectDescriptor licenseProjectDescriptor, - LicenseStore licenseStore, - Map<String, FileHeaderTransformer> transformers) - throws MojoFailureException { - - // check licenses is known - String mainLicense = licenseProjectDescriptor.getMainLicense(); - - checkLicense(mainLicense); - - Header singleHeader = licenseProjectDescriptor.getHeader(); - if (singleHeader != null) { - - // add it to set (and remove it from single) - licenseProjectDescriptor.addHeader(singleHeader); - licenseProjectDescriptor.setHeader(null); - } - - for (Header header : licenseProjectDescriptor.getHeaders()) { - - String headerType = header.getCommentStyle(); - - if (getTransformer(headerType) == null) { - throw new MojoFailureException( - "headerType '" + headerType + - "' is unknown, use one of " + transformers.keySet()); - } - String licenseName = header.getLicenseName(); - if (StringUtils.isEmpty(licenseName)) { - - // use the main license - header.setLicenseName(mainLicense); - } else { - - // check license name - checkLicense(licenseName); - } - - FileSet singleFileSet = header.getFileSet(); - if (singleFileSet != null) { - - // add it to set (and remove it from single) - header.addFileSet(singleFileSet); - header.setFileSet(null); - } - for (FileSet fileSet : header.getFileSets()) { - - String singleInclude = fileSet.getInclude(); - if (singleInclude != null) { - - // add it to set (and remove it from single) - fileSet.addInclude(singleInclude); - fileSet.setInclude(null); - } - - String singleExclude = fileSet.getExclude(); - if (singleExclude != null) { - - // add it to set (and remove it from single) - fileSet.addExclude(singleExclude); - fileSet.setExclude(null); - } - } - } - } - - protected void treatFilesByCommentStyle( - Map<File, String[]> filesToTreat, - LicenseStore licenseStore, - Map<String, FileHeaderTransformer> transformers) { - - universe = new HashMap<String, List<File>>(); - - for (Map.Entry<File, String[]> entry : filesToTreat.entrySet()) { - File root = entry.getKey(); - String[] filesPath = entry.getValue(); - - // Foreach file, sort them by CS - for (String path : filesPath) { - String[] splitPath = path.split("\\."); - String extension = splitPath[splitPath.length - 1]; - File file = new File(root, path); - String commentStyle = getCommentStyle(extension); - - if (commentStyle != null && !commentStyle.isEmpty()) { - List<File> files = universe.get(commentStyle); - if (files == null) { - files = new ArrayList<File>(); - universe.put(commentStyle, files); - } - files.add(file); - } - - } - } - - } - - /** * Check if the given license name is valid (not null, nor empty) and * exists in the license store. * @@ -653,34 +274,66 @@ } } - /** - * Obtain the known Comment style from the given extension - * - * @param extension the extension to match with a comment style - * @return the known comment style, or null if not found - */ - protected String getCommentStyle(String extension) { + @Override + public final String getEncoding() { + return encoding; + } - // trim the extension - extension = extension.trim(); + @Override + public final void setEncoding(String encoding) { + this.encoding = encoding; + } - if (JavaFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { - return JavaFileHeaderTransformer.NAME; - } - if (XmlFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { - return XmlFileHeaderTransformer.NAME; - } - if (AptFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { - return AptFileHeaderTransformer.NAME; - } - if (PropertiesFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { - return PropertiesFileHeaderTransformer.NAME; - } - if (RstFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { - return RstFileHeaderTransformer.NAME; - } + @Deprecated + public File getDescriptor() { + return descriptor; + } - return null; + public boolean isKeepBackup() { + return keepBackup; } + public String getLicenseName() { + return licenseName; + } + + public String getLicenseResolver() { + return licenseResolver; + } + + public LicenseStore getLicenseStore() { + return licenseStore; + } + + @Deprecated + public LicenseProjectDescriptor getLicenseProjectDescriptor() { + return licenseProjectDescriptor; + } + + public void setKeepBackup(boolean keepBackup) { + this.keepBackup = keepBackup; + } + + @Deprecated + public void setDescriptor(File descriptor) { + this.descriptor = descriptor; + } + + public void setLicenseResolver(String licenseResolver) { + this.licenseResolver = licenseResolver; + } + + public void setLicenseName(String licenseName) { + this.licenseName = licenseName; + } + + public void setLicenseStore(LicenseStore licenseStore) { + this.licenseStore = licenseStore; + } + + @Deprecated + public void setLicenseProjectDescriptor( + LicenseProjectDescriptor licenseProjectDescriptor) { + this.licenseProjectDescriptor = licenseProjectDescriptor; + } } Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateFileHeaderMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/UpdateFileHeaderMojo.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/main/java/org/nuiton/license/plugin/UpdateFileHeaderMojo.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -26,22 +26,33 @@ package org.nuiton.license.plugin; import org.apache.commons.lang.StringUtils; +import org.apache.maven.plugin.MojoFailureException; import org.codehaus.plexus.util.FileUtils; import org.nuiton.license.plugin.header.FileHeader; import org.nuiton.license.plugin.header.FileHeaderProcessor; import org.nuiton.license.plugin.header.FileHeaderProcessorConfiguration; import org.nuiton.license.plugin.header.InvalideFileHeaderException; import org.nuiton.license.plugin.header.UpdateFileHeaderFilter; +import org.nuiton.license.plugin.header.transformer.AptFileHeaderTransformer; import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer; +import org.nuiton.license.plugin.header.transformer.JavaFileHeaderTransformer; +import org.nuiton.license.plugin.header.transformer.PropertiesFileHeaderTransformer; +import org.nuiton.license.plugin.header.transformer.RstFileHeaderTransformer; +import org.nuiton.license.plugin.header.transformer.XmlFileHeaderTransformer; import org.nuiton.license.plugin.model.License; import org.nuiton.license.plugin.model.descriptor.FileSet; import org.nuiton.license.plugin.model.descriptor.Header; +import org.nuiton.license.plugin.model.descriptor.LicenseProjectDescriptor; import org.nuiton.plugin.PluginHelper; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; import java.util.EnumMap; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -190,27 +201,125 @@ protected boolean clearAfterOperation; /** + * To specify the base dir from which we apply the license. + * <p/> + * Should be on form "root1,root2,rootn". + * <p/> + * By default, the main roots are "src, target/generated-sources, target/processed-sources". + * <p/> + * <b>Note:</b> If some of these roots do not exist, they will be simply + * ignored. + * <p/> + * <b>Note:</b> This parameter is not useable if you are still using a project file descriptor. + * + * @parameter expression="${license.roots}" + * @since 2.4 + */ + protected String[] roots; + + /** + * Specific files to includes, separated by a comma. By default, it is "** /*". + * <p/> + * <b>Note:</b> This parameter is not useable if you are still using a project file descriptor. + * + * @parameter expression="${license.includes}" + * @since 2.4 + */ + protected String[] includes; + + /** + * Specific files to excludes, separated by a comma. + * By default, thoses file type are excluded: + * <ul> + * <li>modelisation</li> + * <li>images</li> + * <li>i18n properties</li> + * </ul> + * <p/> + * <b>Note:</b> This parameter is not useable if you are still using a project file descriptor. + * + * @parameter expression="${license.excludes}" + * @since 2.4 + */ + protected String[] excludes; + + /** + * To associate extra extension files to an existing comment style. + * <p/> + * Keys of the map are the extension of extra files to treate, and the value + * is the comment style you want to associate. + * <p/> + * For example, to treate file with extensions {@code java2} and {@code jdata} + * as {@code java} files (says using the {@code java} comment style, declare this + * in your plugin configuration : + * <pre> + * <extraExtensions> + * <java2>java</java2> + * <jdata>java</jdata> + * </extraExtensions> + * </pre> + * <p/> + * <b>Note:</b> This parameter is not useable if you are still using a project file descriptor. + * + * @parameter + * @since 2.4.1 + */ + protected Map<String, String> extraExtensions; + + /** * @component role="org.nuiton.processor.Processor" roleHint="file-header" * @since 2.1 */ - protected FileHeaderProcessor processor; + private FileHeaderProcessor processor; /** + * The processor filter used to change header content. + * * @component role="org.nuiton.license.plugin.header.FileHeaderFilter" roleHint="update-file-header" * @since 2.1 */ - protected UpdateFileHeaderFilter filter; + private UpdateFileHeaderFilter filter; - /** internal file header transformer */ - protected FileHeaderTransformer transformer; + /** + * All available header transformers. + * + * @component role="org.nuiton.license.plugin.header.transformer.FileHeaderTransformer" + * @since 2.1 + */ + private Map<String, FileHeaderTransformer> transformers; - /** internal default file header */ - protected FileHeader header; + /** internal file header transformer. */ + private FileHeaderTransformer transformer; - /** timestamp used for generation */ - protected long timestamp; + /** internal default file header. */ + private FileHeader header; + /** timestamp used for generation. */ + private long timestamp; + /** + * The dictionnary of extension indexed by their associated comment style. + * + * @since 2.4.1 + */ + private Map<String, String> extensionToCommentStyle; + + public static final String[] DEFAULT_INCLUDES = new String[]{"**/*"}; + + public static final String[] DEFAULT_EXCLUDES = new String[]{ + "**/*.zargo", "**/*.uml", "**/*.umldi", "**/*.xmi", /* modelisation */ + "**/*.img", "**/*.png", "**/*.jpg", "**/*.jpeg", "**/*.gif", /* images */ + "**/i18n/*.properties", + "**/*.zip" + }; + + public static final String[] DEFAULT_ROOTS = new String[]{ + "src", + "target/generated-sources", + "target/processed-sources" + }; + + /** * Defines state of a file after process. * * @author tchemit <chemit@codelutin.com> @@ -251,11 +360,14 @@ } /** set of processed files */ - protected Set<File> processedFiles; + private Set<File> processedFiles; - /** by file state files treated */ - protected EnumMap<FileState, Set<File>> result; + /** Dictionnary of treated files indexed by their state. */ + private EnumMap<FileState, Set<File>> result; + /** Dictonnary of files to treate indexed by their CommentStyle. */ + private Map<String, List<File>> filesToTreateByCommentStyle; + @Override public void init() throws Exception { @@ -310,8 +422,215 @@ getProcessor().setFilter(filter); super.init(); + + // this block will be removed in version 3 + if (getLicenseProjectDescriptor() != null) { + + // use the main license from the license project descriptor + setLicenseName(getLicenseProjectDescriptor().getMainLicense()); + + // get all files to treate indexed by their comment style + filesToTreateByCommentStyle = obtainFilesToTreateByCommentStyle(); + return; + } + + if (roots == null || roots.length == 0) { + roots = DEFAULT_ROOTS; + if (isVerbose()) { + getLog().info("Will use default roots " + + Arrays.toString(roots)); + } + } + + if (includes == null || includes.length == 0) { + includes = DEFAULT_INCLUDES; + if (isVerbose()) { + getLog().info("Will use default includes " + + Arrays.toString(includes)); + } + } + + if (excludes == null || excludes.length == 0) { + excludes = DEFAULT_EXCLUDES; + if (isVerbose()) { + getLog().info("Will use default excludes" + + Arrays.toString(excludes)); + } + } + + extensionToCommentStyle = new TreeMap<String, String>(); + + // always clean accepted extension on all transformer + for (FileHeaderTransformer transformer : transformers.values()) { + transformer.resetAcceptedExtensions(); + } + + if (extraExtensions != null) { + + // fill extra extensions for each transformer + for (Map.Entry<String, String> entry : extraExtensions.entrySet()) { + String extension = entry.getKey(); + + String commentStyle = entry.getValue(); + FileHeaderTransformer transformer = getTransformer(commentStyle); + if (transformer.acceptExtension(extension)) { + + // this extension is already accepted + getLog().warn("The extension " + extension + + " is already accepted for comment style " + + commentStyle + ", skip it."); + continue; + } + transformer.addAcceptedExtension(extension); + if (isVerbose()) { + getLog().info("Associate extension '" + extension + + "' to comment style '" + commentStyle + + "'"); + } + } + } + + // fill the cache of known extension now : in that way we can know + // directly while looking for a comment style from an extension in later + // code + for (Map.Entry<String, FileHeaderTransformer> entry : + transformers.entrySet()) { + String commentStyle = entry.getKey(); + FileHeaderTransformer transformer = entry.getValue(); + String[] extensions = transformer.getAcceptedExtensions(); + for (String extension : extensions) { + + // check that extension is not in conflict with another one + if (extensionToCommentStyle.containsKey(extension)) { + String conflictCommentStyle = + extensionToCommentStyle.get(extension); + throw new MojoFailureException( + "The extension " + extension + + " associated with the comment style " + + commentStyle + " was already associated with " + + "another comment style : " + conflictCommentStyle); + } + + // can safely add this extension + extensionToCommentStyle.put(extension, commentStyle); + } + } + + // get all files to treate indexed by their comment style + filesToTreateByCommentStyle = obtainFilesToTreateByCommentStyle(); } + protected Map<String, List<File>> obtainFilesToTreateByCommentStyle() { + + Map<String, List<File>> result = new HashMap<String, List<File>>(); + + // add for all known comment style (says transformer) a empty list + // this permits not to have to test if there is an already list each time + // we wants to add a new file... + for (String commentStyle : transformers.keySet()) { + result.put(commentStyle, new ArrayList<File>()); + } + + // this block will be removed in version 3 + if (getLicenseProjectDescriptor() != null) { + + List<Header> headers = getLicenseProjectDescriptor().getHeaders(); + + for (Header header : headers) { + + String commentStyle = header.getCommentStyle(); + + List<File> filesForCS = result.get(commentStyle); + + for (FileSet fileSet : header.getFileSets()) { + + File basedir = new File(getProject().getBasedir(), + fileSet.getBasedir()); + if (getLog().isDebugEnabled()) { + getLog().debug(" - process file set with basedir : " + basedir); + } + + List<String> includes = fileSet.getIncludes(); + if (includes.isEmpty()) { + + // it means include all + includes.add("**/*"); + } + List<String> excludes = fileSet.getExcludes(); + + Map<File, String[]> filestoTreate = new TreeMap<File, String[]>(); + + // obtain files to treate + getFilesToTreateForRoots( + includes.toArray(new String[includes.size()]), + excludes.isEmpty() ? null : + excludes.toArray(new String[excludes.size()]), + Arrays.asList(basedir.getAbsolutePath()), + filestoTreate, + null + ); + + try { + for (Map.Entry<File, String[]> entry : + filestoTreate.entrySet()) { + + File rootFile = entry.getKey(); + + for (String path : entry.getValue()) { + + filesForCS.add(new File(rootFile, path)); + } + } + } finally { + filestoTreate.clear(); + } + } + } + return result; + } + + List<String> rootsList = new ArrayList<String>(roots.length); + for (String root : roots) { + File f = new File(root); + if (f.isAbsolute()) { + rootsList.add(f.getAbsolutePath()); + } else { + f = new File(getProject().getBasedir(), root); + } + if (f.exists()) { + getLog().info("Will search files to update from root " + f); + rootsList.add(f.getAbsolutePath()); + } + } + + // Obtain all files to treate + Map<File, String[]> allFiles = new HashMap<File, String[]>(); + getFilesToTreateForRoots(includes, excludes, rootsList, allFiles, null); + + // filter all these files according to their extension + + for (Map.Entry<File, String[]> entry : allFiles.entrySet()) { + File root = entry.getKey(); + String[] filesPath = entry.getValue(); + + // sort them by the associated comment style to their extension + for (String path : filesPath) { + String extension = FileUtils.extension(path); + String commentStyle = extensionToCommentStyle.get(extension); + if (StringUtils.isEmpty(commentStyle)) { + + // unknown extension, do not treate this file + continue; + } + // + File file = new File(root, path); + List<File> files = result.get(commentStyle); + files.add(file); + } + } + return result; + } + @Override public void doAction() throws Exception { @@ -324,20 +643,13 @@ try { - // No headers, use treat by CommentStyle ! - if (getLicenseProjectDescriptor() == null) { - for (Map.Entry<String, List<File>> commentStyleFiles : getUniverse().entrySet()) { - String commentStyle = commentStyleFiles.getKey(); - List<File> files = commentStyleFiles.getValue(); + for (Map.Entry<String, List<File>> commentStyleFiles : + getFilesToTreateByCommentStyle().entrySet()) { - processCommentStyle(commentStyle, files); - } - } else { - List<Header> headers = getLicenseProjectDescriptor().getHeaders(); - for (Header header : headers) { + String commentStyle = commentStyleFiles.getKey(); + List<File> files = commentStyleFiles.getValue(); - processHeader(header); - } + processCommentStyle(commentStyle, files); } } finally { @@ -377,76 +689,6 @@ } } - protected void processHeader(Header header) throws IOException { - - // obtain license from definition - String licenseName = header.getLicenseName(); - License license = getLicense(licenseName); - - String commentStyle = header.getCommentStyle(); - getLog().info("Process header '" + commentStyle + "'"); - getLog().info(" - using " + license.getDescription()); - - // use header transformer according to comment style given in header - setTransformer(getTransformer(commentStyle)); - - // file header to use if no header is found on a file - FileHeader defaultFileHeader = buildDefaultFileHeader( - license, - getProjectName(), - getInceptionYear(), - getOrganizationName(), - isAddSvnKeyWords(), - getEncoding() - ); - - // change default license header in processor - setHeader(defaultFileHeader); - - // update processor filter - getProcessor().populateFilter(); - - for (FileSet fileSet : header.getFileSets()) { - - File basedir = new File(getProject().getBasedir(), - fileSet.getBasedir()); - if (getLog().isDebugEnabled()) { - getLog().debug(" - process file set with basedir : " + basedir); - } - - List<String> includes = fileSet.getIncludes(); - if (includes.isEmpty()) { - - // it means include all - includes.add("**/*"); - } - List<String> excludes = fileSet.getExcludes(); - - Map<File, String[]> filestoTreate = new TreeMap<File, String[]>(); - - // obtain files to treate - getFilesToTreateForRoots( - includes.toArray(new String[includes.size()]), - excludes.isEmpty() ? null : - excludes.toArray(new String[excludes.size()]), - Arrays.asList(basedir.getAbsolutePath()), - filestoTreate, - null - ); - - try { - for (Map.Entry<File, String[]> entry : - filestoTreate.entrySet()) { - - // treat all files of entry - processFileEntry(entry.getKey(), entry.getValue()); - } - } finally { - filestoTreate.clear(); - } - } - } - protected void processCommentStyle(String commentStyle, List<File> filesToTreat) throws IOException { @@ -476,7 +718,7 @@ // update processor filter getProcessor().populateFilter(); - for (File file: filesToTreat) { + for (File file : filesToTreat) { prepareProcessFile(file); } filesToTreat.clear(); @@ -521,48 +763,6 @@ } - protected void processFileEntry(File entryBasedir, - String[] paths) throws IOException { - - getLog().info(" - " + paths.length + " file(s) to treate in " + entryBasedir); - for (String path : paths) { - File file = new File(entryBasedir, path); - if (getProcessedFiles().contains(file)) { - getLog().info(" - skip already processed file " + file); - continue; - } - - // output file - File processFile = - new File(file.getAbsolutePath() + "_" + getTimestamp()); - boolean doFinalize = false; - try { - doFinalize = processFile(file, processFile); - } catch (Exception e) { - getLog().warn("skip failed file : " + - e.getMessage() + - (e.getCause() == null ? "" : - " Cause : " + e.getCause().getMessage()), e - ); - FileState.fail.addFile(file, getResult()); - doFinalize = false; - } finally { - - // always clean processor internal states - getProcessor().reset(); - - // whatever was the result, this file is treated. - getProcessedFiles().add(file); - - if (doFinalize) { - finalizeFile(file, processFile); - } else { - deleteFile(processFile); - } - } - } - } - /** * Process the given {@code file} and save the result in the given * {@code processFile}. @@ -656,7 +856,7 @@ getLog().info(" - adding license header on file " + file); - //FIXME-TC-20100409 form xml files must add header after a xml prolog line + //FIXME tchemit 20100409 xml files must add header after a xml prolog line content = getTransformer().addHeader( getFilter().getFullHeaderContent(), content @@ -695,7 +895,7 @@ } else { try { - + // replace file with the updated one renameFile(processFile, file); } catch (IOException e) { @@ -758,6 +958,177 @@ } } + /** + * Build a default header given the parameters. + * + * @param license the license type ot use in header + * @param projectName project name as header description + * @param inceptionYear first year of copyright + * @param copyrightHolder holder of copyright + * @param encoding encoding used to read or write files + * @param addSvnKeyWords a flag to add in description section svn keywords + * @return the new file header + * @throws IOException if any problem while creating file header + */ + protected FileHeader buildDefaultFileHeader( + License license, + String projectName, + String inceptionYear, + String copyrightHolder, + boolean addSvnKeyWords, + String encoding) throws IOException { + FileHeader result = new FileHeader(); + + StringBuilder buffer = new StringBuilder(); + buffer.append(projectName); + if (addSvnKeyWords) { + // add svn keyworks + char ls = FileHeaderTransformer.LINE_SEPARATOR; + buffer.append(ls); + + // breaks the keyword otherwise svn will update them here + //TC-20100415 : do not generate thoses redundant keywords +// buffer.append(ls).append("$" + "Author$"); +// buffer.append(ls).append("$" + "LastChangedDate$"); +// buffer.append(ls).append("$" + "LastChangedRevision$"); + buffer.append(ls).append("$" + "Id$"); + buffer.append(ls).append("$" + "HeadURL$"); + + } + result.setDescription(buffer.toString()); + if (getLog().isDebugEnabled()) { + getLog().debug("header description : " + result.getDescription()); + } + + String licenseContent = license.getHeaderContent(encoding); + result.setLicense(licenseContent); + + Integer firstYear = Integer.valueOf(inceptionYear); + result.setCopyrightFirstYear(firstYear); + + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + Integer lastYear = cal.get(Calendar.YEAR); + if (firstYear < lastYear) { + result.setCopyrightLastYear(lastYear); + } + result.setCopyrightHolder(copyrightHolder); + return result; + } + + /** + * Obtain the known Comment style from the given extension + * + * @param extension the extension to match with a comment style + * @return the known comment style, or null if not found + */ + protected String getCommentStyleForExtenion(String extension) { + + // trim the extension + extension = extension.trim(); + + if (JavaFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { + return JavaFileHeaderTransformer.NAME; + } + if (XmlFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { + return XmlFileHeaderTransformer.NAME; + } + if (AptFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { + return AptFileHeaderTransformer.NAME; + } + if (PropertiesFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { + return PropertiesFileHeaderTransformer.NAME; + } + if (RstFileHeaderTransformer.NAME.equalsIgnoreCase(extension)) { + return RstFileHeaderTransformer.NAME; + } + + return null; + } + + public FileHeaderTransformer getTransformer(String transformerName) + throws IllegalArgumentException, IllegalStateException { + if (StringUtils.isEmpty(transformerName)) { + throw new IllegalArgumentException( + "transformerName can not be null, nor empty!"); + } + Map<String, FileHeaderTransformer> transformers = getTransformers(); + if (transformers == null) { + throw new IllegalStateException("No transformers initialized!"); + } + FileHeaderTransformer transformer = + transformers.get(transformerName); + if (transformer == null) { + throw new IllegalArgumentException( + "transformerName " + transformerName + " is unknow, use one this one : " + transformers.keySet()); + } + return transformer; + } + + @Override + protected void validateLicenseProjectDescriptor(LicenseProjectDescriptor licenseProjectDescriptor) + throws MojoFailureException { + + super.validateLicenseProjectDescriptor(licenseProjectDescriptor); + + String mainLicense = licenseProjectDescriptor.getMainLicense(); + + Header singleHeader = licenseProjectDescriptor.getHeader(); + if (singleHeader != null) { + + // add it to set (and remove it from single) + licenseProjectDescriptor.addHeader(singleHeader); + licenseProjectDescriptor.setHeader(null); + } + + for (Header header : licenseProjectDescriptor.getHeaders()) { + + String headerType = header.getCommentStyle(); + + if (getTransformer(headerType) == null) { + throw new MojoFailureException( + "headerType '" + headerType + + "' is unknown, use one of " + transformers.keySet()); + } + String licenseName = header.getLicenseName(); + if (StringUtils.isEmpty(licenseName)) { + + // use the main license + header.setLicenseName(mainLicense); + } else { + + // check license name + checkLicense(licenseName); + } + + FileSet singleFileSet = header.getFileSet(); + if (singleFileSet != null) { + + // add it to set (and remove it from single) + header.addFileSet(singleFileSet); + header.setFileSet(null); + } + for (FileSet fileSet : header.getFileSets()) { + + String singleInclude = fileSet.getInclude(); + if (singleInclude != null) { + + // add it to set (and remove it from single) + fileSet.addInclude(singleInclude); + fileSet.setInclude(null); + } + + String singleExclude = fileSet.getExclude(); + if (singleExclude != null) { + + // add it to set (and remove it from single) + fileSet.addExclude(singleExclude); + fileSet.setExclude(null); + } + } + } + } + public boolean isClearAfterOperation() { return clearAfterOperation; } @@ -841,6 +1212,14 @@ return processor; } + public Map<String, FileHeaderTransformer> getTransformers() { + return transformers; + } + + public Map<String, List<File>> getFilesToTreateByCommentStyle() { + return filesToTreateByCommentStyle; + } + @Override public void setSkip(boolean skipUpdateLicense) { this.skipUpdateLicense = skipUpdateLicense; @@ -913,4 +1292,36 @@ public void setCanUpdateLicense(boolean canUpdateLicense) { this.canUpdateLicense = canUpdateLicense; } + + public void setTransformers(Map<String, FileHeaderTransformer> transformers) { + this.transformers = transformers; + } + + public void setFilesToTreateByCommentStyle(Map<String, List<File>> filesToTreateByCommentStyle) { + this.filesToTreateByCommentStyle = filesToTreateByCommentStyle; + } + + public void setRoots(String[] roots) { + this.roots = roots; + } + + public void setRoots(String roots) { + this.roots = roots.split(","); + } + + public void setIncludes(String[] includes) { + this.includes = includes; + } + + public void setIncludes(String includes) { + this.includes = includes.split(","); + } + + public void setExcludes(String[] excludes) { + this.excludes = excludes; + } + + public void setExcludes(String excludes) { + this.excludes = excludes.split(","); + } } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -27,6 +27,8 @@ import org.nuiton.license.plugin.header.FileHeader; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -79,6 +81,9 @@ /** comment line prefix (to add for header content) */ protected String commentLinePrefix; + /** List of accepted extensions. */ + protected List<String> acceptedExtensions; + protected AbstractFileHeaderTransformer(String name, String description, String commentStartTag, @@ -86,6 +91,7 @@ String commentLinePrefix) { this.name = name; this.description = description; + acceptedExtensions = new ArrayList<String>(); // checks comment start tag is different from comment prefix if (commentStartTag.equals(commentLinePrefix)) { @@ -122,6 +128,35 @@ } @Override + public boolean acceptExtension(String fileExtension) { + + // always test on a safe trimed lower case extension + String safeExtension = fileExtension.trim().toLowerCase(); + return acceptedExtensions.contains(safeExtension); + } + + @Override + public void resetAcceptedExtensions() { + acceptedExtensions.clear(); + addAcceptedExtension(getDefaultAcceptedExtension()); + } + + @Override + public void addAcceptedExtension(String extension) { + // keep trim low case extension + String safeExtension = extension.trim().toLowerCase(); + + if (!acceptedExtensions.contains(safeExtension)) { + acceptedExtensions.add(safeExtension); + } + } + + @Override + public String[] getAcceptedExtensions() { + return acceptedExtensions.toArray(new String[acceptedExtensions.size()]); + } + + @Override public void setDescription(String description) { this.description = description; } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AptFileHeaderTransformer.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AptFileHeaderTransformer.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AptFileHeaderTransformer.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -53,25 +53,8 @@ ); } -// @Override -// public String unboxComent(String header) { -// -// StringBuilder buffer = new StringBuilder(); -// int prefixLength = getCommentLinePrefix().length(); -// for (String line : header.split(LINE_SEPARATOR + "")) { -// if (line.isEmpty()) { -// -// // not be unboxed, but just skipped -// continue; -// } -// int index = line.indexOf(getCommentLinePrefix()); -// if (index > -1) { -// -// // remove comment prefix -// line = line.substring(index + prefixLength); -// } -// buffer.append(line).append(LINE_SEPARATOR); -// } -// return buffer.toString(); -// } + @Override + public String getDefaultAcceptedExtension() { + return "apt"; + } } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -70,6 +70,50 @@ String getDescription(); /** + * Returns the default accepted extension for the transformer. + * + * @return the default accepted extension for the transformer. + * @since 2.4.1 + */ + String getDefaultAcceptedExtension(); + + /** + * Tests if the given file extension can be apply to this transformer. + * + * @param fileExtension the file extension to test. + * @return {@code true} if extension is accepted for the given extension, + * {@code false} otherwise. + * @since 2.4.1 + */ + boolean acceptExtension(String fileExtension); + + /** + * Reset the accepted extensions, says that after invoking this method only + * the default extension associated with the transformer will be accepted. + * + * @see #getDefaultAcceptedExtension() + * @see #acceptExtension(String) + * @since 2.4.1 + */ + void resetAcceptedExtensions(); + + /** + * Add a new accepted extension. + * + * @param extension the new accepted extension to add. + * @since 2.4.1 + */ + void addAcceptedExtension(String extension); + + /** + * Returns all accepted extensions for this transformer. + * + * @return all aceepted extensions for this transformer. + * @since 2.4.1 + */ + String[] getAcceptedExtensions(); + + /** * Obtains the process tag which indicates the begin of the header content. * <p/> * By default, (says if you do not explicitly invoke the Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/JavaFileHeaderTransformer.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/JavaFileHeaderTransformer.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/JavaFileHeaderTransformer.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -52,4 +52,9 @@ COMMENT_LINE_PREFIX ); } + + @Override + public String getDefaultAcceptedExtension() { + return "java"; + } } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/PropertiesFileHeaderTransformer.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/PropertiesFileHeaderTransformer.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/PropertiesFileHeaderTransformer.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -52,4 +52,9 @@ COMMENT_LINE_PREFIX ); } + + @Override + public String getDefaultAcceptedExtension() { + return "properties"; + } } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/RstFileHeaderTransformer.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/RstFileHeaderTransformer.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/RstFileHeaderTransformer.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -52,4 +52,9 @@ COMMENT_LINE_PREFIX ); } + + @Override + public String getDefaultAcceptedExtension() { + return "rst"; + } } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -81,8 +81,13 @@ // prolog detected content = content.substring(prolog.length()); - result = super.addHeader(prolog + '\n'+ header, content); + result = super.addHeader(prolog + '\n' + header, content); } return result; } + + @Override + public String getDefaultAcceptedExtension() { + return "xml"; + } } Modified: trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java 2010-10-15 13:48:36 UTC (rev 1845) +++ trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java 2010-10-16 17:05:40 UTC (rev 1846) @@ -38,7 +38,9 @@ import static org.nuiton.license.plugin.header.transformer.FileHeaderTransformer.DEFAULT_PROCESS_START_TAG; import static org.nuiton.license.plugin.header.transformer.FileHeaderTransformer.DEFAULT_SECTION_DELIMITER; import static org.nuiton.license.plugin.header.transformer.FileHeaderTransformer.LINE_SEPARATOR; -import static org.nuiton.license.plugin.header.transformer.JavaFileHeaderTransformer.*; +import static org.nuiton.license.plugin.header.transformer.JavaFileHeaderTransformer.COMMENT_END_TAG; +import static org.nuiton.license.plugin.header.transformer.JavaFileHeaderTransformer.COMMENT_LINE_PREFIX; +import static org.nuiton.license.plugin.header.transformer.JavaFileHeaderTransformer.COMMENT_START_TAG; /** * Tests the {@link AbstractFileHeaderTransformer}. @@ -84,6 +86,10 @@ new AbstractFileHeaderTransformer("name", "description", "commentPrefix", "commentEndtag", "commentPrefix") { + @Override + public String getDefaultAcceptedExtension() { + return getName(); + } }; } @@ -91,7 +97,10 @@ public void testIllegalTransformer2() throws Exception { new AbstractFileHeaderTransformer("name", "description", "commentstartTag", "commentPrefix", "commentPrefix") { - + @Override + public String getDefaultAcceptedExtension() { + return getName(); + } }; }