Skip to content

Commit 0f49841

Browse files
committed
#7 Starting patch-gen in a separate process until MODULES-136 has been resolved
1 parent 594c335 commit 0f49841

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

patch-gen-maven-plugin/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<groupId>org.apache.maven</groupId>
2626
<artifactId>maven-plugin-api</artifactId>
2727
<version>2.0</version>
28+
<scope>provided</scope>
2829
</dependency>
2930
<dependency>
3031
<groupId>org.apache.maven.plugin-tools</groupId>

patch-gen-maven-plugin/src/main/java/org/jboss/as/patch/generator/maven/plugin/PatchGenMojo.java

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
package org.jboss.as.patch.generator.maven.plugin;
2323

2424
import java.io.File;
25+
import java.io.IOException;
2526
import java.util.ArrayList;
2627
import java.util.List;
2728

29+
import org.apache.maven.artifact.Artifact;
2830
import org.apache.maven.plugin.AbstractMojo;
2931
import org.apache.maven.plugin.MojoExecutionException;
3032
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -71,6 +73,8 @@
7173
@Mojo( name = "generate-patch", defaultPhase = LifecyclePhase.GENERATE_RESOURCES )
7274
public class PatchGenMojo extends AbstractMojo {
7375

76+
private static final String LOG_FILE = "patchgen.log";
77+
7478
@Parameter( property = "patchConfig", required = true )
7579
private File patchConfig;
7680

@@ -98,9 +102,21 @@ public class PatchGenMojo extends AbstractMojo {
98102
@Parameter( property = "combineWith" )
99103
private File combineWith;
100104

105+
@Parameter( property = "project.build.directory" )
106+
private File buildDirectory;
107+
108+
@Parameter( property = "plugin.artifacts" )
109+
protected List<Artifact> pluginArtifacts;
110+
101111
@Override
102112
public void execute() throws MojoExecutionException {
103113
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+
104120
args.add( PatchGenerator.APPLIES_TO_DIST + "=" + appliesToDist.getPath() );
105121
args.add( PatchGenerator.OUTPUT_FILE + "=" + outputFile.getPath() );
106122
args.add( PatchGenerator.PATCH_CONFIG + "=" + patchConfig.getPath() );
@@ -126,6 +142,43 @@ public void execute() throws MojoExecutionException {
126142
args.add( PatchGenerator.COMBINE_WITH + "=" + combineWith.getPath() );
127143
}
128144

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();
130183
}
131184
}

0 commit comments

Comments
 (0)