Author: tchemit Date: 2010-04-12 13:01:09 +0200 (Mon, 12 Apr 2010) New Revision: 1737 Log: - update changelog.txt - update doc - deal with xml prolog for new header on xml - reformat doc - finalize documentation - add javadoc package.html - add optimized license project descriptor (add single tags and deal with them) Added: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessorConfiguration.java trunk/src/main/java/org/nuiton/license/plugin/header/InvalideFileHeaderException.java trunk/src/main/java/org/nuiton/license/plugin/header/UpdateFileHeaderFilter.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/package.html trunk/src/main/java/org/nuiton/license/plugin/header/package.html trunk/src/main/java/org/nuiton/license/plugin/header/transformer/package.html trunk/src/main/java/org/nuiton/license/plugin/model/descriptor/ trunk/src/main/java/org/nuiton/license/plugin/model/descriptor/package.html trunk/src/main/java/org/nuiton/license/plugin/model/package.html trunk/src/main/java/org/nuiton/license/plugin/package.html Modified: trunk/changelog.txt trunk/pom.xml trunk/src/it/update-file-header/src/license/project.xml trunk/src/it/update-project-license/src/license/project.xml trunk/src/license/project.xml trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseWithDescriptorMojo.java trunk/src/main/java/org/nuiton/license/plugin/CommentStyleListMojo.java trunk/src/main/java/org/nuiton/license/plugin/LicenseListMojo.java trunk/src/main/java/org/nuiton/license/plugin/UpdateFileHeaderMojo.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/transformer/AbstractFileHeaderTransformer.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java trunk/src/main/mdo/descriptor.mdo trunk/src/main/resources/META-INF/licenses/gpl_v1/header.txt trunk/src/main/resources/META-INF/licenses/gpl_v2/header.txt trunk/src/main/resources/META-INF/licenses/gpl_v3/header.txt trunk/src/main/resources/META-INF/licenses/licenses.properties trunk/src/site/rst/descriptor.rst trunk/src/site/rst/header.rst trunk/src/site/rst/index.rst trunk/src/site/rst/usage.rst trunk/src/test/java/org/nuiton/license/plugin/UpdateFileHeaderMojoTest.java trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/addLicense/project.xml trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/all/project.xml trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/failLicense/project.xml trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/ignoreLicense/project.xml trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/updateLicense/project.xml trunk/src/test/resources/org/nuiton/license/plugin/updateProjectLicenseMojoTest/projectOne.xml trunk/src/test/resources/org/nuiton/license/plugin/updateProjectLicenseMojoTest/projectTwo.xml Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/changelog.txt 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,3 +1,38 @@ +maven-license-plugin (2.1) stable; urgency=high + + * Anomalie #488: MUST insert xml header after prolog in found + * Evolution #452: Reformat code to respect code formatting + * Evolution #454: Use maven-helper-plugin 1.2.3 + * Evolution #456: Separate Copyright from license content in header + * Evolution #457: Add a new header format to be ignored by updater goal for specific license + * Evolution #458: Add a migration mode from old format to new one + * Evolution #461: Deprecates update-header goal and introduces update-license goal + * Evolution #462: Add new licenses in repository + * Evolution #465: Add AGPL license + * Evolution #478: Deprecates LicenseHeaderGenerator api + * Evolution #479: Introduce update-project-license goal (replace add-license goal) + * Evolution #486: Use junit 4.8.1 + + -- chemit -- Mon, 12 Apr 2010 12:32:09 +0200 + +maven-license-plugin (2.0.2) stable; urgency=high + + * Anomalie #267: can not configure compileSourceRoots on update-header goal + * Evolution #268: Add apt license generator + + -- chemit -- 24/01/2010 + +maven-license-plugin (2.0.1) stable; urgency=high + + * Anomali e #250: Change mojo properties expression from helper.XXX to license.XXX + * Evolution #192: Use mavenpom4redmine 2.0.2 + * Evolution #193: Use maven-helper-plugin 1.2.0 with revisited AbstractPlugin api + * Evolution #247: generate files into target/generated-sources/licene instead of target/generated-sources/resources + * Evolution #248: Rename Mojo classes from Plugin suffix to Mojo suffix + * Evolution #249: Remove ServiceLoader mecanism + + -- chemit -- 21/01/2010 + maven-license-plugin (2.0.0) stable; urgency=high * Evolution #31: add some documentation on site Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/pom.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -238,7 +238,7 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.7</version> + <version>4.8.1</version> <scope>test</scope> </dependency> @@ -277,15 +277,9 @@ <!-- 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> + <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> <!-- ************************************************************* --> @@ -368,42 +362,6 @@ </executions> </plugin> - <plugin> - <artifactId>maven-plugin-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>helpmojo</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <artifactId>maven-antrun-plugin</artifactId> - <!-- TC-20100117 : 1.3 does not works here --> - <version>1.2</version> - <executions> - <!-- copy generated xsd to site --> - <execution> - <id>copy licenProject.xsd</id> - <phase>pre-site</phase> - <configuration> - <tasks> - <copy verbose="${maven.verbose}" - failonerror="false" - overwrite="false" - file="target/generated-site/xsd/licenseProject-1.0.0.xsd" - tofile="target/site/licenseProject-1.0.0.xsd"/> - </tasks> - </configuration> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> <pluginManagement> @@ -431,23 +389,6 @@ </build> - <reporting> - <plugins> - - <plugin> - <artifactId>maven-plugin-plugin</artifactId> - <version>2.5.1</version> - </plugin> - - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cobertura-maven-plugin</artifactId> - <version>2.3</version> - </plugin> - - </plugins> - </reporting> - <profiles> <profile> @@ -468,8 +409,7 @@ <pomInclude>**/pom.xml</pomInclude> </pomIncludes> <postBuildHookScript>verify</postBuildHookScript> - <localRepositoryPath>${basedir}/target/local-repo - </localRepositoryPath> + <localRepositoryPath>${basedir}/target/local-repo</localRepositoryPath> <settingsFile>src/it/settings.xml</settingsFile> <cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo> <!--<debug>true</debug>--> @@ -489,6 +429,90 @@ </build> </profile> + <!-- perform only on a release stage when using the maven-release-plugin --> + <profile> + <id>release-profile</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + + <build> + + <plugins> + + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>helpmojo</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <!-- TC-20100117 : 1.3 does not works here --> + <version>1.2</version> + <executions> + <!-- copy generated xsd to site --> + <execution> + <id>copy-descriptor-xsd</id> + <phase>pre-site</phase> + <configuration> + <tasks> + <copy verbose="${maven.verbose}" + failonerror="false" + overwrite="false" + file="target/generated-site/xsd/licenseProjectDescriptor-${mdoVersion}.xsd" + tofile="target/site/licenseProjectDescriptor-${mdoVersion}.xsd"/> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + + </build> + + </profile> + + <!-- perform only on a release stage when using the maven-release-plugin --> + <profile> + <id>reporting</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + + <reporting> + + <plugins> + + <plugin> + <artifactId>maven-plugin-plugin</artifactId> + <version>2.5.1</version> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>cobertura-maven-plugin</artifactId> + <version>2.3</version> + </plugin> + + </plugins> + </reporting> + + </profile> </profiles> </project> Modified: trunk/src/it/update-file-header/src/license/project.xml =================================================================== --- trunk/src/it/update-file-header/src/license/project.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/it/update-file-header/src/license/project.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,20 +1,13 @@ <?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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-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> + <header> + <commentStyle>java</commentStyle> + <fileSet> + <basedir>src/main/java</basedir> + <include>**/*.java</include> + </fileSet> + </header> </project> Modified: trunk/src/it/update-project-license/src/license/project.xml =================================================================== --- trunk/src/it/update-project-license/src/license/project.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/it/update-project-license/src/license/project.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,19 +1,6 @@ <?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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>gpl_v3</mainLicense> - <licenseSets> - <licenseSet> - <fileSets> - <fileSet> - <headerType>java</headerType> - <basedir>src/main/java</basedir> - <includes> - <include>**/*.java</include> - </includes> - </fileSet> - </fileSets> - </licenseSet> - </licenseSets> </project> Modified: trunk/src/license/project.xml =================================================================== --- trunk/src/license/project.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/license/project.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,53 +1,45 @@ <?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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>lgpl_v3</mainLicense> - <licenseSets> - <licenseSet> - <fileSets> - <fileSet> - <headerType>java</headerType> + <headers> + + <header> + <commentStyle>java</commentStyle> + <fileSets> + <fileSet> <basedir>src/main/java</basedir> - <includes> - <include>**/*.java</include> - </includes> + <include>**/*.java</include> </fileSet> - - <fileSet> - <headerType>java</headerType> + <fileSet> <basedir>src/test/java</basedir> - <includes> - <include>**/*.java</include> - </includes> + <include>**/*.java</include> </fileSet> - <fileSet> - <headerType>java</headerType> <basedir>src/target/generated-sources/modello</basedir> - <includes> - <include>**/*.java</include> - </includes> + <include>**/*.java</include> </fileSet> + </fileSets> + </header> + <header> + <commentStyle>rst</commentStyle> <fileSet> - <headerType>rst</headerType> <basedir>src/site</basedir> - <includes> - <include>**/*.rst</include> - </includes> + <include>**/*.rst</include> </fileSet> + </header> + <header> + <commentStyle>xml</commentStyle> <fileSet> - <headerType>xml</headerType> <basedir>src/site</basedir> - <includes> - <include>**/*.xml</include> - </includes> + <include>**/*.xml</include> </fileSet> + </header> - </fileSets> - </licenseSet> - </licenseSets> + </headers> + </project> Modified: trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseWithDescriptorMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseWithDescriptorMojo.java 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/java/org/nuiton/license/plugin/AbstractLicenseWithDescriptorMojo.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -30,14 +30,15 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; import org.nuiton.license.plugin.header.FileHeader; import org.nuiton.license.plugin.header.transformer.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.license.plugin.model.descriptor.FileSet; +import org.nuiton.license.plugin.model.descriptor.Header; +import org.nuiton.license.plugin.model.descriptor.LicenseProjectDescriptor; +import org.nuiton.license.plugin.model.descriptor.io.xpp3.LicenseProjectDescriptorXpp3Reader; import java.io.File; import java.io.FileReader; @@ -91,9 +92,16 @@ private LicenseStore licenseStore; /** descriptor of project */ - private LicenseProject licenseProject; + private LicenseProjectDescriptor licenseProjectDescriptor; - /** @return {@code true} if goal will not be executed */ + /** + * When is sets to {@code true}, will skip execution. + * <p/> + * This will take effects in method {@link #checkSkip()}. + * So the method {@link #doAction()} will never be invoked. + * + * @return {@code true} if goal will not be executed + */ public abstract boolean isSkip(); /** @@ -109,6 +117,10 @@ getLog().info("skip flag is on, will skip goal."); return false; } + if (!getDescriptor().exists()) { + getLog().warn("skip - could not find descriptor " + getDescriptor()); + return false; + } return super.checkSkip(); } @@ -124,11 +136,41 @@ setLicenseStore(licenseStore); // load project descriptor - LicenseProject licenseProject = null; - FileReader reader = new FileReader(getDescriptor()); + File descriptorFile = new File(getDescriptor().getAbsolutePath()); + if (!descriptorFile.exists()) { + + // try to find the file in the direct parent module + MavenProject mavenProject = getProject().getParent(); + if (mavenProject != null) { + + File basedir = getProject().getBasedir(); + + // try with the parent + String path = descriptorFile.getAbsolutePath().substring( + basedir.getAbsolutePath().length() + 1); + setDescriptor(new File(mavenProject.getBasedir() + + File.separator + path)); + if (isVerbose()) { + getLog().info("try in parent module " + getDescriptor()); + } + + } + descriptorFile = new File(getDescriptor().getAbsolutePath()); + } + + if (!descriptorFile.exists()) { +// throw new MojoFailureException( +// "could not find descriptor " + descriptorFile); + return; + } + + getLog().info("Loading descriptor " + descriptorFile); + LicenseProjectDescriptor licenseProject = null; + FileReader reader = new FileReader(descriptorFile); try { - licenseProject = new LicenseProjectXpp3Reader().read(reader); - setLicenseProject(licenseProject); + licenseProject = + new LicenseProjectDescriptorXpp3Reader().read(reader); + setLicenseProjectDescriptor(licenseProject); } finally { reader.close(); } @@ -136,9 +178,9 @@ // check that license project is sane (known licenses + header types) // + populate default license name in LicenseSet (with main License) if // none given for licenseSet - validateProjectFile(licenseProject, - licenseStore, - getTransformers() + validateLicenseProjectDescriptor(licenseProject, + licenseStore, + getTransformers() ); } @@ -162,8 +204,8 @@ return licenseStore; } - public LicenseProject getLicenseProject() { - return licenseProject; + public LicenseProjectDescriptor getLicenseProjectDescriptor() { + return licenseProjectDescriptor; } public void setKeepBackup(boolean keepBackup) { @@ -178,7 +220,8 @@ this.licenseResolver = licenseResolver; } - public void setTransformers(Map<String, FileHeaderTransformer> transformers) { + public void setTransformers( + Map<String, FileHeaderTransformer> transformers) { this.transformers = transformers; } @@ -187,13 +230,14 @@ } - public void setLicenseProject(LicenseProject licenseProject) { - this.licenseProject = licenseProject; + public void setLicenseProjectDescriptor( + LicenseProjectDescriptor licenseProjectDescriptor) { + this.licenseProjectDescriptor = licenseProjectDescriptor; } public License getMainLicense() throws IllegalArgumentException, IllegalStateException { - LicenseProject licenseProject = getLicenseProject(); + LicenseProjectDescriptor licenseProject = getLicenseProjectDescriptor(); if (licenseProject == null) { throw new IllegalStateException("No license project initialized!"); } @@ -209,7 +253,8 @@ public License getLicense(String licenseName) throws IllegalArgumentException, IllegalStateException { if (StringUtils.isEmpty(licenseName)) { - throw new IllegalArgumentException("licenseName can not be null, nor empty"); + throw new IllegalArgumentException( + "licenseName can not be null, nor empty"); } LicenseStore licenseStore = getLicenseStore(); if (licenseStore == null) { @@ -222,7 +267,8 @@ public FileHeaderTransformer getTransformer(String transformerName) throws IllegalArgumentException, IllegalStateException { if (StringUtils.isEmpty(transformerName)) { - throw new IllegalArgumentException("transformerName can not be null, nor empty!"); + throw new IllegalArgumentException( + "transformerName can not be null, nor empty!"); } Map<String, FileHeaderTransformer> transformers = getTransformers(); if (transformers == null) { @@ -290,8 +336,8 @@ return result; } - protected void validateProjectFile( - LicenseProject licenseProject, + protected void validateLicenseProjectDescriptor( + LicenseProjectDescriptor licenseProjectDescriptor, LicenseStore licenseStore, Map<String, FileHeaderTransformer> transformers) throws MojoFailureException { @@ -299,19 +345,35 @@ List<String> licenseNames = Arrays.asList(licenseStore.getLicenseNames()); // check licenses is known - String mainLicense = licenseProject.getMainLicense(); + String mainLicense = licenseProjectDescriptor.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(); + Header singleHeader = licenseProjectDescriptor.getHeader(); + if (singleHeader != null) { + + // add it to set (and remove it from single) + licenseProjectDescriptor.addHeader(singleHeader); + licenseProjectDescriptor.setHeader(null); + } + + for (Header header : licenseProjectDescriptor.getHeaders()) { + + String headerType = header.getCommentStyle(); + + if (getTransformer(headerType) == null) { + throw new MojoFailureException( + "headerType '" + headerType + + "' is unknown, use one of " + transformers.keySet()); + } + String licenseName = header.getLicenseName(); if (StringUtils.isEmpty(licenseName)) { // use the main license - licenseSet.setLicenseName(mainLicense); + header.setLicenseName(mainLicense); } else { // check license name @@ -322,15 +384,30 @@ } } - // check header types (for each file set) - for (FileSet fileSet : licenseSet.getFileSets()) { - String headerType = fileSet.getHeaderType(); + FileSet singleFileSet = header.getFileSet(); + if (singleFileSet != null) { - if (getTransformer(headerType) == null) { - throw new MojoFailureException( - "headerType '" + headerType + - "' is unknown, use one of " + transformers.keySet()); + // add it to set (and remove it from single) + header.addFileSet(singleFileSet); + header.setFileSet(null); + } + for (FileSet fileSet : header.getFileSets()) { + + String singleInclude = fileSet.getInclude(); + if (singleInclude != null) { + + // add it to set (and remove it from single) + fileSet.addInclude(singleInclude); + fileSet.setInclude(null); } + + String singleExclude = fileSet.getExclude(); + if (singleExclude != null) { + + // add it to set (and remove it from single) + fileSet.addExclude(singleExclude); + fileSet.setExclude(null); + } } } } Modified: trunk/src/main/java/org/nuiton/license/plugin/CommentStyleListMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/CommentStyleListMojo.java 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/java/org/nuiton/license/plugin/CommentStyleListMojo.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -32,8 +32,10 @@ import org.apache.maven.plugin.MojoFailureException; import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Map; -import java.util.Map.Entry; /** * Displays all the available comment style to box file headers. @@ -70,22 +72,35 @@ @Override public void doAction() throws MojoExecutionException, MojoFailureException { - StringBuilder buffer = new StringBuilder("\n"); - buffer.append("\n\n-------------------------------------------------------------------------------\n"); - buffer.append(" maven-license-plugin\n"); - buffer.append("-------------------------------------------------------------------------------\n\n"); + StringBuilder buffer = new StringBuilder(); + if (isVerbose()) { + buffer.append("\n\n-------------------------------------------------------------------------------\n"); + buffer.append(" maven-license-plugin\n"); + buffer.append("-------------------------------------------------------------------------------\n\n"); + } + List<String> names = new ArrayList<String>(transformers.keySet()); + Collections.sort(names); - buffer.append("List of available comment style:\n\n"); - for (Entry<String, FileHeaderTransformer> e : transformers.entrySet()) { - FileHeaderTransformer generator = e.getValue(); - buffer.append(" - "); - buffer.append(e.getKey()); - buffer.append(" : "); - buffer.append(generator.getDescription()); - buffer.append("\n"); + int maxLength = 0; + for (String name : names) { + if (name.length() > maxLength) { + maxLength = name.length(); + } + } + + String pattern = " - %1$-" + maxLength + "s : %2$s\n"; + + buffer.append("List of available comment styles:\n\n"); + for (String transformerName : names) { + FileHeaderTransformer transformer = + transformers.get(transformerName); + buffer.append(String.format(pattern, + transformerName, + transformer.getDescription()) + ); if (detail) { buffer.append("\n example : \n"); - buffer.append(generator.boxComment("header", true)); + buffer.append(transformer.boxComment("header", true)); buffer.append('\n'); } } Modified: trunk/src/main/java/org/nuiton/license/plugin/LicenseListMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/LicenseListMojo.java 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/java/org/nuiton/license/plugin/LicenseListMojo.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -34,6 +34,9 @@ import org.nuiton.license.plugin.model.LicenseStore; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; /** * Display all available licenses. @@ -75,18 +78,31 @@ @Override public void doAction() throws MojoExecutionException, MojoFailureException { StringBuilder buffer = new StringBuilder(); - buffer.append("\n\n-------------------------------------------------------------------------------\n"); - buffer.append(" maven-license-plugin\n"); - buffer.append("-------------------------------------------------------------------------------\n\n"); + + if (isVerbose()) { + buffer.append("\n\n-------------------------------------------------------------------------------\n"); + buffer.append(" maven-license-plugin\n"); + buffer.append("-------------------------------------------------------------------------------\n\n"); + } buffer.append("Available licenses :\n\n"); - for (License license : licenseStore.getLicenses()) { - String licenseName = license.getName(); - buffer.append(" * "); - buffer.append(licenseName); - buffer.append(" : "); - buffer.append(license.getDescription()); - buffer.append('\n'); + List<String> names = Arrays.asList(licenseStore.getLicenseNames()); + + int maxLength = 0; + for (String name : names) { + if (name.length() > maxLength) { + maxLength = name.length(); + } + } + Collections.sort(names); + + String pattern = " * %1$-" + maxLength + "s : %2$s\n"; + for (String licenseName : names) { + License license = licenseStore.getLicense(licenseName); + buffer.append(String.format(pattern, + licenseName, + license.getDescription()) + ); if (detail) { try { buffer.append("\n"); Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateFileHeaderMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/UpdateFileHeaderMojo.java 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/java/org/nuiton/license/plugin/UpdateFileHeaderMojo.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -29,13 +29,11 @@ package org.nuiton.license.plugin; import org.apache.commons.lang.StringUtils; -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.*; import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer; import org.nuiton.license.plugin.model.License; -import org.nuiton.license.plugin.model.project.FileSet; -import org.nuiton.license.plugin.model.project.LicenseSet; +import org.nuiton.license.plugin.model.descriptor.FileSet; +import org.nuiton.license.plugin.model.descriptor.Header; import org.nuiton.plugin.PluginHelper; import java.io.File; @@ -57,7 +55,7 @@ * @goal update-file-header * @since 2.1 */ -public class UpdateFileHeaderMojo extends AbstractLicenseWithDescriptorMojo { +public class UpdateFileHeaderMojo extends AbstractLicenseWithDescriptorMojo implements FileHeaderProcessorConfiguration { /** * Name of project (or module). @@ -150,24 +148,73 @@ */ protected boolean clearAfterOperation; + /** + * @component role="org.nuiton.processor.Processor" roleHint="file-header" + * @since 2.1 + */ + protected FileHeaderProcessor processor; + + /** + * @component role="org.nuiton.license.plugin.header.FileHeaderFilter" roleHint="update-file-header" + * @since 2.1 + */ + protected UpdateFileHeaderFilter filter; + + /** internal file header transformer */ + protected FileHeaderTransformer transformer; + + /** internal default file header */ + protected FileHeader header; + /** timestamp used for generation */ protected long timestamp; - /** set of processed files */ - protected Set<File> processedFiles; + /** + * Defines state of a file after process. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ + enum FileState { - /** set of updated files */ - protected Set<File> updatedFiles; + /** file was updated */ + update, - /** set of added header files */ - protected Set<File> addedFiles; + /** file was up to date */ + uptodate, - /** set of ignored files */ - protected Set<File> ignoreFiles; + /** something was added on file */ + add, - /** set of failed files */ - protected Set<File> failedFiles; + /** file was ignored */ + ignore, + /** treatment failed for file */ + fail; + + /** + * register a file for this state on result dictionary. + * + * @param file file to add + * @param result dictionary to update + */ + public void addFile(File file, + EnumMap<FileState, Set<File>> result) { + Set<File> fileSet = result.get(this); + if (fileSet == null) { + fileSet = new HashSet<File>(); + result.put(this, fileSet); + } + fileSet.add(file); + } + } + + /** set of processed files */ + protected Set<File> processedFiles; + + /** by file state files treated */ + protected EnumMap<FileState, Set<File>> result; + @Override public void init() throws Exception { @@ -199,7 +246,7 @@ getLog().info(buffer.toString()); } - if (updateCopyright) { + if (isUpdateCopyright()) { getLog().warn("updateCopyright is not still available..."); //TODO-TC20100409 checks scm @@ -212,268 +259,266 @@ // set timestamp used for temporary files setTimestamp(System.nanoTime()); + getFilter().setUpdateCopyright(isUpdateCopyright()); + getFilter().setLog(getLog()); + getProcessor().setConfiguration(this); + getProcessor().setFilter(filter); + super.init(); } @Override public void doAction() throws Exception { - // create a file header processor which updates license content only - FileHeaderProcessor processor = new FileHeaderProcessor() { + clear(); - @Override - public FileHeaderFilter newFilter( - FileHeader header, FileHeaderTransformer transformer) { - - return new UpdateLicenseHeaderFilter(header, - transformer, - isUpdateCopyright() - ); - } - }; - - clear(); - processedFiles = new HashSet<File>(); - ignoreFiles = new HashSet<File>(); - addedFiles = new HashSet<File>(); - updatedFiles = new HashSet<File>(); - failedFiles = new HashSet<File>(); + result = new EnumMap<FileState, Set<File>>(FileState.class); try { - processFiles(processor); + for (Header header : getLicenseProjectDescriptor().getHeaders()) { + + processHeader(header); + } + } finally { StringBuilder buffer = new StringBuilder(); - buffer.append("Operation result on "); - buffer.append(getProcessedFiles().size()); - buffer.append(" file(s) :"); + String format = "Operation result on %1$s file(s) :"; + buffer.append(String.format(format, getProcessedFiles().size())); - reportType(getFailedFiles(), "fail", buffer); - reportType(getAddedFiles(), "add", buffer); - reportType(getUpdatedFiles(), "update", buffer); - reportType(getIgnoreFiles(), "ignore", buffer); + for (FileState state : FileState.values()) { + reportType(state, buffer); + } + getLog().info(buffer.toString()); + // clean internal states if (isClearAfterOperation()) { clear(); } } } - @Override - protected void finalize() throws Throwable { - super.finalize(); - clear(); - } + protected void processHeader(Header header) throws IOException { - protected void clear() { - if (processedFiles != null) { - processedFiles.clear(); - } - if (ignoreFiles != null) { - ignoreFiles.clear(); - } - if (failedFiles != null) { - failedFiles.clear(); - } - if (updatedFiles != null) { - updatedFiles.clear(); - } - if (addedFiles != null) { - addedFiles.clear(); - } - } + // obtain license from definition + String licenseName = header.getLicenseName(); + License license = getLicense(licenseName); - protected void processFiles(FileHeaderProcessor processor) throws IOException { - for (LicenseSet licenseSet : getLicenseProject().getLicenseSets()) { + getLog().info("process header '" + header.getCommentStyle() + "'"); + getLog().info("using " + license.getDescription()); - // obtain license from definition - String licenseName = licenseSet.getLicenseName(); - License license = getLicense(licenseName); + // use header transformer according to comment style given in header + setTransformer(getTransformer(header.getCommentStyle())); + // file header to use if no header is found on a file + FileHeader defaultFileHeader = buildDefaultFileHeader( + license, + getProjectName(), + getInceptionYear(), + getOrganizationName(), + isAddSvnKeyWords(), + getEncoding() + ); + + // change default license header in processor + setHeader(defaultFileHeader); + + // update processor filter + getProcessor().populateFilter(); + + for (FileSet fileSet : header.getFileSets()) { + + File basedir = new File(getProject().getBasedir(), + fileSet.getBasedir()); if (isVerbose()) { - getLog().info("process " + license.getDescription()); + getLog().info("process file set with basedir : " + basedir); } - // file header to use if no header is found on a file - FileHeader defaultFileHeader = buildDefaultFileHeader( - license, - getProjectName(), - getInceptionYear(), - getOrganizationName(), - isAddSvnKeyWords(), - getEncoding() + 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 ); - // change default license header in processor - processor.setHeader(defaultFileHeader); + try { + for (Map.Entry<File, String[]> entry : + filestoTreate.entrySet()) { - for (FileSet fileSet : licenseSet.getFileSets()) { - File basedir = new File(getProject().getBasedir(), - fileSet.getBasedir()); - if (isVerbose()) { - getLog().info("process file set with basedir : " + basedir); + // treate all files of entry + processFileEntry(entry.getKey(), entry.getValue()); } + } finally { + filestoTreate.clear(); + } + } + } - List<String> includes = fileSet.getIncludes(); - if (includes.isEmpty()) { + protected void processFileEntry(File entryBasedir, + String[] paths) throws IOException { - // it means include all - includes.add("**/*"); - } - List<String> excludes = fileSet.getExcludes(); + getLog().info(paths.length + " file(s) to treate in " + entryBasedir); + for (String path : paths) { + File file = new File(entryBasedir, path); + if (getProcessedFiles().contains(file)) { + getLog().info("skip already processed file " + file); + continue; + } - 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 + // output file + File processFile = + new File(file.getAbsolutePath() + "_" + getTimestamp()); + boolean doFinalize = false; + try { + doFinalize = processFile(file, processFile); + } catch (Exception e) { + getLog().warn("skip failed file : " + + e.getMessage() + + (e.getCause() == null ? "" : + " Cause : " + e.getCause().getMessage()), e ); + FileState.fail.addFile(file, getResult()); + doFinalize = false; + } finally { - // get header transformer according to file set - FileHeaderTransformer transformer = getTransformer(fileSet.getHeaderType()); + // always clean processor internal states + getProcessor().reset(); - // change transformer in processor - processor.setTransformer(transformer); + // whatever was the result, this file is treated. + getProcessedFiles().add(file); - // treate all files of entry - for (Map.Entry<File, String[]> entry : - filestoTreate.entrySet()) { - File entryBasedir = entry.getKey(); - getLog().info("process entry " + entryBasedir); - String[] paths = entry.getValue(); - getLog().info(paths.length + " file(s) to treate."); - for (String path : paths) { - File file = new File(entryBasedir, path); - if (getProcessedFiles().contains(file)) { - getLog().info("skip already processed file " + file); - continue; - } - getProcessedFiles().add(file); - updateFile(processor, file); - } + if (doFinalize) { + finalizeFile(file, processFile); + } else { + deleteFile(processFile); } - - filestoTreate.clear(); } } } - protected void updateFile(FileHeaderProcessor processor, - File file) throws IOException { + /** + * Process the given {@code file} and save the result in the given + * {@code processFile}. + * + * @param file the file to process + * @param processFile the ouput processed file + * @return {@code true} if processFile can be finalize, otherwise need to be delete + * @throws IOException if any pb while treatment + */ + protected boolean processFile(File file, + File processFile) throws IOException { - getLog().debug("start for file " + file); - - // file where to write result - File processFile = new File(file.getAbsolutePath() + "_" + getTimestamp()); getLog().debug("will process into file " + processFile); if (isVerbose()) { getLog().info("process file " + file); } + String content; + try { - try { - processor.process(file, processFile); - } catch (IllegalStateException e) { + // check before all that file should not be skip by the ignoreTag + // this is a costy operation + //TODO-TC-20100411 We should process always from the read content not reading again from file - // could not obtain existing header - getLog().warn( - "skip file " + file + - " Could not extract existing header!)"); - failedFiles.add(file); - deleteFile(processFile); - return; - } + content = PluginHelper.readAsString(file, getEncoding()); - if (processor.isTouched()) { + } catch (IOException e) { + throw new IOException("Could not obtain content of file " + file); + } - if (isVerbose()) { - getLog().info("header was updated for " + file); - } - updatedFiles.add(file); - finalizeFile(file, processFile); - return; - } + //check that file is not marked to be ignored + if (content.contains(getIgnoreTag())) { + getLog().info( + "ignore file (detected " + getIgnoreTag() + ") " + file); - if (processor.isDetectHeader()) { + FileState.ignore.addFile(file, getResult()); - // file has not a valid header (found a start process atg, but - // not an ending one), can not do anything - getLog().warn( - "skip file " + file + - " (no license footer tag found : '##%*' !)"); - failedFiles.add(file); - deleteFile(processFile); - return; + return false; + } + + FileHeaderProcessor processor = getProcessor(); + + // process file to detect header + + try { + processor.process(file, processFile); + } catch (IllegalStateException e) { + // could not obtain existing header + throw new InvalideFileHeaderException( + "Could not extract header on file " + file, e); + } catch (Exception e) { + if (e instanceof InvalideFileHeaderException) { + throw (InvalideFileHeaderException) e; } + throw new IOException("Could not process file " + file, e); + } - // file has no header dealed by the plugin - String content = PluginHelper.readAsString(file, getEncoding()); + if (processor.isTouched()) { - //check that file is not marked to be ignored - if (content.contains(getIgnoreTag())) { - getLog().info("ignore file (detected " + getIgnoreTag() + ") " + file); - - ignoreFiles.add(file); - deleteFile(processFile); - return; + if (isVerbose()) { + getLog().info("header was updated for " + file); } + if (processor.isModified()) { - // no header and not marked to be ignored : add a new header - getLog().info("adding license header on file " + file); + // header content has changed + // must copy back process file to file (if not dry run) - //FIXME-TC-20100409 form xml files must add header after a xml prolog line - content = processor.getFullHeaderContent() + "\n" + content; - if (!isDryRun()) { - writeFile(processFile, content, getEncoding()); + FileState.update.addFile(file, getResult()); + return true; + } - addedFiles.add(file); - finalizeFile(file, processFile); + FileState.uptodate.addFile(file, getResult()); + return false; + } - } catch (Exception e) { - getLog().warn( - "skip file " + file + " (could not process " + - "for reason : " + e.getMessage() + ")", e); - deleteFile(processFile); - } finally { + // header was not fully (or not at all) detected in file - // always clean processor internal states - processor.reset(); + if (processor.isDetectHeader()) { + + // file has not a valid header (found a start process atg, but + // not an ending one), can not do anything + throw new InvalideFileHeaderException( + "Could not find header end on file " + file); } - } - protected void reportType(Set<File> set, String operation, StringBuilder buffer) { - if (set.isEmpty()) { - if (isVerbose()) { - buffer.append("\n * no header to ").append(operation).append("."); - } - } else { - buffer.append("\n * ").append(operation).append(" header on "); - buffer.append(set.size()); - if (set.size() == 1) { - buffer.append(" file."); - } else { - buffer.append(" files."); - } - if (isVerbose()) { - for (File file : set) { - buffer.append("\n - ").append(file); - } - } + // no header at all, add a new header + + getLog().info("adding license header on file " + file); + + //FIXME-TC-20100409 form xml files must add header after a xml prolog line + content = getTransformer().addHeader( + getFilter().getFullHeaderContent(), + content + ); + + if (!isDryRun()) { + writeFile(processFile, content, getEncoding()); } + + FileState.add.addFile(file, getResult()); + return true; } protected void finalizeFile(File file, File processFile) throws IOException { @@ -505,6 +550,52 @@ } } + @Override + protected void finalize() throws Throwable { + super.finalize(); + clear(); + } + + protected void clear() { + Set<File> files = getProcessedFiles(); + if (files != null) { + files.clear(); + } + EnumMap<FileState, Set<File>> result = getResult(); + if (result != null) { + for (Set<File> fileSet : result.values()) { + fileSet.clear(); + } + result.clear(); + } + } + + protected void reportType(FileState state, StringBuilder buffer) { + String operation = state.name(); + + Set<File> set = getFiles(state); + if (set == null || set.isEmpty()) { + if (isVerbose()) { + buffer.append("\n * no header to "); + buffer.append(operation); + buffer.append("."); + } + return; + } + buffer.append("\n * ").append(operation).append(" header on "); + buffer.append(set.size()); + if (set.size() == 1) { + buffer.append(" file."); + } else { + buffer.append(" files."); + } + if (isVerbose()) { + for (File file : set) { + buffer.append("\n - ").append(file); + } + } + } + public boolean isClearAfterOperation() { return clearAfterOperation; } @@ -537,38 +628,48 @@ return dryRun; } + public UpdateFileHeaderFilter getFilter() { + return filter; + } + @Override - public boolean isSkip() { - return skipUpdateLicense; + public FileHeader getFileHeader() { + return header; } @Override - public void setSkip(boolean skipUpdateLicense) { - this.skipUpdateLicense = skipUpdateLicense; + public FileHeaderTransformer getTransformer() { + return transformer; } + @Override + public boolean isSkip() { + return skipUpdateLicense; + } + public Set<File> getProcessedFiles() { return processedFiles; } - public Set<File> getUpdatedFiles() { - return updatedFiles; + public EnumMap<FileState, Set<File>> getResult() { + return result; } - public Set<File> getAddedFiles() { - return addedFiles; + public Set<File> getFiles(FileState state) { + return result.get(state); } - public Set<File> getIgnoreFiles() { - return ignoreFiles; + public boolean isAddSvnKeyWords() { + return addSvnKeyWords; } - public Set<File> getFailedFiles() { - return failedFiles; + public FileHeaderProcessor getProcessor() { + return processor; } - public boolean isAddSvnKeyWords() { - return addSvnKeyWords; + @Override + public void setSkip(boolean skipUpdateLicense) { + this.skipUpdateLicense = skipUpdateLicense; } public void setDryRun(boolean dryRun) { @@ -611,91 +712,21 @@ this.clearAfterOperation = clearAfterOperation; } - public void setProcessedFiles(Set<File> processedFiles) { - this.processedFiles = processedFiles; + public void setTransformer(FileHeaderTransformer transformer) { + this.transformer = transformer; } - public void setUpdatedFiles(Set<File> updatedFiles) { - this.updatedFiles = updatedFiles; + public void setHeader(FileHeader header) { + this.header = header; } - public void setAddedFiles(Set<File> addedFiles) { - this.addedFiles = addedFiles; + public void setProcessor(FileHeaderProcessor processor) { + this.processor = processor; } - public void setIgnoreFiles(Set<File> ignoreFiles) { - this.ignoreFiles = ignoreFiles; + public void setFilter(UpdateFileHeaderFilter filter) { + this.filter = filter; } - public void setFailedFiles(Set<File> failedFiles) { - this.failedFiles = failedFiles; - } - public class UpdateLicenseHeaderFilter extends FileHeaderFilter { - - protected final boolean updateCopyright; - - public UpdateLicenseHeaderFilter(FileHeader header, - FileHeaderTransformer transformer, - boolean updateCopyright) { - super(header, transformer); - this.updateCopyright = updateCopyright; - } - - @Override - protected String treateHeader(FileHeader header, - FileHeaderTransformer transformer, - String ch) { - - if (getLog().isDebugEnabled()) { - getLog().debug("header\n" + ch); - } - - // unbox comment - String unbox = transformer.unboxComent(ch); - - if (getLog().isDebugEnabled()) { - getLog().info("unboxed comment header\n" + unbox); - } - - // obtain current license of file - FileHeader fileHeader = transformer.toFileHeader(unbox); - - // updates license - fileHeader.setLicense(header.getLicense()); - - if (updateCopyright) { - // 1) obtain the svn last comit on this file - - // 2) compute the last year of copyright - - // 3) if necessary update last year - //fileHeader.setCopyrightLastYear(lastYear); - } - // 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 process start tag - // remove all after process end tag - // this is a requirement for processor to respect involution. - int index = newHeader.indexOf(transformer.getProcessStartTag()); - int lastIndex = - newHeader.lastIndexOf(transformer.getProcessEndTag()) + - transformer.getProcessEndTag().length(); - - String result = newHeader.substring(index, lastIndex); - - if (getLog().isDebugEnabled()) { - getLog().debug("updated Header =\n" + result); - } - - return result; - } - } } 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-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderFilter.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -28,47 +28,78 @@ package org.nuiton.license.plugin.header; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.apache.maven.plugin.logging.Log; import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer; import org.nuiton.processor.filters.DefaultFilter; /** - * TODO + * File Header filter. * * @author tchemit <chemit@codelutin.com> * @since 2.1 */ public abstract class FileHeaderFilter extends DefaultFilter { - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private final Log log = LogFactory.getLog(FileHeaderFilter.class); - - /** flag pour indiquer si la licence a ete trouvee entre le header et le footer */ + /** + * flag set to {@code true} when a header was detected (says detects both + * start and end process tags). + */ protected boolean touched; - /** flag pour indiquer si on a rencontree le header du filtre */ + /** flag set to {@code true} when a header was detected and was modified. */ + protected boolean modified; + + /** flag set to {@code true} as soon as start process tag was detected. */ protected boolean detectHeader; - protected FileHeader header; + /** incoming default file header model */ + protected FileHeader fileHeader; + /** header transformer */ protected FileHeaderTransformer transformer; - protected abstract String treateHeader(FileHeader header, FileHeaderTransformer transformer, String ch); + /** cached header content */ + protected String headerContent; - public FileHeaderFilter(FileHeader header, FileHeaderTransformer transformer) { - this.header = header; - this.transformer = transformer; + /** cached full header content (with process tag + comment box) */ + protected String processTagHeaderContent; + + /** cached full header content (with process tag + comment box) */ + protected String fullHeaderContent; + + /** maven logger */ + protected Log log; + + /** + * The logic to implements when a header was touched. + * + * @param ch the actual header content + * @return the new header content (beginning by a + * {@link FileHeaderTransformer#getProcessStartTag()} and ending + * with a {@link FileHeaderTransformer#getProcessEndTag()}). + */ + protected abstract String treateHeader(String ch); + + public FileHeaderFilter() { } + public Log getLog() { + return log; + } + + public void setLog(Log log) { + this.log = log; + } + @Override protected String performInFilter(String ch) { if (log.isDebugEnabled()) { log.debug(ch); } - if (touched) { - // on autorise pas deux process de la licence dans un fichier java - throw new IllegalStateException("Can only have one file header start tag : " + getHeader()); + if (isTouched()) { + // Can NOT authorize two header in a same source + throw new IllegalStateException( + "Can only have one file header start tag : " + getHeader()); } if (getMatchIndexFor(ch, getHeader()) == NOT_FOUND) { @@ -76,12 +107,17 @@ touched = true; // update header - String newHeader = treateHeader(header, transformer, ch); + String newHeader = treateHeader(ch); + if (!ch.equals(newHeader)) { + + // header content was modified, mark it + modified = true; + } return newHeader; } - // ce cas arrive lorsque l'on a parcouru tout le fichier avec detection - // de la balise header mais sans balise footer - // et on arrive dans cette methode dans le flush du filter + // Means we detects the process start tag but not the end one. + // coming then here from the flush filter method... So changes nothing + // just return the text as it comes. return ch; } @@ -95,12 +131,12 @@ @Override protected String getHeader() { - return transformer.getProcessStartTag(); + return getTransformer().getProcessStartTag(); } @Override protected String getFooter() { - return transformer.getProcessEndTag(); + return getTransformer().getProcessEndTag(); } @Override @@ -112,17 +148,74 @@ } } + public String getHeaderContent() { + if (headerContent == null) { + headerContent = getTransformer().toString(getFileHeader()); + } + return headerContent; + } + + public String getProcessTagHeaderContent() { + if (processTagHeaderContent == null) { + + // box with process tag + processTagHeaderContent = + getTransformer().boxProcessTag(getHeaderContent()); + + } + return processTagHeaderContent; + } + + public String getFullHeaderContent() { + if (fullHeaderContent == null) { + + // box with comment + fullHeaderContent = getTransformer().boxComment( + getProcessTagHeaderContent(), + true + ); + } + return fullHeaderContent; + } + public boolean isTouched() { return touched; } + public boolean isModified() { + return modified; + } + public boolean isDetectHeader() { return detectHeader; } + public FileHeader getFileHeader() { + return fileHeader; + } + + public FileHeaderTransformer getTransformer() { + return transformer; + } + + public void setFileHeader(FileHeader fileHeader) { + this.fileHeader = fileHeader; + } + + public void setTransformer(FileHeaderTransformer transformer) { + this.transformer = transformer; + } + public void reset() { touched = false; + modified = false; detectHeader = false; state = State.SEARCH_HEADER; } + + public void resetContent() { + headerContent = null; + processTagHeaderContent = null; + fullHeaderContent = null; + } } 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-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessor.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -37,62 +37,62 @@ import java.io.IOException; /** - * TODO + * File header processor. * * @author tchemit <chemit@codelutin.com> + * @plexus.component role="org.nuiton.processor.Processor" role-hint="file-header" * @since 2.1 */ -public abstract class FileHeaderProcessor extends Processor { +public class FileHeaderProcessor extends Processor { - /** file header */ - protected FileHeader header; + /** processor configuration */ + protected FileHeaderProcessorConfiguration configuration; - protected FileHeaderTransformer transformer; - - /** internal filter */ + /** internal file header filter */ protected FileHeaderFilter filter; - /** cached header content */ - protected String headerContent; + public FileHeaderProcessor() { + } - /** cached full header content (with process tag + comment box) */ - protected String processTagHeaderContent; + public FileHeaderProcessorConfiguration getConfiguration() { + return configuration; + } - /** cached full header content (with process tag + comment box) */ - protected String fullHeaderContent; - - public abstract FileHeaderFilter newFilter(FileHeader header, FileHeaderTransformer transformer); - - public FileHeaderProcessor() { + public FileHeaderFilter getFilter() { + return filter; } /** - * @return {@code true} if processed file was modified (says the header was - * fully found and updating), {@code false} otherwise + * @return {@code true} if processed file was touched (says the header was + * fully found), {@code false} otherwise * @see FileHeaderFilter#isTouched() */ public boolean isTouched() { - return filter != null && filter.isTouched(); + return getFilter() != null && getFilter().isTouched(); } /** + * @return {@code true} if processed file was modified (says the header was + * fully found and content changed), {@code false} otherwise + * @see FileHeaderFilter#isModified() + */ + public boolean isModified() { + return getFilter() != null && getFilter().isModified(); + } + + /** * @return {@code true} if header of header was detected * @see FileHeaderFilter#isDetectHeader() */ public boolean isDetectHeader() { - return filter != null && filter.isDetectHeader(); + return getFilter() != null && getFilter().isDetectHeader(); } public void process(File filein, File fileout) throws IOException, IllegalStateException { - if (header == null) { - throw new IllegalStateException("no file header sets."); - } - if (transformer == null) { - throw new IllegalStateException("no file header transformer sets."); - } - if (filter == null) { - setFilter(newFilter(header, transformer)); - } + + checkInit(); + reset(); + FileReader input = new FileReader(filein); try { FileWriter output = new FileWriter(fileout); @@ -106,69 +106,69 @@ } } - public String getHeaderContent() { - if (headerContent == null) { - headerContent = transformer.toString(header); - } - return headerContent; - } + public void populateFilter() { + FileHeader fileHeader = getConfiguration().getFileHeader(); + boolean change = false; - public String getProcessTagHeaderContent() { - if (processTagHeaderContent == null) { + FileHeaderFilter filter = getFilter(); - // box with process tag - processTagHeaderContent = - transformer.boxProcessTag(getHeaderContent()); + if (!fileHeader.equals(filter.getFileHeader())) { + // change file header + + filter.setFileHeader(fileHeader); + change = true; } - return processTagHeaderContent; - } + FileHeaderTransformer transformer = getConfiguration().getTransformer(); + if (!transformer.equals(filter.getTransformer())) { - public String getFullHeaderContent() { - if (fullHeaderContent == null) { + // change file transformer - // box with comment - fullHeaderContent = - transformer.boxComment(getProcessTagHeaderContent(), true); + filter.setTransformer(transformer); + change = true; } - return fullHeaderContent; - } + if (change) { -// public FileHeader getHeader() { -// return header; -// } -// -// public FileHeaderTransformer getTransformer() { -// return transformer; -// } - - public void setHeader(FileHeader header) { - this.header = header; - reset(); + // something has changed, must reset content cache + filter.resetContent(); + } } - public void setTransformer(FileHeaderTransformer transformer) { - this.transformer = transformer; - reset(); + public void setConfiguration(FileHeaderProcessorConfiguration configuration) { + this.configuration = configuration; } -// -// protected FileHeaderFilter getFilter() { -// return filter; -// } public void setFilter(FileHeaderFilter filter) { this.filter = filter; setInputFilter(filter); } - public void reset() { if (filter != null) { filter.reset(); - filter = null; } - headerContent = null; - processTagHeaderContent = null; - fullHeaderContent = null; } + + protected FileHeader getFileHeader() { + return getConfiguration().getFileHeader(); + } + + protected FileHeaderTransformer getTransformer() { + return getConfiguration().getTransformer(); + } + + protected void checkInit() throws IllegalStateException { + if (getConfiguration() == null) { + throw new IllegalStateException("no configuration set."); + } + if (getFileHeader() == null) { + throw new IllegalStateException("no file header set."); + } + if (getTransformer() == null) { + throw new IllegalStateException("no file header transformer set."); + } + if (getFilter() == null) { + throw new IllegalStateException("no file header filter set."); + } + } } Added: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessorConfiguration.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessorConfiguration.java (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessorConfiguration.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -0,0 +1,51 @@ +/* + * #%L + * Maven License Plugin + * + * $Author$ + * $LastChangedDate$ + * $LastChangedRevision$ + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.license.plugin.header; + +import org.apache.maven.plugin.logging.Log; +import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer; + +/** + * Contract of required configuration of the {@link FileHeaderProcessor}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +public interface FileHeaderProcessorConfiguration { + + /** @return mojo logger */ + Log getLog(); + + /** @return the current file header to use */ + FileHeader getFileHeader(); + + /** @return the current file transformer to use */ + FileHeaderTransformer getTransformer(); + +} Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/FileHeaderProcessorConfiguration.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/license/plugin/header/InvalideFileHeaderException.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/InvalideFileHeaderException.java (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/header/InvalideFileHeaderException.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -0,0 +1,57 @@ +/* + * #%L + * Maven License Plugin + * + * $Author$ + * $LastChangedDate$ + * $LastChangedRevision$ + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.license.plugin.header; + +import java.io.IOException; + +/** + * Exception to be thrown when a file header could not be read or transformed + * back to a {@link FileHeader} + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +public class InvalideFileHeaderException extends IOException { + private static final long serialVersionUID = 1L; + + public InvalideFileHeaderException() { + } + + public InvalideFileHeaderException(String message) { + super(message); + } + + public InvalideFileHeaderException(String message, Throwable cause) { + super(message, cause); + } + + public InvalideFileHeaderException(Throwable cause) { + super(cause); + } +} Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/InvalideFileHeaderException.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/license/plugin/header/UpdateFileHeaderFilter.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/UpdateFileHeaderFilter.java (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/header/UpdateFileHeaderFilter.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -0,0 +1,109 @@ +/* + * #%L + * Maven License Plugin + * + * $Author$ + * $LastChangedDate$ + * $LastChangedRevision$ + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.license.plugin.header; + +import org.nuiton.license.plugin.header.transformer.FileHeaderTransformer; + +/** + * Implementation of {@link FileHeaderFilter} to update an incoming header. + * + * @author tchemit <chemit@codelutin.com> + * @plexus.component role="org.nuiton.license.plugin.header.FileHeaderFilter" role-hint="update-file-header" + * @since 2.1 + */ +public class UpdateFileHeaderFilter extends FileHeaderFilter { + + protected boolean updateCopyright; + + public UpdateFileHeaderFilter() { + } + + @Override + protected String treateHeader(String ch) { + + if (getLog().isDebugEnabled()) { + getLog().debug("header\n" + ch); + } + + FileHeaderTransformer transformer = getTransformer(); + + // unbox comment + String unbox = transformer.unboxComent(ch); + + if (getLog().isDebugEnabled()) { + getLog().info("unboxed comment header\n" + unbox); + } + + // obtain current license of file + FileHeader fileHeader = transformer.toFileHeader(unbox); + + // updates license + fileHeader.setLicense(getFileHeader().getLicense()); + + if (isUpdateCopyright()) { + // 1) obtain the svn last comit on this file + + // 2) compute the last year of copyright + + // 3) if necessary update last year + //fileHeader.setCopyrightLastYear(lastYear); + } + // 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 process start tag + // remove all after process end tag + // this is a requirement for processor to respect involution. + int index = newHeader.indexOf(transformer.getProcessStartTag()); + int lastIndex = + newHeader.lastIndexOf(transformer.getProcessEndTag()) + + transformer.getProcessEndTag().length(); + + String result = newHeader.substring(index, lastIndex); + + if (getLog().isDebugEnabled()) { + getLog().debug("updated Header =\n" + result); + } + return result; + } + + public boolean isUpdateCopyright() { + return updateCopyright; + } + + public void setUpdateCopyright(boolean updateCopyright) { + this.updateCopyright = updateCopyright; + } +} Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/UpdateFileHeaderFilter.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/license/plugin/header/generator/package.html =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/package.html (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/package.html 2010-04-12 11:01:09 UTC (rev 1737) @@ -0,0 +1,11 @@ +<html> +<body> +<h1>Header generator package</h1> + +<p> + This package contains the old and <b>deprecated</b> api (since 2.1) of the + file header generator. +</p> + +</body> +</html> Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/generator/package.html ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/license/plugin/header/package.html =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/package.html (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/header/package.html 2010-04-12 11:01:09 UTC (rev 1737) @@ -0,0 +1,13 @@ +<html> +<body> +<h1>Header package</h1> + +<p> + This package contains the api of the file header. +</p> + +<p> + <b>Note:</b> The generator package is deprecated since 2.1. +</p> +</body> +</html> Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/package.html ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL 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-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/AbstractFileHeaderTransformer.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -181,6 +181,11 @@ } @Override + public String addHeader(String header, String content) { + return header + content; + } + + @Override public void setCommentLinePrefix(String commentLinePrefix) { this.commentLinePrefix = commentLinePrefix; } @@ -222,7 +227,10 @@ } @Override - public String toString(FileHeader model) { + public String toString(FileHeader model) throws NullPointerException { + if (model == null) { + throw new NullPointerException("model can not be null!"); + } StringBuilder buffer = new StringBuilder(); String sectionDelimiter = LINE_SEPARATOR + getSectionDelimiter() + 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-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/FileHeaderTransformer.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -115,6 +115,15 @@ String getCommentLinePrefix(); /** + * Adds the header. + * + * @param header header to add + * @param content content of original file + * @return the new full file content beginning with header + */ + String addHeader(String header, String content); + + /** * Box the given {@code header} in a comment. * * @param header the header content WITHOUT any comment boxing @@ -165,8 +174,9 @@ * * @param model the model of the file header * @return the UNBOXED header content + * @throws NullPointerException if model is null */ - String toString(FileHeader model); + String toString(FileHeader model) throws NullPointerException; /** * Changes the name of the transformer. Modified: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/XmlFileHeaderTransformer.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -39,7 +39,8 @@ public static final String NAME = "xml"; - public static final String DESCRIPTION = "header transformer with xml comment style"; + public static final String DESCRIPTION = + "header transformer with xml comment style"; public static final String COMMENT_LINE_PREFIX = " "; @@ -55,4 +56,36 @@ COMMENT_LINE_PREFIX ); } -} + + @Override + public String addHeader(String header, String content) { + + String result; + + String prolog = null; + int startProlog = content.indexOf("<?xml"); + if (startProlog > -1) { + + // prolog start was detected + int endProlog = content.indexOf("?>", startProlog); + + if (endProlog > -1) { + + // prolog end was detected + prolog = content.substring(0, endProlog + 2); + } + } + + if (prolog == null) { + + // no prolog detected + result = super.addHeader(header, content); + } else { + + // prolog detected + content = content.substring(prolog.length()); + result = super.addHeader(prolog + '\n'+ header, content); + } + return result; + } +} \ No newline at end of file Added: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/package.html =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/transformer/package.html (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/header/transformer/package.html 2010-04-12 11:01:09 UTC (rev 1737) @@ -0,0 +1,10 @@ +<html> +<body> +<h1>Header transformer package</h1> + +<p> + This package contains the api of the file header transformer. +</p> + +</body> +</html> Property changes on: trunk/src/main/java/org/nuiton/license/plugin/header/transformer/package.html ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/license/plugin/model/descriptor/package.html =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/model/descriptor/package.html (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/model/descriptor/package.html 2010-04-12 11:01:09 UTC (rev 1737) @@ -0,0 +1,6 @@ +<html> +<body> +<h1>Descriptor Model package</h1> +This package contains the api of the license project descriptor. +</body> +</html> Property changes on: trunk/src/main/java/org/nuiton/license/plugin/model/descriptor/package.html ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/license/plugin/model/package.html =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/model/package.html (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/model/package.html 2010-04-12 11:01:09 UTC (rev 1737) @@ -0,0 +1,10 @@ +<html> +<body> +<h1>Model package</h1> +This package contains all models of the project. +<ul> + <li>LicenceProjectDescriptor api (generated by modello)</li> + <li>License api </li> +</ul> +</body> +</html> Property changes on: trunk/src/main/java/org/nuiton/license/plugin/model/package.html ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/license/plugin/package.html =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/package.html (rev 0) +++ trunk/src/main/java/org/nuiton/license/plugin/package.html 2010-04-12 11:01:09 UTC (rev 1737) @@ -0,0 +1,6 @@ +<html> +<body> +<h1>Maven license plugin</h1> +Base package of the plugin containing all mojos. +</body> +</html> Property changes on: trunk/src/main/java/org/nuiton/license/plugin/package.html ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/src/main/mdo/descriptor.mdo =================================================================== --- trunk/src/main/mdo/descriptor.mdo 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/mdo/descriptor.mdo 2010-04-12 11:01:09 UTC (rev 1737) @@ -28,38 +28,41 @@ <model xsd.namespace="http://maven-site.nuiton.org/maven-license-plugin/1.0.0" xsd.targetNamespace="http://maven-site.nuiton.org/maven-license-plugin/1.0.0"> - <id>licenseProject</id> - <name>LicenseProject</name> + <id>licenseProjectDescriptor</id> + <name>LicenseProjectDescriptor</name> <description> <![CDATA[ <p> Maven License Plugin relies on the provided project descriptors to dictate - its execution. Although there are already prefabricated descriptors available + its execution. + </p> + <p> + TODO : Although there are already prefabricated descriptors available for use, they can only suffice some of the common license requirements. </p> <p> So in order for you to customize the way the License Plugin updates your licenses, you need to know how to use the License project Descriptor. </p> - <p> - This descriptor specifies the type of licenses to apply for some defined - filesets. - </p> ]]> </description> <defaults> <default> <key>package</key> - <value>org.nuiton.license.plugin.model.project</value> + <value>org.nuiton.license.plugin.model.descriptor</value> </default> </defaults> <classes> <class rootElement="true" xml.tagName="project"> - <name>LicenseProject</name> + <name>LicenseProjectDescriptor</name> <description> <![CDATA[ - An license project defines a collection of files to be reacted by the - plugin (says update header). + The license project descriptor describe licenses used in a project. + <p/> + <ul> + <li>mainLicense of the project</li> + <li>headers to update (or add) on sources of the project</li> + </ul> ]]> </description> <version>1.0.0+</version> @@ -77,27 +80,45 @@ </description> </field> <field> - <name>licenseSets</name> + <name>headers</name> <version>1.0.0+</version> <association> - <type>LicenseSet</type> + <type>Header</type> <multiplicity>*</multiplicity> </association> <description> <![CDATA[ - Specifies licenses to apply on a project. A licenseSet is specified - by providing one or more of <licenseSet> subelements. + Collection of header. + + {@link Header} ]]> </description> </field> + <field> + <name>header</name> + <version>1.0.0+</version> + <association> + <type>Header</type> + <multiplicity>1</multiplicity> + </association> + <description> + <![CDATA[ + To add a single header. + + {@link Header} + ]]> + </description> + </field> </fields> </class> <class> - <name>LicenseSet</name> + <name>Header</name> <description> <![CDATA[ - A licenseSet represents one license to apply to one or more filesets. + A Header represents a set of resources using the same {@code header type}. + <p/> + The licenseName can be inherited by the mainLicense of the project. ]]> </description> <version>1.0.0+</version> @@ -115,6 +136,17 @@ </description> </field> <field> + <name>commentStyle</name> + <version>1.0.0+</version> + <type>String</type> + <required>true</required> + <description> + <![CDATA[ + The style of the comment which box the header to generate (or updates). + ]]> + </description> + </field> + <field> <name>fileSets</name> <version>1.0.0+</version> <association> @@ -128,6 +160,20 @@ ]]> </description> </field> + <field> + <name>fileSet</name> + <version>1.0.0+</version> + <association> + <type>FileSet</type> + <multiplicity>1</multiplicity> + </association> + <description> + <![CDATA[ + Specifies a single file sets to include in the license set. A fileSet is + specified by providing one or more of <licenseSet> subelements. + ]]> + </description> + </field> </fields> </class> @@ -142,14 +188,6 @@ </description> <fields> <field> - <name>headerType</name> - <version>1.0.0+</version> - <type>String</type> - <required>true</required> - <description>The type of header to generate (or updates). - </description> - </field> - <field> <name>useDefaultExcludes</name> <version>1.0.0+</version> <type>boolean</type> @@ -188,6 +226,24 @@ </description> </field> <field> + <name>include</name> + <version>1.0.0+</version> + <type>String</type> + <!--<association>--> + <!--<multiplicity>1</multiplicity>--> + <!--</association>--> + <description> + <![CDATA[ + <p> + To add a single include. + </p> + When <include> subelements are present, they define a set of + files and directory to include. If none is present, then + <includes> represents all valid values. + ]]> + </description> + </field> + <field> <name>excludes</name> <version>1.0.0+</version> <association> @@ -203,6 +259,24 @@ </description> </field> <field> + <name>exclude</name> + <version>1.0.0+</version> + <type>String</type> + <!--<association>--> + <!--<multiplicity>1</multiplicity>--> + <!--</association>--> + <description> + <![CDATA[ + <p> + To add a single exclude. + </p> + When <exclude> subelements are present, they define a set of + files and directory to exclude. If none is present, then + <excludes> represents no exclusions. + ]]> + </description> + </field> + <field> <name>lineEnding</name> <version>1.0.0+</version> <type>String</type> Modified: trunk/src/main/resources/META-INF/licenses/gpl_v1/header.txt =================================================================== --- trunk/src/main/resources/META-INF/licenses/gpl_v1/header.txt 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/resources/META-INF/licenses/gpl_v1/header.txt 2010-04-12 11:01:09 UTC (rev 1737) @@ -6,7 +6,7 @@ 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. +GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see Modified: trunk/src/main/resources/META-INF/licenses/gpl_v2/header.txt =================================================================== --- trunk/src/main/resources/META-INF/licenses/gpl_v2/header.txt 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/resources/META-INF/licenses/gpl_v2/header.txt 2010-04-12 11:01:09 UTC (rev 1737) @@ -6,7 +6,7 @@ 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. +GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see Modified: trunk/src/main/resources/META-INF/licenses/gpl_v3/header.txt =================================================================== --- trunk/src/main/resources/META-INF/licenses/gpl_v3/header.txt 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/resources/META-INF/licenses/gpl_v3/header.txt 2010-04-12 11:01:09 UTC (rev 1737) @@ -6,7 +6,7 @@ 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. +GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see Modified: trunk/src/main/resources/META-INF/licenses/licenses.properties =================================================================== --- trunk/src/main/resources/META-INF/licenses/licenses.properties 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/main/resources/META-INF/licenses/licenses.properties 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,10 +1,10 @@ -agpl_v3=GNU Affero General Public License version 3.0 -apache_v2=License Apache version 3.0 +agpl_v3=GNU Affero General Public License (AGPL) version 3.0 +apache_v2=Apache License version 2.0 cddl_v1=COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 -fdl_v1_3=Free Documentation License Version 1.3 -gpl_v1=License gpl version 1.0 -gpl_v2=License gpl version 2.0 -gpl_v3=License gpl version 3.0 -lgpl_v2_1=License lgpl version 2.1 -lgpl_v3=License lgpl version 3.0 +fdl_v1_3=GNU Free Documentation License (FDL) version 1.3 +gpl_v1=GNU General Public License (GPL) version 1.0 +gpl_v2=GNU General Public License (GPL) version 2.0 +gpl_v3=GNU General Public License (GPL) version 3.0 +lgpl_v2_1=GNU General Lesser Public License (LGPL) version 2.1 +lgpl_v3=GNU General Lesser Public License (LGPL) version 3.0 mit=MIT-License Modified: trunk/src/site/rst/descriptor.rst =================================================================== --- trunk/src/site/rst/descriptor.rst 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/site/rst/descriptor.rst 2010-04-12 11:01:09 UTC (rev 1737) @@ -13,7 +13,7 @@ .. - .. * #%L .. * Maven License Plugin -.. * +.. * .. * .. * $Author$ .. * $LastChangedDate$ .. * $LastChangedRevision$ @@ -23,16 +23,16 @@ .. * Copyright (C) 2008 - 2010 CodeLutin .. * %% .. * This program is free software: you can redistribute it and/or modify -.. * it under the terms of the GNU Lesser General Public License as -.. * published by the Free Software Foundation, either version 3 of the +.. * 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 +.. * +.. * You should have received a copy of the GNU General Lesser Public .. * License along with this program. If not, see .. * <http://www.gnu.org/licenses/lgpl-3.0.html>. .. * #L% @@ -65,21 +65,22 @@ <?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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>gpl_v3</mainLicense> - <licenseSets> - <licenseSet> + <headers> + <header> + <licenseName>lgpl_v3</licenseName> + <commentStyle>java</commentStyle> <fileSets> <fileSet> - <headerType>java</headerType> - <basedir>src/main/java</basedir> + <basedir>all/src</basedir> <includes> <include>**/*.java</include> </includes> </fileSet> </fileSets> - </licenseSet> - </licenseSets> + </header> + </headers> </project> .. _update-file-header: update-file-header-mojo.html @@ -88,4 +89,4 @@ .. _comment-style-list: comment-style-list-mojo.html -.. _xsd file: licenseProject-1.0.0.xsd +.. _xsd file: licenseProjectDescriptor-1.0.0.xsd Modified: trunk/src/site/rst/header.rst =================================================================== --- trunk/src/site/rst/header.rst 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/site/rst/header.rst 2010-04-12 11:01:09 UTC (rev 1737) @@ -13,7 +13,7 @@ .. - .. * #%L .. * Maven License Plugin -.. * +.. * .. * .. * $Author$ .. * $LastChangedDate$ .. * $LastChangedRevision$ @@ -23,16 +23,16 @@ .. * Copyright (C) 2008 - 2010 CodeLutin .. * %% .. * This program is free software: you can redistribute it and/or modify -.. * it under the terms of the GNU Lesser General Public License as -.. * published by the Free Software Foundation, either version 3 of the +.. * 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 +.. * +.. * You should have received a copy of the GNU General Lesser Public .. * License along with this program. If not, see .. * <http://www.gnu.org/licenses/lgpl-3.0.html>. .. * #L% @@ -55,21 +55,21 @@ :: - (1) #\%\L + (1) # % L (2) Project description - (3) -- + (3) %% (4) Copyright (C) 2010 your organization - (5) -- + (5) %% (6) License content - (7) \#\L\% + (7) # L % - * (1) the start process tag used to detect begin of header (NEVER suppress it). - * (2) Project description section - * (3) Header section delimiter - * (4) Copyright section of the file (see next section for detail) - * (5) Header section delimiter - * (6) License section - * (7) the end process tag used to detect end of header (NEVER suppress it). +* (1) the start process tag used to detect begin of header (NEVER suppress it). +* (2) Project description section +* (3) Header section delimiter +* (4) Copyright section of the file (see next section for detail) +* (5) Header section delimiter +* (6) License section +* (7) the end process tag used to detect end of header (NEVER suppress it). Configuration ------------- @@ -86,6 +86,7 @@ Copyright section must exactly be of this form : :: + Copyright (C) firstYear[ - lastYear] holder If *firstYear* and *lastYear* are the same then lastYear is omitted. @@ -107,6 +108,7 @@ ---------- :: + /* * HEADER */ @@ -115,6 +117,7 @@ --------- :: + <!-- HEADER --> @@ -123,6 +126,7 @@ ---------------- :: + ###### # HEADER ###### @@ -131,6 +135,7 @@ --------- :: + ~~~~~~ ~~ HEADER ~~~~~~ @@ -139,10 +144,11 @@ --------- :: - .. - .. HEADER - .. + .. - + .. * HEADER + .. - + Ignore a header =============== Modified: trunk/src/site/rst/index.rst =================================================================== --- trunk/src/site/rst/index.rst 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/site/rst/index.rst 2010-04-12 11:01:09 UTC (rev 1737) @@ -13,7 +13,7 @@ .. - .. * #%L .. * Maven License Plugin -.. * +.. * .. * .. * $Author$ .. * $LastChangedDate$ .. * $LastChangedRevision$ @@ -23,16 +23,16 @@ .. * Copyright (C) 2008 - 2010 CodeLutin .. * %% .. * This program is free software: you can redistribute it and/or modify -.. * it under the terms of the GNU Lesser General Public License as -.. * published by the Free Software Foundation, either version 3 of the +.. * 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 +.. * +.. * You should have received a copy of the GNU General Lesser Public .. * License along with this program. If not, see .. * <http://www.gnu.org/licenses/lgpl-3.0.html>. .. * #L% @@ -71,9 +71,9 @@ /* * # % L * 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 Modified: trunk/src/site/rst/usage.rst =================================================================== --- trunk/src/site/rst/usage.rst 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/site/rst/usage.rst 2010-04-12 11:01:09 UTC (rev 1737) @@ -12,7 +12,7 @@ .. - .. * #%L .. * Maven License Plugin -.. * +.. * .. * .. * $Author$ .. * $LastChangedDate$ .. * $LastChangedRevision$ @@ -22,16 +22,16 @@ .. * Copyright (C) 2008 - 2010 CodeLutin .. * %% .. * This program is free software: you can redistribute it and/or modify -.. * it under the terms of the GNU Lesser General Public License as -.. * published by the Free Software Foundation, either version 3 of the +.. * 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 +.. * +.. * You should have received a copy of the GNU General Lesser Public .. * License along with this program. If not, see .. * <http://www.gnu.org/licenses/lgpl-3.0.html>. .. * #L% @@ -88,6 +88,24 @@ for full detail see `license-list`_ detail page. +Example of execution +++++++++++++++++++++ + +:: + [INFO] [license:license-list {execution: default-cli}] + [INFO] Available licenses : + + * agpl_v3 : GNU Affero General Public License (AGPL) version 3.0 + * apache_v2 : Apache License version 2.0 + * cddl_v1 : COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + * fdl_v1_3 : GNU Free Documentation License (FDL) version 1.3 + * gpl_v1 : GNU General Public License (GPL) version 1.0 + * gpl_v2 : GNU General Public License (GPL) version 2.0 + * gpl_v3 : GNU General Public License (GPL) version 3.0 + * lgpl_v2_1 : GNU General Lesser Public License (LGPL) version 2.1 + * lgpl_v3 : GNU General Lesser Public License (LGPL) version 3.0 + * mit : MIT-License + comment-style-list goal _______________________ @@ -107,6 +125,19 @@ for full detail see `comment-style-list`_ detail page. +Example of execution +++++++++++++++++++++ + +:: + [INFO] [license:comment-style-list {execution: default-cli}] + [INFO] List of available comment styles: + + - apt : header transformer with apt comment style + - java : header transformer with java comment style + - properties : header transformer with properties file comment style + - rst : header transformer with rst comment style + - xml : header transformer with xml comment style + help goal _________ Modified: trunk/src/test/java/org/nuiton/license/plugin/UpdateFileHeaderMojoTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/plugin/UpdateFileHeaderMojoTest.java 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/test/java/org/nuiton/license/plugin/UpdateFileHeaderMojoTest.java 2010-04-12 11:01:09 UTC (rev 1737) @@ -34,7 +34,10 @@ import org.nuiton.plugin.PluginHelper; import java.io.File; +import java.util.Set; +import static org.nuiton.license.plugin.UpdateFileHeaderMojo.FileState; + /** * Tests the {@link UpdateFileHeaderMojo}. * @@ -43,6 +46,19 @@ */ public class UpdateFileHeaderMojoTest extends AbstractMojoTest<UpdateFileHeaderMojo> { + + private Set<File> uptodates; + + private Set<File> updates; + + private Set<File> adds; + + private Set<File> fails; + + private Set<File> ignores; + + private Set<File> process; + @Override protected String getGoalName(String methodName) { return "update-file-header"; @@ -68,10 +84,15 @@ // checkPattern(f, content, "Project name : maven-license-plugin-java", false); // checkPattern(f, content, "Organization is CodeLutin", false); - mojo.setVerbose(true); - mojo.execute(); - Assert.assertEquals(1, mojo.getProcessedFiles().size()); + execute(true, mojo); + Assert.assertEquals(1, process.size()); + if (updates == null) { + Assert.assertEquals(1, adds.size()); + } else { + Assert.assertEquals(1, updates.size()); + Assert.assertNull(adds); + } content = PluginHelper.readAsString(f, mojo.getEncoding()); // check header @@ -79,11 +100,10 @@ checkPattern(f, content, "Project name : maven-license-plugin-java", true); checkPattern(f, content, "Organization is CodeLutin", true); - mojo.setVerbose(false); - mojo.execute(); + execute(false, mojo); - Assert.assertEquals(1, mojo.getProcessedFiles().size()); - Assert.assertEquals(1, mojo.getUpdatedFiles().size()); + Assert.assertEquals(1, process.size()); + Assert.assertEquals(1, updates.size()); int oldLength = content.length(); content = PluginHelper.readAsString(f, mojo.getEncoding()); @@ -92,44 +112,51 @@ Assert.assertEquals(oldLength, newLength); } +// @Ignore + @Test public void all() throws Exception { UpdateFileHeaderMojo mojo = getMojo(); mojo.setClearAfterOperation(false); - mojo.setVerbose(true); - mojo.execute(); - Assert.assertEquals(4, mojo.getProcessedFiles().size()); - if (mojo.getUpdatedFiles().size() == 2) { - Assert.assertEquals(2, mojo.getUpdatedFiles().size()); - Assert.assertEquals(0, mojo.getAddedFiles().size()); + execute(true, mojo); + Assert.assertEquals(4, process.size()); + + if (updates.size() < 2) { + // first invocation + Assert.assertEquals(1, updates.size()); + Assert.assertEquals(1, adds.size()); + Assert.assertNull(uptodates); } else { - Assert.assertEquals(1, mojo.getUpdatedFiles().size()); - Assert.assertEquals(1, mojo.getAddedFiles().size()); + Assert.assertEquals(2, updates.size()); + Assert.assertNull(uptodates); + Assert.assertNull(adds); } - Assert.assertEquals(1, mojo.getFailedFiles().size()); - Assert.assertEquals(1, mojo.getIgnoreFiles().size()); + Assert.assertEquals(1, fails.size()); + Assert.assertEquals(1, ignores.size()); - mojo.setVerbose(false); - mojo.execute(); + execute(false, mojo); - Assert.assertEquals(4, mojo.getProcessedFiles().size()); - Assert.assertEquals(2, mojo.getUpdatedFiles().size()); - Assert.assertEquals(0, mojo.getAddedFiles().size()); - Assert.assertEquals(1, mojo.getFailedFiles().size()); - Assert.assertEquals(1, mojo.getIgnoreFiles().size()); + Assert.assertEquals(4, process.size()); + Assert.assertNull(uptodates); +// Assert.assertEquals(2, uptodates.size()); + Assert.assertEquals(2, updates.size()); + Assert.assertNull(adds); + Assert.assertEquals(1, fails.size()); + Assert.assertEquals(1, ignores.size()); mojo.setClearAfterOperation(true); mojo.execute(); - Assert.assertEquals(0, mojo.getProcessedFiles().size()); - Assert.assertEquals(0, mojo.getUpdatedFiles().size()); - Assert.assertEquals(0, mojo.getAddedFiles().size()); - Assert.assertEquals(0, mojo.getFailedFiles().size()); - Assert.assertEquals(0, mojo.getIgnoreFiles().size()); + Assert.assertEquals(0, process.size()); + for (FileState state : FileState.values()) { + Assert.assertNull(mojo.getFiles(state)); + } } +// @Ignore + @Test public void updateLicense() throws Exception { @@ -146,11 +173,17 @@ checkPattern(f, content, "License Test :: do NOT update!", true); // checkPattern(f, content, "Fake to be removed!", true); - mojo.setVerbose(true); - mojo.execute(); - Assert.assertEquals(1, mojo.getProcessedFiles().size()); - Assert.assertEquals(1, mojo.getUpdatedFiles().size()); + execute(true, mojo); + Assert.assertEquals(1, process.size()); + if (uptodates != null) { + + Assert.assertEquals(1, uptodates.size()); + Assert.assertNull(updates); + } else { + Assert.assertNull(uptodates); + Assert.assertEquals(1, updates.size()); + } content = PluginHelper.readAsString(f, mojo.getEncoding()); // check header (description + copyright) does not changed @@ -160,11 +193,13 @@ // check license changed checkPattern(f, content, "Fake to be removed!", false); - mojo.setVerbose(false); - mojo.execute(); + execute(false, mojo); - Assert.assertEquals(1, mojo.getProcessedFiles().size()); - Assert.assertEquals(1, mojo.getUpdatedFiles().size()); + Assert.assertEquals(1, process.size()); + Assert.assertNull(uptodates); + Assert.assertEquals(1, updates.size()); +// Assert.assertEquals(1, uptodates.size()); +// Assert.assertNull(updates); int oldLength = content.length(); content = PluginHelper.readAsString(f, mojo.getEncoding()); @@ -173,6 +208,7 @@ Assert.assertEquals(oldLength, newLength); } +// @Ignore @Test public void failLicense() throws Exception { @@ -191,12 +227,10 @@ checkPattern(f, content, "License content do NOT update!", true); // checkPattern(f, content, "Fake to be removed!", true); - mojo.setVerbose(true); - mojo.execute(); + execute(true, mojo); + Assert.assertEquals(1, process.size()); + Assert.assertEquals(1, fails.size()); - Assert.assertEquals(1, mojo.getProcessedFiles().size()); - Assert.assertEquals(1, mojo.getFailedFiles().size()); - content = PluginHelper.readAsString(f, mojo.getEncoding()); // check header does not changed @@ -204,13 +238,10 @@ checkPattern(f, content, "License Test :: do NOT update!", true); checkPattern(f, content, "License content do NOT update!", true); - mojo.setVerbose(false); - mojo.execute(); + execute(false, mojo); + Assert.assertEquals(1, process.size()); + Assert.assertEquals(1, fails.size()); - Assert.assertEquals(1, mojo.getProcessedFiles().size()); - Assert.assertEquals(1, mojo.getFailedFiles().size()); - - content = PluginHelper.readAsString(f, mojo.getEncoding()); // check header does not changed @@ -219,6 +250,9 @@ checkPattern(f, content, "License content do NOT update!", true); } + +// @Ignore + @Test public void ignoreLicense() throws Exception { @@ -236,11 +270,10 @@ checkPattern(f, content, "yet another license", true); checkPattern(f, content, "NEVER_FINd_ME!", false); - mojo.setVerbose(true); - mojo.execute(); + execute(true, mojo); - Assert.assertEquals(1, mojo.getProcessedFiles().size()); - Assert.assertEquals(1, mojo.getIgnoreFiles().size()); + Assert.assertEquals(1, process.size()); + Assert.assertEquals(1, ignores.size()); content = PluginHelper.readAsString(f, mojo.getEncoding()); @@ -250,13 +283,11 @@ checkPattern(f, content, "yet another license", true); checkPattern(f, content, "NEVER_FINd_ME!", false); - mojo.setVerbose(false); - mojo.execute(); + execute(false, mojo); - Assert.assertEquals(1, mojo.getProcessedFiles().size()); - Assert.assertEquals(1, mojo.getIgnoreFiles().size()); + Assert.assertEquals(1, process.size()); + Assert.assertEquals(1, ignores.size()); - content = PluginHelper.readAsString(f, mojo.getEncoding()); // check header (description + copyright) does not changed @@ -266,6 +297,8 @@ checkPattern(f, content, "NEVER_FINd_ME!", false); } +// @Ignore + @Test public void skip() throws Exception { @@ -274,6 +307,19 @@ Assert.assertTrue(mojo.isSkip()); } + protected void execute(boolean verbose, + UpdateFileHeaderMojo mojo) throws Exception { + mojo.setVerbose(verbose); + mojo.execute(); + + process = mojo.getProcessedFiles(); + uptodates = mojo.getFiles(FileState.uptodate); + updates = mojo.getFiles(FileState.update); + adds = mojo.getFiles(FileState.add); + fails = mojo.getFiles(FileState.fail); + ignores = mojo.getFiles(FileState.ignore); + } + protected File getMyBeanFile(String testName) { File f = PluginHelper.getFile(getBasedir(), "target", Modified: trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/addLicense/project.xml =================================================================== --- trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/addLicense/project.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/addLicense/project.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,20 +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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>gpl_v3</mainLicense> - <licenseSets> - <licenseSet> + <headers> + <header> <licenseName>lgpl_v3</licenseName> + <commentStyle>java</commentStyle> <fileSets> <fileSet> - <headerType>java</headerType> <basedir>addLicense/src</basedir> <includes> <include>**/*.java</include> </includes> </fileSet> </fileSets> - </licenseSet> - </licenseSets> + </header> + </headers> </project> Modified: trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/all/project.xml =================================================================== --- trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/all/project.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/all/project.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,20 +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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>gpl_v3</mainLicense> - <licenseSets> - <licenseSet> + <headers> + <header> <licenseName>lgpl_v3</licenseName> + <commentStyle>java</commentStyle> <fileSets> <fileSet> - <headerType>java</headerType> <basedir>all/src</basedir> <includes> <include>**/*.java</include> </includes> </fileSet> </fileSets> - </licenseSet> - </licenseSets> + </header> + </headers> </project> Modified: trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/failLicense/project.xml =================================================================== --- trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/failLicense/project.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/failLicense/project.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,20 +1,22 @@ <?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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>gpl_v3</mainLicense> - <licenseSets> - <licenseSet> + + <headers> + <header> <licenseName>lgpl_v3</licenseName> + <commentStyle>java</commentStyle> <fileSets> <fileSet> - <headerType>java</headerType> <basedir>failLicense/src</basedir> <includes> <include>**/*.java</include> </includes> </fileSet> </fileSets> - </licenseSet> - </licenseSets> + </header> + </headers> + </project> Modified: trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/ignoreLicense/project.xml =================================================================== --- trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/ignoreLicense/project.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/ignoreLicense/project.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,20 +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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>gpl_v3</mainLicense> - <licenseSets> - <licenseSet> + <headers> + <header> <licenseName>lgpl_v3</licenseName> + <commentStyle>java</commentStyle> <fileSets> <fileSet> - <headerType>java</headerType> <basedir>ignoreLicense/src</basedir> <includes> <include>**/*.java</include> </includes> </fileSet> </fileSets> - </licenseSet> - </licenseSets> + </header> + </headers> </project> Modified: trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/updateLicense/project.xml =================================================================== --- trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/updateLicense/project.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/test/resources/org/nuiton/license/plugin/updateFileHeaderMojoTest/updateLicense/project.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -2,20 +2,20 @@ <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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>gpl_v3</mainLicense> - <licenseSets> - <licenseSet> + <headers> + <header> <licenseName>lgpl_v3</licenseName> + <commentStyle>java</commentStyle> <fileSets> <fileSet> - <headerType>java</headerType> <basedir>updateLicense/src</basedir> <includes> <include>**/*.java</include> </includes> </fileSet> </fileSets> - </licenseSet> - </licenseSets> + </header> + </headers> </project> Modified: trunk/src/test/resources/org/nuiton/license/plugin/updateProjectLicenseMojoTest/projectOne.xml =================================================================== --- trunk/src/test/resources/org/nuiton/license/plugin/updateProjectLicenseMojoTest/projectOne.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/test/resources/org/nuiton/license/plugin/updateProjectLicenseMojoTest/projectOne.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,6 +1,6 @@ <?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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>lgpl_v3</mainLicense> </project> Modified: trunk/src/test/resources/org/nuiton/license/plugin/updateProjectLicenseMojoTest/projectTwo.xml =================================================================== --- trunk/src/test/resources/org/nuiton/license/plugin/updateProjectLicenseMojoTest/projectTwo.xml 2010-04-10 20:50:02 UTC (rev 1736) +++ trunk/src/test/resources/org/nuiton/license/plugin/updateProjectLicenseMojoTest/projectTwo.xml 2010-04-12 11:01:09 UTC (rev 1737) @@ -1,6 +1,6 @@ <?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"> + xsi:schemaLocation="http://maven-site.nuiton.org/maven-license-plugin/1.0.0 http://maven-site.nuiton.org/maven-license-plugin/licenseProjectDescriptor-1.0.0.xsd"> <mainLicense>gpl_v3</mainLicense> </project>