r1702 - in trunk/src: main/java/org/nuiton/license/plugin main/java/org/nuiton/license/plugin/header/generator main/java/org/nuiton/license/plugin/repository test/java/org/nuiton/license/plugin test/java/org/nuiton/license/plugin/repository
Author: tchemit Date: 2010-04-04 09:55:41 +0200 (Sun, 04 Apr 2010) New Revision: 1702 Log: Evolution #452: Reformat code to respect code formatting Modified: trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java trunk/src/main/java/org/nuiton/license/plugin/GeneratorListMojo.java trunk/src/main/java/org/nuiton/license/plugin/LicenseListMojo.java trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/AptLicenseHeaderGeneratorImpl.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/HeaderGenerator.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/JavaLicenseHeaderGeneratorImpl.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/LicenseHeaderGenerator.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/PropertiesLicenseHeaderGeneratorImpl.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/XmlLicenseHeaderGeneratorImpl.java trunk/src/main/java/org/nuiton/license/plugin/repository/License.java trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseDefinition.java trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseRepository.java trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseRepositoryFactory.java trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java trunk/src/test/java/org/nuiton/license/plugin/UpdateHeaderMojoTest.java trunk/src/test/java/org/nuiton/license/plugin/repository/LicenseRepositoryFactoryTest.java Modified: trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -31,7 +31,8 @@ import java.io.File; /** - * Le goal pour ajouter le fichier LICENSE.txt dans le classpath (et le generer s'il n'existe pas). + * Le goal pour ajouter le fichier LICENSE.txt dans le classpath (et le generer + * s'il n'existe pas). * * @author chemit * @goal add-license @@ -49,6 +50,7 @@ * @since 1.0.0 */ protected MavenProject project; + /** * Fichier de la licence du module. * @@ -57,10 +59,12 @@ * @since 1.0.0 */ protected File licenseFile; + /** * Le type de license a appliquer. * <p/> - * Pour obtenir la liste des licenses disponibles, utilisez le goal <b>available-licenses</b> + * Pour obtenir la liste des licenses disponibles, utilisez le goal + * <b>available-licenses</b> * <pre> * mvn helper:available-licenses -Ddetail * </pre> @@ -70,14 +74,17 @@ * @since 1.0.0 */ protected String licenseName; + /** * Repertoire de sortie des sources. * - * @parameter expression="${license.outputDirectory}" default-value="target/generated-sources/license" + * @parameter expression="${license.outputDirectory}" + * default-value="target/generated-sources/license" * @required * @since 1.0.0 */ protected File outputDirectory; + /** * Repertoire de sortie des classes (classpath). * @@ -85,6 +92,7 @@ * @since 1.0.0 */ protected String licenseFilename; + /** * Encoding a utiliser pour lire et ecrire les fichiers. * @@ -93,6 +101,7 @@ * @since 1.0.0 */ protected String encoding; + /** * Un flag pour conserver un backup des fichiers modifies. * @@ -100,6 +109,7 @@ * @since 1.0.0 */ protected boolean keepBackup; + /** * Un flag pour forcer la generation. * @@ -107,6 +117,7 @@ * @since 1.0.0 */ protected boolean force; + /** * Un flag pour activer le mode verbeux. * @@ -114,15 +125,19 @@ * @since 1.0.0 */ protected boolean verbose; + /** - * Un flag pour faire une copie nommée dans META-INF (prefixe avec le nom de l'artifact). + * Un flag pour faire une copie nommée dans META-INF (prefixe avec le nom de + * l'artifact). * <p/> - * Cette option n'est utilisable que sur des modules avec un class-path (pas pour un pom) + * Cette option n'est utilisable que sur des modules avec un class-path (pas + * pour un pom) * * @parameter expression="${license.copyToMETA_INF}" default-value="false" * @since 1.0.0 */ protected boolean copyToMETA_INF; + /** * La baseURL d'un resolver de license supplementaire * @@ -130,6 +145,7 @@ * @since 1.0.0 */ protected String[] extraResolver; + protected License license; protected boolean hasClassPath() { @@ -151,7 +167,12 @@ // acquire license - LicenseRepository factory = LicenseRepositoryFactory.newLicenseRepository(true, true, extraResolver); + LicenseRepository factory = + LicenseRepositoryFactory.newLicenseRepository( + true, + true, + extraResolver + ); license = factory.getLicense(licenseName); @@ -191,7 +212,11 @@ copyFile(licenseFile, target); if (copyToMETA_INF) { - File destFile = PluginHelper.getFile(outputDirectory, "META-INF", project.getArtifactId() + "-" + licenseFile.getName()); + File destFile = PluginHelper.getFile( + outputDirectory, + "META-INF", project.getArtifactId() + "-" + + licenseFile.getName() + ); copyFile(licenseFile, destFile); } addResourceDir(outputDirectory, "**/*.txt"); @@ -206,7 +231,7 @@ return licenseName; } - public org.nuiton.license.plugin.repository.License getLicense() { + public License getLicense() { return license; } @@ -242,7 +267,7 @@ this.extraResolver = extraResolver; } - public void setLicense(org.nuiton.license.plugin.repository.License license) { + public void setLicense(License license) { this.license = license; } Modified: trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/AddThirdPartyFileMojo.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -34,17 +34,19 @@ import org.apache.maven.shared.dependency.tree.DependencyNode; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; +import org.nuiton.plugin.AbstractPlugin; +import org.nuiton.plugin.PluginHelper; import java.io.File; import java.util.List; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; -import org.nuiton.plugin.AbstractPlugin; -import org.nuiton.plugin.PluginHelper; /** - * Le goal pour copier le fichier THIRD-PARTY.txt (contenant les licenses de toutes les dependances du projet) - * dans le classpath (et le generer s'il n'existe pas). + * Le goal pour copier le fichier THIRD-PARTY.txt (contenant les licenses de + * toutes les dependances du projet) dans le classpath (et le generer s'il + * n'existe pas). * * @author chemit * @goal add-third-party @@ -55,6 +57,7 @@ public class AddThirdPartyFileMojo extends AbstractPlugin { private static final String unknownLicenseMessage = "Unknown license"; + /** * Dependance du projet. * @@ -64,22 +67,27 @@ * @since 1.0.0 */ protected MavenProject project; + /** * Fichier ou ecrire les licences des dependances. * - * @parameter expression="${license.thirdPartyFilename}" default-value="THIRD-PARTY.txt" + * @parameter expression="${license.thirdPartyFilename}" + * default-value="THIRD-PARTY.txt" * @required * @since 1.0.0 */ protected String thirdPartyFilename; + /** * Repertoire de sortie des classes (classpath). * - * @parameter expression="${license.outputDirectory}" default-value="target/generated-sources/license" + * @parameter expression="${license.outputDirectory}" + * default-value="target/generated-sources/license" * @required * @since 1.0.0 */ protected File outputDirectory; + /** * Encoding a utiliser pour lire et ecrire les fichiers. * @@ -88,6 +96,7 @@ * @since 1.0.0 */ protected String encoding; + /** * Un flag pour forcer la generation. * @@ -95,6 +104,7 @@ * @since 1.0.0 */ protected boolean force; + /** * Un flag pour conserver un backup des fichiers modifies. * @@ -102,13 +112,16 @@ * @since 1.0.0 */ protected boolean keepBackup; + /** - * Un flag pour faire une copie nommé dans META-INF (prefixe avec le nom de l'artifact). + * Un flag pour faire une copie nommé dans META-INF (prefixe avec le nom de + * l'artifact). * * @parameter expression="${license.copyToMETA_INF}" default-value="false" * @since 1.0.0 */ protected boolean copyToMETA_INF; + /** * Un flag pour activer le mode verbeux. * @@ -116,6 +129,7 @@ * @since 1.0.0 */ protected boolean verbose; + /** * Local Repository. * @@ -125,6 +139,7 @@ * @since 1.0.0 */ protected ArtifactRepository localRepository; + /** * Remote repositories used for the project. * @@ -134,47 +149,55 @@ * @since 1.0.0 */ protected List<?> remoteRepositories; + /** * Dependency tree builder component. * * @component */ protected DependencyTreeBuilder dependencyTreeBuilder; + /** * Artifact Factory component. * * @component */ protected ArtifactFactory factory; + /** * Artifact metadata source component. * * @component */ protected ArtifactMetadataSource artifactMetadataSource; + /** * Artifact collector component. * * @component */ protected ArtifactCollector collector; + /** * Maven Project Builder component. * * @component */ protected MavenProjectBuilder mavenProjectBuilder; + /** - * content of third party file (only computed if {@link #force} is active or the - * {@link #thirdPartyFile} does not exist, or is not up-to-date. + * content of third party file (only computed if {@link #force} is active or + * the {@link #thirdPartyFile} does not exist, or is not up-to-date. */ protected String thirdPartyFileContent; + protected File thirdPartyFile; @Override protected boolean checkPackaging() { return rejectPackaging(Packaging.pom); } + boolean doGenerate; @Override @@ -204,7 +227,8 @@ thirdPartyFileContent = buildGroupedLicenses(licenseMap); // log dependencies with no license - SortedSet<String> dependenciesWithNoLicense = licenseMap.get(unknownLicenseMessage); + SortedSet<String> dependenciesWithNoLicense = + licenseMap.get(unknownLicenseMessage); if (dependenciesWithNoLicense != null) { for (String dep : dependenciesWithNoLicense) { // no license found for the dependency @@ -231,17 +255,28 @@ writeFile(thirdPartyFile, thirdPartyFileContent, encoding); } if (copyToMETA_INF) { - copyFile(thirdPartyFile, new File(outputDirectory, "META-INF" + File.separator + project.getArtifactId() + "-" + thirdPartyFile.getName())); + copyFile(thirdPartyFile, new File( + outputDirectory, + "META-INF" + File.separator + project.getArtifactId() + + "-" + thirdPartyFile.getName()) + ); } - addResourceDir(outputDirectory,"**/*.txt"); + addResourceDir(outputDirectory, "**/*.txt"); } /** @return resolve the dependency tree */ protected DependencyNode resolveProject() { try { - ArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_TEST); - return dependencyTreeBuilder.buildDependencyTree(project, localRepository, factory, - artifactMetadataSource, artifactFilter, collector); + ArtifactFilter artifactFilter = + new ScopeArtifactFilter(Artifact.SCOPE_TEST); + return dependencyTreeBuilder.buildDependencyTree( + project, + localRepository, + factory, + artifactMetadataSource, + artifactFilter, + collector + ); } catch (DependencyTreeBuilderException e) { getLog().error("Unable to build dependency tree.", e); return null; @@ -252,7 +287,8 @@ if (node.getState() != DependencyNode.INCLUDED) { // this dependency is not included, so do not treate it if (verbose) { - getLog().info("do not include this dependency " + node.toNodeString()); + getLog().info("do not include this dependency " + + node.toNodeString()); } return; } @@ -264,7 +300,8 @@ if (!Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) { try { - MavenProject artifactProject = getMavenProjectFromRepository(artifact); + MavenProject artifactProject = + getMavenProjectFromRepository(artifact); String artifactName = getArtifactName(artifactProject); List<?> licenses = artifactProject.getLicenses(); @@ -276,7 +313,8 @@ } else { for (Object o : licenses) { if (o == null) { - getLog().warn("could not acquire the license for " + artifactName); + getLog().warn("could not acquire the license for " + + artifactName); continue; } License license = (License) o; @@ -300,7 +338,8 @@ protected String buildGroupedLicenses(LicenseMap licenseMap) { StringBuilder sb = new StringBuilder(); - sb.append("List of third-party dependencies grouped by their license type."); + sb.append("List of third-party dependencies grouped by " + + "their license type."); for (String licenseName : licenseMap.keySet()) { sb.append("\n\n").append(licenseName).append(" : "); @@ -332,7 +371,8 @@ } /** - * Get the <code>Maven project</code> from the repository depending the <code>Artifact</code> given. + * Get the <code>Maven project</code> from the repository depending the + * <code>Artifact</code> given. * * @param artifact an artifact * @return the Maven project for the given artifact @@ -344,17 +384,25 @@ boolean allowStubModel = false; if (!"pom".equals(artifact.getType())) { - artifact = factory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion(), artifact.getScope()); + artifact = factory.createProjectArtifact( + artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersion(), + artifact.getScope() + ); allowStubModel = true; } // TODO: we should use the MavenMetadataSource instead - return mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, - allowStubModel); + return mavenProjectBuilder.buildFromRepository( + artifact, + remoteRepositories, + localRepository, + allowStubModel + ); } - protected class LicenseMap extends java.util.TreeMap<String, SortedSet<String>> { + protected class LicenseMap extends TreeMap<String, SortedSet<String>> { private static final long serialVersionUID = 864199843545688069L; Modified: trunk/src/main/java/org/nuiton/license/plugin/GeneratorListMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/GeneratorListMojo.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/GeneratorListMojo.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -20,24 +20,22 @@ */ package org.nuiton.license.plugin; -import java.util.Map; -import java.util.Map.Entry; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.nuiton.license.plugin.header.generator.HeaderGenerator; +import java.util.Map; +import java.util.Map.Entry; + /** * Displays all the available generators. * * @author chemit - * * @requiresProject false * @requiresDirectInvocation * @goal generator-list - * * @since 1.0.1 - * */ public class GeneratorListMojo extends AbstractMojo { @@ -48,6 +46,7 @@ * @since 1.0.1 */ protected boolean detail; + /** * All available generators * @@ -67,13 +66,17 @@ buffer.append("No generator found.\n\n"); } else { buffer.append("List of available generators :\n\n"); - for (Entry<String, HeaderGenerator> stringHeaderGeneratorEntry : _generators.entrySet()) { - Entry<String, HeaderGenerator> e = stringHeaderGeneratorEntry; + for (Entry<String, HeaderGenerator> e : _generators.entrySet()) { HeaderGenerator generator = e.getValue(); - buffer.append(" - ").append(e.getKey()).append(" : ").append(generator.getDescription()); + buffer.append(" - "); + buffer.append(e.getKey()); + buffer.append(" : "); + buffer.append(generator.getDescription()); buffer.append("\n"); if (detail) { - buffer.append("\n example : \n").append(generator.getHeader("content ")).append('\n'); + buffer.append("\n example : \n"); + buffer.append(generator.getHeader("content ")); + 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-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/LicenseListMojo.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -20,16 +20,16 @@ */ package org.nuiton.license.plugin; -import java.io.IOException; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; - import org.nuiton.license.plugin.repository.License; import org.nuiton.license.plugin.repository.LicenseDefinition; import org.nuiton.license.plugin.repository.LicenseRepository; import org.nuiton.license.plugin.repository.LicenseRepositoryFactory; +import java.io.IOException; + /** * Display all available licenses. * @@ -37,7 +37,6 @@ * @goal license-list * @requiresProject false * @requiresDirectInvocation - * * @since 1.0.1 */ public class LicenseListMojo extends AbstractMojo { @@ -49,6 +48,7 @@ * @since 1.0.1 */ protected String extraResolver; + /** * Encoding a utiliser pour lire et ecrire les fichiers. * @@ -57,6 +57,7 @@ * @since 1.0.0 */ protected String encoding; + /** * Un drapeau pour afficher aussi le contenu des license. * @@ -75,23 +76,37 @@ LicenseRepository factory; try { - factory = LicenseRepositoryFactory.newLicenseRepository(true, true, extraResolver); + factory = LicenseRepositoryFactory.newLicenseRepository( + true, + true, + extraResolver + ); } catch (IllegalArgumentException ex) { - throw new MojoExecutionException("could not obtain the license repository", ex); + throw new MojoExecutionException( + "could not obtain the license repository", ex); } catch (IOException ex) { - throw new MojoExecutionException("could not obtain the license repository", ex); + throw new MojoExecutionException( + "could not obtain the license repository", ex); } for (LicenseDefinition entry : factory.getDefinitions()) { String licenseName = entry.getName(); - buffer.append(" * ").append(licenseName).append(" : ").append(entry.getDescription()).append('\n'); + buffer.append(" * "); + buffer.append(licenseName); + buffer.append(" : "); + buffer.append(entry.getDescription()); + buffer.append('\n'); if (detail) { try { License license = factory.getLicense(licenseName); - buffer.append("\n").append(license.getHeaderContent(encoding)).append("\n\n"); + buffer.append("\n"); + buffer.append(license.getHeaderContent(encoding)); + buffer.append("\n\n"); } catch (IOException ex) { - throw new MojoExecutionException("could not instanciate license with name " + licenseName + " for reason " + ex.getMessage(), ex); + throw new MojoExecutionException( + "could not instanciate license with name " + + licenseName + " for reason " + ex.getMessage(), ex); } } } Modified: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -58,6 +58,7 @@ * @since 1.0.0 */ protected MavenProject project; + /** * Encoding a utiliser pour lire et ecrire les fichiers. * @@ -66,6 +67,7 @@ * @since 1.0.0 */ protected String encoding; + /** * l'annee de creation du module (sera place dans le header) * @@ -74,14 +76,17 @@ * @since 1.0.0 */ protected String inceptionYear; + /** * le nom de l'organisation (sera place dans le header) * - * @parameter expression="${license.organizationName}" default-value="${project.organization.name}" + * @parameter expression="${license.organizationName}" + * default-value="${project.organization.name}" * @required * @since 1.0.0 */ protected String organizationName; + /** * le nom du projet (sera place dans le header) * @@ -90,6 +95,7 @@ * @since 1.0.0 */ protected String projectName; + /** * Le type de license a appliquer. * @@ -98,6 +104,7 @@ * @since 1.0.0 */ protected String licenseName; + /** * Le type de générateur a utiliser pour encapsuler le header. * <p/> @@ -108,13 +115,14 @@ * @since 1.0.1 */ protected String generatorName; + /** * La liste des patterns de fichiers à inclure (séparés par des virgules). * <p/> * Exemple : <code>**\/*.java,**\/*.properties</code> * <p/> - * On recherchera alors les fichiers respectant l'un des patterns dans - * tous les répertoires de sources et de tests. + * On recherchera alors les fichiers respectant l'un des patterns dans tous + * les répertoires de sources et de tests. * <p/> * Par défaut, on veut utiliser le plugin sur des fichiers sources java. * @@ -123,13 +131,14 @@ * @since 1.0.1 */ protected String includes = "**/*.java"; + /** * La liste des patterns de fichiers à exclure (séparés par des virgules). * <p/> * Exemple : <code>**\/*.java,**\/*.properties</code> * <p/> - * On recherchera alors les fichiers respectant l'un des patterns dans - * tous les répertoires de sources et de tests. + * On recherchera alors les fichiers respectant l'un des patterns dans tous + * les répertoires de sources et de tests. * <p/> * Par défaut, on n'exclue rien. * @@ -137,53 +146,57 @@ * @since 1.0.1 */ protected String excludes; + /** * Compile source directory roots to inspect. - * + * <p/> * Can use it a a comma separated string : - * - * <pre><compileSourceRoots>src/site,src.target/extra-site</compileSourceRoots> </pre> - * + * <p/> + * <pre><compileSourceRoots>src/site,src.target/extra-site</compileSourceRoots> + * </pre> + * <p/> * or a list : - * + * <p/> * <pre> * <compileSourceRoots> * <root>src/site</root> </pre> - * <root>src/target/extra-site</root> </pre> - * </compileSourceRoots> - * </pre> - * + * <root>src/target/extra-site</root> </pre> + * </compileSourceRoots> </pre> + * <p/> * <b>Note:</b> If not set, will use the build compile roots. * - * @parameter expression="${license.compileSourceRoots}" default-value="${project.compileSourceRoots}" + * @parameter expression="${license.compileSourceRoots}" + * default-value="${project.compileSourceRoots}" * @required * @since 1.0.0 */ protected List<String> compileSourceRoots; + /** * Test source directory roots to inspect. - * + * <p/> * Can use it a a comma separated string : - * - * <pre><testSourceRoots>src/test1,src/test2</testSourceRoots> </pre> - * + * <p/> + * <pre><testSourceRoots>src/test1,src/test2</testSourceRoots> + * </pre> + * <p/> * or a list : - * + * <p/> * <pre> * <testSourceRoots> * <root>src/site</root> </pre> - * <root>src/target/extra-site</root> </pre> - * </testSourceRoots> - * </pre> - * + * <root>src/target/extra-site</root> </pre> + * </testSourceRoots> </pre> + * <p/> * <b>Note:</b> If not set, will use the build test roots. * - * - * @parameter expression="${license.testSourceRoots}" default-value="${project.testCompileSourceRoots}" + * @parameter expression="${license.testSourceRoots}" + * default-value="${project.testCompileSourceRoots}" * @required * @since 1.0.0 */ protected List<String> testSourceRoots; + /** * Un resolver externe * @@ -191,6 +204,7 @@ * @since 1.0.0 */ protected String licenseResolver; + /** * La template (velocity) a utiliser pour construire le header. * <p/> @@ -200,6 +214,7 @@ * @since 1.0.1 */ protected String template; + /** * Des paramètres supplémentaires à utiliser dans la template du header. * @@ -207,6 +222,7 @@ * @since 1.0.1 */ protected Map<String, String> templateParameters; + /** * Un flag pour conserver un backup des fichiers modifies. * @@ -214,6 +230,7 @@ * @since 1.0.0 */ protected boolean keepBackup; + /** * Un flag pour activer le mode verbeux. * @@ -221,6 +238,7 @@ * @since 1.0.0 */ protected boolean verbose; + /** * A flag to skip the goal. * @@ -228,6 +246,7 @@ * @since 1.0.3 */ protected boolean skipUpdateHeader; + /** * A flag to test plugin but modify no file. * @@ -235,6 +254,7 @@ * @since 1.0.3 */ protected boolean dryRun; + /** * Velocity Component. * @@ -242,27 +262,27 @@ * @since 2.0.0 */ protected VelocityComponent velocity; + /** * All available generators * * @component role="org.nuiton.license.plugin.header.generator.HeaderGenerator" */ protected Map<String, HeaderGenerator> _generators; - /** - * le header a ajouter dans chaque fichier source java - */ + + /** le header a ajouter dans chaque fichier source java */ protected String licenseHeaderContent; - /** - * le header complet (avec les balises de commentaires) - */ + + /** le header complet (avec les balises de commentaires) */ protected String boxedLicenseHeaderContent; + /** - * la liste des chemin relatifs des sources java a traiter pour chaque repertoire contenant des sources + * la liste des chemin relatifs des sources java a traiter pour chaque + * repertoire contenant des sources */ protected Map<File, String[]> filesToTreate; - /** - * le timestamp utilise pour la generation - */ + + /** le timestamp utilise pour la generation */ protected long timestamp; @Override @@ -334,16 +354,16 @@ throw new MojoExecutionException("no header generator found"); } if (verbose) { - for (Entry<String, HeaderGenerator> stringHeaderGeneratorEntry : _generators.entrySet()) { - Entry<String, HeaderGenerator> next = stringHeaderGeneratorEntry; + for (Entry<String, HeaderGenerator> e : _generators.entrySet()) { + Entry<String, HeaderGenerator> next = e; getLog().info("config - available generator : " + next.getKey()); } - if (compileSourceRoots!=null) { + if (compileSourceRoots != null) { for (String root : compileSourceRoots) { getLog().info("config - compile source root : " + root); } } - if (testSourceRoots!=null) { + if (testSourceRoots != null) { for (String root : testSourceRoots) { getLog().info("config - test source root : " + root); } @@ -351,7 +371,9 @@ } if (!_generators.containsKey(generatorName.trim())) { - throw new MojoExecutionException("the generator named '" + generatorName + "' is unknown (use generator-list goal to see all of them)"); + throw new MojoExecutionException( + "the generator named '" + generatorName + + "' is unknown (use generator-list goal to see all of them)"); } HeaderGenerator generator = _generators.get(generatorName); @@ -369,11 +391,17 @@ File templateFile = new File(template); - // verifie que la template existe (dans le class-path ou en tant que fichier) + // verifie que la template existe (dans le class-path ou en tant que + // fichier) checkResource(templateFile); // recuperation de la license a utiliser - LicenseRepository factory = LicenseRepositoryFactory.newLicenseRepository(true, true, licenseResolver); + LicenseRepository factory = + LicenseRepositoryFactory.newLicenseRepository( + true, + true, + licenseResolver + ); License license = factory.getLicense(licenseName); if (verbose) { @@ -387,7 +415,8 @@ // build the comment boxed header content boxedLicenseHeaderContent = generator.getHeader(licenseHeaderContent); if (verbose) { - getLog().info("config - header to use\n" + boxedLicenseHeaderContent); + getLog().info("config - header to use\n" + + boxedLicenseHeaderContent); } } @@ -408,7 +437,8 @@ } // file where to writeFile result - File processFile = new File(file.getAbsolutePath() + "_" + timestamp); + File processFile = new File(file.getAbsolutePath() + "_" + + timestamp); try { p.process(file, processFile); @@ -416,11 +446,16 @@ if (!foundLicenseHeader) { if (p.getLicenceFilter().isDetectHeader()) { - getLog().warn("skip file " + file + " (no license footer tag found : '##%*' !)"); + getLog().warn( + "skip file " + file + + " (no license footer tag found : '##%*' !)"); } else { // no license header found in file, add it getLog().info("adding license header on file " + file); - String content = PluginHelper.readAsString(file, encoding); + String content = PluginHelper.readAsString( + file, + encoding + ); content = boxedLicenseHeaderContent + content; if (!dryRun) { writeFile(processFile, content, encoding); @@ -443,7 +478,9 @@ } } catch (Exception e) { - getLog().warn("skip file " + file + " (could not process for reason : " + e.getMessage() + ")"); + getLog().warn( + "skip file " + file + " (could not process " + + "for reason : " + e.getMessage() + ")"); deleteFile(processFile); } finally { // toujours cleaner les états du filtre du processeur @@ -464,7 +501,8 @@ * @return le header construit * @throws Exception pour toute erreur pendant la construction du header */ - protected String computeHeader(License license, HeaderGenerator generator) throws Exception { + protected String computeHeader(License license, + HeaderGenerator generator) throws Exception { // recuperation de la license a mettre dans le header String licenseContent = license.getHeaderContent(encoding); @@ -497,7 +535,10 @@ buffer.append("config - parameters for template : "); for (Object key : context.getKeys()) { - buffer.append("\n * ").append(key).append(" : ").append(context.get(key + "")); + buffer.append("\n * "); + buffer.append(key); + buffer.append(" : "); + buffer.append(context.get(key + "")); } getLog().info(buffer.toString()); } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/AptLicenseHeaderGeneratorImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/AptLicenseHeaderGeneratorImpl.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/AptLicenseHeaderGeneratorImpl.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -23,18 +23,19 @@ import org.nuiton.processor.filters.LicenseFilter; /** - * Le generateur de header pour des fichiers apt. + * Le generateur de header pour des fichiers apt. * * @author chemit + * @plexus.component role-hint="license-apt" * @since 1.0.1 - * - * @plexus.component role-hint="license-apt" */ public class AptLicenseHeaderGeneratorImpl extends LicenseHeaderGenerator { public static final String GENERATOR_NAME = "license-apt"; - public static final String GENERATOR_DESCRIPTION = "generator with apt comment style"; + public static final String GENERATOR_DESCRIPTION = + "generator with apt comment style"; + public AptLicenseHeaderGeneratorImpl() { super("~~~ ", "\n", "\n", LicenseFilter.HEADER, LicenseFilter.FOOTER); } @@ -48,4 +49,4 @@ public String getDescription() { return GENERATOR_DESCRIPTION; } -} \ No newline at end of file +} Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/HeaderGenerator.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/HeaderGenerator.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/HeaderGenerator.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -30,21 +30,13 @@ */ public interface HeaderGenerator { - /** - * Plexus role name - */ + /** Plexus role name */ String ROLE_NAME = HeaderGenerator.class.getName(); - /** - * - * @return the name of the generator - */ + /** @return the name of the generator */ String getName(); - /** - * - * @return the description of the generator - */ + /** @return the description of the generator */ String getDescription(); /** @@ -53,16 +45,12 @@ */ String getHeader(String content); - /** - * - * @return the prefix to add on each lines of the header - */ + /** @return the prefix to add on each lines of the header */ String getLinePrefix(); /** - * - * @param content - * @return the prefix content + * @param content the license + * @return the prefix content (wrapping header) * @throws IOException if any io exceptions */ String prefixContent(String content) throws IOException; Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/JavaLicenseHeaderGeneratorImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/JavaLicenseHeaderGeneratorImpl.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/JavaLicenseHeaderGeneratorImpl.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -26,15 +26,16 @@ * Le geénérateur de header pour les fichiers sources java. * * @author chemit + * @plexus.component role-hint="license-java" * @since 1.0.1 - * - * @plexus.component role-hint="license-java" */ public class JavaLicenseHeaderGeneratorImpl extends LicenseHeaderGenerator { public static final String GENERATOR_NAME = "license-java"; - public static final String GENERATOR_DESCRIPTION = "generator with java comment style"; + public static final String GENERATOR_DESCRIPTION = + "generator with java comment style"; + public JavaLicenseHeaderGeneratorImpl() { super(" *", "/*", " */", LicenseFilter.HEADER, LicenseFilter.FOOTER); } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/LicenseHeaderGenerator.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/LicenseHeaderGenerator.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/LicenseHeaderGenerator.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -20,24 +20,33 @@ */ package org.nuiton.license.plugin.header.generator; -import java.io.IOException; import org.nuiton.plugin.PluginHelper; +import java.io.IOException; + /** * Une implentation de base pour les generateur d'en-tete de license. - * + * * @author chemit * @since 1.0.1 */ public abstract class LicenseHeaderGenerator implements HeaderGenerator { protected String linePrefix; + protected String openTag; + protected String closeTag; + protected String openProcessTag; + protected String closeProcessTag; - public LicenseHeaderGenerator(String linePrefix, String openTag, String closeTag, String openProcessTag, String closeProcessTag) { + public LicenseHeaderGenerator(String linePrefix, + String openTag, + String closeTag, + String openProcessTag, + String closeProcessTag) { this.linePrefix = linePrefix; this.openTag = openTag; this.closeTag = closeTag; @@ -47,12 +56,30 @@ @Override public String getHeader(String licenseHeaderContent) { - return openTag + "\n" + linePrefix + " " + openProcessTag + " " + licenseHeaderContent + " " + closeProcessTag + "\n" + closeTag + "\n"; + StringBuilder buffer = new StringBuilder(); + buffer.append(openTag); + buffer.append('\n'); + buffer.append(linePrefix); + buffer.append(' '); + buffer.append(openProcessTag); + buffer.append(' '); + buffer.append(licenseHeaderContent); + buffer.append(' '); + buffer.append(closeProcessTag); + buffer.append('\n'); + buffer.append(closeTag); + buffer.append('\n'); + return buffer.toString(); +// return openTag + "\n" + linePrefix + " " + openProcessTag + " " + +// licenseHeaderContent + " " + closeProcessTag + "\n" + closeTag + "\n"; } @Override public String prefixContent(String content) throws IOException { - String result = PluginHelper.prefixLines(linePrefix + " ", linePrefix, content); + String result = PluginHelper.prefixLines(linePrefix + " ", + linePrefix, + content + ); return result; } Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/PropertiesLicenseHeaderGeneratorImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/PropertiesLicenseHeaderGeneratorImpl.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/PropertiesLicenseHeaderGeneratorImpl.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -24,17 +24,21 @@ /** * Le generateur de header pour des fichiers de proprietes. - * + * * @author chemit + * @plexus.component role-hint="license-properties" * @since 1.0.1 - * - * @plexus.component role-hint="license-properties" */ public class PropertiesLicenseHeaderGeneratorImpl extends LicenseHeaderGenerator { public static final String GENERATOR_NAME = "license-properties"; - public static final String GENERATOR_DESCRIPTION = "generator with properties file comment style"; - public static final String LINE = "###############################################################################"; + + public static final String GENERATOR_DESCRIPTION = + "generator with properties file comment style"; + + public static final String LINE = + "###############################################################################"; + public static final String PREFIX = "#"; public PropertiesLicenseHeaderGeneratorImpl() { Modified: trunk/src/main/java/org/nuiton/license/plugin/header/generator/XmlLicenseHeaderGeneratorImpl.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/header/generator/XmlLicenseHeaderGeneratorImpl.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/header/generator/XmlLicenseHeaderGeneratorImpl.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -23,18 +23,19 @@ import org.nuiton.processor.filters.LicenseFilter; /** - * Le generateur de header pour des fichiers xml. + * Le generateur de header pour des fichiers xml. * * @author chemit + * @plexus.component role-hint="license-xml" * @since 1.0.1 - * - * @plexus.component role-hint="license-xml" */ public class XmlLicenseHeaderGeneratorImpl extends LicenseHeaderGenerator { public static final String GENERATOR_NAME = "license-xml"; - public static final String GENERATOR_DESCRIPTION = "generator with xml comment style"; + public static final String GENERATOR_DESCRIPTION = + "generator with xml comment style"; + public XmlLicenseHeaderGeneratorImpl() { super(" ", "<!--", "-->", LicenseFilter.HEADER, LicenseFilter.FOOTER); } Modified: trunk/src/main/java/org/nuiton/license/plugin/repository/License.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/repository/License.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/repository/License.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -20,14 +20,15 @@ */ package org.nuiton.license.plugin.repository; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; +import org.codehaus.plexus.util.IOUtil; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.codehaus.plexus.util.IOUtil; /** * The model of a license. @@ -36,21 +37,16 @@ */ public class License { - /** - * the name of the licenses (ex lgpl-3.0) - */ + /** the name of the licenses (ex lgpl-3.0) */ protected String name; - /** - * the description of the license - */ + + /** the description of the license */ protected String description; - /** - * url of the license's content - */ + + /** url of the license's content */ protected URL licenseURL; - /** - * url of the header's template - */ + + /** url of the header's template */ protected URL headerURL; public License() { @@ -77,13 +73,12 @@ throw new IllegalStateException("no licenseURL defined in " + this); } - Reader r = new BufferedReader(new InputStreamReader(licenseURL.openStream(), encoding)); + Reader r = new BufferedReader( + new InputStreamReader(licenseURL.openStream(), encoding)); try { return IOUtil.toString(r); } finally { - if (r != null) { - r.close(); - } + r.close(); } } @@ -91,13 +86,12 @@ if (headerURL == null) { throw new IllegalStateException("no headerURL defined in " + this); } - Reader r = new BufferedReader(new InputStreamReader(headerURL.openStream(), encoding)); + Reader r = new BufferedReader( + new InputStreamReader(headerURL.openStream(), encoding)); try { return IOUtil.toString(r); } finally { - if (r != null) { - r.close(); - } + r.close(); } } @@ -119,7 +113,10 @@ @Override public String toString() { - ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE); + ToStringBuilder builder = new ToStringBuilder( + this, + ToStringStyle.MULTI_LINE_STYLE + ); builder.append("name", name); builder.append("description", description); builder.append("licenseURL", licenseURL); Modified: trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseDefinition.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseDefinition.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseDefinition.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -20,11 +20,12 @@ */ package org.nuiton.license.plugin.repository; -import java.io.IOException; -import java.net.URL; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; +import java.io.IOException; +import java.net.URL; + /** * Model of a license definition in a license repository. * @@ -33,9 +34,13 @@ public class LicenseDefinition { public static final String LICENSE_HEADER_FILE = "header.txt"; + public static final String LICENSE_CONTENT_FILE = "license.txt"; + protected URL baseURL; + protected String name; + protected String description; public LicenseDefinition(URL baseURL, String name, String description) { @@ -66,7 +71,10 @@ @Override public String toString() { - ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE); + ToStringBuilder builder = new ToStringBuilder( + this, + ToStringStyle.MULTI_LINE_STYLE + ); builder.append("name", name); builder.append("description", description); builder.append("baseURL", baseURL); Modified: trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseRepository.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseRepository.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseRepository.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -24,35 +24,30 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Properties; /** - * * @author chemit * @since 1.0.3 */ public class LicenseRepository { public static final String REPOSITORY_DEFINITION_FILE = "licenses.properties"; - /** - * the base url of the licenses repository - */ + + /** the base url of the licenses repository */ protected URL baseURL; - /** - * next repository (can be {@code null}). - */ + + /** next repository (can be {@code null}). */ protected LicenseRepository next; + protected List<LicenseDefinition> definitions; + protected final Map<LicenseDefinition, License> cache; + /** - * flag to known if repository was init (pass to {@code true} - * when invoking the method {@link #load()}). + * flag to known if repository was init (pass to {@code true} when invoking + * the method {@link #load()}). */ protected boolean init; @@ -94,7 +89,9 @@ this.definitions = new ArrayList<LicenseDefinition>(); if (!checkExists(definitionURL)) { - throw new IllegalArgumentException("no licenses.properties found withurl [" + definitionURL + "] for resolver " + this); + throw new IllegalArgumentException( + "no licenses.properties found withurl [" + + definitionURL + "] for resolver " + this); } Properties p = new Properties(); p.load(definitionURL.openStream()); @@ -107,7 +104,11 @@ URL licenseURL = getUrl(baseURL, licenseName); - LicenseDefinition def = new LicenseDefinition(licenseURL, licenseName, licenseDescription); + LicenseDefinition def = new LicenseDefinition( + licenseURL, + licenseName, + licenseDescription + ); definitions.add(def); } definitions = Collections.unmodifiableList(definitions); @@ -121,7 +122,8 @@ public List<LicenseDefinition> getAllDefinitions() { LicenseRepository[] repos = getAllRepositories(); - List<LicenseDefinition> result = new ArrayList<LicenseDefinition>(repos.length); + List<LicenseDefinition> result = + new ArrayList<LicenseDefinition>(repos.length); for (LicenseRepository repo : repos) { result.addAll(repo.definitions); } @@ -135,7 +137,8 @@ public LicenseDefinition getDefinition(String licenseName) { checkInit(); if (licenseName == null || licenseName.trim().isEmpty()) { - throw new IllegalArgumentException("licenceName can not be null, nor empty"); + throw new IllegalArgumentException( + "licenceName can not be null, nor empty"); } licenseName = licenseName.trim().toLowerCase(); LicenseDefinition definition = null; @@ -154,7 +157,8 @@ public License getLicense(String licenseName) throws IOException { checkInit(); if (licenseName == null || licenseName.trim().isEmpty()) { - throw new IllegalArgumentException("licenceName can not be null, nor empty"); + throw new IllegalArgumentException( + "licenceName can not be null, nor empty"); } LicenseDefinition definition = getDefinition(licenseName); @@ -183,12 +187,14 @@ return license; } - public static URL getUrl(URL baseUrl, String suffix) throws IllegalArgumentException { + public static URL getUrl(URL baseUrl, + String suffix) throws IllegalArgumentException { String url = baseUrl.toString() + "/" + suffix; try { return new URL(url); } catch (MalformedURLException ex) { - throw new IllegalArgumentException("could not obtain url " + url, ex); + throw new IllegalArgumentException( + "could not obtain url " + url, ex); } } @@ -214,13 +220,17 @@ protected void checkNotInit() throws IllegalStateException { if (init) { - throw new IllegalStateException("license repository " + this + " was already initialize..."); + throw new IllegalStateException( + "license repository " + this + + " was already initialize..."); } } protected void checkInit() throws IllegalStateException { if (!init) { - throw new IllegalStateException("repository " + this + " is not init, use the load method before any license request"); + throw new IllegalStateException( + "repository " + this + " is not init, use the load " + + "method before any license request"); } } } Modified: trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseRepositoryFactory.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseRepositoryFactory.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/main/java/org/nuiton/license/plugin/repository/LicenseRepositoryFactory.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -34,13 +34,10 @@ */ public class LicenseRepositoryFactory { - /** - * class-path directory where is the licenses repository - */ + /** class-path directory where is the licenses repository */ public static final String JAR_LICENSE_REPOSITORY = "/META-INF/licenses"; - /** - * to use log facility, just put in your code: log.info(\"...\"); - */ + + /** to use log facility, just put in your code: log.info(\"...\"); */ static private final Log log = LogFactory.getLog(LicenseRepositoryFactory.class); /** @@ -52,7 +49,10 @@ * @return the instanciate and ready to use license repository * @throws IOException if any problem while acquiring license repository */ - public static LicenseRepository newLicenseRepository(boolean useJarRepository, boolean load, String... extraResolvers) throws IOException { + public static LicenseRepository newLicenseRepository( + boolean useJarRepository, + boolean load, + String... extraResolvers) throws IOException { List<URL> baseURLs = new ArrayList<URL>(); if (extraResolvers != null) { @@ -66,9 +66,11 @@ url = new URL(exUrl); } catch (Exception e) { if (log.isDebugEnabled()) { - log.warn("could not convert url [" + exUrl + "], for reason " + e.getMessage()); + log.warn("could not convert url [" + exUrl + + "], for reason " + e.getMessage()); } else { - log.warn("could not convert url [" + exUrl + "], for reason " + e.getMessage()); + log.warn("could not convert url [" + exUrl + + "], for reason " + e.getMessage()); } log.warn("will skip the url [" + exUrl + "]"); continue; @@ -110,10 +112,12 @@ return result; } - public static LicenseRepository newJarLicenseRepository(boolean load) throws IOException { + public static LicenseRepository newJarLicenseRepository( + boolean load) throws IOException { LicenseRepository result = new LicenseRepository(); // the first repository is always a jar repository - URL baseURL = LicenseRepositoryFactory.class.getResource(JAR_LICENSE_REPOSITORY); + URL baseURL = LicenseRepositoryFactory.class.getResource( + JAR_LICENSE_REPOSITORY); result.setBaseURL(baseURL); if (load) { result.load(); Modified: trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -20,13 +20,15 @@ */ package org.nuiton.license.plugin; -import static org.junit.Assert.*; import org.junit.Test; +import org.nuiton.plugin.AbstractMojoTest; import java.io.File; import java.io.IOException; -import org.nuiton.plugin.AbstractMojoTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class AddLicenseFileMojoTest extends AbstractMojoTest<AddLicenseFileMojo> { @Override @@ -42,13 +44,19 @@ mojo.setOutputDirectory(outputDirectory); if (!outputDirectory.exists()) { if (!outputDirectory.mkdirs()) { - throw new IOException("could not create directory : " + outputDirectory); + throw new IOException( + "could not create directory : " + outputDirectory); } } - mojo.setLicenseFile(new File(pomFile.getParentFile(), mojo.getLicenseFile().toString())); - log.info("pom : " + getRelativePathFromBasedir(mojo.getProject().getFile())); - log.info("outputDirectory : " + getRelativePathFromBasedir(mojo.getOutputDirectory())); - log.info("licenseFile : " + getRelativePathFromBasedir(mojo.getLicenseFile())); + mojo.setLicenseFile(new File(pomFile.getParentFile(), + mojo.getLicenseFile().toString()) + ); + log.info("pom : " + + getRelativePathFromBasedir(mojo.getProject().getFile())); + log.info("outputDirectory : " + + getRelativePathFromBasedir(mojo.getOutputDirectory())); + log.info("licenseFile : " + + getRelativePathFromBasedir(mojo.getLicenseFile())); } @Test @@ -60,7 +68,11 @@ // always assume pom is older than any file // since we can not ensure order of copy test resources - mojo.getProject().getFile().setLastModified(0); + File file = mojo.getProject().getFile(); + boolean b = file.setLastModified(0); + if (!b) { + throw new IOException("could not change lastModified on " + file); + } // then executing the mojo, will do NOT change the licence file mojo.execute(); @@ -87,7 +99,11 @@ // always assume pom is older than any file // since we can not ensure order of copy test resources - mojo.getProject().getFile().setLastModified(0); + File file = mojo.getProject().getFile(); + boolean b = file.setLastModified(0); + if (!b) { + throw new IOException("could not changed lastModified on " + file); + } // then executing the mojo, will do NOT change the licence file mojo.execute(); Modified: trunk/src/test/java/org/nuiton/license/plugin/UpdateHeaderMojoTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/plugin/UpdateHeaderMojoTest.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/test/java/org/nuiton/license/plugin/UpdateHeaderMojoTest.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -20,20 +20,24 @@ */ package org.nuiton.license.plugin; +import org.junit.Test; +import org.nuiton.plugin.AbstractMojoTest; +import org.nuiton.plugin.PluginHelper; +import org.nuiton.processor.filters.LicenseFilter; + import java.io.File; import java.io.IOException; import java.util.Map.Entry; -import static org.junit.Assert.*; -import org.junit.Test; -import org.nuiton.processor.filters.LicenseFilter; -import org.nuiton.plugin.PluginHelper; -import org.nuiton.plugin.AbstractMojoTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** @author chemit */ public class UpdateHeaderMojoTest extends AbstractMojoTest<UpdateHeaderMojo> { - public static final String _LICENSE_TO_CHANGE_ = LicenseFilter.HEADER + " license to change " + LicenseFilter.FOOTER; + public static final String _LICENSE_TO_CHANGE_ = + LicenseFilter.HEADER + " license to change " + LicenseFilter.FOOTER; + public static final String _MUST_BE_THERE = "// MUST BE THERE!"; @Override @@ -65,7 +69,8 @@ testPom(new String[]{_MUST_BE_THERE}, new String[]{_LICENSE_TO_CHANGE_}); } - public void testPom(String[] mandatoryPatterns, String[] excludePatterns) throws Exception { + public void testPom(String[] mandatoryPatterns, + String[] excludePatterns) throws Exception { UpdateHeaderMojo mojo = getMojo(); @@ -76,7 +81,8 @@ for (String javaRelativePath : entry.getValue()) { File f = new File(src, javaRelativePath); - assertTrue("generated file " + f + " was not found...", f.exists()); + assertTrue("generated file " + f + " was not found...", + f.exists()); String content = PluginHelper.readAsString(f, "utf-8"); @@ -93,9 +99,16 @@ } } - protected void checkPattern(String content, String pattern, boolean required, File f) throws IOException { + protected void checkPattern(String content, + String pattern, + boolean required, + File f) throws IOException { - String errorMessage = required ? "could not find the pattern : " : "should not have found pattern :"; - assertEquals(errorMessage + pattern + " in file " + f, required, content.contains(pattern)); + String errorMessage = required ? "could not find the pattern : " : + "should not have found pattern :"; + assertEquals(errorMessage + pattern + " in file " + f, + required, + content.contains(pattern) + ); } } Modified: trunk/src/test/java/org/nuiton/license/plugin/repository/LicenseRepositoryFactoryTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/plugin/repository/LicenseRepositoryFactoryTest.java 2010-03-27 20:04:32 UTC (rev 1701) +++ trunk/src/test/java/org/nuiton/license/plugin/repository/LicenseRepositoryFactoryTest.java 2010-04-04 07:55:41 UTC (rev 1702) @@ -20,22 +20,26 @@ */ package org.nuiton.license.plugin.repository; -import java.io.File; -import java.io.IOException; -import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; import org.junit.Test; import org.nuiton.plugin.TestHelper; +import java.io.File; +import java.io.IOException; +import java.util.List; + /** @author chemit */ public class LicenseRepositoryFactoryTest extends Assert { public static final String NEWLICENSE = "new_license"; + public static final String NEWLICENSE2 = "new_license2"; protected static final Log log = LogFactory.getLog(LicenseRepositoryFactoryTest.class); + protected static final String encoding = "utf-8"; + protected File baseDir; protected File getBaseDir() { @@ -130,11 +134,11 @@ assertEquals(definitions, allDefinitions); assertLicenseRepositoryFound(repository, - "gpl_v1", - "gpl_v2", - "gpl_v3", - "lgpl_v2_1", - "lgpl_v3"); + "gpl_v1", + "gpl_v2", + "gpl_v3", + "lgpl_v2_1", + "lgpl_v3"); } @Test @@ -150,11 +154,11 @@ assertEquals(1, repositories.length); assertNotNull(repositories[0]); assertLicenseRepositoryFound(repository, - "gpl_v1", - "gpl_v2", - "gpl_v3", - "lgpl_v2_1", - "lgpl_v3"); + "gpl_v1", + "gpl_v2", + "gpl_v3", + "lgpl_v2_1", + "lgpl_v3"); repository = LicenseRepositoryFactory.newLicenseRepository(true, true, ""); repositories = repository.getAllRepositories(); @@ -162,11 +166,11 @@ assertEquals(1, repositories.length); assertNotNull(repositories[0]); assertLicenseRepositoryFound(repository, - "gpl_v1", - "gpl_v2", - "gpl_v3", - "lgpl_v2_1", - "lgpl_v3"); + "gpl_v1", + "gpl_v2", + "gpl_v3", + "lgpl_v2_1", + "lgpl_v3"); repository = LicenseRepositoryFactory.newLicenseRepository(true, false, "file://yo"); assertNotNull(repository); @@ -196,22 +200,22 @@ assertEquals(1, repositories[1].getDefinitions().size()); assertLicenseRepositoryFound(repositories[0], - "gpl_v1", - "gpl_v2", - "gpl_v3", - "lgpl_v2_1", - "lgpl_v3"); + "gpl_v1", + "gpl_v2", + "gpl_v3", + "lgpl_v2_1", + "lgpl_v3"); assertNotNull(repositories[1].getBaseURL()); assertEquals(repo, new File(repositories[1].getBaseURL().getFile())); assertLicenseRepositoryFound(repositories[1], - generatedLicence); + generatedLicence); // add license - addLicenseToRepository(repo,NEWLICENSE); + addLicenseToRepository(repo, NEWLICENSE); repository.reload(); @@ -226,11 +230,11 @@ assertNotNull(repositories[1].getDefinitions().get(1)); assertLicenseRepositoryFound(repositories[1], - NEWLICENSE, generatedLicence); + NEWLICENSE, generatedLicence); // add another license - addLicenseToRepository(repo,NEWLICENSE2); + addLicenseToRepository(repo, NEWLICENSE2); repository.reload(); repositories = repository.getAllRepositories(); @@ -243,7 +247,7 @@ assertEquals(3, repositories[1].getDefinitions().size()); assertLicenseRepositoryFound(repositories[1], NEWLICENSE, - NEWLICENSE2, generatedLicence); + NEWLICENSE2, generatedLicence); } // // @Test
participants (1)
-
tchemit@users.nuiton.org