Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
IN PROGRESS - issue NXCM-1165: Move plugin IT's into plugin module
Browse files Browse the repository at this point in the history
https://issues.sonatype.org/browse/NXCM-1165

git-svn-id: file:///opt/svn/repositories/sonatype.org/plugins/trunk/nexus-test-environment-maven-plugin@336 c2a14038-686d-4adc-8740-a14e5738cb64
  • Loading branch information
velo committed Oct 6, 2009
1 parent 644a7d1 commit 9b18d72
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 31 deletions.
Expand Up @@ -29,7 +29,6 @@
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter;
Expand All @@ -40,10 +39,7 @@
import org.apache.maven.shared.filtering.MavenFilteringException;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.zip.ZipArchiver;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
Expand Down Expand Up @@ -177,11 +173,6 @@ public class AbstractEnvironmentMojo
*/
private boolean extractNexusPluginsJavascript;

/**
* @component
*/
private MavenProjectHelper projectHelper;

public void execute()
throws MojoExecutionException, MojoFailureException
{
Expand Down Expand Up @@ -280,15 +271,6 @@ public void execute()
if ( resourcesSourceLocation.isDirectory() )
{
project.getProperties().put( "test-resources-source-folder", getPath( resourcesSourceLocation ) );

try
{
attachResources();
}
catch ( Exception e )
{
throw new MojoFailureException( "Unable to attach 'resources' bundle", e );
}
}

// start default configs
Expand Down Expand Up @@ -357,19 +339,6 @@ protected Artifact getNexusBundle()
return getMavenArtifact( nexusBundleArtifact );
}

private void attachResources()
throws ArchiverException, IOException, ComponentLookupException
{
ZipArchiver za = (ZipArchiver) plexus.lookup( Archiver.ROLE, "zip" );
za.addDirectory( resourcesSourceLocation );
File destFile =
new File( project.getBuild().getDirectory(), project.getBuild().getFinalName() + "-resources.zip" );
za.setDestFile( destFile );
za.createArchive();

projectHelper.attachArtifact( project, "zip", "resources", destFile );
}

private void extractPluginJs()
throws MojoExecutionException
{
Expand Down Expand Up @@ -892,6 +861,7 @@ private Set<Artifact> getFilteredArtifacts( String groupId, String artifactId, S
return filtterArtifacts( projectArtifacts, filter );
}

@SuppressWarnings( "unchecked" )
private Set<Artifact> filtterArtifacts( Set<Artifact> projectArtifacts, FilterArtifacts filter )
throws MojoExecutionException
{
Expand Down
@@ -0,0 +1,121 @@
package org.sonatype.plugin.nexus.testenvironment;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;

/**
* @author velo
* @goal package
* @phase package
*/
public class PackageTestsMojo
extends AbstractMojo
{

/**
* @component
*/
private ArchiverManager archiverManager;

/**
* @component
*/
private MavenProjectHelper projectHelper;

/**
* The maven project.
*
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;

/**
* @parameter default-value="${project.build.testOutputDirectory}"
*/
private File testClasses;

/**
* @parameter default-value="${project.testResources}"
*/
private List<Resource> testResources;

/**
* @parameter default-value="${basedir}/resources"
*/
private File resourcesSourceLocation;

/**
* @parameter default-value="${project.build.directory}/${project.build.finalName}-test-resources.zip"
*/
private File destinationFile;

@SuppressWarnings( "unchecked" )
public void execute()
throws MojoExecutionException, MojoFailureException
{
Archiver archiver;
try
{
archiver = archiverManager.getArchiver( "zip" );
}
catch ( NoSuchArchiverException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}

archiver.setDestFile( destinationFile );
try
{
if ( testClasses.exists() )
{
archiver.addDirectory( testClasses, "classes/" );
}

if ( resourcesSourceLocation.exists() )
{
archiver.addDirectory( resourcesSourceLocation, "resources/" );
}

for ( Resource resource : testResources )
{
File dir = new File( resource.getDirectory() );
if ( !dir.exists() )
{
continue;
}

String[] includes = (String[]) resource.getIncludes().toArray( new String[0] );
String[] excludes = (String[]) resource.getExcludes().toArray( new String[0] );

archiver.addDirectory( dir, "test-resources/", includes, excludes );
}

archiver.createArchive();
}
catch ( ArchiverException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
catch ( IOException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}

projectHelper.attachArtifact( project, "zip", "test-resources", destinationFile );
}

}

0 comments on commit 9b18d72

Please sign in to comment.