in src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java [81:118]
private static PmdResult fork(PmdRequest request) throws MavenReportException {
File basePmdDir = new File(request.getTargetDirectory(), "pmd");
basePmdDir.mkdirs();
File pmdRequestFile = new File(basePmdDir, "pmdrequest.bin");
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(pmdRequestFile))) {
out.writeObject(request);
} catch (IOException e) {
throw new MavenReportException(e.getMessage(), e);
}
String classpath = buildClasspath();
ProcessBuilder pb = new ProcessBuilder();
// note: using env variable instead of -cp cli arg to avoid length limitations under Windows
pb.environment().put("CLASSPATH", classpath);
pb.command().add(request.getJavaExecutable());
pb.command().add(PmdExecutor.class.getName());
pb.command().add(pmdRequestFile.getAbsolutePath());
LOG.debug("Executing: CLASSPATH={}, command={}", classpath, pb.command());
try {
final Process p = pb.start();
// Note: can't use pb.inheritIO(), since System.out/System.err has been modified after process start
// and inheritIO would only inherit file handles, not the changed streams.
ProcessStreamHandler.start(p.getInputStream(), System.out);
ProcessStreamHandler.start(p.getErrorStream(), System.err);
int exit = p.waitFor();
LOG.debug("PmdExecutor exit code: {}", exit);
if (exit != 0) {
throw new MavenReportException("PmdExecutor exited with exit code " + exit);
}
return new PmdResult(new File(request.getTargetDirectory(), "pmd.xml"), request.getOutputEncoding());
} catch (IOException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new MavenReportException(e.getMessage(), e);
}
}