[Arakhnę-Dev] [272] * Add utility functions in the Maven plugins

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


Revision: 272
Author:   galland
Date:     2011-08-24 20:54:21 +0200 (Wed, 24 Aug 2011)
Log Message:
-----------
* Add utility functions in the Maven plugins
* Make public ?\195?\160 large amount of the utility functions in the Maven plugins.

Modified Paths:
--------------
    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/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java

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-23 17:17:38 UTC (rev 271)
+++ trunk/license-installer/src/main/java/org/arakhne/maven/plugins/licenseinstaller/InstallLicenseMojo.java	2011-08-24 18:54:21 UTC (rev 272)
@@ -38,6 +38,7 @@
 import org.apache.maven.model.Developer;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
 import org.arakhne.maven.AbstractArakhneMojo;
 import org.sonatype.aether.RepositorySystem;
 import org.sonatype.aether.RepositorySystemSession;
@@ -63,6 +64,13 @@
 public class InstallLicenseMojo extends AbstractArakhneMojo implements Constants {
 
 	/**
+	 * @component role="org.apache.maven.project.MavenProjectBuilder"
+	 * @required
+	 * @readonly
+	 */
+	private MavenProjectBuilder mavenProjectBuilder;
+
+	/**
 	 * @component
 	 */
 	private ArtifactHandlerManager artifactHandlerManager;
@@ -366,7 +374,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected File getOutputDirectory() {
+	public File getOutputDirectory() {
 		return this.outputDirectory;
 	}
 
@@ -374,7 +382,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected File getBaseDirectory() {
+	public File getBaseDirectory() {
 		return this.baseDirectory;
 	}
 
@@ -382,7 +390,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected ArtifactHandlerManager getArtifactHandlerManager() {
+	public ArtifactHandlerManager getArtifactHandlerManager() {
 		return this.artifactHandlerManager;
 	}
 
@@ -390,7 +398,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected MavenSession getMavenSession() {
+	public MavenSession getMavenSession() {
 		return this.mavenSession;
 	}
 
@@ -398,7 +406,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected RepositorySystemSession getRepositorySystemSession() {
+	public RepositorySystemSession getRepositorySystemSession() {
 		return this.repoSession;
 	}
 
@@ -406,7 +414,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected List<RemoteRepository> getRemoteRepositoryList() {
+	public List<RemoteRepository> getRemoteRepositoryList() {
 		return this.remoteRepos;
 	}
 
@@ -414,8 +422,15 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected RepositorySystem getRepositorySystem() {
+	public RepositorySystem getRepositorySystem() {
 		return this.repoSystem;
 	}
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public MavenProjectBuilder getMavenProjectBuilder() {
+		return this.mavenProjectBuilder;
+	}
 
 }

Modified: trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java	2011-08-23 17:17:38 UTC (rev 271)
+++ trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java	2011-08-24 18:54:21 UTC (rev 272)
@@ -47,6 +47,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.ResourceBundle;
 import java.util.Set;
 import java.util.TreeMap;
@@ -65,15 +66,20 @@
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Contributor;
+import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Developer;
 import org.apache.maven.model.License;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Organization;
 import org.apache.maven.model.Parent;
+import org.apache.maven.model.Plugin;
 import org.apache.maven.model.Scm;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.sonatype.aether.RepositorySystem;
 import org.sonatype.aether.RepositorySystemSession;
@@ -145,7 +151,7 @@
 	 * @param out
 	 * @throws IOException
 	 */
-	public void fileCopy(File in, File out) throws IOException {
+	public final void fileCopy(File in, File out) throws IOException {
 		assert (in != null);
 		assert (out != null);
 		FileChannel inChannel = new FileInputStream(in).getChannel();
@@ -167,7 +173,7 @@
 	 * @param out
 	 * @throws IOException
 	 */
-	public void fileCopy(URL in, File out) throws IOException {
+	public final void fileCopy(URL in, File out) throws IOException {
 		assert (in != null);
 		InputStream inStream = in.openStream();
 		OutputStream outStream = new FileOutputStream(out);
@@ -195,7 +201,7 @@
 	 *            are the parameters to replace.
 	 * @return the read text.
 	 */
-	public String getLString(Class<?> source, String label, Object... params) {
+	public final 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$
@@ -211,7 +217,7 @@
 	 * @param file
 	 * @return the <var>file</var> without the prefix.
 	 */
-	public String removePathPrefix(File prefix, File file) {
+	public final String removePathPrefix(File prefix, File file) {
 		StringBuffer b = new StringBuffer();
 		b.append("^"); //$NON-NLS-1$
 		b.append(Pattern.quote(prefix.getAbsolutePath()));
@@ -281,7 +287,7 @@
 	 * 
 	 * @return the preferred charsets in the preferred order of use.
 	 */
-	protected Charset[] getPreferredCharsets() {
+	public final Charset[] getPreferredCharsets() {
 		return this.preferredCharsets;
 	}
 
@@ -291,7 +297,7 @@
 	 * @param charsets
 	 *            are the preferred charsets in the preferred order of use.
 	 */
-	protected void setPreferredCharsets(Charset... charsets) {
+	public final void setPreferredCharsets(Charset... charsets) {
 		this.preferredCharsets = charsets;
 	}
 
@@ -300,7 +306,7 @@
 	 * 
 	 * @return the manager of the SVN repository.
 	 */
-	protected synchronized final SVNClientManager getSVNClientManager() {
+	public final synchronized SVNClientManager getSVNClientManager() {
 		if (this.svnManager == null) {
 			this.svnManager = SVNClientManager.newInstance();
 		}
@@ -318,7 +324,7 @@
 	 * 
 	 * @return the artifact resolver.
 	 */
-	protected abstract ArtifactHandlerManager getArtifactHandlerManager();
+	public abstract ArtifactHandlerManager getArtifactHandlerManager();
 
 	/**
 	 * Replies the output directory of the project. Basically it is <code>getRootDirectory()+"/target"</code>.
@@ -331,7 +337,7 @@
 	 * 
 	 * @return the output directory.
 	 */
-	protected abstract File getOutputDirectory();
+	public abstract File getOutputDirectory();
 
 	/**
 	 * Replies the root directory of the project. Basically it is the value stored inside the Maven property named <code>project.basedir</code>.
@@ -344,12 +350,27 @@
 	 * 
 	 * @return the root directory.
 	 */
-	protected abstract File getBaseDirectory();
+	public abstract File getBaseDirectory();
 
 	/**
 	 * Replies the current maven session. Basically it is an internal component of Maven.
 	 * <p>
 	 * It is an attribute defined as: <code><pre>
+	 * <span>/</span>* <span>@</span>component role="org.apache.maven.project.MavenProjectBuilder"
+	 * * <span>@</span>required
+	 * * <span>@</span>readonly
+	 * <span>*</span>/
+	 * private MavenProjectBuilder projectBuilder;
+	 * </pre></code>
+	 * 
+	 * @return the maven session
+	 */
+	public abstract MavenProjectBuilder getMavenProjectBuilder();
+
+	/**
+	 * Replies the current project builder. Basically it is an internal component of Maven.
+	 * <p>
+	 * It is an attribute defined as: <code><pre>
 	 * <span>/</span>* <span>@</span>parameter expression="&dollar;{session}"
 	 * * <span>@</span>required
 	 * <span>*</span>/
@@ -358,9 +379,8 @@
 	 * 
 	 * @return the maven session
 	 */
-	protected abstract MavenSession getMavenSession();
+	public abstract MavenSession getMavenSession();
 
-
 	/**
 	 * Replies the repository system used by this maven instance. Basically it is an internal component of Maven.
 	 * <p>
@@ -372,7 +392,7 @@
 	 * 
 	 * @return the repository system
 	 */
-	protected abstract  RepositorySystem getRepositorySystem();
+	public abstract  RepositorySystem getRepositorySystem();
 
 	/**
 	 * Replies the current repository/network configuration of Maven..
@@ -385,7 +405,7 @@
 	 * 
 	 * @return the repository system
 	 */
-	protected abstract  RepositorySystemSession getRepositorySystemSession();
+	public abstract  RepositorySystemSession getRepositorySystemSession();
 
 	/**
 	 * Replies the project's remote repositories to use for the resolution of plugins and their dependencies..
@@ -398,7 +418,7 @@
 	 * 
 	 * @return the repository system
 	 */
-	protected abstract  List<RemoteRepository> getRemoteRepositoryList();
+	public abstract  List<RemoteRepository> getRemoteRepositoryList();
 	
 
 	/**
@@ -408,7 +428,7 @@
 	 *            is the file for which the maven artifact should be retreived.
 	 * @return the maven artifact or <code>null</code> if none.
 	 */
-	protected synchronized ExtendedArtifact searchArtifact(File file) {
+	public final synchronized ExtendedArtifact searchArtifact(File file) {
 		String filename = removePathPrefix(getBaseDirectory(), file);
 
 		getLog().debug("Retreiving module for " + filename); //$NON-NLS-1$
@@ -449,7 +469,7 @@
 	 *            is the file selector
 	 * @return the list of files.
 	 */
-	protected final Collection<File> findFiles(File directory, FileFilter filter) {
+	public final Collection<File> findFiles(File directory, FileFilter filter) {
 		Collection<File> files = new ArrayList<File>();
 		findFiles(directory, filter, files);
 		return files;
@@ -465,7 +485,7 @@
 	 * @param fileOut
 	 *            is the list of files to fill.
 	 */
-	protected synchronized void findFiles(File directory, FileFilter filter, Collection<? super File> fileOut) {
+	public final synchronized void findFiles(File directory, FileFilter filter, Collection<? super File> fileOut) {
 		if (directory != null && filter != null) {
 			File candidate;
 			List<File> candidates = new ArrayList<File>();
@@ -511,7 +531,7 @@
 	 * @param fileOut
 	 *            is the list of files to fill.
 	 */
-	protected synchronized void findFiles(File directory, FileFilter filter, Map<? super File, File> fileOut) {
+	public final synchronized void findFiles(File directory, FileFilter filter, Map<? super File, File> fileOut) {
 		findFiles(directory, filter, fileOut, null);
 	}
 
@@ -526,7 +546,7 @@
 	 *            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,
+	public final synchronized void findFiles(File directory, FileFilter filter, Map<? super File, File> fileOut,
 			FindFileListener listener) {
 		if (directory != null && filter != null) {
 			File candidate;
@@ -572,7 +592,7 @@
 	 * 
 	 * @param message
 	 */
-	protected synchronized void info(Object... message) {
+	public final synchronized void info(Object... message) {
 		StringBuffer b = new StringBuffer();
 		for (Object o : message) {
 			if (o != null) {
@@ -588,7 +608,7 @@
 	 * @param error
 	 * @param message
 	 */
-	protected synchronized void info(Throwable error, Object... message) {
+	public final synchronized void info(Throwable error, Object... message) {
 		StringBuffer b = new StringBuffer();
 		for (Object o : message) {
 			if (o != null) {
@@ -604,7 +624,7 @@
 	 * @param messages
 	 *            are the messages to log.
 	 */
-	protected void debug(Object... messages) {
+	public final void debug(Object... messages) {
 		StringBuffer buffer = new StringBuffer();
 		for (Object s : messages) {
 			if (s != null)
@@ -619,7 +639,7 @@
 	 * @param messages
 	 *            are the messages to log.
 	 */
-	protected void warn(Object... messages) {
+	public final void warn(Object... messages) {
 		StringBuffer buffer = new StringBuffer();
 		for (Object s : messages) {
 			if (s != null)
@@ -633,7 +653,7 @@
 	 * 
 	 * @param message
 	 */
-	protected synchronized void error(Object... message) {
+	public final synchronized void error(Object... message) {
 		StringBuffer b = new StringBuffer();
 		for (Object o : message) {
 			if (o != null) {
@@ -649,7 +669,7 @@
 	 * @param error
 	 * @param message
 	 */
-	protected synchronized void error(Throwable error, Object... message) {
+	public final synchronized void error(Throwable error, Object... message) {
 		StringBuffer b = new StringBuffer();
 		for (Object o : message) {
 			if (o != null) {
@@ -666,7 +686,7 @@
 	 *            is the directory where to find the <code>pom.xml</code> file.
 	 * @return the artifact or <code>null</code>.
 	 */
-	protected synchronized final ExtendedArtifact readPom(File pomDirectory) {
+	public synchronized final ExtendedArtifact readPom(File pomDirectory) {
 		return readPomFile(new File(pomDirectory, "pom.xml")); //$NON-NLS-1$
 	}
 
@@ -677,7 +697,7 @@
 	 *            is the <code>pom.xml</code> file.
 	 * @return the artifact or <code>null</code>.
 	 */
-	protected synchronized final ExtendedArtifact readPomFile(File pomFile) {
+	public synchronized final ExtendedArtifact readPomFile(File pomFile) {
 		String groupId = null;
 		String artifactId = null;
 		String name = null;
@@ -820,8 +840,8 @@
 	 * @return the artifact definition.
 	 * @throws MojoExecutionException 
 	 */
-	protected org.sonatype.aether.artifact.Artifact resolveArtifact(String groupId, String artifactId, String version) throws MojoExecutionException {
-		return this.resolveArtifact(new org.sonatype.aether.util.artifact.DefaultArtifact(groupId, artifactId,"jar", version));//$NON-NLS-1$
+	public final org.sonatype.aether.artifact.Artifact resolveArtifact(String groupId, String artifactId, String version) throws MojoExecutionException {
+		return resolveArtifact(new org.sonatype.aether.util.artifact.DefaultArtifact(groupId, artifactId,"jar", version));//$NON-NLS-1$
 	}
 	
 	/**
@@ -830,7 +850,7 @@
 	 * @return the artifact definition.
 	 * @throws MojoExecutionException
 	 */
-	protected org.sonatype.aether.artifact.Artifact resolveArtifact(org.sonatype.aether.artifact.Artifact mavenArtifact) throws MojoExecutionException {		
+	public final org.sonatype.aether.artifact.Artifact resolveArtifact(org.sonatype.aether.artifact.Artifact mavenArtifact) throws MojoExecutionException {		
 		assert(mavenArtifact!=null);
 		ArtifactRequest request = new ArtifactRequest();
 		request.setArtifact(mavenArtifact);
@@ -850,6 +870,45 @@
 	}
 
 	/**
+	 * Retreive the extended artifact definition of the given artifact.
+	 * @param mavenArtifact - the artifact to resolve
+	 * @return the artifact definition.
+	 * @throws MojoExecutionException
+	 */
+	public final Artifact resolveArtifact(Artifact mavenArtifact) throws MojoExecutionException {		
+		org.sonatype.aether.artifact.Artifact a = createArtifact(mavenArtifact);
+		a = resolveArtifact(a);
+		return createArtifact(a);
+	}
+	
+	/** Replies the Aether artifact for the maven API artifact.
+	 * 
+	 * @param mavenArtifact
+	 * @return the aether artifact
+	 */
+	public final org.sonatype.aether.artifact.Artifact createArtifact(Artifact mavenArtifact) {
+		if (mavenArtifact==null) return null;
+		return new org.sonatype.aether.util.artifact.DefaultArtifact(
+				mavenArtifact.getGroupId(),
+				mavenArtifact.getArtifactId(),
+				"jar", //$NON-NLS-1$
+				mavenArtifact.getVersion());
+	}
+
+	/** Replies the Maven artifact for the Aether API artifact.
+	 * 
+	 * @param aetherArtifact
+	 * @return the aether artifact
+	 */
+	public final Artifact createArtifact(org.sonatype.aether.artifact.Artifact aetherArtifact) {
+		if (aetherArtifact==null) return null;
+		return createArtifact(
+				aetherArtifact.getGroupId(),
+				aetherArtifact.getArtifactId(),
+				aetherArtifact.getVersion());
+	}
+
+	/**
 	 * Create an Jar runtime artifact from the given values.
 	 * 
 	 * @param groupId
@@ -857,7 +916,7 @@
 	 * @param version
 	 * @return the artifact
 	 */
-	public Artifact createArtifact(String groupId, String artifactId, String version) {
+	public final Artifact createArtifact(String groupId, String artifactId, String version) {
 		return createArtifact(groupId, artifactId, version, "runtime", "jar"); //$NON-NLS-1$//$NON-NLS-2$
 	}
 
@@ -872,7 +931,7 @@
 	 * @return the artifact
 	 * @see DefaultArtifactFactory
 	 */
-	public Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type) {
+	public final Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type) {
 		VersionRange versionRange = null;
 		if (version != null) {
 			versionRange = VersionRange.createFromVersion(version);
@@ -903,7 +962,7 @@
 	 * 
 	 * @throws MojoExecutionException
 	 */
-	public abstract void checkMojoAttributes() throws MojoExecutionException;
+	protected abstract void checkMojoAttributes() throws MojoExecutionException;
 
 	private String getLogType(Object o) {
 		if (o instanceof Boolean || o instanceof AtomicBoolean)
@@ -948,7 +1007,7 @@
 	 *            is the message to put in the exception.
 	 * @param o
 	 */
-	protected void assertNotNull(String message, Object o) {
+	protected final void assertNotNull(String message, Object o) {
 		if (getLog().isDebugEnabled()) {
 			StringBuffer b = new StringBuffer();
 			b.append("\t("); //$NON-NLS-1$
@@ -978,7 +1037,7 @@
 	/**
 	 * Clear internal buffers.
 	 */
-	public synchronized void clearInternalBuffers() {
+	protected synchronized void clearInternalBuffers() {
 		this.localArtifactDescriptions.clear();
 		this.remoteArtifactDescriptions.clear();
 	}
@@ -997,7 +1056,7 @@
 	 * @param values
 	 * @return the jointed values
 	 */
-	protected static String join(String joint, String... values) {
+	public static String join(String joint, String... values) {
 		StringBuffer b = new StringBuffer();
 		for (String value : values) {
 			if (value != null && !EMPTY_STRING.equals(value)) {
@@ -1035,7 +1094,7 @@
 	 * @see #getPreferredCharsets()
 	 * @see #setPreferredCharsets(Charset...)
 	 */
-	protected Charset detectEncoding(File file) {
+	public final Charset detectEncoding(File file) {
 		Collection<Charset> fittingCharsets = new TreeSet<Charset>();
 		for (Charset c : Charset.availableCharsets().values()) {
 			CharsetDecoder decoder = c.newDecoder();
@@ -1076,7 +1135,232 @@
 		return null;
 	}
 
-	/**
+    /** Replies the dependencies specified in the the Maven configuration
+     * of the current project.
+     * 
+     * @param isTransitive indicates if the dependencies of dependencies
+     * must also be replied by the iterator.
+     * @return the iterator.
+     * @see #getDependencies(MavenProject, boolean)
+     */
+	public final Iterator<MavenProject> getDependencies(boolean isTransitive) {
+    	return getDependencies(getMavenSession().getCurrentProject(), isTransitive);
+    }
+
+    /** Replies the dependencies specified in the the Maven configuration
+     * of the given project.
+     * 
+     * @param project is the maven project for which the dependencies must be replied.
+     * @param isTransitive indicates if the dependencies of dependencies
+     * must also be replied by the iterator.
+     * @return the iterator.
+     * @see #getDependencies(boolean)
+     */
+	public final Iterator<MavenProject> getDependencies(MavenProject project, boolean isTransitive) {
+    	return new DependencyIterator(project, isTransitive);
+    }
+
+    /** Replies the plugins specified in the the Maven configuration
+     * of the current project.
+     * 
+     * @param isTransitive indicates if the plugins of dependencies
+     * must also be replied by the iterator.
+     * @return the iterator.
+     * @see #getPlugins(MavenProject, boolean)
+     */
+	public final Iterator<Plugin> getPlugins(boolean isTransitive) {
+    	return getPlugins(getMavenSession().getCurrentProject(), isTransitive);
+    }
+
+    /** Replies the plugins specified in the the Maven configuration
+     * of the given project.
+     * 
+     * @param project is the maven project for which the plugins must be replied.
+     * @param isTransitive indicates if the plugins of dependencies
+     * must also be replied by the iterator.
+     * @return the iterator.
+     * @see #getPlugins(boolean)
+     */
+	public final Iterator<Plugin> getPlugins(MavenProject project, boolean isTransitive) {
+    	return new PluginIterator(project, isTransitive);
+    }
+
+    /** Load the Maven project for the given artifact.
+     * 
+     * @param artifact
+     * @return the maven project.
+     */
+	public MavenProject getMavenProject(Artifact artifact) {
+    	try {
+			MavenProject prj = getMavenProjectBuilder().buildFromRepository(
+					artifact,
+					getRemoteRepositoryList(),
+					getMavenSession().getLocalRepository());
+			return prj;
+		}
+    	catch (ProjectBuildingException e) {
+			getLog().warn(e);
+		}
+    	return null;
+    }
+
+    /**
+     * @author $Author: sgalland$
+     * @version $FullVersion$
+     * @mavengroupid $GroupId$
+     * @mavenartifactid $ArtifactId$
+     */
+    private class DependencyIterator implements Iterator<MavenProject> {
+    	
+		private List<Dependency> dependencies = new ArrayList<Dependency>();
+		private Set<String> treated = new TreeSet<String>();
+		private final boolean isTransitive;
+		private MavenProject next;
+
+		/**
+		 * @param project is the project for which the dependencies must
+		 * be replied.
+    	 * @param isTransitive indicates if the dependencies of dependencies must also be replied
+    	 * by the iterator.
+    	 */
+		public DependencyIterator(MavenProject project, boolean isTransitive) {
+    		this.isTransitive = isTransitive;
+    		this.dependencies.addAll(project.getDependencies());
+    		searchNext();
+    	}
+
+		private void searchNext() {
+    		this.next = null;
+    		
+    		while (this.next==null && !this.dependencies.isEmpty()) {
+    			try {
+    				Dependency dependency = this.dependencies.remove(0);
+    				if (dependency!=null) {
+    					String artifactId = dependency.getGroupId()+":"+dependency.getArtifactId()+":"+dependency.getVersion();  //$NON-NLS-1$//$NON-NLS-2$
+    					if (!this.treated.contains(artifactId)) {
+        					Artifact dependencyArtifact = createArtifact(
+        							dependency.getGroupId(),
+        							dependency.getArtifactId(),
+        							dependency.getVersion(),
+        							dependency.getScope(),
+        							dependency.getType());
+    						resolveArtifact(dependencyArtifact);
+    						MavenProject dependencyProject = getMavenProjectBuilder().buildFromRepository(
+    								dependencyArtifact,
+    								getRemoteRepositoryList(),
+    								getMavenSession().getLocalRepository());
+    						if (dependencyProject!=null) {
+    							if (this.isTransitive) {
+    								this.dependencies.addAll(dependencyProject.getDependencies());
+    							}
+    							this.next = dependencyProject;
+        						this.treated.add(artifactId);
+    						}
+    					}
+    				}
+    			}
+    			catch (MojoExecutionException e) {
+    				throw new NoSuchElementException();
+    			}
+    			catch (ProjectBuildingException e) {
+    				throw new NoSuchElementException();
+    			}
+    		}
+    	}
+    	
+		/**
+		 * {@inheritDoc}
+		 */
+		public boolean hasNext() {
+			return this.next!=null;
+		}
+
+		/**
+		 * {@inheritDoc}
+		 */
+		public MavenProject next() {
+			MavenProject n = this.next;
+			if (n==null) throw new NoSuchElementException();
+			searchNext();
+			return n;
+		}
+
+		/**
+		 * {@inheritDoc}
+		 */
+		public void remove() {
+			throw new UnsupportedOperationException();
+		}
+    	
+    } // class DependencyIterator
+
+    /**
+     * @author $Author: sgalland$
+     * @version $FullVersion$
+     * @mavengroupid $GroupId$
+     * @mavenartifactid $ArtifactId$
+     */
+    private class PluginIterator implements Iterator<Plugin> {
+
+    	private final Iterator<MavenProject> dependencyIterator;
+    	private Iterator<org.apache.maven.model.Plugin> pluginIterator;
+    	private Plugin next;
+    	
+    	/**
+    	 * @param project
+    	 * @param isTransitive
+    	 */
+    	public PluginIterator(MavenProject project, boolean isTransitive) {
+    		this.dependencyIterator = getDependencies(project, isTransitive);
+    		searchNext();
+    	}
+    	
+		private void searchNext() {
+    		this.next = null;
+    		while (this.next==null) {
+    			if (this.pluginIterator!=null && this.pluginIterator.hasNext()) {
+    				this.next = this.pluginIterator.next();
+    			}
+    			else if (this.dependencyIterator.hasNext()) {
+    				MavenProject project = this.dependencyIterator.next();
+    				List<Plugin> buildPlugins = project.getBuildPlugins();
+    				if (buildPlugins!=null) {
+    					this.pluginIterator = buildPlugins.iterator();
+    				}
+    			}
+    			else {
+    				return;
+    			}
+    		}
+    	}
+
+		/**
+		 * {@inheritDoc}
+		 */
+		public boolean hasNext() {
+			return this.next!=null;
+		}
+
+		/**
+		 * {@inheritDoc}
+		 */
+		public Plugin next() {
+			org.apache.maven.model.Plugin n = this.next;
+			if (n==null) throw new NoSuchElementException();
+			searchNext();
+			return n;
+		}
+
+		/**
+		 * {@inheritDoc}
+		 */
+		public void remove() {
+			throw new UnsupportedOperationException();
+		}
+    	
+    } // class PluginIterator
+
+    /**
 	 * Abstract implementation for all Arakhn&ecirc; maven modules. This implementation is thread safe.
 	 * 
 	 * @author $Author: galland$
@@ -1086,7 +1370,7 @@
 	 * 
 	 * @component
 	 */
-	public interface FindFileListener extends EventListener {
+	public static interface FindFileListener extends EventListener {
 
 		/** Invoked when a file which is not matching the file filter was found.
 		 * 
@@ -1095,6 +1379,6 @@
 		 */
 		public void findFile(File file, File rootDirectory);
 		
-	}
+	} // interface FindFileListener
 	
 }
\ No newline at end of file

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-23 17:17:38 UTC (rev 271)
+++ trunk/tag-replacer/src/main/java/org/arakhne/maven/plugins/tagreplacer/AbstractReplaceMojo.java	2011-08-24 18:54:21 UTC (rev 272)
@@ -44,6 +44,7 @@
 import org.apache.maven.model.Organization;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
 import org.arakhne.maven.AbstractArakhneMojo;
 import org.arakhne.maven.ExtendedArtifact;
 import org.sonatype.aether.RepositorySystem;
@@ -124,6 +125,13 @@
 	private ArtifactHandlerManager artifactHandlerManager;
 
 	/**
+	 * @component role="org.apache.maven.project.MavenProjectBuilder"
+	 * @required
+	 * @readonly
+	 */
+	private MavenProjectBuilder mavenProjectBuilder;
+	
+	/**
 	 * @parameter expression="${project.basedir}"
 	 */
 	private File baseDirectory;
@@ -599,7 +607,15 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected MavenSession getMavenSession() {
+	public MavenProjectBuilder getMavenProjectBuilder() {
+		return this.mavenProjectBuilder;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public MavenSession getMavenSession() {
 		return this.mavenSession;
 	}
 
@@ -607,7 +623,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected File getBaseDirectory() {
+	public File getBaseDirectory() {
 		return this.baseDirectory;
 	}
 
@@ -615,7 +631,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected File getOutputDirectory() {
+	public File getOutputDirectory() {
 		return this.outputDirectory;
 	}
 	
@@ -680,7 +696,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected ArtifactHandlerManager getArtifactHandlerManager() {
+	public ArtifactHandlerManager getArtifactHandlerManager() {
 		return this.artifactHandlerManager;
 	}
 
@@ -709,7 +725,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected RepositorySystemSession getRepositorySystemSession() {
+	public RepositorySystemSession getRepositorySystemSession() {
 		return this.repoSession;
 	}
 
@@ -717,7 +733,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected List<RemoteRepository> getRemoteRepositoryList() {
+	public List<RemoteRepository> getRemoteRepositoryList() {
 		return this.remoteRepos;
 	}
 
@@ -725,7 +741,7 @@
 	 * {@inheritDoc}
 	 */
 	@Override
-	protected RepositorySystem getRepositorySystem() {
+	public RepositorySystem getRepositorySystem() {
 		return this.repoSystem;
 	}
 


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