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.bluetrainsoftware.maven.jaxrs2typescript.MainMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException {
    try {/* w  w  w. j  ava2s  .  com*/
        sourceModules.forEach(module -> {
            Set<Class<?>> classesToExport = new HashSet<>();

            if (module.getClassName() != null) {
                addClassByName(module.getClassName(), classesToExport);
            }

            if (module.getClassNames() != null && module.getClassNames().size() > 0) {
                module.getClassNames().stream().forEach(name -> addClassByName(name, classesToExport));
            }

            if (module.getPackageName() != null) {
                new FastClasspathScanner(module.getPackageName())
                        .matchClassesWithAnnotation(Path.class, classesToExport::add).scan();
            }

            if (classesToExport.size() > 0) {
                exportModule(module, classesToExport);
            } else {
                getLog().error(String.format("found no classes or interfaces in package/path `%s`",
                        module.getTypescriptModule()));
            }
        });

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

From source file:com.bluexml.side.Integration.m2.ampMojo.AbstractAmpMojo.java

License:Open Source License

public void buildExplodedAmp(File webappDirectory) throws MojoExecutionException, MojoFailureException {
    webappDirectory.mkdirs();/* www . j  av a 2  s .c o m*/

    try {
        buildAmp(mProject, webappDirectory);
    } catch (IOException e) {
        throw new MojoExecutionException("Could not build AMP", e);
    }
}

From source file:com.bluexml.side.Integration.m2.ampMojo.AmpWithAttachementMojo.java

License:Open Source License

/**
 * Executes the WarMojo on the current project.
 * //from w w w  .j a v  a  2  s. c o  m
 * @throws MojoExecutionException
 *             if an error occured while building the webapp
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    File vAmpFile = AmpWithAttachementMojo.getAmpFile(new File(getOutputDirectory()), getAmpName(),
            getClassifier());

    try {
        this.performPackaging(vAmpFile);
    } catch (Exception eAssemblyFailure) {
        /*
         * behavior is the same for the following exceptions:
         * DependencyResolutionRequiredException ManifestException
         * IOException ArchiverException
         */
        throw new MojoExecutionException("Error assembling AMP: " + eAssemblyFailure.getMessage(),
                eAssemblyFailure);
    }
}

From source file:com.bluexml.side.integration.m2.zipPackage.ZipPackage.java

License:Open Source License

/**
 * use Ant to package all resources and jar
 * /*from  w  ww.j  av  a  2s .  co m*/
 * @throws MojoExecutionException
 */
public void makePackage() throws MojoExecutionException {
    // run ant script (much friendly)
    Project project = new Project();
    project.init();
    DefaultLogger logger = new AntLogger(getLog());
    logger.setMessageOutputLevel(Project.MSG_INFO);
    logger.setErrorPrintStream(System.err);
    logger.setOutputPrintStream(System.out);
    project.addBuildListener(logger);

    Properties props = getProject().getProperties();
    getLog().info("Properties :" + getProject().getArtifact().getFile());
    for (Map.Entry<Object, Object> iterable_element : props.entrySet()) {
        getLog().info(iterable_element.getKey() + " : " + iterable_element.getValue());

    }

    project.setProperty("ant.file", getBuildFile().getAbsolutePath());
    project.setUserProperty("module.version", getProject().getVersion());
    project.setUserProperty("module.title", getProject().getName());
    project.setUserProperty("module.description", getProject().getDescription());
    project.setUserProperty("module.id", getProject().getArtifactId());
    project.setUserProperty("baseDir", getProject().getBasedir().toString());
    project.setUserProperty("finalName", getFinalName());
    project.setBaseDir(getProject().getBasedir());

    ProjectHelper.configureProject(project, getBuildFile());

    try {
        getLog().debug("launch ant script");
        project.executeTarget("package");
    } catch (Exception e) {
        e.printStackTrace();
        throw new MojoExecutionException(e.getMessage(), e);
    }
    getLog().debug("ant task finished");
}

From source file:com.bluexml.side.integration.m2.zipPackage.ZipPackage.java

License:Open Source License

public File getBuildFile() throws MojoExecutionException {
    if (antBuidFile == null) {
        String path = "build.xml";
        String buildFilePath = "";
        InputStream in = ZipPackage.class.getClassLoader().getResourceAsStream(path);
        getLog().debug("Get Stream :" + in);
        try {//from ww w  . j av a2s  . com
            antBuidFile = File.createTempFile("makePackage", "buildFile");
            writeStreamInFile(antBuidFile, in);
            buildFilePath = antBuidFile.getAbsolutePath();
        } catch (Exception e) {
            throw new MojoExecutionException("Error when creating tempory file", e);
        }
        if (buildFilePath == null) {
            throw new MojoExecutionException("Erreur when getting ant script");
        }
    }
    return antBuidFile;
}

From source file:com.brobston.indelible.processor.PreprocessorMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    boolean hasConfigError = false;
    if (!getSourceDirectory().isDirectory()) {
        getLog().error(String.format("The source directory '%0' is not a directory", getSourceDirectory()));
        hasConfigError = true;/*from  www  .jav a  2 s . co  m*/
    }
    if (!getOutputDirectory().isDirectory()) {
        getLog().error(String.format("The output directory '%0' is not a directory", getOutputDirectory()));
        hasConfigError = true;
    }
    if (!getPreprocessOutputDirectory().isDirectory()) {
        getLog().error(String.format("The preprocess output directory '%0' is not a directory",
                getPreprocessOutputDirectory()));
        hasConfigError = true;
    }

    if (hasConfigError) {
        throw new MojoFailureException("There were configuration errors.  Please see the log.");
    }

    Injector childInjector = injector.createChildInjector(new Module() {
        @Override
        public void configure(Binder binder) {
            binder.bind(File.class).annotatedWith(SourceDirectory.class).toInstance(getSourceDirectory());
            binder.bind(File.class).annotatedWith(OutputDirectory.class).toInstance(getOutputDirectory());
            binder.bind(File.class).annotatedWith(PreprocessOutputDirectory.class)
                    .toInstance(getPreprocessOutputDirectory());
            binder.bind(String.class).annotatedWith(Encoding.class).toInstance(getEncoding());
        }
    });

    CodeFileProcessorFactory codeFileProcessorFactory = childInjector
            .getInstance(CodeFileProcessorFactory.class);
    CodeMetadataFactory codeMetadataFactory = childInjector.getInstance(CodeMetadataFactory.class);
    Provider<CodeMetadataPersistence> codeMetadataPersistenceProvider = childInjector
            .getProvider(CodeMetadataPersistence.class);

    try {
        getJavaFiles(getSourceDirectory()).map(codeFileProcessorFactory::create).parallel()
                .<CodeMetadata>flatMap(
                        codeFileProcessor -> Throwables.propagate(codeFileProcessor::getClassNamesInFile)
                                .stream().map(codeMetadataFactory::create).peek(new Consumer<CodeMetadata>() {
                                    @Override
                                    public void accept(CodeMetadata codeMetadata) {
                                        try {
                                            codeFileProcessor.process(codeMetadata);
                                        } catch (Exception e) {
                                            throw com.google.common.base.Throwables.propagate(e);
                                        }
                                    }
                                }))
                .forEach(codeMetadata -> codeMetadataPersistenceProvider.get().save(codeMetadata));
    } catch (Exception e) {
        throw new MojoExecutionException("IOException", e);
    }
}

From source file:com.bsiag.geneclipsetoc.maven.GenerateEclipseTocMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    List<String> pList;
    if (pages.isEmpty() && pagesListFile == null) {
        throw new MojoFailureException("No pages list defined, add <" + PAGES + "> or <" + PAGES_LIST_FILE
                + "> in your configuration");
    } else if (pagesListFile != null) {
        if (!pages.isEmpty()) {
            throw new MojoFailureException("The pages list is defined using a file (<" + PAGES_LIST_FILE
                    + "> is set),  <" + PAGES + "> configuration can not be used");
        }/* ww w. ja v a2  s .  c o  m*/
        try {
            pList = Files.readLines(pagesListFile, Charsets.UTF_8);
        } catch (IOException e) {
            throw new MojoFailureException("Error while reading the file defined in <" + PAGES_LIST_FILE + ">",
                    e);
        }
    } else {
        pList = pages;
    }

    try {
        GenerateEclipseTocUtility.generate(sourceFolder, pList, helpPrefix, outputTocFile, outputContextsFile,
                helpContexts);
    } catch (IOException e) {
        throw new MojoExecutionException("Error while generating the toc file", e);
    }
    getLog().info("Generated toc file: " + outputTocFile);
}

From source file:com.bt.gs.MyMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    File f = outputDirectory;//from w w w .ja va 2  s  .  c om

    log.debug("outputdirectory = ${project.build.directory}");
    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:com.btmatthews.maven.plugins.crx.CRXMojo.java

License:Apache License

/**
 * Build a list of filter wrappers./*from w  w w.  j a  v  a 2 s  .c o m*/
 *
 * @return The list of filter wrappers.
 * @throws MojoExecutionException If there was a problem building the list of filter wrappers.
 * @since 1.2.0
 */
private List getFilterWrappers() throws MojoExecutionException {
    if (filterWrappers == null) {
        try {
            final MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
            mavenResourcesExecution.setEscapeString("\\");
            filterWrappers = mavenFileFilter.getDefaultFilterWrappers(project, filters, true, session,
                    mavenResourcesExecution);
        } catch (final MavenFilteringException e) {
            throw new MojoExecutionException("Failed to build filtering wrappers: " + e.getMessage(), e);
        }
    }
    return filterWrappers;
}

From source file:com.btmatthews.maven.plugins.crx.CRXVerifyMojo.java

License:Apache License

/**
 * Called when the Maven plug-in is executing. It loads and verifies the signature of a CRX archive.
 *
 * @throws MojoExecutionException If there was an error that should stop the build.
 * @throws MojoFailureException   If there was an error but the build might be allowed to continue.
 *///from w w w.  jav a  2 s.  c  o m
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {

    final File crxFile;

    if (crxPath == null) {

        // Generate CRX file name

        final StringBuilder crxFilename = new StringBuilder();
        crxFilename.append(finalName);
        if (StringUtils.isNotEmpty(classifier)) {
            crxFilename.append('-');
            crxFilename.append(classifier);
        }
        crxFilename.append(".crx");
        crxFile = new File(outputDirectory, crxFilename.toString());
    } else {
        crxFile = crxPath;
    }

    try {
        final CRXArchive archive = archiveHelper.readArchive(crxFile);
        final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        final KeySpec keySpec = new X509EncodedKeySpec(archive.getPublicKey());
        final PublicKey publicKey = keyFactory.generatePublic(keySpec);
        if (!signatureHelper.check(archive.getData(), publicKey, archive.getSignature())) {
            throw new MojoFailureException("The signature is not valid");
        }
    } catch (final FileNotFoundException e) {
        throw new MojoExecutionException("Could not find CRX archive", e);
    } catch (final IOException e) {
        throw new MojoExecutionException("Could not load CRX archive", e);
    } catch (final GeneralSecurityException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}