[Arakhnę-Dev] [249] * javadoc-tag-replacer -> tag-replacer |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 249
Author: galland
Date: 2011-08-13 15:08:58 +0200 (Sat, 13 Aug 2011)
Log Message:
-----------
* javadoc-tag-replacer -> tag-replacer
Added Paths:
-----------
trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java
trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/GenerateSourceMojo.java
trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/Macros.java
trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/ReplaceResourceMojo.java
Added: 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 (rev 0)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java 2011-08-13 13:08:58 UTC (rev 249)
@@ -0,0 +1,569 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2010-11 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.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.maven.plugins.tagreplacer;
+
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.model.Contributor;
+import org.apache.maven.model.Organization;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.arakhne.maven.AbstractArakhneMojo;
+import org.arakhne.maven.ExtendedArtifact;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.charset.Charset;
+import java.text.SimpleDateFormat;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Replace all the tags variables by the corresponding values.
+ * Supported variables are:<table>
+ * <thead>
+ * <tr><th>Name (case-sensitive)</th><th>Description</th></tr>
+ * </thead>
+ * <tbody>
+ * <tr><td>$ArtifactId$</td><td>The artifact id of the Maven module</td></tr>
+ * <tr><td>$Author: id$</td><td>The name and link to the author with the given id. The id is the
+ * identifier of the author or contributor defined the <code>pom.xml</code> file; or it is the
+ * email address of the author.</td></tr>
+ * <tr><td>$Date$</td><td>The date of the last compilation of the Maven module</td></tr>
+ * <tr><td>$Filename$</td><td>The name of file</td></tr>
+ * <tr><td>$FullVersion$</td><td>The name, version, revision and date of the Maven module.
+ * It is equivalent to<br><code>$Version$ (rev:$Revision$) - $Date$</code></td></tr>
+ * <tr><td>$GroupId$</td><td>The group id of the Maven module</td></tr>
+ * <tr><td>$Id$</td><td>The id of file</td></tr>
+ * <tr><td>$Name$</td><td>The name of the Maven module</td></tr>
+ * <tr><td>$Organization$</td><td>The name of organization that publishs the Maven module</td></tr>
+ * <tr><td>$Revision$</td><td>The SCM/SVN revision number of the Maven module</td></tr>
+ * <tr><td>$Version$</td><td>The version of the Maven module</td></tr>
+ * <tr><td>$Website$</td><td>The link to the website of the Maven module</td></tr>
+ * </tbody>
+ * </table>
+ *
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+public abstract class AbstractReplaceMojo extends AbstractArakhneMojo implements Macros {
+
+ /** @component
+ */
+ private ArtifactHandlerManager artifactHandlerManager;
+
+ /** @parameter expression="${project.basedir}"
+ */
+ private File baseDirectory;
+
+ /** @parameter expression="${project.build.directory}"
+ */
+ private File outputDirectory;
+
+ /** @parameter expression="${project.build.outputDirectory}"
+ */
+ private File classDirectory;
+
+ /** @parameter expression="${project.basedir}/src"
+ */
+ private File sourceDirectory;
+
+ /** @parameter expression="${project.build.directory}/generated-sources"
+ */
+ private File generatedSourceDirectory;
+
+ /** Is the artifact id that should replace the project's artifact id.
+ * @parameter default-value="${project.artifactId}"
+ */
+ private String projectArtifactId;
+
+ /** Is the group id that should replace the project's group id.
+ * @parameter default-value="${project.groupId}"
+ */
+ private String projectGroupId;
+
+ /** Is the file encoding.
+ * @parameter default-value="${project.build.sourceEncoding}"
+ */
+ private String encoding;
+
+ /** Indicates if the group id and artifact id of the current
+ * project should be replaced by <var>userArtifactId</var>
+ * and <var>artifactId</var>
+ * @parameter default-value="true"
+ */
+ private boolean overrideArtifactGroup;
+
+ /** Reference to the current maven project.
+ *
+ * @parameter expression="${project}"
+ */
+ private MavenProject mavenProject;
+
+ private String ensureArtifactId(ExtendedArtifact artifact) {
+ if (artifact!=null) {
+ if (this.overrideArtifactGroup && this.mavenProject.getArtifact().equals(artifact)) {
+ String a = this.projectArtifactId;
+ if (a!=null && !EMPTY_STRING.equals(a)) {
+ return this.projectArtifactId;
+ }
+ }
+ return artifact.getArtifactId();
+ }
+ return EMPTY_STRING;
+ }
+
+ private String ensureGroupId(ExtendedArtifact artifact) {
+ if (artifact!=null) {
+ if (this.overrideArtifactGroup && this.mavenProject.getArtifact().equals(artifact)) {
+ String g = this.projectGroupId;
+ if (g!=null && !EMPTY_STRING.equals(g)) {
+ return this.projectGroupId;
+ }
+ }
+ return artifact.getGroupId();
+ }
+ return EMPTY_STRING;
+ }
+
+ /** Replace the Javadoc tags in the given file.
+ *
+ * @param sourceFile is the name of the file to read out. It may be <code>null</code>
+ * @param targetFile is the name of the file to write in. It cannot be <code>null</code>
+ * @param replacementType is the type of replacement to be done.
+ * @param classpath are the directories from which the file is extracted.
+ * @param detectEncoding when <code>true</code> the encoding of the file
+ * will be detected and preserved. When <code>false</code> the encoding
+ * may be loose.
+ * @throws MojoExecutionException
+ */
+ protected synchronized void replaceInFile(
+ File sourceFile, File targetFile,
+ ReplacementType replacementType,
+ File[] classpath,
+ boolean detectEncoding) throws MojoExecutionException {
+ File outputFile, inputFile;
+ assert(targetFile!=null);
+
+ if (sourceFile==null) {
+ inputFile = targetFile;
+ outputFile = new File(targetFile.getAbsolutePath()+".maven.tmp"); //$NON-NLS-1$
+ }
+ else {
+ inputFile = sourceFile;
+ outputFile = targetFile;
+ }
+
+ ExtendedArtifact artifact = searchArtifact(inputFile);
+
+ String filename = removePathPrefix(getBaseDirectory(), inputFile);
+
+ String shortFilename = null;
+ for(int i=0; shortFilename==null && i<classpath.length; ++i) {
+ if (inputFile.getAbsolutePath().startsWith(classpath[i].getAbsolutePath())) {
+ shortFilename = removePathPrefix(classpath[i], inputFile);
+ }
+ }
+
+ if (artifact!=null) {
+ getLog().debug("Replacing in "+filename+" with artifact "+ //$NON-NLS-1$ //$NON-NLS-2$
+ ArtifactUtils.key(artifact));
+ }
+ else {
+ getLog().debug("Replacing in "+filename+" without artifact"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ try {
+ outputFile.getParentFile().mkdirs();
+ Reader r = null;
+
+ Charset charset = null;
+
+ if (detectEncoding) {
+ charset = detectEncoding(inputFile);
+ }
+
+ if (charset==null)
+ charset = Charset.defaultCharset();
+
+ getLog().info("Copying file '" //$NON-NLS-1$
+ +inputFile.getName()
+ +"' with '" //$NON-NLS-1$
+ +charset.displayName()
+ +"' encoding"); //$NON-NLS-1$
+
+ ReadableByteChannel channel = Channels.newChannel(new FileInputStream(inputFile));
+ r = Channels.newReader(channel, charset.newDecoder(), -1);
+
+ if (r==null) {
+ r = new FileReader(inputFile);
+ }
+
+ BufferedReader br = new BufferedReader(r);
+
+ WritableByteChannel wChannel = Channels.newChannel(new FileOutputStream(outputFile));
+ Writer w = Channels.newWriter(wChannel, charset.newEncoder(), -1);
+
+ String line;
+
+ while ((line = br.readLine())!=null) {
+ line = replaceInString(shortFilename, artifact, line, replacementType);
+ w.write(line);
+ w.write("\n"); //$NON-NLS-1$
+ }
+ w.flush();
+ br.close();
+ w.close();
+
+ if (sourceFile==null) {
+ fileCopy(outputFile, targetFile);
+ outputFile.delete();
+ }
+ }
+ catch(IOException e) {
+ throw new MojoExecutionException(e.getLocalizedMessage(), e);
+ }
+ finally {
+ if (sourceFile==null && outputFile.exists()) outputFile.delete();
+ }
+ }
+
+ private Pattern buildMacroPattern(String macroName) {
+ StringBuffer b = new StringBuffer();
+ b.append(Pattern.quote("$")); //$NON-NLS-1$
+ b.append(macroName);
+ b.append("(?:"); //$NON-NLS-1$
+ b.append(Pattern.quote(":")); //$NON-NLS-1$
+ b.append("[^\\$]*)?"); //$NON-NLS-1$
+ b.append(Pattern.quote("$")); //$NON-NLS-1$
+ return Pattern.compile(b.toString(), Pattern.CASE_INSENSITIVE);
+ }
+
+ private Pattern buildMacroPatternWithGroup(String macroName) {
+ StringBuffer b = new StringBuffer();
+ b.append(Pattern.quote("$")); //$NON-NLS-1$
+ b.append(macroName);
+ b.append("(?:"); //$NON-NLS-1$
+ b.append(Pattern.quote(":")); //$NON-NLS-1$
+ b.append("([^\\$]*))?"); //$NON-NLS-1$
+ b.append(Pattern.quote("$")); //$NON-NLS-1$
+ return Pattern.compile(b.toString(), Pattern.CASE_INSENSITIVE);
+ }
+
+ /** Utility function that replace the macros by the replacement text in the given text.
+ *
+ * @param macroName is the name of the macro to replace.
+ * @param text is the text in which the replacement should occur
+ * @param replacement is the replacement text.
+ * @param type is the type of replacement to be 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);
+ }
+
+ /** Utility function that replace the macros by the replacement text in the given text.
+ *
+ * @param macroName is the name of the macro to replace.
+ * @param text is the text in which the replacement should occur
+ * @param replacement is the replacement text.
+ * @param type is the type of replacement to be done.
+ * @param enableWarning indicates if the warnings should be output or not.
+ * @return the result of the replacement
+ */
+ protected synchronized final String replaceMacro(String macroName, String text, String replacement, ReplacementType type, boolean enableWarning) {
+ if (replacement!=null && !EMPTY_STRING.equals(replacement)) {
+ getLog().debug("Replacing "+macroName+" by "+type.name()+": "+replacement); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ 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$
+ return text;
+ }
+
+ /** Replace the author information tags in the given text.
+ *
+ * @param text is the text in which the author tags should be replaced
+ * @param artifact
+ * @param replacementType is the type of replacement.
+ * @return the result of the replacement.
+ * @throws MojoExecutionException
+ */
+ protected synchronized String replaceAuthor(String text, ExtendedArtifact artifact, ReplacementType replacementType) throws MojoExecutionException {
+ String result = text;
+ Pattern p = buildMacroPatternWithGroup(MACRO_AUTHOR);
+ Matcher m = p.matcher(text);
+ boolean hasResult = m.find();
+
+ if (hasResult) {
+ StringBuffer sb = new StringBuffer();
+ StringBuffer replacement = new StringBuffer();
+ String login, link;
+ Contributor contributor;
+ do {
+ login = m.group(1);
+ if (login!=null) {
+ login = login.trim();
+ if (login.length()>0) {
+ replacement.setLength(0);
+ if (artifact!=null) {
+ contributor = artifact.getContributor(login);
+ if (contributor!=null) {
+ link = contributor.getUrl();
+ if (link==null || EMPTY_STRING.equals(link)) {
+ link = contributor.getEmail();
+ }
+ if (link==null || EMPTY_STRING.equals(link)) {
+ replacement.append(contributor.getName());
+ }
+ else if (replacementType==ReplacementType.HTML) {
+ replacement.append("<a target=\"_blank\" href=\""); //$NON-NLS-1$
+ replacement.append(link);
+ replacement.append("\">"); //$NON-NLS-1$
+ replacement.append(contributor.getName());
+ replacement.append("</a>"); //$NON-NLS-1$
+ }
+ else {
+ replacement.append(contributor.getName());
+ replacement.append(" ["); //$NON-NLS-1$
+ replacement.append(link);
+ replacement.append("]"); //$NON-NLS-1$
+ }
+ }
+ else {
+ throw new MojoExecutionException("unable to find a developer or a contributor with an id, a name or an email equal to: "+login); //$NON-NLS-1$
+ }
+ }
+ if (replacement.length()!=0) {
+ m.appendReplacement(sb, Matcher.quoteReplacement(replacement.toString()));
+ }
+ }
+ else {
+ throw new MojoExecutionException("no login for Author tag: "+m.group(0)); //$NON-NLS-1$
+ }
+ }
+ else {
+ throw new MojoExecutionException("no login for Author tag: "+m.group(0)); //$NON-NLS-1$
+ }
+ hasResult = m.find();
+ }
+ while (hasResult);
+
+ m.appendTail(sb);
+
+ result = sb.toString();
+ }
+ return result;
+ }
+
+ /** Replace Javadoc tags in a string.
+ *
+ * @param file is the name of the file in the hierarchy from which the string was extracted.
+ * @param artifact is the artifact in which the file is located. If <code>null</code>
+ * the tags dedicated to the artifact will be replaced by the empty string.
+ * @param line is the line in which the tags should be replaced.
+ * @param replacementType is the type of replacement to be done.
+ * @return the result of the replacement.
+ * @throws MojoExecutionException
+ */
+ protected synchronized String replaceInString(String file, ExtendedArtifact artifact, String line, ReplacementType replacementType) throws MojoExecutionException {
+ String nline = line;
+
+ String replacementName = (artifact==null) ? null : artifact.getName();
+ String replacementVersion = (artifact==null) ? null : artifact.getVersion();
+ String replacementRevision = (artifact==null) ? null : artifact.getScmRevision();
+ String replacementArtifactId = ensureArtifactId(artifact);
+ String replacementGroupId = ensureGroupId(artifact);
+ String replacementWebsite = (artifact==null) ? null : artifact.getWebsite();
+ String replacementFilename = (artifact==null) ? null : file;
+
+ String replacementOrganization = null;
+
+ if (artifact!=null) {
+ Organization orga = artifact.getOrganization();
+ if (orga!=null) {
+ replacementOrganization = orga.getName();
+ }
+ }
+
+ SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //$NON-NLS-1$
+ String currentDate = fmt.format(this.invocationDate);
+
+ String replacementFullVersion;
+ if (artifact==null) {
+ replacementFullVersion = null;
+ }
+ else {
+ String rev = null;
+ if (replacementRevision!=null) {
+ StringBuffer b = new StringBuffer();
+ b.append("(rev:"); //$NON-NLS-1$
+ b.append(replacementRevision);
+ b.append(")"); //$NON-NLS-1$
+ rev = b.toString();
+ }
+ replacementFullVersion = join(" ", //$NON-NLS-1$
+ 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);
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.setLength(0);
+ buffer.append("$Id: "); //$NON-NLS-1$
+ buffer.append(file);
+ buffer.append(' ');
+ if (replacementRevision!=null) {
+ buffer.append("rev:"); //$NON-NLS-1$
+ buffer.append(replacementRevision);
+ buffer.append(' ');
+ }
+ if (replacementVersion!=null) {
+ buffer.append('v');
+ buffer.append(replacementVersion);
+ buffer.append(' ');
+ }
+ buffer.append(currentDate);
+ buffer.append("$"); //$NON-NLS-1$
+ nline = replaceMacro(MACRO_ID, nline, buffer.toString(), ReplacementType.TEXT);
+
+ nline = replaceAuthor(nline, artifact, replacementType);
+
+ return nline;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized void checkMojoAttributes() throws MojoExecutionException {
+ assertNotNull("outputDirectory", this.outputDirectory); //$NON-NLS-1$
+ assertNotNull("sourceDirectory", this.sourceDirectory); //$NON-NLS-1$
+ assertNotNull("generatedSourceDirectory", this.generatedSourceDirectory); //$NON-NLS-1$
+ assertNotNull("artifactHandlerManager", this.artifactHandlerManager); //$NON-NLS-1$
+ assertNotNull("mavenProject", this.mavenProject); //$NON-NLS-1$
+ assertNotNull("artifactId", this.projectArtifactId); //$NON-NLS-1$
+ assertNotNull("groupId", this.projectGroupId); //$NON-NLS-1$
+ if (this.encoding==null)
+ this.encoding = System.getProperty("file.encoding"); //$NON-NLS-1$
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected File getBaseDirectory() {
+ return this.baseDirectory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected File getOutputDirectory() {
+ return this.outputDirectory;
+ }
+
+ /**
+ * Replies the directory where original source are located.
+ *
+ * @return the directory where original source are located.
+ * @see #getGeneratedSourceDirectory()
+ * @see #getClassDirectory()
+ */
+ protected File getSourceDirectory() {
+ return this.sourceDirectory;
+ }
+
+ /**
+ * Replies the directory where generated source are located.
+ *
+ * @return the directory where generated source are located.
+ * @see #getSourceDirectory()
+ * @see #getClassDirectory()
+ */
+ protected File getGeneratedSourceDirectory() {
+ return this.generatedSourceDirectory;
+ }
+
+ /**
+ * Replies the directory where generated classes are located.
+ *
+ * @return the directory where generated classes are located.
+ * @see #getSourceDirectory()
+ * @see #getOutputDirectory()
+ */
+ protected File getClassDirectory() {
+ return this.classDirectory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ArtifactHandlerManager getArtifactHandlerManager() {
+ return this.artifactHandlerManager;
+ }
+
+ /**
+ * Types of replacement.
+ *
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+ protected enum ReplacementType {
+ /** HTML replacement.
+ */
+ HTML,
+
+ /** Raw text replacement.
+ */
+ TEXT;
+
+ }
+
+}
Added: trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/GenerateSourceMojo.java
===================================================================
--- trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/GenerateSourceMojo.java (rev 0)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/GenerateSourceMojo.java 2011-08-13 13:08:58 UTC (rev 249)
@@ -0,0 +1,106 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2011 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.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.maven.plugins.tagreplacer;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.arakhne.maven.JavaSourceFileFilter;
+
+import java.io.File;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Map.Entry;
+
+/**
+ * Generate the Java source files and replace the macros by the corresponding values
+ * on the fly.
+ * Supported macros are described in {@link AbstractReplaceMojo}.
+ *
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ *
+ * @goal generatesrc
+ * @phase generate-sources
+ * @requireProject true
+ * @threadSafe
+ */
+public class GenerateSourceMojo extends AbstractReplaceMojo {
+
+ /** Are the directories where the source files are located.
+ * By default, the directory "src/main/java" is used.
+ *
+ * @parameter
+ */
+ private File[] sources;
+
+ /** Is the directory where the generated files are located.
+ * By default, the directory "target/generated-sources/java" is used.
+ *
+ * @parameter
+ */
+ private File outputLocation;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected synchronized void executeMojo() throws MojoExecutionException {
+ File[] sourceDirs;
+ File mainDirectory = new File(getSourceDirectory(), "main"); //$NON-NLS-1$
+ if (this.sources==null || this.sources.length==0) {
+ sourceDirs = new File[] {
+ new File(mainDirectory, "java"), //$NON-NLS-1$
+ };
+ }
+ else {
+ sourceDirs = this.sources;
+ }
+
+ File targetDir = null;
+ if (this.outputLocation==null) {
+ targetDir = new File(getGeneratedSourceDirectory(), "java"); //$NON-NLS-1$
+ }
+ else {
+ targetDir = this.outputLocation;
+ }
+
+ clearInternalBuffers();
+
+ Map<File,File> htmlBasedFiles = new TreeMap<File,File>();
+
+ for(File sourceDir : sourceDirs) {
+ if ( sourceDir.isDirectory() ) {
+ // Search for .java files
+ findFiles(sourceDir, new JavaSourceFileFilter(), htmlBasedFiles);
+ }
+ }
+
+ for(Entry<File,File> entry : htmlBasedFiles.entrySet()) {
+ String baseFile = removePathPrefix(entry.getValue(), entry.getKey());
+ replaceInFile(
+ entry.getKey(),
+ new File(targetDir, baseFile),
+ ReplacementType.HTML,
+ sourceDirs,
+ false);
+ }
+ }
+
+}
Added: 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 (rev 0)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/Macros.java 2011-08-13 13:08:58 UTC (rev 249)
@@ -0,0 +1,79 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2010-11 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.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.maven.plugins.tagreplacer;
+
+/**
+ * List of the macros strings.
+ *
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+public interface Macros {
+
+ /** $ArtifactId$
+ */
+ public static final String MACRO_ARTIFACTID = "ArtifactId"; //$NON-NLS-1$
+
+ /** $Author$
+ */
+ public static final String MACRO_AUTHOR = "Author"; //$NON-NLS-1$
+
+ /** $Date$
+ */
+ public static final String MACRO_DATE = "Date"; //$NON-NLS-1$
+
+ /** $Filename$
+ */
+ public static final String MACRO_FILENAME = "Filename"; //$NON-NLS-1$
+
+ /** $FullVersion$
+ */
+ public static final String MACRO_FULLVERSION = "FullVersion"; //$NON-NLS-1$
+
+ /** $GroupId$
+ */
+ public static final String MACRO_GROUPID = "GroupId"; //$NON-NLS-1$
+
+ /** $Id$
+ */
+ public static final String MACRO_ID = "Id"; //$NON-NLS-1$
+
+ /** $Name$
+ */
+ public static final String MACRO_NAME = "Name"; //$NON-NLS-1$
+
+ /** $Organization$
+ */
+ public static final String MACRO_ORGANIZATION = "Organization"; //$NON-NLS-1$
+
+ /** $Revision$
+ */
+ public static final String MACRO_REVISION = "Revision"; //$NON-NLS-1$
+
+ /** $Version$
+ */
+ public static final String MACRO_VERSION = "Version"; //$NON-NLS-1$
+
+ /** $Website$
+ */
+ public static final String MACRO_WEBSITE = "Website"; //$NON-NLS-1$
+
+}
Added: trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/ReplaceResourceMojo.java
===================================================================
--- trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/ReplaceResourceMojo.java (rev 0)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/ReplaceResourceMojo.java 2011-08-13 13:08:58 UTC (rev 249)
@@ -0,0 +1,88 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2011 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.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.maven.plugins.tagreplacer;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.arakhne.maven.PropertyFileFilter;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * Generate the property files and replace the macros by the corresponding values
+ * on the fly.
+ * Supported macros are described in {@link AbstractReplaceMojo}.
+ *
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ *
+ * @goal replaceresource
+ * @phase process-resources
+ * @requireProject true
+ * @threadSafe
+ */
+public class ReplaceResourceMojo extends AbstractReplaceMojo {
+
+ /** Are the directories where the property files are located.
+ * By default, the directory "target/classes" is used.
+ *
+ * @parameter
+ */
+ private File[] sources;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected synchronized void executeMojo() throws MojoExecutionException {
+ File[] sourceDirs;
+ if (this.sources==null || this.sources.length==0) {
+ sourceDirs = new File[] {
+ getClassDirectory()
+ };
+ }
+ else {
+ sourceDirs = this.sources;
+ }
+
+ clearInternalBuffers();
+
+ Collection<File> textBasedFiles = new ArrayList<File>();
+
+ for(File sourceDir : sourceDirs) {
+ if ( sourceDir.isDirectory() ) {
+ // Search for .properties files
+ findFiles(sourceDir, new PropertyFileFilter(), textBasedFiles);
+ }
+ }
+
+ for(File file : textBasedFiles) {
+ replaceInFile(
+ null,
+ file,
+ ReplacementType.TEXT,
+ sourceDirs,
+ true);
+ }
+ }
+
+}