Author: tchemit Date: 2013-08-07 17:51:08 +0200 (Wed, 07 Aug 2013) New Revision: 898 Url: http://nuiton.org/projects/maven-helper-plugin/repository/revisions/898 Log: fixes #2805: In collectMojo, can not use absolute file in descriptionFile property fixes #2808: improve the way to check run once on mojo fixes #2809: SendEmail mojo should be able to be executed from any project in reactor and not only the root project fixes #2810: Add skip flag on checkAutoContainer mojo fixes #2811: Add skip flag on shareServerSecret mojo Modified: trunk/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/AbstractPlugin.java trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java Modified: trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java =================================================================== --- trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java 2013-08-07 15:26:04 UTC (rev 897) +++ trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java 2013-08-07 15:51:08 UTC (rev 898) @@ -118,6 +118,14 @@ protected boolean runOnce; /** + * A flag to skip the goal. + * + * @since 2.1 + */ + @Parameter(property = "helper.skipCheckAutocontainer", defaultValue = "false") + protected boolean skipCheckAutocontainer; + + /** * Project. * * @since 1.2.5 @@ -207,8 +215,6 @@ public static final String MAVEN_CENTRAL_URL = "http://repo1.maven.org/maven2/"; - private boolean wasAlreadyExecuted; - @Override public MavenProject getProject() { return project; @@ -232,6 +238,10 @@ @Override public void init() throws Exception { + if (isGoalSkip()) { + return; + } + Log log = getLog(); if (log.isDebugEnabled()) { @@ -240,16 +250,6 @@ setVerbose(true); } - if (runOnce) { - - boolean wasAlreadyExecuted = checkAlreadyExecuted(); - - if (wasAlreadyExecuted) { - return; - } - - } - safeRepositories = createSafeRepositories(); artifacts = prepareArtifacts(); @@ -262,9 +262,16 @@ } } - protected boolean checkAlreadyExecuted() { - // compute the unique key refering to parameters of plugin + @Override + protected boolean checkSkip() { + if (isGoalSkip()) { + // goal mark to be skipped + getLog().info("skipGoal flag is on, will skip the goal."); + return false; + } + + StringBuilder buffer = new StringBuilder("check-auto-container##"); Artifact artifact = project.getArtifact(); buffer.append(artifact.getGroupId()).append(":"); @@ -275,29 +282,10 @@ String key = buffer.toString(); - if (verbose) { - getLog().info("check if already done for key : " + key); - } - Object value = project.getProperties().get(key); - if (value != null) { - // ok was already done - wasAlreadyExecuted = true; - } - long timestamp = System.nanoTime(); - project.getProperties().put(key, timestamp + ""); - if (verbose) { - getLog().info("Adding cache key " + key + - " with timestamp " + timestamp); - } - return wasAlreadyExecuted; - } + boolean wasAlreadyExecuted = checkRunOnceDone(runOnce, false, key); - @Override - protected boolean checkSkip() { - if (runOnce && wasAlreadyExecuted) { + if (wasAlreadyExecuted) { - // ok was already done - getLog().info("Goal was already executed, will skip goal."); return false; } @@ -555,8 +543,7 @@ protected void disconnect(Wagon wagon) { try { wagon.disconnect(); - } - catch (ConnectionException e) { + } catch (ConnectionException e) { Log log = getLog(); if (log.isDebugEnabled()) { log.error("Error disconnecting wagon - ignored", e); @@ -582,4 +569,8 @@ return proxyInfo; } + protected boolean isGoalSkip() { + return skipCheckAutocontainer; + } + } \ No newline at end of file Modified: trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java =================================================================== --- trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2013-08-07 15:26:04 UTC (rev 897) +++ trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2013-08-07 15:51:08 UTC (rev 898) @@ -285,8 +285,14 @@ if (StringUtils.isNotBlank(descriptionFile)) { - description = new File(rootProject.getBasedir(), descriptionFile); + description = new File(descriptionFile); + if (!description.isAbsolute()) { + + // relativize from root project + description = new File(rootProject.getBasedir(), descriptionFile); + } + withDescriptionFile = true; if (description.exists()) { Modified: trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java =================================================================== --- trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java 2013-08-07 15:26:04 UTC (rev 897) +++ trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java 2013-08-07 15:51:08 UTC (rev 898) @@ -202,11 +202,6 @@ @Parameter(property = "redmine.runOnce", defaultValue = "true") protected boolean runOnce; - /** - * internal flag to know if plugin was already executed - * (for multi-module projects) - */ - private boolean runOnceDone; /////////////////////////////////////////////////////////////////////////// /// Plugin /////////////////////////////////////////////////////////////////////////// @@ -242,16 +237,6 @@ return; } - runOnceDone = false; - if (runOnce) { - // check - - if (!isExecutionRoot()) { - runOnceDone = true; - return; - } - } - if (!emailContentFile.exists()) { // no file to publish... throw new MojoExecutionException( @@ -312,15 +297,26 @@ return false; } - if (runOnce && runOnceDone) { - // already run - getLog().info("runOnce flag is on and goal was already " + - "executed, will skip the goal"); + // check if plugin was already done + StringBuilder buffer = new StringBuilder("send-email"); + buffer.append("##").append(emailTitle); + buffer.append("##").append(emailContentFile); + buffer.append("##").append(mailSender.getEmail()); + for (String toAddress : toAddresses) { + buffer.append("##").append(toAddress); + } + buffer.append("##").append(mailSender.getEmail()); + + String key = buffer.toString(); + boolean wasAlreadyExecuted = checkRunOnceDone(runOnce, false, key); + + if (wasAlreadyExecuted) { + return false; } - return true; + return super.checkSkip(); } @Override Modified: trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java =================================================================== --- trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2013-08-07 15:26:04 UTC (rev 897) +++ trunk/helper-maven-plugin/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2013-08-07 15:51:08 UTC (rev 898) @@ -153,6 +153,15 @@ protected boolean runOnce; /** + * A flag to skip the goal. + * + * @since 2.1 + */ + @Parameter(property = "helper.skipShareServerSecret", defaultValue = "false") + protected boolean skipShareServerSecret; + + + /** * A flag to skip null values. * * @since 1.6 @@ -206,6 +215,10 @@ @Override public void init() throws Exception { + if (isGoalSkip()) { + return; + } + propertiesToTreate = new EnumMap<Property, String>(Property.class); if (StringUtils.isNotEmpty(usernameOut)) { @@ -242,39 +255,25 @@ @Override public boolean checkSkip() { - if (runOnce) { - // compute the unique key refering to parameters of plugin + StringBuilder buffer = new StringBuilder("share-secret##"); + buffer.append(serverId); + buffer.append("##"); + for (Map.Entry<Property, String> entry : + propertiesToTreate.entrySet()) { + buffer.append(entry.getKey()).append(entry.getValue()); + } + // check if plugin was already done. - StringBuilder buffer = new StringBuilder("share-secret##"); - buffer.append(serverId); - buffer.append("##"); - for (Map.Entry<Property, String> entry : - propertiesToTreate.entrySet()) { - buffer.append(entry.getKey()).append(entry.getValue()); - } - // check if plugin was already done. + String key = buffer.toString(); - String key = buffer.toString(); + boolean wasAlreadyDone = checkRunOnceDone(runOnce, false, key); - if (verbose) { - getLog().info("check if already done for key : " + key); - } - Object value = project.getProperties().get(key); - if (value != null) { - // ok was already done - getLog().info("Goal was already executed, will skip goal."); - return false; - } - long timestamp = System.nanoTime(); - project.getProperties().put(key, timestamp + ""); - if (verbose) { - getLog().info("Adding cache key " + key + - " with timestamp " + timestamp); - } + if (wasAlreadyDone) { + return false; + } - } - return true; + return super.checkSkip(); } @Override @@ -386,4 +385,8 @@ public void setRunOnce(boolean runOnce) { this.runOnce = runOnce; } + + protected boolean isGoalSkip() { + return skipShareServerSecret; + } } Modified: trunk/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/AbstractPlugin.java =================================================================== --- trunk/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2013-08-07 15:26:04 UTC (rev 897) +++ trunk/helper-maven-plugin-api/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2013-08-07 15:51:08 UTC (rev 898) @@ -167,7 +167,7 @@ * {@link #rejectPackaging(Plugin.Packaging...)} * * @return {@code true} if can execute the goal for the packaging of the - * project, {@code false} otherwise. + * project, {@code false} otherwise. */ protected boolean checkPackaging() { // by default, accept every type of packaging @@ -228,13 +228,15 @@ } /** - * Check if an execution was already done according to the given parameters. + * Check if an execution was already done according to the given + * parameters based on a timestamp. * * @param runOnce the flag * @param onlyForRoot a flag to * @param buildStartTime the build statrt time (if none means must do it) * @param newStartTime the current build start time - * @return {@code true} if the goal was already invoked + * @return {@code true} if the goal was already invoked, {@code false} + * otherwise (means should run it now!). */ protected boolean checkRunOnceDone(boolean runOnce, boolean onlyForRoot, @@ -279,6 +281,53 @@ } /** + * Check if an execution was already done 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 was already invoked, {@code false} + * otherwise (means should run it now!). + * @since 2.1 + */ + protected boolean checkRunOnceDone(boolean runOnce, + boolean onlyForRoot, + String key) { + + if (!runOnce) { + // will run each time + return false; + } + + if (onlyForRoot && !isExecutionRoot()) { + + // never do it for a child + return true; + } + + + if (isVerbose()) { + getLog().info("check if already done for key : " + key); + } + Object value = getProject().getProperties().get(key); + if (value != null) { + // ok was already done + getLog().info("Goal was already executed (but asked to be run only once), will skip goal."); + return false; + } + long timestamp = System.nanoTime(); + getProject().getProperties().put(key, timestamp + ""); + if (isVerbose()) { + getLog().info("Adding cache key " + key + + " with timestamp " + timestamp); + } + return true; + } + + /** * Recupere le fichier donnée à partir de son chemin relatif sur le basedir * du projet maven. * @@ -328,7 +377,7 @@ * * @param f the file to test * @return {@code true} if file exists and is newer than the pom file, - * {@code false} otherwise. + * {@code false} otherwise. */ protected boolean isFileNewerThanPomFile(File f) { File pomFile = getProject().getFile();