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");
}
}
}
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);
}
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);
}
}
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);
}
}
}
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 + "] ");
}
}
Aggregations