Search in sources :

Example 51 with MojoExecutionException

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

the class PrepareUserGuideMojo method updateOthers.

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

Example 52 with MojoExecutionException

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

the class PrepareUserGuideMojo method updateDataFormats.

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

Example 53 with MojoExecutionException

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

the class SpringBootStarterMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (!isStarterAllowed()) {
        getLog().info("Spring-Boot-Starter: starter not allowed for module " + project.getArtifactId() + ": skipping.");
        return;
    }
    try {
        // create the starter directory
        File starterDir = starterDir();
        getLog().info("Spring-Boot-Starter: starter dir for the component is: " + starterDir.getAbsolutePath());
        if (!starterDir.exists()) {
            starterDir.mkdirs();
        }
        // create the base pom.xml
        Document pom = createBasePom();
        // Apply changes to the starter pom
        fixExcludedDependencies(pom);
        fixAdditionalDependencies(pom);
        fixAdditionalRepositories(pom);
        // Write the starter pom
        File pomFile = new File(starterDir, "pom.xml");
        writeXmlFormatted(pom, pomFile);
        // write LICENSE, USAGE and spring.provides files
        writeStaticFiles();
        writeSpringProvides();
        // synchronized all starters with their parent pom 'modules' section
        synchronizeParentPom();
    } catch (Exception e) {
        throw new MojoFailureException("Unable to create starter", e);
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) Document(org.w3c.dom.Document) File(java.io.File) DependencyTreeBuilderException(org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 54 with MojoExecutionException

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

the class UpdateReadmeMojo method updateLanguageOptions.

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

Example 55 with MojoExecutionException

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

the class UpdateReadmeMojo method updateComponentOptions.

private boolean updateComponentOptions(File file, String changed) throws MojoExecutionException {
    if (!file.exists()) {
        return false;
    }
    try {
        String text = loadText(new FileInputStream(file));
        String existing = StringHelper.between(text, "// component options: START", "// component 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, "// component options: START");
                String after = StringHelper.after(text, "// component options: END");
                text = before + "// component options: START\n" + changed + "\n// component 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// component options: START");
            getLog().warn("\t// component 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)586 IOException (java.io.IOException)322 File (java.io.File)261 MojoFailureException (org.apache.maven.plugin.MojoFailureException)138 Artifact (org.apache.maven.artifact.Artifact)86 ArrayList (java.util.ArrayList)70 FileInputStream (java.io.FileInputStream)56 HashMap (java.util.HashMap)47 MavenProject (org.apache.maven.project.MavenProject)37 MalformedURLException (java.net.MalformedURLException)34 Map (java.util.Map)34 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)32 Properties (java.util.Properties)30 FileOutputStream (java.io.FileOutputStream)28 FileWriter (java.io.FileWriter)28 List (java.util.List)25 URL (java.net.URL)22 InputStream (java.io.InputStream)21 LinkedHashSet (java.util.LinkedHashSet)21 FileNotFoundException (java.io.FileNotFoundException)20