[Arakhnę-Dev] [385] * Avoid to fail on exception when trying to download the plugin description from a Maven pom file .

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


Revision: 385
Author:   galland
Date:     2012-08-24 18:02:33 +0200 (Fri, 24 Aug 2012)
Log Message:
-----------
* Avoid to fail on exception when trying to download the plugin description from a Maven pom file.

Modified Paths:
--------------
    trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java

Modified: trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java	2012-08-24 14:08:19 UTC (rev 384)
+++ trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java	2012-08-24 16:02:33 UTC (rev 385)
@@ -138,7 +138,7 @@
 		}
 		return url;
 	}
-	
+
 	/**
 	 * Empty string constant.
 	 */
@@ -221,7 +221,7 @@
 			}
 		}		
 	}
-	
+
 	private static File toOutput(File root, File file, File newRoot) {
 		String filename = file.getAbsolutePath();
 		String rootPath = root.getAbsolutePath();
@@ -354,8 +354,8 @@
 	public static final String removePathPrefix(File prefix, File file) {
 		String r = file.getAbsolutePath().replaceFirst(
 				"^"+ //$NON-NLS-1$
-				Pattern.quote(prefix.getAbsolutePath()),
-				EMPTY_STRING);
+						Pattern.quote(prefix.getAbsolutePath()),
+						EMPTY_STRING);
 		if (r.startsWith(File.separator))
 			return r.substring(File.separator.length());
 		return r;
@@ -554,8 +554,8 @@
 	 * @return the repository system
 	 */
 	public abstract  List<RemoteRepository> getRemoteRepositoryList();
-	
-	
+
+
 	/**
 	 * Search and reply the maven artifact which is corresponding to the given file.
 	 * 
@@ -862,11 +862,11 @@
 				url = model.getUrl();
 				organization = model.getOrganization();
 				scm = model.getScm();
-				
+
 				developers = model.getDevelopers();
 				contributors = model.getContributors();
 				licenses = model.getLicenses();
-	
+
 				parent = model.getParent();
 			}
 			catch (IOException e) {
@@ -951,7 +951,7 @@
 			} catch (IOException e) {
 				getLog().warn(e);
 			}
-			
+
 			// Be sure that the optional fields version and groupId are correctly set.
 			if (version==null || version.isEmpty()) {
 				version = parent.getVersion();
@@ -998,7 +998,7 @@
 	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$
 	}
-	
+
 	/**
 	 * Retreive the extended artifact definition of the given artifact.
 	 * @param mavenArtifact - the artifact to resolve
@@ -1021,7 +1021,7 @@
 		}
 
 		debug("Resolved artifact " + mavenArtifact.toString() + " to " + result.getArtifact().getFile() + " from " + result.getRepository());//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
-		
+
 		return result.getArtifact();
 	}
 
@@ -1036,7 +1036,7 @@
 		a = resolveArtifact(a);
 		return createArtifact(a);
 	}
-	
+
 	/** Replies the Aether artifact for the maven API artifact.
 	 * 
 	 * @param mavenArtifact
@@ -1169,11 +1169,11 @@
 		if (getLog().isDebugEnabled()) {
 			getLog().debug(
 					"\t(" //$NON-NLS-1$
-				+	getLogType(o)
-				+	") " //$NON-NLS-1$
-				+	message
-				+	" = " //$NON-NLS-1$
-				+	o);
+					+	getLogType(o)
+					+	") " //$NON-NLS-1$
+					+	message
+					+	" = " //$NON-NLS-1$
+					+	o);
 		}
 		if (o == null)
 			throw new AssertionError("assertNotNull: " + message); //$NON-NLS-1$
@@ -1298,86 +1298,86 @@
 		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)
-     */
+	/** 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);
-    }
+		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)
-     */
+	/** 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);
-    }
+		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)
-     */
+	/** 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);
-    }
+		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)
-     */
+	/** 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);
-    }
+		return new PluginIterator(project, isTransitive);
+	}
 
-    /** Load the Maven project for the given artifact.
-     * 
-     * @param artifact
-     * @return the maven project.
-     */
+	/** Load the Maven project for the given artifact.
+	 * 
+	 * @param artifact
+	 * @return the maven project.
+	 */
 	public MavenProject getMavenProject(Artifact artifact) {
-    	try {
-    		MavenSession session = getMavenSession();
-    		MavenProject current = session.getCurrentProject();
+		try {
+			MavenSession session = getMavenSession();
+			MavenProject current = session.getCurrentProject();
 			MavenProject prj = getMavenProjectBuilder().buildFromRepository(
 					artifact,
 					current.getRemoteArtifactRepositories(),
 					session.getLocalRepository());
 			return prj;
 		}
-    	catch (ProjectBuildingException e) {
+		catch (ProjectBuildingException e) {
 			getLog().warn(e);
 		}
-    	return null;
-    }
+		return null;
+	}
 
-    /**
-     * @author $Author: sgalland$
-     * @version $FullVersion$
-     * @mavengroupid $GroupId$
-     * @mavenartifactid $ArtifactId$
-     */
-    private class DependencyIterator implements Iterator<MavenProject> {
-    	
-    	private final List<ArtifactRepository> remoteRepositiories;
+	/**
+	 * @author $Author: sgalland$
+	 * @version $FullVersion$
+	 * @mavengroupid $GroupId$
+	 * @mavenartifactid $ArtifactId$
+	 */
+	private class DependencyIterator implements Iterator<MavenProject> {
+
+		private final List<ArtifactRepository> remoteRepositiories;
 		private final boolean isTransitive;
 		private List<Dependency> dependencies = new ArrayList<Dependency>();
 		private Set<String> treated = new TreeSet<String>();
@@ -1386,25 +1386,26 @@
 		/**
 		 * @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.
-    	 */
+		 * @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.remoteRepositiories = project.getRemoteArtifactRepositories();
-    		this.dependencies.addAll(project.getDependencies());
-    		searchNext();
-    	}
+			this.isTransitive = isTransitive;
+			this.remoteRepositiories = project.getRemoteArtifactRepositories();
+			this.dependencies.addAll(project.getDependencies());
+			searchNext();
+		}
 
 		private void searchNext() {
-    		this.next = null;
-    		
-    		while (this.next==null && !this.dependencies.isEmpty()) {
+			this.next = null;
+
+			while (this.next==null && !this.dependencies.isEmpty()) {
 				Dependency dependency = this.dependencies.remove(0);
 				if (dependency!=null) {
 					String artifactId = dependency.getGroupId()+":"+dependency.getArtifactId()+":"+dependency.getVersion();  //$NON-NLS-1$//$NON-NLS-2$
-					try {
-						if (!this.treated.contains(artifactId)) {
+					if (!this.treated.contains(artifactId)) {
+						boolean isTreated = false;
+						try {
 							Artifact dependencyArtifact = createArtifact(
 									dependency.getGroupId(),
 									dependency.getArtifactId(),
@@ -1422,24 +1423,23 @@
 									this.dependencies.addAll(dependencyProject.getDependencies());
 								}
 								this.next = dependencyProject;
-								this.treated.add(artifactId);
+								isTreated = true;
 							}
 						}
+						catch (MojoExecutionException e) {
+							getLog().warn("Unable to retreive the Maven plugin: "+artifactId, e); //$NON-NLS-1$
+							isTreated = true;
+						}
+						catch (ProjectBuildingException e) {
+							getLog().warn("Unable to retreive the Maven plugin: "+artifactId, e); //$NON-NLS-1$
+							isTreated = true;
+						}
+						if (isTreated) this.treated.add(artifactId);
 					}
-					catch (MojoExecutionException e) {
-						NoSuchElementException nsee = new NoSuchElementException(artifactId);
-						nsee.initCause(e);
-						throw nsee;
-					}
-					catch (ProjectBuildingException e) {
-						NoSuchElementException nsee = new NoSuchElementException(artifactId);
-						nsee.initCause(e);
-						throw nsee;
-					}
 				}
-    		}
-    	}
-    	
+			}
+		}
+
 		/**
 		 * {@inheritDoc}
 		 */
@@ -1466,48 +1466,48 @@
 		public void remove() {
 			throw new UnsupportedOperationException();
 		}
-    	
-    } // class DependencyIterator
 
-    /**
-     * @author $Author: sgalland$
-     * @version $FullVersion$
-     * @mavengroupid $GroupId$
-     * @mavenartifactid $ArtifactId$
-     */
-    private class PluginIterator implements Iterator<Plugin> {
+	} // class DependencyIterator
 
-    	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();
-    	}
-    	
+	/**
+	 * @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;
-    			}
-    		}
-    	}
+			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}
@@ -1535,10 +1535,10 @@
 		public void remove() {
 			throw new UnsupportedOperationException();
 		}
-    	
-    } // class PluginIterator
 
-    /**
+	} // class PluginIterator
+
+	/**
 	 * Abstract implementation for all Arakhn&ecirc; maven modules. This implementation is thread safe.
 	 * 
 	 * @author $Author: galland$
@@ -1556,7 +1556,7 @@
 		 * @param rootDirectory is the root directory in which the file was found. 
 		 */
 		public void findFile(File file, File rootDirectory);
-		
+
 	} // interface FindFileListener
-	
+
 }
\ No newline at end of file


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