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
- 427 discussions
20 Sep '09
Author: tchemit
Date: 2009-09-20 19:39:47 +0200 (Sun, 20 Sep 2009)
New Revision: 580
Modified:
trunk/src/site/apt/index.apt
trunk/src/site/site.xml
trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
Log:
update site documentation on new goals
fix javadoc
Modified: trunk/src/site/apt/index.apt
===================================================================
--- trunk/src/site/apt/index.apt 2009-09-20 17:11:28 UTC (rev 579)
+++ trunk/src/site/apt/index.apt 2009-09-20 17:39:47 UTC (rev 580)
@@ -33,8 +33,10 @@
* {{{available-licenses-mojo.html} helper:available-licenses}} display the known licenses of the plugin.
- * {{{runJava-mojo.html} helper:runJava}} run a java main class.
+ * {{{collect-files-mojo.html} helper:collect-files}} to collect some files over a project.
+ * {{{send-email-mojo.html} helper:send-email}} to sned a email.
+
Plugin toolkit overview
see javadoc.
Modified: trunk/src/site/site.xml
===================================================================
--- trunk/src/site/site.xml 2009-09-20 17:11:28 UTC (rev 579)
+++ trunk/src/site/site.xml 2009-09-20 17:39:47 UTC (rev 580)
@@ -44,6 +44,8 @@
<item name="add-third-party" href="add-third-party-mojo.html"/>
<item name="available-licenses" href="available-licenses-mojo.html"/>
<item name="check-project-files" href="check-project-files-mojo.html"/>
+ <item name="send-email" href="send-email-mojo.html"/>
+ <item name="collect-files" href="collect-files-mojo.html"/>
<item name="help" href="help-mojo.html"/>
<item name="runJava" href="runJava-mojo.html"/>
</item>
Modified: trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-20 17:11:28 UTC (rev 579)
+++ trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-20 17:39:47 UTC (rev 580)
@@ -41,8 +41,8 @@
* @param <P> le mojo a test
* @author chemit
*
- * @deprecated since 1.0.3, prefer use the {@link AbstractMojoTest} which
- * need no more annotation on each test method.
+ * @deprecated since 1.0.3, prefer use the {@link org.nuiton.plugin.AbstractMojoTest}
+ * which need no more annotation on each test method.
*/
@Deprecated
public abstract class BasePluginTestCase<P extends Plugin> {
1
0
20 Sep '09
Author: tchemit
Date: 2009-09-20 19:11:28 +0200 (Sun, 20 Sep 2009)
New Revision: 579
Modified:
trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java
trunk/src/main/java/org/nuiton/io/rest/RestClient.java
trunk/src/main/java/org/nuiton/io/rest/RestClientConfiguration.java
trunk/src/main/java/org/nuiton/io/rest/RestDataNotFoundException.java
trunk/src/main/java/org/nuiton/io/rest/RestException.java
trunk/src/main/java/org/nuiton/io/rest/RestRequest.java
trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java
trunk/src/main/java/org/nuiton/io/rest/RestSession.java
trunk/src/main/java/org/nuiton/mail/MailSender.java
trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java
Log:
add javadoc on new code + improve RestClient api
Modified: trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -5,8 +5,10 @@
import org.apache.commons.lang.builder.ToStringStyle;
/**
- *
+ * Default implementation of a {@link RestClientConfiguration}.
+ *
* @author chemit
+ * @since 1.0.3
*/
public class DefaultRestClientConfiguration implements RestClientConfiguration {
Modified: trunk/src/main/java/org/nuiton/io/rest/RestClient.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestClient.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/io/rest/RestClient.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -8,25 +8,72 @@
import org.apache.commons.logging.LogFactory;
/**
- *
+ * Abtract REST client.
+ *
* @author chemit
+ * @since 1.0.3
*/
public abstract class RestClient {
private static final Log log = LogFactory.getLog(RestClient.class);
- protected final RestClientConfiguration configuration;
+ /**
+ * rest client configuration
+ */
+ protected RestClientConfiguration configuration;
+ /**
+ * rest session
+ */
protected RestSession session;
- protected Map<String, RestRequestBuilder> requestBuilders;
+ /**
+ * registred requests
+ */
+ protected final Map<String, RestRequestBuilder> requestBuilders;
+ /**
+ * Add the default available requests for this client.
+ *
+ * <b>Note:</b> This method is invoked in the constructor of the client.
+ *
+ */
+ protected abstract void addDefaultRequests();
+
+ /**
+ * Open the client.
+ *
+ * <b>Note:</b> At the end of this method, if every thing is ok, then
+ * the method {@link #isOpen()} must returns {@code true}.
+ *
+ * @param session the rest session
+ * @throws IOException if any pb
+ */
protected abstract void open(RestSession session) throws IOException;
+ /**
+ * Close the client.
+ *
+ * <b>Note:</b> At the end of this method, if every thing is ok, then
+ * the method {@link #isOpen()} must returns {@code false}.
+ *
+ * @param session the rest session
+ * @throws IOException if any pb
+ */
protected abstract void close(RestSession session) throws IOException;
+ public RestClient() {
+ this.requestBuilders = new TreeMap<String, RestRequestBuilder>();
+ addDefaultRequests();
+ }
+
public RestClient(RestClientConfiguration configuration) {
+ this();
this.configuration = configuration;
- this.requestBuilders = new TreeMap<String, RestRequestBuilder>();
}
+ /**
+ * Add a request into the client.
+ *
+ * @param builder the new request to add
+ */
public void addRequestBuilder(RestRequestBuilder builder) {
String name = builder.getName();
if (requestBuilders.containsKey(name)) {
@@ -35,6 +82,13 @@
requestBuilders.put(name, builder);
}
+ /**
+ * Obtain a request given his id and the args given.
+ *
+ * @param id id of the request
+ * @param args args passed to build the request
+ * @return the new request
+ */
public RestRequest getRequest(String id, Object... args) {
RestRequestBuilder builder = requestBuilders.get(id);
if (builder == null) {
@@ -45,6 +99,13 @@
return r;
}
+ /**
+ * Ask some data from the server
+ *
+ * @param request request used for asking data
+ * @return the stream of the response
+ * @throws RestException
+ */
public InputStream askData(RestRequest request) throws RestException {
if (!isOpen()) {
throw new IllegalStateException("the client is not opened");
@@ -58,6 +119,13 @@
}
}
+ /**
+ * Send some datas to the server.
+ *
+ * @param request the request used for sending data
+ * @return the stream of the response
+ * @throws RestException
+ */
public InputStream sendData(RestRequest request) throws RestException {
if (!isOpen()) {
throw new IllegalStateException("the client is not opened");
@@ -71,6 +139,14 @@
}
}
+ /**
+ * Open the client.
+ *
+ * <b>Note:</b> this method will instanciate the {@link #session} and invoke
+ * the method {@link #open(org.nuiton.io.rest.RestSession)}.
+ *
+ * @throws RestException
+ */
public void open() throws RestException {
if (isOpen()) {
@@ -100,6 +176,14 @@
}
}
+ /**
+ * Close the client.
+ *
+ * <b>Note:</b> this method will erase the {@link #session} and invoke
+ * the method {@link #close(org.nuiton.io.rest.RestSession)}.
+ *
+ * @throws RestException
+ */
public void close() throws RestException {
if (!isOpen()) {
return;
@@ -114,15 +198,40 @@
}
}
+ /**
+ * Is the client opened ?
+ *
+ * @return {@code true} if the internal {@link #session} is opened,
+ * {@code false} otherwise.
+ */
public boolean isOpen() {
return session != null;
}
+ /**
+ *
+ * @return the internal rest {@link #session}
+ */
public RestSession getSession() {
return session;
}
+ /**
+ *
+ * @return the internal {@link #configuration}
+ */
public RestClientConfiguration getConfiguration() {
return configuration;
}
+
+ /**
+ * Use a new configuration.
+ *
+ * TODO : this method should check client is not opened!
+ *
+ * @param configuration the new configuration
+ */
+ public void setConfiguration(RestClientConfiguration configuration) {
+ this.configuration = configuration;
+ }
}
Modified: trunk/src/main/java/org/nuiton/io/rest/RestClientConfiguration.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestClientConfiguration.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/io/rest/RestClientConfiguration.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -3,8 +3,10 @@
import java.net.URL;
/**
- *
+ * Contract of a {@link RestClient}.
+ *
* @author chemit
+ * @since 1.0.3
*/
public interface RestClientConfiguration {
Modified: trunk/src/main/java/org/nuiton/io/rest/RestDataNotFoundException.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestDataNotFoundException.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/io/rest/RestDataNotFoundException.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -1,12 +1,11 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.nuiton.io.rest;
/**
- *
+ * Exception to be raised if a data does not exist ina 'askData' request, says
+ * when the rest server returns a {@code 4XX} status code.
+ *
* @author chemit
+ * @since 1.0.3
*/
public class RestDataNotFoundException extends RestException {
Modified: trunk/src/main/java/org/nuiton/io/rest/RestException.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestException.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/io/rest/RestException.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -4,7 +4,7 @@
* Base exception for any excpeiton in rest service.
*
* @author chemit
- * @since 1.0.0
+ * @since 1.0.3
*/
public class RestException extends Exception {
Modified: trunk/src/main/java/org/nuiton/io/rest/RestRequest.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestRequest.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/io/rest/RestRequest.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -4,8 +4,10 @@
import java.util.Map;
/**
- *
+ * The contract of a rest request.
+ *
* @author chemit
+ * @since 1.0.3
*/
public interface RestRequest {
Modified: trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -1,8 +1,10 @@
package org.nuiton.io.rest;
/**
- *
+ * The contract of a request builder.
+ *
* @author chemit
+ * @since 1.0.3
*/
public interface RestRequestBuilder {
Modified: trunk/src/main/java/org/nuiton/io/rest/RestSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestSession.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/io/rest/RestSession.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -26,8 +26,10 @@
import org.apache.commons.logging.LogFactory;
/**
- *
+ * A REST session.
+ *
* @author chemit
+ * @since 1.0.3
*/
public class RestSession {
Modified: trunk/src/main/java/org/nuiton/mail/MailSender.java
===================================================================
--- trunk/src/main/java/org/nuiton/mail/MailSender.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/mail/MailSender.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -1,72 +1,46 @@
package org.nuiton.mail;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
/**
- * 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.
+ * Defines the sender of a email.
*
- * @author Stephane Nicoll
+ * Note : this code was stolen in {@code maven-changes-plugin}, should thanks
+ * them...
+ *
+ * @author chemit
+ * @since 1.0.3
*/
-public class MailSender
-{
+public class MailSender {
private String name;
-
private String email;
-
- public MailSender()
- {
+ public MailSender() {
super();
}
-
- public MailSender( String name, String email )
- {
+ public MailSender(String name, String email) {
this.name = name;
this.email = email;
}
- public String getName()
- {
+ public String getName() {
return name;
}
- public void setName( String name )
- {
+ public void setName(String name) {
this.name = name;
}
- public String getEmail()
- {
+ public String getEmail() {
return email;
}
- public void setEmail( String email )
- {
+ public void setEmail(String email) {
this.email = email;
}
- public String toString()
- {
+ @Override
+ public String toString() {
return getName() + " (" + getEmail() + ")";
}
}
Modified: trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java
===================================================================
--- trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java 2009-09-19 18:29:10 UTC (rev 578)
+++ trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java 2009-09-20 17:11:28 UTC (rev 579)
@@ -1,24 +1,5 @@
package org.nuiton.mail;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
import java.security.Security;
import java.util.Date;
import java.util.Iterator;
@@ -41,69 +22,64 @@
/**
* 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";
+ 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." );
+ public void initialize() {
+ if (StringUtils.isEmpty(getSmtpHost())) {
+ System.out.println("Error in configuration: Missing smtpHost.");
}
- if ( getSmtpPort() == 0 )
- {
- setSmtpPort( DEFAULT_SMTP_PORT );
+ if (getSmtpPort() == 0) {
+ setSmtpPort(DEFAULT_SMTP_PORT);
}
props = new Properties();
- props.put( "mail.smtp.host", getSmtpHost() );
+ props.put("mail.smtp.host", getSmtpHost());
- props.put( "mail.smtp.port", String.valueOf( getSmtpPort() ) );
+ props.put("mail.smtp.port", String.valueOf(getSmtpPort()));
- if ( getUsername() != null )
- {
- props.put( "mail.smtp.auth", "true" );
+ if (getUsername() != null) {
+ props.put("mail.smtp.auth", "true");
}
- props.put( "mail.debug", String.valueOf( getLogger().isDebugEnabled() ) );
+ props.put("mail.debug", String.valueOf(getLogger().isDebugEnabled()));
- if ( isSslMode() )
- {
- Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider() );
+ 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.port", String.valueOf(getSmtpPort()));
- props.put( "mail.smtp.socketFactory.class", SSL_FACTORY );
+ props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
- props.put( "mail.smtp.socketFactory.fallback", "false" );
+ props.put("mail.smtp.socketFactory.fallback", "false");
}
- if ( userProperties != null )
- {
- for ( Iterator i = userProperties.keySet().iterator(); i.hasNext(); )
- {
+ if (userProperties != null) {
+ for (Iterator<?> i = userProperties.keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
- String value = userProperties.getProperty( key );
+ String value = userProperties.getProperty(key);
- props.put( key, value );
+ props.put(key, value);
}
}
}
@@ -111,90 +87,76 @@
// ----------------------------------------------------------------------
// MailSender Implementation
// ----------------------------------------------------------------------
+ @Override
+ public void send(MailMessage mail)
+ throws MailSenderException {
+ verify(mail);
- public void send( MailMessage mail )
- throws MailSenderException
- {
- verify( mail );
-
- try
- {
+ try {
Authenticator auth = null;
- if ( getUsername() != null )
- {
- auth = new Authenticator()
- {
- protected PasswordAuthentication getPasswordAuthentication()
- {
- return new PasswordAuthentication( getUsername(), getPassword() );
+ if (getUsername() != null) {
+ auth = new Authenticator() {
+
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(getUsername(), getPassword());
}
};
}
- Session session = Session.getDefaultInstance( props, auth );
+ Session session = Session.getDefaultInstance(props, auth);
- session.setDebug( getLogger().isDebugEnabled() );
+ session.setDebug(getLogger().isDebugEnabled());
- Message msg = new MimeMessage( session );
- InternetAddress addressFrom = new InternetAddress( mail.getFrom().getRfc2822Address() );
- msg.setFrom( addressFrom );
+ Message msg = new MimeMessage(session);
+ InternetAddress addressFrom = new InternetAddress(mail.getFrom().getRfc2822Address());
+ msg.setFrom(addressFrom);
- if ( mail.getToAddresses().size() > 0 )
- {
+ 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 );
+ 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 );
+ msg.setRecipients(Message.RecipientType.TO, addressTo);
}
- if ( mail.getCcAddresses().size() > 0 )
- {
+ 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 );
+ 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 );
+ msg.setRecipients(Message.RecipientType.CC, addressCc);
}
- if ( mail.getBccAddresses().size() > 0 )
- {
+ 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 );
+ 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 );
+ 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() );
+ 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() ) );
+ if (mail.getSendDate() != null) {
+ msg.setHeader("Date", DateFormatUtils.getDateHeader(mail.getSendDate()));
+ } else {
+ msg.setHeader("Date", DateFormatUtils.getDateHeader(new Date()));
}
- else
- {
- msg.setHeader( "Date", DateFormatUtils.getDateHeader( new Date() ) );
- }
// Send the message
- Transport.send( msg );
+ Transport.send(msg);
+ } catch (MessagingException e) {
+ throw new MailSenderException("Error while sending mail.", e);
}
- catch ( MessagingException e )
- {
- throw new MailSenderException( "Error while sending mail.", e );
- }
}
}
1
0
Author: tchemit
Date: 2009-09-19 20:29:10 +0200 (Sat, 19 Sep 2009)
New Revision: 578
Modified:
trunk/pom.xml
Log:
add plexus and mojo javadoc taglets
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-09-19 16:29:35 UTC (rev 577)
+++ trunk/pom.xml 2009-09-19 18:29:10 UTC (rev 578)
@@ -372,6 +372,169 @@
<quiet>true</quiet>
<!-- uniquement a partir de javadoc 2.5 -->
<!--skip>${maven.javadoc.skip}</skip-->
+ <taglets>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+
+ <taglet>
+ <tagletClass>org.codehaus.plexus.javadoc.PlexusComponentTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-javadoc</artifactId>
+ <version>1.0</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.codehaus.plexus.javadoc.PlexusConfigurationTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-javadoc</artifactId>
+ <version>1.0</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.codehaus.plexus.javadoc.PlexusRequirementTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-javadoc</artifactId>
+ <version>1.0</version>
+ </tagletArtifact>
+ </taglet>
+ </taglets>
</configuration>
<executions>
<execution>
@@ -429,6 +592,169 @@
<quiet>true</quiet>
<docencoding>${project.build.sourceEncoding}</docencoding>
<encoding>${project.build.sourceEncoding}</encoding>
+ <taglets>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>2.4.2</version>
+ </tagletArtifact>
+ </taglet>
+
+ <taglet>
+ <tagletClass>org.codehaus.plexus.javadoc.PlexusComponentTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-javadoc</artifactId>
+ <version>1.0</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.codehaus.plexus.javadoc.PlexusConfigurationTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-javadoc</artifactId>
+ <version>1.0</version>
+ </tagletArtifact>
+ </taglet>
+ <taglet>
+ <tagletClass>org.codehaus.plexus.javadoc.PlexusRequirementTaglet</tagletClass>
+ <tagletArtifact>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-javadoc</artifactId>
+ <version>1.0</version>
+ </tagletArtifact>
+ </taglet>
+ </taglets>
</configuration>
</plugin>
1
0
Author: tchemit
Date: 2009-09-19 18:29:35 +0200 (Sat, 19 Sep 2009)
New Revision: 577
Added:
trunk/src/main/java/org/nuiton/io/rest/
trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java
trunk/src/main/java/org/nuiton/io/rest/RestClient.java
trunk/src/main/java/org/nuiton/io/rest/RestClientConfiguration.java
trunk/src/main/java/org/nuiton/io/rest/RestDataNotFoundException.java
trunk/src/main/java/org/nuiton/io/rest/RestException.java
trunk/src/main/java/org/nuiton/io/rest/RestRequest.java
trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java
trunk/src/main/java/org/nuiton/io/rest/RestSession.java
trunk/src/main/java/org/nuiton/mail/
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/main/java/org/nuiton/mail/plugin/SendEmailMojo.java
trunk/src/main/java/org/nuiton/plugin/CheckProjectFilesPlugin.java
trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java
trunk/src/main/resources/META-INF/plexus/
trunk/src/main/resources/META-INF/plexus/components.xml
trunk/src/test/java/org/nuiton/mail/
trunk/src/test/java/org/nuiton/mail/plugin/
trunk/src/test/java/org/nuiton/mail/plugin/SendEmailMojoTest.java
trunk/src/test/resources/org/nuiton/mail/
trunk/src/test/resources/org/nuiton/mail/plugin/
trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/
trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/mailContentFile.txt
trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/sendEmail.xml
trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/skipSendEmail.xml
Removed:
trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
trunk/src/main/java/org/nuiton/util/PluginHelper.java
Log:
[EVOLUTION #42] : ajout d'un goal pour collecter des donn?\195?\169es
[EVOLUTION #43] : ajout d'un goal pour envoyer des mails
[EVOLUTION #44] : ajout d'un client REST
[AUtre...] - optimisation des d?\195?\169pendances, deplacement d'un goal
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-09-19 16:19:34 UTC (rev 576)
+++ trunk/pom.xml 2009-09-19 16:29:35 UTC (rev 577)
@@ -22,19 +22,86 @@
<version>1.1.1</version>
</dependency>
+ <!-- fix dependency pb in xpp3Reader (need at least version > 2.2) -->
<dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
<version>1.2</version>
</dependency>
+ <!-- plexus -->
+
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.5.15</version>
- <!--scope>provided</scope-->
</dependency>
+ <dependency>
+ <optional>true</optional>
+ <groupId>org.sonatype.plexus</groupId>
+ <artifactId>plexus-sec-dispatcher</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+
+ <dependency>
+ <optional>true</optional>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.0-alpha-9-stable-1</version>
+ </dependency>
+
+ <dependency>
+ <optional>true</optional>
+ <groupId>plexus</groupId>
+ <artifactId>plexus-mail-sender-api</artifactId>
+ <version>1.0-alpha-2</version>
+ <exclusions>
+ <exclusion>
+ <groupId>plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <optional>true</optional>
+ <groupId>plexus</groupId>
+ <artifactId>plexus-mail-sender-javamail</artifactId>
+ <version>1.0-alpha-2</version>
+ <exclusions>
+ <exclusion>
+ <groupId>plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <optional>true</optional>
+ <groupId>plexus</groupId>
+ <artifactId>plexus-mail-sender-simple</artifactId>
+ <version>1.0-alpha-2</version>
+ <exclusions>
+ <exclusion>
+ <groupId>plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
<!-- provided dependencies -->
<dependency>
@@ -67,6 +134,17 @@
<artifactId>velocity</artifactId>
<version>1.6.2</version>
</dependency>
+
+ <!-- forces use of javamail 1.4 since it's the only version available in the repo. We should remove this as soon
+ as the dependency in plexus-mail-sender-javamail will be updated
+ -->
+ <dependency>
+ <optional>true</optional>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>1.4</version>
+ </dependency>
+
<!-- tests dependencies -->
@@ -112,8 +190,7 @@
<developer>
<name>Eric Chatellier</name>
<id>echatellier</id>
- <!--<email>chatellier(a)codelutin.com</email>-->
- <email>http://mailhide.recaptcha.net/d?k=01qLvyYlchVJ90Gg2lfYg-5A==&c=8mzC6s-m…</email>
+ <email>chatellier(a)codelutin.com</email>
<organization>CodeLutin</organization>
<timezone>+2</timezone>
<roles>
@@ -124,8 +201,7 @@
<developer>
<name>Tony Chemit</name>
<id>tchemit</id>
- <!--<email>chemit(a)codelutin.com</email>-->
- <email>http://mailhide.recaptcha.net/d?k=01qLvyYlchVJ90Gg2lfYg-5A==&c=Dg32g6wa…</email>
+ <email>chemit(a)codelutin.com</email>
<organization>CodeLutin</organization>
<timezone>+2</timezone>
<roles>
@@ -524,6 +600,47 @@
</plugins>
</build>
</profile>
+
+ <!-- do not execute tests (generaly a bad idea...) -->
+ <profile>
+ <id>notests</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <properties>
+ <maven.test.skip>true</maven.test.skip>
+ </properties>
+ </profile>
+ <!-- do not build reports (speedup site generation in dev) -->
+ <profile>
+ <id>noreports</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <properties>
+ <maven.reports.generate>false</maven.reports.generate>
+ </properties>
+ </profile>
+ <!-- do not build dependencies detail in maven-project-info-report (speedup site generation in dev) -->
+ <profile>
+ <id>nodepdetails</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <properties>
+ <maven.reports.dependencyDetailsEnabled>false</maven.reports.dependencyDetailsEnabled>
+ </properties>
+ </profile>
+ <!-- do not build locations of dependencies in maven-project-info-report (speedup site generation in dev) -->
+ <profile>
+ <id>nodeplocations</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <properties>
+ <maven.reports.dependencyLocationsEnabled>false</maven.reports.dependencyLocationsEnabled>
+ </properties>
+ </profile>
</profiles>
</project>
Deleted: trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java 2009-09-19 16:19:34 UTC (rev 576)
+++ trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -1,103 +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;
-
-import java.io.File;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
-
-/**
- * Check that :
- *
- * 1) the changelog exists on standalone module or root module of a
- * multi-module project.
- * 2) any project module has a README.txt and LICENSE.txt file
- *
- * @goal check-project-files
- * @requiresProject true
- * @phase validate
- * @author chemit
- * @since 1.0.2
- */
-public class CheckProjectFilesPlugin extends AbstractMojo {
-
- /**
- * Dependance du projet.
- *
- * @parameter default-value="${project}"
- * @required
- * @since 1.0.2
- */
- protected MavenProject project;
- /**
- * Un flag pour activer le mode verbeux.
- *
- * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
- * @since 1.0.2
- */
- protected boolean verbose;
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- checkChangelogFile();
- checkReadmeFile();
- checkLicenseFile();
- }
-
- protected void checkChangelogFile() throws MojoExecutionException {
- if (project.isExecutionRoot()) {
- File f = new File(project.getBasedir(), "changelog.txt");
- if (!f.exists()) {
- throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
- } else {
- if (verbose) {
- getLog().info("changelog file dectected : " + f.getAbsolutePath());
- }
- }
- } else {
- getLog().info("changelog.txt is not required for module " + project.getName() + " (not a root module)");
- }
- }
-
- protected void checkReadmeFile() throws MojoExecutionException {
- File f = new File(project.getBasedir(), "README.txt");
- if (!f.exists()) {
- throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
- } else {
- if (verbose) {
- getLog().info("readme file dectected : " + f.getAbsolutePath());
- }
- }
- }
-
- protected void checkLicenseFile() throws MojoExecutionException {
- File f = new File(project.getBasedir(), "LICENSE.txt");
- if (!f.exists()) {
- throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
- } else {
- if (verbose) {
- getLog().info("license file dectected : " + f.getAbsolutePath());
- }
- }
- }
-}
Added: trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,79 @@
+package org.nuiton.io.rest;
+
+import java.net.URL;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
+/**
+ *
+ * @author chemit
+ */
+public class DefaultRestClientConfiguration implements RestClientConfiguration {
+
+ URL restUrl;
+ String restUsername;
+ String restPassword;
+ boolean verbose;
+ String encoding;
+
+ @Override
+ public String getEncoding() {
+ return encoding;
+ }
+
+ @Override
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ @Override
+ public String getRestPassword() {
+ return restPassword;
+ }
+
+ @Override
+ public void setRestPassword(String restPassword) {
+ this.restPassword = restPassword;
+ }
+
+ @Override
+ public URL getRestUrl() {
+ return restUrl;
+ }
+
+ @Override
+ public void setRestUrl(URL restUrl) {
+ this.restUrl = restUrl;
+ }
+
+ @Override
+ public String getRestUsername() {
+ return restUsername;
+ }
+
+ @Override
+ public void setRestUsername(String restUsername) {
+ this.restUsername = restUsername;
+ }
+
+ @Override
+ public boolean isVerbose() {
+ return verbose;
+ }
+
+ @Override
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ @Override
+ public String toString() {
+ ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
+ b.append("redmineUrl", restUrl);
+ b.append("redmineUsername", restUsername);
+ b.append("redminePassword", "***");
+ b.append("encoding", encoding);
+ b.append("verbose", verbose);
+ return b.toString();
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/rest/RestClient.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestClient.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/RestClient.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,128 @@
+package org.nuiton.io.rest;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author chemit
+ */
+public abstract class RestClient {
+
+ private static final Log log = LogFactory.getLog(RestClient.class);
+ protected final RestClientConfiguration configuration;
+ protected RestSession session;
+ protected Map<String, RestRequestBuilder> requestBuilders;
+
+ protected abstract void open(RestSession session) throws IOException;
+
+ protected abstract void close(RestSession session) throws IOException;
+
+ public RestClient(RestClientConfiguration configuration) {
+ this.configuration = configuration;
+ this.requestBuilders = new TreeMap<String, RestRequestBuilder>();
+ }
+
+ public void addRequestBuilder(RestRequestBuilder builder) {
+ String name = builder.getName();
+ if (requestBuilders.containsKey(name)) {
+ throw new IllegalArgumentException("a request builder with name " + name + " already exists.");
+ }
+ requestBuilders.put(name, builder);
+ }
+
+ public RestRequest getRequest(String id, Object... args) {
+ RestRequestBuilder builder = requestBuilders.get(id);
+ if (builder == null) {
+ // pas de builder de requete...
+ return null;
+ }
+ RestRequest r = builder.create(args);
+ return r;
+ }
+
+ public InputStream askData(RestRequest request) throws RestException {
+ if (!isOpen()) {
+ throw new IllegalStateException("the client is not opened");
+ }
+
+ try {
+ InputStream in = session.askData(request);
+ return in;
+ } catch (IOException e) {
+ throw new RestException("could not ask data to server to reason " + e.getMessage(), e);
+ }
+ }
+
+ public InputStream sendData(RestRequest request) throws RestException {
+ if (!isOpen()) {
+ throw new IllegalStateException("the client is not opened");
+ }
+
+ try {
+ InputStream in = session.sendData(request);
+ return in;
+ } catch (IOException e) {
+ throw new RestException("could not send data to server for reason " + e.getMessage(), e);
+ }
+ }
+
+ public void open() throws RestException {
+
+ if (isOpen()) {
+ return;
+ }
+
+ try {
+
+ session = new RestSession(configuration);
+
+ open(session);
+
+ session.setOpen(true);
+ } catch (Exception e) {
+ if (session != null) {
+ try {
+ try {
+ close(session);
+ } catch (IOException ex) {
+ // not important one...
+ }
+ } finally {
+ session = null;
+ }
+ }
+ throw new RestException("could not open rest client for reason " + e.getMessage(), e);
+ }
+ }
+
+ public void close() throws RestException {
+ if (!isOpen()) {
+ return;
+ }
+
+ try {
+ close(session);
+ } catch (Exception e) {
+ throw new RestException("could not close client for reason " + e.getMessage(), e);
+ } finally {
+ session = null;
+ }
+ }
+
+ public boolean isOpen() {
+ return session != null;
+ }
+
+ public RestSession getSession() {
+ return session;
+ }
+
+ public RestClientConfiguration getConfiguration() {
+ return configuration;
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/rest/RestClient.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/rest/RestClientConfiguration.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestClientConfiguration.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/RestClientConfiguration.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,30 @@
+package org.nuiton.io.rest;
+
+import java.net.URL;
+
+/**
+ *
+ * @author chemit
+ */
+public interface RestClientConfiguration {
+
+ URL getRestUrl();
+
+ String getEncoding();
+
+ String getRestUsername();
+
+ String getRestPassword();
+
+ boolean isVerbose();
+
+ void setRestUrl(URL restUrl);
+
+ void setRestPassword(String restPassword);
+
+ void setRestUsername(String restUsername);
+
+ void setEncoding(String encoding);
+
+ void setVerbose(boolean verbose);
+}
Property changes on: trunk/src/main/java/org/nuiton/io/rest/RestClientConfiguration.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/rest/RestDataNotFoundException.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestDataNotFoundException.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/RestDataNotFoundException.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,29 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.nuiton.io.rest;
+
+/**
+ *
+ * @author chemit
+ */
+public class RestDataNotFoundException extends RestException {
+
+ private static final long serialVersionUID = 1L;
+
+ public RestDataNotFoundException() {
+ }
+
+ public RestDataNotFoundException(String message) {
+ super(message);
+ }
+
+ public RestDataNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public RestDataNotFoundException(Throwable cause) {
+ super(cause);
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/rest/RestDataNotFoundException.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/rest/RestException.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestException.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/RestException.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,27 @@
+package org.nuiton.io.rest;
+
+/**
+ * Base exception for any excpeiton in rest service.
+ *
+ * @author chemit
+ * @since 1.0.0
+ */
+public class RestException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public RestException(Throwable cause) {
+ super(cause);
+ }
+
+ public RestException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public RestException(String message) {
+ super(message);
+ }
+
+ public RestException() {
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/rest/RestException.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/rest/RestRequest.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestRequest.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/RestRequest.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,17 @@
+package org.nuiton.io.rest;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ *
+ * @author chemit
+ */
+public interface RestRequest {
+
+ String[] getPath();
+
+ String[] getParameters();
+
+ Map<String, File> getAttachments();
+}
Property changes on: trunk/src/main/java/org/nuiton/io/rest/RestRequest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,12 @@
+package org.nuiton.io.rest;
+
+/**
+ *
+ * @author chemit
+ */
+public interface RestRequestBuilder {
+
+ String getName();
+
+ RestRequest create(Object... args);
+}
Property changes on: trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/rest/RestSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestSession.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/RestSession.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,224 @@
+package org.nuiton.io.rest;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.apache.commons.httpclient.Cookie;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpConnection;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.StatusLine;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.multipart.FilePart;
+import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author chemit
+ */
+public class RestSession {
+
+ protected HttpClient client;
+ protected static final Log log = LogFactory.getLog(RestSession.class);
+ protected boolean open;
+ protected boolean showRequest;
+ protected RestClientConfiguration configuration;
+
+ RestSession(RestClientConfiguration configuration) {
+ this.showRequest = configuration.isVerbose();
+ this.configuration = configuration;
+ this.client = new HttpClient();
+ HostConfiguration hostConfiguration = new HostConfiguration();
+ hostConfiguration.setHost(configuration.getRestUrl().getHost());
+ this.client.setHostConfiguration(hostConfiguration);
+ this.client.setState(new HttpState());
+ }
+
+ public InputStream askData(RestRequest request) throws RestException, IOException {
+
+ if (!open) {
+ throw new IllegalStateException("the session is not opened");
+ }
+ HttpMethod gm;
+
+ gm = doRequest(request);
+
+ StatusLine sl = gm.getStatusLine();
+ int statusCode = sl.getStatusCode();
+
+ if (log.isDebugEnabled()) {
+ log.debug("status code " + statusCode + " for " + gm.getPath());
+ }
+
+ if (statusCode == HttpStatus.SC_NOT_FOUND) {
+ throw new RestDataNotFoundException("could not retreave some datas : " + gm.getResponseBodyAsString());
+ }
+
+ if (statusCode != HttpStatus.SC_OK) {
+ log.error(gm.getResponseBodyAsString());
+ releaseConnection(getConnection());
+ throw new RestException("Got error code <" + statusCode + ":" + sl.getReasonPhrase() + "> on " + gm.getPath());
+ }
+ InputStream stream = gm.getResponseBodyAsStream();
+ return stream;
+ }
+
+ public InputStream sendData(RestRequest request) throws RestException, IOException {
+
+ if (!open) {
+ throw new IllegalStateException("the session is not opened");
+ }
+
+ HttpMethod gm = doRequest(request);
+
+ StatusLine sl = gm.getStatusLine();
+ int statusCode = sl.getStatusCode();
+
+ if (log.isDebugEnabled()) {
+ log.debug("status code " + statusCode + " for " + gm.getPath());
+ }
+
+ if (statusCode != HttpStatus.SC_OK) {
+ log.error(gm.getResponseBodyAsString());
+ releaseConnection(getConnection());
+ throw new RestException("Got error code <" + statusCode + ":" + sl.getReasonPhrase() + "> on " + gm.getPath());
+ }
+
+ InputStream stream = gm.getResponseBodyAsStream();
+ return stream;
+ }
+
+ public void setOpen(boolean open) {
+ this.open = open;
+ }
+
+ public void close() throws IOException {
+ client.getState().clearCookies();
+ releaseConnection(getConnection());
+ this.open = false;
+ }
+
+ protected void releaseConnection(HttpConnection connection) {
+ if (connection != null && connection.isOpen()) {
+ client.getHttpConnectionManager().releaseConnection(connection);
+ }
+ }
+
+ protected HttpConnection getConnection() {
+ return client.getHttpConnectionManager().getConnection(client.getHostConfiguration());
+ }
+
+ protected String getUri(String... paths) {
+ String uri = client.getHostConfiguration().getHostURL();
+ for (String path : paths) {
+ uri += '/' + path;
+ }
+ return uri;
+ }
+
+ public HttpMethod doRequest(RestRequest request) throws IOException {
+
+ String uri = getUri(request.getPath());
+ String[] parameters = request.getParameters();
+ Map<String, File> attachments = request.getAttachments();
+
+ if (showRequest) {
+ log.info("doRequest " + uri);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("doRequest with parameters : " + Arrays.toString(parameters));
+ }
+ PostMethod gm = new PostMethod(uri);
+ if (open) {
+ Cookie[] cookies = client.getState().getCookies();
+ for (Cookie c : cookies) {
+ if (log.isDebugEnabled()) {
+ log.debug("push cookie : " + c.getName() + "=" + c.getValue());
+ }
+ gm.addRequestHeader("Cookie", c.toExternalForm());
+ }
+ }
+
+ if (attachments == null) {
+
+ // not a multi-part request
+
+ if (parameters.length > 0) {
+
+ // add parameters
+
+ int nbParams = parameters.length / 2;
+ for (int i = 0; i < nbParams; i++) {
+ String key = parameters[2 * i];
+ String value = parameters[2 * i + 1];
+ if (value == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("skip null parameter " + key);
+ }
+ continue;
+ }
+ gm.addParameter(key, value);
+ }
+ }
+ } else {
+
+ // multi-part request
+
+ List<Part> paramParts = new ArrayList<Part>();
+
+ if (parameters.length > 0) {
+
+ // add parameters as part of multi-part
+
+ int nbParams = parameters.length / 2;
+ for (int i = 0; i < nbParams; i++) {
+ String key = parameters[2 * i];
+ String value = parameters[2 * i + 1];
+ if (value == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("skip null parameter " + key);
+ }
+ continue;
+ }
+ paramParts.add(new StringPart(key, value));
+ }
+ }
+
+ // add file parts
+ for (Entry<String, File> entry : attachments.entrySet()) {
+ String key = entry.getKey();
+ File file = entry.getValue();
+ paramParts.add(new FilePart(key, file.getName(), file));
+ }
+
+ Part[] parts = paramParts.toArray(new Part[paramParts.size()]);
+
+ MultipartRequestEntity entity = new MultipartRequestEntity(parts, gm.getParams());
+ gm.setRequestEntity(entity);
+// gm.addRequestHeader("content-type", "multipart/form-data");
+ gm.addRequestHeader("content-type", entity.getContentType());
+ gm.addRequestHeader("content-length", entity.getContentLength() + "");
+ if (showRequest) {
+ log.info("content-type : " + entity.getContentType() + ", content-length : " + entity.getContentLength());
+ }
+
+ }
+
+ client.executeMethod(gm);
+
+ return gm;
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/rest/RestSession.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/mail/MailSender.java
===================================================================
--- trunk/src/main/java/org/nuiton/mail/MailSender.java (rev 0)
+++ trunk/src/main/java/org/nuiton/mail/MailSender.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,72 @@
+package org.nuiton.mail;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * 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.
+ *
+ * @author Stephane Nicoll
+ */
+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;
+ }
+
+ public String toString()
+ {
+ return getName() + " (" + getEmail() + ")";
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/mail/MailSender.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java
===================================================================
--- trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java (rev 0)
+++ trunk/src/main/java/org/nuiton/mail/ProjectJavamailMailSender.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,200 @@
+package org.nuiton.mail;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+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.
+ */
+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
+ // ----------------------------------------------------------------------
+
+ public void send( MailMessage mail )
+ throws MailSenderException
+ {
+ verify( mail );
+
+ try
+ {
+ Authenticator auth = null;
+
+ if ( getUsername() != null )
+ {
+ auth = new Authenticator()
+ {
+ 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/mail/ProjectJavamailMailSender.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/mail/plugin/SendEmailMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/mail/plugin/SendEmailMojo.java (rev 0)
+++ trunk/src/main/java/org/nuiton/mail/plugin/SendEmailMojo.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,457 @@
+package org.nuiton.mail.plugin;
+
+import org.nuiton.mail.*;
+import org.nuiton.plugin.*;
+import org.nuiton.util.PluginHelper;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Developer;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Server;
+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.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
+
+/**
+ * Send a email.
+ *
+ * @goal send-email
+ * @requiresOnline true
+ * @requiresProject true
+ *
+ * @author tchemit
+ * @since 1.0.3
+ */
+public class SendEmailMojo extends AbstractPlugin {
+
+ /**
+ * @parameter expression="${session}"
+ * @required
+ * @readonly
+ */
+ protected MavenSession mavenSession;
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ * @since 1.0.0
+ */
+ protected MavenProject project;
+ /**
+ * Dependance du settings.
+ *
+ * @parameter default-value="${settings}"
+ * @required
+ * @readonly
+ * @since 1.0.0
+ */
+ protected Settings settings;
+ /**
+ * Un flag pour activer le mode verbeux.
+ *
+ * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
+ * @since 1.0.0
+ */
+ protected boolean verbose;
+ /**
+ * The Velocity template used to format the email announcement.
+ *
+ * @parameter expression="${helper.emailContentFile}"
+ * @required
+ * @since 1.0.0
+ */
+ private File emailContentFile;
+ /**
+ * The title of the email to send.
+ *
+ * @parameter expression="${helper.emailTitle}"
+ * @required
+ * @since 1.0.0
+ */
+ private String emailTitle;
+ /**
+ * Smtp Server.
+ *
+ * @parameter expression="${helper.smtpHost}"
+ * @required
+ */
+ private String smtpHost;
+ /**
+ * Port.
+ *
+ * @parameter default-value="25" expression="${helper.smtpPort}"
+ * @required
+ */
+ private int smtpPort;
+ /**
+ * The username used to send the email.
+ *
+ * @parameter expression="${helper.username}"
+ */
+ private String username;
+ /**
+ * The password used to send the email.
+ *
+ * @parameter expression="${helper.password}"
+ */
+ private String password;
+ /**
+ * Server id to use for authentication (must be defined in your setting
+ * and use the maven >= 2.1.0 password encryption mecanism).
+ * <p/>
+ *
+ * @parameter expression="${helper.serverId}"
+ * @since 1.0.0
+ */
+ protected String serverId;
+ /**
+ * If the email should be sent in SSL mode.
+ *
+ * @parameter default-value="false" expression="${helper.sslMode}"
+ */
+ private 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}"
+ */
+ private 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}"
+ */
+ private MailSender mailSender;
+ /**
+ * Recipient email address.
+ *
+ * @parameter
+ * @required
+ */
+ private List<String> toAddresses;
+ /**
+ * Possible senders.
+ *
+ * @parameter expression="${project.developers}"
+ * @required
+ * @readonly
+ */
+ private List<Developer> from;
+ /**
+ * Mail content type to use.
+ * @parameter default-value="text/plain"
+ * @required
+ * @since 2.1
+ */
+ private String mailContentType;
+ /**
+ * The encoding used to read and write files.
+ *
+ * @parameter expression="${helper.encoding}" default-value="${project.build.sourceEncoding}"
+ * @since 1.0.0
+ */
+ protected String encoding;
+ /**
+ * A flag to skip the goal.
+ *
+ * @parameter expression="${helper.skipSendEmail}" default-value="false"
+ * @since 1.0.0
+ */
+ private boolean skipSendEmail;
+ /**
+ * A flag to test plugin but send nothing to redmine.
+ *
+ * @parameter expression="${dryRun}" default-value="false"
+ * @since 1.0.0
+ */
+ 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.0
+ */
+ private boolean runOnce;
+ /**
+ * password decypher
+ *
+ * @component roleHint="maven-helper-plugin"
+ * @since 1.0.0
+ */
+ protected SecDispatcher sec;
+ 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;
+ }
+
+ @Override
+ protected boolean ensurePackaging() {
+ // accept all project's packaging
+ return false;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ /// AbstractPlugin
+ ///////////////////////////////////////////////////////////////////////////
+ protected boolean isGoalSkip() {
+ return skipSendEmail;
+ }
+
+ @Override
+ protected boolean init() throws Exception {
+
+ if (isGoalSkip()) {
+ return true;
+ }
+
+ runOnceDone = false;
+ if (runOnce) {
+ // check
+
+ if (!isExecutionRoot()) {
+ getLog().info("runOnce flag is on, will skip the goal");
+ runOnceDone = true;
+ return true;
+ }
+ }
+
+ if (!emailContentFile.exists()) {
+ // no file to publish...
+ getLog().warn("could not find the template " + emailContentFile);
+ getLog().warn("will skip send email...");
+ return false;
+ }
+
+ // check server (if used)
+
+ Server server = null;
+
+ if (serverId != null && !serverId.trim().isEmpty()) {
+
+ server = settings.getServer(serverId);
+
+ if (server == null) {
+ getLog().error("Could not find server with id '" + serverId + "', check your settings.xml file.");
+ return false;
+ }
+ }
+
+ // check authentication configuration is stable
+
+ boolean noUsername = username == null || username.trim().isEmpty();
+ boolean noPassword = password == null || password.trim().isEmpty();
+
+ if (server != null && !noUsername) {
+ getLog().error("Authentication configuration is wrong :\ncan not use both 'serverId' and 'username' parameters, check your plugin configuration.");
+ return false;
+ }
+
+ if (server != null && !noPassword) {
+ getLog().error("Authentication configuration is wrong :\ncan not use both 'serverId' and 'password' parameters, check your plugin configuration.");
+ return false;
+ }
+
+ if ((noUsername && !noPassword) || (!noUsername && noPassword)) {
+ getLog().error("Authentication configuration is wrong :\nconfiguration is not complete, please fill parameter 'serverId' or 'username' and 'password'.");
+ return false;
+ }
+
+ if (server != null) {
+ // obtain username and password from server
+
+ username = server.getUsername();
+ password = sec.decrypt(server.getPassword());
+ }
+
+ // check mail sender
+
+ if (mailSender == null) {
+
+ if (from == null || from.isEmpty()) {
+ 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) {
+ 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 (fromAddress == null || fromAddress.equals("")) {
+ getLog().warn("Invalid mail sender: name and email is mandatory (" + mailSender + ").");
+ getLog().warn("will skip send email...");
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ protected void doAction() throws Exception {
+ if (runOnce && runOnceDone) {
+ 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 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 == getExecutionRootProject();
+ }
+
+ protected MavenProject getExecutionRootProject() {
+ MavenProject root = project;
+ String executionRootDirectory = mavenSession.getExecutionRootDirectory();
+ while (root != null) {
+ File dir = root.getBasedir();
+ getLog().debug("Current Folder:" + dir);
+ boolean result = executionRootDirectory.equalsIgnoreCase(dir.toString());
+ if (result) {
+ break;
+ }
+ root = root.getParent();
+ }
+ if (verbose) {
+ getLog().info("root project " + root);
+ }
+ return root;
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/mail/plugin/SendEmailMojo.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-09-19 16:19:34 UTC (rev 576)
+++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -73,8 +73,15 @@
* @throws Exception if any
*/
protected abstract void doAction() throws Exception;
- protected final 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(String skipAfterInitMessage) {
this.skipAfterInitMessage = skipAfterInitMessage;
}
@@ -84,14 +91,14 @@
try {
if (ensurePackaging()) {
- getLog().info("skip goal for packaging " + getProject().getPackaging());
+ getLog().warn("The goal is skip due to packaging '" + getProject().getPackaging() + "'");
return;
}
boolean canContinue = init();
if (!canContinue) {
- getLog().info(skipAfterInitMessage);
+ getLog().warn(skipAfterInitMessage);
return;
}
Copied: trunk/src/main/java/org/nuiton/plugin/CheckProjectFilesPlugin.java (from rev 570, trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java)
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/CheckProjectFilesPlugin.java (rev 0)
+++ trunk/src/main/java/org/nuiton/plugin/CheckProjectFilesPlugin.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,103 @@
+/*
+ * *##%
+ * 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.plugin;
+
+import java.io.File;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Check that :
+ *
+ * 1) the changelog exists on standalone module or root module of a
+ * multi-module project.
+ * 2) any project module has a README.txt and LICENSE.txt file
+ *
+ * @goal check-project-files
+ * @requiresProject true
+ * @phase validate
+ * @author chemit
+ * @since 1.0.2
+ */
+public class CheckProjectFilesPlugin extends AbstractMojo {
+
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @since 1.0.2
+ */
+ protected MavenProject project;
+ /**
+ * Un flag pour activer le mode verbeux.
+ *
+ * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
+ * @since 1.0.2
+ */
+ protected boolean verbose;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ checkChangelogFile();
+ checkReadmeFile();
+ checkLicenseFile();
+ }
+
+ protected void checkChangelogFile() throws MojoExecutionException {
+ if (project.isExecutionRoot()) {
+ File f = new File(project.getBasedir(), "changelog.txt");
+ if (!f.exists()) {
+ throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
+ } else {
+ if (verbose) {
+ getLog().info("changelog file dectected : " + f.getAbsolutePath());
+ }
+ }
+ } else {
+ getLog().info("changelog.txt is not required for module " + project.getName() + " (not a root module)");
+ }
+ }
+
+ protected void checkReadmeFile() throws MojoExecutionException {
+ File f = new File(project.getBasedir(), "README.txt");
+ if (!f.exists()) {
+ throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
+ } else {
+ if (verbose) {
+ getLog().info("readme file dectected : " + f.getAbsolutePath());
+ }
+ }
+ }
+
+ protected void checkLicenseFile() throws MojoExecutionException {
+ File f = new File(project.getBasedir(), "LICENSE.txt");
+ if (!f.exists()) {
+ throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
+ } else {
+ if (verbose) {
+ getLog().info("license file dectected : " + f.getAbsolutePath());
+ }
+ }
+ }
+}
Added: trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java (rev 0)
+++ trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,325 @@
+package org.nuiton.plugin;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.regex.Pattern;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.execution.MavenSession;
+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.FileUtils;
+
+/**
+ * Collect files some files from a project and copy them into a directory.
+ *
+ * @goal collect-files
+ * @requiresProject true
+ *
+ * @author tchemit
+ * @since 1.0.3
+ */
+public class CollectFilesMojo extends AbstractMojo {
+
+ /**
+ * @parameter expression="${session}"
+ * @required
+ * @readonly
+ */
+ private MavenSession mavenSession;
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ * @since 1.0.3
+ */
+ protected MavenProject project;
+ /**
+ * The artifacts to publish from the project build.
+ *
+ * @parameter expression="${project.attachedArtifacts}"
+ * @required
+ * @readonly
+ * @since 1.0.0
+ */
+ protected List attachedArtifacts;
+ /**
+ * User extra files to collect.
+ *
+ * Multi values can be used, separated by comma.
+ *
+ * @parameter expression="${helper.extraFiles}"
+ * @since 1.0.0
+ */
+ protected String extraFiles;
+ /**
+ * File name pattern of selected files to publish.
+ *
+ * If no Set - no include filter
+ *
+ * @parameter expression="${helper.includes}" default-value=""
+ * @since 1.0.0
+ */
+ protected String includes;
+ /**
+ * File name pattern of selected files to publish.
+ *
+ * If no Set - no exclude filter
+ *
+ * @parameter expression="${helper.excludes}" default-value=""
+ * @since 1.0.0
+ */
+ protected String excludes;
+ /**
+ * Directory where to store collected files.
+ * <p/>
+ * <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.
+ *
+ * @parameter expression="${helper.outputDirectory}" default-value="target/collect"
+ * @since 1.0.0
+ */
+ protected String outputDirectory;
+ /**
+ * Properties file will all files collected indexed by their path.
+ * <p/>
+ * <b>Note :</b> If not Set, will not generate the description file.
+ *
+ * @parameter expression="${helper.descriptionFile}"
+ * @since 1.0.0
+ */
+ protected String descriptionFile;
+ /**
+ * Un flag pour collecter aussi les fichiers attaches au projet.
+ *
+ * @parameter expression="${helper.includeAttached}" default-value="true"
+ * @since 1.0.0
+ */
+ protected boolean includeAttached;
+ /**
+ * Un flag pour recopier les fichiers collectés.
+ *
+ * @parameter expression="${helper.copyFiles}" default-value="true"
+ * @since 1.0.0
+ */
+ protected boolean copyFiles;
+ /**
+ * Un flag pour activer le mode verbeux.
+ *
+ * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
+ * @since 1.0.0
+ */
+ protected boolean verbose;
+ /**
+ * A flag to skip the goal.
+ *
+ * @parameter expression="${helper.skip}" default-value="false"
+ * @since 1.0.0
+ */
+ protected boolean skip;
+ /**
+ * Un flag pour activer le mode verbeux.
+ *
+ * @parameter expression="${helper.dryRun}" default-value="false"
+ * @since 1.0.0
+ */
+ protected boolean dryRun;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ if (skip) {
+ getLog().info("Skip flag in on, goal will not be executed");
+ }
+ List<File> files = getFiles();
+ if (files.isEmpty()) {
+
+ getLog().warn("No files to collect.");
+ return;
+ }
+
+ MavenProject rootProject = getExecutionRootProject();
+
+ File base = new File(rootProject.getBasedir(), outputDirectory);
+
+ File output = new File(base, project.getGroupId() + "--" + project.getArtifactId());
+
+ if (rootProject == project || verbose) {
+ // just print on root
+ getLog().info("Ouput dir : " + output);
+ }
+
+ if (dryRun) {
+ getLog().info("\n dryRun flag is on, no file will be copied!\n");
+ } else {
+
+ if (!output.exists()) {
+ output.mkdirs();
+ }
+ }
+
+ File description = null;
+
+ Properties p = new Properties();
+ boolean withDescriptionFile = false;
+ if (descriptionFile != null && !descriptionFile.trim().isEmpty()) {
+
+ description = new File(rootProject.getBasedir(), descriptionFile);
+
+ withDescriptionFile = true;
+
+ if (description.exists()) {
+ // reload existing
+ try {
+ p.load(new FileInputStream(description));
+ getLog().info("Load " + description);
+ } catch (IOException ex) {
+ throw new MojoExecutionException("could not load file " + description, ex);
+ }
+ }
+ }
+
+ if (!withDescriptionFile && !copyFiles) {
+ throw new MojoExecutionException("must use at least one of the parameters 'copyFiles' or 'descriptionFile'");
+ }
+
+ String basedir = rootProject.getBasedir().getAbsolutePath();
+ int basedirLength = basedir.length();
+ for (File f : files) {
+ String absolutePath = f.getAbsolutePath();
+ String path = absolutePath.substring(basedirLength + 1);
+ File dst = new File(output, f.getName());
+ if (withDescriptionFile && copyFiles) {
+ p.put(path, dst.getAbsolutePath());
+ } else {
+ p.put(path, f.getAbsolutePath());
+ }
+ getLog().info("collected file " + path);
+ if (!dryRun && copyFiles) {
+ try {
+ // copy the collected file
+ FileUtils.copyFile(f, dst);
+ } catch (IOException ex) {
+ throw new MojoExecutionException("could not copy file " + f, ex);
+ }
+ }
+ }
+
+ if (description != null) {
+ try {
+ p.store(new FileOutputStream(description), "Generated by " + this.getClass());
+ getLog().info("Save " + description);
+ } catch (IOException ex) {
+ throw new MojoExecutionException("could not save file " + description, ex);
+ }
+ }
+ }
+
+ protected List<File> getFiles() {
+
+ Pattern includePattern = includes == null || includes.trim().isEmpty() ? null : Pattern.compile(includes.trim());
+ Pattern excludePattern = excludes == null || excludes.trim().isEmpty() ? null : Pattern.compile(excludes.trim());
+
+ List<File> result = new ArrayList<File>();
+
+ // attach the project mail file
+
+ if (includeAttached) {
+
+ 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);
+ }
+ }
+ }
+ File file;
+
+ // attach extra files
+
+ if (extraFiles != null && !extraFiles.trim().isEmpty()) {
+
+ for (String path : extraFiles.split(",")) {
+
+ file = new File(path);
+ addFile(file, "adding user file : ", result, includePattern, excludePattern);
+
+ }
+ }
+
+ // attach project attached files
+
+ if (includeAttached && attachedArtifacts != null) {
+
+ for (Object o : attachedArtifacts) {
+
+ file = ((Artifact) o).getFile();
+ addFile(file, "adding attached artifact file : ", result, includePattern, excludePattern);
+ }
+ }
+
+ return result;
+ }
+
+ protected MavenProject getExecutionRootProject() {
+ MavenProject root = project;
+ String executionRootDirectory = mavenSession.getExecutionRootDirectory();
+ while (root != null) {
+ File basedir = root.getBasedir();
+ getLog().debug("Current Folder:" + basedir);
+ boolean result = executionRootDirectory.equalsIgnoreCase(basedir.toString());
+ if (result) {
+ break;
+ }
+ root = root.getParent();
+ }
+ if (verbose) {
+ getLog().info("root project " + root);
+ }
+ return root;
+ }
+
+ protected void addFile(File f, String msg, List<File> files, Pattern includePattern, Pattern excludePattern) {
+ if (f == null) {
+ return;
+ }
+ if (!f.exists()) {
+ getLog().warn("skip unexisting file " + f);
+ return;
+ }
+ if (excludePattern != null) {
+ if (excludePattern.matcher(f.getName()).matches()) {
+ // skip this file
+ if (verbose) {
+ getLog().info("skip " + f + " : in excludes " + excludes);
+ }
+ return;
+ }
+ }
+ if (includePattern != null) {
+ if (!includePattern.matcher(f.getName()).matches()) {
+ // skip this file
+ if (verbose) {
+ getLog().info("skip " + f + " : not in includes " + includes);
+ }
+ return;
+ }
+ }
+ if (verbose) {
+ getLog().info(msg + f);
+ }
+ files.add(f);
+ }
+}
+
Property changes on: trunk/src/main/java/org/nuiton/plugin/CollectFilesMojo.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/src/main/java/org/nuiton/util/PluginHelper.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/PluginHelper.java 2009-09-19 16:19:34 UTC (rev 576)
+++ trunk/src/main/java/org/nuiton/util/PluginHelper.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -60,6 +60,16 @@
*/
public class PluginHelper {
+ public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
+
+ public static String removeSnapshotSuffix(String versionId) {
+ if (versionId.endsWith(SNAPSHOT_SUFFIX)) {
+ // remove snapshot suffix
+ versionId = versionId.substring(0, versionId.length() - SNAPSHOT_SUFFIX.length());
+ }
+ return versionId;
+ }
+
/**
* Permet de convertir une liste non typee, en une liste typee.
* <p/>
@@ -90,7 +100,13 @@
}
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};
+ static final protected String[] memoryUnites = {"o", "Ko", "Mo", "Go", "To"};
+ static public String convertMemory(long value) {
+ return convert(value, memoryFactors, memoryUnites);
+ }
+
static public String convertTime(long value) {
return convert(value, timeFactors, timeUnites);
}
Added: trunk/src/main/resources/META-INF/plexus/components.xml
===================================================================
--- trunk/src/main/resources/META-INF/plexus/components.xml (rev 0)
+++ trunk/src/main/resources/META-INF/plexus/components.xml 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<component-set>
+ <components>
+ <component>
+ <role>org.sonatype.plexus.components.sec.dispatcher.SecDispatcher</role>
+ <role-hint>maven-helper-plugin</role-hint>
+ <implementation>org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher</implementation>
+ <requirements>
+ <requirement>
+ <role>org.sonatype.plexus.components.cipher.PlexusCipher</role>
+ <field-name>_cipher</field-name>
+ </requirement>
+ <requirement>
+ <role>org.sonatype.plexus.components.sec.dispatcher.PasswordDecryptor</role>
+ <field-name>_decryptors</field-name>
+ </requirement>
+ </requirements>
+ <configuration>
+ <_configurationFile>~/.m2/settings-security.xml</_configurationFile>
+ </configuration>
+ </component>
+ <!--component>
+ <role>org.codehaus.plexus.velocity.VelocityComponent</role>
+ <role-hint>maven-changes-plugin</role-hint>
+ <implementation>org.codehaus.plexus.velocity.DefaultVelocityComponent</implementation>
+ <configuration>
+ <properties>
+ <property>
+ <name>resource.loader</name>
+ <value>file,class</value>
+ </property>
+ <property>
+ <name>class.resource.loader.class</name>
+ <value>org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</value>
+ </property>
+ <property>
+ <name>file.resource.loader.class</name>
+ <value>org.apache.maven.plugin.resource.loader.ProjectResourceLoader</value>
+ </property>
+ </properties>
+ </configuration>
+ </component-->
+ </components>
+</component-set>
\ No newline at end of file
Added: trunk/src/test/java/org/nuiton/mail/plugin/SendEmailMojoTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/mail/plugin/SendEmailMojoTest.java (rev 0)
+++ trunk/src/test/java/org/nuiton/mail/plugin/SendEmailMojoTest.java 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,61 @@
+package org.nuiton.mail.plugin;
+
+import org.nuiton.mail.MailSender;
+import java.io.File;
+import java.util.Arrays;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Test;
+import org.nuiton.plugin.AbstractMojoTest;
+
+/**
+ * @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"));
+
+ 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().doAction();
+ }
+}
Property changes on: trunk/src/test/java/org/nuiton/mail/plugin/SendEmailMojoTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/mailContentFile.txt
===================================================================
--- trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/mailContentFile.txt (rev 0)
+++ trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/mailContentFile.txt 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1 @@
+The content of the test email
\ No newline at end of file
Added: trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/sendEmail.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/sendEmail.xml (rev 0)
+++ trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/sendEmail.xml 2009-09-19 16:29:35 UTC (rev 577)
@@ -0,0 +1,42 @@
+<?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">
+
+ <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
Added: trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/skipSendEmail.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/skipSendEmail.xml (rev 0)
+++ trunk/src/test/resources/org/nuiton/mail/plugin/SendEmailMojoTest/skipSendEmail.xml 2009-09-19 16:29:35 UTC (rev 577)
@@ -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">
+
+
+ <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
Author: tchemit
Date: 2009-09-19 18:19:34 +0200 (Sat, 19 Sep 2009)
New Revision: 576
Modified:
trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java
Log:
- fix bug new parentRootTag = rootTag in arrays xml parsing
- throw error when reader not found
Modified: trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2009-09-15 16:24:34 UTC (rev 575)
+++ trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2009-09-19 16:19:34 UTC (rev 576)
@@ -360,6 +360,8 @@
int eventType = parser.getEventType();
+ eventType = parser.next();
+
if (eventType == XmlPullParser.START_TAG && rootTagName.equals(parser.getName())) {
// there is a child to read
addChild = true;
@@ -372,7 +374,6 @@
break;
}
- eventType = parser.next();
}
if (addChild) {
Modified: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java 2009-09-15 16:24:34 UTC (rev 575)
+++ trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java 2009-09-19 16:19:34 UTC (rev 576)
@@ -101,6 +101,9 @@
Xpp3Reader<O> modelReader = getReader(klass);
+ if (modelReader == null) {
+ throw new IllegalArgumentException("could not find xpp3Reader for type " + klass);
+ }
result = modelReader.readArray(sReader);
} finally {
@@ -481,7 +484,8 @@
protected static Map<Class<?>, Xpp3Reader<?>> getReaders() {
if (readers == null) {
readers = new HashMap<Class<?>, Xpp3Reader<?>>();
- for (Xpp3Reader<?> r : ServiceLoader.load(Xpp3Reader.class)) {
+ for (Xpp3Reader<?> r : ServiceLoader.load(Xpp3Reader.class,Xpp3Helper.class.getClassLoader())) {
+
readers.put(r.getType(), r);
}
}
1
0
Author: tchemit
Date: 2009-09-15 18:24:34 +0200 (Tue, 15 Sep 2009)
New Revision: 575
Modified:
trunk/pom.xml
Log:
bump maven api to 2.1.0
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-09-15 15:44:51 UTC (rev 574)
+++ trunk/pom.xml 2009-09-15 16:24:34 UTC (rev 575)
@@ -144,7 +144,7 @@
<listId>${project.artifactId}</listId>
- <maven.version>2.0.10</maven.version>
+ <maven.version>2.1.0</maven.version>
<maven.src.dir>${basedir}/src</maven.src.dir>
<maven.compile.source>1.6</maven.compile.source>
1
0
r574 - trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest
by tchemit@users.nuiton.org 15 Sep '09
by tchemit@users.nuiton.org 15 Sep '09
15 Sep '09
Author: tchemit
Date: 2009-09-15 17:44:51 +0200 (Tue, 15 Sep 2009)
New Revision: 574
Added:
trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/licenseTwo.txt
trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testTwo.xml
Log:
[FEATURE #50 & #51] update to junit 4.7, rethink AbstractPlugin api
Added: trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/licenseTwo.txt
===================================================================
--- trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/licenseTwo.txt (rev 0)
+++ trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/licenseTwo.txt 2009-09-15 15:44:51 UTC (rev 574)
@@ -0,0 +1 @@
+dummy license
\ No newline at end of file
Added: trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testTwo.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testTwo.xml (rev 0)
+++ trunk/src/test/resources/org/nuiton/license/plugin/LicensePluginTest/testTwo.xml 2009-09-15 15:44:51 UTC (rev 574)
@@ -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">
+
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-helper-plugin-testOne</artifactId>
+ <version>0</version>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton</groupId>
+ <artifactId>maven-helper-plugin</artifactId>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <licenseName>lgpl_v3</licenseName>
+ <licenseFile>licenseTwo.txt</licenseFile>
+ <outputDirectory>target/tests/license-plugin-test</outputDirectory>
+ <verbose>true</verbose>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>add-license</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
1
0
r573 - in trunk: . src/main/java/org/nuiton src/main/java/org/nuiton/license/plugin src/main/java/org/nuiton/plugin src/test/java/org/nuiton src/test/java/org/nuiton/license src/test/java/org/nuiton/license/plugin src/test/java/org/nuiton/plugin src/test/java/org/nuiton/util
by tchemit@users.nuiton.org 15 Sep '09
by tchemit@users.nuiton.org 15 Sep '09
15 Sep '09
Author: tchemit
Date: 2009-09-15 17:44:19 +0200 (Tue, 15 Sep 2009)
New Revision: 573
Added:
trunk/src/main/java/org/nuiton/plugin/
trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
trunk/src/main/java/org/nuiton/plugin/Plugin.java
trunk/src/test/java/org/nuiton/plugin/
trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java
trunk/src/test/java/org/nuiton/plugin/TestHelper.java
Removed:
trunk/src/main/java/org/nuiton/Plugin.java
trunk/src/main/java/org/nuiton/RunJavaPlugin.java
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/AbstractPlugin.java
trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java
trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java
trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java
trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java
trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java
trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java
trunk/src/test/java/org/nuiton/util/PluginConfig.java
Log:
[FEATURE #50 & #51] update to junit 4.7, rethink AbstractPlugin api
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/pom.xml 2009-09-15 15:44:19 UTC (rev 573)
@@ -22,12 +22,6 @@
<version>1.1.1</version>
</dependency>
- <!--dependency>
- <groupId>org.apache.maven.enforcer</groupId>
- <artifactId>enforcer-api</artifactId>
- <version>1.0-beta-1</version>
- </dependency-->
-
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
@@ -83,17 +77,10 @@
<scope>test</scope>
</dependency>
- <!--dependency>
- <groupId>org.apache.maven.shared</groupId>
- <artifactId>maven-verifier</artifactId>
- <version>1.0</version>
- <scope>test</scope>
- </dependency-->
-
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.6</version>
+ <version>4.7</version>
<scope>test</scope>
</dependency>
@@ -115,7 +102,6 @@
<licenses>
<license>
<name>Lesser General Public License (LGPL)</name>
- <!--<url>http://www.gnu.org/licenses/lgpl.txt</url>-->
<url>${project.basedir}/LICENSE.txt</url>
<distribution>local</distribution>
</license>
Modified: trunk/src/main/java/org/nuiton/AbstractPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/AbstractPlugin.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/main/java/org/nuiton/AbstractPlugin.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -41,6 +41,7 @@
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.io.RawInputStreamFacade;
+import org.nuiton.plugin.Plugin;
import org.nuiton.util.MirroredFileUpdater;
import org.nuiton.util.PluginHelper;
@@ -48,7 +49,9 @@
* Un MOJO de base pour les autres MOJO concrets avec les options communes.
*
* @author chemit
+ * @deprecated since 1.0.3, prefer use {@link org.nuiton.plugin.AbstractPlugin}
*/
+@Deprecated
public abstract class AbstractPlugin extends AbstractMojo implements Plugin {
protected abstract boolean ensurePackaging();
Deleted: trunk/src/main/java/org/nuiton/Plugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/Plugin.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/main/java/org/nuiton/Plugin.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -1,23 +0,0 @@
-package org.nuiton;
-
-import org.apache.maven.plugin.Mojo;
-import org.apache.maven.project.MavenProject;
-
-/**
- * A common contract to be implements by our mojo and reports.
- *
- * Just expose a {@link #isVerbose()} flag and the maven project {@link #getProject()}.
- *
- * @author chemit
- * @since 1.0.3
- */
-public interface Plugin extends Mojo {
-
- MavenProject getProject();
-
- void setProject(MavenProject project);
-
- boolean isVerbose();
-
- void setVerbose(boolean verbose);
-}
Deleted: trunk/src/main/java/org/nuiton/RunJavaPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/RunJavaPlugin.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/main/java/org/nuiton/RunJavaPlugin.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -1,190 +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;
-
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import org.apache.maven.project.MavenProject;
-
-/**
- * @goal runJava
- * @requiresDependencyResolution test
- * @requiresProject true
- * @execute phase="process-classes"
- * @since 1.0
- * @author chemit
- */
-public class RunJavaPlugin extends AbstractPlugin {
-
- /**
- * Dependance du projet.
- *
- * @parameter default-value="${project}"
- * @required
- * @since 1.0.0
- */
- protected MavenProject project;
- /**
- * The main class to execute.
- *
- * @parameter expression="${mainClass}" default-value="${maven.jar.main.class}"
- * @required
- * @since 1.0
- */
- protected String mainClass;
- /**
- * The class arguments.
- *
- * @parameter expression="${args}"
- * @since 1.0
- */
- protected String args;
- /**
- * Un flag pour activer le mode verbeux.
- *
- * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
- * @since 1.0.0
- */
- protected boolean verbose;
- protected Class<?> clazz;
- protected ClassLoader cl;
-
- public RunJavaPlugin() {
- super("");
- }
-
- @Override
- protected boolean ensurePackaging() {
- return project != null && ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()));
- }
-
- @Override
- protected boolean init() throws Exception {
-
- cl = initClassLoader(project, new File(project.getBuild().getOutputDirectory()), false, false, false, true, true);
-
- Thread.currentThread().setContextClassLoader(cl);
-
- clazz = Class.forName(mainClass, true, cl);
-
- if (args == null) {
- args = "";
- }
- return true;
- }
-
- @Override
- protected void doAction() throws Exception {
- ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
- Thread bootstrapThread = new Thread(threadGroup, new Runnable() {
-
- @Override
- public void run() {
- try {
- Method main = Class.forName(mainClass, true, cl).getMethod("main", String[].class);
- if (!main.isAccessible()) {
- getLog().debug("Setting accessibility to true in order to invoke main().");
- main.setAccessible(true);
- }
- main.invoke(main, new Object[]{args.split(" ")});
- } catch (NoSuchMethodException e) {
- // just pass it on
- Thread.currentThread().getThreadGroup().uncaughtException(Thread.currentThread(), new Exception("The specified mainClass doesn't contain a main method with appropriate signature.", e));
- } catch (Exception e) {
- // just pass it on
- Thread.currentThread().getThreadGroup().uncaughtException(Thread.currentThread(), e);
- } finally {
-
- }
- }
- }, mainClass + ".main()");
-
- bootstrapThread.setContextClassLoader(cl);
-
- bootstrapThread.start();
-
- joinNonDaemonThreads(threadGroup);
- }
-
- @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;
- }
-
- private void joinNonDaemonThreads(ThreadGroup threadGroup) {
- boolean foundNonDaemon;
- do {
- foundNonDaemon = false;
- Collection<Thread> threads = getActiveThreads(threadGroup);
- for (Iterator<Thread> iter = threads.iterator(); iter.hasNext();) {
- Thread thread = iter.next();
- if (thread.isDaemon()) {
- continue;
- }
- foundNonDaemon = true; //try again; maybe more threads were created while we were busy
- joinThread(thread, 0);
- }
- } while (foundNonDaemon);
- }
-
- private void joinThread(Thread thread, long timeoutMsecs) {
- try {
- getLog().debug("joining on thread " + thread);
- thread.join(timeoutMsecs);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt(); // good practice if don't throw
- getLog().warn("interrupted while joining against thread " + thread, e); // not expected!
- }
- if (thread.isAlive()) //generally abnormal
- {
- getLog().warn("thread " + thread + " was interrupted but is still alive after waiting at least " + timeoutMsecs + "msecs");
- }
- }
-
- private Collection<Thread> getActiveThreads(ThreadGroup threadGroup) {
- Thread[] threads = new Thread[threadGroup.activeCount()];
- int numThreads = threadGroup.enumerate(threads);
- Collection<Thread> result = new ArrayList<Thread>(numThreads);
- for (int i = 0; i < threads.length && threads[i] != null; i++) {
- result.add(threads[i]);
- }
- return result; //note: result should be modifiable
- }
-
-}
Modified: trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/main/java/org/nuiton/license/plugin/LicensePlugin.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -35,7 +35,7 @@
* @requiresProject true
* @requiresDependencyResolution compile
*/
-public class LicensePlugin extends org.nuiton.AbstractPlugin {
+public class LicensePlugin extends org.nuiton.plugin.AbstractPlugin {
/**
* Dependance du projet.
Modified: trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/main/java/org/nuiton/license/plugin/ThirdPartyPlugin.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -41,7 +41,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import org.codehaus.plexus.util.IOUtil;
-import org.nuiton.AbstractPlugin;
+import org.nuiton.plugin.AbstractPlugin;
/**
* Le goal pour copier le fichier THIRD-PARTY.txt (contenant les licenses de toutes les dependances du projet)
Copied: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java (from rev 571, trunk/src/main/java/org/nuiton/AbstractPlugin.java)
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java (rev 0)
+++ trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -0,0 +1,438 @@
+/*
+ * *##%
+ * 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.plugin;
+
+import java.io.ByteArrayInputStream;
+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 java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+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.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.io.RawInputStreamFacade;
+import org.nuiton.util.MirroredFileUpdater;
+import org.nuiton.util.PluginHelper;
+
+/**
+ * Un MOJO de base pour les autres MOJO concrets avec les options communes.
+ *
+ * @author chemit
+ */
+public abstract class AbstractPlugin extends AbstractMojo implements Plugin {
+
+ protected abstract boolean ensurePackaging();
+
+ /**
+ * la methode qui est lancee au debut de la methode {@link #execute()} pour preparer l'init du goal.
+ *
+ * @return <code>true</code> if there is something to generate, <code>false</code> otherwise.
+ * @throws Exception if any
+ */
+ protected abstract boolean init() throws Exception;
+
+ /**
+ * Do plugin action.
+ * <p/>
+ * The method {@link #execute()} invoke this method only and only if :
+ * <ul>
+ * <li>{@link #ensurePackaging()} returns <code>false</code> (filtrer project type, for example).</li>
+ * <li>method {@link #init()} returns <code>true</code>.</li>
+ * </ul>
+ *
+ * @throws Exception if any
+ */
+ protected abstract void doAction() throws Exception;
+ protected final String skipAfterInitMessage;
+
+ protected AbstractPlugin(String skipAfterInitMessage) {
+ this.skipAfterInitMessage = skipAfterInitMessage;
+ }
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ try {
+
+ if (ensurePackaging()) {
+ getLog().info("skip goal for packaging " + getProject().getPackaging());
+ return;
+ }
+
+ boolean canContinue = init();
+
+ if (!canContinue) {
+ getLog().info(skipAfterInitMessage);
+ return;
+ }
+
+ doAction();
+
+ } catch (Exception e) {
+ throw new MojoExecutionException("could not init goal " + getClass().getSimpleName() + " for reason : " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Does the actual copy of the file and logging.
+ *
+ * @param srcFile represents the file to copy.
+ * @param destFile file name of destination file.
+ *
+ * @throws MojoExecutionException with a message if an
+ * error occurs.
+ */
+ protected void copyFile(File srcFile, File destFile)
+ throws MojoExecutionException {
+ try {
+ getLog().info("Copying " + srcFile.getName() + " to " + destFile);
+
+ FileUtils.copyFile(srcFile, destFile);
+
+ } catch (Exception e) {
+ throw new MojoExecutionException("Error copying from " + srcFile + " to " + destFile, e);
+ }
+ }
+
+ /**
+ * Does the actual copy of the content to a fileand logging.
+ *
+ * @param content represents the content to writeFile into file.
+ * @param destFile file name of destination file.
+ * @param encoding encoding to use to writeFile file
+ * @throws MojoExecutionException with a message if an
+ * error occurs.
+ */
+ protected void copyFile(String content, File destFile, String encoding)
+ throws MojoExecutionException {
+ try {
+ getLog().info("Copying content to " + destFile);
+
+ InputStream in = new ByteArrayInputStream(content.getBytes(encoding));
+ RawInputStreamFacade facade = new RawInputStreamFacade(in);
+
+ FileUtils.copyStreamToFile(facade, destFile);
+
+ } catch (Exception e) {
+ throw new MojoExecutionException("Error copying content to " + destFile, e);
+ }
+ }
+
+ public void writeFile(File destFile, String content, String encoding) throws IOException {
+ PluginHelper.write(destFile, content, encoding);
+ }
+
+ /**
+ * Test if a file exists and is newer than the pom file.
+ *
+ * @param f the file to test
+ * @return <code>true</code> if file exists and is newer than the pom file,
+ * <code>false</code> otherwise.
+ */
+ protected boolean isFileNewerThanPomFile(File f) {
+ File pomFile = getProject().getFile();
+ return f.exists() && f.lastModified() > pomFile.lastModified();
+ }
+
+ protected void getFilesToTreateForRoots(String[] includes, String[] excludes, List<String> roots, Map<File, String[]> files, MirroredFileUpdater updater) {
+
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setIncludes(includes);
+ if (excludes != null) {
+ ds.setExcludes(excludes);
+
+ }
+ for (String src : roots) {
+
+ File f = new File(src);
+ if (!f.exists()) {
+ // do nothing on a non-existent
+ continue;
+ }
+
+ if (isVerbose()) {
+ getLog().info("discovering java source files in root " + src);
+ }
+
+ ds.setBasedir(f);
+ // scan
+ ds.scan();
+
+ // get files
+ String[] tmp = ds.getIncludedFiles();
+
+ if (tmp.length < 1) {
+ // no files found
+ continue;
+ }
+
+ List<String> toTreate = new ArrayList<String>();
+
+ if (updater != null) {
+ updater.setSourceDirectory(f);
+ }
+
+
+ for (String filePath : tmp) {
+ File srcFile = new File(f, filePath);
+ // check file is up-to-date
+ if (updater == null || !updater.isFileUpToDate(srcFile)) {
+ toTreate.add(filePath);
+ }
+ }
+
+
+ if (toTreate.isEmpty()) {
+ // no file or all are up-to-date
+ continue;
+ }
+
+ // register files
+ files.put(f, toTreate.toArray(new String[toTreate.size()]));
+
+ }
+ }
+
+ protected Map<String, String> getFilesToTreate(String[] includes, String[] excludes, File srcDir, MirroredFileUpdater updater) {
+
+ Map<String, String> result = new java.util.TreeMap<String, String>();
+
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setIncludes(includes);
+ if (excludes != null) {
+ ds.setExcludes(excludes);
+
+ }
+
+ if (!srcDir.exists()) {
+ // do nothing on a non-existent
+ return result;
+ }
+
+ if (isVerbose()) {
+ getLog().info("discovering files for " + srcDir);
+ }
+
+ ds.setBasedir(srcDir);
+ // scan
+ ds.scan();
+
+ // get files
+ String[] tmp = ds.getIncludedFiles();
+
+ if (tmp.length < 1) {
+ // no files found
+ return result;
+ }
+
+ List<String> toTreate = new ArrayList<String>();
+
+ if (updater != null) {
+ updater.setSourceDirectory(srcDir);
+ }
+
+ for (String filePath : tmp) {
+ File srcFile = new File(srcDir, filePath);
+ File mirrorFile = updater.getMirrorFile(srcFile);
+ // check file is up-to-date
+ if (updater == null || !updater.isFileUpToDate(srcFile)) {
+ result.put(filePath, mirrorFile.getAbsolutePath());
+ toTreate.add(filePath);
+ }
+ }
+
+
+ if (toTreate.isEmpty()) {
+ // no file or all are up-to-date
+ return result;
+ }
+
+ // register files
+ return result;
+ }
+
+ protected void addCompileSourceRoots(File srcDir) {
+ if (!getProject().getCompileSourceRoots().contains(srcDir.getPath())) {
+ if (isVerbose()) {
+ getLog().info("adding source roots : " + srcDir.getPath());
+ }
+ getProject().addCompileSourceRoot(srcDir.getPath());
+ }
+ }
+
+ protected void removeCompileSourceRoots(File srcDir) {
+ if (getProject().getCompileSourceRoots().contains(srcDir.getPath())) {
+ if (isVerbose()) {
+ getLog().info("removing source roots : " + srcDir.getPath());
+ }
+ getProject().getCompileSourceRoots().remove(srcDir.getPath());
+ }
+ }
+
+ protected void addTestCompileSourceRoots(File srcDir) {
+ if (!getProject().getTestCompileSourceRoots().contains(srcDir.getPath())) {
+ if (isVerbose()) {
+ getLog().info("adding test source roots : " + srcDir.getPath());
+ }
+ getProject().addTestCompileSourceRoot(srcDir.getPath());
+ }
+ }
+
+ protected void removeTestCompileSourceRoots(File srcDir) {
+ if (getProject().getTestCompileSourceRoots().contains(srcDir.getPath())) {
+ if (isVerbose()) {
+ getLog().info("removing test source roots : " + srcDir.getPath());
+ }
+ getProject().getTestCompileSourceRoots().remove(srcDir.getPath());
+ }
+ }
+
+ protected void addResourceDir(String dir) {
+ boolean added = PluginHelper.addResourceDir(dir, getProject());
+ if (added) {
+ getLog().info("add resource " + dir);
+ }
+ }
+
+ protected void addTestResourceDir(String dir) {
+ boolean added = PluginHelper.addTestResourceDir(dir, getProject());
+ if (added) {
+ getLog().info("add test resource " + dir);
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected URLClassLoader initClassLoader(MavenProject project, File src, boolean addSourcesToClassPath, boolean testPhase, boolean addResourcesToClassPath, boolean addCompileClassPath, boolean addProjectClassPath) throws MalformedURLException {
+ URLClassLoader loader = null;
+ if (project != null) {
+
+ URLClassLoader result;
+ try {
+
+ List<URL> lUrls = new ArrayList<URL>();
+ List<String> sources = project.getCompileSourceRoots();
+
+ if (addSourcesToClassPath) {
+ for (String source : sources) {
+ lUrls.add(new File(source).toURI().toURL());
+ }
+ if (testPhase) {
+ for (Object source : project.getTestCompileSourceRoots()) {
+ lUrls.add(new File(source.toString()).toURI().toURL());
+ }
+ }
+ }
+ if (addResourcesToClassPath) {
+ for (Object source : project.getResources()) {
+ Resource r = (Resource) source;
+ lUrls.add(new File(r.getDirectory()).toURI().toURL());
+ }
+ }
+ if (testPhase && addCompileClassPath) {
+ if (project != null) {
+ lUrls.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL());
+ }
+ }
+ if (src != null) {
+ lUrls.add(src.toURI().toURL());
+ }
+ if (addProjectClassPath) {
+ getLog().info("use project compile scope class-path");
+ // add also all dependencies of the project in compile scope
+ Set<?> artifacts = project.getArtifacts();
+ for (Object o : artifacts) {
+ Artifact a = (Artifact) o;
+ lUrls.add(a.getFile().toURI().toURL());
+ }
+ }
+
+ result = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader());
+
+ } catch (IOException e) {
+ throw new RuntimeException("Can't create ClassLoader for reason " + e.getMessage(), e);
+ }
+ loader = result;
+ } else {
+ List<URL> lUrls = new ArrayList<URL>();
+ if (addSourcesToClassPath) {
+ lUrls.add(src.toURI().toURL());
+ }
+ loader = new URLClassLoader(lUrls.toArray(new URL[lUrls.size()]), getClass().getClassLoader());
+ }
+ if (isVerbose()) {
+ for (URL entry : loader.getURLs()) {
+ getLog().info("classpath : " + entry);
+ }
+ }
+ return loader;
+ }
+
+ /**
+ *
+ * @param f le fichier de template
+ * @return l'url du fichier demande
+ * @throws IOException pour toute erreur de recherche
+ */
+ protected URL getTemplate(File f) throws IOException {
+ URL r = null;
+ if (f.exists()) {
+ r = f.toURI().toURL();
+ } else {
+ r = getClass().getResource(f.toString());
+ }
+ return r;
+ }
+
+ /**
+ * Vérifie que le fichier donné existe bien (sur le filesystem ou
+ * dans le class-path).
+ *
+ * @param f le fichier que l'on veut vérifié
+ * @throws IOException pour tout erreur de recherche
+ */
+ protected void checkResource(File f) throws IOException {
+ if (!f.exists()) {
+ // test in classPath
+ InputStream r = null;
+ try {
+ r = getClass().getResourceAsStream(f.toString());
+ if (r == null) {
+ throw new IOException("could not find ressource " + f);
+ }
+ } finally {
+ if (r != null) {
+ r.close();
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/plugin/AbstractPlugin.java
___________________________________________________________________
Added: svn:mergeinfo
+
Copied: trunk/src/main/java/org/nuiton/plugin/Plugin.java (from rev 571, trunk/src/main/java/org/nuiton/Plugin.java)
===================================================================
--- trunk/src/main/java/org/nuiton/plugin/Plugin.java (rev 0)
+++ trunk/src/main/java/org/nuiton/plugin/Plugin.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -0,0 +1,23 @@
+package org.nuiton.plugin;
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * A common contract to be implements by our mojo and reports.
+ *
+ * Just expose a {@link #isVerbose()} flag and the maven project {@link #getProject()}.
+ *
+ * @author chemit
+ * @since 1.0.3
+ */
+public interface Plugin extends Mojo {
+
+ MavenProject getProject();
+
+ void setProject(MavenProject project);
+
+ boolean isVerbose();
+
+ void setVerbose(boolean verbose);
+}
Property changes on: trunk/src/main/java/org/nuiton/plugin/Plugin.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Modified: trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java
===================================================================
--- trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/test/java/org/nuiton/license/BaseLicenseTestCase.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -23,22 +23,21 @@
import org.junit.Assert;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import org.codehaus.plexus.util.IOUtil;
+import org.nuiton.plugin.TestHelper;
import org.nuiton.util.PluginHelper;
/** @author chemit */
public abstract class BaseLicenseTestCase extends Assert {
protected static final String encoding = "utf-8";
+ protected File baseDir;
protected File getBaseDir() {
- String path = System.getenv("basedir");
- if (path == null) {
- path = new File("").getAbsolutePath();
+ if (baseDir == null) {
+ baseDir = TestHelper.getBasedir();
}
- return new File(path);
+ return baseDir;
}
protected void assertLicenseFound(String name, License license) throws IOException {
@@ -51,7 +50,7 @@
protected File createLicenseRepository(boolean createLicene) throws IOException {
long timestamp = System.currentTimeMillis();
- File repo = new File(getBaseDir(), "target" + File.separator + "licenses_" + timestamp);
+ File repo = TestHelper.getFile(getBaseDir(), "target", "licenses_" + timestamp);
if (createLicene) {
@@ -68,20 +67,16 @@
String content = "";
if (defFile.exists()) {
- content = IOUtil.toString(new FileInputStream(defFile), encoding) + "\n";
-// content = FileUtil.readAsString(defFile, encoding) + "\n";
+ content = PluginHelper.readAsString(defFile, encoding) + "\n";
}
-
PluginHelper.write(defFile, content + licenseName + "=My dummy license\n", encoding);
-// FileUtil.writeString(defFile, content + licenseName + "=My dummy license\n", encoding);
+
// create dummy licenses
File file = new File(repo, licenseName);
file.mkdirs();
PluginHelper.write(new File(file, "license.txt"), "license:" + licenseName, encoding);
PluginHelper.write(new File(file, "header.txt"), "header:" + licenseName, encoding);
-// FileUtil.writeString(new File(file, "license.txt"), "license:" + licenseName, encoding);
-// FileUtil.writeString(new File(file, "header.txt"), "header:" + licenseName, encoding);
}
}
Modified: trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -20,51 +20,38 @@
*/
package org.nuiton.license.plugin;
-import org.nuiton.util.PluginConfig;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
-import org.junit.AfterClass;
-import org.nuiton.util.BasePluginTestCase;
+import org.nuiton.plugin.AbstractMojoTest;
-/** @author chemit */
-public class LicensePluginTest extends BasePluginTestCase<LicensePlugin> {
+public class LicensePluginTest extends AbstractMojoTest<LicensePlugin> {
- @BeforeClass
- public static void initClass() throws Exception {
- initConfigs(LicensePluginTest.class, "testOne");
+ @Override
+ protected String getGoalName(String methodName) {
+ return "add-license";
}
- @AfterClass
- public static void afterClass() throws Exception {
- configItr = null;
- testDir = null;
- }
-
- @Before
@Override
- public void setUp() throws Exception {
- super.setUp();
- mojo.setOutputDirectory(new File(getBaseDir(), mojo.getOutputDirectory().toString()));
- if (!mojo.getOutputDirectory().exists()) {
- if (!mojo.getOutputDirectory().mkdirs()) {
- throw new IOException("could not create directory : " + mojo.getOutputDirectory());
+ protected void setUpMojo(LicensePlugin mojo, File pomFile) throws Exception {
+ super.setUpMojo(mojo, pomFile);
+ File outputDirectory = new File(getBasedir(), mojo.getOutputDirectory().toString());
+ mojo.setOutputDirectory(outputDirectory);
+ if (!outputDirectory.exists()) {
+ if (!outputDirectory.mkdirs()) {
+ throw new IOException("could not create directory : " + outputDirectory);
}
}
mojo.setLicenseFile(new File(pomFile.getParentFile(), mojo.getLicenseFile().toString()));
}
@Test
- @PluginConfig(pomName = "testOne.xml", goalName = "add-license")
- public void testOne() throws MojoExecutionException, MojoFailureException {
- assertNotNull(mojo);
+ public void testOne() throws Exception {
+ LicensePlugin mojo = getMojo();
+
long t0 = mojo.getLicenseFile().lastModified();
// always assume pom is older than any file
@@ -84,4 +71,29 @@
assertTrue(t1 > t0);
}
+
+ @Test
+ public void testTwo() throws Exception {
+
+ LicensePlugin mojo = getMojo();
+
+ long t0 = mojo.getLicenseFile().lastModified();
+
+ // always assume pom is older than any file
+ // since we can not ensure order of copy test resources
+ mojo.getProject().getFile().setLastModified(0);
+
+ mojo.execute();
+
+ long t1 = mojo.getLicenseFile().lastModified();
+
+ assertEquals(t0, t1);
+
+ mojo.setForce(true);
+
+ mojo.execute();
+ t1 = mojo.getLicenseFile().lastModified();
+
+ assertTrue(t1 > t0);
+ }
}
Added: trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java (rev 0)
+++ trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -0,0 +1,163 @@
+package org.nuiton.plugin;
+
+import java.io.File;
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+import org.apache.maven.project.MavenProject;
+import org.junit.rules.TestName;
+import org.junit.Rule;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.runners.model.FrameworkMethod;
+
+/**
+ *
+ * @param <P> type of goal to test
+ * @author chemit
+ * @since 1.0.3
+ */
+public abstract class AbstractMojoTest<P extends Plugin> {
+
+ protected static Log log;
+ protected static File testDir;
+ @Rule
+ public MojoTestName name = new MojoTestName();
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ log = new SystemStreamLog();
+ TestHelper.getBasedir();
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ testDir = null;
+ log = null;
+ }
+
+ protected abstract String getGoalName(String methodName);
+
+ protected File getPomFile(File testDir, String methodName, String goalName) {
+ File pom = new File(testDir, methodName + ".xml");
+
+ if (isVerbose()) {
+ log.info("getPomFile = " + TestHelper.getRelativePath(getBasedir(), pom));
+ }
+
+ return pom;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected P createMojo(File pomFile, String goalName) throws Exception {
+ Mojo lookupMojo = TestHelper.lookupMojo(goalName, pomFile);
+ P mojo = (P) lookupMojo;
+ return mojo;
+ }
+
+ protected void setUpMojo(P mojo, File pomFile) throws Exception {
+
+ MavenProject project = mojo.getProject();
+ if (project == null) {
+
+// MavenProjectBuilder projectBuilder = (MavenProjectBuilder) delegate.getContainer().lookup(MavenProjectBuilder.ROLE);
+// ProjectBuilderConfiguration projectBuilderConfiguration = null;
+// project = projectBuilder.build(pomFile, projectBuilderConfiguration);
+
+ project = new MavenProject();
+
+ mojo.setProject(project);
+ }
+
+ mojo.getProject().setFile(pomFile);
+ }
+
+ protected P getMojo() {
+ return name.getMojo();
+ }
+
+ protected String getMethodName() {
+ return name.getMethodName();
+ }
+
+ protected File getPomFile() {
+ return name.getPomFile();
+ }
+
+ protected File getBasedir() {
+ return TestHelper.getBasedir();
+ }
+
+ protected File getTestDir() {
+ if (testDir == null) {
+
+ String rep = getClass().getName();
+ rep = rep.replaceAll("\\.", File.separator);
+
+ File f = TestHelper.getFile(getBasedir(), "target", "test-classes");
+
+ testDir = new File(f, rep);
+ if (isVerbose()) {
+ log.info("test dir = " + TestHelper.getRelativePath(getBasedir(), testDir));
+ }
+ }
+ return testDir;
+ }
+
+ protected boolean isVerbose() {
+ return TestHelper.isVerbose();
+ }
+
+ public class MojoTestName extends TestName {
+
+ private File pomFile;
+ private P mojo;
+
+ public MojoTestName() {
+ if (log.isDebugEnabled()) {
+ log.debug("NEW MojotestName instance for " + AbstractMojoTest.this);
+ }
+ getTestDir();
+ }
+
+ @Override
+ public void starting(FrameworkMethod method) {
+ super.starting(method);
+
+ if (isVerbose()) {
+ log.info("==============================================================================================");
+ }
+ log.info("NEW Mojo test starting : " + AbstractMojoTest.this.getClass().getName() + "#" + getMethodName());
+ String goalName = getGoalName(name.getMethodName());
+
+ pomFile = AbstractMojoTest.this.getPomFile(getTestDir(), getMethodName(), goalName);
+
+ try {
+ Assert.assertTrue("could not find pom " + pomFile.getAbsoluteFile(), pomFile.exists());
+
+ mojo = createMojo(pomFile, goalName);
+
+ AbstractMojoTest.this.setUpMojo(mojo, pomFile);
+
+ } catch (Exception ex) {
+ throw new IllegalStateException("could not init test " + getClass() + " - " + getMethodName() + " for reason " + ex.getMessage(), ex);
+ }
+ }
+
+ @Override
+ public void finished(FrameworkMethod method) {
+ super.finished(method);
+ pomFile = null;
+ mojo = null;
+ }
+
+ public P getMojo() {
+ return mojo;
+ }
+
+ public File getPomFile() {
+ return pomFile;
+ }
+ }
+}
Property changes on: trunk/src/test/java/org/nuiton/plugin/AbstractMojoTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/test/java/org/nuiton/plugin/TestHelper.java
===================================================================
--- trunk/src/test/java/org/nuiton/plugin/TestHelper.java (rev 0)
+++ trunk/src/test/java/org/nuiton/plugin/TestHelper.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -0,0 +1,113 @@
+package org.nuiton.plugin;
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.PlexusTestCase;
+import java.io.File;
+import org.junit.Assert;
+
+/**
+ *
+ * @author chemit
+ * @since 1.0.3
+ */
+public abstract class TestHelper {
+
+ protected static boolean verbose;
+ protected static File basedir;
+ protected static DelegateMojoTestCase delegateMojoTest;
+
+ /**
+ *
+ * @return the basedir for all tests
+ * @see PlexusTestCase#getBasedir()
+ */
+ public static File getBasedir() {
+ if (basedir == null) {
+ String path = PlexusTestCase.getBasedir();
+ basedir = new File(path);
+ if (verbose) {
+ System.out.println("basedir = " + basedir.getAbsolutePath());
+ }
+ }
+ return basedir;
+ }
+
+ public static void setBasedir(File basedir) {
+ TestHelper.basedir = basedir;
+ }
+
+ public static boolean isVerbose() {
+ return verbose;
+ }
+
+ public static void setVerbose(boolean verbose) {
+ TestHelper.verbose = verbose;
+ }
+
+ public static File getTestDir(Class<?> type, String prefix) {
+ String rep = type.getName();
+ rep = rep.replaceAll("\\.", File.separator);
+
+ File f = new File(getBasedir(), prefix);
+ File testDir = new File(f, rep);
+ return testDir;
+ }
+
+ public static Mojo lookupMojo(String goalName, File pomFile) throws Exception {
+ Mojo lookupMojo = getDelegateMojoTest().lookupMojo(goalName, pomFile);
+ Assert.assertNotNull(lookupMojo);
+ return lookupMojo;
+
+ }
+
+ public static DelegateMojoTestCase getDelegateMojoTest() throws Exception {
+ if (TestHelper.delegateMojoTest == null) {
+ TestHelper.delegateMojoTest = new DelegateMojoTestCase();
+ TestHelper.delegateMojoTest.setUp();
+ }
+ return TestHelper.delegateMojoTest;
+ }
+
+ public static void setDelegateMojoTest(DelegateMojoTestCase delegateMojoTest) {
+ TestHelper.delegateMojoTest = delegateMojoTest;
+ }
+
+ public static File getFile(File base, String... paths) {
+ StringBuilder buffer = new StringBuilder();
+ for (String path : paths) {
+ buffer.append(File.separator).append(path);
+ }
+ File f = new File(base, buffer.substring(1));
+ return f;
+ }
+
+ public static String getRelativePath(File base, File file) {
+ String result = file.getAbsolutePath().substring(base.getAbsolutePath().length() + 1);
+ return result;
+ }
+
+ public static class DelegateMojoTestCase extends AbstractMojoTestCase {
+
+ @Override
+ public Mojo lookupMojo(String goal, File pom) throws Exception {
+ return super.lookupMojo(goal, pom);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ @Override
+ public PlexusContainer getContainer() {
+ return super.getContainer();
+ }
+ }
+}
Property changes on: trunk/src/test/java/org/nuiton/plugin/TestHelper.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -35,11 +35,16 @@
import org.codehaus.plexus.PlexusTestCase;
import org.junit.Ignore;
import org.junit.Test;
-import org.nuiton.Plugin;
+import org.nuiton.plugin.Plugin;
/**
* @param <P> le mojo a test
- * @author chemit */
+ * @author chemit
+ *
+ * @deprecated since 1.0.3, prefer use the {@link AbstractMojoTest} which
+ * need no more annotation on each test method.
+ */
+@Deprecated
public abstract class BasePluginTestCase<P extends Plugin> {
protected static SystemStreamLog log;
Modified: trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/test/java/org/nuiton/util/JavaFileUpdaterTest.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -20,13 +20,11 @@
*/
package org.nuiton.util;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.nuiton.util.FileUpdaterHelper.JavaFileUpdater;
import java.io.File;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.nuiton.plugin.TestHelper;
import static org.junit.Assert.*;
/**
@@ -36,32 +34,20 @@
*/
public class JavaFileUpdaterTest {
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private final Log log = LogFactory.getLog(FileUpdaterHelper.class);
-
-
- static final char SEP = File.separatorChar;
-
static MirroredFileUpdater fileUpdater;
-
static File sourceFile;
static File mirrorFile;
@BeforeClass
public static void initClass() throws Exception {
- String basedir = System.getProperty("basedir");
- if (basedir == null) {
- log.warn("basedir not found, test is not executed from maven...");
- basedir = new File(new File("").getAbsolutePath()).getAbsolutePath();
- }
- log.info("basedir = " + basedir);
+ File basedir = TestHelper.getBasedir();
- File src = new File(basedir, "src" + SEP + "test" + SEP + "java");
- File dir = new File(basedir, "target" + SEP + "test-classes");
- fileUpdater = (MirroredFileUpdater) FileUpdaterHelper.newJavaFileUpdater(src, dir);
- log.info(fileUpdater);
+ File src = TestHelper.getFile(basedir, "src", "test", "java");
+ File dir = TestHelper.getFile(basedir, "target", "test-classes");
+ fileUpdater = FileUpdaterHelper.newJavaFileUpdater(src, dir);
+
// test source dir exists
File sourceDirectory = fileUpdater.getSourceDirectory();
assertTrue("sourcedir is null", sourceDirectory != null);
@@ -72,11 +58,11 @@
assertTrue("destinationDirectory is null", destinationDirectory != null);
assertTrue("destinationDirectory does not exists " + destinationDirectory, destinationDirectory.exists());
- sourceFile = new File(fileUpdater.getSourceDirectory(), "org" + SEP + "nuiton" + SEP + "util" + SEP + JavaDummy.class.getSimpleName() + ".java");
+ sourceFile = TestHelper.getFile(fileUpdater.getSourceDirectory(), "org", "nuiton", "util", JavaDummy.class.getSimpleName() + ".java");
}
-@Test
+ @Test
public void testSourceFileIsUptoDate() throws Exception {
assertTrue("fileUpdater was not init", fileUpdater != null);
@@ -89,7 +75,7 @@
mirrorFile = fileUpdater.getMirrorFile(sourceFile);
}
-@Test
+ @Test
public void testSourceFileDoesNotHaveMirrorFile() throws Exception {
assertTrue("fileUpdater was not init", fileUpdater != null);
@@ -112,7 +98,7 @@
assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile));
}
-@Test
+ @Test
public void testSourceFileIsNewerThanMirrorFile() throws Exception {
assertTrue("fileUpdater was not init", fileUpdater != null);
@@ -136,5 +122,4 @@
// java file is now up to date (rename method does not affect lasmodified property on a file)
assertTrue(sourceFile + " should be uptodate", fileUpdater.isFileUpToDate(sourceFile));
}
-
}
Modified: trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/test/java/org/nuiton/util/JaxxFileUpdaterTest.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -20,12 +20,10 @@
*/
package org.nuiton.util;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import java.io.File;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.nuiton.plugin.TestHelper;
import static org.junit.Assert.*;
/**
@@ -35,9 +33,6 @@
*/
public class JaxxFileUpdaterTest {
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private final Log log = LogFactory.getLog(FileUpdaterHelper.class);
- static final char SEP = File.separatorChar;
static MirroredFileUpdater fileUpdater;
static File sourceFile;
static File mirrorFile;
@@ -45,18 +40,11 @@
@BeforeClass
public static void initClass() throws Exception {
- String basedir = System.getProperty("basedir");
- if (basedir == null) {
- log.warn("basedir not found, test is not executed from maven...");
- basedir = new File(new File("").getAbsolutePath()).getAbsolutePath();
- }
+ File basedir = TestHelper.getBasedir();
- log.info("basedir = " + basedir);
-
- File src = new File(basedir, "src" + SEP + "test" + SEP + "resources");
- File dir = new File(basedir, "src" + SEP + "test" + SEP + "java");
+ File src = TestHelper.getFile(basedir, "src", "test", "resources");
+ File dir = TestHelper.getFile(basedir, "src", "test", "java");
fileUpdater = FileUpdaterHelper.newJaxxFileUpdater(src, dir);
- log.info(fileUpdater);
// test source dir exists
File sourceDirectory = fileUpdater.getSourceDirectory();
@@ -68,7 +56,7 @@
assertTrue("destinationDirectory is null", destinationDirectory != null);
assertTrue("destinationDirectory does not exists " + destinationDirectory, destinationDirectory.exists());
- sourceFile = new File(fileUpdater.getSourceDirectory(), "org" + SEP + "nuiton" + SEP + "util" + SEP + JaxxDummy.class.getSimpleName() + ".jaxx");
+ sourceFile = TestHelper.getFile(fileUpdater.getSourceDirectory(), "org", "nuiton", "util", JaxxDummy.class.getSimpleName() + ".jaxx");
}
Modified: trunk/src/test/java/org/nuiton/util/PluginConfig.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/PluginConfig.java 2009-09-11 22:06:27 UTC (rev 572)
+++ trunk/src/test/java/org/nuiton/util/PluginConfig.java 2009-09-15 15:44:19 UTC (rev 573)
@@ -25,16 +25,19 @@
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
+import org.nuiton.plugin.AbstractMojoTest;
-/** @author chemit */
+/** @author chemit
+ * @deprecated since 1.0.3, prefer use the {@link AbstractMojoTest} which
+ * need no more annotation on each test method.
+ */
@Retention(RetentionPolicy.RUNTIME)
-
@Target(ElementType.METHOD)
@Inherited
+@Deprecated
public @interface PluginConfig {
String goalName();
String pomName();
-
}
1
0
Author: tchemit
Date: 2009-09-12 00:06:27 +0200 (Sat, 12 Sep 2009)
New Revision: 572
Modified:
trunk/pom.xml
Log:
bump maven-plugin-testing-harness (note: the groupId has changed)
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-09-09 21:41:40 UTC (rev 571)
+++ trunk/pom.xml 2009-09-11 22:06:27 UTC (rev 572)
@@ -77,9 +77,9 @@
<!-- tests dependencies -->
<dependency>
- <groupId>org.apache.maven.shared</groupId>
+ <groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
- <version>1.1</version>
+ <version>1.2</version>
<scope>test</scope>
</dependency>
1
0
r571 - in trunk/src: main/java/org/nuiton test/java/org/nuiton/util
by tchemit@users.nuiton.org 09 Sep '09
by tchemit@users.nuiton.org 09 Sep '09
09 Sep '09
Author: tchemit
Date: 2009-09-09 23:41:40 +0200 (Wed, 09 Sep 2009)
New Revision: 571
Added:
trunk/src/main/java/org/nuiton/Plugin.java
Modified:
trunk/src/main/java/org/nuiton/AbstractPlugin.java
trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
Log:
add a common contract Plugin for mojos and reports
Modified: trunk/src/main/java/org/nuiton/AbstractPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/AbstractPlugin.java 2009-09-08 16:02:25 UTC (rev 570)
+++ trunk/src/main/java/org/nuiton/AbstractPlugin.java 2009-09-09 21:41:40 UTC (rev 571)
@@ -49,7 +49,7 @@
*
* @author chemit
*/
-public abstract class AbstractPlugin extends AbstractMojo {
+public abstract class AbstractPlugin extends AbstractMojo implements Plugin {
protected abstract boolean ensurePackaging();
@@ -102,14 +102,6 @@
}
}
- public abstract MavenProject getProject();
-
- public abstract void setProject(MavenProject project);
-
- public abstract boolean isVerbose();
-
- public abstract void setVerbose(boolean verbose);
-
/**
* Does the actual copy of the file and logging.
*
Added: trunk/src/main/java/org/nuiton/Plugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/Plugin.java (rev 0)
+++ trunk/src/main/java/org/nuiton/Plugin.java 2009-09-09 21:41:40 UTC (rev 571)
@@ -0,0 +1,23 @@
+package org.nuiton;
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * A common contract to be implements by our mojo and reports.
+ *
+ * Just expose a {@link #isVerbose()} flag and the maven project {@link #getProject()}.
+ *
+ * @author chemit
+ * @since 1.0.3
+ */
+public interface Plugin extends Mojo {
+
+ MavenProject getProject();
+
+ void setProject(MavenProject project);
+
+ boolean isVerbose();
+
+ void setVerbose(boolean verbose);
+}
Property changes on: trunk/src/main/java/org/nuiton/Plugin.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-08 16:02:25 UTC (rev 570)
+++ trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-09 21:41:40 UTC (rev 571)
@@ -35,12 +35,12 @@
import org.codehaus.plexus.PlexusTestCase;
import org.junit.Ignore;
import org.junit.Test;
-import org.nuiton.AbstractPlugin;
+import org.nuiton.Plugin;
/**
* @param <P> le mojo a test
* @author chemit */
-public abstract class BasePluginTestCase<P extends AbstractPlugin> {
+public abstract class BasePluginTestCase<P extends Plugin> {
protected static SystemStreamLog log;
protected static File basedir;
@@ -64,7 +64,7 @@
return testDir;
}
- protected static <P extends AbstractPlugin> void initConfigs(Class<? extends BasePluginTestCase<P>> klass, String... testNames) throws Exception {
+ protected static <P extends Plugin> void initConfigs(Class<? extends BasePluginTestCase<P>> klass, String... testNames) throws Exception {
log = new SystemStreamLog();
List<PluginConfig> configs = new ArrayList<PluginConfig>();
String rep = klass.getName();
@@ -73,7 +73,7 @@
File f = new File(getBaseDir(), "target" + File.separator + "test-classes");
//File f = new File(getBaseDir(), "src" + File.separator + "test" + File.separator + "resources");
testDir = new File(f, rep);
- log.info("test dir : " + testDir.getAbsolutePath().substring(getBaseDir().getAbsolutePath().length()+1));
+ log.info("test dir : " + testDir.getAbsolutePath().substring(getBaseDir().getAbsolutePath().length() + 1));
if (testNames.length == 0) {
1
0