[Arakhnę-Dev] [279] * Parse "id" and "login" property in the developer and contributor tags.

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


Revision: 279
Author:   galland
Date:     2011-08-31 09:36:59 +0200 (Wed, 31 Aug 2011)
Log Message:
-----------
* Parse "id" and "login" property in the developer and contributor tags.

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

Modified: trunk/maventools/src/main/java/org/arakhne/maven/ExtendedArtifact.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/ExtendedArtifact.java	2011-08-30 16:30:35 UTC (rev 278)
+++ trunk/maventools/src/main/java/org/arakhne/maven/ExtendedArtifact.java	2011-08-31 07:36:59 UTC (rev 279)
@@ -22,6 +22,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Properties;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
@@ -173,46 +174,64 @@
 	 */
 	public Contributor getPeople(String login, Log logger) {
 		for(Developer devel : getDevelopers()) {
-			if (devel!=null && logger!=null && logger.isDebugEnabled()) {
-				logger.debug(
-						"Comparing '"+login //$NON-NLS-1$
-						+" to the developer [ID="+devel.getId() //$NON-NLS-1$
-						+";NAME="+devel.getName() //$NON-NLS-1$
-						+";EMAIL="+devel.getEmail() //$NON-NLS-1$
-						+"]"); //$NON-NLS-1$
-			}
-			if (devel!=null && 
-					(login.equals(devel.getId())
-							||login.equals(devel.getName())
-							||login.equals(devel.getEmail()))) {
+			if (devel!=null) {
 				if (logger!=null && logger.isDebugEnabled()) {
 					logger.debug(
-							"Selecting the developer [ID="+devel.getId() //$NON-NLS-1$
+							"Comparing '"+login //$NON-NLS-1$
+							+" to the developer [ID="+devel.getId() //$NON-NLS-1$
 							+";NAME="+devel.getName() //$NON-NLS-1$
 							+";EMAIL="+devel.getEmail() //$NON-NLS-1$
 							+"]"); //$NON-NLS-1$
 				}
-				return devel;
+				String idprop = null;
+				Properties props = devel.getProperties();
+				if (props!=null) {
+					idprop = props.getProperty("id", null); //$NON-NLS-1$
+					if (idprop==null)
+						idprop = props.getProperty("login", null); //$NON-NLS-1$
+				}
+				if (login.equals(devel.getId())
+					||login.equals(devel.getName())
+					||login.equals(devel.getEmail())
+					||login.equals(idprop)) {
+					if (logger!=null && logger.isDebugEnabled()) {
+						logger.debug(
+								"Selecting the developer [ID="+devel.getId() //$NON-NLS-1$
+								+";NAME="+devel.getName() //$NON-NLS-1$
+								+";EMAIL="+devel.getEmail() //$NON-NLS-1$
+								+"]"); //$NON-NLS-1$
+					}
+					return devel;
+				}
 			}
 		}
 		for(Contributor contrib : getContributors()) {
-			if (contrib!=null && logger!=null && logger.isDebugEnabled()) {
-				logger.debug(
-						"Comparing '"+login //$NON-NLS-1$
-						+" to the contributor [NAME="+contrib.getName() //$NON-NLS-1$
-						+";EMAIL="+contrib.getEmail() //$NON-NLS-1$
-						+"]"); //$NON-NLS-1$
-			}
-			if (contrib!=null &&
-					(login.equals(contrib.getName())
-							||login.equals(contrib.getEmail()))) {
+			if (contrib!=null) {
 				if (logger!=null && logger.isDebugEnabled()) {
 					logger.debug(
-							"Selecting the contributor [NAME="+contrib.getName() //$NON-NLS-1$
+							"Comparing '"+login //$NON-NLS-1$
+							+" to the contributor [NAME="+contrib.getName() //$NON-NLS-1$
 							+";EMAIL="+contrib.getEmail() //$NON-NLS-1$
 							+"]"); //$NON-NLS-1$
 				}
-				return contrib;
+				String idprop = null;
+				Properties props = contrib.getProperties();
+				if (props!=null) {
+					idprop = props.getProperty("id", null); //$NON-NLS-1$
+					if (idprop==null)
+						idprop = props.getProperty("login", null); //$NON-NLS-1$
+				}
+				if (login.equals(contrib.getName())
+					||login.equals(contrib.getEmail())
+					||login.equals(idprop)) {
+					if (logger!=null && logger.isDebugEnabled()) {
+						logger.debug(
+								"Selecting the contributor [NAME="+contrib.getName() //$NON-NLS-1$
+								+";EMAIL="+contrib.getEmail() //$NON-NLS-1$
+								+"]"); //$NON-NLS-1$
+					}
+					return contrib;
+				}
 			}
 		}
 		if (logger!=null && logger.isDebugEnabled()) {

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-08-30 16:30:35 UTC (rev 278)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java	2011-08-31 07:36:59 UTC (rev 279)
@@ -332,11 +332,13 @@
 			Writer w = Channels.newWriter(wChannel, charset.newEncoder(), -1);
 
 			String line;
+			int nLine = 1;
 
 			while ((line = br.readLine()) != null) {
-				line = replaceInString(shortFilename, artifact, line, replacementType);
+				line = replaceInString(inputFile, nLine, shortFilename, artifact, line, replacementType);
 				w.write(line);
 				w.write("\n"); //$NON-NLS-1$
+				++nLine;
 			}
 			w.flush();
 			br.close();
@@ -387,10 +389,14 @@
 	 *            is the replacement text.
 	 * @param type
 	 *            is the type of replacement to be done.
+	 * @param sourceFile
+	 *            is the filename in which the replacement is done.
+	 * @param sourceLine
+	 *            is the line at which the replacement is done. 
 	 * @return the result of the replacement
 	 */
-	protected final String replaceMacro(String macroName, String text, String replacement, ReplacementType type) {
-		return replaceMacro(macroName, text, replacement, type, true);
+	protected final String replaceMacro(String macroName, String text, String replacement, ReplacementType type, File sourceFile, int sourceLine) {
+		return replaceMacro(macroName, text, replacement, type, true, sourceFile, sourceLine);
 	}
 
 	/**
@@ -406,22 +412,34 @@
 	 *            is the type of replacement to be done.
 	 * @param enableWarning
 	 *            indicates if the warnings should be output or not.
+	 * @param sourceFile
+	 *            is the filename in which the replacement is done.
+	 * @param sourceLine
+	 *            is the line at which the replacement is done. 
 	 * @return the result of the replacement
 	 */
-	protected synchronized final String replaceMacro(String macroName, String text, String replacement, ReplacementType type, boolean enableWarning) {
+	protected synchronized final String replaceMacro(String macroName, String text, String replacement, ReplacementType type, boolean enableWarning, File sourceFile, int sourceLine) {
 		if (replacement != null && !EMPTY_STRING.equals(replacement)) {
 			Pattern p = buildMacroPattern(macroName);
 			Matcher m = p.matcher(text);
 			return m.replaceAll(Matcher.quoteReplacement(replacement));
 		}
 		if (enableWarning)
-			getLog().warn("cannot replace empty macro " + macroName); //$NON-NLS-1$
+			getLog().warn(
+					sourceFile.getName()
+					+":"+sourceLine //$NON-NLS-1$
+					+": cannot replace empty macro $" + macroName //$NON-NLS-1$
+					+"$"); //$NON-NLS-1$
 		return text;
 	}
 
 	/**
 	 * Replace the author information tags in the given text.
 	 * 
+	 * @param sourceFile
+	 *            is the filename in which the replacement is done.
+	 * @param sourceLine
+	 *            is the line at which the replacement is done. 
 	 * @param text
 	 *            is the text in which the author tags should be replaced
 	 * @param artifact
@@ -430,7 +448,7 @@
 	 * @return the result of the replacement.
 	 * @throws MojoExecutionException
 	 */
-	protected synchronized String replaceAuthor(String text, ExtendedArtifact artifact, ReplacementType replacementType) throws MojoExecutionException {
+	protected synchronized String replaceAuthor(File sourceFile, int sourceLine, String text, ExtendedArtifact artifact, ReplacementType replacementType) throws MojoExecutionException {
 		String result = text;
 		Pattern p = buildMacroPatternWithGroup(MACRO_AUTHOR);
 		Matcher m = p.matcher(text);
@@ -469,7 +487,10 @@
 									replacement.append("]"); //$NON-NLS-1$
 								}
 							} else {
-								String msg = "unable to find a developer or a contributor with an id, a name or an email equal to: " + login; //$NON-NLS-1$
+								String msg =
+									sourceFile.getName()
+									+":"+sourceLine //$NON-NLS-1$
+									+": unable to find a developer or a contributor with an id, a name or an email equal to: " + login; //$NON-NLS-1$
 								if (getLog().isDebugEnabled()) {
 									throw new MojoExecutionException(msg);
 								}
@@ -480,14 +501,18 @@
 							m.appendReplacement(sb, Matcher.quoteReplacement(replacement.toString()));
 						}
 					} else {
-						String msg = "no login for Author tag: " + m.group(0); //$NON-NLS-1$
+						String msg = sourceFile.getName()
+						+":"+sourceLine //$NON-NLS-1$
+						+": no login for Author tag: " + m.group(0); //$NON-NLS-1$
 						if (getLog().isDebugEnabled()) {
 							throw new MojoExecutionException(msg);
 						}
 						getLog().warn(msg);
 					}
 				} else {
-					String msg = "no login for Author tag: " + m.group(0); //$NON-NLS-1$
+					String msg = sourceFile.getName()
+					+":"+sourceLine //$NON-NLS-1$
+					+": no login for Author tag: " + m.group(0); //$NON-NLS-1$
 					if (getLog().isDebugEnabled()) {
 						throw new MojoExecutionException(msg);
 					}
@@ -506,6 +531,10 @@
 	/**
 	 * Replace Javadoc tags in a string.
 	 * 
+	 * @param sourceFile
+	 *            is the filename in which the replacement is done.
+	 * @param sourceLine
+	 *            is the line at which the replacement is done. 
 	 * @param file
 	 *            is the name of the file in the hierarchy from which the string was extracted.
 	 * @param artifact
@@ -517,7 +546,7 @@
 	 * @return the result of the replacement.
 	 * @throws MojoExecutionException
 	 */
-	protected synchronized String replaceInString(String file, ExtendedArtifact artifact, String line, ReplacementType replacementType) throws MojoExecutionException {
+	protected synchronized String replaceInString(File sourceFile, int sourceLine, String file, ExtendedArtifact artifact, String line, ReplacementType replacementType) throws MojoExecutionException {
 		String nline = line;
 
 		String replacementName = (artifact == null) ? null : artifact.getName();
@@ -556,16 +585,16 @@
 					replacementVersion, rev, currentDate);
 		}
 
-		nline = replaceMacro(MACRO_NAME, nline, replacementName, replacementType);
-		nline = replaceMacro(MACRO_REVISION, nline, replacementRevision, replacementType);
-		nline = replaceMacro(MACRO_VERSION, nline, replacementVersion, replacementType);
-		nline = replaceMacro(MACRO_ARTIFACTID, nline, replacementArtifactId, replacementType);
-		nline = replaceMacro(MACRO_GROUPID, nline, replacementGroupId, replacementType);
-		nline = replaceMacro(MACRO_WEBSITE, nline, replacementWebsite, replacementType, false);
-		nline = replaceMacro(MACRO_ORGANIZATION, nline, replacementOrganization, replacementType, false);
-		nline = replaceMacro(MACRO_DATE, nline, currentDate, replacementType);
-		nline = replaceMacro(MACRO_FULLVERSION, nline, replacementFullVersion, replacementType);
-		nline = replaceMacro(MACRO_FILENAME, nline, replacementFilename, replacementType);
+		nline = replaceMacro(MACRO_NAME, nline, replacementName, replacementType, sourceFile, sourceLine);
+		nline = replaceMacro(MACRO_REVISION, nline, replacementRevision, replacementType, sourceFile, sourceLine);
+		nline = replaceMacro(MACRO_VERSION, nline, replacementVersion, replacementType, sourceFile, sourceLine);
+		nline = replaceMacro(MACRO_ARTIFACTID, nline, replacementArtifactId, replacementType, sourceFile, sourceLine);
+		nline = replaceMacro(MACRO_GROUPID, nline, replacementGroupId, replacementType, sourceFile, sourceLine);
+		nline = replaceMacro(MACRO_WEBSITE, nline, replacementWebsite, replacementType, false, sourceFile, sourceLine);
+		nline = replaceMacro(MACRO_ORGANIZATION, nline, replacementOrganization, replacementType, false, sourceFile, sourceLine);
+		nline = replaceMacro(MACRO_DATE, nline, currentDate, replacementType, sourceFile, sourceLine);
+		nline = replaceMacro(MACRO_FULLVERSION, nline, replacementFullVersion, replacementType, sourceFile, sourceLine);
+		nline = replaceMacro(MACRO_FILENAME, nline, replacementFilename, replacementType, sourceFile, sourceLine);
 
 		StringBuffer buffer = new StringBuffer();
 		buffer.setLength(0);
@@ -584,9 +613,9 @@
 		}
 		buffer.append(currentDate);
 		buffer.append("$"); //$NON-NLS-1$
-		nline = replaceMacro(MACRO_ID, nline, buffer.toString(), ReplacementType.TEXT);
+		nline = replaceMacro(MACRO_ID, nline, buffer.toString(), ReplacementType.TEXT, sourceFile, sourceLine);
 
-		nline = replaceAuthor(nline, artifact, replacementType);
+		nline = replaceAuthor(sourceFile, sourceLine, nline, artifact, replacementType);
 
 		return nline;
 	}


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