From d72718b67f7dc15105485f26fe54345e07dadfe2 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Fri, 23 Jun 2017 14:55:44 +1000 Subject: [PATCH] fix run forked support of reactor projects Signed-off-by: olivier lamy --- jetty-maven-plugin/pom.xml | 11 ++--- .../jetty-simple-webapp/pom.xml | 4 ++ .../it/jetty-run-forked-mojo-it/postbuild.foo | 8 --- .../jetty-run-forked-mojo-it/postbuild.groovy | 13 +++++ .../maven/plugin/JettyRunForkedMojo.java | 49 ++++++++++++------- .../jetty/maven/plugin/ServerSupport.java | 2 +- .../eclipse/jetty/maven/plugin/Starter.java | 36 +++++++++----- 7 files changed, 77 insertions(+), 46 deletions(-) delete mode 100644 jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.foo create mode 100644 jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.groovy diff --git a/jetty-maven-plugin/pom.xml b/jetty-maven-plugin/pom.xml index 29a15d50215..5cee41ef475 100644 --- a/jetty-maven-plugin/pom.xml +++ b/jetty-maven-plugin/pom.xml @@ -15,6 +15,7 @@ ${project.groupId}.maven.plugin false FOOBEER + @@ -193,7 +194,7 @@ org.apache.maven.plugins maven-invoker-plugin - 3.0.0 + 3.0.1-SNAPSHOT integration-test @@ -212,14 +213,12 @@ */pom.xml - setup - verify ${project.build.directory}/local-repo src/it/settings.xml - ${jetty.stopKey} - ${jetty.stopPort} - ${jetty.runPort} + ${jetty.stopKey} + ${jetty.stopPort} + ${jetty.runPort} clean diff --git a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/pom.xml b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/pom.xml index 21f5b01073a..3c6f21d22ea 100644 --- a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/jetty-simple-webapp/pom.xml @@ -16,6 +16,7 @@ @jetty.runPort@ + @jetty.jvmArgs@ @@ -89,8 +90,10 @@ true false ${project.build.directory}/config/jetty.xml + ${jetty.jvmArgs} + diff --git a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.foo b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.foo deleted file mode 100644 index 134e91137c7..00000000000 --- a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.foo +++ /dev/null @@ -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() \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.groovy b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.groovy new file mode 100644 index 00000000000..8a524044e2a --- /dev/null +++ b/jetty-maven-plugin/src/it/jetty-run-forked-mojo-it/postbuild.groovy @@ -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() \ No newline at end of file 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 6e6b35b46a3..4de7f20ae53 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 @@ -18,6 +18,17 @@ 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.BufferedReader; import java.io.File; @@ -40,18 +51,6 @@ import java.util.Properties; import java.util.Random; 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. @@ -172,15 +171,14 @@ public class JettyRunForkedMojo extends JettyRunMojo } - @Override /** * we o */ - protected MavenProject getProjectReferences( Artifact artifact, MavenProject project ) - { - - return null; - } +// protected MavenProject getProjectReferences( Artifact artifact, MavenProject project ) +// { +// +// return null; +// } /** * ConsoleStreamer @@ -519,6 +517,19 @@ public class JettyRunForkedMojo extends JettyRunMojo 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 List deps = webApp.getWebInfLib(); StringBuffer strbuff = new StringBuffer(); @@ -587,7 +598,7 @@ public class JettyRunForkedMojo extends JettyRunMojo List warArtifacts = new ArrayList(); for ( Iterator iter = project.getArtifacts().iterator(); iter.hasNext(); ) { - Artifact artifact = (Artifact) iter.next(); + Artifact artifact = iter.next(); if (artifact.getType().equals("war")) warArtifacts.add(artifact); diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java index eeda81108f0..3b0512ced41 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java @@ -164,7 +164,7 @@ public class ServerSupport if (server == null) return null; - return (ContextHandlerCollection)server.getChildHandlerByClass(ContextHandlerCollection.class); + return server.getChildHandlerByClass(ContextHandlerCollection.class); } diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Starter.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Starter.java index 37a155f6b89..88f542db616 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Starter.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/Starter.java @@ -22,7 +22,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.URL; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.Enumeration; import java.util.HashSet; import java.util.Iterator; @@ -30,6 +32,8 @@ import java.util.List; import java.util.Properties; import java.util.Set; 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.Server; @@ -174,31 +178,31 @@ public class Starter //apply a properties file that defines the things that we configure in the jetty:run plugin: // - the context path - String str = (String)props.get("context.path"); + String str = props.getProperty("context.path"); if (str != null) webApp.setContextPath(str); // - web.xml - str = (String)props.get("web.xml"); + str = props.getProperty("web.xml"); if (str != null) webApp.setDescriptor(str); - str = (String)props.get("quickstart.web.xml"); + str = props.getProperty("quickstart.web.xml"); if (str != null) webApp.setQuickStartWebDescriptor(Resource.newResource(new File(str))); // - the tmp directory - str = (String)props.getProperty("tmp.dir"); + str = props.getProperty("tmp.dir"); if (str != null) webApp.setTempDirectory(new File(str.trim())); - str = (String)props.getProperty("tmp.dir.persist"); + str = props.getProperty("tmp.dir.persist"); if (str != null) webApp.setPersistTempDirectory(Boolean.valueOf(str)); //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())) { ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str)); @@ -207,7 +211,7 @@ public class Starter } //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())) { ResourceCollection bases = new ResourceCollection(StringUtil.csvSplit(str)); @@ -215,9 +219,9 @@ public class Starter } //For overlays - str = (String)props.getProperty("maven.war.includes"); + str = props.getProperty("maven.war.includes"); List defaultWarIncludes = fromCSV(str); - str = (String)props.getProperty("maven.war.excludes"); + str = props.getProperty("maven.war.excludes"); List defaultWarExcludes = fromCSV(str); //List of war artifacts @@ -288,19 +292,18 @@ public class Starter // - the equivalent of web-inf classes - str = (String)props.getProperty("classes.dir"); + str = props.getProperty("classes.dir"); if (str != null && !"".equals(str.trim())) { webApp.setClasses(new File(str)); } - str = (String)props.getProperty("testClasses.dir"); + str = props.getProperty("testClasses.dir"); if (str != null && !"".equals(str.trim())) { webApp.setTestClasses(new File(str)); } - // - the equivalent of web-inf lib str = props.getProperty("lib.jars"); if (str != null && !"".equals(str.trim())) @@ -311,6 +314,15 @@ public class Starter jars.add(new File(names[j].trim())); webApp.setWebInfLib(jars); } + + str = props.getProperty( "projects.classes.dir" ); + if (str != null && !"".equals(str.trim())) + { + List classesDirectories = // + Arrays.stream(str.split( Pattern.quote("|") )) // + .map( s -> Paths.get( s).toFile() ).collect( Collectors.toList() ); + webApp.getWebInfLib().addAll( classesDirectories ); + } }