21
21
import java .io .File ;
22
22
import java .io .IOException ;
23
23
import java .nio .file .Files ;
24
- import java .util .Locale ;
24
+ import java .util .Collections ;
25
+ import java .util .List ;
25
26
27
+ import org .apache .maven .model .Plugin ;
26
28
import org .apache .maven .plugin .LegacySupport ;
29
+ import org .apache .maven .plugin .MojoExecution ;
30
+ import org .apache .maven .plugin .descriptor .MojoDescriptor ;
31
+ import org .apache .maven .plugin .descriptor .PluginDescriptor ;
27
32
import org .apache .maven .plugin .testing .AbstractMojoTestCase ;
28
33
import org .apache .maven .plugin .testing .ArtifactStubFactory ;
29
34
import org .apache .maven .plugin .testing .stubs .MavenProjectStub ;
39
44
* Abstract class to test reports generation.
40
45
*/
41
46
public abstract class AbstractCheckstyleTestCase extends AbstractMojoTestCase {
42
- private Locale oldLocale ;
43
-
44
47
private ArtifactStubFactory artifactStubFactory ;
45
48
46
49
/**
@@ -53,21 +56,10 @@ protected void setUp() throws Exception {
53
56
// required for mojo lookups to work
54
57
super .setUp ();
55
58
56
- oldLocale = Locale .getDefault ();
57
- Locale .setDefault (Locale .ENGLISH );
58
-
59
59
artifactStubFactory = new DependencyArtifactStubFactory (getTestFile ("target" ), true , false );
60
60
artifactStubFactory .getWorkingDir ().mkdirs ();
61
61
}
62
62
63
- @ Override
64
- protected void tearDown () throws Exception {
65
- super .tearDown ();
66
-
67
- Locale .setDefault (oldLocale );
68
- oldLocale = null ;
69
- }
70
-
71
63
/**
72
64
* Get the current Maven project
73
65
*
@@ -121,8 +113,17 @@ protected CheckstyleReport createReportMojo(String goal, File pluginXmlFile) thr
121
113
repoSession .setLocalRepositoryManager (new SimpleLocalRepositoryManagerFactory ()
122
114
.newInstance (repoSession , new LocalRepository (artifactStubFactory .getWorkingDir ())));
123
115
116
+ List <MavenProject > reactorProjects =
117
+ mojo .getReactorProjects () != null ? mojo .getReactorProjects () : Collections .emptyList ();
118
+
119
+ setVariableValueToObject (mojo , "mojoExecution" , getMockMojoExecution ());
124
120
setVariableValueToObject (mojo , "session" , legacySupport .getSession ());
125
- setVariableValueToObject (mojo , "remoteRepositories" , mojo .getProject ().getRemoteArtifactRepositories ());
121
+ setVariableValueToObject (mojo , "repoSession" , legacySupport .getRepositorySession ());
122
+ setVariableValueToObject (mojo , "reactorProjects" , reactorProjects );
123
+ setVariableValueToObject (
124
+ mojo , "remoteProjectRepositories" , mojo .getProject ().getRemoteProjectRepositories ());
125
+ setVariableValueToObject (
126
+ mojo , "siteDirectory" , new File (mojo .getProject ().getBasedir (), "src/site" ));
126
127
return mojo ;
127
128
}
128
129
@@ -148,4 +149,22 @@ protected File generateReport(CheckstyleReport mojo, File pluginXmlFile) throws
148
149
protected String readFile (File checkstyleTestDir , String fileName ) throws IOException {
149
150
return new String (Files .readAllBytes (checkstyleTestDir .toPath ().resolve (fileName )));
150
151
}
152
+
153
+ private MojoExecution getMockMojoExecution () {
154
+ MojoDescriptor md = new MojoDescriptor ();
155
+ md .setGoal (getGoal ());
156
+
157
+ MojoExecution me = new MojoExecution (md );
158
+
159
+ PluginDescriptor pd = new PluginDescriptor ();
160
+ Plugin p = new Plugin ();
161
+ p .setGroupId ("org.apache.maven.plugins" );
162
+ p .setArtifactId ("maven-checkstyle-plugin" );
163
+ pd .setPlugin (p );
164
+ md .setPluginDescriptor (pd );
165
+
166
+ return me ;
167
+ }
168
+
169
+ protected abstract String getGoal ();
151
170
}
0 commit comments