Author: tchemit Date: 2010-04-09 12:07:51 +0200 (Fri, 09 Apr 2010) New Revision: 1722 Log: - Evolution #478: Deprecates LicenseHeaderGenerator api - rename update-header-file to update-license Added: trunk/src/it/update-license/ trunk/src/it/update-license/pom.xml trunk/src/it/update-license/src/license/project.xml trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean.java trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean2.java trunk/src/it/update-license/verify.groovy trunk/src/main/java/org/nuiton/license/plugin/UpdateLicenseMojo.java Removed: trunk/src/it/update-header-file/LICENSE.txt trunk/src/it/update-header-file/README.txt trunk/src/it/update-header-file/changelog.txt trunk/src/it/update-header-file/invoker.properties trunk/src/it/update-header-file/pom.xml trunk/src/it/update-header-file/src/ trunk/src/it/update-header-file/verify.groovy trunk/src/it/update-license/pom.xml trunk/src/it/update-license/src/license/project.xml trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean.java trunk/src/it/update-license/verify.groovy trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/AptLicenseHeaderGeneratorImpl.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/HeaderGenerator.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/JavaLicenseHeaderGeneratorImpl.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/LicenseHeaderGenerator.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/PropertiesLicenseHeaderGeneratorImpl.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/XmlLicenseHeaderGeneratorImpl.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java Deleted: trunk/src/it/update-header-file/LICENSE.txt =================================================================== --- trunk/src/it/update-header-file/LICENSE.txt 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/it/update-header-file/LICENSE.txt 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,166 +0,0 @@ - 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. - Deleted: trunk/src/it/update-header-file/README.txt =================================================================== --- trunk/src/it/update-header-file/README.txt 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/it/update-header-file/README.txt 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,2 +0,0 @@ -To test parserJava on a new project (says a project with no i18n translations) -At the end we should have in target/generated-sources/i18n getters detected. Deleted: trunk/src/it/update-header-file/changelog.txt =================================================================== --- trunk/src/it/update-header-file/changelog.txt 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/it/update-header-file/changelog.txt 2010-04-09 10:07:51 UTC (rev 1722) @@ -1 +0,0 @@ -see the changelog of org.nuiton:i18n project. \ No newline at end of file Deleted: trunk/src/it/update-header-file/invoker.properties =================================================================== --- trunk/src/it/update-header-file/invoker.properties 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/it/update-header-file/invoker.properties 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,21 +0,0 @@ -# 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 compile - -# 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-at-end - -# 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 Deleted: trunk/src/it/update-header-file/pom.xml =================================================================== --- trunk/src/it/update-header-file/pom.xml 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/it/update-header-file/pom.xml 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,70 +0,0 @@ -<?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> - - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - - <groupId>org.nuiton.license.test</groupId> - <artifactId>test-update-header-file</artifactId> - <version>@pom.version@</version> - - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - - <name>License Test :: update-header-file</name> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - - <packaging>jar</packaging> - - <inceptionYear>2012</inceptionYear> - - <organization> - <name>License Test</name> - </organization> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - <build> - - <plugins> - - <plugin> - <groupId>org.nuiton</groupId> - <artifactId>maven-license-plugin</artifactId> - <version>@pom.version@</version> - <configuration> - <verbose>true</verbose> - </configuration> - <executions> - <execution> - <id>first</id> - <goals> - <goal>update-header-file</goal> - </goals> - <phase>process-sources</phase> - </execution> - <execution> - <!-- this execution is to test with no files --> - <id>second</id> - <goals> - <goal>update-header-file</goal> - </goals> - <phase>compile</phase> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> - - Deleted: trunk/src/it/update-header-file/verify.groovy =================================================================== --- trunk/src/it/update-header-file/verify.groovy 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/it/update-header-file/verify.groovy 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,16 +0,0 @@ - -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!' ); - -return true; Deleted: trunk/src/it/update-license/pom.xml =================================================================== --- trunk/src/it/update-header-file/pom.xml 2010-04-07 10:21:25 UTC (rev 1718) +++ trunk/src/it/update-license/pom.xml 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,62 +0,0 @@ -<?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> - - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - - <groupId>org.nuiton.license.test</groupId> - <artifactId>test-update-header-file</artifactId> - <version>@pom.version@</version> - - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - - <name>License Test :: update-header-file</name> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - - <packaging>jar</packaging> - - <build> - - <plugins> - - <plugin> - <groupId>org.nuiton</groupId> - <artifactId>maven-license-plugin</artifactId> - <version>@pom.version@</version> - <configuration> - <verbose>true</verbose> - </configuration> - <executions> - <execution> - <id>first</id> - <goals> - <goal>update-header-file</goal> - </goals> - <phase>process-sources</phase> - </execution> - <execution> - <!-- this execution is to test with no files --> - <id>second</id> - <goals> - <goal>update-header-file</goal> - </goals> - <phase>compile</phase> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> - - Copied: trunk/src/it/update-license/pom.xml (from rev 1720, trunk/src/it/update-header-file/pom.xml) =================================================================== --- trunk/src/it/update-license/pom.xml (rev 0) +++ trunk/src/it/update-license/pom.xml 2010-04-09 10:07:51 UTC (rev 1722) @@ -0,0 +1,70 @@ +<?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> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + + <groupId>org.nuiton.license.test</groupId> + <artifactId>test-update-header-file</artifactId> + <version>@pom.version@</version> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + + <name>License Test :: update-header-file</name> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + + <packaging>jar</packaging> + + <inceptionYear>2012</inceptionYear> + + <organization> + <name>License Test</name> + </organization> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <build> + + <plugins> + + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin</artifactId> + <version>@pom.version@</version> + <configuration> + <verbose>true</verbose> + </configuration> + <executions> + <execution> + <id>first</id> + <goals> + <goal>update-license</goal> + </goals> + <phase>process-sources</phase> + </execution> + <execution> + <!-- this execution is to test with no files --> + <id>second</id> + <goals> + <goal>update-license</goal> + </goals> + <phase>compile</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> + + Deleted: trunk/src/it/update-license/src/license/project.xml =================================================================== --- trunk/src/it/update-header-file/src/license/project.xml 2010-04-07 10:21:25 UTC (rev 1718) +++ trunk/src/it/update-license/src/license/project.xml 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,20 +0,0 @@ -<?xml version='1.0' encoding='UTF-8'?> -<project xmlns="http://maven-site.nuiton.org/maven-license-plugin/1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProject-1.0.0.xsd"> - <mainLicense>gpl_v3</mainLicense> - <licenseSets> - <licenseSet> - <licenseName>gpl_v3</licenseName> - <fileSets> - <fileSet> - <headerType>license-java</headerType> - <basedir>src/main/java</basedir> - <includes> - <include>**/*.java</include> - </includes> - </fileSet> - </fileSets> - </licenseSet> - </licenseSets> -</project> Copied: trunk/src/it/update-license/src/license/project.xml (from rev 1719, trunk/src/it/update-header-file/src/license/project.xml) =================================================================== --- trunk/src/it/update-license/src/license/project.xml (rev 0) +++ trunk/src/it/update-license/src/license/project.xml 2010-04-09 10:07:51 UTC (rev 1722) @@ -0,0 +1,20 @@ +<?xml version='1.0' encoding='UTF-8'?> +<project xmlns="http://maven-site.nuiton.org/maven-license-plugin/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProject-1.0.0.xsd"> + <mainLicense>gpl_v3</mainLicense> + <licenseSets> + <licenseSet> + <licenseName>gpl_v3</licenseName> + <fileSets> + <fileSet> + <headerType>java</headerType> + <basedir>src/main/java</basedir> + <includes> + <include>**/*.java</include> + </includes> + </fileSet> + </fileSets> + </licenseSet> + </licenseSets> +</project> Deleted: trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean.java =================================================================== --- trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java 2010-04-07 10:21:25 UTC (rev 1718) +++ trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,4 +0,0 @@ -package org.nuiton.license.plugin.test; - -public class MyBean { -} Copied: trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean.java (from rev 1720, trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean.java) =================================================================== --- trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean.java (rev 0) +++ trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -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 { +} Copied: trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean2.java (from rev 1721, trunk/src/it/update-header-file/src/main/java/org/nuiton/license/plugin/test/MyBean2.java) =================================================================== --- trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean2.java (rev 0) +++ trunk/src/it/update-license/src/main/java/org/nuiton/license/plugin/test/MyBean2.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -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 { +} Deleted: trunk/src/it/update-license/verify.groovy =================================================================== --- trunk/src/it/update-header-file/verify.groovy 2010-04-07 10:21:25 UTC (rev 1718) +++ trunk/src/it/update-license/verify.groovy 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,8 +0,0 @@ - -file = new File(basedir, 'src/main/java/org/nuiton/license/plugin/test/MyBean.java'); -assert file.exists(); - -content = file.text; -//assert content.contains( 'Copyright' ); - -return true; Copied: trunk/src/it/update-license/verify.groovy (from rev 1720, trunk/src/it/update-header-file/verify.groovy) =================================================================== --- trunk/src/it/update-license/verify.groovy (rev 0) +++ trunk/src/it/update-license/verify.groovy 2010-04-09 10:07:51 UTC (rev 1722) @@ -0,0 +1,16 @@ + +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!' ); + +return true; Deleted: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -1,471 +0,0 @@ -package org.nuiton.license.plugin; - -import org.apache.commons.lang.StringUtils; -import org.apache.maven.plugin.MojoFailureException; -import org.nuiton.license.plugin.header.FileHeader; -import org.nuiton.license.plugin.header.FileHeaderFilter; -import org.nuiton.license.plugin.header.FileHeaderProcessor; -import org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer; -import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer; -import org.nuiton.license.plugin.model.License; -import org.nuiton.license.plugin.model.LicenseStore; -import org.nuiton.license.plugin.model.project.FileSet; -import org.nuiton.license.plugin.model.project.LicenseProject; -import org.nuiton.license.plugin.model.project.LicenseSet; -import org.nuiton.license.plugin.model.project.io.xpp3.LicenseProjectXpp3Reader; -import org.nuiton.plugin.PluginHelper; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.*; - -/** - * The goal to update (or add) the licence header on some files. - * <p/> - * This goal replace the {@code update-header} goal which can not deal with - * Copyright. - * <p/> - * This goal use a specific project file descriptor {@code license.xml} to - * describe all files to treate more precisly for a whole project. - * - * @author chemit - * @requiresProject true - * @goal update-header-file - * @since 1.2 - */ -public class UpdateHeaderFileMojo extends AbstractLicenseMojo { - - /** - * The project license descriptor file. - * - * @parameter expression="${license.descriptor}" default-value="src/license/project.xml" - * @required - * @since 2.1 - */ - protected File descriptor; - - /** - * l'annee de creation du module (sera place dans le header) - * - * @parameter expression="${license.inceptionYear}" default-value="${project.inceptionYear}" - * @required - * @since 2.1 - */ - protected String inceptionYear; - - /** - * le nom de l'organisation (sera place dans le header) - * - * @parameter expression="${license.organizationName}" - * default-value="${project.organization.name}" - * @required - * @since 2.1 - */ - protected String organizationName; - - /** - * le nom du projet (sera place dans le header) - * - * @parameter expression="${license.projectName}" default-value="${project.name}" - * @required - * @since 2.1 - */ - protected String projectName; - - /** - * To specify an external licenses repository resolver (says the base url - * of the repository). - * - * @parameter expression="${license.licenseResolver}" - * @since 2.1 - */ - protected String licenseResolver; - - /** - * A flag to keep a backup of every modified file. - * - * @parameter expression="${license.keepBackup}" default-value="false" - * @since 2.1 - */ - protected boolean keepBackup; - - /** - * A flag to skip the goal. - * - * @parameter expression="${skipUpdateHeader}" default-value="false" - * @since 2.1 - */ - protected boolean skipUpdateHeader; - - /** - * A flag to test plugin but modify no file. - * - * @parameter expression="${dryRun}" default-value="false" - * @since 2.1 - */ - protected boolean dryRun; - - /** - * All available header transformers. - * - * @component role="org.nuiton.license.plugin.header.transformer.FileHeaderTransformer" - * @since 2.1 - */ - protected Map<String, FileHeaderTransformer> transformers; - - /** timestamp used for generation */ - protected long timestamp; - - /** store of licenses */ - protected LicenseStore licenseStore; - - /** descriptor of project */ - protected LicenseProject licenseProject; - - @Override - protected boolean checkSkip() { - if (skipUpdateHeader) { - getLog().info("skip flag is on, will skip goal."); - return false; - } - return super.checkSkip(); - } - - @Override - protected void init() throws Exception { - if (getLog().isDebugEnabled()) { - - // always be verbose in debug mode - setVerbose(true); - } - - if (skipUpdateHeader) { - return; - } - timestamp = System.nanoTime(); - - // init licenses store - licenseStore = createLicenseStore(licenseResolver); - - // load project descriptor - FileReader reader = new FileReader(descriptor); - try { - licenseProject = new LicenseProjectXpp3Reader().read(reader); - } finally { - reader.close(); - } - - // check that license project is sane (known licenses + header types) - // + populate default license name in LicenseSet (with main License) - validateProjectfile(licenseProject, licenseStore, transformers); - } - - @Override - protected void doAction() throws Exception { - - // create a file header processor which updates license content only - FileHeaderProcessor processor = new UpdateHeaderLicenseProcessor(); - - for (LicenseSet licenseSet : licenseProject.getLicenseSets()) { - String licenseName = licenseSet.getLicenseName(); - License license = licenseStore.getLicense(licenseName); - - getLog().info("process license \n" + license.getDescription()); - - // file header to use if no header is found on a file - FileHeader defaultFileHeader = buildDefaultFileHeader( - license, - getProjectName(), - getInceptionYear(), - getOrganizationName(), - getEncoding() - ); - - processor.setHeader(defaultFileHeader); - - for (FileSet fileSet : licenseSet.getFileSets()) { - File basedir = new File(getProject().getBasedir(), fileSet.getBasedir()); - 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[]>(); - getFilesToTreateForRoots( - includes.toArray(new String[includes.size()]), - excludes.isEmpty() ? null : - excludes.toArray(new String[excludes.size()]), - Arrays.asList(basedir.getAbsolutePath()), - filestoTreate, - null - ); - FileHeaderTransformer transformer = - transformers.get(fileSet.getHeaderType()); - processor.setTransformer(transformer); - - updateFiles(processor, filestoTreate); - } - } - } - - public void updateFiles(FileHeaderProcessor processor, - Map<File, String[]> filestoTreate) throws IOException { - - FileHeaderTransformer transformer = processor.getTransformer(); - FileHeader header = processor.getHeader(); - - String defaultHeaderContent = transformer.toString(header); - getLog().debug("default header :\n" + defaultHeaderContent); - - String defaultFullHeaderContent = transformer.boxProcessTag(defaultHeaderContent); - getLog().info("default header (process tag boxed) :\n" + defaultFullHeaderContent); - - defaultFullHeaderContent = transformer.boxComment(defaultFullHeaderContent, true); - getLog().info("default header to use :\n" + defaultFullHeaderContent); - - for (Map.Entry<File, String[]> entry : filestoTreate.entrySet()) { - File basedir = entry.getKey(); - getLog().info("start entry \n" + basedir); - String[] paths = entry.getValue(); - getLog().info(paths.length + " file(s) to treate."); - for (String path : paths) { - File file = new File(basedir, path); - updateFile(processor, file, defaultFullHeaderContent); - } - } - } - - public void updateFile(FileHeaderProcessor processor, - File file, - String defaultFullHeaderContent) throws IOException { - getLog().debug("scan file " + file); - - - // file where to writeFile result - File processFile = new File(file.getAbsolutePath() + "_" + - timestamp); - - if (isVerbose()) { - getLog().info("process file " + file); - } - - try { - processor.process(file, processFile); - boolean touched = processor.isTouched(); - - if (touched) { - - getLog().info("header was updated for " + file); - } else { - if (processor.isDetectHeader()) { - getLog().warn( - "skip file " + file + - " (no license footer tag found : '##%*' !)"); - } else { - - // no license header found in file, add it - getLog().info("adding license header on file " + file); - String content = PluginHelper.readAsString( - file, - getEncoding() - ); - content = defaultFullHeaderContent + content; - if (!dryRun) { - writeFile(processFile, content, getEncoding()); - } - } - } - - if (keepBackup && !dryRun) { - File backupFile = new File(file.getAbsolutePath() + "~"); - if (isVerbose()) { - getLog().debug("backup original file " + file); - } - renameFile(file, backupFile); - } - if (dryRun) { - deleteFile(processFile); - } else { - renameFile(processFile, file); - - } - - } catch (Exception e) { - getLog().warn( - "skip file " + file + " (could not process " + - "for reason : " + e.getMessage() + ")"); - deleteFile(processFile); - } finally { - // toujours cleaner les états du filtre du processeur - processor.reset(); - } - } - - public long getTimestamp() { - return timestamp; - } - - public String getProjectName() { - return projectName; - } - - public String getInceptionYear() { - return inceptionYear; - } - - public String getOrganizationName() { - return organizationName; - } - - public boolean isKeepBackup() { - return keepBackup; - } - - public boolean isDryRun() { - return dryRun; - } - - public boolean isSkipUpdateHeader() { - return skipUpdateHeader; - } - - public void setDryRun(boolean dryRun) { - this.dryRun = dryRun; - } - - public void setKeepBackup(boolean keepBackup) { - this.keepBackup = keepBackup; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - public void setSkipUpdateHeader(boolean skipUpdateHeader) { - this.skipUpdateHeader = skipUpdateHeader; - } - - public void setInceptionYear(String inceptionYear) { - this.inceptionYear = inceptionYear; - } - - public void setOrganizationName(String organizationName) { - this.organizationName = organizationName; - } - - protected void validateProjectfile( - LicenseProject licenseProject, - LicenseStore licenseStore, - Map<String, FileHeaderTransformer> transformers) - throws MojoFailureException { - - List<String> licenseNames = Arrays.asList(licenseStore.getLicenseNames()); - - // check licenses is known - String mainLicense = licenseProject.getMainLicense(); - if (licenseStore.getLicense(mainLicense) == null) { - throw new MojoFailureException( - "main license '" + mainLicense + - "' is unknown, use one of " + licenseNames); - } - for (LicenseSet licenseSet : licenseProject.getLicenseSets()) { - - String licenseName = licenseSet.getLicenseName(); - if (StringUtils.isEmpty(licenseName)) { - - // use the main license - licenseSet.setLicenseName(mainLicense); - } else { - - // check license name - if (licenseStore.getLicense(licenseName) == null) { - throw new MojoFailureException( - "license '" + licenseName + - "' is unknown, use one of " + licenseNames); - } - } - - // check header types (for each file set) - for (FileSet fileSet : licenseSet.getFileSets()) { - String headerType = fileSet.getHeaderType(); - if (!transformers.containsKey(headerType)) { - throw new MojoFailureException( - "headerType '" + headerType + - "' is unknown, use one of " + transformers.keySet()); - } - } - } - } - - protected FileHeader buildDefaultFileHeader(License license, - String projectName, - String inceptionYear, - String copyrightHolder, - String encoding) throws IOException { - FileHeader result = new FileHeader(); - result.setDescription(projectName); - result.setLicense(license.getHeaderContent(encoding)); - 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; - } - - public class UpdateHeaderLicenseProcessor extends FileHeaderProcessor { - - @Override - public FileHeaderFilter newFilter(FileHeader header, FileHeaderTransformer transformer) { - return new FileHeaderFilter(header, transformer) { - @Override - protected String treateHeader(String ch) { - - // unbox comment - String unbox = transformer.unboxComent(ch); - - // obtain current license of file - - FileHeader fileHeader = transformer.toFileHeader(unbox); - - // updates license - fileHeader.setLicense(header.getLicense()); - - // build new brut header (with no boxing) - - String newHeader = transformer.toString(fileHeader); - - // box with process tag - newHeader = transformer.boxProcessTag(newHeader); - - // box header with comment prefix - newHeader = transformer.boxComment(newHeader, false); - - int index = newHeader.indexOf(transformer.getProcessStartTag()); - - String result = newHeader.substring(index); - while (result.charAt(result.length() - 1) == AbstractFileHeaderTransformer.LINE_SEPARATOR) { - result = result.substring(0, result.length() - 1); - } - if (isVerbose()) { - getLog().debug("new Header =\n" + result); - } - - return result; - } - }; - } - } -} Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -215,7 +215,7 @@ /** * A flag to skip the goal. * - * @parameter expression="${skipUpdateHeader}" default-value="false" + * @parameter expression="${skipUpdateLicense}" default-value="false" * @since 1.0.3 */ protected boolean skipUpdateHeader; Copied: trunk/src/main/java/org/nuiton/license/plugin/UpdateLicenseMojo.java (from rev 1720, trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderFileMojo.java) =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/UpdateLicenseMojo.java (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/UpdateLicenseMojo.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -0,0 +1,481 @@ +package org.nuiton.license.plugin; + +import org.apache.commons.lang.StringUtils; +import org.apache.maven.plugin.MojoFailureException; +import org.nuiton.license.plugin.header.FileHeader; +import org.nuiton.license.plugin.header.FileHeaderFilter; +import org.nuiton.license.plugin.header.FileHeaderProcessor; +import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer; +import org.nuiton.license.plugin.model.License; +import org.nuiton.license.plugin.model.LicenseStore; +import org.nuiton.license.plugin.model.project.FileSet; +import org.nuiton.license.plugin.model.project.LicenseProject; +import org.nuiton.license.plugin.model.project.LicenseSet; +import org.nuiton.license.plugin.model.project.io.xpp3.LicenseProjectXpp3Reader; +import org.nuiton.plugin.PluginHelper; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.*; + +/** + * The goal to update (or add) the licence header on some files and also update + * (or add) the project license file. + * <p/> + * This goal replace the {@code update-header} goal which can not deal with + * Copyright. + * <p/> + * This goal use a specific project file descriptor {@code project.xml} to + * describe all files to update for a whole project. + * + * @author chemit + * @requiresProject true + * @goal update-license + * @since 2.1 + */ +public class UpdateLicenseMojo extends AbstractLicenseMojo { + + /** + * The project license descriptor file. + * + * @parameter expression="${license.descriptor}" default-value="src/license/project.xml" + * @required + * @since 2.1 + */ + protected File descriptor; + + /** + * l'annee de creation du module (sera place dans le header) + * + * @parameter expression="${license.inceptionYear}" default-value="${project.inceptionYear}" + * @required + * @since 2.1 + */ + protected String inceptionYear; + + /** + * le nom de l'organisation (sera place dans le header) + * + * @parameter expression="${license.organizationName}" + * default-value="${project.organization.name}" + * @required + * @since 2.1 + */ + protected String organizationName; + + /** + * le nom du projet (sera place dans le header) + * + * @parameter expression="${license.projectName}" default-value="${project.name}" + * @required + * @since 2.1 + */ + protected String projectName; + + /** + * To specify an external licenses repository resolver (says the base url + * of the repository). + * + * @parameter expression="${license.licenseResolver}" + * @since 2.1 + */ + protected String licenseResolver; + + /** + * A flag to keep a backup of every modified file. + * + * @parameter expression="${license.keepBackup}" default-value="false" + * @since 2.1 + */ + protected boolean keepBackup; + + /** + * A flag to skip the goal. + * + * @parameter expression="${license.skipUpdateLicense}" default-value="false" + * @since 2.1 + */ + protected boolean skipUpdateLicense; + + /** + * A flag to test plugin but modify no file. + * + * @parameter expression="${dryRun}" default-value="false" + * @since 2.1 + */ + protected boolean dryRun; + + /** + * All available header transformers. + * + * @component role="org.nuiton.license.plugin.header.transformer.FileHeaderTransformer" + * @since 2.1 + */ + protected Map<String, FileHeaderTransformer> transformers; + + /** timestamp used for generation */ + protected long timestamp; + + /** store of licenses */ + protected LicenseStore licenseStore; + + /** descriptor of project */ + protected LicenseProject licenseProject; + + @Override + protected boolean checkSkip() { + if (skipUpdateLicense) { + getLog().info("skip flag is on, will skip goal."); + return false; + } + return super.checkSkip(); + } + + @Override + protected void init() throws Exception { + if (getLog().isDebugEnabled()) { + + // always be verbose in debug mode + setVerbose(true); + } + + if (skipUpdateLicense) { + return; + } + timestamp = System.nanoTime(); + + // init licenses store + licenseStore = createLicenseStore(licenseResolver); + + // load project descriptor + FileReader reader = new FileReader(descriptor); + try { + licenseProject = new LicenseProjectXpp3Reader().read(reader); + } finally { + reader.close(); + } + + // check that license project is sane (known licenses + header types) + // + populate default license name in LicenseSet (with main License) + validateProjectfile(licenseProject, licenseStore, transformers); + } + + @Override + protected void doAction() throws Exception { + + // create a file header processor which updates license content only + FileHeaderProcessor processor = new FileHeaderProcessor() { + + @Override + public FileHeaderFilter newFilter( + FileHeader header, FileHeaderTransformer transformer) { + + return new UpdateLicenseHeaderFilter(header, transformer); + } + }; + + for (LicenseSet licenseSet : licenseProject.getLicenseSets()) { + + // obtain license from definition + String licenseName = licenseSet.getLicenseName(); + License license = licenseStore.getLicense(licenseName); + + if (isVerbose()) { + getLog().info("process license \n" + license.getDescription()); + } + + // file header to use if no header is found on a file + FileHeader defaultFileHeader = buildDefaultFileHeader( + license, + getProjectName(), + getInceptionYear(), + getOrganizationName(), + getEncoding() + ); + + // change default license header in processor + processor.setHeader(defaultFileHeader); + + for (FileSet fileSet : licenseSet.getFileSets()) { + File basedir = new File(getProject().getBasedir(), + fileSet.getBasedir()); + 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 + ); + + // get header transformer according to file set + FileHeaderTransformer transformer = + transformers.get(fileSet.getHeaderType()); + + // change transformer in processor + processor.setTransformer(transformer); + + // treate all files of entry + for (Map.Entry<File, String[]> entry : filestoTreate.entrySet()) { + File entryBasedir = entry.getKey(); + getLog().info("start entry \n" + entryBasedir); + String[] paths = entry.getValue(); + getLog().info(paths.length + " file(s) to treate."); + for (String path : paths) { + File file = new File(entryBasedir, path); + updateFile(processor, file); + } + } + } + } + } + + public void updateFile(FileHeaderProcessor processor, + File file) throws IOException { + getLog().debug("scan file " + file); + + // file where to write result + File processFile = new File(file.getAbsolutePath() + "_" + + timestamp); + + if (isVerbose()) { + getLog().info("process file " + file); + } + + try { + processor.process(file, processFile); + boolean touched = processor.isTouched(); + + if (touched) { + + getLog().info("header was updated for " + file); + } else { + if (processor.isDetectHeader()) { + getLog().warn( + "skip file " + file + + " (no license footer tag found : '##%*' !)"); + } else { + + // no license header found in file, add it + getLog().info("adding license header on file " + file); + String content = PluginHelper.readAsString( + file, + getEncoding() + ); + + //FIXME-TC-20100409 form xml files must add header after a xml prolog line + content = processor.getFullHeaderContent() + content; + if (!dryRun) { + writeFile(processFile, content, getEncoding()); + } + } + } + + if (keepBackup && !dryRun) { + File backupFile = new File(file.getAbsolutePath() + "~"); + if (isVerbose()) { + getLog().debug("backup original file " + file); + } + renameFile(file, backupFile); + } + if (dryRun) { + deleteFile(processFile); + } else { + renameFile(processFile, file); + } + + } catch (Exception e) { + getLog().warn( + "skip file " + file + " (could not process " + + "for reason : " + e.getMessage() + ")"); + deleteFile(processFile); + } finally { + + // always clean processor internal states + processor.reset(); + } + } + + public long getTimestamp() { + return timestamp; + } + + public String getProjectName() { + return projectName; + } + + public String getInceptionYear() { + return inceptionYear; + } + + public String getOrganizationName() { + return organizationName; + } + + public boolean isKeepBackup() { + return keepBackup; + } + + public boolean isDryRun() { + return dryRun; + } + + public boolean isSkipUpdateLicense() { + return skipUpdateLicense; + } + + public void setDryRun(boolean dryRun) { + this.dryRun = dryRun; + } + + public void setKeepBackup(boolean keepBackup) { + this.keepBackup = keepBackup; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public void setSkipUpdateLicense(boolean skipUpdateLicense) { + this.skipUpdateLicense = skipUpdateLicense; + } + + public void setInceptionYear(String inceptionYear) { + this.inceptionYear = inceptionYear; + } + + public void setOrganizationName(String organizationName) { + this.organizationName = organizationName; + } + + protected void validateProjectfile( + LicenseProject licenseProject, + LicenseStore licenseStore, + Map<String, FileHeaderTransformer> transformers) + throws MojoFailureException { + + List<String> licenseNames = Arrays.asList(licenseStore.getLicenseNames()); + + // check licenses is known + String mainLicense = licenseProject.getMainLicense(); + if (licenseStore.getLicense(mainLicense) == null) { + throw new MojoFailureException( + "main license '" + mainLicense + + "' is unknown, use one of " + licenseNames); + } + for (LicenseSet licenseSet : licenseProject.getLicenseSets()) { + + String licenseName = licenseSet.getLicenseName(); + if (StringUtils.isEmpty(licenseName)) { + + // use the main license + licenseSet.setLicenseName(mainLicense); + } else { + + // check license name + if (licenseStore.getLicense(licenseName) == null) { + throw new MojoFailureException( + "license '" + licenseName + + "' is unknown, use one of " + licenseNames); + } + } + + // check header types (for each file set) + for (FileSet fileSet : licenseSet.getFileSets()) { + String headerType = fileSet.getHeaderType(); + if (!transformers.containsKey(headerType)) { + throw new MojoFailureException( + "headerType '" + headerType + + "' is unknown, use one of " + transformers.keySet()); + } + } + } + } + + protected FileHeader buildDefaultFileHeader( + License license, + String projectName, + String inceptionYear, + String copyrightHolder, + String encoding) throws IOException { + FileHeader result = new FileHeader(); + result.setDescription(projectName); + result.setLicense(license.getHeaderContent(encoding)); + 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; + } + + public class UpdateLicenseHeaderFilter extends FileHeaderFilter { + + public UpdateLicenseHeaderFilter(FileHeader header, + FileHeaderTransformer transformer) { + super(header, transformer); + } + + @Override + protected String treateHeader(FileHeader header, + FileHeaderTransformer transformer, + String ch) { + + // unbox comment + String unbox = transformer.unboxComent(ch); + + // obtain current license of file + FileHeader fileHeader = transformer.toFileHeader(unbox); + + // updates license + fileHeader.setLicense(header.getLicense()); + + // build new brut header (with no boxing) + + String newHeader = transformer.toString(fileHeader); + + // box with process tag + newHeader = transformer.boxProcessTag(newHeader); + + // box header with comment prefix + newHeader = transformer.boxComment(newHeader, false); + + // remove all before start process tag since we MUST begin by + // the start tag in processor logic. + int index = newHeader.indexOf(transformer.getProcessStartTag()); + + String result = newHeader.substring(index); + + // remove all extra spaces characters at the end of header (since + // we UST finish with process end tag in processor logic. + while (Character.isSpaceChar(result.charAt(result.length() - 1))) { + result = result.substring(0, result.length() - 1); + } + if (isVerbose()) { + getLog().debug("updated Header =\n" + result); + } + + return result; + } + } +} Property changes on: trunk/src/main/java/org/nuiton/license/plugin/UpdateLicenseMojo.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -26,7 +26,7 @@ protected FileHeaderTransformer transformer; - protected abstract String treateHeader(String ch); + protected abstract String treateHeader(FileHeader header, FileHeaderTransformer transformer, String ch); public FileHeaderFilter(FileHeader header, FileHeaderTransformer transformer) { this.header = header; @@ -48,7 +48,7 @@ touched = true; // update header - String newHeader = treateHeader(ch); + String newHeader = treateHeader(header, transformer, ch); return newHeader; } // ce cas arrive lorsque l'on a parcouru tout le fichier avec detection Modified: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -24,6 +24,15 @@ /** internal filter */ protected FileHeaderFilter filter; + /** cached header content */ + protected String headerContent; + + /** cached full header content (with process tag + comment box) */ + protected String processTagHeaderContent; + + /** cached full header content (with process tag + comment box) */ + protected String fullHeaderContent; + public abstract FileHeaderFilter newFilter(FileHeader header, FileHeaderTransformer transformer); public FileHeaderProcessor() { @@ -69,22 +78,50 @@ } } - public FileHeader getHeader() { - return header; + public String getHeaderContent() { + if (headerContent == null) { + headerContent = transformer.toString(header); + } + return headerContent; } + public String getProcessTagHeaderContent() { + if (processTagHeaderContent == null) { + + // box with process tag + processTagHeaderContent = + transformer.boxProcessTag(getHeaderContent()); + + } + return processTagHeaderContent; + } + + public String getFullHeaderContent() { + if (fullHeaderContent == null) { + + // box with comment + fullHeaderContent = + transformer.boxComment(getProcessTagHeaderContent(), true); + } + return fullHeaderContent; + } + +// public FileHeader getHeader() { +// return header; +// } +// +// public FileHeaderTransformer getTransformer() { +// return transformer; +// } + public void setHeader(FileHeader header) { this.header = header; - filter = null; + reset(); } - public FileHeaderTransformer getTransformer() { - return transformer; - } - public void setTransformer(FileHeaderTransformer transformer) { this.transformer = transformer; - filter = null; + reset(); } // // protected FileHeaderFilter getFilter() { @@ -100,6 +137,10 @@ public void reset() { if (filter != null) { filter.reset(); + filter = null; } + headerContent = null; + processTagHeaderContent = null; + fullHeaderContent = null; } } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/AptLicenseHeaderGeneratorImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/AptLicenseHeaderGeneratorImpl.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/AptLicenseHeaderGeneratorImpl.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -20,6 +20,7 @@ */ package org.nuiton.license.plugin.header.generator; +import org.nuiton.license.plugin.header.FileHeader; import org.nuiton.processor.filters.LicenseFilter; /** @@ -28,7 +29,9 @@ * @author chemit * @plexus.component role-hint="license-apt" * @since 1.0.1 + * @deprecated since 2.1, prefer use now the {@link FileHeader} api */ +@Deprecated public class AptLicenseHeaderGeneratorImpl extends LicenseHeaderGenerator { public static final String GENERATOR_NAME = "license-apt"; Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/HeaderGenerator.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/HeaderGenerator.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/HeaderGenerator.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -20,6 +20,8 @@ */ package org.nuiton.license.plugin.header.generator; +import org.nuiton.license.plugin.header.FileHeader; + import java.io.IOException; /** @@ -27,7 +29,9 @@ * * @author chemit * @since 1.0.0 + * @deprecated since 2.1, prefer use now the {@link FileHeader} api */ +@Deprecated public interface HeaderGenerator { /** Plexus role name */ Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/JavaLicenseHeaderGeneratorImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/JavaLicenseHeaderGeneratorImpl.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/JavaLicenseHeaderGeneratorImpl.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -20,6 +20,7 @@ */ package org.nuiton.license.plugin.header.generator; +import org.nuiton.license.plugin.header.FileHeader; import org.nuiton.processor.filters.LicenseFilter; /** @@ -28,7 +29,9 @@ * @author chemit * @plexus.component role-hint="license-java" * @since 1.0.1 + * @deprecated since 2.1, prefer use now the {@link FileHeader} api */ +@Deprecated public class JavaLicenseHeaderGeneratorImpl extends LicenseHeaderGenerator { public static final String GENERATOR_NAME = "license-java"; Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/LicenseHeaderGenerator.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/LicenseHeaderGenerator.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/LicenseHeaderGenerator.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -20,6 +20,7 @@ */ package org.nuiton.license.plugin.header.generator; +import org.nuiton.license.plugin.header.FileHeader; import org.nuiton.plugin.PluginHelper; import java.io.IOException; @@ -29,7 +30,9 @@ * * @author chemit * @since 1.0.1 + * @deprecated since 2.1, prefer use now the {@link FileHeader} api */ +@Deprecated public abstract class LicenseHeaderGenerator implements HeaderGenerator { protected String linePrefix; Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/PropertiesLicenseHeaderGeneratorImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/PropertiesLicenseHeaderGeneratorImpl.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/PropertiesLicenseHeaderGeneratorImpl.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -20,6 +20,7 @@ */ package org.nuiton.license.plugin.header.generator; +import org.nuiton.license.plugin.header.FileHeader; import org.nuiton.processor.filters.LicenseFilter; /** @@ -28,7 +29,9 @@ * @author chemit * @plexus.component role-hint="license-properties" * @since 1.0.1 + * @deprecated since 2.1, prefer use now the {@link FileHeader} api */ +@Deprecated public class PropertiesLicenseHeaderGeneratorImpl extends LicenseHeaderGenerator { public static final String GENERATOR_NAME = "license-properties"; Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/XmlLicenseHeaderGeneratorImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/XmlLicenseHeaderGeneratorImpl.java 2010-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/XmlLicenseHeaderGeneratorImpl.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -20,6 +20,7 @@ */ package org.nuiton.license.plugin.header.generator; +import org.nuiton.license.plugin.header.FileHeader; import org.nuiton.processor.filters.LicenseFilter; /** @@ -28,7 +29,9 @@ * @author chemit * @plexus.component role-hint="license-xml" * @since 1.0.1 + * @deprecated since 2.1, prefer use now the {@link FileHeader} api */ +@Deprecated public class XmlLicenseHeaderGeneratorImpl extends LicenseHeaderGenerator { public static final String GENERATOR_NAME = "license-xml"; 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-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -30,8 +30,6 @@ "(.[^\\d]+)?\\s(\\d{4})?(\\s+-\\s+(\\d{4})?){0,1}\\s+(.+)?" ); - public static final char LINE_SEPARATOR = '\n'; - /** name of transformer */ protected String name; 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-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -36,6 +36,8 @@ /** default process end tag */ String DEFAULT_PROCESS_END_TAG = "#L%"; + char LINE_SEPARATOR = '\n'; + /** @return the name of the transformer */ String getName(); 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-04-08 20:03:11 UTC (rev 1721) +++ trunk/src/test/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformerTest.java 2010-04-09 10:07:51 UTC (rev 1722) @@ -12,7 +12,7 @@ import static org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer.DEFAULT_PROCESS_END_TAG; import static org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer.DEFAULT_PROCESS_START_TAG; import static org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer.DEFAULT_SECTION_DELIMITER; -import static org.nuiton.license.plugin.header.transformer.AbstractFileHeaderTransformer.LINE_SEPARATOR; +import static org.nuiton.license.plugin.header.transformer.FileHeaderTransformer.LINE_SEPARATOR; import static org.nuiton.license.plugin.header.transformer.JavaFileHeaderTransformer.*; /**