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:$.MarkdownMojo.java

License:Apache License

/**
     * Compiles all markdown files located in the internal and external asset directories.
     * <p>/*from   www.  ja v  a 2s . c o  m*/
     * This is the main Mojo entry point. The {@code execute} method is invoked by the regular Maven execution.
     *
     * @throws MojoExecutionException if a markdown file cannot be processed
     */
    public void execute() throws MojoExecutionException {
        if (extensions == null || extensions.isEmpty()) {
            extensions = ImmutableList.of("md", "markdown");
        }

        if (instance == null) {
            instance = new PegDownProcessor(Extensions.ALL);
        }

        try {
            // The getResources method locates all the assets files from "src/main/resources/assets" (internal
            // assets) and "src/main/assets" (exernal assets) having on of the given extensions.
            for (File f : getResources(extensions)) {
                process(f);
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Error while processing a Markdown file", e);
        }

    }

From source file:$.MyMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
        File f = outputDirectory;

        if (!f.exists()) {
            f.mkdirs();/*from w  ww  . j  a va2 s . com*/
        }

        File touch = new File(f, "touch.txt");

        FileWriter w = null;
        try {
            w = new FileWriter(touch);

            w.write("touch.txt");
        } catch (IOException e) {
            throw new MojoExecutionException("Error creating file " + touch, e);
        } finally {
            if (w != null) {
                try {
                    w.close();
                } catch (IOException e) {
                    // ignore
                }
            }
        }
    }

From source file:$package.NetExecutableMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    try {/*from   w w w . ja  v a  2 s  . co  m*/
        netExecutableFactory
                .getNetExecutableFor(new ExecutableRequirement(vendor, null, frameworkVersion, profile),
                        getCommands(), null)
                .execute();
    } catch (ExecutionException e) {
        throw new MojoExecutionException("NPANDAY-xxx-000: Unable to execute: Vendor " + vendor
                + ", frameworkVersion = " + frameworkVersion + ", Profile = " + profile, e);
    } catch (PlatformUnsupportedException e) {
        throw new MojoExecutionException("NPANDAY-xxx-001: Platform Unsupported: Vendor " + vendor
                + ", frameworkVersion = " + frameworkVersion + ", Profile = " + profile, e);
    }
}

From source file:ants.and.food.MyMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    File f = outputDirectory;/*w  w  w . j a v  a 2  s.  c o m*/

    if (!f.exists()) {
        f.mkdirs();
    }

    File touch = new File(f, "touch.txt");

    FileWriter w = null;
    try {
        w = new FileWriter(touch);

        w.write("touch.txt");
    } catch (IOException e) {
        throw new MojoExecutionException("Error creating file " + touch, e);
    } finally {
        if (w != null) {
            try {
                w.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}

From source file:apparat.embedding.maven.AbstractApparatMojo.java

License:Open Source License

/**
 * {@inheritDoc}/*w w  w  .j a  va  2s  . c om*/
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final MavenLogAdapter logAdapter = new MavenLogAdapter(getLog());

    try {
        apparat.log.Log.setLevel(logAdapter.getLevel());
        apparat.log.Log.addOutput(logAdapter);

        if (null == overrideArtifact) {
            if (null != project) {
                processArtifact(project.getArtifact());

                for (final Artifact artifact : project.getAttachedArtifacts()) {
                    processArtifact(artifact);
                }
            }
        } else {
            if (!overrideArtifact.exists()) {
                if (failIfOverrideIsMissing) {
                    throw new MojoFailureException("File " + overrideArtifact + " does not exist.");
                } else {
                    getLog().warn("Override " + overrideArtifact + " is missing.");
                    return;
                }
            }

            try {
                processFile(overrideArtifact);
            } catch (final Throwable cause) {
                throw new MojoExecutionException("Apparat execution failed.", cause);
            }
        }
    } finally {
        apparat.log.Log.removeOutput(logAdapter);
    }
}

From source file:apparat.embedding.maven.AbstractApparatMojo.java

License:Open Source License

private void processArtifact(final Artifact artifact) throws MojoExecutionException, MojoFailureException {
    if (null == artifact) {
        return;/*w  w w  .j a  va 2 s  .c  o  m*/
    }

    final String artifactType = artifact.getType();
    if (artifactType.equals("swc") || artifactType.equals("swf")) {
        try {
            if (null != artifact.getFile()) {
                processFile(artifact.getFile());
            }
        } catch (final Throwable cause) {
            throw new MojoExecutionException("Apparat execution failed.", cause);
        }
    } else {
        getLog().debug("Skipped artifact since its type is " + artifactType + ".");
    }
}

From source file:aQute.bnd.maven.export.plugin.CreateLauncherMavenPlugin.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {/*from ww  w .  ja  v  a 2  s . c  o  m*/
        Collection<File> jarsToInclude = getDependecyFiles();
        JarsLauncher jarsLauncher;
        try {
            jarsLauncher = new JarsLauncher();
        } catch (Exception ex) {
            throw new MojoExecutionException("Exception in execution", ex);
        }
        addFrameworkJars(jarsLauncher);
        //projectLauncher.getRunpath().add(ROLE)
        for (File jarToInclude : jarsToInclude) {
            jarsLauncher.addRunBundle(jarToInclude);
        }
        if ("jar".equals(project.getArtifact().getType())) {
            final File thisArtifactJar = project.getArtifact().getFile();
            if (thisArtifactJar.exists()) {
                jarsLauncher.addRunBundle(thisArtifactJar);
            } else {
                getLog().warn(thisArtifactJar + " does not exist, nota dding to bundle.");
            }
        }
        OutputStream outStream;
        try (Jar jar = jarsLauncher.executable()) {
            buildDirectory.mkdirs();
            outStream = new FileOutputStream(new File(buildDirectory, finalName + "-launcher.jar"));
            jar.write(outStream);
        } catch (Exception ex) {
            throw new MojoExecutionException("Exception in execution", ex);
        }
        outStream.close();

    } catch (IOException ex) {
        throw new MojoExecutionException("Exception in execution", ex);
    }

}

From source file:aQute.bnd.maven.export.plugin.CreateLauncherMavenPlugin.java

License:Apache License

private void addFrameworkJar(JarsLauncher jarsLauncher, String groupId, String artifactId, String version)
        throws MojoExecutionException {
    Artifact external = new DefaultArtifact(groupId, artifactId, "jar", version);
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(external);/* w  w w . j a  v  a  2  s  .  co  m*/
    request.setRepositories(remoteRepos);

    getLog().info("Resolving artifact " + external + " from " + remoteRepos);

    ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(repoSession, request);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    File jar = result.getArtifact().getFile();
    jarsLauncher.addFrameworkJar(jar);
}

From source file:ar.com.fluxit.jqa.JQAMavenPlugin.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException {
    try {/*from w  w  w. j av a  2 s. c  o m*/
        if ("pom".equals(this.packaging)) {
            getLog().info("Artifact ignored because it has pom packaging");
        } else {
            checkParams();
            String sourceJavaVersion = getSourceJavaVersion(this.project);
            getLogger().info("The source Java version is " + sourceJavaVersion);
            doExecute(this.outputDirectory, new File(this.project.getBuild().getOutputDirectory()),
                    new File(this.project.getBuild().getTestOutputDirectory()), this.project, this.sourceDir,
                    sourceJavaVersion);
        }
    } catch (final Exception e) {
        throw new MojoExecutionException("An error occurred while executing the rules", e);
    }
}

From source file:at.bestsolution.bindex.BIndexMojo.java

License:Open Source License

public void execute() throws MojoExecutionException {
    getLog().info("Hello, world.");
    getLog().info("repoDir" + repoDir);
    getLog().info("indexFile " + indexFile);

    final RepoIndex repoIndex = new RepoIndex();

    final Set<File> files = new HashSet<>();
    try {//from  w  w w .ja  va  2 s  .com
        Files.walkFileTree(Paths.get(repoDir.toURI()), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                getLog().debug("Checking " + file);
                if (file.getFileName().toString().endsWith(".jar")) {
                    getLog().debug("Adding " + file);
                    files.add(file.toFile());
                }
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        throw new MojoExecutionException("damn it", e);
    }

    Path indexFilePath = Paths.get(indexFile.toURI());

    if (!Files.exists(indexFilePath)) {
        try {
            Files.createFile(indexFilePath);
        } catch (IOException e) {
            throw new MojoExecutionException("damn it", e);
        }
    }

    try (OutputStream out = Files.newOutputStream(indexFilePath)) {
        repoIndex.index(files, out, buildConfiguration());
    } catch (IOException e) {
        throw new MojoExecutionException("damn it", e);
    } catch (Exception e) {
        throw new MojoExecutionException("damn it", e);
    }

}