use of org.apache.maven.shared.invoker.InvocationRequest in project maven-plugins by apache.
the class SiteInvoker method invoke.
/**
* @param projectFile not null, should be in the ${project.basedir}
* @param invokerLog not null
* @param mavenHome not null
* @param goals the list of goals
* @param properties the properties for the invoker
*/
private void invoke(File projectFile, File invokerLog, String mavenHome, List goals, List activeProfiles, Properties properties) {
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File(mavenHome));
File localRepoDir = new File(localRepository.getBasedir());
invoker.setLocalRepositoryDirectory(localRepoDir);
InvocationRequest request = new DefaultInvocationRequest();
request.setLocalRepositoryDirectory(localRepoDir);
// request.setUserSettingsFile( settingsFile );
request.setBatchMode(true);
request.setShowErrors(getLog().isErrorEnabled());
request.setDebug(getLog().isDebugEnabled());
// request.setShowVersion( false );
request.setBaseDirectory(projectFile.getParentFile());
request.setPomFile(projectFile);
request.setGoals(goals);
request.setProperties(properties);
request.setProfiles(activeProfiles);
File javaHome = getJavaHome();
if (javaHome != null) {
request.setJavaHome(javaHome);
}
InvocationResult invocationResult;
try {
if (getLog().isDebugEnabled()) {
getLog().debug("Invoking Maven for the goals: " + goals + " with properties=" + properties);
}
invocationResult = invoke(invoker, request, invokerLog, goals, properties, null);
} catch (MavenInvocationException e) {
getLog().error("Error when invoking Maven, consult the invoker log.");
getLog().debug(e);
return;
}
String invokerLogContent = null;
Reader reader = null;
try {
reader = ReaderFactory.newReader(invokerLog, "UTF-8");
invokerLogContent = IOUtil.toString(reader);
reader.close();
reader = null;
} catch (IOException e) {
getLog().error("IOException: " + e.getMessage());
getLog().debug(e);
} finally {
IOUtil.close(reader);
}
if (invokerLogContent != null && invokerLogContent.contains("Error occurred during initialization of VM")) {
getLog().info("Error occurred during initialization of VM, try to use an empty MAVEN_OPTS.");
if (getLog().isDebugEnabled()) {
getLog().debug("Reinvoking Maven for the goals: " + goals + " with an empty MAVEN_OPTS");
}
try {
invocationResult = invoke(invoker, request, invokerLog, goals, properties, "");
} catch (MavenInvocationException e) {
getLog().error("Error when reinvoking Maven, consult the invoker log.");
getLog().debug(e);
return;
}
}
if (invocationResult.getExitCode() != 0) {
if (getLog().isErrorEnabled()) {
getLog().error("Error when invoking Maven, consult the invoker log file: " + invokerLog.getAbsolutePath());
}
}
}
use of org.apache.maven.shared.invoker.InvocationRequest in project ddf by codice.
the class OwaspDiffRunner method main.
public static void main(String[] args) throws OwaspDiffRunnerException {
System.out.println(BEGIN_OWASP_AUDIT);
try {
mavenHome = getMavenHome();
localRepo = getLocalRepo();
String modulesOfChangedPoms = getModulesOfChangedPoms();
if (modulesOfChangedPoms.isEmpty()) {
System.out.println("No changed poms.");
return;
}
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File(PROJECT_ROOT + File.separator + "pom.xml"));
request.setBaseDirectory(new File(PROJECT_ROOT));
request.setLocalRepositoryDirectory(new File(localRepo));
request.setGoals(Arrays.asList("dependency-check:check", "--quiet", "-pl", modulesOfChangedPoms, "-Powasp"));
invoker.setMavenHome(new File(mavenHome));
System.out.println("-- Maven home: " + mavenHome);
System.out.println("-- Local Maven repo: " + localRepo);
InvocationResult mavenBuildResult;
try {
mavenBuildResult = invoker.execute(request);
} catch (MavenInvocationException e) {
throw new OwaspDiffRunnerException(OwaspDiffRunnerException.UNABLE_TO_RUN_MAVEN + modulesOfChangedPoms, e);
}
if (mavenBuildResult.getExitCode() != 0) {
throw new OwaspDiffRunnerException(OwaspDiffRunnerException.FOUND_VULNERABILITIES);
}
} finally {
System.out.println(END_OWASP_AUDIT);
}
}
Aggregations