This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository maven-helper-plugin. See http://git.nuiton.org/maven-helper-plugin.git commit 22b9ef3718ef42770452c303a7abe8fa5f0fff8d Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon May 25 15:23:31 2015 +0200 use jdk 7 api (refs #3702) --- .../src/main/java/org/nuiton/io/FileUpdater.java | 6 +- .../main/java/org/nuiton/io/FileUpdaterHelper.java | 6 +- .../java/org/nuiton/io/MirroredFileUpdater.java | 2 +- .../main/java/org/nuiton/io/SortedProperties.java | 4 +- .../java/org/nuiton/plugin/AbstractPlugin.java | 136 ++++-------- .../java/org/nuiton/plugin/DependencyUtil.java | 14 +- .../src/main/java/org/nuiton/plugin/Plugin.java | 2 +- .../main/java/org/nuiton/plugin/PluginHelper.java | 12 +- .../java/org/nuiton/plugin/PluginIOContext.java | 2 +- .../java/org/nuiton/plugin/PluginWithEncoding.java | 2 +- .../nuiton/plugin/VelocityTemplateGenerator.java | 2 +- .../java/org/nuiton/plugin/PluginHelperTest.java | 2 +- .../test/resources/org/nuiton/io/JaxxDummy.java | 2 +- .../main/java/org/nuiton/plugin/MojoTestRule.java | 67 ++++-- .../main/java/org/nuiton/plugin/TestHelper.java | 2 +- .../java/org/nuiton/helper/io/mail/MailSender.java | 5 +- .../helper/io/mail/ProjectJavamailMailSender.java | 2 +- .../helper/plugin/CheckAutoContainerPlugin.java | 242 ++++++++++----------- .../org/nuiton/helper/plugin/CollectFilesMojo.java | 17 +- .../helper/plugin/ExecuteRemoteCommandMojo.java | 10 +- .../org/nuiton/helper/plugin/SendEmailMojo.java | 25 +-- .../helper/plugin/ShareServerSecretPlugin.java | 4 +- .../helper/plugin/TransformProjectVersionMojo.java | 27 +-- .../plugin/CheckAutoContainerPluginTest.java | 42 ++++ .../nuiton/helper/plugin/SendEmailMojoTest.java | 29 +-- .../plugin/TransformProjectVersionMojoTest.java | 46 ++-- .../checkAutoContainerPluginTest/central.xml | 83 +++++++ 27 files changed, 425 insertions(+), 368 deletions(-) diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/io/FileUpdater.java b/helper-maven-plugin-api/src/main/java/org/nuiton/io/FileUpdater.java index c8b68b9..ace721a 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/io/FileUpdater.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/io/FileUpdater.java @@ -26,10 +26,10 @@ import java.io.File; /** * Contract to be realized to test if a file is up to date. - * <p/> - * use {@link #isFileUpToDate(File)} to determine if a file is up to date. * - * @author tchemit <chemit@codelutin.com> + * Use {@link #isFileUpToDate(File)} to determine if a file is up to date. + * + * @author tchemit - chemit@codelutin.com */ public interface FileUpdater { diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/io/FileUpdaterHelper.java b/helper-maven-plugin-api/src/main/java/org/nuiton/io/FileUpdaterHelper.java index 4d15393..7ac76c8 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/io/FileUpdaterHelper.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/io/FileUpdaterHelper.java @@ -24,7 +24,7 @@ package org.nuiton.io; import java.io.File; -/** @author tchemit <chemit@codelutin.com> */ +/** @author tchemit - chemit@codelutin.com */ public class FileUpdaterHelper { static public MirroredFileUpdater newJavaFileUpdater() { @@ -46,7 +46,7 @@ public class FileUpdaterHelper { /** * To test if a java source file is newser than his compiled class * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com */ public static class JavaFileUpdater extends MirroredFileUpdater { @@ -70,7 +70,7 @@ public class FileUpdaterHelper { * To test if a jaxx source file is newser than his generated java * source file. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com */ public static class JaxxFileUpdater extends MirroredFileUpdater { diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/io/MirroredFileUpdater.java b/helper-maven-plugin-api/src/main/java/org/nuiton/io/MirroredFileUpdater.java index 5c9460e..be3dad7 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/io/MirroredFileUpdater.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/io/MirroredFileUpdater.java @@ -31,7 +31,7 @@ import java.io.File; * Simple base implementation of a {@link FileUpdater} for an updater with * a sourcedir and a destinationdir. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com */ public class MirroredFileUpdater implements FileUpdater { diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/io/SortedProperties.java b/helper-maven-plugin-api/src/main/java/org/nuiton/io/SortedProperties.java index 0bff97d..035f021 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/io/SortedProperties.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/io/SortedProperties.java @@ -46,7 +46,7 @@ import java.util.Vector; * be defined but you must use this class only with Java 1.6. * * @author ruchaud <ruchaud@codelutin.com> - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com */ public class SortedProperties extends Properties { @@ -122,7 +122,7 @@ public class SortedProperties extends Properties { } catch (IllegalArgumentException e) { // keys are not string !!! // can not sort keys - result = new Vector<Object>(objects); + result = new Vector<>(objects); } return result.elements(); } diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/AbstractPlugin.java b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/AbstractPlugin.java index 26aac72..7ed5a9c 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/AbstractPlugin.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/AbstractPlugin.java @@ -49,16 +49,14 @@ import java.util.TreeMap; /** * Base mojo with usefull methods and implementing {@link Plugin} contract. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com */ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { /** * Method to initialize the mojo before doing any concrete actions. - * <p/> + * * <b>Note:</b> The method is invoked before the {@link #doAction()} method. - * <p/> - * <p/> * * @throws Exception if any */ @@ -66,7 +64,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { /** * Do plugin action. - * <p/> + * * The method {@link #execute()} invoke this method only and only if : * <ul> * <li>{@link #checkPackaging()} returns {@code true}.</li> @@ -103,14 +101,11 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { init(); - } catch (MojoFailureException e) { - throw e; - } catch (MojoExecutionException e) { + } catch (MojoFailureException | MojoExecutionException e) { throw e; } catch (Exception e) { throw new MojoExecutionException( - "could not init goal " + getClass().getSimpleName() + - " for reason : " + e.getMessage(), e); + "could not init goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e); } // check if mojo can be skipped @@ -129,14 +124,11 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { doAction(); - } catch (MojoFailureException e) { - throw e; - } catch (MojoExecutionException e) { + } catch (MojoFailureException | MojoExecutionException e) { throw e; } catch (Exception e) { throw new MojoExecutionException( - "could not execute goal " + getClass().getSimpleName() + - " for reason : " + e.getMessage(), e); + "could not execute goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e); } } finally { afterExecute(); @@ -150,18 +142,16 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { /** * 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 : - * <p/> + * * {@link #acceptPackaging(Plugin.Packaging...)} - * <p/> * and - * <p/> * {@link #rejectPackaging(Plugin.Packaging...)} * * @return {@code true} if can execute the goal for the packaging of the @@ -288,8 +278,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { * @param onlyForRoot a flag to * @param buildStartTime the build statrt time (if none means must do it) * @param newStartTime the current build start time - * {@code true} if the goal should be invoked, {@code false} - * otherwise. + * {@code true} if the goal should be invoked, {@code false} otherwise. * @since 2.1 */ protected boolean needInvoke(boolean runOnce, @@ -335,22 +324,17 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { } /** - * Check if an execution should be done or not according to the - * given parameters. - * <p/> - * Will search if the given {@code key} is found in project, if not then - * means that the plugin was not invoked. + * Check if an execution should be done or not according to the given parameters. + * + * Will search if the given {@code key} is found in project, if not then means that the plugin was not invoked. * * @param runOnce always return true if not set * @param onlyForRoot flag to only accept root project * @param key key to check over project (first time will put it in project properties) - * @return {@code true} if the goal should be invoked, {@code false} - * otherwise. + * @return {@code true} if the goal should be invoked, {@code false} otherwise. * @since 2.1 */ - protected boolean needInvoke(boolean runOnce, - boolean onlyForRoot, - String key) { + protected boolean needInvoke(boolean runOnce, boolean onlyForRoot, String key) { if (!runOnce) { // will run each time @@ -407,8 +391,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { * @param destFile file name of destination file. * @throws IOException if could not copy file. */ - public void copyFile(File srcFile, File destFile) - throws IOException { + public void copyFile(File srcFile, File destFile) throws IOException { getLog().info("Copying " + srcFile.getName() + " to " + destFile); PluginHelper.copy(srcFile, destFile); @@ -423,9 +406,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { * @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 { + public void writeFile(File destFile, String content, String encoding) throws IOException { PluginHelper.writeString(destFile, content, encoding); } @@ -487,7 +468,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { continue; } - List<String> toTreate = new ArrayList<String>(); + List<String> toTreate = new ArrayList<>(); if (updater != null) { updater.setSourceDirectory(f); @@ -528,7 +509,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { File srcDir, MirroredFileUpdater updater) { - Map<String, String> result = new TreeMap<String, String>(); + Map<String, String> result = new TreeMap<>(); DirectoryScanner ds = new DirectoryScanner(); ds.setIncludes(includes); @@ -558,7 +539,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { return result; } - List<String> toTreate = new ArrayList<String>(); + List<String> toTreate = new ArrayList<>(); if (updater != null) { updater.setSourceDirectory(srcDir); @@ -568,7 +549,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { File srcFile = new File(srcDir, filePath); File mirrorFile = updater.getMirrorFile(srcFile); // check file is up-to-date - if (updater == null || !updater.isFileUpToDate(srcFile)) { + if (!updater.isFileUpToDate(srcFile)) { result.put(filePath, mirrorFile.getAbsolutePath()); toTreate.add(filePath); } @@ -638,11 +619,9 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { * @param srcDir the location to remove from test compile source roots */ protected void removeTestCompileSourceRoots(File srcDir) { - if (getProject().getTestCompileSourceRoots().contains( - srcDir.getPath())) { + if (getProject().getTestCompileSourceRoots().contains(srcDir.getPath())) { if (isVerbose()) { - getLog().info("removing test source roots : " + - srcDir.getPath()); + getLog().info("removing test source roots : " + srcDir.getPath()); } getProject().getTestCompileSourceRoots().remove(srcDir.getPath()); } @@ -657,11 +636,9 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { * @since 1.1.1 */ protected void addResourceDir(File dir, String... includes) { - boolean added = PluginHelper.addResourceDir(dir, getProject(), - includes); + boolean added = PluginHelper.addResourceDir(dir, getProject(), includes); if (added && isVerbose()) { - getLog().info("add resource " + dir + " with includes " + - Arrays.toString(includes)); + getLog().info("add resource " + dir + " with includes " + Arrays.toString(includes)); } } @@ -674,11 +651,9 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { * @since 1.1.1 */ protected void addTestResourceDir(File dir, String... includes) { - boolean added = PluginHelper.addTestResourceDir( - dir, getProject(), includes); + boolean added = PluginHelper.addTestResourceDir(dir, getProject(), includes); if (added && isVerbose()) { - getLog().info("add test resource " + dir + " with includes " + - Arrays.toString(includes)); + getLog().info("add test resource " + dir + " with includes " + Arrays.toString(includes)); } } @@ -783,8 +758,8 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { URLClassLoader result; try { - Set<String> dones = new HashSet<String>(); - List<URL> lUrls = new ArrayList<URL>(); + Set<String> dones = new HashSet<>(); + List<URL> lUrls = new ArrayList<>(); List<String> sources = project.getCompileSourceRoots(); if (addSourcesToClassPath) { @@ -794,23 +769,18 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { if (testPhase) { for (Object source : project.getTestCompileSourceRoots()) { - addDirectoryToUrlsList( - new File(source.toString()), lUrls, dones); + addDirectoryToUrlsList(new File(source.toString()), lUrls, dones); } } } if (addResourcesToClassPath) { for (Object source : project.getResources()) { Resource r = (Resource) source; - addDirectoryToUrlsList( - new File(r.getDirectory()), lUrls, dones); + addDirectoryToUrlsList(new File(r.getDirectory()), lUrls, dones); } } if (testPhase && addCompileClassPath) { - addDirectoryToUrlsList( - new File(project.getBuild().getOutputDirectory()), - lUrls, - dones); + addDirectoryToUrlsList(new File(project.getBuild().getOutputDirectory()), lUrls, dones); } if (src != null) { addDirectoryToUrlsList(src, lUrls, dones); @@ -826,10 +796,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { } } - result = new URLClassLoader( - lUrls.toArray(new URL[lUrls.size()]), - getClass().getClassLoader() - ); + result = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); } catch (IOException e) { throw new RuntimeException( @@ -838,12 +805,11 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { } loader = result; } else { - List<URL> lUrls = new ArrayList<URL>(); + List<URL> lUrls = new ArrayList<>(); if (addSourcesToClassPath) { lUrls.add(src.toURI().toURL()); } - loader = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), - getClass().getClassLoader()); + loader = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader()); } if (isVerbose()) { for (URL entry : loader.getURLs()) { @@ -855,7 +821,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { /** * Add the given {@code directory} in {@code urls} if not already included. - * <p/> + * * <b>Note:</b> We use a extra list to store file string representation, * since we do NOT want any url resolution and the * {@link URL#equals(Object)} is doing some... @@ -870,14 +836,13 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { File directory, List<URL> urls, Set<String> done) throws MalformedURLException { - // do the comparaison on a String to avoid url to be resolved - // (in URL.equals method) + // do the comparaison on a String to avoid url to be resolved (in URL.equals method) addUrlToUrlsList(directory.toURI().toURL(), urls, done); } /** * Add the given {@code url} in {@code urls} if not already included. - * <p/> + * * <b>Note:</b> We use a extra list to store file string representation, * since we do NOT want any url resolution and the * {@link URL#equals(Object)} is doing some.. @@ -887,12 +852,8 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { * @param done list of string representation of urls * @since 1.1.0 */ - protected void addUrlToUrlsList(URL url, - List<URL> urls, - Set<String> done) { - - // do the comparaison on a String to avoid url to be resolved - // (in URL.equals method) + protected void addUrlToUrlsList(URL url, List<URL> urls, Set<String> done) { + // do the comparaison on a String to avoid url to be resolved (in URL.equals method) String u = url.toString(); if (!done.contains(u)) { done.add(u); @@ -905,8 +866,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { * * @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 + * @throws IOException for any error while looking up for the url of the resources */ protected URL getTemplate(File f) throws IOException { URL r; @@ -923,8 +883,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { * classPath. * * @param f the required resource file. - * @throws IOException for any error while looking up for the resources - * content. + * @throws IOException for any error while looking up for the resources content. */ protected void checkResource(File f) throws IOException { if (!f.exists()) { @@ -958,10 +917,10 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { /** * Method to be invoked in init phase to check sanity of {@link PluginWithEncoding#getEncoding()}. - * <p/> + * * If no encoding was filled, then use the default for system * (via {@code file.encoding} environement property). - * <p/> + * * <b>Note:</b> If mojo is not implementing {@link PluginWithEncoding}, * nothing is done. * @@ -972,8 +931,7 @@ public abstract class AbstractPlugin extends AbstractMojo implements Plugin { if (PluginWithEncoding.class.isAssignableFrom(getClass())) { if (isVerbose()) { - getLog().info("Will check encoding : " + - ((PluginWithEncoding) this).getEncoding()); + getLog().info("Will check encoding : " + ((PluginWithEncoding) this).getEncoding()); } PluginHelper.checkEncoding((PluginWithEncoding) this); } diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/DependencyUtil.java b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/DependencyUtil.java index e032150..7f5c087 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/DependencyUtil.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/DependencyUtil.java @@ -32,7 +32,7 @@ import java.util.*; /** * Une classe de methodes utiles sur les dependences entre artifacts. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 0.5 */ public class DependencyUtil { @@ -49,7 +49,7 @@ public class DependencyUtil { } Map<String, ArtifactDependencyEntry> dico = - new HashMap<String, ArtifactDependencyEntry>(artifacts.size()); + new HashMap<>(artifacts.size()); for (Artifact a : artifacts) { ArtifactDependencyEntry entry = new ArtifactDependencyEntry(a); @@ -57,14 +57,14 @@ public class DependencyUtil { } // contient les artifacts non encore fixes - Set<String> universe = new HashSet<String>(dico.keySet()); + Set<String> universe = new HashSet<>(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 ArrayList<String>(); + List<String> parsed = new ArrayList<>(); // premiere passe pour recuperer l'ensemble des dependances for (ArtifactDependencyEntry entry : dico.values()) { @@ -83,7 +83,7 @@ public class DependencyUtil { } // on parcourt les artifacts pour detecter les nouveau // artifacts fixes - List<String> levelFixed = new ArrayList<String>(); + List<String> levelFixed = new ArrayList<>(); for (String key : universe) { ArtifactDependencyEntry entry = dico.get(key); @@ -138,8 +138,8 @@ public class DependencyUtil { Set<String> universe, boolean verbose) { - List<String> order = new ArrayList<String>(); - Set<String> exclude = new HashSet<String>(); + List<String> order = new ArrayList<>(); + Set<String> exclude = new HashSet<>(); if (verbose) { log.info("start [" + entry.artifactKey + "]"); diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/Plugin.java b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/Plugin.java index 52f67bf..7ab813d 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/Plugin.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/Plugin.java @@ -30,7 +30,7 @@ import org.apache.maven.project.MavenProject; * <p/> * Just expose a {@link #isVerbose()} flag and the maven project {@link #getProject()}. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.0.3 */ public interface Plugin extends Mojo { diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginHelper.java b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginHelper.java index e0dccf8..3e29aad 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginHelper.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginHelper.java @@ -57,7 +57,7 @@ import java.util.zip.ZipFile; /** * Une classe pour mutualiser toutes les méthodes utiles pour un plugin. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com */ public class PluginHelper { @@ -209,7 +209,7 @@ public class PluginHelper { * @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>(); + SortedSet<String> result = new TreeSet<>(); for (Entry<?, ?> e : map.entrySet()) { if (e.getValue() == null || e.getValue().toString().isEmpty()) { result.add(e.getKey().toString()); @@ -446,7 +446,7 @@ public class PluginHelper { String[] includes, String[] excludes) { DirectoryScanner ds = new DirectoryScanner(); - List<File> result = new ArrayList<File>(); + List<File> result = new ArrayList<>(); ds.setBasedir(dir); if (includes != null) { ds.setIncludes(includes); @@ -587,7 +587,7 @@ public class PluginHelper { * @throws IOException if any pb while reading file */ public static String[] getLines(File src) throws IOException { - List<String> result = new ArrayList<String>(); + List<String> result = new ArrayList<>(); BufferedReader stream = new BufferedReader( new InputStreamReader(new FileInputStream(src))); @@ -610,7 +610,7 @@ public class PluginHelper { * @throws IOException if any pb while reading file */ public static File[] getLinesAsFiles(File src) throws IOException { - List<File> result = new ArrayList<File>(); + List<File> result = new ArrayList<>(); for (String line : getLines(src)) { if (!line.isEmpty()) { result.add(new File(line)); @@ -625,7 +625,7 @@ public class PluginHelper { * @throws IOException if any pb while reading file */ public static URL[] getLinesAsURL(File src) throws IOException { - List<URL> result = new ArrayList<URL>(); + List<URL> result = new ArrayList<>(); for (String line : getLines(src)) { if (!line.isEmpty()) { result.add(new URL(line)); diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginIOContext.java b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginIOContext.java index 6a3ea6d..b11d108 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginIOContext.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginIOContext.java @@ -31,7 +31,7 @@ import java.io.File; * <p/> * En sortie, on ne peut avoir qu'un seul répertoire ({@link #output}. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.0.1 */ public class PluginIOContext { diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginWithEncoding.java b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginWithEncoding.java index f4e322b..cf529b7 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginWithEncoding.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/PluginWithEncoding.java @@ -27,7 +27,7 @@ package org.nuiton.plugin; * <p/> * Just expose a getter-setter {@link #getEncoding()} and {@link #setEncoding(String)}. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.2.6 */ public interface PluginWithEncoding extends Plugin { diff --git a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java index 6db1fad..aaa5f8f 100644 --- a/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java +++ b/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java @@ -40,7 +40,7 @@ import java.util.Properties; * <p/> * TODO TC-20091011 should use plexus velocity component * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.3 */ public class VelocityTemplateGenerator { diff --git a/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/PluginHelperTest.java b/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/PluginHelperTest.java index e6e19a9..b746d83 100644 --- a/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/PluginHelperTest.java +++ b/helper-maven-plugin-api/src/test/java/org/nuiton/plugin/PluginHelperTest.java @@ -34,7 +34,7 @@ import java.net.URL; /** * Tests the {@link PluginHelper} class. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.2.3 */ public class PluginHelperTest { diff --git a/helper-maven-plugin-api/src/test/resources/org/nuiton/io/JaxxDummy.java b/helper-maven-plugin-api/src/test/resources/org/nuiton/io/JaxxDummy.java index f4110ae..14b9e2c 100644 --- a/helper-maven-plugin-api/src/test/resources/org/nuiton/io/JaxxDummy.java +++ b/helper-maven-plugin-api/src/test/resources/org/nuiton/io/JaxxDummy.java @@ -22,7 +22,7 @@ package org.nuiton.io; * #L% */ -/** @author tchemit <chemit@codelutin.com> */ +/** @author tchemit - chemit@codelutin.com */ public class JaxxDummy { /** * A dummy file to test {@link org.nuiton.util.FileUpdaterHelper.JaxxFileUpdater} in {@link JaxxFileUpdaterTest} diff --git a/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/MojoTestRule.java b/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/MojoTestRule.java index a014b09..a43763a 100644 --- a/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/MojoTestRule.java +++ b/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/MojoTestRule.java @@ -26,7 +26,7 @@ import java.io.File; * the mojo</li> <li>{@link #mojo} : the instanciated and initialized * mojo</li> </ul> */ -public abstract class MojoTestRule<P extends Plugin> extends MojoRule { +public class MojoTestRule<P extends AbstractPlugin> extends MojoRule { /** Logger. */ private static final Log log = LogFactory.getLog(MojoTestRule.class); @@ -56,11 +56,19 @@ public abstract class MojoTestRule<P extends Plugin> extends MojoRule { */ private final Class<?> testClass; - protected MojoTestRule(Class<?> testClass) { - this.testClass = testClass; + /** + * Goal name of the mojo to test. + */ + private final String goalName; + + public static <P extends AbstractPlugin> MojoTestRule<P> newRule(Class<?> testClass, String goalName) { + return new MojoTestRule<>(testClass, goalName); } - protected abstract String getGoalName(String methodName); + protected MojoTestRule(Class<?> testClass, String goalName) { + this.testClass = testClass; + this.goalName = goalName; + } @Override public Statement apply(final Statement base, Description description) { @@ -103,6 +111,28 @@ public abstract class MojoTestRule<P extends Plugin> extends MojoRule { } + public boolean initMojo(P mojo) { + + boolean canContinue; + try { + + mojo.init(); + canContinue = true; + + } catch (Exception e) { + + canContinue = false; + + if (log.isDebugEnabled()) { + log.debug("Could not init mojo ", e); + } + + } + + return canContinue; + + } + protected void tearDownMojo(P mojo) { // by default nothing to clear @@ -112,17 +142,11 @@ public abstract class MojoTestRule<P extends Plugin> extends MojoRule { @Override protected void before() throws Throwable { - if (TestHelper.isVerbose()) { - log.info("=============================================================================================="); - } - log.info("Starting test: " + testClass.getName() + "#" + testMethodName); - String goalName = getGoalName(testMethodName); + testDirectory = getTestDir(testMethodName); - testDirectory = getTestDir(testMethodName, goalName); - - pomFile = getPomFile(testDirectory, testMethodName, goalName); + pomFile = getPomFile(testDirectory, testMethodName); try { @@ -167,17 +191,15 @@ public abstract class MojoTestRule<P extends Plugin> extends MojoRule { /** * Obtain the location of the directory where to find resources for the next test. * - * By convention, will be the package named by the test class name from the - * {@link TestHelper#getTestBasedir()}. + * By convention, will be the package named by the test class name from the {@link TestHelper#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) { + protected File getTestDir(String methodName) { //TC-20091101 use a decipatilize simple name to avoid conflict of package with existing class name. - String rep = getClass().getPackage().getName() + "." + Introspector.decapitalize(testClass.getSimpleName()); + String rep = testClass.getPackage().getName() + "." + Introspector.decapitalize(testClass.getSimpleName()); String[] paths = rep.split("\\."); File directory = TestHelper.getFile(TestHelper.getTestBasedir(), paths); if (TestHelper.isVerbose()) { @@ -191,18 +213,15 @@ public abstract class MojoTestRule<P extends Plugin> extends MojoRule { /** * 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}. + * + * 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(String, - * String)}. + * result of the method {@link #getTestDir(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) { + protected File getPomFile(File testDir, String methodName) { File pom = new File(testDir, methodName + ".xml"); diff --git a/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/TestHelper.java b/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/TestHelper.java index 8151a50..1f46b51 100644 --- a/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/TestHelper.java +++ b/helper-maven-plugin-test-api/src/main/java/org/nuiton/plugin/TestHelper.java @@ -9,7 +9,7 @@ import java.io.File; import java.io.IOException; /** - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.0.3 */ public abstract class TestHelper extends PluginHelper { diff --git a/helper-maven-plugin/src/main/java/org/nuiton/helper/io/mail/MailSender.java b/helper-maven-plugin/src/main/java/org/nuiton/helper/io/mail/MailSender.java index 1570234..b1c312c 100644 --- a/helper-maven-plugin/src/main/java/org/nuiton/helper/io/mail/MailSender.java +++ b/helper-maven-plugin/src/main/java/org/nuiton/helper/io/mail/MailSender.java @@ -25,10 +25,9 @@ package org.nuiton.helper.io.mail; /** * Defines the sender of a email. * - * Note : this code was stolen in {@code maven-changes-plugin}, should thanks - * them... + * Note : this code was stolen in {@code maven-changes-plugin}, should thanks them... * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.0.3 */ public class MailSender { diff --git a/helper-maven-plugin/src/main/java/org/nuiton/helper/io/mail/ProjectJavamailMailSender.java b/helper-maven-plugin/src/main/java/org/nuiton/helper/io/mail/ProjectJavamailMailSender.java index 1abead3..00a289d 100644 --- a/helper-maven-plugin/src/main/java/org/nuiton/helper/io/mail/ProjectJavamailMailSender.java +++ b/helper-maven-plugin/src/main/java/org/nuiton/helper/io/mail/ProjectJavamailMailSender.java @@ -48,7 +48,7 @@ import java.util.Properties; * Note : this code was stolen in {@code maven-changes-plugin}, should thanks * them... * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.0.3 */ public class ProjectJavamailMailSender diff --git a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java index 583f7b9..7c3fb76 100644 --- a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java +++ b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java @@ -24,12 +24,12 @@ package org.nuiton.helper.plugin; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; @@ -40,17 +40,13 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Proxy; -import org.apache.maven.wagon.ConnectionException; -import org.apache.maven.wagon.Wagon; -import org.apache.maven.wagon.authentication.AuthenticationInfo; -import org.apache.maven.wagon.observers.Debug; import org.apache.maven.wagon.proxy.ProxyInfo; -import org.apache.maven.wagon.repository.Repository; import org.codehaus.plexus.util.StringUtils; import org.nuiton.plugin.AbstractPlugin; import org.nuiton.plugin.PluginHelper; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -58,15 +54,15 @@ import java.util.TreeMap; /** * Check all dependencies are auto contained in the given repositories. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @version $Id$ * @since 1.2.5 */ @Mojo(name = "check-auto-container", - defaultPhase = LifecyclePhase.VALIDATE, - requiresProject = true, - requiresOnline = true, - requiresDependencyResolution = ResolutionScope.RUNTIME) + defaultPhase = LifecyclePhase.VALIDATE, + requiresProject = true, + requiresOnline = true, + requiresDependencyResolution = ResolutionScope.RUNTIME) public class CheckAutoContainerPlugin extends AbstractPlugin { /** @@ -136,7 +132,7 @@ public class CheckAutoContainerPlugin extends AbstractPlugin { * * @since 1.2.5 */ - @Parameter( defaultValue = "${project}", required = true, readonly = true ) + @Parameter(defaultValue = "${project}", required = true, readonly = true) protected MavenProject project; /** @@ -156,14 +152,6 @@ public class CheckAutoContainerPlugin extends AbstractPlugin { protected Proxy proxy; /** - * Local repository. - * - * @since 1.2.5 - */ - @Parameter(property = "localRepository", required = true, readonly = true) - protected ArtifactRepository localRepository; - - /** * Artifact repository factory component. * * @since 1.2.5 @@ -172,28 +160,12 @@ public class CheckAutoContainerPlugin extends AbstractPlugin { protected ArtifactRepositoryFactory artifactRepositoryFactory; /** - * Artifact factory component. - * - * @since 1.2.5 - */ - @Component - protected ArtifactFactory factory; - - /** - * Artifact resolver component. - * - * @since 1.2.5 - */ - @Component - protected ArtifactResolver resolver; - - /** * Wagon manager component. * * @since 1.2.5 */ @Component - protected WagonManager wagonManager; + protected ArtifactResolver artifactResolver; /** * Authorized Remote Repositories. @@ -210,8 +182,7 @@ public class CheckAutoContainerPlugin extends AbstractPlugin { private List<Artifact> artifacts; /** - * Dictionnary of already resolved artifacts (keys are repository url and - * values are list of artifact ids). + * Dictionnary of already resolved artifacts (keys are repository url and values are list of artifact ids). * * @since 1.2.5 */ @@ -321,29 +292,26 @@ public class CheckAutoContainerPlugin extends AbstractPlugin { // no more artifacts to check continue; } + long t0 = System.nanoTime(); String url = repository.getUrl(); List<String> ids = getRepositoryCache(url); - Wagon wagon = getWagon(repository); - try { - if (verbose) { - log.info("Use repository " + url); - } - List<Artifact> found = checkDependency(repository, wagon, ids); - long delay = System.nanoTime() - t0; - String message; - if (found.isEmpty()) { - message = "No artifact resolved by the repository " + url; - } else { - message = String.format("%1$4s artifact(s) resolved by repository %2$s in %3$s", found.size(), url, PluginHelper.convertTime(delay)); - } - log.info(message); - artifacts.removeAll(found); - } finally { - disconnect(wagon); + if (verbose) { + log.info("Use repository " + url); + } + List<Artifact> found = checkDependency(repository, ids); + long delay = System.nanoTime() - t0; + String message; + if (found.isEmpty()) { + message = "No artifact resolved by the repository " + url; + } else { + message = String.format("%1$4s artifact(s) resolved by repository %2$s in %3$s", found.size(), url, PluginHelper.convertTime(delay)); } + log.info(message); + artifacts.removeAll(found); + } boolean safe = artifacts.isEmpty(); @@ -363,47 +331,49 @@ public class CheckAutoContainerPlugin extends AbstractPlugin { } protected List<ArtifactRepository> createSafeRepositories() { - List<ArtifactRepository> safeRepositories = new ArrayList<ArtifactRepository>(); + + List<ArtifactRepository> result = new ArrayList<>(); ArtifactRepositoryLayout repositoryLayout = new DefaultRepositoryLayout(); - if (repositories == null) { - repositories = new TreeMap<String, String>(); + if (this.repositories == null) { + this.repositories = new TreeMap<>(); } - List<String> ids = new ArrayList<String>(repositories.keySet()); + List<String> ids = new ArrayList<>(this.repositories.keySet()); if (addMavenCentral) { ids.add(0, MAVEN_CENTRAL_ID); - repositories.put(MAVEN_CENTRAL_ID, MAVEN_CENTRAL_URL); + this.repositories.put(MAVEN_CENTRAL_ID, MAVEN_CENTRAL_URL); } for (String id : ids) { - String url = repositories.get(id); - url = url.trim(); - ArtifactRepository repo; - repo = artifactRepositoryFactory.createDeploymentArtifactRepository( - String.valueOf(id), - url, - repositoryLayout, true); + String url = this.repositories.get(id).trim(); + + ArtifactRepository repo = artifactRepositoryFactory.createDeploymentArtifactRepository( + String.valueOf(id), url, repositoryLayout, true); getLog().info("Will use repository " + repo.getUrl()); if (verbose) { getLog().info(repo.toString()); } - safeRepositories.add(repo); + result.add(repo); } - return safeRepositories; + + return result; + } protected List<Artifact> prepareArtifacts() { - List<Artifact> result = new ArrayList<Artifact>(); + List<Artifact> result = new ArrayList<>(); - List<String> siblings = new ArrayList<String>(); + List<String> siblings = new ArrayList<>(); - for (Object o : reactorProjects) { - MavenProject m = (MavenProject) o; - siblings.add(getArtifactId(m.getArtifact())); + if (reactorProjects != null) { + for (Object o : reactorProjects) { + MavenProject m = (MavenProject) o; + siblings.add(getArtifactId(m.getArtifact())); + } } // treate classic dependencies @@ -454,12 +424,10 @@ public class CheckAutoContainerPlugin extends AbstractPlugin { return artifact; } - private List<Artifact> checkDependency(ArtifactRepository repo, - Wagon wagon, - List<String> ids) throws Exception { + private List<Artifact> checkDependency(ArtifactRepository repo, List<String> ids) throws Exception { + Log log = getLog(); - List<Artifact> result = new ArrayList<Artifact>(); - String url = repo.getUrl(); + List<Artifact> result = new ArrayList<>(); for (Artifact artifact : artifacts) { if (log.isDebugEnabled()) { @@ -467,36 +435,54 @@ public class CheckAutoContainerPlugin extends AbstractPlugin { } String id = getArtifactId(artifact); - boolean resolved; + boolean found; + boolean inCache = ids.contains(id); if (inCache) { // already resolved - resolved = true; + found = true; + } else { // first time resolving this artifact - Artifact copyArtifact = ArtifactUtils.copyArtifact(artifact); - String path = url + "/" + repo.pathOf(copyArtifact); + ArtifactResolutionRequest request = new ArtifactResolutionRequest(); + request.setForceUpdate(true); + request.setRemoteRepositories(Collections.singletonList(repo)); + + if (proxy != null) { + + request.setProxies(Collections.singletonList(proxy)); + + } + request.setArtifact(artifact); + + ArtifactResolutionResult resolutionResult = artifactResolver.resolve(request); + + found = resolutionResult.isSuccess(); - resolved = wagon.resourceExists(StringUtils.replace(path, repo.getUrl(), "")); } - if (resolved) { + if (found) { if (verbose) { log.info(" - [ resolved ] " + artifact + (inCache ? " (from cache)" : "")); } result.add(artifact); ids.add(id); + } else { + if (log.isDebugEnabled()) { log.debug(" - [unresolved] " + artifact); } + } } + return result; + } protected String getArtifactId(Artifact artifact) { @@ -508,56 +494,56 @@ public class CheckAutoContainerPlugin extends AbstractPlugin { protected List<String> getRepositoryCache(String url) { if (resolved == null) { - resolved = new TreeMap<String, List<String>>(); + resolved = new TreeMap<>(); } List<String> ids = resolved.get(url); if (ids == null) { - ids = new ArrayList<String>(); + ids = new ArrayList<>(); resolved.put(url, ids); } return ids; } - protected Wagon getWagon(ArtifactRepository repo) throws Exception { - - Repository repository = new Repository(repo.getId(), repo.getUrl()); - Wagon wagon = wagonManager.getWagon(repository); - - wagon.setTimeout(1000); - - if (getLog().isDebugEnabled()) { - Debug debug = new Debug(); - - wagon.addSessionListener(debug); - wagon.addTransferListener(debug); - } - - // FIXME when upgrading to maven 3.x : this must be changed. - AuthenticationInfo auth = wagonManager.getAuthenticationInfo(repo.getId()); - - ProxyInfo proxyInfo = getProxyInfo(); - if (proxyInfo != null) { - wagon.connect(repository, auth, proxyInfo); - } else { - wagon.connect(repository, auth); - } - - return wagon; - } - - protected void disconnect(Wagon wagon) { - try { - wagon.disconnect(); - } catch (ConnectionException e) { - Log log = getLog(); - if (log.isDebugEnabled()) { - log.error("Error disconnecting wagon - ignored", e); - } else { - log.error("Error disconnecting wagon - ignored"); - } - } - } +// protected Wagon getWagon(ArtifactRepository repo) throws Exception { +// +// Repository repository = new Repository(repo.getId(), repo.getUrl()); +// Wagon wagon = wagonManager.getWagon(repository); +// +// wagon.setTimeout(1000); +// +// if (getLog().isDebugEnabled()) { +// Debug debug = new Debug(); +// +// wagon.addSessionListener(debug); +// wagon.addTransferListener(debug); +// } +// +// // FIXME when upgrading to maven 3.x : this must be changed. +// AuthenticationInfo auth = wagonManager.getAuthenticationInfo(repo.getId()); +// +// ProxyInfo proxyInfo = getProxyInfo(); +// if (proxyInfo != null) { +// wagon.connect(repository, auth, proxyInfo); +// } else { +// wagon.connect(repository, auth); +// } +// +// return wagon; +// } +// +// protected void disconnect(Wagon wagon) { +// try { +// wagon.disconnect(); +// } catch (ConnectionException e) { +// Log log = getLog(); +// if (log.isDebugEnabled()) { +// log.error("Error disconnecting wagon - ignored", e); +// } else { +// log.error("Error disconnecting wagon - ignored"); +// } +// } +// } protected ProxyInfo getProxyInfo() { ProxyInfo proxyInfo = null; diff --git a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java index 3439d2c..8d65dcd 100644 --- a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java +++ b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java @@ -45,7 +45,7 @@ import java.util.regex.Pattern; /** * Collect files some files from a project and copy them into a directory. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.1.0 */ @Mojo(name = "collect-files", requiresProject = true) @@ -298,18 +298,16 @@ public class CollectFilesMojo extends AbstractPlugin implements PluginWithEncodi incomingFiles = getFiles(description); getLog().info("Loaded " + description); } catch (IOException ex) { - throw new MojoExecutionException( - "could not load file " + description, ex); + throw new MojoExecutionException("could not load file " + description, ex); } } else { - incomingFiles = new ArrayList<File>(); + incomingFiles = new ArrayList<>(); } } if (!withDescriptionFile && !copyFiles) { throw new MojoExecutionException( - "must use at least one of the parameters 'copyFiles' or " + - "'descriptionFile'"); + "must use at least one of the parameters 'copyFiles' or 'descriptionFile'"); } String basedir = rootProject.getBasedir().getAbsolutePath(); @@ -344,8 +342,7 @@ public class CollectFilesMojo extends AbstractPlugin implements PluginWithEncodi getLog().info("Saved " + description); } } catch (IOException ex) { - throw new MojoExecutionException( - "could not save file " + description, ex); + throw new MojoExecutionException("could not save file " + description, ex); } } } @@ -358,7 +355,7 @@ public class CollectFilesMojo extends AbstractPlugin implements PluginWithEncodi * @throws IOException if any pb while reading file */ public List<File> getFiles(File input) throws IOException { - List<File> result = new ArrayList<File>(); + List<File> result = new ArrayList<>(); result.addAll(Arrays.asList(PluginHelper.getLinesAsFiles(input))); return result; } @@ -387,7 +384,7 @@ public class CollectFilesMojo extends AbstractPlugin implements PluginWithEncodi Pattern excludePattern = StringUtils.isBlank(excludes) ? null : Pattern.compile(excludes.trim()); - List<File> result = new ArrayList<File>(); + List<File> result = new ArrayList<>(); // attach the project mail file diff --git a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java index e3a8524..8c7e265 100644 --- a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java +++ b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java @@ -46,7 +46,7 @@ import org.nuiton.plugin.AbstractPlugin; /** * Mojo to execute on a remote server some scripts. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.3.1 */ @Mojo(name = "execute-remote-command", @@ -85,7 +85,7 @@ public class ExecuteRemoteCommandMojo extends AbstractPlugin { /** * Url where to execute script. - * <p/> + * * The url must contains the wagon protocol (says scp:... or scpexe:...). */ @Parameter(property = "helper.repositoryUrl", required = true) @@ -120,8 +120,7 @@ public class ExecuteRemoteCommandMojo extends AbstractPlugin { if (server == null) { throw new MojoExecutionException( - "Could not find server with id '" + repositoryId + - "', check your settings.xml file."); + "Could not find server with id '" + repositoryId + "', check your settings.xml file."); } Repository repository = new Repository(repositoryId, repositoryUrl); @@ -132,8 +131,7 @@ public class ExecuteRemoteCommandMojo extends AbstractPlugin { disconnect(wagon); throw new MojoExecutionException( - "The wagon " + wagon + " is not a command executor, " + - "will not be able to execute command."); + "The wagon " + wagon + " is not a command executor, will not be able to execute command."); } commandExecutor = (CommandExecutor) wagon; diff --git a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java index 0023505..40a51cc 100644 --- a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java +++ b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java @@ -44,7 +44,7 @@ import java.util.List; /** * Send a email. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.0.3 */ @Mojo(name = "send-email", requiresOnline = true, requiresProject = true) @@ -244,8 +244,7 @@ public class SendEmailMojo extends AbstractPlugin implements PluginWithEncoding if (!emailContentFile.exists()) { // no file to publish... - throw new MojoExecutionException( - "could not find the template " + emailContentFile); + throw new MojoExecutionException("could not find the template " + emailContentFile); } // check mail sender @@ -265,16 +264,13 @@ public class SendEmailMojo extends AbstractPlugin implements PluginWithEncoding } else { for (Developer developer : from) { if (fromDeveloperId.equals(developer.getId())) { - mailSender = new MailSender(developer.getName(), - developer.getEmail() - ); + mailSender = new MailSender(developer.getName(), developer.getEmail()); break; } } if (mailSender == null) { throw new MojoExecutionException( - "Missing developer with id '" + fromDeveloperId + - "' in the <developers> section in your pom."); + "Missing developer with id '" + fromDeveloperId + "' in the <developers> section in your pom."); } } } @@ -282,13 +278,11 @@ public class SendEmailMojo extends AbstractPlugin implements PluginWithEncoding String fromAddress = mailSender.getEmail(); if (StringUtils.isEmpty(fromAddress)) { throw new MojoExecutionException( - "Invalid mail sender: name and email is mandatory (" + - mailSender + ")."); + "Invalid mail sender: name and email is mandatory (" + mailSender + ")."); } if (StringUtils.isBlank(emailTitle)) { - throw new MojoExecutionException( - "Mail title can not be blank."); + throw new MojoExecutionException("Mail title can not be blank."); } emailTitle = emailTitle.trim(); @@ -367,15 +361,12 @@ public class SendEmailMojo extends AbstractPlugin implements PluginWithEncoding return skipSendEmail; } - protected MailMessage createMessage( - String newsContent, - MailSender mailSender) throws MailSenderException { + protected MailMessage createMessage(String newsContent, MailSender mailSender) throws MailSenderException { String fromName = mailSender.getName(); String fromAddress = mailSender.getEmail(); - getLog().info("Using this sender for email announcement: " + - fromAddress + " < " + fromName + " > "); + getLog().info("Using this sender for email announcement: " + fromAddress + " < " + fromName + " > "); MailMessage mailMsg = new MailMessage(); mailMsg.setSubject(emailTitle); diff --git a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java index ca6be69..b2ef259 100644 --- a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java +++ b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java @@ -51,7 +51,7 @@ import java.util.Properties; * passphraseOut * </pre> * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.1.0 */ @Mojo(name = "share-server-secret", @@ -225,7 +225,7 @@ public class ShareServerSecretPlugin extends AbstractPlugin { return; } - propertiesToTreate = new EnumMap<Property, String>(Property.class); + propertiesToTreate = new EnumMap<>(Property.class); if (StringUtils.isNotEmpty(usernameOut)) { propertiesToTreate.put(Property.username, usernameOut); diff --git a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/TransformProjectVersionMojo.java b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/TransformProjectVersionMojo.java index f5564ba..0d170d6 100644 --- a/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/TransformProjectVersionMojo.java +++ b/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/TransformProjectVersionMojo.java @@ -34,7 +34,7 @@ import java.util.Properties; /** * Transform the version of the project and store it in a project property. * - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 2.0 */ @Mojo(name = "transform-project-version", @@ -88,8 +88,7 @@ public class TransformProjectVersionMojo extends AbstractPlugin { * * @since 2.0 */ - @Parameter(property = "helper.versionKey", defaultValue = "newVersion", - required = true) + @Parameter(property = "helper.versionKey", defaultValue = "newVersion", required = true) private String versionKey = "newVersion"; /** @@ -122,11 +121,13 @@ public class TransformProjectVersionMojo extends AbstractPlugin { // check if plugin was already done. - boolean shouldInvoke = needInvoke(runOnce, false, key); + boolean shouldInvoke = needInvoke(true, false, key); - return shouldInvoke && super.checkSkip(); + result = shouldInvoke && super.checkSkip(); } + return result; + } @Override @@ -136,9 +137,7 @@ public class TransformProjectVersionMojo extends AbstractPlugin { if (!newVersionPattern.contains("#V") && !newVersionPattern.contains("#R")) { throw new MojoExecutionException( - "newVersionPattern (" + newVersionPattern + - ") must at least contains one of those patterns:" + - " *#V* or *#R*."); + "newVersionPattern (" + newVersionPattern + ") must at least contains one of those patterns: *#V* or *#R*."); } if (newVersionPattern.contains("#S")) { @@ -149,14 +148,12 @@ public class TransformProjectVersionMojo extends AbstractPlugin { if (firstIndex != lastIndex) { throw new MojoExecutionException( - "newVersionPattern (" + newVersionPattern + - ") can only contains one pattern *#S*."); + "newVersionPattern (" + newVersionPattern + ") can only contains one pattern *#S*."); } if (lastIndex != newVersionPattern.length() - 2) { throw new MojoExecutionException( - "newVersionPattern (" + newVersionPattern + - ") can only contains pattern *#S* at his end."); + "newVersionPattern (" + newVersionPattern + ") can only contains pattern *#S* at his end."); } } @@ -174,8 +171,7 @@ public class TransformProjectVersionMojo extends AbstractPlugin { if (snapshotFound) { // remove snapshot - version = version.substring(0, version.length() - - SNAPSHOT_SUFFIX.length()); + version = version.substring(0, version.length() - SNAPSHOT_SUFFIX.length()); } String newVersion = newVersionPattern.replaceAll("#V", version); @@ -189,8 +185,7 @@ public class TransformProjectVersionMojo extends AbstractPlugin { Properties properties = project.getProperties(); - getLog().info("export newVersion [" + newVersion + "] " + - " in ${" + versionKey + "}"); + getLog().info("export newVersion [" + newVersion + "] in ${" + versionKey + "}"); properties.setProperty(versionKey, newVersion); } diff --git a/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/CheckAutoContainerPluginTest.java b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/CheckAutoContainerPluginTest.java new file mode 100644 index 0000000..977d15a --- /dev/null +++ b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/CheckAutoContainerPluginTest.java @@ -0,0 +1,42 @@ +package org.nuiton.helper.plugin; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.plugin.MojoTestRule; + +/** + * Created on 5/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.2 + */ +public class CheckAutoContainerPluginTest { + + @Rule + public MojoTestRule<CheckAutoContainerPlugin> rule = + MojoTestRule.newRule(CheckAutoContainerPluginTest.class, "check-auto-container"); + + //FIXME Got a NPE in artifact resolver (session is null) :( + /* + java.lang.NullPointerException + at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:208) + at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:401) + at org.nuiton.helper.plugin.CheckAutoContainerPlugin.checkDependency(CheckAutoContainerPlugin.java:461) + */ + @Ignore + @Test + public void central() throws Exception { + + CheckAutoContainerPlugin mojo = rule.getMojo(); + Assert.assertNotNull(mojo); + boolean canContinue = rule.initMojo(mojo); + Assume.assumeTrue(canContinue); + + mojo.doAction(); + + } + +} \ No newline at end of file diff --git a/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java index ead8638..4546600 100644 --- a/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java +++ b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java @@ -35,7 +35,7 @@ import java.io.File; import java.util.Collections; /** - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 1.0.0 */ public class SendEmailMojoTest { @@ -44,12 +44,7 @@ public class SendEmailMojoTest { private static final Log log = LogFactory.getLog(SendEmailMojoTest.class); @Rule - public MojoTestRule<SendEmailMojo> rule = new MojoTestRule<SendEmailMojo>(SendEmailMojoTest.class) { - - @Override - protected String getGoalName(String methodName) { - return "send-email"; - } + public MojoTestRule<SendEmailMojo> rule = new MojoTestRule<SendEmailMojo>(SendEmailMojoTest.class, "send-email") { @Override protected void setUpMojo(SendEmailMojo mojo, File pomFile) throws Exception { @@ -65,12 +60,7 @@ public class SendEmailMojoTest { // add a destination mojo.setToAddresses(Collections.singletonList("chemit@codelutin.com")); - try { - mojo.init(); - canContinue = true; - } catch (Exception e) { - canContinue = false; - } + canContinue = initMojo(mojo); if (canContinue) { if (mojo.isVerbose()) { @@ -88,17 +78,22 @@ public class SendEmailMojoTest { @Test public void sendEmail() throws Exception { + Assume.assumeTrue(canContinue); + SendEmailMojo mojo = rule.getMojo(); + Assert.assertNotNull(mojo); + mojo.doAction(); - Assert.assertNotNull(rule.getMojo()); - rule.getMojo().doAction(); } @Test public void skipSendEmail() throws Exception { + Assume.assumeTrue(canContinue); - Assert.assertNotNull(rule.getMojo()); - rule.getMojo().execute(); + SendEmailMojo mojo = rule.getMojo(); + Assert.assertNotNull(mojo); + mojo.execute(); + } } diff --git a/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/TransformProjectVersionMojoTest.java b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/TransformProjectVersionMojoTest.java index 2b9362e..85e6dfc 100644 --- a/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/TransformProjectVersionMojoTest.java +++ b/helper-maven-plugin/src/test/java/org/nuiton/helper/plugin/TransformProjectVersionMojoTest.java @@ -33,7 +33,7 @@ import java.io.File; import java.util.Properties; /** - * @author tchemit <chemit@codelutin.com> + * @author tchemit - chemit@codelutin.com * @since 2.0 */ public class TransformProjectVersionMojoTest { @@ -44,29 +44,14 @@ public class TransformProjectVersionMojoTest { protected boolean canContinue; @Rule - public MojoTestRule<TransformProjectVersionMojo> rule = new MojoTestRule<TransformProjectVersionMojo>(TransformProjectVersionMojoTest.class) { - - @Override - protected String getGoalName(String methodName) { - return "transform-project-version"; - } + public MojoTestRule<TransformProjectVersionMojo> rule = new MojoTestRule<TransformProjectVersionMojo>(TransformProjectVersionMojoTest.class, "transform-project-version") { @Override protected void setUpMojo(TransformProjectVersionMojo mojo, File pomFile) throws Exception { super.setUpMojo(mojo, pomFile); - try { - mojo.init(); - canContinue = true; - } catch (Exception e) { - - canContinue = false; - - if (log.isDebugEnabled()) { - log.debug("Could not init mojo ", e); - } - } + canContinue = initMojo(mojo); } }; @@ -75,57 +60,66 @@ public class TransformProjectVersionMojoTest { public void simple() throws Exception { Assert.assertTrue(canContinue); - Assert.assertNotNull(rule.getMojo()); - rule.getMojo().doAction(); + TransformProjectVersionMojo mojo = rule.getMojo(); + Assert.assertNotNull(mojo); + mojo.doAction(); assertNewVersion("newVersion", "1.0-rev-1"); + } @Test public void keepSnapshot() throws Exception { Assert.assertTrue(canContinue); - Assert.assertNotNull(rule.getMojo()); - rule.getMojo().doAction(); + TransformProjectVersionMojo mojo = rule.getMojo(); + Assert.assertNotNull(mojo); + mojo.doAction(); assertNewVersion("newVersion", "2.0-rev-2-SNAPSHOT"); + } @Test public void removeSnapshot() throws Exception { Assert.assertTrue(canContinue); - Assert.assertNotNull(rule.getMojo()); - rule.getMojo().doAction(); + TransformProjectVersionMojo mojo = rule.getMojo(); + Assert.assertNotNull(mojo); + mojo.doAction(); assertNewVersion("newVersion", "2.0-rev-2"); + } @Test public void badVersionPattern1() throws Exception { Assert.assertFalse(canContinue); + } @Test public void badVersionPattern2() throws Exception { Assert.assertFalse(canContinue); + } @Test public void badVersionPattern3() throws Exception { Assert.assertFalse(canContinue); + } - protected void assertNewVersion(String versionKey, - String expectedNewVersion) { + protected void assertNewVersion(String versionKey, String expectedNewVersion) { Properties properties = rule.getMojo().getProject().getProperties(); Object newVersion = properties.get(versionKey); Assert.assertNotNull(newVersion); Assert.assertEquals(expectedNewVersion, newVersion); + } } diff --git a/helper-maven-plugin/src/test/resources/org/nuiton/helper/plugin/checkAutoContainerPluginTest/central.xml b/helper-maven-plugin/src/test/resources/org/nuiton/helper/plugin/checkAutoContainerPluginTest/central.xml new file mode 100644 index 0000000..b243690 --- /dev/null +++ b/helper-maven-plugin/src/test/resources/org/nuiton/helper/plugin/checkAutoContainerPluginTest/central.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + Helper Maven Plugin :: Mojos + %% + Copyright (C) 2009 - 2012 Codelutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + +<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.test</groupId> + <artifactId>check-auto-container-central</artifactId> + <version>0</version> + + <name>check-auto-container-central</name> + <description>check all dependencies are in central.</description> + + <url>http://www.foo.com</url> + + <properties> + + <pluginVersion>@pom.version@</pluginVersion> + + <!-- default encoding --> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + + </properties> + + <dependencies> + + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> + + </dependencies> + <build> + + <plugins> + + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>helper-maven-plugin</artifactId> + <configuration> + <addMavenCentral>true</addMavenCentral> + <failIfNotSafe>true</failIfNotSafe> + <verbose>true</verbose> + </configuration> + <executions> + <execution> + <id>check-central-safe</id> + <goals> + <goal>check-auto-container</goal> + </goals> + <phase>validate</phase> + </execution> + </executions> + </plugin> + + </plugins> + + </build> + +</project> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.