From bddeb8cb775e6a61ed333d524f412d873e51732b Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Aug 2013 12:16:44 -0700 Subject: [PATCH] Re-enabling PropertyPassingTest --- .../jetty/start/CommandLineBuilder.java | 4 +- .../org/eclipse/jetty/start/PropertyDump.java | 34 ++++++++++++++ .../jetty/start/PropertyPassingTest.java | 47 +++---------------- .../test/resources/property-dump-start.config | 8 ---- 4 files changed, 42 insertions(+), 51 deletions(-) delete mode 100644 jetty-start/src/test/resources/property-dump-start.config diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java b/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java index cbce8b02e78..3d088d2b9fe 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java @@ -24,7 +24,7 @@ import java.util.List; public class CommandLineBuilder { - private static File findExecutable(File root, String path) + public static File findExecutable(File root, String path) { String npath = path.replace('/',File.separatorChar); File exe = new File(root,npath); @@ -35,7 +35,7 @@ public class CommandLineBuilder return exe; } - private static String findJavaBin() + public static String findJavaBin() { File javaHome = new File(System.getProperty("java.home")); if (!javaHome.exists()) diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/PropertyDump.java b/jetty-start/src/test/java/org/eclipse/jetty/start/PropertyDump.java index 4928fc0e052..106088aa7bb 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/PropertyDump.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/PropertyDump.java @@ -18,6 +18,10 @@ package org.eclipse.jetty.start; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; import java.util.Enumeration; import java.util.Properties; @@ -25,6 +29,7 @@ public class PropertyDump { public static void main(String[] args) { + // As System Properties Properties props = System.getProperties(); Enumeration names = props.propertyNames(); while (names.hasMoreElements()) @@ -36,6 +41,35 @@ public class PropertyDump System.out.printf("%s=%s%n",name,props.getProperty(name)); } } + + // As File Argument + for (String arg : args) + { + if (arg.endsWith(".properties")) + { + Properties aprops = new Properties(); + File propFile = new File(arg); + System.out.printf("[load file %s]%n",propFile.getName()); + try (FileReader reader = new FileReader(propFile)) + { + aprops.load(reader); + Enumeration anames = aprops.propertyNames(); + while (anames.hasMoreElements()) + { + String name = (String)anames.nextElement(); + if (name.startsWith("test.")) + { + System.out.printf("%s=%s%n",name,aprops.getProperty(name)); + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + System.exit(0); } } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/PropertyPassingTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/PropertyPassingTest.java index 15b4a5e197b..90ae91549c0 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/PropertyPassingTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/PropertyPassingTest.java @@ -32,14 +32,11 @@ import java.util.List; import org.eclipse.jetty.toolchain.test.IO; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.eclipse.jetty.toolchain.test.OS; import org.eclipse.jetty.toolchain.test.TestingDir; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; -@Ignore public class PropertyPassingTest { private static class ConsoleCapture implements Runnable @@ -95,18 +92,17 @@ public class PropertyPassingTest @Test public void testAsJvmArg() throws IOException, InterruptedException { - File testCfg = MavenTestingUtils.getTestResourceFile("property-dump-start.config"); File bogusXml = MavenTestingUtils.getTestResourceFile("bogus.xml"); // Setup command line List commands = new ArrayList<>(); commands.add(getJavaBin()); + commands.add("-Dmain.class=" + PropertyDump.class.getName()); commands.add("-cp"); commands.add(getClassPath()); // addDebug(commands); commands.add("-Dtest.foo=bar"); // TESTING THIS commands.add(getStartJarBin()); - commands.add("--config=" + testCfg.getAbsolutePath()); commands.add(bogusXml.getAbsolutePath()); // Run command, collect output @@ -117,21 +113,19 @@ public class PropertyPassingTest } @Test - @Ignore("not working yet") public void testAsCommandLineArg() throws IOException, InterruptedException { - File testCfg = MavenTestingUtils.getTestResourceFile("property-dump-start.config"); File bogusXml = MavenTestingUtils.getTestResourceFile("bogus.xml"); // Setup command line List commands = new ArrayList<>(); commands.add(getJavaBin()); + commands.add("-Dmain.class=" + PropertyDump.class.getName()); commands.add("-cp"); commands.add(getClassPath()); // addDebug(commands); commands.add(getStartJarBin()); commands.add("test.foo=bar"); // TESTING THIS - commands.add("--config=" + testCfg.getAbsolutePath()); commands.add(bogusXml.getAbsolutePath()); // Run command, collect output @@ -144,18 +138,17 @@ public class PropertyPassingTest @Test public void testAsDashDCommandLineArg() throws IOException, InterruptedException { - File testCfg = MavenTestingUtils.getTestResourceFile("property-dump-start.config"); File bogusXml = MavenTestingUtils.getTestResourceFile("bogus.xml"); // Setup command line List commands = new ArrayList<>(); commands.add(getJavaBin()); + commands.add("-Dmain.class=" + PropertyDump.class.getName()); commands.add("-cp"); commands.add(getClassPath()); // addDebug(commands); commands.add(getStartJarBin()); commands.add("-Dtest.foo=bar"); // TESTING THIS - commands.add("--config=" + testCfg.getAbsolutePath()); commands.add(bogusXml.getAbsolutePath()); // Run command, collect output @@ -199,7 +192,8 @@ public class PropertyPassingTest ConsoleCapture stdErrPump = new ConsoleCapture("STDERR",pid.getErrorStream()).start(); int exitCode = pid.waitFor(); - if(exitCode != 0) { + if (exitCode != 0) + { System.out.printf("STDERR: [" + stdErrPump.getConsoleOutput() + "]%n"); System.out.printf("STDOUT: [" + stdOutPump.getConsoleOutput() + "]%n"); Assert.assertThat("Exit code",exitCode,is(0)); @@ -214,35 +208,6 @@ public class PropertyPassingTest private String getJavaBin() { - File javaHome = new File(System.getProperty("java.home")); - if (!javaHome.exists()) - { - return null; - } - - File javabin = findExecutable(javaHome,"bin/java"); - if (javabin != null) - { - return javabin.getAbsolutePath(); - } - - javabin = findExecutable(javaHome,"bin/java.exe"); - if (javabin != null) - { - return javabin.getAbsolutePath(); - } - - return "java"; - } - - private File findExecutable(File root, String path) - { - String npath = OS.separators(path); - File exe = new File(root,npath); - if (!exe.exists()) - { - return null; - } - return exe; + return CommandLineBuilder.findJavaBin(); } } diff --git a/jetty-start/src/test/resources/property-dump-start.config b/jetty-start/src/test/resources/property-dump-start.config deleted file mode 100644 index f38e5a426a8..00000000000 --- a/jetty-start/src/test/resources/property-dump-start.config +++ /dev/null @@ -1,8 +0,0 @@ - -org.eclipse.jetty.start.PropertyDump.class - -[*] -$(basedir)/src/test/resources - -[default] -$(basedir)/src/test/resources