[Arakhnę-Dev] [197] * Add $Author$ special tag in javadoc. |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 197
Author: galland
Date: 2011-01-04 18:53:05 +0100 (Tue, 04 Jan 2011)
Log Message:
-----------
* Add $Author$ special tag in javadoc.
Modified Paths:
--------------
trunk/arakhneLog4J/pom.xml
trunk/arakhneLogger/pom.xml
trunk/arakhneRefs/pom.xml
trunk/arakhneVmutils/pom.xml
trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/javadoc_tag_replacer/ReplaceMojo.java
Modified: trunk/arakhneLog4J/pom.xml
===================================================================
--- trunk/arakhneLog4J/pom.xml 2011-01-03 23:49:51 UTC (rev 196)
+++ trunk/arakhneLog4J/pom.xml 2011-01-04 17:53:05 UTC (rev 197)
@@ -74,6 +74,19 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>maven-javadoc-tag-replacer</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>site</phase>
+ <goals>
+ <goal>replace</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified: trunk/arakhneLogger/pom.xml
===================================================================
--- trunk/arakhneLogger/pom.xml 2011-01-03 23:49:51 UTC (rev 196)
+++ trunk/arakhneLogger/pom.xml 2011-01-04 17:53:05 UTC (rev 197)
@@ -61,6 +61,19 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>maven-javadoc-tag-replacer</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>site</phase>
+ <goals>
+ <goal>replace</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified: trunk/arakhneRefs/pom.xml
===================================================================
--- trunk/arakhneRefs/pom.xml 2011-01-03 23:49:51 UTC (rev 196)
+++ trunk/arakhneRefs/pom.xml 2011-01-04 17:53:05 UTC (rev 197)
@@ -69,6 +69,19 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>maven-javadoc-tag-replacer</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>site</phase>
+ <goals>
+ <goal>replace</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified: trunk/arakhneVmutils/pom.xml
===================================================================
--- trunk/arakhneVmutils/pom.xml 2011-01-03 23:49:51 UTC (rev 196)
+++ trunk/arakhneVmutils/pom.xml 2011-01-04 17:53:05 UTC (rev 197)
@@ -53,6 +53,19 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>maven-javadoc-tag-replacer</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>site</phase>
+ <goals>
+ <goal>replace</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified: 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/javadoc_tag_replacer/ReplaceMojo.java 2011-01-03 23:49:51 UTC (rev 196)
+++ trunk/maven-javadoc-tag-replacer/src/main/java/org/arakhne/maven/javadoc_tag_replacer/ReplaceMojo.java 2011-01-04 17:53:05 UTC (rev 197)
@@ -28,7 +28,10 @@
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;
@@ -41,7 +44,9 @@
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;
@@ -58,6 +63,7 @@
* <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>
@@ -93,7 +99,8 @@
try {
// Replace in files
for(File file : htmlFiles) {
- replaceInFile(file);
+ String filename = file.toString().replace(javadocDir.toString(), ""); //$NON-NLS-1$
+ replaceInFile(file, filename);
}
}
finally {
@@ -124,7 +131,7 @@
boolean foundPom = true;
while (!this.currentArtifact.containsKey(pomPath) &&
foundPom) {
- ExtendedArtifact artifact = readPom(pomDirectory, pomPath);
+ ExtendedArtifact artifact = readPom(pomDirectory);
if (artifact!=null) {
this.currentArtifact.put(pomPath, artifact);
getLog().info("Found module description for " //$NON-NLS-1$
@@ -140,22 +147,30 @@
}
}
- private ExtendedArtifact readPom(File pomDirectory, String pomPath) {
+ @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;
- 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$
+ 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;
@@ -163,9 +178,54 @@
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().error(e);
+ }
+ }
+
Artifact a = this.artifactFactory.createArtifact(groupId, artifactId, version, "runtime", "jar"); //$NON-NLS-1$//$NON-NLS-2$
- return new ExtendedArtifact(a, name);
+ return new ExtendedArtifact(a, name, developers, contributors);
}
private ExtendedArtifact searchArtifact(File file) {
@@ -203,7 +263,7 @@
return null;
}
- private void replaceInFile(File file) throws MojoExecutionException {
+ private void replaceInFile(File file, String filename) throws MojoExecutionException {
ExtendedArtifact artifact = searchArtifact(file);
@@ -216,7 +276,7 @@
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
while (line!=null) {
- line = replaceInString(artifact, line);
+ line = replaceInString(filename, artifact, line);
writer.write(line);
writer.write("\n"); //$NON-NLS-1$
line = reader.readLine();
@@ -238,17 +298,96 @@
}
}
- private String replaceInString(ExtendedArtifact artifact, String line) {
+ 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$
- 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$
+ 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;
@@ -266,14 +405,20 @@
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) {
+ 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;
}
/**
@@ -284,6 +429,46 @@
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.