[Arakhnę-Dev] [313] * Enforce the retreival of the URL or email of the project' s developers and contributors.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 313
Author:   galland
Date:     2011-11-05 13:34:12 +0100 (Sat, 05 Nov 2011)
Log Message:
-----------
* Enforce the retreival of the URL or email of the project's developers and contributors.

Modified Paths:
--------------
    trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
    trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java

Modified: trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java	2011-11-05 11:43:15 UTC (rev 312)
+++ trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java	2011-11-05 12:34:12 UTC (rev 313)
@@ -78,6 +78,7 @@
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
 import org.apache.maven.project.ProjectBuildingException;
@@ -105,6 +106,39 @@
  */
 public abstract class AbstractArakhneMojo extends AbstractMojo {
 
+	/** Replies the preferred URL for the given contributor.
+	 * 
+	 * @param contributor
+	 * @param log
+	 * @return the URL or <code>null</code> if no URL could be built.
+	 */
+	protected static URL getContributorURL(Contributor contributor, Log log) {
+		URL url = null;
+		if (contributor!=null) {
+			String s = contributor.getUrl();
+			if (s!=null && !EMPTY_STRING.equals(s)) {
+				try {
+					url = new URL(s);
+				}
+				catch(Throwable _) {
+					url = null;
+				}
+			}
+			if (url==null) {
+				s = contributor.getEmail();
+				if (s!=null && !EMPTY_STRING.equals(s)) {
+					try {
+						url = new URL("mailto:"+s); //$NON-NLS-1$
+					}
+					catch(Throwable _) {
+						url = null;
+					}
+				}
+			}
+		}
+		return url;
+	}
+	
 	/**
 	 * Empty string constant.
 	 */

Modified: trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java
===================================================================
--- trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java	2011-11-05 11:43:15 UTC (rev 312)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java	2011-11-05 12:34:12 UTC (rev 313)
@@ -28,6 +28,7 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
+import java.net.URL;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
@@ -463,7 +464,8 @@
 		if (hasResult) {
 			StringBuffer sb = new StringBuffer();
 			StringBuffer replacement = new StringBuffer();
-			String login, link;
+			String login;
+			URL url;
 			Contributor contributor;
 			do {
 				login = m.group(1);
@@ -474,25 +476,25 @@
 						if (artifact != null) {
 							contributor = artifact.getPeople(login, getLog());
 							if (contributor != null) {
-								link = contributor.getUrl();
-								if (link == null || EMPTY_STRING.equals(link)) {
-									link = contributor.getEmail();
+								url = getContributorURL(contributor, getLog());
+								if (url == null) {
+									replacement.append(contributor.getName());
 								}
-								if (link == null || EMPTY_STRING.equals(link)) {
-									replacement.append(contributor.getName());
-								} else if (replacementType == ReplacementType.HTML) {
+								else if (replacementType == ReplacementType.HTML) {
 									replacement.append("<a target=\"_blank\" href=\""); //$NON-NLS-1$
-									replacement.append(link);
+									replacement.append(url.toExternalForm());
 									replacement.append("\">"); //$NON-NLS-1$
 									replacement.append(contributor.getName());
 									replacement.append("</a>"); //$NON-NLS-1$
-								} else {
+								}								
+								else {
 									replacement.append(contributor.getName());
 									replacement.append(" ["); //$NON-NLS-1$
-									replacement.append(link);
+									replacement.append(url.toExternalForm());
 									replacement.append("]"); //$NON-NLS-1$
 								}
-							} else {
+							}
+							else {
 								String msg =
 									sourceFile.getName()
 									+":"+sourceLine //$NON-NLS-1$
@@ -506,7 +508,8 @@
 						if (replacement.length() != 0) {
 							m.appendReplacement(sb, Matcher.quoteReplacement(replacement.toString()));
 						}
-					} else {
+					}
+					else {
 						String msg = sourceFile.getName()
 						+":"+sourceLine //$NON-NLS-1$
 						+": no login for Author tag: " + m.group(0); //$NON-NLS-1$
@@ -515,7 +518,8 @@
 						}
 						getLog().warn(msg);
 					}
-				} else {
+				}
+				else {
 					String msg = sourceFile.getName()
 					+":"+sourceLine //$NON-NLS-1$
 					+": no login for Author tag: " + m.group(0); //$NON-NLS-1$


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/