fix run forked support of reactor projects

Signed-off-by: olivier lamy <olamy@webtide.com>
This commit is contained in:
olivier lamy 2017-06-23 14:55:44 +10:00 committed by Joakim Erdfelt
parent 1cdc94f0a5
commit 2f9dc58699
7 changed files with 77 additions and 46 deletions

View File

@ -14,6 +14,7 @@
<bundle-symbolic-name>${project.groupId}.maven.plugin</bundle-symbolic-name> <bundle-symbolic-name>${project.groupId}.maven.plugin</bundle-symbolic-name>
<it.debug>false</it.debug> <it.debug>false</it.debug>
<jetty.stopKey>FOOBEER</jetty.stopKey> <jetty.stopKey>FOOBEER</jetty.stopKey>
<jetty.jvmArgs></jetty.jvmArgs>
</properties> </properties>
<build> <build>
<plugins> <plugins>
@ -195,7 +196,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId> <artifactId>maven-invoker-plugin</artifactId>
<version>3.0.0</version> <version>3.0.1-SNAPSHOT</version>
<executions> <executions>
<execution> <execution>
<id>integration-test</id> <id>integration-test</id>
@ -214,14 +215,12 @@
<pomIncludes> <pomIncludes>
<pomInclude>*/pom.xml</pomInclude> <pomInclude>*/pom.xml</pomInclude>
</pomIncludes> </pomIncludes>
<preBuildHookScript>setup</preBuildHookScript>
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile> <settingsFile>src/it/settings.xml</settingsFile>
<scriptVariables> <scriptVariables>
<jetty.stopKey>${jetty.stopKey}</jetty.stopKey> <jettyStopKey>${jetty.stopKey}</jettyStopKey>
<jetty.stopPort>${jetty.stopPort}</jetty.stopPort> <jettyStopPort>${jetty.stopPort}</jettyStopPort>
<jetty.runPort>${jetty.runPort}</jetty.runPort> <jettyRunPort>${jetty.runPort}</jettyRunPort>
</scriptVariables> </scriptVariables>
<goals> <goals>
<goal>clean</goal> <goal>clean</goal>

View File

@ -16,6 +16,7 @@
<properties> <properties>
<jetty.runPort>@jetty.runPort@</jetty.runPort> <jetty.runPort>@jetty.runPort@</jetty.runPort>
<jetty.jvmArgs>@jetty.jvmArgs@</jetty.jvmArgs>
</properties> </properties>
<dependencies> <dependencies>
@ -89,8 +90,10 @@
<nonBlocking>true</nonBlocking> <nonBlocking>true</nonBlocking>
<waitForChild>false</waitForChild> <waitForChild>false</waitForChild>
<jettyXml>${project.build.directory}/config/jetty.xml</jettyXml> <jettyXml>${project.build.directory}/config/jetty.xml</jettyXml>
<jvmArgs>${jetty.jvmArgs}</jvmArgs>
</configuration> </configuration>
</execution> </execution>
<!--
<execution> <execution>
<id>stop-jetty</id> <id>stop-jetty</id>
<phase>test</phase> <phase>test</phase>
@ -98,6 +101,7 @@
<goal>stop</goal> <goal>stop</goal>
</goals> </goals>
</execution> </execution>
-->
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -1,8 +0,0 @@
Socket s=new Socket(InetAddress.getByName("127.0.0.1"),Integer.getInteger( "jetty.runPort" ));
s.setSoLinger(false, 0);
OutputStream out=s.getOutputStream();
out.write((System.getProperty( "jetty.stopKey" )+"\r\n"+command+"\r\n").getBytes());
out.flush();
s.close()

View File

@ -0,0 +1,13 @@
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 )
s.setSoLinger(false, 0)
OutputStream out=s.getOutputStream()
out.write(( jettyStopKey +"\r\nforcestop\r\n").getBytes())
out.flush()
s.close()

View File

@ -18,6 +18,17 @@
package org.eclipse.jetty.maven.plugin; package org.eclipse.jetty.maven.plugin;
import org.apache.maven.artifact.Artifact;
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.server.Server;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -40,18 +51,6 @@ import java.util.Properties;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
/** /**
* This goal is used to deploy your unassembled webapp into a forked JVM. * This goal is used to deploy your unassembled webapp into a forked JVM.
@ -172,15 +171,14 @@ public class JettyRunForkedMojo extends JettyRunMojo
} }
@Override
/** /**
* we o * we o
*/ */
protected MavenProject getProjectReferences( Artifact artifact, MavenProject project ) // protected MavenProject getProjectReferences( Artifact artifact, MavenProject project )
{ // {
//
return null; // return null;
} // }
/** /**
* ConsoleStreamer * ConsoleStreamer
@ -519,6 +517,19 @@ public class JettyRunForkedMojo extends JettyRunMojo
props.put("testClasses.dir", webApp.getTestClasses().getAbsolutePath()); props.put("testClasses.dir", webApp.getTestClasses().getAbsolutePath());
} }
if ( !webApp.getClassPathFiles().isEmpty() )
{
StringBuilder stringBuilder = new StringBuilder();
for ( File dependency : webApp.getClassPathFiles() )
{
if (dependency.isDirectory())
{
stringBuilder.append( dependency.getCanonicalPath() ).append( '|' );
}
}
props.put( "projects.classes.dir", stringBuilder.toString() );
}
//web-inf lib //web-inf lib
List<File> deps = webApp.getWebInfLib(); List<File> deps = webApp.getWebInfLib();
StringBuffer strbuff = new StringBuffer(); StringBuffer strbuff = new StringBuffer();
@ -587,7 +598,7 @@ public class JettyRunForkedMojo extends JettyRunMojo
List<Artifact> warArtifacts = new ArrayList<Artifact>(); List<Artifact> warArtifacts = new ArrayList<Artifact>();
for ( Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); ) for ( Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); )
{ {
Artifact artifact = (Artifact) iter.next(); Artifact artifact = iter.next();
if (artifact.getType().equals("war")) if (artifact.getType().equals("war"))
warArtifacts.add(artifact); warArtifacts.add(artifact);

View File

@ -164,7 +164,7 @@ public class ServerSupport
if (server == null) if (server == null)
return null; return null;
return (ContextHandlerCollection)server.getChildHandlerByClass(ContextHandlerCollection.class); return server.getChildHandlerByClass(ContextHandlerCollection.class);
} }

View File

@ -22,7 +22,9 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -30,6 +32,8 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
@ -174,31 +178,31 @@ public class Starter
//apply a properties file that defines the things that we configure in the jetty:run plugin: //apply a properties file that defines the things that we configure in the jetty:run plugin:
// - the context path // - the context path
String str = (String)props.get("context.path"); String str = props.getProperty("context.path");
if (str != null) if (str != null)
webApp.setContextPath(str); webApp.setContextPath(str);
// - web.xml // - web.xml
str = (String)props.get("web.xml"); str = props.getProperty("web.xml");
if (str != null) if (str != null)
webApp.setDescriptor(str); webApp.setDescriptor(str);
str = (String)props.get("quickstart.web.xml"); str = props.getProperty("quickstart.web.xml");
if (str != null) if (str != null)
webApp.setQuickStartWebDescriptor(Resource.newResource(new File(str))); webApp.setQuickStartWebDescriptor(Resource.newResource(new File(str)));
// - the tmp directory // - the tmp directory
str = (String)props.getProperty("tmp.dir"); str = props.getProperty("tmp.dir");
if (str != null) if (str != null)
webApp.setTempDirectory(new File(str.trim())); webApp.setTempDirectory(new File(str.trim()));
str = (String)props.getProperty("tmp.dir.persist"); str = props.getProperty("tmp.dir.persist");
if (str != null) if (str != null)
webApp.setPersistTempDirectory(Boolean.valueOf(str)); webApp.setPersistTempDirectory(Boolean.valueOf(str));
//Get the calculated base dirs which includes the overlays //Get the calculated base dirs which includes the overlays
str = (String)props.getProperty("base.dirs"); str = props.getProperty("base.dirs");
if (str != null && !"".equals(str.trim())) if (str != null && !"".equals(str.trim()))
{ {
ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str)); ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str));
@ -207,7 +211,7 @@ public class Starter
} }
//Get the original base dirs without the overlays //Get the original base dirs without the overlays
str = (String)props.get("base.dirs.orig"); str = props.getProperty("base.dirs.orig");
if (str != null && !"".equals(str.trim())) if (str != null && !"".equals(str.trim()))
{ {
ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str)); ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str));
@ -215,9 +219,9 @@ public class Starter
} }
//For overlays //For overlays
str = (String)props.getProperty("maven.war.includes"); str = props.getProperty("maven.war.includes");
List<String> defaultWarIncludes = fromCSV(str); List<String> defaultWarIncludes = fromCSV(str);
str = (String)props.getProperty("maven.war.excludes"); str = props.getProperty("maven.war.excludes");
List<String> defaultWarExcludes = fromCSV(str); List<String> defaultWarExcludes = fromCSV(str);
//List of war artifacts //List of war artifacts
@ -288,19 +292,18 @@ public class Starter
// - the equivalent of web-inf classes // - the equivalent of web-inf classes
str = (String)props.getProperty("classes.dir"); str = props.getProperty("classes.dir");
if (str != null && !"".equals(str.trim())) if (str != null && !"".equals(str.trim()))
{ {
webApp.setClasses(new File(str)); webApp.setClasses(new File(str));
} }
str = (String)props.getProperty("testClasses.dir"); str = props.getProperty("testClasses.dir");
if (str != null && !"".equals(str.trim())) if (str != null && !"".equals(str.trim()))
{ {
webApp.setTestClasses(new File(str)); webApp.setTestClasses(new File(str));
} }
// - the equivalent of web-inf lib // - the equivalent of web-inf lib
str = props.getProperty("lib.jars"); str = props.getProperty("lib.jars");
if (str != null && !"".equals(str.trim())) if (str != null && !"".equals(str.trim()))
@ -312,6 +315,15 @@ public class Starter
webApp.setWebInfLib(jars); webApp.setWebInfLib(jars);
} }
str = props.getProperty( "projects.classes.dir" );
if (str != null && !"".equals(str.trim()))
{
List<File> classesDirectories = //
Arrays.stream(str.split( Pattern.quote("|") )) //
.map( s -> Paths.get( s).toFile() ).collect( Collectors.toList() );
webApp.getWebInfLib().addAll( classesDirectories );
}
} }
public void getConfiguration (String[] args) public void getConfiguration (String[] args)