415899 - jetty-start / add --lib=<cp> capability from Jetty 7/8

+ Adding --lib=<cp> concept from Jetty 7/8 to allow for arbitrary
  library additions, similar to how path=<name> and lib=<name>
  was used back in those revisions.
This commit is contained in:
Joakim Erdfelt 2013-09-03 11:26:35 -07:00
parent 02a838bef7
commit d920ef8c40
7 changed files with 46 additions and 11 deletions

View File

@ -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<String> 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

View File

@ -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=<filename>
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=<classpath>
Add arbitrary classpath entries to the the server classpath.
System Properties:
------------------

View File

@ -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<String> 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<String> expectedLibs = new HashSet<>();
List<String> expectedLibs = new ArrayList<>();
for (String line : textFile)
{
if (line.startsWith("LIB|"))
@ -77,10 +79,10 @@ public class ConfigurationAssert
expectedLibs.add(getValue(line));
}
}
Set<String> actualLibs = new HashSet<>();
List<String> 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<String> actualProperties = new HashSet<>();
List<String> actualProperties = new ArrayList<>();
@SuppressWarnings("unchecked")
Enumeration<String> nameEnum = (Enumeration<String>)args.getProperties().propertyNames();
while (nameEnum.hasMoreElements())
@ -110,7 +112,7 @@ public class ConfigurationAssert
assertContainsUnordered("Properties",expectedProperties,actualProperties);
// Validate Downloads
Set<String> expectedDownloads = new HashSet<>();
List<String> expectedDownloads = new ArrayList<>();
for (String line : textFile)
{
if (line.startsWith("DOWNLOAD|"))
@ -118,7 +120,7 @@ public class ConfigurationAssert
expectedDownloads.add(getValue(line));
}
}
Set<String> actualDownloads = new HashSet<>();
List<String> 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<String> expectedSet, Set<String> 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<String> expectedSet, Collection<String> actualSet)
{
// same size?
boolean mismatch = expectedSet.size() != actualSet.size();

View File

@ -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");

View File

@ -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

View File

@ -0,0 +1 @@
# Nothing of importance, just used by ConfigTest.java