Search in sources :

Example 11 with MojoExecutionException

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!");
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File)

Example 12 with MojoExecutionException

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 13 with MojoExecutionException

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);
}
Also used : Field(java.lang.reflect.Field) PrintStream(java.io.PrintStream) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Resource(org.apache.maven.model.Resource) DefinitionClassInfo(com.sun.identity.cli.annotation.DefinitionClassInfo) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 14 with MojoExecutionException

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;
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BufferedReader(java.io.BufferedReader) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Test(org.testng.annotations.Test)

Example 15 with MojoExecutionException

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);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1221 IOException (java.io.IOException)656 File (java.io.File)572 MojoFailureException (org.apache.maven.plugin.MojoFailureException)275 Artifact (org.apache.maven.artifact.Artifact)162 ArrayList (java.util.ArrayList)151 FileInputStream (java.io.FileInputStream)77 MavenProject (org.apache.maven.project.MavenProject)76 HashMap (java.util.HashMap)68 Properties (java.util.Properties)63 FileOutputStream (java.io.FileOutputStream)61 Map (java.util.Map)60 URL (java.net.URL)59 MalformedURLException (java.net.MalformedURLException)57 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)52 FileWriter (java.io.FileWriter)50 List (java.util.List)49 URLClassLoader (java.net.URLClassLoader)45 LinkedHashSet (java.util.LinkedHashSet)40 InputStream (java.io.InputStream)38