o started building up the code that we will use for the session lifecycle

-> bascially the mechanism is the same as the one we use for the goal
     execution lifecycle

  This first cut is so John can see as we're discussing the session stuff
  at the moment and I need to get this working in order to push all notions
  of artifact handling out of MavenProject.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162969 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2004-08-12 22:52:55 +00:00
parent e232e07440
commit 097c8f7623
12 changed files with 394 additions and 251 deletions

View File

@ -19,6 +19,7 @@ package org.apache.maven;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.MavenLifecycleManager;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
@ -91,30 +92,20 @@ public class DefaultMaven
ExecutionResponse response = new ExecutionResponse();
MavenSession session = new MavenSession( container,
pluginManager,
project,
getLocalRepository() );
for ( Iterator iterator = goals.iterator(); iterator.hasNext(); )
{
String goal = (String) iterator.next();
/*
//!! This needs to be thrown later because we may need to download the plugin first
if ( !getMojoDescriptors().containsKey( goal ) )
{
throw new GoalNotFoundException( goal );
}
*/
MavenGoalExecutionContext context;
try
{
//!! we may not know anything about the plugin at this point.
context = new MavenGoalExecutionContext( container,
project,
getMojoDescriptor( goal ),
getLocalRepository() );
context = new MavenGoalExecutionContext( session, getMojoDescriptor( goal ) );
context.setGoalName( goal );
@ -205,7 +196,7 @@ public class DefaultMaven
Runtime r = Runtime.getRuntime();
getLogger().info( "Final Memory: " + ((r.totalMemory() - r.freeMemory()) / mb) + "M/" + (r.totalMemory() / mb) + "M");
getLogger().info( "Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/" + ( r.totalMemory() / mb ) + "M" );
}

View File

@ -2,15 +2,12 @@ package org.apache.maven.lifecycle;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.decoration.GoalDecoratorBindings;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.plugin.FailureResponse;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositoryUtils;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -20,100 +17,75 @@ import java.util.Set;
*/
public class MavenGoalExecutionContext
{
private MavenSession session;
private String failedGoal;
private FailureResponse failureResponse;
private PlexusContainer container;
private MavenProject project;
private MojoDescriptor mojoDescriptor;
private List resolvedGoals;
private PluginManager pluginManager;
private Set pluginDependencies;
private GoalDecoratorBindings goalDecoratorBindings;
private ArtifactRepository localRepository;
private Set remoteRepositories;
private String goalName;
public MavenGoalExecutionContext( PlexusContainer container,
MavenProject project,
MojoDescriptor goal,
ArtifactRepository localRepository )
throws Exception
public MavenGoalExecutionContext( MavenSession session, MojoDescriptor goal )
{
this.container = container;
this.project = project;
this.session = session;
this.mojoDescriptor = goal;
}
this.localRepository = localRepository;
pluginManager = (PluginManager) lookup( PluginManager.ROLE );
pluginDependencies = new HashSet();
public MavenSession getSession()
{
return session;
}
// ----------------------------------------------------------------------
// Provide an easy way to lookup plexus components
// Delegation to the session
// ----------------------------------------------------------------------
public MavenProject getProject()
{
return session.getProject();
}
public ArtifactRepository getLocalRepository()
{
return session.getLocalRepository();
}
public Set getRemoteRepositories()
{
return session.getRemoteRepositories();
}
public Object lookup( String role )
throws ComponentLookupException
{
return container.lookup( role );
return session.lookup( role );
}
public Object lookup( String role, String roleHint )
public Object lookup( String role, String hint )
throws ComponentLookupException
{
return container.lookup( role, roleHint );
return session.lookup( role, hint );
}
public void release( Object component )
{
if ( component != null )
{
try
{
container.release( component );
}
catch ( Exception e )
{
//@todo what to do here?
}
}
session.release( component );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public boolean requiresDependencyResolution()
{
return mojoDescriptor.requiresDependencyResolution();
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public PlexusContainer getContainer()
{
return container;
}
public MavenProject getProject()
{
return project;
}
public MojoDescriptor getMojoDescriptor()
{
return mojoDescriptor;
@ -124,9 +96,6 @@ public class MavenGoalExecutionContext
this.mojoDescriptor = mojoDescriptor;
}
// ----------------------------------------------------------------------
// Resolved MojoDescriptors
// ----------------------------------------------------------------------
public List getResolvedGoals()
{
return resolvedGoals;
@ -137,12 +106,9 @@ public class MavenGoalExecutionContext
this.resolvedGoals = resolvedGoals;
}
// ----------------------------------------------------------------------
// Delegation to the plugin manager
// ----------------------------------------------------------------------
public MojoDescriptor getMojoDescriptor( String mojoDescriptorName )
{
return pluginManager.getMojoDescriptor( mojoDescriptorName );
return session.getPluginManager().getMojoDescriptor( mojoDescriptorName );
}
public String getPluginId( MojoDescriptor mojoDescriptor )
@ -150,9 +116,6 @@ public class MavenGoalExecutionContext
return mojoDescriptor.getId();
}
// ----------------------------------------------------------------------
// Execution failure
// ----------------------------------------------------------------------
public void setExecutionFailure( String failedGoal, FailureResponse response )
{
this.failedGoal = failedGoal;
@ -185,16 +148,6 @@ public class MavenGoalExecutionContext
this.failureResponse = failureResponse;
}
public Set getPluginDependencies()
{
return pluginDependencies;
}
public void setPluginDependencies( Set pluginDependencies )
{
this.pluginDependencies = pluginDependencies;
}
public GoalDecoratorBindings getGoalDecoratorBindings()
{
return goalDecoratorBindings;
@ -205,25 +158,6 @@ public class MavenGoalExecutionContext
this.goalDecoratorBindings = goalDecoratorBindings;
}
// ----------------------------------------------------------------------
// Local repository
// ----------------------------------------------------------------------
public ArtifactRepository getLocalRepository()
{
return localRepository;
}
public Set getRemoteRepositories()
{
if ( remoteRepositories == null )
{
remoteRepositories = RepositoryUtils.mavenToWagon( project.getRepositories() );
}
return remoteRepositories;
}
public String getGoalName()
{
return goalName;

View File

@ -45,14 +45,15 @@ public class GoalResolutionPhase extends AbstractMavenLifecyclePhase
try
{
pluginManager = (PluginManager) context.getContainer().lookup( PluginManager.ROLE );
pluginManager = (PluginManager) context.lookup( PluginManager.ROLE );
// First, start by retrieving the currently-requested goal.
MojoDescriptor goalDescriptor = context.getMojoDescriptor();
if(goalDescriptor == null) {
throw new GoalNotFoundException(context.getGoalName());
if ( goalDescriptor == null )
{
throw new GoalNotFoundException( context.getGoalName() );
}
String goal = goalDescriptor.getId();
List resolvedGoals = resolveTopLevel( goal, new HashSet(), new LinkedList(), context, pluginManager );

View File

@ -0,0 +1,31 @@
package org.apache.maven.lifecycle.session;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.codehaus.plexus.logging.AbstractLogEnabled;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public abstract class AbstractMavenSessionPhase
extends AbstractLogEnabled
implements MavenSessionPhase
{
public abstract void execute( MavenSession context )
throws Exception;
}

View File

@ -0,0 +1,59 @@
package org.apache.maven.lifecycle.session;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.apache.maven.lifecycle.MavenLifecycleManager;
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.MavenLifecyclePhase;
import java.util.Iterator;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class DefaultMavenSessionPhaseManager
extends AbstractLogEnabled
implements MavenLifecycleManager
{
private List lifecyclePhases;
public List getLifecyclePhases()
{
return lifecyclePhases;
}
public void execute( MavenGoalExecutionContext context )
throws Exception
{
for ( Iterator iterator = lifecyclePhases.iterator(); iterator.hasNext(); )
{
MavenLifecyclePhase phase = (MavenLifecyclePhase) iterator.next();
phase.enableLogging( getLogger() );
phase.execute( context );
if ( context.isExecutionFailure() )
{
break;
}
}
}
}

View File

@ -0,0 +1,118 @@
package org.apache.maven.lifecycle.session;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositoryUtils;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.Set;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenSession
{
private PlexusContainer container;
private MavenProject project;
private ArtifactRepository localRepository;
private PluginManager pluginManager;
private Set remoteRepositories;
public MavenSession( PlexusContainer container,
PluginManager pluginManager,
MavenProject project,
ArtifactRepository localRepository )
{
this.container = container;
this.pluginManager = pluginManager;
this.project = project;
this.localRepository = localRepository;
}
public PlexusContainer getContainer()
{
return container;
}
public PluginManager getPluginManager()
{
return pluginManager;
}
public MavenProject getProject()
{
return project;
}
public ArtifactRepository getLocalRepository()
{
return localRepository;
}
public Set getRemoteRepositories()
{
if ( remoteRepositories == null )
{
remoteRepositories = RepositoryUtils.mavenToWagon( project.getRepositories() );
}
return remoteRepositories;
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public Object lookup( String role )
throws ComponentLookupException
{
return container.lookup( role );
}
public Object lookup( String role, String roleHint )
throws ComponentLookupException
{
return container.lookup( role, roleHint );
}
public void release( Object component )
{
if ( component != null )
{
try
{
container.release( component );
}
catch ( Exception e )
{
//@todo what to do here?
}
}
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven;
package org.apache.maven.lifecycle.session;
/*
* Copyright 2001-2004 The Apache Software Foundation.
@ -16,19 +16,18 @@ package org.apache.maven;
* limitations under the License.
*/
import org.codehaus.plexus.logging.Logger;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id$
*/
public class MavenTest
extends MavenTestCase
public interface MavenSessionPhase
{
public void testMaven()
throws Exception
{
Maven maven = (Maven) lookup( Maven.ROLE );
String ROLE = MavenSessionPhase.class.getName();
assertNotNull( maven );
}
}
void execute( MavenSession context )
throws Exception;
void enableLogging( Logger logger );
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.lifecycle.phase;
package org.apache.maven.lifecycle.session;
/*
* Copyright 2001-2004 The Apache Software Foundation.
@ -16,18 +16,21 @@ package org.apache.maven.lifecycle.phase;
* limitations under the License.
*/
import org.apache.maven.lifecycle.AbstractMavenLifecyclePhase;
import org.apache.maven.lifecycle.MavenLifecycleManager;
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class InheritanceAssemblyPhase
extends AbstractMavenLifecyclePhase
public interface MavenSessionPhaseManager
{
public void execute( MavenGoalExecutionContext context )
throws Exception
{
}
String ROLE = MavenSessionPhaseManager.class.getName();
void execute( MavenGoalExecutionContext context )
throws Exception;
List getLifecyclePhases();
}

View File

@ -16,6 +16,13 @@ package org.apache.maven;
* limitations under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.plexus.PlexusTestCase;
@ -24,20 +31,23 @@ import java.io.File;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id$
*/
public class MavenTestCase
extends PlexusTestCase
{
{
protected PluginManager pluginManager;
protected MavenProjectBuilder projectBuilder;
protected void setUp()
throws Exception
{
super.setUp();
File pluginsDirectory = new File( getBasedir(), "target/maven.home/plugins" );
pluginManager = (PluginManager) lookup( PluginManager.ROLE );
pluginsDirectory.mkdirs();
projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
}
protected void customizeContext()
@ -53,4 +63,60 @@ public class MavenTestCase
getContainer().addContextValue( "maven.home.local", new File( getBasedir(), "target/maven.home.local" ).getPath() );
}
protected MavenGoalExecutionContext createGoalExecutionContext()
throws Exception
{
return createGoalExecutionContext( null, null );
}
protected MavenGoalExecutionContext createGoalExecutionContext( File pom )
throws Exception
{
return createGoalExecutionContext( pom, null );
}
protected MavenGoalExecutionContext createGoalExecutionContext( String goal )
throws Exception
{
return createGoalExecutionContext( null, goal );
}
protected MavenGoalExecutionContext createGoalExecutionContext( File pom, String goal )
throws Exception
{
ArtifactRepository localRepository = new ArtifactRepository( "local", "file://" );
MavenProject project;
if ( pom != null )
{
project = projectBuilder.build( pom, localRepository );
}
else
{
File f = new File( basedir, "target/test-classes/pom.xml" );
project = projectBuilder.build( f, localRepository );
}
project.setProperty( "foo", "bar" );
MavenSession session = new MavenSession( getContainer(), pluginManager, project, localRepository );
MojoDescriptor descriptor;
if ( goal != null )
{
descriptor = pluginManager.getMojoDescriptor( goal );
}
else
{
descriptor = new MojoDescriptor();
}
MavenGoalExecutionContext context = new MavenGoalExecutionContext( session, descriptor );
return context;
}
}

View File

@ -17,28 +17,20 @@ package org.apache.maven.lifecycle.phase;
* limitations under the License.
*/
import junit.framework.TestCase;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.MavenTestCase;
import org.apache.maven.decoration.GoalDecoratorBindings;
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.embed.Embedder;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* @author jdcasey
*/
public class GoalDecorationPhaseTest extends TestCase
public class GoalDecorationPhaseTest
extends MavenTestCase
{
private static final String BASEDIR = "./decoration-unitTest-project";
private static final String DECORATOR_SCRIPT =
"<decorators defaultGoal=\"jar:jar\">" +
"<preGoal name=\"compiler:compile\" attain=\"compiler:init-fs\"/>" +
@ -48,33 +40,19 @@ public class GoalDecorationPhaseTest extends TestCase
"</decorators>";
protected void setUp()
throws Exception
{
File basedir = new File( BASEDIR );
if ( !basedir.exists() )
{
basedir.mkdir();
}
super.setUp();
File mavenScriptFile = new File( basedir, GoalDecorationPhase.MAVEN_SCRIPT );
try
{
BufferedWriter out = new BufferedWriter( new FileWriter( mavenScriptFile ) );
out.write( DECORATOR_SCRIPT );
out.flush();
out.close();
}
catch ( IOException e )
{
e.printStackTrace();
}
}
File mavenScriptFile = new File( basedir, "target/test-classes/" + GoalDecorationPhase.MAVEN_SCRIPT );
protected void tearDown()
{
File basedir = new File( BASEDIR );
File mavenScript = new File( basedir, GoalDecorationPhase.MAVEN_SCRIPT );
mavenScript.delete();
basedir.delete();
BufferedWriter out = new BufferedWriter( new FileWriter( mavenScriptFile ) );
out.write( DECORATOR_SCRIPT );
out.flush();
out.close();
}
public void testShouldConstructWithNoArgs()
@ -84,21 +62,7 @@ public class GoalDecorationPhaseTest extends TestCase
public void testShouldParseDecoratorsFromFile() throws Exception
{
MavenProject project = new MavenProject( new Model() );
project.setFile( new File( new File( BASEDIR ), "project.xml" ) );
Embedder embedder = new Embedder();
embedder.start();
MojoDescriptor descriptor = new MojoDescriptor();
ArtifactRepository localRepository = new ArtifactRepository();
MavenGoalExecutionContext context = new MavenGoalExecutionContext( embedder.getContainer(),
project,
descriptor,
localRepository );
MavenGoalExecutionContext context = createGoalExecutionContext();
GoalDecorationPhase phase = new GoalDecorationPhase();

View File

@ -1,18 +1,11 @@
/* Created on Jul 14, 2004 */
package org.apache.maven.lifecycle.phase;
import junit.framework.TestCase;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.decoration.DefaultGoalDecorator;
import org.apache.maven.decoration.GoalDecoratorBindings;
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.embed.Embedder;
import org.apache.maven.MavenTestCase;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -22,7 +15,8 @@ import java.util.TreeMap;
/**
* @author jdcasey
*/
public class GoalResolutionPhaseTest extends TestCase
public class GoalResolutionPhaseTest
extends MavenTestCase
{
/*
<!-- Test main with preGoal and postGoal -->
@ -43,25 +37,25 @@ public class GoalResolutionPhaseTest extends TestCase
</mojo>
<!-- End of test -->
*/
public void testT1_ShouldFind_PreGoal_MainGoal_PostGoal( )
public void testT1_ShouldFind_PreGoal_MainGoal_PostGoal()
throws Exception
{
String mainGoal = "t1:main";
String preGoal = "t1:preGoal";
String postGoal = "t1:postGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
Map messages = new TreeMap( );
Map messages = new TreeMap();
messages.put( mainGoal, "Main goal is missing." );
messages.put( preGoal, "preGoal is missing" );
messages.put( postGoal, "postGoal is missing" );
List order = new ArrayList( );
List order = new ArrayList();
order.add( preGoal );
order.add( mainGoal );
@ -87,20 +81,20 @@ public class GoalResolutionPhaseTest extends TestCase
</mojo>
<!-- End of test -->
*/
public void testT2_ShouldFind_Prereq_MainGoal( )
public void testT2_ShouldFind_Prereq_MainGoal()
throws Exception
{
String mainGoal = "t2:main";
String prereq = "t2:prereq";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
Map messages = new TreeMap( );
Map messages = new TreeMap();
messages.put( mainGoal, "Main goal is missing." );
messages.put( prereq, "prereq is missing" );
List order = new ArrayList( );
List order = new ArrayList();
order.add( prereq );
order.add( mainGoal );
@ -135,7 +129,7 @@ public class GoalResolutionPhaseTest extends TestCase
</mojo>
<!-- End of test -->
*/
public void testT3_ShouldFind_PreGoal_Prereq_MainGoal_PostGoal( )
public void testT3_ShouldFind_PreGoal_Prereq_MainGoal_PostGoal()
throws Exception
{
String mainGoal = "t3:main";
@ -143,19 +137,19 @@ public class GoalResolutionPhaseTest extends TestCase
String preGoal = "t3:preGoal";
String postGoal = "t3:postGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
Map messages = new TreeMap( );
Map messages = new TreeMap();
messages.put( mainGoal, "Main goal is missing." );
messages.put( prereq, "prereq is missing" );
messages.put( preGoal, "preGoal is missing" );
messages.put( postGoal, "postGoal is missing" );
List order = new ArrayList( );
List order = new ArrayList();
order.add( preGoal );
order.add( prereq );
@ -192,7 +186,7 @@ public class GoalResolutionPhaseTest extends TestCase
</mojo>
<!-- End of test -->
*/
public void testT4_ShouldFind_PreGoal_Prereq_PostGoal_MainGoal( )
public void testT4_ShouldFind_PreGoal_Prereq_PostGoal_MainGoal()
throws Exception
{
String mainGoal = "t4:main";
@ -200,19 +194,19 @@ public class GoalResolutionPhaseTest extends TestCase
String preGoal = "t4:prereq-preGoal";
String postGoal = "t4:prereq-postGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
bindings.addPreGoal( new DefaultGoalDecorator( prereq, preGoal ) );
bindings.addPostGoal( new DefaultGoalDecorator( prereq, postGoal ) );
Map messages = new TreeMap( );
Map messages = new TreeMap();
messages.put( mainGoal, "Main goal is missing." );
messages.put( prereq, "prereq is missing" );
messages.put( preGoal, "preGoal is missing" );
messages.put( postGoal, "postGoal is missing" );
List order = new ArrayList( );
List order = new ArrayList();
order.add( preGoal );
order.add( prereq );
@ -247,24 +241,24 @@ public class GoalResolutionPhaseTest extends TestCase
</mojo>
<!-- End of test -->
*/
public void testT5_ShouldFind_Prereq_PreGoal_MainGoal( )
public void testT5_ShouldFind_Prereq_PreGoal_MainGoal()
throws Exception
{
String mainGoal = "t5:main";
String prereq = "t5:prereq";
String preGoal = "t5:preGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
Map messages = new TreeMap( );
Map messages = new TreeMap();
messages.put( mainGoal, "Main goal is missing." );
messages.put( prereq, "prereq is missing" );
messages.put( preGoal, "preGoal is missing" );
List order = new ArrayList( );
List order = new ArrayList();
order.add( prereq );
order.add( preGoal );
@ -274,51 +268,34 @@ public class GoalResolutionPhaseTest extends TestCase
}
private void runTest( String mainGoal, GoalDecoratorBindings bindings,
List expectedOrder, Map messages )
List expectedOrder, Map messages )
throws Exception
{
MavenProject project = new MavenProject( new Model( ) );
project.setFile( new File( new File( "./resolution-test" ),
"project.xml" ) );
Embedder embedder = new Embedder( );
embedder.start( );
PluginManager pluginManager = ( PluginManager ) embedder.lookup( PluginManager.ROLE );
MojoDescriptor descriptor = pluginManager.getMojoDescriptor( mainGoal );
ArtifactRepository localRepository = new ArtifactRepository();
MavenGoalExecutionContext context = new MavenGoalExecutionContext( embedder.getContainer(),
project,
descriptor,
localRepository );
MavenGoalExecutionContext context = createGoalExecutionContext( mainGoal );
context.setGoalDecoratorBindings( bindings );
GoalResolutionPhase phase = new GoalResolutionPhase( );
GoalResolutionPhase phase = new GoalResolutionPhase();
phase.execute( context );
List goals = context.getResolvedGoals( );
List goals = context.getResolvedGoals();
System.out.println( "Resolved goals: " + goals );
assertNotNull( goals );
assertEquals( expectedOrder.size( ), goals.size( ) );
assertEquals( expectedOrder.size(), goals.size() );
int index = 0;
for ( Iterator it = expectedOrder.iterator( ); it.hasNext( ); )
for ( Iterator it = expectedOrder.iterator(); it.hasNext(); )
{
String goal = ( String ) it.next( );
String failureMessage = ( String ) messages.get( goal );
String goal = (String) it.next();
String resolvedGoal = ( String ) goals.get( index++ );
String failureMessage = (String) messages.get( goal );
String resolvedGoal = (String) goals.get( index++ );
assertEquals( failureMessage, goal, resolvedGoal );
}

View File

@ -34,7 +34,7 @@ public class OgnlProjectValueExtractorTest
project.setProperty( "foo", "bar" );
context = new MavenGoalExecutionContext( getContainer(), project, null, new ArtifactRepository( "foo", "http://bar" ) );
context = createGoalExecutionContext();
}
public void testPropertyValueExtraction()
@ -56,7 +56,7 @@ public class OgnlProjectValueExtractorTest
{
Object value = OgnlProjectValueExtractor.evaluate( "#project.build.directory/classes", context );
String expected = new File( basedir, "src/test/resources/target/classes" ).getCanonicalPath();
String expected = new File( basedir, "target/test-classes/target/classes" ).getCanonicalPath();
String actual = new File( value.toString() ).getCanonicalPath();
@ -78,6 +78,6 @@ public class OgnlProjectValueExtractorTest
{
Object value = OgnlProjectValueExtractor.evaluate( "#localRepository", context );
assertEquals( "foo", ((ArtifactRepository)value).getId() );
assertEquals( "local", ((ArtifactRepository)value).getId() );
}
}