Package org.apache.maven.plugin

Examples of org.apache.maven.plugin.MojoFailureException


    public void execute() throws MojoExecutionException, MojoFailureException {
        // if project is of type "pom", throw an error
        if (project.getPackaging().equalsIgnoreCase("pom")) {
            String errorMsg = "Doh! This plugin cannot be run from a pom project, please run it from a jar or war project (i.e. core or web).";
            //getLog().error(errorMsg);
            throw new MojoFailureException(errorMsg);
        }

        String pojoName = System.getProperty("entity");

        if (pojoName == null) {
View Full Code Here


                            FileUtils.deleteDirectory(templateDirectory + "/dao/" + dir);
                        }
                    }
                }
            } catch (IOException io) {
                throw new MojoFailureException(io.getMessage());
            }

            // export manager templates
            log("Installing service templates...");
            if (!new File(templateDirectory + "/service").exists()) {
                FileUtils.mkdir(templateDirectory + "/service");
            }
            export("plugins/appfuse-maven-plugin/src/main/resources/appfuse/service/",
              ((modular) ? "core/" + templateDirectory : templateDirectory) + "/service");
        }

        if (project.getPackaging().equalsIgnoreCase("war")) {
            if (webFramework == null) {
                getLog().error("The web.framework property is not specified - please modify your pom.xml to add " +
                    " this property. For example: <web.framework>struts</web.framework>.");
                throw new MojoExecutionException("No web.framework property specified, please modify pom.xml to add it.");
            }

            // export web templates
            log("Installing " + webFramework + " templates...");
            if (!new File(templateDirectory + "/web").exists()) {
                FileUtils.mkdir(templateDirectory + "/web");
            }

            export("plugins/appfuse-maven-plugin/src/main/resources/appfuse/web",
              ((modular) ? "web/" + templateDirectory : templateDirectory) + "/web");

            // delete templates that aren't for current web.framework
            try {
                File webDir = new File(templateDirectory + "/web");
                String[] dirs = webDir.list();

                for (String dir : dirs) {
                    if (new File(templateDirectory + "/web/" + dir).isDirectory()) {
                        if (!dir.equals(webFramework)) {
                            FileUtils.deleteDirectory(templateDirectory + "/web/" + dir);
                        }
                    }
                }
            } catch (IOException io) {
                throw new MojoFailureException(io.getMessage());
            }

        }
    }
View Full Code Here

            fw.write(writer.toString());
            fw.flush();
            fw.close();
        } catch (IOException ex) {
            getLog().error("Unable to create pom-fullsource.xml: " + ex.getMessage(), ex);
            throw new MojoFailureException(ex.getMessage());
        }

        log("Updated dependencies in pom.xml...");

        // I tried to use regex here, but couldn't get it to work - going with the old fashioned way instead
        String pomXml = writer.toString();
        int startTag = pomXml.indexOf("\n  <dependencies>");

        String dependencyXml = pomXml.substring(startTag, pomXml.indexOf("</dependencies>", startTag));
        // change 2 spaces to 4
        dependencyXml = dependencyXml.replaceAll("  ", "    ");
        dependencyXml = "\n    <!-- Dependencies calculated by AppFuse when running full-source plugin -->" + dependencyXml;

        try {
            String packaging = project.getPackaging();
            String pathToPom = "pom.xml";
            if (project.hasParent()) {
                if (packaging.equals("jar")) {
                    pathToPom = "core/" + pathToPom;
                } else if (packaging.equals("war")) {
                    pathToPom = "web/" + pathToPom;
                }
            }

            String originalPom = FileUtils.readFileToString(new File(pathToPom), "UTF-8");
            // replace tabs with spaces (in case user has changed their pom.xml
            originalPom = originalPom.replace("\t", "    ");
            startTag = originalPom.indexOf("\n    <dependencies>");

            StringBuffer sb = new StringBuffer();
            sb.append(originalPom.substring(0, startTag));
            sb.append(dependencyXml);
            sb.append(originalPom.substring(originalPom.indexOf("</dependencies>", startTag)));

            String adjustedPom = sb.toString();

            // Calculate properties and add them to pom if not a modular project - otherwise properties are added
            // near the end of this method from a threadlocal
            if (!project.getPackaging().equals("pom") && !project.hasParent()) {
                adjustedPom = addPropertiesToPom(adjustedPom, sortedProperties);
            }

            adjustedPom = adjustLineEndingsForOS(adjustedPom);

            FileUtils.writeStringToFile(new File(pathToPom), adjustedPom, "UTF-8"); // was pomWithProperties
        } catch (IOException ex) {
            getLog().error("Unable to write to pom.xml: " + ex.getMessage(), ex);
            throw new MojoFailureException(ex.getMessage());
        }

        boolean renamePackages = true;
        if (System.getProperty("renamePackages") != null) {
            renamePackages = Boolean.valueOf(System.getProperty("renamePackages"));
        }

        if (renamePackages && !project.getPackaging().equals("pom")) {
            log("Renaming packages to '" + project.getGroupId() + "'...");
            RenamePackages renamePackagesTool = new RenamePackages(project.getGroupId());
            if (project.hasParent()) {
                renamePackagesTool.setBaseDir(project.getBasedir() + "/src");
            }

            renamePackagesTool.execute();
        }

        // when performing full-source on a modular project, add the properties to the root pom.xml at the end
        if (project.getPackaging().equals("war") && project.hasParent()) {
            // store sorted properties in a thread local for later retrieval
            Map properties = propertiesContextHolder.get();
            // alphabetize the properties by key
            Set<String> propertiesToAdd = new TreeSet<String>(properties.keySet());

            StringBuffer calculatedProperties = new StringBuffer();

            for (String key : propertiesToAdd) {
                // don't add property if it already exists in project
                Set<Object> keysInProject = project.getParent().getOriginalModel().getProperties().keySet();
                if (!keysInProject.contains(key)) {
                    String value = getAppFuseProperties().getProperty(key);

                    if (value.contains("&amp;")) {
                        value = "<![CDATA[" + value + "]]>";
                    }

                    calculatedProperties.append("        <");
                    calculatedProperties.append(key);
                    calculatedProperties.append(">");
                    calculatedProperties.append(value);
                    calculatedProperties.append("</");
                    calculatedProperties.append(key);
                    calculatedProperties.append(">");
                    calculatedProperties.append("\n");
                }
            }

            try {
                String originalPom = FileUtils.readFileToString(new File("pom.xml"), "UTF-8");

                // Move modules to build section.
                originalPom = originalPom.replaceAll("  <modules>", "");
                originalPom = originalPom.replaceAll("    <module>.*?</module>", "");
                originalPom = originalPom.replaceAll("  </modules>", "");

                originalPom = originalPom.replace("<repositories>", "<modules>\n" +
                        "        <module>core</module>\n" +
                        "        <module>web</module>\n" +
                        "    </modules>\n\n    <repositories>");

                String pomWithProperties = addPropertiesToPom(originalPom, calculatedProperties);

                FileUtils.writeStringToFile(new File("pom.xml"), pomWithProperties, "UTF-8");
            } catch (IOException ex) {
                getLog().error("Unable to read root pom.xml: " + ex.getMessage(), ex);
                throw new MojoFailureException(ex.getMessage());
            }

        }

        // cleanup so user isn't aware that files were created
View Full Code Here

                            .build();
                    final int exitStatus = protoc.compile();
                    if (exitStatus != 0) {
                        getLog().error("protoc failed output: " + protoc.getOutput());
                        getLog().error("protoc failed error: " + protoc.getError());
                        throw new MojoFailureException(
                                "protoc did not exit cleanly. Review output for more information.");
                    }
                    attachFiles();
                }
            } catch (IOException e) {
                throw new MojoExecutionException("An IO error occured", e);
            } catch (IllegalArgumentException e) {
                throw new MojoFailureException("protoc failed to execute because: " + e.getMessage(), e);
            } catch (CommandLineException e) {
                throw new MojoExecutionException("An error occurred while invoking protoc.", e);
            }
        } else {
            getLog().info(format("%s does not exist. Review the configuration or consider disabling the plugin.",
View Full Code Here

        Embedder embedder = newEmbedder();
        getLog().info("Generating stories view using embedder " + embedder);
        try {
            embedder.generateReportsView();
        } catch (RuntimeException e) {
            throw new MojoFailureException("Failed to generate stories view", e);
        }
    }
View Full Code Here

        Embedder embedder = newEmbedder();
        getLog().info("Mapping stories as paths using embedder " + embedder);
        try {
            embedder.mapStoriesAsPaths(storyPaths());
        } catch (RuntimeException e) {
            throw new MojoFailureException("Failed to map stories as paths", e);
        }
    }
View Full Code Here

        Embedder embedder = newEmbedder();
        getLog().info("Reporting stepdocs as embeddables using embedder " + embedder);
        try {
            embedder.reportStepdocsAsEmbeddables(classNames());
        } catch (RuntimeException e) {
            throw new MojoFailureException("Failed to report stepdocs as embeddables", e);
        }
    }
View Full Code Here

        Embedder embedder = newEmbedder();
        getLog().info("Reporting stepdocs using embedder " + embedder);
        try {
            embedder.reportStepdocs();
        } catch (RuntimeException e) {
            throw new MojoFailureException("Failed to report stepdocs", e);
        }
    }
View Full Code Here

        Embedder embedder = newEmbedder();
        getLog().info("Running stories with annotated embedder runner");
        try {
            embedder.runStoriesWithAnnotatedEmbedderRunner(classNames());
        } catch (RuntimeException e) {
            throw new MojoFailureException("Failed to run stories with annotated embedder runner", e);
        }

    }
View Full Code Here

        Embedder embedder = newEmbedder();
        getLog().info("Running stories as paths using embedder " + embedder);
        try {
            embedder.runStoriesAsPaths(storyPaths());
        } catch (RuntimeException e) {
            throw new MojoFailureException("Failed to run stories as paths", e);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.maven.plugin.MojoFailureException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.