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.anuta.internal.YangHelperMojo.java

License:Open Source License

public void executeGoal(OperationType operationType) throws MojoExecutionException, MojoFailureException {

    Log log = getLog();/*ww  w.  ja  v a 2s  .co  m*/
    if (null != excludes && excludes.length > 0) {
        for (String excl : excludes) {
            log.info("Excluding file " + excl);
        }
    }

    if (!isPyangInstalled()) {
        log.error("Pyang is not installed. Skip conversion.");
        return;
    }

    long startClock = System.currentTimeMillis();

    createResourceCollection();

    List files = new ArrayList();
    try {
        if (directories != null) {
            for (File directory : directories) {
                if (directory.exists() && directory.isDirectory()) {
                    collection.setBaseDir(directory);
                    addCollectionFiles(files);
                }
            }
        } else if (this.sourceDirectory != null && this.sourceDirectory.exists()
                && this.sourceDirectory.isDirectory()) {
            log.info("Using Source Directory." + this.sourceDirectory);
            collection.setBaseDir(this.sourceDirectory);
            addCollectionFiles(files);
        } else {
            log.error("No source directory specified to scan yang files.");
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to find files using includes/excludes", e);
    }

    int numberOfFiles = files.size();

    log.info("Number of files for " + operationType + " " + numberOfFiles);
    if (numberOfFiles > 0) {

        String basedirPath = getBasedirPath();
        Properties hashCache = readFileHashCacheFile();
        ResultCollector resultCollector = new ResultCollector();
        for (int i = 0, n = files.size(); i < n; i++) {
            File file = (File) files.get(i);
            performOperation(file, resultCollector, hashCache, basedirPath);
        }
        log.info("\nOperation            : " + operationType);
        log.info("Number of yang files : " + numberOfFiles);
        log.info("Successful           : " + resultCollector.successCount + " file(s)");
        log.info("Failed               : " + resultCollector.failCount + " file(s)");
        log.info("Skipped              : " + resultCollector.skippedCount + " file(s)\n");
        storeFileHashCache(hashCache);
        long endClock = System.currentTimeMillis();

        log.info("Approximate time taken: " + ((endClock - startClock) / 1000) + "s");
    }
}

From source file:com.appsec.maven.wsit.WsitCleanMojo.java

License:Open Source License

public void execute() throws MojoExecutionException, MojoFailureException {
    try {//from ww  w. j  ava 2s.  c o  m
        checkProperties();

        final File output;
        if (null != todir) {
            WSITBTUtil.doMkDirs(todir);
            output = new File(todir.getAbsoluteFile(), file.getName());
        } else {
            output = tofile;
        }

        getLog().info("Stripping wsit configuration from " + file.getAbsolutePath());
        WsitDocument wsitDoc = WsitDocument.parse(file);
        wsitDoc.stripWsitConfiguration();

        getLog().info("Saving file to " + output.getAbsolutePath());
        wsitDoc.save(output);
    } catch (MojoFailureException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to strip wsit configuration from file", e);
    }
}

From source file:com.appsec.maven.wsit.WsitClientMojo.java

License:Open Source License

public void execute() throws MojoExecutionException, MojoFailureException {
    try {/*w w w.  ja  v  a 2s  .co m*/
        //Validate properties.
        checkProperties();

        WSITBTUtil.doMkDirs(outputdir);

        //If outputfile is not specified, set it to the name of the wsdl file with a .xml extension.
        if (outputfile == null) {
            outputfile = wsdl.getName();
            outputfile = outputfile.substring(0, outputfile.lastIndexOf('.')) + ".xml";
        }

        final File wsitOut = new File(outputdir.getAbsoluteFile(), outputfile);
        FileUtils.copyFile(wsdl, wsitOut);

        WsitDocument wsitDoc = WsitDocument.parse(wsitOut, true);

        if (null != policy) {
            getLog().debug("Using policies from " + policy.getAbsolutePath());
            wsitDoc.mergePolicy(policy);
        } else {
            Document defaultPolicy = createDefaultPolicyDocument();
            wsitDoc.mergePolicy(defaultPolicy);
        }

        wsitDoc.setBindingPolicy(this.bindingpolicy);

        getLog().info("Creating " + wsitOut.getAbsolutePath());
        wsitDoc.save(wsitOut);

        //Create a new wsit-client.xml or update it if it exists.
        final File clientOut = new File(outputdir.getAbsoluteFile(), "wsit-client.xml");

        final WsitDocument clientDoc;
        if (clientOut.exists()) {
            getLog().info("Updating WSIT client configuration " + clientOut.getAbsolutePath());
            clientDoc = WsitDocument.parse(clientOut);
        } else {
            getLog().info("Creating WSIT client configuration " + clientOut.getAbsolutePath());
            clientDoc = WsitDocument.newDocument("mainclientconfig");
        }

        clientDoc.importWsitDocument(wsitDoc, wsitOut.getName());
        clientDoc.save(clientOut);

        project.addCompileSourceRoot(outputdir.getAbsolutePath());
        Resource resource = new Resource();
        resource.setDirectory(outputdir.getAbsolutePath());
        project.addResource(resource);
    } catch (MojoFailureException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("wsit-client failed to generate client config.", e);
    }
}

From source file:com.appsec.maven.wsit.WsitServiceMojo.java

License:Open Source License

public void execute() throws MojoExecutionException, MojoFailureException {
    try {/*from ww w .jav  a  2s. c  o  m*/
        checkProperties();

        WSITBTUtil.doMkDirs(outputdir);
        final File output = new File(outputdir.getAbsoluteFile(), "wsit-" + classname + ".xml");
        getLog().info("Creating " + output.getAbsolutePath());

        FileUtils.copyFile(wsdl, output);

        WsitDocument wsitDoc = WsitDocument.parse(output, true);
        wsitDoc.mergePolicy(policy);
        wsitDoc.setBindingPolicy(bindingpolicy);
        wsitDoc.setInputPolicy(inputpolicy);
        wsitDoc.setOutputPolicy(outputpolicy);
        wsitDoc.setFaultPolicy(faultpolicy);

        wsitDoc.save(output);

        if (this.updatewsdl) {
            final File wsdlout;
            if (this.wsdloutdir != null) {
                WSITBTUtil.doMkDirs(wsdloutdir);
                wsdlout = new File(wsdloutdir.getAbsolutePath(), wsdl.getName());
            } else {
                wsdlout = new File(outputdir.getAbsolutePath(), wsdl.getName());
            }
            getLog().info("Saving updated wsdl to " + wsdlout.getAbsolutePath());
            wsitDoc.stripWsitConfiguration();
            wsitDoc.save(wsdlout);
        }

        project.addCompileSourceRoot(outputdir.getAbsolutePath());
        Resource resource = new Resource();
        resource.setDirectory(outputdir.getAbsolutePath());
        project.addResource(resource);
    } catch (MojoFailureException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to generate wsit configuration", e);
    }
}

From source file:com.argonio.gora.AbstractGoraMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException {
    try {/*from  w ww  .j av  a 2  s  .c o  m*/
        compile();
        registerSourceDirectory(project, getSourcesDirectory().getPath());
        registerSourceDirectory(project, getOutputDirectory().getPath());
    } catch (IOException e) {
        throw new MojoExecutionException("Could not compile schema in " + getSourcesDirectory(), e);
    }
}

From source file:com.arhs.mojo.pack200.AbstractPluginMojo.java

License:Open Source License

/**
 * Perform whatever build-process behavior this Mojo implements.
 *
 * @throws MojoExecutionException If an unexpected problem occurs. Throwing this exception
 *                                causes a <b>BUILD ERROR</b> message to be displayed.
 *///from  w  ww .j  ava  2s .  com
public void execute() throws MojoExecutionException {
    try {
        executeCommand();
    } catch (IOException e) {
        throw new MojoExecutionException("Command is failed.", e);
    }
}

From source file:com.ariatemplates.attester.maven.ArtifactExtractor.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    try {/*w w w .  j a  v a  2  s. c om*/
        Map<?, ?> context = getPluginContext();
        PluginDescriptor pluginDescriptor = (PluginDescriptor) context.get("pluginDescriptor");
        Model projectModel = project.getModel();
        for (Dependency dependency : pluginDescriptor.getPlugin().getDependencies()) {
            if ("zip".equalsIgnoreCase(dependency.getType())) {
                String outputDirectory = inplaceExtractDependency(session.getLocalRepository(), dependency);
                projectModel.addProperty(getPropertyName(dependency), outputDirectory);
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error", e);
    }
}

From source file:com.arloz.maven.StatisticMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    init();//from  ww w. j  av a 2  s . com
    try {
        countDir(getOutputResultFile("src"), sourcedir);
        countDir(getOutputResultFile("test"), testSourcedir);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to count lines of code", e);
    }

}

From source file:com.asual.summer.bundle.BundleDescriptorMojo.java

License:Apache License

public void execute() throws MojoExecutionException {

    try {/*from w  ww. ja  v  a2  s  .  co m*/

        String webXml = "WEB-INF/web.xml";
        File warDir = new File(buildDirectory, finalName);
        File warFile = new File(buildDirectory, finalName + ".war");
        File webXmlFile = new File(warDir, webXml);
        FileUtils.copyFile(new File(basedir, "src/main/webapp/" + webXml), webXmlFile);

        Configuration[] configurations = new Configuration[] { new WebXmlConfiguration(),
                new FragmentConfiguration() };
        WebAppContext context = new WebAppContext();
        context.setDefaultsDescriptor(null);
        context.setDescriptor(webXmlFile.getAbsolutePath());
        context.setConfigurations(configurations);

        for (Artifact artifact : artifacts) {
            JarInputStream in = new JarInputStream(new FileInputStream(artifact.getFile()));
            while (true) {
                ZipEntry entry = in.getNextEntry();
                if (entry != null) {
                    if ("META-INF/web-fragment.xml".equals(entry.getName())) {
                        Resource fragment = Resource
                                .newResource("file:" + artifact.getFile().getAbsolutePath());
                        context.getMetaData().addFragment(fragment, Resource
                                .newResource("jar:" + fragment.getURL() + "!/META-INF/web-fragment.xml"));
                        context.getMetaData().addWebInfJar(fragment);
                    }
                } else {
                    break;
                }
            }
            in.close();
        }

        for (int i = 0; i < configurations.length; i++) {
            configurations[i].preConfigure(context);
        }

        for (int i = 0; i < configurations.length; i++) {
            configurations[i].configure(context);
        }

        for (int i = 0; i < configurations.length; i++) {
            configurations[i].postConfigure(context);
        }

        Descriptor descriptor = context.getMetaData().getWebXml();
        Node root = descriptor.getRoot();

        List<Object> nodes = new ArrayList<Object>();
        List<FragmentDescriptor> fragmentDescriptors = context.getMetaData().getOrderedFragments();
        for (FragmentDescriptor fd : fragmentDescriptors) {
            for (int i = 0; i < fd.getRoot().size(); i++) {
                Object el = fd.getRoot().get(i);
                if (el instanceof Node && ((Node) el).getTag().matches("^name|ordering$")) {
                    continue;
                }
                nodes.add(el);
            }
        }
        root.addAll(nodes);

        BufferedWriter writer = new BufferedWriter(new FileWriter(new File(warDir, webXml)));
        writer.write(root.toString());
        writer.close();

        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(warFile));
        zip(warDir, warDir, zos);
        zos.close();

    } catch (Exception e) {
        getLog().error(e.getMessage(), e);
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:com.asual.summer.bundle.BundleResourcesMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {

    try {//from   w w  w. java 2s  . co  m

        for (Resource resource : resources) {

            File targetDirectory = outputDirectory;

            if (resource.getTargetPath() != null) {
                targetDirectory = new File(outputDirectory, resource.getTargetPath());
            }

            DirectoryScanner scanner = new DirectoryScanner();
            scanner.setBasedir(new File(resource.getDirectory()));
            scanner.setIncludes(new String[] { "**/*.html" });
            scanner.scan();

            for (String name : scanner.getIncludedFiles()) {

                File file = new File(targetDirectory + "/" + name);
                InputStream in = null;
                OutputStream out = null;
                byte[] bytes = null;

                try {
                    in = new FileInputStream(file);
                    bytes = FacesResourceProcessor.execute(file.toURI().toURL(), new FileInputStream(file),
                            encoding);
                } finally {
                    IOUtil.close(in);
                }

                if (bytes != null) {
                    try {
                        out = new FileOutputStream(file);
                        out.write(bytes);
                    } finally {
                        IOUtil.close(out);
                    }
                }
            }
        }

    } catch (Exception e) {
        getLog().error(e.getMessage(), e);
        throw new MojoExecutionException(e.getMessage(), e);
    }
}