[Arakhnę-Dev] [200] * Change prefix of the maven plugin. |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 200
Author: galland
Date: 2011-01-04 19:45:04 +0100 (Tue, 04 Jan 2011)
Log Message:
-----------
* Change prefix of the maven plugin.
Modified Paths:
--------------
trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/AbstractArakhneMojo.java
Added Paths:
-----------
trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/
trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/ReplaceMojo.java
Removed Paths:
-------------
trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/javadoc_tag_replacer/
trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/ReplaceMojo.java
Modified: trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/AbstractArakhneMojo.java
===================================================================
--- trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/javadoc_tag_replacer/AbstractArakhneMojo.java 2011-01-03 20:47:53 UTC (rev 194)
+++ trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/AbstractArakhneMojo.java 2011-01-04 18:45:04 UTC (rev 200)
@@ -18,7 +18,7 @@
* 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.javadoc_tag_replacer;
+package org.arakhne.maven.maven_javadoc_tag_replacer;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
Deleted: trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/ReplaceMojo.java
===================================================================
--- trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/javadoc_tag_replacer/ReplaceMojo.java 2011-01-03 20:47:53 UTC (rev 194)
+++ trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/ReplaceMojo.java 2011-01-04 18:45:04 UTC (rev 200)
@@ -1,672 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2010 Stéphane 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.javadoc_tag_replacer;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Replace all the Javadoc 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>$Date$</td><td>The date of the last compilation of the Maven module</td></tr>
- * <tr><td>$GroupId$</td><td>The group id of the Maven module</td></tr>
- * <tr><td>$Name$</td><td>The name of the Maven module</td></tr>
- * <tr><td>$Revision$</td><td>The version of the Maven module</td></tr>
- * <tr><td>$Version$</td><td>The version of the Maven module</td></tr>
- * </tbody>
- * </table>
- *
- * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
- * @version $Name$ $Revision$ $Date$
- * @mavengroupid $GroupId$
- * @mavenartifactid $ArtifactId$
- * @goal replace
- * @phase site
- * @requireProject true
- */
-public class ReplaceMojo extends AbstractArakhneMojo {
-
- private final Map<String,String> javaFileMap = new TreeMap<String,String>();
- private final Map<String,ExtendedArtifact> currentArtifact = new TreeMap<String,ExtendedArtifact>();
-
- /**
- * {@inheritDoc}
- */
- public void execute() throws MojoExecutionException {
- File javadocDir = new File(this.outputDirectory, "site"+File.separator+"apidocs"); //$NON-NLS-1$ //$NON-NLS-2$
-
- if ( javadocDir.isDirectory() ) {
-
- fillJavaFileMap(this.outputDirectory.getParentFile());
-
- // Search for files
- Collection<File> htmlFiles = findFiles(javadocDir, new HTMLFileFilter());
-
- try {
- // Replace in files
- for(File file : htmlFiles) {
- replaceInFile(file);
- }
- }
- finally {
- this.currentArtifact.clear();
- this.javaFileMap.clear();
- }
- }
- }
-
- private void fillJavaFileMap(File root) {
- getLog().info("Building module descriptions"); //$NON-NLS-1$
- Collection<File> javaFiles = findFiles(root, new JavaFileFilter());
- String pattern = "^(.*)"+File.separator //$NON-NLS-1$
- +"src"+File.separator //$NON-NLS-1$
- +"main"+File.separator //$NON-NLS-1$
- +"java"+File.separator //$NON-NLS-1$
- +"(.*)$"; //$NON-NLS-1$
- Pattern p = Pattern.compile(pattern);
- for(File file : javaFiles) {
- Matcher matcher = p.matcher(file.getAbsolutePath());
- if (matcher.find()) {
- String pomPath = matcher.group(1);
- File pomDirectory = new File(pomPath);
- String className = matcher.group(2);
-
- this.javaFileMap.put(className, pomPath);
-
- boolean foundPom = true;
- while (!this.currentArtifact.containsKey(pomPath) &&
- foundPom) {
- ExtendedArtifact artifact = readPom(pomDirectory, pomPath);
- if (artifact!=null) {
- this.currentArtifact.put(pomPath, artifact);
- getLog().info("Found module description for " //$NON-NLS-1$
- +artifact.toString());
- pomDirectory = pomDirectory.getParentFile();
- pomPath = pomDirectory.getAbsolutePath();
- }
- else {
- foundPom = false;
- }
- }
- }
- }
- }
-
- private ExtendedArtifact readPom(File pomDirectory, String pomPath) {
- String groupId = null;
- String artifactId = null;
- String name = null;
- String version = null;
-
- getLog().info("Parsing pom description for "+pomDirectory.toString()); //$NON-NLS-1$
-
- MavenXpp3Reader pomReader = new MavenXpp3Reader();
- try {
- Model model = pomReader.read(new FileReader(
- new File(pomDirectory, "pom.xml"))); //$NON-NLS-1$
- groupId = model.getGroupId();
- artifactId = model.getArtifactId();
- name = model.getName();
- version = model.getVersion();
- }
- catch (IOException e) {
- return null;
- }
- catch (XmlPullParserException e) {
- return null;
- }
-
- Artifact a = this.artifactFactory.createArtifact(groupId, artifactId, version, "runtime", "jar"); //$NON-NLS-1$//$NON-NLS-2$
- return new ExtendedArtifact(a, name);
- }
-
- private ExtendedArtifact searchArtifact(File file) {
- String pattern = "^(.+)"+File.separator //$NON-NLS-1$
- +"site"+File.separator //$NON-NLS-1$
- +"apidocs"+File.separator //$NON-NLS-1$
- +".*\\.html$"; //$NON-NLS-1$
- Pattern p = Pattern.compile(pattern);
- Matcher matcher = p.matcher(file.getAbsolutePath());
- if (matcher.find()) {
- File outDirectory = new File(matcher.group(1));
- String pomPath = outDirectory.getParent();
- ExtendedArtifact a = this.currentArtifact.get(pomPath);
- if (a!=null) {
- return a;
- }
- }
- return null;
- }
-
- private void replaceInFile(File file) throws MojoExecutionException {
-
- ExtendedArtifact artifact = searchArtifact(file);
-
- if (artifact!=null) {
- getLog().info("Replacing in "+file.getAbsolutePath()); //$NON-NLS-1$
- File outputFile = null;
- try {
- outputFile = new File(file.getAbsolutePath()+".maven.tmp"); //$NON-NLS-1$
- BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
- BufferedReader reader = new BufferedReader(new FileReader(file));
- String line = reader.readLine();
- while (line!=null) {
- line = replaceInString(artifact, line);
- writer.write(line);
- writer.write("\n"); //$NON-NLS-1$
- line = reader.readLine();
- }
- writer.close();
- reader.close();
- fileCopy(outputFile, file);
- outputFile.delete();
- }
- catch(IOException e) {
- throw new MojoExecutionException(e.getLocalizedMessage(), e);
- }
- finally {
- if (outputFile!=null && outputFile.exists()) outputFile.delete();
- }
- }
- else {
- getLog().error("Unable to found artifact description for "+file.toString()); //$NON-NLS-1$
- }
- }
-
- private String replaceInString(ExtendedArtifact artifact, String line) {
- String nline = line;
-
- if (artifact!=null) {
- SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd-HHmmss:SSS"); //$NON-NLS-1$
- nline = nline.replaceAll("[$]Name(:[^$]*)?[$]", artifact.getName()); //$NON-NLS-1$
- nline = nline.replaceAll("[$]Revision(:[^$]*)?[$]", artifact.getVersion()); //$NON-NLS-1$
- nline = nline.replaceAll("[$]Version(:[^$]*)?[$]", artifact.getVersion()); //$NON-NLS-1$
- nline = nline.replaceAll("[$]Date(:[^$]*)?[$]", fmt.format(this.invocationDate)); //$NON-NLS-1$
- nline = nline.replaceAll("[$]ArtifactId(:[^$]*)?[$]", artifact.getArtifactId()); //$NON-NLS-1$
- nline = nline.replaceAll("[$]GroupId(:[^$]*)?[$]", artifact.getGroupId()); //$NON-NLS-1$
- }
-
- return nline;
- }
-
- /**
- * Artifact with name.
- *
- * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
- * @version $Name$ $Revision$ $Date$
- * @mavengroupid $GroupId$
- * @mavenartifactid $ArtifactId$
- */
- private class ExtendedArtifact implements Artifact {
-
- private final String artifactName;
- private final Artifact original;
-
- /**
- * @param a
- * @param name
- */
- public ExtendedArtifact(Artifact a, String name) {
- this.original = a;
- this.artifactName = name;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return this.original.toString();
- }
-
- /** Replies the name of the artifact.
- *
- * @return the name of the artifact.
- */
- public String getName() {
- if (this.artifactName==null || "".equals(this.artifactName)) //$NON-NLS-1$
- return getArtifactId();
- return this.artifactName;
- }
-
- /**
- * {@inheritDoc}
- */
- public void addMetadata(ArtifactMetadata metadata) {
- this.original.addMetadata(metadata);
- }
-
- /**
- * {@inheritDoc}
- */
- public ArtifactHandler getArtifactHandler() {
- return this.original.getArtifactHandler();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getArtifactId() {
- return this.original.getArtifactId();
- }
-
- /**
- * {@inheritDoc}
- */
- public List<?> getAvailableVersions() {
- return this.original.getAvailableVersions();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getBaseVersion() {
- return this.original.getBaseVersion();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getClassifier() {
- return this.original.getClassifier();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getDependencyConflictId() {
- return this.original.getDependencyConflictId();
- }
-
- /**
- * {@inheritDoc}
- */
- public ArtifactFilter getDependencyFilter() {
- return this.original.getDependencyFilter();
- }
-
- /**
- * {@inheritDoc}
- */
- public List<?> getDependencyTrail() {
- return this.original.getDependencyTrail();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getDownloadUrl() {
- return this.original.getDownloadUrl();
- }
-
- /**
- * {@inheritDoc}
- */
- public File getFile() {
- return this.original.getFile();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getGroupId() {
- return this.original.getGroupId();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getId() {
- return this.original.getId();
- }
-
- /**
- * {@inheritDoc}
- */
- public Collection<?> getMetadataList() {
- return this.original.getMetadataList();
- }
-
- /**
- * {@inheritDoc}
- */
- public ArtifactRepository getRepository() {
- return this.original.getRepository();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getScope() {
- return this.original.getScope();
- }
-
- /**
- * {@inheritDoc}
- */
- public ArtifactVersion getSelectedVersion() throws OverConstrainedVersionException {
- return this.original.getSelectedVersion();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getType() {
- return this.original.getType();
- }
-
- /**
- * {@inheritDoc}
- */
- public String getVersion() {
- return this.original.getVersion();
- }
-
- /**
- * {@inheritDoc}
- */
- public VersionRange getVersionRange() {
- return this.original.getVersionRange();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean hasClassifier() {
- return this.original.hasClassifier();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isOptional() {
- return this.original.isOptional();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isRelease() {
- return this.original.isRelease();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isResolved() {
- return this.original.isResolved();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isSelectedVersionKnown() throws OverConstrainedVersionException {
- return this.original.isSelectedVersionKnown();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isSnapshot() {
- return this.original.isSnapshot();
- }
-
- /**
- * {@inheritDoc}
- */
- public void selectVersion(String version) {
- this.original.selectVersion(version);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setArtifactHandler(ArtifactHandler handler) {
- this.original.setArtifactHandler(handler);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setArtifactId(String artifactId) {
- this.original.setArtifactId(artifactId);
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public void setAvailableVersions(List versions) {
- this.original.setAvailableVersions(versions);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setBaseVersion(String baseVersion) {
- this.original.setBaseVersion(baseVersion);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setDependencyFilter(ArtifactFilter artifactFilter) {
- this.original.setDependencyFilter(artifactFilter);
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public void setDependencyTrail(List dependencyTrail) {
- this.original.setDependencyTrail(dependencyTrail);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setDownloadUrl(String downloadUrl) {
- this.original.setDownloadUrl(downloadUrl);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setFile(File destination) {
- this.original.setFile(destination);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setGroupId(String groupId) {
- this.original.setGroupId(groupId);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setRelease(boolean release) {
- this.original.setRelease(release);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setRepository(ArtifactRepository remoteRepository) {
- this.original.setRepository(remoteRepository);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setResolved(boolean resolved) {
- this.original.setResolved(resolved);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setResolvedVersion(String version) {
- this.original.setResolvedVersion(version);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setScope(String scope) {
- this.original.setScope(scope);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setVersion(String version) {
- this.original.setVersion(version);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setVersionRange(VersionRange newRange) {
- this.original.setVersionRange(newRange);
- }
-
- /**
- * {@inheritDoc}
- */
- public void updateVersion(String version, ArtifactRepository localRepository) {
- this.original.updateVersion(version, localRepository);
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public int compareTo(Object o) {
- return this.original.compareTo(o);
- }
-
- } // class ExtendedArtifact
-
- /**
- * File filter for HTML file.
- *
- * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
- * @version $Name$ $Revision$ $Date$
- * @mavengroupid $GroupId$
- * @mavenartifactid $ArtifactId$
- */
- private class HTMLFileFilter implements FileFilter {
-
- /**
- */
- public HTMLFileFilter() {
- //
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean accept(File pathname) {
- return pathname!=null &&
- (pathname.isDirectory() ||
- pathname.getName().endsWith(".html")); //$NON-NLS-1$
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "Hypertext (.html)"; //$NON-NLS-1$
- }
-
- } // class HTMLFileFilter
-
- /**
- * File filter for HTML Java file.
- *
- * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
- * @version $Name$ $Revision$ $Date$
- * @mavengroupid $GroupId$
- * @mavenartifactid $ArtifactId$
- */
- private class JavaFileFilter implements FileFilter {
-
- /**
- */
- public JavaFileFilter() {
- //
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean accept(File pathname) {
- return pathname!=null &&
- (pathname.isDirectory() ||
- pathname.getName().endsWith(".java")); //$NON-NLS-1$
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "Java Source (.java)"; //$NON-NLS-1$
- }
-
- } // class JavaFileFilter
-
-} // class ReplaceMojo
Copied: trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/ReplaceMojo.java (from rev 199, trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/javadoc_tag_replacer/ReplaceMojo.java)
===================================================================
--- trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/ReplaceMojo.java (rev 0)
+++ trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/maven_javadoc_tag_replacer/ReplaceMojo.java 2011-01-04 18:45:04 UTC (rev 200)
@@ -0,0 +1,874 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2010 Stéphane 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.maven_javadoc_tag_replacer;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.model.Contributor;
+import org.apache.maven.model.Developer;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Replace all the Javadoc 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>$Date$</td><td>The date of the last compilation of the Maven module</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>$Revision$</td><td>The version of the Maven module</td></tr>
+ * <tr><td>$Version$</td><td>The version of the Maven module</td></tr>
+ * </tbody>
+ * </table>
+ *
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ * @goal replace
+ * @phase site
+ * @requireProject true
+ */
+public class ReplaceMojo extends AbstractArakhneMojo {
+
+ private final Map<String,String> javaFileMap = new TreeMap<String,String>();
+ private final Map<String,ExtendedArtifact> currentArtifact = new TreeMap<String,ExtendedArtifact>();
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute() throws MojoExecutionException {
+ File javadocDir = new File(this.outputDirectory, "site"+File.separator+"apidocs"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ if ( javadocDir.isDirectory() ) {
+
+ fillJavaFileMap(this.outputDirectory.getParentFile());
+
+ // Search for files
+ Collection<File> htmlFiles = findFiles(javadocDir, new HTMLFileFilter());
+
+ try {
+ // Replace in files
+ for(File file : htmlFiles) {
+ String filename = file.toString().replace(javadocDir.toString(), ""); //$NON-NLS-1$
+ replaceInFile(file, filename);
+ }
+ }
+ finally {
+ this.currentArtifact.clear();
+ this.javaFileMap.clear();
+ }
+ }
+ }
+
+ private void fillJavaFileMap(File root) {
+ getLog().info("Building module descriptions"); //$NON-NLS-1$
+ Collection<File> javaFiles = findFiles(root, new JavaFileFilter());
+ String pattern = "^(.*)"+File.separator //$NON-NLS-1$
+ +"src"+File.separator //$NON-NLS-1$
+ +"main"+File.separator //$NON-NLS-1$
+ +"java"+File.separator //$NON-NLS-1$
+ +"(.*)\\.java$"; //$NON-NLS-1$
+ Pattern p = Pattern.compile(pattern);
+ for(File file : javaFiles) {
+ Matcher matcher = p.matcher(file.getAbsolutePath());
+ if (matcher.find()) {
+ String pomPath = matcher.group(1);
+ File pomDirectory = new File(pomPath);
+ String className = matcher.group(2);
+
+ this.javaFileMap.put(className, pomPath);
+
+ boolean foundPom = true;
+ while (!this.currentArtifact.containsKey(pomPath) &&
+ foundPom) {
+ ExtendedArtifact artifact = readPom(pomDirectory);
+ if (artifact!=null) {
+ this.currentArtifact.put(pomPath, artifact);
+ getLog().info("Found module description for " //$NON-NLS-1$
+ +artifact.toString());
+ pomDirectory = pomDirectory.getParentFile();
+ pomPath = pomDirectory.getAbsolutePath();
+ }
+ else {
+ foundPom = false;
+ }
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private ExtendedArtifact readPom(File pomDirectory) {
+ String groupId = null;
+ String artifactId = null;
+ String name = null;
+ String version = null;
+ List<Developer> developers;
+ List<Contributor> contributors;
+ Parent parent = null;
+
+ MavenXpp3Reader pomReader = new MavenXpp3Reader();
+ try {
+ Model model = pomReader.read(new FileReader(
+ new File(pomDirectory, "pom.xml"))); //$NON-NLS-1$
+ getLog().info("Parsing pom description for "+pomDirectory.toString()); //$NON-NLS-1$
+ groupId = model.getGroupId();
+ artifactId = model.getArtifactId();
+ name = model.getName();
+ version = model.getVersion();
+
+ developers = model.getDevelopers();
+ contributors = model.getContributors();
+
+ parent = model.getParent();
+ }
+ catch (IOException e) {
+ return null;
+ }
+ catch (XmlPullParserException e) {
+ return null;
+ }
+
+ if (developers==null) {
+ developers = new ArrayList<Developer>();
+ }
+ else {
+ List<Developer> list = new ArrayList<Developer>();
+ list.addAll(developers);
+ developers = list;
+ }
+ if (contributors==null) {
+ contributors = new ArrayList<Contributor>();
+ }
+ else {
+ List<Contributor> list = new ArrayList<Contributor>();
+ list.addAll(contributors);
+ contributors = list;
+ }
+
+ if (parent!=null) {
+ String relPath = parent.getRelativePath();
+ File parentPomDirectory = new File(pomDirectory, relPath);
+ try {
+ parentPomDirectory = parentPomDirectory.getCanonicalFile();
+ if (!parentPomDirectory.isDirectory()) {
+ parentPomDirectory = parentPomDirectory.getParentFile();
+ }
+ String parentPomPath = parentPomDirectory.getAbsolutePath();
+ ExtendedArtifact parentArtifact = this.currentArtifact.get(parentPomPath);
+ if (parentArtifact==null) {
+ parentArtifact = readPom(parentPomDirectory);
+ if (parentArtifact!=null) {
+ this.currentArtifact.put(parentPomPath, parentArtifact);
+ getLog().info("Found module description for " //$NON-NLS-1$
+ +parentArtifact.toString());
+ }
+ }
+ if (parentArtifact!=null) {
+ developers.addAll(parentArtifact.getDevelopers());
+ contributors.addAll(parentArtifact.getContributors());
+ }
+ }
+ catch (IOException e) {
+ getLog().warn(e);
+ }
+ }
+
+ Artifact a = this.artifactFactory.createArtifact(groupId, artifactId, version, "runtime", "jar"); //$NON-NLS-1$//$NON-NLS-2$
+ return new ExtendedArtifact(a, name, developers, contributors);
+ }
+
+ private ExtendedArtifact searchArtifact(File file) {
+ getLog().info("Retreiving module for "+file.getAbsolutePath()); //$NON-NLS-1$
+
+ String pattern = "^(.+)"+File.separator //$NON-NLS-1$
+ +"site"+File.separator //$NON-NLS-1$
+ +"apidocs"+File.separator //$NON-NLS-1$
+ +"(.+"+File.separator //$NON-NLS-1$
+ +".+?)(\\..+)?\\.html$"; //$NON-NLS-1$
+ Pattern p = Pattern.compile(pattern);
+ Matcher matcher = p.matcher(file.getAbsolutePath());
+ if (matcher.find()) {
+ String classname = matcher.group(2);
+ classname = classname.replaceAll(File.separator+"class[-]use", ""); //$NON-NLS-1$//$NON-NLS-2$
+ String pomPath = this.javaFileMap.get(classname);
+ if (pomPath!=null) {
+ ExtendedArtifact a = this.currentArtifact.get(pomPath);
+ if (a!=null) {
+ getLog().info("Found: "+a.toString()); //$NON-NLS-1$
+ return a;
+ }
+ }
+ pomPath = new File(matcher.group(1)).getParent();
+ ExtendedArtifact a = this.currentArtifact.get(pomPath);
+ if (a!=null) {
+ getLog().info("Found: "+a.toString()); //$NON-NLS-1$
+ return a;
+ }
+ getLog().info("Not Found: no pom description found"); //$NON-NLS-1$
+ }
+ else {
+ getLog().info("Not Found: regex is not matching"); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ private void replaceInFile(File file, String filename) throws MojoExecutionException {
+
+ ExtendedArtifact artifact = searchArtifact(file);
+
+ if (artifact!=null) {
+ getLog().info("Replacing in "+file.getAbsolutePath()); //$NON-NLS-1$
+ File outputFile = null;
+ try {
+ outputFile = new File(file.getAbsolutePath()+".maven.tmp"); //$NON-NLS-1$
+ BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
+ BufferedReader reader = new BufferedReader(new FileReader(file));
+ String line = reader.readLine();
+ while (line!=null) {
+ line = replaceInString(filename, artifact, line);
+ writer.write(line);
+ writer.write("\n"); //$NON-NLS-1$
+ line = reader.readLine();
+ }
+ writer.close();
+ reader.close();
+ fileCopy(outputFile, file);
+ outputFile.delete();
+ }
+ catch(IOException e) {
+ throw new MojoExecutionException(e.getLocalizedMessage(), e);
+ }
+ finally {
+ if (outputFile!=null && outputFile.exists()) outputFile.delete();
+ }
+ }
+ else {
+ getLog().warn("Unable to found artifact description for "+file.toString()); //$NON-NLS-1$
+ }
+ }
+
+ private String replace(String pattern, String text, String replacement) {
+ Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
+ Matcher m = p.matcher(text);
+ return m.replaceAll(replacement);
+ }
+
+ private String replaceAuthor(String text, ExtendedArtifact artifact) throws MojoExecutionException {
+ String result = text;
+ Pattern p = Pattern.compile("[$]Author:([^$]+)[$]", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+ 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) {
+ contributor = artifact.getContributor(login);
+ if (contributor!=null) {
+ replacement.setLength(0);
+ link = contributor.getUrl();
+ if (link==null || "".equals(link)) { //$NON-NLS-1$
+ link = contributor.getEmail();
+ }
+ if (link==null || "".equals(link)) { //$NON-NLS-1$
+ replacement.append(contributor.getName());
+ }
+ else {
+ 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$
+ }
+ m.appendReplacement(sb, replacement.toString());
+ }
+ 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$
+ }
+ }
+ 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;
+ }
+
+ private String replaceInString(String file, ExtendedArtifact artifact, String line) throws MojoExecutionException {
+ String nline = line;
+
+ if (artifact!=null) {
+ StringBuffer buffer = new StringBuffer();
+
+ nline = replace("[$]Name(:[^$]*)?[$]", nline, artifact.getName()); //$NON-NLS-1$
+ nline = replace("[$]Revision(:[^$]*)?[$]", nline, artifact.getVersion()); //$NON-NLS-1$
+ nline = replace("[$]Version(:[^$]*)?[$]", nline, artifact.getVersion()); //$NON-NLS-1$
+ nline = replace("[$]ArtifactId(:[^$]*)?[$]", nline, artifact.getArtifactId()); //$NON-NLS-1$
+ nline = replace("[$]GroupId(:[^$]*)?[$]", nline, artifact.getGroupId()); //$NON-NLS-1$
+
+ SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd-HHmmss:SSS"); //$NON-NLS-1$
+ String currentDate = fmt.format(this.invocationDate);
+ nline = replace("[$]Date(:[^$]*)?[$]", nline, currentDate); //$NON-NLS-1$
+
+ buffer.setLength(0);
+ buffer.append("$Id: "); //$NON-NLS-1$
+ buffer.append(file);
+ buffer.append(' ');
+ buffer.append(artifact.getVersion());
+ buffer.append(' ');
+ buffer.append(currentDate);
+ buffer.append("$"); //$NON-NLS-1$
+ nline = replace("[$]Id(:[^$]*)?[$]", nline, buffer.toString()); //$NON-NLS-1$
+
+ nline = replaceAuthor(nline, artifact);
+ }
+
+ return nline;
+ }
+
+ /**
+ * Artifact with name.
+ *
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+ private class ExtendedArtifact implements Artifact {
+
+ private final String artifactName;
+ private final Artifact original;
+ private final List<? extends Developer> developers;
+ private final List<? extends Contributor> contributors;
+
+ /**
+ * @param a
+ * @param name
+ * @param developers
+ * @param contributors
+ */
+ public ExtendedArtifact(Artifact a, String name, List<? extends Developer> developers, List<? extends Contributor> contributors) {
+ this.original = a;
+ this.artifactName = name;
+ this.developers = developers;
+ this.contributors = contributors;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return this.original.toString();
+ }
+
+ /** Replies the list of contributors.
+ *
+ * @return the list of contributors.
+ */
+ public List<? extends Contributor> getContributors() {
+ return this.contributors==null ? Collections.<Contributor>emptyList() : this.contributors;
+ }
+
+ /** Replies the list of developers.
+ *
+ * @return the list of developers.
+ */
+ public List<? extends Developer> getDevelopers() {
+ return this.developers==null ? Collections.<Developer>emptyList() : this.developers;
+ }
+
+ /** Replies the contributor for the given login.
+ *
+ * @param login
+ * @return the contributor or <code>null</code>
+ */
+ public Contributor getContributor(String login) {
+ for(Developer devel : getDevelopers()) {
+ if (devel!=null &&
+ (login.equals(devel.getId())
+ ||login.equals(devel.getName())
+ ||login.equals(devel.getEmail()))) {
+ return devel;
+ }
+ }
+ for(Contributor contrib : getContributors()) {
+ if (contrib!=null &&
+ (login.equals(contrib.getName())
+ ||login.equals(contrib.getEmail()))) {
+ return contrib;
+ }
+ }
+ return null;
+ }
+
+ /** Replies the name of the artifact.
+ *
+ * @return the name of the artifact.
+ */
+ public String getName() {
+ if (this.artifactName==null || "".equals(this.artifactName)) //$NON-NLS-1$
+ return getArtifactId();
+ return this.artifactName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addMetadata(ArtifactMetadata metadata) {
+ this.original.addMetadata(metadata);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ArtifactHandler getArtifactHandler() {
+ return this.original.getArtifactHandler();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getArtifactId() {
+ return this.original.getArtifactId();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<?> getAvailableVersions() {
+ return this.original.getAvailableVersions();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getBaseVersion() {
+ return this.original.getBaseVersion();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getClassifier() {
+ return this.original.getClassifier();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDependencyConflictId() {
+ return this.original.getDependencyConflictId();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ArtifactFilter getDependencyFilter() {
+ return this.original.getDependencyFilter();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<?> getDependencyTrail() {
+ return this.original.getDependencyTrail();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDownloadUrl() {
+ return this.original.getDownloadUrl();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public File getFile() {
+ return this.original.getFile();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getGroupId() {
+ return this.original.getGroupId();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getId() {
+ return this.original.getId();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection<?> getMetadataList() {
+ return this.original.getMetadataList();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ArtifactRepository getRepository() {
+ return this.original.getRepository();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getScope() {
+ return this.original.getScope();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ArtifactVersion getSelectedVersion() throws OverConstrainedVersionException {
+ return this.original.getSelectedVersion();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getType() {
+ return this.original.getType();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getVersion() {
+ return this.original.getVersion();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public VersionRange getVersionRange() {
+ return this.original.getVersionRange();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasClassifier() {
+ return this.original.hasClassifier();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isOptional() {
+ return this.original.isOptional();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isRelease() {
+ return this.original.isRelease();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isResolved() {
+ return this.original.isResolved();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSelectedVersionKnown() throws OverConstrainedVersionException {
+ return this.original.isSelectedVersionKnown();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSnapshot() {
+ return this.original.isSnapshot();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void selectVersion(String version) {
+ this.original.selectVersion(version);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setArtifactHandler(ArtifactHandler handler) {
+ this.original.setArtifactHandler(handler);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setArtifactId(String artifactId) {
+ this.original.setArtifactId(artifactId);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public void setAvailableVersions(List versions) {
+ this.original.setAvailableVersions(versions);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setBaseVersion(String baseVersion) {
+ this.original.setBaseVersion(baseVersion);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDependencyFilter(ArtifactFilter artifactFilter) {
+ this.original.setDependencyFilter(artifactFilter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public void setDependencyTrail(List dependencyTrail) {
+ this.original.setDependencyTrail(dependencyTrail);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDownloadUrl(String downloadUrl) {
+ this.original.setDownloadUrl(downloadUrl);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setFile(File destination) {
+ this.original.setFile(destination);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setGroupId(String groupId) {
+ this.original.setGroupId(groupId);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setRelease(boolean release) {
+ this.original.setRelease(release);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setRepository(ArtifactRepository remoteRepository) {
+ this.original.setRepository(remoteRepository);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setResolved(boolean resolved) {
+ this.original.setResolved(resolved);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setResolvedVersion(String version) {
+ this.original.setResolvedVersion(version);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setScope(String scope) {
+ this.original.setScope(scope);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setVersion(String version) {
+ this.original.setVersion(version);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setVersionRange(VersionRange newRange) {
+ this.original.setVersionRange(newRange);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void updateVersion(String version, ArtifactRepository localRepository) {
+ this.original.updateVersion(version, localRepository);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public int compareTo(Object o) {
+ return this.original.compareTo(o);
+ }
+
+ } // class ExtendedArtifact
+
+ /**
+ * File filter for HTML file.
+ *
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+ private class HTMLFileFilter implements FileFilter {
+
+ /**
+ */
+ public HTMLFileFilter() {
+ //
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean accept(File pathname) {
+ return pathname!=null &&
+ (pathname.isDirectory() ||
+ pathname.getName().endsWith(".html")); //$NON-NLS-1$
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "Hypertext (.html)"; //$NON-NLS-1$
+ }
+
+ } // class HTMLFileFilter
+
+ /**
+ * File filter for HTML Java file.
+ *
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+ private class JavaFileFilter implements FileFilter {
+
+ /**
+ */
+ public JavaFileFilter() {
+ //
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean accept(File pathname) {
+ return pathname!=null &&
+ (pathname.isDirectory() ||
+ pathname.getName().endsWith(".java")); //$NON-NLS-1$
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "Java Source (.java)"; //$NON-NLS-1$
+ }
+
+ } // class JavaFileFilter
+
+} // class ReplaceMojo