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
Author: tchemit
Date: 2012-07-14 19:00:02 +0200 (Sat, 14 Jul 2012)
New Revision: 850
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/850
Log:
Fix site scm url
Modified:
trunk/src/site/site_en.xml
Modified: trunk/src/site/site_en.xml
===================================================================
--- trunk/src/site/site_en.xml 2012-07-13 17:10:09 UTC (rev 849)
+++ trunk/src/site/site_en.xml 2012-07-14 17:00:02 UTC (rev 850)
@@ -126,7 +126,7 @@
projectversion='${project.version}'
platform='${project.platform}'
projectid='${project.projectId}'
- scm='${project.scm.connection}'
+ scm='${project.scm.developerConnection}'
scmwebeditorenabled='${project.scmwebeditorEnabled}'
scmwebeditorurl='${project.scmwebeditorUrl}'
siteSourcesType='${project.siteSourcesType}'
1
0
r849 - in trunk/src: main/java/org/nuiton/helper/plugin main/java/org/nuiton/io/rest main/java/org/nuiton/io/xpp3 test/java/org/nuiton/io/xpp3
by tchemit@users.nuiton.org 13 Jul '12
by tchemit@users.nuiton.org 13 Jul '12
13 Jul '12
Author: tchemit
Date: 2012-07-13 19:10:09 +0200 (Fri, 13 Jul 2012)
New Revision: 849
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/849
Log:
update headers
Modified:
trunk/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java
trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java
trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java
trunk/src/main/java/org/nuiton/io/rest/RestMethod.java
trunk/src/main/java/org/nuiton/io/xpp3/AttributeValueToProperty.java
trunk/src/main/java/org/nuiton/io/xpp3/TagContentToProperty.java
trunk/src/main/java/org/nuiton/io/xpp3/TagTextContentToProperty.java
trunk/src/test/java/org/nuiton/io/xpp3/CountryRef.java
trunk/src/test/java/org/nuiton/io/xpp3/CountryRefXpp3Reader.java
Modified: trunk/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java 2012-07-13 16:25:17 UTC (rev 848)
+++ trunk/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java 2012-07-13 17:10:09 UTC (rev 849)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2012 CodeLutin
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java 2012-07-13 16:25:17 UTC (rev 848)
+++ trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java 2012-07-13 17:10:09 UTC (rev 849)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2012 CodeLutin
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java 2012-07-13 16:25:17 UTC (rev 848)
+++ trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java 2012-07-13 17:10:09 UTC (rev 849)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2012 CodeLutin
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Property changes on: trunk/src/main/java/org/nuiton/io/rest/RestMethod.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/src/main/java/org/nuiton/io/xpp3/AttributeValueToProperty.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/AttributeValueToProperty.java 2012-07-13 16:25:17 UTC (rev 848)
+++ trunk/src/main/java/org/nuiton/io/xpp3/AttributeValueToProperty.java 2012-07-13 17:10:09 UTC (rev 849)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2012 CodeLutin
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: trunk/src/main/java/org/nuiton/io/xpp3/TagContentToProperty.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/TagContentToProperty.java 2012-07-13 16:25:17 UTC (rev 848)
+++ trunk/src/main/java/org/nuiton/io/xpp3/TagContentToProperty.java 2012-07-13 17:10:09 UTC (rev 849)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2012 CodeLutin
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: trunk/src/main/java/org/nuiton/io/xpp3/TagTextContentToProperty.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/TagTextContentToProperty.java 2012-07-13 16:25:17 UTC (rev 848)
+++ trunk/src/main/java/org/nuiton/io/xpp3/TagTextContentToProperty.java 2012-07-13 17:10:09 UTC (rev 849)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2012 CodeLutin
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: trunk/src/test/java/org/nuiton/io/xpp3/CountryRef.java
===================================================================
--- trunk/src/test/java/org/nuiton/io/xpp3/CountryRef.java 2012-07-13 16:25:17 UTC (rev 848)
+++ trunk/src/test/java/org/nuiton/io/xpp3/CountryRef.java 2012-07-13 17:10:09 UTC (rev 849)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2012 CodeLutin
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: trunk/src/test/java/org/nuiton/io/xpp3/CountryRefXpp3Reader.java
===================================================================
--- trunk/src/test/java/org/nuiton/io/xpp3/CountryRefXpp3Reader.java 2012-07-13 16:25:17 UTC (rev 848)
+++ trunk/src/test/java/org/nuiton/io/xpp3/CountryRefXpp3Reader.java 2012-07-13 17:10:09 UTC (rev 849)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2009 - 2012 CodeLutin
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
1
0
Author: tchemit
Date: 2012-07-13 18:25:17 +0200 (Fri, 13 Jul 2012)
New Revision: 848
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/848
Log:
refs #2183: Introduce a RequestFactory instead of using it inside the rest client (let's get the request builder if needed)
Modified:
trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java
trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java
Modified: trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java 2012-07-12 22:58:47 UTC (rev 847)
+++ trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java 2012-07-13 16:25:17 UTC (rev 848)
@@ -61,7 +61,7 @@
public RestRequest getRequest(String id, Object... args) {
RestRequest r;
- RestRequestBuilder builder = requestBuilders.get(id);
+ RestRequestBuilder builder = getRequestBuilder(id);
if (builder == null) {
throw new IllegalArgumentException(
@@ -77,4 +77,11 @@
return r;
}
+ /** {@inheritDoc} */
+ public RestRequestBuilder getRequestBuilder(String id) {
+ RestRequestBuilder builder = requestBuilders.get(id);
+
+ return builder;
+ }
+
}
Modified: trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java 2012-07-12 22:58:47 UTC (rev 847)
+++ trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java 2012-07-13 16:25:17 UTC (rev 848)
@@ -55,4 +55,11 @@
*/
RestRequest getRequest(String id, Object... args);
+ /**
+ * Obtain the request builder from a given request id.
+ *
+ * @param id the id of request to seek for
+ * @return the requets builder or {@code null} if not found
+ */
+ RestRequestBuilder getRequestBuilder(String id);
}
1
0
Author: tchemit
Date: 2012-07-13 00:58:47 +0200 (Fri, 13 Jul 2012)
New Revision: 847
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/847
Log:
rest request contains now his method
Added:
trunk/src/main/java/org/nuiton/io/rest/RestMethod.java
Modified:
trunk/src/main/java/org/nuiton/io/rest/RestClient.java
trunk/src/main/java/org/nuiton/io/rest/RestRequest.java
trunk/src/main/java/org/nuiton/io/rest/RestSession.java
Modified: trunk/src/main/java/org/nuiton/io/rest/RestClient.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestClient.java 2012-07-12 17:03:55 UTC (rev 846)
+++ trunk/src/main/java/org/nuiton/io/rest/RestClient.java 2012-07-12 22:58:47 UTC (rev 847)
@@ -25,9 +25,6 @@
package org.nuiton.io.rest;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import java.io.IOException;
import java.io.InputStream;
@@ -39,8 +36,6 @@
*/
public abstract class RestClient {
- private static final Log log = LogFactory.getLog(RestClient.class);
-
/** rest client configuration */
protected RestClientConfiguration configuration;
@@ -85,15 +80,6 @@
}
/**
- * Add a request into the client.
- *
- * @param builder the new request to add
- */
- public void addRequestBuilder(RestRequestBuilder builder) {
- getRequestFactory().addRequestBuilder(builder);
- }
-
- /**
* Obtain a request given his id and the args given.
*
* @param id id of the request
Added: trunk/src/main/java/org/nuiton/io/rest/RestMethod.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestMethod.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/RestMethod.java 2012-07-12 22:58:47 UTC (rev 847)
@@ -0,0 +1,11 @@
+package org.nuiton.io.rest;
+
+/**
+ * Possible rest methods.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public enum RestMethod {
+ GET, POST, PUT, DELETE, HEAD
+}
Modified: trunk/src/main/java/org/nuiton/io/rest/RestRequest.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestRequest.java 2012-07-12 17:03:55 UTC (rev 846)
+++ trunk/src/main/java/org/nuiton/io/rest/RestRequest.java 2012-07-12 22:58:47 UTC (rev 847)
@@ -26,7 +26,6 @@
package org.nuiton.io.rest;
import java.io.File;
-import java.net.URL;
import java.util.Map;
/**
@@ -36,6 +35,7 @@
* @since 1.0.3
*/
public interface RestRequest {
+
/** @return the splitted path to add to url */
String[] getPath();
@@ -61,5 +61,12 @@
* @return the full url for this request
* @since 1.5
*/
- String toPath(URL baseUrl);
+ String toPath(String baseUrl);
+
+ /**
+ * The method to use for this request.
+ *
+ * @return 1.5
+ */
+ RestMethod getMethod();
}
Modified: trunk/src/main/java/org/nuiton/io/rest/RestSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestSession.java 2012-07-12 17:03:55 UTC (rev 846)
+++ trunk/src/main/java/org/nuiton/io/rest/RestSession.java 2012-07-12 22:58:47 UTC (rev 847)
@@ -30,10 +30,16 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.StatusLine;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
@@ -183,28 +189,45 @@
);
}
- protected String getUri(String... paths) {
+ protected String getRequestUrl(RestRequest request) {
String uri = client.getHostConfiguration().getHostURL();
- for (String path : paths) {
- uri += '/' + path;
- }
- return uri;
+ String result = request.toPath(uri);
+ return result;
}
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);
+ log.info("doRequest " + getRequestUrl(request));
}
if (log.isDebugEnabled()) {
log.debug("doRequest with parameters : " +
- Arrays.toString(parameters));
+ Arrays.toString(request.getParameters()));
}
- PostMethod gm = new PostMethod(uri);
+
+ HttpMethod gm;
+ switch (request.getMethod()) {
+
+ case GET:
+ gm = prepareGetRequest(request);
+ break;
+ case POST:
+ gm = preparePostRequest(request);
+
+ break;
+ case PUT:
+ gm = preparePutRequest(request);
+
+ break;
+ case DELETE:
+ gm = prepareDeleteRequest(request);
+ break;
+ case HEAD:
+ default:
+ throw new IllegalStateException("Can not deal with method " + request.getMethod());
+ }
+
+ // add cookies if any
if (open) {
Cookie[] cookies = client.getState().getCookies();
for (Cookie c : cookies) {
@@ -216,8 +239,65 @@
}
}
+ client.executeMethod(gm);
+
+ return gm;
+ }
+
+ public HttpMethod prepareGetRequest(RestRequest request) throws IOException {
+
+ String uri = getRequestUrl(request);
+ String[] parameters = request.getParameters();
+ Map<String, File> attachments = request.getAttachments();
+
+
+ if (attachments != null) {
+
+ // multi-part request
+ //not possible with a simple Get method
+
+ throw new IllegalStateException("Can not do a GET request with multi-parts, use a POST or UPDATE request");
+ }
+
+ GetMethod gm = new GetMethod(uri);
+
+ addParams(gm, parameters);
+
+ return gm;
+ }
+
+ public HttpMethod prepareDeleteRequest(RestRequest request) throws IOException {
+
+ String uri = getRequestUrl(request);
+ String[] parameters = request.getParameters();
+ Map<String, File> attachments = request.getAttachments();
+
+ if (attachments != null) {
+
+ // multi-part request
+ //not possible with a simple Get method
+
+ throw new IllegalStateException("Can not do a DELETE request with multi-parts, use a POST or UPDATE request");
+ }
+
+ DeleteMethod gm = new DeleteMethod(uri);
+
+ addParams(gm, parameters);
+
+ return gm;
+ }
+
+ public HttpMethod preparePostRequest(RestRequest request) throws IOException {
+
+ String uri = getRequestUrl(request);
+ String[] parameters = request.getParameters();
+ Map<String, File> attachments = request.getAttachments();
+
+ PostMethod gm = new PostMethod(uri);
+
if (attachments == null) {
+
// not a multi-part request
if (parameters.length > 0) {
@@ -234,6 +314,7 @@
}
continue;
}
+
gm.addParameter(key, value);
}
}
@@ -241,69 +322,119 @@
// multi-part request
- List<Part> paramParts = new ArrayList<Part>();
+ prepareMultiPart(gm, attachments, parameters);
+ }
+ return gm;
+ }
- if (parameters.length > 0) {
+ public HttpMethod preparePutRequest(RestRequest request) throws IOException {
- // add parameters as part of multi-part
+ String uri = getRequestUrl(request);
+ String[] parameters = request.getParameters();
+ Map<String, File> attachments = request.getAttachments();
- 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));
+ PutMethod gm = new PutMethod(uri);
+
+ if (attachments == null) {
+
+
+ // not a multi-part request
+
+ addParams(gm, parameters);
+
+ } else {
+
+ // multi-part request
+
+ prepareMultiPart(gm, attachments, parameters);
+ }
+ return gm;
+ }
+
+ protected void addParams(HttpMethodBase gm, String... parameters) {
+ if (parameters.length > 0) {
+
+ // add parameters
+
+ int nbParams = parameters.length / 2;
+ NameValuePair[] params = new NameValuePair[nbParams];
+ 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("add parameter [" + key + "]=" + value);
+ log.debug("skip null parameter " + key);
}
+ continue;
}
+ params[i] = new NameValuePair(key, value);
}
+ gm.setQueryString(params);
+ }
+ }
- // add file parts
- for (Entry<String, File> entry : attachments.entrySet()) {
- String key = entry.getKey();
- File file = entry.getValue();
+ protected void prepareMultiPart(EntityEnclosingMethod gm,
+ Map<String, File> attachments,
+ String... parameters) throws IOException {
+
+ 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));
if (log.isDebugEnabled()) {
- log.debug("add attachment " + key + "=" + file);
+ log.debug("add parameter [" + key + "]=" + value);
}
- paramParts.add(new FilePart(
- key,
- file.getName(),
- file,
- FilePart.DEFAULT_CONTENT_TYPE,
- configuration.getEncoding())
- );
}
- if (attachments.isEmpty()) {
- log.warn("no attachment in a multi-part request!");
- }
+ }
- Part[] parts = paramParts.toArray(new Part[paramParts.size()]);
-
- MultipartRequestEntity entity =
- new MultipartRequestEntity(parts, gm.getParams());
+ // add file parts
+ for (Entry<String, File> entry : attachments.entrySet()) {
+ String key = entry.getKey();
+ File file = entry.getValue();
if (log.isDebugEnabled()) {
- entity.writeRequest(System.out);
+ log.debug("add attachment " + key + "=" + file);
}
- 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());
- }
+ paramParts.add(new FilePart(
+ key,
+ file.getName(),
+ file,
+ FilePart.DEFAULT_CONTENT_TYPE,
+ configuration.getEncoding())
+ );
+ }
+ if (attachments.isEmpty()) {
+ log.warn("no attachment in a multi-part request!");
+ }
+ Part[] parts = paramParts.toArray(new Part[paramParts.size()]);
+
+ MultipartRequestEntity entity =
+ new MultipartRequestEntity(parts, gm.getParams());
+ if (log.isDebugEnabled()) {
+ entity.writeRequest(System.out);
}
+ 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;
}
}
1
0
12 Jul '12
Author: tchemit
Date: 2012-07-12 19:03:55 +0200 (Thu, 12 Jul 2012)
New Revision: 846
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/846
Log:
add svn properties + fix headers + fix api 1.6
Modified:
trunk/src/main/java/org/nuiton/io/mail/ProjectJavamailMailSender.java
trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java
trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java
Modified: trunk/src/main/java/org/nuiton/io/mail/ProjectJavamailMailSender.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/mail/ProjectJavamailMailSender.java 2012-07-12 16:55:57 UTC (rev 845)
+++ trunk/src/main/java/org/nuiton/io/mail/ProjectJavamailMailSender.java 2012-07-12 17:03:55 UTC (rev 846)
@@ -25,10 +25,11 @@
package org.nuiton.io.mail;
-import java.security.Security;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Properties;
+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;
import javax.mail.Authenticator;
import javax.mail.Message;
@@ -38,20 +39,18 @@
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
+import java.security.Provider;
+import java.security.Security;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Properties;
-import com.sun.net.ssl.internal.ssl.Provider;
-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.
- *
+ * <p/>
* Note : this code was stolen in {@code maven-changes-plugin}, should thanks
* them...
- *
+ *
* @author tchemit <chemit(a)codelutin.com>
* @since 1.0.3
*/
@@ -59,10 +58,12 @@
extends AbstractMailSender {
private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
+
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
private Properties userProperties;
+
private Properties props;
// ----------------------------------------------------------------------
@@ -90,7 +91,7 @@
props.put("mail.debug", String.valueOf(getLogger().isDebugEnabled()));
if (isSslMode()) {
- Security.addProvider(new Provider());
+ Security.addProvider(getSsllProvider());
props.put("mail.smtp.socketFactory.port", String.valueOf(getSmtpPort()));
@@ -100,7 +101,7 @@
}
if (userProperties != null) {
- for (Iterator<?> i = userProperties.keySet().iterator(); i.hasNext();) {
+ for (Iterator<?> i = userProperties.keySet().iterator(); i.hasNext(); ) {
String key = (String) i.next();
String value = userProperties.getProperty(key);
@@ -110,6 +111,17 @@
}
}
+ private Provider getSsllProvider() {
+ try {
+ Class<?> aClass =
+ Class.forName("com.sun.net.ssl.internal.ssl.Provider");
+ return (Provider) aClass.newInstance();
+ } catch (Exception e) {
+
+ throw new IllegalStateException("Could not obtain ssl provider", e);
+ }
+ }
+
// ----------------------------------------------------------------------
// MailSender Implementation
// ----------------------------------------------------------------------
@@ -142,7 +154,7 @@
if (mail.getToAddresses().size() > 0) {
InternetAddress[] addressTo = new InternetAddress[mail.getToAddresses().size()];
int count = 0;
- for (Iterator<?> i = mail.getToAddresses().iterator(); i.hasNext();) {
+ for (Iterator<?> i = mail.getToAddresses().iterator(); i.hasNext(); ) {
String address = ((MailMessage.Address) i.next()).getRfc2822Address();
addressTo[count++] = new InternetAddress(address);
}
@@ -152,7 +164,7 @@
if (mail.getCcAddresses().size() > 0) {
InternetAddress[] addressCc = new InternetAddress[mail.getCcAddresses().size()];
int count = 0;
- for (Iterator<?> i = mail.getCcAddresses().iterator(); i.hasNext();) {
+ for (Iterator<?> i = mail.getCcAddresses().iterator(); i.hasNext(); ) {
String address = ((MailMessage.Address) i.next()).getRfc2822Address();
addressCc[count++] = new InternetAddress(address);
}
@@ -162,7 +174,7 @@
if (mail.getBccAddresses().size() > 0) {
InternetAddress[] addressBcc = new InternetAddress[mail.getBccAddresses().size()];
int count = 0;
- for (Iterator<?> i = mail.getBccAddresses().iterator(); i.hasNext();) {
+ for (Iterator<?> i = mail.getBccAddresses().iterator(); i.hasNext(); ) {
String address = ((MailMessage.Address) i.next()).getRfc2822Address();
addressBcc[count++] = new InternetAddress(address);
}
Modified: trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java 2012-07-12 16:55:57 UTC (rev 845)
+++ trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java 2012-07-12 17:03:55 UTC (rev 846)
@@ -1,4 +1,27 @@
package org.nuiton.io.rest;
+/*
+ * #%L
+ * Helper Maven Plugin
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 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>.
+ * #L%
+ */
import com.google.common.collect.Maps;
Property changes on: trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java 2012-07-12 16:55:57 UTC (rev 845)
+++ trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java 2012-07-12 17:03:55 UTC (rev 846)
@@ -1,4 +1,27 @@
package org.nuiton.io.rest;
+/*
+ * #%L
+ * Helper Maven Plugin
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 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>.
+ * #L%
+ */
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Property changes on: trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r845 - in trunk: . src/main/java/org/nuiton/io/rest src/main/java/org/nuiton/io/xpp3
by tchemit@users.nuiton.org 12 Jul '12
by tchemit@users.nuiton.org 12 Jul '12
12 Jul '12
Author: tchemit
Date: 2012-07-12 18:55:57 +0200 (Thu, 12 Jul 2012)
New Revision: 845
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/845
Log:
fixes #2183: Introduce a RequestFactory instead of using it inside the rest client
fixes #2182: updates to commons lang 3
Added:
trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java
trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java
Modified:
trunk/pom.xml
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/RestRequest.java
trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java
trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java
trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-07-12 16:53:52 UTC (rev 844)
+++ trunk/pom.xml 2012-07-12 16:55:57 UTC (rev 845)
@@ -1,10 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
- Maven helper plugin
-
- $Id$
- $HeadURL$
+ Helper Maven plugin
%%
Copyright (C) 2009 - 2010 Tony Chemit, CodeLutin
%%
@@ -23,7 +20,9 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->
-<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">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -56,8 +55,8 @@
</dependency>
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
@@ -146,7 +145,7 @@
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
@@ -222,7 +221,7 @@
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
@@ -245,7 +244,7 @@
<id>tchemit</id>
<email>chemit at codelutin dot com</email>
<organization>CodeLutin</organization>
- <timezone>+2</timezone>
+ <timezone>Europe/Paris</timezone>
<roles>
<role>Lead</role>
<role>Developer</role>
@@ -256,7 +255,7 @@
<id>ymartel</id>
<email>martel at codelutin dot com</email>
<organization>CodeLutin</organization>
- <timezone>+2</timezone>
+ <timezone>Europe/Paris</timezone>
<roles>
<role>Developer</role>
</roles>
@@ -268,9 +267,15 @@
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/trunk</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/trunk</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/maven-helper-plugin/trunk</url>
+ <connection>
+ scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/trunk
+ </connection>
+ <developerConnection>
+ scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/trunk
+ </developerConnection>
+ <url>
+ http://www.nuiton.org/repositories/browse/maven-helper-plugin/trunk
+ </url>
</scm>
<distributionManagement>
@@ -301,11 +306,6 @@
<!-- documentation is in apt -->
<siteSourcesType>apt</siteSourcesType>
- <!-- Stay on jdk5 (requirement for some other project using this
- library) -->
- <maven.compiler.source>1.5</maven.compiler.source>
- <maven.compiler.target>1.5</maven.compiler.target>
-
</properties>
<build>
@@ -487,7 +487,7 @@
</plugins>
</build>
-
+
</profile>
<!-- prepare the assembly at release time -->
@@ -527,7 +527,7 @@
</plugins>
</build>
-
+
</profile>
<!-- run the IT at release time -->
Added: trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/AbstractRequestFactory.java 2012-07-12 16:55:57 UTC (rev 845)
@@ -0,0 +1,57 @@
+package org.nuiton.io.rest;
+
+import com.google.common.collect.Maps;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Map;
+
+/**
+ * Abstract implementation of {@link RequestFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public abstract class AbstractRequestFactory implements RequestFactory {
+
+ public static final DateFormat DATE_FORMAT =
+ new SimpleDateFormat("yyyy-MM-dd");
+
+ /** registred requests */
+ protected final Map<String, RestRequestBuilder> requestBuilders;
+
+ public AbstractRequestFactory() {
+ requestBuilders = Maps.newTreeMap();
+ }
+
+ /** {@inheritDoc} */
+ 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);
+ }
+
+ /** {@inheritDoc} */
+ public RestRequest getRequest(String id, Object... args) {
+
+ RestRequest r;
+ RestRequestBuilder builder = requestBuilders.get(id);
+ if (builder == null) {
+
+ throw new IllegalArgumentException(
+ "Could not find any request builder for request named '" +
+ id + "'");
+ }
+ r = builder.create(args);
+ if (r == null) {
+ throw new IllegalArgumentException(
+ "Could not find any request named '" + id +
+ "' using builder " + builder);
+ }
+ return r;
+ }
+
+}
Modified: trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java 2012-07-12 16:53:52 UTC (rev 844)
+++ trunk/src/main/java/org/nuiton/io/rest/DefaultRestClientConfiguration.java 2012-07-12 16:55:57 UTC (rev 845)
@@ -25,8 +25,8 @@
package org.nuiton.io.rest;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
import java.net.URL;
Added: trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/rest/RequestFactory.java 2012-07-12 16:55:57 UTC (rev 845)
@@ -0,0 +1,35 @@
+package org.nuiton.io.rest;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+/**
+ * Factory of {@link RestRequest}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public interface RequestFactory {
+
+ public static final DateFormat DATE_FORMAT =
+ new SimpleDateFormat("yyyy-MM-dd");
+
+ void addDefaultRequests();
+
+ /**
+ * Add a request into the factory.
+ *
+ * @param builder the new request to add
+ */
+ void addRequestBuilder(RestRequestBuilder 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
+ */
+ RestRequest getRequest(String id, Object... args);
+
+}
Modified: trunk/src/main/java/org/nuiton/io/rest/RestClient.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestClient.java 2012-07-12 16:53:52 UTC (rev 844)
+++ trunk/src/main/java/org/nuiton/io/rest/RestClient.java 2012-07-12 16:55:57 UTC (rev 845)
@@ -30,8 +30,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.util.Map;
-import java.util.TreeMap;
/**
* Abtract REST client.
@@ -49,15 +47,13 @@
/** rest session */
protected RestSession session;
- /** registred requests */
- protected final Map<String, RestRequestBuilder> requestBuilders;
-
/**
- * Add the default available requests for this client.
- * <p/>
- * <b>Note:</b> This method is invoked in the constructor of the client.
+ * Obtains the underlying factory of requests.
+ *
+ * @return the factory of requests
+ * @since 1.5
*/
- protected abstract void addDefaultRequests();
+ public abstract RequestFactory getRequestFactory();
/**
* Open the client.
@@ -82,12 +78,9 @@
protected abstract void close(RestSession session) throws IOException;
public RestClient() {
- requestBuilders = new TreeMap<String, RestRequestBuilder>();
- addDefaultRequests();
}
public RestClient(RestClientConfiguration configuration) {
- this();
this.configuration = configuration;
}
@@ -97,11 +90,7 @@
* @param builder the new request to add
*/
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);
+ getRequestFactory().addRequestBuilder(builder);
}
/**
@@ -112,12 +101,7 @@
* @return the new request
*/
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);
+ RestRequest r = getRequestFactory().getRequest(id, args);
return r;
}
Modified: trunk/src/main/java/org/nuiton/io/rest/RestRequest.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestRequest.java 2012-07-12 16:53:52 UTC (rev 844)
+++ trunk/src/main/java/org/nuiton/io/rest/RestRequest.java 2012-07-12 16:55:57 UTC (rev 845)
@@ -26,6 +26,7 @@
package org.nuiton.io.rest;
import java.io.File;
+import java.net.URL;
import java.util.Map;
/**
@@ -44,6 +45,21 @@
*/
String[] getParameters();
+ /**
+ * @return {@code true} if request has some attachments.
+ * @since 1.5
+ */
+ boolean containsAttachments();
+
/** @return the map of attachment to pass to request */
Map<String, File> getAttachments();
+
+ /**
+ * Obtain the full url of the request.
+ *
+ * @param baseUrl the base url to use
+ * @return the full url for this request
+ * @since 1.5
+ */
+ String toPath(URL baseUrl);
}
Modified: trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java 2012-07-12 16:53:52 UTC (rev 844)
+++ trunk/src/main/java/org/nuiton/io/rest/RestRequestBuilder.java 2012-07-12 16:55:57 UTC (rev 845)
@@ -25,13 +25,15 @@
package org.nuiton.io.rest;
+import java.io.Serializable;
+
/**
* The contract of a request builder.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 1.0.3
*/
-public interface RestRequestBuilder {
+public interface RestRequestBuilder extends Serializable {
/** @return the unique name of the request builder */
String getName();
Modified: trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java 2012-07-12 16:53:52 UTC (rev 844)
+++ trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java 2012-07-12 16:55:57 UTC (rev 845)
@@ -35,7 +35,6 @@
public enum DefaultDataConverter implements DataConverter {
Boolean {
-
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Boolean.valueOf(t);
@@ -43,7 +42,6 @@
}
},
Short {
-
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Short.valueOf(t);
@@ -51,7 +49,6 @@
}
},
Integer {
-
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Integer.valueOf(t);
@@ -59,7 +56,6 @@
}
},
Long {
-
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Long.valueOf(t);
@@ -67,7 +63,6 @@
}
},
Float {
-
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Float.valueOf(t);
@@ -75,7 +70,6 @@
}
},
Double {
-
@Override
public Object convert(String t) throws Exception {
Object r = java.lang.Double.valueOf(t);
@@ -83,7 +77,6 @@
}
},
Text {
-
@Override
public Object convert(String t) throws Exception {
return t;
Modified: trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2012-07-12 16:53:52 UTC (rev 844)
+++ trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2012-07-12 16:55:57 UTC (rev 845)
@@ -26,8 +26,8 @@
package org.nuiton.io.xpp3;
import com.google.common.base.Function;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
1
0
12 Jul '12
Author: tchemit
Date: 2012-07-12 18:53:52 +0200 (Thu, 12 Jul 2012)
New Revision: 844
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/844
Log:
fixes #925: Use maven-plugin-plugin 3 api
Modified:
trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java
trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java
trunk/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java
trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java
trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java
Modified: trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java 2012-07-09 10:20:16 UTC (rev 843)
+++ trunk/src/main/java/org/nuiton/helper/plugin/CheckAutoContainerPlugin.java 2012-07-12 16:53:52 UTC (rev 844)
@@ -37,6 +37,11 @@
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Proxy;
import org.apache.maven.wagon.ConnectionException;
@@ -59,13 +64,9 @@
*
* @author tchemit <chemit(a)codelutin.com>
* @version $Id$
- * @goal check-auto-container
- * @phase validate
- * @requiresProject true
- * @requiresOnline true
- * @requiresDependencyResolution runtime
* @since 1.2.5
*/
+@Mojo(name = "check-auto-container", defaultPhase = LifecyclePhase.VALIDATE, requiresProject = true, requiresOnline = true, requiresDependencyResolution = ResolutionScope.RUNTIME)
public class CheckAutoContainerPlugin extends AbstractPlugin {
/**
@@ -73,34 +74,34 @@
* <p/>
* Keys are repository id and Values are repository url.
*
- * @parameter
* @since 1.2.5
*/
+ @Parameter
protected Map<String, String> repositories;
/**
* A flag to add the maven central repository http://repo1.maven.org/maven2
* to {@link #repositories}.
*
- * @parameter expression="${addMavenCentral}" default-value="false"
* @since 1.2.5
*/
+ @Parameter(property = "addMavenCentral", defaultValue = "false")
protected boolean addMavenCentral;
/**
* A flag to fail if project is not auto container.
*
- * @parameter expression="${helper.failIfNotSafe}" default-value="false"
* @since 1.2.5
*/
+ @Parameter(property = "helper.failIfNotSafe", defaultValue = "false")
protected boolean failIfNotSafe;
/**
* A flag to activate verbose mode.
*
- * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
* @since 1.2.5
*/
+ @Parameter(property = "helper.verbose", defaultValue = "${maven.verbose}")
protected boolean verbose;
/**
@@ -109,88 +110,73 @@
* <b>Note:</b> By default, value is {@code true} since it is not necessary
* to check twice for a same artifact.
*
- * @parameter expression="${helper.runOnce}" default-value="true"
* @since 1.2.6
*/
+ @Parameter(property = "helper.runOnce", defaultValue = "true")
protected boolean runOnce;
/**
* Project.
*
- * @parameter default-value="${project}"
- * @required
- * @readonly
* @since 1.2.5
*/
+ @Component
protected MavenProject project;
/**
* The projects in reactor (used to detected sibling dependencies).
*
- * @parameter expression="${reactorProjects}"
- * @readonly
* @since 1.2.5
*/
+ @Parameter(property = "reactorProjects", readonly = true)
protected List<?> reactorProjects;
/**
* Active proxy from settings (if any).
*
- * @parameter default-value="${settings.activeProxy}"
- * @required
- * @readonly
* @since 1.2.5
*/
+ @Parameter(property = "settings.activeProxy", required = true, readonly = true)
protected Proxy proxy;
/**
* Local repository.
*
- * @parameter expression="${localRepository}"
- * @required
- * @readonly
* @since 1.2.5
*/
+ @Parameter(property = "localRepository", required = true, readonly = true)
protected ArtifactRepository localRepository;
/**
* Artifact repository factory component.
*
- * @component
- * @required
- * @readonly
* @since 1.2.5
*/
+ @Component
protected ArtifactRepositoryFactory artifactRepositoryFactory;
/**
* Artifact factory component.
*
- * @component
- * @required
- * @readonly
* @since 1.2.5
*/
+ @Component
protected ArtifactFactory factory;
/**
* Artifact resolver component.
*
- * @component
- * @required
- * @readonly
* @since 1.2.5
*/
+ @Component
protected ArtifactResolver resolver;
/**
* Wagon manager component.
*
- * @component
- * @required
- * @readonly
* @since 1.2.5
*/
+ @Component
protected WagonManager wagonManager;
/**
Modified: trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2012-07-09 10:20:16 UTC (rev 843)
+++ trunk/src/main/java/org/nuiton/helper/plugin/CollectFilesMojo.java 2012-07-12 16:53:52 UTC (rev 844)
@@ -25,11 +25,15 @@
package org.nuiton.helper.plugin;
+import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.nuiton.plugin.AbstractPlugin;
import org.nuiton.plugin.PluginHelper;
@@ -46,69 +50,57 @@
* Collect files some files from a project and copy them into a directory.
*
* @author tchemit <chemit(a)codelutin.com>
- * @goal collect-files
- * @requiresProject true
* @since 1.1.0
*/
+@Mojo(name = "collect-files", requiresProject = true)
public class CollectFilesMojo extends AbstractPlugin implements PluginWithEncoding {
/**
* The projects in the reactor.
*
- * @parameter expression="${reactorProjects}"
- * @readonly
* @since 1.2.4
*/
+ @Parameter(property = "reactorProjects", readonly = true, required = true)
protected List<?> reactorProjects;
/**
* Fallback maven project (for maven 2).
*
- * @parameter default-value="${project}"
- * @required
- * @readonly
* @since 1.0.3
*/
+ @Component
protected MavenProject project;
/**
* The artifacts to publish from the project build.
*
- * @parameter expression="${project.attachedArtifacts}"
- * @required
- * @readonly
* @since 1.0.0
*/
+ @Parameter(property = "project.attachedArtifacts", readonly = true, required = true)
protected List<?> attachedArtifacts;
/**
* The local repository.
*
- * @parameter expression="${localRepository}"
- * @required
- * @readonly
* @since 1.2.2
*/
+ @Parameter(property = "localRepository", readonly = true, required = true)
protected ArtifactRepository localRepository;
/**
* The remote repository.
*
- * @parameter expression="${project.distributionManagementArtifactRepository}"
- * @required
- * @readonly
* @since 1.2.2
*/
+ @Parameter(property = "project.distributionManagementArtifactRepository", readonly = true, required = true)
protected ArtifactRepository deploymentRepository;
/**
* Project artifact.
*
- * @parameter expression="${project.artifact}"
- * @required
- * @readonly
* @since 1.2.2
*/
+ @Parameter(property = "project.artifact", readonly = true, required = true)
protected Artifact artifact;
/**
@@ -116,9 +108,9 @@
* <p/>
* Multi values can be used, separated by comma.
*
- * @parameter expression="${helper.extraFiles}"
* @since 1.0.0
*/
+ @Parameter(property = "helper.extraFiles")
protected String extraFiles;
/**
@@ -126,9 +118,9 @@
* <p/>
* If no Set - no include filter
*
- * @parameter expression="${helper.includes}" default-value=""
* @since 1.0.0
*/
+ @Parameter(property = "helper.includes", defaultValue = "")
protected String includes;
/**
@@ -136,9 +128,9 @@
* <p/>
* If no Set - no exclude filter
*
- * @parameter expression="${helper.excludes}" default-value=""
* @since 1.0.0
*/
+ @Parameter(property = "helper.excludes", defaultValue = "")
protected String excludes;
/**
@@ -148,9 +140,9 @@
* 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
*/
+ @Parameter(property = "helper.outputDirectory", defaultValue = "target/collect")
protected String outputDirectory;
/**
@@ -158,66 +150,65 @@
* <p/>
* <b>Note :</b> If not Set, will not generate the description file.
*
- * @parameter expression="${helper.descriptionFile}"
* @since 1.0.0
*/
+ @Parameter(property = "helper.descriptionFile")
protected String descriptionFile;
/**
* Un flag pour collecter aussi les fichiers attaches au projet.
*
- * @parameter expression="${helper.includeAttached}" default-value="true"
* @since 1.0.0
*/
+ @Parameter(property = "helper.includeAttached", defaultValue = "true")
protected boolean includeAttached;
/**
* Un flag pour collecter aussi les fichiers des sites attaches au projet.
*
- * @parameter expression="${helper.includeSiteAttached}" default-value="false"
* @since 1.2.2
*/
+ @Parameter(property = "helper.includeSiteAttached", defaultValue = "false")
protected boolean includeSiteAttached;
/**
* Un flag pour recopier les fichiers collectés.
*
- * @parameter expression="${helper.copyFiles}" default-value="true"
* @since 1.0.0
*/
+ @Parameter(property = "helper.copyFiles", defaultValue = "true")
protected boolean copyFiles;
/**
* Un flag pour activer le mode verbeux.
*
- * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
* @since 1.0.0
*/
+ @Parameter(property = "helper.verbose", defaultValue = "${maven.verbose}")
protected boolean verbose;
/**
* A flag to skip the goal.
*
- * @parameter expression="${helper.skip}" default-value="false"
* @since 1.0.0
*/
+ @Parameter(property = "helper.skip", defaultValue = "false")
protected boolean skip;
/**
* Un flag pour activer le mode verbeux.
*
- * @parameter expression="${helper.dryRun}" default-value="false"
* @since 1.0.0
*/
+ @Parameter(property = "helper.dryRun", defaultValue = "false")
protected boolean dryRun;
/**
* Encoding a utiliser pour lire et ecrire les fichiers.
*
- * @parameter expression="${helper.encoding}" default-value="${project.build.sourceEncoding}"
- * @required
* @since 1.0.0
*/
+ @Parameter(property = "helper.encoding", defaultValue = "${project.build.sourceEncoding}", required = true)
protected String encoding;
/** Files to collect */
@@ -293,7 +284,7 @@
boolean withDescriptionFile = false;
- if (descriptionFile != null && !descriptionFile.trim().isEmpty()) {
+ if (StringUtils.isNotBlank(descriptionFile)) {
description = new File(rootProject.getBasedir(), descriptionFile);
@@ -389,11 +380,9 @@
protected List<File> getFiles() {
- Pattern includePattern = includes == null ||
- includes.trim().isEmpty() ? null :
+ Pattern includePattern = StringUtils.isBlank(includes) ? null :
Pattern.compile(includes.trim());
- Pattern excludePattern = excludes == null ||
- excludes.trim().isEmpty() ? null :
+ Pattern excludePattern = StringUtils.isBlank(excludes) ? null :
Pattern.compile(excludes.trim());
List<File> result = new ArrayList<File>();
@@ -423,7 +412,7 @@
// attach extra files
- if (extraFiles != null && !extraFiles.trim().isEmpty()) {
+ if (StringUtils.isNotBlank(extraFiles)) {
File basedir = project.getBasedir();
for (String path : extraFiles.split(",")) {
Modified: trunk/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java 2012-07-09 10:20:16 UTC (rev 843)
+++ trunk/src/main/java/org/nuiton/helper/plugin/ExecuteRemoteCommandMojo.java 2012-07-12 16:53:52 UTC (rev 844)
@@ -24,10 +24,14 @@
*/
package org.nuiton.helper.plugin;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
@@ -45,82 +49,54 @@
* Mojo to execute on a remote server some scripts.
*
* @author tchemit <chemit(a)codelutin.com>
- * @goal execute-remote-command
- * @phase validate
- * @requiresProject true
- * @requiresOnline true
* @since 1.3.1
*/
+@Mojo(name = "execute-remote-command", defaultPhase = LifecyclePhase.VALIDATE,
+ requiresOnline = true, requiresProject = true)
public class ExecuteRemoteCommandMojo extends AbstractPlugin {
- /**
- * A flag to activate verbose mode.
- *
- * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
- */
+ /** A flag to activate verbose mode. */
+ @Parameter(property = "helper.verbose", defaultValue = "${maven.verbose}")
protected boolean verbose;
- /**
- * Project.
- *
- * @parameter default-value="${project}"
- * @required
- * @readonly
- */
+ /** Project. */
+ @Component
protected MavenProject project;
- /**
- * Active proxy from settings (if any).
- *
- * @parameter default-value="${settings.activeProxy}"
- * @required
- * @readonly
- */
+ /** Active proxy from settings (if any). */
+ @Parameter(defaultValue = "${settings.activeProxy}", required = true, readonly = true)
protected Proxy proxy;
/**
* Settings.
*
- * @parameter default-value="${settings}"
- * @required
- * @readonly
* @since 1.1.0
*/
+ @Component
protected Settings settings;
/**
* Id of the server to use to obtain user login.
* <p/>
* Must be found in your settings.xml.
- *
- * @parameter expression="${helper.repositoryId}"
- * @required
*/
+ @Parameter(property = "helper.repositoryId", required = true)
protected String repositoryId;
/**
* Url where to execute script.
* <p/>
* The url must contains the wagon protocol (says scp:... or scpexe:...).
- *
- * @parameter expression="${helper.repositoryUrl}"
- * @required
*/
+ @Parameter(property = "helper.repositoryUrl", required = true)
protected String repositoryUrl;
- /**
- * Command to execute on remote server.
- *
- * @parameter expression="${helper.command}"
- * @required
- */
+ /** Command to execute on remote server. */
+ @Parameter(property = "helper.command", required = true)
protected String command;
- /**
- * Wagon manager component.
- *
- * @component
- */
+ /** Wagon manager component. */
+ @Component
protected WagonManager wagonManager;
private CommandExecutor commandExecutor;
@@ -145,7 +121,7 @@
if (server == null) {
throw new MojoExecutionException(
"Could not find server with id '" + repositoryId +
- "', check your settings.xml file.");
+ "', check your settings.xml file.");
}
Repository repository = new Repository(repositoryId, repositoryUrl);
@@ -157,7 +133,7 @@
throw new MojoExecutionException(
"The wagon " + wagon + " is not a command executor, " +
- "will not be able to execute command.");
+ "will not be able to execute command.");
}
commandExecutor = (CommandExecutor) wagon;
Modified: trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java 2012-07-09 10:20:16 UTC (rev 843)
+++ trunk/src/main/java/org/nuiton/helper/plugin/SendEmailMojo.java 2012-07-12 16:53:52 UTC (rev 844)
@@ -25,9 +25,12 @@
package org.nuiton.helper.plugin;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Developer;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
@@ -46,89 +49,81 @@
* Send a email.
*
* @author tchemit <chemit(a)codelutin.com>
- * @goal send-email
- * @requiresOnline true
- * @requiresProject true
* @since 1.0.3
*/
+@Mojo(name = "send-email", requiresOnline = true, requiresProject = true)
public class SendEmailMojo extends AbstractPlugin implements PluginWithEncoding {
/**
* Dependance du projet.
*
- * @parameter default-value="${project}"
- * @required
- * @readonly
* @since 1.0.3
*/
+ @Component
protected MavenProject project;
/**
* Un flag pour activer le mode verbeux.
*
- * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
* @since 1.0.3
*/
+ @Parameter(property = "helper.verbose", defaultValue = "${maven.verbose}")
protected boolean verbose;
/**
* The Velocity template used to format the email announcement.
*
- * @parameter expression="${helper.emailContentFile}"
- * @required
* @since 1.0.3
*/
+ @Parameter(property = "helper.emailContentFile", required = true)
protected File emailContentFile;
/**
* The title of the email to send.
*
- * @parameter expression="${helper.emailTitle}"
- * @required
* @since 1.0.3
*/
+ @Parameter(property = "helper.emailTitle", required = true)
protected String emailTitle;
/**
* Smtp Server.
*
- * @parameter expression="${helper.smtpHost}"
- * @required
* @since 1.0.3
*/
+ @Parameter(property = "helper.smtpHost", required = true)
protected String smtpHost;
/**
* Port.
*
- * @parameter default-value="25" expression="${helper.smtpPort}"
- * @required
* @since 1.0.3
*/
+ @Parameter(property = "helper.smtpPort", defaultValue = "25", required = true)
protected int smtpPort;
/**
* The username used to send the email.
*
- * @parameter expression="${helper.username}"
* @since 1.0.3
*/
+ @Parameter(property = "helper.username")
protected String username;
/**
* The password used to send the email.
*
- * @parameter expression="${helper.password}"
* @since 1.0.3
*/
+ @Parameter(property = "helper.password")
protected String password;
/**
* If the email should be sent in SSL mode.
*
- * @parameter default-value="false" expression="${helper.sslMode}"
* @since 1.0.3
*/
+ @Parameter(property = "helper.sslMode", defaultValue = "false")
protected boolean sslMode;
/**
@@ -138,78 +133,74 @@
* developer is not found, then the first developer in the pom will be
* used.
*
- * @parameter expression="${helper.fromDeveloperId}"
* @since 1.0.3
*/
+ @Parameter(property = "helper.fromDeveloperId")
protected String fromDeveloperId;
/**
* Defines the sender of the announcement if the list of developer is empty
* or if the sender is not a member of the development team.
*
- * @parameter expression="${helper.mailSender}"
* @since 1.0.3
*/
+ @Parameter(property = "helper.mailSender")
protected MailSender mailSender;
/**
* Recipient email address.
*
- * @parameter
- * @required
* @since 1.0.3
*/
+ @Parameter(required = true)
protected List<String> toAddresses;
/**
* Possible senders.
*
- * @parameter expression="${project.developers}"
- * @required
- * @readonly
* @since 1.0.3
*/
+ @Parameter(property = "project.developers", required = true, readonly = true)
protected List<Developer> from;
/**
* Mail content type to use.
*
- * @parameter default-value="text/plain"
- * @required
* @since 1.0.3
*/
+ @Parameter(defaultValue = "text/plain", required = true)
protected String mailContentType;
/**
* The encoding used to read and write files.
*
- * @parameter expression="${helper.encoding}" default-value="${project.build.sourceEncoding}"
* @since 1.0.3
*/
+ @Parameter(property = "helper.encoding", defaultValue = "${project.build.sourceEncoding}")
protected String encoding;
/**
* A flag to skip the goal.
*
- * @parameter expression="${helper.skipSendEmail}" default-value="false"
* @since 1.0.3
*/
+ @Parameter(property = "helper.skipSendEmail", defaultValue = "false")
protected boolean skipSendEmail;
/**
* A flag to test plugin but send nothing to redmine.
*
- * @parameter expression="${dryRun}" default-value="false"
* @since 1.0.3
*/
+ @Parameter(property = "dryRun", defaultValue = "false")
protected boolean dryRun;
/**
* A flag to restirct only one run in a build (for multi-module context).
*
- * @parameter expression="${redmine.runOnce}" default-value="true"
* @since 1.0.3
*/
+ @Parameter(property = "redmine.runOnce", defaultValue = "true")
protected boolean runOnce;
/**
Modified: trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2012-07-09 10:20:16 UTC (rev 843)
+++ trunk/src/main/java/org/nuiton/helper/plugin/ShareServerSecretPlugin.java 2012-07-12 16:53:52 UTC (rev 844)
@@ -25,8 +25,12 @@
package org.nuiton.helper.plugin;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
@@ -51,50 +55,47 @@
* </pre>
*
* @author tchemit <chemit(a)codelutin.com>
- * @goal share-server-secret
- * @phase initialize
- * @requiresProject true
* @since 1.1.0
*/
+@Mojo(name = "share-server-secret", defaultPhase = LifecyclePhase.INITIALIZE, requiresProject = true)
public class ShareServerSecretPlugin extends AbstractPlugin {
/**
* Project.
*
- * @parameter default-value="${project}"
- * @required
- * @readonly
* @since 1.1.0
*/
+ @Component
protected MavenProject project;
+
/**
* Settings.
*
- * @parameter default-value="${settings}"
- * @required
- * @readonly
* @since 1.1.0
*/
+ @Component
protected Settings settings;
+
/**
* 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}"
- * @required
* @since 1.1.0
*/
+ @Parameter(property = "helper.serverId", required = true)
protected String serverId;
+
/**
* The name of the property where to export the username of the server.
* <p/>
* <b>Note:</b> If not set - then no export of the username of the server.
*
- * @parameter
* @since 1.1.0
*/
+ @Parameter
protected String usernameOut;
+
/**
* The name of the property where to export the password of the server.
* <p/>
@@ -103,10 +104,11 @@
* <b>Note:</b> If the password is crypted (since maven 2.1.0) then
* decrypt it.
*
- * @parameter
* @since 1.1.0
*/
+ @Parameter
protected String passwordOut;
+
/**
* The name of the property where to export the passphrase of the server.
* <p/>
@@ -115,50 +117,52 @@
* <b>Note:</b> If the passphrase is crypted (since maven 2.1.0) then
* decrypt it.
*
- * @parameter
* @since 1.1.0
*/
+ @Parameter
protected String passphraseOut;
+
/**
* The name of the property where to export the private key of the server.
* <p/>
* <b>Note:</b> If not set - then no export of the private key of the server.
*
- * @parameter
* @since 1.1.0
*/
+ @Parameter
protected String privateKeyOut;
+
/**
* A flag to activate verbose mode.
*
- * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
* @since 1.1.0
*/
+ @Parameter(property = "helper.verbose", defaultValue = "${maven.verbose}")
protected boolean verbose;
+
/**
* A flag to execute only once the mojo.
* <p/>
* <b>Note:</b> By default, value is {@code true} since it is not necessary
* to inject twice secrets in session.
*
- * @parameter expression="${helper.runOnce}" default-value="true"
* @since 1.1.0
*/
+ @Parameter(property = "helper.runOnce", defaultValue = "true")
protected boolean runOnce;
+
/**
* password decypher
*
- * @component roleHint="maven-helper-plugin"
* @since 1.1.0
*/
+ @Component(hint = "maven-helper-plugin")
protected SecDispatcher sec;
- /**
- * the server to use to obtain secrets
- */
+
+ /** the server to use to obtain secrets */
private Server server;
- /**
- * server secrets to expose
- */
+
+ /** server secrets to expose */
private Map<Property, String> propertiesToTreate;
public enum Property {
1
0
Author: tchemit
Date: 2012-07-09 12:20:16 +0200 (Mon, 09 Jul 2012)
New Revision: 843
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/843
Log:
updates to mavenpom 3.3.4
refs #925: Use maven-plugin-plugin 3 api (change pom)
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-05-30 10:15:07 UTC (rev 842)
+++ trunk/pom.xml 2012-07-09 10:20:16 UTC (rev 843)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.3.2</version>
+ <version>3.3.4</version>
</parent>
<artifactId>helper-maven-plugin</artifactId>
@@ -154,7 +154,15 @@
<scope>provided</scope>
</dependency>
+ <!-- dependencies to mojo annotations -->
<dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>${pluginPluginVersion}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.4</version>
@@ -317,6 +325,21 @@
<plugins>
<plugin>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <configuration>
+ <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>helpmojo</goal>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
@@ -378,6 +401,33 @@
</reportSet>
</reportSets>
</plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadocPluginVersion}</version>
+ <configuration>
+ <quiet>true</quiet>
+ <tagletArtifacts>
+ <tagletArtifact>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-javadoc</artifactId>
+ <version>${pluginPluginVersion}</version>
+ </tagletArtifact>
+ <tagletArtifact>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-javadoc</artifactId>
+ <version>1.5.5</version>
+ </tagletArtifact>
+ </tagletArtifacts>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>javadoc</report>
+ <report>test-javadoc</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
</plugins>
</reporting>
</profile>
1
0
Author: ymartel
Date: 2012-05-30 12:15:07 +0200 (Wed, 30 May 2012)
New Revision: 842
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/842
Log:
update to mavenpom 3.3.2
Modified:
trunk/
trunk/pom.xml
trunk/src/site/site_en.xml
Property changes on: trunk
___________________________________________________________________
Modified: svn:ignore
- *.ipr
*.iws
*.iml
*.log
.project
.classpath
.settings
target
+ *.ipr
*.iws
*.iml
*.log
.project
.classpath
.settings
target
.idea
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-03-25 14:23:27 UTC (rev 841)
+++ trunk/pom.xml 2012-05-30 10:15:07 UTC (rev 842)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.2</version>
+ <version>3.3.2</version>
</parent>
<artifactId>helper-maven-plugin</artifactId>
@@ -226,7 +226,7 @@
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
- <name>Maven helper plugin</name>
+ <name>Helper Maven Plugin</name>
<description>Plugin d'aide pour les projets nuiton</description>
<inceptionYear>2009</inceptionYear>
<url>http://maven-site.nuiton.org/maven-helper-plugin</url>
@@ -235,7 +235,7 @@
<developer>
<name>Tony Chemit</name>
<id>tchemit</id>
- <email>chemit(a)codelutin.com</email>
+ <email>chemit at codelutin dot com</email>
<organization>CodeLutin</organization>
<timezone>+2</timezone>
<roles>
@@ -243,6 +243,16 @@
<role>Developer</role>
</roles>
</developer>
+ <developer>
+ <name>Yannick Martel</name>
+ <id>ymartel</id>
+ <email>martel at codelutin dot com</email>
+ <organization>CodeLutin</organization>
+ <timezone>+2</timezone>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ </developer>
</developers>
<!-- ************************************************************* -->
@@ -346,6 +356,28 @@
<version>${coberturaPluginVersion}</version>
</plugin>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <version>${projectInfoReportsPluginVersion}</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>project-team</report>
+ <report>mailing-list</report>
+ <report>cim</report>
+ <report>issue-tracking</report>
+ <report>license</report>
+ <report>scm</report>
+ <report>dependencies</report>
+ <report>dependency-convergence</report>
+ <report>plugin-management</report>
+ <report>plugins</report>
+ <report>dependency-management</report>
+ <report>summary</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
</plugins>
</reporting>
</profile>
Modified: trunk/src/site/site_en.xml
===================================================================
--- trunk/src/site/site_en.xml 2012-03-25 14:23:27 UTC (rev 841)
+++ trunk/src/site/site_en.xml 2012-05-30 10:15:07 UTC (rev 842)
@@ -31,6 +31,30 @@
<href>index.html</href>
</bannerLeft>
+ <bannerRight>
+ <src>http://www.codelutin.com/images/lutinorange-codelutin.png</src>
+ <href>http://www.codelutin.com</href>
+ </bannerRight>
+
+ <skin>
+ <groupId>org.apache.maven.skins</groupId>
+ <artifactId>maven-fluido-skin</artifactId>
+ <version>1.2.1</version>
+ </skin>
+
+ <custom>
+ <fluidoSkin>
+ <topBarEnabled>true</topBarEnabled>
+ <googleSearch/>
+ <sideBarEnabled>false</sideBarEnabled>
+ <searchEnabled>true</searchEnabled>
+ <sourceLineNumbersEnabled>true</sourceLineNumbersEnabled>
+ </fluidoSkin>
+ </custom>
+
+ <publishDate position="right" format="dd/MM/yyyy"/>
+ <version position="right"/>
+
<poweredBy>
<logo href="http://maven.apache.org" name="Maven"
img="images/logos/maven-feather.png"/>
@@ -42,6 +66,12 @@
<item name="${project.name}" href="index.html"/>
</breadcrumbs>
+ <links>
+ <item name="nuiton.org" href="http://www.nuiton.org"/>
+ <item name="CodeLutin" href="http://codelutin.com"/>
+ <item name="Libre-Entreprise" href="http://www.libre-entreprise.org/"/>
+ </links>
+
<menu name="User">
<item name="Introduction" href="index.html"/>
<item name="Goals" href="plugin-info.html">
@@ -86,5 +116,24 @@
<menu ref="reports"/>
+ <footer>
+
+ <script type="text/javascript"
+ src="http://maven-site.nuiton.org/public/js/maven-site-nuiton.org.js">
+ </script>
+
+ <div id='projectMetas'
+ projectversion='${project.version}'
+ platform='${project.platform}'
+ projectid='${project.projectId}'
+ scm='${project.scm.connection}'
+ scmwebeditorenabled='${project.scmwebeditorEnabled}'
+ scmwebeditorurl='${project.scmwebeditorUrl}'
+ siteSourcesType='${project.siteSourcesType}'
+ piwikEnabled='${project.piwikEnabled}'
+ piwikId='${project.piwikId}'>
+ </div>
+ </footer>
+
</body>
</project>
1
0
r841 - in trunk: . src/main/java/org/nuiton/io/xpp3 src/test/java/org/nuiton/io/xpp3 src/test/resources/org/nuiton/io/xpp3
by tchemit@users.nuiton.org 25 Mar '12
by tchemit@users.nuiton.org 25 Mar '12
25 Mar '12
Author: tchemit
Date: 2012-03-25 16:23:27 +0200 (Sun, 25 Mar 2012)
New Revision: 841
Url: http://nuiton.org/repositories/revision/maven-helper-plugin/841
Log:
fixes #2031 (improve the xpp3 reader api)
Added:
trunk/src/main/java/org/nuiton/io/xpp3/AttributeValueToProperty.java
trunk/src/main/java/org/nuiton/io/xpp3/TagContentToProperty.java
trunk/src/main/java/org/nuiton/io/xpp3/TagTextContentToProperty.java
trunk/src/test/java/org/nuiton/io/xpp3/CountryRef.java
trunk/src/test/java/org/nuiton/io/xpp3/CountryRefXpp3Reader.java
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java
trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java
trunk/src/test/java/org/nuiton/io/xpp3/Identity.java
trunk/src/test/java/org/nuiton/io/xpp3/IdentityXpp3Reader.java
trunk/src/test/java/org/nuiton/io/xpp3/Xpp3ReaderTest.java
trunk/src/test/resources/org/nuiton/io/xpp3/identities.xml
trunk/src/test/resources/org/nuiton/io/xpp3/identities2.xml
trunk/src/test/resources/org/nuiton/io/xpp3/identity.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/pom.xml 2012-03-25 14:23:27 UTC (rev 841)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.1.1</version>
+ <version>3.2</version>
</parent>
<artifactId>helper-maven-plugin</artifactId>
@@ -46,6 +46,11 @@
<!-- compile dependencies -->
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
Modified: trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -25,6 +25,7 @@
package org.nuiton.io.xpp3;
+import com.google.common.collect.Sets;
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -33,8 +34,13 @@
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Array;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
/**
* An abstract xpp3Reader based on {@link PropertyMapper} to set properties of
@@ -54,8 +60,8 @@
* <p/>
* If you want to do something more complex, override these methods.
*
+ * @param <O> the type of object to be build by the reader
* @author tchemit <chemit(a)codelutin.com>
- * @param <O> the type of object to be build by the reader
* @see PropertyMapper
* @see Xpp3Reader
* @since 1.0.0
@@ -249,6 +255,34 @@
}
/**
+ * Obtain all mappers for a given type.
+ * <p/>
+ * In the result, the keys are now the tag-name of attribute-name.
+ * <p/>
+ * Example :
+ * <pre>
+ * my-tag
+ * my-attribute
+ * </pre>
+ *
+ * @param srcType the target type of the searched mappers
+ * @param tagName the tag target of the searched mappers
+ * @return the dictionnary of mappers for the given type.
+ */
+ public Map<String, PropertyMapper> getMappers(Class<?> srcType, String tagName) {
+ Map<String, PropertyMapper> result =
+ new TreeMap<String, PropertyMapper>();
+ String prefix = srcType.getName() + "#" + tagName + "#";
+ for (Entry<String, PropertyMapper> e : allMappers.entrySet()) {
+ if (e.getKey().startsWith(prefix)) {
+
+ result.put(((AttributeValueToProperty) e.getValue()).getAttributeName(), e.getValue());
+ }
+ }
+ return result;
+ }
+
+ /**
* Parse the xml stream from the given parser and a build the associated
* object.
* <p/>
@@ -279,17 +313,17 @@
* @throws IOException if any io pb
* @throws XmlPullParserException if any parsing pb
*/
- protected <T> T read(String rootTagName,
- Class<T> type,
- XmlPullParser parser,
- boolean strict)
+ public <T> T read(String rootTagName,
+ Class<T> type,
+ XmlPullParser parser,
+ boolean strict)
throws XmlPullParserException, IOException {
// search open tag rootTagName
gotoNextOpenTag(rootTagName, parser);
// can init result
- T result = null;
+ T result;
try {
result = type.newInstance();
} catch (Exception ex) {
@@ -303,6 +337,20 @@
Map<String, PropertyMapper> mappers = getMappers(type);
Set<String> parsed = new HashSet<String>();
+
+ // deal with all attributes
+ {
+ Set<String> attributeParsed = Sets.newHashSet();
+ Map<String, PropertyMapper> attributeMappers = getMappers(type, rootTagName);
+ int attributeCount = parser.getAttributeCount();
+ for (int i = 0; i < attributeCount; i++) {
+ String attributeName = parser.getAttributeName(i);
+ PropertyMapper mapper = attributeMappers.get(attributeName);
+ if (mapper != null) {
+ mapper.setProperty(result, parser, attributeParsed, strict);
+ }
+ }
+ }
try {
// go to next tag
int eventType = parser.next();
@@ -312,7 +360,6 @@
checkNotEndOfXml(parser, rootTagName);
if (eventType == XmlPullParser.START_TAG) {
-// System.out.println("reading tag " + parser.getName());
PropertyMapper mapper = mappers.get(parser.getName());
if (mapper != null) {
mapper.setProperty(result, parser, parsed, strict);
@@ -321,6 +368,20 @@
"Unrecognised tag: '" + parser.getName()
+ "'", parser, null);
}
+
+ // deal with all attributes
+ {
+ Set<String> attributeParsed = Sets.newHashSet();
+ Map<String, PropertyMapper> attributeMappers = getMappers(type, rootTagName);
+ int attributeCount = parser.getAttributeCount();
+ for (int i = 0; i < attributeCount; i++) {
+ String attributeName = parser.getAttributeName(i);
+ PropertyMapper attributeMapper = attributeMappers.get(attributeName);
+ if (attributeMapper != null) {
+ attributeMapper.setProperty(result, parser, attributeParsed, strict);
+ }
+ }
+ }
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(rootTagName)) {
// have reach the end of the object
@@ -376,11 +437,11 @@
* @throws IOException if any io pb
* @throws XmlPullParserException if any parsing pb
*/
- protected <T> T[] readArray(String parentRootTagName,
- String rootTagName,
- Class<T> type,
- XmlPullParser parser,
- boolean strict)
+ public <T> T[] readArray(String parentRootTagName,
+ String rootTagName,
+ Class<T> type,
+ XmlPullParser parser,
+ boolean strict)
throws XmlPullParserException, IOException {
// search open tag parentRootTagName
@@ -501,4 +562,57 @@
parser.getName());
}
}
+
+ protected void addTagTextContentMappers(DataConverter type,
+ boolean onlyOne,
+ String... tagNames) throws IntrospectionException {
+ TagTextContentToProperty.addMapper(
+ getType(),
+ type,
+ onlyOne,
+ allMappers,
+ tagNames
+ );
+ }
+
+ protected void addAttributeValueMappers(DataConverter type,
+ boolean onlyOne,
+ String... attributeNames) throws IntrospectionException {
+ AttributeValueToProperty.addMapper(
+ getType(),
+ type,
+ onlyOne,
+ allMappers,
+ getRootTagName(),
+ attributeNames
+ );
+ }
+
+ protected <O> void addTagContentMapper(Class<O> type,
+ boolean onlyOne,
+ Xpp3Reader<O> reader) throws IntrospectionException {
+ TagContentToProperty.addMapper(
+ getType(),
+ type,
+ onlyOne,
+ allMappers,
+ reader.getRootTagName(),
+ reader,
+ false
+ );
+ }
+
+ protected <O> void addTagContentsMapper(Class<O> type,
+ boolean onlyOne,
+ Xpp3Reader<O> reader) throws IntrospectionException {
+ TagContentToProperty.addMapper(
+ getType(),
+ type,
+ onlyOne,
+ allMappers,
+ reader.getArrayRootTagName(),
+ reader,
+ true
+ );
+ }
}
Added: trunk/src/main/java/org/nuiton/io/xpp3/AttributeValueToProperty.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/AttributeValueToProperty.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/xpp3/AttributeValueToProperty.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -0,0 +1,109 @@
+/*
+ * #%L
+ * Maven helper plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 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>.
+ * #L%
+ */
+package org.nuiton.io.xpp3;
+
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.util.Map;
+
+/**
+ * Property mapper from a attribute content.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class AttributeValueToProperty extends PropertyMapper {
+
+ protected final String attributeName;
+
+ public AttributeValueToProperty(String tagName,
+ String attributeName,
+ String propertyName,
+ Class<?> containerType,
+ DataConverter type,
+ boolean onlyOne,
+ PropertyDescriptor descriptor) {
+ super(tagName,
+ propertyName,
+ containerType,
+ type,
+ onlyOne,
+ descriptor
+ );
+ this.attributeName = attributeName;
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ protected String getXmlName() {
+ return attributeName;
+ }
+
+ @Override
+ protected Object getDataFromXml(XmlPullParser parser)
+ throws Exception {
+ String t = parser.getAttributeValue("", attributeName);
+ Object result = null;
+ if (t != null && !(t = t.trim()).isEmpty()) {
+ result = type.convert(t);
+ }
+ return result;
+ }
+
+ public static void addMapper(Class<?> containerType,
+ DataConverter type,
+ boolean onlyOne,
+ Map<String, PropertyMapper> allMappers,
+ String tagName,
+ String... attributeNames) throws IntrospectionException,
+ IllegalArgumentException {
+
+ for (String attributeName : attributeNames) {
+
+ // the tag-name is transformed to tagName
+ String propertyName = TAG_NAME_TRANSFORMER.apply(attributeName);
+
+ PropertyDescriptor descriptor = getDescriptor(containerType,
+ propertyName);
+
+ PropertyMapper mapper = new AttributeValueToProperty(
+ tagName,
+ attributeName,
+ propertyName,
+ containerType,
+ type,
+ onlyOne,
+ descriptor
+ );
+ mapper.registerMapper(allMappers, containerType, tagName, attributeName);
+ }
+
+ }
+
+}
Property changes on: trunk/src/main/java/org/nuiton/io/xpp3/AttributeValueToProperty.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -25,10 +25,17 @@
package org.nuiton.io.xpp3;
+import com.google.common.base.Function;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.text.ParseException;
@@ -46,78 +53,16 @@
* <li>{@link AttributeValueToProperty} to map the text content of a tag
* to a pojo's property</li>
* </ul>
- * <p/>
- * There is two convinient factory methods in {@link Xpp3Helper} to add some new mappers into a given
- * dictionnary of mappers.
- * <ul>
- * <li> {@link Xpp3Helper#addTagTextContentMappers(Class, DataConverter, boolean, Map, String...)}</li>
- * <li>{@link Xpp3Helper#addAttributeValueMappers(Class, DataConverter, boolean, Map, String...)}</li>
- * </ul>
*
* @author tchemit <chemit(a)codelutin.com>
* @since 1.0.3
*/
public abstract class PropertyMapper {
- public static class TagTextContentToProperty extends PropertyMapper {
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(PropertyMapper.class);
- public TagTextContentToProperty(String tagName,
- String propertyName,
- Class<?> containerType,
- DataConverter type,
- boolean onlyOne,
- PropertyDescriptor descriptor) {
- super(tagName,
- propertyName,
- containerType,
- type,
- onlyOne,
- descriptor
- );
- }
-
- @Override
- protected Object getDataFromXml(XmlPullParser parser)
- throws Exception {
- String t = parser.nextText();
- Object result = null;
- if (t != null && !(t = t.trim()).isEmpty()) {
- result = type.convert(t);
- }
- return result;
- }
- }
-
- public static class AttributeValueToProperty extends PropertyMapper {
-
- public AttributeValueToProperty(String tagName,
- String propertyName,
- Class<?> containerType,
- DataConverter type,
- boolean onlyOne,
- PropertyDescriptor descriptor) {
- super(tagName,
- propertyName,
- containerType,
- type,
- onlyOne,
- descriptor
- );
- }
-
- @Override
- protected Object getDataFromXml(XmlPullParser parser)
- throws Exception {
- String t = parser.getAttributeValue("", name);
- Object result = null;
- if (t != null && !(t = t.trim()).isEmpty()) {
- result = type.convert(t);
- }
- return result;
- }
- }
-
- /** name of tag (or attribute to deal with) */
+ /** name of tag. */
protected final String name;
/** the pojo's property to set */
@@ -152,6 +97,10 @@
this.descriptor = descriptor;
}
+ protected String getXmlName() {
+ return name;
+ }
+
protected abstract Object getDataFromXml(XmlPullParser parser)
throws Exception;
@@ -159,15 +108,18 @@
XmlPullParser parser,
Set<String> parsed, boolean strict)
throws XmlPullParserException, IOException {
- if (onlyOne && parsed.contains(name)) {
+ if (onlyOne && parsed.contains(getXmlName())) {
throw new XmlPullParserException(
"Duplicated tag: \'" + parser.getName() + "\'",
parser,
null
);
}
- parsed.add(name);
+ parsed.add(getXmlName());
try {
+ if (log.isInfoEnabled()) {
+ log.info(getXmlName());
+ }
Object r = getDataFromXml(parser);
if (r != null) {
descriptor.getWriteMethod().invoke(src, r);
@@ -183,7 +135,7 @@
throw new XmlPullParserException(e.getMessage());
}
} catch (Exception e) {
- throw new XmlPullParserException(e.getMessage());
+ throw new XmlPullParserException(e.getMessage(), parser, e);
}
}
@@ -225,4 +177,72 @@
toStringBuilder.append("containerType", containerType);
return toStringBuilder.toString();
}
+
+ public static final Function<String, String> TAG_NAME_TRANSFORMER = new Function<String, String>() {
+ @Override
+ public String apply(String input) {
+ String[] parts = input.split("-");
+ StringBuilder buffer = new StringBuilder();
+ for (int i = 0, j = parts.length; i < j; i++) {
+ if (i == 0) {
+ buffer.append(parts[i]);
+ } else {
+ buffer.append(StringUtils.capitalize(parts[i]));
+ }
+ }
+ parts = buffer.toString().split("_");
+ buffer = new StringBuilder();
+ for (int i = 0, j = parts.length; i < j; i++) {
+ if (i == 0) {
+ buffer.append(parts[i]);
+ } else {
+ buffer.append(StringUtils.capitalize(parts[i]));
+ }
+ }
+ String result = buffer.toString();
+ return result;
+ }
+ };
+
+ public static String getMapperForTag(Class<?> type) {
+ return type.getName() + "#";
+ }
+
+ public static String getMapperForAttribute(Class<?> type, String attributeName) {
+ return type.getName() + "#" + attributeName + "#";
+ }
+
+ protected static PropertyDescriptor getDescriptor(Class<?> containerType,
+ String propertyName) throws IntrospectionException {
+ BeanInfo beanInfo = Introspector.getBeanInfo(containerType);
+ PropertyDescriptor descriptor = null;
+ for (PropertyDescriptor propertyDescriptor :
+ beanInfo.getPropertyDescriptors()) {
+ if (propertyDescriptor.getName().equals(propertyName)) {
+ descriptor = propertyDescriptor;
+ break;
+ }
+ }
+ if (descriptor == null) {
+ throw new IllegalArgumentException(
+ "could not find a property descriptor for property " +
+ propertyName + " of " + containerType);
+ }
+ return descriptor;
+ }
+
+ protected void registerMapper(Map<String, PropertyMapper> allMappers,
+ Class<?> containerType,
+ String tagName,
+ String attributeName) {
+ String key;
+ if (attributeName == null) {
+ // tag scope
+ key = getMapperForTag(containerType) + tagName;
+ } else {
+ // attribute scope
+ key = getMapperForAttribute(containerType, tagName) + attributeName;
+ }
+ allMappers.put(key, this);
+ }
}
Added: trunk/src/main/java/org/nuiton/io/xpp3/TagContentToProperty.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/TagContentToProperty.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/xpp3/TagContentToProperty.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -0,0 +1,118 @@
+/*
+ * #%L
+ * Maven helper plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 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>.
+ * #L%
+ */
+package org.nuiton.io.xpp3;
+
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.util.Map;
+
+/**
+ * Property mapper from a tag content to an object.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class TagContentToProperty<O> extends PropertyMapper {
+
+ private final Xpp3Reader<O> reader;
+
+ private final Class<O> datatype;
+
+ private final boolean multiple;
+
+ public TagContentToProperty(String tagName,
+ String propertyName,
+ Class<?> containerType,
+ Class<O> type,
+ boolean onlyOne,
+ PropertyDescriptor descriptor,
+ Xpp3Reader<O> reader,
+ boolean multiple) {
+ super(tagName,
+ propertyName,
+ containerType,
+ null,
+ onlyOne,
+ descriptor
+ );
+ datatype = type;
+ this.reader = reader;
+ this.multiple = multiple;
+ }
+
+ @Override
+ protected Object getDataFromXml(XmlPullParser parser)
+ throws Exception {
+ Object result;
+ if (multiple) {
+ result = reader.readArray(
+ reader.getArrayRootTagName(),
+ reader.getRootTagName(),
+ datatype,
+ parser,
+ true
+ );
+ } else {
+ result = reader.read(
+ reader.getRootTagName(),
+ datatype,
+ parser,
+ true
+ );
+ }
+ return result;
+ }
+
+ public static <O> void addMapper(Class<?> containerType,
+ Class<O> type,
+ boolean onlyOne,
+ Map<String, PropertyMapper> allMappers,
+ String tagName,
+ Xpp3Reader<O> reader,
+ boolean multiple
+ ) throws IntrospectionException,
+ IllegalArgumentException {
+
+ // the tag-name is transformed to tagName
+ String propertyName = TAG_NAME_TRANSFORMER.apply(tagName);
+
+ PropertyDescriptor descriptor = getDescriptor(containerType,
+ propertyName);
+
+ PropertyMapper mapper = new TagContentToProperty<O>(
+ tagName,
+ propertyName,
+ containerType,
+ type,
+ onlyOne,
+ descriptor,
+ reader,
+ multiple
+ );
+ mapper.registerMapper(allMappers, containerType, tagName, null);
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/xpp3/TagContentToProperty.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/src/main/java/org/nuiton/io/xpp3/TagTextContentToProperty.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/TagTextContentToProperty.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/xpp3/TagTextContentToProperty.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -0,0 +1,92 @@
+/*
+ * #%L
+ * Maven helper plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 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>.
+ * #L%
+ */
+package org.nuiton.io.xpp3;
+
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.util.Map;
+
+/**
+ * Property mapp from a tag text content.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class TagTextContentToProperty extends PropertyMapper {
+
+ public TagTextContentToProperty(String tagName,
+ String propertyName,
+ Class<?> containerType,
+ DataConverter type,
+ boolean onlyOne,
+ PropertyDescriptor descriptor) {
+ super(tagName,
+ propertyName,
+ containerType,
+ type,
+ onlyOne,
+ descriptor
+ );
+ }
+
+ @Override
+ protected Object getDataFromXml(XmlPullParser parser)
+ throws Exception {
+ String t = parser.nextText();
+ Object result = null;
+ if (t != null && !(t = t.trim()).isEmpty()) {
+ result = type.convert(t);
+ }
+ return result;
+ }
+
+ public static void addMapper(Class<?> containerType,
+ DataConverter type,
+ boolean onlyOne,
+ Map<String, PropertyMapper> allMappers,
+ String... tagNames) throws IntrospectionException {
+ for (String tagName : tagNames) {
+
+ // the tag-name is transformed to tagName
+ String propertyName = TAG_NAME_TRANSFORMER.apply(tagName);
+
+ PropertyDescriptor descriptor = getDescriptor(containerType,
+ propertyName);
+
+
+ PropertyMapper mapper = new TagTextContentToProperty(
+ tagName,
+ propertyName,
+ containerType,
+ type,
+ onlyOne,
+ descriptor
+ );
+ mapper.registerMapper(allMappers, containerType, tagName, null);
+ }
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/xpp3/TagTextContentToProperty.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -25,25 +25,16 @@
package org.nuiton.io.xpp3;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import org.nuiton.io.xpp3.PropertyMapper.AttributeValueToProperty;
-import org.nuiton.io.xpp3.PropertyMapper.TagTextContentToProperty;
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -60,6 +51,7 @@
* @since 1.0.3
*/
public class Xpp3Helper {
+
/** Logger */
private static final Log log = LogFactory.getLog(Xpp3Helper.class);
@@ -194,7 +186,7 @@
/**
* Clean all the registred readers.
* <p/>
- * To reload them, just call a {@link #getReader(java.lang.Class)}.
+ * To reload them, just call a {@link #getReader(Class)}.
*/
public static void clearReaders() {
if (readers != null) {
@@ -477,111 +469,6 @@
parser.defineEntityReplacementText("diams", "\u2666");
}
- public static void addTagTextContentMappers(
- Class<?> containerType,
- DataConverter type,
- boolean onlyOne,
- Map<String, PropertyMapper> allMappers,
- String... tagNames) throws IntrospectionException {
- try {
- addMappers(TagTextContentToProperty.class,
- containerType,
- type,
- onlyOne,
- allMappers,
- tagNames
- );
- } catch (Exception ex) {
- throw new RuntimeException(
- "could not addMappers for reason : " + ex.getMessage(), ex);
- }
- }
-
- public static void addAttributeValueMappers(
- Class<?> containerType,
- DataConverter type,
- boolean onlyOne,
- Map<String, PropertyMapper> allMappers,
- String... tagNames) throws IntrospectionException {
- try {
- addMappers(AttributeValueToProperty.class,
- containerType,
- type,
- onlyOne,
- allMappers,
- tagNames
- );
- } catch (Exception ex) {
- throw new RuntimeException(
- "could not addMappers for reason : " + ex.getMessage(), ex);
- }
- }
-
- protected static void addMappers(
- Class<? extends PropertyMapper> mapperClass,
- Class<?> containerType,
- DataConverter type,
- boolean onlyOne,
- Map<String, PropertyMapper> allMappers,
- String... tagNames)
- throws IntrospectionException,
- NoSuchMethodException,
- InstantiationException,
- IllegalAccessException,
- IllegalArgumentException,
- InvocationTargetException {
- for (String tagName : tagNames) {
-
- // the tag-name is transformed to tagName
- String[] parts = tagName.split("-");
- StringBuilder buffer = new StringBuilder();
- for (int i = 0, j = parts.length; i < j; i++) {
- if (i == 0) {
- buffer.append(parts[i]);
- } else {
- buffer.append(StringUtils.capitalize(parts[i]));
- }
- }
- String propertyName = buffer.toString();
- BeanInfo beanInfo = Introspector.getBeanInfo(containerType);
- PropertyDescriptor descriptor = null;
- for (PropertyDescriptor propertyDescriptor :
- beanInfo.getPropertyDescriptors()) {
- if (propertyDescriptor.getName().equals(propertyName)) {
- descriptor = propertyDescriptor;
- break;
- }
- }
- if (descriptor == null) {
- throw new IllegalArgumentException(
- "could not find a property descriptor for property " +
- propertyName + " of " + containerType);
- }
- Constructor<? extends PropertyMapper> constructor =
- mapperClass.getConstructor(
- String.class,
- String.class,
- Class.class,
- DataConverter.class,
- boolean.class,
- PropertyDescriptor.class
- );
-
- PropertyMapper mapper =
- constructor.newInstance(
- tagName,
- propertyName,
- containerType,
- type,
- onlyOne,
- descriptor
- );
-// System.out.println("adding a mapper " + mapper);
-
- allMappers.put(containerType.getName() + "#" + tagName, mapper);
- }
- }
-
/**
* Load (if {@link #readers} is {@code null} the readers via a
* {@link ServiceLoader} of contract {@link Xpp3Reader} and returns
Modified: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -25,6 +25,7 @@
package org.nuiton.io.xpp3;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.IOException;
@@ -178,4 +179,17 @@
* @param addDefaultEntities the new value.
*/
void setAddDefaultEntities(boolean addDefaultEntities);
+
+ <T> T[] readArray(String parentRootTagName,
+ String rootTagName,
+ Class<T> type,
+ XmlPullParser parser,
+ boolean strict)
+ throws XmlPullParserException, IOException;
+
+ <T> T read(String rootTagName,
+ Class<T> type,
+ XmlPullParser parser,
+ boolean strict)
+ throws XmlPullParserException, IOException;
}
Added: trunk/src/test/java/org/nuiton/io/xpp3/CountryRef.java
===================================================================
--- trunk/src/test/java/org/nuiton/io/xpp3/CountryRef.java (rev 0)
+++ trunk/src/test/java/org/nuiton/io/xpp3/CountryRef.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -0,0 +1,60 @@
+/*
+ * #%L
+ * Maven helper plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 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>.
+ * #L%
+ */
+package org.nuiton.io.xpp3;
+
+/**
+ * Define a country ref
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class CountryRef {
+
+ protected int id;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof CountryRef)) return false;
+
+ CountryRef that = (CountryRef) o;
+
+ return id == that.id;
+
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+}
Property changes on: trunk/src/test/java/org/nuiton/io/xpp3/CountryRef.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/src/test/java/org/nuiton/io/xpp3/CountryRefXpp3Reader.java
===================================================================
--- trunk/src/test/java/org/nuiton/io/xpp3/CountryRefXpp3Reader.java (rev 0)
+++ trunk/src/test/java/org/nuiton/io/xpp3/CountryRefXpp3Reader.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -0,0 +1,51 @@
+/*
+ * #%L
+ * Maven helper plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 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>.
+ * #L%
+ */
+package org.nuiton.io.xpp3;
+
+import java.beans.IntrospectionException;
+
+/**
+ * To read {@link CountryRef}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class CountryRefXpp3Reader extends AbstractXpp3Reader<CountryRef> {
+
+ public CountryRefXpp3Reader() {
+ this("countryRefs", "country");
+ }
+
+ public CountryRefXpp3Reader(String root, String tag) {
+ super(CountryRef.class, root, tag);
+ }
+
+ @Override
+ protected void initMappers() throws IntrospectionException {
+
+ addAttributeValueMappers(DefaultDataConverter.Integer, true,
+ "id");
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/java/org/nuiton/io/xpp3/CountryRefXpp3Reader.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/src/test/java/org/nuiton/io/xpp3/Identity.java
===================================================================
--- trunk/src/test/java/org/nuiton/io/xpp3/Identity.java 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/test/java/org/nuiton/io/xpp3/Identity.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -44,7 +44,10 @@
protected int age = 51;
+ protected int id;
+ protected CountryRef country;
+
PropertyChangeSupport p;
public Identity() {
@@ -67,6 +70,9 @@
p.removePropertyChangeListener(propertyName, listener);
}
+ public int getId() {
+ return id;
+ }
public String getFirstName() {
return firstName;
@@ -84,6 +90,17 @@
return age;
}
+ public CountryRef getCountry() {
+ return country;
+ }
+
+ public void setId(int id) {
+ int oldId = this.id;
+ this.id = id;
+ p.firePropertyChange("id", oldId, firstName);
+
+ }
+
public void setFirstName(String firstName) {
String oldFirstName = this.firstName;
this.firstName = firstName;
@@ -107,4 +124,8 @@
this.age = age;
p.firePropertyChange("age", oldAge, age);
}
+
+ public void setCountry(CountryRef country) {
+ this.country = country;
+ }
}
Modified: trunk/src/test/java/org/nuiton/io/xpp3/IdentityXpp3Reader.java
===================================================================
--- trunk/src/test/java/org/nuiton/io/xpp3/IdentityXpp3Reader.java 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/test/java/org/nuiton/io/xpp3/IdentityXpp3Reader.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -33,7 +33,7 @@
* Time: 20:37:56
*/
public class IdentityXpp3Reader extends AbstractXpp3Reader<Identity> {
-
+
public IdentityXpp3Reader() {
this("identities");
}
@@ -45,13 +45,20 @@
@Override
protected void initMappers() throws IntrospectionException {
- org.nuiton.io.xpp3.Xpp3Helper.addTagTextContentMappers(Identity.class, DefaultDataConverter.Text, true, allMappers,
- "firstName",
- "lastName",
- "email");
+ addAttributeValueMappers(DefaultDataConverter.Integer, true,
+ "id");
- org.nuiton.io.xpp3.Xpp3Helper.addTagTextContentMappers(Identity.class, DefaultDataConverter.Integer, true, allMappers,
- "age");
+ addTagTextContentMappers(DefaultDataConverter.Text, true,
+ "firstName",
+ "lastName",
+ "email");
+ addTagTextContentMappers(DefaultDataConverter.Integer, true,
+ "age");
+
+ addTagContentMapper(CountryRef.class, true,
+ new CountryRefXpp3Reader(null, "country"));
+
}
+
}
Modified: trunk/src/test/java/org/nuiton/io/xpp3/Xpp3ReaderTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/io/xpp3/Xpp3ReaderTest.java 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/test/java/org/nuiton/io/xpp3/Xpp3ReaderTest.java 2012-03-25 14:23:27 UTC (rev 841)
@@ -44,7 +44,6 @@
*/
public class Xpp3ReaderTest {
-
protected static File dir;
protected Xpp3Reader<Identity> r = new IdentityXpp3Reader("identities");
@@ -75,10 +74,14 @@
}
Assert.assertNotNull(result);
Identity expected = new Identity();
+ expected.setId(1);
expected.setFirstName("first name");
expected.setLastName("last name");
expected.setEmail("noway(a)bishop.uk");
expected.setAge(29);
+ CountryRef country = new CountryRef();
+ country.setId(1);
+ expected.setCountry(country);
assertEqualsIdentity(result, expected);
}
@@ -156,16 +159,21 @@
Assert.assertEquals(expected.getLastName(), result.getLastName());
Assert.assertEquals(expected.getEmail(), result.getEmail());
Assert.assertEquals(expected.getAge(), result.getAge());
+ Assert.assertEquals(expected.getCountry(), result.getCountry());
}
protected static void assertEqualsSimpleIdentity(Identity result) {
Assert.assertNotNull(result);
Identity expected = new Identity();
+ expected.setId(1);
expected.setFirstName("first name");
expected.setLastName("last name");
expected.setEmail("noway(a)bishop.uk");
expected.setAge(29);
+ CountryRef country = new CountryRef();
+ country.setId(1);
+ expected.setCountry(country);
assertEqualsIdentity(result, expected);
}
@@ -174,18 +182,26 @@
Assert.assertNotNull(result);
Assert.assertEquals(2, result.length);
Identity expected = new Identity();
+ expected.setId(1);
expected.setFirstName("first name");
expected.setLastName("last name");
expected.setEmail("noway(a)bishop.uk");
expected.setAge(29);
+ CountryRef country = new CountryRef();
+ country.setId(1);
+ expected.setCountry(country);
assertEqualsIdentity(result[0], expected);
expected = new Identity();
+ expected.setId(2);
expected.setFirstName("first name2");
expected.setLastName("last name2");
expected.setEmail("noway2(a)bishop.uk");
expected.setAge(31);
+ country = new CountryRef();
+ country.setId(2);
+ expected.setCountry(country);
assertEqualsIdentity(result[1], expected);
}
Modified: trunk/src/test/resources/org/nuiton/io/xpp3/identities.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/io/xpp3/identities.xml 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/test/resources/org/nuiton/io/xpp3/identities.xml 2012-03-25 14:23:27 UTC (rev 841)
@@ -23,16 +23,18 @@
#L%
-->
<identities>
- <identity>
- <firstName>first name</firstName>
- <lastName>last name</lastName>
- <email>noway(a)bishop.uk</email>
- <age>29</age>
- </identity>
- <identity>
- <firstName>first name2</firstName>
- <lastName>last name2</lastName>
- <email>noway2(a)bishop.uk</email>
- <age>31</age>
- </identity>
+ <identity id="1">
+ <country id="1"/>
+ <firstName>first name</firstName>
+ <lastName>last name</lastName>
+ <email>noway(a)bishop.uk</email>
+ <age>29</age>
+ </identity>
+ <identity id="2">
+ <country id="2"/>
+ <firstName>first name2</firstName>
+ <lastName>last name2</lastName>
+ <email>noway2(a)bishop.uk</email>
+ <age>31</age>
+ </identity>
</identities>
\ No newline at end of file
Modified: trunk/src/test/resources/org/nuiton/io/xpp3/identities2.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/io/xpp3/identities2.xml 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/test/resources/org/nuiton/io/xpp3/identities2.xml 2012-03-25 14:23:27 UTC (rev 841)
@@ -23,16 +23,18 @@
#L%
-->
<identity>
- <identity>
- <firstName>first name</firstName>
- <lastName>last name</lastName>
- <email>noway(a)bishop.uk</email>
- <age>29</age>
- </identity>
- <identity>
- <firstName>first name2</firstName>
- <lastName>last name2</lastName>
- <email>noway2(a)bishop.uk</email>
- <age>31</age>
- </identity>
+ <identity id="1">
+ <country id="1"/>
+ <firstName>first name</firstName>
+ <lastName>last name</lastName>
+ <email>noway(a)bishop.uk</email>
+ <age>29</age>
+ </identity>
+ <identity id="2">
+ <country id="2"/>
+ <firstName>first name2</firstName>
+ <lastName>last name2</lastName>
+ <email>noway2(a)bishop.uk</email>
+ <age>31</age>
+ </identity>
</identity>
\ No newline at end of file
Modified: trunk/src/test/resources/org/nuiton/io/xpp3/identity.xml
===================================================================
--- trunk/src/test/resources/org/nuiton/io/xpp3/identity.xml 2012-02-29 12:55:42 UTC (rev 840)
+++ trunk/src/test/resources/org/nuiton/io/xpp3/identity.xml 2012-03-25 14:23:27 UTC (rev 841)
@@ -22,9 +22,10 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->
-<identity>
- <firstName>first name</firstName>
- <lastName>last name</lastName>
- <email>noway(a)bishop.uk</email>
- <age>29</age>
+<identity id="1">
+ <country id="1"/>
+ <firstName>first name</firstName>
+ <lastName>last name</lastName>
+ <email>noway(a)bishop.uk</email>
+ <age>29</age>
</identity>
\ No newline at end of file
1
0