r1745 - in trunk: . src/main/java/org/nuiton/license/plugin src/main/java/org/nuiton/license/plugin/header src/main/resources src/site src/site/rst src/test/java/org/nuiton/license/plugin src/test/resources/org/nuiton/license/plugin
Author: tchemit Date: 2010-04-12 14:32:05 +0200 (Mon, 12 Apr 2010) New Revision: 1745 Log: - Evolution #483: Remove deprecated api in 2.1 - optimized dependencies (no more need of velocity) Removed: trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java trunk/src/main/java/org/nuiton/license/plugin/GeneratorListMojo.java trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java trunk/src/main/java/org/nuiton/license/plugin/header/generator/ trunk/src/main/resources/license/ trunk/src/main/resources/licenseProjects/ trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java trunk/src/test/java/org/nuiton/license/plugin/UpdateHeaderMojoTest.java trunk/src/test/resources/org/nuiton/license/plugin/addLicenseFileMojoTest/ trunk/src/test/resources/org/nuiton/license/plugin/updateHeaderMojoTest/ Modified: trunk/pom.xml trunk/src/site/rst/index.rst trunk/src/site/rst/usage.rst trunk/src/site/site_en.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-04-12 12:15:05 UTC (rev 1744) +++ trunk/pom.xml 2010-04-12 12:32:05 UTC (rev 1745) @@ -90,6 +90,16 @@ <artifactId>plexus-sec-dispatcher</artifactId> </exclusion> + <exclusion> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-velocity</artifactId> + </exclusion> + + <exclusion> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity</artifactId> + </exclusion> + </exclusions> </dependency> @@ -115,7 +125,7 @@ <scope>provided</scope> </dependency> - <dependency> + <!--dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-velocity</artifactId> <version>1.1.7</version> @@ -133,7 +143,7 @@ <artifactId>velocity</artifactId> </exclusion> </exclusions> - </dependency> + </dependency--> <dependency> <groupId>log4j</groupId> @@ -191,6 +201,16 @@ <artifactId>plexus-sec-dispatcher</artifactId> </exclusion> + <exclusion> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity</artifactId> + </exclusion> + + <exclusion> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-velocity</artifactId> + </exclusion> + </exclusions> </dependency> @@ -290,9 +310,6 @@ <processor.version>1.0.2</processor.version> - <!-- TODO Remove this when mavenpom greater than 2.1 --> - <helper.version>1.2.3</helper.version> - <!-- version of project license descriptor model --> <mdoVersion>1.0.0</mdoVersion> Deleted: trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java 2010-04-12 12:15:05 UTC (rev 1744) +++ trunk/src/main/java/org/nuiton/license/plugin/AddLicenseFileMojo.java 2010-04-12 12:32:05 UTC (rev 1745) @@ -1,251 +0,0 @@ -/* - * #%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; - -import org.nuiton.license.plugin.model.License; -import org.nuiton.license.plugin.model.LicenseStore; -import org.nuiton.plugin.PluginHelper; - -import java.io.File; - -/** - * Le goal pour ajouter le fichier LICENSE.txt dans le classpath (et le generer - * s'il n'existe pas). - * - * @author tchemit <chemit@codelutin.com> - * @goal add-license - * @phase generate-resources - * @requiresProject true - * @requiresDependencyResolution compile - * @deprecated since 2.1, prefer use now the goal {@code update-project-license}. - */ -@Deprecated -public class AddLicenseFileMojo extends AbstractLicenseMojo { - - /** - * Fichier de la licence du module. - * - * @parameter expression="${license.licenceFile}" default-value="${basedir}/LICENSE.txt" - * @required - * @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> - * <pre> - * mvn helper:available-licenses -Ddetail - * </pre> - * - * @parameter expression="${license.licenseName}" - * @required - * @since 1.0.0 - */ - protected String licenseName; - - /** - * Repertoire de sortie des sources. - * - * @parameter expression="${license.outputDirectory}" - * default-value="target/generated-sources/license" - * @required - * @since 1.0.0 - */ - protected File outputDirectory; - - /** - * Repertoire de sortie des classes (classpath). - * - * @parameter expression="${license.licenceFilename}" default-value="" - * @since 1.0.0 - */ - protected String licenseFilename; - - /** - * Un flag pour conserver un backup des fichiers modifies. - * - * @parameter expression="${license.keepBackup}" default-value="false" - * @since 1.0.0 - */ - protected boolean keepBackup; - - /** - * Un flag pour forcer la generation. - * - * @parameter expression="${license.force}" default-value="false" - * @since 1.0.0 - */ - protected boolean force; - - /** - * 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) - * - * @parameter expression="${license.generateBundle}" default-value="false" - * @since 1.0.0 - */ - protected boolean copyToMETA_INF; - - /** - * La baseURL d'un resolver de license supplementaire - * - * @parameter expression="${license.extraResolver}" - * @since 1.0.0 - */ - protected String[] extraResolver; - - protected License license; - - boolean doGenerate; - - @Override - protected void init() throws Exception { - - // must generate if file does not exist - doGenerate = true; - - if (!force) { - // regenerate only if file exists and is newer than pom file - doGenerate = !isFileNewerThanPomFile(licenseFile); - } - - // acquire license - - LicenseStore licenseStore = createLicenseStore(extraResolver); - license = licenseStore.getLicense(licenseName); - - if (licenseFilename == null || licenseFilename.isEmpty()) { - licenseFilename = licenseName; - } - } - - @Override - protected void doAction() throws Exception { - getLog().info("using licence [" + licenseName + "]"); - - if (doGenerate) { - if (isVerbose()) { - getLog().info("detail : " + license); - } - - if (licenseFile.exists() && keepBackup) { - if (isVerbose()) { - getLog().info("backup " + licenseFile); - } - // copy it to backup file - backupFile(licenseFile); - } - } - - String licenseContent = license.getLicenseContent(getEncoding()); - - if (doGenerate) { - writeFile(licenseFile, licenseContent, getEncoding()); - } - - if (hasClassPath()) { - // copy LICENSE.txt to classpath - File target = new File(outputDirectory, licenseFile.getName()); - - copyFile(licenseFile, target); - - if (copyToMETA_INF) { - File destFile = PluginHelper.getFile( - outputDirectory, - "META-INF", getProject().getArtifactId() + "-" + - licenseFile.getName() - ); - copyFile(licenseFile, destFile); - } - addResourceDir(outputDirectory, "**/*.txt"); - } - } - - public File getLicenseFile() { - return licenseFile; - } - - public String getLicenseName() { - return licenseName; - } - - public License getLicense() { - return license; - } - - public String[] getExtraResolver() { - return extraResolver; - } - - public boolean isKeepBackup() { - return keepBackup; - } - - public boolean isForce() { - return force; - } - - public File getOutputDirectory() { - return outputDirectory; - } - - public void setLicenseFile(File licenseFile) { - this.licenseFile = licenseFile; - } - - public void setLicenseName(String licenseName) { - this.licenseName = licenseName; - } - - public void setExtraResolver(String[] extraResolver) { - this.extraResolver = extraResolver; - } - - public void setLicense(License license) { - this.license = license; - } - - public void setKeepBackup(boolean keepBackup) { - this.keepBackup = keepBackup; - } - - public void setOutputDirectory(File outputDirectory) { - this.outputDirectory = outputDirectory; - } - - public void setForce(boolean force) { - this.force = force; - } -} Deleted: trunk/src/main/java/org/nuiton/license/plugin/GeneratorListMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/GeneratorListMojo.java 2010-04-12 12:15:05 UTC (rev 1744) +++ trunk/src/main/java/org/nuiton/license/plugin/GeneratorListMojo.java 2010-04-12 12:32:05 UTC (rev 1745) @@ -1,99 +0,0 @@ -/* - * #%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; - -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 tchemit <chemit@codelutin.com> - * @requiresProject false - * @requiresDirectInvocation - * @goal generator-list - * @since 1.0.1 - * @deprecated since 2.1, use now the {@code comment(style-list} goal. - */ -@Deprecated -public class GeneratorListMojo extends AbstractLicenseMojo { - - /** - * Un drapeau pour afficher aussi le contenu des license. - * - * @parameter expression="${detail}" - * @since 1.0.1 - */ - protected boolean detail; - - /** - * All available generators - * - * @component role="org.nuiton.license.header.generator.HeaderGenerator" - */ - protected Map<String, HeaderGenerator> _generators; - - @Override - protected void init() throws Exception { - // nothing to do - } - - @Override - public void doAction() throws MojoExecutionException, MojoFailureException { - - // display it - StringBuilder buffer = new StringBuilder("\n"); - buffer.append("\n\n-------------------------------------------------------------------------------\n"); - buffer.append(" maven-license-plugin\n"); - buffer.append("-------------------------------------------------------------------------------\n\n"); - if (_generators == null || _generators.isEmpty()) { - buffer.append("No generator found.\n\n"); - } else { - buffer.append("List of available generators :\n\n"); - for (Entry<String, HeaderGenerator> e : _generators.entrySet()) { - HeaderGenerator generator = e.getValue(); - buffer.append(" - "); - buffer.append(e.getKey()); - buffer.append(" : "); - buffer.append(generator.getDescription()); - buffer.append("\n"); - if (detail) { - buffer.append("\n example : \n"); - buffer.append(generator.getHeader("content ")); - buffer.append('\n'); - } - } - } - getLog().info(buffer.toString()); - } -} Deleted: trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java 2010-04-12 12:15:05 UTC (rev 1744) +++ trunk/src/main/java/org/nuiton/license/plugin/UpdateHeaderMojo.java 2010-04-12 12:32:05 UTC (rev 1745) @@ -1,527 +0,0 @@ -/* - * #%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; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.VelocityEngine; -import org.apache.velocity.context.Context; -import org.codehaus.plexus.velocity.VelocityComponent; -import org.nuiton.license.plugin.header.generator.HeaderGenerator; -import org.nuiton.license.plugin.model.License; -import org.nuiton.license.plugin.model.LicenseStore; -import org.nuiton.plugin.PluginHelper; -import org.nuiton.processor.LicenseProcessor; - -import java.io.File; -import java.io.StringWriter; -import java.util.*; -import java.util.Map.Entry; - -/** - * The goal to update (or add) the licence header on some files. - * - * @author tchemit <chemit@codelutin.com> - * @requiresProject true - * @goal update-header - * @since 1.0.1 - * @deprecated since 1.2, use now the <b>update-header-file</b> goal instead. - */ -@Deprecated -public class UpdateHeaderMojo extends AbstractLicenseMojo { - - /** - * l'annee de creation du module (sera place dans le header) - * - * @parameter expression="${license.inceptionYear}" default-value="${project.inceptionYear}" - * @required - * @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}" - * @required - * @since 1.0.0 - */ - protected String organizationName; - - /** - * le nom du projet (sera place dans le header) - * - * @parameter expression="${license.projectName}" default-value="${project.name}" - * @required - * @since 1.0.0 - */ - protected String projectName; - - /** - * Le type de license a appliquer. - * - * @parameter expression="${license.licenseName}" - * @required - * @since 1.0.0 - */ - protected String licenseName; - - /** - * Le type de générateur a utiliser pour encapsuler le header. - * <p/> - * Par défaut, on veut utiliser le plugin sur des fichiers sources java. - * - * @parameter expression="${license.generatorName}" default-value="license-java" - * @required - * @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. - * <p/> - * Par défaut, on veut utiliser le plugin sur des fichiers sources java. - * - * @parameter expression="${license.includes}" default-value="**\/*.java" - * @required - * @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. - * <p/> - * Par défaut, on n'exclue rien. - * - * @parameter expression="${license.excludes}" - * @since 1.0.1 - */ - protected String excludes; - - /** - * Compile source directory roots to inspect. - * <p/> - * Can use it a a comma separated string : - * <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> - * <p/> - * <b>Note:</b> If not set, will use the build compile roots. - * - * @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 : - * <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> - * <p/> - * <b>Note:</b> If not set, will use the build test roots. - * - * @parameter expression="${license.testSourceRoots}" - * default-value="${project.testCompileSourceRoots}" - * @required - * @since 1.0.0 - */ - protected List<String> testSourceRoots; - - /** - * Un resolver externe - * - * @parameter expression="${license.licenseResolver}" - * @since 1.0.0 - */ - protected String licenseResolver; - - /** - * La template (velocity) a utiliser pour construire le header. - * <p/> - * Cette template doit être dans le class-path ou être un fichier existant - * - * @parameter expression="${license.template}" default-value="/license/defaultHeader.vm" - * @since 1.0.1 - */ - protected String template; - - /** - * Des paramètres supplémentaires à utiliser dans la template du header. - * - * @parameter - * @since 1.0.1 - */ - protected Map<String, String> templateParameters; - - /** - * Un flag pour conserver un backup des fichiers modifies. - * - * @parameter expression="${license.keepBackup}" default-value="false" - * @since 1.0.0 - */ - protected boolean keepBackup; - - /** - * A flag to skip the goal. - * - * @parameter expression="${skipUpdateLicense}" default-value="false" - * @since 1.0.3 - */ - protected boolean skipUpdateHeader; - - /** - * A flag to test plugin but modify no file. - * - * @parameter expression="${dryRun}" default-value="false" - * @since 1.0.3 - */ - protected boolean dryRun; - - /** - * Velocity Component. - * - * @component roleHint="maven-license-plugin" - * @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 */ - protected String licenseHeaderContent; - - /** 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 - */ - protected Map<File, String[]> filesToTreate; - - /** le timestamp utilise pour la generation */ - protected long timestamp; - - /** store of licenses */ - protected LicenseStore licenseStore; - - @Override - public boolean checkPackaging() { - return true; - } - - public void setCompileSourceRoots(String root) { - String[] roots = PluginHelper.splitAndTrim(root, ","); - setCompileSourceRoots(Arrays.asList(roots)); - } - - public void setCompileSourceRoots(List<String> compileSourceRoots) { - this.compileSourceRoots = compileSourceRoots; - } - - public void setTestSourceRoots(String root) { - String[] roots = PluginHelper.splitAndTrim(root, ","); - setTestSourceRoots(Arrays.asList(roots)); - } - - public void setTestSourceRoots(List<String> testSourceRoots) { - this.testSourceRoots = testSourceRoots; - } - - @Override - protected boolean checkSkip() { - if (skipUpdateHeader) { - getLog().info("skip flag is on, will skip goal."); - return false; - } - if (filesToTreate == null || filesToTreate.isEmpty()) { - getLog().info("No file to treate, will skip goal."); - return false; - } - return super.checkSkip(); - } - - @Override - public void init() throws Exception { - - if (skipUpdateHeader) { - return; - } - timestamp = System.nanoTime(); - - if (_generators == null) { - // should never happen... - throw new MojoExecutionException("no header generator found"); - } - if (isVerbose()) { - for (Entry<String, HeaderGenerator> e : _generators.entrySet()) { - Entry<String, HeaderGenerator> next = e; - getLog().info("config - available generator : " + next.getKey()); - } - if (compileSourceRoots != null) { - for (String root : compileSourceRoots) { - getLog().info("config - compile source root : " + root); - } - } - if (testSourceRoots != null) { - for (String root : testSourceRoots) { - getLog().info("config - test source root : " + root); - } - } - } - - if (!_generators.containsKey(generatorName.trim())) { - throw new MojoExecutionException( - "the generator named '" + generatorName + - "' is unknown (use generator-list goal to see all of them)"); - } - HeaderGenerator generator = _generators.get(generatorName); - - // obtain all files to be treated - - filesToTreate = new HashMap<File, String[]>(); - String[] in = includes.split(","); - String[] ex = excludes == null ? null : excludes.split(","); - getFilesToTreateForRoots(in, ex, compileSourceRoots, filesToTreate, null); - getFilesToTreateForRoots(in, ex, testSourceRoots, filesToTreate, null); - - if (filesToTreate.isEmpty()) { - return; - } - - File templateFile = new File(template); - - // verifie que la template existe (dans le class-path ou en tant que - // fichier) - checkResource(templateFile); - - // recuperation de la license a utiliser - licenseStore = createLicenseStore(licenseResolver); - - License license = licenseStore.getLicense(licenseName); - - if (isVerbose()) { - getLog().info("config - use license " + license.getName()); - getLog().info("config - use generator " + generator.getName()); - getLog().info("config - use template " + template); - } - // obtain content of license header - licenseHeaderContent = computeHeader(license, generator); - - // build the comment boxed header content - boxedLicenseHeaderContent = generator.getHeader(licenseHeaderContent); - if (isVerbose()) { - getLog().info("config - header to use\n" + - boxedLicenseHeaderContent); - } - - } - - @Override - protected void doAction() throws Exception { - - // create a licence processor with given header - LicenseProcessor p = new LicenseProcessor(licenseHeaderContent); - - for (Entry<File, String[]> entry : filesToTreate.entrySet()) { - File src = entry.getKey(); - for (String javaRelativePath : entry.getValue()) { - File file = new File(src, javaRelativePath); - - if (isVerbose()) { - getLog().info("process file " + file); - } - - // file where to writeFile result - File processFile = new File(file.getAbsolutePath() + "_" + - timestamp); - - try { - p.process(file, processFile); - boolean foundLicenseHeader = p.getLicenceFilter().wasTouched(); - - if (!foundLicenseHeader) { - if (p.getLicenceFilter().isDetectHeader()) { - getLog().warn( - "skip file " + file + - " (no license footer tag found : '##%*' !)"); - } else { - // no license header found in file, add it - getLog().info("adding license header on file " + file); - String content = PluginHelper.readAsString( - file, - getEncoding() - ); - content = boxedLicenseHeaderContent + content; - if (!dryRun) { - writeFile(processFile, content, getEncoding()); - } - } - } - - if (keepBackup && !dryRun) { - File backupFile = new File(file.getAbsolutePath() + "~"); - if (isVerbose()) { - getLog().debug("backup original file " + file); - } - renameFile(file, backupFile); - } - if (dryRun) { - deleteFile(processFile); - } else { - renameFile(processFile, file); - - } - - } catch (Exception e) { - getLog().warn( - "skip file " + file + " (could not process " + - "for reason : " + e.getMessage() + ")"); - deleteFile(processFile); - } finally { - // toujours cleaner les états du filtre du processeur - p.getLicenceFilter().reset(); - } - } - } - } - - /** - * Construction du header a utiliser. - * <p/> - * Le header est généré à partir de la template velocity donnée et de la - * license donnée. - * - * @param license the license to use to compute header - * @param generator the header generator used to compute header - * @return le header construit - * @throws Exception pour toute erreur pendant la construction du header - */ - protected String computeHeader(License license, - HeaderGenerator generator) throws Exception { - - // recuperation de la license a mettre dans le header - String licenseContent = license.getHeaderContent(getEncoding()); - - // defined inceptionYear (if year is older than now suffix with a - thisYear) - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - String thisYear = cal.get(Calendar.YEAR) + ""; - if (!thisYear.equals(inceptionYear)) { - inceptionYear = inceptionYear + " - " + thisYear; - } - - // preparation de l'environnement velocity - - Context context = new VelocityContext(); - - context.put("inceptionYear", inceptionYear); - context.put("projectName", projectName); - context.put("organizationName", organizationName); - context.put("licenseContent", licenseContent); - - if (templateParameters != null) { - for (Entry<String, String> e : templateParameters.entrySet()) { - context.put(e.getKey(), e.getValue()); - } - } - - if (isVerbose()) { - StringBuilder buffer = new StringBuilder(); - - buffer.append("config - parameters for template : "); - for (Object key : context.getKeys()) { - buffer.append("\n * "); - buffer.append(key); - buffer.append(" : "); - buffer.append(context.get(key + "")); - } - getLog().info(buffer.toString()); - } - - // generation du contenu via velocity - VelocityEngine engine = velocity.getEngine(); - - StringWriter writer = new StringWriter(); - - Template velocityTemplate = engine.getTemplate(template, getEncoding()); - - velocityTemplate.merge(context, writer); - - writer.flush(); - - writer.close(); - - // recuperation du contenu du texte genere - String r = writer.getBuffer().toString(); - - // prefixage de toutes les lignes par un " * " - String result = generator.prefixContent(r.trim() + "\n\n"); - - return '\n' + result; - } -} Modified: trunk/src/site/rst/index.rst =================================================================== --- trunk/src/site/rst/index.rst 2010-04-12 12:15:05 UTC (rev 1744) +++ trunk/src/site/rst/index.rst 2010-04-12 12:32:05 UTC (rev 1745) @@ -107,12 +107,6 @@ * `help`_ display help about the plugin (goals, usage). - * `add-license`_ add (and creates it if not found) the LICENSE.txt in the build (deprecated since 2.1). - - * `update-header`_ add or update license header on some files (deprecated since 2.1). - - * `generator-list`_ display list of available generators (deprecated since 2.1). - Usage ~~~~~ @@ -133,12 +127,6 @@ .. _add-third-party: add-third-party-mojo.html -.. _update-header: update-header-mojo.html - -.. _generator-list: generator-list-mojo.html - -.. _license-list: license-list-mojo.html - .. _help: help-mojo.html .. _usage: usage.html Modified: trunk/src/site/rst/usage.rst =================================================================== --- trunk/src/site/rst/usage.rst 2010-04-12 12:15:05 UTC (rev 1744) +++ trunk/src/site/rst/usage.rst 2010-04-12 12:32:05 UTC (rev 1745) @@ -158,52 +158,6 @@ for full detail see `help`_ detail page. -Deprecated goals since 2.1 -========================== - -Some has been deprecated since we used a unified license project descriptor. - -add-license goal -________________ - -**This goal is deprectaed since v 2.1** - -This goal creates or updates the LICENSE.txt file and add it in build. - -for full detail see `add-license`_ detail page. - -update-header goal -__________________ - -**This goal is deprectaed since v 2.1** - -Prefer use now the **update-file-header** goal. - -This goal adds or updates the license header on some files. - -for full detail see `update-header`_ detail page. - -generator-list goal -___________________ - -**This goal is deprectaed since v 2.1** - -This goal display of available header generators. - -Use it directly (and only) from commandline : - -:: - - mvn license:generator-list - -To display an example of each generator, use the *detail* parameter : - -:: - - mvn license:generator-list -Ddetail - -for full detail see `generator-list`_ detail page. - .. _update-project-license: update-project-license-mojo.html .. _update-file-header: update-file-header-mojo.html @@ -217,9 +171,3 @@ .. _help: help-mojo.html .. _nuiton-processor : http://maven-site.nuiton.org/processor/index.html - -.. _add-license: add-license-mojo.html - -.. _update-header: update-header-mojo.html - -.. _generator-list: generator-list-mojo.html Modified: trunk/src/site/site_en.xml =================================================================== --- trunk/src/site/site_en.xml 2010-04-12 12:15:05 UTC (rev 1744) +++ trunk/src/site/site_en.xml 2010-04-12 12:32:05 UTC (rev 1745) @@ -65,11 +65,6 @@ <item name="comment-style-list" href="comment-style-list-mojo.html"/> <item name="help" href="help-mojo.html"/> </item> - <item name="Deprecated goals" href="usage.html#deprecated-goals-since-2-1"> - <item name="add-license" href="add-license-mojo.html"/> - <item name="update-header" href="update-header-mojo.html"/> - <item name="generator-list" href="generator-list-mojo.html"/> - </item> </item> </menu> Deleted: trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java 2010-04-12 12:15:05 UTC (rev 1744) +++ trunk/src/test/java/org/nuiton/license/plugin/AddLicenseFileMojoTest.java 2010-04-12 12:32:05 UTC (rev 1745) @@ -1,132 +0,0 @@ -/* - * #%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; - -import org.junit.Test; -import org.nuiton.plugin.AbstractMojoTest; -import org.nuiton.plugin.PluginHelper; - -import java.io.File; -import java.io.IOException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 1.0 - * @deprecated since 2.1, will be remove soon. - */ -@Deprecated -public class AddLicenseFileMojoTest extends AbstractMojoTest<AddLicenseFileMojo> { - - @Override - protected String getGoalName(String methodName) { - return "add-license"; - } - - @Override - protected void setUpMojo(AddLicenseFileMojo mojo, File pomFile) throws Exception { - super.setUpMojo(mojo, pomFile); - // license is where the pom is - File outputDirectory = pomFile.getParentFile(); - mojo.setOutputDirectory(outputDirectory); - if (!outputDirectory.exists()) { - if (!outputDirectory.mkdirs()) { - 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())); - } - - @Test - public void testOne() throws Exception { - - AddLicenseFileMojo mojo = getMojo(); - - File licenseFile = mojo.getLicenseFile(); - long t0 = licenseFile.lastModified(); - - // always assume pom is older than any file - // since we can not ensure order of copy test resources - PluginHelper.setLastModified(mojo.getProject().getFile(), 0); - - // then executing the mojo, will do NOT change the licence file - mojo.execute(); - - long t1 = licenseFile.lastModified(); - - assertEquals(t0, t1); - - // force to override the license file - mojo.setForce(true); - - mojo.execute(); - t1 = licenseFile.lastModified(); - - assertTrue(t1 > t0); - } - - @Test - public void testTwo() throws Exception { - - AddLicenseFileMojo mojo = getMojo(); - - File licenseFile = mojo.getLicenseFile(); - long t0 = licenseFile.lastModified(); - - // always assume pom is older than any file - // since we can not ensure order of copy test resources - PluginHelper.setLastModified(mojo.getProject().getFile(), 0); - - // then executing the mojo, will do NOT change the licence file - mojo.execute(); - - long t1 = licenseFile.lastModified(); - - assertEquals(t0, t1); - - // force to override the license file - mojo.setForce(true); - - mojo.execute(); - t1 = licenseFile.lastModified(); - - assertTrue(t1 > t0); - } -} Deleted: trunk/src/test/java/org/nuiton/license/plugin/UpdateHeaderMojoTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/plugin/UpdateHeaderMojoTest.java 2010-04-12 12:15:05 UTC (rev 1744) +++ trunk/src/test/java/org/nuiton/license/plugin/UpdateHeaderMojoTest.java 2010-04-12 12:32:05 UTC (rev 1745) @@ -1,139 +0,0 @@ -/* - * #%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; - -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.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 1.0 - * @deprecated since 2.1, will be remove soon. - */ -@Deprecated -public class UpdateHeaderMojoTest extends AbstractMojoTest<UpdateHeaderMojo> { - - 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 - protected String getGoalName(String methodName) { - return "update-header"; - } - - @Test - public void bug_28() throws Exception { - - testPom(new String[]{_MUST_BE_THERE}, new String[]{}); - } - - @Test - public void java() throws Exception { - - testPom(new String[]{_MUST_BE_THERE}, new String[]{_LICENSE_TO_CHANGE_}); - } - - @Test - public void xml() throws Exception { - - testPom(new String[]{_MUST_BE_THERE}, new String[]{_LICENSE_TO_CHANGE_}); - } - - @Test - public void properties() throws Exception { - - testPom(new String[]{_MUST_BE_THERE}, new String[]{_LICENSE_TO_CHANGE_}); - } - - public void testPom(String[] mandatoryPatterns, - String[] excludePatterns) throws Exception { - - UpdateHeaderMojo mojo = getMojo(); - - mojo.execute(); - - for (Entry<File, String[]> entry : mojo.filesToTreate.entrySet()) { - File src = entry.getKey(); - for (String javaRelativePath : entry.getValue()) { - File f = new File(src, javaRelativePath); - - assertTrue("generated file " + f + " was not found...", - f.exists()); - - - String content = PluginHelper.readAsString(f, "utf-8"); - - if (mojo.isVerbose()) { - mojo.getLog().info("check generated file " + f); - } - for (String p : mandatoryPatterns) { - - checkPattern(f, content, p, true); - } - for (String p : excludePatterns) { - checkPattern(f, content, p, false); - } - } - } - } - - /** - * @param content - * @param pattern - * @param required - * @param f - * @throws IOException - * @deprecated since 2.1, prefer use the - * {@link #checkPattern(File, String, String, boolean)} method instead. - */ - @Deprecated - 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) - ); - } -}
participants (1)
-
tchemit@users.nuiton.org