Search in sources :

Example 96 with MojoExecutionException

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

the class JooTestMojo method executeSelenium.

void executeSelenium(String testsHtmlUrl) throws MojoExecutionException, MojoFailureException {
    jooUnitSeleniumRCHost = System.getProperty("SELENIUM_RC_HOST", jooUnitSeleniumRCHost);
    try {
        //check wether the host is reachable
        //noinspection ResultOfMethodCallIgnored
        InetAddress.getAllByName(jooUnitSeleniumRCHost);
    } catch (UnknownHostException e) {
        throw new MojoExecutionException("Cannot resolve host " + jooUnitSeleniumRCHost + ". Please specify a host running the selenium remote control or skip tests" + " by -DskipTests", e);
    }
    getLog().info("JooTest report directory: " + testResultOutputDirectory.getAbsolutePath());
    Selenium selenium = new DefaultSelenium(jooUnitSeleniumRCHost, jooUnitSeleniumRCPort, jooUnitSeleniumBrowserStartCommand, testsHtmlUrl);
    try {
        selenium.start();
        getLog().debug("Opening " + testsHtmlUrl);
        selenium.open(testsHtmlUrl);
        getLog().debug("Waiting for test results for " + jooUnitTestExecutionTimeout + "ms ...");
        selenium.waitForCondition("selenium.browserbot.getCurrentWindow().result != null || selenium.browserbot.getCurrentWindow().classLoadingError != null", "" + jooUnitTestExecutionTimeout);
        String classLoadingError = selenium.getEval("selenium.browserbot.getCurrentWindow().classLoadingError");
        if (classLoadingError != null && !classLoadingError.equals("null")) {
            throw new MojoExecutionException(classLoadingError);
        }
        String testResultXml = selenium.getEval("selenium.browserbot.getCurrentWindow().result");
        writeResultToFile(testResultXml);
        evalTestOutput(new StringReader(testResultXml));
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot write test results to file", e);
    } catch (ParserConfigurationException e) {
        throw new MojoExecutionException("Cannot create a simple XML Builder", e);
    } catch (SAXException e) {
        throw new MojoExecutionException("Cannot parse test result", e);
    } catch (SeleniumException e) {
        throw new MojoExecutionException("Selenium setup exception", e);
    } finally {
        selenium.stop();
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SeleniumException(com.thoughtworks.selenium.SeleniumException) StringReader(java.io.StringReader) DefaultSelenium(com.thoughtworks.selenium.DefaultSelenium) Selenium(com.thoughtworks.selenium.Selenium) DefaultSelenium(com.thoughtworks.selenium.DefaultSelenium) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 97 with MojoExecutionException

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

the class JooTestMojoBase method jettyRunTest.

protected Server jettyRunTest(boolean tryPortRange) throws MojoExecutionException {
    JettyWebAppContext handler;
    try {
        handler = new JettyWebAppContext();
        handler.setWebInfLib(findJars());
        handler.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
        List<Resource> baseResources = new ArrayList<Resource>();
        baseResources.add(toResource(new File(outputDirectory, "META-INF/resources")));
        baseResources.add(toResource(testOutputDirectory));
        for (org.apache.maven.model.Resource r : testResources) {
            File testResourceDirectory = new File(r.getDirectory());
            if (testResourceDirectory.exists()) {
                baseResources.add(toResource(testResourceDirectory));
            }
        }
        handler.setBaseResource(new ResourceCollection(baseResources.toArray(new Resource[baseResources.size()])));
        getLog().info("Using base resources " + baseResources);
        ServletHolder servletHolder = new ServletHolder("default", DefaultServlet.class);
        servletHolder.setInitParameter("cacheControl", "no-store, no-cache, must-revalidate, max-age=0");
        handler.addServlet(servletHolder, "/");
        getLog().info("Set servlet cache control to 'do not cache'.");
    } catch (Exception e) {
        throw wrap(e);
    }
    return startJetty(handler, tryPortRange);
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) JettyWebAppContext(org.mortbay.jetty.plugin.JettyWebAppContext) ArrayList(java.util.ArrayList) Resource(org.eclipse.jetty.util.resource.Resource) File(java.io.File) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) ResourceCollection(org.eclipse.jetty.util.resource.ResourceCollection)

Example 98 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project kotlin by JetBrains.

the class ExecuteKotlinScriptMojo method getKotlinRuntimeDependencies.

private List<File> getKotlinRuntimeDependencies() throws MojoExecutionException {
    Artifact stdlibDep = null;
    Artifact runtimeDep = null;
    ArrayList<File> files = new ArrayList<File>(2);
    for (Artifact dep : project.getArtifacts()) {
        if (dep.getArtifactId().equals("kotlin-stdlib")) {
            files.add(getArtifactFile(dep));
            stdlibDep = dep;
        }
        if (dep.getArtifactId().equals("kotlin-runtime")) {
            files.add(getArtifactFile(dep));
            runtimeDep = dep;
        }
        if (stdlibDep != null && runtimeDep != null)
            break;
    }
    if (stdlibDep == null) {
        throw new MojoExecutionException("Unable to find kotlin-stdlib artifacts among project dependencies");
    }
    return files;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 99 with MojoExecutionException

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

the class GenerateMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    List<String> toScan = getPackagesToScan();
    if (!sourcesChanged()) {
        getLog().info("Skipping blueprint generation because source files were not changed");
        return;
    }
    BlueprintConfigurationImpl blueprintConfiguration = new BlueprintConfigurationImpl(namespaces, defaultActivation, customParameters);
    try {
        ClassFinder classFinder = createProjectScopeFinder();
        Set<Class<?>> classes = FilteredClassFinder.findClasses(classFinder, toScan);
        Blueprint blueprint = new Blueprint(blueprintConfiguration, classes);
        writeBlueprintIfNeeded(blueprint);
    } catch (Exception e) {
        throw new MojoExecutionException("Error building commands help", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Blueprint(org.apache.aries.blueprint.plugin.model.Blueprint) ClassFinder(org.apache.xbean.finder.ClassFinder) MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 100 with MojoExecutionException

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

the class EbaMojo method writeApplicationManifest.

private void writeApplicationManifest(String fileName) throws MojoExecutionException {
    try {
        // TODO: add support for dependency version ranges. Need to pick
        // them up from the pom and convert them to OSGi version ranges.
        FileUtils.fileAppend(fileName, MANIFEST_VERSION + ": " + "1" + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_MANIFESTVERSION + ": " + "1" + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_SYMBOLICNAME + ": " + getApplicationSymbolicName(project.getArtifact()) + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_VERSION + ": " + getApplicationVersion() + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_NAME + ": " + project.getName() + "\n");
        FileUtils.fileAppend(fileName, APPLICATION_DESCRIPTION + ": " + project.getDescription() + "\n");
        // Write the APPLICATION-CONTENT
        // TODO: check that the dependencies are bundles (currently, the converter
        // will throw an exception)
        Set<Artifact> artifacts;
        if (useTransitiveDependencies) {
            artifacts = project.getArtifacts();
        } else {
            artifacts = project.getDependencyArtifacts();
        }
        artifacts = selectArtifacts(artifacts);
        Iterator<Artifact> iter = artifacts.iterator();
        FileUtils.fileAppend(fileName, APPLICATION_CONTENT + ": ");
        if (iter.hasNext()) {
            Artifact artifact = iter.next();
            FileUtils.fileAppend(fileName, maven2OsgiConverter.getBundleSymbolicName(artifact) + ";version=\"" + Analyzer.cleanupVersion(artifact.getVersion()) + //						+ maven2OsgiConverter.getVersion(artifact.getVersion())
            "\"");
        }
        while (iter.hasNext()) {
            Artifact artifact = iter.next();
            FileUtils.fileAppend(fileName, ",\n " + maven2OsgiConverter.getBundleSymbolicName(artifact) + ";version=\"" + Analyzer.cleanupVersion(artifact.getVersion()) + //						+ maven2OsgiConverter.getVersion(artifact.getVersion())
            "\"");
        }
        FileUtils.fileAppend(fileName, "\n");
        // Add any service imports or exports
        if (instructions.containsKey(APPLICATION_EXPORTSERVICE)) {
            FileUtils.fileAppend(fileName, APPLICATION_EXPORTSERVICE + ": " + instructions.get(APPLICATION_EXPORTSERVICE) + "\n");
        }
        if (instructions.containsKey(APPLICATION_IMPORTSERVICE)) {
            FileUtils.fileAppend(fileName, APPLICATION_IMPORTSERVICE + ": " + instructions.get(APPLICATION_IMPORTSERVICE) + "\n");
        }
        if (instructions.containsKey(APPLICATION_USEBUNDLE)) {
            FileUtils.fileAppend(fileName, APPLICATION_USEBUNDLE + ": " + instructions.get(APPLICATION_USEBUNDLE) + "\n");
        }
    // Add any use bundle entry
    } catch (Exception e) {
        throw new MojoExecutionException("Error writing dependencies into APPLICATION.MF", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException)

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