1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.test.plugin;
20
21 import java.io.File;
22
23 import org.apache.maven.project.MavenProject;
24
25 /**
26 * Test tool that provides a single point of access for staging a plugin artifact - along with its
27 * POM lineage - into a clean test-time local repository. This involves modifying the plugin POM to
28 * provide a stable test-time version for test-build POMs to reference, then installing the plugin
29 * jar and associated POMs (including those ancestors that are reachable using <relativePath>)
30 * into the test local repository.
31 *
32 * <p>
33 * <b>WARNING:</b> Currently, the <code>RepositoryTool</code> will not
34 * resolve parent POMs that exist <b>only</b> in your normal local repository, and are not reachable
35 * using the relativePath element. This may result in failed test builds, as one or more of the
36 * plugin's ancestor POMs cannot be resolved.
37 * </p>
38 *
39 * @plexus.component role="org.apache.maven.shared.test.plugin.PluginTestTool" role-hint="default"
40 * @author jdcasey
41 *
42 */
43 public class PluginTestTool
44 {
45 public static final String ROLE = PluginTestTool.class.getName();
46
47 /**
48 * @plexus.requirement role-hint="default"
49 */
50 private ProjectTool projectTool;
51
52 /**
53 * @plexus.requirement role-hint="default"
54 */
55 private RepositoryTool repositoryTool;
56
57 /**
58 * Stage the plugin, using a stable version, into a temporary local-repository directory that is
59 * generated by this method. When the plugin is staged, return the local repository base directory
60 * for use in test builds.
61 *
62 * @param testVersion The test version for the plugin, used for reference in test-build POMs and
63 * fully-qualified goals
64 * @return The base-directory location of the generated local repository
65 */
66 public File preparePluginForIntegrationTesting( String testVersion )
67 throws TestToolsException
68 {
69 return prepareForTesting( testVersion, false, null );
70 }
71
72 /**
73 * Stage the plugin, using a stable version, into a temporary local-repository directory that is
74 * generated by this method. When the plugin is staged, return the local repository base directory
75 * for use in test builds. This method also skips unit testing during plugin jar production,
76 * since it is assumed that executing these tests would lead to a recursive test-and-build loop.
77 *
78 * @param testVersion The test version for the plugin, used for reference in test-build POMs and
79 * fully-qualified goals
80 * @return The base-directory location of the generated local repository
81 */
82 public File preparePluginForUnitTestingWithMavenBuilds( String testVersion )
83 throws TestToolsException
84 {
85 return prepareForTesting( testVersion, true, null );
86 }
87
88 /**
89 * Stage the plugin, using a stable version, into the specified local-repository directory.
90 * When the plugin is staged, return the local repository base directory for verification.
91 *
92 * @param testVersion The test version for the plugin, used for reference in test-build POMs and
93 * fully-qualified goals
94 * @param localRepositoryDir The base-directory location of the test local repository, into which
95 * the plugin's test version should be staged.
96 * @return The base-directory location of the generated local repository
97 */
98 public File preparePluginForIntegrationTesting( String testVersion, File localRepositoryDir )
99 throws TestToolsException
100 {
101 return prepareForTesting( testVersion, false, localRepositoryDir );
102 }
103
104 /**
105 * Stage the plugin, using a stable version, into the specified local-repository directory.
106 * When the plugin is staged, return the local repository base directory for verification. This
107 * method also skips unit testing during plugin jar production, since it is assumed that
108 * executing these tests would lead to a recursive test-and-build loop.
109 *
110 * @param testVersion The test version for the plugin, used for reference in test-build POMs and
111 * fully-qualified goals
112 * @param localRepositoryDir The base-directory location of the test local repository, into which
113 * the plugin's test version should be staged.
114 * @return The base-directory location of the generated local repository
115 */
116 public File preparePluginForUnitTestingWithMavenBuilds( String testVersion, File localRepositoryDir )
117 throws TestToolsException
118 {
119 return prepareForTesting( testVersion, true, localRepositoryDir );
120 }
121
122 private File prepareForTesting( String testVersion, boolean skipUnitTests, File localRepositoryDir )
123 throws TestToolsException
124 {
125 File pomFile = new File( "pom.xml" );
126 File buildLog = new File( "target/test-build-logs/setup.build.log" );
127 File localRepoDir = localRepositoryDir;
128
129 if ( localRepoDir == null )
130 {
131 localRepoDir = new File( "target/test-local-repository" );
132 }
133
134 MavenProject project = projectTool.packageProjectArtifact( pomFile, testVersion, skipUnitTests, buildLog );
135 repositoryTool.createLocalRepositoryFromPlugin( project, localRepoDir );
136
137 return localRepoDir;
138 }
139
140 }