Field artifactFactoryField = ShadeMojo.class.getDeclaredField( "artifactFactory" );
artifactFactoryField.setAccessible( true );
artifactFactoryField.set( mojo, artifactFactory );
// configure artifactResolver (mocked) for mojo
ArtifactResolver mockArtifactResolver = new DefaultArtifactResolver()
{
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepos, ArtifactRepository repo )
throws ArtifactResolutionException, ArtifactNotFoundException
{
// artifact is resolved
artifact.setResolved( true );
// set file
artifact.setFile( new File(
artifact.getArtifactId() + "-" + artifact.getVersion() + ( artifact.getClassifier() != null ? "-"
+ artifact.getClassifier() : "" ) + ".jar" ) );
}
};
Field artifactResolverField = ShadeMojo.class.getDeclaredField( "artifactResolver" );
artifactResolverField.setAccessible( true );
artifactResolverField.set( mojo, mockArtifactResolver );
// create and configure MavenProject
MavenProject project = new MavenProject();
ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE );
Artifact artifact = new DefaultArtifact( "org.apache.myfaces.core", "myfaces-impl",
VersionRange.createFromVersion( "2.0.1-SNAPSHOT" ), "compile", "jar",
null, artifactHandler );
mockArtifactResolver.resolve( artifact, null, null ); // setFile and setResolved
project.setArtifact( artifact );
Field projectField = ShadeMojo.class.getDeclaredField( "project" );
projectField.setAccessible( true );
projectField.set( mojo, project );