bwalding 2004/01/11 07:24:30
Added: maven-core/src/java/org/apache/maven/jelly/tags/maven
DependencyResolver.java
WerkzDependencyResolver.java
DependencyResolverInterface.java
Log:
Ported from the old maven and upgraded to fit in more properly.
Revision Changes Path
1.1
maven-components/maven-core/src/java/org/apache/maven/jelly/tags/maven/DependencyResolver.java
Index: DependencyResolver.java
===================================================================
package org.apache.maven.jelly.tags.maven;
/*
* ==================================================================== The
* Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The end-user documentation included with the redistribution, if any,
* must include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if and
* wherever such third-party acknowledgments normally appear.
* 4. The names "Apache" and "Apache Software Foundation" and "Apache Maven"
* must not be used to endorse or promote products derived from this software
* without prior written permission. For written permission, please contact
* [EMAIL PROTECTED]
* 5. Products derived from this software may not be called "Apache", "Apache
* Maven", nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/> .
*
* ====================================================================
*/
import java.util.Iterator;
import java.util.List;
import org.apache.maven.project.Project;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Ben Walding</a>
* @version $Id: DependencyResolver.java,v 1.1 2004/01/11 15:24:30 bwalding Exp $
*/
public class DependencyResolver implements DependencyResolverInterface
{
private final DependencyResolverInterface impl;
/**
* 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);
try
{
if ( type == null )
{
impl = new WerkzDependencyResolver();
}
else
{
impl = (DependencyResolverInterface) Class.forName(
type )
.newInstance( );
}
}
catch ( Exception e )
{
throw new RuntimeException( "Unable to create " + type );
}
}
/**
* Creates the dependency resolver with a specific implementation
*
* @param impl
*/
public DependencyResolver( DependencyResolverInterface impl )
{
this.impl = impl;
}
/**
* @see org.apache.maven.jelly.tags.maven.DependencyResolverInterface#clear()
*/
public void clear()
{
impl.clear();
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#setProjects(java.util.List)
*/
public void setProjects( List 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
{
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
{
return impl.getSortedDependencies( project, sourceBuild);
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(boolean)
*/
public List getSortedDependencies( boolean sourceBuild ) throws Exception
{
return impl.getSortedDependencies( sourceBuild);
}
public static Project getProject( List projects, String id )
{
Iterator iter = projects.iterator();
while ( iter.hasNext() )
{
Project project = (Project) iter.next();
String thisId = project.getId();
if ( thisId.equals( id) )
{
return project;
}
}
return null;
}
}
1.1
maven-components/maven-core/src/java/org/apache/maven/jelly/tags/maven/WerkzDependencyResolver.java
Index: WerkzDependencyResolver.java
===================================================================
package org.apache.maven.jelly.tags.maven;
/*
* ==================================================================== The
* Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: 1.
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. The end-user documentation
* included with the redistribution, if any, must include the following
* acknowledgment: "This product includes software developed by the Apache
* Software Foundation (http://www.apache.org/)." Alternately, this
* acknowledgment may appear in the software itself, if and wherever such
* third-party acknowledgments normally appear. 4. The names "Apache" and
* "Apache Software Foundation" and "Apache Maven" must not be used to endorse
* or promote products derived from this software without prior written
* permission. For written permission, please contact [EMAIL PROTECTED] 5.
* Products derived from this software may not be called "Apache", "Apache
* Maven", nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/> .
*
* ====================================================================
*/
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.Project;
import org.apache.maven.werkz.Action;
import org.apache.maven.werkz.Goal;
import org.apache.maven.werkz.Session;
import org.apache.maven.werkz.WerkzProject;
/**
* THIS CLASS IS NOT THREADSAFE.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ben Walding</a>
* @version $Id: WerkzDependencyResolver.java,v 1.7 2003/08/19 04:25:39 dion
* Exp $
*/
public class WerkzDependencyResolver implements DependencyResolverInterface
{
private final List projects = new ArrayList();
private final List sortedGoals = new ArrayList();
private Goal doItAll = null;
private WerkzProject wproject = null;
/**
* @see org.apache.maven.jelly.tags.maven.DependencyResolverInterface#clear()
*/
public void clear()
{
projects.clear();
doItAll = null;
wproject = null;
}
/**
*
*/
public void setProjects( List projects )
{
clear();
this.projects.addAll( projects);
}
/**
* Retrieves the existing goal for a project (based on Id). If no goal
* exists, an exception is thrown.
*
* @param project
* @return ProjectGoal
*/
private ProjectGoal getExistingGoal( Project project )
{
String projectId = project.getId();
ProjectGoal goal = (ProjectGoal) wproject.getGoal( projectId);
if ( goal == null )
{
throw new NullPointerException( "No goal exists : " +
projectId );
}
else
{
return goal;
}
}
/**
* 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
*/
private ProjectGoal getOrCreateGoal( Project project, boolean sourceBuild )
{
ProjectGoal goal = (ProjectGoal) wproject.getGoal( project.getId());
if ( goal == null )
{
goal = new ProjectGoal( project, sourceBuild, wproject );
goal.setAction( new ListAddAction( goal, sortedGoals ));
wproject.addGoal( goal);
}
return goal;
}
/**
* Builds the projects / dependencies into an internal acyclic directed
* graph
*
* @throws Exception
*/
private void buildGraph() throws Exception
{
if ( doItAll != null )
{
return;
}
try
{
wproject = new WerkzProject();
doItAll = new DummyGoal( "DO_IT_ALL", wproject );
doItAll.setAction( new DummyAction() );
//Initialise all the true goals of the system
for ( Iterator iter = projects.iterator(); iter.hasNext(); )
{
Project project = (Project) iter.next();
Goal projectGoal = getOrCreateGoal( project, true);
doItAll.addPrecursor( projectGoal);
}
//Now add the dependencies
for ( Iterator iter = projects.iterator(); iter.hasNext(); )
{
Project project = (Project) iter.next();
Goal projectGoal = getExistingGoal( project);
Iterator depIter = project.getDependencies(
).iterator( );
while ( depIter.hasNext() )
{
Dependency dep = (Dependency) depIter.next();
Project depProject = new Project();
depProject.setArtifactId( dep.getArtifactId());
depProject.setGroupId( dep.getGroupId());
Goal depGoal = getOrCreateGoal( depProject,
false);
projectGoal.addPrecursor( depGoal);
}
}
}
catch ( Exception e )
{
doItAll = null;
wproject = new WerkzProject();
// We want to get the right exception
throw e;
}
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project)
*/
public List getSortedDependencies( Project project ) throws Exception
{
return getSortedDependencies( project, false);
}
/**
* Filters the given list of goals, and returns the associated projects
*
* 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 )
{
List result = new ArrayList();
Iterator iter = goals.iterator();
while ( iter.hasNext() )
{
ProjectGoal goal = (ProjectGoal) iter.next();
if ( (sourceBuild) || (!sourceBuild && goal.getSourceBuild()) )
{
result.add( goal.getProject());
}
}
return result;
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(org.apache.maven.project.Project,
* boolean)
*/
public List getSortedDependencies( Project project, boolean sourceBuild )
throws Exception
{
buildGraph();
sortedGoals.clear();
Session session = new Session();
ProjectGoal g = getExistingGoal( project);
g.attain( session);
return getProjects( sortedGoals, sourceBuild);
}
/**
* @see
org.apache.maven.jelly.tags.maven.DependencyResolverInterface#getSortedDependencies(boolean)
*/
public List getSortedDependencies( boolean sourceBuild ) throws Exception
{
buildGraph();
sortedGoals.clear();
Session session = new Session();
doItAll.attain( session);
return getProjects( sortedGoals, sourceBuild);
}
}
/**
* Simple action that adds the goal to a list when it is invoked
*/
class ListAddAction implements Action
{
private final List list;
private final Goal goal;
public ListAddAction( Goal goal, List list )
{
this.list = list;
this.goal = goal;
}
public boolean requiresAction()
{
return true;
}
public void performAction( Session session ) throws Exception
{
list.add( goal);
}
public void performAction() throws Exception
{
list.add( goal);
}
}
/**
* "Do nothing" action
*/
class DummyAction implements Action
{
public boolean requiresAction()
{
return false;
}
public void performAction( Session session ) throws Exception
{
}
public void performAction() throws Exception
{
}
}
/**
* Overrides Goal to add some extra project information
*/
class ProjectGoal extends Goal
{
private final Project project;
private final boolean sourceBuild;
public ProjectGoal( Project project, boolean sourceBuild,
WerkzProject wproject )
{
super( project.getId(), wproject );
this.project = project;
this.sourceBuild = sourceBuild;
}
public boolean getSourceBuild()
{
return sourceBuild;
}
public Project getProject()
{
return project;
}
}
class DummyGoal extends Goal
{
protected DummyGoal( String name, WerkzProject wproject )
{
super( name, wproject );
}
}
1.1
maven-components/maven-core/src/java/org/apache/maven/jelly/tags/maven/DependencyResolverInterface.java
Index: DependencyResolverInterface.java
===================================================================
package org.apache.maven.jelly.tags.maven;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.maven.project.Project;
import java.util.List;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Ben Walding</a>
* @version $Id: DependencyResolverInterface.java,v 1.1 2004/01/11 15:24:30 bwalding
Exp $
*/
public interface DependencyResolverInterface
{
/**
* Clear the project list and set the graph built flag to false.
*/
void clear();
/**
* Set a list of projects to process.
*
* @param projects List of 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.
*/
List getSortedDependencies(Project project) throws Exception;
/**
* Get the list of projects in dependency sorted order.
*
* @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.
*/
List getSortedDependencies(Project project, boolean sourceBuild) throws
Exception;
/**
* 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.
*/
List getSortedDependencies(boolean sourceBuild) throws Exception;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]