o for milos' test i am now adding the component to the container programmatically so we don't need to manually stuff an artifact handler into

the artifact handler manager


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@587648 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-10-23 20:33:10 +00:00
parent 90e62086d1
commit 7f8b8699a5
3 changed files with 77 additions and 51 deletions

View File

@ -1400,9 +1400,8 @@ public Object getPluginComponent( Plugin plugin,
if ( pluginRealm == null )
{
getLogger().warn(
"getPluginComponent(" + plugin + ", " + role
+ "): descriptor is missing classRealm" );
getLogger().warn( "getPluginComponent(" + plugin + ", " + role + "): descriptor is missing classRealm" );
pluginRealm = container.getLookupRealm();
}

View File

@ -1,16 +1,17 @@
package org.apache.maven.embedder;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
/** @author Jason van Zyl */
public class MavenEmbedderProjectWithExtensionReadingTest
@ -24,7 +25,25 @@ public void testProjectWithExtensionsReading()
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
MavenExecutionResult result = new ExtendableMavenEmbedder( classLoader ).readProjectWithDependencies( request );
MavenEmbedder embedder = new ExtendableMavenEmbedder( classLoader );
// Here we take the artifact handler and programmatically place it into the container
ComponentDescriptor cd = new ComponentDescriptor();
cd.setRole( ArtifactHandler.ROLE );
cd.setRoleHint( "mkleint" );
cd.setImplementation( MyArtifactHandler.class.getName() );
embedder.getPlexusContainer().addComponentDescriptor( cd );
// At this point the artifact handler will be inside the container and
// Maven internally will pick up the artifact handler and use it accordingly to
// create the classpath appropriately.
MavenExecutionResult result = embedder.readProjectWithDependencies( request );
assertNoExceptions( result );
@ -48,13 +67,17 @@ public ExtendableMavenEmbedder( ClassLoader classLoader )
protected Map getPluginExtensionComponents( Plugin plugin )
throws PluginManagerException
{
Map toReturn = new HashMap();
try
{
return getPlexusContainer().lookupMap( ArtifactHandler.ROLE );
}
catch ( ComponentLookupException e )
{
e.printStackTrace();
MyArtifactHandler handler = new MyArtifactHandler();
throw new PluginManagerException( plugin, null );
}
toReturn.put( "mkleint", handler );
return toReturn;
}
protected void verifyPlugin( Plugin plugin,
@ -64,43 +87,4 @@ protected void verifyPlugin( Plugin plugin,
}
}
private class MyArtifactHandler
implements ArtifactHandler
{
public String getExtension()
{
return "jar";
}
public String getDirectory()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public String getClassifier()
{
return null;
}
public String getPackaging()
{
return "mkleint";
}
public boolean isIncludesDependencies()
{
return false;
}
public String getLanguage()
{
return "java";
}
public boolean isAddedToClasspath()
{
return true;
}
}
}

View File

@ -0,0 +1,43 @@
package org.apache.maven.embedder;
import org.apache.maven.artifact.handler.ArtifactHandler;
/** @author Jason van Zyl */
public class MyArtifactHandler
implements ArtifactHandler
{
public String getExtension()
{
return "jar";
}
public String getDirectory()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public String getClassifier()
{
return null;
}
public String getPackaging()
{
return "mkleint";
}
public boolean isIncludesDependencies()
{
return false;
}
public String getLanguage()
{
return "java";
}
public boolean isAddedToClasspath()
{
return true;
}
}