use of org.apache.maven.plugin.MojoExecutionException in project camel by apache.
the class RunMojo method getAllDependencies.
// generic method to retrieve all the transitive dependencies
private Collection<Artifact> getAllDependencies() throws MojoExecutionException {
List<Artifact> artifacts = new ArrayList<Artifact>();
for (Iterator<?> dependencies = project.getDependencies().iterator(); dependencies.hasNext(); ) {
Dependency dependency = (Dependency) dependencies.next();
String groupId = dependency.getGroupId();
String artifactId = dependency.getArtifactId();
VersionRange versionRange;
try {
versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
} catch (InvalidVersionSpecificationException e) {
throw new MojoExecutionException("unable to parse version", e);
}
String type = dependency.getType();
if (type == null) {
type = "jar";
}
String classifier = dependency.getClassifier();
boolean optional = dependency.isOptional();
String scope = dependency.getScope();
if (scope == null) {
scope = Artifact.SCOPE_COMPILE;
}
Artifact art = this.artifactFactory.createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, null, optional);
if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
art.setFile(new File(dependency.getSystemPath()));
}
List<String> exclusions = new ArrayList<String>();
for (Exclusion exclusion : dependency.getExclusions()) {
exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
}
ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
art.setDependencyFilter(newFilter);
artifacts.add(art);
}
return artifacts;
}
use of org.apache.maven.plugin.MojoExecutionException in project camel by apache.
the class UpdateReadmeMojo method templateEndpointOptions.
private String templateEndpointOptions(ComponentModel model) throws MojoExecutionException {
try {
String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("endpoint-options.mvel"));
String out = (String) TemplateRuntime.eval(template, model);
return out;
} catch (Exception e) {
throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project camel by apache.
the class UpdateReadmeMojo method templateLanguageOptions.
private String templateLanguageOptions(LanguageModel model) throws MojoExecutionException {
try {
String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("language-options.mvel"));
String out = (String) TemplateRuntime.eval(template, model);
return out;
} catch (Exception e) {
throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project camel by apache.
the class UpdateReadmeMojo method executeLanguage.
private void executeLanguage() throws MojoExecutionException, MojoFailureException {
// find the language names
List<String> languageNames = findLanguageNames();
final Set<File> jsonFiles = new TreeSet<File>();
PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
// only if there is language we should update the documentation files
if (!languageNames.isEmpty()) {
getLog().debug("Found " + languageNames.size() + " languages");
for (String languageName : languageNames) {
String json = loadLanguageJson(jsonFiles, languageName);
if (json != null) {
File file = new File(docDir, languageName + "-language.adoc");
LanguageModel model = generateLanguageModel(languageName, json);
String docTitle = model.getTitle() + " Language";
boolean deprecated = "true".equals(model.getDeprecated());
if (deprecated) {
docTitle += " (deprecated)";
}
boolean exists = file.exists();
boolean updated;
updated = updateTitles(file, docTitle);
updated |= updateAvailableFrom(file, model.getFirstVersion());
String options = templateLanguageOptions(model);
updated |= updateLanguageOptions(file, options);
if (updated) {
getLog().info("Updated doc file: " + file);
} else if (exists) {
getLog().debug("No changes to doc file: " + file);
} else {
getLog().warn("No language doc file: " + file);
if (isFailFast()) {
throw new MojoExecutionException("Failed build due failFast=true");
}
}
}
}
}
}
use of org.apache.maven.plugin.MojoExecutionException in project camel by apache.
the class UpdateReadmeMojo method updateEndpointOptions.
private boolean updateEndpointOptions(File file, String changed) throws MojoExecutionException {
if (!file.exists()) {
return false;
}
try {
String text = loadText(new FileInputStream(file));
String existing = StringHelper.between(text, "// endpoint options: START", "// endpoint options: END");
if (existing != null) {
// remove leading line breaks etc
existing = existing.trim();
changed = changed.trim();
if (existing.equals(changed)) {
return false;
} else {
String before = StringHelper.before(text, "// endpoint options: START");
String after = StringHelper.after(text, "// endpoint options: END");
text = before + "// endpoint options: START\n" + changed + "\n// endpoint options: END" + after;
writeText(file, text);
return true;
}
} else {
getLog().warn("Cannot find markers in file " + file);
getLog().warn("Add the following markers");
getLog().warn("\t// endpoint options: START");
getLog().warn("\t// endpoint options: END");
if (isFailFast()) {
throw new MojoExecutionException("Failed build due failFast=true");
}
return false;
}
} catch (Exception e) {
throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e);
}
}
Aggregations