Author: tchemit Date: 2009-10-11 22:59:58 +0200 (Sun, 11 Oct 2009) New Revision: 615 Modified: trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java Log: - review exception in AbstractPlugin - add checkRunOnceDone method Modified: trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2009-10-11 13:10:17 UTC (rev 614) +++ trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2009-10-11 20:59:58 UTC (rev 615) @@ -242,7 +242,9 @@ } } - getLog().info("collected file " + path); + if (isVerbose()) { + getLog().info("Collected file " + path); + } if (!dryRun && copyFiles) { // copy the collected file copyFile(f, dst); @@ -253,7 +255,9 @@ if (!dryRun && withDescriptionFile) { try { setFiles(description, incomingFiles); - getLog().info("Saved " + description); + if (isVerbose()) { + getLog().info("Saved " + description); + } } catch (IOException ex) { throw new MojoExecutionException("could not save file " + description, ex); } Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-10-11 13:10:17 UTC (rev 614) +++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-10-11 20:59:58 UTC (rev 615) @@ -32,6 +32,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; @@ -86,25 +87,32 @@ @Override public void execute() throws MojoExecutionException, MojoFailureException { + + boolean canContinue = checkPackaging(); + if (!canContinue) { + getLog().warn("The goal is skip due to packaging '" + getProject().getPackaging() + "'"); + return; + } + try { - boolean canContinue = checkPackaging(); - if (!canContinue) { - getLog().warn("The goal is skip due to packaging '" + getProject().getPackaging() + "'"); - return; - } - canContinue = init(); - if (!canContinue) { - getLog().warn(skipAfterInitMessage); - return; - } + } catch (Exception e) { + throw new MojoExecutionException("could not init goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e); + } + if (!canContinue) { + getLog().warn(skipAfterInitMessage); + return; + } + + try { + doAction(); } catch (Exception e) { - throw new MojoExecutionException("could not init goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e); + throw new MojoExecutionException("could not execute goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e); } } @@ -171,6 +179,62 @@ } /** + * + * @return {@code true} if project is the root execution project + */ + protected boolean isExecutionRoot() { + return getProject().isExecutionRoot(); + } + + /** + * + * @param runOnce + * @param onlyForRoot + * @param buildStartTime + * @param newStartTime + * @return {@code true} if the goal was already invoked + */ + protected boolean checkRunOnceDone(boolean runOnce, boolean onlyForRoot, Date buildStartTime, Date newStartTime) { + + if (!runOnce) { + // will run each time + return false; + } + + if (onlyForRoot && !isExecutionRoot()) { + + // never do it for a child + return true; + } + + if (buildStartTime == null) { + // no build start time, so must run + return false; + } + + if (newStartTime == null) { + + // must run + return false; + } + + if (isVerbose()) { + getLog().info("build timestamp : " + buildStartTime); + getLog().info("plugin timestamp : " + newStartTime); + } + + if (newStartTime.getTime() > buildStartTime.getTime()) { + + // was already generated + return true; + } + + // must run + return false; + + } + + /** * Copy a file to a given locationand logging. * * @param srcFile represents the file to copy.
participants (1)
-
tchemit@users.nuiton.org