Search in sources :

Example 61 with MojoExecutionException

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

the class UpdateReadmeMojo method executeDataFormat.

private void executeDataFormat() throws MojoExecutionException, MojoFailureException {
    // find the dataformat names
    List<String> dataFormatNames = findDataFormatNames();
    final Set<File> jsonFiles = new TreeSet<File>();
    PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
    // only if there is dataformat we should update the documentation files
    if (!dataFormatNames.isEmpty()) {
        getLog().debug("Found " + dataFormatNames.size() + " dataformats");
        for (String dataFormatName : dataFormatNames) {
            String json = loadDataFormatJson(jsonFiles, dataFormatName);
            if (json != null) {
                // special for some data formats
                dataFormatName = asDataFormatName(dataFormatName);
                File file = new File(docDir, dataFormatName + "-dataformat.adoc");
                DataFormatModel model = generateDataFormatModel(dataFormatName, json);
                String title = asDataFormatTitle(model.getName(), model.getTitle());
                model.setTitle(title);
                String docTitle = model.getTitle() + " DataFormat";
                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 = templateDataFormatOptions(model);
                updated |= updateDataFormatOptions(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 dataformat doc file: " + file);
                    if (isFailFast()) {
                        throw new MojoExecutionException("Failed build due failFast=true");
                    }
                }
            }
        }
    }
}
Also used : DataFormatModel(org.apache.camel.maven.packaging.model.DataFormatModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TreeSet(java.util.TreeSet) File(java.io.File)

Example 62 with MojoExecutionException

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

the class UpdateReadmeMojo method templateComponentOptions.

private String templateComponentOptions(ComponentModel model) throws MojoExecutionException {
    try {
        String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("component-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 63 with MojoExecutionException

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

the class UpdateReadmeMojo method updateTitles.

private boolean updateTitles(File file, String title) throws MojoExecutionException {
    if (!file.exists()) {
        return false;
    }
    boolean updated = false;
    try {
        List<String> newLines = new ArrayList<>();
        String text = loadText(new FileInputStream(file));
        String[] lines = text.split("\n");
        for (int i = 0; i < lines.length; i++) {
            String line = lines[i];
            if (i == 0) {
                // first line is the title to make the text less noisy we use level 2
                String newLine = "## " + title;
                newLines.add(newLine);
                updated = !line.equals(newLine);
                continue;
            }
            // use single line headers with # as level instead of the cumbersome adoc weird style
            if (line.startsWith("^^^") || line.startsWith("~~~") || line.startsWith("+++")) {
                String level = line.startsWith("+++") ? "####" : "###";
                // transform legacy heading into new style
                int idx = newLines.size() - 1;
                String prev = newLines.get(idx);
                newLines.set(idx, level + " " + prev);
                // okay if 2nd-prev line is a [[title]] we need to remove that too
                // so we have nice clean sub titles
                idx = newLines.size() - 2;
                if (idx >= 0) {
                    prev = newLines.get(idx);
                    if (prev.startsWith("[[")) {
                        // remove
                        newLines.remove(idx);
                    }
                }
                updated = true;
            } else {
                // okay normal text so just add it
                newLines.add(line);
            }
        }
        if (updated) {
            // build the new updated text
            String newText = newLines.stream().collect(Collectors.joining("\n"));
            writeText(file, newText);
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e);
    }
    return updated;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 64 with MojoExecutionException

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

the class UpdateReadmeMojo method templateEipOptions.

private String templateEipOptions(EipModel model) throws MojoExecutionException {
    try {
        String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("eip-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 65 with MojoExecutionException

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

the class UpdateReadmeMojo method updateEipOptions.

private boolean updateEipOptions(File file, String changed) throws MojoExecutionException {
    if (!file.exists()) {
        return false;
    }
    try {
        String text = loadText(new FileInputStream(file));
        String existing = StringHelper.between(text, "// eip options: START", "// eip 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, "// eip options: START");
                String after = StringHelper.after(text, "// eip options: END");
                text = before + "// eip options: START\n" + changed + "\n// eip 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// eip options: START");
            getLog().warn("\t// eip 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