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 MainSourcesManageMojo extends AbstractSourcesManageMojo
49 {
50
51
52
53
54
55
56
57 private String manageMainSourcesExecutionStrategy;
58
59
60 public MainSourcesManageMojo()
61 {
62 super();
63 }
64
65 @Override
66 protected String getSourcesModuleName() throws MojoExecutionException
67 {
68 return this.getModuleName();
69 }
70
71 @Override
72 protected ClassLoader getSourcesClassLoader() throws MojoExecutionException
73 {
74 return this.getMainClassLoader();
75 }
76
77 @Override
78 protected File getSourcesDirectory() throws MojoExecutionException
79 {
80 final File sourcesDirectory = this.getSourceDirectory();
81 boolean compileSourceRoot = false;
82
83 for ( int i = 0, l0 = this.getMavenProject().getCompileSourceRoots().size(); i < l0; i++ )
84 {
85 final String element = (String) this.getMavenProject().getCompileSourceRoots().get( i );
86
87 if ( sourcesDirectory.equals( this.getAbsoluteFile( element ) ) )
88 {
89 compileSourceRoot = true;
90 break;
91 }
92 }
93
94 if ( !compileSourceRoot )
95 {
96 if ( !sourcesDirectory.exists() && !sourcesDirectory.mkdirs() )
97 {
98 throw new MojoExecutionException( Messages.getMessage(
99 "failedCreatingDirectory", sourcesDirectory.getAbsolutePath() ) );
100
101 }
102
103 this.getMavenProject().addCompileSourceRoot( sourcesDirectory.getAbsolutePath() );
104 this.log( Level.INFO, Messages.getMessage(
105 "addedCompileSourceRoot", sourcesDirectory.getAbsolutePath() ), null );
106
107 }
108
109 return sourcesDirectory;
110 }
111
112 @Override
113 protected String getGoal() throws MojoExecutionException
114 {
115 return "manage-main-sources";
116 }
117
118 @Override
119 protected String getExecutionStrategy() throws MojoExecutionException
120 {
121 return this.manageMainSourcesExecutionStrategy;
122 }
123
124 }