r1630 - in trunk: . src/main/java/org/nuiton/license src/main/java/org/nuiton/license/header src/main/java/org/nuiton/license/header/generator src/main/resources src/site/rst src/test/java/org/nuiton/license src/test/java/org/nuiton/license/header src/test/resources src/test/resources/org src/test/resources/org/nuiton src/test/resources/org/nuiton/license src/test/resources/org/nuiton/license/header src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest src/test/r
Author: tchemit Date: 2009-08-26 22:21:00 +0200 (Wed, 26 Aug 2009) New Revision: 1630 Added: trunk/src/main/java/org/nuiton/license/header/ trunk/src/main/java/org/nuiton/license/header/generator/ trunk/src/main/java/org/nuiton/license/header/generator/HeaderGenerator.java trunk/src/test/java/org/nuiton/license/header/ trunk/src/test/java/org/nuiton/license/header/LicenseProcessorTest.java trunk/src/test/java/org/nuiton/license/header/UpdateHeaderPluginTest.java trunk/src/test/resources/LicenseProcessorTest.java2 trunk/src/test/resources/LicenseProcessorTest_1.java2 trunk/src/test/resources/org/ trunk/src/test/resources/org/nuiton/ trunk/src/test/resources/org/nuiton/license/ trunk/src/test/resources/org/nuiton/license/header/ trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/ trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28.xml trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28/ trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28/JavaDummyKO.java2 trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28/JavaDummyOK.java2 Removed: trunk/src/main/java/org/nuiton/license/plugin/ trunk/src/test/java/org/nuiton/license/plugin/ Modified: trunk/pom.xml trunk/src/main/resources/log4j.properties trunk/src/site/rst/index.rst Log: fix bug #28, rethink the goal : now only one update-header Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-08-25 22:42:31 UTC (rev 1629) +++ trunk/pom.xml 2009-08-26 20:21:00 UTC (rev 1630) @@ -39,6 +39,20 @@ <scope>compile</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> + <!-- tests dependencies --> <dependency> @@ -50,26 +64,19 @@ </dependency> <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + <version>1.1</version> + <scope>test</scope> + </dependency> + + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.6</version> <scope>test</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> - </dependencies> <!-- ************************************************************* --> @@ -77,7 +84,10 @@ <!-- ************************************************************* --> <name>Plugin maven de changement de license</name> - <description>Plugin pour switcher de license dans un module maven 2</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> @@ -89,7 +99,8 @@ <properties> - <processor.version>1.0.0</processor.version> + <helper.version>1.0.2-SNAPSHOT</helper.version> + <processor.version>1.0.1-SNAPSHOT</processor.version> </properties> Copied: trunk/src/main/java/org/nuiton/license/header/generator/HeaderGenerator.java (from rev 1628, trunk/src/main/java/org/nuiton/license/plugin/HeaderGenerator.java) =================================================================== --- trunk/src/main/java/org/nuiton/license/header/generator/HeaderGenerator.java (rev 0) +++ trunk/src/main/java/org/nuiton/license/header/generator/HeaderGenerator.java 2009-08-26 20:21:00 UTC (rev 1630) @@ -0,0 +1,40 @@ +/** + * *##% Plugin maven de changement de license + * Copyright (C) 2008 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.nuiton.license.header.generator; + +/** + * A simple Contract to generate a new header for a given type of file. + * + * @author chemit + * @since 1.0.0 + */ +public interface HeaderGenerator { + + /** + * + * @return the name of the generator + */ + String getName(); + + /** + * @param licenseHeaderContent the content of the license header + * @return the full header to add on the first line of file. + */ + String getHeader(String licenseHeaderContent); +} Property changes on: trunk/src/main/java/org/nuiton/license/header/generator/HeaderGenerator.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/src/main/resources/log4j.properties =================================================================== --- trunk/src/main/resources/log4j.properties 2009-08-25 22:42:31 UTC (rev 1629) +++ trunk/src/main/resources/log4j.properties 2009-08-26 20:21:00 UTC (rev 1630) @@ -1,10 +1,12 @@ # Global logging configuration -log4j.rootLogger=ERROR, stdout +log4j.rootLogger=DEBUG, stdout # Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n # package level -log4j.logger.org.codelutin=INFO +log4j.logger.org.nuiton=INFO +log4j.logger.org.nuiton.processor=TRACE +log4j.logger.org.nuiton.license=DEBUG Modified: trunk/src/site/rst/index.rst =================================================================== --- trunk/src/site/rst/index.rst 2009-08-25 22:42:31 UTC (rev 1629) +++ trunk/src/site/rst/index.rst 2009-08-26 20:21:00 UTC (rev 1630) @@ -11,16 +11,10 @@ The plugin has the following goals: - * `license-switcher license`_ add license file and third-party files to classpath (generate them if necessary). + * `license update-header`_ add or update license header on some files. - * `license-switcher third-party`_ write the licenses of all third-party libraries used in project. - - * `license-switcher switch`_ parse Java sources and switch license header. + * `license help`_ display help about the plugin (goals, usage). - * `license-switcher help`_ display help about the plugin (goals, usage). - - * `license-switcher available-licenses`_ display the known licenses of the plugin. - Usage ~~~~~ @@ -31,15 +25,9 @@ to be done. -.. _license-switcher license: license-mojo.html +.. _license update-header: license-mojo.html -.. _license-switcher third-party: third-party-mojo.html +.. _license help: help-mojo.html -.. _license-switcher switch: switch-mojo.html - -.. _license-switcher help: help-mojo.html - -.. _license-switcher available-licenses: available-licenses-mojo.html - .. _usage page: usage.html \ No newline at end of file Added: trunk/src/test/java/org/nuiton/license/header/LicenseProcessorTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/header/LicenseProcessorTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/license/header/LicenseProcessorTest.java 2009-08-26 20:21:00 UTC (rev 1630) @@ -0,0 +1,89 @@ +package org.nuiton.license.header; + +import org.nuiton.processor.LicenseProcessor; +import java.io.File; +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.util.PluginHelper; + +/** + * + * @author chemit + * @since 1.0.1 + */ +public class LicenseProcessorTest { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private final Log log = LogFactory.getLog(LicenseProcessorTest.class); + static File basedir; + static File testdir; + + @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()); + testdir.mkdirs(); + } + + @AfterClass + public static void afterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @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()); + LicenseProcessor processor = new LicenseProcessor("my license"); + processor.process(in, out); + String content = PluginHelper.readAsString(out, "utf-8"); + if (log.isDebugEnabled()) { + log.debug("output : " + out); + log.debug(content); + } + checkPattern("// MUST BE THERE!", true, out); + checkPattern("my license", false, out); + } + + @Test + public void testProcessor2() throws IOException { + + File in = new File(basedir, "src" + File.separator + "test" + File.separator + "resources" + File.separator + "LicenseProcessorTest_1.java2"); + File out = new File(testdir, in.getName()); + LicenseProcessor processor = new LicenseProcessor("my license"); + processor.process(in, out); + String content = PluginHelper.readAsString(out, "utf-8"); + if (log.isDebugEnabled()) { + log.debug("output : " + out); + log.debug(content); + } + checkPattern("// MUST BE THERE!", true, out); + checkPattern("my license", true, out); + } + + protected void checkPattern(String pattern, boolean required, File f) throws IOException { + + if (log.isDebugEnabled()) { + log.debug("check generated file " + f); + } + + Assert.assertTrue("generated file " + f + " was not found...", f.exists()); + String content = PluginHelper.readAsString(f, "utf-8"); + + String errorMessage = required ? "could not find the pattern : " : "should not have found pattern :"; + Assert.assertEquals(errorMessage + pattern + " in file " + f, required, content.contains(pattern)); + } +} Property changes on: trunk/src/test/java/org/nuiton/license/header/LicenseProcessorTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/test/java/org/nuiton/license/header/UpdateHeaderPluginTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/header/UpdateHeaderPluginTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/license/header/UpdateHeaderPluginTest.java 2009-08-26 20:21:00 UTC (rev 1630) @@ -0,0 +1,84 @@ +/** + * *##% Plugin maven de changement de license + * Copyright (C) 2008 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.nuiton.license.header; + +import java.io.File; +import java.io.IOException; +import java.util.Map.Entry; +import org.nuiton.util.PluginConfig; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import org.junit.AfterClass; +import org.nuiton.util.BasePluginTestCase; +import org.nuiton.util.PluginHelper; + +/** @author chemit */ +public class UpdateHeaderPluginTest extends BasePluginTestCase { + + @BeforeClass + public static void initClass() throws Exception { + initConfigs(UpdateHeaderPluginTest.class, "testBug_28"); + } + + @AfterClass + public static void afterClass() throws Exception { + configItr = null; + testDir = null; + } + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + } + + @Test + @PluginConfig(pomName = "bug_28.xml", goalName = "update-header") + public void testBug_28() throws MojoExecutionException, MojoFailureException, IOException { + assertNotNull(mojo); + + UpdateHeaderPlugin p = (UpdateHeaderPlugin) mojo; + p.execute(); + + for (Entry<File, String[]> entry : p.filesToTreate.entrySet()) { + File src = entry.getKey(); + for (String javaRelativePath : entry.getValue()) { + File f = new File(src, javaRelativePath); + checkPattern("// MUST BE THERE!", true, f); + } + } + } + + protected void checkPattern(String pattern, boolean required, File f) throws IOException { + if (mojo.isVerbose()) { + mojo.getLog().info("check generated file " + f); + } + + assertTrue("generated file " + f + " was not found...", f.exists()); + String content = PluginHelper.readAsString(f, "utf-8"); + + String errorMessage = required ? "could not find the pattern : " : "should not have found pattern :"; + assertEquals(errorMessage + pattern + " in file " + f, required, content.contains(pattern)); + } +} Property changes on: trunk/src/test/java/org/nuiton/license/header/UpdateHeaderPluginTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/test/resources/LicenseProcessorTest.java2 =================================================================== --- trunk/src/test/resources/LicenseProcessorTest.java2 (rev 0) +++ trunk/src/test/resources/LicenseProcessorTest.java2 2009-08-26 20:21:00 UTC (rev 1630) @@ -0,0 +1,10 @@ +/** + * *##% YO + * ##% yy + */ + +public class LicenceProcessorTest { + + +// MUST BE THERE! +} \ No newline at end of file Added: trunk/src/test/resources/LicenseProcessorTest_1.java2 =================================================================== --- trunk/src/test/resources/LicenseProcessorTest_1.java2 (rev 0) +++ trunk/src/test/resources/LicenseProcessorTest_1.java2 2009-08-26 20:21:00 UTC (rev 1630) @@ -0,0 +1,10 @@ +/** + * *##% YO + * ##%* yy + */ + +public class LicenceProcessorTest { + + +// MUST BE THERE! +} \ No newline at end of file Added: trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28/JavaDummyKO.java2 =================================================================== --- trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28/JavaDummyKO.java2 (rev 0) +++ trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28/JavaDummyKO.java2 2009-08-26 20:21:00 UTC (rev 1630) @@ -0,0 +1,25 @@ +/* + * *##% Maven helper plugin + * Copyright (C) 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.nuiton.license.header.UpdateHeaderPluginTest.bug_28; + +/** @author chemit */ +public class JavaDummy { + +// MUST BE THERE! +} Added: trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28/JavaDummyOK.java2 =================================================================== --- trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28/JavaDummyOK.java2 (rev 0) +++ trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28/JavaDummyOK.java2 2009-08-26 20:21:00 UTC (rev 1630) @@ -0,0 +1,25 @@ +/* + * *##% Maven helper plugin + * Copyright (C) 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##% + */ +package org.nuiton.license.header.UpdateHeaderPluginTest.bug_28; + +/** @author chemit */ +public class JavaDummy { + +// MUST BE THERE! +} Added: trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28.xml =================================================================== --- trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28.xml (rev 0) +++ trunk/src/test/resources/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28.xml 2009-08-26 20:21:00 UTC (rev 1630) @@ -0,0 +1,40 @@ +<?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"> + + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin-bug_28</artifactId> + <version>0</version> + + <name>TestOne</name> + + <build> + + <plugins> + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-license-plugin</artifactId> + <configuration> + <encoding>UTF-8</encoding> + <licenseName>lgpl_v3</licenseName> + <generatorName>java</generatorName> + <includes>**/*.java2</includes> + <compileSourceRoots> + <dir>target/test-classes/org/nuiton/license/header/UpdateHeaderPluginTest/bug_28</dir> + </compileSourceRoots> + <testCompileSourceRoots> + </testCompileSourceRoots> + <!--<verbose>true</verbose>--> + </configuration> + <executions> + <execution> + <goals> + <goal>update-header</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file
participants (1)
-
tchemit@users.nuiton.org