Example usage for org.apache.maven.plugin MojoExecutionException MojoExecutionException

List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException

Introduction

In this page you can find the example usage for org.apache.maven.plugin MojoExecutionException MojoExecutionException.

Prototype

public MojoExecutionException(String message, Throwable cause) 

Source Link

Document

Construct a new MojoExecutionException exception wrapping an underlying Throwable and providing a message.

Usage

From source file:com.adaptiweb.mojo.BuildNumberMojo.java

License:Apache License

private SVNStatus getSVNStatus(File file) throws MojoExecutionException {
    try {//w w  w  .  java2s. c om
        return getSVNManager().getStatusClient().doStatus(file, false);
    } catch (SVNException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:com.adgear.data.plugin.IDLSchemaMojo.java

License:Apache License

/**
 * Parses IDL source code for Avro Protocol.
 *
 * @param source IDL source code/*from w w  w  . java2s. c  om*/
 * @return Wrapping protocol object
 */

protected Protocol parseProtocol(String source) throws MojoExecutionException {
    ByteArrayInputStream input;
    try {
        input = new ByteArrayInputStream(source.getBytes(encoding));
    } catch (UnsupportedEncodingException e) {
        throw new MojoExecutionException("Unsupported encoding: " + encoding, e);
    }
    Idl idl = new Idl(input, encoding);
    try {
        return idl.CompilationUnit();
    } catch (ParseException e) {
        throw new MojoExecutionException("Error compiling Avro wrapping protocol :\n" + source, e);
    }
}

From source file:com.adgear.data.plugin.IDLSchemaMojo.java

License:Apache License

/**
 * Compile a schema in corresponding .java and .avsc files in the outputDir. Also compiles .csv
 * file for enumerations//from   www  .j  av  a  2  s  .  c o m
 *
 * @param s Schema to be compiled
 */
protected void compileSchema(Schema s, File outputDir) throws MojoExecutionException {
    /* compile .java output file */
    Compiler compiler = new Compiler(s);
    compiler.setStringType(GenericData.StringType.valueOf(stringType));
    compiler.setTemplateDir(templateDirectory);
    compiler.setFieldVisibility(getFieldVisibility());
    compiler.setCreateSetters(createSetters);
    try {
        compiler.compileToDestination(null, outputDir);
    } catch (IOException e) {
        throw new MojoExecutionException("Error compiling Avro schema " + s.getFullName(), e);
    }
    final String name = Compiler.mangle(s.getName());

    /* Write the schema */
    File schemaFile = new File(getDir(outputDir, s), name + ".avsc");
    try {
        FileUtils.write(schemaFile, s.toString(true), encoding);
    } catch (IOException e) {
        throw new MojoExecutionException("Could not write schema in: " + schemaFile.getPath(), e);
    }

    /* export other */
    switch (s.getType()) {
    case ENUM:
        try {
            FileUtils.write(new File(getDir(outputDir, s), name + ".csv"), toCSV(s), encoding);
        } catch (IOException e) {
            getLog().warn("Could not write " + name + " csv enumeration: " + e.getMessage());
        }
        try {
            FileUtils.write(getThriftFile(outputDir, s), ExportThrift.get().exportEnum(s), encoding);
        } catch (IOException e) {
            getLog().warn("Could not write " + name + " thrift enum schema: " + e.getMessage());
        }
        break;
    case RECORD:
        List<Schema> dependencies = ExportBase.collectDependencies(s, new ArrayList<Schema>(), false);
        Map<String, String> names = new HashMap<String, String>();
        Map<String, String> includePaths = new HashMap<String, String>();
        try {
            for (Schema dependentSchema : dependencies) {
                if (!dependentSchema.getFullName().equals(s.getFullName())) {
                    File includeFile = getThriftFile(outputDir, dependentSchema);
                    if (!includeFile.exists()) {
                        throw new IOException("Missing include file " + includeFile.getName());
                    }
                    names.put(dependentSchema.getFullName(),
                            includeFile.getName().replaceAll("\\.thrift$", ""));
                    includePaths.put(dependentSchema.getFullName(), includeFile.getName());
                }
            }
            FileUtils.write(getThriftFile(outputDir, s),
                    ExportThrift.get().exportRecord(s, includePaths, names), encoding);
        } catch (IOException e) {
            getLog().warn("Could not write " + name + " thrift struct schema: " + e.getMessage());
        }
    }
}

From source file:com.adobe.adobemarketingcloud.github.maven.scq.SecureCQMojo.java

License:Apache License

private boolean performTest(String componentName, AbstractTest test, Configuration configuration)
        throws MojoExecutionException {
    try {/* w  w  w  . j av a 2s.com*/
        test.test();

        if (TestResult.DISABLED == test.getResult()) {
            if (test instanceof DispatcherTest) {
                logDisabledTest(componentName, "authorUrl", "scq.url.author", authorUrl);
            } else if (test instanceof PublishTest) {
                logDisabledTest(componentName, "publishUrl", "scq.url.publish", publishUrl);
            } else if (test instanceof AuthorTest) {
                logDisabledTest(componentName, "dispatcherUrl", "scq.url.dispatcher", dispatcherUrl);
            } else {
                getLog().info("'" + componentName
                        + "' is disabled, skipping it - It may be possible that you haven't specified one of author/publish/dispatcher URL, please refere to plugin documentation.");
            }

            return true;
        }

        getLog().info("'" + componentName + "' result: " + test.getResult());

        if (!test.getErrorMessages().isEmpty()) {
            getLog().warn("'" + componentName + "' detected some failures:");

            for (String message : test.getErrorMessages()) {
                getLog().warn(" - " + message);
            }
        }

        if (!test.getInfoMessages().isEmpty()
                && !"true".equals(configuration.getStringValue("hidePassed", "false"))) {
            getLog().info("'" + componentName + "' passed tests:");

            for (String message : test.getInfoMessages()) {
                getLog().info(" - " + message);
            }
        }

        return TestResult.OK == test.getResult();
    } catch (IOException e) {
        throw new MojoExecutionException("An error occurred while loading test '" + componentName
                + "' configuration, see nested exceptions", e);
    }
}

From source file:com.adviser.maven.MergeFeaturesRepoMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {

    try {/*  w  ww  . j a  v  a 2 s .c  o m*/
        Set<String> bundles = new HashSet<String>();
        Map<String, Feature> featuresMap = new HashMap<String, Feature>();
        for (String uri : descriptors) {
            retrieveDescriptorsRecursively(uri, bundles, featuresMap);
        }
        writeFeatures(featuresMap);

    } catch (MojoExecutionException e) {
        throw e;
    } catch (MojoFailureException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("Error populating repository", e);
    }
}

From source file:com.adviser.maven.MergeFeaturesRepoMojo.java

License:Apache License

private void writeFeatures(Map<String, Feature> featuresMap) throws MojoExecutionException {
    //        /*  w  w  w . j  av  a 2  s.  c o  m*/
    try {
        TreeMap<String, Feature> sortedFeatureMap = new TreeMap<String, Feature>(featuresMap);

        File parent = outputFile.getParentFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }

        getLog().info("Generating " + outputFile.getAbsolutePath());

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.newDocument();

        Element rootElement = doc.createElement("features");
        rootElement.setAttribute("name", mergedRepoName);
        rootElement.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi",
                "http://karaf.apache.org/xmlns/features/v1.0.0");
        doc.appendChild(rootElement);

        //            out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        //            out.println("<features " + name);
        //            out.println("\txmlns=\"http://karaf.apache.org/xmlns/features/v1.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
        //            out.println("\txsi:schemaLocation=\"http://karaf.apache.org/xmlns/features/v1.0.0 http://karaf.apache.org/xmlns/features/v1.0.0\">");
        if (mergedRepoRepositories != null) {
            //                out.println("");
            for (String repo : mergedRepoRepositories) {
                Element repository = doc.createElement("repository");
                repository.setTextContent(repo);
                rootElement.appendChild(repository);
                //                    out.println("\t<repository>" + repo + "</repository>");
            }
        }
        for (Map.Entry<String, Feature> entry : sortedFeatureMap.entrySet()) {
            Feature feature = entry.getValue();
            if (includeFeaturesPrefixes != null) {
                for (String prefix : includeFeaturesPrefixes) {
                    if (feature.getName().startsWith(prefix)) {
                        getLog().info(" Generating feature " + feature.getName() + "/" + feature.getVersion()
                                + " from repo " + feature.getOriginalRepo());
                        rootElement.appendChild(feature.write(doc));
                    }
                }
            }
        }
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        //PrintStream out = new PrintStream(new FileOutputStream(outputFile));
        OutputStream out = new FileOutputStream(outputFile);
        transformer.transform(new DOMSource(doc), new StreamResult(out));
        out.close();
        //            out.println("</features>");
        getLog().info("...done!");
    } catch (Exception e) {
        getLog().error(e);
        throw new MojoExecutionException("Unable to create " + outputFile.getAbsolutePath() + " file: " + e, e);
    } finally {
    }

}

From source file:com.adviser.maven.MojoSupport.java

License:Apache License

/**
 * Set up a classloader for the execution of the main class.
 *
 * @return/*w  w  w  . j  a  v  a  2 s .  co  m*/
 * @throws MojoExecutionException
 */
protected URLClassLoader getClassLoader() throws MojoExecutionException {
    try {
        Set urls = new HashSet();

        URL mainClasses = new File(project.getBuild().getOutputDirectory()).toURL();
        getLog().debug("Adding to classpath : " + mainClasses);
        urls.add(mainClasses);

        URL testClasses = new File(project.getBuild().getTestOutputDirectory()).toURL();
        getLog().debug("Adding to classpath : " + testClasses);
        urls.add(testClasses);

        Set dependencies = project.getArtifacts();
        Iterator iter = dependencies.iterator();
        while (iter.hasNext()) {
            Artifact classPathElement = (Artifact) iter.next();
            getLog().debug("Adding artifact: " + classPathElement.getFile() + " to classpath");
            urls.add(classPathElement.getFile().toURL());
        }
        URLClassLoader appClassloader = new URLClassLoader((URL[]) urls.toArray(new URL[urls.size()]),
                this.getClass().getClassLoader());
        return appClassloader;
    } catch (MalformedURLException e) {
        throw new MojoExecutionException("Error during setting up classpath", e);
    }
}

From source file:com.agileapes.couteau.maven.mojo.AbstractPluginExecutor.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    ClassUtils.overrideThreadContextClassLoader(getProjectClassLoader());
    final List<PluginTask<?>> tasks = sortTasks(getTasks());
    final ThreadPoolTaskManager taskManager = new ThreadPoolTaskManager("TaskManager", getWorkers(), true);
    for (PluginTask task : tasks) {
        //noinspection unchecked
        task.setPluginExecutor(this);
        taskManager.schedule(task);/*from   w  ww.j  av a 2  s  .c om*/
    }
    final Thread taskManagerThread = new Thread(taskManager);
    taskManagerThread.start();
    try {
        taskManagerThread.join();
    } catch (InterruptedException e) {
        throw new MojoExecutionException("Failed to carry out tasks properly", e);
    }
}

From source file:com.agilejava.blammo.mojo.BlammoGeneratorMojo.java

License:Open Source License

public void produceImplementations(List loggers) throws MojoExecutionException {
    ClassLoader loader = this.getClass().getClassLoader();
    InputStream in = loader.getResourceAsStream("loggers.stg");
    Reader reader = new InputStreamReader(in);
    StringTemplateGroup group = new StringTemplateGroup(reader);
    StringTemplate template = group.getInstanceOf("logger");
    Iterator iterator = loggers.iterator();
    while (iterator.hasNext()) {
        Logger logger = (Logger) iterator.next();
        File out = new File(targetDirectory, logger.getImplementationFileName());
        template.setAttribute("logger", logger);
        template.setAttribute("includeId", new Boolean(includeId));
        template.setAttribute("renderClass", renderClass);
        template.setAttribute("renderFunction", renderFunction);
        try {//from ww  w .j ava2s  . c  o m
            out.getParentFile().mkdirs();
            FileUtils.writeStringToFile(out, template.toString(), null);
        } catch (IOException ioe) {
            throw new MojoExecutionException("Failed to write implementation file.", ioe);
        }
        template.reset();
    }
}

From source file:com.agilejava.blammo.mojo.BlammoGeneratorMojo.java

License:Open Source License

public void produceResourceFiles(List loggers) throws MojoExecutionException {
    ClassLoader loader = this.getClass().getClassLoader();
    InputStream in = loader.getResourceAsStream("resourceBundle.stg");
    Reader reader = new InputStreamReader(in);
    StringTemplateGroup group = new StringTemplateGroup(reader);
    StringTemplate template = group.getInstanceOf("logger");
    Iterator iterator = loggers.iterator();
    while (iterator.hasNext()) {
        Logger logger = (Logger) iterator.next();
        File out = new File(targetDirectory, logger.getResourceFileName());
        template.setAttribute("logger", logger);
        try {//from ww  w  .j a v a 2 s  .co m
            out.getParentFile().mkdirs();
            FileUtils.writeStringToFile(out, template.toString(), null);
        } catch (IOException ioe) {
            throw new MojoExecutionException("Failed to write implementation file.", ioe);
        }
        template.reset();
    }
}