parent
67343c5e0f
commit
995e0b6c59
|
@ -814,7 +814,7 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
|
|||
//only unpack if the overlay is newer
|
||||
if (!unpackDir.exists() || (overlay.getResource().lastModified() > unpackDir.lastModified()))
|
||||
{
|
||||
boolean made=unpackDir.mkdirs();
|
||||
boolean made = unpackDir.mkdirs();
|
||||
overlay.getResource().copyTo(unpackDir);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration;
|
||||
import org.eclipse.jetty.quickstart.QuickStartConfiguration.Mode;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
|
||||
/**
|
||||
* JettyForker
|
||||
|
@ -55,7 +50,8 @@ public class JettyForker extends AbstractForker
|
|||
protected String contextXml;
|
||||
|
||||
protected boolean scan;
|
||||
|
||||
|
||||
QuickStartGenerator generator;
|
||||
|
||||
/**
|
||||
* @return the scan
|
||||
|
@ -139,88 +135,25 @@ public class JettyForker extends AbstractForker
|
|||
|
||||
@Override
|
||||
public void doStart ()
|
||||
throws Exception
|
||||
throws Exception
|
||||
{
|
||||
//Run the webapp to create the quickstart file and properties file
|
||||
prepareWebApp();
|
||||
generator = new QuickStartGenerator(forkWebXml, webApp);
|
||||
generator.setContextXml(contextXml);
|
||||
generator.setWebAppPropsFile(webAppPropsFile);
|
||||
generator.setServer(server);
|
||||
generator.generate();
|
||||
super.doStart();
|
||||
}
|
||||
|
||||
|
||||
private void prepareWebApp()
|
||||
throws Exception
|
||||
{
|
||||
if (server == null)
|
||||
server = new Server();
|
||||
|
||||
//ensure handler structure enabled
|
||||
ServerSupport.configureHandlers(server, null, null);
|
||||
|
||||
ServerSupport.configureDefaultConfigurationClasses(server);
|
||||
|
||||
if (webApp == null)
|
||||
webApp = new JettyWebAppContext();
|
||||
|
||||
//set the webapp up to do very little other than generate the quickstart-web.xml
|
||||
webApp.addConfiguration(new MavenQuickStartConfiguration());
|
||||
webApp.setAttribute(QuickStartConfiguration.MODE, Mode.GENERATE);
|
||||
webApp.setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, Resource.newResource(forkWebXml));
|
||||
webApp.setCopyWebDir(false);
|
||||
webApp.setCopyWebInf(false);
|
||||
|
||||
|
||||
//add webapp to our fake server instance
|
||||
ServerSupport.addWebApplication(server, webApp);
|
||||
|
||||
//leave everything unpacked for the forked process to use
|
||||
webApp.setPersistTempDirectory(true);
|
||||
|
||||
generateQuickStart();
|
||||
}
|
||||
|
||||
protected void redeployWebApp ()
|
||||
throws Exception
|
||||
{
|
||||
//regenerating the quickstart will be noticed by the JettyForkedChild process
|
||||
//which will redeploy the webapp
|
||||
generateQuickStart();
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
private void generateQuickStart()
|
||||
throws Exception
|
||||
{
|
||||
if (forkWebXml == null)
|
||||
throw new IllegalStateException ("No forkWebXml");
|
||||
|
||||
if (webAppPropsFile == null)
|
||||
throw new IllegalStateException ("no webAppsPropsFile");
|
||||
|
||||
//if our server has a thread pool associated we can do annotation scanning multithreaded,
|
||||
//otherwise scanning will be single threaded
|
||||
QueuedThreadPool tpool = server.getBean(QueuedThreadPool.class);
|
||||
|
||||
try
|
||||
{
|
||||
if (tpool != null)
|
||||
tpool.start();
|
||||
else
|
||||
webApp.setAttribute(AnnotationConfiguration.MULTI_THREADED, Boolean.FALSE.toString());
|
||||
|
||||
webApp.start(); //just enough to generate the quickstart
|
||||
|
||||
//save config of the webapp BEFORE we stop
|
||||
WebAppPropertyConverter.toProperties(webApp, webAppPropsFile, contextXml);
|
||||
}
|
||||
finally
|
||||
{
|
||||
webApp.stop();
|
||||
if (tpool != null)
|
||||
tpool.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ProcessBuilder createCommand ()
|
||||
{
|
||||
List<String> cmd = new ArrayList<String>();
|
||||
|
|
|
@ -18,9 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.maven.plugin;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
|
@ -53,7 +50,7 @@ public class NewJettyDeployMojo extends AbstractWebAppMojo
|
|||
protected JettyEmbedder embedder;
|
||||
protected JettyForker forker;
|
||||
protected JettyDistroForker distroForker;
|
||||
protected Path war;
|
||||
|
||||
|
||||
@Override
|
||||
public void configureWebApp() throws Exception
|
||||
|
@ -62,8 +59,7 @@ public class NewJettyDeployMojo extends AbstractWebAppMojo
|
|||
throw new MojoExecutionException("No war specified");
|
||||
|
||||
super.configureWebApp();
|
||||
war = Paths.get(webApp.getWar());
|
||||
getLog().info("War = "+war);
|
||||
getLog().info("War = "+webApp.getWar());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,20 +19,44 @@
|
|||
|
||||
package org.eclipse.jetty.maven.plugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
||||
/**
|
||||
* Generate the effective web.xml for a pre-built webapp. This goal will NOT
|
||||
* first build the webapp, it must already exist.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Mojo(name = "neweffective-web-xml", requiresDependencyResolution = ResolutionScope.RUNTIME)
|
||||
public class NewJettyEffectiveWebXml extends AbstractWebAppMojo
|
||||
{
|
||||
/**
|
||||
* The name of the file to generate into
|
||||
*/
|
||||
@Parameter (defaultValue="${project.build.directory}/effective-web.xml")
|
||||
protected File effectiveWebXml;
|
||||
|
||||
@Override
|
||||
public void configureWebApp() throws Exception
|
||||
{
|
||||
//TODO consider if we want to be able to generate for the unassembled webapp: so that we could
|
||||
//bind this into a build phase, and have it generate the quickstart
|
||||
if (StringUtil.isBlank(webApp.getWar()))
|
||||
throw new MojoExecutionException("No war specified");
|
||||
|
||||
super.configureWebApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startJettyEmbedded() throws MojoExecutionException
|
||||
{
|
||||
return; //not starting a full jetty
|
||||
generate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,7 +65,7 @@ public class NewJettyEffectiveWebXml extends AbstractWebAppMojo
|
|||
@Override
|
||||
protected void startJettyForked() throws MojoExecutionException
|
||||
{
|
||||
return; //not starting jetty this way
|
||||
generate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +74,19 @@ public class NewJettyEffectiveWebXml extends AbstractWebAppMojo
|
|||
@Override
|
||||
protected void startJettyDistro() throws MojoExecutionException
|
||||
{
|
||||
return; //not starting jetty
|
||||
generate();
|
||||
}
|
||||
|
||||
private void generate() throws MojoExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
QuickStartGenerator generator = new QuickStartGenerator(effectiveWebXml, webApp);
|
||||
generator.generate();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new MojoExecutionException("Error generating effective web xml", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,20 @@ public class QuickStartGenerator
|
|||
private File webAppPropsFile;
|
||||
private String contextXml;
|
||||
private boolean prepared = false;
|
||||
|
||||
private Server server;
|
||||
private QueuedThreadPool tpool;
|
||||
|
||||
|
||||
/**
|
||||
* @param quickstartXml the file to generate quickstart into
|
||||
* @param webApp the webapp for which to generate quickstart
|
||||
*/
|
||||
public QuickStartGenerator(File quickstartXml, JettyWebAppContext webApp)
|
||||
{
|
||||
this.quickstartXml = quickstartXml;
|
||||
this.webApp = webApp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the webApp
|
||||
*/
|
||||
|
@ -50,14 +63,6 @@ public class QuickStartGenerator
|
|||
return webApp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param webApp the webApp to set
|
||||
*/
|
||||
public void setWebApp(JettyWebAppContext webApp)
|
||||
{
|
||||
this.webApp = webApp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the quickstartXml
|
||||
*/
|
||||
|
@ -65,13 +70,21 @@ public class QuickStartGenerator
|
|||
{
|
||||
return quickstartXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the server
|
||||
*/
|
||||
public Server getServer()
|
||||
{
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param quickstartXml the quickstartXml to set
|
||||
* @param server the server to set
|
||||
*/
|
||||
public void setQuickstartXml(File quickstartXml)
|
||||
public void setServer(Server server)
|
||||
{
|
||||
this.quickstartXml = quickstartXml;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public File getWebAppPropsFile()
|
||||
|
@ -120,27 +133,30 @@ public class QuickStartGenerator
|
|||
|
||||
if (!prepared)
|
||||
{
|
||||
prepareWebApp();
|
||||
prepared = true;
|
||||
|
||||
prepareWebApp();
|
||||
|
||||
if (server == null)
|
||||
server = new Server();
|
||||
|
||||
//ensure handler structure enabled
|
||||
ServerSupport.configureHandlers(server, null, null);
|
||||
|
||||
ServerSupport.configureDefaultConfigurationClasses(server);
|
||||
|
||||
//if our server has a thread pool associated we can do annotation scanning multithreaded,
|
||||
//otherwise scanning will be single threaded
|
||||
if (tpool == null)
|
||||
tpool = server.getBean(QueuedThreadPool.class);
|
||||
|
||||
//add webapp to our fake server instance
|
||||
ServerSupport.addWebApplication(server, webApp);
|
||||
|
||||
//leave everything unpacked for the forked process to use
|
||||
webApp.setPersistTempDirectory(true);
|
||||
}
|
||||
|
||||
Server server = new Server();
|
||||
|
||||
//ensure handler structure enabled
|
||||
ServerSupport.configureHandlers(server, null, null);
|
||||
|
||||
ServerSupport.configureDefaultConfigurationClasses(server);
|
||||
|
||||
//if our server has a thread pool associated we can do annotation scanning multithreaded,
|
||||
//otherwise scanning will be single threaded
|
||||
QueuedThreadPool tpool = server.getBean(QueuedThreadPool.class);
|
||||
|
||||
//add webapp to our fake server instance
|
||||
ServerSupport.addWebApplication(server, webApp);
|
||||
|
||||
//leave everything unpacked for the forked process to use
|
||||
webApp.setPersistTempDirectory(true);
|
||||
|
||||
try
|
||||
{
|
||||
if (tpool != null)
|
||||
|
|
Loading…
Reference in New Issue