use of org.apache.maven.plugin.MojoExecutionException in project hadoop by apache.
the class TestMojo method execute.
public void execute() throws MojoExecutionException {
if (testName == null) {
testName = binary.getName();
}
validatePlatform();
validateParameters();
if (!shouldRunTest()) {
return;
}
if (!results.isDirectory()) {
if (!results.mkdirs()) {
throw new MojoExecutionException("Failed to create " + "output directory '" + results + "'!");
}
}
List<String> cmd = new LinkedList<String>();
cmd.add(binary.getAbsolutePath());
getLog().info("-------------------------------------------------------");
getLog().info(" C M A K E B U I L D E R T E S T");
getLog().info("-------------------------------------------------------");
StringBuilder bld = new StringBuilder();
bld.append(testName).append(": running ");
bld.append(binary.getAbsolutePath());
for (String entry : args) {
cmd.add(entry);
bld.append(" ").append(entry);
}
getLog().info(bld.toString());
ProcessBuilder pb = new ProcessBuilder(cmd);
Exec.addEnvironment(pb, env);
if (workingDirectory != null) {
pb.directory(workingDirectory);
}
pb.redirectError(new File(results, testName + ".stderr"));
pb.redirectOutput(new File(results, testName + ".stdout"));
getLog().info("with extra environment variables " + Exec.envToString(env));
Process proc = null;
TestThread testThread = null;
int retCode = -1;
String status = "IN_PROGRESS";
try {
writeStatusFile(status);
} catch (IOException e) {
throw new MojoExecutionException("Error writing the status file", e);
}
long start = System.nanoTime();
try {
proc = pb.start();
testThread = new TestThread(proc);
testThread.start();
testThread.join(timeout * 1000);
if (!testThread.isAlive()) {
retCode = testThread.retCode();
testThread = null;
proc = null;
}
} catch (IOException e) {
throw new MojoExecutionException("IOException while executing the test " + testName, e);
} catch (InterruptedException e) {
throw new MojoExecutionException("Interrupted while executing " + "the test " + testName, e);
} finally {
if (testThread != null) {
// If the test thread didn't exit yet, that means the timeout expired.
testThread.interrupt();
try {
testThread.join();
} catch (InterruptedException e) {
getLog().error("Interrupted while waiting for testThread", e);
}
status = "TIMED OUT";
} else if (retCode == 0) {
status = "SUCCESS";
} else {
status = "ERROR CODE " + String.valueOf(retCode);
}
try {
writeStatusFile(status);
} catch (Exception e) {
getLog().error("failed to write status file!", e);
}
if (proc != null) {
proc.destroy();
}
}
long end = System.nanoTime();
getLog().info("STATUS: " + status + " after " + TimeUnit.MILLISECONDS.convert(end - start, TimeUnit.NANOSECONDS) + " millisecond(s).");
getLog().info("-------------------------------------------------------");
if (status.equals("TIMED_OUT")) {
if (expectedResult.equals("success")) {
throw new MojoExecutionException("Test " + binary + " timed out after " + timeout + " seconds!");
}
} else if (!status.equals("SUCCESS")) {
if (expectedResult.equals("success")) {
throw new MojoExecutionException("Test " + binary + " returned " + status);
}
} else if (expectedResult.equals("failure")) {
throw new MojoExecutionException("Test " + binary + " succeeded, but we expected failure!");
}
}
use of org.apache.maven.plugin.MojoExecutionException in project che by eclipse.
the class DynaProviderMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
File outFile = new File(outputDirectory, typeName.replace('.', File.separatorChar) + ".java");
String packageName = typeName.substring(0, typeName.lastIndexOf('.'));
String className = typeName.substring(typeName.lastIndexOf('.') + 1, typeName.length());
DynaProviderGenerator generator = new DynaProviderGenerator(packageName, className, classpath);
try {
Files.createDirectories(outFile.toPath().getParent());
} catch (IOException e) {
throw new MojoExecutionException("Can't create packages folders", e);
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outFile))) {
writer.write(generator.generate());
} catch (IOException e) {
throw new MojoExecutionException("Can't write file content", e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project OpenAM by OpenRock.
the class CLIDefinitionGenerator method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
for (String className : definitions) {
try {
Class clazz = Class.forName(className);
Field pdtField = clazz.getDeclaredField("product");
if (pdtField != null) {
DefinitionClassInfo classInfo = pdtField.getAnnotation(DefinitionClassInfo.class);
PrintStream rbOut = createResourcePrintStream(outputDir, classInfo);
getCommonResourceStrings(rbOut, clazz);
rbOut.println("product-name=" + classInfo.productName());
getCommands(className, clazz, rbOut);
rbOut.close();
} else {
throw new Exception("Incorrect Definiton, class=" + className + " missing product field");
}
} catch (Exception ex) {
throw new MojoFailureException("An error occured while generating CLI resources", ex);
}
}
Resource resource = new Resource();
resource.setDirectory(outputDir);
project.addResource(resource);
}
use of org.apache.maven.plugin.MojoExecutionException in project OpenAM by OpenRock.
the class InjectContentTest method shouldThrowMojoExecutionExceptionWithUnknownContentConverter.
@Test(expectedExceptions = MojoExecutionException.class)
public void shouldThrowMojoExecutionExceptionWithUnknownContentConverter() throws MojoExecutionException, IOException {
//Given
File contentFile = mock(File.class);
BufferedReader destinationFileReader = mock(BufferedReader.class);
BufferedWriter tmpFileWriter = mock(BufferedWriter.class);
File temporaryFile = mock(File.class);
Inject inject = setUpInject("DEST_FILE_ABS_PATH", temporaryFile, destinationFileReader, tmpFileWriter, setUpContent("CONTENT_ID", contentFile));
inject.setContentConverter("unknown");
injects.add(inject);
given(ioFactory.createTemporaryFile(inject.getDestinationFile())).willReturn(temporaryFile);
given(destinationFileReader.readLine()).willReturn("${inject.content.CONTENT_ID}").willReturn(null);
//When
try {
injectContent.execute();
} catch (MojoExecutionException e) {
//Then
verify(destinationFileReader).close();
verify(tmpFileWriter).flush();
verify(tmpFileWriter).close();
throw e;
}
}
use of org.apache.maven.plugin.MojoExecutionException in project intellij-community by JetBrains.
the class MavenEffectivePomDumper method writeEffectivePom.
/**
* org.apache.maven.plugins.help.EffectivePomMojo#writeEffectivePom
*/
private static void writeEffectivePom(MavenProject project, XMLWriter writer) throws MojoExecutionException {
Model pom = project.getModel();
cleanModel(pom);
String effectivePom;
StringWriter sWriter = new StringWriter();
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
try {
pomWriter.write(sWriter, pom);
} catch (IOException e) {
throw new MojoExecutionException("Cannot serialize POM to XML.", e);
}
effectivePom = addMavenNamespace(sWriter.toString(), true);
writeComment(writer, "Effective POM for project \'" + project.getId() + "\'");
writer.writeMarkup(effectivePom);
}
Aggregations