1 package org.apache.maven.plugin.source;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.codehaus.plexus.archiver.ArchiverException;
24 import org.codehaus.plexus.archiver.jar.JarArchiver;
25
26 import java.io.File;
27 import java.io.IOException;
28
29 /**
30 * This plugin bundles all the test sources into a jar archive.
31 *
32 * @goal test-jar
33 * @phase package
34 * @execute phase="generate-sources"
35 */
36 public class JarTestSourceMojo
37 extends AbstractJarSourceMojo
38 {
39 /**
40 * @see org.apache.maven.plugin.AbstractMojo#execute()
41 */
42 public void execute()
43 throws MojoExecutionException
44 {
45 if ( "pom".equals( packaging ) )
46 {
47 getLog().info( "NOT adding test sources to attached artifacts for packaging: \'" + packaging + "\'." );
48 }
49 else
50 {
51 File outputFile = new File( outputDirectory, finalName + "-test-sources.jar" );
52 File[] testSourceDirectories = getTestSources();
53
54 try
55 {
56 createJar( outputFile, testSourceDirectories, createArchiver() );
57 }
58 catch ( IOException e )
59 {
60 throw new MojoExecutionException( "Error creating source archive: " + e.getMessage(), e );
61 }
62 catch ( ArchiverException e )
63 {
64 throw new MojoExecutionException( "Error creating source archive: " + e.getMessage(), e );
65 }
66
67 attachArtifact( outputFile, "test-sources" );
68 }
69 }
70
71 }