brett 2004/11/05 23:12:50
Modified: src/java/main/org/apache/maven/jelly/tags/maven Tag:
MAVEN-1_0_1-BRANCH DependencyResolver.java
DependencyResolverInterface.java
GraphDependencyResolver.java
WerkzDependencyResolver.java
Added: src/java/main/org/apache/maven/jelly/tags/maven Tag:
MAVEN-1_0_1-BRANCH DependencyResolverException.java
Log:
throw a more specific exception
Revision Changes Path
No revision
No revision
1.7.2.1 +20 -18
maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/DependencyResolver.java
Index: DependencyResolver.java
===================================================================
RCS file:
/home/cvs/maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/DependencyResolver.java,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -u -r1.7 -r1.7.2.1
--- DependencyResolver.java 23 Mar 2004 02:18:19 -0000 1.7
+++ DependencyResolver.java 6 Nov 2004 07:12:50 -0000 1.7.2.1
@@ -35,35 +35,37 @@
* Creates the dependency resolver. The implementation is chosen by the
* System property "maven.core.dependencyresolver". By default it is
* the WerkzDependencyResolver. Ultimately I see this proxy being removed.
+ *
* @see java.lang.Object#Object()
*/
public DependencyResolver()
{
String prop = "maven.core.dependencyresolver";
- String type = System.getProperty(prop);
+ String type = System.getProperty( prop );
try
{
- if (type == null)
+ if ( type == null )
{
impl = new WerkzDependencyResolver();
}
else
{
- impl = (DependencyResolverInterface)
Class.forName(type).newInstance();
+ impl = (DependencyResolverInterface) Class.forName( type
).newInstance();
}
}
- catch (Exception e)
+ catch ( Exception e )
{
- throw new RuntimeException("Unable to create " + type);
+ throw new RuntimeException( "Unable to create " + type );
}
}
/**
* Creates the dependency resolver with a specific implementation
+ *
* @param impl
*/
- public DependencyResolver(DependencyResolverInterface impl)
+ public DependencyResolver( DependencyResolverInterface impl )
{
this.impl = impl;
}
@@ -79,42 +81,42 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#setProjects(java.util.List)
*/
- public void setProjects(List projects)
+ public void setProjects( List projects )
{
- impl.setProjects(projects);
+ impl.setProjects( projects );
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project)
*/
- public List getSortedDependencies(Project project) throws Exception
+ public List getSortedDependencies( Project project ) throws
DependencyResolverException
{
- return impl.getSortedDependencies(project);
+ return impl.getSortedDependencies( project );
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project,
boolean)
*/
- public List getSortedDependencies(Project project, boolean sourceBuild) throws
Exception
+ public List getSortedDependencies( Project project, boolean sourceBuild )
throws DependencyResolverException
{
- return impl.getSortedDependencies(project, sourceBuild);
+ return impl.getSortedDependencies( project, sourceBuild );
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(boolean)
*/
- public List getSortedDependencies(boolean sourceBuild) throws Exception
+ public List getSortedDependencies( boolean sourceBuild ) throws
DependencyResolverException
{
- return impl.getSortedDependencies(sourceBuild);
+ return impl.getSortedDependencies( sourceBuild );
}
- public static Project getProject(List projects, String id)
+ public static Project getProject( List projects, String id )
{
Iterator iter = projects.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
Project project = (Project) iter.next();
- if (project.getId().equals(id))
+ if ( project.getId().equals( id ) )
{
return project;
}
1.5.2.1 +9 -9
maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/DependencyResolverInterface.java
Index: DependencyResolverInterface.java
===================================================================
RCS file:
/home/cvs/maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/DependencyResolverInterface.java,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -r1.5 -r1.5.2.1
--- DependencyResolverInterface.java 23 Mar 2004 02:18:19 -0000 1.5
+++ DependencyResolverInterface.java 6 Nov 2004 07:12:50 -0000 1.5.2.1
@@ -37,33 +37,33 @@
*
* @param projects List of projects.
*/
- void setProjects(List projects);
+ void setProjects( List projects );
/**
* Get the list of projects in dependency sorted order.
*
* @param project The project to use as the head of the graph.
* @return The list of projects.
- * @throws Exception If an error occurs while processing the graph.
+ * @throws DependencyResolverException If an error occurs while processing the
graph.
*/
- List getSortedDependencies(Project project) throws Exception;
+ List getSortedDependencies( Project project ) throws
DependencyResolverException;
/**
* Get the list of projects in dependency sorted order.
*
- * @param project The project to use as the head of the graph.
+ * @param project The project to use as the head of the graph.
* @param sourceBuild Indicate we are performing a source build.
* @return The list of projects.
- * @throws Exception If an error occurs while processing the graph.
+ * @throws DependencyResolverException If an error occurs while processing the
graph.
*/
- List getSortedDependencies(Project project, boolean sourceBuild) throws
Exception;
+ List getSortedDependencies( Project project, boolean sourceBuild ) throws
DependencyResolverException;
/**
* Get the list of projects in dependency sorted order.
*
* @param sourceBuild Flag to indicate we are performing a source build.
* @return The list of projects.
- * @throws Exception If an error occurs while processing the graph.
+ * @throws DependencyResolverException If an error occurs while processing the
graph.
*/
- List getSortedDependencies(boolean sourceBuild) throws Exception;
+ List getSortedDependencies( boolean sourceBuild ) throws
DependencyResolverException;
}
1.4.2.1 +36 -30
maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/GraphDependencyResolver.java
Index: GraphDependencyResolver.java
===================================================================
RCS file:
/home/cvs/maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/GraphDependencyResolver.java,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -r1.4 -r1.4.2.1
--- GraphDependencyResolver.java 23 Mar 2004 02:18:19 -0000 1.4
+++ GraphDependencyResolver.java 6 Nov 2004 07:12:50 -0000 1.4.2.1
@@ -25,23 +25,29 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+
/**
- * Takes a list of maven projects and determines the overall
- * dependency ordering among the project.
+ * Takes a list of maven projects and determines the overall
+ * dependency ordering among the project.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- *
* @version $Id$
*/
public class GraphDependencyResolver implements DependencyResolverInterface
{
- /** The dependency graph. */
+ /**
+ * The dependency graph.
+ */
private DependencyGraph dependencyGraph;
- /** List of maven projects to analyse. */
+ /**
+ * List of maven projects to analyse.
+ */
private List projects;
- /** Flag to indicate whether the graph has been built. */
+ /**
+ * Flag to indicate whether the graph has been built.
+ */
private boolean graphBuilt;
/**
@@ -66,7 +72,7 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#setProjects(List)
*/
- public void setProjects(List projects)
+ public void setProjects( List projects )
{
this.projects = projects;
}
@@ -74,42 +80,42 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(Project)
*/
- public List getSortedDependencies(Project project) throws Exception
+ public List getSortedDependencies( Project project )
{
- return getSortedDependencies(project, false);
+ return getSortedDependencies( project, false );
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(Project,
boolean)
*/
- public List getSortedDependencies(Project project, boolean sourceBuild) throws
Exception
+ public List getSortedDependencies( Project project, boolean sourceBuild )
{
buildGraph();
- List sortedDependencies = dependencyGraph.getSortedDependencies(project);
+ List sortedDependencies = dependencyGraph.getSortedDependencies( project );
- if (sourceBuild)
+ if ( sourceBuild )
{
return sortedDependencies;
}
- return getBinaryDependencies(sortedDependencies);
+ return getBinaryDependencies( sortedDependencies );
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(boolean)
*/
- public List getSortedDependencies(boolean sourceBuild) throws Exception
+ public List getSortedDependencies( boolean sourceBuild )
{
buildGraph();
List sortedDependencies = dependencyGraph.getSortedDependencies();
- if (sourceBuild)
+ if ( sourceBuild )
{
return sortedDependencies;
}
- return getBinaryDependencies(sortedDependencies);
+ return getBinaryDependencies( sortedDependencies );
}
/**
@@ -118,24 +124,24 @@
* @param sortedDependencies List of projects that have been dependency sorted.
* @return The list of projects.
*/
- private List getBinaryDependencies(List sortedDependencies)
+ private List getBinaryDependencies( List sortedDependencies )
{
HashMap idMap = new HashMap();
- for (Iterator i = projects.iterator(); i.hasNext();)
+ for ( Iterator i = projects.iterator(); i.hasNext(); )
{
Project p = (Project) i.next();
- idMap.put(p.getId(), p);
+ idMap.put( p.getId(), p );
}
List binaryDeps = new ArrayList();
- for (Iterator i = sortedDependencies.iterator(); i.hasNext();)
+ for ( Iterator i = sortedDependencies.iterator(); i.hasNext(); )
{
Project p = (Project) i.next();
- Project dep = (Project) idMap.get(p.getId());
- if (dep != null)
+ Project dep = (Project) idMap.get( p.getId() );
+ if ( dep != null )
{
- binaryDeps.add(dep);
+ binaryDeps.add( dep );
}
}
@@ -147,25 +153,25 @@
*/
private void buildGraph()
{
- if (graphBuilt)
+ if ( graphBuilt )
{
return;
}
- for (Iterator i = projects.iterator(); i.hasNext();)
+ for ( Iterator i = projects.iterator(); i.hasNext(); )
{
Project p = (Project) i.next();
ArrayList dependencies = new ArrayList();
- for (Iterator j = p.getDependencies().iterator(); j.hasNext();)
+ for ( Iterator j = p.getDependencies().iterator(); j.hasNext(); )
{
Dependency d = (Dependency) j.next();
Project dependentProject = new Project();
- dependentProject.setId(d.getId());
- dependencies.add(dependentProject);
+ dependentProject.setId( d.getId() );
+ dependencies.add( dependentProject );
}
- dependencyGraph.addDependencies(p, dependencies);
+ dependencyGraph.addDependencies( p, dependencies );
}
graphBuilt = true;
}
1.10.2.1 +90 -53
maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/WerkzDependencyResolver.java
Index: WerkzDependencyResolver.java
===================================================================
RCS file:
/home/cvs/maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/WerkzDependencyResolver.java,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -r1.10 -r1.10.2.1
--- WerkzDependencyResolver.java 26 Jun 2004 15:00:42 -0000 1.10
+++ WerkzDependencyResolver.java 6 Nov 2004 07:12:50 -0000 1.10.2.1
@@ -18,10 +18,12 @@
*/
import com.werken.werkz.Action;
+import com.werken.werkz.CyclicGoalChainException;
import com.werken.werkz.Goal;
+import com.werken.werkz.NoActionDefinitionException;
import com.werken.werkz.Session;
+import com.werken.werkz.UnattainableGoalException;
import com.werken.werkz.WerkzProject;
-
import org.apache.maven.project.Dependency;
import org.apache.maven.project.Project;
@@ -31,6 +33,7 @@
/**
* THIS CLASS IS NOT THREADSAFE.
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Ben Walding</a>
* @version $Id$
*/
@@ -54,7 +57,7 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#setProjects(java.util.List)
*/
- public void setProjects(List projects)
+ public void setProjects( List projects )
{
this.projects = projects;
}
@@ -62,16 +65,17 @@
/**
* Retrieves the existing goal for a project (based on Id).
* If no goal exists, an exception is thrown.
+ *
* @param project the project to retrieve a goal from
* @return ProjectGoal
*/
- protected ProjectGoal getExistingGoal(Project project)
+ protected ProjectGoal getExistingGoal( Project project )
{
- ProjectGoal goal = (ProjectGoal) wproject.getGoal(project.getId());
+ ProjectGoal goal = (ProjectGoal) wproject.getGoal( project.getId() );
- if (goal == null)
+ if ( goal == null )
{
- throw new NullPointerException("No goal exists : " + project.getId());
+ throw new NullPointerException( "No goal exists : " + project.getId() );
}
else
{
@@ -82,29 +86,29 @@
/**
* Retrieves the existing goal for a project (based on Id).
* If no goal exists, one is created for this given project.
+ *
* @param project
* @param sourceBuild
* @return ProjectGoal
*/
- protected ProjectGoal getOrCreateGoal(Project project, boolean sourceBuild)
+ protected ProjectGoal getOrCreateGoal( Project project, boolean sourceBuild )
{
- ProjectGoal goal = (ProjectGoal) wproject.getGoal(project.getId());
- if (goal == null)
+ ProjectGoal goal = (ProjectGoal) wproject.getGoal( project.getId() );
+ if ( goal == null )
{
- goal = new ProjectGoal(project, sourceBuild);
- goal.setAction(new ListAddAction(goal, sortedGoals));
- wproject.addGoal(goal);
+ goal = new ProjectGoal( project, sourceBuild );
+ goal.setAction( new ListAddAction( goal, sortedGoals ) );
+ wproject.addGoal( goal );
}
return goal;
}
/**
* Builds the projects / dependencies into an internal acyclic directed graph
- * @throws Exception
*/
- public void buildGraph() throws Exception
+ public void buildGraph() throws CyclicGoalChainException
{
- if (doItAll != null)
+ if ( doItAll != null )
{
return;
}
@@ -113,38 +117,38 @@
{
wproject = new WerkzProject();
- doItAll = new Goal("DO_IT_ALL");
- doItAll.setAction(new DummyAction());
+ doItAll = new Goal( "DO_IT_ALL" );
+ doItAll.setAction( new DummyAction() );
//Initialise all the true goals of the system
Iterator iter = projects.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
Project project = (Project) iter.next();
- Goal projectGoal = getOrCreateGoal(project, true);
- doItAll.addPrecursor(projectGoal);
+ Goal projectGoal = getOrCreateGoal( project, true );
+ doItAll.addPrecursor( projectGoal );
}
//Now add the dependencies
iter = projects.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
Project project = (Project) iter.next();
- Goal projectGoal = getExistingGoal(project);
+ Goal projectGoal = getExistingGoal( project );
Iterator depIter = project.getDependencies().iterator();
- while (depIter.hasNext())
+ while ( depIter.hasNext() )
{
Dependency dep = (Dependency) depIter.next();
Project depProject = new Project();
- depProject.setId(dep.getId());
+ depProject.setId( dep.getId() );
- Goal depGoal = getOrCreateGoal(depProject, false);
- projectGoal.addPrecursor(depGoal);
+ Goal depGoal = getOrCreateGoal( depProject, false );
+ projectGoal.addPrecursor( depGoal );
}
}
}
- catch (Exception e)
+ catch ( CyclicGoalChainException e )
{
doItAll = null;
wproject = new WerkzProject();
@@ -156,31 +160,32 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project)
*/
- public List getSortedDependencies(Project project) throws Exception
+ public List getSortedDependencies( Project project ) throws
DependencyResolverException
{
- return getSortedDependencies(project, false);
+ return getSortedDependencies( project, false );
}
/**
* Filters the given list of goals, and returns the associated projects
- *
+ * <p/>
* If param:sourceBuild == true, include goal
* If param:sourceBuild == false, include goal if goal:sourceBuild == true
+ *
* @param goals
* @param sourceBuild
* @return List
*/
- public List getProjects(List goals, boolean sourceBuild)
+ public List getProjects( List goals, boolean sourceBuild )
{
List result = new ArrayList();
Iterator iter = goals.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
ProjectGoal goal = (ProjectGoal) iter.next();
- if ((sourceBuild) || (!sourceBuild && goal.getSourceBuild()))
+ if ( ( sourceBuild ) || ( !sourceBuild && goal.getSourceBuild() ) )
{
- result.add((goal).getProject());
+ result.add( ( goal ).getProject() );
}
}
@@ -190,27 +195,57 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project,
boolean)
*/
- public List getSortedDependencies(Project project, boolean sourceBuild) throws
Exception
+ public List getSortedDependencies( Project project, boolean sourceBuild )
throws DependencyResolverException
{
- buildGraph();
- sortedGoals.clear();
- Session session = new Session();
- ProjectGoal g = getExistingGoal(project);
- g.attain(session);
+ try
+ {
+ buildGraph();
+ sortedGoals.clear();
+ Session session = new Session();
+ ProjectGoal g = getExistingGoal( project );
+ g.attain( session );
+ }
+ catch ( CyclicGoalChainException e )
+ {
+ throw new DependencyResolverException( "A cycle was detected", e );
+ }
+ catch ( UnattainableGoalException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
+ catch ( NoActionDefinitionException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
- return getProjects(sortedGoals, sourceBuild);
+ return getProjects( sortedGoals, sourceBuild );
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(boolean)
*/
- public List getSortedDependencies(boolean sourceBuild) throws Exception
+ public List getSortedDependencies( boolean sourceBuild ) throws
DependencyResolverException
{
- buildGraph();
- sortedGoals.clear();
- Session session = new Session();
- doItAll.attain(session);
- return getProjects(sortedGoals, sourceBuild);
+ try
+ {
+ buildGraph();
+ sortedGoals.clear();
+ Session session = new Session();
+ doItAll.attain( session );
+ return getProjects( sortedGoals, sourceBuild );
+ }
+ catch ( CyclicGoalChainException e )
+ {
+ throw new DependencyResolverException( "A cycle was detected", e );
+ }
+ catch ( UnattainableGoalException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
+ catch ( NoActionDefinitionException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
}
}
@@ -222,7 +257,8 @@
{
private List list;
private Goal goal;
- public ListAddAction(Goal goal, List list)
+
+ public ListAddAction( Goal goal, List list )
{
this.list = list;
this.goal = goal;
@@ -235,12 +271,12 @@
public void performAction( Session session ) throws Exception
{
- list.add(goal);
+ list.add( goal );
}
public void performAction() throws Exception
{
- list.add(goal);
+ list.add( goal );
}
}
@@ -271,9 +307,10 @@
{
private final Project project;
private final boolean sourceBuild;
- public ProjectGoal(Project project, boolean sourceBuild)
+
+ public ProjectGoal( Project project, boolean sourceBuild )
{
- super(project.getId());
+ super( project.getId() );
this.project = project;
this.sourceBuild = sourceBuild;
}
No revision
Index: WerkzDependencyResolver.java
===================================================================
RCS file:
/home/cvs/maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/WerkzDependencyResolver.java,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -r1.10 -r1.10.2.1
--- WerkzDependencyResolver.java 26 Jun 2004 15:00:42 -0000 1.10
+++ WerkzDependencyResolver.java 6 Nov 2004 07:12:50 -0000 1.10.2.1
@@ -18,10 +18,12 @@
*/
import com.werken.werkz.Action;
+import com.werken.werkz.CyclicGoalChainException;
import com.werken.werkz.Goal;
+import com.werken.werkz.NoActionDefinitionException;
import com.werken.werkz.Session;
+import com.werken.werkz.UnattainableGoalException;
import com.werken.werkz.WerkzProject;
-
import org.apache.maven.project.Dependency;
import org.apache.maven.project.Project;
@@ -31,6 +33,7 @@
/**
* THIS CLASS IS NOT THREADSAFE.
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Ben Walding</a>
* @version $Id$
*/
@@ -54,7 +57,7 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#setProjects(java.util.List)
*/
- public void setProjects(List projects)
+ public void setProjects( List projects )
{
this.projects = projects;
}
@@ -62,16 +65,17 @@
/**
* Retrieves the existing goal for a project (based on Id).
* If no goal exists, an exception is thrown.
+ *
* @param project the project to retrieve a goal from
* @return ProjectGoal
*/
- protected ProjectGoal getExistingGoal(Project project)
+ protected ProjectGoal getExistingGoal( Project project )
{
- ProjectGoal goal = (ProjectGoal) wproject.getGoal(project.getId());
+ ProjectGoal goal = (ProjectGoal) wproject.getGoal( project.getId() );
- if (goal == null)
+ if ( goal == null )
{
- throw new NullPointerException("No goal exists : " + project.getId());
+ throw new NullPointerException( "No goal exists : " + project.getId() );
}
else
{
@@ -82,29 +86,29 @@
/**
* Retrieves the existing goal for a project (based on Id).
* If no goal exists, one is created for this given project.
+ *
* @param project
* @param sourceBuild
* @return ProjectGoal
*/
- protected ProjectGoal getOrCreateGoal(Project project, boolean sourceBuild)
+ protected ProjectGoal getOrCreateGoal( Project project, boolean sourceBuild )
{
- ProjectGoal goal = (ProjectGoal) wproject.getGoal(project.getId());
- if (goal == null)
+ ProjectGoal goal = (ProjectGoal) wproject.getGoal( project.getId() );
+ if ( goal == null )
{
- goal = new ProjectGoal(project, sourceBuild);
- goal.setAction(new ListAddAction(goal, sortedGoals));
- wproject.addGoal(goal);
+ goal = new ProjectGoal( project, sourceBuild );
+ goal.setAction( new ListAddAction( goal, sortedGoals ) );
+ wproject.addGoal( goal );
}
return goal;
}
/**
* Builds the projects / dependencies into an internal acyclic directed graph
- * @throws Exception
*/
- public void buildGraph() throws Exception
+ public void buildGraph() throws CyclicGoalChainException
{
- if (doItAll != null)
+ if ( doItAll != null )
{
return;
}
@@ -113,38 +117,38 @@
{
wproject = new WerkzProject();
- doItAll = new Goal("DO_IT_ALL");
- doItAll.setAction(new DummyAction());
+ doItAll = new Goal( "DO_IT_ALL" );
+ doItAll.setAction( new DummyAction() );
//Initialise all the true goals of the system
Iterator iter = projects.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
Project project = (Project) iter.next();
- Goal projectGoal = getOrCreateGoal(project, true);
- doItAll.addPrecursor(projectGoal);
+ Goal projectGoal = getOrCreateGoal( project, true );
+ doItAll.addPrecursor( projectGoal );
}
//Now add the dependencies
iter = projects.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
Project project = (Project) iter.next();
- Goal projectGoal = getExistingGoal(project);
+ Goal projectGoal = getExistingGoal( project );
Iterator depIter = project.getDependencies().iterator();
- while (depIter.hasNext())
+ while ( depIter.hasNext() )
{
Dependency dep = (Dependency) depIter.next();
Project depProject = new Project();
- depProject.setId(dep.getId());
+ depProject.setId( dep.getId() );
- Goal depGoal = getOrCreateGoal(depProject, false);
- projectGoal.addPrecursor(depGoal);
+ Goal depGoal = getOrCreateGoal( depProject, false );
+ projectGoal.addPrecursor( depGoal );
}
}
}
- catch (Exception e)
+ catch ( CyclicGoalChainException e )
{
doItAll = null;
wproject = new WerkzProject();
@@ -156,31 +160,32 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project)
*/
- public List getSortedDependencies(Project project) throws Exception
+ public List getSortedDependencies( Project project ) throws
DependencyResolverException
{
- return getSortedDependencies(project, false);
+ return getSortedDependencies( project, false );
}
/**
* Filters the given list of goals, and returns the associated projects
- *
+ * <p/>
* If param:sourceBuild == true, include goal
* If param:sourceBuild == false, include goal if goal:sourceBuild == true
+ *
* @param goals
* @param sourceBuild
* @return List
*/
- public List getProjects(List goals, boolean sourceBuild)
+ public List getProjects( List goals, boolean sourceBuild )
{
List result = new ArrayList();
Iterator iter = goals.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
ProjectGoal goal = (ProjectGoal) iter.next();
- if ((sourceBuild) || (!sourceBuild && goal.getSourceBuild()))
+ if ( ( sourceBuild ) || ( !sourceBuild && goal.getSourceBuild() ) )
{
- result.add((goal).getProject());
+ result.add( ( goal ).getProject() );
}
}
@@ -190,27 +195,57 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project,
boolean)
*/
- public List getSortedDependencies(Project project, boolean sourceBuild) throws
Exception
+ public List getSortedDependencies( Project project, boolean sourceBuild )
throws DependencyResolverException
{
- buildGraph();
- sortedGoals.clear();
- Session session = new Session();
- ProjectGoal g = getExistingGoal(project);
- g.attain(session);
+ try
+ {
+ buildGraph();
+ sortedGoals.clear();
+ Session session = new Session();
+ ProjectGoal g = getExistingGoal( project );
+ g.attain( session );
+ }
+ catch ( CyclicGoalChainException e )
+ {
+ throw new DependencyResolverException( "A cycle was detected", e );
+ }
+ catch ( UnattainableGoalException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
+ catch ( NoActionDefinitionException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
- return getProjects(sortedGoals, sourceBuild);
+ return getProjects( sortedGoals, sourceBuild );
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(boolean)
*/
- public List getSortedDependencies(boolean sourceBuild) throws Exception
+ public List getSortedDependencies( boolean sourceBuild ) throws
DependencyResolverException
{
- buildGraph();
- sortedGoals.clear();
- Session session = new Session();
- doItAll.attain(session);
- return getProjects(sortedGoals, sourceBuild);
+ try
+ {
+ buildGraph();
+ sortedGoals.clear();
+ Session session = new Session();
+ doItAll.attain( session );
+ return getProjects( sortedGoals, sourceBuild );
+ }
+ catch ( CyclicGoalChainException e )
+ {
+ throw new DependencyResolverException( "A cycle was detected", e );
+ }
+ catch ( UnattainableGoalException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
+ catch ( NoActionDefinitionException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
}
}
@@ -222,7 +257,8 @@
{
private List list;
private Goal goal;
- public ListAddAction(Goal goal, List list)
+
+ public ListAddAction( Goal goal, List list )
{
this.list = list;
this.goal = goal;
@@ -235,12 +271,12 @@
public void performAction( Session session ) throws Exception
{
- list.add(goal);
+ list.add( goal );
}
public void performAction() throws Exception
{
- list.add(goal);
+ list.add( goal );
}
}
@@ -271,9 +307,10 @@
{
private final Project project;
private final boolean sourceBuild;
- public ProjectGoal(Project project, boolean sourceBuild)
+
+ public ProjectGoal( Project project, boolean sourceBuild )
{
- super(project.getId());
+ super( project.getId() );
this.project = project;
this.sourceBuild = sourceBuild;
}
No revision
Index: WerkzDependencyResolver.java
===================================================================
RCS file:
/home/cvs/maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/WerkzDependencyResolver.java,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -r1.10 -r1.10.2.1
--- WerkzDependencyResolver.java 26 Jun 2004 15:00:42 -0000 1.10
+++ WerkzDependencyResolver.java 6 Nov 2004 07:12:50 -0000 1.10.2.1
@@ -18,10 +18,12 @@
*/
import com.werken.werkz.Action;
+import com.werken.werkz.CyclicGoalChainException;
import com.werken.werkz.Goal;
+import com.werken.werkz.NoActionDefinitionException;
import com.werken.werkz.Session;
+import com.werken.werkz.UnattainableGoalException;
import com.werken.werkz.WerkzProject;
-
import org.apache.maven.project.Dependency;
import org.apache.maven.project.Project;
@@ -31,6 +33,7 @@
/**
* THIS CLASS IS NOT THREADSAFE.
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Ben Walding</a>
* @version $Id$
*/
@@ -54,7 +57,7 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#setProjects(java.util.List)
*/
- public void setProjects(List projects)
+ public void setProjects( List projects )
{
this.projects = projects;
}
@@ -62,16 +65,17 @@
/**
* Retrieves the existing goal for a project (based on Id).
* If no goal exists, an exception is thrown.
+ *
* @param project the project to retrieve a goal from
* @return ProjectGoal
*/
- protected ProjectGoal getExistingGoal(Project project)
+ protected ProjectGoal getExistingGoal( Project project )
{
- ProjectGoal goal = (ProjectGoal) wproject.getGoal(project.getId());
+ ProjectGoal goal = (ProjectGoal) wproject.getGoal( project.getId() );
- if (goal == null)
+ if ( goal == null )
{
- throw new NullPointerException("No goal exists : " + project.getId());
+ throw new NullPointerException( "No goal exists : " + project.getId() );
}
else
{
@@ -82,29 +86,29 @@
/**
* Retrieves the existing goal for a project (based on Id).
* If no goal exists, one is created for this given project.
+ *
* @param project
* @param sourceBuild
* @return ProjectGoal
*/
- protected ProjectGoal getOrCreateGoal(Project project, boolean sourceBuild)
+ protected ProjectGoal getOrCreateGoal( Project project, boolean sourceBuild )
{
- ProjectGoal goal = (ProjectGoal) wproject.getGoal(project.getId());
- if (goal == null)
+ ProjectGoal goal = (ProjectGoal) wproject.getGoal( project.getId() );
+ if ( goal == null )
{
- goal = new ProjectGoal(project, sourceBuild);
- goal.setAction(new ListAddAction(goal, sortedGoals));
- wproject.addGoal(goal);
+ goal = new ProjectGoal( project, sourceBuild );
+ goal.setAction( new ListAddAction( goal, sortedGoals ) );
+ wproject.addGoal( goal );
}
return goal;
}
/**
* Builds the projects / dependencies into an internal acyclic directed graph
- * @throws Exception
*/
- public void buildGraph() throws Exception
+ public void buildGraph() throws CyclicGoalChainException
{
- if (doItAll != null)
+ if ( doItAll != null )
{
return;
}
@@ -113,38 +117,38 @@
{
wproject = new WerkzProject();
- doItAll = new Goal("DO_IT_ALL");
- doItAll.setAction(new DummyAction());
+ doItAll = new Goal( "DO_IT_ALL" );
+ doItAll.setAction( new DummyAction() );
//Initialise all the true goals of the system
Iterator iter = projects.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
Project project = (Project) iter.next();
- Goal projectGoal = getOrCreateGoal(project, true);
- doItAll.addPrecursor(projectGoal);
+ Goal projectGoal = getOrCreateGoal( project, true );
+ doItAll.addPrecursor( projectGoal );
}
//Now add the dependencies
iter = projects.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
Project project = (Project) iter.next();
- Goal projectGoal = getExistingGoal(project);
+ Goal projectGoal = getExistingGoal( project );
Iterator depIter = project.getDependencies().iterator();
- while (depIter.hasNext())
+ while ( depIter.hasNext() )
{
Dependency dep = (Dependency) depIter.next();
Project depProject = new Project();
- depProject.setId(dep.getId());
+ depProject.setId( dep.getId() );
- Goal depGoal = getOrCreateGoal(depProject, false);
- projectGoal.addPrecursor(depGoal);
+ Goal depGoal = getOrCreateGoal( depProject, false );
+ projectGoal.addPrecursor( depGoal );
}
}
}
- catch (Exception e)
+ catch ( CyclicGoalChainException e )
{
doItAll = null;
wproject = new WerkzProject();
@@ -156,31 +160,32 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project)
*/
- public List getSortedDependencies(Project project) throws Exception
+ public List getSortedDependencies( Project project ) throws
DependencyResolverException
{
- return getSortedDependencies(project, false);
+ return getSortedDependencies( project, false );
}
/**
* Filters the given list of goals, and returns the associated projects
- *
+ * <p/>
* If param:sourceBuild == true, include goal
* If param:sourceBuild == false, include goal if goal:sourceBuild == true
+ *
* @param goals
* @param sourceBuild
* @return List
*/
- public List getProjects(List goals, boolean sourceBuild)
+ public List getProjects( List goals, boolean sourceBuild )
{
List result = new ArrayList();
Iterator iter = goals.iterator();
- while (iter.hasNext())
+ while ( iter.hasNext() )
{
ProjectGoal goal = (ProjectGoal) iter.next();
- if ((sourceBuild) || (!sourceBuild && goal.getSourceBuild()))
+ if ( ( sourceBuild ) || ( !sourceBuild && goal.getSourceBuild() ) )
{
- result.add((goal).getProject());
+ result.add( ( goal ).getProject() );
}
}
@@ -190,27 +195,57 @@
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project,
boolean)
*/
- public List getSortedDependencies(Project project, boolean sourceBuild) throws
Exception
+ public List getSortedDependencies( Project project, boolean sourceBuild )
throws DependencyResolverException
{
- buildGraph();
- sortedGoals.clear();
- Session session = new Session();
- ProjectGoal g = getExistingGoal(project);
- g.attain(session);
+ try
+ {
+ buildGraph();
+ sortedGoals.clear();
+ Session session = new Session();
+ ProjectGoal g = getExistingGoal( project );
+ g.attain( session );
+ }
+ catch ( CyclicGoalChainException e )
+ {
+ throw new DependencyResolverException( "A cycle was detected", e );
+ }
+ catch ( UnattainableGoalException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
+ catch ( NoActionDefinitionException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
- return getProjects(sortedGoals, sourceBuild);
+ return getProjects( sortedGoals, sourceBuild );
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(boolean)
*/
- public List getSortedDependencies(boolean sourceBuild) throws Exception
+ public List getSortedDependencies( boolean sourceBuild ) throws
DependencyResolverException
{
- buildGraph();
- sortedGoals.clear();
- Session session = new Session();
- doItAll.attain(session);
- return getProjects(sortedGoals, sourceBuild);
+ try
+ {
+ buildGraph();
+ sortedGoals.clear();
+ Session session = new Session();
+ doItAll.attain( session );
+ return getProjects( sortedGoals, sourceBuild );
+ }
+ catch ( CyclicGoalChainException e )
+ {
+ throw new DependencyResolverException( "A cycle was detected", e );
+ }
+ catch ( UnattainableGoalException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
+ catch ( NoActionDefinitionException e )
+ {
+ throw new DependencyResolverException( "An invalid goal was called", e
);
+ }
}
}
@@ -222,7 +257,8 @@
{
private List list;
private Goal goal;
- public ListAddAction(Goal goal, List list)
+
+ public ListAddAction( Goal goal, List list )
{
this.list = list;
this.goal = goal;
@@ -235,12 +271,12 @@
public void performAction( Session session ) throws Exception
{
- list.add(goal);
+ list.add( goal );
}
public void performAction() throws Exception
{
- list.add(goal);
+ list.add( goal );
}
}
@@ -271,9 +307,10 @@
{
private final Project project;
private final boolean sourceBuild;
- public ProjectGoal(Project project, boolean sourceBuild)
+
+ public ProjectGoal( Project project, boolean sourceBuild )
{
- super(project.getId());
+ super( project.getId() );
this.project = project;
this.sourceBuild = sourceBuild;
}
1.1.2.1 +21 -0
maven-jelly-tags/src/java/main/org/apache/maven/jelly/tags/maven/Attic/DependencyResolverException.java
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]