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 javax.xml.bind.JAXBContext;
36 import javax.xml.bind.util.JAXBSource;
37 import javax.xml.transform.Source;
38 import org.apache.maven.plugin.MojoExecutionException;
39 import org.jomc.model.Module;
40 import org.jomc.modlet.ModelContext;
41 import org.jomc.modlet.ModelValidationReport;
42 import org.jomc.modlet.ObjectFactory;
43 import org.jomc.tools.SourceFileProcessor;
44
45
46
47
48
49
50
51 public abstract class AbstractSourcesManageMojo extends AbstractJomcMojo
52 {
53
54
55
56
57 private static final String TOOLNAME = "SourceFileProcessor";
58
59
60
61
62 public AbstractSourcesManageMojo()
63 {
64 super();
65 }
66
67 @Override
68 protected final void executeTool() throws Exception
69 {
70 this.logSeparator();
71
72 if ( this.isSourceProcessingEnabled() )
73 {
74 this.logProcessingModule( TOOLNAME, this.getSourcesModuleName() );
75
76 final ModelContext context = this.createModelContext( this.getSourcesClassLoader() );
77 final SourceFileProcessor tool = this.createSourceFileProcessor( context );
78 final JAXBContext jaxbContext = context.createContext( this.getModel() );
79 final Source source = new JAXBSource( jaxbContext, new ObjectFactory().createModel( tool.getModel() ) );
80 final ModelValidationReport validationReport = context.validateModel( this.getModel(), source );
81
82 this.log( context, validationReport.isModelValid() ? Level.INFO : Level.SEVERE, validationReport );
83
84 if ( validationReport.isModelValid() )
85 {
86 final Module module =
87 tool.getModules() != null ? tool.getModules().getModule( this.getSourcesModuleName() ) : null;
88
89 if ( module != null )
90 {
91 tool.manageSourceFiles( module, this.getSourcesDirectory() );
92 this.logToolSuccess( TOOLNAME );
93 }
94 else
95 {
96 this.logMissingModule( this.getSourcesModuleName() );
97 }
98 }
99 else
100 {
101 throw new MojoExecutionException( Messages.getMessage( "sourceProcessingFailure" ) );
102 }
103 }
104 else if ( this.isLoggable( Level.INFO ) )
105 {
106 this.log( Level.INFO, Messages.getMessage( "sourceProcessingDisabled" ), null );
107 }
108 }
109
110
111
112
113
114
115
116
117 protected abstract String getSourcesModuleName() throws MojoExecutionException;
118
119
120
121
122
123
124
125
126 protected abstract ClassLoader getSourcesClassLoader() throws MojoExecutionException;
127
128
129
130
131
132
133
134
135 protected abstract File getSourcesDirectory() throws MojoExecutionException;
136
137 }