Author: tchemit Date: 2009-08-23 17:20:00 +0200 (Sun, 23 Aug 2009) New Revision: 1625 Removed: trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java Modified: trunk/pom.xml trunk/src/site/site.xml Log: bump versions + use jrst in site + clean site.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-08-16 08:46:34 UTC (rev 1624) +++ trunk/pom.xml 2009-08-23 15:20:00 UTC (rev 1625) @@ -9,7 +9,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom</artifactId> - <version>1.0.0-rc-5-SNAPSHOT</version> + <version>1.0.0</version> </parent> <artifactId>maven-license-plugin</artifactId> @@ -18,9 +18,9 @@ <dependencies> <dependency> - <groupId>org.nuiton.nuiton-processor</groupId> + <groupId>org.nuiton.processor</groupId> <artifactId>nuiton-processor</artifactId> - <version>1.0.0-rc-3</version> + <version>${processor.version}</version> <scope>compile</scope> </dependency> @@ -35,7 +35,7 @@ <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> - <version>1.5.5</version> + <version>1.5.15</version> <scope>compile</scope> </dependency> @@ -87,10 +87,16 @@ <packaging>maven-plugin</packaging> + <properties> + + <processor.version>1.0.0</processor.version> + + </properties> + <build> <defaultGoal>install</defaultGoal> - + <plugins> <plugin> @@ -106,6 +112,21 @@ </plugins> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-site-plugin</artifactId> + <dependencies> + <dependency> + <groupId>org.nuiton.jrst</groupId> + <artifactId>doxia-module-jrst</artifactId> + <version>1.0.0</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </pluginManagement> + </build> <reporting> Deleted: trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java 2009-08-16 08:46:34 UTC (rev 1624) +++ trunk/src/main/java/org/nuiton/license/plugin/SwitchLicensePlugin.java 2009-08-23 15:20:00 UTC (rev 1625) @@ -1,348 +0,0 @@ -/** - * *##% Plugin maven de changement de license - * Copyright (C) 2008 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ -package org.nuiton.license.plugin; - -import org.apache.maven.plugin.MojoExecutionException; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import org.apache.maven.project.MavenProject; -import org.nuiton.AbstractPlugin; -import org.nuiton.license.License; -import org.nuiton.license.LicenseFactory; -import org.nuiton.license.LicenseGenerator; -import org.nuiton.processor.LicenseProcessor; -import org.nuiton.processor.filters.LicenseFilter; -import org.nuiton.util.FileUpdaterHelper; -import org.nuiton.util.MirroredFileUpdater; -import org.nuiton.util.PluginHelper; - -/** - * Le goal pour switcher les licenses de tous les sources java d'un module - * maven. - * - * @author chemit - * @goal switch - * @phase process-resources - * @requiresProject true - * @deprecated since 1.0.0 prefer use {@link UpdateJavaHeaderPlugin} goal - */ -@Deprecated -public class SwitchLicensePlugin extends AbstractPlugin { - - /** - * Dependance du projet. - * - * @parameter default-value="${project}" - * @required - * @since 1.0.0 - */ - protected MavenProject project; - /** - * Encoding a utiliser pour lire et ecrire les fichiers. - * - * @parameter expression="${license.encoding}" default-value="${project.build.sourceEncoding}" - * @required - * @since 1.0.0 - */ - protected String encoding; - /** - * Un flag pour forcer la generation. - * - * @parameter expression="${license.force}" default-value="false" - * @since 1.0.0 - */ - protected boolean force; - /** - * 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; - /** - * Repertoires des fichiers sources a traiter. - * - * @parameter expression="${license.compileSourceRoots}" default-value="${project.compileSourceRoots}" - * @required - * @since 1.0.0 - */ - protected List<String> compileSourceRoots; - /** - * Repertoires des fichiers sources de test a traiter. - * - * @parameter expression="${license.testCompileSourceRoots}" default-value="${project.testCompileSourceRoots}" - * @required - * @since 1.0.0 - */ - protected List<String> testCompileSourceRoots; - /** - * Repertoire de sortie des classes (classpath). - * - * @parameter expression="${license.outputDirectory}" default-value="${project.build.outputDirectory}" - * @required - * @since 1.0.0 - */ - protected File outputDirectory; - /** - * Repertoire du build des tests - * - * @parameter expression="${license.testOutputDirectory}" default-value="${project.build.testOutputDirectory}" - * @required - * @since 1.0.0 - */ - protected File testOutputDirectory; - /** - * Un resolver externe - * - * @parameter expression="${license.extraResolver}" - * @since 1.0.0 - */ - protected String[] extraResolver; - /** - * 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 activer le mode verbeux. - * - * @parameter expression="${license.verbose}" default-value="${maven.verbose}" - * @since 1.0.0 - */ - protected boolean verbose; - /** le header a ajouter dans chaque fichier source java */ - protected String licenseHeaderContent; - /** la liste des chemin relatifs des sources java a traiter pour chaque repertoire contenant des sources */ - protected Map<File, String[]> javaFilesToTreate; - protected Map<LicenseGenerator, List<String>> generators; - protected long timestamp; - - public SwitchLicensePlugin() { - super("all files are up-to-date."); - } - - @Override - public boolean ensurePackaging() { - return "pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()); - } - - @Override - public boolean init() throws IOException { - - timestamp = System.nanoTime(); - - // obtain all java source files to be treated - javaFilesToTreate = getFilesToTreate(); - - boolean doGenerate = !javaFilesToTreate.isEmpty(); - - if (doGenerate) { - - LicenseFactory factory = LicenseFactory.newInstance(extraResolver); - License license = factory.revolv(licenseName); - - // obtain content of license header - licenseHeaderContent = computeHeader(license); - - if (verbose) { - getLog().info("header to write on java source files \n" + licenseHeaderContent); - } - } - - return doGenerate; - } - - @Override - protected void doAction() throws Exception { - // create a licence processor with given header - LicenseProcessor p = new LicenseProcessor(licenseHeaderContent); - - for (Entry<File, String[]> entry : javaFilesToTreate.entrySet()) { - File src = entry.getKey(); - for (String javaRelativePath : entry.getValue()) { - File sourceFile = new File(src, javaRelativePath); - try { - processJavaSource(p, sourceFile); - } catch (Exception e) { - throw new MojoExecutionException("could not treate java source file " + sourceFile + " for reason : " + e.getMessage(), e); - } - } - } - } - - protected Map<File, String[]> getFilesToTreate() { - - Map<File, String[]> files = new java.util.HashMap<File, String[]>(); - - MirroredFileUpdater updater = null; - if (!force) { - updater = FileUpdaterHelper.newJavaFileUpdater(); - updater.setDestinationDirectory(outputDirectory); - } - getFilesToTreateForRoots(new String[]{"**\\/*.java"}, null, compileSourceRoots, files, updater); - if (!force) { - updater.setDestinationDirectory(testOutputDirectory); - } - getFilesToTreateForRoots(new String[]{"**\\/*.java"}, null, testCompileSourceRoots, files, updater); - - return files; - } - - protected String computeHeader(License license) throws IOException { - - - String tmpHeader = license.getHeaderContent(encoding); - - // 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; - } - - // format header with projet informations - tmpHeader = String.format(tmpHeader, projectName, inceptionYear, organizationName); - - // add " * " before each line - BufferedReader reader = new BufferedReader(new java.io.StringReader(tmpHeader)); - StringBuilder sb = new StringBuilder(); - - String line = reader.readLine(); - sb.append(line).append('\n'); - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.isEmpty()) { - sb.append(" *\n"); - } else { - sb.append(" * ").append(line).append("\n"); - } - } - tmpHeader = sb.toString(); - return tmpHeader.substring(0, tmpHeader.length() - 1); - } - - /** - * @param p license processor - * @param sourceFile the java source file where to switch (or add the licence) - * @throws Exception if IO pb - */ - protected void processJavaSource(LicenseProcessor p, File sourceFile) throws Exception { - - if (verbose) { - getLog().info("process file " + sourceFile); - } - - // file where to writeFile result - File processFile = new File(sourceFile.getAbsolutePath() + "_" + timestamp); - - try { - p.process(sourceFile, processFile); - - if (!p.getLicenceFilter().wasTouched()) { - // no license header found in file, add it - addLicenseToJavaSourceFile(sourceFile, processFile); - } - - if (keepBackup) { - File backupFile = new File(sourceFile.getAbsolutePath() + "~"); - if (verbose) { - getLog().debug("backup original file " + sourceFile); - } - sourceFile.renameTo(backupFile); - } - processFile.renameTo(sourceFile); - - } catch (Exception e) { - getLog().error("could not process file " + sourceFile + " for reason " + e.getMessage(), e); - processFile.delete(); - throw e; - } finally { - p.getLicenceFilter().reset(); - } - } - - protected void addLicenseToJavaSourceFile(File sourceFile, File processFile) throws IOException { - getLog().warn("no license was found on file " + sourceFile + ", adding one"); - String content = PluginHelper.readAsString(sourceFile, encoding); - content = "/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n" + content; - writeFile(processFile, content, encoding); - } - - protected void addLicenseToXmlSourceFile(File sourceFile, File processFile) throws IOException { - getLog().warn("no license was found on file " + sourceFile + ", adding one"); - String content = PluginHelper.readAsString(sourceFile, encoding); - content = "<!--\n\n/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n" + content + " \n\n-->"; - writeFile(processFile, content, encoding); - } - - @Override - public boolean isVerbose() { - return verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public MavenProject getProject() { - return project; - } - - @Override - public void setProject(MavenProject project) { - this.project = project; - } -} Modified: trunk/src/site/site.xml =================================================================== --- trunk/src/site/site.xml 2009-08-16 08:46:34 UTC (rev 1624) +++ trunk/src/site/site.xml 2009-08-23 15:20:00 UTC (rev 1625) @@ -1,24 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <project name="${project.name}"> - <publishDate format="dd/MM/yyyy"/> - - <skin> - <groupId>org.nuiton</groupId> - <artifactId>maven-nuiton-skin</artifactId> - <version>1.0.0</version> - </skin> - <bannerLeft> <name>${project.name}</name> <href>index.html</href> </bannerLeft> - <bannerRight> - <src>http://www.codelutin.com/images/lutinorange-codelutin.png</src> - <href>${project.organization.url}</href> - </bannerRight> - <poweredBy> <logo href="http://maven.apache.org" name="Maven" img="images/logos/maven-feather.png"/> <logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="images/jrst-logo.png"/>