[Arakhnę-Dev] [360] * Add replacement tags: year, inceptionyear, and prop. |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 360
Author: galland
Date: 2012-07-11 19:20:15 +0200 (Wed, 11 Jul 2012)
Log Message:
-----------
* Add replacement tags: year, inceptionyear, and prop.
Modified Paths:
--------------
trunk/tag-replacer/lifecycle-mapping-metadata.xml
trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java
trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/Macros.java
Modified: trunk/tag-replacer/lifecycle-mapping-metadata.xml
===================================================================
--- trunk/tag-replacer/lifecycle-mapping-metadata.xml 2012-07-10 13:50:41 UTC (rev 359)
+++ trunk/tag-replacer/lifecycle-mapping-metadata.xml 2012-07-11 17:20:15 UTC (rev 360)
@@ -13,6 +13,7 @@
<goal>generatereplacesrc</goal>
<goal>generatesrc</goal>
<goal>replaceresource</goal>
+ <goal>replacehtml</goal>
</goals>
</pluginExecutionFilter>
<action>
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 2012-07-10 13:50:41 UTC (rev 359)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java 2012-07-11 17:20:15 UTC (rev 360)
@@ -36,6 +36,7 @@
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -543,6 +544,76 @@
}
/**
+ * Replace the property 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 project
+ * @param replacementType
+ * is the type of replacement.
+ * @return the result of the replacement.
+ * @throws MojoExecutionException
+ */
+ protected synchronized String replaceProp(File sourceFile, int sourceLine, String text, MavenProject project, ReplacementType replacementType) throws MojoExecutionException {
+ String result = text;
+ Pattern p = buildMacroPatternWithGroup(MACRO_PROP);
+ Matcher m = p.matcher(text);
+ boolean hasResult = m.find();
+
+ Properties props = null;
+ if (project != null) {
+ props = project.getProperties();
+ }
+
+ if (hasResult) {
+ StringBuffer sb = new StringBuffer();
+ StringBuilder replacement = new StringBuilder();
+ String propName;
+ do {
+ propName = m.group(1);
+ if (propName != null) {
+ propName = propName.trim();
+ if (propName.length() > 0) {
+ replacement.setLength(0);
+ if (props!=null) {
+ String value = props.getProperty(propName);
+ if (value!=null && !value.isEmpty()) {
+ replacement.append(value);
+ }
+ }
+ if (replacement.length() != 0) {
+ m.appendReplacement(sb, Matcher.quoteReplacement(replacement.toString()));
+ }
+ }
+ else {
+ String msg = sourceFile.getName()
+ +":"+sourceLine //$NON-NLS-1$
+ +": no property name for Prop tag: " + m.group(0); //$NON-NLS-1$
+ getLog().warn(msg);
+ }
+ }
+ else {
+ String msg = sourceFile.getName()
+ +":"+sourceLine //$NON-NLS-1$
+ +": no property name for Prop tag: " + m.group(0); //$NON-NLS-1$
+ getLog().warn(msg);
+ }
+ hasResult = m.find();
+ }
+ while (hasResult);
+
+ m.appendTail(sb);
+
+ result = sb.toString();
+ }
+ return result;
+ }
+
+ /**
* Replace Javadoc tags in a string.
*
* @param sourceFile
@@ -582,7 +653,19 @@
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //$NON-NLS-1$
String currentDate = fmt.format(this.invocationDate);
-
+
+ fmt = new SimpleDateFormat("yyyy"); //$NON-NLS-1$
+ String year = fmt.format(this.invocationDate);
+
+ String inceptionYear = null;
+ MavenProject project = getMavenProject(artifact);
+ if (project!=null) {
+ inceptionYear = project.getInceptionYear();
+ }
+ if (inceptionYear==null || inceptionYear.isEmpty()) {
+ inceptionYear = year;
+ }
+
String replacementFullVersion;
if (artifact == null) {
replacementFullVersion = null;
@@ -605,6 +688,8 @@
nline = replaceMacro(MACRO_WEBSITE, nline, replacementWebsite, replacementType, sourceFile, sourceLine);
nline = replaceMacro(MACRO_ORGANIZATION, nline, replacementOrganization, replacementType, sourceFile, sourceLine);
nline = replaceMacro(MACRO_DATE, nline, currentDate, replacementType, sourceFile, sourceLine);
+ nline = replaceMacro(MACRO_YEAR, nline, year, replacementType, sourceFile, sourceLine);
+ nline = replaceMacro(MACRO_INCEPTIONYEAR, nline, inceptionYear, replacementType, sourceFile, sourceLine);
nline = replaceMacro(MACRO_FULLVERSION, nline, replacementFullVersion, replacementType, sourceFile, sourceLine);
nline = replaceMacro(MACRO_FILENAME, nline, replacementFilename, replacementType, sourceFile, sourceLine);
@@ -628,6 +713,7 @@
nline = replaceMacro(MACRO_ID, nline, buffer.toString(), ReplacementType.TEXT, sourceFile, sourceLine);
nline = replaceAuthor(sourceFile, sourceLine, nline, artifact, replacementType);
+ nline = replaceProp(sourceFile, sourceLine, nline, project, replacementType);
return nline;
}
Modified: trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/Macros.java
===================================================================
--- trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/Macros.java 2012-07-10 13:50:41 UTC (rev 359)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/Macros.java 2012-07-11 17:20:15 UTC (rev 360)
@@ -1,7 +1,9 @@
/*
* $Id$
*
- * Copyright (C) 2010-11 Stephane GALLAND This library is free software; you can redistribute it and/or
+ * Copyright (C) 2010-12 Stephane GALLAND
+ *
+ * This library 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 2.1 of the License, or (at your option) any later version.
@@ -32,7 +34,7 @@
*/
public static final String MACRO_ARTIFACTID = "ArtifactId"; //$NON-NLS-1$
- /** $Author$
+ /** $Author: id$
*/
public static final String MACRO_AUTHOR = "Author"; //$NON-NLS-1$
@@ -76,4 +78,22 @@
*/
public static final String MACRO_WEBSITE = "Website"; //$NON-NLS-1$
+ /** $Year$
+ *
+ * @since 2.3
+ */
+ public static final String MACRO_YEAR = "Year"; //$NON-NLS-1$
+
+ /** $InceptionYear$
+ *
+ * @since 2.3
+ */
+ public static final String MACRO_INCEPTIONYEAR = "InceptionYear"; //$NON-NLS-1$
+
+ /** $Prop: name$
+ *
+ * @since 2.3
+ */
+ public static final String MACRO_PROP = "Prop"; //$NON-NLS-1$
+
}