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) 

Source Link

Document

Construct a new MojoExecutionException exception providing a message.

Usage

From source file:com.apigee.edge.config.mavenplugin.GatewayAbstractMojo.java

License:Apache License

protected Map getOrgConfigWithId(Logger logger, String config) throws MojoExecutionException {
    File configFile;/*ww  w. j  a v  a  2 s.c o m*/
    String scope = "org";

    /* configDir takes precedence over edge.json */
    if (configDir != null && configDir.length() > 0) {
        configFile = findConfigFile(scope, config);
        if (configFile == null) {
            logger.info("Config file " + scope + File.separator + config + ".json not found.");
            return null;
        }

        logger.info("Retrieving config from " + scope + File.separator + config + ".json");
        try {
            return ConfigReader.getOrgConfigWithId(configFile);
        } catch (Exception e) {
            throw new MojoExecutionException(e.getMessage());
        }
    }

    /* consolidated edge.json in CWD as fallback */
    configFile = findConsolidatedConfigFile();

    if (configFile == null) {
        logger.info("No edge.json found.");
        throw new MojoExecutionException("config file edge.json not found");
    }

    logger.debug("Retrieving config from edge.json");
    try {
        return ConsolidatedConfigReader.getOrgConfigWithId(configFile, "orgConfig", config);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage());
    }
}

From source file:com.apigee.edge.config.mavenplugin.KVMMojo.java

License:Apache License

/** 
 * Entry point for the mojo.//ww  w.j a  v  a  2  s .  co m
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    if (super.isSkip()) {
        getLog().info("Skipping");
        return;
    }

    Logger logger = LoggerFactory.getLogger(KVMMojo.class);

    try {

        init();

        if (buildOption == OPTIONS.none) {
            logger.info("Skipping KVM (default action)");
            return;
        }

        if (serverProfile.getEnvironment() == null) {
            throw new MojoExecutionException("Apigee environment not found in profile");
        }

        /* org scoped KVMs */
        String scope = "orgConfig";
        List kvms = getOrgConfig(logger, "kvms");
        if (kvms == null || kvms.size() == 0) {
            logger.info("No org scoped KVM config found.");
        } else {
            doOrgUpdate(kvms, scope);
        }

        /* env scoped KVMs */
        kvms = getEnvConfig(logger, "kvms");
        if (kvms == null || kvms.size() == 0) {
            logger.info("No env scoped KVM config found.");
        } else {
            doEnvUpdate(kvms, scope);
        }

        // /* API scoped KVMs */
        Set<String> apis = getAPIList(logger);
        if (apis == null || apis.size() == 0) {
            logger.info("No API scoped KVM config found.");
            return;
        }

        for (String api : apis) {
            kvms = getAPIConfig(logger, "kvms", api);
            if (kvms == null || kvms.size() == 0) {
                logger.info("No API scoped KVM config found for " + api);
            } else {
                doAPIUpdate(api, kvms);
            }
        }

    } catch (MojoFailureException e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    }
}

From source file:com.apigee.edge.config.mavenplugin.MaskConfigMojo.java

License:Apache License

/** 
 * Entry point for the mojo./* w w w  .j  a v  a  2  s . c  o m*/
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    if (super.isSkip()) {
        getLog().info("Skipping");
        return;
    }

    Logger logger = LoggerFactory.getLogger(MaskConfigMojo.class);

    try {

        init();

        if (buildOption == OPTIONS.none) {
            logger.info("Skipping Mask Config (default action)");
            return;
        }

        if (serverProfile.getEnvironment() == null) {
            throw new MojoExecutionException("Apigee environment not found in profile");
        }

        /* Org scoped Masks */
        List maskConfigs = getOrgConfig(logger, "maskconfigs");
        if (maskConfigs == null || maskConfigs.size() == 0) {
            logger.info("No org scoped Mask config found.");
        } else {
            doOrgUpdate(maskConfigs);
        }

        /* API scoped Masks */
        Set<String> apis = getAPIList(logger);
        if (apis == null || apis.size() == 0) {
            logger.info("No API scoped Mask config found in edge.json.");
            return;
        }

        for (String api : apis) {
            maskConfigs = getAPIConfig(logger, "maskconfigs", api);
            if (maskConfigs == null || maskConfigs.size() == 0) {
                logger.info("No API scoped Mask config found in edge.json.");
            } else {
                doAPIUpdate(api, maskConfigs);
            }
        }

    } catch (MojoFailureException e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    }
}

From source file:com.apigee.edge.config.mavenplugin.TargetServerMojo.java

License:Apache License

/** 
 * Entry point for the mojo./*from ww  w.  j a va 2  s . c  o m*/
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    if (super.isSkip()) {
        getLog().info("Skipping");
        return;
    }

    Logger logger = LoggerFactory.getLogger(TargetServerMojo.class);

    try {

        init();

        if (buildOption == OPTIONS.none) {
            logger.info("Skipping Target Servers (default action)");
            return;
        }

        if (serverProfile.getEnvironment() == null) {
            throw new MojoExecutionException("Apigee environment not found in profile");
        }

        List targets = getEnvConfig(logger, "targetServers");
        if (targets == null || targets.size() == 0) {
            logger.info("No target server config found.");
            return;
        }

        doUpdate(targets);

    } catch (MojoFailureException e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    }
}

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

License:Open Source License

/**
 * Executes command./*from w w w. j av  a2 s.  c o  m*/
 *
 * @throws IOException Execution of subprocess failed or the subprocess returned a exit value indicating a failure
 *                     {@code Executor.setExitValue(int)}.
 * @see AbstractPluginMojo#command
 * @see AbstractPluginMojo#executor
 */
private void executeCommand() throws IOException, MojoExecutionException {
    if (debug) {
        getLog().info("Executable: " + command.getExecutable());
        getLog().info("Arguments: " + StringUtils.join(command.getArguments(), " "));
    }

    int processExitValue = executor.execute(command);
    if (debug) {
        getLog().info(String.format("Process returned %d (0x%01X)", processExitValue, processExitValue));
    }

    if (processExitValue == Executor.INVALID_EXITVALUE) {
        throw new MojoExecutionException("An error occurred during the execution of the program.");
    }
}

From source file:com.ariht.maven.plugins.config.generator.ConfigGeneratorImpl.java

License:Apache License

/**
 * Merge templates with filters to generate config, scripts and property io.
 *//*from w  w  w  .  j  a  v  a  2s.  c  o m*/
private void processTemplatesAndGenerateConfig() throws Exception {
    final DirectoryReader directoryReader = new DirectoryReader(log);
    final List<FileInfo> filters = directoryReader.readFiles(configGeneratorParameters.getFiltersBasePath(),
            configGeneratorParameters.getFiltersToIgnore());
    for (FileInfo fileInfo : filters) {
        fileInfo.lookForExternalFiles(configGeneratorParameters.getExternalFilterBasePaths());
    }
    final List<FileInfo> templates = directoryReader.readFiles(configGeneratorParameters.getTemplatesBasePath(),
            configGeneratorParameters.getTemplatesToIgnore());
    logOutputPath();

    // Get list of all properties in all filter io.
    final Set<String> allProperties = getAllProperties(filters);
    // Collection stores missing properties by file so this can be logged once at the end.
    final Map<String, Set<String>> missingPropertiesByFilename = new LinkedHashMap<String, Set<String>>();

    for (final FileInfo filter : filters) {
        final Properties properties = readFilterIntoProperties(filter);
        final LinkedHashMap<String, String> valueMap = Maps.newLinkedHashMap(Maps.fromProperties(properties));

        // No point checking for missing properties if all were found in the filter file
        boolean missingPropertyFound = false;
        for (String missingProperty : Sets.difference(allProperties, valueMap.keySet()).immutableCopy()) {
            valueMap.put(missingProperty, MISSING_PROPERTY_PREFIX + missingProperty + MISSING_PROPERTY_SUFFIX);
            missingPropertyFound = true;
        }
        final StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap,
                configGeneratorParameters.getPropertyPrefix(), configGeneratorParameters.getPropertySuffix());
        for (final FileInfo template : templates) {
            generateConfig(template, filter, configGeneratorParameters.getOutputBasePath(), strSubstitutor,
                    missingPropertiesByFilename, missingPropertyFound);
        }
    }

    if (!missingPropertiesByFilename.keySet().isEmpty()) {
        final StringBuilder sb = new StringBuilder("Missing properties identified:\n");
        for (String filename : missingPropertiesByFilename.keySet()) {
            sb.append(filename).append(": ");
            sb.append(StringUtils.join(missingPropertiesByFilename.get(filename), ", ")).append("\n");
        }
        log.warn(sb.toString());
        if (configGeneratorParameters.isFailOnMissingProperty()) {
            throw new MojoExecutionException(sb.toString());
        }
    }
}

From source file:com.atlassian.maven.plugin.clover.CloverAggregateMojo.java

License:Apache License

private void mergeCloverDatabases(final List<String> dbFiles) throws MojoExecutionException {
    final List<String> parameters = new ArrayList<String>();

    parameters.add("-s");
    parameters.add(span);/*  ww  w  . ja va2 s  .  c o  m*/

    parameters.add("-i");
    parameters.add(getCloverMergeDatabase());

    if (getLog().isDebugEnabled()) {
        parameters.add("-d");
    }

    parameters.addAll(dbFiles);

    int mergeResult = CloverMerge.mainImpl(Iterables.toArray(parameters, String.class));
    if (mergeResult != 0) {
        throw new MojoExecutionException("Clover has failed to merge the children module databases");
    }
}

From source file:com.atlassian.maven.plugin.clover.CloverInstrumentInternalMojo.java

License:Apache License

private void addCloverDependencyToCompileClasspath() throws MojoExecutionException {
    Artifact cloverArtifact = findCloverArtifact(this.pluginArtifacts);
    if (cloverArtifact == null) {
        throw new MojoExecutionException("Couldn't find [" + CLOVER_CORE_GROUP_ID + ":"
                + CLOVER_CORE_ARTIFACT_ID + "] artifact in plugin dependencies");
    }/*from  w w w .  j a  v a2s . c o  m*/

    final String jarScope = scope == null ? Artifact.SCOPE_PROVIDED : scope;
    cloverArtifact = artifactFactory.createArtifact(cloverArtifact.getGroupId(), cloverArtifact.getArtifactId(),
            cloverArtifact.getVersion(), jarScope, cloverArtifact.getType());
    try {
        this.artifactResolver.resolve(cloverArtifact, repositories, localRepository);
    } catch (AbstractArtifactResolutionException e) {
        throw new MojoExecutionException("Could not resolve the clover artifact ( " + cloverArtifact.getId()
                + " ) in the localRepository: " + localRepository.getUrl(), e);
    }

    addArtifactDependency(cloverArtifact);
}

From source file:com.atlassian.maven.plugin.clover.internal.instrumentation.AbstractInstrumenter.java

License:Apache License

private void instrumentSources(final Map<String, String[]> filesToInstrument, final String outputDir)
        throws MojoExecutionException {

    Logger.setInstance(new MvnLogger(configuration.getLog()));
    // only make dirs when there is src to instrument. see CLMVN-118
    new File(outputDir).mkdirs();
    int result = CloverInstr.mainImpl(createCliArgs(filesToInstrument, outputDir));
    if (result != 0) {
        throw new MojoExecutionException(
                "Clover has failed to instrument the source files " + "in the [" + outputDir + "] directory");
    }//w w w  . j a  v  a2 s  .c om
}

From source file:com.atlassian.maven.plugin.clover.internal.instrumentation.AbstractInstrumenter.java

License:Apache License

/**
 * @return the CLI args to be passed to CloverInstr
 *//*from  w  ww . j ava 2  s.c o  m*/
private String[] createCliArgs(final Map<String, String[]> filesToInstrument, final String outputDir)
        throws MojoExecutionException {
    final List<String> parameters = new ArrayList<String>();

    parameters.add("-p");
    parameters.add(getConfiguration().getFlushPolicy());
    parameters.add("-f");
    parameters.add("" + getConfiguration().getFlushInterval());

    parameters.add("-i");
    parameters.add(getConfiguration().resolveCloverDatabase());

    parameters.add("-d");
    parameters.add(outputDir);

    if (getConfiguration().getLog().isDebugEnabled()) {
        parameters.add("-v");
    }

    if (getConfiguration().getDistributedCoverage() != null
            && getConfiguration().getDistributedCoverage().isEnabled()) {
        parameters.add("--distributedCoverage");
        parameters.add(getConfiguration().getDistributedCoverage().toString());
    }

    final String javaLevel = getConfiguration().getJdk();
    if (javaLevel != null) {
        if (javaLevel.matches("1\\.[345678]")) {
            parameters.add("--source");
            parameters.add(javaLevel);
        } else {
            throw new MojoExecutionException("Unsupported java language level version [" + javaLevel
                    + "]. Valid values are [1.3], [1.4], [1.5], [1.6], [1.7] and [1.8]");
        }
    }

    if (!getConfiguration().isUseFullyQualifiedJavaLang()) {
        parameters.add("--dontFullyQualifyJavaLang");
    }

    if (getConfiguration().getEncoding() != null) {
        parameters.add("--encoding");
        parameters.add(getConfiguration().getEncoding());
    } else if (getConfiguration().getProject().getProperties().get(PROP_PROJECT_BUILD_SOURCEENCODING) != null) {
        parameters.add("--encoding");
        parameters.add(getConfiguration().getProject().getProperties().get(PROP_PROJECT_BUILD_SOURCEENCODING)
                .toString());
    }

    if (getConfiguration().getInstrumentation() != null) {
        parameters.add("--instrlevel");
        parameters.add(getConfiguration().getInstrumentation());
    }

    if (getConfiguration().getInstrumentLambda() != null) {
        parameters.add("--instrlambda");
        parameters.add(getConfiguration().getInstrumentLambda());
    }

    for (final String srcDir : filesToInstrument.keySet()) {
        final String[] filesInSourceRoot = filesToInstrument.get(srcDir);
        for (String s : filesInSourceRoot) {
            File file = new File(srcDir, s);
            parameters.add(file.getPath());
        }
    }

    // custom contexts
    addCustomContexts(parameters, getConfiguration().getMethodContexts().entrySet(), "-mc");
    addCustomContexts(parameters, getConfiguration().getStatementContexts().entrySet(), "-sc");

    // Log parameters
    if (getConfiguration().getLog().isDebugEnabled()) {
        getConfiguration().getLog().debug("Parameter list being passed to Clover CLI:");
        for (String param : parameters) {
            getConfiguration().getLog().debug("  parameter = [" + param + "]");
        }
    }

    return Iterables.toArray(parameters, String.class);
}