diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/BaseHome.java b/jetty-start/src/main/java/org/eclipse/jetty/start/BaseHome.java index 8ac34054d01..063dfb41c6a 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/BaseHome.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/BaseHome.java @@ -136,19 +136,34 @@ public class BaseHome Pattern jetty_home = Pattern.compile("(-D)?jetty.home=(.*)"); Pattern jetty_base = Pattern.compile("(-D)?jetty.base=(.*)"); + File homePath = null; + File basePath = null; + for (String arg : args.getCommandLine()) { Matcher home_match = jetty_home.matcher(arg); if (home_match.matches()) { - setHomeDir(new File(home_match.group(2))); + homePath = new File(home_match.group(2)); } Matcher base_match = jetty_base.matcher(arg); if (base_match.matches()) { - setBaseDir(new File(base_match.group(2))); + basePath = new File(base_match.group(2)); } } + + if (homePath != null) + { + // logic if home is specified + this.homeDir = homePath; + this.baseDir = basePath == null?homePath:basePath; + } + else if (basePath != null) + { + // logic if home is undeclared + this.baseDir = basePath; + } } public boolean isBaseDifferent() 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 7c1d469d6dc..1c0b269d4cd 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 @@ -23,6 +23,8 @@ import static org.hamcrest.Matchers.*; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; @@ -97,6 +99,11 @@ public class ConfigurationAssert while (nameEnum.hasMoreElements()) { String name = nameEnum.nextElement(); + if ("jetty.home".equals(name) || "jetty.base".equals(name)) + { + // strip these out from assertion, to make assertions easier. + continue; + } String value = args.getProperties().getProperty(name); actualProperties.add(name + "=" + value); } @@ -105,13 +112,107 @@ public class ConfigurationAssert private static void assertContainsUnordered(String msg, Set expectedSet, Set actualSet) { - boolean mismatch = true; + // same size? + boolean mismatch = expectedSet.size() != actualSet.size(); + + // test content + Set missing = new HashSet<>(); + for (String expected : expectedSet) + { + if (!actualSet.contains(expected)) + { + missing.add(expected); + } + } + + if (mismatch || missing.size() > 0) + { + // build up detailed error message + StringWriter message = new StringWriter(); + PrintWriter err = new PrintWriter(message); + + err.printf("%s: Assert Contains (Unordered)",msg); + if (mismatch) + { + err.print(" [size mismatch]"); + } + if (missing.size() >= 0) + { + err.printf(" [%d entries missing]",missing.size()); + } + err.println(); + err.printf("Actual Entries (size: %d)%n",actualSet.size()); + for (String actual : actualSet) + { + char indicator = expectedSet.contains(actual)?' ':'>'; + err.printf("%s| %s%n",indicator,actual); + } + err.printf("Expected Entries (size: %d)%n",expectedSet.size()); + for (String expected : expectedSet) + { + char indicator = actualSet.contains(expected)?' ':'>'; + err.printf("%s| %s",indicator,expected); + } + err.flush(); + Assert.fail(message.toString()); + } } private static void assertOrdered(String msg, List expectedList, List actualList) { - // TODO Auto-generated method stub + // same size? + boolean mismatch = expectedList.size() != actualList.size(); + // test content + List badEntries = new ArrayList<>(); + int min = Math.min(expectedList.size(),actualList.size()); + int max = Math.max(expectedList.size(),actualList.size()); + for (int i = 0; i < min; i++) + { + if (!expectedList.get(i).equals(actualList.get(i))) + { + badEntries.add(i); + } + } + for (int i = min; i < max; i++) + { + badEntries.add(i); + } + + if (mismatch || badEntries.size() > 0) + { + // build up detailed error message + StringWriter message = new StringWriter(); + PrintWriter err = new PrintWriter(message); + + err.printf("%s: Assert Contains (Unordered)",msg); + if (mismatch) + { + err.print(" [size mismatch]"); + } + if (badEntries.size() >= 0) + { + err.printf(" [%d entries not matched]",badEntries.size()); + } + err.println(); + err.printf("Actual Entries (size: %d)%n",actualList.size()); + for (int i = 0; i < actualList.size(); i++) + { + String actual = actualList.get(i); + char indicator = badEntries.contains(i)?'>':' '; + err.printf("%s[%d] %s%n",indicator,i,actual); + } + + err.printf("Expected Entries (size: %d)%n",expectedList.size()); + for (int i = 0; i < expectedList.size(); i++) + { + String expected = expectedList.get(i); + char indicator = badEntries.contains(i)?'>':' '; + err.printf("%s[%d] %s%n",indicator,i,expected); + } + err.flush(); + Assert.fail(message.toString()); + } } private static String getValue(String arg) 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 949ccec8965..a556fc0bf83 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 @@ -25,24 +25,25 @@ import java.util.List; import java.util.Vector; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.junit.Before; import org.junit.Test; public class MainTest { - @Before - public void setUp() throws Exception + private void addUseCasesHome(List cmdLineArgs) { File testJettyHome = MavenTestingUtils.getTestResourceDir("usecases/home"); - System.setProperty("jetty.home",testJettyHome.getAbsolutePath()); + cmdLineArgs.add("jetty.home=" + testJettyHome); } @Test public void testBasicProcessing() throws Exception { + List cmdLineArgs = new ArrayList<>(); + addUseCasesHome(cmdLineArgs); + cmdLineArgs.add("jetty.port=9090"); + Main main = new Main(); - StartArgs args = main.processCommandLine(new String[] - { "jetty.port=9090" }); + StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()])); BaseHome baseHome = main.getBaseHome(); System.err.println(args); @@ -54,6 +55,8 @@ public class MainTest { List cmdLineArgs = new ArrayList<>(); + addUseCasesHome(cmdLineArgs); + // JVM args cmdLineArgs.add("--exec"); cmdLineArgs.add("-Xms1024m"); @@ -66,7 +69,7 @@ public class MainTest Main main = new Main(); - StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[6])); + StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()])); BaseHome baseHome = main.getBaseHome(); System.err.println(args); @@ -76,7 +79,7 @@ public class MainTest public void testJettyHomeWithSpaces() { List cmdLineArgs = new ArrayList<>(); - + // main.addJvmArgs(jvmArgs); // // Classpath classpath = nastyWayToCreateAClasspathObject("/jetty/home with spaces/"); diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/UseCases.java b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java similarity index 98% rename from jetty-start/src/test/java/org/eclipse/jetty/start/UseCases.java rename to jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java index d8289854f9d..6b0bc0e1d30 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/UseCases.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java @@ -28,7 +28,7 @@ import org.junit.Test; /** * Various Home + Base use cases */ -public class UseCases +public class TestUseCases { private void assertUseCase(String homeName, String baseName, String assertName) throws Exception { diff --git a/jetty-start/src/test/resources/usecases/assert-barebones.txt b/jetty-start/src/test/resources/usecases/assert-barebones.txt index 1349723c154..164f3f99f4b 100644 --- a/jetty-start/src/test/resources/usecases/assert-barebones.txt +++ b/jetty-start/src/test/resources/usecases/assert-barebones.txt @@ -1,28 +1,15 @@ # The XMLs we expect (order is important) -XML|${jetty.home}/etc/jetty-jmx.xml XML|${jetty.home}/etc/jetty.xml XML|${jetty.home}/etc/jetty-http.xml -XML|${jetty.home}/etc/jetty-plus.xml -XML|${jetty.home}/etc/jetty-annotations.xml -XML|${jetty.home}/etc/jetty-websockets.xml # The LIBs we expect (order is irrelevant) -LIB|${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar -LIB|${jetty.home}/lib/annotations/org.objectweb.asm-TEST.jar -LIB|${jetty.home}/lib/jetty-annotations-TEST.jar LIB|${jetty.home}/lib/jetty-continuation-TEST.jar LIB|${jetty.home}/lib/jetty-http-TEST.jar LIB|${jetty.home}/lib/jetty-io-TEST.jar -LIB|${jetty.home}/lib/jetty-jmx-TEST.jar -LIB|${jetty.home}/lib/jetty-jndi-TEST.jar -LIB|${jetty.home}/lib/jetty-plus-TEST.jar LIB|${jetty.home}/lib/jetty-schemas-3.1.jar -LIB|${jetty.home}/lib/jetty-security-TEST.jar LIB|${jetty.home}/lib/jetty-server-TEST.jar LIB|${jetty.home}/lib/jetty-util-TEST.jar LIB|${jetty.home}/lib/jetty-xml-TEST.jar -LIB|${jetty.home}/lib/jndi/javax.activation-1.1.jar -LIB|${jetty.home}/lib/jndi/javax.transaction-api-1.2.jar LIB|${jetty.home}/lib/servlet-api-3.1.jar # The Properties we expect (order is irrelevant)