From d920ef8c40a1552022e6de32a04d63ed92f9c29b Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 3 Sep 2013 11:26:35 -0700 Subject: [PATCH] 415899 - jetty-start / add --lib= capability from Jetty 7/8 + Adding --lib= concept from Jetty 7/8 to allow for arbitrary library additions, similar to how path= and lib= was used back in those revisions. --- .../org/eclipse/jetty/start/StartArgs.java | 10 ++++++- .../org/eclipse/jetty/start/usage.txt | 9 +++++- .../jetty/start/ConfigurationAssert.java | 29 ++++++++++++++----- .../org/eclipse/jetty/start/MainTest.java | 5 ++++ .../test/resources/assert-home-with-jvm.txt | 3 +- .../src/test/resources/extra-libs/example.jar | 0 .../extra-resources/example.properties | 1 + 7 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 jetty-start/src/test/resources/extra-libs/example.jar create mode 100644 jetty-start/src/test/resources/extra-resources/example.properties diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index d3001317a1c..ae49cf7449e 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -64,7 +64,6 @@ public class StartArgs System.setProperty("jetty.version",VERSION); } - // TODO: might make sense to declare this in modules/base.mod private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration"; private List commandLine = new ArrayList<>(); @@ -669,6 +668,15 @@ public class StartArgs exec = true; return; } + + // Arbitrary Libraries + + if(arg.startsWith("--lib=")) + { + String cp = getValue(arg); + classpath.addClasspath(cp); + return; + } // Module Management diff --git a/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt b/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt index c72edbb5543..ec19dd47c9f 100644 --- a/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt +++ b/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt @@ -6,6 +6,8 @@ Usage: java -jar start.jar [options...] [properties...] [configs...] configured to start any java main class. Command Line Options: +--------------------- + --help This help / usage information. --version Print the version information for Jetty and @@ -23,7 +25,7 @@ Command Line Options: o Properties o Server Classpath o Server XML Configuration - + --dry-run Print the command line that the start.jar generates, then exit. This may be used to generate command lines when the start.ini includes -X or -D arguments. @@ -38,6 +40,9 @@ Debug and Start Logging: ------------------------ --debug Enable debug output of the startup procedure. + Note: this does not setup debug for Jetty itself. + If you want debug for Jetty, configure your logging + (See bellow) --start-log-file= A filename, relative to ${jetty.base}, where all startup @@ -119,6 +124,8 @@ Advanced Commands: location, download it from the given http URI. Note: location is always relative to ${jetty.base} + --lib= + Add arbitrary classpath entries to the the server classpath. System Properties: ------------------ diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java index 8484add4c64..04586a0e267 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; +import java.util.Collection; import java.util.Enumeration; import java.util.HashSet; import java.util.List; @@ -49,6 +50,7 @@ public class ConfigurationAssert */ public static void assertConfiguration(BaseHome baseHome, StartArgs args, String filename) throws FileNotFoundException, IOException { + File testResourcesDir = MavenTestingUtils.getTestResourcesDir(); File file = MavenTestingUtils.getTestResourceFile(filename); TextFile textFile = new TextFile(file); @@ -64,12 +66,12 @@ public class ConfigurationAssert List actualXmls = new ArrayList<>(); for (File xml : args.getXmlFiles()) { - actualXmls.add(baseHome.toShortForm(xml)); + actualXmls.add(shorten(baseHome,xml,testResourcesDir)); } assertOrdered("XML Resolution Order",expectedXmls,actualXmls); // Validate LIBs (order is not important) - Set expectedLibs = new HashSet<>(); + List expectedLibs = new ArrayList<>(); for (String line : textFile) { if (line.startsWith("LIB|")) @@ -77,10 +79,10 @@ public class ConfigurationAssert expectedLibs.add(getValue(line)); } } - Set actualLibs = new HashSet<>(); + List actualLibs = new ArrayList<>(); for (File path : args.getClasspath()) { - actualLibs.add(baseHome.toShortForm(path)); + actualLibs.add(shorten(baseHome,path,testResourcesDir)); } assertContainsUnordered("Libs",expectedLibs,actualLibs); @@ -93,7 +95,7 @@ public class ConfigurationAssert expectedProperties.add(getValue(line)); } } - Set actualProperties = new HashSet<>(); + List actualProperties = new ArrayList<>(); @SuppressWarnings("unchecked") Enumeration nameEnum = (Enumeration)args.getProperties().propertyNames(); while (nameEnum.hasMoreElements()) @@ -110,7 +112,7 @@ public class ConfigurationAssert assertContainsUnordered("Properties",expectedProperties,actualProperties); // Validate Downloads - Set expectedDownloads = new HashSet<>(); + List expectedDownloads = new ArrayList<>(); for (String line : textFile) { if (line.startsWith("DOWNLOAD|")) @@ -118,7 +120,7 @@ public class ConfigurationAssert expectedDownloads.add(getValue(line)); } } - Set actualDownloads = new HashSet<>(); + List actualDownloads = new ArrayList<>(); for (DownloadArg darg : args.getDownloads()) { actualDownloads.add(String.format("%s:%s",darg.uri,darg.location)); @@ -127,7 +129,18 @@ public class ConfigurationAssert } - private static void assertContainsUnordered(String msg, Set expectedSet, Set actualSet) + private static String shorten(BaseHome baseHome, File path, File testResourcesDir) + { + String value = baseHome.toShortForm(path); + if (value.startsWith(testResourcesDir.getAbsolutePath())) + { + int len = testResourcesDir.getAbsolutePath().length(); + value = "${maven-test-resources}" + value.substring(len); + } + return value; + } + + private static void assertContainsUnordered(String msg, Collection expectedSet, Collection actualSet) { // same size? boolean mismatch = expectedSet.size() != actualSet.size(); diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java index 15f2fab11d9..713d5df9494 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java @@ -101,6 +101,11 @@ public class MainTest cmdLineArgs.add("--exec"); cmdLineArgs.add("-Xms1024m"); cmdLineArgs.add("-Xmx1024m"); + + // Arbitrary Libs + File extraJar = MavenTestingUtils.getTestResourceFile("extra-libs/example.jar"); + File extraDir = MavenTestingUtils.getTestResourceDir("extra-resources"); + cmdLineArgs.add(String.format("--lib=%s%s%s",extraJar.getAbsolutePath(),File.pathSeparatorChar,extraDir.getAbsolutePath())); // Arbitrary XMLs cmdLineArgs.add("jetty.xml"); diff --git a/jetty-start/src/test/resources/assert-home-with-jvm.txt b/jetty-start/src/test/resources/assert-home-with-jvm.txt index 165a9e41409..b73061bba42 100644 --- a/jetty-start/src/test/resources/assert-home-with-jvm.txt +++ b/jetty-start/src/test/resources/assert-home-with-jvm.txt @@ -33,7 +33,8 @@ LIB|${jetty.home}/lib/websocket/websocket-client-TEST.jar LIB|${jetty.home}/lib/websocket/websocket-common-TEST.jar LIB|${jetty.home}/lib/websocket/websocket-server-TEST.jar LIB|${jetty.home}/lib/websocket/websocket-servlet-TEST.jar - +LIB|${maven-test-resources}/extra-resources +LIB|${maven-test-resources}/extra-libs/example.jar # The Properties we expect (order is irrelevant) # PROP|jetty.port=9090 diff --git a/jetty-start/src/test/resources/extra-libs/example.jar b/jetty-start/src/test/resources/extra-libs/example.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/extra-resources/example.properties b/jetty-start/src/test/resources/extra-resources/example.properties new file mode 100644 index 00000000000..e7a73e57752 --- /dev/null +++ b/jetty-start/src/test/resources/extra-resources/example.properties @@ -0,0 +1 @@ +# Nothing of importance, just used by ConfigTest.java