Author: tchemit Date: 2009-09-21 12:11:54 +0200 (Mon, 21 Sep 2009) New Revision: 1642 Added: trunk/src/main/resources/META-INF/plexus/ trunk/src/main/resources/META-INF/plexus/components.xml Modified: trunk/pom.xml trunk/src/main/java/org/nuiton/license/header/plugin/UpdateHeaderPlugin.java trunk/src/test/java/org/nuiton/license/header/LicenseProcessorTest.java trunk/src/test/java/org/nuiton/license/header/plugin/UpdateHeaderPluginTest.java Log: [EVOLUTION #56] : utilisation novuelles api de maven-helper-plugin - utilisation component plexus-velocity - ajout des tagslets javadocs pour les mojo Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-08-29 21:29:19 UTC (rev 1641) +++ trunk/pom.xml 2009-09-21 10:11:54 UTC (rev 1642) @@ -9,7 +9,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom</artifactId> - <version>1.0.2-SNAPSHOT</version> + <version>1.0.3-SNAPSHOT</version> </parent> <artifactId>maven-license-plugin</artifactId> @@ -29,134 +29,547 @@ <artifactId>maven-helper-plugin</artifactId> <version>${helper.version}</version> <scope>compile</scope> - </dependency> + <exclusions> + <exclusion> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact-manager</artifactId> + </exclusion> + + <exclusion> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-dependency-tree</artifactId> + </exclusion> + + <exclusion> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + </exclusion> + + <exclusion> + <groupId>org.apache.maven</groupId> + <artifactId>maven-profile</artifactId> + </exclusion> + + <exclusion> + <groupId>org.apache.maven</groupId> + <artifactId>maven-settings</artifactId> + </exclusion> + <exclusion> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + </exclusion> + + </exclusions> + </dependency> + <!-- FIXME si on ne le rajoute pas, on se retrouve avec la version 1.1 qui ne convient pas --> - <dependency> + <!--<dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> <version>1.5.15</version> <scope>compile</scope> - </dependency> + </dependency>--> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-project</artifactId> - <version>${maven.version}</version> - <scope>provided</scope> - </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>${maven.version}</version> + <scope>provided</scope> + </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>${maven.version}</version> - <scope>provided</scope> - </dependency> - + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>${maven.version}</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-velocity</artifactId> + <version>1.1.7</version> + <exclusions> + <exclusion> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-container-default</artifactId> + </exclusion> + <exclusion> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-api</artifactId> + </exclusion> + <exclusion> + <groupId>velocity</groupId> + <artifactId>velocity</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- tests dependencies --> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>maven-helper-plugin</artifactId> - <version>${helper.version}</version> - <scope>test</scope> - <classifier>tests</classifier> - </dependency> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>maven-helper-plugin</artifactId> + <version>${helper.version}</version> + <scope>test</scope> + <classifier>tests</classifier> + </dependency> - <dependency> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-plugin-testing-harness</artifactId> - <version>1.1</version> - <scope>test</scope> - </dependency> + <dependency> + <groupId>org.apache.maven.plugin-testing</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + <version>1.2</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.7</version> + <scope>test</scope> + </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.6</version> - <scope>test</scope> - </dependency> +</dependencies> - </dependencies> - <!-- ************************************************************* --> <!-- *** Project Information ************************************* --> <!-- ************************************************************* --> - <name>Maven License Plugin</name> +<name>Maven License Plugin</name> - <description> +<description> Plugin pour mettre à jour l'en-tête des fichiers (avec la license choisie) dans un module maven 2. - </description> - <inceptionYear>2008</inceptionYear> - <url>http://maven-site.nuiton.org/maven-license-plugin</url> +</description> +<inceptionYear>2008</inceptionYear> +<url>http://maven-site.nuiton.org/maven-license-plugin</url> <!-- ************************************************************* --> <!-- *** Build Settings ****************************************** --> <!-- ************************************************************* --> - <packaging>maven-plugin</packaging> +<packaging>maven-plugin</packaging> - <properties> +<properties> - <helper.version>1.0.2-SNAPSHOT</helper.version> - <processor.version>1.0.1-SNAPSHOT</processor.version> + <processor.version>1.0.1-SNAPSHOT</processor.version> - </properties> +</properties> - <build> +<build> - <defaultGoal>install</defaultGoal> + <defaultGoal>install</defaultGoal> + <plugins> + + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>helpmojo</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + + <pluginManagement> <plugins> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <version>${javadoc.version}</version> + <configuration> + <docencoding>${project.reporting.outputEncoding}</docencoding> + <encoding>${project.reporting.outputEncoding}</encoding> + <charset>${project.reporting.outputEncoding}</charset> + <quiet>true</quiet> + <!-- uniquement a partir de javadoc 2.5 --> + <!--skip>${maven.javadoc.skip}</skip--> + <taglets> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> - <plugin> - <artifactId>maven-plugin-plugin</artifactId> + <taglet> + <tagletClass>org.codehaus.plexus.javadoc.PlexusComponentTaglet</tagletClass> + <tagletArtifact> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-javadoc</artifactId> + <version>1.0</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.codehaus.plexus.javadoc.PlexusConfigurationTaglet</tagletClass> + <tagletArtifact> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-javadoc</artifactId> + <version>1.0</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.codehaus.plexus.javadoc.PlexusRequirementTaglet</tagletClass> + <tagletArtifact> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-javadoc</artifactId> + <version>1.0</version> + </tagletArtifact> + </taglet> + </taglets> + </configuration> <executions> <execution> + <id>attach-javadocs</id> <goals> - <goal>helpmojo</goal> + <goal>jar</goal> </goals> </execution> </executions> </plugin> - + <plugin> + <artifactId>maven-site-plugin</artifactId> + <dependencies> + <dependency> + <groupId>org.nuiton.jrst</groupId> + <artifactId>doxia-module-jrst</artifactId> + <version>${jrst.version}</version> + </dependency> + </dependencies> + </plugin> </plugins> + </pluginManagement> - <pluginManagement> - <plugins> - <plugin> - <artifactId>maven-site-plugin</artifactId> - <dependencies> - <dependency> - <groupId>org.nuiton.jrst</groupId> - <artifactId>doxia-module-jrst</artifactId> - <version>${jrst.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </pluginManagement> +</build> - </build> +<reporting> + <plugins> + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + </plugin> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <version>${javadoc.version}</version> + <configuration> + <docencoding>${project.reporting.outputEncoding}</docencoding> + <encoding>${project.reporting.outputEncoding}</encoding> + <charset>${project.reporting.outputEncoding}</charset> + <quiet>true</quiet> + <!-- uniquement a partir de javadoc 2.5 --> + <!--skip>${maven.javadoc.skip}</skip--> + <taglets> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet</tagletClass> + <tagletArtifact> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-tools-javadoc</artifactId> + <version>2.4.2</version> + </tagletArtifact> + </taglet> - <reporting> - <plugins> - <plugin> - <artifactId>maven-plugin-plugin</artifactId> - </plugin> - </plugins> - </reporting> + <taglet> + <tagletClass>org.codehaus.plexus.javadoc.PlexusComponentTaglet</tagletClass> + <tagletArtifact> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-javadoc</artifactId> + <version>1.0</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.codehaus.plexus.javadoc.PlexusConfigurationTaglet</tagletClass> + <tagletArtifact> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-javadoc</artifactId> + <version>1.0</version> + </tagletArtifact> + </taglet> + <taglet> + <tagletClass>org.codehaus.plexus.javadoc.PlexusRequirementTaglet</tagletClass> + <tagletArtifact> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-javadoc</artifactId> + <version>1.0</version> + </tagletArtifact> + </taglet> + </taglets> + </configuration> + </plugin> + </plugins> +</reporting> <!-- ************************************************************* --> <!-- *** Build Environment ************************************** --> <!-- ************************************************************* --> <!-- Source control management. --> - <scm> - <connection>scm:svn:http://svn.nuiton.org/svn/maven-license-plugin/trunk</connection> - <developerConnection>scm:svn:http://svn.nuiton.org/svn/maven-license-plugin/trunk</developerConnection> - <url>http://www.nuiton.org/repositories/browse/maven-license-plugin/trunk</url> - </scm> +<scm> + <connection>scm:svn:http://svn.nuiton.org/svn/maven-license-plugin/trunk</connection> + <developerConnection>scm:svn:http://svn.nuiton.org/svn/maven-license-plugin/trunk</developerConnection> + <url>http://www.nuiton.org/repositories/browse/maven-license-plugin/trunk</url> +</scm> </project> Modified: trunk/src/main/java/org/nuiton/license/header/plugin/UpdateHeaderPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/license/header/plugin/UpdateHeaderPlugin.java 2009-08-29 21:29:19 UTC (rev 1641) +++ trunk/src/main/java/org/nuiton/license/header/plugin/UpdateHeaderPlugin.java 2009-09-21 10:11:54 UTC (rev 1642) @@ -25,22 +25,24 @@ import java.io.File; import java.io.StringWriter; -import java.net.URL; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Properties; import org.apache.maven.project.MavenProject; -import org.nuiton.AbstractPlugin; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.context.Context; +import org.codehaus.plexus.velocity.VelocityComponent; import org.nuiton.license.License; import org.nuiton.license.LicenseFactory; import org.nuiton.license.header.generator.HeaderGenerator; import org.nuiton.license.header.generator.HeaderGeneratorUtil; +import org.nuiton.plugin.AbstractPlugin; import org.nuiton.util.PluginHelper; -import org.nuiton.util.VelocityTemplateGenerator; /** * The goal to update (or add) the licence header on some files. @@ -193,6 +195,12 @@ * @since 1.0.0 */ protected boolean verbose; + /** + * Velocity Component. + * + * @component roleHint="maven-license-plugin" + */ + private VelocityComponent velocity; /** le header a ajouter dans chaque fichier source java */ protected String licenseHeaderContent; /** le header complet (avec les balises de commentaires) */ @@ -263,7 +271,7 @@ // verifie que la template existe (dans le class-path ou en tant que fichier) checkResource(templateFile); - URL templateURL = getTemplate(templateFile); + // URL templateURL = getTemplate(templateFile); // recuperation de la license a utiliser LicenseFactory factory = LicenseFactory.newInstance(licenseResolver); @@ -272,10 +280,10 @@ if (verbose) { getLog().info("config - use license " + license.getName()); getLog().info("config - use generator " + generator.getName()); - getLog().info("config - use template " + templateURL); + getLog().info("config - use template " + template); } // obtain content of license header - licenseHeaderContent = computeHeader(license, templateURL, generator); + licenseHeaderContent = computeHeader(license, generator); // build the comment boxed header content boxedLicenseHeaderContent = generator.getHeader(licenseHeaderContent); @@ -348,12 +356,11 @@ * license donnée. * * @param license - * @param templateURL * @param generator * @return le header construit * @throws Exception pour toute erreur pendant la construction du header */ - protected String computeHeader(License license, URL templateURL, HeaderGenerator generator) throws Exception { + protected String computeHeader(License license, HeaderGenerator generator) throws Exception { // recuperation de la license a mettre dans le header String licenseContent = license.getHeaderContent(encoding); @@ -366,33 +373,45 @@ inceptionYear = inceptionYear + " - " + thisYear; } - // preparation de l'environnement velocity - Properties env = new Properties(); - env.put("inceptionYear", inceptionYear); - env.put("projectName", projectName); - env.put("organizationName", organizationName); - env.put("licenseContent", licenseContent); +// // preparation de l'environnement velocity +// Properties env = new Properties(); +// env.put("inceptionYear", inceptionYear); +// env.put("projectName", projectName); +// env.put("organizationName", organizationName); +// env.put("licenseContent", licenseContent); +// +// if (templateParameters != null) { +// for (Entry<String, String> e : templateParameters.entrySet()) { +// env.put(e.getKey(), e.getValue()); +// } +// } - if (templateParameters != null) { - for (Entry<String, String> e : templateParameters.entrySet()) { - env.put(e.getKey(), e.getValue()); - } - } + + Context context = createVelocityContext(licenseContent); + if (verbose) { StringBuilder buffer = new StringBuilder(); buffer.append("config - parameters for template : "); - for (Entry<Object, Object> e : env.entrySet()) { - buffer.append("\n * " + e.getKey() + " : " + e.getValue()); + for (Object key : context.getKeys()) { + buffer.append("\n * " + key + " : " + context.get(key + "")); } getLog().info(buffer.toString()); } // generation du contenu via velocity + VelocityEngine engine = velocity.getEngine(); + StringWriter writer = new StringWriter(); - VelocityTemplateGenerator gen = new VelocityTemplateGenerator(project, templateURL); - gen.generate(env, writer); + Template velocityTemplate = engine.getTemplate(template, encoding); + + velocityTemplate.merge(context, writer); + + writer.flush(); + + writer.close(); + // recuperation du contenu du texte genere String r = writer.getBuffer().toString(); @@ -401,4 +420,23 @@ return '\n' + result; } + + protected Context createVelocityContext(String licenseContent) throws MojoExecutionException { + + // prepare velocity context + Context context = new VelocityContext(); + + context.put("inceptionYear", inceptionYear); + context.put("projectName", projectName); + context.put("organizationName", organizationName); + context.put("licenseContent", licenseContent); + + if (templateParameters != null) { + for (Entry<String, String> e : templateParameters.entrySet()) { + context.put(e.getKey(), e.getValue()); + } + } + + return context; + } } Added: trunk/src/main/resources/META-INF/plexus/components.xml =================================================================== --- trunk/src/main/resources/META-INF/plexus/components.xml (rev 0) +++ trunk/src/main/resources/META-INF/plexus/components.xml 2009-09-21 10:11:54 UTC (rev 1642) @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<component-set> + <components> + <component> + <role>org.codehaus.plexus.velocity.VelocityComponent</role> + <role-hint>maven-license-plugin</role-hint> + <implementation>org.codehaus.plexus.velocity.DefaultVelocityComponent</implementation> + <configuration> + <properties> + <property> + <name>resource.loader</name> + <value>file,classpath</value> + </property> + <property> + <name>classpath.resource.loader.class</name> + <value>org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</value> + </property> + <property> + <name>file.resource.loader.class</name> + <value>org.apache.velocity.runtime.resource.loader.FileResourceLoader</value> + </property> + </properties> + </configuration> + </component> + </components> +</component-set> \ No newline at end of file Modified: trunk/src/test/java/org/nuiton/license/header/LicenseProcessorTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/header/LicenseProcessorTest.java 2009-08-29 21:29:19 UTC (rev 1641) +++ trunk/src/test/java/org/nuiton/license/header/LicenseProcessorTest.java 2009-09-21 10:11:54 UTC (rev 1642) @@ -25,13 +25,13 @@ import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.codehaus.plexus.PlexusTestCase; import org.junit.Before; import org.junit.BeforeClass; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; +import org.nuiton.plugin.TestHelper; import org.nuiton.util.PluginHelper; /** @@ -48,9 +48,8 @@ @BeforeClass public static void initClass() throws Exception { - String path = PlexusTestCase.getBasedir(); - basedir = new File(path); - testdir = new File(basedir, "target" + File.separator + "tests" + File.separator + LicenseProcessorTest.class.getSimpleName()); + basedir = TestHelper.getBasedir(); + testdir = TestHelper.getFile(basedir, "target", "tests", LicenseProcessorTest.class.getSimpleName()); testdir.mkdirs(); } @@ -65,8 +64,8 @@ @Test public void testProcessor() throws IOException { - File in = new File(basedir, "src" + File.separator + "test" + File.separator + "resources" + File.separator + "LicenseProcessorTest.java2"); - File out = new File(testdir, in.getName()); + File in = TestHelper.getFile(basedir, "src", "test", "resources", "LicenseProcessorTest.java2"); + File out = TestHelper.getFile(testdir, in.getName()); LicenseProcessor processor = new LicenseProcessor("my license"); processor.process(in, out); String content = PluginHelper.readAsString(out, "utf-8"); @@ -81,7 +80,7 @@ @Test public void testProcessor2() throws IOException { - File in = new File(basedir, "src" + File.separator + "test" + File.separator + "resources" + File.separator + "LicenseProcessorTest_1.java2"); + File in = TestHelper.getFile(basedir, "src", "test", "resources", "LicenseProcessorTest_1.java2"); File out = new File(testdir, in.getName()); LicenseProcessor processor = new LicenseProcessor("my license"); processor.process(in, out); Modified: trunk/src/test/java/org/nuiton/license/header/plugin/UpdateHeaderPluginTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/header/plugin/UpdateHeaderPluginTest.java 2009-08-29 21:29:19 UTC (rev 1641) +++ trunk/src/test/java/org/nuiton/license/header/plugin/UpdateHeaderPluginTest.java 2009-09-21 10:11:54 UTC (rev 1642) @@ -23,71 +23,47 @@ import java.io.File; import java.io.IOException; import java.util.Map.Entry; -import org.nuiton.util.PluginConfig; import static org.junit.Assert.*; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; -import org.junit.AfterClass; import org.nuiton.processor.filters.LicenseFilter; -import org.nuiton.util.BasePluginTestCase; import org.nuiton.util.PluginHelper; +import org.nuiton.plugin.AbstractMojoTest; /** @author chemit */ -public class UpdateHeaderPluginTest extends BasePluginTestCase { +public class UpdateHeaderPluginTest extends AbstractMojoTest<UpdateHeaderPlugin> { public static final String _LICENSE_TO_CHANGE_ = LicenseFilter.HEADER + " license to change " + LicenseFilter.FOOTER; public static final String _MUST_BE_THERE = "// MUST BE THERE!"; - UpdateHeaderPlugin plugin; - @BeforeClass - public static void initClass() throws Exception { - initConfigs(UpdateHeaderPluginTest.class, "testBug_28", "testJava", "testXml", "testProperties"); - } - - @AfterClass - public static void afterClass() throws Exception { - configItr = null; - testDir = null; - } - - @Before @Override - public void setUp() throws Exception { - super.setUp(); - assertNotNull(mojo); - plugin = (UpdateHeaderPlugin) mojo; - plugin.setVerbose(true); + protected String getGoalName(String methodName) { + return "update-header"; } @Test - @PluginConfig(pomName = "bug_28.xml", goalName = "update-header") - public void testBug_28() throws Exception { + public void bug_28() throws Exception { testPom(new String[]{_MUST_BE_THERE}, new String[]{}); } @Test - @PluginConfig(pomName = "java.xml", goalName = "update-header") - public void testJava() throws Exception { + public void java() throws Exception { testPom(new String[]{_MUST_BE_THERE}, new String[]{_LICENSE_TO_CHANGE_}); } @Test - @PluginConfig(pomName = "xml.xml", goalName = "update-header") - public void testXml() throws Exception { + public void xml() throws Exception { testPom(new String[]{_MUST_BE_THERE}, new String[]{_LICENSE_TO_CHANGE_}); } @Test - @PluginConfig(pomName = "properties.xml", goalName = "update-header") - public void testProperties() throws Exception { + public void properties() throws Exception { testPom(new String[]{_MUST_BE_THERE}, new String[]{_LICENSE_TO_CHANGE_}); @@ -95,9 +71,11 @@ public void testPom(String[] mandatoryPatterns, String[] excludePatterns) throws Exception { - plugin.execute(); + UpdateHeaderPlugin mojo = getMojo(); - for (Entry<File, String[]> entry : plugin.filesToTreate.entrySet()) { + mojo.execute(); + + for (Entry<File, String[]> entry : mojo.filesToTreate.entrySet()) { File src = entry.getKey(); for (String javaRelativePath : entry.getValue()) { File f = new File(src, javaRelativePath);