1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package org.jomc.mojo;
32
33 import java.io.File;
34 import java.util.logging.Level;
35 import org.apache.maven.plugin.MojoExecutionException;
36
37
38
39
40
41
42
43
44
45
46
47
48 public final class TestSourcesManageMojo extends AbstractSourcesManageMojo
49 {
50
51
52
53
54
55
56
57 private String manageTestSourcesExecutionStrategy;
58
59
60
61
62 public TestSourcesManageMojo()
63 {
64 super();
65 }
66
67 @Override
68 protected String getSourcesModuleName() throws MojoExecutionException
69 {
70 return this.getTestModuleName();
71 }
72
73 @Override
74 protected ClassLoader getSourcesClassLoader() throws MojoExecutionException
75 {
76 return this.getTestClassLoader();
77 }
78
79 @Override
80 protected File getSourcesDirectory() throws MojoExecutionException
81 {
82 final File sourcesDirectory = this.getTestSourceDirectory();
83 boolean testCompileSourceRoot = false;
84
85 for ( int i = 0, l0 = this.getMavenProject().getTestCompileSourceRoots().size(); i < l0; i++ )
86 {
87 final String element = (String) this.getMavenProject().getTestCompileSourceRoots().get( i );
88
89 if ( sourcesDirectory.equals( this.getAbsoluteFile( element ) ) )
90 {
91 testCompileSourceRoot = true;
92 break;
93 }
94 }
95
96 if ( !testCompileSourceRoot )
97 {
98 if ( !sourcesDirectory.exists() && !sourcesDirectory.mkdirs() )
99 {
100 throw new MojoExecutionException( Messages.getMessage(
101 "failedCreatingDirectory", sourcesDirectory.getAbsolutePath() ) );
102
103 }
104
105 this.getMavenProject().addTestCompileSourceRoot( sourcesDirectory.getAbsolutePath() );
106 this.log( Level.INFO, Messages.getMessage(
107 "addedTestCompileSourceRoot", sourcesDirectory.getAbsolutePath() ), null );
108
109 }
110
111 return sourcesDirectory;
112 }
113
114 @Override
115 protected String getGoal() throws MojoExecutionException
116 {
117 return "manage-test-sources";
118 }
119
120 @Override
121 protected String getExecutionStrategy() throws MojoExecutionException
122 {
123 return this.manageTestSourcesExecutionStrategy;
124 }
125
126 }