Author: tchemit Date: 2009-12-28 10:27:41 +0100 (Mon, 28 Dec 2009) New Revision: 640 Modified: trunk/pom.xml trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java trunk/src/main/java/org/nuiton/helper/plugin/GenerateSiteIndexPlugin.java trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java Log: - use new io api - improve code of Sharesceret mojo - make inetegration tests attached to a release Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-12-28 09:16:26 UTC (rev 639) +++ trunk/pom.xml 2009-12-28 09:27:41 UTC (rev 640) @@ -1307,6 +1307,12 @@ <profile> <id>run-its</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> <build> <plugins> <plugin> Modified: trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2009-12-28 09:16:26 UTC (rev 639) +++ trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2009-12-28 09:27:41 UTC (rev 640) @@ -185,7 +185,6 @@ File output = new File(base, project.getGroupId() + "--" + project.getArtifactId()); if (rootProject == project || verbose) { - // just print on root getLog().info("Ouput dir : " + output); } @@ -193,8 +192,8 @@ getLog().info("\n dryRun flag is on, no file will be copied!\n"); } else { - if (copyFiles && !output.exists()) { - output.mkdirs(); + if (copyFiles) { + createDirectoryIfNecessary(output); } } @@ -294,15 +293,11 @@ * @throws IOException if any pb when writing file */ public void setFiles(File output, List<File> files) throws IOException { -// BufferedWriter writer = new BufferedWriter(new FileWriter(output)); StringBuilder builder = new StringBuilder(); for (File f : files) { builder.append(f.getAbsolutePath()).append("\n"); -// writer.write(f.getAbsolutePath()); -// writer.newLine(); } writeFile(output, builder.toString(), encoding); -// writer.close(); } protected List<File> getFiles() { Modified: trunk/src/main/java/org/nuiton/helper/plugin/GenerateSiteIndexPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/GenerateSiteIndexPlugin.java 2009-12-28 09:16:26 UTC (rev 639) +++ trunk/src/main/java/org/nuiton/helper/plugin/GenerateSiteIndexPlugin.java 2009-12-28 09:27:41 UTC (rev 640) @@ -106,14 +106,6 @@ * @since 1.1.1 */ protected boolean verbose; -// /** -// * Un flag pour forcer la génération de la page html. -// * -// * @parameter expression="${helper.force}" default-value="false" -// * @since 1.1.1 -// */ -// protected boolean force; - /** * The first locale of the given locales. */ @@ -169,9 +161,7 @@ try { - if (!out.getParentFile().exists()) { - out.getParentFile().mkdirs(); - } + createDirectoryIfNecessary(out.getParentFile()); Writer writer = new OutputStreamWriter(new FileOutputStream(out), templateEncoding); Modified: trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java =================================================================== --- trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2009-12-28 09:16:26 UTC (rev 639) +++ trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2009-12-28 09:27:41 UTC (rev 640) @@ -1,15 +1,18 @@ package org.nuiton.helper.plugin; -import org.nuiton.plugin.*; -import java.util.Properties; -import org.apache.maven.plugin.MojoExecutionException; +import org.apache.commons.lang.StringUtils; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; +import org.nuiton.plugin.AbstractPlugin; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; +import java.util.EnumMap; +import java.util.Map; +import java.util.Properties; + /** - * Obtain a server authentication and share it in the maven + * Obtain a server authentication and share it in the maven * project properties. * <p/> * To select data to export from the server with the given {@code serverId}, @@ -20,13 +23,12 @@ * privateKeyOut * passphraseOut * </pre> - * + * * @author chemit - * @since 1.1.0 - * * @goal share-server-secret * @phase initialize * @requiresProject true + * @since 1.1.0 */ public class ShareServerSecretPlugin extends AbstractPlugin { @@ -66,7 +68,7 @@ * @parameter * @since 1.1.0 */ - private String usernameOut; + protected String usernameOut; /** * The name of the property where to export the password of the server. * <p/> @@ -77,7 +79,7 @@ * @parameter * @since 1.1.0 */ - private String passwordOut; + protected String passwordOut; /** * The name of the property where to export the passphrase of the server. * <p/> @@ -88,16 +90,16 @@ * @parameter * @since 1.1.0 */ - private String passphraseOut; + protected String passphraseOut; /** * The name of the property where to export the private key of the server. * <p/> * <b>Note:</b> If not set - then no export of the private key of the server. - * + * * @parameter * @since 1.1.0 */ - private String privateKeyOut; + protected String privateKeyOut; /** * Un flag pour activer le mode verbeux. * @@ -112,76 +114,96 @@ * @since 1.1.0 */ protected SecDispatcher sec; - private boolean exportUsername; - private boolean exportPassword; - private boolean exportPassphrase; - private boolean exportPrivateKey; + /** + * the server to use to obtain secrets + */ + private Server server; + /** + * server secrets to expose + */ + private Map<Property, String> propertiesToTreate; + public enum Property { + username { + @Override + public String getSecret(Server server) { + return server.getUsername(); + } + }, + password { + @Override + public String getSecret(Server server) { + return server.getPassword(); + } + }, + passphrase { + @Override + public String getSecret(Server server) { + return server.getPassphrase(); + } + }, + privateKey { + @Override + public String getSecret(Server server) { + return server.getPrivateKey(); + } + }; + + public abstract String getSecret(Server server); + } + @Override protected boolean init() throws Exception { - if (usernameOut != null && !usernameOut.trim().isEmpty()) { - exportUsername = true; + + propertiesToTreate = new EnumMap<Property, String>(Property.class); + + if (StringUtils.isNotEmpty(usernameOut)) { + propertiesToTreate.put(Property.username, usernameOut); } - if (passwordOut != null && !passwordOut.trim().isEmpty()) { - exportPassword = true; + if (StringUtils.isNotEmpty(passwordOut)) { + propertiesToTreate.put(Property.password, passwordOut); } - if (passphraseOut != null && !passphraseOut.trim().isEmpty()) { - exportPassphrase = true; + if (StringUtils.isNotEmpty(passphraseOut)) { + propertiesToTreate.put(Property.passphrase, passphraseOut); } - if (privateKeyOut != null && !privateKeyOut.trim().isEmpty()) { - exportPrivateKey = true; + if (StringUtils.isNotEmpty(privateKeyOut)) { + propertiesToTreate.put(Property.privateKey, privateKeyOut); } - if (!(exportUsername || exportPassword || exportPassphrase || exportPrivateKey)) { + if (propertiesToTreate.isEmpty()) { getLog().error("Nothing to export, you should specify what to export via 'usernameOut', 'passwordOut', 'passphraseOut', 'privateKeyOut' parameters."); return false; } + + if (StringUtils.isEmpty(serverId)) { + getLog().error("No 'serverId' defined."); + return false; + } + + server = settings.getServer(serverId.trim()); + + if (server == null) { + getLog().error("Could not find server with id '" + serverId + "', check your settings.xml file."); + return false; + } + return true; } @Override protected void doAction() throws Exception { - Server server = null; - if (serverId != null && !serverId.trim().isEmpty()) { - - server = settings.getServer(serverId); - - if (server == null) { - throw new MojoExecutionException("Could not find server with id '" + serverId + "', check your settings.xml file."); - } - } - Properties properties = project.getModel().getProperties(); - if (exportUsername) { + for (Map.Entry<Property, String> entry : this.propertiesToTreate.entrySet()) { + Property key = entry.getKey(); + String propertyValue = key.getSecret(server); + String propertyTargetName = entry.getValue(); - String username = server.getUsername(); - username = sec.decrypt(username); - getLog().info("export server [" + serverId + "] username in ${" + usernameOut + "}"); - properties.setProperty(usernameOut, username); - } + propertyValue = sec.decrypt(propertyValue); - if (exportPassword) { - String password = server.getPassword(); - password = sec.decrypt(password); - - getLog().info("export server [" + serverId + "] password in ${" + passwordOut + "}"); - properties.setProperty(passwordOut, password); + getLog().info("export server [" + serverId + "] " + key.name() + " in ${" + propertyTargetName + "}"); + properties.setProperty(propertyTargetName, propertyValue); } - - if (exportPassphrase) { - String passphrase = server.getPassphrase(); - passphrase = sec.decrypt(passphrase); - - getLog().info("export server [" + serverId + "] passphrase in ${" + passphraseOut + "}"); - properties.setProperty(passphraseOut, passphrase); - } - if (exportPrivateKey) { - String privateKey = server.getPrivateKey(); - - getLog().info("export server [" + serverId + "] privateKey in ${" + privateKeyOut + "}"); - properties.setProperty(privateKeyOut, privateKey); - } } @Override @@ -203,4 +225,44 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } + + public String getPassphraseOut() { + return passphraseOut; + } + + public void setPassphraseOut(String passphraseOut) { + this.passphraseOut = passphraseOut; + } + + public String getPasswordOut() { + return passwordOut; + } + + public void setPasswordOut(String passwordOut) { + this.passwordOut = passwordOut; + } + + public String getPrivateKeyOut() { + return privateKeyOut; + } + + public void setPrivateKeyOut(String privateKeyOut) { + this.privateKeyOut = privateKeyOut; + } + + public String getUsernameOut() { + return usernameOut; + } + + public void setUsernameOut(String usernameOut) { + this.usernameOut = usernameOut; + } + + public String getServerId() { + return serverId; + } + + public void setServerId(String serverId) { + this.serverId = serverId; + } }