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
32
33 package org.jomc.mojo;
34
35 import java.io.File;
36 import java.util.ResourceBundle;
37 import java.util.logging.Level;
38 import javax.xml.bind.JAXBContext;
39 import javax.xml.bind.util.JAXBSource;
40 import org.apache.maven.plugin.MojoExecutionException;
41 import org.jomc.model.ModelContext;
42 import org.jomc.model.ModelValidationReport;
43 import org.jomc.model.Module;
44 import org.jomc.model.ObjectFactory;
45 import org.jomc.tools.JavaSources;
46
47
48
49
50
51
52
53
54
55
56
57 public final class MainJavaSourcesMojo extends AbstractJomcMojo
58 {
59
60
61 private static final String TOOLNAME = "JavaSources";
62
63
64 public MainJavaSourcesMojo()
65 {
66 super();
67 }
68
69 @Override
70 protected void executeTool() throws Exception
71 {
72 if ( this.isSourceProcessingEnabled() )
73 {
74 File sourceDirectory = new File( this.getMavenProject().getBuild().getSourceDirectory() );
75
76 if ( !sourceDirectory.isAbsolute() )
77 {
78 sourceDirectory = new File( this.getMavenProject().getBasedir(),
79 this.getMavenProject().getBuild().getSourceDirectory() );
80
81 }
82
83 final ModelContext context = this.getModelContext( this.getMainClassLoader() );
84 final JavaSources tool = this.getJavaSourcesTool( context );
85 final JAXBContext jaxbContext = context.createContext();
86
87 final ModelValidationReport validationReport = context.validateModel( new JAXBSource(
88 jaxbContext, new ObjectFactory().createModules( tool.getModules() ) ) );
89
90 this.log( context, validationReport.isModelValid() ? Level.INFO : Level.SEVERE, validationReport );
91
92 if ( validationReport.isModelValid() )
93 {
94 this.logSeparator( Level.INFO );
95 final Module module = tool.getModules().getModule( this.getJomcModuleName() );
96
97 if ( module != null )
98 {
99 this.logProcessingModule( TOOLNAME, module.getName() );
100 tool.manageSources( module, sourceDirectory );
101 this.logToolSuccess( TOOLNAME );
102 }
103 else
104 {
105 this.logMissingModule( this.getJomcModuleName() );
106 }
107
108 this.logSeparator( Level.INFO );
109 }
110 else
111 {
112 throw new MojoExecutionException( getMessage( "failed" ) );
113 }
114 }
115 else
116 {
117 this.logSeparator( Level.INFO );
118 this.log( Level.INFO, getMessage( "disabled" ), null );
119 this.logSeparator( Level.INFO );
120 }
121 }
122
123 private static String getMessage( final String key )
124 {
125 return ResourceBundle.getBundle( MainJavaSourcesMojo.class.getName().replace( '.', '/' ) ).getString( key );
126 }
127
128 }