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.capgemini.csd.utils.maven.plugin.debt.DebtMojo.java

License:Open Source License

@SuppressWarnings("unchecked")
private void executeWithExceptionsHandled() throws Exception {

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);

    getLog().debug("Got the Java Compiler and Java File Manager.");

    List<File> files = null;
    if (getSourceDirectory().exists()) {
        files = FileUtils.getFiles(getSourceDirectory(), "**/*.java", null);
    } else {//from  ww  w. j a  v a  2  s. c  o  m
        getLog().warn("No source files detected. @Debt Processor task will be skipped.");
        return;
    }

    getLog().debug("Got all the source files to analyse for @Debt annotations.");
    getLog().debug("Number of files: " + files.size());

    Iterable<? extends JavaFileObject> compilationUnits = null;

    if (files != null && !files.isEmpty()) {
        compilationUnits = fileManager.getJavaFileObjectsFromFiles(files);
    } else {
        getLog().warn("No source files detected. @Debt Processor task will be skipped.");
        return;
    }

    String compileClassPath = buildClassPath();

    getLog().debug("Compile classpath: " + compileClassPath);

    String processor = DEBT_PROCESSOR;

    List<String> options = new ArrayList<String>(10);

    options.add("-cp");
    options.add(compileClassPath);
    options.add("-proc:only");

    addCompilerArguments(options);

    if (processor != null) {
        options.add("-processor");
        options.add(processor);
    } else {
        getLog().debug("No @Debt processor found. Using default discovery mechanism.");
    }

    for (String option : options) {
        getLog().debug("javac option: " + option);
    }

    DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();

    CompilationTask task = compiler.getTask(new PrintWriter(System.out), fileManager, dc, options, null,
            compilationUnits);

    boolean result = false;
    try {
        result = task.call();
    } catch (Exception ex) {
        throw new MojoExecutionException(
                "There was an exception thrown while processing the @Debt annotations.", ex);
    }

    // Process the Diagnostics and fail the build if required
    for (Diagnostic<? extends JavaFileObject> diag : dc.getDiagnostics()) {
        getLog().info(diag.getMessage(null));

        if (!result && diag.getKind().equals(Diagnostic.Kind.ERROR)) {
            throw new MojoExecutionException(
                    "Processing the @Debt annotations failed. " + diag.getMessage(null));
        }
    }
}

From source file:com.carmatech.maven.MergeFilesMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    logger = getLog();/* w  ww. j  a v  a 2s  .co  m*/
    validateOperations();
    initializeOperations();

    try {
        mergeFiles();
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:com.carrotgarden.maven.batik.BatikMojo.java

License:BSD License

/**
 * {@inheritDoc}//from  ww  w  .j a v a2 s .c  o m
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    try {

        final String[] args = arguments.split("\\s+");

        getLog().info("batik: args = " + Arrays.toString(args));

        final Main main = new Main(args) {

            @Override
            public boolean proceedOnSourceTranscodingFailure(final SVGConverterSource source, final File dest,
                    final String errorCode) {

                super.proceedOnSourceTranscodingFailure(source, dest, errorCode);

                final String message = "batik: convert failed";
                getLog().error(message);
                throw new RuntimeException(message);

            }

            @Override
            public void validateConverterConfig(final SVGConverter c) {

                @SuppressWarnings("unchecked")
                final List<String> expandedSources = c.getSources();

                if ((expandedSources == null) || (expandedSources.size() < 1)) {

                    getLog().info(USAGE);

                    final String message = "batik: invalid config";

                    getLog().error(message);

                    throw new RuntimeException(message);

                }

            }

        };

        main.execute();

    } catch (final Throwable exception) {

        final String help = "http://xmlgraphics.apache.org/batik/tools/rasterizer.html";

        final String message = "batik: help @ " + help;

        getLog().error(message);

        throw new MojoExecutionException("batik: rasterize failed", exception);

    }

}

From source file:com.carrotgarden.maven.image4j.Image4jMojoMultiple.java

License:BSD License

/**
 * {@inheritDoc}//from   w w w . jav a2 s  .c o m
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    try {

        getLog().info("image4j : sources = " + sources);
        getLog().info("image4j : target = " + target);

        final List<BufferedImage> sources = new LinkedList<BufferedImage>();

        for (final File file : this.sources) {
            final BufferedImage source = ImageIO.read(file);
            sources.add(source);
        }

        this.target.getParentFile().mkdirs();

        ICOEncoder.write(sources, this.target);

    } catch (final Throwable exception) {

        throw new MojoExecutionException("image4j: convert failed", exception);

    }

}

From source file:com.carrotgarden.maven.image4j.Image4jMojoSingle.java

License:BSD License

/**
 * {@inheritDoc}/*from   w  ww .  jav  a  2 s.  c o  m*/
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    try {

        getLog().info("image4j : source = " + source);
        getLog().info("image4j : target = " + target);

        final BufferedImage source = ImageIO.read(this.source);

        this.target.getParentFile().mkdirs();

        ICOEncoder.write(source, this.target);

    } catch (final Throwable exception) {

        throw new MojoExecutionException("image4j: convert failed", exception);

    }

}

From source file:com.carrotgarden.maven.imgscalr.ImgscalrMojo.java

License:BSD License

/**
 * {@inheritDoc}//from w  w w  . j  a v  a  2s.  co  m
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    try {

        getLog().info("imgscalr : source = " + source);
        getLog().info("imgscalr : target = " + target);
        getLog().info("imgscalr : w x h = " + width + " x " + height);

        final BufferedImage source = ImageIO.read(this.source);

        final BufferedImage target = Scalr.resize(source, Method.QUALITY, Mode.AUTOMATIC, width, height);

        final String format = getFileExtension(this.target);

        this.target.getParentFile().mkdirs();

        ImageIO.write(target, format, this.target);

    } catch (final Throwable exception) {
        throw new MojoExecutionException("imgscalr: scale failed", exception);
    }

}

From source file:com.carrotgarden.maven.osgi.MakeArchiveMojo.java

License:BSD License

@Override
public void execute() throws MojoExecutionException {
    try {//from   w ww .ja  v  a  2 s . c o  m

        // LogScopeList();

        switch (projectFunction) {
        case NONE:
            makeNone();
            return;
        case FEATURE:
            makeFeature();
            return;
        case REPOSITORY:
            makeRepository();
            return;
        default:
            throw new IllegalStateException("unknown projectFunction : " + projectFunction);
        }

    } catch (Throwable e) {

        throw new MojoExecutionException("BADA-BOOM", e);

    }
}

From source file:com.carrotgarden.maven.osgi.MakeArchiveMojo.java

License:BSD License

protected void copyFile(File source, File target) throws MojoExecutionException {
    try {//from   w w w.j  a  v a2s .c  o  m

        getLog().info("COPY");

        FileUtils.copyFile(source, target);

    } catch (Exception e) {
        throw new MojoExecutionException("Error copying artifact from " + source + " to " + target, e);
    }
}

From source file:com.carrotgarden.maven.osgi.MakeFolderMojo.java

License:BSD License

protected void copyFile(File source, File target) throws MojoExecutionException {
    try {/*  w w  w . j av a 2  s. c o m*/

        getLog().info("COPY : " + target);

        FileUtils.copyFile(source, target);

    } catch (Exception e) {
        throw new MojoExecutionException("Error copying artifact from " + source + " to " + target, e);
    }
}

From source file:com.carrotgarden.maven.staging.StagingWagonMojo.java

License:BSD License

/**
 * discover artifact list assuming remote is a nexus server serving index
 *//*from  w ww. j  a v a  2 s  .  com*/
protected List<String> artifactList() throws MojoExecutionException {

    try {

        if (artifactList == null) {

            artifactList = new ArrayList<String>();

            final WebClient webClient = new WebClient();

            final String indexPath = localPath("index.html");

            final Element[] config = new Element[] { element("url", sourceServerURL), //
                    element("fromFile", remotePath()), //
                    element("toFile", indexPath), //
                    element("serverId", sourceServerId) //
            };

            executeMojo(wagonPlugin, "download-single", configuration(config),
                    executionEnvironment(project, session, manager) //
            );

            final String indexURL = "file:" + indexPath;

            final HtmlPage page = webClient.getPage(indexURL);

            @SuppressWarnings("unchecked")
            final List<HtmlAnchor> list = (List<HtmlAnchor>) page.getByXPath("//a");

            for (final HtmlAnchor anchor : list) {

                final String artifact = anchor.getTextContent().trim();

                if (artifact.startsWith(artifactPrefix())) {
                    artifactList.add(artifact);
                }

            }

        }

        return artifactList;

    } catch (final Throwable e) {

        throw new MojoExecutionException("can not get list", e);

    }

}