Author: tchemit Date: 2010-01-01 19:47:47 +0100 (Fri, 01 Jan 2010) New Revision: 644 Removed: trunk/src/main/java/org/nuiton/helper/plugin/GenerateSiteIndexPlugin.java trunk/src/main/resources/org/nuiton/helper/plugin/ Modified: trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java Log: - reject Evolution #128: Ajout d'un goal pour g?\195?\169n?\195?\169rer une page index.html dans les site respectant la symetricLayout - Evolution #181: Permettre de n'?\195?\169xecuter qu'une seule fois le goal share-server-secret Deleted: trunk/src/main/java/org/nuiton/helper/plugin/GenerateSiteIndexPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/GenerateSiteIndexPlugin.java 2010-01-01 17:26:30 UTC (rev 643) +++ trunk/src/main/java/org/nuiton/helper/plugin/GenerateSiteIndexPlugin.java 2010-01-01 18:47:47 UTC (rev 644) @@ -1,211 +0,0 @@ -package org.nuiton.helper.plugin; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; -import org.apache.maven.settings.Settings; -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.VelocityEngine; -import org.apache.velocity.context.Context; -import org.apache.velocity.exception.ResourceNotFoundException; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.velocity.VelocityComponent; -import org.nuiton.plugin.AbstractPlugin; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; - -/** - * Generate a simple index.html page for the site using the symetricLayout. - * - * @author chemit - * @goal generate-site-index - * @phase pre-site - * @requiresProject true - * @since 1.1.1 - */ -public class GenerateSiteIndexPlugin extends AbstractPlugin { - - /** - * Directory where the template file will be generated. - * - * @parameter expression="${helper.templateOutputDirectory}" default-value="${project.reporting.outputDirectory}" - * @required - * @since 1.1.1 - */ - protected File templateOutputDirectory; - /** - * Directory that contains the template. - * <p> - * <b>Note:</b> This directory must be a subdirectory of - * <code>/src/main/resources/ or current project base directory</code>. - * </p> - * - * @parameter expression="${helper.templateDirectory}" default-value="org/nuiton/helper/plugin" - * @required - * @since 1.1.1 - */ - protected String templateDirectory; - /** - * Velocity template name to use. - * - * @parameter expression="${helper.template}" default-value="site-index.vm" - * @required - * @since 1.1.1 - */ - protected String template; - /** - * The template encoding. - * - * @parameter expression="${helper.templateEncoding}" default-value="${project.reporting.outputEncoding}" - * @since 1.1.1 - */ - protected String templateEncoding; - /** - * The name of the artifact to be used in the announcement. - * - * @parameter expression="${redmine.title}" default-value="${project.name}" - * @required - * @since 1.1.1 - */ - protected String title; - /** - * A comma separated list of locales supported by Maven. The first valid token will be the default Locale - * for this instance of the Java Virtual Machine. - * - * @parameter expression="${locales}" - * @required - */ - protected String locales; - /** - * Dependance du projet. - * - * @parameter default-value="${project}" - * @required - * @readonly - * @since 1.1.1 - */ - protected MavenProject project; - /** - * Dependance du settings. - * - * @parameter default-value="${settings}" - * @required - * @readonly - * @since 1.1.1 - */ - protected Settings settings; - - /** - * Un flag pour activer le mode verbeux. - * - * @parameter expression="${helper.verbose}" default-value="${maven.verbose}" - * @since 1.1.1 - */ - protected boolean verbose; - /** - * The first locale of the given locales. - */ - protected String defaultLocale; - - /** - * Velocity Component. - * - * @component roleHint="maven-helper-plugin" - */ - protected VelocityComponent velocity; - - @Override - protected void init() throws Exception { -// protected boolean init() throws Exception { - if (StringUtils.isEmpty(templateEncoding)) { - templateEncoding = ReaderFactory.FILE_ENCODING; - getLog().warn("File encoding has not been set, using platform encoding " + templateEncoding + ", i.e. build is platform dependent!"); - } - int firstComma = locales.indexOf(","); - if (firstComma == -1) { - defaultLocale = locales; - } else { - defaultLocale = locales.substring(0, firstComma); - } - -// return true; - } - - @Override - protected void doAction() throws Exception { - - - File out = new File(templateOutputDirectory, "index.html"); - if (verbose) { - getLog().info("destination file " + out); - } - - VelocityEngine engine = velocity.getEngine(); - - engine.setApplicationAttribute("baseDirectory", project.getBasedir()); - - // prepare velocity context - - Context context = new VelocityContext(); - - context.put("project", project); - context.put("title", title); - context.put("defaultLocale", defaultLocale); - - String templatePath = templateDirectory + "/" + template; - - // generate index.html - - try { - - createDirectoryIfNecessary(out.getParentFile()); - - Writer writer = new OutputStreamWriter(new FileOutputStream(out), templateEncoding); - - Template velocityTemplate = engine.getTemplate(templatePath, templateEncoding); - - velocityTemplate.merge(context, writer); - - writer.flush(); - - writer.close(); - - getLog().info("Created index.html from [" + template + "] in " + out); - - } catch (ResourceNotFoundException rnfe) { - throw new MojoExecutionException("Resource not found.", rnfe); - } catch (Exception e) { - throw new MojoExecutionException(e.toString(), e); - } - - } - - - public MavenProject getProject() { - return project; - } - - public void setProject(MavenProject project) { - this.project = project; - } - - public Settings getSettings() { - return settings; - } - - public void setSettings(Settings settings) { - this.settings = settings; - } - - public boolean isVerbose() { - return verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } -} Modified: trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2010-01-01 17:26:30 UTC (rev 643) +++ trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2010-01-01 18:47:47 UTC (rev 644) @@ -109,6 +109,16 @@ */ protected boolean verbose; /** + * Un flag pour ne lancer le plugin qu'une seule fois par build. + * <p/> + * <b>Note:</b> Par défaut, la valeur est à {@code true} car il ne parrâit pas + * nécessaire de rejouer le mojo à chaque fois. + * + * @parameter expression="${helper.runOnce}" default-value="true" + * @since 1.1.0 + */ + protected boolean runOnce; + /** * password decypher * * @component roleHint="maven-helper-plugin" @@ -196,6 +206,41 @@ } @Override + protected 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. + + 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 + 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); + } + + } + return true; + } + + @Override protected void doAction() throws Exception { Properties properties = project.getModel().getProperties();