Author: tchemit Date: 2010-06-29 23:41:39 +0200 (Tue, 29 Jun 2010) New Revision: 739 Url: http://nuiton.org/repositories/revision/maven-helper-plugin/739 Log: Evolution #748: Add runOnce property on mojo check-auto-container Modified: trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java Modified: trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java 2010-06-29 21:23:08 UTC (rev 738) +++ trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java 2010-06-29 21:41:39 UTC (rev 739) @@ -103,6 +103,17 @@ protected boolean verbose; /** + * A flag to execute only once the mojo. + * <p/> + * <b>Note:</b> By default, value is {@code true} since it is not necessary + * to check twice for a same artifact. + * + * @parameter expression="${helper.runOnce}" default-value="true" + * @since 1.2.6 + */ + protected boolean runOnce; + + /** * Project. * * @parameter default-value="${project}" @@ -207,6 +218,8 @@ public static final String MAVEN_CENTRAL_URL = "http://repo1.maven.org/maven2/"; + private boolean wasAlreadyExecuted; + @Override public MavenProject getProject() { return project; @@ -238,6 +251,16 @@ setVerbose(true); } + if (runOnce) { + + boolean wasAlreadyExecuted = checkAlreadyExecuted(); + + if (wasAlreadyExecuted) { + return; + } + + } + safeRepositories = createSafeRepositories(); artifacts = prepareArtifacts(); @@ -250,9 +273,45 @@ } } + protected boolean checkAlreadyExecuted() { + // compute the unique key refering to parameters of plugin + + StringBuilder buffer = new StringBuilder("check-auto-container##"); + Artifact artifact = project.getArtifact(); + buffer.append(artifact.getGroupId()).append(":"); + buffer.append(artifact.getArtifactId()).append(":"); + buffer.append(artifact.getVersion()).append("##"); + + // check if plugin was already done. + + 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; + } + @Override protected boolean checkSkip() { + if (runOnce && wasAlreadyExecuted) { + // ok was already done + getLog().info("Goal was already executed, will skip goal."); + return false; + } + if (artifacts.isEmpty()) { getLog().info("Project has no dependecy."); return false;
participants (1)
-
tchemit@users.nuiton.org