Issue #5264 - Changing Distro to Home in jetty-maven-plugin

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2020-09-22 11:35:15 -05:00
parent d1f6cbb9da
commit 63736990c5
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
16 changed files with 137 additions and 111 deletions

View File

@ -23,4 +23,4 @@ Running Logs
--------------------
The output of each Maven build will be located in /target/it/${project-name}/build.log
The jetty log output for those goals that fork a new process (currently "distro" and "run-forked") can be found in /target/it/${project-name}/jetty-simple-webapp/target/jetty.out.
The jetty log output for those goals that fork a new process (currently "home" and "run-forked") can be found in /target/it/${project-name}/jetty-simple-webapp/target/jetty.out.

View File

@ -246,12 +246,43 @@
<artifactId>jakarta.transaction-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-home</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>zip</type>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>test-jetty-webapp</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.tests</groupId>
<artifactId>test-jndi-webapp</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.tests</groupId>
<artifactId>test-jaas-webapp</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.tests</groupId>
<artifactId>test-spec-webapp</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.tests</groupId>
<artifactId>test-proxy-webapp</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.example-async-rest</groupId>
<artifactId>example-async-rest-webapp</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>

View File

@ -16,7 +16,7 @@
<properties>
<jetty.port.file>${project.build.directory}/jetty-start-distro-port.txt</jetty.port.file>
<jetty.jvmArgs>@jetty.jvmArgs@</jetty.jvmArgs>
<jetty.deployMode>DISTRO</jetty.deployMode>
<jetty.deployMode>HOME</jetty.deployMode>
</properties>
<dependencies>

View File

@ -12,7 +12,7 @@ s.close()
File buildLog = new File( basedir, 'build.log' )
assert buildLog.text.contains( 'Distro process starting' )
assert buildLog.text.contains( 'Home process starting' )
assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.IntegrationTestGetContent')
assert buildLog.text.contains( 'pingServlet ok')
assert buildLog.text.contains( 'helloServlet')

View File

@ -16,7 +16,7 @@
<properties>
<jetty.port.file>${project.build.directory}/jetty-start-war-distro-port.txt</jetty.port.file>
<jetty.jvmArgs>@jetty.jvmArgs@</jetty.jvmArgs>
<jetty.deployMode>DISTRO</jetty.deployMode>
<jetty.deployMode>HOME</jetty.deployMode>
</properties>
<dependencies>

View File

@ -1,35 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
System.out.println( "running postbuild.groovy port " + jettyStopPort + ", key:" + jettyStopKey )
int port = Integer.parseInt( jettyStopPort )
Socket s=new Socket(InetAddress.getByName("127.0.0.1"),port )
OutputStream out=s.getOutputStream()
out.write(( jettyStopKey +"\r\nforcestop\r\n").getBytes())
out.flush()
s.close()
File buildLog = new File( basedir, 'build.log' )
assert buildLog.text.contains( 'Distro process starting' )
assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.IntegrationTestGetContent')
assert buildLog.text.contains( 'pingServlet ok')
assert buildLog.text.contains( 'helloServlet')
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
System.out.println( "running postbuild.groovy port " + jettyStopPort + ", key:" + jettyStopKey )
int port = Integer.parseInt( jettyStopPort )
Socket s=new Socket(InetAddress.getByName("127.0.0.1"),port )
OutputStream out=s.getOutputStream()
out.write(( jettyStopKey +"\r\nforcestop\r\n").getBytes())
out.flush()
s.close()
File buildLog = new File( basedir, 'build.log' )
assert buildLog.text.contains( 'Home process starting' )
assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.IntegrationTestGetContent')
assert buildLog.text.contains( 'pingServlet ok')
assert buildLog.text.contains( 'helloServlet')

View File

@ -77,19 +77,19 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
{
EMBED,
FORK,
DISTRO
HOME
}
/**
* Max number of times to check to see if jetty has started correctly
* when running in FORK or DISTRO mode.
* when running in FORK or HOME mode.
*/
@Parameter (defaultValue = "10")
protected int maxChildStartChecks;
/**
* How long to wait in msec between checks to see if jetty has started
* correctly when running in FORK or DISTRO mode.
* correctly when running in FORK or HOME mode.
*/
@Parameter (defaultValue = "200")
protected long maxChildStartCheckMs;
@ -225,9 +225,9 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
*/
@Parameter
protected Map<String,String> systemProperties;
/**
* Controls how to run jetty. Valid values are EMBED,FORK,DISTRO.
/**
* Controls how to run jetty. Valid values are EMBED,FORK,HOME.
*/
@Parameter (property = "jetty.deployMode", defaultValue = "EMBED")
protected DeploymentMode deployMode;
@ -272,7 +272,7 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
//End of EMBED only
//Start of parameters only valid for FORK/DISTRO
//Start of parameters only valid for FORK/HOME
/**
* Extra environment variables to be passed to the forked process
*/
@ -301,10 +301,9 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
*/
@Parameter
protected String stopKey;
//End of FORK or DISTRO parameters
//Start of parameters only valid for DISTRO
//End of FORK or HOME parameters
//Start of parameters only valid for HOME
/**
* Location of jetty home directory
*/
@ -323,9 +322,8 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
*/
@Parameter
protected String[] modules;
//End of DISTRO only parameters
//End of HOME only parameters
//Start of parameters only valid for FORK
/**
* The file into which to generate the quickstart web xml for the forked process to use
@ -445,9 +443,9 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
startJettyForked();
break;
}
case DISTRO:
case HOME:
{
startJettyDistro();
startJettyHome();
break;
}
default:
@ -460,7 +458,7 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
protected abstract void startJettyForked() throws MojoExecutionException;
protected abstract void startJettyDistro() throws MojoExecutionException;
protected abstract void startJettyHome() throws MojoExecutionException;
protected JettyEmbedder newJettyEmbedder()
throws Exception
@ -504,10 +502,10 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
return jetty;
}
protected JettyDistroForker newJettyDistroForker()
protected JettyHomeForker newJettyHomeForker()
throws Exception
{
JettyDistroForker jetty = new JettyDistroForker();
JettyHomeForker jetty = new JettyHomeForker();
jetty.setStopKey(stopKey);
jetty.setStopPort(stopPort);
jetty.setEnv(env);
@ -548,7 +546,7 @@ public abstract class AbstractWebAppMojo extends AbstractMojo
jetty.setContextXml(contextXml);
if (jettyHome == null)
jetty.setJettyDistro(mavenProjectHelper.resolveArtifact(JETTY_HOME_GROUPID, JETTY_HOME_ARTIFACTID, plugin.getVersion(), "zip"));
jetty.setJettyHomeZip(mavenProjectHelper.resolveArtifact(JETTY_HOME_GROUPID, JETTY_HOME_ARTIFACTID, plugin.getVersion(), "zip"));
jetty.setJettyHome(jettyHome);
jetty.setJettyBase(jettyBase);

View File

@ -72,7 +72,7 @@ public class JettyEffectiveWebXml extends AbstractUnassembledWebAppMojo
}
@Override
protected void startJettyDistro() throws MojoExecutionException
protected void startJettyHome() throws MojoExecutionException
{
generate();
}

View File

@ -44,12 +44,12 @@ import org.eclipse.jetty.util.resource.JarResource;
import org.eclipse.jetty.util.resource.Resource;
/**
* JettyDistroForker
* JettyHomeBaseForker
*
* Unpacks a jetty distribution and configures it with a base that allows it
* Unpacks a jetty-home and configures it with a base that allows it
* to run an unassembled webapp.
*/
public class JettyDistroForker extends AbstractForker
public class JettyHomeForker extends AbstractForker
{
protected MavenWebAppContext webApp;
@ -61,9 +61,9 @@ public class JettyDistroForker extends AbstractForker
protected File jettyHome;
/**
* Zip of jetty distro
* Zip of jetty-home
*/
protected File jettyDistro;
protected File jettyHomeZip;
/**
* Location of existing jetty base directory
@ -135,14 +135,14 @@ public class JettyDistroForker extends AbstractForker
this.contextXml = contextXml;
}
public File getJettyDistro()
public File getJettyHomeZip()
{
return jettyDistro;
return jettyHomeZip;
}
public void setJettyDistro(File jettyDistro)
public void setJettyHomeZip(File jettyHomeZip)
{
this.jettyDistro = jettyDistro;
this.jettyHomeZip = jettyHomeZip;
}
public MavenWebAppContext getWebApp()
@ -229,7 +229,7 @@ public class JettyDistroForker extends AbstractForker
ProcessBuilder builder = new ProcessBuilder(cmd);
builder.directory(workDir);
PluginLog.getLog().info("Distro process starting");
PluginLog.getLog().info("Home process starting");
//set up extra environment vars if there are any
if (!env.isEmpty())
@ -389,20 +389,20 @@ public class JettyDistroForker extends AbstractForker
private void configureJettyHome()
throws Exception
{
if (jettyHome == null && jettyDistro == null)
throw new IllegalStateException("No jettyDistro");
if (jettyHome == null && jettyHomeZip == null)
throw new IllegalStateException("No jettyHome");
if (baseDir == null)
throw new IllegalStateException("No baseDir");
if (jettyHome == null)
{
JarResource res = (JarResource)JarResource.newJarResource(Resource.newResource(jettyDistro));
JarResource res = (JarResource)JarResource.newJarResource(Resource.newResource(jettyHomeZip));
res.copyTo(baseDir);
//zip will unpack to target/jetty-home-<VERSION>
String name = jettyDistro.getName();
String name = jettyHome.getName();
int i = name.lastIndexOf('.');
name = (i > 0 ? name.substring(0, i) : "distro");
name = (i > 0 ? name.substring(0, i) : "home");
jettyHome = new File(baseDir, name);
}
}

View File

@ -74,11 +74,11 @@ public class JettyRunMojo extends AbstractUnassembledWebAppMojo
/**
* Only one of the following will be used, depending the mode
* the mojo is started in: EMBED, FORK, DISTRO
* the mojo is started in: EMBED, FORK, HOME
*/
protected JettyEmbedder embedder;
protected JettyForker forker;
protected JettyDistroForker distroForker;
protected JettyHomeForker homeForker;
@Override
public void execute() throws MojoExecutionException, MojoFailureException
@ -124,15 +124,15 @@ public class JettyRunMojo extends AbstractUnassembledWebAppMojo
}
@Override
public void startJettyDistro() throws MojoExecutionException
public void startJettyHome() throws MojoExecutionException
{
try
{
distroForker = newJettyDistroForker();
distroForker.setWaitForChild(true); //we always run at the command line, echo child output and wait for it
homeForker = newJettyHomeForker();
homeForker.setWaitForChild(true); //we always run at the command line, echo child output and wait for it
//TODO is it ok to start the scanner before we start jetty?
startScanner();
distroForker.start(); //forks a jetty distro
homeForker.start(); //forks a jetty distro
}
catch (Exception e)
{
@ -371,7 +371,7 @@ public class JettyRunMojo extends AbstractUnassembledWebAppMojo
scanner.start();
break;
}
case DISTRO:
case HOME:
{
verifyPomConfiguration();
if (reconfigure)
@ -379,7 +379,7 @@ public class JettyRunMojo extends AbstractUnassembledWebAppMojo
getLog().info("Reconfiguring scanner after change to pom.xml ...");
warArtifacts = null; //TODO if there are any changes to the pom, then we would have to tell the
//existing forked distro process to stop, then rerun the configuration and then refork - too complicated??!
//existing forked home process to stop, then rerun the configuration and then refork - too complicated??!
if (scanner != null)
{
scanner.reset();
@ -388,7 +388,7 @@ public class JettyRunMojo extends AbstractUnassembledWebAppMojo
}
configureWebApp();
//regenerate the webapp and redeploy it
distroForker.redeployWebApp();
homeForker.redeployWebApp();
//restart scanner
if (scanner != null)
scanner.start();

View File

@ -68,7 +68,7 @@ public class JettyRunWarMojo extends AbstractWebAppMojo
protected Scanner scanner;
protected JettyEmbedder embedder;
protected JettyForker forker;
protected JettyDistroForker distroForker;
protected JettyHomeForker homeForker;
protected Path war;
@Override
@ -133,15 +133,14 @@ public class JettyRunWarMojo extends AbstractWebAppMojo
* Deploy the built war to a jetty distro.
*/
@Override
public void startJettyDistro() throws MojoExecutionException
public void startJettyHome() throws MojoExecutionException
{
try
{
distroForker = newJettyDistroForker();
distroForker.setWaitForChild(true); //we always run at the command line, echo child output and wait for it
homeForker = newJettyHomeForker();
homeForker.setWaitForChild(true); //we always run at the command line, echo child output and wait for it
startScanner();
distroForker.start(); //forks a jetty distro
homeForker.start(); //forks a jetty distro
}
catch (Exception e)
{
@ -268,7 +267,7 @@ public class JettyRunWarMojo extends AbstractWebAppMojo
break;
}
case DISTRO:
case HOME:
{
verifyPomConfiguration();
if (reconfigure)
@ -280,7 +279,7 @@ public class JettyRunWarMojo extends AbstractWebAppMojo
}
configureWebApp();
//regenerate the webapp and redeploy it
distroForker.redeployWebApp();
homeForker.redeployWebApp();
//restart scanner
scanner.start();

View File

@ -91,16 +91,16 @@ public class JettyStartMojo extends AbstractUnassembledWebAppMojo
* jetty:stop goal to terminate
*/
@Override
public void startJettyDistro() throws MojoExecutionException
public void startJettyHome() throws MojoExecutionException
{
try
{
JettyDistroForker jetty = newJettyDistroForker();
JettyHomeForker jetty = newJettyHomeForker();
jetty.setWaitForChild(false); //never wait for child to finish
jetty.setMaxChildStartChecks(maxChildStartChecks);
jetty.setMaxChildStartCheckMs(maxChildStartCheckMs);
jetty.setJettyOutputFile(getJettyOutputFile("jetty-start.out"));
jetty.start(); //forks a jetty distro
jetty.start(); //forks a jetty home
}
catch (Exception e)
{

View File

@ -50,7 +50,7 @@ import org.eclipse.jetty.util.StringUtil;
* </p>
* <p>
* You can configure this goal to run the webapp either in-process with maven, or
* forked into a new process, or deployed into a jetty distribution.
* forked into a new process, or deployed into a {@code ${jetty.base}} directory.
* </p>
*/
@Mojo(name = "start-war", requiresDependencyResolution = ResolutionScope.RUNTIME)
@ -61,7 +61,7 @@ public class JettyStartWarMojo extends AbstractWebAppMojo
protected JettyEmbedder embedder;
protected JettyForker forker;
protected JettyDistroForker distroForker;
protected JettyHomeForker homeForker;
@Override
public void configureWebApp() throws Exception
@ -122,16 +122,16 @@ public class JettyStartWarMojo extends AbstractWebAppMojo
* Fork a jetty distro to run the given war.
*/
@Override
public void startJettyDistro() throws MojoExecutionException
public void startJettyHome() throws MojoExecutionException
{
try
{
distroForker = newJettyDistroForker();
distroForker.setWaitForChild(false); //never wait for child tofinish
distroForker.setMaxChildStartCheckMs(maxChildStartCheckMs);
distroForker.setMaxChildStartChecks(maxChildStartChecks);
distroForker.setJettyOutputFile(getJettyOutputFile("jetty-start-war.out"));
distroForker.start(); //forks a jetty distro
homeForker = newJettyHomeForker();
homeForker.setWaitForChild(false); //never wait for child tofinish
homeForker.setMaxChildStartCheckMs(maxChildStartCheckMs);
homeForker.setMaxChildStartChecks(maxChildStartChecks);
homeForker.setJettyOutputFile(getJettyOutputFile("jetty-start-war.out"));
homeForker.start(); //forks a jetty distro
}
catch (Exception e)
{

View File

@ -61,7 +61,7 @@ public class JettyStopMojo extends AbstractWebAppMojo
}
@Override
protected void startJettyDistro() throws MojoExecutionException
protected void startJettyHome() throws MojoExecutionException
{
//Does not start jetty
return;

View File

@ -25,7 +25,7 @@ import org.eclipse.jetty.util.resource.Resource;
* ServerListener
*
* Listener to create a file that signals that the startup is completed.
* Used by the JettyRunDistro maven goal to determine that the child
* Used by the JettyRunHome maven goal to determine that the child
* process is started, and that jetty is ready.
*/
public class ServerListener implements LifeCycle.Listener

View File

@ -102,9 +102,7 @@ public class TestForkedChild
{
baseDir = MavenTestingUtils.getTestResourceDir("root");
testDir = MavenTestingUtils.getTargetTestingDir("forkedChild");
if (testDir.exists())
FS.delete(testDir);
testDir.mkdirs();
FS.ensureEmpty(testDir);
tmpDir = new File(testDir, "tmp");
webappPropsFile = new File(testDir, "webapp.props");