Search in sources :

Example 56 with MojoExecutionException

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;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Dependency(org.apache.maven.model.Dependency) ExecutableDependency(org.codehaus.mojo.exec.ExecutableDependency) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) Exclusion(org.apache.maven.model.Exclusion) File(java.io.File)

Example 57 with MojoExecutionException

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 58 with MojoExecutionException

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 59 with MojoExecutionException

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");
                    }
                }
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TreeSet(java.util.TreeSet) LanguageModel(org.apache.camel.maven.packaging.model.LanguageModel) File(java.io.File)

Example 60 with MojoExecutionException

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)645 IOException (java.io.IOException)349 File (java.io.File)298 MojoFailureException (org.apache.maven.plugin.MojoFailureException)146 Artifact (org.apache.maven.artifact.Artifact)100 ArrayList (java.util.ArrayList)86 FileInputStream (java.io.FileInputStream)56 HashMap (java.util.HashMap)50 MavenProject (org.apache.maven.project.MavenProject)40 MalformedURLException (java.net.MalformedURLException)36 Map (java.util.Map)35 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)33 FileWriter (java.io.FileWriter)32 Properties (java.util.Properties)32 FileOutputStream (java.io.FileOutputStream)30 List (java.util.List)30 URL (java.net.URL)28 LinkedHashSet (java.util.LinkedHashSet)26 InputStream (java.io.InputStream)24 URLClassLoader (java.net.URLClassLoader)23