Maven-helper-plugin-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
December 2009
- 1 participants
- 3 discussions
29 Dec '09
Author: tchemit
Date: 2009-12-29 16:39:54 +0100 (Tue, 29 Dec 2009)
New Revision: 641
Added:
trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java
trunk/src/main/java/org/nuiton/io/mail/
trunk/src/main/java/org/nuiton/io/mail/MailSender.java
trunk/src/main/java/org/nuiton/io/mail/ProjectJavamailMailSender.java
trunk/src/test/java/org/nuiton/helper/
trunk/src/test/java/org/nuiton/helper/plugin/
trunk/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java
trunk/src/test/resources/org/nuiton/helper/
trunk/src/test/resources/org/nuiton/helper/plugin/
trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/
trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/mailContentFile.txt
trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/sendEmail.xml
trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/skipSendEmail.xml
Removed:
trunk/src/main/java/org/nuiton/mail/MailSender.java
trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java
trunk/src/main/java/org/nuiton/mail/plugin/
trunk/src/test/java/org/nuiton/mail/
trunk/src/test/resources/org/nuiton/mail/
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
trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
trunk/src/main/java/org/nuiton/plugin/Plugin.java
trunk/src/main/java/org/nuiton/plugin/PluginHelper.java
Log:
- begin of version 1.2.0
- improve AbstrctPlugin api :
* init method does not anylonger returns anything just throw exception if something is wrong)
* add a checkSkip method in api to make possible easely to not execute the doAction method
* doAction method should not anylonger performs test form skipping content
- use the new api on goals
- move mail api to io.mail
-move mail mojo to helper.plugin package (with other goals)
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-12-28 09:27:41 UTC (rev 640)
+++ trunk/pom.xml 2009-12-29 15:39:54 UTC (rev 641)
@@ -11,7 +11,7 @@
<groupId>org.nuiton</groupId>
<artifactId>maven-helper-plugin</artifactId>
- <version>1.1.1-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<dependencies>
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:27:41 UTC (rev 640)
+++ trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -20,26 +20,22 @@
*/
package org.nuiton.helper.plugin;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Pattern;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.nuiton.plugin.AbstractPlugin;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
/**
* Collect files some files from a project and copy them into a directory.
*
+ * @author tchemit
* @goal collect-files
* @requiresProject true
- *
- * @author tchemit
* @since 1.1.0
*/
public class CollectFilesMojo extends AbstractPlugin {
@@ -64,7 +60,7 @@
protected List attachedArtifacts;
/**
* User extra files to collect.
- *
+ * <p/>
* Multi values can be used, separated by comma.
*
* @parameter expression="${helper.extraFiles}"
@@ -73,7 +69,7 @@
protected String extraFiles;
/**
* File name pattern of selected files to publish.
- *
+ * <p/>
* If no Set - no include filter
*
* @parameter expression="${helper.includes}" default-value=""
@@ -82,7 +78,7 @@
protected String includes;
/**
* File name pattern of selected files to publish.
- *
+ * <p/>
* If no Set - no exclude filter
*
* @parameter expression="${helper.excludes}" default-value=""
@@ -92,7 +88,7 @@
/**
* Directory where to store collected files.
* <p/>
- * <b>Note :</b> In a multi-module context, will always use the value of
+ * <b>Note :</b> In a multi-module context, will always use the value of
* the property of the root module, because we need to push collected files
* to only one place.
*
@@ -152,18 +148,35 @@
* @since 1.0.0
*/
protected String encoding;
- List<File> files;
+ /**
+ * Files to collect
+ */
+ protected List<File> files;
@Override
- protected boolean init() throws Exception {
+ protected void init() throws Exception {
if (skip) {
- return true;
+ return;
}
files = getFiles();
+// if (files.isEmpty()) {
+//
+// getLog().warn("No file to collect.");
+// skip = true;
+// }
+ }
+
+ @Override
+ protected boolean checkSkip() {
+ if (skip) {
+ getLog().info("Skip flag is on, goal will not be executed.");
+ return false;
+ }
+
if (files.isEmpty()) {
- getLog().warn("No file to collect.");
+ getLog().warn("No file to collect, goal will not be executed.");
return false;
}
@@ -173,10 +186,10 @@
@Override
public void doAction() throws Exception {
- if (skip) {
- getLog().info("Skip flag in on, goal will not be executed");
- return;
- }
+// if (skip) {
+// getLog().info("Skip flag in on, goal will not be executed");
+// return;
+// }
MavenProject rootProject = getExecutionRootProject();
@@ -265,7 +278,7 @@
/**
* Read a file containing on each line the path of a file.
- *
+ *
* @param input the file containing the list of files
* @return the list of files read from the given file
* @throws IOException if any pb while reading file
@@ -289,7 +302,7 @@
* Each line is the absolute path of each files of the list
*
* @param output the file when to write
- * @param files the files to store
+ * @param files the files to store
* @throws IOException if any pb when writing file
*/
public void setFiles(File output, List<File> files) throws IOException {
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:27:41 UTC (rev 640)
+++ trunk/src/main/java/org/nuiton/helper/plugin/GenerateSiteIndexPlugin.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -119,7 +119,8 @@
protected VelocityComponent velocity;
@Override
- protected boolean init() throws Exception {
+ 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!");
@@ -131,7 +132,7 @@
defaultLocale = locales.substring(0, firstComma);
}
- return true;
+// return true;
}
@Override
Copied: trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java (from rev 640, trunk/src/main/java/org/nuiton/mail/plugin/SendEmailMojo.java)
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java (rev 0)
+++ trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -0,0 +1,426 @@
+/*
+ * *##%
+ * Maven helper plugin
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package org.nuiton.helper.plugin;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.model.Developer;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.codehaus.plexus.mailsender.MailMessage;
+import org.codehaus.plexus.mailsender.MailSenderException;
+import org.nuiton.io.mail.MailSender;
+import org.nuiton.io.mail.ProjectJavamailMailSender;
+import org.nuiton.plugin.AbstractPlugin;
+import org.nuiton.plugin.PluginHelper;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Send a email.
+ *
+ * @author tchemit
+ * @goal send-email
+ * @requiresOnline true
+ * @requiresProject true
+ * @since 1.0.3
+ */
+public class SendEmailMojo extends AbstractPlugin {
+
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ * @since 1.0.3
+ */
+ protected MavenProject project;
+ /**
+ * Dependance du settings.
+ *
+ * @parameter default-value="${settings}"
+ * @required
+ * @readonly
+ * @since 1.0.3
+ */
+ protected Settings settings;
+ /**
+ * Un flag pour activer le mode verbeux.
+ *
+ * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
+ * @since 1.0.3
+ */
+ protected boolean verbose;
+ /**
+ * The Velocity template used to format the email announcement.
+ *
+ * @parameter expression="${helper.emailContentFile}"
+ * @required
+ * @since 1.0.3
+ */
+ protected File emailContentFile;
+ /**
+ * The title of the email to send.
+ *
+ * @parameter expression="${helper.emailTitle}"
+ * @required
+ * @since 1.0.3
+ */
+ protected String emailTitle;
+ /**
+ * Smtp Server.
+ *
+ * @parameter expression="${helper.smtpHost}"
+ * @required
+ * @since 1.0.3
+ */
+ protected String smtpHost;
+ /**
+ * Port.
+ *
+ * @parameter default-value="25" expression="${helper.smtpPort}"
+ * @required
+ * @since 1.0.3
+ */
+ protected int smtpPort;
+ /**
+ * The username used to send the email.
+ *
+ * @parameter expression="${helper.username}"
+ * @since 1.0.3
+ */
+ protected String username;
+ /**
+ * The password used to send the email.
+ *
+ * @parameter expression="${helper.password}"
+ * @since 1.0.3
+ */
+ protected String password;
+ /**
+ * If the email should be sent in SSL mode.
+ *
+ * @parameter default-value="false" expression="${helper.sslMode}"
+ * @since 1.0.3
+ */
+ protected boolean sslMode;
+ /**
+ * The id of the developer sending the announcement mail. Only used if the <tt>mailSender</tt>
+ * attribute is not set. In this case, this should match the id of one of the developers in
+ * the pom. If a matching developer is not found, then the first developer in the pom will be
+ * used.
+ *
+ * @parameter expression="${helper.fromDeveloperId}"
+ * @since 1.0.3
+ */
+ protected String fromDeveloperId;
+ /**
+ * Defines the sender of the announcement if the list of developer is empty or
+ * if the sender is not a member of the development team.
+ *
+ * @parameter expression="${helper.mailSender}"
+ * @since 1.0.3
+ */
+ protected MailSender mailSender;
+ /**
+ * Recipient email address.
+ *
+ * @parameter
+ * @required
+ * @since 1.0.3
+ */
+ protected List<String> toAddresses;
+ /**
+ * Possible senders.
+ *
+ * @parameter expression="${project.developers}"
+ * @required
+ * @readonly
+ * @since 1.0.3
+ */
+ protected List<Developer> from;
+ /**
+ * Mail content type to use.
+ *
+ * @parameter default-value="text/plain"
+ * @required
+ * @since 1.0.3
+ */
+ protected String mailContentType;
+ /**
+ * The encoding used to read and write files.
+ *
+ * @parameter expression="${helper.encoding}" default-value="${project.build.sourceEncoding}"
+ * @since 1.0.3
+ */
+ protected String encoding;
+ /**
+ * A flag to skip the goal.
+ *
+ * @parameter expression="${helper.skipSendEmail}" default-value="false"
+ * @since 1.0.3
+ */
+ private boolean skipSendEmail;
+ /**
+ * A flag to test plugin but send nothing to redmine.
+ *
+ * @parameter expression="${dryRun}" default-value="false"
+ * @since 1.0.3
+ */
+ protected boolean dryRun;
+ /**
+ * A flag to restirct only one run in a build (for multi-module context).
+ *
+ * @parameter expression="${redmine.runOnce}" default-value="true"
+ * @since 1.0.3
+ */
+ private boolean runOnce;
+ /**
+ * internal flag to know if plugin was already executed (for multi-module projects)
+ */
+ private boolean runOnceDone;
+ ///////////////////////////////////////////////////////////////////////////
+ /// Plugin
+ ///////////////////////////////////////////////////////////////////////////
+
+ @Override
+ public MavenProject getProject() {
+ return project;
+ }
+
+ @Override
+ public void setProject(MavenProject project) {
+ this.project = project;
+ }
+
+ @Override
+ public boolean isVerbose() {
+ return verbose;
+ }
+
+ @Override
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ /// AbstractPlugin
+ ///////////////////////////////////////////////////////////////////////////
+ @Override
+ protected void init() throws Exception {
+// protected boolean init() throws Exception {
+
+ if (isGoalSkip()) {
+ return;
+// return true;
+ }
+
+ runOnceDone = false;
+ if (runOnce) {
+ // check
+
+ if (!isExecutionRoot()) {
+// getLog().info("runOnce flag is on, will skip the goal");
+ runOnceDone = true;
+ return;
+// return true;
+ }
+ }
+
+ if (!emailContentFile.exists()) {
+ // no file to publish...
+ throw new MojoExecutionException("could not find the template " + emailContentFile);
+// getLog().warn("could not find the template " + emailContentFile);
+// getLog().warn("will skip send email...");
+// return false;
+ }
+
+ // check mail sender
+
+ if (mailSender == null) {
+
+ if (from == null || from.isEmpty()) {
+ throw new MojoExecutionException("The <developers> section in your pom should not be empty. Add a <developer> entry or set the " + "mailSender parameter.");
+// getLog().warn("The <developers> section in your pom should not be empty. Add a <developer> entry or set the " + "mailSender parameter.");
+// getLog().warn("will skip send email...");
+// return false;
+ }
+
+ if (fromDeveloperId == null) {
+ final Developer dev = from.get(0);
+ mailSender = new MailSender(dev.getName(), dev.getEmail());
+ } else {
+ for (Developer developer : from) {
+ if (fromDeveloperId.equals(developer.getId())) {
+ mailSender = new MailSender(developer.getName(), developer.getEmail());
+ break;
+ }
+ }
+ if (mailSender == null) {
+ throw new MojoExecutionException("Missing developer with id '" + fromDeveloperId + "' in the <developers> section in your pom.");
+// getLog().warn("Missing developer with id '" + fromDeveloperId + "' in the <developers> section in your pom.");
+// getLog().warn("will skip send email...");
+// return false;
+ }
+ }
+ }
+
+ String fromAddress = mailSender.getEmail();
+ if (StringUtils.isEmpty(fromAddress)) {
+ throw new MojoExecutionException("Invalid mail sender: name and email is mandatory (" + mailSender + ").");
+// getLog().warn("Invalid mail sender: name and email is mandatory (" + mailSender + ").");
+// getLog().warn("will skip send email...");
+// return false;
+ }
+
+// return true;
+ }
+
+ @Override
+ protected boolean checkSkip() {
+ if (isGoalSkip()) {
+ // goal mark to be skipped
+ getLog().info("skipGoal flag is on, will skip the goal.");
+ return false;
+ }
+
+ if (runOnce && runOnceDone) {
+ // already run
+ getLog().info("runOnce flag is on and goal was laready executed, will skip the goal");
+
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ protected void doAction() throws Exception {
+// if (runOnce && runOnceDone) {
+// // already run
+// return;
+// }
+// if (isGoalSkip()) {
+// getLog().info("skipGoal flag is on, the goal is skip.");
+// return;
+// }
+
+ if (dryRun) {
+ getLog().info("\n dryRun flag is on, no mail will be send!\n");
+ }
+
+ String newsContent = PluginHelper.readAsString(emailContentFile, encoding);
+
+ MailMessage mailMsg = createMessage(newsContent, mailSender);
+
+
+ ProjectJavamailMailSender mailer = createMailer();
+
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("fromDeveloperId: " + fromDeveloperId);
+ }
+
+ if (dryRun) {
+ getLog().info("Mail title : " + emailTitle);
+ getLog().info("Mail content :\n" + mailMsg.getContent());
+ return;
+ }
+ getLog().info("Connecting to Host: " + smtpHost + ":" + smtpPort);
+
+ try {
+
+ mailer.send(mailMsg);
+ getLog().info("Sent...");
+ } catch (MailSenderException e) {
+ throw new MojoExecutionException("Failed to send email for reason " + e.getMessage(), e);
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ /// Other
+ ///////////////////////////////////////////////////////////////////////////
+ protected boolean isGoalSkip() {
+ return skipSendEmail;
+ }
+
+ protected MailMessage createMessage(String newsContent, MailSender mailSender) throws MailSenderException {
+
+ String fromName = mailSender.getName();
+ String fromAddress = mailSender.getEmail();
+
+ getLog().info("Using this sender for email announcement: " + fromAddress + " < " + fromName + " > ");
+
+ MailMessage mailMsg = new MailMessage();
+ mailMsg.setSubject(emailTitle);
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("email announcement :\n" + newsContent);
+ }
+ mailMsg.setContent(newsContent);
+ mailMsg.setContentType(mailContentType);
+ mailMsg.setFrom(fromAddress, fromName);
+ for (String e : toAddresses) {
+ getLog().info("Sending mail to " + e + "...");
+ mailMsg.addTo(e, "");
+ }
+ return mailMsg;
+ }
+
+ protected ProjectJavamailMailSender createMailer() {
+
+ ProjectJavamailMailSender mailer = new ProjectJavamailMailSender();
+ ConsoleLogger logger = new ConsoleLogger(Logger.LEVEL_INFO, "base");
+ if (getLog().isDebugEnabled()) {
+ logger.setThreshold(Logger.LEVEL_DEBUG);
+ }
+ mailer.enableLogging(logger);
+ mailer.setSmtpHost(smtpHost);
+ mailer.setSmtpPort(smtpPort);
+ mailer.setSslMode(sslMode);
+ if (username != null) {
+ mailer.setUsername(username);
+ }
+ if (password != null) {
+ mailer.setPassword(password);
+ }
+ mailer.initialize();
+ return mailer;
+ }
+
+ public void setMailSender(MailSender sender) {
+ this.mailSender = sender;
+ }
+
+ public void setFrom(List<Developer> from) {
+ this.from = from;
+ }
+
+ public void setToAddresses(List<String> toAddresses) {
+ this.toAddresses = toAddresses;
+ }
+
+ protected boolean isExecutionRoot() {
+ return project.isExecutionRoot();
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
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:27:41 UTC (rev 640)
+++ trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -1,6 +1,7 @@
package org.nuiton.helper.plugin;
import org.apache.commons.lang.StringUtils;
+import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
@@ -153,7 +154,8 @@
}
@Override
- protected boolean init() throws Exception {
+ protected void init() throws Exception {
+// protected boolean init() throws Exception {
propertiesToTreate = new EnumMap<Property, String>(Property.class);
@@ -170,23 +172,27 @@
propertiesToTreate.put(Property.privateKey, privateKeyOut);
}
if (propertiesToTreate.isEmpty()) {
- getLog().error("Nothing to export, you should specify what to export via 'usernameOut', 'passwordOut', 'passphraseOut', 'privateKeyOut' parameters.");
- return false;
+ throw new MojoExecutionException("Nothing to export, you should specify what to export via 'usernameOut', 'passwordOut', 'passphraseOut' or 'privateKeyOut' parameters.");
+//
+// 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;
+ throw new MojoExecutionException("No 'serverId' defined.");
+// 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;
+ throw new MojoExecutionException("Could not find server with id '" + serverId + "', check your settings.xml file.");
+// getLog().error("Could not find server with id '" + serverId + "', check your settings.xml file.");
+// return false;
}
- return true;
+// return true;
}
@Override
@@ -199,6 +205,9 @@
String propertyValue = key.getSecret(server);
String propertyTargetName = entry.getValue();
+ if (isVerbose()) {
+ getLog().info("will decrypt [" + key + "] : " + propertyValue);
+ }
propertyValue = sec.decrypt(propertyValue);
getLog().info("export server [" + serverId + "] " + key.name() + " in ${" + propertyTargetName + "}");
Copied: trunk/src/main/java/org/nuiton/io/mail/MailSender.java (from rev 640, trunk/src/main/java/org/nuiton/mail/MailSender.java)
===================================================================
--- trunk/src/main/java/org/nuiton/io/mail/MailSender.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/mail/MailSender.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -0,0 +1,66 @@
+/*
+ * *##%
+ * Maven helper plugin
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package org.nuiton.io.mail;
+
+/**
+ * Defines the sender of a email.
+ *
+ * Note : this code was stolen in {@code maven-changes-plugin}, should thanks
+ * them...
+ *
+ * @author chemit
+ * @since 1.0.3
+ */
+public class MailSender {
+
+ private String name;
+ private String email;
+
+ public MailSender() {
+ super();
+ }
+
+ public MailSender(String name, String email) {
+ this.name = name;
+ this.email = email;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ @Override
+ public String toString() {
+ return getName() + " (" + getEmail() + ")";
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/mail/MailSender.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Copied: trunk/src/main/java/org/nuiton/io/mail/ProjectJavamailMailSender.java (from rev 640, trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java)
===================================================================
--- trunk/src/main/java/org/nuiton/io/mail/ProjectJavamailMailSender.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/mail/ProjectJavamailMailSender.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -0,0 +1,182 @@
+/*
+ * *##%
+ * Maven helper plugin
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package org.nuiton.io.mail;
+
+import java.security.Security;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.mail.Authenticator;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.PasswordAuthentication;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+import org.codehaus.plexus.mailsender.AbstractMailSender;
+import org.codehaus.plexus.mailsender.MailMessage;
+import org.codehaus.plexus.mailsender.MailSenderException;
+import org.codehaus.plexus.mailsender.util.DateFormatUtils;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Helper class for sending email.
+ *
+ * Note : this code was stolen in {@code maven-changes-plugin}, should thanks
+ * them...
+ *
+ * @author chemit
+ * @since 1.0.3
+ */
+public class ProjectJavamailMailSender
+ extends AbstractMailSender {
+
+ private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+ private Properties userProperties;
+ private Properties props;
+
+ // ----------------------------------------------------------------------
+ // Component Lifecycle
+ // ----------------------------------------------------------------------
+ public void initialize() {
+ if (StringUtils.isEmpty(getSmtpHost())) {
+ System.out.println("Error in configuration: Missing smtpHost.");
+ }
+
+ if (getSmtpPort() == 0) {
+ setSmtpPort(DEFAULT_SMTP_PORT);
+ }
+
+ props = new Properties();
+
+ props.put("mail.smtp.host", getSmtpHost());
+
+ props.put("mail.smtp.port", String.valueOf(getSmtpPort()));
+
+ if (getUsername() != null) {
+ props.put("mail.smtp.auth", "true");
+ }
+
+ props.put("mail.debug", String.valueOf(getLogger().isDebugEnabled()));
+
+ if (isSslMode()) {
+ Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
+
+ props.put("mail.smtp.socketFactory.port", String.valueOf(getSmtpPort()));
+
+ props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
+
+ props.put("mail.smtp.socketFactory.fallback", "false");
+ }
+
+ if (userProperties != null) {
+ for (Iterator<?> i = userProperties.keySet().iterator(); i.hasNext();) {
+ String key = (String) i.next();
+
+ String value = userProperties.getProperty(key);
+
+ props.put(key, value);
+ }
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ // MailSender Implementation
+ // ----------------------------------------------------------------------
+ @Override
+ public void send(MailMessage mail)
+ throws MailSenderException {
+ verify(mail);
+
+ try {
+ Authenticator auth = null;
+
+ if (getUsername() != null) {
+ auth = new Authenticator() {
+
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(getUsername(), getPassword());
+ }
+ };
+ }
+
+ Session session = Session.getDefaultInstance(props, auth);
+
+ session.setDebug(getLogger().isDebugEnabled());
+
+ Message msg = new MimeMessage(session);
+ InternetAddress addressFrom = new InternetAddress(mail.getFrom().getRfc2822Address());
+ msg.setFrom(addressFrom);
+
+ if (mail.getToAddresses().size() > 0) {
+ InternetAddress[] addressTo = new InternetAddress[mail.getToAddresses().size()];
+ int count = 0;
+ for (Iterator<?> i = mail.getToAddresses().iterator(); i.hasNext();) {
+ String address = ((MailMessage.Address) i.next()).getRfc2822Address();
+ addressTo[count++] = new InternetAddress(address);
+ }
+ msg.setRecipients(Message.RecipientType.TO, addressTo);
+ }
+
+ if (mail.getCcAddresses().size() > 0) {
+ InternetAddress[] addressCc = new InternetAddress[mail.getCcAddresses().size()];
+ int count = 0;
+ for (Iterator<?> i = mail.getCcAddresses().iterator(); i.hasNext();) {
+ String address = ((MailMessage.Address) i.next()).getRfc2822Address();
+ addressCc[count++] = new InternetAddress(address);
+ }
+ msg.setRecipients(Message.RecipientType.CC, addressCc);
+ }
+
+ if (mail.getBccAddresses().size() > 0) {
+ InternetAddress[] addressBcc = new InternetAddress[mail.getBccAddresses().size()];
+ int count = 0;
+ for (Iterator<?> i = mail.getBccAddresses().iterator(); i.hasNext();) {
+ String address = ((MailMessage.Address) i.next()).getRfc2822Address();
+ addressBcc[count++] = new InternetAddress(address);
+ }
+ msg.setRecipients(Message.RecipientType.BCC, addressBcc);
+ }
+
+ // Setting the Subject and Content Type
+ msg.setSubject(mail.getSubject());
+ msg.setContent(mail.getContent(), mail.getContentType() == null ? "text/plain" : mail.getContentType());
+
+ if (mail.getSendDate() != null) {
+ msg.setHeader("Date", DateFormatUtils.getDateHeader(mail.getSendDate()));
+ } else {
+ msg.setHeader("Date", DateFormatUtils.getDateHeader(new Date()));
+ }
+
+ // Send the message
+ Transport.send(msg);
+ } catch (MessagingException e) {
+ throw new MailSenderException("Error while sending mail.", e);
+ }
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/mail/ProjectJavamailMailSender.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Deleted: trunk/src/main/java/org/nuiton/mail/MailSender.java
===================================================================
--- trunk/src/main/java/org/nuiton/mail/MailSender.java 2009-12-28 09:27:41 UTC (rev 640)
+++ trunk/src/main/java/org/nuiton/mail/MailSender.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -1,66 +0,0 @@
-/*
- * *##%
- * Maven helper plugin
- * Copyright (C) 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package org.nuiton.mail;
-
-/**
- * Defines the sender of a email.
- *
- * Note : this code was stolen in {@code maven-changes-plugin}, should thanks
- * them...
- *
- * @author chemit
- * @since 1.0.3
- */
-public class MailSender {
-
- private String name;
- private String email;
-
- public MailSender() {
- super();
- }
-
- public MailSender(String name, String email) {
- this.name = name;
- this.email = email;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- @Override
- public String toString() {
- return getName() + " (" + getEmail() + ")";
- }
-}
Deleted: trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java
===================================================================
--- trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java 2009-12-28 09:27:41 UTC (rev 640)
+++ trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -1,182 +0,0 @@
-/*
- * *##%
- * Maven helper plugin
- * Copyright (C) 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package org.nuiton.mail;
-
-import java.security.Security;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Properties;
-
-import javax.mail.Authenticator;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.PasswordAuthentication;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-
-import org.codehaus.plexus.mailsender.AbstractMailSender;
-import org.codehaus.plexus.mailsender.MailMessage;
-import org.codehaus.plexus.mailsender.MailSenderException;
-import org.codehaus.plexus.mailsender.util.DateFormatUtils;
-import org.codehaus.plexus.util.StringUtils;
-
-/**
- * Helper class for sending email.
- *
- * Note : this code was stolen in {@code maven-changes-plugin}, should thanks
- * them...
- *
- * @author chemit
- * @since 1.0.3
- */
-public class ProjectJavamailMailSender
- extends AbstractMailSender {
-
- private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
- // ----------------------------------------------------------------------
- //
- // ----------------------------------------------------------------------
- private Properties userProperties;
- private Properties props;
-
- // ----------------------------------------------------------------------
- // Component Lifecycle
- // ----------------------------------------------------------------------
- public void initialize() {
- if (StringUtils.isEmpty(getSmtpHost())) {
- System.out.println("Error in configuration: Missing smtpHost.");
- }
-
- if (getSmtpPort() == 0) {
- setSmtpPort(DEFAULT_SMTP_PORT);
- }
-
- props = new Properties();
-
- props.put("mail.smtp.host", getSmtpHost());
-
- props.put("mail.smtp.port", String.valueOf(getSmtpPort()));
-
- if (getUsername() != null) {
- props.put("mail.smtp.auth", "true");
- }
-
- props.put("mail.debug", String.valueOf(getLogger().isDebugEnabled()));
-
- if (isSslMode()) {
- Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
-
- props.put("mail.smtp.socketFactory.port", String.valueOf(getSmtpPort()));
-
- props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
-
- props.put("mail.smtp.socketFactory.fallback", "false");
- }
-
- if (userProperties != null) {
- for (Iterator<?> i = userProperties.keySet().iterator(); i.hasNext();) {
- String key = (String) i.next();
-
- String value = userProperties.getProperty(key);
-
- props.put(key, value);
- }
- }
- }
-
- // ----------------------------------------------------------------------
- // MailSender Implementation
- // ----------------------------------------------------------------------
- @Override
- public void send(MailMessage mail)
- throws MailSenderException {
- verify(mail);
-
- try {
- Authenticator auth = null;
-
- if (getUsername() != null) {
- auth = new Authenticator() {
-
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(getUsername(), getPassword());
- }
- };
- }
-
- Session session = Session.getDefaultInstance(props, auth);
-
- session.setDebug(getLogger().isDebugEnabled());
-
- Message msg = new MimeMessage(session);
- InternetAddress addressFrom = new InternetAddress(mail.getFrom().getRfc2822Address());
- msg.setFrom(addressFrom);
-
- if (mail.getToAddresses().size() > 0) {
- InternetAddress[] addressTo = new InternetAddress[mail.getToAddresses().size()];
- int count = 0;
- for (Iterator<?> i = mail.getToAddresses().iterator(); i.hasNext();) {
- String address = ((MailMessage.Address) i.next()).getRfc2822Address();
- addressTo[count++] = new InternetAddress(address);
- }
- msg.setRecipients(Message.RecipientType.TO, addressTo);
- }
-
- if (mail.getCcAddresses().size() > 0) {
- InternetAddress[] addressCc = new InternetAddress[mail.getCcAddresses().size()];
- int count = 0;
- for (Iterator<?> i = mail.getCcAddresses().iterator(); i.hasNext();) {
- String address = ((MailMessage.Address) i.next()).getRfc2822Address();
- addressCc[count++] = new InternetAddress(address);
- }
- msg.setRecipients(Message.RecipientType.CC, addressCc);
- }
-
- if (mail.getBccAddresses().size() > 0) {
- InternetAddress[] addressBcc = new InternetAddress[mail.getBccAddresses().size()];
- int count = 0;
- for (Iterator<?> i = mail.getBccAddresses().iterator(); i.hasNext();) {
- String address = ((MailMessage.Address) i.next()).getRfc2822Address();
- addressBcc[count++] = new InternetAddress(address);
- }
- msg.setRecipients(Message.RecipientType.BCC, addressBcc);
- }
-
- // Setting the Subject and Content Type
- msg.setSubject(mail.getSubject());
- msg.setContent(mail.getContent(), mail.getContentType() == null ? "text/plain" : mail.getContentType());
-
- if (mail.getSendDate() != null) {
- msg.setHeader("Date", DateFormatUtils.getDateHeader(mail.getSendDate()));
- } else {
- msg.setHeader("Date", DateFormatUtils.getDateHeader(new Date()));
- }
-
- // Send the message
- Transport.send(msg);
- } catch (MessagingException e) {
- throw new MailSenderException("Error while sending mail.", e);
- }
- }
-}
Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-12-28 09:27:41 UTC (rev 640)
+++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -49,13 +49,15 @@
* <p/>
* <b>Note:</b> The method is invoked before the {@link #doAction()} method.
* <p/>
+ * <p/>
+ * // * @return <code>true</code> if mojo is well initialize and something has
+ * // * to be done in the {@link #doAction()} method, <code>false</code>
+ * // * otherwise.
*
- * @return <code>true</code> if mojo is well initialize and something has
- * to be done in the {@link #doAction()} method, <code>false</code>
- * otherwise.
* @throws Exception if any
*/
- protected abstract boolean init() throws Exception;
+ protected abstract void init() throws Exception;
+// protected abstract boolean init() throws Exception;
/**
* Do plugin action.
@@ -70,41 +72,54 @@
*/
protected abstract void doAction() throws Exception;
- /**
- * the message to display when will skip the goal
- */
- protected String skipAfterInitMessage;
+// /**
+// * the message to display when will skip the goal
+// */
+// protected String skipAfterInitMessage;
- protected AbstractPlugin() {
- this("The goal could not be initialized, will skip the goal");
- }
+// protected AbstractPlugin() {
+// this("The goal could not be initialized, will skip the goal");
+// }
- protected AbstractPlugin(String skipAfterInitMessage) {
- this.skipAfterInitMessage = skipAfterInitMessage;
- }
+// protected AbstractPlugin(String skipAfterInitMessage) {
+// this.skipAfterInitMessage = skipAfterInitMessage;
+// }
@Override
- public void execute() throws MojoExecutionException, MojoFailureException {
+ public final void execute() throws MojoExecutionException, MojoFailureException {
+ // check if project packaging is compatible with the mojo
+
boolean canContinue = checkPackaging();
if (!canContinue) {
getLog().warn("The goal is skip due to packaging '" + getProject().getPackaging() + "'");
return;
}
+ // init the mojo
+
try {
- canContinue = init();
+ init();
+// canContinue = init();
} catch (Exception e) {
throw new MojoExecutionException("could not init goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e);
}
+ // check if mojo can be skipped
+
+ canContinue = checkSkip();
if (!canContinue) {
- getLog().warn(skipAfterInitMessage);
+ if (isVerbose() || getLog().isDebugEnabled()) {
+ getLog().info("Goal will not be executed.");
+ }
+// getLog().warn(skipAfterInitMessage);
return;
}
+ // can really execute the mojo
+
try {
doAction();
@@ -134,14 +149,25 @@
* project, {@code false} otherwise.
*/
protected boolean checkPackaging() {
+ // by default, accept every type of packaging
return true;
}
/**
+ * Checks if the mojo execution should be skipped.
+ *
+ * @return {@code false} if the mojo should not be executed.
+ */
+ protected boolean checkSkip() {
+ // by default, never skip goal
+ return true;
+ }
+
+ /**
* Accept the project's packaging between some given.
*
* @param packages the accepted packaging
- * @return {@code true} if the project's packagin is one of the given ones.
+ * @return {@code true} if the project's packaging is one of the given ones.
*/
protected boolean acceptPackaging(Packaging... packages) {
String projectPackaging = getProject().getPackaging();
@@ -252,19 +278,18 @@
*
* @param srcFile represents the file to copy.
* @param destFile file name of destination file.
- * @throws MojoExecutionException with a message if an
- * error occurs.
+ * @throws IOException if could not copy file.
*/
public void copyFile(File srcFile, File destFile)
- throws MojoExecutionException {
- try {
- getLog().info("Copying " + srcFile.getName() + " to " + destFile);
+ throws IOException {
+// try {
+ getLog().info("Copying " + srcFile.getName() + " to " + destFile);
- PluginHelper.copy(srcFile, destFile);
+ PluginHelper.copy(srcFile, destFile);
- } catch (Exception e) {
- throw new MojoExecutionException("Error copying from " + srcFile + " to " + destFile, e);
- }
+// } catch (Exception e) {
+// throw new MojoExecutionException("Error copying from " + srcFile + " to " + destFile, e);
+// }
}
/**
@@ -586,6 +611,26 @@
}
/**
+ * @param file the source file
+ * @return the backup file
+ */
+ public File getBackupFile(File file) {
+ return new File(file.getAbsolutePath() + "~");
+ }
+
+ /**
+ * Backups the given file using the {@link #getBackupFile(java.io.File)} as
+ * destination file.
+ *
+ * @param f the file to backup
+ * @throws IOException if any pb while copying the file
+ */
+ protected void backupFile(File f) throws IOException {
+ File dst = getBackupFile(f);
+ copyFile(f, dst);
+ }
+
+ /**
* Init mojo classLoader.
*
* @param project the maven project
Modified: trunk/src/main/java/org/nuiton/plugin/Plugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/Plugin.java 2009-12-28 09:27:41 UTC (rev 640)
+++ trunk/src/main/java/org/nuiton/plugin/Plugin.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -25,15 +25,33 @@
/**
* A common contract to be implements by our mojo and reports.
+ * <p/>
+ * Just expose a {@link #isVerbose()} flag and the maven project {@link #getProject()}.
*
- * Just expose a {@link #isVerbose()} flag and the maven project {@link #getProject()}.
- *
* @author chemit
* @since 1.0.3
*/
public interface Plugin extends Mojo {
/**
+ * An enumeration to qualify the init result of a plugin
+ */
+ enum InitState {
+ /**
+ * when something is wrong and should throw an error
+ */
+ failed,
+ /**
+ * when the plugin execution should be skipped
+ */
+ skip,
+ /**
+ * when plugin can be executed
+ */
+ ok
+ }
+
+ /**
* An enumeration to qualify a maven module packaging
*/
enum Packaging {
@@ -43,8 +61,10 @@
plugin,
war,
ear
- };
+ }
+ ;
+
MavenProject getProject();
void setProject(MavenProject project);
Modified: trunk/src/main/java/org/nuiton/plugin/PluginHelper.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2009-12-28 09:27:41 UTC (rev 640)
+++ trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -20,32 +20,19 @@
*/
package org.nuiton.plugin;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
+import java.io.*;
+import java.text.MessageFormat;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
/**
* Une classe pour mutualiser toutes les méthodes utiles pour un plugin.
*
@@ -269,7 +256,7 @@
/**
* @param newresourceDir the new resource directory to add
- * @param project the maven project to modifiy
+ * @param project the maven project to modifiy
* @return {@code true} if resources was added
* @deprecated since 1.1.1, prefer use the {@link #addResourceDir(java.io.File, org.apache.maven.project.MavenProject, String...)}
*/
@@ -282,7 +269,7 @@
/**
* @param newresourceDir the new resource directory to add
- * @param project the maven project to modifiy
+ * @param project the maven project to modifiy
* @return {@code true} if resources was added
* @deprecated since 1.1.1, prefer use the {@link #addTestResourceDir(java.io.File, org.apache.maven.project.MavenProject, String...)}
*/
@@ -295,8 +282,8 @@
/**
* @param newresourceDir the new resource directory to add
- * @param project the maven project to modifiy
- * @param resources the known resources for the maven project
+ * @param project the maven project to modifiy
+ * @param resources the known resources for the maven project
* @return {@code true} if resources was added
* @deprecated since 1.1.1, prefer use the {@link #addResourceDir(java.io.File, org.apache.maven.project.MavenProject, java.util.List, String...)}
*/
@@ -365,6 +352,10 @@
* @since 1.1.1
*/
public static void deleteFile(File file) throws IOException {
+ if (!file.exists()) {
+ // file does not exist, can not delete it
+ return;
+ }
boolean b = file.delete();
if (!b) {
throw new IOException("could not delete file " + file);
Copied: trunk/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java (from rev 640, trunk/src/test/java/org/nuiton/mail/plugin/SendEmailMojoTest.java)
===================================================================
--- trunk/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java (rev 0)
+++ trunk/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java 2009-12-29 15:39:54 UTC (rev 641)
@@ -0,0 +1,88 @@
+/*
+ * *##%
+ * Maven helper plugin
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package org.nuiton.helper.plugin;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Test;
+import org.nuiton.io.mail.MailSender;
+import org.nuiton.plugin.AbstractMojoTest;
+
+import java.io.File;
+import java.util.Arrays;
+
+/**
+ * @author tchemit
+ * @since 1.0.0
+ */
+public class SendEmailMojoTest extends AbstractMojoTest<SendEmailMojo> {
+
+ protected boolean canContinue;
+
+ @Override
+ protected String getGoalName(String methodName) {
+ return "send-email";
+ }
+
+ @Override
+ protected void setUpMojo(SendEmailMojo mojo, File pomFile) throws Exception {
+ super.setUpMojo(mojo, pomFile);
+
+ // add a mailSender here
+ MailSender sender = new MailSender();
+ sender.setName("Nuiton Release Notification");
+ sender.setEmail("test(a)noway.fr");
+ mojo.setMailSender(sender);
+
+ // add a destination
+ mojo.setToAddresses(Arrays.asList("chemit(a)codelutin.com"));
+
+ try {
+ mojo.init();
+ canContinue = true;
+ } catch (Exception e) {
+ canContinue = false;
+ }
+// canContinue = mojo.init();
+ if (canContinue) {
+ if (mojo.isVerbose()) {
+ log.info("setup done for " + mojo.getProject().getFile().getName());
+ }
+ } else {
+ log.error("setup was not successfull, will skip this test [" + getClass() + "]");
+ }
+ }
+
+ @Test
+ public void sendEmail() throws Exception {
+ Assume.assumeTrue(canContinue);
+
+ Assert.assertNotNull(getMojo());
+ getMojo().doAction();
+ }
+
+ @Test
+ public void skipSendEmail() throws Exception {
+ Assume.assumeTrue(canContinue);
+ Assert.assertNotNull(getMojo());
+ getMojo().execute();
+ }
+}
Property changes on: trunk/src/test/java/org/nuiton/helper/plugin/SendEmailMojoTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Copied: trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/mailContentFile.txt (from rev 640, trunk/src/test/resources/org/nuiton/mail/plugin/sendEmailMojoTest/mailContentFile.txt)
===================================================================
--- trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/mailContentFile.txt (rev 0)
+++ trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/mailContentFile.txt 2009-12-29 15:39:54 UTC (rev 641)
@@ -0,0 +1 @@
+The content of the test email
\ No newline at end of file
Copied: trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/sendEmail.xml (from rev 640, trunk/src/test/resources/org/nuiton/mail/plugin/sendEmailMojoTest/sendEmail.xml)
===================================================================
--- trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/sendEmail.xml (rev 0)
+++ trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/sendEmail.xml 2009-12-29 15:39:54 UTC (rev 641)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.nuiton.test</groupId>
+ <artifactId>test-send-email</artifactId>
+ <version>0</version>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-helper-plugin</artifactId>
+ <configuration>
+ <emailContentFile>target/test-classes/org/nuiton/mail/plugin/sendEmailMojoTest/mailContentFile.txt</emailContentFile>
+ <emailTitle>[ANNOUNCEMENT] - One 1.0.0 released</emailTitle>
+ <encoding>UTF-8</encoding>
+ <skipSendEmail>false</skipSendEmail>
+ <!--<mailSender>
+ <name>Nuiton Release Notification</name>
+ <email>noreply@${platform}</email>
+ </mailSender>
+ <toAddresses>
+ <item>chemit(a)codelutin.com</item>
+ </toAddresses>-->
+ <smtpHost>smtp</smtpHost>
+ <smtpPort>25</smtpPort>
+ <dryRun>true</dryRun>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>send-email</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Copied: trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/skipSendEmail.xml (from rev 640, trunk/src/test/resources/org/nuiton/mail/plugin/sendEmailMojoTest/skipSendEmail.xml)
===================================================================
--- trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/skipSendEmail.xml (rev 0)
+++ trunk/src/test/resources/org/nuiton/helper/plugin/sendEmailMojoTest/skipSendEmail.xml 2009-12-29 15:39:54 UTC (rev 641)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.nuiton.test</groupId>
+ <artifactId>test-send-email</artifactId>
+ <version>0</version>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-helper-plugin</artifactId>
+ <configuration>
+ <emailContentFile>target/test-classes/org/nuiton/smail/plugin/sendEmailMojoTest/mailContentFile.txt</emailContentFile>
+ <emailTitle>[ANNOUNCEMENT] - One 1.0.0 released</emailTitle>
+ <encoding>UTF-8</encoding>
+ <skipSendEmail>true</skipSendEmail>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>send-email</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
1
0
28 Dec '09
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;
+ }
}
1
0
Author: tchemit
Date: 2009-12-28 10:16:26 +0100 (Mon, 28 Dec 2009)
New Revision: 639
Modified:
trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
trunk/src/main/java/org/nuiton/plugin/PluginHelper.java
Log:
add some usefull methods for io operations on files + reformat
Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-11-26 13:56:56 UTC (rev 638)
+++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-12-28 09:16:26 UTC (rev 639)
@@ -20,10 +20,14 @@
*/
package org.nuiton.plugin;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.nuiton.io.MirroredFileUpdater;
import java.io.File;
import java.io.IOException;
@@ -31,16 +35,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.model.Resource;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.nuiton.io.MirroredFileUpdater;
+import java.util.*;
/**
* Base mojo with usefull methods and implementing {@link Plugin} contract.
@@ -54,9 +49,10 @@
* <p/>
* <b>Note:</b> The method is invoked before the {@link #doAction()} method.
* <p/>
- * @return <code>true</code> if mojo is well initialize and something has
- * to be done in the {@link #doAction()} method, <code>false</code>
- * otherwise.
+ *
+ * @return <code>true</code> if mojo is well initialize and something has
+ * to be done in the {@link #doAction()} method, <code>false</code>
+ * otherwise.
* @throws Exception if any
*/
protected abstract boolean init() throws Exception;
@@ -73,6 +69,7 @@
* @throws Exception if any
*/
protected abstract void doAction() throws Exception;
+
/**
* the message to display when will skip the goal
*/
@@ -126,16 +123,15 @@
* the {@link #execute()}.
* <p/>
* <b>Tip:</b> There is two method to simplify the packaging check :
- *
- * {@link #acceptPackaging(org.nuiton.plugin.Plugin.Packaging[])}
- *
+ * <p/>
+ * {@link #acceptPackaging(org.nuiton.plugin.Plugin.Packaging...)}
+ * <p/>
* and
+ * <p/>
+ * {@link #rejectPackaging(org.nuiton.plugin.Plugin.Packaging...)}
*
- * {@link #rejectPackaging(org.nuiton.plugin.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() {
return true;
@@ -143,7 +139,7 @@
/**
* Accept the project's packaging between some given.
- *
+ *
* @param packages the accepted packaging
* @return {@code true} if the project's packagin is one of the given ones.
*/
@@ -180,7 +176,6 @@
}
/**
- *
* @return {@code true} if project is the root execution project
*/
protected boolean isExecutionRoot() {
@@ -188,11 +183,12 @@
}
/**
+ * Check if an execution was already done according to the given parameters.
*
- * @param runOnce
- * @param onlyForRoot
- * @param buildStartTime
- * @param newStartTime
+ * @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
*/
protected boolean checkRunOnceDone(boolean runOnce, boolean onlyForRoot, Date buildStartTime, Date newStartTime) {
@@ -240,7 +236,6 @@
* du projet maven.
*
* @param paths les paths pour atteindre le fichier ou le répertoire
- *
* @return le fichier de la destination
* @since 1.1.0
*/
@@ -255,11 +250,10 @@
/**
* Copy a file to a given locationand logging.
*
- * @param srcFile represents the file to copy.
+ * @param srcFile represents the file to copy.
* @param destFile file name of destination file.
- *
* @throws MojoExecutionException with a message if an
- * error occurs.
+ * error occurs.
*/
public void copyFile(File srcFile, File destFile)
throws MojoExecutionException {
@@ -278,7 +272,7 @@
* {@code encoding}.
*
* @param destFile location where to write the content
- * @param content content ot write in the file
+ * @param content content ot write in the file
* @param encoding the enconding of the file
* @throws IOException if any pb while writing the content into the file
*/
@@ -300,14 +294,20 @@
/**
* Collects some file.
- *
+ *
* @param includes includes
* @param excludes excludes
- * @param roots root directories to treate
- * @param files cache of file detected indexed by their root directory
- * @param updater
+ * @param roots root directories to treate
+ * @param files cache of file detected indexed by their root directory
+ * @param updater the updater used to detect changes (if none, will get all
+ * the files)
*/
- protected void getFilesToTreateForRoots(String[] includes, String[] excludes, List<String> roots, Map<File, String[]> files, MirroredFileUpdater updater) {
+ protected void getFilesToTreateForRoots(
+ String[] includes,
+ String[] excludes,
+ List<String> roots, Map<File,
+ String[]> files,
+ MirroredFileUpdater updater) {
DirectoryScanner ds = new DirectoryScanner();
ds.setIncludes(includes);
@@ -371,8 +371,8 @@
*
* @param includes includes
* @param excludes excludes
- * @param srcDir the directory to treate
- * @param updater an updater (will give the mirrored files)
+ * @param srcDir the directory to treate
+ * @param updater an updater (will give the mirrored files)
* @return the map of mirrored files associated to their files in srcDir
*/
protected Map<String, String> getFilesToTreate(String[] includes, String[] excludes, File srcDir, MirroredFileUpdater updater) {
@@ -496,8 +496,38 @@
/**
* Add a new resource location to the maven project (in not already present).
*
+ * @param dir the new resource location to add
+ * @param includes files to include
+ * @since 1.1.1
+ */
+ protected void addResourceDir(File dir, String... includes) {
+ boolean added = PluginHelper.addResourceDir(dir, getProject(), includes);
+ if (added && isVerbose()) {
+ getLog().info("add resource " + dir + " with includes " + Arrays.toString(includes));
+ }
+ }
+
+ /**
+ * Add a new test resource location to the maven project (in not already present).
+ *
+ * @param dir the new resource location to add
+ * @param includes files to include
+ * @since 1.1.1
+ */
+ protected void addTestResourceDir(File dir, String... includes) {
+ boolean added = PluginHelper.addTestResourceDir(dir, getProject(), includes);
+ if (added && isVerbose()) {
+ getLog().info("add test resource " + dir + " with includes " + Arrays.toString(includes));
+ }
+ }
+
+ /**
+ * Add a new resource location to the maven project (in not already present).
+ *
* @param dir the new resource location to add
+ * @deprecated since 1.1.1, prefer use the method {@link #addResourceDir(java.io.File, String...)}
*/
+ @Deprecated
protected void addResourceDir(String dir) {
boolean added = PluginHelper.addResourceDir(dir, getProject());
if (added) {
@@ -509,7 +539,9 @@
* Add a new test resource location to the maven project (in not already present).
*
* @param dir the new resource location to add
+ * @deprecated since 1.1.1, prefer use the method {@link #addTestResourceDir(java.io.File, String...)}
*/
+ @Deprecated
protected void addTestResourceDir(String dir) {
boolean added = PluginHelper.addTestResourceDir(dir, getProject());
if (added) {
@@ -518,21 +550,57 @@
}
/**
+ * Create the directory if necessary.
+ *
+ * @param dir the directory to create if not already existing
+ * @throws IOException if could not create the directory
+ * @since 1.1.1
+ */
+ protected void createDirectoryIfNecessary(File dir) throws IOException {
+ boolean b = PluginHelper.createDirectoryIfNecessary(dir);
+ if (b && isVerbose()) {
+ getLog().info("mkdir " + dir);
+ }
+ }
+
+ /**
+ * Create a new file.
+ *
+ * @param file the file to create
+ * @throws IOException if could not create the file
+ * @since 1.1.1
+ */
+ protected void createNewFile(File file) throws IOException {
+ PluginHelper.createNewFile(file);
+ }
+
+ /**
+ * Delete the given file.
+ *
+ * @param file the file to delete
+ * @throws IOException if could not delete the file
+ * @since 1.1.1
+ */
+ protected void deleteFile(File file) throws IOException {
+ PluginHelper.deleteFile(file);
+ }
+
+ /**
* Init mojo classLoader.
*
- * @param project the maven project
- * @param src the source directory
- * @param addSourcesToClassPath a flag to a maven sources to classLoader
- * @param testPhase a flag to specify if we are in a test phase (changes the classLoader)
+ * @param project the maven project
+ * @param src the source directory
+ * @param addSourcesToClassPath a flag to a maven sources to classLoader
+ * @param testPhase a flag to specify if we are in a test phase (changes the classLoader)
* @param addResourcesToClassPath flag to add maven's resources to classLoader
- * @param addCompileClassPath flag to add maven's project compile classPath to classLoader
- * @param addProjectClassPath flag to add maven'es project dependecies to classLoader
+ * @param addCompileClassPath flag to add maven's project compile classPath to classLoader
+ * @param addProjectClassPath flag to add maven'es project dependecies to classLoader
* @return the new classLoader
- * @throws MalformedURLException
+ * @throws MalformedURLException if an url was not correct
*/
@SuppressWarnings({"unchecked"})
protected URLClassLoader initClassLoader(MavenProject project, File src, boolean addSourcesToClassPath, boolean testPhase, boolean addResourcesToClassPath, boolean addCompileClassPath, boolean addProjectClassPath) throws MalformedURLException {
- URLClassLoader loader = null;
+ URLClassLoader loader;
if (project != null) {
URLClassLoader result;
@@ -559,9 +627,7 @@
}
}
if (testPhase && addCompileClassPath) {
- if (project != null) {
- addDirectoryToUrlsList(new File(project.getBuild().getOutputDirectory()), lUrls, dones);
- }
+ addDirectoryToUrlsList(new File(project.getBuild().getOutputDirectory()), lUrls, dones);
}
if (src != null) {
addDirectoryToUrlsList(src, lUrls, dones);
@@ -599,14 +665,14 @@
/**
* Add the given {@code directory} in {@code urls} if not already included.
- *
+ * <p/>
* <b>Note:</b> We use a extra list to store file string representation, since
* we do NOT want any url resolution and the {@link URL#equals(java.lang.Object)} is
* doing some...
*
* @param directory the directory to insert in {@code urls}
- * @param urls list of urls
- * @param done list of string representation of urls
+ * @param urls list of urls
+ * @param done list of string representation of urls
* @throws MalformedURLException if pb while converting file to url
* @since 1.1.0
*/
@@ -617,12 +683,12 @@
/**
* Add the given {@code url} in {@code urls} if not already included.
- *
+ * <p/>
* <b>Note:</b> We use a extra list to store file string representation, since
* we do NOT want any url resolution and the {@link URL#equals(java.lang.Object)} is
* doing some..
*
- * @param url the url to insert in {@code urls}
+ * @param url the url to insert in {@code urls}
* @param urls list of urls
* @param done list of string representation of urls
* @since 1.1.0
Modified: trunk/src/main/java/org/nuiton/plugin/PluginHelper.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2009-11-26 13:56:56 UTC (rev 638)
+++ trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2009-12-28 09:16:26 UTC (rev 639)
@@ -39,6 +39,7 @@
import java.util.TreeSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;
@@ -71,7 +72,7 @@
* <p/>
* Note : <b>Aucune liste n'est creee, ni recopiee</b>
*
- * @param <O> le type des objets de la liste
+ * @param <O> le type des objets de la liste
* @param list la liste a convertir
* @param type le type des elements de la liste
* @return la liste typee
@@ -90,6 +91,7 @@
}
return (List<O>) list;
}
+
static final protected double[] timeFactors = {1000000, 1000, 60, 60, 24};
static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h", "d"};
static final protected double[] memoryFactors = {1024, 1024, 1024, 1024};
@@ -126,7 +128,7 @@
* Split the given {@code text} using the {@code separator} and trim
* each part of result.
*
- * @param txt text to split
+ * @param txt text to split
* @param separator the split separator
* @return the splited text with trimmed parts.
* @since 1.1.0
@@ -142,9 +144,9 @@
/**
* Prefix the lines of the given content with a given prefix.
*
- * @param prefix prefix to add on each line of text
+ * @param prefix prefix to add on each line of text
* @param prefixForEmpty prefix to add for empty lines
- * @param content the text to treate
+ * @param content the text to treate
* @return the text transformed
* @throws IOException if any reading problem
*/
@@ -183,7 +185,6 @@
* d'un dictionnaire donne.
*
* @param map le dictionner a parcourir
- *
* @return la liste des clefs dont la valeur est nulle ou vide
*/
static public SortedSet<String> getEmptyKeys(Map<?, ?> map) {
@@ -196,18 +197,110 @@
return result;
}
+ /**
+ * Add the directory as a resource of the given project.
+ *
+ * @param dir the directory to add
+ * @param project the project to update
+ * @param includes the includes of the resource
+ * @return {@code true} if the resources was added (not already existing)
+ * @since 1.1.1
+ */
+ public static boolean addResourceDir(File dir, MavenProject project, String... includes) {
+ List<?> resources = project.getResources();
+ boolean added = addResourceDir(dir, project, resources, includes);
+ return added;
+ }
+
+ /**
+ * Add thedirectory as a test resource of the given project.
+ *
+ * @param dir the directory to add
+ * @param project the project to update
+ * @param includes the includes of the resource
+ * @return {@code true} if the resources was added (not already existing)
+ * @since 1.1.1
+ */
+ public static boolean addTestResourceDir(File dir, MavenProject project, String... includes) {
+ List<?> resources = project.getTestResources();
+ boolean added = addResourceDir(dir, project, resources, includes);
+ return added;
+ }
+
+ /**
+ * Add the directory as a resource in the given resource list.
+ *
+ * @param dir the directory to add
+ * @param project the project involved
+ * @param resources the list of existing resources
+ * @param includes includes of the new resources
+ * @return {@code true} if the resource was added (not already existing)
+ * @since 1.1.1
+ */
+ public static boolean addResourceDir(File dir, MavenProject project, List<?> resources, String... includes) {
+ String newresourceDir = dir.getAbsolutePath();
+ boolean shouldAdd = true;
+ for (Object o : resources) {
+ Resource r = (Resource) o;
+ if (!r.getDirectory().equals(newresourceDir)) {
+ continue;
+ }
+
+ for (String i : includes) {
+ if (!r.getIncludes().contains(i)) {
+ r.addInclude(i);
+ }
+ }
+ shouldAdd = false;
+ break;
+ }
+ if (shouldAdd) {
+ Resource r = new Resource();
+ r.setDirectory(newresourceDir);
+ for (String i : includes) {
+ if (!r.getIncludes().contains(i)) {
+ r.addInclude(i);
+ }
+ }
+ project.addResource(r);
+ }
+ return shouldAdd;
+ }
+
+ /**
+ * @param newresourceDir the new resource directory to add
+ * @param project the maven project to modifiy
+ * @return {@code true} if resources was added
+ * @deprecated since 1.1.1, prefer use the {@link #addResourceDir(java.io.File, org.apache.maven.project.MavenProject, String...)}
+ */
+ @Deprecated
public static boolean addResourceDir(String newresourceDir, MavenProject project) {
List<?> resources = project.getResources();
boolean added = addResourceDir(newresourceDir, project, resources);
return added;
}
+ /**
+ * @param newresourceDir the new resource directory to add
+ * @param project the maven project to modifiy
+ * @return {@code true} if resources was added
+ * @deprecated since 1.1.1, prefer use the {@link #addTestResourceDir(java.io.File, org.apache.maven.project.MavenProject, String...)}
+ */
+ @Deprecated
public static boolean addTestResourceDir(String newresourceDir, MavenProject project) {
List<?> resources = project.getTestResources();
boolean added = addResourceDir(newresourceDir, project, resources);
return added;
}
+ /**
+ * @param newresourceDir the new resource directory to add
+ * @param project the maven project to modifiy
+ * @param resources the known resources for the maven project
+ * @return {@code true} if resources was added
+ * @deprecated since 1.1.1, prefer use the {@link #addResourceDir(java.io.File, org.apache.maven.project.MavenProject, java.util.List, String...)}
+ */
+ @Deprecated
public static boolean addResourceDir(String newresourceDir, MavenProject project, List<?> resources) {
boolean shouldAdd = true;
for (Object o : resources) {
@@ -231,6 +324,54 @@
}
/**
+ * Cretae the directory (and his parents) if necessary.
+ *
+ * @param dir the directory to create if not exisiting
+ * @return {@code true} if directory was created, {@code false} if was no need to create it
+ * @throws IOException if could not create directory
+ * @since 1.1.1
+ */
+ public static boolean createDirectoryIfNecessary(File dir) throws IOException {
+ if (!dir.exists()) {
+ boolean b = dir.mkdirs();
+ if (!b) {
+ throw new IOException("Could not create directory " + dir);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Create the given file.
+ *
+ * @param file the file to create
+ * @throws IOException if could not create the file
+ * @since 1.1.1
+ */
+ public static void createNewFile(File file) throws IOException {
+ createDirectoryIfNecessary(file.getParentFile());
+ boolean b = file.createNewFile();
+ if (!b) {
+ throw new IOException("could not create new file " + file);
+ }
+ }
+
+ /**
+ * Delete the given file.
+ *
+ * @param file the file to delete
+ * @throws IOException if could not delete the file
+ * @since 1.1.1
+ */
+ public static void deleteFile(File file) throws IOException {
+ boolean b = file.delete();
+ if (!b) {
+ throw new IOException("could not delete file " + file);
+ }
+ }
+
+ /**
* Permet de copier le fichier source vers le fichier cible.
*
* @param source le fichier source
@@ -238,7 +379,8 @@
* @throws java.io.IOException Erreur de copie
*/
public static void copy(File source, File target) throws IOException {
- target.getParentFile().mkdirs();
+ createDirectoryIfNecessary(target.getParentFile());
+// target.getParentFile().mkdirs();
FileUtils.copyFile(source, target);
// FileChannel sourceChannel = new FileInputStream(source).getChannel();
// FileChannel targetChannel = new FileOutputStream(target).getChannel();
@@ -300,9 +442,11 @@
* @throws IOException if IO pb
*/
static public void writeString(File file, String content, String encoding) throws IOException {
- file.getParentFile().mkdirs();
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding));
+ createDirectoryIfNecessary(file.getParentFile());
+// file.getParentFile().mkdirs();
+ BufferedWriter out = null;
try {
+ out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding));
IOUtil.copy(content, out);
// out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding));
// out.write(content);
1
0