Search in sources :

Example 16 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)

Example 17 with MojoExecutionException

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

the class PomConverter method writePom.

/**
   * Serializes the given DOM document into a POM file within the given directory.
   */
private static void writePom(Document document, File projectBaseDir) throws MojoExecutionException {
    try {
        File pomFile = new File(projectBaseDir, "pom.xml");
        // keep trailing whitespace because it's not reproduced by the transformer and we want to keep the diff small
        String pom = readFileToString(pomFile);
        String trailingWhitespace = pom.substring(pom.lastIndexOf('>') + 1);
        PrintWriter pomWriter = new PrintWriter(pomFile);
        try {
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            // the transformer does not reproduce the new line after the XML declaration, so we do it on our own
            // see https://bugs.openjdk.java.net/browse/JDK-7150637
            transformer.setOutputProperty(OMIT_XML_DECLARATION, "yes");
            if (document.getXmlEncoding() != null) {
                pomWriter.print("<?xml version=\"");
                pomWriter.print(document.getXmlVersion());
                pomWriter.print("\" encoding=\"");
                pomWriter.print(document.getXmlEncoding());
                pomWriter.println("\"?>");
            }
            transformer.transform(new DOMSource(document), new StreamResult(pomWriter));
            pomWriter.write(trailingWhitespace);
        } finally {
            pomWriter.close();
        }
    } catch (IOException e) {
        throw new MojoExecutionException("error while generating modified POM", e);
    } catch (TransformerException e) {
        throw new MojoExecutionException("error while generating modified POM", e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) IOException(java.io.IOException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException) PrintWriter(java.io.PrintWriter)

Example 18 with MojoExecutionException

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

the class PomConverter method removeExmlPlugin.

/**
   * Replaces exml-maven-plugin configuration by jangaroo-maven-plugin configuration within
   * {@code /project/build/plugins} and {@code /project/build/pluginManagement/plugins}.
   */
private static void removeExmlPlugin(Document document) throws MojoExecutionException {
    try {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        Node pluginsNode = (Node) xPath.evaluate("/project/build/plugins", document, NODE);
        removeExmlPlugin(pluginsNode);
        pluginsNode = (Node) xPath.evaluate("/project/build/pluginManagement/plugins", document, NODE);
        removeExmlPlugin(pluginsNode);
    } 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)

Example 19 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 20 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project asterixdb by apache.

the class GrammarExtensionMojo method processExtension.

private void processExtension() throws MojoExecutionException {
    try (BufferedReader reader = Files.newBufferedReader(Paths.get(base, gextension), StandardCharsets.UTF_8)) {
        StringBuilder identifier = new StringBuilder();
        String nextOperation = OVERRIDEPRODUCTION;
        while (read || (position.line = reader.readLine()) != null) {
            read = false;
            if (position.line.trim().startsWith("//")) {
                // skip comments
                continue;
            }
            String[] tokens = position.line.split(REGEX_WS_PAREN);
            position.index = 0;
            int openBraceIndex = position.line.indexOf(OPEN_BRACE);
            int openAngularIndex = position.line.trim().indexOf(OPEN_ANGULAR);
            if (tokens.length > 0 && identifier.length() == 0 && EXTENSIONKEYWORDS.contains(tokens[0])) {
                switch(tokens[0]) {
                    case KWIMPORT:
                        handleImport(reader);
                        break;
                    case KWUNIMPORT:
                        handleUnImport(reader);
                        break;
                    case NEWPRODUCTION:
                        nextOperation = NEWPRODUCTION;
                        break;
                    case NEW_AT_THE_END_PRODUCTION:
                        nextOperation = NEW_AT_THE_END_PRODUCTION;
                        break;
                    case NEW_AT_THE_END_CLASS_DEFINITION:
                        nextOperation = NEW_AT_THE_END_CLASS_DEFINITION;
                        break;
                    case MERGEPRODUCTION:
                        nextOperation = MERGEPRODUCTION;
                        shouldReplace = shouldReplace(tokens, position.line);
                        break;
                    case OVERRIDEPRODUCTION:
                        nextOperation = OVERRIDEPRODUCTION;
                        break;
                    default:
                        break;
                }
            } else if (openBraceIndex >= 0 && openAngularIndex < 0) {
                String beforeBrace = position.line.substring(0, openBraceIndex);
                if (beforeBrace.trim().length() > 0) {
                    identifier.append(beforeBrace);
                } else if (identifier.length() == 0) {
                    identifier.append(lastIdentifier);
                }
                position.index = openBraceIndex;
                switch(nextOperation) {
                    case NEWPRODUCTION:
                        handleNew(identifier, reader);
                        break;
                    case NEW_AT_THE_END_CLASS_DEFINITION:
                        readFinalProduction(identifier, reader);
                        addFinalProduction(identifier, extensionMethodsAtTheClassDef);
                        break;
                    case OVERRIDEPRODUCTION:
                        handleOverride(identifier, reader);
                        break;
                    case MERGEPRODUCTION:
                        handleMerge(identifier, reader);
                        break;
                    default:
                        throw new MojoExecutionException("Malformed extention file");
                }
                nextOperation = NEWPRODUCTION;
            } else if (openAngularIndex == 0) {
                if (nextOperation != NEWPRODUCTION && nextOperation != NEW_AT_THE_END_PRODUCTION) {
                    throw new MojoExecutionException("Can only add new REGEX production kind");
                }
                position.index = position.line.indexOf(OPEN_ANGULAR);
                readFinalProduction(identifier, reader);
                if (nextOperation == NEWPRODUCTION) {
                    addFinalProduction(identifier, extensionFinals);
                } else if (nextOperation == NEW_AT_THE_END_PRODUCTION) {
                    addFinalProduction(identifier, extensionFinalsAtTheEnd);
                }
            } else if (identifier.length() > 0 || position.line.trim().length() > 0) {
                identifier.append(position.line);
                identifier.append('\n');
            }
        }
    } catch (Exception e) {
        getLog().error(e);
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

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