r599 - in trunk: . src/main/java/org/nuiton/io src/main/java/org/nuiton/io/plugin src/main/java/org/nuiton/license src/main/java/org/nuiton/license/plugin src/main/java/org/nuiton/mail/plugin src/main/java/org/nuiton/plugin src/main/java/org/nuiton/util src/site/apt src/test/java/org/nuiton src/test/java/org/nuiton/io src/test/java/org/nuiton/license src/test/java/org/nuiton/license/plugin src/test/java/org/nuiton/plugin src/test/resources/org/nuiton src/test/resources/org/nuit
Author: tchemit Date: 2009-09-29 12:32:02 +0200 (Tue, 29 Sep 2009) New Revision: 599 Added: trunk/src/main/java/org/nuiton/io/FileUpdater.java trunk/src/main/java/org/nuiton/io/FileUpdaterHelper.java trunk/src/main/java/org/nuiton/io/MirroredFileUpdater.java trunk/src/main/java/org/nuiton/io/PropertiesDateRemoveFilterStream.java trunk/src/main/java/org/nuiton/io/SortedProperties.java trunk/src/main/java/org/nuiton/io/plugin/ trunk/src/main/java/org/nuiton/io/plugin/CollectFilesMojo.java trunk/src/main/java/org/nuiton/plugin/DependencyUtil.java trunk/src/main/java/org/nuiton/plugin/PluginHelper.java trunk/src/main/java/org/nuiton/plugin/PluginIOContext.java trunk/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java trunk/src/test/java/org/nuiton/io/ trunk/src/test/java/org/nuiton/io/JavaFileUpdaterTest.java trunk/src/test/java/org/nuiton/io/JaxxFileUpdaterTest.java trunk/src/test/resources/org/nuiton/io/ trunk/src/test/resources/org/nuiton/io/JavaDummy.java trunk/src/test/resources/org/nuiton/io/JaxxDummy.java trunk/src/test/resources/org/nuiton/io/JaxxDummy.jaxx Removed: trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java Modified: trunk/pom.xml trunk/src/main/java/org/nuiton/license/JarLicenseResolver.java trunk/src/main/java/org/nuiton/license/License.java trunk/src/main/java/org/nuiton/license/LicenseFactory.java trunk/src/main/java/org/nuiton/license/LicenseResolver.java trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java trunk/src/main/java/org/nuiton/mail/plugin/SendEmailMojo.java trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java trunk/src/main/java/org/nuiton/plugin/Plugin.java trunk/src/main/java/org/nuiton/util/DependencyUtil.java trunk/src/main/java/org/nuiton/util/FileUpdater.java trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java trunk/src/main/java/org/nuiton/util/PluginHelper.java trunk/src/main/java/org/nuiton/util/PluginIOContext.java trunk/src/main/java/org/nuiton/util/SourceEntry.java trunk/src/main/java/org/nuiton/util/VelocityTemplateGenerator.java trunk/src/site/apt/index.apt trunk/src/site/apt/mojoTestFramework.apt trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java trunk/src/test/java/org/nuiton/license/JarLicenseResolverTest.java trunk/src/test/java/org/nuiton/license/LicenseFactoryTest.java trunk/src/test/java/org/nuiton/license/LicenseResolverTest.java trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java trunk/src/test/java/org/nuiton/plugin/TestHelper.java Log: [Evolution #65] : reorganisation des packages [Evolution #66] : ajout documentation framework mojo et test mojo Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/pom.xml 2009-09-29 10:32:02 UTC (rev 599) @@ -10,7 +10,7 @@ <groupId>org.nuiton</groupId> <artifactId>maven-helper-plugin</artifactId> - <version>1.0.3-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <dependencies> Copied: trunk/src/main/java/org/nuiton/io/FileUpdater.java (from rev 580, trunk/src/main/java/org/nuiton/util/FileUpdater.java) =================================================================== --- trunk/src/main/java/org/nuiton/io/FileUpdater.java (rev 0) +++ trunk/src/main/java/org/nuiton/io/FileUpdater.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,40 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.io; + +import java.io.File; + +/** + * Contract to be realized to test if a file is up to date. + * <p/> + * use {@link #isFileUpToDate(java.io.File)} to determine if a file is up to date. + * + * @author chemit + */ +public interface FileUpdater { + + /** + * @param f file to test + * @return <code>true</code> if file is up to date, <code>false</code> otherwise + */ + boolean isFileUpToDate(File f); + +} Property changes on: trunk/src/main/java/org/nuiton/io/FileUpdater.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/main/java/org/nuiton/io/FileUpdaterHelper.java (from rev 580, trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java) =================================================================== --- trunk/src/main/java/org/nuiton/io/FileUpdaterHelper.java (rev 0) +++ trunk/src/main/java/org/nuiton/io/FileUpdaterHelper.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,81 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.io; + +import java.io.File; + +/** @author chemit */ +public class FileUpdaterHelper { + + static public MirroredFileUpdater newJavaFileUpdater() { + return newJavaFileUpdater(null, null); + } + + static public MirroredFileUpdater newJaxxFileUpdater() { + return newJaxxFileUpdater(null, null); + } + + static public MirroredFileUpdater newJavaFileUpdater(File src, File dst) { + return new JavaFileUpdater(src, dst); + } + + static public MirroredFileUpdater newJaxxFileUpdater(File src, File dst) { + return new JaxxFileUpdater(src, dst); + } + + /** + * To test if a java source file is newser than his compiled class + * + * @author chemit + */ + public static class JavaFileUpdater extends MirroredFileUpdater { + + protected JavaFileUpdater(File sourceDirectory, File destinationDirectory) { + super(".java", ".class", sourceDirectory, destinationDirectory); + } + + @Override + public File getMirrorFile(File f) { + String file = f.getAbsolutePath().substring(prefixSourceDirecotory); + String mirrorRelativePath = file.substring(0, file.length() - 4) + "class"; + return new File(destinationDirectory + File.separator + mirrorRelativePath); + } + } + + /** + * To test if a jaxx source file is newser than his generated java source file + * + * @author chemit + */ + public static class JaxxFileUpdater extends MirroredFileUpdater { + + protected JaxxFileUpdater(File sourceDirectory, File destinationDirectory) { + super(".jaxx", ".java", sourceDirectory, destinationDirectory); + } + + @Override + public File getMirrorFile(File f) { + String file = f.getAbsolutePath().substring(prefixSourceDirecotory); + String mirrorRelativePath = file.substring(0, file.length() - 4) + "java"; + return new File(destinationDirectory + File.separator + mirrorRelativePath); + } + } +} Property changes on: trunk/src/main/java/org/nuiton/io/FileUpdaterHelper.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/main/java/org/nuiton/io/MirroredFileUpdater.java (from rev 580, trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java) =================================================================== --- trunk/src/main/java/org/nuiton/io/MirroredFileUpdater.java (rev 0) +++ trunk/src/main/java/org/nuiton/io/MirroredFileUpdater.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,115 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.io; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.File; + +/** + * Simple base implementation of a {@link FileUpdater} for an updater with a sourcedir and a destinationdir. + * + * @author chemit + */ +public class MirroredFileUpdater implements FileUpdater { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private final Log log = LogFactory.getLog(MirroredFileUpdater.class); + /** source basedir */ + protected File sourceDirectory; + /** length of source basedir absolute path */ + protected int prefixSourceDirecotory; + /** destination basedir */ + protected File destinationDirectory; + protected String fileInPattern = ""; + protected String fileOutPattern = ""; + + public MirroredFileUpdater(String fileInPattern, String fileOutPattern, File sourceDirectory, File destinationDirectory) { + this.fileInPattern = fileInPattern; + this.fileOutPattern = fileOutPattern; + this.sourceDirectory = sourceDirectory; + this.destinationDirectory = destinationDirectory; + if (sourceDirectory != null) { + this.prefixSourceDirecotory = sourceDirectory.getAbsolutePath().length(); + } + if (log.isDebugEnabled()) { + log.debug(this); + } + } + + public File getSourceDirectory() { + return sourceDirectory; + } + + public File getDestinationDirectory() { + return destinationDirectory; + } + + public String getFileInPattern() { + return fileInPattern; + } + + public String getFileOutPattern() { + return fileOutPattern; + } + + public File getMirrorFile(File f) { + String filename = f.getName(); + String file = f.getAbsolutePath().substring(prefixSourceDirecotory); + file = file.substring(0, file.length() - filename.length()); + String destFilename = applyTransformationFilename(filename); + String mirrorRelativePath = file + destFilename; + return new File(destinationDirectory + File.separator + mirrorRelativePath); + } + + @Override + public boolean isFileUpToDate(File f) { + File mirror = getMirrorFile(f); + return mirror.exists() && f.lastModified() < mirror.lastModified(); + } + + public void setDestinationDirectory(File destinationDirectory) { + this.destinationDirectory = destinationDirectory; + } + + public void setSourceDirectory(File sourceDirectory) { + this.sourceDirectory = sourceDirectory; + this.prefixSourceDirecotory = sourceDirectory.getAbsolutePath().length(); + } + + public void setFileInPattern(String fileInPattern) { + this.fileInPattern = fileInPattern; + } + + public void setFileOutPattern(String fileOutPattern) { + this.fileOutPattern = fileOutPattern; + } + + public String applyTransformationFilename(String filename) { + return filename.replaceAll(fileInPattern, fileOutPattern); + } + + @Override + public String toString() { + return super.toString() + "<srcdir:" + sourceDirectory + ", destdir:" + destinationDirectory + ">"; + } +} Property changes on: trunk/src/main/java/org/nuiton/io/MirroredFileUpdater.java ___________________________________________________________________ Added: svn:mergeinfo + Added: trunk/src/main/java/org/nuiton/io/PropertiesDateRemoveFilterStream.java =================================================================== --- trunk/src/main/java/org/nuiton/io/PropertiesDateRemoveFilterStream.java (rev 0) +++ trunk/src/main/java/org/nuiton/io/PropertiesDateRemoveFilterStream.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,41 @@ +package org.nuiton.io; + +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * Un ecrivain qui supprime la premiere ligne rencontree dans le flux. + * + * + * <b>Note: </b> Attention, les performance d'utilisation de cet ecrivain + * est problèmatique, car sur de gros fichiers (>1000 entrees) les + * performances se degradent serieusement : pour 1200 entrees on arrive à + * plus de 5 secondes, alors que sans on a 76 ms! ... + * + * FIXME : implanter quelque chose de plus performant dans tous les cas + */ +public class PropertiesDateRemoveFilterStream extends FilterOutputStream { + + private boolean firstLineOver; + char endChar; + + public PropertiesDateRemoveFilterStream(OutputStream out) { + super(out); + firstLineOver = false; + String lineSeparator = System.getProperty("line.separator"); + endChar = lineSeparator.charAt(lineSeparator.length() - 1); + } + + @Override + public void write(int b) throws IOException { + if (!firstLineOver) { + char c = (char) b; + if (c == endChar) { + firstLineOver = true; + } + } else { + out.write(b); + } + } +} Property changes on: trunk/src/main/java/org/nuiton/io/PropertiesDateRemoveFilterStream.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/main/java/org/nuiton/io/SortedProperties.java =================================================================== --- trunk/src/main/java/org/nuiton/io/SortedProperties.java (rev 0) +++ trunk/src/main/java/org/nuiton/io/SortedProperties.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,101 @@ +package org.nuiton.io; + +import org.nuiton.plugin.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.Properties; +import java.util.Vector; + +/** + * Permet d'avoir les fichiers de proprietes tries. + * + * @author julien + * @author chemit + */ +public class SortedProperties extends Properties { + + private static final long serialVersionUID = -1147150444452577558L; + /** l'encoding a utiliser pour lire et ecrire le properties. */ + protected String encoding; + /** un drapeau pour savoir s'il faut enlever l'entete generere */ + protected boolean removeHeader; + + public SortedProperties(String encoding) { + this(encoding, true); + } + + public SortedProperties(String encoding, boolean removeHeader) { + super(); + this.encoding = encoding; + this.removeHeader = removeHeader; + } + + public SortedProperties(Properties defaults) { + super(defaults); + } + + @Override + public synchronized Enumeration<Object> keys() { + List<Object> objects = Collections.list(super.keys()); + Vector<Object> result; + try { + // Attention, si les clef ne sont pas des string, ca ne marchera pas + List<String> list = PluginHelper.toGenericList(objects, String.class); + Collections.sort(list); + result = new Vector<Object>(list); + } catch (IllegalArgumentException e) { + // keys are not string !!! + // can not sort keys + result = new Vector<Object>(objects); + } + return result.elements(); + } + + /** + * Charge le properties a partir d'un fichier. + * + * @param src le fichier src a charger en utilisant l'encoding declare + * @return l'instance du properties + * @throws IOException if any io pb + */ + public SortedProperties load(File src) throws IOException { + super.load(new InputStreamReader(new FileInputStream(src), encoding)); + return this; + } + + /** + * Sauvegarde le properties dans un fichier, sans commentaire et en utilisant l'encoding declare. + * + * @param dst the fichier de destination + * @throws IOException if any io pb + */ + public void store(File dst) throws IOException { + if (removeHeader) { + super.store(new OutputStreamWriter(new PropertiesDateRemoveFilterStream(new FileOutputStream(dst)), encoding), null); + } else { + super.store(new FileOutputStream(dst), null); + } + } + + /** + * Sauvegarde le properties dans un fichier, sans commentaire en laissant java encode en unicode. + * + * @param dst le fichier de destination + * @throws IOException if any io pb + */ + public void store(OutputStream dst) throws IOException { + if (removeHeader) { + super.store(new PropertiesDateRemoveFilterStream(dst), null); + } else { + super.store(dst, null); + } + } +} Property changes on: trunk/src/main/java/org/nuiton/io/SortedProperties.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Copied: trunk/src/main/java/org/nuiton/io/plugin/CollectFilesMojo.java (from rev 587, trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java) =================================================================== --- trunk/src/main/java/org/nuiton/io/plugin/CollectFilesMojo.java (rev 0) +++ trunk/src/main/java/org/nuiton/io/plugin/CollectFilesMojo.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,421 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.io.plugin; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.nuiton.plugin.AbstractPlugin; + +/** + * Collect files some files from a project and copy them into a directory. + * + * @goal collect-files + * @requiresProject true + * + * @author tchemit + * @since 1.0.3 + */ +public class CollectFilesMojo extends AbstractPlugin { + + /** + * Dependance du projet. + * + * @parameter default-value="${project}" + * @required + * @readonly + * @since 1.0.3 + */ + protected MavenProject project; + /** + * The artifacts to publish from the project build. + * + * @parameter expression="${project.attachedArtifacts}" + * @required + * @readonly + * @since 1.0.0 + */ + protected List attachedArtifacts; + /** + * User extra files to collect. + * + * Multi values can be used, separated by comma. + * + * @parameter expression="${helper.extraFiles}" + * @since 1.0.0 + */ + protected String extraFiles; + /** + * File name pattern of selected files to publish. + * + * If no Set - no include filter + * + * @parameter expression="${helper.includes}" default-value="" + * @since 1.0.0 + */ + protected String includes; + /** + * File name pattern of selected files to publish. + * + * If no Set - no exclude filter + * + * @parameter expression="${helper.excludes}" default-value="" + * @since 1.0.0 + */ + protected String excludes; + /** + * Directory where to store collected files. + * <p/> + * <b>Note :</b> In a multi-module context, will always use the value of + * the property of the root module, because we need to push collected files + * to only one place. + * + * @parameter expression="${helper.outputDirectory}" default-value="target/collect" + * @since 1.0.0 + */ + protected String outputDirectory; + /** + * File with all files collected (one file by line in absolute path). + * <p/> + * <b>Note :</b> If not Set, will not generate the description file. + * + * @parameter expression="${helper.descriptionFile}" + * @since 1.0.0 + */ + protected String descriptionFile; + /** + * Un flag pour collecter aussi les fichiers attaches au projet. + * + * @parameter expression="${helper.includeAttached}" default-value="true" + * @since 1.0.0 + */ + protected boolean includeAttached; + /** + * Un flag pour recopier les fichiers collectés. + * + * @parameter expression="${helper.copyFiles}" default-value="true" + * @since 1.0.0 + */ + protected boolean copyFiles; + /** + * Un flag pour activer le mode verbeux. + * + * @parameter expression="${helper.verbose}" default-value="${maven.verbose}" + * @since 1.0.0 + */ + protected boolean verbose; + /** + * A flag to skip the goal. + * + * @parameter expression="${helper.skip}" default-value="false" + * @since 1.0.0 + */ + protected boolean skip; + /** + * Un flag pour activer le mode verbeux. + * + * @parameter expression="${helper.dryRun}" default-value="false" + * @since 1.0.0 + */ + protected boolean dryRun; + /** + * Encoding a utiliser pour lire et ecrire les fichiers. + * + * @parameter expression="${helper.encoding}" default-value="${project.build.sourceEncoding}" + * @required + * @since 1.0.0 + */ + protected String encoding; + List<File> files; + + @Override + protected boolean init() throws Exception { + if (skip) { + return true; + } + + files = getFiles(); + if (files.isEmpty()) { + + getLog().warn("No file to collect."); + return false; + } + + return true; + } + + @Override + public void doAction() throws Exception { + + if (skip) { + getLog().info("Skip flag in on, goal will not be executed"); + return; + } + + MavenProject rootProject = getExecutionRootProject(); + + File base = new File(rootProject.getBasedir(), outputDirectory); + + File output = new File(base, project.getGroupId() + "--" + project.getArtifactId()); + + if (rootProject == project || verbose) { + // just print on root + getLog().info("Ouput dir : " + output); + } + + if (dryRun) { + getLog().info("\n dryRun flag is on, no file will be copied!\n"); + } else { + + if (copyFiles && !output.exists()) { + output.mkdirs(); + } + } + + File description = null; + + List<File> incomingFiles = null; + + boolean withDescriptionFile = false; + + if (descriptionFile != null && !descriptionFile.trim().isEmpty()) { + + description = new File(rootProject.getBasedir(), descriptionFile); + + withDescriptionFile = true; + + if (description.exists()) { + // reload existing + try { + incomingFiles = getFiles(description); + getLog().info("Loaded " + description); + } catch (IOException ex) { + throw new MojoExecutionException("could not load file " + description, ex); + } + } else { + incomingFiles = new ArrayList<File>(); + } + } + + if (!withDescriptionFile && !copyFiles) { + throw new MojoExecutionException("must use at least one of the parameters 'copyFiles' or 'descriptionFile'"); + } + + String basedir = rootProject.getBasedir().getAbsolutePath(); + int basedirLength = basedir.length(); + for (File f : files) { + String absolutePath = f.getAbsolutePath(); + String path = absolutePath.substring(basedirLength + 1); + File dst = new File(output, f.getName()); + + if (withDescriptionFile) { + if (copyFiles) { + incomingFiles.add(dst); + } else { + incomingFiles.add(f); + } + } + + getLog().info("collected file " + path); + if (!dryRun && copyFiles) { + // copy the collected file + copyFile(f, dst); + + } + } + + if (!dryRun && withDescriptionFile) { + try { + setFiles(description, incomingFiles); + getLog().info("Saved " + description); + } catch (IOException ex) { + throw new MojoExecutionException("could not save file " + description, ex); + } + } + } + + /** + * Read a file containing on each line the path of a file. + * + * @param input the file containing the list of files + * @return the list of files read from the given file + * @throws IOException if any pb while reading file + */ + public List<File> getFiles(File input) throws IOException { + List<File> result = new ArrayList<File>(); + BufferedReader stream = new BufferedReader(new InputStreamReader(new FileInputStream(input))); + while (stream.ready()) { + String line = stream.readLine().trim(); + if (!line.isEmpty()) { + File f = new File(line); + result.add(f); + } + } + return result; + } + + /** + * Save the list of files in the given output file. + * <p/> + * Each line is the absolute path of each files of the list + * + * @param output the file when to write + * @param files the files to store + * @throws IOException if any pb when writing file + */ + public void setFiles(File output, List<File> files) throws IOException { +// BufferedWriter writer = new BufferedWriter(new FileWriter(output)); + StringBuilder builder = new StringBuilder(); + for (File f : files) { + builder.append(f.getAbsolutePath()).append("\n"); +// writer.write(f.getAbsolutePath()); +// writer.newLine(); + } + writeFile(output, builder.toString(), encoding); +// writer.close(); + } + + protected List<File> getFiles() { + + Pattern includePattern = includes == null || includes.trim().isEmpty() ? null : Pattern.compile(includes.trim()); + Pattern excludePattern = excludes == null || excludes.trim().isEmpty() ? null : Pattern.compile(excludes.trim()); + + List<File> result = new ArrayList<File>(); + + // attach the project mail file + + if (includeAttached) { + + if ("pom".equals(project.getPackaging())) { + addFile(project.getFile(), "adding artifact file : ", result, includePattern, excludePattern); + } else { + Artifact a = project.getArtifact(); + if (a != null) { + addFile(a.getFile(), "adding artifact file : ", result, includePattern, excludePattern); + } + } + } + File file; + + // attach extra files + + if (extraFiles != null && !extraFiles.trim().isEmpty()) { + + File basedir = project.getBasedir(); + for (String path : extraFiles.split(",")) { + path = path.trim(); + if (path.startsWith(basedir.getAbsolutePath())) { + file = new File(path.trim()); + } else { + file = new File(basedir, path.trim()); + } + + addFile(file, "adding user file : ", result, includePattern, excludePattern); + + } + } + + // attach project attached files + + if (includeAttached && attachedArtifacts != null) { + + for (Object o : attachedArtifacts) { + + file = ((Artifact) o).getFile(); + addFile(file, "adding attached artifact file : ", result, includePattern, excludePattern); + } + } + + return result; + } + + protected MavenProject getExecutionRootProject() { + MavenProject root = project; + while (!root.isExecutionRoot()) { + root = root.getParent(); + } + if (verbose) { + getLog().info("root project " + root); + } + return root; + } + + protected void addFile(File f, String msg, List<File> files, Pattern includePattern, Pattern excludePattern) { + if (f == null) { + return; + } + if (!f.exists()) { + getLog().warn("skip unexisting file " + f + " (" + msg + ")"); + return; + } + if (excludePattern != null) { + if (excludePattern.matcher(f.getName()).matches()) { + // skip this file + if (verbose) { + getLog().info("skip " + f + " : in excludes " + excludes); + } + return; + } + } + if (includePattern != null) { + if (!includePattern.matcher(f.getName()).matches()) { + // skip this file + if (verbose) { + getLog().info("skip " + f + " : not in includes " + includes); + } + return; + } + } + if (verbose) { + getLog().info(msg + f); + } + files.add(f); + } + + @Override + public MavenProject getProject() { + return project; + } + + @Override + public boolean isVerbose() { + return verbose; + } + + @Override + public void setProject(MavenProject project) { + this.project = project; + } + + @Override + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } +} + Property changes on: trunk/src/main/java/org/nuiton/io/plugin/CollectFilesMojo.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Modified: trunk/src/main/java/org/nuiton/license/JarLicenseResolver.java =================================================================== --- trunk/src/main/java/org/nuiton/license/JarLicenseResolver.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/license/JarLicenseResolver.java 2009-09-29 10:32:02 UTC (rev 599) @@ -36,7 +36,9 @@ * * @author chemit * @see LicenseResolver + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin */ +@Deprecated public class JarLicenseResolver extends LicenseResolver { private static final Log log = LogFactory.getLog(JarLicenseResolver.class); Modified: trunk/src/main/java/org/nuiton/license/License.java =================================================================== --- trunk/src/main/java/org/nuiton/license/License.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/license/License.java 2009-09-29 10:32:02 UTC (rev 599) @@ -32,7 +32,9 @@ * The model of a license. * * @author chemit + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin */ +@Deprecated public class License { /** the name of the licenses (ex lgpl-3.0) */ Modified: trunk/src/main/java/org/nuiton/license/LicenseFactory.java =================================================================== --- trunk/src/main/java/org/nuiton/license/LicenseFactory.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/license/LicenseFactory.java 2009-09-29 10:32:02 UTC (rev 599) @@ -34,7 +34,9 @@ * To obtain an instance of a {@link org.nuiton.license.LicenseFactory} use the method {@link #newInstance(String[])}. * * @author chemit + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin */ +@Deprecated public class LicenseFactory { protected List<LicenseResolver> resolvers; Modified: trunk/src/main/java/org/nuiton/license/LicenseResolver.java =================================================================== --- trunk/src/main/java/org/nuiton/license/LicenseResolver.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/license/LicenseResolver.java 2009-09-29 10:32:02 UTC (rev 599) @@ -46,7 +46,9 @@ * </pre> * * @author chemit + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin */ +@Deprecated public class LicenseResolver { private static final Log log = LogFactory.getLog(LicenseResolver.class); Modified: trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/license/plugin/AvailableLicensesPlugin.java 2009-09-29 10:32:02 UTC (rev 599) @@ -33,7 +33,9 @@ * @author chemit * @goal available-licenses * @requiresProject false + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin */ +@Deprecated public class AvailableLicensesPlugin extends AbstractMojo { /** Modified: trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java 2009-09-29 10:32:02 UTC (rev 599) @@ -34,7 +34,9 @@ * @phase generate-resources * @requiresProject true * @requiresDependencyResolution compile + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin */ +@Deprecated public class LicensePlugin extends org.nuiton.plugin.AbstractPlugin { /** @@ -132,11 +134,6 @@ return !("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging())); } - @Override - protected boolean ensurePackaging() { - return false; -// return project != null && ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging())); - } boolean doGenerate; @Override @@ -184,7 +181,7 @@ String licenseContent = license.getLicenseContent(encoding); if (doGenerate) { - copyFile(licenseContent, licenseFile, encoding); + writeFile(licenseFile,licenseContent, encoding); } if (hasClassPath()) { Modified: trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java 2009-09-29 10:32:02 UTC (rev 599) @@ -52,7 +52,9 @@ * @phase generate-resources * @requiresDependencyResolution test * @requiresProject true + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin */ +@Deprecated public class ThirdPartyPlugin extends AbstractPlugin { private static final String unknownLicenseMessage = "Unknown license"; @@ -176,8 +178,8 @@ } @Override - protected boolean ensurePackaging() { - return "pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()); + protected boolean checkPackaging() { + return !"pom".equals(project.getPackaging()) && !"site".equals(project.getPackaging()); } boolean doGenerate; @@ -234,7 +236,7 @@ } thirdPartyFile.renameTo(new File(thirdPartyFile.getAbsolutePath() + '~')); } - copyFile(thirdPartyFileContent, thirdPartyFile, encoding); + writeFile(thirdPartyFile,thirdPartyFileContent, encoding); } if (copyToMETA_INF) { copyFile(thirdPartyFile, new File(outputDirectory, "META-INF" + File.separator + project.getArtifactId() + "-" + thirdPartyFile.getName())); Modified: trunk/src/main/java/org/nuiton/mail/plugin/SendEmailMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/mail/plugin/SendEmailMojo.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/mail/plugin/SendEmailMojo.java 2009-09-29 10:32:02 UTC (rev 599) @@ -22,7 +22,7 @@ import org.nuiton.mail.*; import org.nuiton.plugin.*; -import org.nuiton.util.PluginHelper; +import org.nuiton.plugin.PluginHelper; import java.io.File; import java.util.List; @@ -214,6 +214,9 @@ * @since 1.0.3 */ protected SecDispatcher sec; + /** + * internal flag to know if plugin was already executed (for multi-module projects) + */ private boolean runOnceDone; /////////////////////////////////////////////////////////////////////////// /// Plugin @@ -238,19 +241,10 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - - @Override - protected boolean ensurePackaging() { - // accept all project's packaging - return false; - } - + /////////////////////////////////////////////////////////////////////////// /// AbstractPlugin /////////////////////////////////////////////////////////////////////////// - protected boolean isGoalSkip() { - return skipSendEmail; - } @Override protected boolean init() throws Exception { @@ -400,6 +394,10 @@ /////////////////////////////////////////////////////////////////////////// /// Other /////////////////////////////////////////////////////////////////////////// + protected boolean isGoalSkip() { + return skipSendEmail; + } + protected MailMessage createMessage(String newsContent, MailSender mailSender) throws MailSenderException { String fromName = mailSender.getName(); Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-09-29 10:32:02 UTC (rev 599) @@ -20,7 +20,6 @@ */ package org.nuiton.plugin; -import java.io.ByteArrayInputStream; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -39,10 +38,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Resource; import org.codehaus.plexus.util.DirectoryScanner; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.io.RawInputStreamFacade; -import org.nuiton.util.MirroredFileUpdater; -import org.nuiton.util.PluginHelper; +import org.nuiton.io.MirroredFileUpdater; /** * Un MOJO de base pour les autres MOJO concrets avec les options communes. @@ -51,12 +47,14 @@ */ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { - protected abstract boolean ensurePackaging(); - /** - * la methode qui est lancee au debut de la methode {@link #execute()} pour preparer l'init du goal. - * - * @return <code>true</code> if there is something to generate, <code>false</code> otherwise. + * Method to initialize the mojo before doing any concrete actions. + * <p/> + * <b>Note:</b> The method is invoked before the {@link #doAction()} method. + * <p/> + * @return <code>true</code> if mojo is well initialize and something has + * to be done in the {@link #doAction()} method, <code>false</code> + * otherwise. * @throws Exception if any */ protected abstract boolean init() throws Exception; @@ -66,7 +64,7 @@ * <p/> * The method {@link #execute()} invoke this method only and only if : * <ul> - * <li>{@link #ensurePackaging()} returns <code>false</code> (filtrer project type, for example).</li> + * <li>{@link #checkPackaging()} returns <code>false</code> (filtrer project type, for example).</li> * <li>method {@link #init()} returns <code>true</code>.</li> * </ul> * @@ -90,12 +88,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { try { - if (ensurePackaging()) { + boolean canContinue = checkPackaging(); + if (!canContinue) { getLog().warn("The goal is skip due to packaging '" + getProject().getPackaging() + "'"); return; } - boolean canContinue = init(); + canContinue = init(); if (!canContinue) { getLog().warn(skipAfterInitMessage); @@ -110,52 +109,114 @@ } /** - * Does the actual copy of the file and logging. + * Check if the project packaging is acceptable for the mojo. + * <p/> + * By default, accept all packaging types. + * <p/> + * <b>Note:</b> This method is the first instruction to be executed in + * the {@link #execute()}. + * <p/> + * <b>Tip:</b> There is two method to simplify the packaging check : * - * @param srcFile represents the file to copy. - * @param destFile file name of destination file. + * {@link #acceptPackaging(org.nuiton.plugin.Plugin.Packaging[])} * - * @throws MojoExecutionException with a message if an - * error occurs. + * and + * + * {@link #rejectPackaging(org.nuiton.plugin.Plugin.Packaging[])} + * + * + * @return {@code true} if can execute the goal for the packaging of the + * project, {@code false} otherwise. */ - protected void copyFile(File srcFile, File destFile) - throws MojoExecutionException { - try { - getLog().info("Copying " + srcFile.getName() + " to " + destFile); + protected boolean checkPackaging() { + return true; + } - FileUtils.copyFile(srcFile, destFile); +// /** +// * +// * @return {@code false} if packaging is ok +// * @deprecated since 1.0.3, do nothing!, use now the {@link #checkPackaging()} method instead +// * which return {@code true} is packaging is ok, be ware, the result is not the same +// * than in this method... +// */ +// @Deprecated +// protected boolean ensurePackaging() { +// return false; +// } + protected boolean acceptPackaging(Packaging... packages) { + String projectPackaging = getProject().getPackaging(); - } catch (Exception e) { - throw new MojoExecutionException("Error copying from " + srcFile + " to " + destFile, e); + for (Packaging p : packages) { + if (p.name().equals(projectPackaging)) { + // accept packaging + return true; + } } + // reject packaging + return false; } + protected boolean rejectPackaging(Packaging... packages) { + String projectPackaging = getProject().getPackaging(); + + for (Packaging p : packages) { + if (p.name().equals(projectPackaging)) { + // reject this packaging + return false; + } + } + // accept packaging + return true; + } + /** - * Does the actual copy of the content to a fileand logging. + * Does the actual copy of the file and logging. * - * @param content represents the content to writeFile into file. + * @param srcFile represents the file to copy. * @param destFile file name of destination file. - * @param encoding encoding to use to writeFile file + * * @throws MojoExecutionException with a message if an * error occurs. */ - protected void copyFile(String content, File destFile, String encoding) + public void copyFile(File srcFile, File destFile) throws MojoExecutionException { try { - getLog().info("Copying content to " + destFile); + getLog().info("Copying " + srcFile.getName() + " to " + destFile); - InputStream in = new ByteArrayInputStream(content.getBytes(encoding)); - RawInputStreamFacade facade = new RawInputStreamFacade(in); + PluginHelper.copy(srcFile, destFile); +// FileUtils.copyFile(srcFile, destFile); - FileUtils.copyStreamToFile(facade, destFile); - } catch (Exception e) { - throw new MojoExecutionException("Error copying content to " + destFile, 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 writeFile into file. +// * @param destFile file name of destination file. +// * @param encoding encoding to use to writeFile 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); +// +// PluginHelper.writeString(destFile, content, encoding); +//// 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); +// } +// } public void writeFile(File destFile, String content, String encoding) throws IOException { - PluginHelper.write(destFile, content, encoding); + PluginHelper.writeString(destFile, content, encoding); } /** Deleted: trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java 2009-09-29 10:32:02 UTC (rev 599) @@ -1,386 +0,0 @@ -/* - * *##% - * Maven helper plugin - * Copyright (C) 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.plugin; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; -import org.apache.maven.artifact.Artifact; -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 org.codehaus.plexus.util.FileUtils; - -/** - * Collect files some files from a project and copy them into a directory. - * - * @goal collect-files - * @requiresProject true - * - * @author tchemit - * @since 1.0.3 - */ -public class CollectFilesMojo extends AbstractMojo { - - /** - * Dependance du projet. - * - * @parameter default-value="${project}" - * @required - * @readonly - * @since 1.0.3 - */ - protected MavenProject project; - /** - * The artifacts to publish from the project build. - * - * @parameter expression="${project.attachedArtifacts}" - * @required - * @readonly - * @since 1.0.0 - */ - protected List attachedArtifacts; - /** - * User extra files to collect. - * - * Multi values can be used, separated by comma. - * - * @parameter expression="${helper.extraFiles}" - * @since 1.0.0 - */ - protected String extraFiles; - /** - * File name pattern of selected files to publish. - * - * If no Set - no include filter - * - * @parameter expression="${helper.includes}" default-value="" - * @since 1.0.0 - */ - protected String includes; - /** - * File name pattern of selected files to publish. - * - * If no Set - no exclude filter - * - * @parameter expression="${helper.excludes}" default-value="" - * @since 1.0.0 - */ - protected String excludes; - /** - * Directory where to store collected files. - * <p/> - * <b>Note :</b> In a multi-module context, will always use the value of - * the property of the root module, because we need to push collected files - * to only one place. - * - * @parameter expression="${helper.outputDirectory}" default-value="target/collect" - * @since 1.0.0 - */ - protected String outputDirectory; - /** - * File with all files collected (one file by line in absolute path). - * <p/> - * <b>Note :</b> If not Set, will not generate the description file. - * - * @parameter expression="${helper.descriptionFile}" - * @since 1.0.0 - */ - protected String descriptionFile; - /** - * Un flag pour collecter aussi les fichiers attaches au projet. - * - * @parameter expression="${helper.includeAttached}" default-value="true" - * @since 1.0.0 - */ - protected boolean includeAttached; - /** - * Un flag pour recopier les fichiers collectés. - * - * @parameter expression="${helper.copyFiles}" default-value="true" - * @since 1.0.0 - */ - protected boolean copyFiles; - /** - * Un flag pour activer le mode verbeux. - * - * @parameter expression="${helper.verbose}" default-value="${maven.verbose}" - * @since 1.0.0 - */ - protected boolean verbose; - /** - * A flag to skip the goal. - * - * @parameter expression="${helper.skip}" default-value="false" - * @since 1.0.0 - */ - protected boolean skip; - /** - * Un flag pour activer le mode verbeux. - * - * @parameter expression="${helper.dryRun}" default-value="false" - * @since 1.0.0 - */ - protected boolean dryRun; - - @Override - public void execute() throws MojoExecutionException, MojoFailureException { - - if (skip) { - getLog().info("Skip flag in on, goal will not be executed"); - return; - } - List<File> files = getFiles(); - if (files.isEmpty()) { - - getLog().warn("No file to collect."); - return; - } - - MavenProject rootProject = getExecutionRootProject(); - - File base = new File(rootProject.getBasedir(), outputDirectory); - - File output = new File(base, project.getGroupId() + "--" + project.getArtifactId()); - - if (rootProject == project || verbose) { - // just print on root - getLog().info("Ouput dir : " + output); - } - - if (dryRun) { - getLog().info("\n dryRun flag is on, no file will be copied!\n"); - } else { - - if (copyFiles && !output.exists()) { - output.mkdirs(); - } - } - - File description = null; - - List<File> incomingFiles = null; - - boolean withDescriptionFile = false; - - if (descriptionFile != null && !descriptionFile.trim().isEmpty()) { - - description = new File(rootProject.getBasedir(), descriptionFile); - - withDescriptionFile = true; - - if (description.exists()) { - // reload existing - try { - incomingFiles = getFiles(description); - getLog().info("Loaded " + description); - } catch (IOException ex) { - throw new MojoExecutionException("could not load file " + description, ex); - } - } else { - incomingFiles = new ArrayList<File>(); - } - } - - if (!withDescriptionFile && !copyFiles) { - throw new MojoExecutionException("must use at least one of the parameters 'copyFiles' or 'descriptionFile'"); - } - - String basedir = rootProject.getBasedir().getAbsolutePath(); - int basedirLength = basedir.length(); - for (File f : files) { - String absolutePath = f.getAbsolutePath(); - String path = absolutePath.substring(basedirLength + 1); - File dst = new File(output, f.getName()); - - if (withDescriptionFile) { - if (copyFiles) { - incomingFiles.add(dst); - } else { - incomingFiles.add(f); - } - } - - getLog().info("collected file " + path); - if (!dryRun && copyFiles) { - try { - // copy the collected file - FileUtils.copyFile(f, dst); - } catch (IOException ex) { - throw new MojoExecutionException("could not copy file " + f, ex); - } - } - } - - if (!dryRun && withDescriptionFile) { - try { - setFiles(description, incomingFiles); - getLog().info("Saved " + description); - } catch (IOException ex) { - throw new MojoExecutionException("could not save file " + description, ex); - } - } - } - - /** - * Read a file containing on each line the path of a file. - * - * @param input the file containing the list of files - * @return the list of files read from the given file - * @throws IOException if any pb while reading file - */ - public static List<File> getFiles(File input) throws IOException { - List<File> result = new ArrayList<File>(); - BufferedReader stream = new BufferedReader(new InputStreamReader(new FileInputStream(input))); - while (stream.ready()) { - String line = stream.readLine().trim(); - if (!line.isEmpty()) { - File f = new File(line); - result.add(f); - } - } - return result; - } - - /** - * Save the list of files in the given output file. - * <p/> - * Each line is the absolute path of each files of the list - * - * @param output the file when to write - * @param files the files to store - * @throws IOException if any pb when writing file - */ - public static void setFiles(File output, List<File> files) throws IOException { - BufferedWriter writer = new BufferedWriter(new FileWriter(output)); - for (File f : files) { - writer.write(f.getAbsolutePath()); - writer.newLine(); - } - writer.close(); - } - - protected List<File> getFiles() { - - Pattern includePattern = includes == null || includes.trim().isEmpty() ? null : Pattern.compile(includes.trim()); - Pattern excludePattern = excludes == null || excludes.trim().isEmpty() ? null : Pattern.compile(excludes.trim()); - - List<File> result = new ArrayList<File>(); - - // attach the project mail file - - if (includeAttached) { - - if ("pom".equals(project.getPackaging())) { - addFile(project.getFile(), "adding artifact file : ", result, includePattern, excludePattern); - } else { - Artifact a = project.getArtifact(); - if (a != null) { - addFile(a.getFile(), "adding artifact file : ", result, includePattern, excludePattern); - } - } - } - File file; - - // attach extra files - - if (extraFiles != null && !extraFiles.trim().isEmpty()) { - - File basedir = project.getBasedir(); - for (String path : extraFiles.split(",")) { - path = path.trim(); - if (path.startsWith(basedir.getAbsolutePath())) { - file = new File(path.trim()); - } else { - file = new File(basedir, path.trim()); - } - - addFile(file, "adding user file : ", result, includePattern, excludePattern); - - } - } - - // attach project attached files - - if (includeAttached && attachedArtifacts != null) { - - for (Object o : attachedArtifacts) { - - file = ((Artifact) o).getFile(); - addFile(file, "adding attached artifact file : ", result, includePattern, excludePattern); - } - } - - return result; - } - - protected MavenProject getExecutionRootProject() { - MavenProject root = project; - while (!root.isExecutionRoot()) { - root = root.getParent(); - } - if (verbose) { - getLog().info("root project " + root); - } - return root; - } - - protected void addFile(File f, String msg, List<File> files, Pattern includePattern, Pattern excludePattern) { - if (f == null) { - return; - } - if (!f.exists()) { - getLog().warn("skip unexisting file " + f + " (" + msg + ")"); - return; - } - if (excludePattern != null) { - if (excludePattern.matcher(f.getName()).matches()) { - // skip this file - if (verbose) { - getLog().info("skip " + f + " : in excludes " + excludes); - } - return; - } - } - if (includePattern != null) { - if (!includePattern.matcher(f.getName()).matches()) { - // skip this file - if (verbose) { - getLog().info("skip " + f + " : not in includes " + includes); - } - return; - } - } - if (verbose) { - getLog().info(msg + f); - } - files.add(f); - } -} - Copied: trunk/src/main/java/org/nuiton/plugin/DependencyUtil.java (from rev 580, trunk/src/main/java/org/nuiton/util/DependencyUtil.java) =================================================================== --- trunk/src/main/java/org/nuiton/plugin/DependencyUtil.java (rev 0) +++ trunk/src/main/java/org/nuiton/plugin/DependencyUtil.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,236 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.plugin; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.shared.dependency.tree.DependencyNode; + +/** + * Une classe de methodes utiles sur les dependences entre artifacts. + * + * @author chemit + * @since 0.5 + */ +public class DependencyUtil { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + private static final Log log = LogFactory.getLog(DependencyUtil.class); + + public static void sortArtifacts(DependencyNode rootNode, List<Artifact> artifacts, boolean verbose) { + + if (artifacts.size() == 1) { + return; + } + + Map<String, ArtifactDependencyEntry> dico = new java.util.HashMap<String, ArtifactDependencyEntry>(artifacts.size()); + + for (Artifact a : artifacts) { + ArtifactDependencyEntry entry = new ArtifactDependencyEntry(a); + dico.put(entry.artifactKey, entry); + } + + // contient les artifacts non encore fixes + Set<String> universe = new java.util.HashSet<String>(dico.keySet()); + + // recupere les noeuds pour chaque artifact en une seule passe + + setNodes(rootNode, dico, universe, verbose); + + // contient les artifacts resouds dans l'ordre de dependances + List<String> parsed = new java.util.ArrayList<String>(); + + // premiere passe pour recuperer l'ensemble des dependances + for (ArtifactDependencyEntry entry : dico.values()) { + List<String> dependencies = getDependencies(rootNode, entry, universe, verbose); + entry.depIds = dependencies; + } + + int level = 0; + do { + if (verbose) { + log.info("run into level " + (level++)); + } + // on parcourt les artifacts pour detecter les nouveau artifacts fixes + List<String> levelFixed = new java.util.ArrayList<String>(); + + for (String key : universe) { + ArtifactDependencyEntry entry = dico.get(key); + // cet artifact n'est pas encore fixe + if (entry.depIds.isEmpty()) { + // plus de dependance pour cet artifact + levelFixed.add(key); + if (verbose) { + log.info("fixed artifact " + key); + } + } + } + + if (levelFixed.isEmpty()) { + // aucune modification, c'est un cycle! + throw new IllegalStateException("cycle detecte ! entre les artifacts " + universe); + } + + // on met a jour les listes + universe.removeAll(levelFixed); + parsed.addAll(levelFixed); + + if (universe.isEmpty()) { + // tout a ete resolu, plus rien a faire + break; + } + + // on supprime les dependances fixees a ce niveau + for (String key : universe) { + ArtifactDependencyEntry entry = dico.get(key); + entry.depIds.removeAll(levelFixed); + } + + levelFixed.clear(); + } while (true); + + artifacts.clear(); + for (String key : parsed) { + artifacts.add(dico.get(key).artifact); + } + + } + + protected static String getArtifactId(Artifact artifact) { + return artifact.getArtifactId() + ":" + artifact.getGroupId(); + } + + protected static List<String> getDependencies(DependencyNode rootNode, ArtifactDependencyEntry entry, Set<String> universe, boolean verbose) { + + List<String> order = new java.util.ArrayList<String>(); + Set<String> exclude = new java.util.HashSet<String>(); + + if (verbose) { + log.info("start [" + entry.artifactKey + "]"); + } + DependencyNode node = entry.node; + + getDependencies(rootNode, node, entry.artifactKey, universe, verbose, order, exclude); + + return order; + } + + private static void getDependencies(DependencyNode rootNode, DependencyNode node, String artifactKey, Set<String> universe, boolean verbose, List<String> order, Set<String> exclude) { + + for (Iterator<?> itr = node.preorderIterator(); itr.hasNext();) { + DependencyNode d = (DependencyNode) itr.next(); + Artifact artifact = d.getArtifact(); + String key = getArtifactId(artifact); + if (artifactKey.equals(key)) { + // artifact du noeud en parametre, rien a faire + continue; + } + if (order.contains(key) || exclude.contains(key)) { + // artifact deja rencontree + continue; + } + + if (d.getState() != DependencyNode.INCLUDED) { + // on doit recuperer le noeud complete + if (log.isDebugEnabled()) { + log.debug("!!! doit recuperer le noeud complet pour " + d.getArtifact()); + } + DependencyNode node1 = getNode(rootNode, key, verbose); + getDependencies(rootNode, node1, artifactKey, universe, verbose, order, exclude); + } + + if (log.isDebugEnabled()) { + log.debug("[" + artifactKey + "] ??????? [" + key + "]"); + } + + if (universe.contains(key)) { + // artifact a retenir + if (verbose) { + log.info(" << [" + d.getArtifact() + "]"); + } + order.add(key); + continue; + } + + // cet artifact peut etre marque comme a ne plus etre scanne + exclude.add(key); + } + + } + + protected static void setNodes(DependencyNode rootNode, Map<String, ArtifactDependencyEntry> dico, Set<String> universe, boolean verbose) { + + for (Iterator<?> itr = rootNode.preorderIterator(); itr.hasNext();) { + DependencyNode d = (DependencyNode) itr.next(); + Artifact artifact = d.getArtifact(); + String key = getArtifactId(artifact); + if (log.isDebugEnabled()) { + log.debug("key : " + key); + } + if (universe.contains(key) && d.getState() == DependencyNode.INCLUDED) { + ArtifactDependencyEntry entry = dico.get(key); + entry.node = d; + if (d == null) { + // ce cas ne devrait jamais arrive + throw new IllegalStateException("on a pas trouve le node pour l'artifact " + artifact); + } + if (log.isDebugEnabled()) { + log.debug("detected node : " + d); + } + } + } + } + + protected static DependencyNode getNode(DependencyNode rootNode, String requiredKey, boolean verbose) { + + for (Iterator<?> itr = rootNode.preorderIterator(); itr.hasNext();) { + DependencyNode d = (DependencyNode) itr.next(); + Artifact artifact = d.getArtifact(); + String key = getArtifactId(artifact); + if (log.isDebugEnabled()) { + log.debug("key : " + key); + } + if (requiredKey.equals(key) && d.getState() == DependencyNode.INCLUDED) { + return d; + } + } + + return null; + } + + public static class ArtifactDependencyEntry { + + protected final Artifact artifact; + protected final String artifactKey; + protected DependencyNode node; + protected List<String> depIds; + + public ArtifactDependencyEntry(Artifact artifact) { + this.artifact = artifact; + this.artifactKey = getArtifactId(artifact); + } + } +} Property changes on: trunk/src/main/java/org/nuiton/plugin/DependencyUtil.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/src/main/java/org/nuiton/plugin/Plugin.java =================================================================== --- trunk/src/main/java/org/nuiton/plugin/Plugin.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/plugin/Plugin.java 2009-09-29 10:32:02 UTC (rev 599) @@ -33,6 +33,18 @@ */ public interface Plugin extends Mojo { + /** + * An enumeration to qualify a maven module packaging + */ + enum Packaging { + + pom, + jar, + plugin, + war, + ear + }; + MavenProject getProject(); void setProject(MavenProject project); Copied: trunk/src/main/java/org/nuiton/plugin/PluginHelper.java (from rev 580, trunk/src/main/java/org/nuiton/util/PluginHelper.java) =================================================================== --- trunk/src/main/java/org/nuiton/plugin/PluginHelper.java (rev 0) +++ trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,421 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.plugin; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import org.apache.maven.model.Resource; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; + +/** + * Une classe pour mutualiser toutes les méthodes utiles pour un plugin. + * + * @author chemit + */ +public class PluginHelper { + + public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; + + public static String removeSnapshotSuffix(String versionId) { + if (versionId.endsWith(SNAPSHOT_SUFFIX)) { + // remove snapshot suffix + versionId = versionId.substring(0, versionId.length() - SNAPSHOT_SUFFIX.length()); + } + return versionId; + } + + /** + * Permet de convertir une liste non typee, en une liste typee. + * <p/> + * La liste en entree en juste bien castee. + * <p/> + * On effectue une verification sur le typage des elements de la liste. + * <p/> + * Note : <b>Aucune liste n'est creee, ni recopiee</b> + * + * @param <O> le type des objets de la liste + * @param list la liste a convertir + * @param type le type des elements de la liste + * @return la liste typee + * @throws IllegalArgumentException si un element de la liste en entree n'est + * pas en adequation avec le type voulue. + */ + @SuppressWarnings({"unchecked"}) + static public <O> List<O> toGenericList(List<?> list, Class<O> type) throws IllegalArgumentException { + if (list.isEmpty()) { + return (List<O>) list; + } + for (Object o : list) { + if (!(type.isAssignableFrom(o.getClass()))) { + throw new IllegalArgumentException("can not cast List with object of type " + o.getClass() + " to " + type + " type!"); + } + } + return (List<O>) list; + } + static final protected double[] timeFactors = {1000000, 1000, 60, 60, 24}; + static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h", "d"}; + static final protected double[] memoryFactors = {1024, 1024, 1024, 1024}; + static final protected String[] memoryUnites = {"o", "Ko", "Mo", "Go", "To"}; + + static public String convertMemory(long value) { + return convert(value, memoryFactors, memoryUnites); + } + + static public String convertTime(long value) { + return convert(value, timeFactors, timeUnites); + } + + static public String convertTime(long value, long value2) { + return convertTime(value2 - value); + } + + static public String convert(long value, double[] factors, String[] unites) { + long sign = value == 0 ? 1 : value / Math.abs(value); + int i = 0; + double tmp = Math.abs(value); + while (i < factors.length && i < unites.length && tmp > factors[i]) { + tmp = tmp / factors[i++]; + } + + tmp *= sign; + String result; + result = MessageFormat.format("{0,number,0.###}{1}", tmp, + unites[i]); + return result; + } + + /** + * Prefix the lines of the given content with a given prefix. + * + * @param prefix prefix to add on each line of text + * @param prefixForEmpty prefix to add for empty lines + * @param content the text to treate + * @return the text transformed + * @throws IOException if any reading problem + */ + static public String prefixLines(String prefix, String prefixForEmpty, String content) throws IOException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new java.io.StringReader(content)); + StringBuilder sb = new StringBuilder(); + + String line = reader.readLine(); + while (line != null) { + line = line.trim(); + if (line.isEmpty()) { + sb.append(prefixForEmpty); + } else { + sb.append(prefix); + sb.append(line); + } + line = reader.readLine(); + if (line != null) { + sb.append('\n'); + } + } + + String result = sb.toString(); + return result; + } finally { + if (reader != null) { + reader.close(); + } + } + } + + /** + * Obtenir les clefs de toutes les valeurs nulles ou vide a partir + * d'un dictionnaire donne. + * + * @param map le dictionner a parcourir + * + * @return la liste des clefs dont la valeur est nulle ou vide + */ + static public SortedSet<String> getEmptyKeys(Map<?, ?> map) { + SortedSet<String> result = new TreeSet<String>(); + for (Entry<?, ?> e : map.entrySet()) { + if (e.getValue() == null || e.getValue().toString().isEmpty()) { + result.add(e.getKey().toString()); + } + } + return result; + } + + public static boolean addResourceDir(String newresourceDir, MavenProject project) { + List<?> resources = project.getResources(); + boolean added = addResourceDir(newresourceDir, project, resources); + return added; + } + + public static boolean addTestResourceDir(String newresourceDir, MavenProject project) { + List<?> resources = project.getTestResources(); + boolean added = addResourceDir(newresourceDir, project, resources); + return added; + } + + public static boolean addResourceDir(String newresourceDir, MavenProject project, List<?> resources) { + boolean shouldAdd = true; + for (Object o : resources) { + Resource r = (Resource) o; + if (!r.getDirectory().equals(newresourceDir)) { + continue; + } + r.addInclude("**/*.properties"); + r.addInclude("**/*.txt"); + shouldAdd = false; + break; + } + if (shouldAdd) { + Resource r = new Resource(); + r.setDirectory(newresourceDir); + r.addInclude("**/*.properties"); + r.addInclude("**/*.txt"); + project.addResource(r); + } + return shouldAdd; + } + + /** + * Permet de copier le fichier source vers le fichier cible. + * + * @param source le fichier source + * @param target le fichier cible + * @throws java.io.IOException Erreur de copie + */ + public static void copy(File source, File target) throws IOException { + target.getParentFile().mkdirs(); + FileUtils.copyFile(source, target); +// FileChannel sourceChannel = new FileInputStream(source).getChannel(); +// FileChannel targetChannel = new FileOutputStream(target).getChannel(); +// sourceChannel.transferTo(0, sourceChannel.size(), targetChannel); +// // or +// // targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); +// sourceChannel.close(); +// targetChannel.close(); + } + + /** + * Permet de lire un fichier et de retourner sont contenu sous forme d'une + * chaine de carateres + * + * @param file le fichier a lire + * @param encoding encoding to read file + * @return the content of the file + * @throws IOException if IO pb + */ + static public String readAsString(File file, String encoding) throws IOException { + FileInputStream inf = new FileInputStream(file); + BufferedReader in = new BufferedReader(new InputStreamReader(inf, encoding)); + try { + return IOUtil.toString(in); +// return FileUtil.readAsString(r); + } finally { + in.close(); + } + } + + /** + * Permet de lire un fichier et de retourner sont contenu sous forme d'une + * chaine de carateres + * + * @param reader la source alire + * @return the content of the file + * @throws IOException if IO pb + */ + static public String readAsString(java.io.Reader reader) throws IOException { + return IOUtil.toString(reader); +// StringBuffer result = new StringBuffer(); +// char[] cbuf = new char[2000]; +// BufferedReader in = new BufferedReader(reader); +// int nb = in.read(cbuf); +// while (nb != -1) { +// result.append(cbuf, 0, nb); +// nb = in.read(cbuf); +// } +// in.close(); +// return result.toString(); + } + + /** + * Sauvegarde un contenu dans un fichier. + * + * @param file le fichier a ecrire + * @param content le contenu du fichier + * @param encoding l'encoding d'ecriture + * @throws IOException if IO pb + */ + static public void writeString(File file, String content, String encoding) throws IOException { + file.getParentFile().mkdirs(); + BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding)); + try { + IOUtil.copy(content, out); +// out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding)); +// out.write(content); + } finally { + if (out != null) { + out.close(); + } + } + } +// +// public static 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); +// } + + public static List<File> getIncludedFiles(File dir, String[] includes, String[] excludes) { + DirectoryScanner ds = new DirectoryScanner(); + List<File> result = new ArrayList<File>(); + ds.setBasedir(dir); + if (includes != null) { + ds.setIncludes(includes); + } + if (excludes != null) { + + ds.setExcludes(excludes); + } + ds.addDefaultExcludes(); + ds.scan(); + for (String file : ds.getIncludedFiles()) { + File in = new File(dir, file); + result.add(in); + } + return result; + } + + public static void copyFiles(File src, File dst, String[] includes, String[] excludes, boolean overwrite) throws IOException { + PluginIOContext c = new PluginIOContext(); + c.setInput(src); + c.setOutput(dst); + copyFiles(c, includes, excludes, overwrite); + } + + public static void copyFiles(PluginIOContext p, String[] includes, String[] excludes, boolean overwrite) throws IOException { + DirectoryScanner ds = new DirectoryScanner(); + + + for (File input : p.getInputs()) { + ds.setBasedir(input); + if (includes != null) { + ds.setIncludes(includes); + } + if (excludes != null) { + + ds.setExcludes(excludes); + } + ds.addDefaultExcludes(); + ds.scan(); + for (String file : ds.getIncludedFiles()) { + File in = new File(input, file); + File out = new File(p.getOutput(), file); + if (overwrite) { + FileUtils.copyFile(in, out); + } else { + FileUtils.copyFileIfModified(in, out); + } + } + } + } + + public static void expandFiles(PluginIOContext p, String[] includes, String[] excludes, String[] zipIncludes, boolean overwrite) throws IOException { + + DirectoryScanner ds = new DirectoryScanner(); + + for (File input : p.getInputs()) { + ds.setBasedir(input); + if (includes != null) { + ds.setIncludes(includes); + } + if (excludes != null) { + + ds.setExcludes(excludes); + } + ds.addDefaultExcludes(); + ds.scan(); + for (String file : ds.getIncludedFiles()) { + File in = new File(input, file); + File out = new File(p.getOutput(), file).getParentFile(); + expandFile(in, out, zipIncludes, overwrite); + } + } + } + + public static File getFile(File base, String... paths) { + StringBuilder buffer = new StringBuilder(); + for (String path : paths) { + buffer.append(File.separator).append(path); + } + File f = new File(base, buffer.substring(1)); + return f; + } + + public static String getRelativePath(File base, File file) { + String result = file.getAbsolutePath().substring(base.getAbsolutePath().length() + 1); + return result; + } + + public static void expandFile(File src, File dst, String[] includes, boolean overwrite) throws IOException { +// System.out.println("expandFile src:" + src + " to " + dst); + ZipFile zipFile = new ZipFile(src); + Enumeration<? extends ZipEntry> entries = zipFile.entries(); + while (entries.hasMoreElements()) { + ZipEntry nextElement = entries.nextElement(); + String name = nextElement.getName(); +// System.out.println("name : " + name); + for (String include : includes) { + if (DirectoryScanner.match(include, name)) { + System.out.println("matching name : " + name + " with pattern " + include); + File dstFile = new File(dst, name); + if (overwrite || !dstFile.exists() || nextElement.getTime() > dstFile.lastModified()) { + System.out.println("will expand : " + name + " to " + dstFile); + InputStream inputStream = zipFile.getInputStream(nextElement); + FileOutputStream outStream = new FileOutputStream(dstFile); + IOUtil.copy(inputStream, outStream, 2048); + } + + } + } + } + } +} Property changes on: trunk/src/main/java/org/nuiton/plugin/PluginHelper.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/main/java/org/nuiton/plugin/PluginIOContext.java (from rev 580, trunk/src/main/java/org/nuiton/util/PluginIOContext.java) =================================================================== --- trunk/src/main/java/org/nuiton/plugin/PluginIOContext.java (rev 0) +++ trunk/src/main/java/org/nuiton/plugin/PluginIOContext.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,60 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.plugin; + +import java.io.File; + +/** + * Une classe pour définir les entrées-sortie d'un plugin. + * + * En entrée, on peut avoir un ou plusieurs répertoires ({@link #inputs}. + * <p/> + * En sortie, on ne peut avoir qu'un seul répertoire ({@link #output}. + * + * + * @author chemit + * @since 1.0.1 + */ +public class PluginIOContext { + + File[] inputs; + File output; + + public File[] getInputs() { + return inputs; + } + + public File getOutput() { + return output; + } + + public void setInput(File input) { + this.inputs = new File[]{input}; + } + + public void setInputs(File[] inputs) { + this.inputs = inputs; + } + + public void setOutput(File output) { + this.output = output; + } +} Property changes on: trunk/src/main/java/org/nuiton/plugin/PluginIOContext.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Copied: trunk/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java (from rev 580, trunk/src/main/java/org/nuiton/util/VelocityTemplateGenerator.java) =================================================================== --- trunk/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java (rev 0) +++ trunk/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,184 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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>. + * ##%* + */ +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License" ); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nuiton.plugin; + +import java.io.File; +import java.io.FileWriter; +import java.io.Writer; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Iterator; +import java.util.Properties; + +import org.apache.maven.project.MavenProject; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; + +/** + * Generator of template base on velocity. + * + * @author chemit + * @since 1.3 + * + */ +public class VelocityTemplateGenerator { + + protected VelocityEngine engine; + protected final MavenProject mavenProject; + protected Template velocityTemplate; + + public VelocityTemplateGenerator(MavenProject mavenProject, URL template) throws URISyntaxException { + + if (mavenProject == null) { + throw new IllegalArgumentException("mavenProject must not be null"); + } + + if (template == null) { + throw new IllegalArgumentException("template must not be null"); + } + + this.mavenProject = mavenProject; + + Properties props = new Properties(); + + String templateName; + + if (template.toURI().isOpaque()) { + + // template is in a jar + + props = new Properties(); + props.setProperty("resource.loader", "jar"); + props.setProperty("jar.resource.loader.description", "Jar resource loader for default webstart templates"); + props.setProperty("jar.resource.loader.class", "org.apache.velocity.runtime.resource.loader.JarResourceLoader"); + + // obtain the jar url + + String url = template.toString(); + int i = url.indexOf("!"); + templateName = url.substring(i + 2); + + props.setProperty("jar.resource.loader.path", url.substring(0, i + 2)); + + } else { + + File f = new File(template.getFile()); + templateName = f.getName(); + + //props.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogSystem"); + props.setProperty("file.resource.loader.path", f.getParent()); + } + + try { + engine = new VelocityEngine(); + //engine.setProperty("runtime.log.logsystem", new NullLogSystem()); + engine.init(props); + } catch (Exception e) { + IllegalArgumentException iae = new IllegalArgumentException("Could not initialise Velocity"); + iae.initCause(e); + throw iae; + } + + try { + this.velocityTemplate = engine.getTemplate(templateName); + } catch (Exception e) { + IllegalArgumentException iae = + new IllegalArgumentException("Could not load the template file from '" + template + "'"); + iae.initCause(e); + throw iae; + } + } + + public void generate(Properties context, Writer writer) throws Exception { + + VelocityContext vcontext = new VelocityContext(); + + // Note: properties that contain dots will not be properly parsed by Velocity. Should we replace dots with underscores ? + addPropertiesToContext(System.getProperties(), vcontext); + + addPropertiesToContext(mavenProject.getProperties(), vcontext); + addPropertiesToContext(context, vcontext); + + vcontext.put("project", mavenProject.getModel()); + + try { + velocityTemplate.merge(vcontext, writer); + writer.flush(); + } catch (Exception e) { + throw new Exception("Could not generate the template " + velocityTemplate.getName() + ": " + e.getMessage(), e); + } finally { + writer.close(); + } + } + + public void generate(Properties context, File outputFile) throws Exception { + + + VelocityContext vcontext = new VelocityContext(); + + // Note: properties that contain dots will not be properly parsed by Velocity. Should we replace dots with underscores ? + addPropertiesToContext(System.getProperties(), vcontext); + + addPropertiesToContext(mavenProject.getProperties(), vcontext); + addPropertiesToContext(context, vcontext); + + vcontext.put("project", mavenProject.getModel()); + + vcontext.put("outputFile", outputFile.getName()); + + FileWriter writer = new FileWriter(outputFile); + + try { + velocityTemplate.merge(vcontext, writer); + writer.flush(); + } catch (Exception e) { + throw new Exception("Could not generate the template " + velocityTemplate.getName() + ": " + e.getMessage(), e); + } finally { + writer.close(); + } + } + + protected void addPropertiesToContext(Properties properties, VelocityContext context) { + + for (Iterator<?> iter = properties.keySet().iterator(); iter.hasNext();) { + String key = (String) iter.next(); + Object value = properties.get(key); + context.put(key, value); + } + + } +} Property changes on: trunk/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Modified: trunk/src/main/java/org/nuiton/util/DependencyUtil.java =================================================================== --- trunk/src/main/java/org/nuiton/util/DependencyUtil.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/util/DependencyUtil.java 2009-09-29 10:32:02 UTC (rev 599) @@ -34,7 +34,9 @@ * * @author chemit * @since 0.5 + * @deprecated since 1.0.3, move to package org.nuiton.plugin */ +@Deprecated public class DependencyUtil { /** to use log facility, just put in your code: log.info(\"...\"); */ Modified: trunk/src/main/java/org/nuiton/util/FileUpdater.java =================================================================== --- trunk/src/main/java/org/nuiton/util/FileUpdater.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/util/FileUpdater.java 2009-09-29 10:32:02 UTC (rev 599) @@ -28,7 +28,10 @@ * use {@link #isFileUpToDate(java.io.File)} to determine if a file is up to date. * * @author chemit + * @deprecated since 1.0.3, move to package org.nuiton.plugin */ +@Deprecated + public interface FileUpdater { /** Modified: trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java =================================================================== --- trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/util/FileUpdaterHelper.java 2009-09-29 10:32:02 UTC (rev 599) @@ -22,7 +22,11 @@ import java.io.File; -/** @author chemit */ +/** + * @author chemit + * @deprecated since 1.0.3, move to package org.nuiton.plugin + */ +@Deprecated public class FileUpdaterHelper { static public MirroredFileUpdater newJavaFileUpdater() { Modified: trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java =================================================================== --- trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/util/MirroredFileUpdater.java 2009-09-29 10:32:02 UTC (rev 599) @@ -29,7 +29,9 @@ * Simple base implementation of a {@link FileUpdater} for an updater with a sourcedir and a destinationdir. * * @author chemit + * @deprecated since 1.0.3, move to package org.nuiton.plugin */ +@Deprecated public class MirroredFileUpdater implements FileUpdater { /** to use log facility, just put in your code: log.info(\"...\"); */ Modified: trunk/src/main/java/org/nuiton/util/PluginHelper.java =================================================================== --- trunk/src/main/java/org/nuiton/util/PluginHelper.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/util/PluginHelper.java 2009-09-29 10:32:02 UTC (rev 599) @@ -57,7 +57,9 @@ * Une classe pour mutualiser toutes les méthodes utiles pour un plugin. * * @author chemit + * @deprecated since 1.0.3, move to package org.nuiton.plugin */ +@Deprecated public class PluginHelper { public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; Modified: trunk/src/main/java/org/nuiton/util/PluginIOContext.java =================================================================== --- trunk/src/main/java/org/nuiton/util/PluginIOContext.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/util/PluginIOContext.java 2009-09-29 10:32:02 UTC (rev 599) @@ -32,7 +32,9 @@ * * @author chemit * @since 1.0.1 + * @deprecated since 1.0.3, move to package org.nuiton.plugin */ +@Deprecated public class PluginIOContext { File[] inputs; Modified: trunk/src/main/java/org/nuiton/util/SourceEntry.java =================================================================== --- trunk/src/main/java/org/nuiton/util/SourceEntry.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/util/SourceEntry.java 2009-09-29 10:32:02 UTC (rev 599) @@ -44,7 +44,9 @@ * to expose his methods.</b> * * @author tony + * @deprecated since 1.0.3, move to package org.nuiton.plugin */ +@Deprecated public class SourceEntry { /** * If you want to restrict use of the entry, set the class name goal to Modified: trunk/src/main/java/org/nuiton/util/VelocityTemplateGenerator.java =================================================================== --- trunk/src/main/java/org/nuiton/util/VelocityTemplateGenerator.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/main/java/org/nuiton/util/VelocityTemplateGenerator.java 2009-09-29 10:32:02 UTC (rev 599) @@ -53,8 +53,9 @@ * * @author chemit * @since 1.3 - * + * @deprecated since 1.0.3, move to package org.nuiton.plugin */ +@Deprecated public class VelocityTemplateGenerator { protected VelocityEngine engine; Modified: trunk/src/site/apt/index.apt =================================================================== --- trunk/src/site/apt/index.apt 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/site/apt/index.apt 2009-09-29 10:32:02 UTC (rev 599) @@ -39,14 +39,13 @@ Plugin toolkit overview - see javadoc. + {{{mojoFramework.html}Mojo test framework}}. - <<A faire>> + see {{{apidocs/index.html}javadoc}}. + Test toolkit overview - * {{{mojoTestFramework.html}Mojo test framework}}. + {{{mojoTestFramework.html}Mojo test framework}}. - see test-javadoc. - - <<A faire>> + see {{{testapidocs/index.html}test-javadoc}}. Modified: trunk/src/site/apt/mojoTestFramework.apt =================================================================== --- trunk/src/site/apt/mojoTestFramework.apt 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/site/apt/mojoTestFramework.apt 2009-09-29 10:32:02 UTC (rev 599) @@ -132,7 +132,7 @@ this is not a real maven execution environement, for example you can not defined in the pom file some properties... - You can then override the <<setupMojo>> method, lie in the next example : + You can then override the <<setupMojo>> method, like in the next example : -------------------------------------------------------------------------------- @@ -172,4 +172,4 @@ } -------------------------------------------------------------------------------- - For more explanations, see the test-javadoc. + For more explanations, see the {{{testapidocs/index.html}test-javadoc}}. Copied: trunk/src/test/java/org/nuiton/io/JavaFileUpdaterTest.java (from rev 580, trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java) =================================================================== --- trunk/src/test/java/org/nuiton/io/JavaFileUpdaterTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/io/JavaFileUpdaterTest.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,125 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.io; + +import org.nuiton.io.FileUpdaterHelper.JavaFileUpdater; +import java.io.File; +import org.junit.BeforeClass; +import org.junit.Test; +import org.nuiton.plugin.TestHelper; +import static org.junit.Assert.*; + +/** + * Test of a {@link JavaFileUpdater} on the test sourcepath and test-classpath + * + * @author chemit + */ +public class JavaFileUpdaterTest { + + static MirroredFileUpdater fileUpdater; + static File sourceFile; + static File mirrorFile; + + @BeforeClass + public static void initClass() throws Exception { + + File basedir = TestHelper.getBasedir(); + + File src = TestHelper.getFile(basedir, "src", "test", "resources"); + File dir = TestHelper.getFile(basedir, "target", "test-classes"); + + fileUpdater = FileUpdaterHelper.newJavaFileUpdater(src, dir); + + // test source dir exists + File sourceDirectory = fileUpdater.getSourceDirectory(); + assertTrue("sourcedir is null", sourceDirectory != null); + assertTrue("sourcedir does not exists " + sourceDirectory, sourceDirectory.exists()); + + // test destination dir exists + File destinationDirectory = fileUpdater.getDestinationDirectory(); + assertTrue("destinationDirectory is null", destinationDirectory != null); + assertTrue("destinationDirectory does not exists " + destinationDirectory, destinationDirectory.exists()); + + sourceFile = TestHelper.getFile(fileUpdater.getSourceDirectory(), "org", "nuiton", "io", JavaDummy.class.getSimpleName() + ".java"); + + } + + @Test + public void testSourceFileIsUptoDate() throws Exception { + + assertTrue("fileUpdater was not init", fileUpdater != null); + assertTrue("sourceFile was not init ", sourceFile != null); + assertTrue("could not find source of this test " + sourceFile, sourceFile.exists()); + + // java file is up to date since it was compiled to launch this test + assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + + mirrorFile = fileUpdater.getMirrorFile(sourceFile); + } + + @Test + public void testSourceFileDoesNotHaveMirrorFile() throws Exception { + + assertTrue("fileUpdater was not init", fileUpdater != null); + assertTrue("sourceFile was not init ", sourceFile != null); + assertTrue("could not find source of this test " + sourceFile, sourceFile.exists()); + assertTrue("mirrorFile was not init ", mirrorFile != null); + assertTrue("could not find mirrorFile " + mirrorFile, mirrorFile.exists()); + + // now rename mirror Class, so source file is no more up to date + File mirrorClassRenamed = new File(fileUpdater.getMirrorFile(sourceFile).getAbsolutePath() + "2"); + mirrorFile.renameTo(mirrorClassRenamed); + + // java file is no more up to date + assertFalse(sourceFile + " should not be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + + // renmae mirror Class to his original name + mirrorClassRenamed.renameTo(mirrorFile); + + // java file is now up to date (rename method does not affect lasmodified property on a file) + assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + } + + @Test + public void testSourceFileIsNewerThanMirrorFile() throws Exception { + + assertTrue("fileUpdater was not init", fileUpdater != null); + assertTrue("sourceFile was not init ", sourceFile != null); + assertTrue("could not find source of this test " + sourceFile, sourceFile.exists()); + assertTrue("mirrorFile was not init ", mirrorFile != null); + assertTrue("could not find mirrorFile " + mirrorFile, mirrorFile.exists()); + + long sourceTime = sourceFile.lastModified(); + long mirrorTime = mirrorFile.lastModified(); + + // make source file newer than mirror file + sourceFile.setLastModified(mirrorTime + 10); + + // java file is no more up to date + assertFalse(sourceFile + " should not be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + + // put back old time to source file + sourceFile.setLastModified(sourceTime); + + // java file is now up to date (rename method does not affect lasmodified property on a file) + assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + } +} Property changes on: trunk/src/test/java/org/nuiton/io/JavaFileUpdaterTest.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/test/java/org/nuiton/io/JaxxFileUpdaterTest.java (from rev 580, trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java) =================================================================== --- trunk/src/test/java/org/nuiton/io/JaxxFileUpdaterTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/io/JaxxFileUpdaterTest.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,132 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.io; + +import java.io.File; +import org.junit.BeforeClass; +import org.junit.Test; +import org.nuiton.plugin.TestHelper; +import static org.junit.Assert.*; + +/** + * Test of a {@link org.nuiton.util.FileUpdaterHelper.JaxxFileUpdater} on the test sourcepath + * + * @author chemit + */ +public class JaxxFileUpdaterTest { + + static MirroredFileUpdater fileUpdater; + static File sourceFile; + static File mirrorFile; + + @BeforeClass + public static void initClass() throws Exception { + + File basedir = TestHelper.getBasedir(); + + File src = TestHelper.getFile(basedir, "src", "test", "resources"); + File dir = TestHelper.getFile(basedir, "target", "test-classes"); + fileUpdater = FileUpdaterHelper.newJaxxFileUpdater(src, dir); + + // test source dir exists + File sourceDirectory = fileUpdater.getSourceDirectory(); + assertTrue("sourcedir is null", sourceDirectory != null); + assertTrue("sourcedir does not exists " + sourceDirectory, sourceDirectory.exists()); + + // test destination dir exists + File destinationDirectory = fileUpdater.getDestinationDirectory(); + assertTrue("destinationDirectory is null", destinationDirectory != null); + assertTrue("destinationDirectory does not exists " + destinationDirectory, destinationDirectory.exists()); + + sourceFile = TestHelper.getFile(fileUpdater.getSourceDirectory(), "org", "nuiton", "io", JaxxDummy.class.getSimpleName() + ".jaxx"); + + } + + @Test + public void testSourceFileIsUptoDate() throws Exception { + + assertTrue("fileUpdater was not init", fileUpdater != null); + + assertTrue("sourceFile was not init ", sourceFile != null); + assertTrue("could not find source of this test " + sourceFile, sourceFile.exists()); + + mirrorFile = fileUpdater.getMirrorFile(sourceFile); + + // we do not know if jaxx file is newer than the dummy java source ? + + sourceFile.setLastModified(mirrorFile.lastModified() - 10); + + // java file is up to date since it was compiled to launch this test + assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + } + + @Test + public void testSourceFileDoesNotHaveMirrorFile() throws Exception { + + assertTrue("fileUpdater was not init", fileUpdater != null); + + assertTrue("sourceFile was not init ", sourceFile != null); + assertTrue("could not find source of this test " + sourceFile, sourceFile.exists()); + + assertTrue("mirrorFile was not init ", mirrorFile != null); + assertTrue("could not find mirrorFile " + mirrorFile, mirrorFile.exists()); + + // now rename mirror Class, so source file is no more up to date + File mirrorClassRenamed = new File(fileUpdater.getMirrorFile(sourceFile).getAbsolutePath() + "2"); + mirrorFile.renameTo(mirrorClassRenamed); + + // java file is no more up to date + assertFalse(sourceFile + " should not be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + + // renmae mirror Class to his original name + mirrorClassRenamed.renameTo(mirrorFile); + + // java file is now up to date (rename method does not affect lasmodified property on a file) + assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + } + + @Test + public void testSourceFileIsNewerThanMirrorFile() throws Exception { + + assertTrue("fileUpdater was not init", fileUpdater != null); + + assertTrue("sourceFile was not init ", sourceFile != null); + assertTrue("could not find source of this test " + sourceFile, sourceFile.exists()); + + assertTrue("mirrorFile was not init ", mirrorFile != null); + assertTrue("could not find mirrorFile " + mirrorFile, mirrorFile.exists()); + + long sourceTime = sourceFile.lastModified(); + long mirrorTime = mirrorFile.lastModified(); + + // make source file newer than mirror file + sourceFile.setLastModified(mirrorTime + 10); + + // java file is no more up to date + assertFalse(sourceFile + " should not be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + + // put back old time to source file + sourceFile.setLastModified(sourceTime); + + // java file is now up to date (rename method does not affect lasmodified property on a file) + assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile)); + } +} Property changes on: trunk/src/test/java/org/nuiton/io/JaxxFileUpdaterTest.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java =================================================================== --- trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java 2009-09-29 10:32:02 UTC (rev 599) @@ -25,9 +25,12 @@ import java.io.File; import java.io.IOException; import org.nuiton.plugin.TestHelper; -import org.nuiton.util.PluginHelper; - -/** @author chemit */ +/** + * + * @author chemit + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin + */ +@Deprecated public abstract class BaseLicenseTestCase extends Assert { protected static final String encoding = "utf-8"; @@ -67,16 +70,16 @@ String content = ""; if (defFile.exists()) { - content = PluginHelper.readAsString(defFile, encoding) + "\n"; + content = TestHelper.readAsString(defFile, encoding) + "\n"; } - PluginHelper.write(defFile, content + licenseName + "=My dummy license\n", encoding); + TestHelper.writeString(defFile, content + licenseName + "=My dummy license\n", encoding); // create dummy licenses File file = new File(repo, licenseName); file.mkdirs(); - PluginHelper.write(new File(file, "license.txt"), "license:" + licenseName, encoding); - PluginHelper.write(new File(file, "header.txt"), "header:" + licenseName, encoding); + TestHelper.writeString(new File(file, "license.txt"), "license:" + licenseName, encoding); + TestHelper.writeString(new File(file, "header.txt"), "header:" + licenseName, encoding); } } Modified: trunk/src/test/java/org/nuiton/license/JarLicenseResolverTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/JarLicenseResolverTest.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/test/java/org/nuiton/license/JarLicenseResolverTest.java 2009-09-29 10:32:02 UTC (rev 599) @@ -25,8 +25,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Map; - -/** @author chemit */ +/** + * + * @author chemit + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin + */ +@Deprecated public class JarLicenseResolverTest extends BaseLicenseTestCase { @Test(expected = IllegalArgumentException.class) Modified: trunk/src/test/java/org/nuiton/license/LicenseFactoryTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/LicenseFactoryTest.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/test/java/org/nuiton/license/LicenseFactoryTest.java 2009-09-29 10:32:02 UTC (rev 599) @@ -24,8 +24,12 @@ import java.io.File; import java.util.Map; - -/** @author chemit */ +/** + * + * @author chemit + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin + */ +@Deprecated public class LicenseFactoryTest extends BaseLicenseTestCase { @Test Modified: trunk/src/test/java/org/nuiton/license/LicenseResolverTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/LicenseResolverTest.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/test/java/org/nuiton/license/LicenseResolverTest.java 2009-09-29 10:32:02 UTC (rev 599) @@ -24,8 +24,12 @@ import java.io.File; import java.util.Map; - -/** @author chemit */ +/** + * + * @author chemit + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin + */ +@Deprecated public class LicenseResolverTest extends BaseLicenseTestCase { @Test(expected = IllegalArgumentException.class) Modified: trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java =================================================================== --- trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-09-29 10:32:02 UTC (rev 599) @@ -26,7 +26,12 @@ import java.io.File; import java.io.IOException; import org.nuiton.plugin.AbstractMojoTest; - +/** + * + * @author chemit + * @deprecated since 1.0.3, move all license stuff in maven-license-plugin + */ +@Deprecated public class LicensePluginTest extends AbstractMojoTest<LicensePlugin> { @Override Modified: trunk/src/test/java/org/nuiton/plugin/TestHelper.java =================================================================== --- trunk/src/test/java/org/nuiton/plugin/TestHelper.java 2009-09-27 20:17:18 UTC (rev 598) +++ trunk/src/test/java/org/nuiton/plugin/TestHelper.java 2009-09-29 10:32:02 UTC (rev 599) @@ -32,7 +32,7 @@ * @author chemit * @since 1.0.3 */ -public abstract class TestHelper { +public abstract class TestHelper extends PluginHelper { protected static boolean verbose; protected static File basedir; @@ -94,20 +94,6 @@ TestHelper.delegateMojoTest = delegateMojoTest; } - public static File getFile(File base, String... paths) { - StringBuilder buffer = new StringBuilder(); - for (String path : paths) { - buffer.append(File.separator).append(path); - } - File f = new File(base, buffer.substring(1)); - return f; - } - - public static String getRelativePath(File base, File file) { - String result = file.getAbsolutePath().substring(base.getAbsolutePath().length() + 1); - return result; - } - public static class DelegateMojoTestCase extends AbstractMojoTestCase { @Override Copied: trunk/src/test/resources/org/nuiton/io/JavaDummy.java (from rev 580, trunk/src/test/java/org/nuiton/util/JavaDummy.java) =================================================================== --- trunk/src/test/resources/org/nuiton/io/JavaDummy.java (rev 0) +++ trunk/src/test/resources/org/nuiton/io/JavaDummy.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,28 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.io; + +/** @author chemit */ +public class JavaDummy { + /** + * A dummy file to test {@link org.nuiton.util.FileUpdaterHelper.JavaFileUpdater} in {@link JavaFileUpdaterTest} + */ +} Property changes on: trunk/src/test/resources/org/nuiton/io/JavaDummy.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/test/resources/org/nuiton/io/JaxxDummy.java (from rev 580, trunk/src/test/java/org/nuiton/util/JaxxDummy.java) =================================================================== --- trunk/src/test/resources/org/nuiton/io/JaxxDummy.java (rev 0) +++ trunk/src/test/resources/org/nuiton/io/JaxxDummy.java 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,28 @@ +/* + * *##% + * Maven helper plugin + * Copyright (C) 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.io; + +/** @author chemit */ +public class JaxxDummy { + /** + * A dummy file to test {@link org.nuiton.util.FileUpdaterHelper.JaxxFileUpdater} in {@link JaxxFileUpdaterTest} + */ +} Property changes on: trunk/src/test/resources/org/nuiton/io/JaxxDummy.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/test/resources/org/nuiton/io/JaxxDummy.jaxx (from rev 580, trunk/src/test/resources/org/nuiton/util/JaxxDummy.jaxx) =================================================================== --- trunk/src/test/resources/org/nuiton/io/JaxxDummy.jaxx (rev 0) +++ trunk/src/test/resources/org/nuiton/io/JaxxDummy.jaxx 2009-09-29 10:32:02 UTC (rev 599) @@ -0,0 +1,3 @@ +<Object> + Dummy file to test org.nuiton.util.FileUpdaterHelper.JaxxFileUpdater +</Object> \ No newline at end of file Property changes on: trunk/src/test/resources/org/nuiton/io/JaxxDummy.jaxx ___________________________________________________________________ Added: svn:mergeinfo +
participants (1)
-
tchemit@users.nuiton.org