[Arakhnę-Dev] [239] * Prepare for Maven 3 |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 239
Author: galland
Date: 2011-08-06 16:07:15 +0200 (Sat, 06 Aug 2011)
Log Message:
-----------
* Prepare for Maven 3
Modified Paths:
--------------
trunk/arakhneLog4J/pom.xml
trunk/arakhneLogger/pom.xml
trunk/arakhneRefs/pom.xml
trunk/arakhneVmutils/java/pom.xml
trunk/license-installer/src/main/java/org/arakhne/maven/plugins/licenseinstaller/InstallLicenseMojo.java
trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
trunk/tag-replacer/pom.xml
trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/AbstractReplaceMojo.java
trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/ReplaceSourceMojo.java
Removed Paths:
-------------
trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/ReplaceHtmlMojo.java
Modified: trunk/arakhneLog4J/pom.xml
===================================================================
--- trunk/arakhneLog4J/pom.xml 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/arakhneLog4J/pom.xml 2011-08-06 14:07:15 UTC (rev 239)
@@ -36,6 +36,26 @@
</dependencies>
<build>
+ <!--
+ Configure the source files as resources to be filtered into a custom
+ target directory
+ -->
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <filtering>true</filtering>
+ <targetPath>${project.build.directory}/generated-sources/java</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <!--
+ Overrule the default pom source directory to match our generated
+ sources so the compiler will pick them up
+ -->
+ <sourceDirectory>${project.build.directory}/generated-sources/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -78,9 +98,9 @@
<artifactId>tag-replacer</artifactId>
<executions>
<execution>
- <phase>site</phase>
+ <phase>process-resources</phase>
<goals>
- <goal>replacehtml</goal>
+ <goal>replacesrc</goal>
</goals>
</execution>
</executions>
Modified: trunk/arakhneLogger/pom.xml
===================================================================
--- trunk/arakhneLogger/pom.xml 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/arakhneLogger/pom.xml 2011-08-06 14:07:15 UTC (rev 239)
@@ -24,6 +24,26 @@
<!-- ======================================= -->
<build>
+ <!--
+ Configure the source files as resources to be filtered into a custom
+ target directory
+ -->
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <filtering>true</filtering>
+ <targetPath>${project.build.directory}/generated-sources/java</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <!--
+ Overrule the default pom source directory to match our generated
+ sources so the compiler will pick them up
+ -->
+ <sourceDirectory>${project.build.directory}/generated-sources/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -66,9 +86,9 @@
<artifactId>tag-replacer</artifactId>
<executions>
<execution>
- <phase>site</phase>
+ <phase>process-resources</phase>
<goals>
- <goal>replacehtml</goal>
+ <goal>replacesrc</goal>
</goals>
</execution>
</executions>
Modified: trunk/arakhneRefs/pom.xml
===================================================================
--- trunk/arakhneRefs/pom.xml 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/arakhneRefs/pom.xml 2011-08-06 14:07:15 UTC (rev 239)
@@ -32,6 +32,26 @@
</dependencies>
<build>
+ <!--
+ Configure the source files as resources to be filtered into a custom
+ target directory
+ -->
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <filtering>true</filtering>
+ <targetPath>${project.build.directory}/generated-sources/java</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <!--
+ Overrule the default pom source directory to match our generated
+ sources so the compiler will pick them up
+ -->
+ <sourceDirectory>${project.build.directory}/generated-sources/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -74,9 +94,9 @@
<artifactId>tag-replacer</artifactId>
<executions>
<execution>
- <phase>site</phase>
+ <phase>process-resources</phase>
<goals>
- <goal>replacehtml</goal>
+ <goal>replacesrc</goal>
</goals>
</execution>
</executions>
Modified: trunk/arakhneVmutils/java/pom.xml
===================================================================
--- trunk/arakhneVmutils/java/pom.xml 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/arakhneVmutils/java/pom.xml 2011-08-06 14:07:15 UTC (rev 239)
@@ -31,6 +31,26 @@
<!-- ======================================= -->
<build>
+ <!--
+ Configure the source files as resources to be filtered into a custom
+ target directory
+ -->
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <filtering>true</filtering>
+ <targetPath>${project.build.directory}/generated-sources/java</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <!--
+ Overrule the default pom source directory to match our generated
+ sources so the compiler will pick them up
+ -->
+ <sourceDirectory>${project.build.directory}/generated-sources/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
@@ -80,24 +100,24 @@
</instructions>
</configuration>
</plugin>
- <plugin>
- <groupId>org.arakhne.afc</groupId>
- <artifactId>tag-replacer</artifactId>
- <executions>
- <execution>
- <phase>site</phase>
- <goals>
- <goal>replacehtml</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <groupId>${project.groupId}</groupId>
- <artifactId>arakhneVmutils</artifactId>
- </configuration>
- </plugin>
<plugin>
<groupId>org.arakhne.afc</groupId>
+ <artifactId>tag-replacer</artifactId>
+ <executions>
+ <execution>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>replacesrc</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <projectGroupId>${project.groupId}</projectGroupId>
+ <projectArtifactId>arakhneVmutils</projectArtifactId>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.arakhne.afc</groupId>
<artifactId>license-installer</artifactId>
<executions>
<execution>
Modified: trunk/license-installer/src/main/java/org/arakhne/maven/plugins/licenseinstaller/InstallLicenseMojo.java
===================================================================
--- trunk/license-installer/src/main/java/org/arakhne/maven/plugins/licenseinstaller/InstallLicenseMojo.java 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/license-installer/src/main/java/org/arakhne/maven/plugins/licenseinstaller/InstallLicenseMojo.java 2011-08-06 14:07:15 UTC (rev 239)
@@ -55,6 +55,7 @@
* @goal installlicense
* @phase compile
* @requireProject true
+ * @threadSafe
*/
public class InstallLicenseMojo extends AbstractArakhneMojo implements Constants {
@@ -62,6 +63,10 @@
*/
private ArtifactHandlerManager artifactHandlerManager;
+ /** @parameter expression="${project.basedir}"
+ */
+ private File baseDirectory;
+
/** @parameter expression="${project.build.directory}"
*/
private File outputDirectory;
@@ -122,7 +127,7 @@
/** {@inheritDoc}
*/
@Override
- public void checkMojoAttributes() {
+ public synchronized void checkMojoAttributes() {
assertNotNull("copyrightDates", this.copyrightDates); //$NON-NLS-1$
assertNotNull("copyrighters", this.copyrighters); //$NON-NLS-1$
assertNotNull("licenses", this.licenses); //$NON-NLS-1$
@@ -135,7 +140,7 @@
* {@inheritDoc}
*/
@Override
- public void executeMojo() throws MojoExecutionException {
+ public synchronized void executeMojo() throws MojoExecutionException {
if ("pom".equalsIgnoreCase(this.mavenProject.getPackaging())) { //$NON-NLS-1$
String key = ArtifactUtils.key(
this.mavenProject.getGroupId(),
@@ -343,6 +348,14 @@
* {@inheritDoc}
*/
@Override
+ protected File getBaseDirectory() {
+ return this.baseDirectory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
protected ArtifactHandlerManager getArtifactHandlerManager() {
return this.artifactHandlerManager;
}
Modified: trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java 2011-08-06 14:07:15 UTC (rev 239)
@@ -38,8 +38,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
-
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
@@ -63,6 +61,7 @@
/**
* Abstract implementation for all Arakhnê maven modules.
+ * This implementation is thread safe.
*
* @author $Author: galland$
* @version $Name$ $Revision$ $Date$
@@ -98,7 +97,7 @@
* @param out
* @throws IOException
*/
- public static void fileCopy(File in, File out) throws IOException {
+ public void fileCopy(File in, File out) throws IOException {
assert(in!=null);
assert(out!=null);
FileChannel inChannel = new FileInputStream(in).getChannel();
@@ -118,7 +117,7 @@
* @param out
* @throws IOException
*/
- public static void fileCopy(URL in, File out) throws IOException {
+ public void fileCopy(URL in, File out) throws IOException {
assert(in!=null);
InputStream inStream = in.openStream();
OutputStream outStream = new FileOutputStream(out);
@@ -143,7 +142,7 @@
* @param params are the parameters to replace.
* @return the read text.
*/
- public static String getLString(Class<?> source, String label, Object... params) {
+ public String getLString(Class<?> source, String label, Object... params) {
ResourceBundle rb = ResourceBundle.getBundle(source.getCanonicalName());
String text = rb.getString(label);
text = text.replaceAll("[\\n\\r]","\n"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -152,22 +151,63 @@
return text;
}
+ /** Remove the path prefix from a file.
+ *
+ * @param prefix
+ * @param file
+ * @return the <var>file</var> without the prefix.
+ */
+ public String removePathPrefix(File prefix, File file) {
+ StringBuffer b = new StringBuffer();
+ b.append("^"); //$NON-NLS-1$
+ b.append(Pattern.quote(prefix.getAbsolutePath()));
+ String r = file.getAbsolutePath().replaceFirst(b.toString(), EMPTY_STRING);
+ if (r.startsWith(File.separator))
+ return r.substring(File.separator.length());
+ return r;
+ }
+
+ /** Quote the dollar and backslash characters in a replacement text.
+ *
+ * @param replacement is the replacement text.
+ * @return the quoted replacement text
+ * @see #unquoteReplacementText(String)
+ * @see Matcher#replaceAll(String)
+ * @see String#replaceAll(String, String)
+ * @see Pattern#quote(String)
+ */
+ public String quoteReplacementText(String replacement) {
+ // Protect the dollar and backslashs signs
+ String s = replacement.replaceAll(Pattern.quote("$"), "$"); //$NON-NLS-1$//$NON-NLS-2$
+ s = s.replaceAll(Pattern.quote("\\\\"), "\"); //$NON-NLS-1$//$NON-NLS-2$
+ return s;
+ }
+
+ /** Unquote the dollar and backslash characters in a replacement text.
+ *
+ * @param replacement is the replacement text.
+ * @return the unquoted replacement text
+ * @see #quoteReplacementText(String)
+ * @see Matcher#replaceAll(String)
+ * @see String#replaceAll(String, String)
+ * @see Pattern#quote(String)
+ */
+ public String unquoteReplacementText(String replacement) {
+ // Unprotect the dollar and backslashs signs
+ String s = replacement;
+ s = s.replaceAll(Pattern.quote("$"), "\\$"); //$NON-NLS-1$//$NON-NLS-2$
+ s = s.replaceAll(Pattern.quote("\"), "\\\\"); //$NON-NLS-1$//$NON-NLS-2$
+ return s;
+ }
+
/** Invocation date.
*/
protected final Date invocationDate = new Date();
- /** Map the Java classname to the directory name where
- * the pom.xml file of the corresponding mave module
- * may be found.
- */
- private final Map<String,File> classToPomDirectoryMap = new TreeMap<String,File>();
-
- private AtomicBoolean isClassToPomDirectoryFilled = new AtomicBoolean(false);
-
/** Map the directory of pom.xml files to the definition
* of the corresponding maven module.
*/
- private final Map<File,ExtendedArtifact> pomDirectoryToArtifactMap = new TreeMap<File,ExtendedArtifact>();
+ private final Map<File,ExtendedArtifact> artifactDescriptions = new TreeMap<File,ExtendedArtifact>();
/** Replies the artifact handler manager.
* <p>
@@ -182,7 +222,8 @@
*/
protected abstract ArtifactHandlerManager getArtifactHandlerManager();
- /** Replies the output directory.
+ /** Replies the output directory of the project.
+ * Basically it is <code>getRootDirectory()+"/target"</code>.
* <p>
* It is an attribute defined as:
* <code><pre>
@@ -195,89 +236,55 @@
*/
protected abstract File getOutputDirectory();
- /** Fill the attribute {@link #javaFileMap}.
- *
- * @param root is the root directory to explore.
- */
- private void fillJavaFileMap(File root) {
- if (!this.isClassToPomDirectoryFilled.getAndSet(true)) {
- getLog().info("Building module descriptions"); //$NON-NLS-1$
- Collection<File> javaFiles = findFiles(root, new PropertyFileFilter());
- 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()) {
- File pomDirectory = new File(matcher.group(1));
- String className = matcher.group(2);
-
- this.classToPomDirectoryMap.put(className, pomDirectory);
-
- // Fill the artifacts for project where the classname was
- // found and for all the parent projects.
- boolean foundPom = true;
- while (pomDirectory!=null
- &&!this.pomDirectoryToArtifactMap.containsKey(pomDirectory)
- &&foundPom) {
- ExtendedArtifact artifact = readPom(pomDirectory);
- if (artifact!=null) {
- this.pomDirectoryToArtifactMap.put(pomDirectory, artifact);
- getLog().info("Found module description for " //$NON-NLS-1$
- +artifact.toString());
- pomDirectory = pomDirectory.getParentFile();
- }
- else {
- foundPom = false;
- }
- }
- }
- }
- }
- }
+ /** Replies the root directory of the project.
+ * Basically it is the value stored inside the
+ * Maven property named <code>project.basedir</code>.
+ * <p>
+ * It is an attribute defined as:
+ * <code><pre>
+ * <span>/</span>* <span>@</span>parameter expression="${project.basedir}"
+ * <span>*</span>/
+ * private File baseDirectory;
+ * </pre></code>
+ *
+ * @return the root directory.
+ */
+ protected abstract File getBaseDirectory();
/** Search and reply the maven artifact which is corresponding to the given file.
*
* @param file is the file for which the maven artifact should be retreived.
* @return the maven artifact or <code>null</code> if none.
*/
- protected ExtendedArtifact searchArtifact(File file) {
- fillJavaFileMap(getOutputDirectory().getParentFile());
+ protected synchronized ExtendedArtifact searchArtifact(File file) {
+ String filename = removePathPrefix(getBaseDirectory(), file);
- getLog().info("Retreiving module for "+file.getAbsolutePath()); //$NON-NLS-1$
+ getLog().debug("Retreiving module for "+filename); //$NON-NLS-1$
+
+ File theFile = file;
+ File pomDirectory = null;
+ while (theFile!=null && pomDirectory==null) {
+ if (theFile.isDirectory()) {
+ File pomFile = new File(theFile, "pom.xml"); //$NON-NLS-1$
+ if (pomFile.exists()) {
+ pomDirectory = theFile;
+ }
+ }
+ theFile = theFile.getParentFile();
+ }
+
+ if (pomDirectory!=null) {
+ ExtendedArtifact a = this.artifactDescriptions.get(pomDirectory);
+ if (a==null) {
+ a = readPom(pomDirectory);
+ this.artifactDescriptions.put(pomDirectory, a);
+ getLog().debug("Found module description for " //$NON-NLS-1$
+ +a.toString());
+ }
+ return a;
+ }
- 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", EMPTY_STRING); //$NON-NLS-1$
- File pomPath = this.classToPomDirectoryMap.get(classname);
- if (pomPath!=null) {
- ExtendedArtifact a = this.pomDirectoryToArtifactMap.get(pomPath);
- if (a!=null) {
- getLog().info("Found: "+a.toString()); //$NON-NLS-1$
- return a;
- }
- }
- pomPath = new File(matcher.group(1)).getParentFile();
- ExtendedArtifact a = this.pomDirectoryToArtifactMap.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$
- }
+ getLog().warn("maven module not found"); //$NON-NLS-1$
return null;
}
@@ -287,18 +294,32 @@
* @param filter is the file selector
* @return the list of files.
*/
- protected Collection<File> findFiles(File directory, FileFilter filter) {
- Collection<File> selectedFiles = new ArrayList<File>();
+ protected final Collection<File> findFiles(File directory, FileFilter filter) {
+ Collection<File> files = new ArrayList<File>();
+ findFiles(directory, filter, files);
+ return files;
+ }
+
+ /** Replies a list of files which are found on the file system.
+ *
+ * @param directory is the directory to search in.
+ * @param filter is the file selector
+ * @param fileOut is the list of files to fill.
+ */
+ protected synchronized void findFiles(File directory, FileFilter filter, Collection<? super File> fileOut) {
if (directory!=null && filter!=null) {
File candidate;
List<File> candidates = new ArrayList<File>();
- getLog().info("Retreiving " //$NON-NLS-1$
+ String relativePath = removePathPrefix(getBaseDirectory(), directory);
+
+ getLog().debug("Retreiving " //$NON-NLS-1$
+filter.toString()
+" files from " //$NON-NLS-1$
- +directory.getAbsolutePath());
+ +relativePath);
candidates.add(directory);
+ int nbFiles = 0;
while (!candidates.isEmpty()) {
candidate = candidates.remove(0);
@@ -310,25 +331,25 @@
candidates.add(child);
}
else {
- selectedFiles.add(child);
+ fileOut.add(child);
+ ++nbFiles;
}
}
}
}
}
- getLog().info("Found " //$NON-NLS-1$
- +selectedFiles.size()
+ getLog().debug("Found " //$NON-NLS-1$
+ +nbFiles
+" file(s)"); //$NON-NLS-1$
}
- return selectedFiles;
}
/** Log an information message.
*
* @param message
*/
- protected void info(Object... message) {
+ protected synchronized void info(Object... message) {
StringBuffer b = new StringBuffer();
for(Object o : message) {
if (o!=null) {
@@ -343,7 +364,7 @@
* @param error
* @param message
*/
- protected void info(Throwable error, Object... message) {
+ protected synchronized void info(Throwable error, Object... message) {
StringBuffer b = new StringBuffer();
for(Object o : message) {
if (o!=null) {
@@ -357,7 +378,7 @@
*
* @param message
*/
- protected void error(Object... message) {
+ protected synchronized void error(Object... message) {
StringBuffer b = new StringBuffer();
for(Object o : message) {
if (o!=null) {
@@ -372,7 +393,7 @@
* @param error
* @param message
*/
- protected void error(Throwable error, Object... message) {
+ protected synchronized void error(Throwable error, Object... message) {
StringBuffer b = new StringBuffer();
for(Object o : message) {
if (o!=null) {
@@ -389,7 +410,7 @@
* @param pomDirectory is the directory where to find the <code>pom.xml</code> file.
* @return the artifact or <code>null</code>.
*/
- protected final ExtendedArtifact readPom(File pomDirectory) {
+ protected synchronized final ExtendedArtifact readPom(File pomDirectory) {
String groupId = null;
String artifactId = null;
String name = null;
@@ -406,7 +427,6 @@
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();
@@ -461,11 +481,11 @@
if (!parentPomDirectory.isDirectory()) {
parentPomDirectory = parentPomDirectory.getParentFile();
}
- ExtendedArtifact parentArtifact = this.pomDirectoryToArtifactMap.get(parentPomDirectory);
+ ExtendedArtifact parentArtifact = this.artifactDescriptions.get(parentPomDirectory);
if (parentArtifact==null) {
parentArtifact = readPom(parentPomDirectory);
if (parentArtifact!=null) {
- this.pomDirectoryToArtifactMap.put(parentPomDirectory, parentArtifact);
+ this.artifactDescriptions.put(parentPomDirectory, parentArtifact);
getLog().info("Found module description for " //$NON-NLS-1$
+parentArtifact.toString());
}
@@ -584,9 +604,8 @@
/** Clear internal buffers.
*/
- public void clearInternalBuffers() {
- this.classToPomDirectoryMap.clear();
- this.pomDirectoryToArtifactMap.clear();
+ public synchronized void clearInternalBuffers() {
+ this.artifactDescriptions.clear();
}
/** Invoked when the Mojo should be executed.
Modified: trunk/tag-replacer/pom.xml
===================================================================
--- trunk/tag-replacer/pom.xml 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/tag-replacer/pom.xml 2011-08-06 14:07:15 UTC (rev 239)
@@ -39,7 +39,7 @@
</execution>
</executions>
<configuration>
- <goalPrefix>javadoc-tag-replacer</goalPrefix>
+ <goalPrefix>tag-replacer</goalPrefix>
</configuration>
</plugin>
</plugins>
Modified: trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/AbstractReplaceMojo.java
===================================================================
--- trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/AbstractReplaceMojo.java 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/AbstractReplaceMojo.java 2011-08-06 14:07:15 UTC (rev 239)
@@ -72,23 +72,35 @@
*/
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 artifactId;
+ private String projectArtifactId;
/** Is the group id that should replace the project's group id.
* @parameter default-value="${project.groupId}"
*/
- private String groupId;
+ private String projectGroupId;
/** Indicates if the group id and artifact id of the current
* project should be replaced by <var>userArtifactId</var>
@@ -106,9 +118,9 @@
private String ensureArtifactId(ExtendedArtifact artifact) {
if (artifact!=null) {
if (this.overrideArtifactGroup && this.mavenProject.getArtifact().equals(artifact)) {
- String a = this.artifactId;
+ String a = this.projectArtifactId;
if (a!=null && !EMPTY_STRING.equals(a)) {
- return this.artifactId;
+ return this.projectArtifactId;
}
}
return artifact.getArtifactId();
@@ -119,9 +131,9 @@
private String ensureGroupId(ExtendedArtifact artifact) {
if (artifact!=null) {
if (this.overrideArtifactGroup && this.mavenProject.getArtifact().equals(artifact)) {
- String g = this.groupId;
+ String g = this.projectGroupId;
if (g!=null && !EMPTY_STRING.equals(g)) {
- return this.groupId;
+ return this.projectGroupId;
}
}
return artifact.getGroupId();
@@ -132,20 +144,29 @@
/** Replace the Javadoc tags in the given file.
*
* @param file is the name of the file on the local file system.
- * @param filename is the name of the file in the javadoc hierarchy.
* @param replacementType is the type of replacement to be done.
+ * @param classpath are the directories from which the file is extracted.
* @throws MojoExecutionException
*/
- protected void replaceInFile(File file, String filename, ReplacementType replacementType) throws MojoExecutionException {
+ protected synchronized void replaceInFile(File file, ReplacementType replacementType, File[] classpath) throws MojoExecutionException {
ExtendedArtifact artifact = searchArtifact(file);
+ String filename = removePathPrefix(getBaseDirectory(), file);
+
+ String shortFilename = null;
+ for(int i=0; shortFilename==null && i<classpath.length; ++i) {
+ if (file.getAbsolutePath().startsWith(classpath[i].getAbsolutePath())) {
+ shortFilename = removePathPrefix(classpath[i], file);
+ }
+ }
+
if (artifact!=null) {
- getLog().info("Replacing in "+file.getAbsolutePath()+" with artifact "+ //$NON-NLS-1$ //$NON-NLS-2$
+ getLog().debug("Replacing in "+filename+" with artifact "+ //$NON-NLS-1$ //$NON-NLS-2$
ArtifactUtils.key(artifact));
}
else {
- getLog().info("Replacing in "+file.getAbsolutePath()+" without artifact"); //$NON-NLS-1$ //$NON-NLS-2$
+ getLog().debug("Replacing in "+filename+" without artifact"); //$NON-NLS-1$ //$NON-NLS-2$
}
File outputFile = null;
@@ -155,7 +176,7 @@
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
while (line!=null) {
- line = replaceInString(filename, artifact, line, replacementType);
+ line = replaceInString(shortFilename, artifact, line, replacementType);
writer.write(line);
writer.write("\n"); //$NON-NLS-1$
line = reader.readLine();
@@ -195,33 +216,47 @@
return Pattern.compile(b.toString(), Pattern.CASE_INSENSITIVE);
}
- private String quoteReplacementText(String replacement) {
- // Protect the dollar and backslashs signs
- String s = replacement.replaceAll(Pattern.quote("$"), "$"); //$NON-NLS-1$//$NON-NLS-2$
- s = s.replaceAll(Pattern.quote("\\\\"), "&backslash;"); //$NON-NLS-1$//$NON-NLS-2$
- return s;
- }
-
- private String unquoteReplacementText(String replacement) {
+ private String unquoteReplacementText(String replacement, ReplacementType replacementType) {
// Unprotect the dollar and backslashs signs
- String s = replacement.replaceAll(Pattern.quote("$"), "\\$"); //$NON-NLS-1$//$NON-NLS-2$
- s = s.replaceAll(Pattern.quote("&backslash;"), "\\\\"); //$NON-NLS-1$//$NON-NLS-2$
- return s;
+ if (replacementType!=ReplacementType.HTML) {
+ return unquoteReplacementText(replacement);
+ }
+ return replacement;
}
- /** Uitility function that replace the macros by the replacement text in the given text.
+ /** 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) {
- Pattern p = buildMacroPattern(macroName);
- Matcher m = p.matcher(text);
- return unquoteReplacementText(m.replaceAll(quoteReplacementText(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 unquoteReplacementText(m.replaceAll(quoteReplacementText(replacement)), type);
+ }
+ 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
@@ -230,7 +265,7 @@
* @return the result of the replacement.
* @throws MojoExecutionException
*/
- protected String replaceAuthor(String text, ExtendedArtifact artifact, ReplacementType replacementType) 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);
@@ -275,7 +310,9 @@
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$
}
}
- m.appendReplacement(sb, quoteReplacementText(replacement.toString()));
+ if (replacement.length()!=0) {
+ m.appendReplacement(sb, quoteReplacementText(replacement.toString()));
+ }
}
else {
throw new MojoExecutionException("no login for Author tag: "+m.group(0)); //$NON-NLS-1$
@@ -290,14 +327,14 @@
m.appendTail(sb);
- result = unquoteReplacementText(sb.toString());
+ result = unquoteReplacementText(sb.toString(), replacementType);
}
return result;
}
/** Replace Javadoc tags in a string.
*
- * @param file is the name of the file in the javadoc hierarchy from which the string was extracted.
+ * @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.
@@ -305,18 +342,16 @@
* @return the result of the replacement.
* @throws MojoExecutionException
*/
- protected String replaceInString(String file, ExtendedArtifact artifact, String line, ReplacementType replacementType) throws MojoExecutionException {
+ protected synchronized String replaceInString(String file, ExtendedArtifact artifact, String line, ReplacementType replacementType) throws MojoExecutionException {
String nline = line;
- StringBuffer buffer = new StringBuffer();
-
- String replacementName = (artifact==null) ? EMPTY_STRING : artifact.getName();
- String replacementVersion = (artifact==null) ? EMPTY_STRING : artifact.getVersion();
+ String replacementName = (artifact==null) ? null : artifact.getName();
+ String replacementVersion = (artifact==null) ? null : artifact.getVersion();
String replacementArtifactId = ensureArtifactId(artifact);
String replacementGroupId = ensureGroupId(artifact);
- String replacementWebsite = (artifact==null) ? EMPTY_STRING : artifact.getWebsite();
+ String replacementWebsite = (artifact==null) ? null : artifact.getWebsite();
- String replacementOrganization = EMPTY_STRING;
+ String replacementOrganization = null;
if (artifact!=null) {
Organization orga = artifact.getOrganization();
@@ -325,29 +360,31 @@
}
}
- nline = replaceMacro(MACRO_NAME, nline, replacementName);
- nline = replaceMacro(MACRO_REVISION, nline, replacementVersion);
- nline = replaceMacro(MACRO_VERSION, nline, replacementVersion);
- nline = replaceMacro(MACRO_ARTIFACTID, nline, replacementArtifactId);
- nline = replaceMacro(MACRO_GROUPID, nline, replacementGroupId);
- nline = replaceMacro(MACRO_WEBSITE, nline, replacementWebsite);
- nline = replaceMacro(MACRO_ORGANIZATION, nline, replacementOrganization);
+ nline = replaceMacro(MACRO_NAME, nline, replacementName, replacementType);
+ nline = replaceMacro(MACRO_REVISION, nline, replacementVersion, 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);
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //$NON-NLS-1$
String currentDate = fmt.format(this.invocationDate);
- nline = replaceMacro(MACRO_DATE, nline, currentDate);
+ nline = replaceMacro(MACRO_DATE, nline, currentDate, replacementType);
+ StringBuffer buffer = new StringBuffer();
buffer.setLength(0);
buffer.append("$Id: "); //$NON-NLS-1$
buffer.append(file);
buffer.append(' ');
if (artifact!=null) {
+ buffer.append('v');
buffer.append(replacementVersion);
buffer.append(' ');
}
buffer.append(currentDate);
buffer.append("$"); //$NON-NLS-1$
- nline = replaceMacro(MACRO_ID, nline, buffer.toString());
+ nline = replaceMacro(MACRO_ID, nline, buffer.toString(), ReplacementType.TEXT);
nline = replaceAuthor(nline, artifact, replacementType);
@@ -358,33 +395,66 @@
* {@inheritDoc}
*/
@Override
- public void checkMojoAttributes() {
+ public synchronized void checkMojoAttributes() {
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.artifactId); //$NON-NLS-1$
- assertNotNull("groupId", this.groupId); //$NON-NLS-1$
+ assertNotNull("artifactId", this.projectArtifactId); //$NON-NLS-1$
+ assertNotNull("groupId", this.projectGroupId); //$NON-NLS-1$
}
/**
* {@inheritDoc}
*/
@Override
+ protected File getBaseDirectory() {
+ return this.baseDirectory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
protected File getOutputDirectory() {
return this.outputDirectory;
}
/**
- * Replies the directory where source are located.
+ * Replies the directory where original source are located.
*
- * @return the directory where 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
Deleted: trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/ReplaceHtmlMojo.java
===================================================================
--- trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/ReplaceHtmlMojo.java 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/ReplaceHtmlMojo.java 2011-08-06 14:07:15 UTC (rev 239)
@@ -1,88 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2010-11 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.plugins.javadoctagreplacer;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.arakhne.maven.HtmlFileFilter;
-
-import java.io.File;
-import java.util.Collection;
-
-/**
- * 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>$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>$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 version 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 $Name$ $Revision$ $Date$
- * @mavengroupid $GroupId$
- * @mavenartifactid $ArtifactId$
- *
- * @goal replacehtml
- * @phase site
- * @requireProject true
- */
-public class ReplaceHtmlMojo extends AbstractReplaceMojo {
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void executeMojo() throws MojoExecutionException {
- File[] javadocDirs = new File[] {
- new File(getOutputDirectory(), "site"+File.separator+"apidocs"), //$NON-NLS-1$ //$NON-NLS-2$
- new File(getOutputDirectory(), "apidocs") //$NON-NLS-1$
- };
-
- for(File javadocDir : javadocDirs) {
- clearInternalBuffers();
- if ( javadocDir.isDirectory() ) {
-
- // Search for files
- Collection<File> htmlFiles = findFiles(javadocDir, new HtmlFileFilter());
-
- // Replace in files
- for(File file : htmlFiles) {
- String filename = file.toString().replace(javadocDir.toString(), EMPTY_STRING);
- replaceInFile(file, filename, ReplacementType.HTML);
- }
- }
- }
- }
-
-}
Modified: trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/ReplaceSourceMojo.java
===================================================================
--- trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/ReplaceSourceMojo.java 2011-08-05 20:43:42 UTC (rev 238)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/javadoctagreplacer/ReplaceSourceMojo.java 2011-08-06 14:07:15 UTC (rev 239)
@@ -25,6 +25,7 @@
import org.arakhne.maven.PropertyFileFilter;
import java.io.File;
+import java.util.ArrayList;
import java.util.Collection;
/**
@@ -55,39 +56,53 @@
* @mavenartifactid $ArtifactId$
*
* @goal replacesrc
- * @phase site
+ * @phase package
* @requireProject true
+ * @threadSafe
*/
public class ReplaceSourceMojo extends AbstractReplaceMojo {
- /**
+ /** Are the directories where the html files are located.
+ * By default, the directories "target/generated-sources/java" and
+ * "target/classes" are used.
+ *
+ * @parameter
+ */
+ private File[] sources;
+
+ /**
* {@inheritDoc}
*/
@Override
- protected void executeMojo() throws MojoExecutionException {
- File sourceDir = getSourceDirectory();
-
- clearInternalBuffers();
- if ( sourceDir.isDirectory() ) {
+ protected synchronized void executeMojo() throws MojoExecutionException {
+ File[] sourceDirs;
+ if (this.sources==null || this.sources.length==0) {
+ sourceDirs = new File[] {
+ getClassDirectory(),
+ new File(getGeneratedSourceDirectory(), "java") //$NON-NLS-1$
+ };
+ }
+ else {
+ sourceDirs = this.sources;
+ }
+
+ clearInternalBuffers();
- // Search for .java files
- Collection<File> sourceFiles = findFiles(sourceDir, new JavaSourceFileFilter());
+ Collection<File> htmlBasedFiles = new ArrayList<File>();
+ Collection<File> textBasedFiles = new ArrayList<File>();
+
+ for(File sourceDir : sourceDirs) {
+ if ( sourceDir.isDirectory() ) {
+ // Search for .java files
+ findFiles(sourceDir, new JavaSourceFileFilter(), htmlBasedFiles);
+ // Search for .properties files
+ findFiles(sourceDir, new PropertyFileFilter(), textBasedFiles);
+ }
+ }
- // Replace in .java files
- for(File file : sourceFiles) {
- String filename = file.toString().replace(sourceDir.getParent().toString(), EMPTY_STRING);
- replaceInFile(file, filename, ReplacementType.HTML);
- }
-
- // Search for .properties files
- Collection<File> propertyFiles = findFiles(sourceDir, new PropertyFileFilter());
-
- // Replace in .properties files
- for(File file : propertyFiles) {
- String filename = file.toString().replace(sourceDir.getParent().toString(), EMPTY_STRING);
- replaceInFile(file, filename, ReplacementType.TEXT);
- }
- }
- }
+ for(File file : htmlBasedFiles) {
+ replaceInFile(file, ReplacementType.HTML, sourceDirs);
+ }
+ }
}