[Arakhnę-Dev] [269] * tag-replacer plugin must not force the using maven modules to override the {project .build.sourceDirectory}.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 269
Author:   galland
Date:     2011-08-22 14:19:46 +0200 (Mon, 22 Aug 2011)
Log Message:
-----------
* tag-replacer plugin must not force the using maven modules to override the {project.build.sourceDirectory}. In place tag-replacer is silently proceeding this replacement inside the maven project under compilation.

Modified Paths:
--------------
    trunk/arakhneLog4J/pom.xml
    trunk/arakhneLogger/pom.xml
    trunk/arakhneRefs/pom.xml
    trunk/arakhneVmutils/java/pom.xml
    trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
    trunk/pom.xml
    trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java
    trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/GenerateSourceMojo.java

Modified: trunk/arakhneLog4J/pom.xml
===================================================================
--- trunk/arakhneLog4J/pom.xml	2011-08-22 08:47:00 UTC (rev 268)
+++ trunk/arakhneLog4J/pom.xml	2011-08-22 12:19:46 UTC (rev 269)
@@ -36,11 +36,6 @@
 	</dependencies>
 
 	<build>
-		<!--
-			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>

Modified: trunk/arakhneLogger/pom.xml
===================================================================
--- trunk/arakhneLogger/pom.xml	2011-08-22 08:47:00 UTC (rev 268)
+++ trunk/arakhneLogger/pom.xml	2011-08-22 12:19:46 UTC (rev 269)
@@ -24,11 +24,6 @@
 	<!-- ======================================= -->
 		
 	<build>
-		<!--
-			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>

Modified: trunk/arakhneRefs/pom.xml
===================================================================
--- trunk/arakhneRefs/pom.xml	2011-08-22 08:47:00 UTC (rev 268)
+++ trunk/arakhneRefs/pom.xml	2011-08-22 12:19:46 UTC (rev 269)
@@ -32,11 +32,6 @@
 	</dependencies>
 
 	<build>
-		<!--
-			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>

Modified: trunk/arakhneVmutils/java/pom.xml
===================================================================
--- trunk/arakhneVmutils/java/pom.xml	2011-08-22 08:47:00 UTC (rev 268)
+++ trunk/arakhneVmutils/java/pom.xml	2011-08-22 12:19:46 UTC (rev 269)
@@ -31,11 +31,6 @@
 	<!-- ======================================= -->
 
 	<build>
-		<!--
-			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>

Modified: trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java	2011-08-22 08:47:00 UTC (rev 268)
+++ trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java	2011-08-22 12:19:46 UTC (rev 269)
@@ -43,6 +43,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
+import java.util.EventListener;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -511,6 +512,22 @@
 	 *            is the list of files to fill.
 	 */
 	protected synchronized void findFiles(File directory, FileFilter filter, Map<? super File, File> fileOut) {
+		findFiles(directory, filter, fileOut, null);
+	}
+
+	/**
+	 * Replies a map of files which are found on the file system. The map has the found files as keys and the search directory as values.
+	 * 
+	 * @param directory
+	 *            is the directory to search in.
+	 * @param filter
+	 *            is the file selector
+	 * @param fileOut
+	 *            is the list of files to fill.
+	 * @param listener on the files that are not matching the file filter.
+	 */
+	protected synchronized void findFiles(File directory, FileFilter filter, Map<? super File, File> fileOut,
+			FindFileListener listener) {
 		if (directory != null && filter != null) {
 			File candidate;
 			List<File> candidates = new ArrayList<File>();
@@ -527,15 +544,19 @@
 			while (!candidates.isEmpty()) {
 				candidate = candidates.remove(0);
 				if (candidate.isDirectory()) {
-					File[] children = candidate.listFiles(filter);
+					File[] children = candidate.listFiles();
 					if (children != null) {
 						for (File child : children) {
 							if (child != null && child.isDirectory()) {
 								candidates.add(child);
-							} else {
+							}
+							else if (filter.accept(child)) {
 								fileOut.put(child, directory);
 								++nbFiles;
 							}
+							else if (listener!=null) {
+								listener.findFile(child, directory);
+							}
 						}
 					}
 				}
@@ -1055,4 +1076,25 @@
 		return null;
 	}
 
+	/**
+	 * Abstract implementation for all Arakhn&ecirc; maven modules. This implementation is thread safe.
+	 * 
+	 * @author $Author: galland$
+	 * @version $FullVersion$
+	 * @mavengroupid $GroupId$
+	 * @mavenartifactid $ArtifactId$
+	 * 
+	 * @component
+	 */
+	public interface FindFileListener extends EventListener {
+
+		/** Invoked when a file which is not matching the file filter was found.
+		 * 
+		 * @param file is the file that is not matching the file filter.
+		 * @param rootDirectory is the root directory in which the file was found. 
+		 */
+		public void findFile(File file, File rootDirectory);
+		
+	}
+	
 }
\ No newline at end of file

Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml	2011-08-22 08:47:00 UTC (rev 268)
+++ trunk/pom.xml	2011-08-22 12:19:46 UTC (rev 269)
@@ -248,12 +248,12 @@
 				<plugin>
 					<groupId>org.arakhne.afc</groupId>
 					<artifactId>tag-replacer</artifactId>
-					<version>2.0</version>
+					<version>2.1-SNAPSHOT</version>
 				</plugin>
 				<plugin>
 					<groupId>org.arakhne.afc</groupId>
 					<artifactId>license-installer</artifactId>
-					<version>2.0</version>
+					<version>2.1-SNAPSHOT</version>
 				</plugin>
 
 				<plugin>

Modified: trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java
===================================================================
--- trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java	2011-08-22 08:47:00 UTC (rev 268)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java	2011-08-22 12:19:46 UTC (rev 269)
@@ -33,6 +33,7 @@
 import java.nio.channels.WritableByteChannel;
 import java.nio.charset.Charset;
 import java.text.SimpleDateFormat;
+import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -144,6 +145,11 @@
 	private File sourceDirectory;
 
 	/**
+	 * @parameter expression="${project.build.sourceDirectory}"
+	 */
+	private File javaSourceRoot;
+
+	/**
 	 * @parameter expression="${project.build.directory}/generated-sources"
 	 */
 	private File generatedSourceDirectory;
@@ -299,7 +305,7 @@
 			if (charset == null)
 				charset = Charset.defaultCharset();
 
-			getLog().info("Copying file '" //$NON-NLS-1$
+			getLog().debug("Copying file '" //$NON-NLS-1$
 					+ inputFile.getName() + "' with '" //$NON-NLS-1$
 					+ charset.displayName() + "' encoding"); //$NON-NLS-1$
 
@@ -618,6 +624,29 @@
 	protected File getOutputDirectory() {
 		return this.outputDirectory;
 	}
+	
+	/** Replace the current source directory by the given directory.
+	 * 
+	 * @param newSourceDirectory
+	 */
+	protected void setSourceDirectoryForAllMojo(File newSourceDirectory) {
+		List<String> sourceRoots = this.mavenProject.getCompileSourceRoots();
+		getLog().debug("Old source roots: "+sourceRoots.toString()); //$NON-NLS-1$
+		Iterator<String> iterator = sourceRoots.iterator();
+		String removableSourcePath = this.javaSourceRoot.getAbsolutePath();
+		getLog().debug("Removable source root: "+removableSourcePath); //$NON-NLS-1$
+		String path;
+		while (iterator.hasNext()) {
+			path = iterator.next();
+			if (path!=null && path.equals(removableSourcePath)) {
+				getLog().debug("Removing source root: "+path); //$NON-NLS-1$
+				iterator.remove();
+			}
+		}
+		getLog().debug("Adding source root: "+newSourceDirectory.getAbsolutePath()); //$NON-NLS-1$
+		this.mavenProject.addCompileSourceRoot(newSourceDirectory.toString());
+		this.sourceDirectory = newSourceDirectory;
+	}
 
 	/**
 	 * Replies the directory where original source are located.

Modified: trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/GenerateSourceMojo.java
===================================================================
--- trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/GenerateSourceMojo.java	2011-08-22 08:47:00 UTC (rev 268)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/GenerateSourceMojo.java	2011-08-22 12:19:46 UTC (rev 269)
@@ -101,6 +101,8 @@
 					sourceDirs,
 					false);
 		}
+		
+		setSourceDirectoryForAllMojo(targetDir);
 	}
     
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/