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 public TestSourcesManageMojo()
61 {
62 super();
63 }
64
65 @Override
66 protected String getSourcesModuleName() throws MojoExecutionException
67 {
68 return this.getTestModuleName();
69 }
70
71 @Override
72 protected ClassLoader getSourcesClassLoader() throws MojoExecutionException
73 {
74 return this.getTestClassLoader();
75 }
76
77 @Override
78 protected File getSourcesDirectory() throws MojoExecutionException
79 {
80 final File sourcesDirectory = this.getTestSourceDirectory();
81 boolean testCompileSourceRoot = false;
82
83 for ( int i = 0, l0 = this.getMavenProject().getTestCompileSourceRoots().size(); i < l0; i++ )
84 {
85 final String element = (String) this.getMavenProject().getTestCompileSourceRoots().get( i );
86
87 if ( sourcesDirectory.equals( this.getAbsoluteFile( element ) ) )
88 {
89 testCompileSourceRoot = true;
90 break;
91 }
92 }
93
94 if ( !testCompileSourceRoot )
95 {
96 if ( !sourcesDirectory.exists() && !sourcesDirectory.mkdirs() )
97 {
98 throw new MojoExecutionException( Messages.getMessage(
99 "failedCreatingDirectory", sourcesDirectory.getAbsolutePath() ) );
100
101 }
102
103 this.getMavenProject().addTestCompileSourceRoot( sourcesDirectory.getAbsolutePath() );
104 this.log( Level.INFO, Messages.getMessage(
105 "addedTestCompileSourceRoot", sourcesDirectory.getAbsolutePath() ), null );
106
107 }
108
109 return sourcesDirectory;
110 }
111
112 @Override
113 protected String getGoal() throws MojoExecutionException
114 {
115 return "manage-test-sources";
116 }
117
118 @Override
119 protected String getExecutionStrategy() throws MojoExecutionException
120 {
121 return this.manageTestSourcesExecutionStrategy;
122 }
123
124 }