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.bugvm.maven.plugin.AbstractBugVMMojo.java

License:Apache License

protected Artifact resolveArtifact(Artifact artifact) throws MojoExecutionException {

    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);/*from w w w  .java 2s.  c  om*/
    if (artifact.isSnapshot()) {
        request.setForceUpdate(true);
    }
    request.setLocalRepository(localRepository);
    final List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories();
    request.setRemoteRepositories(remoteRepositories);

    getLog().debug("Resolving artifact " + artifact);

    ArtifactResolutionResult result = artifactResolver.resolve(request);
    if (!result.isSuccess()) {
        throw new MojoExecutionException("Unable to resolve artifact: " + artifact);
    }
    Collection<Artifact> resolvedArtifacts = result.getArtifacts();
    artifact = (Artifact) resolvedArtifacts.iterator().next();
    return artifact;
}

From source file:com.bugvm.maven.plugin.AbstractBugVMMojo.java

License:Apache License

protected void unpack(File archive, File targetDirectory) throws MojoExecutionException {

    if (!targetDirectory.exists()) {

        getLog().info("Extracting '" + archive + "' to: " + targetDirectory);
        if (!targetDirectory.mkdirs()) {
            throw new MojoExecutionException(
                    "Unable to create base directory to unpack into: " + targetDirectory);
        }/*from  w ww.  ja  va2  s  .com*/

        try {
            UnArchiver unArchiver = archiverManager.getUnArchiver(archive);
            unArchiver.setSourceFile(archive);
            unArchiver.setDestDirectory(targetDirectory);
            unArchiver.extract();
        } catch (NoSuchArchiverException e) {
            throw new MojoExecutionException("Unable to unpack archive " + archive + " to " + targetDirectory,
                    e);
        }
        getLog().debug("Archive '" + archive + "' unpacked to: " + targetDirectory);

    } else {
        getLog().debug("Archive '" + archive + "' was already unpacked in: " + targetDirectory);
    }
}

From source file:com.butterfill.plsqlcore.maven.Extract.java

License:Apache License

/**
 * Creates a directory with the specified name.
 * <br/>//from  w  w  w.  ja va  2s . c  o m
 * There are 4 possible scenarios:
 * <ul>
 * <li>The directory exists. This is ok. No action needed,</li>
 * <li>Something that is not a directory exists with the specified name. This is an error,</li>
 * <li>The directory exists and we can create it or</li>
 * <li>The directory exists but we can't create it. This is an error.</li>
 * </ul>
 * 
 * @param name 
 *   The name of the directory to create.
 * @throws java.lang.Exception
 *   If something that is not a directory exists with the specified name
 *   or we fail to create the directory.
 */
private void mkDir(final String name) throws Exception {
    final File dir = new File(outputDirectory + name);

    if (dir.exists()) {
        if (dir.isDirectory()) {
            getLog().info("directory exists: " + dir.getCanonicalPath());

        } else {
            throw new MojoExecutionException(dir.getCanonicalPath() + " is not a directory");

        }

    } else {
        if (dir.mkdirs()) {
            getLog().info("directory created: " + dir.getCanonicalPath());

        } else {
            throw new MojoExecutionException("failed to create directory: " + dir.getCanonicalPath());

        }

    }

}

From source file:com.butterfill.plsqlcore.maven.Extract.java

License:Apache License

/**
 * Calls ExtractorMain#extract having set the output directory name, 
 * passing in the includes file if it has been provided.
 * /*from   ww  w. j a v a 2s  .c  o  m*/
 * @see #setIncludesFile(java.io.File)
 * @see #setOutputDirectory(java.io.File) 
 * @throws org.apache.maven.plugin.MojoExecutionException
 *   If the extract fails.
 * @throws org.apache.maven.plugin.MojoFailureException
 *   If the extract fails.
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    if (!execute) {
        getLog().info("Execution has been disabled. Not extracting");
        return;
    }

    if (!executeIfNoNetwork) {
        try {
            URLConnection urlConnection = new URL("http://www.sun.com").openConnection();
            urlConnection.setUseCaches(false);
            urlConnection.getInputStream().close();
            // if we can get the input stream, the network connection is ok
            getLog().debug("Network OK");

        } catch (Exception ex) {
            // assume that any exceptions thrown mean we have no network connection
            getLog().warn("No Network (failed to connect to http://www.sun.com). Not extracting");
            return;

        }

    }

    try {
        // set-up a map to hold all modules that we'll extract.
        // each module will be keyed by it's location - so we can avoid adding duplicates
        Map<String, PlsqlCoreModule> moduleMap = new HashMap<String, PlsqlCoreModule>();

        // read the includes file via JAXB
        PlsqlCoreIncludes plsqlCoreIncludes = (PlsqlCoreIncludes) jaxbUnmarshaller.unmarshal(includesFile);

        // add each location to be included to the module map.
        // add module should take care of adding depencies
        for (String location : plsqlCoreIncludes.getPlsqlCoreModuleLocation()) {
            addModule(formatLocation(location), moduleMap);

        }

        // extract each module in the module map
        for (Map.Entry<String, PlsqlCoreModule> entry : moduleMap.entrySet()) {
            // get the location from the PlsqlCoreModule
            String location = formatLocation(entry.getValue().getLocation());

            // make sure the location from the PlsqlCoreModule matches the
            // loaction given in the includes file
            if (!entry.getKey().equals(location)) {
                throw new MojoExecutionException("[Location Mismatch] " + includesFile.getName() + ":\""
                        + entry.getKey() + "\" plsql-core-module.xml:\"" + location + "\"");
            }

            // get the name of the module
            String moduleName = getModuleName(location);

            // setup output dir for this module
            mkDir(moduleName);

            // extract each file listed in the modules file set
            for (String fileName : entry.getValue().getFileSet().getFile()) {
                getLog().info("Extracting: " + location + fileName);

                URL baseUrl = new URL(location);

                URLConnection urlConnection = new URL(baseUrl, fileName).openConnection();

                urlConnection.setUseCaches(false);

                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(urlConnection.getInputStream()));

                BufferedWriter writer = new BufferedWriter(new FileWriter(
                        outputDirectory + File.separator + moduleName + File.separator + fileName));

                for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                    writer.write(line);
                    writer.newLine();

                }

                writer.close();
                reader.close();

            }

        }

    } catch (Exception ex) {
        // log a warning if the extract failed
        getLog().warn("extract failed", ex);
        // log the output dir
        getLog().info("outputDirectory: " + outputDirectory);
        // the name of the includes file
        try {
            getLog().info("includesFile: " + includesFile.getCanonicalPath());
        } catch (Exception nonCriticalException) {
            getLog().debug("failed to log name of includes file", nonCriticalException);
        }
        // and throw an exception so that the user knows something went wrong
        throw new MojoExecutionException("extract failed", ex);

    }

}

From source file:com.capgemini.csd.utils.maven.plugin.debt.DebtMojo.java

License:Open Source License

/**
 * Runs the debt:debt goal/*w  w  w  .j  a  v a  2 s.  co m*/
 */
@Override
public void execute() throws MojoExecutionException {
    getLog().info("Scanning source for @Debt annotations.");

    try {
        executeWithExceptionsHandled();
    } catch (Exception ex) {
        if (failOnCompileError) {
            throw new MojoExecutionException(ex.getMessage());
        }
    }
}

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

License:Apache License

private void validateOperations() throws MojoExecutionException {
    if ((operations == null) || (operations.length == 0)) {
        throw new MojoExecutionException(
                "An operation should be defined for maven-properties-files-plugin to work.");
    }//from ww  w  .  j  av a2  s. c  om
}

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

License:Open Source License

protected void validate() throws MojoExecutionException {
    if (_server == null)
        throw new MojoExecutionException("server is required by " + getMojoName());

    if (_port == -1)
        throw new MojoExecutionException("port is required by " + getMojoName());

    if (_user == null)
        throw new MojoExecutionException("user is required by " + getMojoName());
}

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

License:Open Source License

/**
  * Runs a new instance on EC2 using the generated user data.
  *//ww w .j  a  v  a  2 s  .  c o  m
  * @return instance descriptor of the created instance
  */
protected ReservationDescription.Instance launchServer(Jec2 ec2, int i) throws MojoExecutionException {
    String userData = buildUserDataScript(i);

    try {
        // XXX instance type, public ip_p
        ReservationDescription description = ec2.runInstances(_amiId, 1, 1, _securityGroups, userData,
                _keyPair);

        List<ReservationDescription.Instance> instances = description.getInstances();

        if (instances.size() != 1)
            throw new MojoExecutionException("Incorrect number of instances launched: " + instances.size());

        ReservationDescription.Instance instance = instances.get(0);

        switch (i) {
        case -1:
            getLog().info("New instance [frontend]: " + instance.getInstanceId());
            break;

        case 0:
            getLog().info("New instance [triad-a]: " + instance.getInstanceId());
            break;

        case 1:
            getLog().info("New instance [triad-b]: " + instance.getInstanceId());
            break;

        case 2:
            getLog().info("New instance [triad-c]: " + instance.getInstanceId());
            break;
        }

        return instance;
    } catch (EC2Exception e) {
        throw new MojoExecutionException("Exception while launching instance", e);
    }
}

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

License:Open Source License

protected void associateElasticIp(Jec2 ec2, int i, ReservationDescription.Instance instance)
        throws MojoExecutionException {
    try {/* w  w w.java2s  .  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.");

        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.MavenEc2AssociateTriadIps.java

License:Open Source License

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

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

    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));

    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);
    }
}