Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2014-07-16 05:31:48 +0000
committerGreg Wilkins2014-07-16 05:31:48 +0000
commit853e020210d1e638c67d93bc636c0ba036986407 (patch)
treefe1cbd6e4269ab0253f46ccc35cd59731680aeb8 /jetty-maven-plugin
parent4d2a580c2c8ca054841697a9d8848bdceb1c97f9 (diff)
parentdd5cdab54cdd6787ab25775291ff5c56716b1415 (diff)
downloadorg.eclipse.jetty.project-853e020210d1e638c67d93bc636c0ba036986407.tar.gz
org.eclipse.jetty.project-853e020210d1e638c67d93bc636c0ba036986407.tar.xz
org.eclipse.jetty.project-853e020210d1e638c67d93bc636c0ba036986407.zip
Merge remote-tracking branch 'origin/master' into jetty-http2
Diffstat (limited to 'jetty-maven-plugin')
-rw-r--r--jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java157
-rw-r--r--jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java22
-rw-r--r--jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java3
-rw-r--r--jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java32
4 files changed, 193 insertions, 21 deletions
diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java
new file mode 100644
index 0000000000..6c607c85df
--- /dev/null
+++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java
@@ -0,0 +1,157 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+
+package org.eclipse.jetty.maven.plugin;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.eclipse.jetty.annotations.AnnotationConfiguration;
+import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.util.resource.Resource;
+import org.eclipse.jetty.util.thread.QueuedThreadPool;
+
+/**
+ * JettyEffectiveWebXml
+ *
+ * @goal effective-web-xml
+ * @requiresDependencyResolution test
+ * @execute phase="test-compile"
+ * @description Runs jetty on the unassembled webapp to generate the effective web.xml
+ */
+public class JettyEffectiveWebXml extends JettyRunMojo
+{
+ /**
+ * The target directory
+ *
+ * @parameter expression="${project.build.directory}"
+ * @required
+ * @readonly
+ */
+ protected File target;
+
+ /**
+ * The target directory
+ *
+ * @parameter
+ */
+ protected File effectiveWebXml;
+
+
+ protected boolean deleteOnExit = true;
+
+
+ /**
+ * @see org.apache.maven.plugin.Mojo#execute()
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+ super.execute();
+ }
+
+
+ @Override
+ public void startJetty() throws MojoExecutionException
+ {
+ //Only do enough setup to be able to produce a quickstart-web.xml file to
+ //pass onto the forked process to run
+
+ //if the user didn't nominate a file to generate into, pick the name and
+ //make sure that it is deleted on exit
+ if (effectiveWebXml == null)
+ {
+ deleteOnExit = true;
+ effectiveWebXml = new File(target, "effective-web.xml");
+ effectiveWebXml.deleteOnExit();
+ }
+
+ Resource descriptor = Resource.newResource(effectiveWebXml);
+
+ QueuedThreadPool tpool = null;
+
+ try
+ {
+ printSystemProperties();
+
+ //apply any config from a jetty.xml file first to our "fake" server instance
+ //TODO probably not necessary
+ applyJettyXml ();
+
+
+ server.configureHandlers();
+
+ //ensure config of the webapp based on settings in plugin
+ configureWebApplication();
+
+
+ //set the webapp up to do very little other than generate the quickstart-web.xml
+ webApp.setCopyWebDir(false);
+ webApp.setCopyWebInf(false);
+ webApp.setGenerateQuickStart(true);
+
+ if (!effectiveWebXml.getParentFile().exists())
+ effectiveWebXml.getParentFile().mkdirs();
+ if (!effectiveWebXml.exists())
+ effectiveWebXml.createNewFile();
+
+ webApp.setQuickStartWebDescriptor(descriptor);
+
+ server.addWebApplication(webApp);
+
+ //if our server has a thread pool associated we can do any annotation scanning multithreaded,
+ //otherwise scanning will be single threaded
+ tpool = server.getBean(QueuedThreadPool.class);
+ if (tpool != null)
+ tpool.start();
+ else
+ webApp.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE.toString());
+
+ webApp.start(); //just enough to generate the quickstart
+
+ }
+ catch (Exception e)
+ {
+ throw new MojoExecutionException("Effective web.xml generation failed", e);
+ }
+ finally
+ {
+ try {webApp.stop();}catch (Exception x) {};
+
+ try {if (tpool != null) tpool.stop();} catch (Exception x) {};
+ }
+
+
+ if (deleteOnExit)
+ {
+ try
+ {
+ //just show the result in the log
+ getLog().info(IO.toString(descriptor.getInputStream()));
+ }
+ catch (IOException e)
+ {
+ throw new MojoExecutionException("Unable to output effective web.xml", e);
+ }
+
+ }
+
+ }
+}
diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java
index 663749d033..aa73a33860 100644
--- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java
+++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java
@@ -43,6 +43,7 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
+import org.eclipse.jetty.quickstart.QuickStartDescriptorGenerator;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
@@ -98,6 +99,13 @@ public class JettyRunForkedMojo extends JettyRunMojo
*/
protected File target;
+ /**
+ * The file into which to generate the quickstart web xml for the forked process to use
+ *
+ * @parameter expression="${project.build.directory}/fork-web.xml"
+ */
+ protected File forkWebXml;
+
/**
* Arbitrary jvm args to pass to the forked process
@@ -229,7 +237,11 @@ public class JettyRunForkedMojo extends JettyRunMojo
public void startJetty() throws MojoExecutionException
{
//Only do enough setup to be able to produce a quickstart-web.xml file to
- //pass onto the forked process to run
+ //pass onto the forked process to run
+
+ if (forkWebXml == null)
+ forkWebXml = new File (target, "fork-web.xml");
+
try
{
printSystemProperties();
@@ -251,7 +263,13 @@ public class JettyRunForkedMojo extends JettyRunMojo
webApp.setCopyWebDir(false);
webApp.setCopyWebInf(false);
webApp.setGenerateQuickStart(true);
- webApp.setQuickStartDir(target);
+
+ if (!forkWebXml.getParentFile().exists())
+ forkWebXml.getParentFile().mkdirs();
+ if (!forkWebXml.exists())
+ forkWebXml.createNewFile();
+
+ webApp.setQuickStartWebDescriptor(Resource.newResource(forkWebXml));
server.addWebApplication(webApp);
diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java
index 41147fca0d..130dd52504 100644
--- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java
+++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java
@@ -55,8 +55,7 @@ import org.eclipse.jetty.webapp.WebAppContext;
* This can be used, for example, to deploy a static webapp that is not part of your maven build.
* </p>
* <p>
- * There is a <a href="run-mojo.html">reference guide</a> to the configuration parameters for this plugin, and more detailed information
- * with examples in the <a href="http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin">Configuration Guide</a>.
+ * There is a <a href="http://www.eclipse.org/jetty/documentation/current/maven-and-jetty.html">reference guide</a> to the configuration parameters for this plugin.
* </p>
*
*
diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java
index 4b8a76bc7d..265e2852a7 100644
--- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java
+++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.maven.plugin;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
@@ -66,7 +67,7 @@ public class JettyWebAppContext extends WebAppContext
- private static final String DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN = ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$|.*javax.servlet.jsp.jstl-[^/]*\\.jar";
+ private static final String DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN = ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$|.*javax.servlet.jsp.jstl-[^/]*\\.jar|.*taglibs-standard-impl-.*\\.jar";
private static final String WEB_INF_CLASSES_PREFIX = "/WEB-INF/classes";
private static final String WEB_INF_LIB_PREFIX = "/WEB-INF/lib";
@@ -125,7 +126,7 @@ public class JettyWebAppContext extends WebAppContext
private boolean _isGenerateQuickStart;
private PreconfigureDescriptorProcessor _preconfigProcessor;
- private File _quickStartDir;
+
@@ -274,15 +275,7 @@ public class JettyWebAppContext extends WebAppContext
return _isGenerateQuickStart;
}
- public void setQuickStartDir (File dir)
- {
- _quickStartDir = dir;
- }
-
- public File getQuickStartDir()
- {
- return _quickStartDir;
- }
+
@Override
@@ -290,9 +283,14 @@ public class JettyWebAppContext extends WebAppContext
{
if (isGenerateQuickStart())
{
- QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, (getQuickStartDir()==null?getTempDirectory():getQuickStartDir()), _preconfigProcessor.getXML());
- File f = generator.generateQuickStartWebXml();
- setQuickStartWebDescriptor(Resource.newResource(f));
+ if (getQuickStartWebDescriptor() == null)
+ throw new IllegalStateException ("No location to generate quickstart descriptor");
+
+ QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, _preconfigProcessor.getXML());
+ try (FileOutputStream fos = new FileOutputStream(getQuickStartWebDescriptor().getFile()))
+ {
+ generator.generateQuickStartWebXml(fos);
+ }
}
else
super.startWebapp();
@@ -303,7 +301,9 @@ public class JettyWebAppContext extends WebAppContext
public void doStart () throws Exception
{
//choose if this will be a quickstart or normal start
- if (getQuickStartWebDescriptor() == null)
+ if (!isGenerateQuickStart() && getQuickStartWebDescriptor() != null)
+ setConfigurations(_quickStartConfigurations);
+ else
{
setConfigurations(_defaultConfigurations);
if (isGenerateQuickStart())
@@ -312,8 +312,6 @@ public class JettyWebAppContext extends WebAppContext
getMetaData().addDescriptorProcessor(_preconfigProcessor);
}
}
- else
- setConfigurations(_quickStartConfigurations);
//inject configurations with config from maven plugin

Back to the top