Search in sources :

Example 1 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project jetty.project by eclipse.

the class JspcMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (getLog().isDebugEnabled()) {
        getLog().info("webAppSourceDirectory=" + webAppSourceDirectory);
        getLog().info("generatedClasses=" + generatedClasses);
        getLog().info("webXmlFragment=" + webXmlFragment);
        getLog().info("webXml=" + webXml);
        getLog().info("insertionMarker=" + (insertionMarker == null || insertionMarker.equals("") ? END_OF_WEBAPP : insertionMarker));
        getLog().info("keepSources=" + keepSources);
        getLog().info("mergeFragment=" + mergeFragment);
        if (sourceVersion != null)
            getLog().info("sourceVersion=" + sourceVersion);
        if (targetVersion != null)
            getLog().info("targetVersion=" + targetVersion);
    }
    try {
        prepare();
        compile();
        cleanupSrcs();
        mergeWebXml();
    } catch (Exception e) {
        throw new MojoExecutionException("Failure processing jsps", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 2 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project jetty.project by eclipse.

the class JettyRunMojo method checkPomConfiguration.

/**
     * Verify the configuration given in the pom.
     * 
     * @see AbstractJettyMojo#checkPomConfiguration()
     */
public void checkPomConfiguration() throws MojoExecutionException {
    // check the location of the static content/jsps etc
    try {
        if ((webAppSourceDirectory == null) || !webAppSourceDirectory.exists()) {
            getLog().info("webAppSourceDirectory" + (webAppSourceDirectory == null ? " not set." : (webAppSourceDirectory.getAbsolutePath() + " does not exist.")) + " Trying " + DEFAULT_WEBAPP_SRC);
            webAppSourceDirectory = new File(project.getBasedir(), DEFAULT_WEBAPP_SRC);
            if (!webAppSourceDirectory.exists()) {
                getLog().info("webAppSourceDirectory " + webAppSourceDirectory.getAbsolutePath() + " does not exist. Trying " + project.getBuild().getDirectory() + File.separator + FAKE_WEBAPP);
                //try last resort of making a fake empty dir
                File target = new File(project.getBuild().getDirectory());
                webAppSourceDirectory = new File(target, FAKE_WEBAPP);
                if (!webAppSourceDirectory.exists())
                    webAppSourceDirectory.mkdirs();
            }
        } else
            getLog().info("Webapp source directory = " + webAppSourceDirectory.getCanonicalPath());
    } catch (IOException e) {
        throw new MojoExecutionException("Webapp source directory does not exist", e);
    }
    // check reload mechanic
    if (!"automatic".equalsIgnoreCase(reload) && !"manual".equalsIgnoreCase(reload)) {
        throw new MojoExecutionException("invalid reload mechanic specified, must be 'automatic' or 'manual'");
    } else {
        getLog().info("Reload Mechanic: " + reload);
    }
    // check the classes to form a classpath with
    try {
        //allow a webapp with no classes in it (just jsps/html)
        if (classesDirectory != null) {
            if (!classesDirectory.exists())
                getLog().info("Classes directory " + classesDirectory.getCanonicalPath() + " does not exist");
            else
                getLog().info("Classes = " + classesDirectory.getCanonicalPath());
        } else
            getLog().info("Classes directory not set");
    } catch (IOException e) {
        throw new MojoExecutionException("Location of classesDirectory does not exist");
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) File(java.io.File)

Example 3 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project jetty.project by eclipse.

the class JettyRunWarExplodedMojo method configureScanner.

/**
     * @see AbstractJettyMojo#configureScanner()
     */
public void configureScanner() throws MojoExecutionException {
    scanner.watch(project.getFile().toPath());
    File webInfDir = new File(war, "WEB-INF");
    File webXml = new File(webInfDir, "web.xml");
    if (webXml.exists())
        scanner.watch(webXml.toPath());
    File jettyWebXmlFile = findJettyWebXmlFile(webInfDir);
    if (jettyWebXmlFile != null)
        scanner.watch(jettyWebXmlFile.toPath());
    File jettyEnvXmlFile = new File(webInfDir, "jetty-env.xml");
    if (jettyEnvXmlFile.exists())
        scanner.watch(jettyEnvXmlFile.toPath());
    File classes = new File(webInfDir, "classes");
    if (classes.exists()) {
        PathWatcher.Config classesConfig = new PathWatcher.Config(classes.toPath());
        classesConfig.setRecurseDepth(PathWatcher.Config.UNLIMITED_DEPTH);
        scanner.watch(classesConfig);
    }
    File lib = new File(webInfDir, "lib");
    if (lib.exists()) {
        PathWatcher.Config libConfig = new PathWatcher.Config(lib.toPath());
        libConfig.setRecurseDepth(PathWatcher.Config.UNLIMITED_DEPTH);
        scanner.watch(libConfig);
    }
    scanner.addListener(new PathWatcher.EventListListener() {

        @Override
        public void onPathWatchEvents(List<PathWatchEvent> events) {
            try {
                boolean reconfigure = false;
                for (PathWatchEvent e : events) {
                    if (e.getPath().equals(project.getFile().toPath())) {
                        reconfigure = true;
                        break;
                    }
                }
                restartWebApp(reconfigure);
            } catch (Exception e) {
                getLog().error("Error reconfiguring/restarting webapp after change in watched files", e);
            }
        }
    });
}
Also used : PathWatcher(org.eclipse.jetty.util.PathWatcher) PathWatchEvent(org.eclipse.jetty.util.PathWatcher.PathWatchEvent) File(java.io.File) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 4 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project che by eclipse.

the class TypeScriptDTOGeneratorMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("Generating TypeScript DTO");
    TypeScriptDtoGenerator typeScriptDtoGenerator = new TypeScriptDtoGenerator();
    typeScriptDtoGenerator.setUseClassPath(useClassPath);
    // define output path for the file to write with typescript definition
    String output = typeScriptDtoGenerator.execute();
    this.typescriptFile = new File(targetDirectory, project.getArtifactId() + ".ts");
    File parentDir = this.typescriptFile.getParentFile();
    if (!parentDir.exists() && !parentDir.mkdirs()) {
        throw new MojoExecutionException("Unable to create a directory for writing DTO typescript file '" + parentDir + "'.");
    }
    try (Writer fileWriter = Files.newBufferedWriter(this.typescriptFile.toPath(), StandardCharsets.UTF_8)) {
        fileWriter.write(output);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot write DTO typescript file");
    }
    // attach this typescript file as maven artifact
    projectHelper.attachArtifact(project, "ts", typescriptFile);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) File(java.io.File) Writer(java.io.Writer)

Example 5 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project che by eclipse.

the class EffectivePomWriter method writeEffectivePom.

/**
     * method from org.apache.maven.plugins.help.EffectivePomMojo
     * Method for writing the effective pom informations of the current build.
     *
     * @param project the project of the current build, not null.
     * @param writer the XML writer , not null, not null.
     * @throws MojoExecutionException if any
     */
private static void writeEffectivePom(MavenProject project, XMLWriter writer) throws MojoExecutionException {
    Model pom = project.getModel();
    cleanModel(pom);
    String effectivePom;
    StringWriter sWriter = new StringWriter();
    MavenXpp3Writer pomWriter = new MavenXpp3Writer();
    try {
        pomWriter.write(sWriter, pom);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot serialize POM to XML.", e);
    }
    effectivePom = addMavenNamespace(sWriter.toString(), true);
    writeComment(writer, "Effective POM for project \'" + project.getId() + "\'");
    writer.writeMarkup(effectivePom);
}
Also used : StringWriter(java.io.StringWriter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) IOException(java.io.IOException) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1220 IOException (java.io.IOException)656 File (java.io.File)571 MojoFailureException (org.apache.maven.plugin.MojoFailureException)275 Artifact (org.apache.maven.artifact.Artifact)162 ArrayList (java.util.ArrayList)150 FileInputStream (java.io.FileInputStream)77 MavenProject (org.apache.maven.project.MavenProject)76 HashMap (java.util.HashMap)68 Properties (java.util.Properties)63 FileOutputStream (java.io.FileOutputStream)61 Map (java.util.Map)60 URL (java.net.URL)59 MalformedURLException (java.net.MalformedURLException)56 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)52 FileWriter (java.io.FileWriter)50 List (java.util.List)49 URLClassLoader (java.net.URLClassLoader)45 LinkedHashSet (java.util.LinkedHashSet)40 InputStream (java.io.InputStream)38