Search in sources :

Example 21 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project camel by apache.

the class ValidateComponentMojo method execute.

/**
     * Execute goal.
     *
     * @throws org.apache.maven.plugin.MojoExecutionException execution of the main class or one of the
     *                                                        threads it generated failed.
     * @throws org.apache.maven.plugin.MojoFailureException   something bad happened...
     */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (!validate) {
        getLog().info("Validation disabled");
    } else {
        final Set<File> jsonFiles = new TreeSet<File>();
        PackageHelper.findJsonFiles(outDir, jsonFiles, new CamelComponentsFileFilter());
        boolean failed = false;
        for (File file : jsonFiles) {
            final String name = asName(file);
            final ErrorDetail detail = new ErrorDetail();
            getLog().debug("Validating file " + file);
            validate(file, detail);
            if (detail.hasErrors()) {
                failed = true;
                getLog().warn("The " + detail.getKind() + ": " + name + " has validation errors");
                if (detail.isMissingDescription()) {
                    getLog().warn("Missing description on: " + detail.getKind());
                }
                if (detail.isMissingLabel()) {
                    getLog().warn("Missing label on: " + detail.getKind());
                }
                if (detail.isMissingSyntax()) {
                    getLog().warn("Missing syntax on endpoint");
                }
                if (detail.isMissingUriPath()) {
                    getLog().warn("Missing @UriPath on endpoint");
                }
                if (!detail.getMissingComponentDocumentation().isEmpty()) {
                    getLog().warn("Missing component documentation for the following options:" + indentCollection("\n\t", detail.getMissingComponentDocumentation()));
                }
                if (!detail.getMissingEndpointDocumentation().isEmpty()) {
                    getLog().warn("Missing endpoint documentation for the following options:" + indentCollection("\n\t", detail.getMissingEndpointDocumentation()));
                }
            }
        }
        if (failed) {
            throw new MojoFailureException("Validating failed, see errors above!");
        } else {
            getLog().info("Validation complete");
        }
    }
}
Also used : TreeSet(java.util.TreeSet) MojoFailureException(org.apache.maven.plugin.MojoFailureException) File(java.io.File)

Example 22 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project camel by apache.

the class SpringBootAutoConfigurationMojo method createConnectorConfigurationSource.

private void createConnectorConfigurationSource(String packageName, ComponentModel model, String javaType, String connectorScheme, List<String> componentOptions) throws MojoFailureException {
    final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
    int pos = javaType.lastIndexOf(".");
    String name = javaType.substring(pos + 1);
    name = name.replace("Component", "ConnectorConfiguration");
    javaClass.setPackage(packageName).setName(name);
    String doc = "Generated by camel-connector-maven-plugin - do not edit this file!";
    if (!Strings.isBlank(model.getDescription())) {
        doc = model.getDescription() + "\n\n" + doc;
    }
    // replace Component with Connector
    doc = doc.replaceAll("Component", "Connector");
    doc = doc.replaceAll("component", "connector");
    javaClass.getJavaDoc().setFullText(doc);
    // compute the configuration prefix to use with spring boot configuration
    String prefix = "";
    if (!"false".equalsIgnoreCase(configurationPrefix)) {
        // make sure prefix is in lower case
        prefix = configurationPrefix.toLowerCase(Locale.US);
        if (!prefix.endsWith(".")) {
            prefix += ".";
        }
    }
    prefix += connectorScheme.toLowerCase(Locale.US);
    javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix);
    for (ComponentOptionModel option : model.getComponentOptions()) {
        // only include the options that has been explicit configured in the camel-connector.json file
        boolean accepted = false;
        if (componentOptions != null) {
            accepted = componentOptions.stream().anyMatch(o -> o.equals(option.getName()));
        }
        if (accepted) {
            String type = option.getJavaType();
            PropertySource<JavaClassSource> prop = javaClass.addProperty(type, option.getName());
            if ("true".equals(option.getDeprecated())) {
                prop.getField().addAnnotation(Deprecated.class);
                prop.getAccessor().addAnnotation(Deprecated.class);
                prop.getMutator().addAnnotation(Deprecated.class);
                // DeprecatedConfigurationProperty must be on getter when deprecated
                prop.getAccessor().addAnnotation(DeprecatedConfigurationProperty.class);
            }
            if (!Strings.isBlank(option.getDescription())) {
                prop.getField().getJavaDoc().setFullText(option.getDescription());
            }
            if (!Strings.isBlank(option.getDefaultValue())) {
                if ("java.lang.String".equals(option.getJavaType())) {
                    prop.getField().setStringInitializer(option.getDefaultValue());
                } else if ("long".equals(option.getJavaType()) || "java.lang.Long".equals(option.getJavaType())) {
                    // the value should be a Long number
                    String value = option.getDefaultValue() + "L";
                    prop.getField().setLiteralInitializer(value);
                } else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) {
                    prop.getField().setLiteralInitializer(option.getDefaultValue());
                } else if (!Strings.isBlank(option.getEnums())) {
                    String enumShortName = type.substring(type.lastIndexOf(".") + 1);
                    prop.getField().setLiteralInitializer(enumShortName + "." + option.getDefaultValue());
                    javaClass.addImport(model.getJavaType());
                }
            }
        }
    }
    sortImports(javaClass);
    String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
    writeSourceIfChanged(javaClass, fileName);
}
Also used : StringHelper.getSafeValue(org.apache.camel.maven.connector.util.StringHelper.getSafeValue) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ComponentModel(org.apache.camel.maven.connector.model.ComponentModel) Parameter(org.apache.maven.plugins.annotations.Parameter) JSonSchemaHelper(org.apache.camel.maven.connector.util.JSonSchemaHelper) ArrayList(java.util.ArrayList) AutoConfigureAfter(org.springframework.boot.autoconfigure.AutoConfigureAfter) Mojo(org.apache.maven.plugins.annotations.Mojo) Roaster(org.jboss.forge.roaster.Roaster) StringHelper.getShortJavaType(org.apache.camel.maven.connector.util.StringHelper.getShortJavaType) Locale(java.util.Locale) Map(java.util.Map) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) LifecyclePhase(org.apache.maven.plugins.annotations.LifecyclePhase) PropertySource(org.jboss.forge.roaster.model.source.PropertySource) MethodSource(org.jboss.forge.roaster.model.source.MethodSource) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ComponentOptionModel(org.apache.camel.maven.connector.model.ComponentOptionModel) DeprecatedConfigurationProperty(org.springframework.boot.context.properties.DeprecatedConfigurationProperty) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileUtils(org.apache.commons.io.FileUtils) FileInputStream(java.io.FileInputStream) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) Formatter(org.jboss.forge.roaster.model.util.Formatter) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) Strings(org.jboss.forge.roaster.model.util.Strings) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean) FileHelper.loadText(org.apache.camel.maven.connector.util.FileHelper.loadText) Collections(java.util.Collections) AbstractMojo(org.apache.maven.plugin.AbstractMojo) InputStream(java.io.InputStream) Import(org.jboss.forge.roaster.model.source.Import) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) ComponentOptionModel(org.apache.camel.maven.connector.model.ComponentOptionModel)

Example 23 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project wire by square.

the class WireGenerateSourcesMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    // Add the directory into which generated sources are placed as a compiled source root.
    project.addCompileSourceRoot(generatedSourceDirectory);
    try {
        List<String> directories = protoPaths != null && protoPaths.length > 0 ? Arrays.asList(protoPaths) : Collections.singletonList(protoSourceDirectory);
        List<String> protoFilesList = Arrays.asList(protoFiles);
        Schema schema = loadSchema(directories, protoFilesList);
        Profile profile = loadProfile(schema);
        IdentifierSet identifierSet = identifierSet();
        if (!identifierSet.isEmpty()) {
            schema = retainRoots(identifierSet, schema);
        }
        JavaGenerator javaGenerator = JavaGenerator.get(schema).withAndroid(emitAndroid).withCompact(emitCompact).withProfile(profile);
        for (ProtoFile protoFile : schema.protoFiles()) {
            if (!protoFilesList.isEmpty() && !protoFilesList.contains(protoFile.location().path())) {
                // Don't emit anything for files not explicitly compiled.
                continue;
            }
            for (Type type : protoFile.types()) {
                Stopwatch stopwatch = Stopwatch.createStarted();
                TypeSpec typeSpec = javaGenerator.generateType(type);
                ClassName javaTypeName = javaGenerator.generatedTypeName(type);
                writeJavaFile(javaTypeName, typeSpec, type.location().withPathOnly());
                getLog().info(String.format("Generated %s in %s", javaTypeName, stopwatch));
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Wire Plugin: Failure compiling proto sources.", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Schema(com.squareup.wire.schema.Schema) ProtoFile(com.squareup.wire.schema.ProtoFile) Stopwatch(com.google.common.base.Stopwatch) JavaGenerator(com.squareup.wire.java.JavaGenerator) IdentifierSet(com.squareup.wire.schema.IdentifierSet) Profile(com.squareup.wire.java.Profile) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Type(com.squareup.wire.schema.Type) ClassName(com.squareup.javapoet.ClassName) TypeSpec(com.squareup.javapoet.TypeSpec)

Example 24 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project jslint4java by happygiraffe.

the class JSLintMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("skipping JSLint");
        return;
    }
    JSLint jsLint = applyJSlintSource();
    applyDefaults();
    applyOptions(jsLint);
    List<File> files = getFilesToProcess();
    int failures = 0;
    ReportWriter reporter = makeReportWriter();
    try {
        reporter.open();
        for (File file : files) {
            JSLintResult result = lintFile(jsLint, file);
            failures += result.getIssues().size();
            logIssues(result, reporter);
        }
    } finally {
        reporter.close();
    }
    if (failures > 0) {
        String message = "JSLint found " + failures + " problems in " + files.size() + " files";
        if (failOnError) {
            throw new MojoFailureException(message);
        } else {
            getLog().info(message);
        }
    }
}
Also used : JSLint(com.googlecode.jslint4java.JSLint) MojoFailureException(org.apache.maven.plugin.MojoFailureException) JSLintResult(com.googlecode.jslint4java.JSLintResult) File(java.io.File) JSLint(com.googlecode.jslint4java.JSLint)

Example 25 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project grails-maven by grails.

the class MvnPluginValidateMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        getGrailsServices().readProjectDescriptor();
    } catch (final MojoExecutionException e) {
        getLog().info("No Grails project found - skipping validation.");
        return;
    }
    final GrailsPluginProject grailsProject = getGrailsServices().readGrailsPluginProject();
    final String pluginName = grailsProject.getPluginName();
    if (!artifactId.equals(pluginName) && !artifactId.equals(PLUGIN_PREFIX + pluginName)) {
        throw new MojoFailureException("The plugin name in the pom.xml [" + artifactId + "]" + " is not the expected '" + pluginName + "' or '" + PLUGIN_PREFIX + pluginName + "'. " + "Please correct the pom.xml or the plugin " + "descriptor.");
    }
    final String pomVersion = version.trim();
    final String grailsVersion = grailsProject.getVersion();
    if (!grailsVersion.equals(pomVersion)) {
        throw new MojoFailureException("The version specified in the plugin descriptor " + "[" + grailsVersion + "] is different from the version in the pom.xml [" + pomVersion + "] ");
    }
}
Also used : GrailsPluginProject(org.grails.maven.plugin.tools.GrailsPluginProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

MojoFailureException (org.apache.maven.plugin.MojoFailureException)157 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)94 File (java.io.File)93 IOException (java.io.IOException)91 ArrayList (java.util.ArrayList)50 TreeSet (java.util.TreeSet)33 FileInputStream (java.io.FileInputStream)32 FileOutputStream (java.io.FileOutputStream)21 List (java.util.List)21 Map (java.util.Map)21 MavenProject (org.apache.maven.project.MavenProject)18 Set (java.util.Set)15 MalformedURLException (java.net.MalformedURLException)14 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)13 InputStream (java.io.InputStream)12 URLClassLoader (java.net.URLClassLoader)12 Matcher (java.util.regex.Matcher)12 Artifact (org.apache.maven.artifact.Artifact)12 AbstractMojo (org.apache.maven.plugin.AbstractMojo)12