Author: tchemit Date: 2009-05-11 19:54:46 +0000 (Mon, 11 May 2009) New Revision: 1525 Removed: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/JavaLicenseGenerator.java maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/XmlLicenseGenerator.java maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/SwitchLicensePlugin.java maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JavaLicenseGeneratorTest.java maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/XmlLicenseGeneratorTest.java Modified: maven-nuiton-project-helper-plugin/trunk/pom.xml maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/License.java maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/AbstractLicensePlugin.java maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/LicensePlugin.java maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/ThirdPartyPlugin.java maven-nuiton-project-helper-plugin/trunk/src/site/site.xml maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/BasePluginTestCase.java maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/codelutin/license/plugin/impl/LicensePluginTest/testOne.xml Log: first goals : * add-license * add-third-party Modified: maven-nuiton-project-helper-plugin/trunk/pom.xml =================================================================== --- maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/pom.xml 2009-05-11 19:54:46 UTC (rev 1525) @@ -6,19 +6,20 @@ <!-- ************************************************************* --> <!-- *** POM Relationships *************************************** --> <!-- ************************************************************* --> - <parent> - <groupId>org.codelutin</groupId> - <artifactId>lutinproject</artifactId> - <version>3.5.4</version> - </parent> + <!--parent> + <groupId>org.nuiton</groupId> + <artifactId>nuitonproject</artifactId> + <version>3.6.0-SNAPSHOT</version> + </parent--> - <artifactId>maven-license-switcher-plugin</artifactId> + <groupId>org.nuiton</groupId> + <artifactId>maven-nuiton-project-helper-plugin</artifactId> <version>1.0.0-SNAPSHOT</version> <dependencies> - <dependency> + <!--dependency> <groupId>org.codelutin</groupId> <artifactId>lutinprocessor</artifactId> <version>${processor.version}</version> @@ -30,7 +31,7 @@ <artifactId>lutinpluginutil</artifactId> <version>${lutinpluginutil.version}</version> <scope>compile</scope> - </dependency> + </dependency--> <dependency> <groupId>org.apache.maven.shared</groupId> @@ -68,16 +69,53 @@ <scope>provided</scope> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.6</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1.1</version> + <scope>compile</scope> + </dependency> + </dependencies> <!-- ************************************************************* --> <!-- *** Project Information ************************************* --> <!-- ************************************************************* --> - <name>Plugin maven pour switcher les licenses</name> + <name>Plugin maven d'aide pour les projets nuiton</name> - <description>Plugin pour switcher de license dans un module maven 2</description> - <inceptionYear>2008</inceptionYear> + <url>http://lutinbuilder.labs.libre-entreprise.org/maven-nuiton-project-helper-plugin</url> + <description>Plugin d'aide pour les projets nuiton</description> + <inceptionYear>2009</inceptionYear> + + <licenses> + <license> + <name>LGPL</name> + <url>http://www.gnu.org/licenses/lgpl.txt</url> + <distribution>repo</distribution> + </license> + </licenses> + + <developers> + <developer> + <id>tchemit</id> + <name>Tony Chemit</name> + <email>chemit@codelutin.com</email> + <organization>CodeLutin</organization> + <roles> + <role>Développeur</role> + </roles> + <timezone>+2</timezone> + </developer> + </developers> + <!-- ************************************************************* --> <!-- *** Build Settings ****************************************** --> <!-- ************************************************************* --> @@ -85,20 +123,48 @@ <packaging>maven-plugin</packaging> <properties> - <labs.id>12</labs.id> - <labs.project>lutinutil</labs.project> + + <!--labs.id>12</labs.id> + <labs.project>lutinutil</labs.project--> - <processor.version>0.18</processor.version> - <lutinpluginutil.version>0.5</lutinpluginutil.version> - <maven.version>2.0.10</maven.version> + <maven.src.dir>${basedir}/src</maven.src.dir> + <maven.compile.source>1.6</maven.compile.source> + <maven.compile.target>1.6</maven.compile.target> + + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + + <!-- to allow bad tests --> + <maven.test.testFailureIgnore>false</maven.test.testFailureIgnore> + + <!-- to skip tests (can use also profile notests) --> + <maven.test.skip>false</maven.test.skip> + + <!-- to control fork mode of tests --> + <maven.test.forkMode>never</maven.test.forkMode> + </properties> <build> <defaultGoal>install</defaultGoal> + <!--Ressources--> + + <testResources> + <testResource> + <directory>${maven.src.dir}/test/resources</directory> + <includes> + <include>**/*</include> + </includes> + <excludes> + <exclude>**/*~</exclude> + </excludes> + </testResource> + </testResources> + <plugins> <!-- plugin plugin --> @@ -136,25 +202,108 @@ </execution> </executions> </plugin> - <!-- plugin site --> - <plugin> - <artifactId>maven-site-plugin</artifactId> - <dependencies> - <dependency> - <groupId>org.codelutin</groupId> - <artifactId>doxia-module-jrst</artifactId> - <version>1.0.0</version> - </dependency> - </dependencies> - </plugin> + </plugins> + + <pluginManagement> + + <plugins> + + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <configuration> + <encoding>${project.build.sourceEncoding}</encoding> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>${maven.compile.source}</source> + <target>${maven.compile.target}</target> + <encoding>${project.build.sourceEncoding}</encoding> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.4.3</version> + <configuration> + <skip>${maven.test.skip}</skip> + <testFailureIgnore>${maven.test.testFailureIgnore}</testFailureIgnore> + <forkMode>${maven.test.forkMode}</forkMode> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-source-plugin</artifactId> + <version>2.1</version> + <inherited>true</inherited> + <executions> + <execution> + <id>attach-sources</id> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.5</version> + <configuration> + <docencoding>${project.reporting.outputEncoding}</docencoding> + <encoding>${project.reporting.outputEncoding}</encoding> + <charset>${project.reporting.outputEncoding}</charset> + <quiet>true</quiet> + </configuration> + <executions> + <execution> + <id>attach-javadocs</id> + <goals> + <goal>jar</goal> + </goals> + <configuration> + <attach>true</attach> + <quiet>true</quiet> + <!-- uniquement a partir de javadoc 2.5 --> + <!--skip>${maven.javadoc.skip}</skip--> + </configuration> + </execution> + </executions> + + </plugin> + + <plugin> + <artifactId>maven-site-plugin</artifactId> + <version>2.0</version> + <configuration> + <locales>fr</locales> + <siteDirectory>src/site</siteDirectory> + <inputEncoding>${project.reporting.outputEncoding}</inputEncoding> + <outputEncoding>${project.reporting.outputEncoding}</outputEncoding> + <generateReports>true</generateReports> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-release-plugin</artifactId> + <version>2.0-beta-9</version> + </plugin> + + </plugins> + </pluginManagement> </build> - <!--Site--> <reporting> <plugins> - <!--Site report's plugin--> <plugin> + <artifactId>maven-project-info-reports-plugin</artifactId> + <version>2.1.1-cl</version> + </plugin> + + <plugin> <artifactId>maven-plugin-plugin</artifactId> </plugin> </plugins> Deleted: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/JavaLicenseGenerator.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/JavaLicenseGenerator.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/JavaLicenseGenerator.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -1,13 +0,0 @@ -package org.codelutin.license; - -import org.codelutin.processor.filters.LicenseFilter; - -/** @author chemit */ -public class JavaLicenseGenerator implements LicenseGenerator { - - @Override - public String getHeader(String licenseHeaderContent) { - return "/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n"; - } - -} Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/License.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/License.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/License.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -1,13 +1,12 @@ package org.codelutin.license; -import org.codelutin.util.FileUtil; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.io.InputStream; import java.net.URL; +import org.codehaus.plexus.util.IOUtil; /** * The model of a license. @@ -18,10 +17,8 @@ /** the name of the licenses (ex lgpl-3.0) */ protected String name; - /** url of the license's content */ protected URL licenseURL; - /** url of the header's template */ protected URL headerURL; @@ -48,7 +45,8 @@ InputStream inputStream = licenseURL.openStream(); Reader r = new BufferedReader(new InputStreamReader(inputStream, encoding)); try { - return FileUtil.readAsString(r); + return IOUtil.toString(r); +// return FileUtil.readAsString(r); } finally { r.close(); } @@ -60,7 +58,8 @@ } Reader r = new BufferedReader(new InputStreamReader(headerURL.openStream(), encoding)); try { - return FileUtil.readAsString(r); + return IOUtil.toString(r); +// return FileUtil.readAsString(r); } finally { r.close(); } Deleted: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/XmlLicenseGenerator.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/XmlLicenseGenerator.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/XmlLicenseGenerator.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -1,13 +0,0 @@ -package org.codelutin.license; - -import org.codelutin.processor.filters.LicenseFilter; - -/** @author chemit */ -public class XmlLicenseGenerator implements LicenseGenerator { - - @Override - public String getHeader(String licenseHeaderContent) { - return "<!--\n\n/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n\n-->\n"; - } - -} \ No newline at end of file Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/AbstractLicensePlugin.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/AbstractLicensePlugin.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/AbstractLicensePlugin.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -18,12 +18,16 @@ */ package org.codelutin.license.plugin; +import java.io.ByteArrayInputStream; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import java.io.File; +import java.io.InputStream; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.io.RawInputStreamFacade; /** * Un MOJO de base pour les autres MOJO concrets avec les options communes. @@ -54,7 +58,6 @@ * @throws Exception if any */ protected abstract void doAction() throws Exception; - /** * Dependance du projet. * @@ -62,7 +65,6 @@ * @required */ protected MavenProject project; - /** * Repertoire de sortie des classes (classpath). * @@ -70,7 +72,6 @@ * @required */ protected File outputDirectory; - /** * Encoding a utiliser pour lire et ecrire les fichiers. * @@ -78,7 +79,6 @@ * @required */ protected String encoding; - /** * Un flag pour conserver un backup des fichiers modifies. * @@ -97,7 +97,6 @@ * @parameter expression="${license-switcher.force}" default-value="false" */ protected boolean force; - /** * Fichier ou ecrire les licences des dependances. * @@ -195,4 +194,49 @@ public void setPomFile(File pomFile) { this.pomFile = pomFile; } + + /** + * Does the actual copy of the file and logging. + * + * @param srcFile represents the file to copy. + * @param destFile file name of destination file. + * + * @throws MojoExecutionException with a message if an + * error occurs. + */ + protected void copyFile(File srcFile, File destFile) + throws MojoExecutionException { + try { + getLog().info("Copying " + srcFile.getName() + " to " + destFile); + + FileUtils.copyFile(srcFile, destFile); + + } catch (Exception e) { + throw new MojoExecutionException("Error copying from " + srcFile + " to " + destFile, e); + } + } + + /** + * Does the actual copy of the content to a fileand logging. + * + * @param content represents the content to write into file. + * @param destFile file name of destination file. + * @param encoding encoding to use to write file + * @throws MojoExecutionException with a message if an + * error occurs. + */ + protected void copyFile(String content, File destFile, String encoding) + throws MojoExecutionException { + try { + getLog().info("Copying content to " + destFile); + + InputStream in = new ByteArrayInputStream(content.getBytes(encoding)); + RawInputStreamFacade facade = new RawInputStreamFacade(in); + + FileUtils.copyStreamToFile(facade, destFile); + + } catch (Exception e) { + throw new MojoExecutionException("Error copying content to " + destFile, e); + } + } } Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/LicensePlugin.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/LicensePlugin.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/LicensePlugin.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -18,25 +18,23 @@ */ package org.codelutin.license.plugin.impl; -import org.apache.maven.plugin.MojoExecutionException; import org.codelutin.license.License; import org.codelutin.license.LicenseFactory; import org.codelutin.license.plugin.AbstractLicensePlugin; -import org.codelutin.util.FileUtil; import java.io.File; -import java.io.IOException; /** * Le goal pour ajouter le fichier LICENSE.txt dans le classpath (et le generer s'il n'existe pas). * * @author chemit - * @goal license + * @goal add-license * @phase generate-resources * @requiresProject true * @requiresDependencyResolution compile */ public class LicensePlugin extends AbstractLicensePlugin { + /** * Fichier de la licence du module. * @@ -45,7 +43,6 @@ * @readonly */ protected File licenseFile; - /** * Le type de license a appliquer. * @@ -53,14 +50,12 @@ * @required */ protected String licenseName; - /** * La baseURL d'un resolver de license supplementaire * * @parameter expression="${license-switcher.extraResolver}" */ protected String[] extraResolver; - protected License license; @Override @@ -107,23 +102,28 @@ File backup = new File(licenseFile.getAbsolutePath() + "~"); licenseFile.renameTo(backup); } - try { - FileUtil.writeString(licenseFile, license.getLicenseContent(encoding), encoding); +// try { + String licenseContent = license.getLicenseContent(encoding); - // copy LICENSE.txt to classpath - File target = new File(outputDirectory, licenseFile.getName()); + //FileUtil.writeString(licenseFile, licenseContent, encoding); - try { + // copy LICENSE.txt to classpath + File target = new File(outputDirectory, licenseFile.getName()); - FileUtil.copy(licenseFile, target); +// try { - } catch (IOException e) { - throw new MojoExecutionException("could not write file " + target + " for reason : " + e.getMessage(), e); - } + copyFile(licenseContent, licenseFile, encoding); - } catch (IOException e) { - throw new MojoExecutionException("could not write license file " + licenseFile + " for reason : " + e.getMessage(), e); - } + copyFile(licenseFile, target); + + +// } catch (IOException e) { +// throw new MojoExecutionException("could not write file " + target + " for reason : " + e.getMessage(), e); +// } +// +// } catch (IOException e) { +// throw new MojoExecutionException("could not write license file " + licenseFile + " for reason : " + e.getMessage(), e); +// } } public File getLicenseFile() { Deleted: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/SwitchLicensePlugin.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/SwitchLicensePlugin.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/SwitchLicensePlugin.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -1,339 +0,0 @@ -/** - * *##% Plugin maven pour switcher les licenses - * Copyright (C) 2008 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.codelutin.license.plugin.impl; - -import org.apache.maven.plugin.MojoExecutionException; -import org.codehaus.plexus.util.DirectoryScanner; -import org.codelutin.license.License; -import org.codelutin.license.LicenseFactory; -import org.codelutin.license.LicenseGenerator; -import org.codelutin.license.plugin.AbstractLicensePlugin; -import org.codelutin.processor.LicenseProcessor; -import org.codelutin.processor.filters.LicenseFilter; -import org.codelutin.util.FileUpdater; -import org.codelutin.util.FileUpdaterHelper; -import org.codelutin.util.FileUtil; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -/** - * Le goal pour switcher les licenses de tous les sources java d'un module - * maven. - * - * @author chemit - * @goal switch - * @phase process-resources - * @requiresProject true - */ -public class SwitchLicensePlugin extends AbstractLicensePlugin { - - /** - * l'annee de creation du module (sera place dans le header) - * - * @parameter default-value="${project.inceptionYear}" - * @required - */ - protected String inceptionYear; - - /** - * le nom de l'organisation (sera place dans le header) - * - * @parameter default-value="${project.organization.name}" - * @required - * @readonly - */ - protected String organizationName; - - /** - * le nom du projet (sera place dans le header) - * - * @parameter default-value="${project.name}" - * @required - * @readonly - */ - protected String projectName; - - /** - * Le type de license a appliquer. - * - * @parameter expression="${license-switcher.licenseName}" - * @required - */ - protected String licenseName; - - /** - * Repertoires des fichiers sources a traiter. - * - * @parameter expression="${license-switcher.compileSourceRoots}" default-value="${project.compileSourceRoots}" - * @required - */ - protected List<String> compileSourceRoots; - - /** - * Repertoires des fichiers sources de test a traiter. - * - * @parameter expression="${license-switcher.testCompileSourceRoots}" default-value="${project.testCompileSourceRoots}" - * @required - */ - protected List<String> testCompileSourceRoots; - - /** - * Repertoires du build des sources - * - * @parameter expression="${license-switcher.outputDirectory}" default-value="${project.build.outputDirectory}" - * @required - */ - protected File outputDirectory; - /** - * Repertoire du build des tests - * - * @parameter expression="${license-switcher.testOutputDirectory}" default-value="${project.build.testOutputDirectory}" - * @required - */ - protected File testOutputDirectory; - - /** - * Un resolver externe - * - * @parameter expression="${license-switcher.extraResolver}" - */ - protected String[] extraResolver; - - /** 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; - - @Override - protected boolean shouldSkip() { - return "pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()); - } - - @Override - protected boolean init() throws IOException { - - boolean doGenerate = force; - - timestamp = System.nanoTime(); - - // obtain all java source files to be treated - javaFilesToTreate = getFilesToTreate(); - - 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() { - - // init directory scanner - DirectoryScanner ds = new DirectoryScanner(); - ds.setIncludes(new String[]{"**\\/*.java"}); - - Map<File, String[]> files = new java.util.HashMap<File, String[]>(); - - getFilesToTreateForJavaRoots(ds, compileSourceRoots, outputDirectory, files); - - getFilesToTreateForJavaRoots(ds, testCompileSourceRoots, testOutputDirectory, files); - - return files; - } - - protected void getFilesToTreateForJavaRoots(DirectoryScanner ds, List<String> roots, File dstRoot, Map<File, String[]> files) { - - for (String src : roots) { - - File f = new File(src); - if (!f.exists()) { - // do nothing on a non-existent - continue; - } - - if (verbose) { - getLog().info("discovering java source files in root " + src); - } - - ds.setBasedir(f); - // scan - ds.scan(); - - // get files - String[] tmp = ds.getIncludedFiles(); - - if (tmp.length < 1) { - // no files found - continue; - } - - FileUpdater updater = FileUpdaterHelper.newJavaFileUpdater(f, dstRoot); - List<String> toTreate = new ArrayList<String>(); - - for (String filePath : tmp) { - File srcFile = new File(f, filePath); - // check file is up-to-date - if (!updater.isFileUpToDate(srcFile)) { - toTreate.add(filePath); - } - } - - if (toTreate.isEmpty()) { - // no file or all are up-to-date - continue; - } - - // register files - files.put(f, toTreate.toArray(new String[toTreate.size()])); - - } - } - - 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 java.io.IOException if IO pb - */ - protected void processJavaSource(LicenseProcessor p, File sourceFile) throws Exception { - - if (verbose) { - getLog().info("process file " + sourceFile); - } - - // file where to write 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 = FileUtil.readAsString(sourceFile, encoding); - content = "/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n" + content; - FileUtil.writeString(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 = FileUtil.readAsString(sourceFile, encoding); - content = "<!--\n\n/**\n * " + LicenseFilter.HEADER + " " + licenseHeaderContent + " " + LicenseFilter.FOOTER + "\n */\n" + content + " \n\n-->"; - FileUtil.writeString(processFile, content, encoding); - } - -} Modified: maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/ThirdPartyPlugin.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/ThirdPartyPlugin.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/main/java/org/codelutin/license/plugin/impl/ThirdPartyPlugin.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -26,7 +26,6 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.model.License; -import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; @@ -34,10 +33,8 @@ import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; import org.codelutin.license.plugin.AbstractLicensePlugin; -import org.codelutin.util.FileUtil; import java.io.File; -import java.io.IOException; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; @@ -47,7 +44,7 @@ * dans le classpath (et le generer s'il n'existe pas). * * @author chemit - * @goal third-party + * @goal add-third-party * @phase process-classes * @requiresDependencyResolution test * @requiresProject true @@ -55,7 +52,6 @@ public class ThirdPartyPlugin extends AbstractLicensePlugin { private static final String unknownLicenseMessage = "Unknown license"; - /** * Local Repository. * @@ -64,8 +60,6 @@ * @readonly */ protected ArtifactRepository localRepository; - - /** * Remote repositories used for the project. * @@ -73,8 +67,7 @@ * @required * @readonly */ - protected List remoteRepositories; - + protected List<?> remoteRepositories; /** * Fichier ou ecrire les licences des dependances. * @@ -82,42 +75,36 @@ * @required */ protected File thirdPartyFile; - /** * 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. @@ -128,7 +115,7 @@ protected boolean shouldSkip() { return "pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()); } - + @Override protected boolean init() throws Exception { @@ -178,11 +165,12 @@ } thirdPartyFile.renameTo(new File(thirdPartyFile.getAbsolutePath() + '~')); } - try { - FileUtil.writeString(thirdPartyFile, thirdPartyFileContent, encoding); - } catch (IOException e) { - throw new MojoExecutionException("could not write file " + thirdPartyFile + " for reason : " + e.getMessage(), e); - } + copyFile(thirdPartyFileContent, thirdPartyFile, encoding); +// try { +// FileUtil.writeString(thirdPartyFile, thirdPartyFileContent, encoding); +// } catch (IOException e) { +// throw new MojoExecutionException("could not write file " + thirdPartyFile + " for reason : " + e.getMessage(), e); +// } } /** @return resolve the dependency tree */ @@ -191,8 +179,7 @@ ArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_TEST); return dependencyTreeBuilder.buildDependencyTree(project, localRepository, factory, artifactMetadataSource, artifactFilter, collector); - } - catch (DependencyTreeBuilderException e) { + } catch (DependencyTreeBuilderException e) { getLog().error("Unable to build dependency tree.", e); return null; } @@ -217,7 +204,7 @@ MavenProject artifactProject = getMavenProjectFromRepository(artifact); String artifactName = getArtifactName(artifactProject); - List licenses = artifactProject.getLicenses(); + List<?> licenses = artifactProject.getLicenses(); if (licenses.isEmpty()) { // no license found for the dependency @@ -237,8 +224,7 @@ licenseMap.put(licenseKey, artifactName); } } - } - catch (ProjectBuildingException e) { + } catch (ProjectBuildingException e) { getLog().error("ProjectBuildingException error : ", e); } } @@ -306,9 +292,9 @@ } protected class LicenseMap extends java.util.TreeMap<String, SortedSet<String>> { + private static final long serialVersionUID = 864199843545688069L; - /** {@inheritDoc} */ public SortedSet<String> put(String key, String value) { // handle multiple values as a set to avoid duplicates SortedSet<String> valueList = get(key); Modified: maven-nuiton-project-helper-plugin/trunk/src/site/site.xml =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/site/site.xml 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/site/site.xml 2009-05-11 19:54:46 UTC (rev 1525) @@ -21,9 +21,9 @@ <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"/> + <!--logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="images/jrst-logo.png"/> <logo href="http://docutils.sourceforge.net/rst.html" name="ReStructuredText" - img="images/restructuredtext-logo.png"/> + img="images/restructuredtext-logo.png"/--> </poweredBy> <body> @@ -35,29 +35,31 @@ <menu name="Utilisateur"> <item name="Introduction" href="index.html"/> <item name="Goals" href="plugin-info.html"> - <item name="license" href="license-mojo.html"/> - <item name="third-party" href="third-party-mojo.html"/> - <item name="switch" href="switch-mojo.html"/> + <item name="add-license" href="add-license-mojo.html"/> + <item name="add-third-party" href="add-third-party-mojo.html"/> <item name="available-licenses" href="available-licenses-mojo.html"/> <item name="help" href="help-mojo.html"/> </item> - <item name="Usage" href="usage.html"/> - <item name="FAQ" href="faq.html"/> + <!--item name="Usage" href="usage.html"/> + <item name="FAQ" href="faq.html"/--> </menu> - <menu name="Examples"> + + <!--menu name="Examples"> <item name="Todo" href="Todo.html"/> - </menu> + </menu--> <menu name="Téléchargement"> - <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}" - name="Télécharger la dernière version"/> - <item href="${labs.builder.url}/org/codelutin/${project.artifactId}" - name="Voir toutes les versions"/> + <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}/${project.build.finalName}.jar" + name="Librairie (jar)"/> + <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}/${project.build.finalName}-javadoc.jar" + name="Javadoc (jar)"/> + <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}/${project.build.finalName}-sources.jar" + name="Sources (jar)"/> </menu> - <menu name="Développeur"> + <!--menu name="Développeur"> <item name="A faire" href="Todo.html"/> - </menu> + </menu--> <menu ref="reports"/> Modified: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/BaseLicenseTestCase.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -1,10 +1,15 @@ package org.codelutin.license; -import org.codelutin.util.FileUtil; +import java.io.ByteArrayInputStream; import org.junit.Assert; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.io.RawInputStreamFacade; /** @author chemit */ public abstract class BaseLicenseTestCase extends Assert { @@ -45,16 +50,30 @@ String content = ""; if (defFile.exists()) { - content = FileUtil.readAsString(defFile, encoding) + "\n"; + + content = IOUtil.toString(new FileInputStream(defFile), encoding) + "\n"; +// content = FileUtil.readAsString(defFile, encoding) + "\n"; } - FileUtil.writeString(defFile, content + licenseName + "=My dummy license\n", encoding); + + write(defFile, content + licenseName + "=My dummy license\n", encoding); +// FileUtil.writeString(defFile, content + licenseName + "=My dummy license\n", encoding); // create dummy licenses File file = new File(repo, licenseName); file.mkdirs(); - FileUtil.writeString(new File(file, "license.txt"), "license:" + licenseName, encoding); - FileUtil.writeString(new File(file, "header.txt"), "header:" + licenseName, encoding); + write(new File(file, "license.txt"), "license:" + licenseName, encoding); + write(new File(file, "header.txt"), "header:" + licenseName, encoding); +// FileUtil.writeString(new File(file, "license.txt"), "license:" + licenseName, encoding); +// FileUtil.writeString(new File(file, "header.txt"), "header:" + licenseName, encoding); } + + protected void write(File destFile, String content, String encoding) throws IOException { + + InputStream in = new ByteArrayInputStream(content.getBytes(encoding)); + RawInputStreamFacade facade = new RawInputStreamFacade(in); + + FileUtils.copyStreamToFile(facade, destFile); + } } Deleted: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JavaLicenseGeneratorTest.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JavaLicenseGeneratorTest.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/JavaLicenseGeneratorTest.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -1,24 +0,0 @@ -package org.codelutin.license; - -import org.junit.Before; -import org.junit.After; -import org.junit.Test; - -/** @author chemit */ -public class JavaLicenseGeneratorTest { - - @Before - public void setUp() { - // Add your code here - } - - @After - public void tearDown() { - // Add your code here - } - - @Test - public void testGetHeader() { - // Add your code here - } -} Deleted: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/XmlLicenseGeneratorTest.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/XmlLicenseGeneratorTest.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/XmlLicenseGeneratorTest.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -1,23 +0,0 @@ -package org.codelutin.license; - -import org.junit.Before; -import org.junit.After; -import org.junit.Test; - -/** @author chemit */ -public class XmlLicenseGeneratorTest { - @Before - public void setUp() { - // Add your code here - } - - @After - public void tearDown() { - // Add your code here - } - - @Test - public void testGetHeader() { - // Add your code here - } -} Modified: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/BasePluginTestCase.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/BasePluginTestCase.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/BasePluginTestCase.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -42,7 +42,8 @@ String rep = klass.getName(); rep = rep.replaceAll("\\.", File.separator); - File f = new File(getBaseDir(), "src" + File.separator + "test" + File.separator + "resources"); + File f = new File(getBaseDir(), "target" + File.separator + "test-classes"); + //File f = new File(getBaseDir(), "src" + File.separator + "test" + File.separator + "resources"); testDir = new File(f, rep); System.out.println("test dir : " + testDir); Modified: maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/test/java/org/codelutin/license/plugin/impl/LicensePluginTest.java 2009-05-11 19:54:46 UTC (rev 1525) @@ -43,11 +43,16 @@ } @Test - @PluginConfig(pomName = "testOne.xml", goalName = "license") + @PluginConfig(pomName = "testOne.xml", goalName = "add-license") public void testOne() throws MojoExecutionException, MojoFailureException { // Add your code here Assert.assertNotNull(this.mojo); + LicensePlugin p = (LicensePlugin) mojo; + + // always assume pom is older than any file + // since we can not ensure order of copy test resources + p.getPomFile().setLastModified(0); this.mojo.execute(); } Modified: maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/codelutin/license/plugin/impl/LicensePluginTest/testOne.xml =================================================================== --- maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/codelutin/license/plugin/impl/LicensePluginTest/testOne.xml 2009-05-11 17:49:30 UTC (rev 1524) +++ maven-nuiton-project-helper-plugin/trunk/src/test/resources/org/codelutin/license/plugin/impl/LicensePluginTest/testOne.xml 2009-05-11 19:54:46 UTC (rev 1525) @@ -2,28 +2,29 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.codelutin</groupId> - <artifactId>lutinproject</artifactId> - <version>3.3</version> - </parent> + + <groupId>org.nuiton</groupId> + <artifactId>maven-nuiton-project-helper-plugin-testOne</artifactId> + <version>0</version> + <build> <plugins> <plugin> - <groupId>org.codelutin</groupId> - <artifactId>maven-license-switcher-plugin</artifactId> + <groupId>org.nuiton</groupId> + <artifactId>maven-nuiton-project-helper-plugin</artifactId> <configuration> - <encoding>UTF-8</encoding> + <encoding>UTF-8</encoding> <licenseName>lgpl_v3</licenseName> <licenseFile>licenseOne.txt</licenseFile> <pomFile>testOne.xml</pomFile> <outputDirectory>target/tests/LicenPluginTest/test-java</outputDirectory> + <verbose>true</verbose> </configuration> <executions> <execution> <goals> - <goal>license</goal> + <goal>add-license</goal> </goals> </execution> </executions>