Author: tchemit
Date: 2010-01-18 02:04:31 +0100 (Mon, 18 Jan 2010)
New Revision: 664
Removed:
trunk/src/main/java/org/nuiton/mail/
Modified:
trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java
trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java
trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java
trunk/src/main/java/org/nuiton/io/rest/RestClient.java
trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java
trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.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
trunk/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java
Log:
Evolution #231: Ajout des fichiers de sites dans le goal collect-files (parametre includeSiteAttached) + clean code
Modified: trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -21,6 +21,8 @@
package org.nuiton.helper.plugin;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.nuiton.plugin.AbstractPlugin;
@@ -61,6 +63,33 @@
*/
protected List attachedArtifacts;
/**
+ * The local repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ * @since 1.2.2
+ */
+ protected ArtifactRepository localRepository;
+ /**
+ * The remote repository.
+ *
+ * @parameter expression="${project.distributionManagementArtifactRepository}"
+ * @required
+ * @readonly
+ * @since 1.2.2
+ */
+ protected ArtifactRepository deploymentRepository;
+ /**
+ * Project artifact.
+ *
+ * @parameter expression="${project.artifact}"
+ * @required
+ * @readonly
+ * @since 1.2.2
+ */
+ protected Artifact artifact;
+ /**
* User extra files to collect.
* <p/>
* Multi values can be used, separated by comma.
@@ -115,6 +144,14 @@
*/
protected boolean includeAttached;
/**
+ * Un flag pour collecter aussi les fichiers des sites attaches au projet.
+ *
+ * @parameter expression="${helper.includeSiteAttached}" default-value="false"
+ * @since 1.2.2
+ */
+ protected boolean includeSiteAttached;
+
+ /**
* Un flag pour recopier les fichiers collectés.
*
* @parameter expression="${helper.copyFiles}" default-value="true"
@@ -162,13 +199,8 @@
}
files = getFiles();
-// if (files.isEmpty()) {
-//
-// getLog().warn("No file to collect.");
-// skip = true;
-// }
}
-
+
@Override
protected boolean checkSkip() {
if (skip) {
@@ -188,11 +220,6 @@
@Override
public void doAction() throws Exception {
-// if (skip) {
-// getLog().info("Skip flag in on, goal will not be executed");
-// return;
-// }
-
MavenProject rootProject = getExecutionRootProject();
File base = new File(rootProject.getBasedir(), outputDirectory);
@@ -288,14 +315,6 @@
public List<File> getFiles(File input) throws IOException {
List<File> result = new ArrayList<File>();
result.addAll(Arrays.asList(PluginHelper.getLinesAsFiles(input)));
-// BufferedReader stream = new BufferedReader(new InputStreamReader(new FileInputStream(input)));
-// while (stream.ready()) {
-// String line = stream.readLine().trim();
-// if (!line.isEmpty()) {
-// File f = new File(line);
-// result.add(f);
-// }
-// }
return result;
}
@@ -330,10 +349,8 @@
if ("pom".equals(project.getPackaging())) {
addFile(project.getFile(), "adding artifact file : ", result, includePattern, excludePattern);
} else {
- Artifact a = project.getArtifact();
- if (a != null) {
- addFile(a.getFile(), "adding artifact file : ", result, includePattern, excludePattern);
- }
+
+ addFile(artifact.getFile(), "adding artifact file : ", result, includePattern, excludePattern);
}
}
File file;
@@ -359,6 +376,9 @@
// attach project attached files
if (includeAttached && attachedArtifacts != null) {
+ if (isVerbose()) {
+ getLog().info("Will add build attached files.");
+ }
for (Object o : attachedArtifacts) {
@@ -367,6 +387,22 @@
}
}
+ if (includeSiteAttached) {
+ if (isVerbose()) {
+ getLog().info("Will add site attached files.");
+ }
+ for (ArtifactMetadata o : artifact.getMetadataList()) {
+ //TC-20100118 : we do not want to include maven-site-plugin as dependencies
+ //This is a big hack and we should sheck this name does not changes when bumping
+ // maven version (anyway, it is not risky since this class should never change ?)
+ if ("SiteDescriptorArtifactMetadata".equals(o.getClass().getSimpleName())) {
+ File destination = new File(localRepository.getBasedir(),
+ localRepository.pathOfLocalRepositoryMetadata(o, deploymentRepository));
+ addFile(destination, "adding site descriptor file : ", result, includePattern, excludePattern);
+ }
+ }
+ }
+
return result;
}
Modified: trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -24,7 +24,6 @@
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;
@@ -58,15 +57,6 @@
*/
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}"
@@ -182,7 +172,7 @@
* @parameter expression="${helper.skipSendEmail}" default-value="false"
* @since 1.0.3
*/
- private boolean skipSendEmail;
+ protected boolean skipSendEmail;
/**
* A flag to test plugin but send nothing to redmine.
*
@@ -196,7 +186,7 @@
* @parameter expression="${redmine.runOnce}" default-value="true"
* @since 1.0.3
*/
- private boolean runOnce;
+ protected boolean runOnce;
/**
* internal flag to know if plugin was already executed (for multi-module projects)
*/
@@ -230,11 +220,9 @@
///////////////////////////////////////////////////////////////////////////
@Override
protected void init() throws Exception {
-// protected boolean init() throws Exception {
if (isGoalSkip()) {
return;
-// return true;
}
runOnceDone = false;
@@ -242,19 +230,14 @@
// 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
@@ -263,9 +246,6 @@
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) {
@@ -280,9 +260,6 @@
}
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;
}
}
}
@@ -290,12 +267,8 @@
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
@@ -318,14 +291,6 @@
@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");
Modified: trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -165,7 +165,6 @@
@Override
public void init() throws Exception {
-// protected boolean init() throws Exception {
propertiesToTreate = new EnumMap<Property, String>(Property.class);
@@ -183,26 +182,17 @@
}
if (propertiesToTreate.isEmpty()) {
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)) {
throw new MojoExecutionException("No 'serverId' defined.");
-// getLog().error("No 'serverId' defined.");
-// return false;
}
server = settings.getServer(serverId.trim());
if (server == null) {
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;
}
@Override
Modified: trunk/src/main/java/org/nuiton/io/rest/RestClient.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestClient.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/io/rest/RestClient.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -124,7 +124,7 @@
*
* @param request request used for asking data
* @return the stream of the response
- * @throws RestException
+ * @throws RestException if any pb while asking data
*/
public InputStream askData(RestRequest request) throws RestException {
if (!isOpen()) {
@@ -144,7 +144,7 @@
*
* @param request the request used for sending data
* @return the stream of the response
- * @throws RestException
+ * @throws RestException if any pb while sending data
*/
public InputStream sendData(RestRequest request) throws RestException {
if (!isOpen()) {
@@ -165,7 +165,7 @@
* <b>Note:</b> this method will instanciate the {@link #session} and invoke
* the method {@link #open(org.nuiton.io.rest.RestSession)}.
*
- * @throws RestException
+ * @throws RestException if any pb while opening session
*/
public void open() throws RestException {
@@ -202,7 +202,7 @@
* <b>Note:</b> this method will erase the {@link #session} and invoke
* the method {@link #close(org.nuiton.io.rest.RestSession)}.
*
- * @throws RestException
+ * @throws RestException if any pb while closing session
*/
public void close() throws RestException {
if (!isOpen()) {
Modified: trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -96,10 +96,6 @@
protected abstract void initMappers() throws IntrospectionException;
-// protected AbstractXpp3Reader(Class<O> type) {
-// this(type, null, null);
-// }
-
protected AbstractXpp3Reader(Class<O> type, String rootTagName) {
this(type, null, rootTagName);
}
@@ -165,7 +161,6 @@
if (addDefaultEntities) {
Xpp3Helper.addDefaultEntities(parser);
-
}
parser.next();
@@ -373,9 +368,9 @@
checkNotEndOfXml(parser, parentRootTagName);
- int eventType = parser.getEventType();
+// int eventType = parser.getEventType();
- eventType = parser.next();
+ int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && rootTagName.equals(parser.getName())) {
// there is a child to read
Modified: trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -36,46 +36,52 @@
Object r = java.lang.Boolean.valueOf(t);
return r;
}
- }, Short {
+ },
+ Short {
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Short.valueOf(t);
return r;
}
- }, Integer {
+ },
+ Integer {
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Integer.valueOf(t);
return r;
}
- }, Long {
+ },
+ Long {
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Long.valueOf(t);
return r;
}
- }, Float {
+ },
+ Float {
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Float.valueOf(t);
return r;
}
- }, Double {
+ },
+ Double {
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Double.valueOf(t);
return r;
}
- }, Text {
+ },
+ Text {
@Override
public Object convert(String t) throws Exception {
return t;
}
- };
+ }
}
\ No newline at end of file
Modified: trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -58,7 +58,7 @@
}
@Override
- protected Object getDataFromXml(XmlPullParser parser) throws XmlPullParserException, Exception {
+ protected Object getDataFromXml(XmlPullParser parser) throws Exception {
String t = parser.nextText();
Object result = null;
if (t != null && !(t = t.trim()).isEmpty()) {
@@ -120,7 +120,7 @@
this.descriptor = descriptor;
}
- protected abstract Object getDataFromXml(XmlPullParser parser) throws XmlPullParserException, Exception;
+ protected abstract Object getDataFromXml(XmlPullParser parser) throws Exception;
public void setProperty(Object src, XmlPullParser parser, Set<String> parsed, boolean strict) throws XmlPullParserException, IOException {
if (onlyOne && parsed.contains(name)) {
Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -50,14 +50,10 @@
* <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.
*
* @throws Exception if any
*/
protected abstract void init() throws Exception;
-// protected abstract boolean init() throws Exception;
/**
* Do plugin action.
@@ -72,19 +68,6 @@
*/
protected abstract void doAction() throws Exception;
-// /**
-// * 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(String skipAfterInitMessage) {
-// this.skipAfterInitMessage = skipAfterInitMessage;
-// }
-
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
try {
@@ -101,7 +84,6 @@
try {
init();
-// canContinue = init();
} catch (Exception e) {
throw new MojoExecutionException("could not init goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e);
@@ -114,7 +96,6 @@
if (isVerbose() || getLog().isDebugEnabled()) {
getLog().info("Goal will not be executed.");
}
-// getLog().warn(skipAfterInitMessage);
return;
}
@@ -264,7 +245,6 @@
// must run
return false;
-
}
/**
@@ -292,14 +272,9 @@
*/
public void copyFile(File srcFile, File destFile)
throws IOException {
-// try {
getLog().info("Copying " + srcFile.getName() + " to " + destFile);
PluginHelper.copy(srcFile, destFile);
-
-// } catch (Exception e) {
-// throw new MojoExecutionException("Error copying from " + srcFile + " to " + destFile, e);
-// }
}
/**
@@ -397,7 +372,6 @@
// register files
files.put(f, toTreate.toArray(new String[toTreate.size()]));
-
}
}
@@ -620,7 +594,7 @@
PluginHelper.deleteFile(file);
}
-/**
+ /**
* Rename the given file to the destination one.
*
* @param file the file to rename
Modified: trunk/src/main/java/org/nuiton/plugin/Plugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/Plugin.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/plugin/Plugin.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -63,8 +63,6 @@
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 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/plugin/PluginHelper.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -386,15 +386,7 @@
*/
public static void copy(File source, File target) throws IOException {
createDirectoryIfNecessary(target.getParentFile());
-// target.getParentFile().mkdirs();
FileUtils.copyFile(source, target);
-// FileChannel sourceChannel = new FileInputStream(source).getChannel();
-// FileChannel targetChannel = new FileOutputStream(target).getChannel();
-// sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
-// // or
-// // targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
-// sourceChannel.close();
-// targetChannel.close();
}
/**
@@ -411,7 +403,6 @@
BufferedReader in = new BufferedReader(new InputStreamReader(inf, encoding));
try {
return IOUtil.toString(in);
-// return FileUtil.readAsString(r);
} finally {
in.close();
}
@@ -427,16 +418,6 @@
*/
static public String readAsString(java.io.Reader reader) throws IOException {
return IOUtil.toString(reader);
-// StringBuffer result = new StringBuffer();
-// char[] cbuf = new char[2000];
-// BufferedReader in = new BufferedReader(reader);
-// int nb = in.read(cbuf);
-// while (nb != -1) {
-// result.append(cbuf, 0, nb);
-// nb = in.read(cbuf);
-// }
-// in.close();
-// return result.toString();
}
/**
@@ -449,29 +430,17 @@
*/
static public void writeString(File file, String content, String encoding) throws IOException {
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);
} finally {
if (out != null) {
out.close();
}
}
}
-//
-// public static void write(File destFile, String content, String encoding) throws IOException {
-//
-// InputStream in = new ByteArrayInputStream(content.getBytes(encoding));
-// RawInputStreamFacade facade = new RawInputStreamFacade(in);
-//
-// FileUtils.copyStreamToFile(facade, destFile);
-// }
-
public static List<File> getIncludedFiles(File dir, String[] includes, String[] excludes) {
DirectoryScanner ds = new DirectoryScanner();
List<File> result = new ArrayList<File>();
@@ -564,13 +533,11 @@
}
public static void expandFile(File src, File dst, String[] includes, boolean overwrite) throws IOException {
-// System.out.println("expandFile src:" + src + " to " + dst);
ZipFile zipFile = new ZipFile(src);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry nextElement = entries.nextElement();
String name = nextElement.getName();
-// System.out.println("name : " + name);
for (String include : includes) {
if (DirectoryScanner.match(include, name)) {
System.out.println("matching name : " + name + " with pattern " + include);
Modified: trunk/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java 2010-01-17 20:14:40 UTC (rev 663)
+++ trunk/src/main/java/org/nuiton/plugin/VelocityTemplateGenerator.java 2010-01-18 01:04:31 UTC (rev 664)
@@ -40,7 +40,6 @@
import java.io.Writer;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.Iterator;
import java.util.Properties;
import org.apache.maven.project.MavenProject;
@@ -100,13 +99,11 @@
File f = new File(template.getFile());
templateName = f.getName();
- //props.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogSystem");
props.setProperty("file.resource.loader.path", f.getParent());
}
try {
engine = new VelocityEngine();
- //engine.setProperty("runtime.log.logsystem", new NullLogSystem());
engine.init(props);
} catch (Exception e) {
IllegalArgumentException iae = new IllegalArgumentException("Could not initialise Velocity");
@@ -175,8 +172,8 @@
protected void addPropertiesToContext(Properties properties, VelocityContext context) {
- for (Iterator<?> iter = properties.keySet().iterator(); iter.hasNext();) {
- String key = (String) iter.next();
+ for (Object o : properties.keySet()) {
+ String key = (String) o;
Object value = properties.get(key);
context.put(key, value);
}