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.chiralbehaviors.ultrastructure.plugin.owl.OwlToJavaGenerator.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (ontology == null) {
        throw new MojoFailureException("Ontology file name required");
    }//w w w  .  j  a  v  a2s . co m
    if (packageName == null) {
        throw new MojoFailureException("Package name required");
    }
    List<String> arguments = new ArrayList<>();
    if (deleteDirectory) {
        arguments.add("-d");
    }
    arguments.add("-f");
    arguments.add(factoryName);
    arguments.add("-o");
    arguments.add(outputDirectory.getAbsolutePath());
    arguments.add("-p");
    arguments.add(packageName);
    if (reasoner != null) {
        arguments.add("-r");
        arguments.add(reasoner);
    }
    arguments.add(ontology.getAbsolutePath());

    getLog().info("Generating code");
    try {
        GenerateSimpleJavaCode.main(arguments.toArray(new String[arguments.size()]));
    } catch (Exception e) {
        getLog().error(String.format("Error generating"), e);
        throw new MojoExecutionException("Error in generation", e);
    }
}

From source file:com.choncms.maven.CopyPluginsMojo.java

License:Apache License

private void copyArtifact(File location, File plugins_dir) throws MojoExecutionException {
    try {//from   ww  w .  ja v  a 2s  .c om
        FileUtils.copyFileToDirectory(location, plugins_dir);
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying file ", e);
    }
}

From source file:com.citytechinc.cq.component.maven.ComponentMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    LogSingleton.getInstance().setLogger(getLog());

    try {//w  w  w.  j a va2  s . co m

        @SuppressWarnings("unchecked")
        List<String> classpathElements = project.getCompileClasspathElements();

        ClassLoader classLoader = ComponentMojoUtil.getClassLoader(classpathElements,
                this.getClass().getClassLoader());

        ClassPool classPool = ComponentMojoUtil.getClassPool(classLoader);

        Reflections reflections = ComponentMojoUtil.getReflections(classLoader);

        List<CtClass> classList = ComponentMojoUtil.getAllComponentAnnotations(classPool, reflections,
                getExcludedClasses());

        WidgetRegistry widgetRegistry = new DefaultWidgetRegistry(classPool, classLoader, reflections,
                getAdditionalFeatures());

        TouchUIWidgetRegistry touchUIWidgetRegistry = new DefaultTouchUIWidgetRegistry(classPool, classLoader,
                reflections, getAdditionalFeatures());

        Map<String, ComponentNameTransformer> transformers = ComponentMojoUtil.getAllTransformers(classPool,
                reflections);

        ComponentNameTransformer transformer = transformers.get(transformerName);

        if (transformer == null) {
            throw new ConfigurationException("The configured transformer wasn't found");
        }

        ComponentMojoUtil.buildArchiveFileForProjectAndClassList(classList, widgetRegistry,
                touchUIWidgetRegistry, classLoader, classPool, new File(project.getBuild().getDirectory()),
                componentPathBase, componentPathSuffix, defaultComponentGroup, getArchiveFileForProject(),
                getTempArchiveFileForProject(), transformer, generateTouchUiDialogs);

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

}

From source file:com.cloudbees.maven.license.ProcessMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    if (disableCheck)
        return;/*w w  w. j a  v  a2  s  . c  o m*/

    GroovyShell shell = createShell(LicenseScript.class);

    List<LicenseScript> comp = parseScripts(script, shell);

    if (generateLicenseHtml != null && generateLicenseXml == null) {// we need XML to be able to generate HTML
        try {
            generateLicenseXml = File.createTempFile("license", "xml");
            generateLicenseXml.deleteOnExit();
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to generate a temporary file", e);
        }
    }

    if (generateLicenseXml != null)
        comp.add((LicenseScript) shell.parse(getClass().getResourceAsStream("xmlgen.groovy"), "xmlgen.groovy"));

    if (generateLicenseHtml != null)
        comp.add((LicenseScript) shell.parse(getClass().getResourceAsStream("htmlgen.groovy"),
                "htmlgen.groovy"));

    if (inlineScript != null)
        comp.add((LicenseScript) shell.parse(inlineScript, "inlineScript"));

    for (LicenseScript s : comp) {
        s.project = project;
        s.mojo = this;
        s.run(); // setup
    }

    List<MavenProject> dependencies = new ArrayList<MavenProject>();

    // run against the project itself
    for (LicenseScript s : comp) {
        s.runCompleter(new CompleterDelegate(project, project));
    }
    dependencies.add(project);

    try {
        Map<Artifact, MavenProject> models = new HashMap<Artifact, MavenProject>();

        for (Artifact a : (Set<Artifact>) project.getArtifacts()) {
            Artifact pom = artifactFactory.createProjectArtifact(a.getGroupId(), a.getArtifactId(),
                    a.getVersion());
            MavenProject model = projectBuilder.buildFromRepository(pom,
                    project.getRemoteArtifactRepositories(), localRepository);
            models.put(a, model);
        }

        // filter them out
        for (LicenseScript s : comp) {
            s.runFilter(new FilterDelegate(models));
        }

        // filter out optional components
        for (Iterator<Entry<Artifact, MavenProject>> itr = models.entrySet().iterator(); itr.hasNext();) {
            Entry<Artifact, MavenProject> e = itr.next();
            if (e.getKey().isOptional())
                itr.remove();
        }

        for (MavenProject e : models.values()) {
            // let the completion script intercept and process the licenses
            for (LicenseScript s : comp) {
                s.runCompleter(new CompleterDelegate(e, project));
            }
        }

        dependencies.addAll(models.values());
    } catch (ProjectBuildingException e) {
        throw new MojoExecutionException("Failed to parse into dependencies", e);
    }

    if (requireCompleteLicenseInfo) {
        List<MavenProject> missing = new ArrayList<MavenProject>();
        for (MavenProject d : dependencies) {
            if (d.getLicenses().isEmpty())
                missing.add(d);
        }
        if (!missing.isEmpty()) {
            StringBuilder buf = new StringBuilder(
                    "The following dependencies are missing license information:\n");
            for (MavenProject p : missing) {
                buf.append("  " + p.getGroupId() + ':' + p.getArtifactId() + ':' + p.getVersion());
                for (p = p.getParent(); p != null; p = p.getParent())
                    buf.append(" -> " + p.getGroupId() + ':' + p.getArtifactId() + ':' + p.getVersion());
                buf.append('\n');
            }
            buf.append(
                    "\nAdd/update your completion script to fill them, or run with -Dlicense.disableCheck to bypass the check.");
            throw new MojoExecutionException(buf.toString());
        }
    }

    for (LicenseScript s : comp) {
        s.runGenerator(new GeneratorDelegate(dependencies));
    }

    if (attach) {
        if (generateLicenseXml != null)
            projectHelper.attachArtifact(project, "license.xml", null, generateLicenseXml);
        if (generateLicenseHtml != null)
            projectHelper.attachArtifact(project, "license.html", null, generateLicenseHtml);
    }
}

From source file:com.cloudbees.maven.license.ProcessMojo.java

License:Apache License

private List<LicenseScript> parseScripts(File src, GroovyShell shell) throws MojoExecutionException {
    List<LicenseScript> comp = new ArrayList<LicenseScript>();
    if (src != null) {
        try {/*from  w w w  . j a v  a 2s.  c  o m*/
            if (src.isDirectory()) {
                for (File script : src.listFiles())
                    comp.add((LicenseScript) shell.parse(script));
            } else {
                comp.add((LicenseScript) shell.parse(src));
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to parse the script: " + src, e);
        }
    }
    return comp;
}

From source file:com.cloudcontrolled.cctrl.maven.plugin.CloudControlledMojo.java

License:Apache License

/**
 * <p>/*from  w  w  w .  j a  v a  2  s. c  om*/
 * retrieveBranch.
 * </p>
 * 
 * @throws org.apache.maven.plugin.MojoExecutionException
 *             if any.
 * @return a {@link java.lang.String} object.
 */
public String retrieveBranch() throws MojoExecutionException {
    try {
        return getRepository().getBranch();
    } catch (IOException e) {
        throw new MojoExecutionException(e.getClass().getSimpleName(), e);
    }
}

From source file:com.cloudcontrolled.cctrl.maven.plugin.deploy.CloudcontrolledDeploy.java

License:Apache License

/** {@inheritDoc} */
@Override/*from  w  w w. ja  v a 2  s .  c o  m*/
public void execute() throws MojoExecutionException, MojoFailureException {

    if (deployment == null || deployment.isEmpty()) {
        deployment = retrieveBranch();
        if (CloudControlSupport.MASTER_BRANCH.equals(deployment)) {
            deployment = "default";
        }
    }

    if (deployment == null) {
        Repository repository = null;
        try {
            repository = getRepository();
            String branch = repository.getBranch();
            if (!CloudControlSupport.MASTER_BRANCH.equals(branch)) {
                deployment = branch;
            }
        } catch (IOException e) {
            throw new MojoExecutionException(e.getClass().getSimpleName(), e);
        } finally {
            if (repository != null) {
                repository.close();
            }
        }
    }

    String deploymentQualifier = application
            + (deployment != null ? ":" + deployment + (commitId != null ? ":" + commitId : "") : "");
    log.info("Deploying " + deploymentQualifier + " to CloudControl PaaS.");

    CloudControlClient client = CloudControlSupport.createCloudControlClient();
    UpdateDeploymentRequest request = CloudControlSupport.createUpdateDeploymentRequest(application, deployment,
            commitId);

    UpdateDeploymentResponse response = null;
    try {
        response = client.send(request);

        if (response.isError()) {
            throw new MojoFailureException(response.getContent());
        }
    } catch (CloudControlClientException ccce) {
        throw new MojoExecutionException("CloudControlClientException", ccce);
    }

    log.info("Successfully deployed " + deploymentQualifier);
    log.info("Please, visit to following domain: http://" + response.getDeployment().getDefaultSubdomain());
}

From source file:com.cloudcontrolled.cctrl.maven.plugin.push.CloudcontrolledPush.java

License:Apache License

private String retrieveRemoteRepositoryLocation() throws MojoFailureException, MojoExecutionException {
    CloudControlClient client = CloudControlSupport.createCloudControlClient();
    ApplicationRequest applicationRequest = CloudControlSupport.createApplicationRequest(application);

    ApplicationResponse applicationResponse = null;
    try {//from w w  w. j a va  2s . co  m
        applicationResponse = client.send(applicationRequest);

        if (applicationResponse.isError()) {
            throw new MojoFailureException(applicationResponse.getContent());
        }
    } catch (CloudControlClientException ccce) {
        throw new MojoExecutionException(ccce.getClass().getSimpleName(), ccce);
    }

    String remoteRepository = "git+";
    remoteRepository += applicationResponse.getApplication().getRepository();

    return remoteRepository;
}

From source file:com.cloudcontrolled.cctrl.maven.plugin.push.CloudcontrolledPush.java

License:Apache License

private String push(String remoteLocation) throws MojoExecutionException {
    Repository repository = null;/*  w w  w  .j a  v a2 s. co m*/
    Git git;
    try {
        repository = getRepository();
        git = Git.wrap(repository);

        PushCommand pushCommand = git.push();
        pushCommand.setRemote(remoteLocation);
        pushCommand.setRefSpecs(new RefSpec(repository.getFullBranch()));

        Iterable<PushResult> pushResult = pushCommand.call();
        Iterator<PushResult> result = pushResult.iterator();

        StringBuffer buffer = new StringBuffer();
        if (result.hasNext()) {
            while (result.hasNext()) {
                String line = result.next().getMessages();
                if (!line.isEmpty()) {
                    buffer.append(line);
                    if (result.hasNext()) {
                        buffer.append(System.getProperty("line.separator"));
                    }
                }
            }
        }

        return buffer.toString();
    } catch (Exception e) {
        throw new MojoExecutionException(e.getClass().getSimpleName(), e);
    } finally {
        if (repository != null) {
            repository.close();
        }
    }
}

From source file:com.cloudera.cdk.maven.plugins.AbstractDatasetMojo.java

License:Apache License

void configureSchema(DatasetDescriptor.Builder descriptorBuilder, String avroSchemaFile,
        String avroSchemaReflectClass) throws MojoExecutionException {
    if (avroSchemaFile != null) {
        File avroSchema = new File(avroSchemaFile);
        try {//  w  ww .  j  a v  a2s .  co  m
            if (avroSchema.exists()) {
                descriptorBuilder.schema(avroSchema);
            } else {
                descriptorBuilder.schema(Resources.getResource(avroSchemaFile).openStream());
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Problem while reading file " + avroSchemaFile, e);
        }
    } else if (avroSchemaReflectClass != null) {

        try {
            List<URL> classpath = new ArrayList<URL>();
            for (Object element : mavenProject.getCompileClasspathElements()) {
                String path = (String) element;
                classpath.add(new File(path).toURI().toURL());
            }
            ClassLoader parentClassLoader = getClass().getClassLoader(); // use Maven's classloader, not the system one
            ClassLoader classLoader = new URLClassLoader(classpath.toArray(new URL[classpath.size()]),
                    parentClassLoader);

            descriptorBuilder.schema(Class.forName(avroSchemaReflectClass, true, classLoader));
        } catch (ClassNotFoundException e) {
            throw new MojoExecutionException("Problem finding class " + avroSchemaReflectClass, e);
        } catch (MalformedURLException e) {
            throw new MojoExecutionException("Problem finding class " + avroSchemaReflectClass, e);
        } catch (DependencyResolutionRequiredException e) {
            throw new MojoExecutionException("Problem finding class " + avroSchemaReflectClass, e);
        }
    }
}