mirror of https://github.com/apache/maven.git
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:
parent
e232e07440
commit
097c8f7623
|
@ -19,6 +19,7 @@ package org.apache.maven;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
|
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
|
||||||
import org.apache.maven.lifecycle.MavenLifecycleManager;
|
import org.apache.maven.lifecycle.MavenLifecycleManager;
|
||||||
|
import org.apache.maven.lifecycle.session.MavenSession;
|
||||||
import org.apache.maven.plugin.PluginManager;
|
import org.apache.maven.plugin.PluginManager;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
@ -91,30 +92,20 @@ public class DefaultMaven
|
||||||
|
|
||||||
ExecutionResponse response = new ExecutionResponse();
|
ExecutionResponse response = new ExecutionResponse();
|
||||||
|
|
||||||
|
MavenSession session = new MavenSession( container,
|
||||||
|
pluginManager,
|
||||||
|
project,
|
||||||
|
getLocalRepository() );
|
||||||
|
|
||||||
for ( Iterator iterator = goals.iterator(); iterator.hasNext(); )
|
for ( Iterator iterator = goals.iterator(); iterator.hasNext(); )
|
||||||
{
|
{
|
||||||
String goal = (String) iterator.next();
|
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;
|
MavenGoalExecutionContext context;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//!! we may not know anything about the plugin at this point.
|
context = new MavenGoalExecutionContext( session, getMojoDescriptor( goal ) );
|
||||||
|
|
||||||
context = new MavenGoalExecutionContext( container,
|
|
||||||
project,
|
|
||||||
getMojoDescriptor( goal ),
|
|
||||||
getLocalRepository() );
|
|
||||||
|
|
||||||
context.setGoalName( goal );
|
context.setGoalName( goal );
|
||||||
|
|
||||||
|
@ -205,7 +196,7 @@ public class DefaultMaven
|
||||||
|
|
||||||
Runtime r = Runtime.getRuntime();
|
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" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,12 @@ package org.apache.maven.lifecycle;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.decoration.GoalDecoratorBindings;
|
import org.apache.maven.decoration.GoalDecoratorBindings;
|
||||||
|
import org.apache.maven.lifecycle.session.MavenSession;
|
||||||
import org.apache.maven.plugin.FailureResponse;
|
import org.apache.maven.plugin.FailureResponse;
|
||||||
import org.apache.maven.plugin.PluginManager;
|
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.project.MavenProject;
|
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 org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -20,100 +17,75 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class MavenGoalExecutionContext
|
public class MavenGoalExecutionContext
|
||||||
{
|
{
|
||||||
|
private MavenSession session;
|
||||||
|
|
||||||
private String failedGoal;
|
private String failedGoal;
|
||||||
|
|
||||||
private FailureResponse failureResponse;
|
private FailureResponse failureResponse;
|
||||||
|
|
||||||
private PlexusContainer container;
|
|
||||||
|
|
||||||
private MavenProject project;
|
|
||||||
|
|
||||||
private MojoDescriptor mojoDescriptor;
|
private MojoDescriptor mojoDescriptor;
|
||||||
|
|
||||||
private List resolvedGoals;
|
private List resolvedGoals;
|
||||||
|
|
||||||
private PluginManager pluginManager;
|
|
||||||
|
|
||||||
private Set pluginDependencies;
|
|
||||||
|
|
||||||
private GoalDecoratorBindings goalDecoratorBindings;
|
private GoalDecoratorBindings goalDecoratorBindings;
|
||||||
|
|
||||||
private ArtifactRepository localRepository;
|
|
||||||
|
|
||||||
private Set remoteRepositories;
|
|
||||||
|
|
||||||
private String goalName;
|
private String goalName;
|
||||||
|
|
||||||
public MavenGoalExecutionContext( PlexusContainer container,
|
public MavenGoalExecutionContext( MavenSession session, MojoDescriptor goal )
|
||||||
MavenProject project,
|
|
||||||
MojoDescriptor goal,
|
|
||||||
ArtifactRepository localRepository )
|
|
||||||
throws Exception
|
|
||||||
{
|
{
|
||||||
this.container = container;
|
this.session = session;
|
||||||
|
|
||||||
this.project = project;
|
|
||||||
|
|
||||||
this.mojoDescriptor = goal;
|
this.mojoDescriptor = goal;
|
||||||
|
}
|
||||||
|
|
||||||
this.localRepository = localRepository;
|
public MavenSession getSession()
|
||||||
|
{
|
||||||
pluginManager = (PluginManager) lookup( PluginManager.ROLE );
|
return session;
|
||||||
|
|
||||||
pluginDependencies = new HashSet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// 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 )
|
public Object lookup( String role )
|
||||||
throws ComponentLookupException
|
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
|
throws ComponentLookupException
|
||||||
{
|
{
|
||||||
return container.lookup( role, roleHint );
|
return session.lookup( role, hint );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void release( Object component )
|
public void release( Object component )
|
||||||
{
|
{
|
||||||
if ( component != null )
|
session.release( component );
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
container.release( component );
|
|
||||||
}
|
|
||||||
catch ( Exception e )
|
|
||||||
{
|
|
||||||
//@todo what to do here?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
public boolean requiresDependencyResolution()
|
public boolean requiresDependencyResolution()
|
||||||
{
|
{
|
||||||
return mojoDescriptor.requiresDependencyResolution();
|
return mojoDescriptor.requiresDependencyResolution();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
public PlexusContainer getContainer()
|
|
||||||
{
|
|
||||||
return container;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MavenProject getProject()
|
|
||||||
{
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MojoDescriptor getMojoDescriptor()
|
public MojoDescriptor getMojoDescriptor()
|
||||||
{
|
{
|
||||||
return mojoDescriptor;
|
return mojoDescriptor;
|
||||||
|
@ -124,9 +96,6 @@ public class MavenGoalExecutionContext
|
||||||
this.mojoDescriptor = mojoDescriptor;
|
this.mojoDescriptor = mojoDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Resolved MojoDescriptors
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
public List getResolvedGoals()
|
public List getResolvedGoals()
|
||||||
{
|
{
|
||||||
return resolvedGoals;
|
return resolvedGoals;
|
||||||
|
@ -137,12 +106,9 @@ public class MavenGoalExecutionContext
|
||||||
this.resolvedGoals = resolvedGoals;
|
this.resolvedGoals = resolvedGoals;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Delegation to the plugin manager
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
public MojoDescriptor getMojoDescriptor( String mojoDescriptorName )
|
public MojoDescriptor getMojoDescriptor( String mojoDescriptorName )
|
||||||
{
|
{
|
||||||
return pluginManager.getMojoDescriptor( mojoDescriptorName );
|
return session.getPluginManager().getMojoDescriptor( mojoDescriptorName );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPluginId( MojoDescriptor mojoDescriptor )
|
public String getPluginId( MojoDescriptor mojoDescriptor )
|
||||||
|
@ -150,9 +116,6 @@ public class MavenGoalExecutionContext
|
||||||
return mojoDescriptor.getId();
|
return mojoDescriptor.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Execution failure
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
public void setExecutionFailure( String failedGoal, FailureResponse response )
|
public void setExecutionFailure( String failedGoal, FailureResponse response )
|
||||||
{
|
{
|
||||||
this.failedGoal = failedGoal;
|
this.failedGoal = failedGoal;
|
||||||
|
@ -185,16 +148,6 @@ public class MavenGoalExecutionContext
|
||||||
this.failureResponse = failureResponse;
|
this.failureResponse = failureResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set getPluginDependencies()
|
|
||||||
{
|
|
||||||
return pluginDependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPluginDependencies( Set pluginDependencies )
|
|
||||||
{
|
|
||||||
this.pluginDependencies = pluginDependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GoalDecoratorBindings getGoalDecoratorBindings()
|
public GoalDecoratorBindings getGoalDecoratorBindings()
|
||||||
{
|
{
|
||||||
return goalDecoratorBindings;
|
return goalDecoratorBindings;
|
||||||
|
@ -205,25 +158,6 @@ public class MavenGoalExecutionContext
|
||||||
this.goalDecoratorBindings = goalDecoratorBindings;
|
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()
|
public String getGoalName()
|
||||||
{
|
{
|
||||||
return goalName;
|
return goalName;
|
||||||
|
|
|
@ -45,12 +45,13 @@ public class GoalResolutionPhase extends AbstractMavenLifecyclePhase
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pluginManager = (PluginManager) context.getContainer().lookup( PluginManager.ROLE );
|
pluginManager = (PluginManager) context.lookup( PluginManager.ROLE );
|
||||||
|
|
||||||
// First, start by retrieving the currently-requested goal.
|
// First, start by retrieving the currently-requested goal.
|
||||||
MojoDescriptor goalDescriptor = context.getMojoDescriptor();
|
MojoDescriptor goalDescriptor = context.getMojoDescriptor();
|
||||||
if(goalDescriptor == null) {
|
if ( goalDescriptor == null )
|
||||||
throw new GoalNotFoundException(context.getGoalName());
|
{
|
||||||
|
throw new GoalNotFoundException( context.getGoalName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
String goal = goalDescriptor.getId();
|
String goal = goalDescriptor.getId();
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.apache.maven;
|
package org.apache.maven.lifecycle.session;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2004 The Apache Software Foundation.
|
* Copyright 2001-2004 The Apache Software Foundation.
|
||||||
|
@ -16,19 +16,18 @@ package org.apache.maven;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||||
*
|
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class MavenTest
|
public interface MavenSessionPhase
|
||||||
extends MavenTestCase
|
|
||||||
{
|
{
|
||||||
public void testMaven()
|
String ROLE = MavenSessionPhase.class.getName();
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Maven maven = (Maven) lookup( Maven.ROLE );
|
|
||||||
|
|
||||||
assertNotNull( maven );
|
void execute( MavenSession context )
|
||||||
}
|
throws Exception;
|
||||||
|
|
||||||
|
void enableLogging( Logger logger );
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.apache.maven.lifecycle.phase;
|
package org.apache.maven.lifecycle.session;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2004 The Apache Software Foundation.
|
* Copyright 2001-2004 The Apache Software Foundation.
|
||||||
|
@ -16,18 +16,21 @@ package org.apache.maven.lifecycle.phase;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.lifecycle.AbstractMavenLifecyclePhase;
|
import org.apache.maven.lifecycle.MavenLifecycleManager;
|
||||||
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
|
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class InheritanceAssemblyPhase
|
public interface MavenSessionPhaseManager
|
||||||
extends AbstractMavenLifecyclePhase
|
|
||||||
{
|
{
|
||||||
public void execute( MavenGoalExecutionContext context )
|
String ROLE = MavenSessionPhaseManager.class.getName();
|
||||||
throws Exception
|
|
||||||
{
|
void execute( MavenGoalExecutionContext context )
|
||||||
}
|
throws Exception;
|
||||||
|
|
||||||
|
List getLifecyclePhases();
|
||||||
}
|
}
|
|
@ -16,6 +16,13 @@ package org.apache.maven;
|
||||||
* limitations under the License.
|
* 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.ClassRealm;
|
||||||
import org.codehaus.classworlds.ClassWorld;
|
import org.codehaus.classworlds.ClassWorld;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
@ -24,20 +31,23 @@ import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||||
*
|
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class MavenTestCase
|
public class MavenTestCase
|
||||||
extends PlexusTestCase
|
extends PlexusTestCase
|
||||||
{
|
{
|
||||||
|
protected PluginManager pluginManager;
|
||||||
|
|
||||||
|
protected MavenProjectBuilder projectBuilder;
|
||||||
|
|
||||||
protected void setUp()
|
protected void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
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()
|
protected void customizeContext()
|
||||||
|
@ -53,4 +63,60 @@ public class MavenTestCase
|
||||||
|
|
||||||
getContainer().addContextValue( "maven.home.local", new File( getBasedir(), "target/maven.home.local" ).getPath() );
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,28 +17,20 @@ package org.apache.maven.lifecycle.phase;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.apache.maven.MavenTestCase;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.decoration.GoalDecoratorBindings;
|
import org.apache.maven.decoration.GoalDecoratorBindings;
|
||||||
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
|
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.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jdcasey
|
* @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 =
|
private static final String DECORATOR_SCRIPT =
|
||||||
"<decorators defaultGoal=\"jar:jar\">" +
|
"<decorators defaultGoal=\"jar:jar\">" +
|
||||||
"<preGoal name=\"compiler:compile\" attain=\"compiler:init-fs\"/>" +
|
"<preGoal name=\"compiler:compile\" attain=\"compiler:init-fs\"/>" +
|
||||||
|
@ -48,33 +40,19 @@ public class GoalDecorationPhaseTest extends TestCase
|
||||||
"</decorators>";
|
"</decorators>";
|
||||||
|
|
||||||
protected void setUp()
|
protected void setUp()
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
File basedir = new File( BASEDIR );
|
super.setUp();
|
||||||
if ( !basedir.exists() )
|
|
||||||
{
|
File mavenScriptFile = new File( basedir, "target/test-classes/" + GoalDecorationPhase.MAVEN_SCRIPT );
|
||||||
basedir.mkdir();
|
|
||||||
}
|
|
||||||
|
|
||||||
File mavenScriptFile = new File( basedir, GoalDecorationPhase.MAVEN_SCRIPT );
|
|
||||||
try
|
|
||||||
{
|
|
||||||
BufferedWriter out = new BufferedWriter( new FileWriter( mavenScriptFile ) );
|
BufferedWriter out = new BufferedWriter( new FileWriter( mavenScriptFile ) );
|
||||||
out.write( DECORATOR_SCRIPT );
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void tearDown()
|
out.write( DECORATOR_SCRIPT );
|
||||||
{
|
|
||||||
File basedir = new File( BASEDIR );
|
out.flush();
|
||||||
File mavenScript = new File( basedir, GoalDecorationPhase.MAVEN_SCRIPT );
|
|
||||||
mavenScript.delete();
|
out.close();
|
||||||
basedir.delete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShouldConstructWithNoArgs()
|
public void testShouldConstructWithNoArgs()
|
||||||
|
@ -84,21 +62,7 @@ public class GoalDecorationPhaseTest extends TestCase
|
||||||
|
|
||||||
public void testShouldParseDecoratorsFromFile() throws Exception
|
public void testShouldParseDecoratorsFromFile() throws Exception
|
||||||
{
|
{
|
||||||
MavenProject project = new MavenProject( new Model() );
|
MavenGoalExecutionContext context = createGoalExecutionContext();
|
||||||
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 );
|
|
||||||
|
|
||||||
GoalDecorationPhase phase = new GoalDecorationPhase();
|
GoalDecorationPhase phase = new GoalDecorationPhase();
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
/* Created on Jul 14, 2004 */
|
/* Created on Jul 14, 2004 */
|
||||||
package org.apache.maven.lifecycle.phase;
|
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.DefaultGoalDecorator;
|
||||||
import org.apache.maven.decoration.GoalDecoratorBindings;
|
import org.apache.maven.decoration.GoalDecoratorBindings;
|
||||||
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
|
import org.apache.maven.lifecycle.MavenGoalExecutionContext;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.MavenTestCase;
|
||||||
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 java.io.File;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -22,7 +15,8 @@ import java.util.TreeMap;
|
||||||
/**
|
/**
|
||||||
* @author jdcasey
|
* @author jdcasey
|
||||||
*/
|
*/
|
||||||
public class GoalResolutionPhaseTest extends TestCase
|
public class GoalResolutionPhaseTest
|
||||||
|
extends MavenTestCase
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
<!-- Test main with preGoal and postGoal -->
|
<!-- Test main with preGoal and postGoal -->
|
||||||
|
@ -43,25 +37,25 @@ public class GoalResolutionPhaseTest extends TestCase
|
||||||
</mojo>
|
</mojo>
|
||||||
<!-- End of test -->
|
<!-- End of test -->
|
||||||
*/
|
*/
|
||||||
public void testT1_ShouldFind_PreGoal_MainGoal_PostGoal( )
|
public void testT1_ShouldFind_PreGoal_MainGoal_PostGoal()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
String mainGoal = "t1:main";
|
String mainGoal = "t1:main";
|
||||||
String preGoal = "t1:preGoal";
|
String preGoal = "t1:preGoal";
|
||||||
String postGoal = "t1:postGoal";
|
String postGoal = "t1:postGoal";
|
||||||
|
|
||||||
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
|
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
|
||||||
|
|
||||||
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
|
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
|
||||||
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
|
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
|
||||||
|
|
||||||
Map messages = new TreeMap( );
|
Map messages = new TreeMap();
|
||||||
|
|
||||||
messages.put( mainGoal, "Main goal is missing." );
|
messages.put( mainGoal, "Main goal is missing." );
|
||||||
messages.put( preGoal, "preGoal is missing" );
|
messages.put( preGoal, "preGoal is missing" );
|
||||||
messages.put( postGoal, "postGoal is missing" );
|
messages.put( postGoal, "postGoal is missing" );
|
||||||
|
|
||||||
List order = new ArrayList( );
|
List order = new ArrayList();
|
||||||
|
|
||||||
order.add( preGoal );
|
order.add( preGoal );
|
||||||
order.add( mainGoal );
|
order.add( mainGoal );
|
||||||
|
@ -87,20 +81,20 @@ public class GoalResolutionPhaseTest extends TestCase
|
||||||
</mojo>
|
</mojo>
|
||||||
<!-- End of test -->
|
<!-- End of test -->
|
||||||
*/
|
*/
|
||||||
public void testT2_ShouldFind_Prereq_MainGoal( )
|
public void testT2_ShouldFind_Prereq_MainGoal()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
String mainGoal = "t2:main";
|
String mainGoal = "t2:main";
|
||||||
String prereq = "t2:prereq";
|
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( mainGoal, "Main goal is missing." );
|
||||||
messages.put( prereq, "prereq is missing" );
|
messages.put( prereq, "prereq is missing" );
|
||||||
|
|
||||||
List order = new ArrayList( );
|
List order = new ArrayList();
|
||||||
|
|
||||||
order.add( prereq );
|
order.add( prereq );
|
||||||
order.add( mainGoal );
|
order.add( mainGoal );
|
||||||
|
@ -135,7 +129,7 @@ public class GoalResolutionPhaseTest extends TestCase
|
||||||
</mojo>
|
</mojo>
|
||||||
<!-- End of test -->
|
<!-- End of test -->
|
||||||
*/
|
*/
|
||||||
public void testT3_ShouldFind_PreGoal_Prereq_MainGoal_PostGoal( )
|
public void testT3_ShouldFind_PreGoal_Prereq_MainGoal_PostGoal()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
String mainGoal = "t3:main";
|
String mainGoal = "t3:main";
|
||||||
|
@ -143,19 +137,19 @@ public class GoalResolutionPhaseTest extends TestCase
|
||||||
String preGoal = "t3:preGoal";
|
String preGoal = "t3:preGoal";
|
||||||
String postGoal = "t3:postGoal";
|
String postGoal = "t3:postGoal";
|
||||||
|
|
||||||
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
|
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
|
||||||
|
|
||||||
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
|
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
|
||||||
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
|
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
|
||||||
|
|
||||||
Map messages = new TreeMap( );
|
Map messages = new TreeMap();
|
||||||
|
|
||||||
messages.put( mainGoal, "Main goal is missing." );
|
messages.put( mainGoal, "Main goal is missing." );
|
||||||
messages.put( prereq, "prereq is missing" );
|
messages.put( prereq, "prereq is missing" );
|
||||||
messages.put( preGoal, "preGoal is missing" );
|
messages.put( preGoal, "preGoal is missing" );
|
||||||
messages.put( postGoal, "postGoal is missing" );
|
messages.put( postGoal, "postGoal is missing" );
|
||||||
|
|
||||||
List order = new ArrayList( );
|
List order = new ArrayList();
|
||||||
|
|
||||||
order.add( preGoal );
|
order.add( preGoal );
|
||||||
order.add( prereq );
|
order.add( prereq );
|
||||||
|
@ -192,7 +186,7 @@ public class GoalResolutionPhaseTest extends TestCase
|
||||||
</mojo>
|
</mojo>
|
||||||
<!-- End of test -->
|
<!-- End of test -->
|
||||||
*/
|
*/
|
||||||
public void testT4_ShouldFind_PreGoal_Prereq_PostGoal_MainGoal( )
|
public void testT4_ShouldFind_PreGoal_Prereq_PostGoal_MainGoal()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
String mainGoal = "t4:main";
|
String mainGoal = "t4:main";
|
||||||
|
@ -200,19 +194,19 @@ public class GoalResolutionPhaseTest extends TestCase
|
||||||
String preGoal = "t4:prereq-preGoal";
|
String preGoal = "t4:prereq-preGoal";
|
||||||
String postGoal = "t4:prereq-postGoal";
|
String postGoal = "t4:prereq-postGoal";
|
||||||
|
|
||||||
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
|
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
|
||||||
|
|
||||||
bindings.addPreGoal( new DefaultGoalDecorator( prereq, preGoal ) );
|
bindings.addPreGoal( new DefaultGoalDecorator( prereq, preGoal ) );
|
||||||
bindings.addPostGoal( new DefaultGoalDecorator( prereq, postGoal ) );
|
bindings.addPostGoal( new DefaultGoalDecorator( prereq, postGoal ) );
|
||||||
|
|
||||||
Map messages = new TreeMap( );
|
Map messages = new TreeMap();
|
||||||
|
|
||||||
messages.put( mainGoal, "Main goal is missing." );
|
messages.put( mainGoal, "Main goal is missing." );
|
||||||
messages.put( prereq, "prereq is missing" );
|
messages.put( prereq, "prereq is missing" );
|
||||||
messages.put( preGoal, "preGoal is missing" );
|
messages.put( preGoal, "preGoal is missing" );
|
||||||
messages.put( postGoal, "postGoal is missing" );
|
messages.put( postGoal, "postGoal is missing" );
|
||||||
|
|
||||||
List order = new ArrayList( );
|
List order = new ArrayList();
|
||||||
|
|
||||||
order.add( preGoal );
|
order.add( preGoal );
|
||||||
order.add( prereq );
|
order.add( prereq );
|
||||||
|
@ -247,24 +241,24 @@ public class GoalResolutionPhaseTest extends TestCase
|
||||||
</mojo>
|
</mojo>
|
||||||
<!-- End of test -->
|
<!-- End of test -->
|
||||||
*/
|
*/
|
||||||
public void testT5_ShouldFind_Prereq_PreGoal_MainGoal( )
|
public void testT5_ShouldFind_Prereq_PreGoal_MainGoal()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
String mainGoal = "t5:main";
|
String mainGoal = "t5:main";
|
||||||
String prereq = "t5:prereq";
|
String prereq = "t5:prereq";
|
||||||
String preGoal = "t5:preGoal";
|
String preGoal = "t5:preGoal";
|
||||||
|
|
||||||
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
|
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
|
||||||
|
|
||||||
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
|
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
|
||||||
|
|
||||||
Map messages = new TreeMap( );
|
Map messages = new TreeMap();
|
||||||
|
|
||||||
messages.put( mainGoal, "Main goal is missing." );
|
messages.put( mainGoal, "Main goal is missing." );
|
||||||
messages.put( prereq, "prereq is missing" );
|
messages.put( prereq, "prereq is missing" );
|
||||||
messages.put( preGoal, "preGoal is missing" );
|
messages.put( preGoal, "preGoal is missing" );
|
||||||
|
|
||||||
List order = new ArrayList( );
|
List order = new ArrayList();
|
||||||
|
|
||||||
order.add( prereq );
|
order.add( prereq );
|
||||||
order.add( preGoal );
|
order.add( preGoal );
|
||||||
|
@ -277,48 +271,31 @@ public class GoalResolutionPhaseTest extends TestCase
|
||||||
List expectedOrder, Map messages )
|
List expectedOrder, Map messages )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
MavenProject project = new MavenProject( new Model( ) );
|
MavenGoalExecutionContext context = createGoalExecutionContext( mainGoal );
|
||||||
|
|
||||||
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 );
|
|
||||||
|
|
||||||
context.setGoalDecoratorBindings( bindings );
|
context.setGoalDecoratorBindings( bindings );
|
||||||
|
|
||||||
GoalResolutionPhase phase = new GoalResolutionPhase( );
|
GoalResolutionPhase phase = new GoalResolutionPhase();
|
||||||
|
|
||||||
phase.execute( context );
|
phase.execute( context );
|
||||||
|
|
||||||
List goals = context.getResolvedGoals( );
|
List goals = context.getResolvedGoals();
|
||||||
|
|
||||||
System.out.println( "Resolved goals: " + goals );
|
System.out.println( "Resolved goals: " + goals );
|
||||||
|
|
||||||
assertNotNull( goals );
|
assertNotNull( goals );
|
||||||
|
|
||||||
assertEquals( expectedOrder.size( ), goals.size( ) );
|
assertEquals( expectedOrder.size(), goals.size() );
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
for ( Iterator it = expectedOrder.iterator( ); it.hasNext( ); )
|
for ( Iterator it = expectedOrder.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
String goal = ( String ) it.next( );
|
String goal = (String) it.next();
|
||||||
String failureMessage = ( String ) messages.get( goal );
|
|
||||||
|
|
||||||
String resolvedGoal = ( String ) goals.get( index++ );
|
String failureMessage = (String) messages.get( goal );
|
||||||
|
|
||||||
|
String resolvedGoal = (String) goals.get( index++ );
|
||||||
|
|
||||||
assertEquals( failureMessage, goal, resolvedGoal );
|
assertEquals( failureMessage, goal, resolvedGoal );
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class OgnlProjectValueExtractorTest
|
||||||
|
|
||||||
project.setProperty( "foo", "bar" );
|
project.setProperty( "foo", "bar" );
|
||||||
|
|
||||||
context = new MavenGoalExecutionContext( getContainer(), project, null, new ArtifactRepository( "foo", "http://bar" ) );
|
context = createGoalExecutionContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertyValueExtraction()
|
public void testPropertyValueExtraction()
|
||||||
|
@ -56,7 +56,7 @@ public class OgnlProjectValueExtractorTest
|
||||||
{
|
{
|
||||||
Object value = OgnlProjectValueExtractor.evaluate( "#project.build.directory/classes", context );
|
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();
|
String actual = new File( value.toString() ).getCanonicalPath();
|
||||||
|
|
||||||
|
@ -78,6 +78,6 @@ public class OgnlProjectValueExtractorTest
|
||||||
{
|
{
|
||||||
Object value = OgnlProjectValueExtractor.evaluate( "#localRepository", context );
|
Object value = OgnlProjectValueExtractor.evaluate( "#localRepository", context );
|
||||||
|
|
||||||
assertEquals( "foo", ((ArtifactRepository)value).getId() );
|
assertEquals( "local", ((ArtifactRepository)value).getId() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue