Maven-helper-plugin-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
September 2009
- 1 participants
- 34 discussions
r600 - in trunk/src: main/java/org/nuiton/plugin site site/apt
by tchemit@users.nuiton.org 29 Sep '09
by tchemit@users.nuiton.org 29 Sep '09
29 Sep '09
Author: tchemit
Date: 2009-09-29 19:47:52 +0200 (Tue, 29 Sep 2009)
New Revision: 600
Added:
trunk/src/site/apt/mojoFramework.apt
Modified:
trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
trunk/src/site/apt/index.apt
trunk/src/site/apt/mojoTestFramework.apt
trunk/src/site/site.xml
Log:
Evolution #66: documentation des frameworks mojo et test mojo
Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-09-29 10:32:02 UTC (rev 599)
+++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-09-29 17:47:52 UTC (rev 600)
@@ -41,7 +41,7 @@
import org.nuiton.io.MirroredFileUpdater;
/**
- * Un MOJO de base pour les autres MOJO concrets avec les options communes.
+ * Base mojo with usefull methods and implementing {@link Plugin} contract.
*
* @author chemit
*/
@@ -64,7 +64,7 @@
* <p/>
* The method {@link #execute()} invoke this method only and only if :
* <ul>
- * <li>{@link #checkPackaging()} returns <code>false</code> (filtrer project type, for example).</li>
+ * <li>{@link #checkPackaging()} returns <code>true</code>.</li>
* <li>method {@link #init()} returns <code>true</code>.</li>
* </ul>
*
@@ -132,17 +132,12 @@
return true;
}
-// /**
-// *
-// * @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;
-// }
+ /**
+ * Accept the project's packaging between some given.
+ *
+ * @param packages the accepted packaging
+ * @return {@code true} if the project's packagin is one of the given ones.
+ */
protected boolean acceptPackaging(Packaging... packages) {
String projectPackaging = getProject().getPackaging();
@@ -156,6 +151,12 @@
return false;
}
+ /**
+ * Accept the project's packaging if not in given one.
+ *
+ * @param packages the rejecting packagings
+ * @return {@code true} if the project's packaging is not in the given ones.
+ */
protected boolean rejectPackaging(Packaging... packages) {
String projectPackaging = getProject().getPackaging();
@@ -170,7 +171,7 @@
}
/**
- * Does the actual copy of the file and logging.
+ * Copy a file to a given locationand logging.
*
* @param srcFile represents the file to copy.
* @param destFile file name of destination file.
@@ -184,37 +185,21 @@
getLog().info("Copying " + srcFile.getName() + " to " + destFile);
PluginHelper.copy(srcFile, destFile);
-// FileUtils.copyFile(srcFile, destFile);
} catch (Exception e) {
throw new MojoExecutionException("Error copying from " + srcFile + " to " + destFile, e);
}
}
-// /**
-// * Does the actual copy of the content to a fileand logging.
-// *
-// * @param content represents the content to 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);
-// }
-// }
+ /**
+ * Write a {@code content} into the given destination file for the given
+ * {@code encoding}.
+ *
+ * @param destFile location where to write the content
+ * @param content content ot write in the file
+ * @param encoding the enconding of the file
+ * @throws IOException if any pb while writing the content into the file
+ */
public void writeFile(File destFile, String content, String encoding) throws IOException {
PluginHelper.writeString(destFile, content, encoding);
}
@@ -231,6 +216,15 @@
return f.exists() && f.lastModified() > pomFile.lastModified();
}
+ /**
+ * Collects some file.
+ *
+ * @param includes includes
+ * @param excludes excludes
+ * @param roots root directories to treate
+ * @param files cache of file detected indexed by their root directory
+ * @param updater
+ */
protected void getFilesToTreateForRoots(String[] includes, String[] excludes, List<String> roots, Map<File, String[]> files, MirroredFileUpdater updater) {
DirectoryScanner ds = new DirectoryScanner();
@@ -290,6 +284,15 @@
}
}
+ /**
+ * Collect to some files with a mirror.
+ *
+ * @param includes includes
+ * @param excludes excludes
+ * @param srcDir the directory to treate
+ * @param updater an updater (will give the mirrored files)
+ * @return the map of mirrored files associated to their files in srcDir
+ */
protected Map<String, String> getFilesToTreate(String[] includes, String[] excludes, File srcDir, MirroredFileUpdater updater) {
Map<String, String> result = new java.util.TreeMap<String, String>();
@@ -348,6 +351,12 @@
return result;
}
+ /**
+ * Add a given directory in maven project's compile source roots (if not
+ * already present).
+ *
+ * @param srcDir the location to include in compile source roots
+ */
protected void addCompileSourceRoots(File srcDir) {
if (!getProject().getCompileSourceRoots().contains(srcDir.getPath())) {
if (isVerbose()) {
@@ -357,6 +366,12 @@
}
}
+ /**
+ * Remove a given directory in maven project's compile source roots (if
+ * present).
+ *
+ * @param srcDir the location to remove from compile source roots
+ */
protected void removeCompileSourceRoots(File srcDir) {
if (getProject().getCompileSourceRoots().contains(srcDir.getPath())) {
if (isVerbose()) {
@@ -366,6 +381,12 @@
}
}
+ /**
+ * Add a given directory in maven project's test compile source roots (if not
+ * already present).
+ *
+ * @param srcDir the location to include in test compile source roots
+ */
protected void addTestCompileSourceRoots(File srcDir) {
if (!getProject().getTestCompileSourceRoots().contains(srcDir.getPath())) {
if (isVerbose()) {
@@ -375,6 +396,12 @@
}
}
+ /**
+ * Remove a given directory in maven project's test compile source roots (if
+ * present).
+ *
+ * @param srcDir the location to remove from test compile source roots
+ */
protected void removeTestCompileSourceRoots(File srcDir) {
if (getProject().getTestCompileSourceRoots().contains(srcDir.getPath())) {
if (isVerbose()) {
@@ -384,6 +411,11 @@
}
}
+ /**
+ * Add a new resource location to the maven project (in not already present).
+ *
+ * @param dir the new resource location to add
+ */
protected void addResourceDir(String dir) {
boolean added = PluginHelper.addResourceDir(dir, getProject());
if (added) {
@@ -391,6 +423,11 @@
}
}
+ /**
+ * Add a new test resource location to the maven project (in not already present).
+ *
+ * @param dir the new resource location to add
+ */
protected void addTestResourceDir(String dir) {
boolean added = PluginHelper.addTestResourceDir(dir, getProject());
if (added) {
@@ -398,6 +435,19 @@
}
}
+ /**
+ * Init mojo classLoader.
+ *
+ * @param project the maven project
+ * @param src the source directory
+ * @param addSourcesToClassPath a flag to a maven sources to classLoader
+ * @param testPhase a flag to specify if we are in a test phase (changes the classLoader)
+ * @param addResourcesToClassPath flag to add maven's resources to classLoader
+ * @param addCompileClassPath flag to add maven's project compile classPath to classLoader
+ * @param addProjectClassPath flag to add maven'es project dependecies to classLoader
+ * @return the new classLoader
+ * @throws MalformedURLException
+ */
@SuppressWarnings({"unchecked"})
protected URLClassLoader initClassLoader(MavenProject project, File src, boolean addSourcesToClassPath, boolean testPhase, boolean addResourcesToClassPath, boolean addCompileClassPath, boolean addProjectClassPath) throws MalformedURLException {
URLClassLoader loader = null;
@@ -465,10 +515,11 @@
}
/**
+ * Obtain the url of a file, if file does not exist, try in the classPath.
*
- * @param f le fichier de template
- * @return l'url du fichier demande
- * @throws IOException pour toute erreur de recherche
+ * @param f the required resource file.
+ * @return the url of the resource
+ * @throws IOException for any error while looking up for the url of the resources
*/
protected URL getTemplate(File f) throws IOException {
URL r = null;
@@ -481,11 +532,10 @@
}
/**
- * Vérifie que le fichier donné existe bien (sur le filesystem ou
- * dans le class-path).
- *
- * @param f le fichier que l'on veut vérifié
- * @throws IOException pour tout erreur de recherche
+ * Check that the given resource exists in a simple fs file or in the classPath.
+ *
+ * @param f the required resource file.
+ * @throws IOException for any error while looking up for the resources content.
*/
protected void checkResource(File f) throws IOException {
if (!f.exists()) {
Modified: trunk/src/site/apt/index.apt
===================================================================
--- trunk/src/site/apt/index.apt 2009-09-29 10:32:02 UTC (rev 599)
+++ trunk/src/site/apt/index.apt 2009-09-29 17:47:52 UTC (rev 600)
@@ -27,8 +27,6 @@
* {{{add-third-party-mojo.html} helper:add-third-party}} write the licenses of all third-party libraries used in project.
- * {{{check-project-files-mojo.html} helper:check-project-files}} check the root module of project has a changelog.txt file.
-
* {{{help-mojo.html} helper:help}} display help about the plugin (goals, usage).
* {{{available-licenses-mojo.html} helper:available-licenses}} display the known licenses of the plugin.
@@ -39,7 +37,7 @@
Plugin toolkit overview
- {{{mojoFramework.html}Mojo test framework}}.
+ {{{mojoFramework.html}Mojo framework}}.
see {{{apidocs/index.html}javadoc}}.
Added: trunk/src/site/apt/mojoFramework.apt
===================================================================
--- trunk/src/site/apt/mojoFramework.apt (rev 0)
+++ trunk/src/site/apt/mojoFramework.apt 2009-09-29 17:47:52 UTC (rev 600)
@@ -0,0 +1,40 @@
+----
+Mojo framework
+----
+----
+2009-08-22
+----
+
+Introduction
+
+ This document explains the mojo framework api of <maven-helper-plugin>.
+
+ The <mojo framework> aims to simplify the writing of new mojos.
+
+ To use this framework, your mojo classes <<MUST>> implement the contract
+ <<org.nuiton.plugin.Plugin>>.
+
+ The framework use these technologies :
+
+ * <<java 6>>
+
+ * <<maven 2.2.1>>
+
+How to use it
+
+ Implements the <<org.nuiton.plugin.AbstractPlugin>> class.
+
+ There is some filtering methods :
+
+ * <<checkPackaging>> to test if can perform mojo for the project's packaging.
+
+ * <<init>> : initialize the mojo, and return <<true>> if can execute the mojo.
+
+ The core method is the <<doAction>> one, put there your logic.
+
+Usefull methods
+
+ The <<org.nuiton.plugin.AbstractPlugin>> contains some usefull methods to work
+ around the maven project and io operations on the files of the project.
+
+ For more explanations, see the {{{apidocs/index.html}javadoc}}.
Modified: trunk/src/site/apt/mojoTestFramework.apt
===================================================================
--- trunk/src/site/apt/mojoTestFramework.apt 2009-09-29 10:32:02 UTC (rev 599)
+++ trunk/src/site/apt/mojoTestFramework.apt 2009-09-29 17:47:52 UTC (rev 600)
@@ -1,5 +1,5 @@
----
-Test framework api
+Mojo Test framework
----
----
2009-08-22
@@ -17,6 +17,8 @@
The framework use these technologies :
* <<java 6>>
+
+ * <<maven 2.2.1>>
* <<junit 4.7>>
Modified: trunk/src/site/site.xml
===================================================================
--- trunk/src/site/site.xml 2009-09-29 10:32:02 UTC (rev 599)
+++ trunk/src/site/site.xml 2009-09-29 17:47:52 UTC (rev 600)
@@ -43,7 +43,6 @@
<item name="add-license" href="add-license-mojo.html"/>
<item name="add-third-party" href="add-third-party-mojo.html"/>
<item name="available-licenses" href="available-licenses-mojo.html"/>
- <item name="check-project-files" href="check-project-files-mojo.html"/>
<item name="send-email" href="send-email-mojo.html"/>
<item name="collect-files" href="collect-files-mojo.html"/>
<item name="help" href="help-mojo.html"/>
@@ -52,6 +51,7 @@
</menu>
<menu name="Développeur">
+ <item name="Mojo framework" href="mojoFramework.html"/>
<item name="Mojo test framework" href="mojoTestFramework.html"/>
<item name="A faire" href="Todo.html"/>
</menu>
1
0
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
+
1
0
Author: tchemit
Date: 2009-09-27 22:17:18 +0200 (Sun, 27 Sep 2009)
New Revision: 598
Modified:
trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java
Log:
fix javadoc
Modified: trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java 2009-09-27 19:16:22 UTC (rev 597)
+++ trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java 2009-09-27 20:17:18 UTC (rev 598)
@@ -236,7 +236,7 @@
}
/**
- * To offer inside each test method (annotated by a {@link Test}) the
+ * To offer inside each test method (annotated by a {@link org.junit.Test}) the
* following properties :
*
* <ul>
1
0
Author: tchemit
Date: 2009-09-27 21:16:22 +0200 (Sun, 27 Sep 2009)
New Revision: 597
Added:
trunk/src/site/apt/mojoTestFramework.apt
Modified:
trunk/src/site/apt/index.apt
trunk/src/site/site.xml
Log:
add documentation for Mojo Test Framework
Modified: trunk/src/site/apt/index.apt
===================================================================
--- trunk/src/site/apt/index.apt 2009-09-27 19:15:24 UTC (rev 596)
+++ trunk/src/site/apt/index.apt 2009-09-27 19:16:22 UTC (rev 597)
@@ -45,6 +45,8 @@
Test toolkit overview
+ * {{{mojoTestFramework.html}Mojo test framework}}.
+
see test-javadoc.
<<A faire>>
Added: trunk/src/site/apt/mojoTestFramework.apt
===================================================================
--- trunk/src/site/apt/mojoTestFramework.apt (rev 0)
+++ trunk/src/site/apt/mojoTestFramework.apt 2009-09-27 19:16:22 UTC (rev 597)
@@ -0,0 +1,175 @@
+----
+Test framework api
+----
+----
+2009-08-22
+----
+
+Introduction
+
+ This document explains to mojo test framework api of <maven-helper-plugin>.
+
+ The <mojo test framework> aims to simplify the writing of tests on a mojo.
+
+ To use this framework, your mojo classes <<MUST>> implement the contract
+ <<org.nuiton.plugin.Plugin>>.
+
+ The framework use these technologies :
+
+ * <<java 6>>
+
+ * <<junit 4.7>>
+
+ * <<maven-plugin-testing-harness 1.2>>.
+
+How to use it
+
+ For each mojo you want to test, implements the <<org.nuiton.plugin.AbstractMojoTest>>
+ class.
+
+ For each mojo's invocation you want to test :
+
+ * write a method with a Junit <<Test>> annotation.
+
+ * write the pom file corresponding to the mojo's invocation to test.
+
+Directory layout of a mojo test
+
+ The mojo test framework api follows a simple directory layout convention :
+
+ * the mojo test class is in the same package as the mojo (respect JUnit convention)
+
+ * the pom files to use for tests are in the sub package with the name of the
+ plugin test class of the test class's package.
+
+ * each test method's name is the file name (suffixed by <.xml>) of the pom to use.
+
+Example
+
+ Having a <<org.nuiton.test.plugin.MyMojo>> class to test, and wants to do
+ two tests <firstTest> and <secondTest>.
+
+ Here is the test class code to produce :
+
+--------------------------------------------------------------------------------
+package org.nuiton.test.plugin;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.nuiton.plugin.AbstractMojoTest;
+
+public class MyMojoTest extends AbstractMojoTest<MyMojo> {
+
+ @Override
+ protected String getGoalName(String methodName) {
+ return "my-goal";
+ }
+
+ @Test
+ public void firstTest() throws Exception {
+
+ MyMojo mojo = getMojo();
+
+ mojo.execute();
+
+ // do my assertions after the goal be executed
+ }
+
+ @Test
+ public void seconTest() throws Exception {
+
+ MyMojo mojo = getMojo();
+
+ mojo.execute();
+
+ // do my assertions after the goal be executed
+ }
+}
+--------------------------------------------------------------------------------
+
+ and writes two pom files names <firstTest.xml> and <secondTest.xml> in directory
+
+--------------------------------------------------------------------------------
+src/test/resources/org/nuiton/test/plugin/MyMojoTest
+--------------------------------------------------------------------------------
+
+ Finally, the next directory tree is what you should have for the example project :
+
+--------------------------------------------------------------------------------
+maven-test-plugin
+|-- pom.xml
+`-- src
+ |-- main
+ | |-- java
+ | | `-- org
+ | | `-- nuiton
+ | | `-- test
+ | | `-- plugin
+ | | `-- MyMojo.java
+ `-- test
+ |-- java
+ | `-- org
+ | `-- nuiton
+ | `-- test
+ | `-- plugin
+ | `-- MyMojoTest.java
+ `-- resources
+ `-- org
+ `-- nuiton
+ `-- test
+ `-- plugin
+ `-- MyMojoTest
+ |-- firstTest.xml
+ `-- secondTest.xml
+--------------------------------------------------------------------------------
+
+Go deeper in AbstractMojoTest
+
+ Often, we could want to do some extra initialization on the mojo before
+ executing it.
+
+ <Note:> There is some limitations of the <maven-plugin-testing-harness> and
+ 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 :
+
+--------------------------------------------------------------------------------
+
+ @Override
+ protected void setUpMojo(MyMojoTest mojo, File pomFile) throws Exception {
+ super.setUpMojo(mojo, pomFile);
+
+ // do your extra pom customization
+ }
+--------------------------------------------------------------------------------
+
+* Changing the default behaviour
+
+ If you do not want to follow the default behaviour, you can override some
+ methods to make the test fits your needs.
+
+ <<Note:>> this is not a good idea to change the default behaviour, since it
+ would be nice that every mojo test respect the conventions to make it easier
+ for every developper (and not only the one who wrote the test case...)
+
+
+--------------------------------------------------------------------------------
+
+ @Override
+ protected MyMojo createMojo(File pomFile, String goalName) throws Exception {
+ return super.createMojo(pomFile, goalName);
+ }
+
+ @Override
+ protected File getPomFile(File testDir, String methodName, String goalName) {
+ return super.getPomFile(testDir, methodName, goalName);
+ }
+
+ @Override
+ protected File getTestDir(String methodName, String goalName) {
+ return super.getTestDir(methodName, goalName);
+ }
+--------------------------------------------------------------------------------
+
+ For more explanations, see the test-javadoc.
Modified: trunk/src/site/site.xml
===================================================================
--- trunk/src/site/site.xml 2009-09-27 19:15:24 UTC (rev 596)
+++ trunk/src/site/site.xml 2009-09-27 19:16:22 UTC (rev 597)
@@ -52,6 +52,7 @@
</menu>
<menu name="Développeur">
+ <item name="Mojo test framework" href="mojoTestFramework.html"/>
<item name="A faire" href="Todo.html"/>
</menu>
1
0
Author: tchemit
Date: 2009-09-27 21:15:24 +0200 (Sun, 27 Sep 2009)
New Revision: 596
Modified:
trunk/pom.xml
Log:
- add javadoc for test (use javadoc plugin v 2.6)
- improve test dependencies (exclude wagon and others...)
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-09-27 19:11:50 UTC (rev 595)
+++ trunk/pom.xml 2009-09-27 19:15:24 UTC (rev 596)
@@ -172,6 +172,26 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
</exclusion>
+
+ <exclusion>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-http-lightweight</artifactId>
+ </exclusion>
+
+ <exclusion>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-file</artifactId>
+ </exclusion>
+
+ <exclusion>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh</artifactId>
+ </exclusion>
+
+ <exclusion>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-api</artifactId>
+ </exclusion>
</exclusions>
</dependency>
@@ -183,6 +203,13 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.9</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<!-- ************************************************************* -->
@@ -243,7 +270,7 @@
<maven.version>2.2.1</maven.version>
<plexusMailSender.version>1.0-alpha-2</plexusMailSender.version>
- <javadoc.version>2.4</javadoc.version>
+ <javadoc.version>2.6</javadoc.version>
<maven.src.dir>${basedir}/src</maven.src.dir>
<maven.compile.source>1.6</maven.compile.source>
@@ -564,6 +591,12 @@
<goal>jar</goal>
</goals>
</execution>
+ <execution>
+ <id>attach-test-javadocs</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
</executions>
</plugin>
@@ -948,6 +981,9 @@
<execution>
<id>attach-javadocs</id>
</execution>
+ <execution>
+ <id>attach-test-javadocs</id>
+ </execution>
</executions>
</plugin>
1
0
Author: tchemit
Date: 2009-09-27 21:11:50 +0200 (Sun, 27 Sep 2009)
New Revision: 595
Modified:
trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java
Log:
add javadoc on AbstractMojoTest + improve design
Modified: trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java 2009-09-27 19:09:25 UTC (rev 594)
+++ trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java 2009-09-27 19:11:50 UTC (rev 595)
@@ -21,71 +21,193 @@
package org.nuiton.plugin;
import java.io.File;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.maven.plugin.Mojo;
-import org.apache.maven.plugin.logging.Log;
-import org.apache.maven.plugin.logging.SystemStreamLog;
+import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuilderConfiguration;
import org.junit.rules.TestName;
import org.junit.Rule;
-import org.junit.AfterClass;
import org.junit.Assert;
-import org.junit.BeforeClass;
import org.junit.runners.model.FrameworkMethod;
/**
+ * Base test class for a mojo.
*
+ * <b>Note:</b> replace the previous class
+ * {@code org.nuiton.util.BasePluginTestCase}.
+ * <p/>
+ * Inside each test method, we can use the following objects :
+ *
+ * <ul>
+ * <li>{@link #getTestDir()} : location of mojo resources (where the pom file for example)</li>
+ * <li>{@link #getPomFile()} : location of the pom file</li>
+ * <li>{@link #getMojo()} : the instanciated and ready to execute mojo</li>
+ * </ul>
+ * <p/>
+ * To change the behaviour of initialization of mojo, you can override the
+ * following methods :
+ * <ul>
+ * <li>{@link #getBasedir()} </li>
+ * <li>{@link #getTestBasedir()} </li>
+ * <li>{@link #getTestDir(java.lang.String, java.lang.String)}</li>
+ * <li>{@link #getPomFile(java.io.File, java.lang.String, java.lang.String)}</li>
+ * <li>{@link #createMojo(java.io.File, java.lang.String)}</li>
+ * <li>{@link #setUpMojo(org.nuiton.plugin.Plugin, java.io.File)}</li>
+ * </ul>
+ *
* @param <P> type of goal to test
* @author chemit
* @since 1.0.3
*/
public abstract class AbstractMojoTest<P extends Plugin> {
- protected static Log log;
- protected static File testDir;
+ /**
+ * Test logger
+ */
+ protected static final Log log = LogFactory.getLog(AbstractMojoTest.class);
+ /**
+ * the basedir of the project
+ */
+ protected static File basedir;
+ /**
+ * the basedir of all tests (by convention
+ * {@code getBasedir()/target/test-classes}).
+ */
+ protected static File testBasedir;
+ /**
+ * Your test rule which offers methodName, testDir, pomFile and mojo inside
+ * test methods.
+ */
@Rule
- public MojoTestName name = new MojoTestName();
+ public MojoTestRule name = new MojoTestRule();
- @BeforeClass
- public static void beforeClass() throws Exception {
- log = new SystemStreamLog();
- TestHelper.getBasedir();
+ public File getBasedir() {
+ if (basedir == null) {
+ basedir = TestHelper.getBasedir();
+ if (log.isDebugEnabled()) {
+ log.debug("basedir = " + basedir);
+ }
+ }
+ return basedir;
}
- @AfterClass
- public static void afterClass() throws Exception {
- testDir = null;
- log = null;
+ public File getTestBasedir() {
+ if (testBasedir == null) {
+ testBasedir = TestHelper.getFile(getBasedir(), "target", "test-classes");
+ if (log.isDebugEnabled()) {
+ log.debug("testBasedir = " + testBasedir);
+ }
+ }
+ return testBasedir;
}
+ public String getRelativePathFromBasedir(File f) {
+ return TestHelper.getRelativePath(getBasedir(), f);
+ }
+
+ public String getRelativePathFromTestBasedir(File f) {
+ return TestHelper.getRelativePath(getTestBasedir(), f);
+ }
+
+ /**
+ * Obtain the name of the goal according to the methodName.
+ * <p/>
+ * By convention, we should consider that a test class use always the same
+ * goal's name.
+ *
+ * @param methodName the name of the next test to execute.
+ *
+ * @return the name of the goal to test for the given method test name.
+ */
protected abstract String getGoalName(String methodName);
+ /**
+ * Obtain the location of the directory where to find resources for the next
+ * test.
+ * <p/>
+ * By convention, will be the package named by the test class name from the
+ * {@link #getTestBasedir()}.
+ *
+ * @param methodName the method of the next test to execute
+ * @param goalName the common goal name to use
+ * @return the directory where to find resources for the test
+ */
+ protected File getTestDir(String methodName, String goalName) {
+
+ String rep = getClass().getName();
+ rep = rep.replaceAll("\\.", File.separator);
+
+ File testDir = new File(getTestBasedir(), rep);
+ if (isVerbose()) {
+ log.info("test dir = " + getRelativePathFromBasedir(testDir));
+ } else if (log.isDebugEnabled()) {
+ log.debug("test dir = " + getRelativePathFromBasedir(testDir));
+ }
+
+ return testDir;
+ }
+
+ /**
+ * Obtain the location of the pom file to use for next mojo test.
+ * <p/>
+ * By default, the pom file is the file with name {@code methodName+".xml"}
+ * in the {@code testDir}.
+ *
+ * @param testDir the location of resources for the next test (is the result
+ * of the method {@link #getTestDir(java.lang.String, java.lang.String)}.
+ * @param methodName the name of the next test
+ * @param goalName the name of the common goal
+ * @return the location of the pom file for the next mojo test.
+ */
protected File getPomFile(File testDir, String methodName, String goalName) {
File pom = new File(testDir, methodName + ".xml");
if (isVerbose()) {
- log.info("getPomFile = " + TestHelper.getRelativePath(getBasedir(), pom));
+ log.info("pom file = " + getRelativePathFromBasedir(pom));
+ } else if (log.isDebugEnabled()) {
+ log.debug("pom file = " + getRelativePathFromBasedir(pom));
}
return pom;
}
+ /**
+ * Create the mojo base on the given {@code pomFile} for the
+ * given {@code goalName}.
+ *
+ * @param pomFile the location of the pom file
+ * @param goalName the name of the goal to lookup
+ * @return the instanciated mojo
+ * @throws Exception if any problem while creating the mojo
+ */
@SuppressWarnings("unchecked")
protected P createMojo(File pomFile, String goalName) throws Exception {
Mojo lookupMojo = TestHelper.lookupMojo(goalName, pomFile);
- P mojo = (P) lookupMojo;
- return mojo;
+ P result = (P) lookupMojo;
+ return result;
}
+ /**
+ * Initialize the given mojo.
+ *
+ * @param mojo the instanciate mojo
+ * @param pomFile the pom file used to instanciate the mojo
+ * @throws Exception if any pb
+ */
protected void setUpMojo(P mojo, File pomFile) throws Exception {
MavenProject project = mojo.getProject();
if (project == null) {
-// MavenProjectBuilder projectBuilder = (MavenProjectBuilder) delegate.getContainer().lookup(MavenProjectBuilder.ROLE);
-// ProjectBuilderConfiguration projectBuilderConfiguration = null;
-// project = projectBuilder.build(pomFile, projectBuilderConfiguration);
+ log.debug("init maven project");
+ MavenProjectBuilder projectBuilder = (MavenProjectBuilder) TestHelper.getDelegateMojoTest().getContainer().lookup(MavenProjectBuilder.ROLE);
+ ProjectBuilderConfiguration projectBuilderConfiguration = new DefaultProjectBuilderConfiguration();
+ project = projectBuilder.build(pomFile, projectBuilderConfiguration);
- project = new MavenProject();
+// project = new MavenProject();
mojo.setProject(project);
}
@@ -105,40 +227,43 @@
return name.getPomFile();
}
- protected File getBasedir() {
- return TestHelper.getBasedir();
- }
-
protected File getTestDir() {
- if (testDir == null) {
-
- String rep = getClass().getName();
- rep = rep.replaceAll("\\.", File.separator);
-
- File f = TestHelper.getFile(getBasedir(), "target", "test-classes");
-
- testDir = new File(f, rep);
- if (isVerbose()) {
- log.info("test dir = " + TestHelper.getRelativePath(getBasedir(), testDir));
- }
- }
- return testDir;
+ return name.getTestDir();
}
protected boolean isVerbose() {
return TestHelper.isVerbose();
}
- public class MojoTestName extends TestName {
+ /**
+ * To offer inside each test method (annotated by a {@link Test}) the
+ * following properties :
+ *
+ * <ul>
+ * <li>{@link #testDir} : location where to find resources for the test</li>
+ * <li>{@link #pomFile} : location of the pom file to use to build the mojo</li>
+ * <li>{@link #mojo} : the instanciated and initialized mojo</li>
+ * </ul>
+ */
+ protected class MojoTestRule extends TestName {
+ /**
+ * location of the pom to use
+ */
private File pomFile;
+ /**
+ * the mojo to used in the test method (based on the {@link #pomFile}).
+ */
private P mojo;
+ /**
+ * the directory where the resources of the test are
+ */
+ private File testDir;
- public MojoTestName() {
+ public MojoTestRule() {
if (log.isDebugEnabled()) {
- log.debug("NEW MojotestName instance for " + AbstractMojoTest.this);
+ log.debug("NEW MojoTest instance for " + getTestClass());
}
- getTestDir();
}
@Override
@@ -148,17 +273,20 @@
if (isVerbose()) {
log.info("==============================================================================================");
}
- log.info("NEW Mojo test starting : " + AbstractMojoTest.this.getClass().getName() + "#" + getMethodName());
+ log.info("NEW Mojo test starting : " + getTestClass().getName() + "#" + getMethodName());
+
String goalName = getGoalName(name.getMethodName());
- pomFile = AbstractMojoTest.this.getPomFile(getTestDir(), getMethodName(), goalName);
+ testDir = getTest().getTestDir(getMethodName(), goalName);
+ pomFile = getTest().getPomFile(testDir, getMethodName(), goalName);
+
try {
Assert.assertTrue("could not find pom " + pomFile.getAbsoluteFile(), pomFile.exists());
mojo = createMojo(pomFile, goalName);
- AbstractMojoTest.this.setUpMojo(mojo, pomFile);
+ getTest().setUpMojo(mojo, pomFile);
} catch (Exception ex) {
throw new IllegalStateException("could not init test " + getClass() + " - " + getMethodName() + " for reason " + ex.getMessage(), ex);
@@ -170,6 +298,7 @@
super.finished(method);
pomFile = null;
mojo = null;
+ testDir = null;
}
public P getMojo() {
@@ -179,5 +308,17 @@
public File getPomFile() {
return pomFile;
}
+
+ public File getTestDir() {
+ return testDir;
+ }
+
+ public AbstractMojoTest<P> getTest() {
+ return AbstractMojoTest.this;
+ }
+
+ public Class<?> getTestClass() {
+ return getTest().getClass();
+ }
}
}
1
0
27 Sep '09
Author: tchemit
Date: 2009-09-27 21:09:25 +0200 (Sun, 27 Sep 2009)
New Revision: 594
Modified:
trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java
Log:
add comments on test + use pomFile directory for license to treate (reflects more the real world)
Modified: trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-09-27 19:06:50 UTC (rev 593)
+++ trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-09-27 19:09:25 UTC (rev 594)
@@ -37,7 +37,8 @@
@Override
protected void setUpMojo(LicensePlugin mojo, File pomFile) throws Exception {
super.setUpMojo(mojo, pomFile);
- File outputDirectory = new File(getBasedir(), mojo.getOutputDirectory().toString());
+ // license is where the pom is
+ File outputDirectory = pomFile.getParentFile();
mojo.setOutputDirectory(outputDirectory);
if (!outputDirectory.exists()) {
if (!outputDirectory.mkdirs()) {
@@ -45,6 +46,9 @@
}
}
mojo.setLicenseFile(new File(pomFile.getParentFile(), mojo.getLicenseFile().toString()));
+ log.info("pom : " + getRelativePathFromBasedir(mojo.getProject().getFile()));
+ log.info("outputDirectory : " + getRelativePathFromBasedir(mojo.getOutputDirectory()));
+ log.info("licenseFile : " + getRelativePathFromBasedir(mojo.getLicenseFile()));
}
@Test
@@ -58,12 +62,14 @@
// since we can not ensure order of copy test resources
mojo.getProject().getFile().setLastModified(0);
+ // then executing the mojo, will do NOT change the licence file
mojo.execute();
long t1 = mojo.getLicenseFile().lastModified();
assertEquals(t0, t1);
+ // force to override the license file
mojo.setForce(true);
mojo.execute();
@@ -83,12 +89,14 @@
// since we can not ensure order of copy test resources
mojo.getProject().getFile().setLastModified(0);
+ // then executing the mojo, will do NOT change the licence file
mojo.execute();
long t1 = mojo.getLicenseFile().lastModified();
assertEquals(t0, t1);
+ // force to override the license file
mojo.setForce(true);
mojo.execute();
1
0
r593 - in trunk/src/test/resources: . org/nuiton/license/plugin/LicensePluginTest org/nuiton/mail/plugin/SendEmailMojoTest
by tchemit@users.nuiton.org 27 Sep '09
by tchemit@users.nuiton.org 27 Sep '09
27 Sep '09
Author: tchemit
Date: 2009-09-27 21:06:50 +0200 (Sun, 27 Sep 2009)
New Revision: 593
Modified:
trunk/src/test/resources/log4j.properties
trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml
trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testTwo.xml
trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/sendEmail.xml
trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/skipSendEmail.xml
Log:
- add model version in mojo test poms
- improve logger pattern (remove thread)
Modified: trunk/src/test/resources/log4j.properties
===================================================================
--- trunk/src/test/resources/log4j.properties 2009-09-26 01:33:14 UTC (rev 592)
+++ trunk/src/test/resources/log4j.properties 2009-09-27 19:06:50 UTC (rev 593)
@@ -3,8 +3,9 @@
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+log4j.appender.stdout.layout.ConversionPattern=[%p] (%F:%L) %M - %m%n
+#log4j.appender.stdout.layout.ConversionPattern=[%p] [%t] (%F:%L) %M - %m%n
# package level
-log4j.logger.org.nuiton=DEBUG
+log4j.logger.org.nuiton=INFO
Modified: trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml 2009-09-26 01:33:14 UTC (rev 592)
+++ trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testOne.xml 2009-09-27 19:06:50 UTC (rev 593)
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
<groupId>org.nuiton</groupId>
<artifactId>maven-helper-plugin-testOne</artifactId>
<version>0</version>
-
+ <modelVersion>4.0.0</modelVersion>
+
<build>
<plugins>
@@ -17,7 +16,7 @@
<encoding>UTF-8</encoding>
<licenseName>lgpl_v3</licenseName>
<licenseFile>licenseOne.txt</licenseFile>
- <outputDirectory>target/tests/license-plugin-test</outputDirectory>
+ <!--<outputDirectory>test</outputDirectory>-->
<verbose>true</verbose>
</configuration>
<executions>
Modified: trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testTwo.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testTwo.xml 2009-09-26 01:33:14 UTC (rev 592)
+++ trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testTwo.xml 2009-09-27 19:06:50 UTC (rev 593)
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
<groupId>org.nuiton</groupId>
<artifactId>maven-helper-plugin-testOne</artifactId>
<version>0</version>
@@ -17,7 +18,7 @@
<encoding>UTF-8</encoding>
<licenseName>lgpl_v3</licenseName>
<licenseFile>licenseTwo.txt</licenseFile>
- <outputDirectory>target/tests/license-plugin-test</outputDirectory>
+ <!--<outputDirectory>test</outputDirectory>-->
<verbose>true</verbose>
</configuration>
<executions>
Modified: trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/sendEmail.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/sendEmail.xml 2009-09-26 01:33:14 UTC (rev 592)
+++ trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/sendEmail.xml 2009-09-27 19:06:50 UTC (rev 593)
@@ -3,6 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
<groupId>org.nuiton.test</groupId>
<artifactId>test-send-email</artifactId>
<version>0</version>
Modified: trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/skipSendEmail.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/skipSendEmail.xml 2009-09-26 01:33:14 UTC (rev 592)
+++ trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/skipSendEmail.xml 2009-09-27 19:06:50 UTC (rev 593)
@@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
+ <modelVersion>4.0.0</modelVersion>
<groupId>org.nuiton.test</groupId>
<artifactId>test-send-email</artifactId>
<version>0</version>
1
0
Author: tchemit
Date: 2009-09-26 03:33:14 +0200 (Sat, 26 Sep 2009)
New Revision: 592
Modified:
trunk/pom.xml
Log:
fix javadoc report encoding to UTF-8 via the charset property
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-09-25 23:06:03 UTC (rev 591)
+++ trunk/pom.xml 2009-09-26 01:33:14 UTC (rev 592)
@@ -618,6 +618,8 @@
<quiet>true</quiet>
<docencoding>${project.build.sourceEncoding}</docencoding>
<encoding>${project.build.sourceEncoding}</encoding>
+ <charset>${project.reporting.outputEncoding}</charset>
+ <excludePackageNames>${maven.javadoc.excludePackageNames}</excludePackageNames>
<taglets>
<taglet>
<tagletClass>org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet</tagletClass>
1
0
Author: tchemit
Date: 2009-09-26 01:06:03 +0200 (Sat, 26 Sep 2009)
New Revision: 591
Modified:
trunk/pom.xml
Log:
javax.mail:mail is not optional (otherwise in artifacts using maven-helpr-plugin we have a research of a javax.mail:mail:3.2 which does not exists on central...)
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-09-25 22:15:34 UTC (rev 590)
+++ trunk/pom.xml 2009-09-25 23:06:03 UTC (rev 591)
@@ -153,7 +153,6 @@
as the dependency in plexus-mail-sender-javamail will be updated
-->
<dependency>
- <optional>true</optional>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
1
0