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.caucho.maven.aws.MavenEc2ListCluster.java

License:Open Source License

/**
 * Executes the maven resin:ec2-start-triad task
 *///w  w w.  j ava  2s.co m
public void execute() throws MojoExecutionException {
    Jec2 ec2 = new Jec2(_accessKeyId, _secretAccessKey);

    if (_triadIps == null || _triadIps.length < 1 || _triadIps.length > 3)
        throw new MojoExecutionException("Please specify between 1 and 3 triad server elastic IPs");

    describeTriadMembers(ec2);

    if (_frontendIp != null)
        describeFrontend(ec2);

    describeDynamicServers(ec2);
}

From source file:com.caucho.maven.aws.MavenEc2StartTriad.java

License:Open Source License

protected void associateElasticIp(Jec2 ec2, int i, ReservationDescription.Instance instance)
        throws MojoExecutionException {
    try {//  ww  w  .  j a v  a 2s .c  o  m
        String[] instanceIds = new String[] { instance.getInstanceId() };

        while (!instance.isRunning()) {
            getLog().info("Instance " + instance.getInstanceId() + " not yet running (" + instance.getState()
                    + "). " + "Sleeping...");

            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                getLog().debug("Sleep interrupted", e);
            }

            List<ReservationDescription> descriptions = ec2.describeInstances(instanceIds);

            if (descriptions.size() != 1)
                throw new MojoExecutionException(
                        "Unknown status for instance " + instance.getInstanceId() + ": " + descriptions);

            List<ReservationDescription.Instance> instances = descriptions.get(0).getInstances();

            if (instances.size() != 1)
                throw new MojoExecutionException(
                        "Unknown status for instance " + instance.getInstanceId() + ": " + instances);

            instance = instances.get(0);

            if (instance.isShuttingDown() || instance.isTerminated())
                throw new MojoExecutionException(
                        "Instance shutting down or terminated before associating address: "
                                + instance.getInstanceId());
        }

        getLog().info("Instance " + instance.getInstanceId()
                + " is now running.  Pausing before associating address...");

        // even when running, ec2 may not accept the elastic ip association
        // right away
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            getLog().debug("Sleep interrupted", e);
        }

        String elasticIp = null;

        if (i < 0)
            elasticIp = _frontendIp;
        else
            elasticIp = _triadIps[i];

        ec2.associateAddress(instance.getInstanceId(), elasticIp);

        getLog().info("Instance " + instance.getInstanceId() + " now associated with Elastic IP " + elasticIp);
    } catch (EC2Exception e) {
        throw new MojoExecutionException("Exception while associating Elastic IP", e);
    }
}

From source file:com.caucho.maven.aws.MavenEc2StartTriad.java

License:Open Source License

/**
 * Executes the maven resin:ec2-start-triad task
 *//*from w  w w  . j av a  2s .c om*/
public void execute() throws MojoExecutionException {
    Jec2 ec2 = new Jec2(_accessKeyId, _secretAccessKey);

    if (_triadIps == null || _triadIps.length < 1 || _triadIps.length > 3)
        throw new MojoExecutionException("Please specify between 1 and 3 triad server elastic IPs");

    // XXX check that triad members are not already running
    getLog().info("----- Starting instances -----");
    ReservationDescription.Instance frontend = null;
    List<ReservationDescription.Instance> triads = new ArrayList<ReservationDescription.Instance>();

    if (_frontendIp != null)
        frontend = launchServer(ec2, -1);

    for (int i = 0; i < _triadIps.length; i++)
        triads.add(launchServer(ec2, i));

    getLog().info("");
    getLog().info("----- Associating Elastic IPs -----");

    if (frontend != null)
        associateElasticIp(ec2, -1, frontend);

    for (int i = 0; i < _triadIps.length; i++) {
        ReservationDescription.Instance triad = triads.get(i);
        associateElasticIp(ec2, i, triad);
    }
}

From source file:com.caucho.maven.MavenCopyTag.java

License:Open Source License

@Override
protected void validate() throws MojoExecutionException {
    super.validate();

    if (_tag == null && getContextRoot() == null)
        throw new MojoExecutionException("tag or contextRoot is required by " + getMojoName());

    if (_sourceTag == null && _sourceContextRoot == null)
        throw new MojoExecutionException("sourceTag or sourceContextRoot is required by " + getMojoName());
}

From source file:com.caucho.maven.MavenDeleteTag.java

License:Open Source License

@Override
protected void validate() throws MojoExecutionException {
    super.validate();

    if (_tag == null && getContextRoot() == null)
        throw new MojoExecutionException("tag or contextRoot is required by " + getMojoName());
}

From source file:com.caucho.maven.MavenQueryTags.java

License:Open Source License

@Override
protected void validate() throws MojoExecutionException {
    super.validate();

    if (_pattern == null && getStage() == null && getVirtualHost() == null && getContextRoot() == null
            && getVersion() == null)
        throw new MojoExecutionException(
                "At least one of pattern, stage, virtualHost, contextRoot, or version is required by "
                        + getMojoName());
}

From source file:com.caucho.maven.MavenUploadWar.java

License:Open Source License

/**
 * Sets the path of the WAR file (defaults to target/${finalName}.war)
 * @parameter/*  w ww.j av a 2 s.c o m*/
 */
public void setWarFile(String warFile) throws MojoExecutionException {
    if (!warFile.endsWith(".war"))
        throw new MojoExecutionException("war-file must have .war extension");

    _warFile = warFile;

    if (getContextRoot() == null) {
        int lastSlash = _warFile.lastIndexOf("/");

        if (lastSlash < 0)
            lastSlash = 0;

        int end = _warFile.length() - ".war".length();

        setContextRoot(_warFile.substring(lastSlash, end));
    }
}

From source file:com.caucho.maven.MavenUploadWar.java

License:Open Source License

@Override
protected void processSystemProperties() throws MojoExecutionException {
    super.processSystemProperties();

    Properties properties = System.getProperties();
    String archive = properties.getProperty("resin.archive");
    String writeHead = properties.getProperty("resin.writeHead");
    String warFile = properties.getProperty("resin.warFile");

    if (archive != null)
        _archive = archive;//from  ww w  . ja v a  2  s .c  o  m

    if (writeHead != null) {
        if ("true".equalsIgnoreCase(writeHead))
            _writeHead = true;
        else if ("false".equalsIgnoreCase(writeHead))
            _writeHead = false;
        else
            throw new MojoExecutionException("resin.writeHead must be a either 'true' or 'false'");
    }

    if (warFile != null)
        setWarFile(warFile);
}

From source file:com.caucho.maven.MavenUploadWar.java

License:Open Source License

@Override
protected void validate() throws MojoExecutionException {
    super.validate();

    if (_warFile == null)
        throw new MojoExecutionException("war-file is required by " + getMojoName());
}

From source file:com.cedarsoft.fish.maven.HelpUtil.java

License:Apache License

/**
 * Invoke the following private method <code>
 * DefaultLifecycleExecutor#getMojoDescriptor(String, MavenSession, MavenProject, String, boolean, boolean)</code>
 *
 * @param task not null//from   w w  w  .jav  a2  s .  c o  m
 * @param session not null
 * @param project not null
 * @param invokedVia not null
 * @param canUsePrefix not null
 * @param isOptionalMojo not null
 * @return MojoDescriptor for the task
 * @throws MojoFailureException if can not invoke the method.
 * @throws MojoExecutionException if no descriptor was found for <code>task</code>.
 * @see DefaultLifecycleExecutor#getMojoDescriptor(String, MavenSession, MavenProject, String, boolean, boolean)
 */
protected static MojoDescriptor getMojoDescriptor(String task, MavenSession session, MavenProject project,
        String invokedVia, boolean canUsePrefix, boolean isOptionalMojo)
        throws MojoFailureException, MojoExecutionException {
    try {
        DefaultLifecycleExecutor lifecycleExecutor = (DefaultLifecycleExecutor) session
                .lookup(LifecycleExecutor.ROLE);

        Method m = lifecycleExecutor.getClass().getDeclaredMethod("getMojoDescriptor",
                new Class[] { String.class, MavenSession.class, MavenProject.class, String.class, Boolean.TYPE,
                        Boolean.TYPE });
        m.setAccessible(true);
        MojoDescriptor mojoDescriptor = (MojoDescriptor) m.invoke(lifecycleExecutor, new Object[] { task,
                session, project, invokedVia, Boolean.valueOf(canUsePrefix), Boolean.valueOf(isOptionalMojo) });

        if (mojoDescriptor == null) {
            throw new MojoExecutionException("No MOJO exists for '" + task + "'.");
        }

        return mojoDescriptor;
    } catch (SecurityException e) {
        throw new MojoFailureException("SecurityException: " + e.getMessage());
    } catch (IllegalArgumentException e) {
        throw new MojoFailureException("IllegalArgumentException: " + e.getMessage());
    } catch (ComponentLookupException e) {
        throw new MojoFailureException("ComponentLookupException: " + e.getMessage());
    } catch (NoSuchMethodException e) {
        throw new MojoFailureException("NoSuchMethodException: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new MojoFailureException("IllegalAccessException: " + e.getMessage());
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();

        if (cause instanceof BuildFailureException) {
            throw new MojoFailureException("BuildFailureException: " + cause.getMessage());
        } else if (cause instanceof LifecycleExecutionException) {
            throw new MojoFailureException("LifecycleExecutionException: " + cause.getMessage());
        } else if (cause instanceof PluginNotFoundException) {
            throw new MojoFailureException("PluginNotFoundException: " + cause.getMessage());
        }

        StringWriter s = new StringWriter();
        PrintWriter writer = new PrintWriter(s);
        e.printStackTrace(writer);

        throw new MojoFailureException("InvocationTargetException: " + e.getMessage() + "\n" + s.toString());
    }
}