Search in sources :

Example 91 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 92 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 93 with MojoExecutionException

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

the class AbstractCompilerMojo method buildOutputFile.

private void buildOutputFile(File tempOutputDir, File outputFile) throws MojoExecutionException {
    final Log log = getLog();
    if (log.isDebugEnabled()) {
        log.debug("Output file: " + outputFile);
    }
    try {
        // If the directory where the output file is going to land
        // doesn't exist then create it.
        File outputFileDirectory = outputFile.getParentFile();
        if (!outputFileDirectory.exists()) {
            //noinspection ResultOfMethodCallIgnored
            if (outputFileDirectory.mkdirs()) {
                log.debug("created output directory " + outputFileDirectory);
            }
        }
        @SuppressWarnings({ "unchecked" }) List<File> // resource bundle classes should always be loaded dynamically:
        files = FileUtils.getFiles(tempOutputDir, "**/*.js", "**/*_properties_*.js");
        // We should now have all the files we want to concat so let's do it.
        Writer fos = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8");
        int tempOutputDirPathLength = tempOutputDir.getAbsolutePath().length() + 1;
        for (File file : files) {
            String className = file.getAbsolutePath();
            className = className.substring(tempOutputDirPathLength, className.length() - ".js".length());
            className = className.replace(File.separatorChar, '.');
            fos.write("// class " + className + "\n");
            IOUtil.copy(new FileInputStream(file), fos, "UTF-8");
            fos.write('\n');
        }
        fos.close();
    } catch (IOException e) {
        throw new MojoExecutionException("could not build output file " + outputFile + ": " + e.toString(), e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractCompileLog(net.jangaroo.jooc.AbstractCompileLog) Log(org.apache.maven.plugin.logging.Log) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) FileInputStream(java.io.FileInputStream)

Example 94 with MojoExecutionException

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

the class PropertiesMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (!generatedSourcesDirectory.exists()) {
        getLog().info("generating sources into: " + generatedSourcesDirectory.getPath());
        getLog().debug("created " + generatedSourcesDirectory.mkdirs());
    }
    if (properties == null) {
        properties = new FileSet();
        properties.setDirectory(resourceDirectory.getAbsolutePath());
        properties.addInclude("**/*.properties");
    }
    FileLocations config = new FileLocations();
    config.setOutputDirectory(generatedSourcesDirectory);
    for (String srcFileRelativePath : new FileSetManager().getIncludedFiles(properties)) {
        config.addSourceFile(new File(resourceDirectory, srcFileRelativePath));
    }
    try {
        config.setSourcePath(Arrays.asList(resourceDirectory));
    } catch (IOException e) {
        throw new MojoExecutionException("configuration failure", e);
    }
    PropertyClassGenerator generator = new PropertyClassGenerator(config);
    try {
        generator.generate();
    } catch (PropcException e) {
        throw new MojoExecutionException("Generation failure", e);
    }
}
Also used : FileSet(org.apache.maven.shared.model.fileset.FileSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) PropertyClassGenerator(net.jangaroo.properties.PropertyClassGenerator) PropcException(net.jangaroo.properties.api.PropcException) IOException(java.io.IOException) File(java.io.File) FileLocations(net.jangaroo.utils.FileLocations) FileSetManager(org.apache.maven.shared.model.fileset.util.FileSetManager)

Example 95 with MojoExecutionException

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

the class JooTestMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (!skip && !skipTests && !skipJooUnitTests && isTestAvailable()) {
        Server server = jettyRunTest(true);
        String url = getTestUrl(server);
        try {
            File testResultOutputFile = new File(testResultOutputDirectory, getTestResultFileName());
            File phantomTestRunner = new File(testResultOutputDirectory, "phantomjs-joounit-page-runner.js");
            FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("/net/jangaroo/jooc/mvnplugin/phantomjs-joounit-page-runner.js"), phantomTestRunner);
            final PhantomJsTestRunner phantomJsTestRunner = new PhantomJsTestRunner(phantomBin, url, testResultOutputFile.getPath(), phantomTestRunner.getPath(), jooUnitTestExecutionTimeout, jooUnitMaxRetriesOnCrashes, getLog());
            if (phantomJsTestRunner.canRun()) {
                executePhantomJs(testResultOutputFile, phantomJsTestRunner);
            } else {
                executeSelenium(url);
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot create local copy of phantomjs-joounit-page-runner.js", e);
        } finally {
            try {
                server.stop();
            } catch (Exception e) {
                // never mind we just couldn't step the selenium server.
                getLog().error("Could not stop test Jetty.", e);
            }
        }
    }
}
Also used : Server(org.eclipse.jetty.server.Server) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) File(java.io.File) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) UnknownHostException(java.net.UnknownHostException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SeleniumException(com.thoughtworks.selenium.SeleniumException)

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