22
22
package org .jboss .as .patch .generator .maven .plugin ;
23
23
24
24
import java .io .File ;
25
+ import java .io .IOException ;
25
26
import java .util .ArrayList ;
26
27
import java .util .List ;
27
28
29
+ import org .apache .maven .artifact .Artifact ;
28
30
import org .apache .maven .plugin .AbstractMojo ;
29
31
import org .apache .maven .plugin .MojoExecutionException ;
30
32
import org .apache .maven .plugins .annotations .LifecyclePhase ;
68
70
*
69
71
* @author Gunnar Morling
70
72
*/
71
- @ Mojo ( name = "GenPatch " , defaultPhase = LifecyclePhase .GENERATE_RESOURCES )
73
+ @ Mojo ( name = "generate-patch " , defaultPhase = LifecyclePhase .GENERATE_RESOURCES )
72
74
public class PatchGenMojo extends AbstractMojo {
73
75
76
+ private static final String LOG_FILE = "patchgen.log" ;
77
+
74
78
@ Parameter ( property = "patchConfig" , required = true )
75
79
private File patchConfig ;
76
80
@@ -98,9 +102,21 @@ public class PatchGenMojo extends AbstractMojo {
98
102
@ Parameter ( property = "combineWith" )
99
103
private File combineWith ;
100
104
105
+ @ Parameter ( property = "project.build.directory" )
106
+ private File buildDirectory ;
107
+
108
+ @ Parameter ( property = "plugin.artifacts" )
109
+ protected List <Artifact > pluginArtifacts ;
110
+
101
111
@ Override
102
112
public void execute () throws MojoExecutionException {
103
113
List <String > args = new ArrayList <>();
114
+
115
+ args .add ( "java" );
116
+ args .add ( "-cp" );
117
+ args .add ( getClasspath () );
118
+ args .add ( PatchGenerator .class .getName () );
119
+
104
120
args .add ( PatchGenerator .APPLIES_TO_DIST + "=" + appliesToDist .getPath () );
105
121
args .add ( PatchGenerator .OUTPUT_FILE + "=" + outputFile .getPath () );
106
122
args .add ( PatchGenerator .PATCH_CONFIG + "=" + patchConfig .getPath () );
@@ -126,6 +142,43 @@ public void execute() throws MojoExecutionException {
126
142
args .add ( PatchGenerator .COMBINE_WITH + "=" + combineWith .getPath () );
127
143
}
128
144
129
- PatchGenerator .main ( args .toArray ( new String [0 ] ) );
145
+ // Ideally, we'd just invoke PatchGenerator directly; currently we cannot do so due to https://issues.jboss.org/browse/MODULES-136:
146
+ // JBoss Modules, when used as a library, will set some system properties to values causing trouble for other plug-ins later in the
147
+ // build; e.g. SAXParserFactory is redirected to a JBoss Modules specific variant which then cannot be found by other users such as
148
+ // the Checkstyle plug-in (which naturally doesn't have JBoss Modules on the plug-in dependency path). Hence we start patch-gen in
149
+ // a separate process
150
+ //
151
+ // PatchGenerator.main( args.toArray( new String[0] ) );
152
+ try {
153
+ Process p = new ProcessBuilder ( args )
154
+ .redirectOutput ( new File ( buildDirectory , LOG_FILE ) )
155
+ .redirectError ( new File ( buildDirectory , LOG_FILE ) )
156
+ .start ();
157
+ p .waitFor ();
158
+ }
159
+ catch (IOException | InterruptedException e ) {
160
+ throw new MojoExecutionException ( "Execution of PatchGenerator failed. See " + LOG_FILE + " for details." , e );
161
+ }
162
+
163
+ if ( !outputFile .exists () ) {
164
+ throw new MojoExecutionException ( "Execution of PatchGenerator failed. See " + LOG_FILE + " for details." );
165
+ }
166
+ }
167
+
168
+ private String getClasspath () {
169
+ StringBuilder sb = new StringBuilder ();
170
+ boolean first = true ;
171
+
172
+ for ( Artifact artifact : pluginArtifacts ) {
173
+ if ( first ) {
174
+ first = false ;
175
+ }
176
+ else {
177
+ sb .append ( File .pathSeparator );
178
+ }
179
+ sb .append ( artifact .getFile ().getPath () );
180
+ }
181
+
182
+ return sb .toString ();
130
183
}
131
184
}
0 commit comments