Search in sources :

Example 86 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project midpoint by Evolveum.

the class SchemaDocMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("SchemaDoc plugin started");
    PrismContext prismContext = createInitializedPrismContext();
    File outDir = initializeOutDir();
    PathGenerator pathGenerator = new PathGenerator(outDir);
    VelocityEngine velocityEngine = createVelocityEngine();
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    try {
        renderSchemaIndex(schemaRegistry, prismContext, velocityEngine, pathGenerator);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    for (PrismSchema schema : schemaRegistry.getSchemas()) {
        try {
            renderSchema(schema, prismContext, velocityEngine, pathGenerator);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    try {
        copyResources(outDir);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    File archiveFile = null;
    try {
        archiveFile = generateArchive(outDir, finalName + "-schemadoc.zip");
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    projectHelper.attachArtifact(project, "zip", "schemadoc", archiveFile);
    getLog().info("SchemaDoc plugin finished");
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) VelocityEngine(org.apache.velocity.app.VelocityEngine) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) PrismContext(com.evolveum.midpoint.prism.PrismContext) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry)

Example 87 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 88 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 89 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)

Example 90 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project jangaroo-tools by CoreMedia.

the class PomConverter method changePackaging.

/**
   * Changes the packaging from jangaroo to jangaroo-pkg in {@code /project/packaging}
   */
private static void changePackaging(Document document) throws MojoExecutionException {
    try {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        Node packagingNode = (Node) xPath.evaluate("/project/packaging[text() = 'jangaroo']", document, NODE);
        if (packagingNode != null) {
            packagingNode.setTextContent("jangaroo-pkg");
        }
    } catch (XPathException e) {
        throw new MojoExecutionException("error while generating modified POM", e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) XPathException(javax.xml.xpath.XPathException) Node(org.w3c.dom.Node)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)586 IOException (java.io.IOException)322 File (java.io.File)261 MojoFailureException (org.apache.maven.plugin.MojoFailureException)138 Artifact (org.apache.maven.artifact.Artifact)86 ArrayList (java.util.ArrayList)70 FileInputStream (java.io.FileInputStream)56 HashMap (java.util.HashMap)47 MavenProject (org.apache.maven.project.MavenProject)37 MalformedURLException (java.net.MalformedURLException)34 Map (java.util.Map)34 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)32 Properties (java.util.Properties)30 FileOutputStream (java.io.FileOutputStream)28 FileWriter (java.io.FileWriter)28 List (java.util.List)25 URL (java.net.URL)22 InputStream (java.io.InputStream)21 LinkedHashSet (java.util.LinkedHashSet)21 FileNotFoundException (java.io.FileNotFoundException)20