{
fail( "plugin descriptor not found: '" + pluginXml + "'." );
}
Reader reader = null;
PluginDescriptor pd;
try
{
reader = new InputStreamReader( resource.openStream() );
pd = new PluginDescriptorBuilder().build( reader, pluginXml );
}
finally
{
IOUtil.close( reader );
}
Map<String, Object> config = new HashMap<String, Object>();
config.put( "basedir", new File( "." ).getAbsoluteFile() );
config.put( "messageLevel", "info" );
MojoDescriptor md = pd.getMojo( "test" );
AntMojoWrapper wrapper =
new AntMojoWrapper( new AntScriptInvoker( md, Thread.currentThread().getContextClassLoader() ) );
wrapper.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
MockControl artifactCtl = null;
MockControl pathTranslatorCtl = null;
if ( includeImplied )
{
File pluginXmlFile = new File( StringUtils.replace( resource.getPath(), "%20", " " ) );
File jarFile = File.createTempFile( "AntMojoWrapperTest.", ".test.jar" );
jarFile.deleteOnExit();
JarArchiver archiver = new JarArchiver();
archiver.enableLogging( new ConsoleLogger( Logger.LEVEL_ERROR, "archiver" ) );
archiver.setDestFile( jarFile );
archiver.addFile( pluginXmlFile, pluginXml );
archiver.createArchive();
artifactCtl = MockControl.createControl( Artifact.class );
Artifact artifact = (Artifact) artifactCtl.getMock();
artifact.getFile();
artifactCtl.setReturnValue( jarFile, MockControl.ZERO_OR_MORE );
artifact.getGroupId();
artifactCtl.setReturnValue( "groupId", MockControl.ZERO_OR_MORE );
artifact.getArtifactId();
artifactCtl.setReturnValue( "artifactId", MockControl.ZERO_OR_MORE );
artifact.getVersion();
artifactCtl.setReturnValue( "1", MockControl.ZERO_OR_MORE );
artifact.getId();
artifactCtl.setReturnValue( "groupId:artifactId:jar:1", MockControl.ZERO_OR_MORE );
artifact.getClassifier();
artifactCtl.setReturnValue( null, MockControl.ZERO_OR_MORE );
pathTranslatorCtl = MockControl.createControl( PathTranslator.class );
PathTranslator pt = (PathTranslator) pathTranslatorCtl.getMock();
Model model = new Model();
Build build = new Build();
build.setDirectory( "target" );
model.setBuild( build );
MavenProject project = new MavenProject( model );
project.setFile( new File( "pom.xml" ).getAbsoluteFile() );
artifactCtl.replay();
pathTranslatorCtl.replay();
pd.setPluginArtifact( artifact );
pd.setArtifacts( Collections.singletonList( artifact ) );
config.put( "project", project );
config.put( "session", new MavenSession( null, null, null, null, null, null, null, null, null, null ) );
config.put( "mojoExecution", new MojoExecution( md ) );