From 053b9fe34b34325e1e9a74c4b01d323b04e8cef6 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sat, 17 Aug 2013 11:59:16 -0700 Subject: [PATCH 01/28] Fixing Jar close resource leak --- .../src/main/java/org/eclipse/jetty/start/JarVersion.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java b/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java index 858a2c09e04..efd11ea7d2d 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java @@ -127,10 +127,8 @@ public class JarVersion public static String getVersion(File file) { - try + try(JarFile jar = new JarFile(file)) { - JarFile jar = new JarFile(file); - String version = null; Manifest manifest = jar.getManifest(); From 4a8902885abc87ea5a56235281493a30786db21b Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sat, 17 Aug 2013 11:59:56 -0700 Subject: [PATCH 02/28] Removing CORBA reference?? and adding improved debug method --- .../src/main/java/org/eclipse/jetty/start/Config.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java index 7365199b7e7..2452955374a 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java @@ -45,8 +45,6 @@ import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; -import org.omg.CORBA._PolicyStub; - /** *

* It allows an application to be started with the command "java -jar start.jar". @@ -328,6 +326,14 @@ public class Config System.err.println(msg); } } + + public static void debug(String format, Object ... args) + { + if (DEBUG) + { + System.err.printf(format+"%n",args); + } + } public static void debug(Throwable t) { From fde5e583182228b06c92c6fb2f598b58c5959055 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sat, 17 Aug 2013 12:00:25 -0700 Subject: [PATCH 03/28] More javadoc, minor cleanup --- .../java/org/eclipse/jetty/start/Main.java | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 7390ac88608..cea09e561b5 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -221,7 +221,7 @@ public class Main continue; } - + // Alternative start.config file if (arg.startsWith("--config=")) { _startConfig = arg.substring(9); @@ -230,6 +230,9 @@ public class Main // Special internal indicator that jetty was started by the jetty.sh Daemon + // All this does is setup a start.log that captures startup console output + // in the tiny window of time before the real logger kicks in. + // Useful for capturing when things go horribly wrong if ("--daemon".equals(arg)) { File startDir = new File(System.getProperty("jetty.logs","logs")); @@ -260,6 +263,7 @@ public class Main continue; } + // Start Property (syntax similar to System Property) if (arg.startsWith("-D")) { String[] assign = arg.substring(2).split("=",2); @@ -278,6 +282,7 @@ public class Main continue; } + // Anything else is a JVM argument if (arg.startsWith("-")) { _jvmArgs.add(arg); @@ -379,8 +384,7 @@ public class Main location.replaceAll("/",File.separator); File file = new File(location); - if (Config.isDebug()) - System.err.println("Download to "+file.getAbsolutePath()+(file.exists()?" Exists!":"")); + Config.debug("Download to %s %s",file.getAbsolutePath(),(file.exists()?"[Exists!]":"")); if (file.exists()) return; @@ -536,18 +540,34 @@ public class Main System.exit(EXIT_USAGE); } - String path(String path) + /** + * Replace/Shorten arbitrary path with property strings "${jetty.home}" or "${jetty.base}" where appropriate. + * + * @param path + * the path to shorten + * @return the potentially shortened path + */ + private String path(String path) { - if (path==null) + if (path == null) + { return path; + } if (path.startsWith(_config.getJettyHome())) - path = "${jetty.home}" + path.substring(_config.getJettyHome().length()); - if (_config.getJettyBase()!=null && path.startsWith(_config.getJettyBase())) - path = "${jetty.base}" + path.substring(_config.getJettyBase().length()); + { + return "${jetty.home}" + path.substring(_config.getJettyHome().length()); + } + if (_config.getJettyBase() != null && path.startsWith(_config.getJettyBase())) + { + return "${jetty.base}" + path.substring(_config.getJettyBase().length()); + } return path; } - String path(File file) + /** + * Convenience method for path(file.getCanonicalPath()) + */ + private String path(File file) { try { @@ -679,7 +699,7 @@ public class Main System.out.println(cmd.toString()); } - + // Informational command line, don't run jetty if (_noRun) return; @@ -1214,7 +1234,7 @@ public class Main /** * Convert a start.ini format file into an argument list. */ - List loadStartIni(File ini,String name) + private List loadStartIni(File ini,String name) { if (ini==null || !ini.exists() || ini.isDirectory() || !ini.canRead()) { From 2da91a1bdb21a7a5c54242ec7ee9bf708f646dcb Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sat, 17 Aug 2013 14:26:12 -0700 Subject: [PATCH 04/28] Adding HomeBase to simplify file access logic between jetty.home and jetty.base --- .../org/eclipse/jetty/start/HomeBase.java | 212 ++++++++++++++++++ .../org/eclipse/jetty/start/HomeBaseTest.java | 115 ++++++++++ .../test/resources/hb.1/base/start.d/jmx.ini | 0 .../resources/hb.1/base/start.d/logging.ini | 1 + .../resources/hb.1/base/start.d/myapp.ini | 0 .../src/test/resources/hb.1/base/start.ini | 7 + .../test/resources/hb.1/home/start.d/jmx.ini | 0 .../test/resources/hb.1/home/start.d/jndi.ini | 0 .../test/resources/hb.1/home/start.d/jsp.ini | 0 .../resources/hb.1/home/start.d/logging.ini | 1 + .../test/resources/hb.1/home/start.d/ssl.ini | 0 .../src/test/resources/hb.1/home/start.ini | 11 + 12 files changed, 347 insertions(+) create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java create mode 100644 jetty-start/src/test/java/org/eclipse/jetty/start/HomeBaseTest.java create mode 100644 jetty-start/src/test/resources/hb.1/base/start.d/jmx.ini create mode 100644 jetty-start/src/test/resources/hb.1/base/start.d/logging.ini create mode 100644 jetty-start/src/test/resources/hb.1/base/start.d/myapp.ini create mode 100644 jetty-start/src/test/resources/hb.1/base/start.ini create mode 100644 jetty-start/src/test/resources/hb.1/home/start.d/jmx.ini create mode 100644 jetty-start/src/test/resources/hb.1/home/start.d/jndi.ini create mode 100644 jetty-start/src/test/resources/hb.1/home/start.d/jsp.ini create mode 100644 jetty-start/src/test/resources/hb.1/home/start.d/logging.ini create mode 100644 jetty-start/src/test/resources/hb.1/home/start.d/ssl.ini create mode 100644 jetty-start/src/test/resources/hb.1/home/start.ini diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java new file mode 100644 index 00000000000..7322bb6673a --- /dev/null +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java @@ -0,0 +1,212 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +/** + * File access for ${jetty.home}, and optional ${jetty.base}, directories + */ +public class HomeBase +{ + private static class AllFilter implements FileFilter + { + public static final AllFilter INSTANCE = new AllFilter(); + + @Override + public boolean accept(File pathname) + { + return true; + } + } + + private final File homeDir; + private final File baseDir; + + public HomeBase(File homeDir, File baseDir) + { + this.homeDir = homeDir; + this.baseDir = baseDir; + } + + /** + * Replace/Shorten arbitrary path with property strings "${jetty.home}" or "${jetty.base}" where appropriate. + * + * @param path + * the path to shorten + * @return the potentially shortened path + */ + public String toShortForm(String path) + { + if (path == null) + { + return path; + } + + String value = homeDir.getAbsolutePath(); + + if (path.startsWith(value)) + { + return "${jetty.home}" + path.substring(value.length()); + } + + if (baseDir != null) + { + value = baseDir.getAbsolutePath(); + if (path.startsWith(value)) + { + return "${jetty.base}" + path.substring(value.length()); + } + } + return path; + } + + /** + * Convenience method for toShortForm(file.getCanonicalPath()) + */ + public String toShortForm(File path) + { + try + { + return toShortForm(path.getCanonicalPath()); + } + catch (IOException ignore) + { + /* ignore */ + } + return toShortForm(path.getAbsolutePath()); + } + + /** + * Get a specific file reference. + *

+ * If file exists in ${jetty.base}, return its reference, otherwise return the ${jetty.home} references. + * + * @param relPath + * the path to get. + * @return the file references. + */ + public File getFile(String relPath) + { + String rpath = separators(relPath); + + if (baseDir != null) + { + File file = new File(baseDir,rpath); + if (file.exists()) + { + return file; + } + } + return new File(homeDir,rpath); + } + + public static String separators(String path) + { + StringBuilder ret = new StringBuilder(); + for (char c : path.toCharArray()) + { + if ((c == '/') || (c == '\\')) + { + ret.append(File.separatorChar); + } + else + { + ret.append(c); + } + } + return ret.toString(); + } + + /** + * Get all of the files that are in a specific relative directory. + *

+ * If the same found path exists in both ${jetty.base} and ${jetty.home}, then the one in ${jetty.base} is returned + * (it overrides the one in ${jetty.home}) + * + * @param relPathToDirectory + * the relative path to the directory + * @return the list of files found. + */ + public List listFiles(String relPathToDirectory) + { + return listFiles(relPathToDirectory,AllFilter.INSTANCE); + } + + /** + * Get all of the files that are in a specific relative directory, with applied {@link FileFilter} + *

+ * If the same found path exists in both ${jetty.base} and ${jetty.home}, then the one in ${jetty.base} is returned + * (it overrides the one in ${jetty.home}) + * + * @param relPathToDirectory + * the relative path to the directory + * @param filter + * the filter to use + * @return the list of files found. + */ + public List listFiles(String relPathToDirectory, FileFilter filter) + { + Objects.requireNonNull(filter,"FileFilter cannot be null"); + + File homePath = new File(homeDir,separators(relPathToDirectory)); + List homeFiles = new ArrayList<>(); + homeFiles.addAll(Arrays.asList(homePath.listFiles(filter))); + + if (baseDir != null) + { + // merge + File basePath = new File(baseDir,separators(relPathToDirectory)); + File baseFiles[] = basePath.listFiles(filter); + List ret = new ArrayList<>(); + + for (File base : baseFiles) + { + String relpath = toRelativePath(baseDir,base); + File home = new File(homeDir,separators(relpath)); + if (home.exists()) + { + homeFiles.remove(home); + } + ret.add(base); + } + + // add any remaining home files. + ret.addAll(homeFiles); + + return ret; + } + else + { + // simple return + return homeFiles; + } + } + + private String toRelativePath(File dir, File path) + { + return dir.toURI().relativize(path.toURI()).toASCIIString(); + } +} diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/HomeBaseTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/HomeBaseTest.java new file mode 100644 index 00000000000..5df9f12ea5f --- /dev/null +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/HomeBaseTest.java @@ -0,0 +1,115 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +import static org.hamcrest.Matchers.*; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jetty.toolchain.test.IO; +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.junit.Assert; +import org.junit.Test; + +public class HomeBaseTest +{ + private void assertFileList(HomeBase hb, String message, List expected, List files) + { + List actual = new ArrayList<>(); + for (File file : files) + { + actual.add(hb.toShortForm(file)); + } + Assert.assertThat(message,actual,containsInAnyOrder(expected.toArray())); + } + + @Test + public void testGetFile_OnlyHome() throws IOException + { + File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home"); + File baseDir = null; + + HomeBase hb = new HomeBase(homeDir,baseDir); + File startIni = hb.getFile("/start.ini"); + + String ref = hb.toShortForm(startIni); + Assert.assertThat("Reference",ref,startsWith("${jetty.home}")); + + String contents = IO.readToString(startIni); + Assert.assertThat("Contents",contents,containsString("Home Ini")); + } + + @Test + public void testListFiles_OnlyHome() throws IOException + { + File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home"); + File baseDir = null; + + HomeBase hb = new HomeBase(homeDir,baseDir); + List files = hb.listFiles("/start.d"); + + List expected = new ArrayList<>(); + expected.add("${jetty.home}/start.d/jmx.ini"); + expected.add("${jetty.home}/start.d/jndi.ini"); + expected.add("${jetty.home}/start.d/jsp.ini"); + expected.add("${jetty.home}/start.d/logging.ini"); + expected.add("${jetty.home}/start.d/ssl.ini"); + + assertFileList(hb,"Files found",expected,files); + } + + @Test + public void testListFiles_Both() throws IOException + { + File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home"); + File baseDir = MavenTestingUtils.getTestResourceDir("hb.1/base"); + + HomeBase hb = new HomeBase(homeDir,baseDir); + List files = hb.listFiles("/start.d"); + + List expected = new ArrayList<>(); + expected.add("${jetty.base}/start.d/jmx.ini"); + expected.add("${jetty.home}/start.d/jndi.ini"); + expected.add("${jetty.home}/start.d/jsp.ini"); + expected.add("${jetty.base}/start.d/logging.ini"); + expected.add("${jetty.home}/start.d/ssl.ini"); + expected.add("${jetty.base}/start.d/myapp.ini"); + + assertFileList(hb,"Files found",expected,files); + } + + @Test + public void testGetFile_Both() throws IOException + { + File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home"); + File baseDir = MavenTestingUtils.getTestResourceDir("hb.1/base"); + + HomeBase hb = new HomeBase(homeDir,baseDir); + File startIni = hb.getFile("/start.ini"); + + String ref = hb.toShortForm(startIni); + Assert.assertThat("Reference",ref,startsWith("${jetty.base}")); + + String contents = IO.readToString(startIni); + Assert.assertThat("Contents",contents,containsString("Base Ini")); + } +} diff --git a/jetty-start/src/test/resources/hb.1/base/start.d/jmx.ini b/jetty-start/src/test/resources/hb.1/base/start.d/jmx.ini new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/hb.1/base/start.d/logging.ini b/jetty-start/src/test/resources/hb.1/base/start.d/logging.ini new file mode 100644 index 00000000000..d648d1b1fd8 --- /dev/null +++ b/jetty-start/src/test/resources/hb.1/base/start.d/logging.ini @@ -0,0 +1 @@ +# Base Logging \ No newline at end of file diff --git a/jetty-start/src/test/resources/hb.1/base/start.d/myapp.ini b/jetty-start/src/test/resources/hb.1/base/start.d/myapp.ini new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/hb.1/base/start.ini b/jetty-start/src/test/resources/hb.1/base/start.ini new file mode 100644 index 00000000000..c0ebe8c9a9f --- /dev/null +++ b/jetty-start/src/test/resources/hb.1/base/start.ini @@ -0,0 +1,7 @@ +#=========================================================== +# Base Ini +#=========================================================== + +OPTIONS=jmx +etc/jetty-jmx.xml + diff --git a/jetty-start/src/test/resources/hb.1/home/start.d/jmx.ini b/jetty-start/src/test/resources/hb.1/home/start.d/jmx.ini new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/hb.1/home/start.d/jndi.ini b/jetty-start/src/test/resources/hb.1/home/start.d/jndi.ini new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/hb.1/home/start.d/jsp.ini b/jetty-start/src/test/resources/hb.1/home/start.d/jsp.ini new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/hb.1/home/start.d/logging.ini b/jetty-start/src/test/resources/hb.1/home/start.d/logging.ini new file mode 100644 index 00000000000..7161329d503 --- /dev/null +++ b/jetty-start/src/test/resources/hb.1/home/start.d/logging.ini @@ -0,0 +1 @@ +# Home Logging \ No newline at end of file diff --git a/jetty-start/src/test/resources/hb.1/home/start.d/ssl.ini b/jetty-start/src/test/resources/hb.1/home/start.d/ssl.ini new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/hb.1/home/start.ini b/jetty-start/src/test/resources/hb.1/home/start.ini new file mode 100644 index 00000000000..69a418ea91a --- /dev/null +++ b/jetty-start/src/test/resources/hb.1/home/start.ini @@ -0,0 +1,11 @@ +#=========================================================== +# Home Ini +#=========================================================== + +OPTIONS=Server,jsp,resources,websocket,ext +etc/jetty.xml +start.d/ +etc/jetty-deploy.xml +etc/jetty-webapps.xml +etc/jetty-contexts.xml + From 432bcf5e35f51b8920610c032d66e90b5f2cc7f0 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sat, 17 Aug 2013 14:27:18 -0700 Subject: [PATCH 05/28] Making warning show on System.err --- jetty-start/src/main/java/org/eclipse/jetty/start/Main.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index cea09e561b5..a31f021ab14 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -362,8 +362,8 @@ public class Main // Anything else is considered an XML file. if (xmls.contains(arg)) { - System.out.println("WARN: Argument '" + arg + "' specified multiple times. Check start.ini?"); - System.out.println("Use \"java -jar start.jar --help\" for more information."); + System.err.println("WARN: Argument '" + arg + "' specified multiple times. Check start.ini?"); + System.err.println("Use \"java -jar start.jar --help\" for more information."); } xmls.add(arg); } From a1ca1dd6f818df89d096b1366d2eb58484807b9e Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sat, 17 Aug 2013 14:30:13 -0700 Subject: [PATCH 06/28] Reducing code duplication --- .../src/main/java/org/eclipse/jetty/start/Main.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index a31f021ab14..90e90849421 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -1216,7 +1216,10 @@ public class Main static void usageExit(Throwable t, int exit) { - t.printStackTrace(System.err); + if (t != null) + { + t.printStackTrace(System.err); + } System.err.println(); System.err.println("Usage: java -jar start.jar [options] [properties] [configs]"); System.err.println(" java -jar start.jar --help # for more information"); @@ -1225,10 +1228,7 @@ public class Main static void usageExit(int exit) { - System.err.println(); - System.err.println("Usage: java -jar start.jar [options] [properties] [configs]"); - System.err.println(" java -jar start.jar --help # for more information"); - System.exit(exit); + usageExit(null, exit); } /** From b081559435bbb5791dfda217f621aa3e1c946ee8 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sat, 17 Aug 2013 16:22:20 -0700 Subject: [PATCH 07/28] Making Config use HomeBase q + Cleaning up Start INI handling with new StartIni class + Eliminating recursive sub-ini directory issue + Adding NaturalSort utility class + Adding FS utility class --- .../java/org/eclipse/jetty/start/Config.java | 85 +--- .../main/java/org/eclipse/jetty/start/FS.java | 89 ++++ .../org/eclipse/jetty/start/HomeBase.java | 230 ++++++---- .../java/org/eclipse/jetty/start/Main.java | 430 ++++++------------ .../org/eclipse/jetty/start/NaturalSort.java | 56 +++ .../org/eclipse/jetty/start/StartIni.java | 149 ++++++ .../org/eclipse/jetty/start/HomeBaseTest.java | 21 +- .../org/eclipse/jetty/start/MainTest.java | 25 +- .../jetty/start/PropertyPassingTest.java | 2 + .../src/test/resources/empty.home/start.ini | 3 + 10 files changed, 648 insertions(+), 442 deletions(-) create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/FS.java create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/NaturalSort.java create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java create mode 100644 jetty-start/src/test/resources/empty.home/start.ini diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java index 2452955374a..a44220ad008 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java @@ -170,20 +170,11 @@ public class Config /** * Natural language sorting for key names. */ - private final Comparator keySorter = new Comparator() - { - private final Collator collator = Collator.getInstance(); - - public int compare(String o1, String o2) - { - CollationKey key1 = collator.getCollationKey(o1); - CollationKey key2 = collator.getCollationKey(o2); - return key1.compareTo(key2); - } - }; + private final Comparator keySorter = new NaturalSort.Strings(); private static final String _version; private static boolean DEBUG = false; + private final HomeBase _homebase; private final Map _properties = new HashMap(); private final Map _classpaths = new HashMap(); private final List _xml = new ArrayList(); @@ -207,6 +198,20 @@ public class Config return o1.compareTo(o2); } }); + + public Config() + { + _homebase = new HomeBase(); + setProperty("jetty.home",_homebase.getHome()); + if(_homebase.hasBase()) { + setProperty("jetty.base",_homebase.getBase()); + } + } + + public HomeBase getHomeBase() + { + return _homebase; + } public Classpath defineOption(String option) { @@ -286,32 +291,12 @@ public class Config private void close(InputStream stream) { - if (stream == null) - return; - - try - { - stream.close(); - } - catch (IOException ignore) - { - /* ignore */ - } + FS.close(stream); } private void close(Reader reader) { - if (reader == null) - return; - - try - { - reader.close(); - } - catch (IOException ignore) - { - /* ignore */ - } + FS.close(reader); } public static boolean isDebug() @@ -1024,38 +1009,4 @@ public class Config return buf.toString(); } - - public String getJettyHome() - { - return getProperty("jetty.home"); - } - - public String getJettyBase() - { - return getProperty("jetty.base"); - } - - public File getFileBaseHomeAbs(String filename) - { - File file; - - String base = getJettyBase(); - if (base!=null) - { - file=new File(base,filename); - if (file.exists()) - return file; - } - - file=new File(getJettyHome(),filename); - if (file.exists()) - return file; - - file=new File(filename); - if (file.exists()) - return file; - - return null; - - } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java new file mode 100644 index 00000000000..9476f8425ed --- /dev/null +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java @@ -0,0 +1,89 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +import java.io.Closeable; +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.regex.Pattern; + +public class FS +{ + public static class FilenameRegexFilter implements FileFilter + { + private final Pattern pattern; + + public FilenameRegexFilter(String regex) + { + pattern = Pattern.compile(regex,Pattern.CASE_INSENSITIVE); + } + + @Override + public boolean accept(File path) + { + return pattern.matcher(path.getName()).matches(); + } + } + + public static class IniFilter extends FilenameRegexFilter + { + public IniFilter() + { + super("^.*\\.ini$"); + } + } + + public static class XmlFilter extends FilenameRegexFilter + { + public XmlFilter() + { + super("^.*\\.xml$"); + } + } + + public static boolean isXml(String filename) + { + return Pattern.compile(".xml$",Pattern.CASE_INSENSITIVE).matcher(filename).matches(); + } + + public static boolean isFile(File file) + { + if (file == null) + { + return false; + } + return file.exists() && file.isFile(); + } + + public static void close(Closeable c) + { + if (c == null) + return; + + try + { + c.close(); + } + catch (IOException ignore) + { + /* ignore */ + } + } +} diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java index 7322bb6673a..a7097c612ad 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java @@ -23,6 +23,7 @@ import java.io.FileFilter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -42,87 +43,6 @@ public class HomeBase } } - private final File homeDir; - private final File baseDir; - - public HomeBase(File homeDir, File baseDir) - { - this.homeDir = homeDir; - this.baseDir = baseDir; - } - - /** - * Replace/Shorten arbitrary path with property strings "${jetty.home}" or "${jetty.base}" where appropriate. - * - * @param path - * the path to shorten - * @return the potentially shortened path - */ - public String toShortForm(String path) - { - if (path == null) - { - return path; - } - - String value = homeDir.getAbsolutePath(); - - if (path.startsWith(value)) - { - return "${jetty.home}" + path.substring(value.length()); - } - - if (baseDir != null) - { - value = baseDir.getAbsolutePath(); - if (path.startsWith(value)) - { - return "${jetty.base}" + path.substring(value.length()); - } - } - return path; - } - - /** - * Convenience method for toShortForm(file.getCanonicalPath()) - */ - public String toShortForm(File path) - { - try - { - return toShortForm(path.getCanonicalPath()); - } - catch (IOException ignore) - { - /* ignore */ - } - return toShortForm(path.getAbsolutePath()); - } - - /** - * Get a specific file reference. - *

- * If file exists in ${jetty.base}, return its reference, otherwise return the ${jetty.home} references. - * - * @param relPath - * the path to get. - * @return the file references. - */ - public File getFile(String relPath) - { - String rpath = separators(relPath); - - if (baseDir != null) - { - File file = new File(baseDir,rpath); - if (file.exists()) - { - return file; - } - } - return new File(homeDir,rpath); - } - public static String separators(String path) { StringBuilder ret = new StringBuilder(); @@ -140,6 +60,104 @@ public class HomeBase return ret.toString(); } + private File homeDir; + private File baseDir; + + public HomeBase() + { + String userDir = System.getProperty("user.dir"); + this.homeDir = new File(System.getProperty("jetty.home",userDir)); + String base = System.getProperty("jetty.base"); + if (base != null) + { + this.baseDir = new File(base); + } + } + + public HomeBase(File homeDir, File baseDir) + { + this.homeDir = homeDir; + this.baseDir = baseDir; + } + + public boolean hasBase() + { + return this.baseDir != null; + } + + public void setBaseDir(File dir) + { + this.baseDir = dir; + } + + public File getBaseDir() + { + return baseDir; + } + + public String getBase() + { + if (baseDir == null) + { + return null; + } + return baseDir.getAbsolutePath(); + } + + /** + * Get a specific file reference. + *

+ * File references go through 3 possibly scenarios. + *

    + *
  1. If exists relative to ${jetty.base}, return that reference
  2. + *
  3. If exists relative to ${jetty.home}, return that reference
  4. + *
  5. Otherwise return absolute path reference
  6. + *
+ * + * @param path + * the path to get. + * @return the file reference. + */ + public File getFile(String path) + { + String rpath = separators(path); + + // Relative to Base Directory First + if (baseDir != null) + { + File file = new File(baseDir,rpath); + if (file.exists()) + { + return file; + } + } + + // Then relative to Home Directory + File file = new File(homeDir,rpath); + if (file.exists()) + { + return file; + } + + // Finally, as an absolute path + return new File(rpath); + } + + public void setHomeDir(File dir) + { + this.homeDir = dir; + } + + public File getHomeDir() + { + return homeDir; + } + + public String getHome() + { + return homeDir.getAbsolutePath(); + } + /** * Get all of the files that are in a specific relative directory. *

@@ -196,11 +214,13 @@ public class HomeBase // add any remaining home files. ret.addAll(homeFiles); + Collections.sort(ret, new NaturalSort.Files()); return ret; } else { // simple return + Collections.sort(homeFiles, new NaturalSort.Files()); return homeFiles; } } @@ -209,4 +229,52 @@ public class HomeBase { return dir.toURI().relativize(path.toURI()).toASCIIString(); } + + /** + * Convenience method for toShortForm(file.getCanonicalPath()) + */ + public String toShortForm(File path) + { + try + { + return toShortForm(path.getCanonicalPath()); + } + catch (IOException ignore) + { + /* ignore */ + } + return toShortForm(path.getAbsolutePath()); + } + + /** + * Replace/Shorten arbitrary path with property strings "${jetty.home}" or "${jetty.base}" where appropriate. + * + * @param path + * the path to shorten + * @return the potentially shortened path + */ + public String toShortForm(String path) + { + if (path == null) + { + return path; + } + + String value = homeDir.getAbsolutePath(); + + if (path.startsWith(value)) + { + return "${jetty.home}" + path.substring(value.length()); + } + + if (baseDir != null) + { + value = baseDir.getAbsolutePath(); + if (path.startsWith(value)) + { + return "${jetty.base}" + path.substring(value.length()); + } + } + return path; + } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 90e90849421..292822d73eb 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -26,7 +26,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; -import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -51,17 +50,17 @@ import java.util.Locale; import java.util.Properties; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.regex.Pattern; /*-------------------------------------------*/ /** *

- * Main start class. This class is intended to be the main class listed in the MANIFEST.MF of the start.jar archive. It - * allows an application to be started with the command "java -jar start.jar". + * Main start class. This class is intended to be the main class listed in the MANIFEST.MF of the start.jar archive. It allows an application to be started with + * the command "java -jar start.jar". *

* *

- * The behaviour of Main is controlled by the parsing of the {@link Config} "org/eclipse/start/start.config" file - * obtained as a resource or file. + * The behaviour of Main is controlled by the parsing of the {@link Config} "org/eclipse/start/start.config" file obtained as a resource or file. *

*/ public class Main @@ -78,10 +77,10 @@ public class Main private boolean _dumpVersions = false; private boolean _listConfig = false; private boolean _listOptions = false; - private boolean _noRun=false; + private boolean _noRun = false; private boolean _dryRun = false; private boolean _exec = false; - private final Config _config = new Config(); + private final Config _config; private final Set _sysProps = new HashSet<>(); private final List _jvmArgs = new ArrayList<>(); private final List _enable = new ArrayList<>(); @@ -107,40 +106,39 @@ public class Main Main() throws IOException { - String jetty_home=new File(System.getProperty("jetty.home",".")).getCanonicalPath(); - _config.setProperty("jetty.home",jetty_home); + _config = new Config(); } Config getConfig() { return _config; } - + public List processCommandLine(String[] args) throws Exception { - String source=""; - + String source = ""; + // Handle default ini args ArrayList arguments = new ArrayList<>(Arrays.asList(args)); - boolean ini=false; - for(String arg : arguments) + boolean ini = false; + for (String arg : arguments) if (arg.startsWith("--ini=") || arg.equals("--ini")) ini = true; if (!ini) arguments.add("--ini=start.ini"); - + // The XML Configuration Files to initialize with List xmls = new ArrayList(); // Process the arguments in for loop so list of args can be extended. - for (int i=0;i8?arg.substring(9):arguments.get(++i); - _noRun=true; + String module = arg.length() > 8?arg.substring(9):arguments.get(++i); + _noRun = true; _enable.add(module); } if (arg.startsWith("--disable=") || arg.equals("--disable")) { - String module=arg.length()>9?arg.substring(10):arguments.get(++i); - _noRun=true; + String module = arg.length() > 9?arg.substring(10):arguments.get(++i); + _noRun = true; _disable.add(module); } - + if (arg.startsWith("--ini=") || arg.equals("--ini")) { ini = true; if (arg.length() > 6) { - String name=arg.substring(6); - File file=_config.getFileBaseHomeAbs(name); - arguments.addAll(i+1,loadStartIni(file,name)); + String name = arg.substring(6); + File file = _config.getHomeBase().getFile(name); + StartIni startini = new StartIni(file); + int idx; + while ((idx = startini.lineIndexOf(0,Pattern.compile("^.*/$"))) >= 0) + { + String subPath = startini.getLines().get(idx); + startini.getLines().remove(idx); + // find the sub ini files (based on HomeBase) + List childInis = _config.getHomeBase().listFiles(subPath,new FS.IniFilter()); + for (File childIni : childInis) + { + StartIni cini = new StartIni(childIni); + idx += startini.overlayAt(idx,cini); + } + } + arguments.addAll(i + 1,startini.getLines()); } - + continue; } - + // Alternative start.config file if (arg.startsWith("--config=")) { _startConfig = arg.substring(9); continue; } - - + // Special internal indicator that jetty was started by the jetty.sh Daemon // All this does is setup a start.log that captures startup console output // in the tiny window of time before the real logger kicks in. @@ -299,7 +309,7 @@ public class Main case 2: if ("_SRC_".equals(assign[0])) { - source=assign[1].trim(); + source = assign[1].trim(); } else if ("DEFINE".equals(assign[0])) { @@ -307,29 +317,29 @@ public class Main for (String opt : opts) _config.defineOption(opt.trim()); } - else if ("DEPEND".equals(assign[0])) + else if ("DEPEND".equals(assign[0])) { String opts[] = assign[1].split(","); for (String opt : opts) { - opt=opt.trim(); - if (!_config.getOptions().contains(opt)) + opt = opt.trim(); + if (!_config.getOptions().contains(opt)) { - System.err.printf("ERROR: Missing Dependency: %s DEPEND %s%n",path(source),opt ); - _noRun=true; + System.err.printf("ERROR: Missing Dependency: %s DEPEND %s%n",path(source),opt); + _noRun = true; } } } - else if ("EXCLUDE".equals(assign[0])) + else if ("EXCLUDE".equals(assign[0])) { String opts[] = assign[1].split(","); for (String opt : opts) { - opt=opt.trim(); - if (_config.getOptions().contains(opt)) + opt = opt.trim(); + if (_config.getOptions().contains(opt)) { - System.err.printf("ERROR: Excluded Dependency: %s EXCLUDE %s%n",path(source),opt ); - _noRun=true; + System.err.printf("ERROR: Excluded Dependency: %s EXCLUDE %s%n",path(source),opt); + _noRun = true; } } } @@ -348,7 +358,7 @@ public class Main this._config.setProperty(assign[0],assign[1]); } break; - + case 1: this._config.setProperty(assign[0],null); break; @@ -376,42 +386,42 @@ public class Main try { String[] split = arg.split(":",3); - if (split.length!=3 || "http".equalsIgnoreCase(split[0]) || !split[1].startsWith("//")) + if (split.length != 3 || "http".equalsIgnoreCase(split[0]) || !split[1].startsWith("//")) throw new IllegalArgumentException("Not --download=:"); - - String location=split[2]; - if (File.separatorChar!='/') + + String location = split[2]; + if (File.separatorChar != '/') location.replaceAll("/",File.separator); File file = new File(location); - + Config.debug("Download to %s %s",file.getAbsolutePath(),(file.exists()?"[Exists!]":"")); if (file.exists()) return; - - URL url = new URL(split[0].substring(11)+":"+split[1]); - System.err.println("DOWNLOAD: "+url+" to "+location); + URL url = new URL(split[0].substring(11) + ":" + split[1]); + + System.err.println("DOWNLOAD: " + url + " to " + location); if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); - byte[] buf=new byte[8192]; + byte[] buf = new byte[8192]; try (InputStream in = url.openStream(); OutputStream out = new FileOutputStream(file);) { - while(true) + while (true) { int len = in.read(buf); - if (len>0) + if (len > 0) out.write(buf,0,len); - if (len<0) + if (len < 0) break; } } } - catch(Exception e) + catch (Exception e) { - System.err.println("ERROR: processing "+arg+"\n"+e); + System.err.println("ERROR: processing " + arg + "\n" + e); e.printStackTrace(); usageExit(EXIT_USAGE); } @@ -457,7 +467,7 @@ public class Main } else if (info.equals("@CONFIGS")) { - FileFilter filter =new FileFilter() + FileFilter filter = new FileFilter() { public boolean accept(File path) { @@ -470,45 +480,25 @@ public class Main return (name.startsWith("jetty") && name.endsWith(".xml")); } }; - - // list home etc - File etc = new File(_config.getJettyHome(),"etc"); - if (!etc.exists() || !etc.isDirectory()) - { - System.out.print(indent); - System.out.println("Unable to find/list " + etc); - continue; - } - List configFiles = new ArrayList(); - File[] configs = etc.listFiles(filter); - configFiles.addAll(Arrays.asList(configs)); - - // list base etc - if (!_config.getJettyHome().equals(_config.getJettyBase())) - { - etc = new File(_config.getJettyBase(),"etc"); - if (etc.exists() && etc.isDirectory()) - { - configs = etc.listFiles(filter); - configFiles.addAll(Arrays.asList(configs)); - } - } - - Collections.sort(configFiles); + + // list etc + List configFiles = _config.getHomeBase().listFiles("etc",filter); for (File configFile : configFiles) + { System.out.printf("%s%s%n",indent,path(configFile)); + } } else if (info.equals("@STARTINI")) { for (File file : _iniFiles) { - String path=path(file); + String path = path(file); System.out.printf("%s%s%n",indent,path); if (Config.isDebug()) { - try (FileReader reader=new FileReader(file); BufferedReader in = new BufferedReader(reader);) + try (FileReader reader = new FileReader(file); BufferedReader in = new BufferedReader(reader);) { String arg; while ((arg = in.readLine()) != null) @@ -540,45 +530,16 @@ public class Main System.exit(EXIT_USAGE); } - /** - * Replace/Shorten arbitrary path with property strings "${jetty.home}" or "${jetty.base}" where appropriate. - * - * @param path - * the path to shorten - * @return the potentially shortened path - */ private String path(String path) { - if (path == null) - { - return path; - } - if (path.startsWith(_config.getJettyHome())) - { - return "${jetty.home}" + path.substring(_config.getJettyHome().length()); - } - if (_config.getJettyBase() != null && path.startsWith(_config.getJettyBase())) - { - return "${jetty.base}" + path.substring(_config.getJettyBase().length()); - } - return path; + return _config.getHomeBase().toShortForm(path); } - - /** - * Convenience method for path(file.getCanonicalPath()) - */ - private String path(File file) + + private String path(File file) { - try - { - return path(file.getCanonicalPath()); - } - catch (IOException e) - { - } - return path(file.getAbsolutePath()); + return _config.getHomeBase().toShortForm(file); } - + public void invokeMain(ClassLoader classloader, String classname, List args) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { @@ -622,24 +583,11 @@ public class Main main.invoke(null,method_params); } - /* ------------------------------------------------------------ */ public static void close(Closeable c) { - if (c == null) - { - return; - } - try - { - c.close(); - } - catch (IOException e) - { - e.printStackTrace(System.err); - } + FS.close(c); } - /* ------------------------------------------------------------ */ public void start(List xmls) throws IOException, InterruptedException { // Load potential Config (start.config) @@ -676,7 +624,7 @@ public class Main enable(m); for (String m : _disable) disable(m); - + // Show the usage information and return if (_showUsage) usage(); @@ -698,7 +646,7 @@ public class Main CommandLineBuilder cmd = buildCommandLine(classpath,configuredXmls); System.out.println(cmd.toString()); } - + // Informational command line, don't run jetty if (_noRun) return; @@ -793,26 +741,25 @@ public class Main private String resolveXmlConfig(String xmlFilename) throws FileNotFoundException { - if (!xmlFilename.toLowerCase(Locale.ENGLISH).endsWith(".xml")) + if (!FS.isXml(xmlFilename)) { // Nothing to resolve. return xmlFilename; } - // Look for the file as absolute, jetty-base or jetty-home - File xml = _config.getFileBaseHomeAbs(xmlFilename); - if (xml!=null && xml.isFile()) + // Try normal locations + File xml = _config.getHomeBase().getFile(xmlFilename); + if (FS.isFile(xml)) + { return xml.getAbsolutePath(); - - // Try corrected / for \ - xml = _config.getFileBaseHomeAbs(fixPath(xmlFilename)); - if (xml!=null && xml.isFile()) - return xml.getAbsolutePath(); - - // Try in etc - xml = _config.getFileBaseHomeAbs("etc/"+xmlFilename); - if (xml!=null && xml.isFile()) + } + + // Try again, but prefixed with "etc/" + xml = _config.getHomeBase().getFile("etc/" + xmlFilename); + if (FS.isFile(xml)) + { return xml.getAbsolutePath(); + } throw new FileNotFoundException("Unable to find XML Config: " + xmlFilename); } @@ -825,9 +772,11 @@ public class Main { cmd.addArg(x); } - cmd.addRawArg("-Djetty.home=" + _config.getJettyHome()); - if (_config.getJettyBase()!=null) - cmd.addRawArg("-Djetty.base=" + _config.getJettyBase()); + cmd.addRawArg("-Djetty.home=" + _config.getHomeBase().getHome()); + if (_config.getHomeBase().hasBase()) + { + cmd.addRawArg("-Djetty.base=" + _config.getHomeBase().getBase()); + } // Special Stop/Shutdown properties ensureSystemPropertySet("STOP.PORT"); @@ -857,14 +806,13 @@ public class Main for (String xml : xmls) { - cmd.addRawArg(xml); + cmd.addRawArg(xml); } return cmd; } /** - * Ensure that the System Properties are set (if defined as a System property, or start.config property, or - * start.ini property) + * Ensure that the System Properties are set (if defined as a System property, or start.config property, or start.ini property) * * @param key * the key to be sure of @@ -950,8 +898,13 @@ public class Main System.out.println("Note: If using multiple options (eg: 'Server,servlet,webapp,jms,jmx') " + "then overlapping entries will not be repeated in the eventual classpath."); System.out.println(); - System.out.printf("${jetty.home} = %s%n",_config.getJettyHome()); - System.out.printf("${jetty.base} = %s%n",_config.getJettyBase()); + System.out.printf("${jetty.home} = %s%n",_config.getHomeBase().getHome()); + String base = ""; + if (_config.getHomeBase().hasBase()) + { + base = _config.getHomeBase().getBase(); + } + System.out.printf("${jetty.base} = %s%n",base); System.out.println(); for (String sectionId : sectionIds) @@ -1014,11 +967,6 @@ public class Main System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),path(element)); } - private String fixPath(String path) - { - return path.replace('/',File.separatorChar); - } - private String getVersion(File element) { if (element.isDirectory()) @@ -1079,8 +1027,8 @@ public class Main /** * Load Configuration. * - * No specific configuration is real until a {@link Config#getCombinedClasspath(java.util.Collection)} is used to - * execute the {@link Class} specified by {@link Config#getMainClassname()} is executed. + * No specific configuration is real until a {@link Config#getCombinedClasspath(java.util.Collection)} is used to execute the {@link Class} specified by + * {@link Config#getMainClassname()} is executed. * * @param xmls * the command line specified xml configuration options. @@ -1228,114 +1176,32 @@ public class Main static void usageExit(int exit) { - usageExit(null, exit); - } - - /** - * Convert a start.ini format file into an argument list. - */ - private List loadStartIni(File ini,String name) - { - if (ini==null || !ini.exists() || ini.isDirectory() || !ini.canRead()) - { - System.err.println("Warning - bad ini file: " + name); - // No start.ini found, skip load. - return Collections.emptyList(); - } - - ini=ini.getAbsoluteFile(); - if (!_iniFiles.contains(ini)) - _iniFiles.add(ini); - List args = new ArrayList(); - - args.add("_SRC_="+name); - - FileReader reader = null; - BufferedReader buf = null; - try - { - reader = new FileReader(ini); - buf = new BufferedReader(reader); - - String arg; - while ((arg = buf.readLine()) != null) - { - arg = arg.trim(); - if (arg.length() == 0 || arg.startsWith("#")) - { - continue; - } - - if (arg.endsWith("/")) - { - try - { - File start_d = _config.getFileBaseHomeAbs(arg); - if (start_d!=null && start_d.isDirectory()) - { - _iniDirs.add(start_d); - File[] inis = start_d.listFiles(new FilenameFilter() - { - @Override - public boolean accept(File dir, String name) - { - return name.toLowerCase(Locale.ENGLISH).endsWith(".ini"); - } - }); - Arrays.sort(inis); - - for (File i : inis) - args.addAll(loadStartIni(i,i.getAbsolutePath())); - - args.add("_SRC_="+name); - continue; - } - } - catch(Exception e) - { - e.printStackTrace(); - } - } - - args.add(arg); - } - } - catch (IOException e) - { - usageExit(e,ERR_UNKNOWN); - } - finally - { - Main.close(buf); - Main.close(reader); - } - - return args; + usageExit(null,exit); } void addJvmArgs(List jvmArgs) { _jvmArgs.addAll(jvmArgs); } - + private void enable(final String module) { - final String mini=module+".ini"; - final String disable=module+".ini.disabled"; - final AtomicBoolean found=new AtomicBoolean(false); - FileFilter filter =new FileFilter() + final String mini = module + ".ini"; + final String disable = module + ".ini.disabled"; + final AtomicBoolean found = new AtomicBoolean(false); + FileFilter filter = new FileFilter() { public boolean accept(File path) { if (!path.isFile()) return false; - String n=path.getName(); - int i=n.indexOf(mini); - if (i<0) + String n = path.getName(); + int i = n.indexOf(mini); + if (i < 0) return false; - if (i>0 && i!=4 && n.charAt(i-1)!='-') + if (i > 0 && i != 4 && n.charAt(i - 1) != '-') return false; - + found.set(true); if (n.endsWith(mini)) { @@ -1343,41 +1209,41 @@ public class Main } else if (n.endsWith(disable)) { - String enabled=n.substring(0,n.length()-9); + String enabled = n.substring(0,n.length() - 9); System.err.printf("Enable %s in %s as %s%n",module,path(path.getParent()),enabled); path.renameTo(new File(path.getParentFile(),enabled)); } - else + else System.err.printf("Bad module %s in %s as %s%n",module,path(path.getParent()),n); - + return false; } }; - + for (File dir : _iniDirs) dir.listFiles(filter); - + if (!found.get()) for (File dir : _iniDirs) System.err.printf("Module %s not found in %s%n",module,path(dir)); } - + private void disable(final String module) { - final String mini=module+".ini"; - final String disable=module+".ini.disabled"; - final AtomicBoolean found=new AtomicBoolean(false); - FileFilter filter =new FileFilter() + final String mini = module + ".ini"; + final String disable = module + ".ini.disabled"; + final AtomicBoolean found = new AtomicBoolean(false); + FileFilter filter = new FileFilter() { public boolean accept(File path) { if (!path.isFile()) return false; - String n=path.getName(); - int i=n.indexOf(mini); - if (i<0) + String n = path.getName(); + int i = n.indexOf(mini); + if (i < 0) return false; - if (i>0 && i!=4 && n.charAt(i-1)!='-') + if (i > 0 && i != 4 && n.charAt(i - 1) != '-') return false; found.set(true); @@ -1387,20 +1253,20 @@ public class Main } else if (n.endsWith(mini)) { - String disabled=n+".disabled"; + String disabled = n + ".disabled"; System.err.printf("Disable %s in %s as %s%n",module,path(path.getParent()),disabled); path.renameTo(new File(path.getParentFile(),disabled)); } - else + else System.err.printf("Bad module %s in %s as %s%n",module,path(path.getParent()),n); - + return false; } }; - + for (File dir : _iniDirs) dir.listFiles(filter); - + if (!found.get()) for (File dir : _iniDirs) System.err.printf("Module %s not found in %s%n",module,path(dir)); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/NaturalSort.java b/jetty-start/src/main/java/org/eclipse/jetty/start/NaturalSort.java new file mode 100644 index 00000000000..dc72712af2a --- /dev/null +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/NaturalSort.java @@ -0,0 +1,56 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +import java.io.File; +import java.text.CollationKey; +import java.text.Collator; +import java.util.Comparator; + +/** + * Natural Language Sorting + */ +public class NaturalSort +{ + public static class Strings implements Comparator + { + private final Collator collator = Collator.getInstance(); + + @Override + public int compare(String o1, String o2) + { + CollationKey key1 = collator.getCollationKey(o1); + CollationKey key2 = collator.getCollationKey(o2); + return key1.compareTo(key2); + } + } + + public static class Files implements Comparator + { + private final Collator collator = Collator.getInstance(); + + @Override + public int compare(File o1, File o2) + { + CollationKey key1 = collator.getCollationKey(o1.getAbsolutePath()); + CollationKey key2 = collator.getCollationKey(o2.getAbsolutePath()); + return key1.compareTo(key2); + } + } +} diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java new file mode 100644 index 00000000000..ab4c477191c --- /dev/null +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java @@ -0,0 +1,149 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Simple Start .INI handler + */ +public class StartIni implements Iterable +{ + private final File file; + private final LinkedList lines; + + public StartIni(File file) throws FileNotFoundException, IOException + { + this.file = file; + this.lines = new LinkedList<>(); + try (FileReader reader = new FileReader(file)) + { + try (BufferedReader buf = new BufferedReader(reader)) + { + String line; + while ((line = buf.readLine()) != null) + { + line = line.trim(); + if (line.length() == 0) + { + // skip (empty line) + continue; + } + if (line.charAt(0) == '#') + { + // skip (comment) + continue; + } + + // Smart Handling, split into multiple OPTIONS lines + if (line.startsWith("OPTIONS=")) + { + for (String part : line.split(",")) + { + lines.add("OPTIONS=" + part); + } + } + else + { + // Add line as-is + lines.add(line); + } + } + } + } + } + + public File getFile() + { + return file; + } + + public int lineIndexOf(int offset, Pattern pattern) + { + int len = lines.size(); + for (int i = offset; i < len; i++) + { + if (pattern.matcher(lines.get(i)).matches()) + { + return i; + } + } + return -1; + } + + public List getLineMatches(Pattern pattern) + { + List ret = new ArrayList<>(); + for (String line : lines) + { + if (pattern.matcher(line).matches()) + { + ret.add(line); + } + } + return ret; + } + + public List getLines() + { + return lines; + } + + @Override + public Iterator iterator() + { + return lines.iterator(); + } + + public int overlayAt(int index, StartIni child) + { + int idx = index; + int count = 0; + for (String line : child) + { + if (this.hasLine(line)) + { + // skip + continue; + } + lines.add(idx++,line); + count++; + } + return count; + } + + private boolean hasLine(String line) + { + return lines.contains(line); + } + + public void removeLine(String line) + { + lines.remove(line); + } +} diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/HomeBaseTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/HomeBaseTest.java index 5df9f12ea5f..2785a83cce3 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/HomeBaseTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/HomeBaseTest.java @@ -77,6 +77,25 @@ public class HomeBaseTest assertFileList(hb,"Files found",expected,files); } + @Test + public void testListFiles_Filtered_OnlyHome() throws IOException + { + File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home"); + File baseDir = null; + + HomeBase hb = new HomeBase(homeDir,baseDir); + List files = hb.listFiles("/start.d", new FS.IniFilter()); + + List expected = new ArrayList<>(); + expected.add("${jetty.home}/start.d/jmx.ini"); + expected.add("${jetty.home}/start.d/jndi.ini"); + expected.add("${jetty.home}/start.d/jsp.ini"); + expected.add("${jetty.home}/start.d/logging.ini"); + expected.add("${jetty.home}/start.d/ssl.ini"); + + assertFileList(hb,"Files found",expected,files); + } + @Test public void testListFiles_Both() throws IOException { @@ -96,7 +115,7 @@ public class HomeBaseTest assertFileList(hb,"Files found",expected,files); } - + @Test public void testGetFile_Both() throws IOException { 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 c4243260afe..69a5c6c5552 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 @@ -18,12 +18,8 @@ package org.eclipse.jetty.start; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import java.io.File; import java.io.IOException; @@ -35,6 +31,7 @@ import java.util.Vector; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.hamcrest.Matchers; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -59,11 +56,17 @@ public class MainTest { Main main = new Main(); List xmls = main.processCommandLine(new String[] {}); - - assertEquals("etc/jetty.xml",xmls.get(0)); - assertEquals("etc/jetty-jmx.xml",xmls.get(1)); - assertEquals("start.d","etc/jetty-testrealm.xml",xmls.get(2)); - assertEquals("start.d","etc/jetty-contexts.xml",xmls.get(5)); + + List expectedXmls = new ArrayList(); + expectedXmls.add("etc/jetty.xml"); // from start.ini + expectedXmls.add("etc/jetty-jmx.xml"); // from start.d/10-jmx.ini + // nothing from start.d/20-websocket.xml + expectedXmls.add("etc/jetty-testrealm.xml"); // from start.d/90-testrealm.ini + expectedXmls.add("etc/jetty-deploy.xml"); // from start.ini + expectedXmls.add("etc/jetty-webapps.xml"); // from start.ini + expectedXmls.add("etc/jetty-contexts.xml"); // from start.ini + + Assert.assertThat("XML Resolution Order "+xmls, xmls, contains(expectedXmls.toArray())); Set options = main.getConfig().getOptions(); assertThat(options,Matchers.contains("Server","ext","jmx","jsp","newOption","resources","websocket")); 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 9275957109d..a5a1f9972cd 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 @@ -190,6 +190,8 @@ public class PropertyPassingTest System.out.println("Command line: " + cline); ProcessBuilder builder = new ProcessBuilder(commands); + // Set PWD + builder.directory(MavenTestingUtils.getTestResourceDir("empty.home")); Process pid = builder.start(); ConsoleCapture stdOutPump = new ConsoleCapture("STDOUT",pid.getInputStream()).start(); diff --git a/jetty-start/src/test/resources/empty.home/start.ini b/jetty-start/src/test/resources/empty.home/start.ini new file mode 100644 index 00000000000..e751e99807d --- /dev/null +++ b/jetty-start/src/test/resources/empty.home/start.ini @@ -0,0 +1,3 @@ +#=========================================================== +# Empty start.ini +#=========================================================== From 637be5259e974fbe61e26696bcc008cc6f766979 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sun, 18 Aug 2013 08:20:27 -0700 Subject: [PATCH 08/28] Fixing up confusion over OPTIONS vs OPTION --- .../java/org/eclipse/jetty/start/Main.java | 30 +++--- .../org/eclipse/jetty/start/StartIni.java | 91 ++++++++++--------- .../org/eclipse/jetty/start/MainTest.java | 35 +++++-- 3 files changed, 87 insertions(+), 69 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 292822d73eb..185eac9f048 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -52,6 +52,8 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Pattern; +import org.eclipse.jetty.start.StartIni.IncludeListener; + /*-------------------------------------------*/ /** *

@@ -63,7 +65,7 @@ import java.util.regex.Pattern; * The behaviour of Main is controlled by the parsing of the {@link Config} "org/eclipse/start/start.config" file obtained as a resource or file. *

*/ -public class Main +public class Main implements IncludeListener { private static final String START_LOG_FILENAME = "start.log"; private static final SimpleDateFormat START_LOG_ROLLOVER_DATEFORMAT = new SimpleDateFormat("yyyy_MM_dd-HHmmSSSSS.'" + START_LOG_FILENAME + "'"); @@ -212,20 +214,7 @@ public class Main { String name = arg.substring(6); File file = _config.getHomeBase().getFile(name); - StartIni startini = new StartIni(file); - int idx; - while ((idx = startini.lineIndexOf(0,Pattern.compile("^.*/$"))) >= 0) - { - String subPath = startini.getLines().get(idx); - startini.getLines().remove(idx); - // find the sub ini files (based on HomeBase) - List childInis = _config.getHomeBase().listFiles(subPath,new FS.IniFilter()); - for (File childIni : childInis) - { - StartIni cini = new StartIni(childIni); - idx += startini.overlayAt(idx,cini); - } - } + StartIni startini = new StartIni(file,this); arguments.addAll(i + 1,startini.getLines()); } @@ -380,6 +369,17 @@ public class Main return xmls; } + + @Override + public List onIniInclude(String path) throws IOException + { + List included = new ArrayList<>(); + for(File file: _config.getHomeBase().listFiles(path,new FS.IniFilter())) + { + included.add(new StartIni(file)); + } + return included; + } private void download(String arg) { diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java index ab4c477191c..59a574793cd 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java @@ -34,10 +34,20 @@ import java.util.regex.Pattern; */ public class StartIni implements Iterable { + public static interface IncludeListener + { + public List onIniInclude(String path) throws IOException; + } + private final File file; private final LinkedList lines; public StartIni(File file) throws FileNotFoundException, IOException + { + this(file,null); + } + + public StartIni(File file, IncludeListener listener) throws FileNotFoundException, IOException { this.file = file; this.lines = new LinkedList<>(); @@ -54,48 +64,68 @@ public class StartIni implements Iterable // skip (empty line) continue; } + if (line.charAt(0) == '#') { // skip (comment) continue; } - // Smart Handling, split into multiple OPTIONS lines + // Smart Handling, split into multiple OPTIONS lines (for dup check reasons) if (line.startsWith("OPTIONS=")) { - for (String part : line.split(",")) + int idx = line.indexOf('='); + String value = line.substring(idx + 1); + for (String part : value.split(",")) { - lines.add("OPTIONS=" + part); + addUniqueLine("OPTION=" + part); + } + } + // Smart Handling, includes + else if (line.endsWith("/")) + { + if (listener == null) + { + System.err.printf("Nested includes not supported: %s (found in %s)%n",line,file.getAbsolutePath()); + } + else + { + // Collect HomeBase resolved included StartIni's + for (StartIni included : listener.onIniInclude(line)) + { + // Merge each line with prior lines to prevent duplicates + for (String includedLine : included) + { + addUniqueLine(includedLine); + } + } } } else { // Add line as-is - lines.add(line); + addUniqueLine(line); } } } } } + private void addUniqueLine(String line) + { + if (lines.contains(line)) + { + // skip + return; + } + lines.add(line); + } + public File getFile() { return file; } - public int lineIndexOf(int offset, Pattern pattern) - { - int len = lines.size(); - for (int i = offset; i < len; i++) - { - if (pattern.matcher(lines.get(i)).matches()) - { - return i; - } - } - return -1; - } - public List getLineMatches(Pattern pattern) { List ret = new ArrayList<>(); @@ -119,31 +149,4 @@ public class StartIni implements Iterable { return lines.iterator(); } - - public int overlayAt(int index, StartIni child) - { - int idx = index; - int count = 0; - for (String line : child) - { - if (this.hasLine(line)) - { - // skip - continue; - } - lines.add(idx++,line); - count++; - } - return count; - } - - private boolean hasLine(String line) - { - return lines.contains(line); - } - - public void removeLine(String line) - { - lines.remove(line); - } } 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 69a5c6c5552..6d643258d34 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,13 +25,12 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.Vector; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.hamcrest.Matchers; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -56,7 +55,8 @@ public class MainTest { Main main = new Main(); List xmls = main.processCommandLine(new String[] {}); - + + // Order is important here List expectedXmls = new ArrayList(); expectedXmls.add("etc/jetty.xml"); // from start.ini expectedXmls.add("etc/jetty-jmx.xml"); // from start.d/10-jmx.ini @@ -65,11 +65,26 @@ public class MainTest expectedXmls.add("etc/jetty-deploy.xml"); // from start.ini expectedXmls.add("etc/jetty-webapps.xml"); // from start.ini expectedXmls.add("etc/jetty-contexts.xml"); // from start.ini - - Assert.assertThat("XML Resolution Order "+xmls, xmls, contains(expectedXmls.toArray())); + assertThat("XML Resolution Order " + xmls,xmls,contains(expectedXmls.toArray())); + + // Order is irrelevant here Set options = main.getConfig().getOptions(); - assertThat(options,Matchers.contains("Server","ext","jmx","jsp","newOption","resources","websocket")); + Set expectedOptions = new HashSet<>(); + // from start.ini + expectedOptions.add("Server"); + expectedOptions.add("jsp"); + expectedOptions.add("resources"); + expectedOptions.add("websocket"); + expectedOptions.add("ext"); + expectedOptions.add("newOption"); + // from start.d/10-jmx.ini + expectedOptions.add("jmx"); + // from start.d/20-websocket.ini + expectedOptions.add("websocket"); + // no options from start.d/90-testrealm.ini + + assertThat("Options " + options,options,containsInAnyOrder(expectedOptions.toArray())); } @Test @@ -99,14 +114,14 @@ public class MainTest hasItems("/jetty/home with spaces/somejar.jar:/jetty/home with spaces/someotherjar.jar")); assertThat("args does not contain --exec",commandArgs,hasItems("--exec")); assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xms1024m")); - assertThat("CommandLine should contain jvmArgs", commandArgs, hasItems("-Xmx1024m")); + assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xmx1024m")); assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty.xml")); assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-jmx.xml")); - assertThat("CommandLine should contain xmls", commandArgs, hasItems("jetty-logging.xml")); + assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-logging.xml")); String commandLine = cmd.toString(); - assertThat("cmd.toString() should be properly escaped",commandLine,containsString("-cp /jetty/home\\ with\\ " + - "spaces/somejar.jar:/jetty/home\\ with\\ spaces/someotherjar.jar")); + assertThat("cmd.toString() should be properly escaped",commandLine,containsString("-cp /jetty/home\\ with\\ " + + "spaces/somejar.jar:/jetty/home\\ with\\ spaces/someotherjar.jar")); assertThat("cmd.toString() doesn't contain xml config files",commandLine,containsString(" jetty.xml jetty-jmx.xml jetty-logging.xml")); } From bb3d8e3a5255261ae96e0413ecfe0353a15dac90 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sun, 18 Aug 2013 08:27:45 -0700 Subject: [PATCH 09/28] Using try-with-resources more consistently --- .../java/org/eclipse/jetty/start/Config.java | 39 ++++--------------- .../org/eclipse/jetty/start/JarVersion.java | 2 +- .../java/org/eclipse/jetty/start/Main.java | 13 ++----- 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java index a44220ad008..64c829f6ce2 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java @@ -27,8 +27,6 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import java.net.URL; -import java.text.CollationKey; -import java.text.Collator; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -289,16 +287,6 @@ public class Config } } - private void close(InputStream stream) - { - FS.close(stream); - } - - private void close(Reader reader) - { - FS.close(reader); - } - public static boolean isDebug() { return DEBUG; @@ -544,7 +532,10 @@ public class Config */ public void parse(CharSequence buf) throws IOException { - parse(new StringReader(buf.toString())); + try (StringReader reader = new StringReader(buf.toString())) + { + parse(reader); + } } /** @@ -555,28 +546,18 @@ public class Config */ public void parse(InputStream stream) throws IOException { - InputStreamReader reader = null; - try + try (InputStreamReader reader = new InputStreamReader(stream)) { - reader = new InputStreamReader(stream); parse(reader); } - finally - { - close(reader); - } } /** */ public void parse(Reader reader) throws IOException { - BufferedReader buf = null; - - try + try(BufferedReader buf = new BufferedReader(reader)) { - buf = new BufferedReader(reader); - List options = new ArrayList(); options.add(DEFAULT_SECTION); _classpaths.put(DEFAULT_SECTION,new Classpath()); @@ -849,10 +830,6 @@ public class Config } } } - finally - { - close(buf); - } } private List processDynamicSectionIdentifier(String dynamicPathId,List sections) throws IOException @@ -929,8 +906,8 @@ public class Config } finally { - close(reader); - close(stream); + FS.close(reader); + FS.close(stream); } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java b/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java index efd11ea7d2d..029f7654522 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java @@ -102,7 +102,7 @@ public class JarVersion } finally { - Main.close(stream); + FS.close(stream); } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 185eac9f048..fcff1e9218e 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.start; import java.io.BufferedReader; -import java.io.Closeable; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; @@ -50,7 +49,6 @@ import java.util.Locale; import java.util.Properties; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.regex.Pattern; import org.eclipse.jetty.start.StartIni.IncludeListener; @@ -525,7 +523,7 @@ public class Main implements IncludeListener } finally { - close(buf); + FS.close(buf); } System.exit(EXIT_USAGE); } @@ -583,11 +581,6 @@ public class Main implements IncludeListener main.invoke(null,method_params); } - public static void close(Closeable c) - { - FS.close(c); - } - public void start(List xmls) throws IOException, InterruptedException { // Load potential Config (start.config) @@ -1020,7 +1013,7 @@ public class Main implements IncludeListener } finally { - close(cfgstream); + FS.close(cfgstream); } } @@ -1068,7 +1061,7 @@ public class Main implements IncludeListener } finally { - close(cfgstream); + FS.close(cfgstream); } } From 22c65c8f10c21ce0200976fe1e21b28752c4c3b6 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sun, 18 Aug 2013 10:22:25 -0700 Subject: [PATCH 10/28] Fixing enable/disable --- .../main/java/org/eclipse/jetty/start/FS.java | 85 ++++++++-- .../org/eclipse/jetty/start/HomeBase.java | 51 +++--- .../java/org/eclipse/jetty/start/Main.java | 151 +++++++++--------- .../org/eclipse/jetty/start/StartIni.java | 2 +- 4 files changed, 177 insertions(+), 112 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java index 9476f8425ed..abcaad75a32 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java @@ -26,6 +26,44 @@ import java.util.regex.Pattern; public class FS { + public static class AllFilter implements FileFilter + { + public static final AllFilter INSTANCE = new AllFilter(); + + @Override + public boolean accept(File pathname) + { + return true; + } + } + + public static class FileNamesFilter implements FileFilter + { + private final String filenames[]; + + public FileNamesFilter(String... names) + { + this.filenames = names; + } + + @Override + public boolean accept(File path) + { + if (!path.isFile()) + { + return false; + } + for (String name : filenames) + { + if (name.equalsIgnoreCase(path.getName())) + { + return true; + } + } + return false; + } + } + public static class FilenameRegexFilter implements FileFilter { private final Pattern pattern; @@ -38,7 +76,7 @@ public class FS @Override public boolean accept(File path) { - return pattern.matcher(path.getName()).matches(); + return path.isFile() && pattern.matcher(path.getName()).matches(); } } @@ -58,20 +96,6 @@ public class FS } } - public static boolean isXml(String filename) - { - return Pattern.compile(".xml$",Pattern.CASE_INSENSITIVE).matcher(filename).matches(); - } - - public static boolean isFile(File file) - { - if (file == null) - { - return false; - } - return file.exists() && file.isFile(); - } - public static void close(Closeable c) { if (c == null) @@ -86,4 +110,35 @@ public class FS /* ignore */ } } + + public static boolean isFile(File file) + { + if (file == null) + { + return false; + } + return file.exists() && file.isFile(); + } + + public static boolean isXml(String filename) + { + return Pattern.compile(".xml$",Pattern.CASE_INSENSITIVE).matcher(filename).matches(); + } + + public static String separators(String path) + { + StringBuilder ret = new StringBuilder(); + for (char c : path.toCharArray()) + { + if ((c == '/') || (c == '\\')) + { + ret.append(File.separatorChar); + } + else + { + ret.append(c); + } + } + return ret.toString(); + } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java index a7097c612ad..9e5096c72b3 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java @@ -43,23 +43,6 @@ public class HomeBase } } - public static String separators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == '/') || (c == '\\')) - { - ret.append(File.separatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } - private File homeDir; private File baseDir; @@ -120,7 +103,7 @@ public class HomeBase */ public File getFile(String path) { - String rpath = separators(path); + String rpath = FS.separators(path); // Relative to Base Directory First if (baseDir != null) @@ -189,21 +172,21 @@ public class HomeBase { Objects.requireNonNull(filter,"FileFilter cannot be null"); - File homePath = new File(homeDir,separators(relPathToDirectory)); + File homePath = new File(homeDir,FS.separators(relPathToDirectory)); List homeFiles = new ArrayList<>(); homeFiles.addAll(Arrays.asList(homePath.listFiles(filter))); if (baseDir != null) { // merge - File basePath = new File(baseDir,separators(relPathToDirectory)); + File basePath = new File(baseDir,FS.separators(relPathToDirectory)); File baseFiles[] = basePath.listFiles(filter); List ret = new ArrayList<>(); for (File base : baseFiles) { String relpath = toRelativePath(baseDir,base); - File home = new File(homeDir,separators(relpath)); + File home = new File(homeDir,FS.separators(relpath)); if (home.exists()) { homeFiles.remove(home); @@ -224,6 +207,32 @@ public class HomeBase return homeFiles; } } + + /** + * Collect the list of files in both ${jetty.base} and ${jetty.home}, with + * , even if the same file shows up in both places. + */ + public List rawListFiles(String relPathToDirectory, FileFilter filter) + { + Objects.requireNonNull(filter,"FileFilter cannot be null"); + + List ret = new ArrayList<>(); + + // Home Dir + File homePath = new File(homeDir,FS.separators(relPathToDirectory)); + ret.addAll(Arrays.asList(homePath.listFiles(filter))); + + if (baseDir != null) + { + // Base Dir + File basePath = new File(baseDir,FS.separators(relPathToDirectory)); + ret.addAll(Arrays.asList(basePath.listFiles(filter))); + } + + // Sort + Collections.sort(ret, new NaturalSort.Files()); + return ret; + } private String toRelativePath(File dir, File path) { diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index fcff1e9218e..42b3328250b 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -24,7 +24,6 @@ import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -48,7 +47,6 @@ import java.util.List; import java.util.Locale; import java.util.Properties; import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.jetty.start.StartIni.IncludeListener; @@ -85,8 +83,10 @@ public class Main implements IncludeListener private final List _jvmArgs = new ArrayList<>(); private final List _enable = new ArrayList<>(); private final List _disable = new ArrayList<>(); + // Actively being used ini files private final List _iniFiles = new ArrayList<>(); - private final List _iniDirs = new ArrayList<>(); + // Actively being referenced ini include paths + private final List _iniIncludePaths = new ArrayList<>(); private String _startConfig = null; public static void main(String[] args) @@ -122,10 +122,16 @@ public class Main implements IncludeListener ArrayList arguments = new ArrayList<>(Arrays.asList(args)); boolean ini = false; for (String arg : arguments) + { if (arg.startsWith("--ini=") || arg.equals("--ini")) + { ini = true; + } + } if (!ini) + { arguments.add("--ini=start.ini"); + } // The XML Configuration Files to initialize with List xmls = new ArrayList(); @@ -213,6 +219,7 @@ public class Main implements IncludeListener String name = arg.substring(6); File file = _config.getHomeBase().getFile(name); StartIni startini = new StartIni(file,this); + _iniFiles.add(file); arguments.addAll(i + 1,startini.getLines()); } @@ -367,13 +374,21 @@ public class Main implements IncludeListener return xmls; } - + @Override public List onIniInclude(String path) throws IOException { List included = new ArrayList<>(); - for(File file: _config.getHomeBase().listFiles(path,new FS.IniFilter())) + + HomeBase hb = _config.getHomeBase(); + + // Allow --enable and --disable to work + _iniIncludePaths.add(path); + + // Scan for ini files + for (File file : hb.listFiles(path,new FS.IniFilter())) { + _iniFiles.add(file); included.add(new StartIni(file)); } return included; @@ -491,21 +506,15 @@ public class Main implements IncludeListener { for (File file : _iniFiles) { - String path = path(file); + String path = _config.getHomeBase().toShortForm(file); System.out.printf("%s%s%n",indent,path); if (Config.isDebug()) { - try (FileReader reader = new FileReader(file); BufferedReader in = new BufferedReader(reader);) + StartIni ini = new StartIni(file); + for (String arg : ini) { - String arg; - while ((arg = in.readLine()) != null) - { - arg = arg.trim(); - if (arg.length() == 0 || arg.startsWith("#")) - continue; - System.out.printf("%s +-- %s%n",indent,arg); - } + System.out.printf("%s +-- %s%n",indent,arg); } } } @@ -1181,87 +1190,79 @@ public class Main implements IncludeListener { final String mini = module + ".ini"; final String disable = module + ".ini.disabled"; - final AtomicBoolean found = new AtomicBoolean(false); - FileFilter filter = new FileFilter() + + FileFilter disabledModuleFilter = new FS.FileNamesFilter(mini, disable); + + HomeBase hb = _config.getHomeBase(); + + // walk all ini include paths that were used + boolean found = false; + for (String includedPath : _iniIncludePaths) { - public boolean accept(File path) + Config.debug("Searching ${jetty.home}/%s and ${jetty.base}/% for %s",includedPath,includedPath,mini); + for (File file : hb.rawListFiles(includedPath,disabledModuleFilter)) { - if (!path.isFile()) - return false; - String n = path.getName(); - int i = n.indexOf(mini); - if (i < 0) - return false; - if (i > 0 && i != 4 && n.charAt(i - 1) != '-') - return false; - - found.set(true); - if (n.endsWith(mini)) + String n = file.getName(); + if (n.equalsIgnoreCase(mini)) { - System.err.printf("Module %s already enabled in %s as %s%n",module,path(path.getParent()),n); + System.err.printf("Module %s already enabled in %s%n",module,hb.toShortForm(file.getParent())); + found = true; } - else if (n.endsWith(disable)) + else if (n.equals(disable)) { - String enabled = n.substring(0,n.length() - 9); - System.err.printf("Enable %s in %s as %s%n",module,path(path.getParent()),enabled); - path.renameTo(new File(path.getParentFile(),enabled)); + System.err.printf("Enabling Module %s in %s%n",module,hb.toShortForm(file.getParent())); + file.renameTo(new File(file.getParentFile(),mini)); + found = true; } - else - System.err.printf("Bad module %s in %s as %s%n",module,path(path.getParent()),n); - - return false; } - }; + } - for (File dir : _iniDirs) - dir.listFiles(filter); - - if (!found.get()) - for (File dir : _iniDirs) - System.err.printf("Module %s not found in %s%n",module,path(dir)); + if (!found) + { + for (String includedPath : _iniIncludePaths) + { + System.err.printf("Module %s not found in %s%n",module,includedPath); + } + } } private void disable(final String module) { final String mini = module + ".ini"; final String disable = module + ".ini.disabled"; - final AtomicBoolean found = new AtomicBoolean(false); - FileFilter filter = new FileFilter() + + FileFilter disabledModuleFilter = new FS.FileNamesFilter(mini, disable); + + HomeBase hb = _config.getHomeBase(); + + // walk all ini include paths that were used + boolean found = false; + for (String includedPath : _iniIncludePaths) { - public boolean accept(File path) + Config.debug("Searching ${jetty.home}/%s and ${jetty.base}/% for %s",includedPath,includedPath,mini); + for (File file : hb.rawListFiles(includedPath,disabledModuleFilter)) { - if (!path.isFile()) - return false; - String n = path.getName(); - int i = n.indexOf(mini); - if (i < 0) - return false; - if (i > 0 && i != 4 && n.charAt(i - 1) != '-') - return false; - - found.set(true); - if (n.endsWith(disable)) + String n = file.getName(); + if (n.equalsIgnoreCase(disable)) { - System.err.printf("Module %s already disabled in %s as %s%n",module,path(path.getParent()),n); + System.err.printf("Module %s already disabled in %s%n",module,hb.toShortForm(file.getParent())); + found = true; } - else if (n.endsWith(mini)) + else if (n.equals(mini)) { - String disabled = n + ".disabled"; - System.err.printf("Disable %s in %s as %s%n",module,path(path.getParent()),disabled); - path.renameTo(new File(path.getParentFile(),disabled)); + System.err.printf("Disabling Module %s in %s%n",module,hb.toShortForm(file.getParent())); + file.renameTo(new File(file.getParentFile(),disable)); + found = true; } - else - System.err.printf("Bad module %s in %s as %s%n",module,path(path.getParent()),n); - - return false; } - }; + } - for (File dir : _iniDirs) - dir.listFiles(filter); - - if (!found.get()) - for (File dir : _iniDirs) - System.err.printf("Module %s not found in %s%n",module,path(dir)); + if (!found) + { + for (String includedPath : _iniIncludePaths) + { + System.err.printf("Module %s not found in %s%n",module,includedPath); + } + } } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java index 59a574793cd..2772bec5f42 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java @@ -86,7 +86,7 @@ public class StartIni implements Iterable { if (listener == null) { - System.err.printf("Nested includes not supported: %s (found in %s)%n",line,file.getAbsolutePath()); + Config.debug("Nested include ignored: %s (found in %s)",line,file.getAbsolutePath()); } else { From b2e194a890b5b352b685345a412796acbf48fde2 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sun, 18 Aug 2013 10:29:57 -0700 Subject: [PATCH 11/28] Consolidating filters --- .../java/org/eclipse/jetty/start/HomeBase.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java index 9e5096c72b3..8b4153515da 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java @@ -28,21 +28,10 @@ import java.util.List; import java.util.Objects; /** - * File access for ${jetty.home}, and optional ${jetty.base}, directories + * File access for ${jetty.home}, and optional ${jetty.base}, directories. */ public class HomeBase { - private static class AllFilter implements FileFilter - { - public static final AllFilter INSTANCE = new AllFilter(); - - @Override - public boolean accept(File pathname) - { - return true; - } - } - private File homeDir; private File baseDir; @@ -153,7 +142,7 @@ public class HomeBase */ public List listFiles(String relPathToDirectory) { - return listFiles(relPathToDirectory,AllFilter.INSTANCE); + return listFiles(relPathToDirectory,FS.AllFilter.INSTANCE); } /** From d92ee024d2b8d3b50b63211fce9ce3d8a89a3cb7 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Sun, 18 Aug 2013 10:40:15 -0700 Subject: [PATCH 12/28] jetty.base is always defined. --- .../java/org/eclipse/jetty/start/Config.java | 4 +- .../main/java/org/eclipse/jetty/start/FS.java | 3 +- .../org/eclipse/jetty/start/HomeBase.java | 43 ++++++++++--------- .../java/org/eclipse/jetty/start/Main.java | 12 +----- 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java index 64c829f6ce2..e7ecc9497a0 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java @@ -201,9 +201,7 @@ public class Config { _homebase = new HomeBase(); setProperty("jetty.home",_homebase.getHome()); - if(_homebase.hasBase()) { - setProperty("jetty.base",_homebase.getBase()); - } + setProperty("jetty.base",_homebase.getBase()); } public HomeBase getHomeBase() diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java index abcaad75a32..1a5999103d6 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java @@ -22,6 +22,7 @@ import java.io.Closeable; import java.io.File; import java.io.FileFilter; import java.io.IOException; +import java.util.Locale; import java.util.regex.Pattern; public class FS @@ -122,7 +123,7 @@ public class FS public static boolean isXml(String filename) { - return Pattern.compile(".xml$",Pattern.CASE_INSENSITIVE).matcher(filename).matches(); + return filename.toLowerCase(Locale.ENGLISH).endsWith(".xml"); } public static String separators(String path) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java index 8b4153515da..b225f2832b4 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/HomeBase.java @@ -28,7 +28,13 @@ import java.util.List; import java.util.Objects; /** - * File access for ${jetty.home}, and optional ${jetty.base}, directories. + * File access for ${jetty.home}, ${jetty.base}, directories. + *

+ * By default, both ${jetty.home} and ${jetty.base} are the same directory, but they can point at different directories. + *

+ * The ${jetty.home} directory is where the main Jetty binaries and default configuration is housed. + *

+ * The ${jetty.base} directory is where the execution specific configuration and webapps are obtained from. */ public class HomeBase { @@ -39,11 +45,7 @@ public class HomeBase { String userDir = System.getProperty("user.dir"); this.homeDir = new File(System.getProperty("jetty.home",userDir)); - String base = System.getProperty("jetty.base"); - if (base != null) - { - this.baseDir = new File(base); - } + this.baseDir = new File(System.getProperty("jetty.base",homeDir.getAbsolutePath())); } public HomeBase(File homeDir, File baseDir) @@ -51,12 +53,12 @@ public class HomeBase this.homeDir = homeDir; this.baseDir = baseDir; } - - public boolean hasBase() + + public boolean isBaseDifferent() { - return this.baseDir != null; + return homeDir.compareTo(baseDir) != 0; } - + public void setBaseDir(File dir) { this.baseDir = dir; @@ -95,7 +97,7 @@ public class HomeBase String rpath = FS.separators(path); // Relative to Base Directory First - if (baseDir != null) + if (isBaseDifferent()) { File file = new File(baseDir,rpath); if (file.exists()) @@ -114,7 +116,7 @@ public class HomeBase // Finally, as an absolute path return new File(rpath); } - + public void setHomeDir(File dir) { this.homeDir = dir; @@ -165,7 +167,7 @@ public class HomeBase List homeFiles = new ArrayList<>(); homeFiles.addAll(Arrays.asList(homePath.listFiles(filter))); - if (baseDir != null) + if (isBaseDifferent()) { // merge File basePath = new File(baseDir,FS.separators(relPathToDirectory)); @@ -186,20 +188,19 @@ public class HomeBase // add any remaining home files. ret.addAll(homeFiles); - Collections.sort(ret, new NaturalSort.Files()); + Collections.sort(ret,new NaturalSort.Files()); return ret; } else { // simple return - Collections.sort(homeFiles, new NaturalSort.Files()); + Collections.sort(homeFiles,new NaturalSort.Files()); return homeFiles; } } - + /** - * Collect the list of files in both ${jetty.base} and ${jetty.home}, with - * , even if the same file shows up in both places. + * Collect the list of files in both ${jetty.base} and ${jetty.home}, with , even if the same file shows up in both places. */ public List rawListFiles(String relPathToDirectory, FileFilter filter) { @@ -211,7 +212,7 @@ public class HomeBase File homePath = new File(homeDir,FS.separators(relPathToDirectory)); ret.addAll(Arrays.asList(homePath.listFiles(filter))); - if (baseDir != null) + if (isBaseDifferent()) { // Base Dir File basePath = new File(baseDir,FS.separators(relPathToDirectory)); @@ -219,7 +220,7 @@ public class HomeBase } // Sort - Collections.sort(ret, new NaturalSort.Files()); + Collections.sort(ret,new NaturalSort.Files()); return ret; } @@ -265,7 +266,7 @@ public class HomeBase return "${jetty.home}" + path.substring(value.length()); } - if (baseDir != null) + if (isBaseDifferent()) { value = baseDir.getAbsolutePath(); if (path.startsWith(value)) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 42b3328250b..beefe4ae4c5 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -775,10 +775,7 @@ public class Main implements IncludeListener cmd.addArg(x); } cmd.addRawArg("-Djetty.home=" + _config.getHomeBase().getHome()); - if (_config.getHomeBase().hasBase()) - { - cmd.addRawArg("-Djetty.base=" + _config.getHomeBase().getBase()); - } + cmd.addRawArg("-Djetty.base=" + _config.getHomeBase().getBase()); // Special Stop/Shutdown properties ensureSystemPropertySet("STOP.PORT"); @@ -901,12 +898,7 @@ public class Main implements IncludeListener + "then overlapping entries will not be repeated in the eventual classpath."); System.out.println(); System.out.printf("${jetty.home} = %s%n",_config.getHomeBase().getHome()); - String base = ""; - if (_config.getHomeBase().hasBase()) - { - base = _config.getHomeBase().getBase(); - } - System.out.printf("${jetty.base} = %s%n",base); + System.out.printf("${jetty.base} = %s%n",_config.getHomeBase().getBase()); System.out.println(); for (String sectionId : sectionIds) From 5600d411ed56717b16376ab86f2923ea62503852 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Aug 2013 08:50:38 -0700 Subject: [PATCH 13/28] Start.d in-progress, coordinating with Jesse --- .../org/eclipse/jetty/start/BaseHome.java | 125 +++++----- .../main/java/org/eclipse/jetty/start/FS.java | 44 ++-- .../java/org/eclipse/jetty/start/Main.java | 213 ++++++++++++------ .../org/eclipse/jetty/start/StartArgs.java | 213 ++++++++++++++++++ .../org/eclipse/jetty/start/StartIni.java | 89 +------- .../org/eclipse/jetty/start/StartLog.java | 125 ++++++++++ .../org/eclipse/jetty/start/TextFile.java | 110 +++++++++ .../eclipse/jetty/start/UsageException.java | 50 ++++ .../org/eclipse/jetty/start/MainTest.java | 2 + .../jetty/start/PropertyPassingTest.java | 1 + 10 files changed, 751 insertions(+), 221 deletions(-) create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/UsageException.java 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 204e02534f8..92dcda2e550 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 @@ -53,47 +53,7 @@ public class BaseHome public BaseHome(File homeDir, File baseDir) { this.homeDir = homeDir; - this.baseDir = baseDir==null?homeDir:baseDir; - } - - - public void initialize(ArrayList arguments) - { - Pattern jetty_home=Pattern.compile("(-D)?jetty.home=(.*)"); - Pattern jetty_base=Pattern.compile("(-D)?jetty.base=(.*)"); - for (String arg : arguments) - { - Matcher home_match=jetty_home.matcher(arg); - if (home_match.matches()) - setHomeDir(new File(home_match.group(2))); - Matcher base_match=jetty_base.matcher(arg); - if (base_match.matches()) - setBaseDir(new File(base_match.group(2))); - } - } - - - public boolean isBaseDifferent() - { - return homeDir.compareTo(baseDir) != 0; - } - - public void setBaseDir(File dir) - { - this.baseDir = dir; - try - { - System.setProperty("jetty.base",dir.getCanonicalPath()); - } - catch(IOException e) - { - e.printStackTrace(); - } - } - - public File getBaseDir() - { - return baseDir; + this.baseDir = baseDir == null?homeDir:baseDir; } public String getBase() @@ -105,6 +65,23 @@ public class BaseHome return baseDir.getAbsolutePath(); } + public File getBaseDir() + { + return baseDir; + } + + /** + * Create a file reference to some content in "${jetty.base}" + * + * @param path + * the path to reference + * @return the file reference + */ + public File getBaseFile(String path) + { + return new File(baseDir,FS.separators(path)); + } + /** * Get a specific file reference. *

@@ -144,17 +121,9 @@ public class BaseHome return new File(rpath); } - public void setHomeDir(File dir) + public String getHome() { - this.homeDir = dir; - try - { - System.setProperty("jetty.home",dir.getCanonicalPath()); - } - catch(IOException e) - { - e.printStackTrace(); - } + return homeDir.getAbsolutePath(); } public File getHomeDir() @@ -162,9 +131,29 @@ public class BaseHome return homeDir; } - public String getHome() + public void initialize(StartArgs args) { - return homeDir.getAbsolutePath(); + Pattern jetty_home = Pattern.compile("(-D)?jetty.home=(.*)"); + Pattern jetty_base = Pattern.compile("(-D)?jetty.base=(.*)"); + + for (String arg : args.getCommandLine()) + { + Matcher home_match = jetty_home.matcher(arg); + if (home_match.matches()) + { + setHomeDir(new File(home_match.group(2))); + } + Matcher base_match = jetty_base.matcher(arg); + if (base_match.matches()) + { + setBaseDir(new File(base_match.group(2))); + } + } + } + + public boolean isBaseDifferent() + { + return homeDir.compareTo(baseDir) != 0; } /** @@ -209,7 +198,7 @@ public class BaseHome File baseFiles[] = basePath.listFiles(filter); List ret = new ArrayList<>(); - if (baseFiles!=null) + if (baseFiles != null) { for (File base : baseFiles) { @@ -262,6 +251,32 @@ public class BaseHome return ret; } + public void setBaseDir(File dir) + { + this.baseDir = dir; + try + { + System.setProperty("jetty.base",dir.getCanonicalPath()); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void setHomeDir(File dir) + { + this.homeDir = dir; + try + { + System.setProperty("jetty.home",dir.getCanonicalPath()); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + private String toRelativePath(File dir, File path) { return dir.toURI().relativize(path.toURI()).toASCIIString(); @@ -296,7 +311,7 @@ public class BaseHome { return path; } - + String value; if (isBaseDifferent()) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java index 1a5999103d6..d12d9d7cb1b 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java @@ -38,6 +38,22 @@ public class FS } } + public static class FilenameRegexFilter implements FileFilter + { + private final Pattern pattern; + + public FilenameRegexFilter(String regex) + { + pattern = Pattern.compile(regex,Pattern.CASE_INSENSITIVE); + } + + @Override + public boolean accept(File path) + { + return path.isFile() && pattern.matcher(path.getName()).matches(); + } + } + public static class FileNamesFilter implements FileFilter { private final String filenames[]; @@ -65,22 +81,6 @@ public class FS } } - public static class FilenameRegexFilter implements FileFilter - { - private final Pattern pattern; - - public FilenameRegexFilter(String regex) - { - pattern = Pattern.compile(regex,Pattern.CASE_INSENSITIVE); - } - - @Override - public boolean accept(File path) - { - return path.isFile() && pattern.matcher(path.getName()).matches(); - } - } - public static class IniFilter extends FilenameRegexFilter { public IniFilter() @@ -96,11 +96,23 @@ public class FS super("^.*\\.xml$"); } } + + public static boolean canReadDirectory(File path) + { + return (path.exists() && path.isDirectory() && path.canRead()); + } + + public static boolean canReadFile(File path) + { + return (path.exists() && path.isFile() && path.canRead()); + } public static void close(Closeable c) { if (c == null) + { return; + } try { diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 983c9dff9ca..9811be59043 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.start; +import static org.eclipse.jetty.start.UsageException.*; import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; @@ -52,14 +53,41 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** + * Main start class. *

- * Main start class. This class is intended to be the main class listed in the MANIFEST.MF of the start.jar archive. It allows an application to be started with - * the command "java -jar start.jar". - *

- * + * This class is intended to be the main class listed in the MANIFEST.MF of the start.jar archive. It allows the Jetty Application server to be started with the + * command "java -jar start.jar". *

- * The behaviour of Main is controlled by the parsing of the {@link Config} "org/eclipse/start/start.config" file obtained as a resource or file. - *

+ * Argument processing steps: + *
    + *
  1. Directory Locations: + *
      + *
    • jetty.home=[directory] (the jetty.home location)
    • + *
    • jetty.base=[directory] (the jetty.base location)
    • + *
    + *
  2. + *
  3. Start Logging behavior: + *
      + *
    • --debug (debugging enabled)
    • + *
    • --start-log-file=logs/start.log (output start logs to logs/start.log location)
    • + *
    + *
  4. + *
  5. Module Resolution
  6. + *
  7. Properties Resolution
  8. + *
  9. Execution + *
      + *
    • --list-modules
    • + *
    • --list-classpath
    • + *
    • --list-config
    • + *
    • --version
    • + *
    • --help
    • + *
    • --dry-run
    • + *
    • --exec
    • + *
    • --stop
    • + *
    • (or normal startup)
    • + *
    + *
  10. + *
*/ public class Main { @@ -68,10 +96,6 @@ public class Main private static final Pattern NNN_MODULE_INI = Pattern.compile("^(\\d\\d\\d-)(.*?\\.ini)(\\.disabled)?$",Pattern.CASE_INSENSITIVE); private static final int EXIT_USAGE = 1; - private static final int ERR_LOGGING = -1; - private static final int ERR_INVOKE_MAIN = -2; - private static final int ERR_NOT_STOPPED = -4; - private static final int ERR_UNKNOWN = -5; private boolean _showUsage = false; private boolean _dumpVersions = false; private boolean _listConfig = false; @@ -95,9 +119,13 @@ public class Main if (xmls != null) main.start(xmls); } + catch (UsageException e) + { + usageExit(e.getCause(),e.getExitCode()); + } catch (Throwable e) { - usageExit(e,ERR_UNKNOWN); + usageExit(e,UsageException.ERR_UNKNOWN); } } @@ -111,28 +139,80 @@ public class Main return _config; } - public List processCommandLine(String[] args) throws Exception + public List processCommandLine(String[] cmdLine) throws Exception { + StartArgs args = new StartArgs(cmdLine); + BaseHome baseHome = _config.getBaseHome(); - ArrayList cmd_line = new ArrayList<>(Arrays.asList(args)); + // Processing Order is important! + // ------------------------------------------------------------ + // 1) Directory Locations // Set Home and Base at the start, as all other paths encountered // will be based off of them. - _config.getBaseHome().initialize(cmd_line); - - List inis = new ArrayList<>(); - - - // Do we have a start.ini? - File start_ini=_config.getBaseHome().getFile("start.ini"); - if (start_ini.exists()&& start_ini.canRead() && !start_ini.isDirectory()) - inis.add(new StartIni(start_ini)); - - // Do we have a start.d? - File start_d=_config.getBaseHome().getFile("start.d"); - if (start_d.exists()&& start_d.canRead() && start_d.isDirectory()) + _config.getBaseHome().initialize(args); + + // ------------------------------------------------------------ + // 2) Start Logging + StartLog.getInstance().initialize(baseHome,args); + + // ------------------------------------------------------------ + // 3) Load Inis + File start_ini = baseHome.getBaseFile("start.ini"); + if (FS.canReadFile(start_ini)) { - List files=new ArrayList<>(); + args.parse(new StartIni(start_ini)); + } + + File start_d = _config.getBaseHome().getBaseFile("start.d"); + if (FS.canReadDirectory(start_d)) + { + List files = new ArrayList<>(); + for (File file : start_d.listFiles(new FS.IniFilter())) + { + files.add(file); + } + + Collections.sort(files,new NaturalSort.Files()); + for (File file : files) + { + args.parse(new StartIni(file)); + } + } + + // 4) Parse everything provided. + // This would be the directory information + + // the various start inis + // and then the raw command line arguments + args.parseCommandLine(); + + // 5) Module Registration + Modules modules = new Modules(); + modules.registerAll(baseHome); + + // 6) Active Module Resolution + for (String enabledModule : args.getEnabledModules()) + { + modules.enable(enabledModule); + } + modules.buildGraph(); + + List activeModules = modules.resolveEnabled(); + + // 7) Lib & XML Expansion / Resolution + args.expandModules(baseHome, activeModules); + + /* + // Do we have a start.ini? + File start_ini = _config.getBaseHome().getFile("start.ini"); + if (start_ini.exists() && start_ini.canRead() && !start_ini.isDirectory()) + inis.add(new StartIni(start_ini)); + + // Do we have a start.d? + File start_d = _config.getBaseHome().getFile("start.d"); + if (start_d.exists() && start_d.canRead() && start_d.isDirectory()) + { + List files = new ArrayList<>(); for (File file : start_d.listFiles(new FS.IniFilter())) files.add(file); @@ -145,18 +225,17 @@ public class Main inis.add(new StartIni(cmd_line)); // TODO - we could sort the StartIni files by dependency here - // The XML Configuration Files to initialize with List xmls = new ArrayList(); - + // Expand arguments - for (StartIni ini:inis) + for (StartIni ini : inis) { String source = ""; - if (ini.getFile()!=null) - source=ini.getFile().getAbsolutePath(); - + if (ini.getFile() != null) + source = ini.getFile().getAbsolutePath(); + for (String arg : ini.getLines()) { @@ -372,10 +451,10 @@ public class Main xmls.add(arg); } } - - return xmls; - } + */ + return null; + } private void download(String arg) { @@ -487,13 +566,13 @@ public class Main } else if (info.equals("@STARTINI")) { - BaseHome hb=_config.getBaseHome(); + BaseHome hb = _config.getBaseHome(); File start_d = hb.getFile("start.d"); if (start_d.exists() && start_d.isDirectory()) { - File[] files=start_d.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?.*\\.ini(\\.disabled)?")); + File[] files = start_d.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?.*\\.ini(\\.disabled)?")); Arrays.sort(files,new NaturalSort.Files()); - for (File file: files) + for (File file : files) { String path = _config.getBaseHome().toShortForm(file); System.out.printf("%s%s%n",indent,path); @@ -1168,18 +1247,18 @@ public class Main _jvmArgs.addAll(jvmArgs); } - private void enable(final String module,boolean verbose) throws IOException + private void enable(final String module, boolean verbose) throws IOException { final String mini = module + ".ini"; final String disable = module + ".ini.disabled"; - BaseHome hb=_config.getBaseHome(); + BaseHome hb = _config.getBaseHome(); File start_d = hb.getFile("start.d"); - boolean found=false; - File enabled=null; + boolean found = false; + File enabled = null; if (start_d.exists() && start_d.isDirectory()) { - for (File file: start_d.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?"+Pattern.quote(module)+"\\.ini(\\.disabled)?"))) + for (File file : start_d.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?" + Pattern.quote(module) + "\\.ini(\\.disabled)?"))) { String n = file.getName(); if (n.equalsIgnoreCase(mini)) @@ -1189,20 +1268,20 @@ public class Main found = true; break; } - + if (n.equalsIgnoreCase(disable)) { - enabled=new File(file.getParentFile(),mini); + enabled = new File(file.getParentFile(),mini); System.err.printf("Enabling Module %s as %s%n",module,hb.toShortForm(enabled)); file.renameTo(enabled); found = true; break; } - + Matcher matcher = NNN_MODULE_INI.matcher(n); if (matcher.matches()) { - if (matcher.group(3)==null) + if (matcher.group(3) == null) { if (verbose) System.err.printf("Module %s already enabled in %s as %s%n",module,hb.toShortForm(file.getParent()),n); @@ -1210,12 +1289,12 @@ public class Main } else { - enabled=new File(file.getParentFile(),matcher.group(1)+mini); + enabled = new File(file.getParentFile(),matcher.group(1) + mini); System.err.printf("Enabling Module %s as %s%n",module,hb.toShortForm(enabled)); file.renameTo(enabled); found = true; } - } + } } } @@ -1226,14 +1305,14 @@ public class Main if (start_home.exists() && start_home.isDirectory()) { - for (File file: start_home.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?"+Pattern.quote(module)+"\\.ini(\\.disabled)?"))) + for (File file : start_home.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?" + Pattern.quote(module) + "\\.ini(\\.disabled)?"))) { try { String n = file.getName(); if (n.equalsIgnoreCase(mini) || n.equalsIgnoreCase(disable)) { - enabled=new File(start_d,mini); + enabled = new File(start_d,mini); Files.copy(file.toPath(),enabled.toPath()); System.err.printf("Enabling Module %s as %s%n",module,hb.toShortForm(enabled)); found = true; @@ -1243,14 +1322,14 @@ public class Main Matcher matcher = NNN_MODULE_INI.matcher(n); if (matcher.matches()) { - enabled=new File(start_d,matcher.group(1)+mini); + enabled = new File(start_d,matcher.group(1) + mini); Files.copy(file.toPath(),enabled.toPath()); System.err.printf("Enabling Module %s as %s%n",module,hb.toShortForm(enabled)); found = true; break; } } - catch(IOException e) + catch (IOException e) { e.printStackTrace(); } @@ -1262,20 +1341,20 @@ public class Main { System.err.printf("Module %s not found!%n",module); } - else if (enabled!=null) + else if (enabled != null) { // handle dependencies - StartIni ini=new StartIni(enabled); - for (String line:ini.getLineMatches(Pattern.compile("^DEPEND=.*$"))) + StartIni ini = new StartIni(enabled); + for (String line : ini.getLineMatches(Pattern.compile("^DEPEND=.*$"))) { - String depend=line.trim().split("=")[1]; - for (String m:depend.split(",")) + String depend = line.trim().split("=")[1]; + for (String m : depend.split(",")) enable(m,false); } - for (String line:ini.getLineMatches(Pattern.compile("^EXCLUDE=.*$"))) + for (String line : ini.getLineMatches(Pattern.compile("^EXCLUDE=.*$"))) { - String depend=line.trim().split("=")[1]; - for (String m:depend.split(",")) + String depend = line.trim().split("=")[1]; + for (String m : depend.split(",")) disable(m,false); } } @@ -1286,12 +1365,12 @@ public class Main final String mini = module + ".ini"; final String disable = module + ".ini.disabled"; - BaseHome hb=_config.getBaseHome(); + BaseHome hb = _config.getBaseHome(); File start_d = hb.getFile("start.d"); - boolean found=false; + boolean found = false; if (start_d.exists() && start_d.isDirectory()) { - for (File file: start_d.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?"+Pattern.quote(module)+"\\.ini(\\.disabled)?"))) + for (File file : start_d.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?" + Pattern.quote(module) + "\\.ini(\\.disabled)?"))) { String n = file.getName(); if (n.equalsIgnoreCase(disable)) @@ -1311,7 +1390,7 @@ public class Main Matcher matcher = NNN_MODULE_INI.matcher(n); if (matcher.matches()) { - if (matcher.group(3)!=null) + if (matcher.group(3) != null) { if (verbose) System.err.printf("Module %s already disabled in %s as %s%n",module,hb.toShortForm(file.getParent()),n); @@ -1319,7 +1398,7 @@ public class Main } else { - String disabled=matcher.group(1)+disable; + String disabled = matcher.group(1) + disable; System.err.printf("Disabling Module %s in %s as %s%n",module,hb.toShortForm(file.getParent()),disabled); file.renameTo(new File(file.getParentFile(),disabled)); found = true; 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 new file mode 100644 index 00000000000..73d88f5191b --- /dev/null +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -0,0 +1,213 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +import static org.eclipse.jetty.start.UsageException.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * The Arguments required to start Jetty. + */ +public class StartArgs +{ + // TODO: might make sense to declare this in modules/base.mod + private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration.class"; + + private List commandLine = new ArrayList<>(); + private List enabledModules = new ArrayList<>(); + private List downloads = new ArrayList<>(); + private List classpath = new ArrayList<>(); + private List xmls = new ArrayList<>(); + private Map properties = new HashMap<>(); + private Map systemProperties = new HashMap<>(); + private Map jvmArgs = new HashMap<>(); + + // Should the server be run? + private boolean run = true; + private boolean help = false; + private boolean stopCommand = false; + private boolean listModules = false; + private boolean listClasspath = false; + private boolean listConfig = false; + private boolean version = false; + private boolean dryRun = false; + private boolean exec = false; + + public StartArgs(String[] commandLineArgs) + { + commandLine.addAll(Arrays.asList(commandLineArgs)); + } + + public List getStartCommands() + { + return null; + } + + public List getCommandLine() + { + return this.commandLine; + } + + public void parse(TextFile file) + { + for (String line : file) + { + parse(line); + } + } + + public void parse(String arg) + { + if ("--help".equals(arg) || "-?".equals(arg)) + { + help = true; + run = false; + return; + } + + if ("--stop".equals(arg)) + { + stopCommand = true; + run = false; + /* + * int port = Integer.parseInt(_config.getProperty("STOP.PORT","-1")); String key = _config.getProperty("STOP.KEY",null); int timeout = + * Integer.parseInt(_config.getProperty("STOP.WAIT","0")); stop(port,key,timeout); + */ + return; + } + + if (arg.startsWith("--download=")) + { + downloads.add(getValue(arg)); + return; + } + + if ("--list-classpath".equals(arg) || "--version".equals(arg) || "-v".equals(arg) || "--info".equals(arg)) + { + listClasspath = true; + run = false; + return; + } + + if ("--list-config".equals(arg)) + { + listConfig = true; + run = false; + return; + } + + if ("--dry-run".equals(arg) || "--exec-print".equals(arg)) + { + dryRun = true; + run = false; + return; + } + + if (arg.startsWith("--enable=")) + { + String moduleName = getValue(arg); + // TODO: + run = false; + return; + } + + if (arg.startsWith("--disable=")) + { + String moduleName = getValue(arg); + // TODO: + run = false; + return; + } + + if (arg.startsWith("MODULE=")) + { + enabledModules.add(getValue(arg)); + return; + } + + if (arg.startsWith("MODULES=")) + { + for (String moduleName : getValue(arg).split(",")) + { + if (moduleName == null) + { + continue; // skip + } + enabledModules.add(moduleName.trim()); + } + return; + } + + // Start property (syntax similar to System property) + if(arg.startsWith("-D")) + { + String[] assign = arg.substring(2).split("=",2); +// TODO systemProperties.add(assign[0]); + switch (assign.length) + { + case 2: + System.setProperty(assign[0],assign[1]); + break; + case 1: + System.setProperty(assign[0],""); + break; + default: + break; + } + return; + } + } + + private String getValue(String arg) + { + int idx = arg.indexOf('='); + if (idx == (-1)) + { + throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg); + } + String value = arg.substring(idx + 1).trim(); + if (value.length() <= 0) + { + throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg); + } + return value; + } + + public void parseCommandLine() + { + for (String line : commandLine) + { + parse(line); + } + } + + public List getEnabledModules() + { + return this.enabledModules; + } + + public void expandModules(BaseHome baseHome, List activeModules) + { + // TODO Auto-generated method stub + } +} diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java index 7fcc9743815..1bd3f207192 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java @@ -18,111 +18,34 @@ package org.eclipse.jetty.start; -import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Pattern; /** * Simple Start .INI handler */ -public class StartIni implements Iterable +public class StartIni extends TextFile { - public static interface IncludeListener - { - public List onIniInclude(String path) throws IOException; - } - - private final File file; - private final List lines= new ArrayList<>(); - public StartIni(File file) throws FileNotFoundException, IOException { - this.file = file; - try (FileReader reader = new FileReader(file)) - { - try (BufferedReader buf = new BufferedReader(reader)) - { - String line; - while ((line = buf.readLine()) != null) - process(line.trim()); - } - } + super(file); } - public StartIni(ArrayList arguments) + public void addUniqueLine(String line) { - file=null; - for (String line: arguments) - process(line); - } - - private void process(String line) - { - if (line.length() == 0) - return; - - if (line.charAt(0) == '#') - return; - - // Smart Handling, split into multiple OPTIONS lines (for dup check reasons) - if (line.startsWith("OPTIONS=")) + if (line.startsWith("MODULES=")) { int idx = line.indexOf('='); String value = line.substring(idx + 1); for (String part : value.split(",")) { - addUniqueLine("OPTION=" + part); + super.addUniqueLine("MODULE=" + part); } } else { - // Add line as-is - addUniqueLine(line); + super.addUniqueLine(line); } } - - private void addUniqueLine(String line) - { - if (lines.contains(line)) - { - // skip - return; - } - lines.add(line); - } - - public File getFile() - { - return file; - } - - public List getLineMatches(Pattern pattern) - { - List ret = new ArrayList<>(); - for (String line : lines) - { - if (pattern.matcher(line).matches()) - { - ret.add(line); - } - } - return ret; - } - - public List getLines() - { - return lines; - } - - @Override - public Iterator iterator() - { - return lines.iterator(); - } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java new file mode 100644 index 00000000000..62696232aba --- /dev/null +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java @@ -0,0 +1,125 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Centralized Place for logging. + *

+ * Because startup cannot rely on Jetty's Logging, an alternative logging is established. + *

+ * Optional behavior is to create a ${jetty.base}/logs/start.log with whatever output the startup process produces. + */ +public class StartLog +{ + private final static StartLog INSTANCE = new StartLog(); + + public static StartLog getInstance() + { + return INSTANCE; + } + + private boolean debug = false; + + public void initLogFile(File logfile) throws IOException + { + if (logfile != null) + { + File logDir = logfile.getParentFile(); + if (!logDir.exists() || !logDir.canWrite()) + { + String err = String.format("Cannot write %s to directory %s [directory doesn't exist or is read-only]",logfile.getName(), + logDir.getAbsolutePath()); + throw new UsageException(UsageException.ERR_LOGGING,new IOException(err)); + } + + File startLog = logfile; + + if (!startLog.exists() && !startLog.createNewFile()) + { + // Output about error is lost in majority of cases. + throw new UsageException(UsageException.ERR_LOGGING,new IOException("Unable to create: " + startLog.getAbsolutePath())); + } + + if (!startLog.canWrite()) + { + // Output about error is lost in majority of cases. + throw new UsageException(UsageException.ERR_LOGGING,new IOException("Unable to write to: " + startLog.getAbsolutePath())); + } + PrintStream logger = new PrintStream(new FileOutputStream(startLog,false)); + System.setOut(logger); + System.setErr(logger); + System.out.println("Establishing " + logfile + " on " + new Date()); + } + } + + public static void debug(String format, Object... args) + { + if (INSTANCE.debug) + { + System.out.printf(format + "%n",args); + } + } + + public static void warn(String format, Object... args) + { + System.err.printf(format + "%n",args); + } + + public void initialize(BaseHome baseHome, StartArgs args) throws IOException + { + Pattern debugBoolPat = Pattern.compile("(-D)?debug=(.*)"); + Pattern debugPat = Pattern.compile("(-D)?debug"); + Pattern logFilePat = Pattern.compile("(-D)?start-log-file=(.*)"); + + Matcher matcher; + for (String arg : args.getCommandLine()) + { + matcher = debugBoolPat.matcher(arg); + if (matcher.matches()) + { + debug = Boolean.parseBoolean(matcher.group(2)); + continue; + } + + matcher = debugPat.matcher(arg); + if (matcher.matches()) + { + debug = true; + continue; + } + + matcher = logFilePat.matcher(arg); + if (matcher.matches()) + { + String filename = matcher.group(2); + File logfile = baseHome.getBaseFile(filename); + initLogFile(logfile); + } + } + } +} diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java new file mode 100644 index 00000000000..45ae50bbec5 --- /dev/null +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java @@ -0,0 +1,110 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Simple common abstraction for Text files, that consist of a series of lines. + *

+ * Ignoring lines that are empty, deemed to be comments, or are duplicates of prior lines. + */ +public class TextFile implements Iterable +{ + private final File file; + private final List lines = new ArrayList<>(); + + public TextFile(File file) throws FileNotFoundException, IOException + { + this.file = file; + try (FileReader reader = new FileReader(file)) + { + try (BufferedReader buf = new BufferedReader(reader)) + { + String line; + while ((line = buf.readLine()) != null) + { + process(line.trim()); + } + } + } + } + + public void addUniqueLine(String line) + { + if (lines.contains(line)) + { + // skip + return; + } + lines.add(line); + } + + public File getFile() + { + return file; + } + + public List getLineMatches(Pattern pattern) + { + List ret = new ArrayList<>(); + for (String line : lines) + { + if (pattern.matcher(line).matches()) + { + ret.add(line); + } + } + return ret; + } + + public List getLines() + { + return lines; + } + + @Override + public Iterator iterator() + { + return lines.iterator(); + } + + private void process(String line) + { + if (line.length() == 0) + { + return; + } + + if (line.charAt(0) == '#') + { + return; + } + + addUniqueLine(line); + } +} diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/UsageException.java b/jetty-start/src/main/java/org/eclipse/jetty/start/UsageException.java new file mode 100644 index 00000000000..2590a81fce5 --- /dev/null +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/UsageException.java @@ -0,0 +1,50 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +/** + * A Usage Error has occured. Print the usage and exit with the appropriate exit code. + */ +@SuppressWarnings("serial") +public class UsageException extends RuntimeException +{ + public static final int ERR_LOGGING = -1; + public static final int ERR_INVOKE_MAIN = -2; + public static final int ERR_NOT_STOPPED = -4; + public static final int ERR_UNKNOWN = -5; + public static final int ERR_BAD_ARG = -6; + private int exitCode; + + public UsageException(int exitCode, Throwable cause) + { + super(cause); + this.exitCode = exitCode; + } + + public UsageException(int exitCode, String format, Object... objs) + { + super(String.format(format,objs)); + this.exitCode = exitCode; + } + + public int getExitCode() + { + return exitCode; + } +} 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 aea359b4768..bc37277d768 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 @@ -32,11 +32,13 @@ import java.util.Vector; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; /* ------------------------------------------------------------ */ /** */ +@Ignore public class MainTest { /* ------------------------------------------------------------ */ 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 a5a1f9972cd..15b4a5e197b 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 @@ -39,6 +39,7 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; +@Ignore public class PropertyPassingTest { private static class ConsoleCapture implements Runnable From 725e405dace78d62a895141aa35f0c6aef34a5ae Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 22 Aug 2013 11:53:58 -0500 Subject: [PATCH 14/28] first pass for mod files for distribution --- .../src/main/config/modules/annotations.mod | 14 + jetty-client/pom.xml | 288 +++++++++--------- .../src/main/config/modules/client.mod | 6 + .../src/main/config/modules/deploy.mod | 9 + jetty-distribution/pom.xml | 5 + jetty-jaas/src/main/config/modules/jaas.mod | 9 + jetty-jmx/src/main/config/modules/jmx.mod | 9 + jetty-jndi/pom.xml | 17 ++ jetty-jndi/src/main/config/modules/jndi.mod | 12 + .../src/main/config/modules/monitor.mod | 10 + jetty-nosql/pom.xml | 17 ++ jetty-nosql/src/main/config/modules/nosql.mod | 7 + .../src/main/config/modules/overlay.mod | 10 + jetty-plus/src/main/config/modules/plus.mod | 10 + jetty-proxy/src/main/config/modules/proxy.mod | 10 + .../src/main/config/modules/rewrite.mod | 10 + jetty-server/src/main/config/modules/base.mod | 6 + .../src/main/config/modules/debug.mod | 7 + jetty-server/src/main/config/modules/http.mod | 7 + .../src/main/config/modules/https.mod | 8 + .../src/main/config/modules/ipaccess.mod | 7 + .../src/main/config/modules/lowresources.mod | 7 + .../src/main/config/modules/requestlog.mod | 7 + .../src/main/config/modules/server.mod | 14 + .../src/main/config/modules/stats.mod | 7 + .../src/main/config/modules/xinetd.mod | 7 + jetty-server/src/main/config/modules/xml.mod | 8 + jetty-webapp/pom.xml | 17 ++ .../src/main/config/modules/webapp.mod | 7 + 29 files changed, 413 insertions(+), 139 deletions(-) create mode 100644 jetty-annotations/src/main/config/modules/annotations.mod create mode 100644 jetty-client/src/main/config/modules/client.mod create mode 100644 jetty-deploy/src/main/config/modules/deploy.mod create mode 100644 jetty-jaas/src/main/config/modules/jaas.mod create mode 100644 jetty-jmx/src/main/config/modules/jmx.mod create mode 100644 jetty-jndi/src/main/config/modules/jndi.mod create mode 100644 jetty-monitor/src/main/config/modules/monitor.mod create mode 100644 jetty-nosql/src/main/config/modules/nosql.mod create mode 100644 jetty-overlay-deployer/src/main/config/modules/overlay.mod create mode 100644 jetty-plus/src/main/config/modules/plus.mod create mode 100644 jetty-proxy/src/main/config/modules/proxy.mod create mode 100644 jetty-rewrite/src/main/config/modules/rewrite.mod create mode 100644 jetty-server/src/main/config/modules/base.mod create mode 100644 jetty-server/src/main/config/modules/debug.mod create mode 100644 jetty-server/src/main/config/modules/http.mod create mode 100644 jetty-server/src/main/config/modules/https.mod create mode 100644 jetty-server/src/main/config/modules/ipaccess.mod create mode 100644 jetty-server/src/main/config/modules/lowresources.mod create mode 100644 jetty-server/src/main/config/modules/requestlog.mod create mode 100644 jetty-server/src/main/config/modules/server.mod create mode 100644 jetty-server/src/main/config/modules/stats.mod create mode 100644 jetty-server/src/main/config/modules/xinetd.mod create mode 100644 jetty-server/src/main/config/modules/xml.mod create mode 100644 jetty-webapp/src/main/config/modules/webapp.mod diff --git a/jetty-annotations/src/main/config/modules/annotations.mod b/jetty-annotations/src/main/config/modules/annotations.mod new file mode 100644 index 00000000000..3470bf75c79 --- /dev/null +++ b/jetty-annotations/src/main/config/modules/annotations.mod @@ -0,0 +1,14 @@ +# +# Jetty Annotation Scanning Module +# + +# Annotations needs plus, and jndi features +DEPEND=plus + +# Annotations needs jetty annotation jars +LIB=lib/jetty-annotations-${jetty.version}.jar +# Need annotation processing jars too +LIB=lib/annotations/*.jar + +# Enable annotation scanning webapp configurations +etc/jetty-annotations.xml diff --git a/jetty-client/pom.xml b/jetty-client/pom.xml index a7cd736f1ed..b2ccc2cf64a 100644 --- a/jetty-client/pom.xml +++ b/jetty-client/pom.xml @@ -1,144 +1,154 @@ - - - org.eclipse.jetty - jetty-project - 9.1.0-SNAPSHOT - + + + org.eclipse.jetty + jetty-project + 9.1.0-SNAPSHOT + - 4.0.0 - jetty-client - Jetty :: Asynchronous HTTP Client - http://www.eclipse.org/jetty - - ${project.groupId}.client - target/test-policy - - - - - org.apache.felix - maven-bundle-plugin - true - - - - manifest - - - - javax.net.*,* - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - org.codehaus.mojo - findbugs-maven-plugin - - org.eclipse.jetty.client.* - - - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-test-resources - - unpack - - - - - org.eclipse.jetty.toolchain - jetty-test-policy - ${jetty-test-policy-version} - jar - true - **/*.keystore,**/*.pem - ${jetty.test.policy.loc} - - - - - - - - + 4.0.0 + jetty-client + Jetty :: Asynchronous HTTP Client + http://www.eclipse.org/jetty + + ${project.groupId}.client + target/test-policy + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + config + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + + manifest + + + + javax.net.*,* + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.codehaus.mojo + findbugs-maven-plugin + + org.eclipse.jetty.client.* + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + generate-test-resources + + unpack + + + + + org.eclipse.jetty.toolchain + jetty-test-policy + ${jetty-test-policy-version} + jar + true + **/*.keystore,**/*.pem + ${jetty.test.policy.loc} + + + + + + + + - - - org.eclipse.jetty - jetty-http - ${project.version} - - - org.eclipse.jetty - jetty-io - ${project.version} - - - org.eclipse.jetty.spdy - spdy-client - ${project.version} - + + + org.eclipse.jetty + jetty-http + ${project.version} + + + org.eclipse.jetty + jetty-io + ${project.version} + + + org.eclipse.jetty.spdy + spdy-client + ${project.version} + - - org.eclipse.jetty - jetty-server - ${project.version} - test - - - org.eclipse.jetty - jetty-security - ${project.version} - test - - - org.eclipse.jetty - jetty-servlet - ${project.version} - test - - - - org.eclipse.jetty.toolchain - jetty-test-helper - test - + + org.eclipse.jetty + jetty-server + ${project.version} + test + + + org.eclipse.jetty + jetty-security + ${project.version} + test + + + org.eclipse.jetty + jetty-servlet + ${project.version} + test + + + + org.eclipse.jetty.toolchain + jetty-test-helper + test + - - com.ning - async-http-client - 1.7.5 - test - - - org.apache.httpcomponents - httpclient - 4.2.1 - test - - + + com.ning + async-http-client + 1.7.5 + test + + + org.apache.httpcomponents + httpclient + 4.2.1 + test + + diff --git a/jetty-client/src/main/config/modules/client.mod b/jetty-client/src/main/config/modules/client.mod new file mode 100644 index 00000000000..f434cdc0870 --- /dev/null +++ b/jetty-client/src/main/config/modules/client.mod @@ -0,0 +1,6 @@ +# +# Client Feature +# + +# Client jars +LIB=lib/jetty-client-${jetty.version}.jar diff --git a/jetty-deploy/src/main/config/modules/deploy.mod b/jetty-deploy/src/main/config/modules/deploy.mod new file mode 100644 index 00000000000..5705ac61d91 --- /dev/null +++ b/jetty-deploy/src/main/config/modules/deploy.mod @@ -0,0 +1,9 @@ +# +# Deploy Feature +# + +# Deploy jars +LIB=lib/jetty-deploy-${jetty.version}.jar + +# Deploy configuration +etc/jetty-deploy.xml diff --git a/jetty-distribution/pom.xml b/jetty-distribution/pom.xml index e55ebe97928..bf9aac223e6 100644 --- a/jetty-distribution/pom.xml +++ b/jetty-distribution/pom.xml @@ -612,6 +612,11 @@ jetty-proxy ${project.version} + + org.eclipse.jetty + jetty-overlay-deployer + ${project.version} + org.eclipse.jetty jetty-jaas diff --git a/jetty-jaas/src/main/config/modules/jaas.mod b/jetty-jaas/src/main/config/modules/jaas.mod new file mode 100644 index 00000000000..d0d6f0fa463 --- /dev/null +++ b/jetty-jaas/src/main/config/modules/jaas.mod @@ -0,0 +1,9 @@ +# +# JAAS Feature +# + +# JAAS jars +LIB=lib/jetty-jaas-${jetty.version}.jar + +# JAAS configuration +etc/jetty-jaas.xml diff --git a/jetty-jmx/src/main/config/modules/jmx.mod b/jetty-jmx/src/main/config/modules/jmx.mod new file mode 100644 index 00000000000..2a7922690e9 --- /dev/null +++ b/jetty-jmx/src/main/config/modules/jmx.mod @@ -0,0 +1,9 @@ +# +# JMX Feature +# + +# JMX jars (as defined in start.config) +LIB=lib/jetty-jmx-${jetty.version}.jar + +# JMX configuration +etc/jetty-jmx.xml diff --git a/jetty-jndi/pom.xml b/jetty-jndi/pom.xml index dbd3fbcbdd4..0f088b669e3 100644 --- a/jetty-jndi/pom.xml +++ b/jetty-jndi/pom.xml @@ -14,6 +14,23 @@ + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + config + + + + + org.apache.felix maven-bundle-plugin diff --git a/jetty-jndi/src/main/config/modules/jndi.mod b/jetty-jndi/src/main/config/modules/jndi.mod new file mode 100644 index 00000000000..de3087bd26f --- /dev/null +++ b/jetty-jndi/src/main/config/modules/jndi.mod @@ -0,0 +1,12 @@ +# +# JNDI Support +# + +DEPEND=server +DEPEND=plus + +LIB=lib/jetty-jndi-${jetty.version}.jar +LIB=lib/jndi/*.jar + +# Annotations needs annotations configuration +etc/jetty-server.xml diff --git a/jetty-monitor/src/main/config/modules/monitor.mod b/jetty-monitor/src/main/config/modules/monitor.mod new file mode 100644 index 00000000000..249ccef15d1 --- /dev/null +++ b/jetty-monitor/src/main/config/modules/monitor.mod @@ -0,0 +1,10 @@ +# +# Jetty Monitor module +# + +DEPEND=server +DEPEND=client + +LIB=lib/jetty-monitor-${jetty.version}.jar + +etc/jetty-monitor.xml \ No newline at end of file diff --git a/jetty-nosql/pom.xml b/jetty-nosql/pom.xml index e06a15b9cbb..ebfa3c9d392 100644 --- a/jetty-nosql/pom.xml +++ b/jetty-nosql/pom.xml @@ -14,6 +14,23 @@ install + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + config + + + + + org.apache.felix maven-bundle-plugin diff --git a/jetty-nosql/src/main/config/modules/nosql.mod b/jetty-nosql/src/main/config/modules/nosql.mod new file mode 100644 index 00000000000..3d8b099ed0e --- /dev/null +++ b/jetty-nosql/src/main/config/modules/nosql.mod @@ -0,0 +1,7 @@ +# +# Jetty Nosql module +# + +DEPEND=webapp + +LIB=lib/jetty-nosql-${jetty.version}.jar \ No newline at end of file diff --git a/jetty-overlay-deployer/src/main/config/modules/overlay.mod b/jetty-overlay-deployer/src/main/config/modules/overlay.mod new file mode 100644 index 00000000000..a006476a60d --- /dev/null +++ b/jetty-overlay-deployer/src/main/config/modules/overlay.mod @@ -0,0 +1,10 @@ +# +# Jetty Overlay module +# + +DEPEND=deploy + +LIB=lib/jetty-overlay-deployer-${jetty.version}.jar + +# Plus requires configuration +etc/jetty-overlay.xml diff --git a/jetty-plus/src/main/config/modules/plus.mod b/jetty-plus/src/main/config/modules/plus.mod new file mode 100644 index 00000000000..31d8e76b95c --- /dev/null +++ b/jetty-plus/src/main/config/modules/plus.mod @@ -0,0 +1,10 @@ +# +# Jetty Proxy module +# + +DEPEND=server + +LIB=lib/jetty-plus-${jetty.version}.jar + +# Plus requires configuration +etc/jetty-plus.xml diff --git a/jetty-proxy/src/main/config/modules/proxy.mod b/jetty-proxy/src/main/config/modules/proxy.mod new file mode 100644 index 00000000000..9e2bc46db8c --- /dev/null +++ b/jetty-proxy/src/main/config/modules/proxy.mod @@ -0,0 +1,10 @@ +# +# Jetty Proxy module +# + +DEPEND=server + +LIB=lib/jetty-proxy-${jetty.version}.jar + +# Proxy requires configuration +etc/jetty-proxy.xml diff --git a/jetty-rewrite/src/main/config/modules/rewrite.mod b/jetty-rewrite/src/main/config/modules/rewrite.mod new file mode 100644 index 00000000000..d5ccf960410 --- /dev/null +++ b/jetty-rewrite/src/main/config/modules/rewrite.mod @@ -0,0 +1,10 @@ +# +# Jetty Rewrite module +# + +DEPEND=server + +LIB=lib/jetty-rewrite-${jetty.version}.jar + +# Annotations needs annotations configuration +etc/jetty-rewrite.xml diff --git a/jetty-server/src/main/config/modules/base.mod b/jetty-server/src/main/config/modules/base.mod new file mode 100644 index 00000000000..f85269aa64c --- /dev/null +++ b/jetty-server/src/main/config/modules/base.mod @@ -0,0 +1,6 @@ +# +# Base Module +# + +LIB=lib/jetty-util-${jetty.version}.jar +LIB=lib/jetty-io-${jetty.version}.jar diff --git a/jetty-server/src/main/config/modules/debug.mod b/jetty-server/src/main/config/modules/debug.mod new file mode 100644 index 00000000000..8cdf5b94ab6 --- /dev/null +++ b/jetty-server/src/main/config/modules/debug.mod @@ -0,0 +1,7 @@ +# +# Debug module +# + +DEPEND=server + +etc/jetty-debug.xml diff --git a/jetty-server/src/main/config/modules/http.mod b/jetty-server/src/main/config/modules/http.mod new file mode 100644 index 00000000000..94eed962e9b --- /dev/null +++ b/jetty-server/src/main/config/modules/http.mod @@ -0,0 +1,7 @@ +# +# Jetty HTTP Server +# + +DEPEND=server + +etc/jetty-http.xml diff --git a/jetty-server/src/main/config/modules/https.mod b/jetty-server/src/main/config/modules/https.mod new file mode 100644 index 00000000000..5e930e934f7 --- /dev/null +++ b/jetty-server/src/main/config/modules/https.mod @@ -0,0 +1,8 @@ +# +# Jetty HTTP Server +# + +DEPEND=server + +etc/jetty-ssl.xml +etc/jetty-https.xml diff --git a/jetty-server/src/main/config/modules/ipaccess.mod b/jetty-server/src/main/config/modules/ipaccess.mod new file mode 100644 index 00000000000..f99f26ec3e3 --- /dev/null +++ b/jetty-server/src/main/config/modules/ipaccess.mod @@ -0,0 +1,7 @@ +# +# IPAccess module +# + +DEPEND=server + +etc/jetty-ipaccess.xml diff --git a/jetty-server/src/main/config/modules/lowresources.mod b/jetty-server/src/main/config/modules/lowresources.mod new file mode 100644 index 00000000000..578d8165edd --- /dev/null +++ b/jetty-server/src/main/config/modules/lowresources.mod @@ -0,0 +1,7 @@ +# +# Low Resources module +# + +DEPEND=server + +etc/jetty-lowresources.xml diff --git a/jetty-server/src/main/config/modules/requestlog.mod b/jetty-server/src/main/config/modules/requestlog.mod new file mode 100644 index 00000000000..060ca9f0a22 --- /dev/null +++ b/jetty-server/src/main/config/modules/requestlog.mod @@ -0,0 +1,7 @@ +# +# Request Log module +# + +DEPEND=server + +etc/jetty-requestlog.xml diff --git a/jetty-server/src/main/config/modules/server.mod b/jetty-server/src/main/config/modules/server.mod new file mode 100644 index 00000000000..06bf6772f5b --- /dev/null +++ b/jetty-server/src/main/config/modules/server.mod @@ -0,0 +1,14 @@ +# +# Base server +# + +DEPEND=base + +LIB=lib/servlet-api-3.1.jar +LIB=lib/jetty-schemas-3.1.jar +LIB=lib/jetty-http-${jetty.version}.jar +LIB=lib/jetty-continuation-${jetty.version}.jar +LIB=lib/jetty-server-${jetty.version}.jar + +# Annotations needs annotations configuration +etc/jetty.xml diff --git a/jetty-server/src/main/config/modules/stats.mod b/jetty-server/src/main/config/modules/stats.mod new file mode 100644 index 00000000000..cd56d5b4d7b --- /dev/null +++ b/jetty-server/src/main/config/modules/stats.mod @@ -0,0 +1,7 @@ +# +# Stats module +# + +DEPEND=server + +etc/jetty-stats.xml diff --git a/jetty-server/src/main/config/modules/xinetd.mod b/jetty-server/src/main/config/modules/xinetd.mod new file mode 100644 index 00000000000..c93064ad767 --- /dev/null +++ b/jetty-server/src/main/config/modules/xinetd.mod @@ -0,0 +1,7 @@ +# +# Stats module +# + +DEPEND=server + +etc/jetty-xinetd.xml diff --git a/jetty-server/src/main/config/modules/xml.mod b/jetty-server/src/main/config/modules/xml.mod new file mode 100644 index 00000000000..949e2057117 --- /dev/null +++ b/jetty-server/src/main/config/modules/xml.mod @@ -0,0 +1,8 @@ +# +# Jetty XML Configuration +# + +DEPEND=base + +LIB=lib/jetty-xml-${jetty.version}.jar + diff --git a/jetty-webapp/pom.xml b/jetty-webapp/pom.xml index b5d5aeffa77..167f1392840 100644 --- a/jetty-webapp/pom.xml +++ b/jetty-webapp/pom.xml @@ -27,6 +27,23 @@ + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + config + + + + + org.apache.maven.plugins maven-assembly-plugin diff --git a/jetty-webapp/src/main/config/modules/webapp.mod b/jetty-webapp/src/main/config/modules/webapp.mod new file mode 100644 index 00000000000..187db774b69 --- /dev/null +++ b/jetty-webapp/src/main/config/modules/webapp.mod @@ -0,0 +1,7 @@ +# +# Base server +# + +DEPEND=deploy + +LIB=lib/jetty-webapp-${jetty.version}.jar From 8efba9fb401b519d951ebf9d134cd199dbfb5dca Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 22 Aug 2013 11:59:07 -0500 Subject: [PATCH 15/28] bring back start.ini --- .../src/main/resources/start.ini | 237 ++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 jetty-distribution/src/main/resources/start.ini diff --git a/jetty-distribution/src/main/resources/start.ini b/jetty-distribution/src/main/resources/start.ini new file mode 100644 index 00000000000..3d7646db818 --- /dev/null +++ b/jetty-distribution/src/main/resources/start.ini @@ -0,0 +1,237 @@ +#=========================================================== +# Jetty start.jar arguments +# +# The contents of this file, together with the start.ini +# fragments found in start.d directory are used to build +# the classpath and command line on a call to +# java -jar start.jar [arg...] +# +# Use the following command to see more options +# java -jar start.jar --help +# +# Each line in this file is prepended to the command line +# as arguments, which may be either: +# + A property like: name=value +# + A file of properties like: /etc/myjetty.properties +# + A classpath option like: OPTION=jmx +# + An XML configuration file like: etc/jetty-feature.xml +# + A start.jar option like: --dry-run +# +# If --exec or --exec-print are used, then this file may also +# contain lines with: +# + A JVM option like: -Xmx2000m +# + A System Property like: -Dcom.sun.management.jmxremote +# +#----------------------------------------------------------- +# +# NOTE: The lines in this file may be uncommented to activate +# features. Alternately, the lines may be copied to a ini file +# in the start.d directory to enabled configuration without +# editing this file. See start.d/900-demo.ini for an example. +# +# Future releases will switch start.d style configuration for +# all features. +#=========================================================== + + + +#=========================================================== +# Configure JVM arguments. +# If JVM args are include in an ini file then --exec is needed +# to start a new JVM from start.jar with the extra args. +# If you wish to avoid an extra JVM running, place JVM args +# on the normal command line and do not use --exec +#----------------------------------------------------------- +# --exec +# -Xmx2000m +# -Xmn512m +# -XX:+UseConcMarkSweepGC +# -XX:ParallelCMSThreads=2 +# -XX:+CMSClassUnloadingEnabled +# -XX:+UseCMSCompactAtFullCollection +# -XX:CMSInitiatingOccupancyFraction=80 +# -verbose:gc +# -XX:+PrintGCDateStamps +# -XX:+PrintGCTimeStamps +# -XX:+PrintGCDetails +# -XX:+PrintTenuringDistribution +# -XX:+PrintCommandLineFlags +# -XX:+DisableExplicitGC + +# -Dorg.apache.jasper.compiler.disablejsr199=true + + + +#=========================================================== +# Default Server Options +# Use the core server jars with websocket on the classpath +# Add the contents of the resources directory to the classpath +# Add jars discovered in lib/ext to the classpath +# Include the core jetty configuration file +#----------------------------------------------------------- +OPTIONS=Server,websocket,resources,ext +threads.min=10 +threads.max=200 +threads.timeout=60000 +#jetty.host=myhost.com +jetty.dump.start=false +jetty.dump.stop=false + +etc/jetty.xml + +#=========================================================== +# JMX Management +# To enable remote JMX access uncomment jmxremote and +# enable --exec +#----------------------------------------------------------- +OPTIONS=jmx +# jetty.jmxrmihost=localhost +# jetty.jmxrmiport=1099 +# -Dcom.sun.management.jmxremote +etc/jetty-jmx.xml + +#=========================================================== +# Java Server Pages +#----------------------------------------------------------- +OPTIONS=jsp + +#=========================================================== +# Request logger +# Will add a handler to log all HTTP requests to a standard +# request log format file. +#----------------------------------------------------------- +# requestlog.retain=90 +# requestlog.append=true +# requestlog.extended=true +# etc/jetty-requestlog.xml + + +#=========================================================== +# stderr/stdout logging. +# The following configuration will redirect stderr and stdout +# to file which is rolled over daily. +#----------------------------------------------------------- +# jetty.log.retain=90 +# etc/jetty-logging.xml + + +#=========================================================== +# Enable SetUID +# The default user and group is 'jetty' and if you are +# starting as root you must change the run privledged to true +#----------------------------------------------------------- +# OPTIONS=setuid +# jetty.startServerAsPrivileged=false +# jetty.username=jetty +# jetty.groupname=jetty +# jetty.umask=002 +# etc/jetty-setuid.xml + + +#=========================================================== +# HTTP Connector +#----------------------------------------------------------- +jetty.port=8080 +http.timeout=30000 +etc/jetty-http.xml + + +#=========================================================== +# SSL Context +# Create the keystore and trust store for use by +# HTTPS and SPDY +#----------------------------------------------------------- +# jetty.keystore=etc/keystore +# jetty.keystore.password=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4 +# jetty.keymanager.password=OBF:1u2u1wml1z7s1z7a1wnl1u2g +# jetty.truststore=etc/keystore +# jetty.truststore.password=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4 +# jetty.secure.port=8443 +# etc/jetty-ssl.xml + + +#=========================================================== +# HTTPS Connector +# Must be used with jetty-ssl.xml +#----------------------------------------------------------- +# jetty.https.port=8443 +# etc/jetty-https.xml + + +#=========================================================== +# NPN Next Protocol Negotiation +# +# The SPDY and HTTP/2.0 connectors require NPN. The jar for +# NPN cannot be downloaded from eclipse. So the --download +# option is used to install the NPN jar if it does not already +# exist +# +#----------------------------------------------------------- +# --exec +# --download=http://repo1.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar +# -Xbootclasspath/p:lib/npn/npn-boot-1.1.5.v20130313.jar + + +#=========================================================== +# SPDY Connector +# Requires SSL Context and NPN from above +#----------------------------------------------------------- +# OPTIONS=spdy +# jetty.spdy.port=8443 +# etc/jetty-spdy.xml + + +#=========================================================== +# Webapplication Deployer +#----------------------------------------------------------- +etc/jetty-deploy.xml + + +# =========================================================== +# Enable JAAS +# ----------------------------------------------------------- +# OPTIONS=jaas +# jaas.login.conf=etc/login.conf +# etc/jetty-jaas.xml + +# =========================================================== +# Enable JNDI +# ----------------------------------------------------------- +# OPTIONS=jndi + +# =========================================================== +# Enable additional webapp environment configurators +# ----------------------------------------------------------- +# OPTIONS=plus +# etc/jetty-plus.xml + +# =========================================================== +# Enable servlet 3.1 annotations +# ----------------------------------------------------------- +# OPTIONS=annotations +# etc/jetty-annotations.xml + +#=========================================================== +# Other server features +#----------------------------------------------------------- +# etc/jetty-debug.xml +# etc/jetty-ipaccess.xml +# etc/jetty-stats.xml + + +#=========================================================== +# Low resource managment +#----------------------------------------------------------- +# lowresources.period=1050 +# lowresources.lowResourcesIdleTimeout=200 +# lowresources.monitorThreads=true +# lowresources.maxConnections=0 +# lowresources.maxMemory=0 +# lowresources.maxLowResourcesTime=5000 +# etc/jetty-lowresources.xml + + +#=========================================================== +# The start.d directory contains the active start.ini fragments +start.d/ + From 6ef6841a2e05f8840e4c0db4e2f7456cd85dd4a5 Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 22 Aug 2013 12:04:11 -0500 Subject: [PATCH 16/28] add modules directory --- jetty-distribution/src/main/resources/modules/.donotdelete | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 jetty-distribution/src/main/resources/modules/.donotdelete diff --git a/jetty-distribution/src/main/resources/modules/.donotdelete b/jetty-distribution/src/main/resources/modules/.donotdelete new file mode 100644 index 00000000000..e69de29bb2d From e7d33f52a4b895ebc604cb9a54166a4cf24e434a Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 22 Aug 2013 12:07:51 -0500 Subject: [PATCH 17/28] add security mod --- jetty-security/src/main/config/modules/security.mod | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 jetty-security/src/main/config/modules/security.mod diff --git a/jetty-security/src/main/config/modules/security.mod b/jetty-security/src/main/config/modules/security.mod new file mode 100644 index 00000000000..5a3c4a368a6 --- /dev/null +++ b/jetty-security/src/main/config/modules/security.mod @@ -0,0 +1,7 @@ +# +# Jetty Security Module +# + +DEPEND=server + +LIB=lib/jetty-security-${jetty.version}.jar From 450cdb3ef43b8ea4c8f11ac2d897995451110ff9 Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 22 Aug 2013 12:21:52 -0500 Subject: [PATCH 18/28] add servlet/s mod --- jetty-proxy/src/main/config/modules/proxy.mod | 1 + jetty-servlet/src/main/config/modules/servlet.mod | 7 +++++++ jetty-servlets/src/main/config/modules/servlets.mod | 7 +++++++ jetty-webapp/src/main/config/modules/webapp.mod | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 jetty-servlet/src/main/config/modules/servlet.mod create mode 100644 jetty-servlets/src/main/config/modules/servlets.mod diff --git a/jetty-proxy/src/main/config/modules/proxy.mod b/jetty-proxy/src/main/config/modules/proxy.mod index 9e2bc46db8c..5ab6e70a880 100644 --- a/jetty-proxy/src/main/config/modules/proxy.mod +++ b/jetty-proxy/src/main/config/modules/proxy.mod @@ -3,6 +3,7 @@ # DEPEND=server +DEPEND=client LIB=lib/jetty-proxy-${jetty.version}.jar diff --git a/jetty-servlet/src/main/config/modules/servlet.mod b/jetty-servlet/src/main/config/modules/servlet.mod new file mode 100644 index 00000000000..a427eed5478 --- /dev/null +++ b/jetty-servlet/src/main/config/modules/servlet.mod @@ -0,0 +1,7 @@ +# +# Jetty Servlet Module +# + +DEPEND=server + +LIB=lib/jetty-servlet-${jetty.version}.jar diff --git a/jetty-servlets/src/main/config/modules/servlets.mod b/jetty-servlets/src/main/config/modules/servlets.mod new file mode 100644 index 00000000000..3d471891dab --- /dev/null +++ b/jetty-servlets/src/main/config/modules/servlets.mod @@ -0,0 +1,7 @@ +# +# Jetty Servlets Module +# + +DEPEND=servlet + +LIB=lib/jetty-servlets-${jetty.version}.jar diff --git a/jetty-webapp/src/main/config/modules/webapp.mod b/jetty-webapp/src/main/config/modules/webapp.mod index 187db774b69..c39d5aae063 100644 --- a/jetty-webapp/src/main/config/modules/webapp.mod +++ b/jetty-webapp/src/main/config/modules/webapp.mod @@ -2,6 +2,6 @@ # Base server # -DEPEND=deploy +DEPEND=servlet LIB=lib/jetty-webapp-${jetty.version}.jar From 5c87965ff1aebb49c760940246c8bd4a3c2c1ff4 Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 22 Aug 2013 12:23:29 -0500 Subject: [PATCH 19/28] server depends on xml.. --- jetty-server/src/main/config/modules/server.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/jetty-server/src/main/config/modules/server.mod b/jetty-server/src/main/config/modules/server.mod index 06bf6772f5b..aa6cad6b0e6 100644 --- a/jetty-server/src/main/config/modules/server.mod +++ b/jetty-server/src/main/config/modules/server.mod @@ -3,6 +3,7 @@ # DEPEND=base +DEPEND=xml LIB=lib/servlet-api-3.1.jar LIB=lib/jetty-schemas-3.1.jar From 314169b49de93642e68930dfcbae7e0d1fd16847 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Aug 2013 10:40:25 -0700 Subject: [PATCH 20/28] Removing start.config related classes --- .../org/eclipse/jetty/start/Classpath.java | 134 ++- .../jetty/start/CommandLineBuilder.java | 118 +- .../java/org/eclipse/jetty/start/Config.java | 990 --------------- .../main/java/org/eclipse/jetty/start/FS.java | 2 +- .../java/org/eclipse/jetty/start/Main.java | 1072 ++--------------- .../java/org/eclipse/jetty/start/Module.java | 155 ++- .../java/org/eclipse/jetty/start/Modules.java | 2 +- .../org/eclipse/jetty/start/StartArgs.java | 364 +++++- .../org/eclipse/jetty/start/StartLog.java | 105 +- .../org/eclipse/jetty/start/TextFile.java | 28 +- .../org/eclipse/jetty/start/ConfigTest.java | 648 ---------- .../org/eclipse/jetty/start/MainTest.java | 106 +- .../org/eclipse/jetty/start/ModuleTest.java | 2 +- 13 files changed, 775 insertions(+), 2951 deletions(-) delete mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/Config.java delete mode 100644 jetty-start/src/test/java/org/eclipse/jetty/start/ConfigTest.java diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java index 775936cefc0..4a49e2da179 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java @@ -24,16 +24,17 @@ import java.io.PrintStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.StringTokenizer; -import java.util.Vector; /** * Class to handle CLASSPATH construction */ -public class Classpath +public class Classpath implements Iterable { - - private final Vector _elements = new Vector(); + private final List elements = new ArrayList(); public Classpath() { @@ -44,60 +45,55 @@ public class Classpath addClasspath(initial); } - public File[] getElements() + @Override + public Iterator iterator() { - return _elements.toArray(new File[_elements.size()]); + return elements.iterator(); + } + + public List getElements() + { + return elements; } public int count() { - return _elements.size(); + return elements.size(); } public boolean addComponent(String component) { - if ((component != null) && (component.length() > 0)) + if ((component == null) || (component.length() <= 0)) { - try - { - File f = new File(component); - if (f.exists()) - { - File key = f.getCanonicalFile(); - if (!_elements.contains(key)) - { - _elements.add(key); - return true; - } - } - } - catch (IOException e) - { - } + // nothing to add + return false; } - return false; + + return addComponent(new File(component)); } - public boolean addComponent(File component) + public boolean addComponent(File path) { - if (component != null) + if ((path == null) || (!path.exists())) { - try - { - if (component.exists()) - { - File key = component.getCanonicalFile(); - if (!_elements.contains(key)) - { - _elements.add(key); - return true; - } - } - } - catch (IOException e) + // not a valid component + return false; + } + + try + { + File key = path.getCanonicalFile(); + if (!elements.contains(key)) { + elements.add(key); + return true; } } + catch (IOException e) + { + StartLog.debug(e); + } + return false; } @@ -106,7 +102,7 @@ public class Classpath boolean added = false; if (s != null) { - StringTokenizer t = new StringTokenizer(s, File.pathSeparator); + StringTokenizer t = new StringTokenizer(s,File.pathSeparator); while (t.hasMoreTokens()) { added |= addComponent(t.nextToken()); @@ -118,9 +114,9 @@ public class Classpath public void dump(PrintStream out) { int i = 0; - for (File element : _elements) + for (File element : elements) { - out.printf("%2d: %s\n", i++, element.getAbsolutePath()); + out.printf("%2d: %s%n",i++,element.getAbsolutePath()); } } @@ -128,28 +124,28 @@ public class Classpath public String toString() { StringBuffer cp = new StringBuffer(1024); - int cnt = _elements.size(); - if (cnt >= 1) + boolean needDelim = false; + for (File element : elements) { - cp.append(((_elements.elementAt(0))).getPath()); - } - for (int i = 1; i < cnt; i++) - { - cp.append(File.pathSeparatorChar); - cp.append(((_elements.elementAt(i))).getPath()); + if (needDelim) + { + cp.append(File.pathSeparatorChar); + } + cp.append(element.getAbsolutePath()); + needDelim = true; } return cp.toString(); } public ClassLoader getClassLoader() { - int cnt = _elements.size(); + int cnt = elements.size(); URL[] urls = new URL[cnt]; for (int i = 0; i < cnt; i++) { try { - urls[i] = _elements.elementAt(i).toURI().toURL(); + urls[i] = elements.get(i).toURI().toURL(); } catch (MalformedURLException e) { @@ -165,14 +161,14 @@ public class Classpath { parent = ClassLoader.getSystemClassLoader(); } - return new Loader(urls, parent); + return new Loader(urls,parent); } private static class Loader extends URLClassLoader { Loader(URL[] urls, ClassLoader parent) { - super(urls, parent); + super(urls,parent); } @Override @@ -182,29 +178,35 @@ public class Classpath } } - - /** - * Overlay another classpath, copying its elements into place on this - * Classpath, while eliminating duplicate entries on the classpath. - * - * @param cpOther the other classpath to overlay + * Overlay another classpath, copying its elements into place on this Classpath, while eliminating duplicate entries on the classpath. + * + * @param other + * the other classpath to overlay */ - public void overlay(Classpath cpOther) + public void overlay(Classpath other) { - for (File otherElement : cpOther._elements) + for (File otherElement : other.elements) { - if (this._elements.contains(otherElement)) + if (this.elements.contains(otherElement)) { // Skip duplicate entries continue; } - this._elements.add(otherElement); + this.elements.add(otherElement); } } public boolean isEmpty() { - return (_elements == null) || (_elements.isEmpty()); + return (elements == null) || (elements.isEmpty()); + } + + /** + * Add the System classpath to this object's tracking + */ + public void addSystemClasspath() + { + addClasspath(System.getProperty("java.class.path")); } } 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 d50a4b70c1f..cbce8b02e78 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 @@ -18,13 +18,89 @@ package org.eclipse.jetty.start; +import java.io.File; import java.util.ArrayList; import java.util.List; public class CommandLineBuilder { + private static File findExecutable(File root, String path) + { + String npath = path.replace('/',File.separatorChar); + File exe = new File(root,npath); + if (!exe.exists()) + { + return null; + } + return exe; + } + + private static String findJavaBin() + { + 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"; + } + + /** + * Perform an optional quoting of the argument, being intelligent with spaces and quotes as needed. If a subString is set in quotes it won't the subString + * won't be escaped. + * + * @param arg + * @return + */ + public static String quote(String arg) + { + boolean needsQuoting = (arg.indexOf(' ') >= 0) || (arg.indexOf('"') >= 0); + if (!needsQuoting) + { + return arg; + } + StringBuilder buf = new StringBuilder(); + // buf.append('"'); + boolean escaped = false; + boolean quoted = false; + for (char c : arg.toCharArray()) + { + if (!quoted && !escaped && ((c == '"') || (c == ' '))) + { + buf.append("\\"); + } + // don't quote text in single quotes + if (!escaped && (c == '\'')) + { + quoted = !quoted; + } + escaped = (c == '\\'); + buf.append(c); + } + // buf.append('"'); + return buf.toString(); + } + private List args; + public CommandLineBuilder() + { + this(findJavaBin()); + } + public CommandLineBuilder(String bin) { args = new ArrayList(); @@ -42,7 +118,9 @@ public class CommandLineBuilder public void addArg(String arg) { if (arg != null) + { args.add(quote(arg)); + } } /** @@ -65,7 +143,7 @@ public class CommandLineBuilder */ public void addEqualsArg(String name, String value) { - if (value != null && value.length() > 0) + if ((value != null) && (value.length() > 0)) { args.add(quote(name + "=" + value)); } @@ -86,7 +164,9 @@ public class CommandLineBuilder public void addRawArg(String arg) { if (arg != null) + { args.add(arg); + } } public List getArgs() @@ -94,42 +174,6 @@ public class CommandLineBuilder return args; } - /** - * Perform an optional quoting of the argument, being intelligent with spaces and quotes as needed. If a - * subString is set in quotes it won't the subString won't be escaped. - * - * @param arg - * @return - */ - public static String quote(String arg) - { - boolean needsQuoting = arg.indexOf(' ') >= 0 || arg.indexOf('"') >= 0; - if (!needsQuoting) - { - return arg; - } - StringBuilder buf = new StringBuilder(); - // buf.append('"'); - boolean escaped = false; - boolean quoted = false; - for (char c : arg.toCharArray()) - { - if (!quoted && !escaped && ((c == '"') || (c == ' '))) - { - buf.append("\\"); - } - // don't quote text in single quotes - if (!escaped && c == '\'') - { - quoted = !quoted; - } - escaped = (c == '\\'); - buf.append(c); - } - // buf.append('"'); - return buf.toString(); - } - @Override public String toString() { diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java deleted file mode 100644 index 5f92976211c..00000000000 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Config.java +++ /dev/null @@ -1,990 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.start; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileFilter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.TreeSet; - -/** - *

- * It allows an application to be started with the command "java -jar start.jar". - *

- * - *

- * The behaviour of Main is controlled by the "org/eclipse/start/start.config" file obtained as a resource or file. This can be overridden with the - * START system property. The format of each line in this file is: - *

- * - *

- * Each line contains entry in the format: - *

- * - *
- *   SUBJECT [ [!] CONDITION [AND|OR] ]*
- * 
- * - *

- * where SUBJECT: - *

- *
    - *
  • ends with ".class" is the Main class to run.
  • - *
  • ends with ".xml" is a configuration file for the command line
  • - *
  • ends with "/" is a directory from which to add all jar and zip files.
  • - *
  • ends with "/*" is a directory from which to add all unconsidered jar and zip files.
  • - *
  • ends with "/**" is a directory from which to recursively add all unconsidered jar and zip files.
  • - *
  • Containing = are used to assign system properties.
  • - *
  • Containing ~= are used to assign start properties.
  • - *
  • Containing /= are used to assign a canonical path.
  • - *
  • all other subjects are treated as files to be added to the classpath.
  • - *
- * - *

- * property expansion: - *

- *
    - *
  • ${name} is expanded to a start property
  • - *
  • $(name) is expanded to either a start property or a system property.
  • - *
  • The start property ${version} is defined as the version of the start.jar
  • - *
- * - *

- * Files starting with "/" are considered absolute, all others are relative to the home directory. - *

- * - *

- * CONDITION is one of: - *

- *
    - *
  • always
  • - *
  • never
  • - *
  • available classname - true if class on classpath
  • - *
  • property name - true if set as start property
  • - *
  • system name - true if set as system property
  • - *
  • exists file - true if file/dir exists
  • - *
  • java OPERATOR version - java version compared to literal
  • - *
  • nargs OPERATOR number - number of command line args compared to literal
  • - *
  • OPERATOR := one of "<",">","<=",">=", "==","!="
  • - *
- * - *

- * CONDITIONS can be combined with AND OR or !, with AND being the assume operator for a list of CONDITIONS. - *

- * - *

- * Classpath operations are evaluated on the fly, so once a class or jar is added to the classpath, subsequent available conditions will see that class. - *

- * - *

- * The configuration file may be divided into sections with option names like: [ssl,default] - *

- * - *

- * Note: a special discovered section identifier [=path_to_directory/*] is allowed to auto-create section IDs, based on directory names found in - * the path specified in the "path_to_directory/" part of the identifier. - *

- * - *

- * Clauses after a section header will only be included if they match one of the tags in the options property. By default options are set to "default,*" or the - * OPTIONS property may be used to pass in a list of tags, eg. : - *

- * - *
- *    java -jar start.jar OPTIONS=jetty,jsp,ssl
- * 
- * - *

- * The tag '*' is always appended to the options, so any section with the * tag is always applied. - *

- * - *

- * The property map maintained by this class is static and shared between all instances in the same classloader - *

- */ -public class Config -{ - public static final String DEFAULT_SECTION = ""; - static - { - String ver = System.getProperty("jetty.version",null); - - if (ver == null) - { - Package pkg = Config.class.getPackage(); - if (pkg != null && "Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) && (pkg.getImplementationVersion() != null)) - { - ver = pkg.getImplementationVersion(); - } - } - - if (ver == null) - { - ver = "Unknown"; - } - __version = ver; - } - - /** - * Natural language sorting for key names. - */ - private final Comparator keySorter = new NaturalSort.Strings(); - - private static final String __version; - private static boolean DEBUG = false; - private static Config __instance; - - private final BaseHome _homebase; - private final Map _properties = new HashMap(); - private final Map _classpaths = new HashMap(); - private final List _xml = new ArrayList(); - private String _classname = null; - - private int argCount = 0; - - private final Set _options = new TreeSet(new Comparator() - { - // Make sure "*" is always at the end of the list - public int compare(String o1, String o2) - { - if ("*".equals(o1)) - { - return 1; - } - if ("*".equals(o2)) - { - return -1; - } - return o1.compareTo(o2); - } - }); - - public Config() - { - __instance = this; - _homebase = new BaseHome(); - setProperty("jetty.home",_homebase.getHome()); - setProperty("jetty.base",_homebase.getBase()); - } - - public BaseHome getBaseHome() - { - return _homebase; - } - - public Classpath defineOption(String option) - { - Classpath cp = _classpaths.get(option); - if (cp == null) - { - cp = new Classpath(); - _classpaths.put(option,cp); - } - return cp; - } - - private boolean addClasspathComponent(List sections, String component) - { - for (String section : sections) - { - Classpath cp = defineOption(section); - - boolean added = cp.addComponent(component); - if (!added) - { - // First failure means all failed. - return false; - } - } - - return true; - } - - private boolean addClasspathPath(List sections, String path) - { - for (String section : sections) - { - Classpath cp = _classpaths.get(section); - if (!cp.addClasspath(path)) - { - // First failure means all failed. - return false; - } - _classpaths.put(section,cp); - } - - return true; - } - - private void addJars(List sections, File dir, boolean recurse) throws IOException - { - List entries = new ArrayList(); - File[] files = dir.listFiles(); - if (files == null) - { - // No files found, skip it. - return; - } - entries.addAll(Arrays.asList(files)); - Collections.sort(entries,FilenameComparator.INSTANCE); - - for (File entry : entries) - { - if (entry.isDirectory()) - { - if (recurse) - addJars(sections,entry,recurse); - } - else - { - String name = entry.getName().toLowerCase(Locale.ENGLISH); - if (name.endsWith(".jar") || name.endsWith(".zip")) - { - String jar = entry.getCanonicalPath(); - boolean added = addClasspathComponent(sections,jar); - debug((added?" CLASSPATH+=":" !") + jar); - } - } - } - } - - public static boolean isDebug() - { - return DEBUG; - } - - public static void debug(String msg) - { - if (DEBUG) - { - System.err.println(msg); - } - } - - public static void debug(String format, Object... args) - { - if (DEBUG) - { - System.err.printf(format + "%n",args); - } - } - - public static void debug(Throwable t) - { - if (DEBUG) - { - t.printStackTrace(System.err); - } - } - - private String expand(String s) - { - int i1 = 0; - int i2 = 0; - while (s != null) - { - i1 = s.indexOf("$(",i2); - if (i1 < 0) - break; - i2 = s.indexOf(")",i1 + 2); - if (i2 < 0) - break; - String name = s.substring(i1 + 2,i2); - String property = getProperty(name); - s = s.substring(0,i1) + property + s.substring(i2 + 1); - } - - i1 = 0; - i2 = 0; - while (s != null) - { - i1 = s.indexOf("${",i2); - if (i1 < 0) - break; - i2 = s.indexOf("}",i1 + 2); - if (i2 < 0) - break; - String name = s.substring(i1 + 2,i2); - String property = getProperty(name); - s = s.substring(0,i1) + property + s.substring(i2 + 1); - } - - return s; - } - - /** - * Get the default classpath. - * - * @return the default classpath - */ - public Classpath getClasspath() - { - return _classpaths.get(DEFAULT_SECTION); - } - - /** - * Get the active classpath, as dictated by OPTIONS= entries. - * - * @return the Active classpath - * @see #getCombinedClasspath(Collection) - */ - public Classpath getActiveClasspath() - { - return getCombinedClasspath(_options); - } - - /** - * Get the combined classpath representing the default classpath plus all named sections. - * - * NOTE: the default classpath will be prepended, and the '*' classpath will be appended. - * - * @param optionIds - * the list of section ids to fetch - * @return the {@link Classpath} representing combination all of the selected sectionIds, combined with the default section id, and '*' special id. - */ - public Classpath getCombinedClasspath(Collection optionIds) - { - Classpath cp = new Classpath(); - - cp.overlay(_classpaths.get(DEFAULT_SECTION)); - for (String optionId : optionIds) - { - Classpath otherCp = _classpaths.get(optionId); - if (otherCp == null) - { - throw new IllegalArgumentException("No such OPTION: " + optionId); - } - cp.overlay(otherCp); - } - cp.overlay(_classpaths.get("*")); - return cp; - } - - public String getMainClassname() - { - return _classname; - } - - public void clearProperties() - { - _properties.clear(); - } - - /* This method is static so it can be accessed by XmlConfiguration */ - public static Properties getProperties() - { - Properties properties = new Properties(); - // Add System Properties First - Enumeration ensysprop = System.getProperties().propertyNames(); - while (ensysprop.hasMoreElements()) - { - String name = (String)ensysprop.nextElement(); - properties.put(name,System.getProperty(name)); - } - // Add Config Properties Next (overwriting any System Properties that exist) - for (String key : __instance._properties.keySet()) - { - properties.put(key,__instance._properties.get(key)); - } - return properties; - } - - public String getProperty(String name) - { - if ("version".equalsIgnoreCase(name)) - { - return __version; - } - // Search Config Properties First - if (_properties.containsKey(name)) - { - return _properties.get(name); - } - // Return what exists in System.Properties otherwise. - return System.getProperty(name); - } - - public String getProperty(String name, String defaultValue) - { - // Search Config Properties First - if (_properties.containsKey(name)) - return _properties.get(name); - // Return what exists in System.Properties otherwise. - return System.getProperty(name,defaultValue); - } - - /** - * Get the classpath for the named section - * - * @param sectionId - * @return the classpath for the specified section id - */ - public Classpath getSectionClasspath(String sectionId) - { - return _classpaths.get(sectionId); - } - - /** - * Get the list of section Ids. - * - * @return the set of unique section ids - */ - public Set getSectionIds() - { - Set ids = new TreeSet(keySorter); - ids.addAll(_classpaths.keySet()); - return ids; - } - - public List getXmlConfigs() - { - return _xml; - } - - private boolean isAvailable(List options, String classname) - { - // Try default/parent class loader first. - try - { - Class.forName(classname); - return true; - } - catch (NoClassDefFoundError e) - { - debug(e); - } - catch (ClassNotFoundException e) - { - debug("ClassNotFoundException (parent class loader): " + classname); - } - - // Try option classloaders instead - ClassLoader loader; - Classpath classpath; - for (String optionId : options) - { - classpath = _classpaths.get(optionId); - if (classpath == null) - { - // skip, no classpath - continue; - } - - loader = classpath.getClassLoader(); - - try - { - loader.loadClass(classname); - return true; - } - catch (NoClassDefFoundError e) - { - debug(e); - } - catch (ClassNotFoundException e) - { - debug("ClassNotFoundException (section class loader: " + optionId + "): " + classname); - } - } - return false; - } - - /** - * Parse the configuration - * - * @param buf - * @throws IOException - */ - public void parse(CharSequence buf) throws IOException - { - try (StringReader reader = new StringReader(buf.toString())) - { - parse(reader); - } - } - - /** - * Parse the configuration - * - * @param stream - * the stream to read from - * @throws IOException - */ - public void parse(InputStream stream) throws IOException - { - try (InputStreamReader reader = new InputStreamReader(stream)) - { - parse(reader); - } - } - - /** - */ - public void parse(Reader reader) throws IOException - { - try (BufferedReader buf = new BufferedReader(reader)) - { - List options = new ArrayList(); - options.add(DEFAULT_SECTION); - _classpaths.put(DEFAULT_SECTION,new Classpath()); - Version java_version = new Version(System.getProperty("java.version")); - Version ver = new Version(); - - String line = null; - while ((line = buf.readLine()) != null) - { - String trim = line.trim(); - if (trim.length() == 0) // empty line - continue; - - if (trim.startsWith("#")) // comment - continue; - - // handle options - if (trim.startsWith("[") && trim.endsWith("]")) - { - String identifier = trim.substring(1,trim.length() - 1); - - // Normal case: section identifier (possibly separated by commas) - options = Arrays.asList(identifier.split(",")); - List option_ids = new ArrayList(); - - // Ensure section classpaths exist - for (String optionId : options) - { - if (optionId.charAt(0) == '=') - continue; - - if (!_classpaths.containsKey(optionId)) - _classpaths.put(optionId,new Classpath()); - - if (!option_ids.contains(optionId)) - option_ids.add(optionId); - } - - // Process Dynamic - for (String optionId : options) - { - if (optionId.charAt(0) != '=') - continue; - - option_ids = processDynamicSectionIdentifier(optionId.substring(1),option_ids); - } - - options = option_ids; - - continue; - } - - try - { - StringTokenizer st = new StringTokenizer(line); - String subject = st.nextToken(); - boolean expression = true; - boolean not = false; - String condition = null; - // Evaluate all conditions - while (st.hasMoreTokens()) - { - condition = st.nextToken(); - if (condition.equalsIgnoreCase("!")) - { - not = true; - continue; - } - if (condition.equalsIgnoreCase("OR")) - { - if (expression) - break; - expression = true; - continue; - } - if (condition.equalsIgnoreCase("AND")) - { - if (!expression) - break; - continue; - } - boolean eval = true; - if (condition.equals("true") || condition.equals("always")) - { - eval = true; - } - else if (condition.equals("false") || condition.equals("never")) - { - eval = false; - } - else if (condition.equals("available")) - { - String class_to_check = st.nextToken(); - eval = isAvailable(options,class_to_check); - } - else if (condition.equals("exists")) - { - try - { - eval = false; - File file = new File(expand(st.nextToken())); - eval = file.exists(); - } - catch (Exception e) - { - debug(e); - } - } - else if (condition.equals("property")) - { - String property = getProperty(st.nextToken()); - eval = property != null && property.length() > 0; - } - else if (condition.equals("system")) - { - String property = System.getProperty(st.nextToken()); - eval = property != null && property.length() > 0; - } - else if (condition.equals("java")) - { - String operator = st.nextToken(); - String version = st.nextToken(); - ver.parse(version); - eval = (operator.equals("<") && java_version.compare(ver) < 0) || (operator.equals(">") && java_version.compare(ver) > 0) - || (operator.equals("<=") && java_version.compare(ver) <= 0) || (operator.equals("=<") && java_version.compare(ver) <= 0) - || (operator.equals("=>") && java_version.compare(ver) >= 0) || (operator.equals(">=") && java_version.compare(ver) >= 0) - || (operator.equals("==") && java_version.compare(ver) == 0) || (operator.equals("!=") && java_version.compare(ver) != 0); - } - else if (condition.equals("nargs")) - { - String operator = st.nextToken(); - int number = Integer.parseInt(st.nextToken()); - eval = (operator.equals("<") && argCount < number) || (operator.equals(">") && argCount > number) - || (operator.equals("<=") && argCount <= number) || (operator.equals("=<") && argCount <= number) - || (operator.equals("=>") && argCount >= number) || (operator.equals(">=") && argCount >= number) - || (operator.equals("==") && argCount == number) || (operator.equals("!=") && argCount != number); - } - else - { - System.err.println("ERROR: Unknown condition: " + condition); - eval = false; - } - expression &= not?!eval:eval; - not = false; - } - - String file = expand(subject); - debug((expression?"T ":"F ") + line); - if (!expression) - continue; - - // Setting of a start property - if (subject.indexOf("~=") > 0) - { - int i = file.indexOf("~="); - String property = file.substring(0,i); - String value = fixPath(file.substring(i + 2)); - debug(" " + property + "~=" + value); - setProperty(property,value); - continue; - } - - // Setting of start property with canonical path - if (subject.indexOf("/=") > 0) - { - int i = file.indexOf("/="); - String property = file.substring(0,i); - String value = fixPath(file.substring(i + 2)); - String canonical = new File(value).getCanonicalPath(); - debug(" " + property + "/=" + value + "==" + canonical); - setProperty(property,canonical); - continue; - } - - // Setting of system property - if (subject.indexOf("=") > 0) - { - int i = file.indexOf("="); - String property = file.substring(0,i); - String value = fixPath(file.substring(i + 1)); - debug(" " + property + "=" + value); - System.setProperty(property,value); - continue; - } - - // Add all unconsidered JAR and ZIP files to classpath - if (subject.endsWith("/*")) - { - // directory of JAR files - only add jars and zips within the directory - File dir = new File(fixPath(file.substring(0,file.length() - 1))); - addJars(options,dir,false); - continue; - } - - // Recursively add all unconsidered JAR and ZIP files to classpath - if (subject.endsWith("/**")) - { - // directory hierarchy of jar files - recursively add all jars and zips in the hierarchy - File dir = new File(fixPath(file.substring(0,file.length() - 2))); - addJars(options,dir,true); - continue; - } - - // Add raw classpath directory to classpath - if (subject.endsWith("/")) - { - // class directory - File cd = new File(fixPath(file)); - String d = cd.getCanonicalPath(); - boolean added = addClasspathComponent(options,d); - debug((added?" CLASSPATH+=":" !") + d); - continue; - } - - // Add XML configuration - if (subject.toLowerCase(Locale.ENGLISH).endsWith(".xml")) - { - // Config file - File f = new File(fixPath(file)); - if (f.exists()) - _xml.add(f.getCanonicalPath()); - debug(" ARGS+=" + f); - continue; - } - - // Set the main class to execute (overrides any previously set) - if (subject.toLowerCase(Locale.ENGLISH).endsWith(".class")) - { - // Class - String cn = expand(subject.substring(0,subject.length() - 6)); - if (cn != null && cn.length() > 0) - { - debug(" CLASS=" + cn); - _classname = cn; - } - continue; - } - - // Add raw classpath entry - if (subject.toLowerCase(Locale.ENGLISH).endsWith(".path")) - { - // classpath (jetty.class.path?) to add to runtime classpath - String cn = expand(subject.substring(0,subject.length() - 5)); - if (cn != null && cn.length() > 0) - { - debug(" PATH=" + cn); - addClasspathPath(options,cn); - } - continue; - } - - // single JAR file - File f = new File(fixPath(file)); - if (f.exists()) - { - String d = f.getCanonicalPath(); - boolean added = addClasspathComponent(options,d); - if (!added) - { - added = addClasspathPath(options,expand(subject)); - } - debug((added?" CLASSPATH+=":" !") + d); - } - } - catch (Exception e) - { - System.err.println("on line: '" + line + "'"); - e.printStackTrace(); - } - } - } - } - - private List processDynamicSectionIdentifier(String dynamicPathId, List sections) throws IOException - { - String rawPath; - boolean deep; - - if (dynamicPathId.endsWith("/*")) - { - deep = false; - rawPath = fixPath(dynamicPathId.substring(0,dynamicPathId.length() - 1)); - } - else if (dynamicPathId.endsWith("/**")) - { - deep = true; - rawPath = fixPath(dynamicPathId.substring(0,dynamicPathId.length() - 2)); - } - else - { - String msg = "Illegal dynamic path [" + dynamicPathId + "]"; - throw new IOException(msg); - } - - File parentDir = new File(expand(rawPath)); - if (!parentDir.exists()) - return sections; - debug("dynamic: " + parentDir); - - File dirs[] = parentDir.listFiles(new FileFilter() - { - public boolean accept(File path) - { - return path.isDirectory(); - } - }); - - List dyn_sections = new ArrayList(); - List super_sections = new ArrayList(); - if (sections != null) - super_sections.addAll(sections); - - for (File dir : dirs) - { - String id = dir.getName(); - if (!_classpaths.keySet().contains(id)) - _classpaths.put(id,new Classpath()); - - dyn_sections.clear(); - if (sections != null) - dyn_sections.addAll(sections); - dyn_sections.add(id); - super_sections.add(id); - debug("dynamic: " + dyn_sections); - addJars(dyn_sections,dir,deep); - } - - return super_sections; - } - - private String fixPath(String path) - { - return path.replace('/',File.separatorChar); - } - - public void parse(URL url) throws IOException - { - InputStream stream = null; - InputStreamReader reader = null; - try - { - stream = url.openStream(); - reader = new InputStreamReader(stream); - parse(reader); - } - finally - { - FS.close(reader); - FS.close(stream); - } - } - - public void setArgCount(int argCount) - { - this.argCount = argCount; - } - - public void setProperty(String name, String value) - { - if (name.equals("DEBUG")) - { - DEBUG = Boolean.parseBoolean(value); - if (DEBUG) - { - System.setProperty("org.eclipse.jetty.util.log.stderr.DEBUG","true"); - System.setProperty("org.eclipse.jetty.start.DEBUG","true"); - } - } - if (name.equals("OPTIONS")) - { - _options.clear(); - String ids[] = value.split(","); - for (String id : ids) - addOption(id); - } - if (name.equals("jetty.base")) - { - File base = new File(value); - try - { - value = base.getCanonicalPath(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - _properties.put(name,value); - } - - public void addOption(String option) - { - _options.add(option); - _properties.put("OPTIONS",join(_options,",")); - } - - public Set getKnownOptions() - { - return _classpaths.keySet(); - } - - public Set getOptions() - { - return _options; - } - - public void removeOption(String option) - { - _options.remove(option); - _properties.put("OPTIONS",join(_options,",")); - } - - private String join(Collection coll, String delim) - { - StringBuffer buf = new StringBuffer(); - Iterator i = coll.iterator(); - boolean hasNext = i.hasNext(); - while (hasNext) - { - buf.append(String.valueOf(i.next())); - hasNext = i.hasNext(); - if (hasNext) - buf.append(delim); - } - - return buf.toString(); - } -} diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java index d12d9d7cb1b..5a40f47fb95 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java @@ -96,7 +96,7 @@ public class FS super("^.*\\.xml$"); } } - + public static boolean canReadDirectory(File path) { return (path.exists() && path.isDirectory() && path.canRead()); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 9811be59043..367e1af50c1 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -19,18 +19,14 @@ package org.eclipse.jetty.start; import static org.eclipse.jetty.start.UsageException.*; -import java.io.BufferedReader; + import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.OutputStream; -import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.ConnectException; @@ -38,19 +34,10 @@ import java.net.InetAddress; import java.net.Socket; import java.net.SocketTimeoutException; import java.net.URL; -import java.nio.file.Files; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.Date; -import java.util.HashSet; import java.util.List; import java.util.Locale; -import java.util.Properties; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * Main start class. @@ -91,33 +78,16 @@ import java.util.regex.Pattern; */ public class Main { - private static final String START_LOG_FILENAME = "start.log"; - private static final SimpleDateFormat START_LOG_ROLLOVER_DATEFORMAT = new SimpleDateFormat("yyyy_MM_dd-HHmmSSSSS.'" + START_LOG_FILENAME + "'"); - private static final Pattern NNN_MODULE_INI = Pattern.compile("^(\\d\\d\\d-)(.*?\\.ini)(\\.disabled)?$",Pattern.CASE_INSENSITIVE); - private static final int EXIT_USAGE = 1; - private boolean _showUsage = false; - private boolean _dumpVersions = false; - private boolean _listConfig = false; - private boolean _listOptions = false; - private boolean _noRun = false; - private boolean _dryRun = false; - private boolean _exec = false; - private final Config _config; - private final Set _sysProps = new HashSet<>(); - private final List _jvmArgs = new ArrayList<>(); - private final List _enable = new ArrayList<>(); - private final List _disable = new ArrayList<>(); - private String _startConfig = null; + private final BaseHome baseHome; public static void main(String[] args) { try { Main main = new Main(); - List xmls = main.processCommandLine(args); - if (xmls != null) - main.start(xmls); + StartArgs startArgs = main.processCommandLine(args); + main.start(startArgs); } catch (UsageException e) { @@ -131,18 +101,12 @@ public class Main Main() throws IOException { - _config = new Config(); + baseHome = new BaseHome(); } - Config getConfig() - { - return _config; - } - - public List processCommandLine(String[] cmdLine) throws Exception + public StartArgs processCommandLine(String[] cmdLine) throws Exception { StartArgs args = new StartArgs(cmdLine); - BaseHome baseHome = _config.getBaseHome(); // Processing Order is important! // ------------------------------------------------------------ @@ -150,7 +114,7 @@ public class Main // Set Home and Base at the start, as all other paths encountered // will be based off of them. - _config.getBaseHome().initialize(args); + baseHome.initialize(args); // ------------------------------------------------------------ // 2) Start Logging @@ -164,7 +128,7 @@ public class Main args.parse(new StartIni(start_ini)); } - File start_d = _config.getBaseHome().getBaseFile("start.d"); + File start_d = baseHome.getBaseFile("start.d"); if (FS.canReadDirectory(start_d)) { List files = new ArrayList<>(); @@ -200,260 +164,9 @@ public class Main List activeModules = modules.resolveEnabled(); // 7) Lib & XML Expansion / Resolution - args.expandModules(baseHome, activeModules); + args.expandModules(baseHome,activeModules); - /* - // Do we have a start.ini? - File start_ini = _config.getBaseHome().getFile("start.ini"); - if (start_ini.exists() && start_ini.canRead() && !start_ini.isDirectory()) - inis.add(new StartIni(start_ini)); - - // Do we have a start.d? - File start_d = _config.getBaseHome().getFile("start.d"); - if (start_d.exists() && start_d.canRead() && start_d.isDirectory()) - { - List files = new ArrayList<>(); - for (File file : start_d.listFiles(new FS.IniFilter())) - files.add(file); - - Collections.sort(files,new NaturalSort.Files()); - for (File file : files) - inis.add(new StartIni(file)); - } - - // Add the commandline last - inis.add(new StartIni(cmd_line)); - - // TODO - we could sort the StartIni files by dependency here - - // The XML Configuration Files to initialize with - List xmls = new ArrayList(); - - // Expand arguments - for (StartIni ini : inis) - { - String source = ""; - if (ini.getFile() != null) - source = ini.getFile().getAbsolutePath(); - - for (String arg : ini.getLines()) - { - - if ("--help".equals(arg) || "-?".equals(arg)) - { - _showUsage = true; - _noRun = true; - continue; - } - - if ("--stop".equals(arg)) - { - int port = Integer.parseInt(_config.getProperty("STOP.PORT","-1")); - String key = _config.getProperty("STOP.KEY",null); - int timeout = Integer.parseInt(_config.getProperty("STOP.WAIT","0")); - stop(port,key,timeout); - _noRun = true; - } - - if (arg.startsWith("--download=")) - { - download(arg); - continue; - } - - if ("--version".equals(arg) || "-v".equals(arg) || "--info".equals(arg)) - { - _dumpVersions = true; - _noRun = true; - continue; - } - - if ("--list-modes".equals(arg) || "--list-options".equals(arg)) - { - _listOptions = true; - _noRun = true; - continue; - } - - if ("--list-config".equals(arg)) - { - _listConfig = true; - _noRun = true; - continue; - } - - if ("--exec-print".equals(arg) || "--dry-run".equals(arg)) - { - _dryRun = true; - _noRun = true; - continue; - } - - if ("--exec".equals(arg)) - { - _exec = true; - continue; - } - - if (arg.startsWith("--enable=")) - { - String module = arg.substring(9); - _noRun = true; - _enable.add(module); - } - - if (arg.startsWith("--disable=")) - { - String module = arg.substring(10); - _noRun = true; - _disable.add(module); - } - - // Alternative start.config file - if (arg.startsWith("--config=")) - { - _startConfig = arg.substring(9); - continue; - } - - // Special internal indicator that jetty was started by the jetty.sh Daemon - // All this does is setup a start.log that captures startup console output - // in the tiny window of time before the real logger kicks in. - // Useful for capturing when things go horribly wrong - if ("--daemon".equals(arg)) - { - File startDir = new File(System.getProperty("jetty.logs","logs")); - if (!startDir.exists() || !startDir.canWrite()) - startDir = new File("."); - - File startLog = new File(startDir,START_LOG_ROLLOVER_DATEFORMAT.format(new Date())); - - if (!startLog.exists() && !startLog.createNewFile()) - { - // Output about error is lost in majority of cases. - System.err.println("Unable to create: " + startLog.getAbsolutePath()); - // Toss a unique exit code indicating this failure. - usageExit(ERR_LOGGING); - } - - if (!startLog.canWrite()) - { - // Output about error is lost in majority of cases. - System.err.println("Unable to write to: " + startLog.getAbsolutePath()); - // Toss a unique exit code indicating this failure. - usageExit(ERR_LOGGING); - } - PrintStream logger = new PrintStream(new FileOutputStream(startLog,false)); - System.setOut(logger); - System.setErr(logger); - System.out.println("Establishing " + START_LOG_FILENAME + " on " + new Date()); - continue; - } - - // Start Property (syntax similar to System Property) - if (arg.startsWith("-D")) - { - String[] assign = arg.substring(2).split("=",2); - _sysProps.add(assign[0]); - switch (assign.length) - { - case 2: - System.setProperty(assign[0],assign[1]); - break; - case 1: - System.setProperty(assign[0],""); - break; - default: - break; - } - continue; - } - - // Anything else is a JVM argument - if (arg.startsWith("-")) - { - _jvmArgs.add(arg); - continue; - } - - // Is this a Property? - if (arg.indexOf('=') >= 0) - { - String[] assign = arg.split("=",2); - - switch (assign.length) - { - case 2: - if ("DEFINE".equals(assign[0])) - { - String opts[] = assign[1].split(","); - for (String opt : opts) - _config.defineOption(opt.trim()); - } - else if ("DEPEND".equals(assign[0])) - { - String opts[] = assign[1].split(","); - for (String opt : opts) - { - opt = opt.trim(); - if (!_config.getOptions().contains(opt)) - { - System.err.printf("ERROR: Missing Dependency: %s DEPEND %s%n",path(source),opt); - _noRun = true; - } - } - } - else if ("EXCLUDE".equals(assign[0])) - { - String opts[] = assign[1].split(","); - for (String opt : opts) - { - opt = opt.trim(); - if (_config.getOptions().contains(opt)) - { - System.err.printf("ERROR: Excluded Dependency: %s EXCLUDE %s%n",path(source),opt); - _noRun = true; - } - } - } - else if ("OPTION".equals(assign[0])) - { - String opts[] = assign[1].split(","); - for (String opt : opts) - _config.addOption(opt.trim()); - } - else if ("OPTIONS".equals(assign[0])) - { - this._config.setProperty(assign[0],assign[1]); - } - else - { - this._config.setProperty(assign[0],assign[1]); - } - break; - - case 1: - this._config.setProperty(assign[0],null); - break; - default: - break; - } - - continue; - } - - // Anything else is considered an XML file. - if (xmls.contains(arg)) - { - System.err.println("WARN: Argument '" + arg + "' specified multiple times. Check start.ini?"); - System.err.println("Use \"java -jar start.jar --help\" for more information."); - } - xmls.add(arg); - } - } - */ - - return null; + return args; } private void download(String arg) @@ -469,7 +182,7 @@ public class Main location.replaceAll("/",File.separator); File file = new File(location); - Config.debug("Download to %s %s",file.getAbsolutePath(),(file.exists()?"[Exists!]":"")); + StartLog.debug("Download to %s %s",file.getAbsolutePath(),(file.exists()?"[Exists!]":"")); if (file.exists()) return; @@ -512,143 +225,30 @@ public class Main System.err.println("ERROR: detailed usage resource unavailable"); usageExit(EXIT_USAGE); } - - BufferedReader buf = null; - try - { - buf = new BufferedReader(new InputStreamReader(usageStream)); - String line; - - while ((line = buf.readLine()) != null) - { - if (line.endsWith("@") && line.indexOf('@') != line.lastIndexOf('@')) - { - String indent = line.substring(0,line.indexOf("@")); - String info = line.substring(line.indexOf('@'),line.lastIndexOf('@')); - - if (info.equals("@OPTIONS")) - { - List sortedOptions = new ArrayList(); - sortedOptions.addAll(_config.getSectionIds()); - Collections.sort(sortedOptions); - - for (String option : sortedOptions) - { - if ("*".equals(option) || option.trim().length() == 0) - continue; - System.out.print(indent); - System.out.println(option); - } - } - else if (info.equals("@CONFIGS")) - { - FileFilter filter = new FileFilter() - { - public boolean accept(File path) - { - if (!path.isFile()) - { - return false; - } - - String name = path.getName().toLowerCase(Locale.ENGLISH); - return (name.startsWith("jetty") && name.endsWith(".xml")); - } - }; - - // list etc - List configFiles = _config.getBaseHome().listFiles("etc",filter); - - for (File configFile : configFiles) - { - System.out.printf("%s%s%n",indent,path(configFile)); - } - } - else if (info.equals("@STARTINI")) - { - BaseHome hb = _config.getBaseHome(); - File start_d = hb.getFile("start.d"); - if (start_d.exists() && start_d.isDirectory()) - { - File[] files = start_d.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?.*\\.ini(\\.disabled)?")); - Arrays.sort(files,new NaturalSort.Files()); - for (File file : files) - { - String path = _config.getBaseHome().toShortForm(file); - System.out.printf("%s%s%n",indent,path); - - if (Config.isDebug()) - { - StartIni ini = new StartIni(file); - for (String arg : ini) - { - System.out.printf("%s +-- %s%n",indent,arg); - } - } - } - } - } - } - else - { - System.out.println(line); - } - } - } - catch (IOException e) - { - usageExit(e,EXIT_USAGE); - } - finally - { - FS.close(buf); - } System.exit(EXIT_USAGE); } - private String path(String path) - { - return _config.getBaseHome().toShortForm(path); - } - - private String path(File file) - { - return _config.getBaseHome().toShortForm(file); - } - - public void invokeMain(ClassLoader classloader, String classname, List args) throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException, ClassNotFoundException + public void invokeMain(StartArgs args) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException, IOException { Class invoked_class = null; + ClassLoader classloader = args.getClasspath().getClassLoader(); + String mainclass = args.getMainClassname(); try { - invoked_class = classloader.loadClass(classname); + invoked_class = classloader.loadClass(mainclass); } catch (ClassNotFoundException e) { - e.printStackTrace(); + StartLog.warn(e); + usageExit(ERR_INVOKE_MAIN); + return; } - if (Config.isDebug() || invoked_class == null) - { - if (invoked_class == null) - { - System.err.println("ClassNotFound: " + classname); - } - else - { - System.err.println(classname + " " + invoked_class.getPackage().getImplementationVersion()); - } + StartLog.debug("%s - %s",invoked_class,invoked_class.getPackage().getImplementationVersion()); - if (invoked_class == null) - { - usageExit(ERR_INVOKE_MAIN); - return; - } - } - - String argArray[] = args.toArray(new String[0]); + CommandLineBuilder cmd = args.getMainArgs(baseHome); + String argArray[] = cmd.getArgs().toArray(new String[0]); Class[] method_param_types = new Class[] { argArray.getClass() }; @@ -659,74 +259,71 @@ public class Main main.invoke(null,method_params); } - public void start(List xmls) throws IOException, InterruptedException + public void start(StartArgs args) throws IOException, InterruptedException { - // Load potential Config (start.config) - List configuredXmls = loadConfig(xmls); - - // No XML defined in start.config or command line. Can't execute. - if (configuredXmls.isEmpty()) - { - throw new FileNotFoundException("No XML configuration files specified in start.config or command line."); - } - - // Normalize the XML config options passed on the command line. - configuredXmls = resolveXmlConfigs(configuredXmls); - // Get Desired Classpath based on user provided Active Options. - Classpath classpath = _config.getActiveClasspath(); + Classpath classpath = args.getClasspath(); System.setProperty("java.class.path",classpath.toString()); ClassLoader cl = classpath.getClassLoader(); - if (Config.isDebug()) - { - System.err.println("java.class.path=" + System.getProperty("java.class.path")); - System.err.println("jetty.home=" + System.getProperty("jetty.home")); - System.err.println("jetty.base=" + System.getProperty("jetty.base")); - System.err.println("java.home=" + System.getProperty("java.home")); - System.err.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir")); - System.err.println("java.class.path=" + classpath); - System.err.println("classloader=" + cl); - System.err.println("classloader.parent=" + cl.getParent()); - System.err.println("properties=" + Config.getProperties()); - } - for (String m : _enable) - enable(m,true); - for (String m : _disable) - disable(m,true); + StartLog.debug("java.class.path=" + System.getProperty("java.class.path")); + StartLog.debug("jetty.home=" + System.getProperty("jetty.home")); + StartLog.debug("jetty.base=" + System.getProperty("jetty.base")); + StartLog.debug("java.home=" + System.getProperty("java.home")); + StartLog.debug("java.io.tmpdir=" + System.getProperty("java.io.tmpdir")); + StartLog.debug("java.class.path=" + classpath); + StartLog.debug("classloader=" + cl); + StartLog.debug("classloader.parent=" + cl.getParent()); + StartLog.debug("properties=" + args.getProperties()); // Show the usage information and return - if (_showUsage) + if (args.isHelp()) + { usage(); + } // Show the version information and return - if (_dumpVersions) + if (args.isVersion()) + { showClasspathWithVersions(classpath); + } - // Show all options with version information - if (_listOptions) - showAllOptionsWithVersions(); - - if (_listConfig) + // Show configuration + if (args.isListConfig()) + { listConfig(); + } + + // Show modules + if (args.isListModules()) + { + listModules(); + } // Show Command Line to execute Jetty - if (_dryRun) + if (args.isDryRun()) { - CommandLineBuilder cmd = buildCommandLine(classpath,configuredXmls); + CommandLineBuilder cmd = args.getMainArgs(baseHome); System.out.println(cmd.toString()); } + // Various Downloads + for (String url : args.getDownloads()) + { + download(url); + } + // Informational command line, don't run jetty - if (_noRun) + if (!args.isRun()) + { return; + } // execute Jetty in another JVM - if (_exec) + if (args.isExec()) { - CommandLineBuilder cmd = buildCommandLine(classpath,configuredXmls); - + CommandLineBuilder cmd = args.getMainArgs(baseHome); ProcessBuilder pbuilder = new ProcessBuilder(cmd.getArgs()); final Process process = pbuilder.start(); Runtime.getRuntime().addShutdownHook(new Thread() @@ -734,7 +331,7 @@ public class Main @Override public void run() { - Config.debug("Destroying " + process); + StartLog.debug("Destroying " + process); process.destroy(); } }); @@ -747,7 +344,7 @@ public class Main return; } - if (_jvmArgs.size() > 0 || _sysProps.size() > 0) + if (args.hasJvmArgs() || args.hasSystemProperties()) { System.err.println("WARNING: System properties and/or JVM args set. Consider using --dry-run or --exec"); } @@ -758,26 +355,7 @@ public class Main // Invoke the Main Class try { - // Get main class as defined in start.config - String classname = _config.getMainClassname(); - - // Check for override of start class (via "jetty.server" property) - String mainClass = System.getProperty("jetty.server"); - if (mainClass != null) - { - classname = mainClass; - } - - // Check for override of start class (via "main.class" property) - mainClass = System.getProperty("main.class"); - if (mainClass != null) - { - classname = mainClass; - } - - Config.debug("main.class=" + classname); - - invokeMain(cl,classname,configuredXmls); + invokeMain(args); } catch (Exception e) { @@ -785,6 +363,11 @@ public class Main } } + private void listModules() + { + // TODO Auto-generated method stub + } + private void copyInThread(final InputStream in, final OutputStream out) { new Thread(new Runnable() @@ -810,202 +393,9 @@ public class Main }).start(); } - private String resolveXmlConfig(String xmlFilename) throws FileNotFoundException - { - if (!FS.isXml(xmlFilename)) - { - // Nothing to resolve. - return xmlFilename; - } - - // Try normal locations - File xml = _config.getBaseHome().getFile(xmlFilename); - if (FS.isFile(xml)) - { - return xml.getAbsolutePath(); - } - - // Try again, but prefixed with "etc/" - xml = _config.getBaseHome().getFile("etc/" + xmlFilename); - if (FS.isFile(xml)) - { - return xml.getAbsolutePath(); - } - - throw new FileNotFoundException("Unable to find XML Config: " + xmlFilename); - } - - CommandLineBuilder buildCommandLine(Classpath classpath, List xmls) throws IOException - { - CommandLineBuilder cmd = new CommandLineBuilder(findJavaBin()); - - for (String x : _jvmArgs) - { - cmd.addArg(x); - } - cmd.addRawArg("-Djetty.home=" + _config.getBaseHome().getHome()); - cmd.addRawArg("-Djetty.base=" + _config.getBaseHome().getBase()); - - // Special Stop/Shutdown properties - ensureSystemPropertySet("STOP.PORT"); - ensureSystemPropertySet("STOP.KEY"); - - // System Properties - for (String p : _sysProps) - { - String v = System.getProperty(p); - cmd.addEqualsArg("-D" + p,v); - } - - cmd.addArg("-cp"); - cmd.addRawArg(classpath.toString()); - cmd.addRawArg(_config.getMainClassname()); - - // Check if we need to pass properties as a file - Properties properties = Config.getProperties(); - if (properties.size() > 0) - { - File prop_file = File.createTempFile("start",".properties"); - if (!_dryRun) - prop_file.deleteOnExit(); - properties.store(new FileOutputStream(prop_file),"start.jar properties"); - cmd.addArg(prop_file.getAbsolutePath()); - } - - for (String xml : xmls) - { - cmd.addRawArg(xml); - } - return cmd; - } - - /** - * Ensure that the System Properties are set (if defined as a System property, or start.config property, or start.ini property) - * - * @param key - * the key to be sure of - */ - private void ensureSystemPropertySet(String key) - { - if (_sysProps.contains(key)) - { - return; // done - } - - Properties props = Config.getProperties(); - if (props.containsKey(key)) - { - String val = props.getProperty(key,null); - if (val == null) - { - return; // no value to set - } - // setup system property - _sysProps.add(key); - System.setProperty(key,val); - } - } - - private String findJavaBin() - { - 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 = path.replace('/',File.separatorChar); - File exe = new File(root,npath); - if (!exe.exists()) - { - return null; - } - return exe; - } - private void showAllOptionsWithVersions() { - Set sectionIds = _config.getSectionIds(); - - StringBuffer msg = new StringBuffer(); - msg.append("There "); - if (sectionIds.size() > 1) - { - msg.append("are "); - } - else - { - msg.append("is "); - } - msg.append(String.valueOf(sectionIds.size())); - msg.append(" OPTION"); - if (sectionIds.size() > 1) - { - msg.append("s"); - } - msg.append(" available to use."); - System.out.println(msg); - System.out.println("Each option is listed along with associated available classpath entries, in the order that they would appear from that mode."); - System.out.println("Note: If using multiple options (eg: 'Server,servlet,webapp,jms,jmx') " - + "then overlapping entries will not be repeated in the eventual classpath."); - System.out.println(); - System.out.printf("${jetty.home} = %s%n",_config.getBaseHome().getHome()); - System.out.printf("${jetty.base} = %s%n",_config.getBaseHome().getBase()); - System.out.println(); - - for (String sectionId : sectionIds) - { - if (Config.DEFAULT_SECTION.equals(sectionId)) - { - System.out.println("GLOBAL option (Prepended Entries)"); - } - else if ("*".equals(sectionId)) - { - System.out.println("GLOBAL option (Appended Entries) (*)"); - } - else - { - System.out.printf("Option [%s]",sectionId); - if (Character.isUpperCase(sectionId.charAt(0))) - { - System.out.print(" (Aggregate)"); - } - System.out.println(); - } - System.out.println("-------------------------------------------------------------"); - - Classpath sectionCP = _config.getSectionClasspath(sectionId); - - if (sectionCP.isEmpty()) - { - System.out.println("Empty option, no classpath entries active."); - System.out.println(); - continue; - } - - int i = 0; - for (File element : sectionCP.getElements()) - System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),path(element)); - - System.out.println(); - } + // TODO } private void showClasspathWithVersions(Classpath classpath) @@ -1013,7 +403,8 @@ public class Main // Iterate through active classpath, and fetch Implementation Version from each entry (if present) // to dump to end user. - System.out.println("Active Options: " + _config.getOptions()); + // TODO: modules instead + // System.out.println("Active Options: " + _config.getOptions()); if (classpath.count() == 0) { @@ -1027,7 +418,9 @@ public class Main int i = 0; for (File element : classpath.getElements()) - System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),path(element)); + { + System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),baseHome.toShortForm(element)); + } } private String getVersion(File element) @@ -1049,112 +442,9 @@ public class Main return ""; } - private List resolveXmlConfigs(List xmls) throws FileNotFoundException - { - List ret = new ArrayList(); - for (String xml : xmls) - { - ret.add(resolveXmlConfig(xml)); - } - - return ret; - } - private void listConfig() { - InputStream cfgstream = null; - try - { - cfgstream = getConfigStream(); - byte[] buf = new byte[4096]; - - int len = 0; - - while (len >= 0) - { - len = cfgstream.read(buf); - if (len > 0) - System.out.write(buf,0,len); - } - } - catch (Exception e) - { - usageExit(e,ERR_UNKNOWN); - } - finally - { - FS.close(cfgstream); - } - } - - /** - * Load Configuration. - * - * No specific configuration is real until a {@link Config#getCombinedClasspath(java.util.Collection)} is used to execute the {@link Class} specified by - * {@link Config#getMainClassname()} is executed. - * - * @param xmls - * the command line specified xml configuration options. - * @return the list of xml configurations arriving via command line and start.config choices. - */ - private List loadConfig(List xmls) - { - InputStream cfgstream = null; - try - { - // Pass in xmls.size into Config so that conditions based on "nargs" work. - _config.setArgCount(xmls.size()); - - cfgstream = getConfigStream(); - - // parse the config - _config.parse(cfgstream); - - // Collect the configured xml configurations. - List ret = new ArrayList(); - ret.addAll(xmls); // add command line provided xmls first. - for (String xmlconfig : _config.getXmlConfigs()) - { - // add xmlconfigs arriving via start.config - if (!ret.contains(xmlconfig)) - { - ret.add(xmlconfig); - } - } - - return ret; - } - catch (Exception e) - { - usageExit(e,ERR_UNKNOWN); - return null; // never executed (just here to satisfy javac compiler) - } - finally - { - FS.close(cfgstream); - } - } - - private InputStream getConfigStream() throws FileNotFoundException - { - String config = _startConfig; - if (config == null || config.length() == 0) - { - config = System.getProperty("START","org/eclipse/jetty/start/start.config"); - } - - Config.debug("config=" + config); - - // Look up config as resource first. - InputStream cfgstream = getClass().getClassLoader().getResourceAsStream(config); - - // resource not found, try filesystem next - if (cfgstream == null) - { - cfgstream = new FileInputStream(config); - } - - return cfgstream; + // TODO } /** @@ -1183,32 +473,32 @@ public class Main System.err.println("Using empty key"); } - Socket s = new Socket(InetAddress.getByName("127.0.0.1"),_port); - if (timeout > 0) - s.setSoTimeout(timeout * 1000); - try + try (Socket s = new Socket(InetAddress.getByName("127.0.0.1"),_port)) { - OutputStream out = s.getOutputStream(); - out.write((_key + "\r\nstop\r\n").getBytes()); - out.flush(); - if (timeout > 0) { - System.err.printf("Waiting %,d seconds for jetty to stop%n",timeout); - LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream())); - String response; - while ((response = lin.readLine()) != null) + s.setSoTimeout(timeout * 1000); + } + + try (OutputStream out = s.getOutputStream()) + { + out.write((_key + "\r\nstop\r\n").getBytes()); + out.flush(); + + if (timeout > 0) { - Config.debug("Received \"" + response + "\""); - if ("Stopped".equals(response)) - System.err.println("Server reports itself as Stopped"); + System.err.printf("Waiting %,d seconds for jetty to stop%n",timeout); + LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream())); + String response; + while ((response = lin.readLine()) != null) + { + StartLog.debug("Received \"%s\"",response); + if ("Stopped".equals(response)) + StartLog.warn("Server reports itself as Stopped"); + } } } } - finally - { - s.close(); - } } catch (SocketTimeoutException e) { @@ -1241,176 +531,4 @@ public class Main { usageExit(null,exit); } - - void addJvmArgs(List jvmArgs) - { - _jvmArgs.addAll(jvmArgs); - } - - private void enable(final String module, boolean verbose) throws IOException - { - final String mini = module + ".ini"; - final String disable = module + ".ini.disabled"; - - BaseHome hb = _config.getBaseHome(); - File start_d = hb.getFile("start.d"); - boolean found = false; - File enabled = null; - if (start_d.exists() && start_d.isDirectory()) - { - for (File file : start_d.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?" + Pattern.quote(module) + "\\.ini(\\.disabled)?"))) - { - String n = file.getName(); - if (n.equalsIgnoreCase(mini)) - { - if (verbose) - System.err.printf("Module %s already enabled in %s%n",module,hb.toShortForm(file.getParent())); - found = true; - break; - } - - if (n.equalsIgnoreCase(disable)) - { - enabled = new File(file.getParentFile(),mini); - System.err.printf("Enabling Module %s as %s%n",module,hb.toShortForm(enabled)); - file.renameTo(enabled); - found = true; - break; - } - - Matcher matcher = NNN_MODULE_INI.matcher(n); - if (matcher.matches()) - { - if (matcher.group(3) == null) - { - if (verbose) - System.err.printf("Module %s already enabled in %s as %s%n",module,hb.toShortForm(file.getParent()),n); - found = true; - } - else - { - enabled = new File(file.getParentFile(),matcher.group(1) + mini); - System.err.printf("Enabling Module %s as %s%n",module,hb.toShortForm(enabled)); - file.renameTo(enabled); - found = true; - } - } - } - } - - // Shall we look for a template in home? - if (!found && hb.isBaseDifferent()) - { - File start_home = new File(hb.getHomeDir(),"start.d"); - - if (start_home.exists() && start_home.isDirectory()) - { - for (File file : start_home.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?" + Pattern.quote(module) + "\\.ini(\\.disabled)?"))) - { - try - { - String n = file.getName(); - if (n.equalsIgnoreCase(mini) || n.equalsIgnoreCase(disable)) - { - enabled = new File(start_d,mini); - Files.copy(file.toPath(),enabled.toPath()); - System.err.printf("Enabling Module %s as %s%n",module,hb.toShortForm(enabled)); - found = true; - break; - } - - Matcher matcher = NNN_MODULE_INI.matcher(n); - if (matcher.matches()) - { - enabled = new File(start_d,matcher.group(1) + mini); - Files.copy(file.toPath(),enabled.toPath()); - System.err.printf("Enabling Module %s as %s%n",module,hb.toShortForm(enabled)); - found = true; - break; - } - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - } - - if (!found) - { - System.err.printf("Module %s not found!%n",module); - } - else if (enabled != null) - { - // handle dependencies - StartIni ini = new StartIni(enabled); - for (String line : ini.getLineMatches(Pattern.compile("^DEPEND=.*$"))) - { - String depend = line.trim().split("=")[1]; - for (String m : depend.split(",")) - enable(m,false); - } - for (String line : ini.getLineMatches(Pattern.compile("^EXCLUDE=.*$"))) - { - String depend = line.trim().split("=")[1]; - for (String m : depend.split(",")) - disable(m,false); - } - } - } - - private void disable(final String module, boolean verbose) - { - final String mini = module + ".ini"; - final String disable = module + ".ini.disabled"; - - BaseHome hb = _config.getBaseHome(); - File start_d = hb.getFile("start.d"); - boolean found = false; - if (start_d.exists() && start_d.isDirectory()) - { - for (File file : start_d.listFiles(new FS.FilenameRegexFilter("(\\d\\d\\d-)?" + Pattern.quote(module) + "\\.ini(\\.disabled)?"))) - { - String n = file.getName(); - if (n.equalsIgnoreCase(disable)) - { - if (verbose) - System.err.printf("Module %s already disabled in %s%n",module,hb.toShortForm(file.getParent())); - found = true; - } - else if (n.equalsIgnoreCase(mini)) - { - System.err.printf("Disabling Module %s in %s%n",module,hb.toShortForm(file.getParent())); - file.renameTo(new File(file.getParentFile(),disable)); - found = true; - } - else - { - Matcher matcher = NNN_MODULE_INI.matcher(n); - if (matcher.matches()) - { - if (matcher.group(3) != null) - { - if (verbose) - System.err.printf("Module %s already disabled in %s as %s%n",module,hb.toShortForm(file.getParent()),n); - found = true; - } - else - { - String disabled = matcher.group(1) + disable; - System.err.printf("Disabling Module %s in %s as %s%n",module,hb.toShortForm(file.getParent()),disabled); - file.renameTo(new File(file.getParentFile(),disabled)); - found = true; - } - } - } - } - } - - if (!found && verbose) - { - System.err.printf("Module %s not found!%n",module); - } - } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java index 776bce8e91e..ec492ca53fc 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java @@ -18,9 +18,8 @@ package org.eclipse.jetty.start; -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; +import java.io.FileNotFoundException; import java.io.IOException; import java.text.CollationKey; import java.text.Collator; @@ -35,7 +34,7 @@ import java.util.regex.Pattern; /** * Represents a Module metadata, as defined in Jetty. */ -public class Module +public class Module extends TextFile { public static class DepthComparator implements Comparator { @@ -57,104 +56,90 @@ public class Module } } - public static Module fromFile(File file) throws IOException - { - String name = file.getName(); - - // Strip .ini - name = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(name).replaceFirst(""); - - // XML Pattern - Pattern xmlPattern = Pattern.compile(".xml$",Pattern.CASE_INSENSITIVE); - - Set parents = new HashSet<>(); - List xmls = new ArrayList<>(); - List libs = new ArrayList<>(); - try (FileReader reader = new FileReader(file)) - { - try (BufferedReader buf = new BufferedReader(reader)) - { - String line; - while ((line = buf.readLine()) != null) - { - line = line.trim(); - if (line.length() <= 0) - { - continue; // skip empty lines - } - if (line.charAt(0) == '#') - { - continue; // skip lines with comments - } - - // has assignment - int idx = line.indexOf('='); - if (idx >= 0) - { - String key = line.substring(0,idx); - String value = line.substring(idx + 1); - - boolean handled = false; - switch (key.toUpperCase(Locale.ENGLISH)) - { - case "DEPEND": - parents.add(value); - handled = true; - break; - case "LIB": - libs.add(value); - handled = true; - break; - } - if (handled) - { - continue; // no further processing of line needed - } - } - - // Is it an XML line? - if (xmlPattern.matcher(line).find()) - { - xmls.add(line); - continue; // legit xml - } - - throw new IllegalArgumentException("Unrecognized Module Metadata line [" + line + "] in Module file [" + file + "]"); - } - } - } - - return new Module(name,parents,xmls,libs); - } - /** The name of this Module */ - private final String name; + private String name; /** List of Modules, by name, that this Module depends on */ - private final Set parentNames; + private Set parentNames; /** The Edges to parent modules */ - private final Set parentEdges; + private Set parentEdges; /** The Edges to child modules */ - private final Set childEdges; + private Set childEdges; /** The depth of the module in the tree */ private int depth = 0; /** List of xml configurations for this Module */ - private final List xmls; + private List xmls; /** List of library options for this Module */ - private final List libs; + private List libs; /** Is this Module enabled via start.jar command line, start.ini, or start.d/*.ini ? */ private boolean enabled = false; - public Module(String name, Set parentNames, List xmls, List libs) + public Module(File file) throws FileNotFoundException, IOException { - this.name = name; - this.parentNames = parentNames; - this.xmls = xmls; - this.libs = libs; + super(file); - // initialize edge collections, will be filled out by Modules#buildGraph() later */ + String name = file.getName(); + // Strip .ini + name = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(name).replaceFirst(""); + } + + @Override + public void init() + { + String name = getFile().getName(); + + // Strip .ini + this.name = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(name).replaceFirst(""); + + this.parentNames = new HashSet<>(); this.parentEdges = new HashSet<>(); this.childEdges = new HashSet<>(); + this.xmls = new ArrayList<>(); + this.libs = new ArrayList<>(); + } + + @Override + public void process(String line) + { + boolean handled = false; + + if(line == null) { + + } + + // has assignment + int idx = line.indexOf('='); + if (idx >= 0) + { + String key = line.substring(0,idx); + String value = line.substring(idx + 1); + + switch (key.toUpperCase(Locale.ENGLISH)) + { + case "DEPEND": + parentNames.add(value); + handled = true; + break; + case "LIB": + libs.add(value); + handled = true; + break; + } + } + + if (handled) + { + return; // no further processing of line needed + } + + // Is it an XML line? + if (FS.isXml(line)) + { + xmls.add(line); + return; + } + + throw new IllegalArgumentException("Unrecognized Module Metadata line [" + line + "] in Module file [" + getFile() + "]"); } public void addChildEdge(Module child) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java index 3d57279d1df..5e23ce03759 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java @@ -229,7 +229,7 @@ public class Modules implements Iterable { for (File file : basehome.listFiles("modules",new FS.FilenameRegexFilter("^.*\\.mod$"))) { - register(Module.fromFile(file)); + register(new Module(file)); } } } 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 73d88f5191b..1d707ddbeb6 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 @@ -19,28 +19,60 @@ package org.eclipse.jetty.start; import static org.eclipse.jetty.start.UsageException.*; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Properties; +import java.util.Set; /** * The Arguments required to start Jetty. */ public class StartArgs { + public static final String VERSION; + + static + { + String ver = System.getProperty("jetty.version",null); + + if (ver == null) + { + Package pkg = StartArgs.class.getPackage(); + if ((pkg != null) && "Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) && (pkg.getImplementationVersion() != null)) + { + ver = pkg.getImplementationVersion(); + } + } + + if (ver == null) + { + ver = "TEST"; + } + + VERSION = ver; + } + // TODO: might make sense to declare this in modules/base.mod private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration.class"; private List commandLine = new ArrayList<>(); private List enabledModules = new ArrayList<>(); private List downloads = new ArrayList<>(); - private List classpath = new ArrayList<>(); - private List xmls = new ArrayList<>(); - private Map properties = new HashMap<>(); - private Map systemProperties = new HashMap<>(); - private Map jvmArgs = new HashMap<>(); + private Classpath classpath; + private List xmlRefs = new ArrayList<>(); + private List xmls = new ArrayList<>(); + private Properties properties = new Properties(); + private Set systemPropertyKeys = new HashSet<>(); + private List jvmArgs = new ArrayList<>(); // Should the server be run? private boolean run = true; @@ -56,11 +88,84 @@ public class StartArgs public StartArgs(String[] commandLineArgs) { commandLine.addAll(Arrays.asList(commandLineArgs)); + classpath = new Classpath(); + classpath.addSystemClasspath(); } - public List getStartCommands() + public void buildStartCommandLine() { - return null; + // TODO Auto-generated method stub + } + + /** + * Build up the Classpath and XML file references based on enabled Module list. + * + * @param baseHome + * @param activeModules + */ + public void expandModules(BaseHome baseHome, List activeModules) + { + for (Module module : activeModules) + { + // Find and Expand Libraries + for (String rawlibref : module.getLibs()) + { + String libref = rawlibref.replace("${jetty.version}",VERSION); + libref = FS.separators(libref); + + if (libref.contains("*")) + { + // Glob Reference + int idx = libref.lastIndexOf(File.separatorChar); + + String relativePath = "/"; + String filenameRef = libref; + if (idx >= 0) + { + relativePath = libref.substring(0,idx); + filenameRef = libref.substring(idx + 1); + } + + StringBuilder regex = new StringBuilder(); + regex.append('^'); + for (char c : filenameRef.toCharArray()) + { + switch (c) + { + case '*': + regex.append(".*"); + break; + case '.': + regex.append("\\."); + break; + default: + regex.append(c); + } + } + regex.append('$'); + + FileFilter filter = new FS.FilenameRegexFilter(regex.toString()); + + for (File libfile : baseHome.listFiles(relativePath,filter)) + { + classpath.addComponent(libfile); + } + } + else + { + // Straight Reference + File libfile = baseHome.getFile(libref); + classpath.addComponent(libfile); + } + } + + // Find and Expand XML files + } + } + + public Classpath getClasspath() + { + return classpath; } public List getCommandLine() @@ -68,12 +173,171 @@ public class StartArgs return this.commandLine; } - public void parse(TextFile file) + public List getEnabledModules() { - for (String line : file) + return this.enabledModules; + } + + public List getDownloads() + { + return downloads; + } + + /** + * Ensure that the System Properties are set (if defined as a System property, or start.config property, or start.ini property) + * + * @param key + * the key to be sure of + */ + private void ensureSystemPropertySet(String key) + { + if (systemPropertyKeys.contains(key)) { - parse(line); + return; // done } + + if (properties.containsKey(key)) + { + String val = properties.getProperty(key,null); + if (val == null) + { + return; // no value to set + } + // setup system property + systemPropertyKeys.add(key); + System.setProperty(key,val); + } + } + + public Properties getProperties() + { + return properties; + } + + public CommandLineBuilder getMainArgs(BaseHome baseHome) throws IOException + { + CommandLineBuilder cmd = new CommandLineBuilder(); + + for (String x : jvmArgs) + { + cmd.addArg(x); + } + + cmd.addRawArg("-Djetty.home=" + baseHome.getHome()); + cmd.addRawArg("-Djetty.base=" + baseHome.getBase()); + + // Special Stop/Shutdown properties + ensureSystemPropertySet("STOP.PORT"); + ensureSystemPropertySet("STOP.KEY"); + + // System Properties + for (String propKey : systemPropertyKeys) + { + String value = System.getProperty(propKey); + cmd.addEqualsArg("-D" + propKey,value); + } + + cmd.addArg("-cp"); + cmd.addRawArg(classpath.toString()); + cmd.addRawArg(getMainClassname()); + + // Check if we need to pass properties as a file + if (properties.size() > 0) + { + File prop_file = File.createTempFile("start",".properties"); + if (!dryRun) + { + prop_file.deleteOnExit(); + } + try (FileOutputStream out = new FileOutputStream(prop_file)) + { + properties.store(out,"start.jar properties"); + } + cmd.addArg(prop_file.getAbsolutePath()); + } + + for (File xml : xmls) + { + cmd.addRawArg(xml.getAbsolutePath()); + } + + return cmd; + } + + public String getMainClassname() + { + String mainclass = System.getProperty("jetty.server",SERVER_MAIN); + return System.getProperty("main.class",mainclass); + } + + private String getValue(String arg) + { + int idx = arg.indexOf('='); + if (idx == (-1)) + { + throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg); + } + String value = arg.substring(idx + 1).trim(); + if (value.length() <= 0) + { + throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg); + } + return value; + } + + public boolean hasJvmArgs() + { + return jvmArgs.size() > 0; + } + + public boolean hasSystemProperties() + { + return systemPropertyKeys.size() > 0; + } + + public boolean isDryRun() + { + return dryRun; + } + + public boolean isExec() + { + return exec; + } + + public boolean isHelp() + { + return help; + } + + public boolean isListClasspath() + { + return listClasspath; + } + + public boolean isListConfig() + { + return listConfig; + } + + public boolean isListModules() + { + return listModules; + } + + public boolean isRun() + { + return run; + } + + public boolean isStopCommand() + { + return stopCommand; + } + + public boolean isVersion() + { + return version; } public void parse(String arg) @@ -89,10 +353,12 @@ public class StartArgs { stopCommand = true; run = false; - /* - * int port = Integer.parseInt(_config.getProperty("STOP.PORT","-1")); String key = _config.getProperty("STOP.KEY",null); int timeout = - * Integer.parseInt(_config.getProperty("STOP.WAIT","0")); stop(port,key,timeout); - */ + // + // int port = Integer.parseInt(_config.getProperty("STOP.PORT","-1")); + // String key = _config.getProperty("STOP.KEY",null); + // int timeout = Integer.parseInt(_config.getProperty("STOP.WAIT","0")); + // stop(port,key,timeout); + // return; } @@ -123,6 +389,12 @@ public class StartArgs return; } + if ("--exec".equals(arg)) + { + exec = true; + return; + } + if (arg.startsWith("--enable=")) { String moduleName = getValue(arg); @@ -157,12 +429,12 @@ public class StartArgs } return; } - + // Start property (syntax similar to System property) - if(arg.startsWith("-D")) + if (arg.startsWith("-D")) { String[] assign = arg.substring(2).split("=",2); -// TODO systemProperties.add(assign[0]); + systemPropertyKeys.add(assign[0]); switch (assign.length) { case 2: @@ -176,21 +448,49 @@ public class StartArgs } return; } + + // Anything else with a "-" is considered a JVM argument + if (arg.startsWith("-")) + { + // Only add non-duplicates + if (!jvmArgs.contains(arg)) + { + jvmArgs.add(arg); + } + return; + } + + // Is this a raw property declaration? + int idx = arg.indexOf('='); + if (idx >= 0) + { + String key = arg.substring(0,idx); + String value = arg.substring(idx + 1); + properties.setProperty(key,value); + return; + } + + // Is this an xml file? + if (FS.isXml(arg)) + { + // only add non-duplicates + if (!xmlRefs.contains(arg)) + { + xmlRefs.add(arg); + } + return; + } + + // Anything else is unrecognized + throw new UsageException(ERR_BAD_ARG,"Unrecognized argument: %s",arg); } - private String getValue(String arg) + public void parse(TextFile file) { - int idx = arg.indexOf('='); - if (idx == (-1)) + for (String line : file) { - throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg); + parse(line); } - String value = arg.substring(idx + 1).trim(); - if (value.length() <= 0) - { - throw new UsageException(ERR_BAD_ARG,"Argument is missing a required value: %s",arg); - } - return value; } public void parseCommandLine() @@ -200,14 +500,4 @@ public class StartArgs parse(line); } } - - public List getEnabledModules() - { - return this.enabledModules; - } - - public void expandModules(BaseHome baseHome, List activeModules) - { - // TODO Auto-generated method stub - } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java index 62696232aba..ee8d0bab5ea 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java @@ -23,7 +23,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Date; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -38,13 +37,72 @@ public class StartLog { private final static StartLog INSTANCE = new StartLog(); + public static void debug(String format, Object... args) + { + if (INSTANCE.debug) + { + System.out.printf(format + "%n",args); + } + } + + public static void debug(Throwable t) + { + if (INSTANCE.debug) + { + t.printStackTrace(System.out); + } + } + public static StartLog getInstance() { return INSTANCE; } + public static void warn(String format, Object... args) + { + System.err.printf(format + "%n",args); + } + private boolean debug = false; + public void initialize(BaseHome baseHome, StartArgs args) throws IOException + { + // Debug with boolean + Pattern debugBoolPat = Pattern.compile("(-D)?debug=(.*)"); + // Debug enable flag (no boolean) + Pattern debugPat = Pattern.compile("(-D)?debug"); + // Log file name + Pattern logFilePat = Pattern.compile("(-D)?start-log-file=(.*)"); + + // TODO: support backward compatible --daemon argument ?? + + Matcher matcher; + for (String arg : args.getCommandLine()) + { + matcher = debugBoolPat.matcher(arg); + if (matcher.matches()) + { + debug = Boolean.parseBoolean(matcher.group(2)); + continue; + } + + matcher = debugPat.matcher(arg); + if (matcher.matches()) + { + debug = true; + continue; + } + + matcher = logFilePat.matcher(arg); + if (matcher.matches()) + { + String filename = matcher.group(2); + File logfile = baseHome.getBaseFile(filename); + initLogFile(logfile); + } + } + } + public void initLogFile(File logfile) throws IOException { if (logfile != null) @@ -77,49 +135,8 @@ public class StartLog } } - public static void debug(String format, Object... args) + public static void warn(Throwable t) { - if (INSTANCE.debug) - { - System.out.printf(format + "%n",args); - } - } - - public static void warn(String format, Object... args) - { - System.err.printf(format + "%n",args); - } - - public void initialize(BaseHome baseHome, StartArgs args) throws IOException - { - Pattern debugBoolPat = Pattern.compile("(-D)?debug=(.*)"); - Pattern debugPat = Pattern.compile("(-D)?debug"); - Pattern logFilePat = Pattern.compile("(-D)?start-log-file=(.*)"); - - Matcher matcher; - for (String arg : args.getCommandLine()) - { - matcher = debugBoolPat.matcher(arg); - if (matcher.matches()) - { - debug = Boolean.parseBoolean(matcher.group(2)); - continue; - } - - matcher = debugPat.matcher(arg); - if (matcher.matches()) - { - debug = true; - continue; - } - - matcher = logFilePat.matcher(arg); - if (matcher.matches()) - { - String filename = matcher.group(2); - File logfile = baseHome.getBaseFile(filename); - initLogFile(logfile); - } - } + t.printStackTrace(System.err); } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java index 45ae50bbec5..fc7909b05e9 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java @@ -41,6 +41,8 @@ public class TextFile implements Iterable public TextFile(File file) throws FileNotFoundException, IOException { this.file = file; + init(); + try (FileReader reader = new FileReader(file)) { try (BufferedReader buf = new BufferedReader(reader)) @@ -48,12 +50,26 @@ public class TextFile implements Iterable String line; while ((line = buf.readLine()) != null) { + if (line.length() == 0) + { + continue; + } + + if (line.charAt(0) == '#') + { + continue; + } + process(line.trim()); } } } } + public void init() + { + } + public void addUniqueLine(String line) { if (lines.contains(line)) @@ -93,18 +109,8 @@ public class TextFile implements Iterable return lines.iterator(); } - private void process(String line) + public void process(String line) { - if (line.length() == 0) - { - return; - } - - if (line.charAt(0) == '#') - { - return; - } - addUniqueLine(line); } } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigTest.java deleted file mode 100644 index 6432e148e13..00000000000 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigTest.java +++ /dev/null @@ -1,648 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.start; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class ConfigTest -{ - private void assertEquals(String msg, Classpath expected, Classpath actual) - { - Assert.assertNotNull(msg + " : expected classpath should not be null",expected); - Assert.assertNotNull(msg + " : actual classpath should not be null",actual); - Assert.assertTrue(msg + " : expected should have an entry",expected.count() >= 1); - Assert.assertTrue(msg + " : actual should have an entry",actual.count() >= 1); - if (expected.count() != actual.count()) - { - expected.dump(System.err); - actual.dump(System.err); - Assert.assertEquals(msg + " : count",expected.count(),actual.count()); - } - - List actualEntries = Arrays.asList(actual.getElements()); - List expectedEntries = Arrays.asList(expected.getElements()); - - int len = expectedEntries.size(); - - for (int i = 0; i < len; i++) - { - File expectedFile = expectedEntries.get(i); - File actualFile = actualEntries.get(i); - if (!expectedFile.equals(actualFile)) - { - expected.dump(System.err); - actual.dump(System.err); - Assert.assertEquals(msg + ": entry [" + i + "]",expectedEntries.get(i),actualEntries.get(i)); - } - } - } - - private void assertEquals(String msg, Collection expected, Collection actual) - { - Assert.assertTrue(msg + " : expected should have an entry",expected.size() >= 1); - Assert.assertEquals(msg + " : size",expected.size(),actual.size()); - for (String expectedVal : expected) - { - Assert.assertTrue(msg + " : should contain <" + expectedVal + ">",actual.contains(expectedVal)); - } - } - - private String getJettyEtcFile(String name) - { - File etc = new File(getTestableJettyHome(),"etc"); - return new File(etc,name).getAbsolutePath(); - } - - private File getJettyHomeDir() - { - return new File(getTestResourcesDir(),"jetty.home"); - } - - private String getTestableJettyHome() - { - return getJettyHomeDir().getAbsolutePath(); - } - - private File getTestResourcesDir() - { - File src = new File(System.getProperty("user.dir"),"src"); - File test = new File(src,"test"); - return new File(test,"resources"); - } - - @Before - public void reset() - { - } - - /* - * Test for SUBJECT "/=" for assign canonical path - */ - @Test - public void testSubjectAssignCanonicalPath() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("test.resources.dir/=src/test/resources\n"); - - Config cfg = new Config(); - cfg.parse(buf); - - Assert.assertEquals(getTestResourcesDir().getCanonicalPath(),cfg.getProperty("test.resources.dir")); - } - - /* - * Test for SUBJECT "~=" for assigning Start Properties - */ - @Test - public void testSubjectAssignStartProperty() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("test.jetty.start.text~=foo\n"); - buf.append("test.jetty.start.quote~=Eatagramovabits\n"); - - Config options = new Config(); - options.parse(buf); - - Assert.assertEquals("foo",options.getProperty("test.jetty.start.text")); - Assert.assertEquals("Eatagramovabits",options.getProperty("test.jetty.start.quote")); - } - - /* - * Test for SUBJECT "=" for assigning System Properties - */ - @Test - public void testSubjectAssignSystemProperty() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("test.jetty.start.text=foo\n"); - buf.append("test.jetty.start.quote=Eatagramovabits\n"); - - Config options = new Config(); - options.parse(buf); - - Assert.assertEquals("foo",System.getProperty("test.jetty.start.text")); - Assert.assertEquals("Eatagramovabits",System.getProperty("test.jetty.start.quote")); - } - - /* - * Test for SUBJECT ending with "/**", all jar and zip components in dir (deep, recursive) - */ - @Test - public void testSubjectComponentDirDeep() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("$(jetty.home)/lib/**\n"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - Classpath actual = options.getClasspath(); - Classpath expected = new Classpath(); - - File lib = new File(getJettyHomeDir(),"lib"); - - expected.addComponent(new File(lib,"core.jar")); - expected.addComponent(new File(lib,"example.jar")); - expected.addComponent(new File(lib,"http.jar")); - expected.addComponent(new File(lib,"io.jar")); - expected.addComponent(new File(lib,"JSR.ZIP")); - expected.addComponent(new File(lib,"LOGGING.JAR")); - expected.addComponent(new File(lib,"server.jar")); - expected.addComponent(new File(lib,"spec.zip")); - expected.addComponent(new File(lib,"util.jar")); - expected.addComponent(new File(lib,"xml.jar")); - - File ext = new File(lib,"ext"); - expected.addComponent(new File(ext,"custom-impl.jar")); - File foo = new File(lib,"foo"); - File bar = new File(foo,"bar"); - expected.addComponent(new File(bar,"foobar.jar")); - - assertEquals("Components (Deep)",expected,actual); - } - - /* - * Test for SUBJECT ending with "/*", all jar and zip components in dir (shallow, no recursion) - */ - @Test - public void testSubjectComponentDirShallow() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("# Example of any shallow components in /lib/\n"); - buf.append("$(jetty.home)/lib/*\n"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - Classpath actual = options.getClasspath(); - Classpath expected = new Classpath(); - - File lib = new File(getJettyHomeDir(),"lib"); - - expected.addComponent(new File(lib,"core.jar")); - expected.addComponent(new File(lib,"example.jar")); - expected.addComponent(new File(lib,"http.jar")); - expected.addComponent(new File(lib,"io.jar")); - expected.addComponent(new File(lib,"JSR.ZIP")); - expected.addComponent(new File(lib,"LOGGING.JAR")); - expected.addComponent(new File(lib,"server.jar")); - expected.addComponent(new File(lib,"spec.zip")); - expected.addComponent(new File(lib,"util.jar")); - expected.addComponent(new File(lib,"xml.jar")); - - assertEquals("Components (Shallow)",expected,actual); - } - - /* - * Test for SUBJECT ending with ".class", a Main Class - */ - @Test - public void testSubjectMainClass() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("org.eclipse.jetty.xml.XmlConfiguration.class"); - - Config options = new Config(); - options.parse(buf); - - Assert.assertEquals("org.eclipse.jetty.xml.XmlConfiguration",options.getMainClassname()); - } - - /* - * Test for SUBJECT ending with ".class", a Main Class - */ - @Test - public void testSubjectMainClassConditionalPropertySet() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("org.eclipse.jetty.xml.XmlConfiguration.class\n"); - buf.append("${start.class}.class property start.class"); - - Config options = new Config(); - options.setProperty("start.class","net.company.server.Start"); - options.parse(buf); - - Assert.assertEquals("net.company.server.Start",options.getMainClassname()); - } - - /* - * Test for SUBJECT ending with ".class", a Main Class - */ - @Test - public void testSubjectMainClassConditionalPropertyUnset() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("org.eclipse.jetty.xml.XmlConfiguration.class\n"); - buf.append("${start.class}.class property start.class"); - - Config options = new Config(); - // The "start.class" property is unset. - options.parse(buf); - - Assert.assertEquals("org.eclipse.jetty.xml.XmlConfiguration",options.getMainClassname()); - } - - /* - * Test for SUBJECT ending with "/", a simple Classpath Entry - */ - @Test - public void testSubjectSimpleComponent() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("$(jetty.home)/resources/\n"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - Classpath actual = options.getClasspath(); - Classpath expected = new Classpath(); - - expected.addComponent(new File(getJettyHomeDir(),"resources")); - - assertEquals("Simple Component",expected,actual); - } - - /* - * Test for SUBJECT ending with "/", a simple Classpath Entry - */ - @Test - public void testSubjectSimpleComponentMultiple() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("$(jetty.home)/resources/\n"); - buf.append("$(jetty.home)/etc/\n"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - Classpath actual = options.getClasspath(); - Classpath expected = new Classpath(); - - expected.addComponent(new File(getJettyHomeDir(),"resources")); - expected.addComponent(new File(getJettyHomeDir(),"etc")); - - assertEquals("Simple Component",expected,actual); - } - - /* - * Test for SUBJECT ending with "/", a simple Classpath Entry - */ - @Test - public void testSubjectSimpleComponentNotExists() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("$(jetty.home)/resources/\n"); - buf.append("$(jetty.home)/foo/\n"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - Classpath actual = options.getClasspath(); - Classpath expected = new Classpath(); - - expected.addComponent(new File(getJettyHomeDir(),"resources")); - - assertEquals("Simple Component",expected,actual); - } - - /* - * Test for SUBJECT ending with ".xml", an XML Configuration File - */ - @Test - public void testSubjectXmlConfigAlt() throws IOException - { - StringBuffer buf = new StringBuffer(); - // Doesn't exist - buf.append("$(jetty.home)/etc/jetty.xml nargs == 0\n"); - // test-alt does exist. - buf.append("./src/test/resources/test-alt.xml nargs == 0 AND ! exists $(jetty.home)/etc/jetty.xml"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - List actual = options.getXmlConfigs(); - String expected = new File("src/test/resources/test-alt.xml").getAbsolutePath(); - Assert.assertEquals("XmlConfig.size",1,actual.size()); - Assert.assertEquals(expected,actual.get(0)); - } - - /* - * Test for SUBJECT ending with ".xml", an XML Configuration File - */ - @Test - public void testSubjectXmlConfigDefault() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("$(jetty.home)/etc/test-jetty.xml nargs == 0\n"); - buf.append("./jetty-server/src/main/config/etc/test-jetty.xml nargs == 0 AND ! exists $(jetty.home)/etc/test-jetty.xml"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - List actual = options.getXmlConfigs(); - String expected = getJettyEtcFile("test-jetty.xml"); - Assert.assertEquals("XmlConfig.size",1,actual.size()); - Assert.assertEquals(expected,actual.get(0)); - } - - /* - * Test for SUBJECT ending with ".xml", an XML Configuration File. - */ - @Test - public void testSubjectXmlConfigMultiple() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("$(jetty.home)/etc/test-jetty.xml nargs == 0\n"); - buf.append("$(jetty.home)/etc/test-jetty-ssl.xml nargs == 0\n"); - buf.append("$(jetty.home)/etc/test-jetty-security.xml nargs == 0\n"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - List actual = options.getXmlConfigs(); - List expected = new ArrayList(); - expected.add(getJettyEtcFile("test-jetty.xml")); - expected.add(getJettyEtcFile("test-jetty-ssl.xml")); - expected.add(getJettyEtcFile("test-jetty-security.xml")); - - assertEquals("Multiple XML Configs",expected,actual); - } - - /* - * Test Section Handling - */ - @Test - public void testSectionClasspathSingle() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("[All]\n"); - buf.append("$(jetty.home)/lib/core-test.jar\n"); - buf.append("$(jetty.home)/lib/util.jar\n"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - Classpath defaultClasspath = options.getClasspath(); - Assert.assertNotNull("Default Classpath should not be null",defaultClasspath); - Classpath foocp = options.getSectionClasspath("Foo"); - Assert.assertNull("Foo Classpath should not exist",foocp); - - Classpath allcp = options.getSectionClasspath("All"); - Assert.assertNotNull("Classpath section 'All' should exist",allcp); - - File lib = new File(getJettyHomeDir(),"lib"); - - Classpath expected = new Classpath(); - expected.addComponent(new File(lib,"core-test.jar")); - expected.addComponent(new File(lib,"util.jar")); - - assertEquals("Single Classpath Section",expected,allcp); - } - - /* - * Test Section Handling - */ - @Test - public void testSectionClasspathAvailable() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("[All]\n"); - buf.append("$(jetty.home)/lib/core.jar ! available org.eclipse.jetty.dummy.Handler\n"); - buf.append("$(jetty.home)/lib/util.jar ! available org.eclipse.jetty.dummy.StringUtils\n"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - Classpath defaultClasspath = options.getClasspath(); - Assert.assertNotNull("Default Classpath should not be null",defaultClasspath); - Classpath foocp = options.getSectionClasspath("Foo"); - Assert.assertNull("Foo Classpath should not exist",foocp); - - Classpath allcp = options.getSectionClasspath("All"); - Assert.assertNotNull("Classpath section 'All' should exist",allcp); - - File lib = new File(getJettyHomeDir(),"lib"); - - Classpath expected = new Classpath(); - expected.addComponent(new File(lib,"core.jar")); - expected.addComponent(new File(lib,"util.jar")); - - assertEquals("Single Classpath Section",expected,allcp); - } - - /* - * Test Section Handling, with multiple defined sections. - */ - @Test - public void testSectionClasspathMultiples() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("# default\n"); - buf.append("$(jetty.home)/lib/spec.zip\n"); - buf.append("\n"); - buf.append("[*]\n"); - buf.append("$(jetty.home)/lib/io.jar\n"); - buf.append("$(jetty.home)/lib/util.jar\n"); - buf.append("\n"); - buf.append("[All,server,default]\n"); - buf.append("$(jetty.home)/lib/core.jar\n"); - buf.append("$(jetty.home)/lib/server.jar\n"); - buf.append("$(jetty.home)/lib/http.jar\n"); - buf.append("\n"); - buf.append("[All,xml,default]\n"); - buf.append("$(jetty.home)/lib/xml.jar\n"); - buf.append("\n"); - buf.append("[All,logging]\n"); - buf.append("$(jetty.home)/lib/LOGGING.JAR\n"); - - String jettyHome = getTestableJettyHome(); - - Config cfg = new Config(); - cfg.setProperty("jetty.home",jettyHome); - cfg.parse(buf); - - Classpath defaultClasspath = cfg.getClasspath(); - Assert.assertNotNull("Default Classpath should not be null",defaultClasspath); - - Classpath foocp = cfg.getSectionClasspath("Foo"); - Assert.assertNull("Foo Classpath should not exist",foocp); - - // Test if entire section list can be fetched - Set sections = cfg.getSectionIds(); - - Set expected = new HashSet(); - expected.add(Config.DEFAULT_SECTION); - expected.add("*"); - expected.add("All"); - expected.add("server"); - expected.add("default"); - expected.add("xml"); - expected.add("logging"); - - assertEquals("Multiple Section IDs",expected,sections); - - // Test fetch of specific section by name works - Classpath cpAll = cfg.getSectionClasspath("All"); - Assert.assertNotNull("Classpath section 'All' should exist",cpAll); - - File lib = new File(getJettyHomeDir(),"lib"); - - Classpath expectedAll = new Classpath(); - expectedAll.addComponent(new File(lib,"core.jar")); - expectedAll.addComponent(new File(lib,"server.jar")); - expectedAll.addComponent(new File(lib,"http.jar")); - expectedAll.addComponent(new File(lib,"xml.jar")); - expectedAll.addComponent(new File(lib,"LOGGING.JAR")); - - assertEquals("Classpath 'All' Section",expectedAll,cpAll); - - // Test combined classpath fetch of multiple sections works - List activated = new ArrayList(); - activated.add("server"); - activated.add("logging"); - - Classpath cpCombined = cfg.getCombinedClasspath(activated); - - Classpath expectedCombined = new Classpath(); - // from default - expectedCombined.addComponent(new File(lib,"spec.zip")); - // from 'server' - expectedCombined.addComponent(new File(lib,"core.jar")); - expectedCombined.addComponent(new File(lib,"server.jar")); - expectedCombined.addComponent(new File(lib,"http.jar")); - // from 'logging' - expectedCombined.addComponent(new File(lib,"LOGGING.JAR")); - // from '*' - expectedCombined.addComponent(new File(lib,"io.jar")); - expectedCombined.addComponent(new File(lib,"util.jar")); - - assertEquals("Classpath combined 'server,logging'",expectedCombined,cpCombined); - } - - @Test - public void testDynamicSection() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("[All,default,=$(jetty.home)/lib/*]\n"); - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - Classpath defaultClasspath = options.getClasspath(); - Assert.assertNotNull("Default Classpath should not be null",defaultClasspath); - Classpath foocp = options.getSectionClasspath("foo"); - Assert.assertNotNull("Foo Classpath should not exist",foocp); - - Classpath allcp = options.getSectionClasspath("All"); - Assert.assertNotNull("Classpath section 'All' should exist",allcp); - - Classpath extcp = options.getSectionClasspath("ext"); - Assert.assertNotNull("Classpath section 'ext' should exist", extcp); - - Assert.assertEquals("Deep Classpath Section",0,foocp.count()); - - File lib = new File(getJettyHomeDir(),"lib"); - File ext = new File(lib, "ext"); - Classpath expected = new Classpath(); - expected.addComponent(new File(ext,"custom-impl.jar")); - assertEquals("Single Classpath Section",expected,extcp); - } - - @Test - public void testDeepDynamicSection() throws IOException - { - StringBuffer buf = new StringBuffer(); - buf.append("[All,default,=$(jetty.home)/lib/**]\n"); - - - String jettyHome = getTestableJettyHome(); - - Config options = new Config(); - options.setProperty("jetty.home",jettyHome); - options.parse(buf); - - Classpath defaultClasspath = options.getClasspath(); - Assert.assertNotNull("Default Classpath should not be null",defaultClasspath); - Classpath foocp = options.getSectionClasspath("foo"); - Assert.assertNotNull("Foo Classpath should not exist",foocp); - - Classpath allcp = options.getSectionClasspath("All"); - Assert.assertNotNull("Classpath section 'All' should exist",allcp); - - Classpath extcp = options.getSectionClasspath("ext"); - Assert.assertNotNull("Classpath section 'ext' should exist", extcp); - - File lib = new File(getJettyHomeDir(),"lib"); - - Classpath expected = new Classpath(); - File foo = new File(lib, "foo"); - File bar = new File(foo, "bar"); - expected.addComponent(new File(bar,"foobar.jar")); - assertEquals("Deep Classpath Section",expected,foocp); - - File ext = new File(lib, "ext"); - expected = new Classpath(); - expected.addComponent(new File(ext,"custom-impl.jar")); - assertEquals("Single Classpath Section",expected,extcp); - } -} 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 bc37277d768..8b704e022ba 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 @@ -56,37 +56,37 @@ public class MainTest public void testProcessCommandLine() throws Exception { Main main = new Main(); - List xmls = main.processCommandLine(new String[] {}); - System.err.println(xmls); - - // Order is important here - List expectedXmls = new ArrayList(); - expectedXmls.add("etc/jetty.xml"); // from start.ini - expectedXmls.add("etc/jetty-deploy.xml"); // from start.ini - expectedXmls.add("etc/jetty-webapps.xml"); // from start.ini - expectedXmls.add("etc/jetty-contexts.xml"); // from start.ini - expectedXmls.add("etc/jetty-jmx.xml"); // from start.d/10-jmx.ini - expectedXmls.add("etc/jetty-testrealm.xml"); // from start.d/90-testrealm.ini - - assertThat("XML Resolution Order " + xmls,xmls,contains(expectedXmls.toArray())); - - // Order is irrelevant here - Set options = main.getConfig().getOptions(); - Set expectedOptions = new HashSet<>(); - // from start.ini - expectedOptions.add("Server"); - expectedOptions.add("jsp"); - expectedOptions.add("resources"); - expectedOptions.add("websocket"); - expectedOptions.add("ext"); - expectedOptions.add("newOption"); - // from start.d/10-jmx.ini - expectedOptions.add("jmx"); - // from start.d/20-websocket.ini - expectedOptions.add("websocket"); - // no options from start.d/90-testrealm.ini - - assertThat("Options " + options,options,containsInAnyOrder(expectedOptions.toArray())); +// List xmls = main.processCommandLine(new String[] {}); +// System.err.println(xmls); +// +// // Order is important here +// List expectedXmls = new ArrayList(); +// expectedXmls.add("etc/jetty.xml"); // from start.ini +// expectedXmls.add("etc/jetty-deploy.xml"); // from start.ini +// expectedXmls.add("etc/jetty-webapps.xml"); // from start.ini +// expectedXmls.add("etc/jetty-contexts.xml"); // from start.ini +// expectedXmls.add("etc/jetty-jmx.xml"); // from start.d/10-jmx.ini +// expectedXmls.add("etc/jetty-testrealm.xml"); // from start.d/90-testrealm.ini +// +// assertThat("XML Resolution Order " + xmls,xmls,contains(expectedXmls.toArray())); +// +// // Order is irrelevant here +// Set options = main.getConfig().getOptions(); +// Set expectedOptions = new HashSet<>(); +// // from start.ini +// expectedOptions.add("Server"); +// expectedOptions.add("jsp"); +// expectedOptions.add("resources"); +// expectedOptions.add("websocket"); +// expectedOptions.add("ext"); +// expectedOptions.add("newOption"); +// // from start.d/10-jmx.ini +// expectedOptions.add("jmx"); +// // from start.d/20-websocket.ini +// expectedOptions.add("websocket"); +// // no options from start.d/90-testrealm.ini +// +// assertThat("Options " + options,options,containsInAnyOrder(expectedOptions.toArray())); } @Test @@ -103,28 +103,28 @@ public class MainTest xmls.add("jetty-logging.xml"); Main main = new Main(); - main.addJvmArgs(jvmArgs); - - Classpath classpath = nastyWayToCreateAClasspathObject("/jetty/home with spaces/"); - CommandLineBuilder cmd = main.buildCommandLine(classpath,xmls); - assertThat("CommandLineBuilder shouldn't be null",cmd,notNullValue()); - - List commandArgs = cmd.getArgs(); - assertThat("commandArgs elements",commandArgs.size(),equalTo(12)); - assertThat("args does not contain -cp",commandArgs,hasItems("-cp")); - assertThat("Classpath should be correctly quoted and match expected value",commandArgs, - hasItems("/jetty/home with spaces/somejar.jar:/jetty/home with spaces/someotherjar.jar")); - assertThat("args does not contain --exec",commandArgs,hasItems("--exec")); - assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xms1024m")); - assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xmx1024m")); - assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty.xml")); - assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-jmx.xml")); - assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-logging.xml")); - - String commandLine = cmd.toString(); - assertThat("cmd.toString() should be properly escaped",commandLine,containsString("-cp /jetty/home\\ with\\ " - + "spaces/somejar.jar:/jetty/home\\ with\\ spaces/someotherjar.jar")); - assertThat("cmd.toString() doesn't contain xml config files",commandLine,containsString(" jetty.xml jetty-jmx.xml jetty-logging.xml")); +// main.addJvmArgs(jvmArgs); +// +// Classpath classpath = nastyWayToCreateAClasspathObject("/jetty/home with spaces/"); +// CommandLineBuilder cmd = main.buildCommandLine(classpath,xmls); +// assertThat("CommandLineBuilder shouldn't be null",cmd,notNullValue()); +// +// List commandArgs = cmd.getArgs(); +// assertThat("commandArgs elements",commandArgs.size(),equalTo(12)); +// assertThat("args does not contain -cp",commandArgs,hasItems("-cp")); +// assertThat("Classpath should be correctly quoted and match expected value",commandArgs, +// hasItems("/jetty/home with spaces/somejar.jar:/jetty/home with spaces/someotherjar.jar")); +// assertThat("args does not contain --exec",commandArgs,hasItems("--exec")); +// assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xms1024m")); +// assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xmx1024m")); +// assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty.xml")); +// assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-jmx.xml")); +// assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-logging.xml")); +// +// String commandLine = cmd.toString(); +// assertThat("cmd.toString() should be properly escaped",commandLine,containsString("-cp /jetty/home\\ with\\ " +// + "spaces/somejar.jar:/jetty/home\\ with\\ spaces/someotherjar.jar")); +// assertThat("cmd.toString() doesn't contain xml config files",commandLine,containsString(" jetty.xml jetty-jmx.xml jetty-logging.xml")); } private Classpath nastyWayToCreateAClasspathObject(String jettyHome) throws NoSuchFieldException, IllegalAccessException diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleTest.java index d283ba1befe..af8726f4a7b 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleTest.java @@ -32,7 +32,7 @@ public class ModuleTest private Module loadTestHomeModule(String moduleFileName) throws IOException { File file = MavenTestingUtils.getTestResourceFile("usecases/home/modules/" + moduleFileName); - return Module.fromFile(file); + return new Module(file); } @Test From f99a517c1d3a48cba1533610890f63c2f10c4c39 Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 22 Aug 2013 12:52:56 -0500 Subject: [PATCH 21/28] update mod files --- .../test/resources/usecases/home/modules/client.mod | 6 ++++++ .../src/test/resources/usecases/home/modules/debug.mod | 7 +++++++ .../test/resources/usecases/home/modules/deploy.mod | 9 +++++++++ .../src/test/resources/usecases/home/modules/http.mod | 3 +++ .../src/test/resources/usecases/home/modules/https.mod | 3 +++ .../test/resources/usecases/home/modules/ipaccess.mod | 7 +++++++ .../src/test/resources/usecases/home/modules/jaas.mod | 9 +++++++++ .../resources/usecases/home/modules/lowresources.mod | 7 +++++++ .../test/resources/usecases/home/modules/monitor.mod | 10 ++++++++++ .../src/test/resources/usecases/home/modules/plus.mod | 5 +++-- .../src/test/resources/usecases/home/modules/proxy.mod | 10 ++++++++++ .../resources/usecases/home/modules/requestlog.mod | 7 +++++++ .../test/resources/usecases/home/modules/rewrite.mod | 10 ++++++++++ .../src/test/resources/usecases/home/modules/stats.mod | 7 +++++++ .../test/resources/usecases/home/modules/webapp.mod | 7 +++++++ .../test/resources/usecases/home/modules/xinetd.mod | 7 +++++++ 16 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 jetty-start/src/test/resources/usecases/home/modules/client.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/debug.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/deploy.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/ipaccess.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/jaas.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/lowresources.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/monitor.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/proxy.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/requestlog.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/rewrite.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/stats.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/webapp.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/xinetd.mod diff --git a/jetty-start/src/test/resources/usecases/home/modules/client.mod b/jetty-start/src/test/resources/usecases/home/modules/client.mod new file mode 100644 index 00000000000..f434cdc0870 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/client.mod @@ -0,0 +1,6 @@ +# +# Client Feature +# + +# Client jars +LIB=lib/jetty-client-${jetty.version}.jar diff --git a/jetty-start/src/test/resources/usecases/home/modules/debug.mod b/jetty-start/src/test/resources/usecases/home/modules/debug.mod new file mode 100644 index 00000000000..8cdf5b94ab6 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/debug.mod @@ -0,0 +1,7 @@ +# +# Debug module +# + +DEPEND=server + +etc/jetty-debug.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/deploy.mod b/jetty-start/src/test/resources/usecases/home/modules/deploy.mod new file mode 100644 index 00000000000..5705ac61d91 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/deploy.mod @@ -0,0 +1,9 @@ +# +# Deploy Feature +# + +# Deploy jars +LIB=lib/jetty-deploy-${jetty.version}.jar + +# Deploy configuration +etc/jetty-deploy.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/http.mod b/jetty-start/src/test/resources/usecases/home/modules/http.mod index b8d4045eb8d..94eed962e9b 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/http.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/http.mod @@ -1,3 +1,6 @@ +# +# Jetty HTTP Server +# DEPEND=server diff --git a/jetty-start/src/test/resources/usecases/home/modules/https.mod b/jetty-start/src/test/resources/usecases/home/modules/https.mod index 69784924390..5e930e934f7 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/https.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/https.mod @@ -1,3 +1,6 @@ +# +# Jetty HTTP Server +# DEPEND=server diff --git a/jetty-start/src/test/resources/usecases/home/modules/ipaccess.mod b/jetty-start/src/test/resources/usecases/home/modules/ipaccess.mod new file mode 100644 index 00000000000..f99f26ec3e3 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/ipaccess.mod @@ -0,0 +1,7 @@ +# +# IPAccess module +# + +DEPEND=server + +etc/jetty-ipaccess.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/jaas.mod b/jetty-start/src/test/resources/usecases/home/modules/jaas.mod new file mode 100644 index 00000000000..d0d6f0fa463 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/jaas.mod @@ -0,0 +1,9 @@ +# +# JAAS Feature +# + +# JAAS jars +LIB=lib/jetty-jaas-${jetty.version}.jar + +# JAAS configuration +etc/jetty-jaas.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/lowresources.mod b/jetty-start/src/test/resources/usecases/home/modules/lowresources.mod new file mode 100644 index 00000000000..578d8165edd --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/lowresources.mod @@ -0,0 +1,7 @@ +# +# Low Resources module +# + +DEPEND=server + +etc/jetty-lowresources.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/monitor.mod b/jetty-start/src/test/resources/usecases/home/modules/monitor.mod new file mode 100644 index 00000000000..249ccef15d1 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/monitor.mod @@ -0,0 +1,10 @@ +# +# Jetty Monitor module +# + +DEPEND=server +DEPEND=client + +LIB=lib/jetty-monitor-${jetty.version}.jar + +etc/jetty-monitor.xml \ No newline at end of file diff --git a/jetty-start/src/test/resources/usecases/home/modules/plus.mod b/jetty-start/src/test/resources/usecases/home/modules/plus.mod index bc2b1af55a9..31d8e76b95c 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/plus.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/plus.mod @@ -1,9 +1,10 @@ # -# Jetty Plus Module +# Jetty Proxy module # DEPEND=server -LIB=lib/jetty-plus-${jetty.version}.xml +LIB=lib/jetty-plus-${jetty.version}.jar +# Plus requires configuration etc/jetty-plus.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/proxy.mod b/jetty-start/src/test/resources/usecases/home/modules/proxy.mod new file mode 100644 index 00000000000..9e2bc46db8c --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/proxy.mod @@ -0,0 +1,10 @@ +# +# Jetty Proxy module +# + +DEPEND=server + +LIB=lib/jetty-proxy-${jetty.version}.jar + +# Proxy requires configuration +etc/jetty-proxy.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/requestlog.mod b/jetty-start/src/test/resources/usecases/home/modules/requestlog.mod new file mode 100644 index 00000000000..060ca9f0a22 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/requestlog.mod @@ -0,0 +1,7 @@ +# +# Request Log module +# + +DEPEND=server + +etc/jetty-requestlog.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/rewrite.mod b/jetty-start/src/test/resources/usecases/home/modules/rewrite.mod new file mode 100644 index 00000000000..d5ccf960410 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/rewrite.mod @@ -0,0 +1,10 @@ +# +# Jetty Rewrite module +# + +DEPEND=server + +LIB=lib/jetty-rewrite-${jetty.version}.jar + +# Annotations needs annotations configuration +etc/jetty-rewrite.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/stats.mod b/jetty-start/src/test/resources/usecases/home/modules/stats.mod new file mode 100644 index 00000000000..cd56d5b4d7b --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/stats.mod @@ -0,0 +1,7 @@ +# +# Stats module +# + +DEPEND=server + +etc/jetty-stats.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/webapp.mod b/jetty-start/src/test/resources/usecases/home/modules/webapp.mod new file mode 100644 index 00000000000..187db774b69 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/webapp.mod @@ -0,0 +1,7 @@ +# +# Base server +# + +DEPEND=deploy + +LIB=lib/jetty-webapp-${jetty.version}.jar diff --git a/jetty-start/src/test/resources/usecases/home/modules/xinetd.mod b/jetty-start/src/test/resources/usecases/home/modules/xinetd.mod new file mode 100644 index 00000000000..c93064ad767 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/xinetd.mod @@ -0,0 +1,7 @@ +# +# Stats module +# + +DEPEND=server + +etc/jetty-xinetd.xml From 54091990cb556750efe863d99f0413d01a5a31cf Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 22 Aug 2013 13:08:51 -0500 Subject: [PATCH 22/28] remove duplicate schema.jar --- jetty-distribution/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-distribution/pom.xml b/jetty-distribution/pom.xml index bf9aac223e6..c008de54ed0 100644 --- a/jetty-distribution/pom.xml +++ b/jetty-distribution/pom.xml @@ -297,7 +297,7 @@ org.eclipse.jetty - org.eclipse.jetty.orbit,org.eclipse.jetty.spdy,org.eclipse.jetty.websocket + org.eclipse.jetty.orbit,org.eclipse.jetty.spdy,org.eclipse.jetty.websocket,org.eclipse.jetty.toolchain jetty-all,jetty-start,jetty-monitor jar ${assembly-directory}/lib From 0032c1443d28f1951a80789f48c24e3495466afa Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Thu, 22 Aug 2013 13:23:29 -0500 Subject: [PATCH 23/28] add spdy and websocket mod --- .../src/main/config/modules/spdy.mod | 7 +++++++ .../src/main/config/modules/websocket.mod | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 jetty-spdy/spdy-http-server/src/main/config/modules/spdy.mod create mode 100644 jetty-websocket/javax-websocket-server-impl/src/main/config/modules/websocket.mod diff --git a/jetty-spdy/spdy-http-server/src/main/config/modules/spdy.mod b/jetty-spdy/spdy-http-server/src/main/config/modules/spdy.mod new file mode 100644 index 00000000000..1f3d5e99614 --- /dev/null +++ b/jetty-spdy/spdy-http-server/src/main/config/modules/spdy.mod @@ -0,0 +1,7 @@ + +DEPEND=server + +LIB=lib/spdy/*.jar + +etc/jetty-ssl.xml +etc/jetty-spdy.xml diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/config/modules/websocket.mod b/jetty-websocket/javax-websocket-server-impl/src/main/config/modules/websocket.mod new file mode 100644 index 00000000000..e61ec33e184 --- /dev/null +++ b/jetty-websocket/javax-websocket-server-impl/src/main/config/modules/websocket.mod @@ -0,0 +1,14 @@ +# +# WebSocket Feature +# + +# WebSocket needs Annotations feature +DEPEND=server +DEPEND=annotations + +# WebSocket needs websocket jars (as defined in start.config) +LIB=lib/websockets/*.jar + +# WebSocket needs websocket configuration +etc/jetty-websockets.xml + From e17cee533ae7209f323cc205ce1ae1ff14d267da Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Aug 2013 12:00:40 -0700 Subject: [PATCH 24/28] More cleanup in start.jar --- .../org/eclipse/jetty/start/BaseHome.java | 34 +- .../org/eclipse/jetty/start/Classpath.java | 128 +++--- .../jetty/start/FilenameComparator.java | 70 ---- .../org/eclipse/jetty/start/JarVersion.java | 48 ++- .../java/org/eclipse/jetty/start/Main.java | 363 ++++++++++-------- .../java/org/eclipse/jetty/start/Module.java | 174 +++++---- .../java/org/eclipse/jetty/start/Modules.java | 110 +++--- .../org/eclipse/jetty/start/NaturalSort.java | 28 +- .../org/eclipse/jetty/start/StartArgs.java | 134 +++++-- .../org/eclipse/jetty/start/StartIni.java | 1 + .../org/eclipse/jetty/start/StartLog.java | 25 +- .../org/eclipse/jetty/start/TextFile.java | 10 +- .../eclipse/jetty/start/UsageException.java | 12 +- .../java/org/eclipse/jetty/start/Version.java | 125 +++--- .../org/eclipse/jetty/start/start.config | 179 --------- .../jetty/start/ConfigurationAssert.java | 115 ++++++ .../org/eclipse/jetty/start/MainTest.java | 130 +++---- .../org/eclipse/jetty/start/ModuleTest.java | 2 +- .../org/eclipse/jetty/start/ModulesTest.java | 6 +- .../test/resources/assert-home-with-jvm.txt | 29 ++ .../src/test/resources/assert-home.txt | 24 ++ .../resources/usecases/home/etc/README.spnego | 0 .../usecases/home/etc/jdbcRealm.properties | 0 .../usecases/home/etc/jetty-annotations.xml | 0 .../usecases/home/etc/jetty-contexts.xml | 0 .../usecases/home/etc/jetty-debug.xml | 0 .../usecases/home/etc/jetty-demo.xml | 0 .../usecases/home/etc/jetty-deploy.xml | 0 .../usecases/home/etc/jetty-http.xml | 0 .../usecases/home/etc/jetty-https.xml | 0 .../usecases/home/etc/jetty-ipaccess.xml | 0 .../usecases/home/etc/jetty-jaas.xml | 0 .../resources/usecases/home/etc/jetty-jmx.xml | 0 .../usecases/home/etc/jetty-logging.xml | 0 .../usecases/home/etc/jetty-lowresources.xml | 0 .../usecases/home/etc/jetty-monitor.xml | 0 .../usecases/home/etc/jetty-plus.xml | 0 .../usecases/home/etc/jetty-proxy.xml | 0 .../usecases/home/etc/jetty-requestlog.xml | 0 .../usecases/home/etc/jetty-rewrite.xml | 0 .../usecases/home/etc/jetty-setuid.xml | 0 .../usecases/home/etc/jetty-spdy-proxy.xml | 0 .../usecases/home/etc/jetty-spdy.xml | 0 .../resources/usecases/home/etc/jetty-ssl.xml | 0 .../usecases/home/etc/jetty-started.xml | 0 .../usecases/home/etc/jetty-stats.xml | 0 .../usecases/home/etc/jetty-testrealm.xml | 0 .../usecases/home/etc/jetty-webapps.xml | 0 .../usecases/home/etc/jetty-websockets.xml | 0 .../usecases/home/etc/jetty-xinetd.xml | 0 .../resources/usecases/home/etc/jetty.conf | 0 .../resources/usecases/home/etc/jetty.xml | 0 .../test/resources/usecases/home/etc/keystore | 0 .../test/resources/usecases/home/etc/krb5.ini | 0 .../usecases/home/etc/realm.properties | 0 .../resources/usecases/home/etc/spnego.conf | 0 .../usecases/home/etc/spnego.properties | 0 .../usecases/home/etc/test-realm.xml | 0 .../usecases/home/etc/webdefault.xml | 0 .../annotations/javax.annotation-api-1.2.jar | 0 .../annotations/org.objectweb.asm-TEST.jar | 0 .../resources/usecases/home/lib/ext/.nodelete | 0 .../home/lib/jetty-annotations-TEST.jar | 0 .../usecases/home/lib/jetty-client-TEST.jar | 0 .../home/lib/jetty-continuation-TEST.jar | 0 .../usecases/home/lib/jetty-deploy-TEST.jar | 0 .../usecases/home/lib/jetty-http-TEST.jar | 0 .../usecases/home/lib/jetty-io-TEST.jar | 0 .../usecases/home/lib/jetty-jaas-TEST.jar | 0 .../usecases/home/lib/jetty-jmx-TEST.jar | 0 .../usecases/home/lib/jetty-jndi-TEST.jar | 0 .../usecases/home/lib/jetty-jsp-TEST.jar | 0 .../usecases/home/lib/jetty-plus-TEST.jar | 0 .../usecases/home/lib/jetty-proxy-TEST.jar | 0 .../usecases/home/lib/jetty-rewrite-TEST.jar | 0 .../home/lib/jetty-schemas-3.1.RC0.jar | 0 .../usecases/home/lib/jetty-schemas-3.1.jar | 0 .../usecases/home/lib/jetty-security-TEST.jar | 0 .../usecases/home/lib/jetty-server-TEST.jar | 0 .../usecases/home/lib/jetty-servlet-TEST.jar | 0 .../usecases/home/lib/jetty-servlets-TEST.jar | 0 .../usecases/home/lib/jetty-util-TEST.jar | 0 .../usecases/home/lib/jetty-webapp-TEST.jar | 0 .../usecases/home/lib/jetty-xml-TEST.jar | 0 .../home/lib/jndi/javax.activation-1.1.jar | 0 .../lib/jndi/javax.transaction-api-1.2.jar | 0 .../usecases/home/lib/jsp/javax.el-3.0.0.jar | 0 .../home/lib/jsp/javax.servlet.jsp-2.3.2.jar | 0 .../lib/jsp/javax.servlet.jsp-api-2.3.1.jar | 0 .../lib/jsp/javax.servlet.jsp.jstl-1.2.0.jar | 0 ...pache.taglibs.standard.glassfish-1.2.0.jar | 0 .../lib/jsp/org.eclipse.jdt.core-3.8.2.jar | 0 .../home/lib/monitor/jetty-monitor-TEST.jar | 0 .../usecases/home/lib/servlet-api-3.1.jar | 0 .../lib/setuid/jetty-setuid-java-1.0.1.jar | 0 .../home/lib/setuid/libsetuid-linux.so | 0 .../usecases/home/lib/setuid/libsetuid-osx.so | 0 .../home/lib/spdy/spdy-client-TEST.jar | 0 .../usecases/home/lib/spdy/spdy-core-TEST.jar | 0 .../home/lib/spdy/spdy-http-common-TEST.jar | 0 .../home/lib/spdy/spdy-http-server-TEST.jar | 0 .../home/lib/spdy/spdy-server-TEST.jar | 0 .../javax-websocket-client-impl-TEST.jar | 0 .../lib/websocket/javax.websocket-api-1.0.jar | 0 .../usecases/home/modules/websocket.mod | 3 +- .../usecases/home/resources/.nodelete | 0 106 files changed, 897 insertions(+), 853 deletions(-) delete mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/FilenameComparator.java delete mode 100644 jetty-start/src/main/resources/org/eclipse/jetty/start/start.config create mode 100644 jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java create mode 100644 jetty-start/src/test/resources/assert-home-with-jvm.txt create mode 100644 jetty-start/src/test/resources/assert-home.txt create mode 100644 jetty-start/src/test/resources/usecases/home/etc/README.spnego create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jdbcRealm.properties create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-annotations.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-contexts.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-debug.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-demo.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-deploy.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-http.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-https.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-ipaccess.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-jaas.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-jmx.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-logging.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-lowresources.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-monitor.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-plus.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-proxy.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-requestlog.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-rewrite.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-setuid.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-spdy-proxy.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-spdy.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-ssl.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-started.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-stats.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-testrealm.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-webapps.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-websockets.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty-xinetd.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty.conf create mode 100644 jetty-start/src/test/resources/usecases/home/etc/jetty.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/keystore create mode 100644 jetty-start/src/test/resources/usecases/home/etc/krb5.ini create mode 100644 jetty-start/src/test/resources/usecases/home/etc/realm.properties create mode 100644 jetty-start/src/test/resources/usecases/home/etc/spnego.conf create mode 100644 jetty-start/src/test/resources/usecases/home/etc/spnego.properties create mode 100644 jetty-start/src/test/resources/usecases/home/etc/test-realm.xml create mode 100644 jetty-start/src/test/resources/usecases/home/etc/webdefault.xml create mode 100644 jetty-start/src/test/resources/usecases/home/lib/annotations/javax.annotation-api-1.2.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/annotations/org.objectweb.asm-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/ext/.nodelete create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-annotations-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-client-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-continuation-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-deploy-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-http-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-io-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-jaas-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-jmx-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-jndi-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-jsp-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-plus-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-proxy-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-rewrite-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-schemas-3.1.RC0.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-schemas-3.1.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-security-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-server-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-servlet-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-servlets-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-util-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-webapp-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jetty-xml-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jndi/javax.activation-1.1.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jndi/javax.transaction-api-1.2.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jsp/javax.el-3.0.0.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jsp/javax.servlet.jsp-2.3.2.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jsp/javax.servlet.jsp-api-2.3.1.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jsp/javax.servlet.jsp.jstl-1.2.0.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/jsp/org.eclipse.jdt.core-3.8.2.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/monitor/jetty-monitor-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/servlet-api-3.1.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/setuid/jetty-setuid-java-1.0.1.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/setuid/libsetuid-linux.so create mode 100644 jetty-start/src/test/resources/usecases/home/lib/setuid/libsetuid-osx.so create mode 100644 jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-client-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-core-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-http-common-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-http-server-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-server-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/websocket/javax-websocket-client-impl-TEST.jar create mode 100644 jetty-start/src/test/resources/usecases/home/lib/websocket/javax.websocket-api-1.0.jar create mode 100644 jetty-start/src/test/resources/usecases/home/resources/.nodelete 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 92dcda2e550..8ac34054d01 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 @@ -189,26 +189,32 @@ public class BaseHome File homePath = new File(homeDir,FS.separators(relPathToDirectory)); List homeFiles = new ArrayList<>(); - homeFiles.addAll(Arrays.asList(homePath.listFiles(filter))); + if (FS.canReadDirectory(homePath)) + { + homeFiles.addAll(Arrays.asList(homePath.listFiles(filter))); + } if (isBaseDifferent()) { // merge File basePath = new File(baseDir,FS.separators(relPathToDirectory)); - File baseFiles[] = basePath.listFiles(filter); List ret = new ArrayList<>(); - - if (baseFiles != null) + if (FS.canReadDirectory(basePath)) { - for (File base : baseFiles) + File baseFiles[] = basePath.listFiles(filter); + + if (baseFiles != null) { - String relpath = toRelativePath(baseDir,base); - File home = new File(homeDir,FS.separators(relpath)); - if (home.exists()) + for (File base : baseFiles) { - homeFiles.remove(home); + String relpath = toRelativePath(baseDir,base); + File home = new File(homeDir,FS.separators(relpath)); + if (home.exists()) + { + homeFiles.remove(home); + } + ret.add(base); } - ret.add(base); } } @@ -253,27 +259,27 @@ public class BaseHome public void setBaseDir(File dir) { - this.baseDir = dir; try { + this.baseDir = dir.getCanonicalFile(); System.setProperty("jetty.base",dir.getCanonicalPath()); } catch (IOException e) { - e.printStackTrace(); + e.printStackTrace(System.err); } } public void setHomeDir(File dir) { - this.homeDir = dir; try { + this.homeDir = dir.getCanonicalFile(); System.setProperty("jetty.home",dir.getCanonicalPath()); } catch (IOException e) { - e.printStackTrace(); + e.printStackTrace(System.err); } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java index 4a49e2da179..488f09e0447 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java @@ -34,6 +34,20 @@ import java.util.StringTokenizer; */ public class Classpath implements Iterable { + private static class Loader extends URLClassLoader + { + Loader(URL[] urls, ClassLoader parent) + { + super(urls,parent); + } + + @Override + public String toString() + { + return "startJarLoader@" + Long.toHexString(hashCode()); + } + } + private final List elements = new ArrayList(); public Classpath() @@ -45,31 +59,18 @@ public class Classpath implements Iterable addClasspath(initial); } - @Override - public Iterator iterator() + public boolean addClasspath(String s) { - return elements.iterator(); - } - - public List getElements() - { - return elements; - } - - public int count() - { - return elements.size(); - } - - public boolean addComponent(String component) - { - if ((component == null) || (component.length() <= 0)) + boolean added = false; + if (s != null) { - // nothing to add - return false; + StringTokenizer t = new StringTokenizer(s,File.pathSeparator); + while (t.hasMoreTokens()) + { + added |= addComponent(t.nextToken()); + } } - - return addComponent(new File(component)); + return added; } public boolean addComponent(File path) @@ -97,18 +98,20 @@ public class Classpath implements Iterable return false; } - public boolean addClasspath(String s) + public boolean addComponent(String component) { - boolean added = false; - if (s != null) + if ((component == null) || (component.length() <= 0)) { - StringTokenizer t = new StringTokenizer(s,File.pathSeparator); - while (t.hasMoreTokens()) - { - added |= addComponent(t.nextToken()); - } + // nothing to add + return false; } - return added; + + return addComponent(new File(component)); + } + + public int count() + { + return elements.size(); } public void dump(PrintStream out) @@ -120,23 +123,6 @@ public class Classpath implements Iterable } } - @Override - public String toString() - { - StringBuffer cp = new StringBuffer(1024); - boolean needDelim = false; - for (File element : elements) - { - if (needDelim) - { - cp.append(File.pathSeparatorChar); - } - cp.append(element.getAbsolutePath()); - needDelim = true; - } - return cp.toString(); - } - public ClassLoader getClassLoader() { int cnt = elements.size(); @@ -164,18 +150,20 @@ public class Classpath implements Iterable return new Loader(urls,parent); } - private static class Loader extends URLClassLoader + public List getElements() { - Loader(URL[] urls, ClassLoader parent) - { - super(urls,parent); - } + return elements; + } - @Override - public String toString() - { - return "startJarLoader@" + Long.toHexString(hashCode()); - } + public boolean isEmpty() + { + return (elements == null) || (elements.isEmpty()); + } + + @Override + public Iterator iterator() + { + return elements.iterator(); } /** @@ -197,16 +185,20 @@ public class Classpath implements Iterable } } - public boolean isEmpty() + @Override + public String toString() { - return (elements == null) || (elements.isEmpty()); - } - - /** - * Add the System classpath to this object's tracking - */ - public void addSystemClasspath() - { - addClasspath(System.getProperty("java.class.path")); + StringBuffer cp = new StringBuffer(1024); + boolean needDelim = false; + for (File element : elements) + { + if (needDelim) + { + cp.append(File.pathSeparatorChar); + } + cp.append(element.getAbsolutePath()); + needDelim = true; + } + return cp.toString(); } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/FilenameComparator.java b/jetty-start/src/main/java/org/eclipse/jetty/start/FilenameComparator.java deleted file mode 100644 index 266716ff84a..00000000000 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/FilenameComparator.java +++ /dev/null @@ -1,70 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.start; - -import java.io.File; -import java.text.CollationKey; -import java.text.Collator; -import java.util.Comparator; - -/** - * Smart comparator for filenames, with natural language sorting, and files sorted before sub directories. - */ -public class FilenameComparator implements Comparator -{ - public static final FilenameComparator INSTANCE = new FilenameComparator(); - private Collator collator = Collator.getInstance(); - - public int compare(File o1, File o2) - { - if (o1.isFile()) - { - if (o2.isFile()) - { - CollationKey key1 = toKey(o1); - CollationKey key2 = toKey(o2); - return key1.compareTo(key2); - } - else - { - // Push o2 directories below o1 files - return -1; - } - } - else - { - if (o2.isDirectory()) - { - CollationKey key1 = toKey(o1); - CollationKey key2 = toKey(o2); - return key1.compareTo(key2); - } - else - { - // Push o2 files above o1 directories - return 1; - } - } - } - - private CollationKey toKey(File f) - { - return collator.getCollationKey(f.getAbsolutePath()); - } -} \ No newline at end of file diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java b/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java index 029f7654522..51fc8dcaf0d 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/JarVersion.java @@ -50,7 +50,7 @@ public class JarVersion return entry; } } - + return null; } @@ -58,11 +58,15 @@ public class JarVersion { Attributes attribs = manifest.getMainAttributes(); if (attribs == null) + { return null; + } String version = attribs.getValue("Bundle-Version"); if (version == null) + { return null; + } return stripV(version); } @@ -71,11 +75,15 @@ public class JarVersion { Attributes attribs = manifest.getMainAttributes(); if (attribs == null) + { return null; + } String version = attribs.getValue(Attributes.Name.IMPLEMENTATION_VERSION); if (version == null) + { return null; + } return stripV(version); } @@ -84,19 +92,23 @@ public class JarVersion { JarEntry pomProp = findEntry(jar,"META-INF/maven/.*/pom\\.properties$"); if (pomProp == null) + { return null; - + } + InputStream stream = null; - + try { stream = jar.getInputStream(pomProp); Properties props = new Properties(); props.load(stream); - + String version = props.getProperty("version"); if (version == null) + { return null; + } return stripV(version); } @@ -109,15 +121,19 @@ public class JarVersion private static String getSubManifestImplVersion(Manifest manifest) { Map entries = manifest.getEntries(); - + for (Attributes attribs : entries.values()) { if (attribs == null) + { continue; // skip entry + } String version = attribs.getValue(Attributes.Name.IMPLEMENTATION_VERSION); if (version == null) + { continue; // empty, no value, skip it + } return stripV(version); } @@ -127,28 +143,36 @@ public class JarVersion public static String getVersion(File file) { - try(JarFile jar = new JarFile(file)) + try (JarFile jar = new JarFile(file)) { String version = null; - + Manifest manifest = jar.getManifest(); version = getMainManifestImplVersion(manifest); if (version != null) + { return version; - + } + version = getSubManifestImplVersion(manifest); if (version != null) + { return version; - + } + version = getBundleVersion(manifest); if (version != null) + { return version; - + } + version = getMavenVersion(jar); if (version != null) + { return version; - + } + return "(not specified)"; } catch (IOException e) @@ -160,7 +184,9 @@ public class JarVersion private static String stripV(String version) { if (version.charAt(0) == 'v') + { return version.substring(1); + } return version; } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 367e1af50c1..0f75f5b0606 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -79,7 +79,6 @@ import java.util.Locale; public class Main { private static final int EXIT_USAGE = 1; - private final BaseHome baseHome; public static void main(String[] args) { @@ -99,74 +98,54 @@ public class Main } } + static void usageExit(int exit) + { + usageExit(null,exit); + } + + static void usageExit(Throwable t, int exit) + { + if (t != null) + { + t.printStackTrace(System.err); + } + System.err.println(); + System.err.println("Usage: java -jar start.jar [options] [properties] [configs]"); + System.err.println(" java -jar start.jar --help # for more information"); + System.exit(exit); + } + + private final BaseHome baseHome; + Main() throws IOException { baseHome = new BaseHome(); } - public StartArgs processCommandLine(String[] cmdLine) throws Exception + private void copyInThread(final InputStream in, final OutputStream out) { - StartArgs args = new StartArgs(cmdLine); - - // Processing Order is important! - // ------------------------------------------------------------ - // 1) Directory Locations - - // Set Home and Base at the start, as all other paths encountered - // will be based off of them. - baseHome.initialize(args); - - // ------------------------------------------------------------ - // 2) Start Logging - StartLog.getInstance().initialize(baseHome,args); - - // ------------------------------------------------------------ - // 3) Load Inis - File start_ini = baseHome.getBaseFile("start.ini"); - if (FS.canReadFile(start_ini)) + new Thread(new Runnable() { - args.parse(new StartIni(start_ini)); - } - - File start_d = baseHome.getBaseFile("start.d"); - if (FS.canReadDirectory(start_d)) - { - List files = new ArrayList<>(); - for (File file : start_d.listFiles(new FS.IniFilter())) + @Override + public void run() { - files.add(file); + try + { + byte[] buf = new byte[1024]; + int len = in.read(buf); + while (len > 0) + { + out.write(buf,0,len); + len = in.read(buf); + } + } + catch (IOException e) + { + // e.printStackTrace(); + } } - Collections.sort(files,new NaturalSort.Files()); - for (File file : files) - { - args.parse(new StartIni(file)); - } - } - - // 4) Parse everything provided. - // This would be the directory information + - // the various start inis - // and then the raw command line arguments - args.parseCommandLine(); - - // 5) Module Registration - Modules modules = new Modules(); - modules.registerAll(baseHome); - - // 6) Active Module Resolution - for (String enabledModule : args.getEnabledModules()) - { - modules.enable(enabledModule); - } - modules.buildGraph(); - - List activeModules = modules.resolveEnabled(); - - // 7) Lib & XML Expansion / Resolution - args.expandModules(baseHome,activeModules); - - return args; + }).start(); } private void download(String arg) @@ -174,24 +153,32 @@ public class Main try { String[] split = arg.split(":",3); - if (split.length != 3 || "http".equalsIgnoreCase(split[0]) || !split[1].startsWith("//")) + if ((split.length != 3) || "http".equalsIgnoreCase(split[0]) || !split[1].startsWith("//")) + { throw new IllegalArgumentException("Not --download=:"); + } String location = split[2]; if (File.separatorChar != '/') + { location.replaceAll("/",File.separator); + } File file = new File(location); StartLog.debug("Download to %s %s",file.getAbsolutePath(),(file.exists()?"[Exists!]":"")); if (file.exists()) + { return; + } URL url = new URL(split[0].substring(11) + ":" + split[1]); System.err.println("DOWNLOAD: " + url + " to " + location); if (!file.getParentFile().exists()) + { file.getParentFile().mkdirs(); + } byte[] buf = new byte[8192]; try (InputStream in = url.openStream(); OutputStream out = new FileOutputStream(file);) @@ -201,9 +188,13 @@ public class Main int len = in.read(buf); if (len > 0) + { out.write(buf,0,len); + } if (len < 0) + { break; + } } } } @@ -215,17 +206,23 @@ public class Main } } - private void usage() + private String getVersion(File element) { - String usageResource = "org/eclipse/jetty/start/usage.txt"; - InputStream usageStream = getClass().getClassLoader().getResourceAsStream(usageResource); - - if (usageStream == null) + if (element.isDirectory()) { - System.err.println("ERROR: detailed usage resource unavailable"); - usageExit(EXIT_USAGE); + return "(dir)"; } - System.exit(EXIT_USAGE); + + if (element.isFile()) + { + String name = element.getName().toLowerCase(Locale.ENGLISH); + if (name.endsWith(".jar")) + { + return JarVersion.getVersion(element); + } + } + + return ""; } public void invokeMain(StartArgs args) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException, IOException @@ -259,6 +256,128 @@ public class Main main.invoke(null,method_params); } + private void listConfig() + { + // TODO + } + + private void listModules() + { + // TODO Auto-generated method stub + } + + public StartArgs processCommandLine(String[] cmdLine) throws Exception + { + StartArgs args = new StartArgs(cmdLine); + + // Processing Order is important! + // ------------------------------------------------------------ + // 1) Directory Locations + + // Set Home and Base at the start, as all other paths encountered + // will be based off of them. + baseHome.initialize(args); + + // ------------------------------------------------------------ + // 2) Start Logging + StartLog.getInstance().initialize(baseHome,args); + + StartLog.debug("jetty.home=%s",baseHome.getHome()); + StartLog.debug("jetty.base=%s",baseHome.getBase()); + + // ------------------------------------------------------------ + // 3) Load Inis + File start_ini = baseHome.getBaseFile("start.ini"); + if (FS.canReadFile(start_ini)) + { + StartLog.debug("Reading ${jetty.base}/start.ini) - %s",start_ini); + args.parse(new StartIni(start_ini)); + } + + File start_d = baseHome.getBaseFile("start.d"); + if (FS.canReadDirectory(start_d)) + { + List files = new ArrayList<>(); + for (File file : start_d.listFiles(new FS.IniFilter())) + { + files.add(file); + } + + Collections.sort(files,new NaturalSort.Files()); + for (File file : files) + { + StartLog.debug("Reading ${jetty.base}/start.d/%s - %s",file.getName(),file); + args.parse(new StartIni(file)); + } + } + + // 4) Parse everything provided. + // This would be the directory information + + // the various start inis + // and then the raw command line arguments + StartLog.debug("Parsing collected arguments"); + args.parseCommandLine(); + + // 5) Module Registration + Modules modules = new Modules(); + StartLog.debug("Registering all modules"); + modules.registerAll(baseHome); + + // 6) Active Module Resolution + for (String enabledModule : args.getEnabledModules()) + { + StartLog.debug("Enabling module: %s",enabledModule); + modules.enable(enabledModule); + } + StartLog.debug("Building Module Graph"); + modules.buildGraph(); + + List activeModules = modules.resolveEnabled(); + + // 7) Lib & XML Expansion / Resolution + args.expandModules(baseHome,activeModules); + + // 8) Resolve Extra XMLs + args.resolveExtraXmls(baseHome); + + return args; + } + + public BaseHome getBaseHome() + { + return baseHome; + } + + private void showAllOptionsWithVersions() + { + // TODO + } + + private void showClasspathWithVersions(Classpath classpath) + { + // Iterate through active classpath, and fetch Implementation Version from each entry (if present) + // to dump to end user. + + // TODO: modules instead + // System.out.println("Active Options: " + _config.getOptions()); + + if (classpath.count() == 0) + { + System.out.println("No version information available show."); + return; + } + + System.out.println("Version Information on " + classpath.count() + " entr" + ((classpath.count() > 1)?"ies":"y") + " in the classpath."); + System.out.println("Note: order presented here is how they would appear on the classpath."); + System.out.println(" changes to the OPTIONS=[option,option,...] command line option will be reflected here."); + + int i = 0; + for (File element : classpath.getElements()) + { + System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),baseHome.toShortForm(element)); + } + } + public void start(StartArgs args) throws IOException, InterruptedException { // Get Desired Classpath based on user provided Active Options. @@ -363,90 +482,6 @@ public class Main } } - private void listModules() - { - // TODO Auto-generated method stub - } - - private void copyInThread(final InputStream in, final OutputStream out) - { - new Thread(new Runnable() - { - public void run() - { - try - { - byte[] buf = new byte[1024]; - int len = in.read(buf); - while (len > 0) - { - out.write(buf,0,len); - len = in.read(buf); - } - } - catch (IOException e) - { - // e.printStackTrace(); - } - } - - }).start(); - } - - private void showAllOptionsWithVersions() - { - // TODO - } - - private void showClasspathWithVersions(Classpath classpath) - { - // Iterate through active classpath, and fetch Implementation Version from each entry (if present) - // to dump to end user. - - // TODO: modules instead - // System.out.println("Active Options: " + _config.getOptions()); - - if (classpath.count() == 0) - { - System.out.println("No version information available show."); - return; - } - - System.out.println("Version Information on " + classpath.count() + " entr" + ((classpath.count() > 1)?"ies":"y") + " in the classpath."); - System.out.println("Note: order presented here is how they would appear on the classpath."); - System.out.println(" changes to the OPTIONS=[option,option,...] command line option will be reflected here."); - - int i = 0; - for (File element : classpath.getElements()) - { - System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),baseHome.toShortForm(element)); - } - } - - private String getVersion(File element) - { - if (element.isDirectory()) - { - return "(dir)"; - } - - if (element.isFile()) - { - String name = element.getName().toLowerCase(Locale.ENGLISH); - if (name.endsWith(".jar")) - { - return JarVersion.getVersion(element); - } - } - - return ""; - } - - private void listConfig() - { - // TODO - } - /** * Stop a running jetty instance. */ @@ -494,7 +529,9 @@ public class Main { StartLog.debug("Received \"%s\"",response); if ("Stopped".equals(response)) + { StartLog.warn("Server reports itself as Stopped"); + } } } } @@ -515,20 +552,16 @@ public class Main } } - static void usageExit(Throwable t, int exit) + private void usage() { - if (t != null) - { - t.printStackTrace(System.err); - } - System.err.println(); - System.err.println("Usage: java -jar start.jar [options] [properties] [configs]"); - System.err.println(" java -jar start.jar --help # for more information"); - System.exit(exit); - } + String usageResource = "org/eclipse/jetty/start/usage.txt"; + InputStream usageStream = getClass().getClassLoader().getResourceAsStream(usageResource); - static void usageExit(int exit) - { - usageExit(null,exit); + if (usageStream == null) + { + System.err.println("ERROR: detailed usage resource unavailable"); + usageExit(EXIT_USAGE); + } + System.exit(EXIT_USAGE); } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java index ec492ca53fc..2c9584823c9 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java @@ -82,65 +82,6 @@ public class Module extends TextFile // Strip .ini name = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(name).replaceFirst(""); } - - @Override - public void init() - { - String name = getFile().getName(); - - // Strip .ini - this.name = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(name).replaceFirst(""); - - this.parentNames = new HashSet<>(); - this.parentEdges = new HashSet<>(); - this.childEdges = new HashSet<>(); - this.xmls = new ArrayList<>(); - this.libs = new ArrayList<>(); - } - - @Override - public void process(String line) - { - boolean handled = false; - - if(line == null) { - - } - - // has assignment - int idx = line.indexOf('='); - if (idx >= 0) - { - String key = line.substring(0,idx); - String value = line.substring(idx + 1); - - switch (key.toUpperCase(Locale.ENGLISH)) - { - case "DEPEND": - parentNames.add(value); - handled = true; - break; - case "LIB": - libs.add(value); - handled = true; - break; - } - } - - if (handled) - { - return; // no further processing of line needed - } - - // Is it an XML line? - if (FS.isXml(line)) - { - xmls.add(line); - return; - } - - throw new IllegalArgumentException("Unrecognized Module Metadata line [" + line + "] in Module file [" + getFile() + "]"); - } public void addChildEdge(Module child) { @@ -152,6 +93,36 @@ public class Module extends TextFile this.parentEdges.add(parent); } + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + Module other = (Module)obj; + if (name == null) + { + if (other.name != null) + { + return false; + } + } + else if (!name.equals(other.name)) + { + return false; + } + return true; + } + public Set getChildEdges() { return childEdges; @@ -187,38 +158,78 @@ public class Module extends TextFile return xmls; } + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = (prime * result) + ((name == null)?0:name.hashCode()); + return result; + } + + @Override + public void init() + { + String name = getFile().getName(); + + // Strip .ini + this.name = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(name).replaceFirst(""); + + this.parentNames = new HashSet<>(); + this.parentEdges = new HashSet<>(); + this.childEdges = new HashSet<>(); + this.xmls = new ArrayList<>(); + this.libs = new ArrayList<>(); + } + public boolean isEnabled() { return enabled; } @Override - public int hashCode() + public void process(String line) { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null)?0:name.hashCode()); - return result; - } + boolean handled = false; - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Module other = (Module)obj; - if (name == null) + if (line == null) { - if (other.name != null) - return false; + } - else if (!name.equals(other.name)) - return false; - return true; + + // has assignment + int idx = line.indexOf('='); + if (idx >= 0) + { + String key = line.substring(0,idx); + String value = line.substring(idx + 1); + + switch (key.toUpperCase(Locale.ENGLISH)) + { + case "DEPEND": + parentNames.add(value); + handled = true; + break; + case "LIB": + libs.add(value); + handled = true; + break; + } + } + + if (handled) + { + return; // no further processing of line needed + } + + // Is it an XML line? + if (FS.isXml(line)) + { + xmls.add(line); + return; + } + + throw new IllegalArgumentException("Unrecognized Module Metadata line [" + line + "] in Module file [" + getFile() + "]"); } public void setDepth(int depth) @@ -231,6 +242,7 @@ public class Module extends TextFile this.enabled = enabled; } + @Override public String toString() { StringBuilder str = new StringBuilder(); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java index 5e23ce03759..d72c943c741 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java @@ -37,11 +37,6 @@ public class Modules implements Iterable { private Map modules = new HashMap<>(); - public void register(Module module) - { - modules.put(module.getName(),module); - } - private void bfsCalculateDepth(final Module module, final int depthNow) { int depth = depthNow + 1; @@ -95,6 +90,24 @@ public class Modules implements Iterable return modules.size(); } + public void dump() + { + List ordered = new ArrayList<>(); + ordered.addAll(modules.values()); + Collections.sort(ordered,Collections.reverseOrder(new Module.DepthComparator())); + + for (Module module : ordered) + { + System.out.printf("Module: %s%n",module.getName()); + System.out.printf(" depth: %d%n",module.getDepth()); + System.out.printf(" parents: [%s]%n",join(module.getParentNames(),',')); + for (String xml : module.getXmls()) + { + System.out.printf(" xml: %s%n",xml); + } + } + } + public void enable(String name) { Module module = modules.get(name); @@ -116,40 +129,6 @@ public class Modules implements Iterable } } - public void dump() - { - List ordered = new ArrayList<>(); - ordered.addAll(modules.values()); - Collections.sort(ordered,Collections.reverseOrder(new Module.DepthComparator())); - - for (Module module : ordered) - { - System.out.printf("Module: %s%n",module.getName()); - System.out.printf(" depth: %d%n",module.getDepth()); - System.out.printf(" parents: [%s]%n",join(module.getParentNames(),',')); - for (String xml : module.getXmls()) - { - System.out.printf(" xml: %s%n",xml); - } - } - } - - private String join(Collection objs, char delim) - { - StringBuilder str = new StringBuilder(); - boolean needDelim = false; - for (Object obj : objs) - { - if (needDelim) - { - str.append(delim); - } - str.append(obj); - needDelim = true; - } - return str.toString(); - } - public Module get(String name) { Module module = modules.get(name); @@ -166,27 +145,20 @@ public class Modules implements Iterable return modules.values().iterator(); } - /** - * Resolve the execution order of the enabled modules, and all dependant modules, based on depth first transitive reduction. - * - * @return the list of active modules (plus dependant modules), in execution order. - */ - public List resolveEnabled() + private String join(Collection objs, char delim) { - Set active = new HashSet(); - - for (Module module : modules.values()) + StringBuilder str = new StringBuilder(); + boolean needDelim = false; + for (Object obj : objs) { - if (module.isEnabled()) + if (needDelim) { - findParents(module,active); + str.append(delim); } + str.append(obj); + needDelim = true; } - - List ordered = new ArrayList<>(); - ordered.addAll(active); - Collections.sort(ordered,new Module.DepthComparator()); - return ordered; + return str.toString(); } // TODO: Resolve LIB names to actual java.io.File references via HomeBase @@ -225,6 +197,11 @@ public class Modules implements Iterable return xmls; } + public void register(Module module) + { + modules.put(module.getName(),module); + } + public void registerAll(BaseHome basehome) throws IOException { for (File file : basehome.listFiles("modules",new FS.FilenameRegexFilter("^.*\\.mod$"))) @@ -232,4 +209,27 @@ public class Modules implements Iterable register(new Module(file)); } } + + /** + * Resolve the execution order of the enabled modules, and all dependant modules, based on depth first transitive reduction. + * + * @return the list of active modules (plus dependant modules), in execution order. + */ + public List resolveEnabled() + { + Set active = new HashSet(); + + for (Module module : modules.values()) + { + if (module.isEnabled()) + { + findParents(module,active); + } + } + + List ordered = new ArrayList<>(); + ordered.addAll(active); + Collections.sort(ordered,new Module.DepthComparator()); + return ordered; + } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/NaturalSort.java b/jetty-start/src/main/java/org/eclipse/jetty/start/NaturalSort.java index 5b7ee0444bc..f6a7e7ac81e 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/NaturalSort.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/NaturalSort.java @@ -27,20 +27,7 @@ import java.util.Comparator; * Natural Language Sorting */ public class NaturalSort -{ - public static class Strings implements Comparator - { - private final Collator collator = Collator.getInstance(); - - @Override - public int compare(String o1, String o2) - { - CollationKey key1 = collator.getCollationKey(o1); - CollationKey key2 = collator.getCollationKey(o2); - return key1.compareTo(key2); - } - } - +{ public static class Files implements Comparator { private final Collator collator = Collator.getInstance(); @@ -53,4 +40,17 @@ public class NaturalSort return key1.compareTo(key2); } } + + public static class Strings implements Comparator + { + private final Collator collator = Collator.getInstance(); + + @Override + public int compare(String o1, String o2) + { + CollationKey key1 = collator.getCollationKey(o1); + CollationKey key2 = collator.getCollationKey(o2); + return key1.compareTo(key2); + } + } } 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 1d707ddbeb6..09045686bfa 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 @@ -26,10 +26,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.Set; @@ -89,12 +87,45 @@ public class StartArgs { commandLine.addAll(Arrays.asList(commandLineArgs)); classpath = new Classpath(); - classpath.addSystemClasspath(); } - public void buildStartCommandLine() + private void addUniqueXmlFile(String xmlRef, File xmlfile) throws IOException { - // TODO Auto-generated method stub + if (!FS.canReadFile(xmlfile)) + { + throw new IOException("Cannot read file: " + xmlRef); + } + xmlfile = xmlfile.getCanonicalFile(); + if (!xmls.contains(xmlfile)) + { + xmls.add(xmlfile); + } + } + + /** + * Ensure that the System Properties are set (if defined as a System property, or start.config property, or start.ini property) + * + * @param key + * the key to be sure of + */ + private void ensureSystemPropertySet(String key) + { + if (systemPropertyKeys.contains(key)) + { + return; // done + } + + if (properties.containsKey(key)) + { + String val = properties.getProperty(key,null); + if (val == null) + { + return; // no value to set + } + // setup system property + systemPropertyKeys.add(key); + System.setProperty(key,val); + } } /** @@ -102,8 +133,9 @@ public class StartArgs * * @param baseHome * @param activeModules + * @throws IOException */ - public void expandModules(BaseHome baseHome, List activeModules) + public void expandModules(BaseHome baseHome, List activeModules) throws IOException { for (Module module : activeModules) { @@ -160,6 +192,12 @@ public class StartArgs } // Find and Expand XML files + for (String xmlRef : module.getXmls()) + { + // Straight Reference + File xmlfile = baseHome.getFile(xmlRef); + addUniqueXmlFile(xmlRef,xmlfile); + } } } @@ -173,45 +211,14 @@ public class StartArgs return this.commandLine; } - public List getEnabledModules() - { - return this.enabledModules; - } - public List getDownloads() { return downloads; } - /** - * Ensure that the System Properties are set (if defined as a System property, or start.config property, or start.ini property) - * - * @param key - * the key to be sure of - */ - private void ensureSystemPropertySet(String key) + public List getEnabledModules() { - if (systemPropertyKeys.contains(key)) - { - return; // done - } - - if (properties.containsKey(key)) - { - String val = properties.getProperty(key,null); - if (val == null) - { - return; // no value to set - } - // setup system property - systemPropertyKeys.add(key); - System.setProperty(key,val); - } - } - - public Properties getProperties() - { - return properties; + return this.enabledModules; } public CommandLineBuilder getMainArgs(BaseHome baseHome) throws IOException @@ -270,6 +277,11 @@ public class StartArgs return System.getProperty("main.class",mainclass); } + public Properties getProperties() + { + return properties; + } + private String getValue(String arg) { int idx = arg.indexOf('='); @@ -285,6 +297,11 @@ public class StartArgs return value; } + public List getXmlFiles() + { + return xmls; + } + public boolean hasJvmArgs() { return jvmArgs.size() > 0; @@ -349,6 +366,12 @@ public class StartArgs return; } + if ("--debug".equals(arg)) + { + // valid, but handled in StartLog instead + return; + } + if ("--stop".equals(arg)) { stopCommand = true; @@ -500,4 +523,37 @@ public class StartArgs parse(line); } } + + public void resolveExtraXmls(BaseHome baseHome) throws IOException + { + // Find and Expand XML files + for (String xmlRef : xmlRefs) + { + // Straight Reference + File xmlfile = baseHome.getFile(xmlRef); + if (!xmlfile.exists()) + { + xmlfile = baseHome.getFile("etc/" + xmlRef); + } + addUniqueXmlFile(xmlRef,xmlfile); + } + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append("StartArgs [commandLine="); + builder.append(commandLine); + builder.append(", enabledModules="); + builder.append(enabledModules); + builder.append(", xmlRefs="); + builder.append(xmlRefs); + builder.append(", properties="); + builder.append(properties); + builder.append(", jvmArgs="); + builder.append(jvmArgs); + builder.append("]"); + return builder.toString(); + } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java index 1bd3f207192..c81c8595c75 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIni.java @@ -32,6 +32,7 @@ public class StartIni extends TextFile super(file); } + @Override public void addUniqueLine(String line) { if (line.startsWith("MODULES=")) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java index ee8d0bab5ea..41b23f78521 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartLog.java @@ -63,14 +63,17 @@ public class StartLog System.err.printf(format + "%n",args); } + public static void warn(Throwable t) + { + t.printStackTrace(System.err); + } + private boolean debug = false; public void initialize(BaseHome baseHome, StartArgs args) throws IOException { // Debug with boolean Pattern debugBoolPat = Pattern.compile("(-D)?debug=(.*)"); - // Debug enable flag (no boolean) - Pattern debugPat = Pattern.compile("(-D)?debug"); // Log file name Pattern logFilePat = Pattern.compile("(-D)?start-log-file=(.*)"); @@ -79,6 +82,12 @@ public class StartLog Matcher matcher; for (String arg : args.getCommandLine()) { + if ("--debug".equals(arg)) + { + debug = true; + continue; + } + matcher = debugBoolPat.matcher(arg); if (matcher.matches()) { @@ -86,13 +95,6 @@ public class StartLog continue; } - matcher = debugPat.matcher(arg); - if (matcher.matches()) - { - debug = true; - continue; - } - matcher = logFilePat.matcher(arg); if (matcher.matches()) { @@ -134,9 +136,4 @@ public class StartLog System.out.println("Establishing " + logfile + " on " + new Date()); } } - - public static void warn(Throwable t) - { - t.printStackTrace(System.err); - } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java index fc7909b05e9..c24c49457c3 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/TextFile.java @@ -42,7 +42,7 @@ public class TextFile implements Iterable { this.file = file; init(); - + try (FileReader reader = new FileReader(file)) { try (BufferedReader buf = new BufferedReader(reader)) @@ -66,10 +66,6 @@ public class TextFile implements Iterable } } - public void init() - { - } - public void addUniqueLine(String line) { if (lines.contains(line)) @@ -103,6 +99,10 @@ public class TextFile implements Iterable return lines; } + public void init() + { + } + @Override public Iterator iterator() { diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/UsageException.java b/jetty-start/src/main/java/org/eclipse/jetty/start/UsageException.java index 2590a81fce5..08ba684bed8 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/UsageException.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/UsageException.java @@ -31,18 +31,18 @@ public class UsageException extends RuntimeException public static final int ERR_BAD_ARG = -6; private int exitCode; - public UsageException(int exitCode, Throwable cause) - { - super(cause); - this.exitCode = exitCode; - } - public UsageException(int exitCode, String format, Object... objs) { super(String.format(format,objs)); this.exitCode = exitCode; } + public UsageException(int exitCode, Throwable cause) + { + super(cause); + this.exitCode = exitCode; + } + public int getExitCode() { return exitCode; diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Version.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Version.java index 49d823c93ac..c49de4aae7f 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Version.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Version.java @@ -19,30 +19,79 @@ package org.eclipse.jetty.start; /** - * Utility class for parsing and comparing version strings. - * JDK 1.1 compatible. + * Utility class for parsing and comparing version strings. JDK 1.1 compatible. * */ - -public class Version { - + +public class Version +{ + int _version = 0; int _revision = 0; int _subrevision = 0; String _suffix = ""; - - public Version() { + + public Version() + { } - - public Version(String version_string) { + + public Version(String version_string) + { parse(version_string); } - + + // java.lang.Comparable is Java 1.2! Cannot use it /** - * parses version string in the form version[.revision[.subrevision[extension]]] - * into this instance. + * Compares with other version. Does not take extension into account, as there is no reliable way to order them. + * + * @return -1 if this is older version that other, 0 if its same version, 1 if it's newer version than other */ - public void parse(String version_string) { + public int compare(Version other) + { + if (other == null) + { + throw new NullPointerException("other version is null"); + } + if (this._version < other._version) + { + return -1; + } + if (this._version > other._version) + { + return 1; + } + if (this._revision < other._revision) + { + return -1; + } + if (this._revision > other._revision) + { + return 1; + } + if (this._subrevision < other._subrevision) + { + return -1; + } + if (this._subrevision > other._subrevision) + { + return 1; + } + return 0; + } + + /** + * Check whether this verion is in range of versions specified + */ + public boolean isInRange(Version low, Version high) + { + return ((compare(low) >= 0) && (compare(high) <= 0)); + } + + /** + * parses version string in the form version[.revision[.subrevision[extension]]] into this instance. + */ + public void parse(String version_string) + { _version = 0; _revision = 0; _subrevision = 0; @@ -50,33 +99,41 @@ public class Version { int pos = 0; int startpos = 0; int endpos = version_string.length(); - while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) { + while ((pos < endpos) && Character.isDigit(version_string.charAt(pos))) + { pos++; } _version = Integer.parseInt(version_string.substring(startpos,pos)); - if ((pos < endpos) && version_string.charAt(pos)=='.') { + if ((pos < endpos) && (version_string.charAt(pos) == '.')) + { startpos = ++pos; - while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) { + while ((pos < endpos) && Character.isDigit(version_string.charAt(pos))) + { pos++; } _revision = Integer.parseInt(version_string.substring(startpos,pos)); } - if ((pos < endpos) && version_string.charAt(pos)=='.') { + if ((pos < endpos) && (version_string.charAt(pos) == '.')) + { startpos = ++pos; - while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) { + while ((pos < endpos) && Character.isDigit(version_string.charAt(pos))) + { pos++; } _subrevision = Integer.parseInt(version_string.substring(startpos,pos)); } - if (pos < endpos) { + if (pos < endpos) + { _suffix = version_string.substring(pos); } } - + /** * @return string representation of this version */ - public String toString() { + @Override + public String toString() + { StringBuffer sb = new StringBuffer(10); sb.append(_version); sb.append('.'); @@ -86,30 +143,4 @@ public class Version { sb.append(_suffix); return sb.toString(); } - - // java.lang.Comparable is Java 1.2! Cannot use it - /** - * Compares with other version. Does not take extension into account, - * as there is no reliable way to order them. - * @return -1 if this is older version that other, - * 0 if its same version, - * 1 if it's newer version than other - */ - public int compare(Version other) { - if (other == null) throw new NullPointerException("other version is null"); - if (this._version < other._version) return -1; - if (this._version > other._version) return 1; - if (this._revision < other._revision) return -1; - if (this._revision > other._revision) return 1; - if (this._subrevision < other._subrevision) return -1; - if (this._subrevision > other._subrevision) return 1; - return 0; - } - - /** - * Check whether this verion is in range of versions specified - */ - public boolean isInRange(Version low, Version high) { - return (compare(low)>=0 && compare(high)<=0); - } } diff --git a/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config b/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config deleted file mode 100644 index cd4cdf55a41..00000000000 --- a/jetty-start/src/main/resources/org/eclipse/jetty/start/start.config +++ /dev/null @@ -1,179 +0,0 @@ -# This file controls what file are to be put on classpath or command line. -# -# Format is as follows: -# -# Each line contains entry in the format: -# -# SUBJECT [ [!] CONDITION [AND|OR] ]* -# -# where SUBJECT: -# ends with ".class" is the Main class to run. -# ends with ".xml" is a configuration file for the command line -# ends with "/" is a directory from which to add all jar and zip files. -# ends with "/*" is a directory from which to add all unconsidered jar and zip files. -# ends with "/**" is a directory from which to recursively add all unconsidered jar and zip files. -# Containing = are used to assign system properties. -# Containing ~= are used to assign start properties. -# Containing /= are used to assign a canonical path. -# all other subjects are treated as files to be added to the classpath. -# -# ${name} is expanded to a start property -# $(name) is expanded to either a start property or a system property. -# The start property ${version} is defined as the version of the start.jar -# -# Files starting with "/" are considered absolute, all others are relative to -# the home directory. -# -# CONDITION is one of: -# always -# never -# available classname # true if class on classpath -# property name # true if set as start property -# system name # true if set as system property -# exists file # true if file/dir exists -# java OPERATOR version # java version compared to literal -# nargs OPERATOR number # number of command line args compared to literal -# OPERATOR := one of "<",">","<=",">=","==","!=" -# -# CONTITIONS can be combined with AND OR or !, with AND being the assume -# operator for a list of CONDITIONS. -# -# Classpath operations are evaluated on the fly, so once a class or jar is -# added to the classpath, subsequent available conditions will see that class. -# -# The configuration file may be divided into sections with option names like: -# [ssl,default] -# -# Clauses after a section header will only be included if they match one of the tags in the -# options property. By default options are set to "default,*" or the OPTIONS property may -# be used to pass in a list of tags, eg. : -# -# java -jar start.jar OPTIONS=jetty,jsp,ssl -# -# The tag '*' is always appended to the options, so any section with the * tag is always -# applied. -# - -# add a property defined classpath -${path}.path property path - -# add a property defined library directory -${lib}/** exists ${lib} - -# Try different settings of jetty.home until the start.jar is found. -jetty.home=. ! exists $(jetty.home)/start.jar -jetty.home=.. ! exists $(jetty.home)/start.jar -jetty.home=jetty-distribution/src/main/resources ! exists $(jetty.home)/start.jar -jetty.home=../jetty-distribution/src/main/resources ! exists $(jetty.home)/start.jar -jetty.home=. ! exists $(jetty.home)/start.jar -jetty.home/=$(jetty.home) exists $(jetty.home)/start.jar - -# Set the jetty.base property -jetty.base=$(jetty.base) system jetty.base - -# The main class to run -org.eclipse.jetty.xml.XmlConfiguration.class -${start.class}.class property start.class - -# The default configuration files -$(jetty.base)/etc/jetty.xml nargs == 0 AND property jetty.base -$(jetty.home)/etc/jetty.xml nargs == 0 -./jetty-server/src/main/config/etc/jetty.xml nargs == 0 AND ! exists $(jetty.home)/etc/jetty.xml - -# Default OPTIONS if not specified on the command line -OPTIONS~=default,* ! property OPTIONS - -# Add a resources directory if it is there -[All,resources,default] -$(jetty.base)/resources/ property jetty.base -$(jetty.home)/resources/ - -# Add jetty modules -[*] -$(jetty.home)/lib/jetty-util-$(version).jar ! available org.eclipse.jetty.util.StringUtil -$(jetty.home)/lib/jetty-io-$(version).jar ! available org.eclipse.jetty.io.Buffer - -[Server,All,xml,default] -$(jetty.home)/lib/jetty-xml-$(version).jar ! available org.eclipse.jetty.xml.XmlParser - -[Server,All,server,default] -$(jetty.home)/lib/servlet-api-3.1.jar ! available javax.servlet.ServletContext -$(jetty.home)/lib/jetty-schemas-3.1.jar -$(jetty.home)/lib/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser -$(jetty.home)/lib/jetty-continuation-$(version).jar ! available org.eclipse.jetty.continuation.Continuation -$(jetty.home)/lib/jetty-server-$(version).jar ! available org.eclipse.jetty.server.Server - -[Server,All,security,default] -$(jetty.home)/lib/jetty-security-$(version).jar ! available org.eclipse.jetty.security.LoginService - -[Server,All,servlet,default] -$(jetty.home)/lib/servlet-api-3.0.jar ! available javax.servlet.ServletContext -$(jetty.home)/lib/jetty-servlet-$(version).jar ! available org.eclipse.jetty.servlet.ServletHandler - -[servlets] -$(jetty.home)/lib/jetty-servlets-$(version).jar ! available org.eclipse.jetty.servlets.MultiPartFilter - -[Server,All,webapp,default] -$(jetty.home)/lib/jetty-webapp-$(version).jar ! available org.eclipse.jetty.webapp.WebAppContext - -[Server,All,deploy,default] -$(jetty.home)/lib/jetty-deploy-$(version).jar ! available org.eclipse.jetty.deploy.ContextDeployer - -[All,rewrite] -$(jetty.home)/lib/jetty-rewrite-$(version).jar ! available org.eclipse.jetty.rewrite.handler.RewriteHandler - -[All,jmx] -$(jetty.home)/lib/jetty-jmx-$(version).jar ! available org.eclipse.jetty.jmx.MBeanContainer - -[All,ajp] -$(jetty.home)/lib/jetty-ajp-$(version).jar ! available org.eclipse.jetty.ajp.Ajp13Connection - -[All,plus,jndi] -$(jetty.home)/lib/jetty-jndi-${version}.jar ! available org.eclipse.jetty.jndi.ContextFactory -$(jetty.home)/lib/jetty-plus-${version}.jar ! available org.eclipse.jetty.plus.jndi.NamingEntry -$(jetty.home)/lib/jndi/** exists $(jetty.home)/lib/jndi - -[All,jaas] -$(jetty.home)/lib/jetty-jaas-${version}.jar ! available org.eclipse.jetty.jaas.JAASLoginService - -[All,annotations] -$(jetty.home)/lib/jetty-annotations-$(version).jar ! available org.eclipse.jetty.annotations.AnnotationParser -$(jetty.home)/lib/annotations/** exists $(jetty.home)/lib/annotations - -[All,setuid] -$(jetty.home)/lib/jetty-setuid-$(version).jar ! available org.eclipse.jetty.setuid.SetUID -$(jetty.home)/lib/setuid/** - -[All,policy] -$(jetty.home)/lib/jetty-policy-$(version).jar ! available org.eclipse.jetty.policy.JettyPolicy - -[All,client] -$(jetty.home)/lib/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser -$(jetty.home)/lib/jetty-client-$(version).jar ! available org.eclipse.jetty.client.HttpClient - -[All,proxy] -$(jetty.home)/lib/jetty-proxy-$(version).jar ! available org.eclipse.jetty.proxy.ConnectHandler -$(jetty.home)/lib/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser -$(jetty.home)/lib/jetty-client-$(version).jar ! available org.eclipse.jetty.client.HttpClient - -[All,websocket] -$(jetty.home)/lib/websocket/** - -[All,overlay,overlays] -$(jetty.home)/lib/jetty-overlay-deployer-$(version).jar ! available org.eclipse.jetty.overlay.OverlayedAppProvider - - -# Add ext if it exists -[Server,All,default,ext] -$(jetty.base)/lib/ext/** property jetty.base -$(jetty.home)/lib/ext/** - -# Add all other sub-directories in /lib/ as options in a dynamic way -[All,=$(jetty.base)/lib/**] -[All,=$(jetty.home)/lib/**] - -# Set property jetty.base and jetty.log as jetty.home if not set -jetty.base=${jetty.home} ! property jetty.base -jetty.logs=${jetty.base}/logs ! property jetty.logs - - 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 new file mode 100644 index 00000000000..47b9925d6d1 --- /dev/null +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java @@ -0,0 +1,115 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.start; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.junit.Assert; + +public class ConfigurationAssert +{ + /** + * Given a provided StartArgs, assert that the configuration it has determined is valid based on values in a assert text file. + * + * @param baseHome + * the BaseHome used. Access it via {@link Main#getBaseHome()} + * @param args + * the StartArgs that has been processed via {@link Main#processCommandLine(String[])} + * @param filename + * the filename of the assertion values + * @throws IOException + */ + public static void assertConfiguration(BaseHome baseHome, StartArgs args, String filename) throws FileNotFoundException, IOException + { + File file = MavenTestingUtils.getTestResourceFile(filename); + TextFile textFile = new TextFile(file); + + // Validate XMLs (order is important) + List expectedXmls = new ArrayList<>(); + for (String line : textFile) + { + if (line.startsWith("XML|")) + { + expectedXmls.add(getValue(line)); + } + } + List actualXmls = new ArrayList<>(); + for (File xml : args.getXmlFiles()) + { + actualXmls.add(baseHome.toShortForm(xml)); + } + assertThat("XML Resolution Order " + actualXmls,actualXmls,contains(expectedXmls.toArray())); + + // Validate LIBs (order is not important) + Set expectedLibs = new HashSet<>(); + for (String line : textFile) + { + if (line.startsWith("LIB|")) + { + expectedLibs.add(getValue(line)); + } + } + Set actualLibs = new HashSet<>(); + for (File path : args.getClasspath()) + { + actualLibs.add(baseHome.toShortForm(path)); + } + assertThat("Libs " + actualLibs,actualLibs,containsInAnyOrder(expectedLibs.toArray())); + + // Validate PROPERTIES (order is not important) + Set expectedProperties = new HashSet<>(); + for (String line : textFile) + { + if (line.startsWith("PROP|")) + { + expectedProperties.add(getValue(line)); + } + } + Set actualProperties = new HashSet<>(); + @SuppressWarnings("unchecked") + Enumeration nameEnum = (Enumeration)args.getProperties().propertyNames(); + while (nameEnum.hasMoreElements()) + { + String name = nameEnum.nextElement(); + String value = args.getProperties().getProperty(name); + actualProperties.add(name + "=" + value); + } + assertThat("Properties " + actualProperties,actualProperties,containsInAnyOrder(expectedProperties.toArray())); + } + + private static String getValue(String arg) + { + int idx = arg.indexOf('|'); + Assert.assertThat("Expecting '|' sign in [" + arg + "]",idx,greaterThanOrEqualTo(0)); + String value = arg.substring(idx + 1).trim(); + Assert.assertThat("Expecting Value after '|' in [" + arg + "]",value.length(),greaterThan(0)); + return value; + } +} 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 8b704e022ba..1c9ef5bf52e 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 @@ -18,113 +18,85 @@ package org.eclipse.jetty.start; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - import java.io.File; -import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.Vector; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -/* ------------------------------------------------------------ */ -/** - */ -@Ignore public class MainTest { - /* ------------------------------------------------------------ */ - /** - * @throws java.lang.Exception - */ @Before public void setUp() throws Exception { - File testJettyHome = MavenTestingUtils.getTestResourceDir("jetty.home"); + File testJettyHome = MavenTestingUtils.getTestResourceDir("usecases/home"); System.setProperty("jetty.home",testJettyHome.getAbsolutePath()); } @Test - public void testProcessCommandLine() throws Exception + public void testBasicProcessing() throws Exception { Main main = new Main(); -// List xmls = main.processCommandLine(new String[] {}); -// System.err.println(xmls); -// -// // Order is important here -// List expectedXmls = new ArrayList(); -// expectedXmls.add("etc/jetty.xml"); // from start.ini -// expectedXmls.add("etc/jetty-deploy.xml"); // from start.ini -// expectedXmls.add("etc/jetty-webapps.xml"); // from start.ini -// expectedXmls.add("etc/jetty-contexts.xml"); // from start.ini -// expectedXmls.add("etc/jetty-jmx.xml"); // from start.d/10-jmx.ini -// expectedXmls.add("etc/jetty-testrealm.xml"); // from start.d/90-testrealm.ini -// -// assertThat("XML Resolution Order " + xmls,xmls,contains(expectedXmls.toArray())); -// -// // Order is irrelevant here -// Set options = main.getConfig().getOptions(); -// Set expectedOptions = new HashSet<>(); -// // from start.ini -// expectedOptions.add("Server"); -// expectedOptions.add("jsp"); -// expectedOptions.add("resources"); -// expectedOptions.add("websocket"); -// expectedOptions.add("ext"); -// expectedOptions.add("newOption"); -// // from start.d/10-jmx.ini -// expectedOptions.add("jmx"); -// // from start.d/20-websocket.ini -// expectedOptions.add("websocket"); -// // no options from start.d/90-testrealm.ini -// -// assertThat("Options " + options,options,containsInAnyOrder(expectedOptions.toArray())); + StartArgs args = main.processCommandLine(new String[] + { "jetty.port=9090" }); + BaseHome baseHome = main.getBaseHome(); + System.err.println(args); + + ConfigurationAssert.assertConfiguration(baseHome,args,"assert-home.txt"); } @Test - public void testBuildCommandLine() throws IOException, NoSuchFieldException, IllegalAccessException + public void testWithCommandLine() throws Exception { - List jvmArgs = new ArrayList(); - jvmArgs.add("--exec"); - jvmArgs.add("-Xms1024m"); - jvmArgs.add("-Xmx1024m"); + List cmdLineArgs = new ArrayList<>(); - List xmls = new ArrayList(); - xmls.add("jetty.xml"); - xmls.add("jetty-jmx.xml"); - xmls.add("jetty-logging.xml"); + // JVM args + cmdLineArgs.add("--exec"); + cmdLineArgs.add("-Xms1024m"); + cmdLineArgs.add("-Xmx1024m"); + + // Arbitrary XMLs + cmdLineArgs.add("jetty.xml"); + cmdLineArgs.add("jetty-jmx.xml"); + cmdLineArgs.add("jetty-logging.xml"); Main main = new Main(); -// main.addJvmArgs(jvmArgs); -// -// Classpath classpath = nastyWayToCreateAClasspathObject("/jetty/home with spaces/"); -// CommandLineBuilder cmd = main.buildCommandLine(classpath,xmls); -// assertThat("CommandLineBuilder shouldn't be null",cmd,notNullValue()); -// -// List commandArgs = cmd.getArgs(); -// assertThat("commandArgs elements",commandArgs.size(),equalTo(12)); -// assertThat("args does not contain -cp",commandArgs,hasItems("-cp")); -// assertThat("Classpath should be correctly quoted and match expected value",commandArgs, -// hasItems("/jetty/home with spaces/somejar.jar:/jetty/home with spaces/someotherjar.jar")); -// assertThat("args does not contain --exec",commandArgs,hasItems("--exec")); -// assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xms1024m")); -// assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xmx1024m")); -// assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty.xml")); -// assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-jmx.xml")); -// assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-logging.xml")); -// -// String commandLine = cmd.toString(); -// assertThat("cmd.toString() should be properly escaped",commandLine,containsString("-cp /jetty/home\\ with\\ " -// + "spaces/somejar.jar:/jetty/home\\ with\\ spaces/someotherjar.jar")); -// assertThat("cmd.toString() doesn't contain xml config files",commandLine,containsString(" jetty.xml jetty-jmx.xml jetty-logging.xml")); + + StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[6])); + BaseHome baseHome = main.getBaseHome(); + System.err.println(args); + + ConfigurationAssert.assertConfiguration(baseHome,args,"assert-home-with-jvm.txt"); + } + + public void testJettyHomeWithSpaces() + { + // main.addJvmArgs(jvmArgs); + // + // Classpath classpath = nastyWayToCreateAClasspathObject("/jetty/home with spaces/"); + // CommandLineBuilder cmd = main.buildCommandLine(classpath,xmls); + // assertThat("CommandLineBuilder shouldn't be null",cmd,notNullValue()); + // + // List commandArgs = cmd.getArgs(); + // assertThat("commandArgs elements",commandArgs.size(),equalTo(12)); + // assertThat("args does not contain -cp",commandArgs,hasItems("-cp")); + // assertThat("Classpath should be correctly quoted and match expected value",commandArgs, + // hasItems("/jetty/home with spaces/somejar.jar:/jetty/home with spaces/someotherjar.jar")); + // assertThat("args does not contain --exec",commandArgs,hasItems("--exec")); + // assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xms1024m")); + // assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xmx1024m")); + // assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty.xml")); + // assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-jmx.xml")); + // assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-logging.xml")); + // + // String commandLine = cmd.toString(); + // assertThat("cmd.toString() should be properly escaped",commandLine,containsString("-cp /jetty/home\\ with\\ " + // + "spaces/somejar.jar:/jetty/home\\ with\\ spaces/someotherjar.jar")); + // assertThat("cmd.toString() doesn't contain xml config files",commandLine,containsString(" jetty.xml jetty-jmx.xml jetty-logging.xml")); } private Classpath nastyWayToCreateAClasspathObject(String jettyHome) throws NoSuchFieldException, IllegalAccessException diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleTest.java index af8726f4a7b..beed91f3478 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ModuleTest.java @@ -44,7 +44,7 @@ public class ModuleTest Assert.assertThat("Module Parents Size",Module.getParentNames().size(),is(2)); Assert.assertThat("Module Parents",Module.getParentNames(),containsInAnyOrder("annotations","server")); Assert.assertThat("Module Xmls Size",Module.getXmls().size(),is(1)); - Assert.assertThat("Module Xmls",Module.getXmls(),contains("etc/jetty-websocket.xml")); + Assert.assertThat("Module Xmls",Module.getXmls(),contains("etc/jetty-websockets.xml")); Assert.assertThat("Module Options Size",Module.getLibs().size(),is(1)); Assert.assertThat("Module Options",Module.getLibs(),contains("lib/websockets/*.jar")); } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java index 101e128646d..83307347f14 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java @@ -39,7 +39,7 @@ public class ModulesTest Modules modules = new Modules(); modules.registerAll(basehome); - Assert.assertThat("Module count",modules.count(),is(11)); + Assert.assertThat("Module count",modules.count(),is(24)); } @Test @@ -141,7 +141,7 @@ public class ModulesTest expectedLibs.add("lib/jetty-http-${jetty.version}.jar"); expectedLibs.add("lib/jetty-continuation-${jetty.version}.jar"); expectedLibs.add("lib/jetty-server-${jetty.version}.jar"); - expectedLibs.add("lib/jetty-plus-${jetty.version}.xml"); + expectedLibs.add("lib/jetty-plus-${jetty.version}.jar"); expectedLibs.add("lib/jetty-annotations-${jetty.version}.jar"); expectedLibs.add("lib/annotations/*.jar"); expectedLibs.add("lib/websockets/*.jar"); @@ -155,7 +155,7 @@ public class ModulesTest expectedXmls.add("etc/jetty-http.xml"); expectedXmls.add("etc/jetty-plus.xml"); expectedXmls.add("etc/jetty-annotations.xml"); - expectedXmls.add("etc/jetty-websocket.xml"); + expectedXmls.add("etc/jetty-websockets.xml"); List actualXmls = modules.normalizeXmls(active); Assert.assertThat("Resolved XMLs: " + actualXmls,actualXmls,contains(expectedXmls.toArray())); diff --git a/jetty-start/src/test/resources/assert-home-with-jvm.txt b/jetty-start/src/test/resources/assert-home-with-jvm.txt new file mode 100644 index 00000000000..18337a5d691 --- /dev/null +++ b/jetty-start/src/test/resources/assert-home-with-jvm.txt @@ -0,0 +1,29 @@ +# 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 +XML|${jetty.home}/etc/jetty-logging.xml + +# The LIBs we expect (order is irrelevant) +LIB|${jetty.home}/lib/jetty-http-TEST.jar +LIB|${jetty.home}/lib/jetty-util-TEST.jar +LIB|${jetty.home}/lib/jetty-schemas-3.1.jar +LIB|${jetty.home}/lib/jetty-jmx-TEST.jar +LIB|${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar +LIB|${jetty.home}/lib/servlet-api-3.1.jar +LIB|${jetty.home}/lib/jetty-annotations-TEST.jar +LIB|${jetty.home}/lib/jetty-plus-TEST.jar +LIB|${jetty.home}/lib/jetty-io-TEST.jar +LIB|${jetty.home}/lib/jetty-continuation-TEST.jar +LIB|${jetty.home}/lib/annotations/org.objectweb.asm-TEST.jar +LIB|${jetty.home}/lib/jetty-server-TEST.jar + +# The Properties we expect (order is irrelevant) +# PROP|jetty.port=9090 + +# JVM Args +JVM|-Xms1024m +JVM|-Xms1024m diff --git a/jetty-start/src/test/resources/assert-home.txt b/jetty-start/src/test/resources/assert-home.txt new file mode 100644 index 00000000000..a0c1a8eaf37 --- /dev/null +++ b/jetty-start/src/test/resources/assert-home.txt @@ -0,0 +1,24 @@ +# 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/jetty-http-TEST.jar +LIB|${jetty.home}/lib/jetty-util-TEST.jar +LIB|${jetty.home}/lib/jetty-schemas-3.1.jar +LIB|${jetty.home}/lib/jetty-jmx-TEST.jar +LIB|${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar +LIB|${jetty.home}/lib/servlet-api-3.1.jar +LIB|${jetty.home}/lib/jetty-annotations-TEST.jar +LIB|${jetty.home}/lib/jetty-plus-TEST.jar +LIB|${jetty.home}/lib/jetty-io-TEST.jar +LIB|${jetty.home}/lib/jetty-continuation-TEST.jar +LIB|${jetty.home}/lib/annotations/org.objectweb.asm-TEST.jar +LIB|${jetty.home}/lib/jetty-server-TEST.jar + +# The Properties we expect (order is irrelevant) +PROP|jetty.port=9090 diff --git a/jetty-start/src/test/resources/usecases/home/etc/README.spnego b/jetty-start/src/test/resources/usecases/home/etc/README.spnego new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jdbcRealm.properties b/jetty-start/src/test/resources/usecases/home/etc/jdbcRealm.properties new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-annotations.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-annotations.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-contexts.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-contexts.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-debug.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-debug.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-demo.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-demo.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-deploy.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-deploy.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-http.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-http.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-https.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-https.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-ipaccess.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-ipaccess.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-jaas.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-jaas.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-jmx.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-jmx.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-logging.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-logging.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-lowresources.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-lowresources.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-monitor.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-monitor.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-plus.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-plus.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-proxy.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-proxy.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-requestlog.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-requestlog.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-rewrite.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-rewrite.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-setuid.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-setuid.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-spdy-proxy.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-spdy-proxy.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-spdy.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-spdy.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-ssl.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-ssl.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-started.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-started.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-stats.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-stats.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-testrealm.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-testrealm.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-webapps.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-webapps.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-websockets.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-websockets.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty-xinetd.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty-xinetd.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty.conf b/jetty-start/src/test/resources/usecases/home/etc/jetty.conf new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/jetty.xml b/jetty-start/src/test/resources/usecases/home/etc/jetty.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/keystore b/jetty-start/src/test/resources/usecases/home/etc/keystore new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/krb5.ini b/jetty-start/src/test/resources/usecases/home/etc/krb5.ini new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/realm.properties b/jetty-start/src/test/resources/usecases/home/etc/realm.properties new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/spnego.conf b/jetty-start/src/test/resources/usecases/home/etc/spnego.conf new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/spnego.properties b/jetty-start/src/test/resources/usecases/home/etc/spnego.properties new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/test-realm.xml b/jetty-start/src/test/resources/usecases/home/etc/test-realm.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/etc/webdefault.xml b/jetty-start/src/test/resources/usecases/home/etc/webdefault.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/annotations/javax.annotation-api-1.2.jar b/jetty-start/src/test/resources/usecases/home/lib/annotations/javax.annotation-api-1.2.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/annotations/org.objectweb.asm-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/annotations/org.objectweb.asm-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/ext/.nodelete b/jetty-start/src/test/resources/usecases/home/lib/ext/.nodelete new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-annotations-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-annotations-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-client-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-client-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-continuation-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-continuation-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-deploy-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-deploy-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-http-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-http-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-io-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-io-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-jaas-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-jaas-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-jmx-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-jmx-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-jndi-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-jndi-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-jsp-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-jsp-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-plus-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-plus-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-proxy-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-proxy-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-rewrite-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-rewrite-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-schemas-3.1.RC0.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-schemas-3.1.RC0.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-schemas-3.1.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-schemas-3.1.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-security-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-security-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-server-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-server-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-servlet-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-servlet-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-servlets-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-servlets-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-util-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-util-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-webapp-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-webapp-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jetty-xml-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/jetty-xml-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jndi/javax.activation-1.1.jar b/jetty-start/src/test/resources/usecases/home/lib/jndi/javax.activation-1.1.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jndi/javax.transaction-api-1.2.jar b/jetty-start/src/test/resources/usecases/home/lib/jndi/javax.transaction-api-1.2.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jsp/javax.el-3.0.0.jar b/jetty-start/src/test/resources/usecases/home/lib/jsp/javax.el-3.0.0.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jsp/javax.servlet.jsp-2.3.2.jar b/jetty-start/src/test/resources/usecases/home/lib/jsp/javax.servlet.jsp-2.3.2.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jsp/javax.servlet.jsp-api-2.3.1.jar b/jetty-start/src/test/resources/usecases/home/lib/jsp/javax.servlet.jsp-api-2.3.1.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jsp/javax.servlet.jsp.jstl-1.2.0.jar b/jetty-start/src/test/resources/usecases/home/lib/jsp/javax.servlet.jsp.jstl-1.2.0.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.jar b/jetty-start/src/test/resources/usecases/home/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/jsp/org.eclipse.jdt.core-3.8.2.jar b/jetty-start/src/test/resources/usecases/home/lib/jsp/org.eclipse.jdt.core-3.8.2.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/monitor/jetty-monitor-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/monitor/jetty-monitor-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/servlet-api-3.1.jar b/jetty-start/src/test/resources/usecases/home/lib/servlet-api-3.1.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/setuid/jetty-setuid-java-1.0.1.jar b/jetty-start/src/test/resources/usecases/home/lib/setuid/jetty-setuid-java-1.0.1.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/setuid/libsetuid-linux.so b/jetty-start/src/test/resources/usecases/home/lib/setuid/libsetuid-linux.so new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/setuid/libsetuid-osx.so b/jetty-start/src/test/resources/usecases/home/lib/setuid/libsetuid-osx.so new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-client-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-client-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-core-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-core-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-http-common-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-http-common-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-http-server-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-http-server-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-server-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/spdy/spdy-server-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/websocket/javax-websocket-client-impl-TEST.jar b/jetty-start/src/test/resources/usecases/home/lib/websocket/javax-websocket-client-impl-TEST.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/lib/websocket/javax.websocket-api-1.0.jar b/jetty-start/src/test/resources/usecases/home/lib/websocket/javax.websocket-api-1.0.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jetty-start/src/test/resources/usecases/home/modules/websocket.mod b/jetty-start/src/test/resources/usecases/home/modules/websocket.mod index 1984482f809..b8571fb12aa 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/websocket.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/websocket.mod @@ -10,5 +10,4 @@ DEPEND=annotations LIB=lib/websockets/*.jar # WebSocket needs websocket configuration -etc/jetty-websocket.xml - +etc/jetty-websockets.xml diff --git a/jetty-start/src/test/resources/usecases/home/resources/.nodelete b/jetty-start/src/test/resources/usecases/home/resources/.nodelete new file mode 100644 index 00000000000..e69de29bb2d From bddeb8cb775e6a61ed333d524f412d873e51732b Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Aug 2013 12:16:44 -0700 Subject: [PATCH 25/28] 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 From 5b2d9bc825826598b450db44c483acb1b69aee0c Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Aug 2013 12:45:52 -0700 Subject: [PATCH 26/28] More work to get jetty to start --- .../resources/start.d/000-jvm.ini.disabled | 27 --------- .../resources/start.d/000-npn.ini.disabled | 17 ------ .../src/main/resources/start.d/010-ext.ini | 3 - .../start.d/010-jmx-remote.ini.disabled | 9 --- .../main/resources/start.d/010-resources.ini | 3 - .../src/main/resources/start.d/100-jetty.ini | 21 ------- .../src/main/resources/start.d/110-jmx.ini | 8 --- .../src/main/resources/start.d/110-jsp.ini | 6 -- .../start.d/110-logging.ini.disabled | 11 ---- .../resources/start.d/110-setuid.ini.disabled | 14 ----- .../resources/start.d/200-ssl.ini.disabled | 18 ------ .../main/resources/start.d/200-websocket.ini | 6 -- .../src/main/resources/start.d/210-http.ini | 12 ---- .../resources/start.d/210-https.ini.disabled | 15 ----- .../resources/start.d/210-spdy.ini.disabled | 12 ---- .../resources/start.d/300-jaas.ini.disabled | 10 ---- .../resources/start.d/300-jndi.ini.disabled | 6 -- .../src/main/resources/start.d/300-plus.ini | 6 -- .../start.d/300-requestlog.ini.disabled | 11 ---- .../resources/start.d/310-annotations.ini | 9 --- .../start.d/320-websocket-annotations.ini | 9 --- .../resources/start.d/400-debug.ini.disabled | 1 - .../start.d/400-ipaccess.ini.disabled | 1 - .../start.d/400-lowresources.ini.disabled | 13 ----- .../start.d/400-rewrite.ini.disabled | 7 --- .../resources/start.d/400-stats.ini.disabled | 1 - .../src/main/resources/start.d/500-deploy.ini | 8 --- .../start.d/{900-demo.ini => demo.ini} | 15 +---- .../src/main/resources/start.ini | 53 ++++++------------ .../org/eclipse/jetty/start/Classpath.java | 3 + .../jetty/start/CommandLineBuilder.java | 4 +- .../java/org/eclipse/jetty/start/Main.java | 14 +++-- .../org/eclipse/jetty/start/StartArgs.java | 55 +++++++++++-------- jetty-start/src/test/resources/test-alt.xml | 1 - 34 files changed, 67 insertions(+), 342 deletions(-) delete mode 100644 jetty-distribution/src/main/resources/start.d/000-jvm.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/000-npn.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/010-ext.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/010-jmx-remote.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/010-resources.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/100-jetty.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/110-jmx.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/110-jsp.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/110-logging.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/110-setuid.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/200-ssl.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/200-websocket.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/210-http.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/210-https.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/210-spdy.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/300-jaas.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/300-jndi.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/300-plus.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/300-requestlog.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/310-annotations.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/320-websocket-annotations.ini delete mode 100644 jetty-distribution/src/main/resources/start.d/400-debug.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/400-ipaccess.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/400-lowresources.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/400-rewrite.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/400-stats.ini.disabled delete mode 100644 jetty-distribution/src/main/resources/start.d/500-deploy.ini rename jetty-distribution/src/main/resources/start.d/{900-demo.ini => demo.ini} (56%) delete mode 100644 jetty-start/src/test/resources/test-alt.xml diff --git a/jetty-distribution/src/main/resources/start.d/000-jvm.ini.disabled b/jetty-distribution/src/main/resources/start.d/000-jvm.ini.disabled deleted file mode 100644 index 939258b8713..00000000000 --- a/jetty-distribution/src/main/resources/start.d/000-jvm.ini.disabled +++ /dev/null @@ -1,27 +0,0 @@ - -#=========================================================== -# Configure JVM arguments. -# If JVM args are include in an ini file then --exec is needed -# to start a new JVM from start.jar with the extra args. -# If you wish to avoid an extra JVM running, place JVM args -# on the normal command line and do not use --exec -# -# IF USED, THIS MODULE WILL INVOKE AN EXTRA JVM INSTANCE!! -#----------------------------------------------------------- ---exec --Xmx2000m --Xmn512m --XX:+UseConcMarkSweepGC --XX:ParallelCMSThreads=2 --XX:+CMSClassUnloadingEnabled --XX:+UseCMSCompactAtFullCollection --XX:CMSInitiatingOccupancyFraction=80 -# -verbose:gc -# -XX:+PrintGCDateStamps -# -XX:+PrintGCTimeStamps -# -XX:+PrintGCDetails -# -XX:+PrintTenuringDistribution -# -XX:+PrintCommandLineFlags -# -XX:+DisableExplicitGC - -# -Dorg.apache.jasper.compiler.disablejsr199=true diff --git a/jetty-distribution/src/main/resources/start.d/000-npn.ini.disabled b/jetty-distribution/src/main/resources/start.d/000-npn.ini.disabled deleted file mode 100644 index b944d150cd7..00000000000 --- a/jetty-distribution/src/main/resources/start.d/000-npn.ini.disabled +++ /dev/null @@ -1,17 +0,0 @@ -#=========================================================== -# NPN Next Protocol Negotiation -# -# The SPDY and HTTP/2.0 connectors require NPN. The jar for -# NPN cannot be downloaded from eclipse. So the --download -# option is used to install the NPN jar if it does not already -# exist -# -#----------------------------------------------------------- - -DEFINE=npn -OPTION=npn - ---exec ---download=http://repo1.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar --Xbootclasspath/p:lib/npn/npn-boot-1.1.5.v20130313.jar - diff --git a/jetty-distribution/src/main/resources/start.d/010-ext.ini b/jetty-distribution/src/main/resources/start.d/010-ext.ini deleted file mode 100644 index d4cb1eecf86..00000000000 --- a/jetty-distribution/src/main/resources/start.d/010-ext.ini +++ /dev/null @@ -1,3 +0,0 @@ -# Add libraries from lib/ext to the classpath - -OPTION=ext diff --git a/jetty-distribution/src/main/resources/start.d/010-jmx-remote.ini.disabled b/jetty-distribution/src/main/resources/start.d/010-jmx-remote.ini.disabled deleted file mode 100644 index 6ee25430de4..00000000000 --- a/jetty-distribution/src/main/resources/start.d/010-jmx-remote.ini.disabled +++ /dev/null @@ -1,9 +0,0 @@ -#=========================================================== -# JMX Management -#----------------------------------------------------------- - -jetty.jmxrmihost=localhost -jetty.jmxrmiport=1099 - ---exec --Dcom.sun.management.jmxremote \ No newline at end of file diff --git a/jetty-distribution/src/main/resources/start.d/010-resources.ini b/jetty-distribution/src/main/resources/start.d/010-resources.ini deleted file mode 100644 index b5fa4fdbd01..00000000000 --- a/jetty-distribution/src/main/resources/start.d/010-resources.ini +++ /dev/null @@ -1,3 +0,0 @@ -# Add the resources directory to the classpath - -OPTION=resources diff --git a/jetty-distribution/src/main/resources/start.d/100-jetty.ini b/jetty-distribution/src/main/resources/start.d/100-jetty.ini deleted file mode 100644 index dd40dedf807..00000000000 --- a/jetty-distribution/src/main/resources/start.d/100-jetty.ini +++ /dev/null @@ -1,21 +0,0 @@ - -#=========================================================== -# Default Server Options -# Use the core server jars with websocket on the classpath -# Add the contents of the resources directory to the classpath -# Add jars discovered in lib/ext to the classpath -# Include the core jetty configuration file -#----------------------------------------------------------- -DEFINE=jetty -OPTION=jetty - -threads.min=10 -threads.max=200 -threads.timeout=60000 -#jetty.host=myhost.com -jetty.dump.start=false -jetty.dump.stop=false -#jetty.logs=/var/log/jetty - -OPTION=Server -etc/jetty.xml diff --git a/jetty-distribution/src/main/resources/start.d/110-jmx.ini b/jetty-distribution/src/main/resources/start.d/110-jmx.ini deleted file mode 100644 index 9422dda6872..00000000000 --- a/jetty-distribution/src/main/resources/start.d/110-jmx.ini +++ /dev/null @@ -1,8 +0,0 @@ -#=========================================================== -# JMX Management -#----------------------------------------------------------- - -OPTION=jmx -DEPEND=jetty - -etc/jetty-jmx.xml diff --git a/jetty-distribution/src/main/resources/start.d/110-jsp.ini b/jetty-distribution/src/main/resources/start.d/110-jsp.ini deleted file mode 100644 index 9a502210359..00000000000 --- a/jetty-distribution/src/main/resources/start.d/110-jsp.ini +++ /dev/null @@ -1,6 +0,0 @@ -#=========================================================== -# Java Server Pages -#----------------------------------------------------------- - -OPTION=jsp -DEPEND=jetty diff --git a/jetty-distribution/src/main/resources/start.d/110-logging.ini.disabled b/jetty-distribution/src/main/resources/start.d/110-logging.ini.disabled deleted file mode 100644 index cb98680ba98..00000000000 --- a/jetty-distribution/src/main/resources/start.d/110-logging.ini.disabled +++ /dev/null @@ -1,11 +0,0 @@ -#=========================================================== -# stderr/stdout logging. -# The following configuration will redirect stderr and stdout -# to file which is rolled over daily. -#----------------------------------------------------------- - -DEPEND=jetty - -jetty.log.retain=90 - -etc/jetty-logging.xml diff --git a/jetty-distribution/src/main/resources/start.d/110-setuid.ini.disabled b/jetty-distribution/src/main/resources/start.d/110-setuid.ini.disabled deleted file mode 100644 index dc1219a8c61..00000000000 --- a/jetty-distribution/src/main/resources/start.d/110-setuid.ini.disabled +++ /dev/null @@ -1,14 +0,0 @@ -#=========================================================== -# Enable SetUID -# The default user and group is 'jetty' and if you are -# starting as root you must change the run privledged to true -#----------------------------------------------------------- - -jetty.startServerAsPrivileged=false -jetty.username=jetty -jetty.groupname=jetty -jetty.umask=002 - -OPTION=setuid - -etc/jetty-setuid.xml diff --git a/jetty-distribution/src/main/resources/start.d/200-ssl.ini.disabled b/jetty-distribution/src/main/resources/start.d/200-ssl.ini.disabled deleted file mode 100644 index a0d04715771..00000000000 --- a/jetty-distribution/src/main/resources/start.d/200-ssl.ini.disabled +++ /dev/null @@ -1,18 +0,0 @@ -#=========================================================== -# SSL Context -# Create the keystore and trust store for use by -# HTTPS and SPDY -#----------------------------------------------------------- - -jetty.keystore=etc/keystore -jetty.keystore.password=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4 -jetty.keymanager.password=OBF:1u2u1wml1z7s1z7a1wnl1u2g -jetty.truststore=etc/keystore -jetty.truststore.password=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4 -jetty.secure.port=8443 - -DEPEND=jetty -DEFINE=ssl -OPTION=ssl - -etc/jetty-ssl.xml diff --git a/jetty-distribution/src/main/resources/start.d/200-websocket.ini b/jetty-distribution/src/main/resources/start.d/200-websocket.ini deleted file mode 100644 index 0cfd0f5a7f7..00000000000 --- a/jetty-distribution/src/main/resources/start.d/200-websocket.ini +++ /dev/null @@ -1,6 +0,0 @@ -#=========================================================== -# WebSocket Support -#----------------------------------------------------------- - -DEPEND=jetty -OPTION=websocket diff --git a/jetty-distribution/src/main/resources/start.d/210-http.ini b/jetty-distribution/src/main/resources/start.d/210-http.ini deleted file mode 100644 index 062b907d958..00000000000 --- a/jetty-distribution/src/main/resources/start.d/210-http.ini +++ /dev/null @@ -1,12 +0,0 @@ -#=========================================================== -# HTTP Connector -#----------------------------------------------------------- - -jetty.port=8080 -http.timeout=30000 - -DEPEND=jetty -DEFINE=http -OPTION=http - -etc/jetty-http.xml diff --git a/jetty-distribution/src/main/resources/start.d/210-https.ini.disabled b/jetty-distribution/src/main/resources/start.d/210-https.ini.disabled deleted file mode 100644 index f518d158164..00000000000 --- a/jetty-distribution/src/main/resources/start.d/210-https.ini.disabled +++ /dev/null @@ -1,15 +0,0 @@ -#=========================================================== -# HTTPS Connector -# Must be used with jetty-ssl.xml -#----------------------------------------------------------- - -jetty.https.port=8443 - -EXCLUDE=spdy - -DEFINE=https -OPTION=https -DEPEND=ssl - -etc/jetty-https.xml - diff --git a/jetty-distribution/src/main/resources/start.d/210-spdy.ini.disabled b/jetty-distribution/src/main/resources/start.d/210-spdy.ini.disabled deleted file mode 100644 index d6f70c38d2c..00000000000 --- a/jetty-distribution/src/main/resources/start.d/210-spdy.ini.disabled +++ /dev/null @@ -1,12 +0,0 @@ -#=========================================================== -# SPDY Connector -#----------------------------------------------------------- - -jetty.spdy.port=8443 - -EXCLUDE=https - -OPTION=spdy -DEPEND=npn,ssl - -etc/jetty-spdy.xml diff --git a/jetty-distribution/src/main/resources/start.d/300-jaas.ini.disabled b/jetty-distribution/src/main/resources/start.d/300-jaas.ini.disabled deleted file mode 100644 index 2d10e7f9079..00000000000 --- a/jetty-distribution/src/main/resources/start.d/300-jaas.ini.disabled +++ /dev/null @@ -1,10 +0,0 @@ -# =========================================================== -# Enable JAAS -# ----------------------------------------------------------- - -jaas.login.conf=etc/login.conf - -OPTION=jaas -EXCLUDE=demo - -etc/jetty-jaas.xml diff --git a/jetty-distribution/src/main/resources/start.d/300-jndi.ini.disabled b/jetty-distribution/src/main/resources/start.d/300-jndi.ini.disabled deleted file mode 100644 index f07ab9f5b7f..00000000000 --- a/jetty-distribution/src/main/resources/start.d/300-jndi.ini.disabled +++ /dev/null @@ -1,6 +0,0 @@ -# =========================================================== -# Enable JNDI -# ----------------------------------------------------------- - -OPTION=jndi -EXCLUDE=demo diff --git a/jetty-distribution/src/main/resources/start.d/300-plus.ini b/jetty-distribution/src/main/resources/start.d/300-plus.ini deleted file mode 100644 index f446f497730..00000000000 --- a/jetty-distribution/src/main/resources/start.d/300-plus.ini +++ /dev/null @@ -1,6 +0,0 @@ -# =========================================================== -# Enable additional webapp environment configurators -# ----------------------------------------------------------- - -OPTION=plus -etc/jetty-plus.xml diff --git a/jetty-distribution/src/main/resources/start.d/300-requestlog.ini.disabled b/jetty-distribution/src/main/resources/start.d/300-requestlog.ini.disabled deleted file mode 100644 index f4b73711f16..00000000000 --- a/jetty-distribution/src/main/resources/start.d/300-requestlog.ini.disabled +++ /dev/null @@ -1,11 +0,0 @@ - -#=========================================================== -# Request logger -# Will add a handler to log all HTTP requests to a standard -# request log format file. -#----------------------------------------------------------- - -requestlog.retain=90 -requestlog.append=true -requestlog.extended=true -etc/jetty-requestlog.xml \ No newline at end of file diff --git a/jetty-distribution/src/main/resources/start.d/310-annotations.ini b/jetty-distribution/src/main/resources/start.d/310-annotations.ini deleted file mode 100644 index 8e0d9639de3..00000000000 --- a/jetty-distribution/src/main/resources/start.d/310-annotations.ini +++ /dev/null @@ -1,9 +0,0 @@ -# =========================================================== -# Enable servlet 3.1 annotations -# ----------------------------------------------------------- - -OPTION=annotations -DEPEND=plus - -etc/jetty-annotations.xml - diff --git a/jetty-distribution/src/main/resources/start.d/320-websocket-annotations.ini b/jetty-distribution/src/main/resources/start.d/320-websocket-annotations.ini deleted file mode 100644 index 5ceac0b69ac..00000000000 --- a/jetty-distribution/src/main/resources/start.d/320-websocket-annotations.ini +++ /dev/null @@ -1,9 +0,0 @@ -#=========================================================== -# WebSocket Annotations Support -#----------------------------------------------------------- - -DEFINE=websocket-annotations -OPTION=websocket-annotations -DEPEND=websocket - -etc/jetty-websockets.xml diff --git a/jetty-distribution/src/main/resources/start.d/400-debug.ini.disabled b/jetty-distribution/src/main/resources/start.d/400-debug.ini.disabled deleted file mode 100644 index d2f69bb8101..00000000000 --- a/jetty-distribution/src/main/resources/start.d/400-debug.ini.disabled +++ /dev/null @@ -1 +0,0 @@ -etc/jetty-debug.xml diff --git a/jetty-distribution/src/main/resources/start.d/400-ipaccess.ini.disabled b/jetty-distribution/src/main/resources/start.d/400-ipaccess.ini.disabled deleted file mode 100644 index d272540be4f..00000000000 --- a/jetty-distribution/src/main/resources/start.d/400-ipaccess.ini.disabled +++ /dev/null @@ -1 +0,0 @@ -etc/jetty-ipaccess.xml diff --git a/jetty-distribution/src/main/resources/start.d/400-lowresources.ini.disabled b/jetty-distribution/src/main/resources/start.d/400-lowresources.ini.disabled deleted file mode 100644 index 5df05ebb6aa..00000000000 --- a/jetty-distribution/src/main/resources/start.d/400-lowresources.ini.disabled +++ /dev/null @@ -1,13 +0,0 @@ -#=========================================================== -# Low resource management -#----------------------------------------------------------- - -lowresources.period=1050 -lowresources.lowResourcesIdleTimeout=200 -lowresources.monitorThreads=true -lowresources.maxConnections=0 -lowresources.maxMemory=0 -lowresources.maxLowResourcesTime=5000 - -etc/jetty-lowresources.xml - diff --git a/jetty-distribution/src/main/resources/start.d/400-rewrite.ini.disabled b/jetty-distribution/src/main/resources/start.d/400-rewrite.ini.disabled deleted file mode 100644 index 0af34782037..00000000000 --- a/jetty-distribution/src/main/resources/start.d/400-rewrite.ini.disabled +++ /dev/null @@ -1,7 +0,0 @@ -# =========================================================== -# Enable rewrite handler -# ----------------------------------------------------------- - -OPTION=rewrite -EXCLUDE=demo -etc/jetty-rewrite.xml diff --git a/jetty-distribution/src/main/resources/start.d/400-stats.ini.disabled b/jetty-distribution/src/main/resources/start.d/400-stats.ini.disabled deleted file mode 100644 index d01ddfc30b0..00000000000 --- a/jetty-distribution/src/main/resources/start.d/400-stats.ini.disabled +++ /dev/null @@ -1 +0,0 @@ -etc/jetty-stats.xml diff --git a/jetty-distribution/src/main/resources/start.d/500-deploy.ini b/jetty-distribution/src/main/resources/start.d/500-deploy.ini deleted file mode 100644 index b8f9a40a96e..00000000000 --- a/jetty-distribution/src/main/resources/start.d/500-deploy.ini +++ /dev/null @@ -1,8 +0,0 @@ -#=========================================================== -# Webapplication Deployer -#----------------------------------------------------------- - -DEFINE=deploy -OPTION=deploy -DEPEND=jetty -etc/jetty-deploy.xml diff --git a/jetty-distribution/src/main/resources/start.d/900-demo.ini b/jetty-distribution/src/main/resources/start.d/demo.ini similarity index 56% rename from jetty-distribution/src/main/resources/start.d/900-demo.ini rename to jetty-distribution/src/main/resources/start.d/demo.ini index 7f053aacf9a..037e743f2c9 100644 --- a/jetty-distribution/src/main/resources/start.d/900-demo.ini +++ b/jetty-distribution/src/main/resources/start.d/demo.ini @@ -1,4 +1,3 @@ - # =========================================================== # Enable the demonstration web applications # @@ -6,22 +5,12 @@ # the start.d directory or rename it to not end with ".ini" # =========================================================== - - -# The following options are explicitly configured for the demo -# in this file. Thus they cannot be used with the normal -# activation of them +MODULES=jaas,jndi,rewrite,client,annotations,websocket jaas.login.conf=webapps.demo/test-jaas.d/login.conf -EXCLUDE=jaas,jndi,rewrite -OPTION=jaas,jndi,rewrite,client - -etc/jetty-rewrite.xml -etc/jetty-jaas.xml # Activate the demo options and configurations -OPTION=jndi.demo +MODULES=jndi.demo etc/jetty-demo.xml etc/test-realm.xml -DEPEND=ext,resources,http,plus,annotations,websocket-annotations,deploy diff --git a/jetty-distribution/src/main/resources/start.ini b/jetty-distribution/src/main/resources/start.ini index 3d7646db818..78d063a2a91 100644 --- a/jetty-distribution/src/main/resources/start.ini +++ b/jetty-distribution/src/main/resources/start.ini @@ -57,11 +57,9 @@ # -XX:+PrintTenuringDistribution # -XX:+PrintCommandLineFlags # -XX:+DisableExplicitGC - # -Dorg.apache.jasper.compiler.disablejsr199=true - #=========================================================== # Default Server Options # Use the core server jars with websocket on the classpath @@ -69,7 +67,6 @@ # Add jars discovered in lib/ext to the classpath # Include the core jetty configuration file #----------------------------------------------------------- -OPTIONS=Server,websocket,resources,ext threads.min=10 threads.max=200 threads.timeout=60000 @@ -77,33 +74,30 @@ threads.timeout=60000 jetty.dump.start=false jetty.dump.stop=false -etc/jetty.xml - #=========================================================== # JMX Management # To enable remote JMX access uncomment jmxremote and # enable --exec #----------------------------------------------------------- -OPTIONS=jmx +MODULE=jmx # jetty.jmxrmihost=localhost # jetty.jmxrmiport=1099 # -Dcom.sun.management.jmxremote -etc/jetty-jmx.xml #=========================================================== # Java Server Pages #----------------------------------------------------------- -OPTIONS=jsp +MODULE=jsp #=========================================================== # Request logger # Will add a handler to log all HTTP requests to a standard # request log format file. #----------------------------------------------------------- +# MODULE=requestlog # requestlog.retain=90 # requestlog.append=true # requestlog.extended=true -# etc/jetty-requestlog.xml #=========================================================== @@ -111,29 +105,27 @@ OPTIONS=jsp # The following configuration will redirect stderr and stdout # to file which is rolled over daily. #----------------------------------------------------------- +# MODULE=logging # jetty.log.retain=90 -# etc/jetty-logging.xml - #=========================================================== # Enable SetUID # The default user and group is 'jetty' and if you are # starting as root you must change the run privledged to true #----------------------------------------------------------- -# OPTIONS=setuid +# MODULE=setuid # jetty.startServerAsPrivileged=false # jetty.username=jetty # jetty.groupname=jetty # jetty.umask=002 -# etc/jetty-setuid.xml #=========================================================== # HTTP Connector #----------------------------------------------------------- +MODULE=http jetty.port=8080 http.timeout=30000 -etc/jetty-http.xml #=========================================================== @@ -147,15 +139,14 @@ etc/jetty-http.xml # jetty.truststore=etc/keystore # jetty.truststore.password=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4 # jetty.secure.port=8443 -# etc/jetty-ssl.xml #=========================================================== # HTTPS Connector # Must be used with jetty-ssl.xml #----------------------------------------------------------- +MODULE=https # jetty.https.port=8443 -# etc/jetty-https.xml #=========================================================== @@ -176,62 +167,54 @@ etc/jetty-http.xml # SPDY Connector # Requires SSL Context and NPN from above #----------------------------------------------------------- -# OPTIONS=spdy +# MODULE=spdy # jetty.spdy.port=8443 -# etc/jetty-spdy.xml #=========================================================== # Webapplication Deployer #----------------------------------------------------------- -etc/jetty-deploy.xml - +MODULE=deploy # =========================================================== # Enable JAAS # ----------------------------------------------------------- -# OPTIONS=jaas +# MODULE=jaas # jaas.login.conf=etc/login.conf -# etc/jetty-jaas.xml # =========================================================== # Enable JNDI # ----------------------------------------------------------- -# OPTIONS=jndi +# MODULE=jndi # =========================================================== # Enable additional webapp environment configurators # ----------------------------------------------------------- -# OPTIONS=plus -# etc/jetty-plus.xml +# MODULE=plus # =========================================================== # Enable servlet 3.1 annotations # ----------------------------------------------------------- -# OPTIONS=annotations -# etc/jetty-annotations.xml +# MODULE=annotations #=========================================================== # Other server features #----------------------------------------------------------- -# etc/jetty-debug.xml -# etc/jetty-ipaccess.xml -# etc/jetty-stats.xml +# MODULE=debug +# MODULE=ipaccess +# MODULE=stats #=========================================================== # Low resource managment #----------------------------------------------------------- +# MODULE=lowresources # lowresources.period=1050 # lowresources.lowResourcesIdleTimeout=200 # lowresources.monitorThreads=true # lowresources.maxConnections=0 # lowresources.maxMemory=0 # lowresources.maxLowResourcesTime=5000 -# etc/jetty-lowresources.xml - -#=========================================================== -# The start.d directory contains the active start.ini fragments -start.d/ +MODULES=webapp diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java index 488f09e0447..3333b52d613 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java @@ -132,11 +132,14 @@ public class Classpath implements Iterable try { urls[i] = elements.get(i).toURI().toURL(); + StartLog.debug("URLClassLoader.url[%d] = %s",i,urls[i]); } catch (MalformedURLException e) { + StartLog.warn(e); } } + StartLog.debug("Loaded %d URLs into URLClassLoader",urls.length); ClassLoader parent = Thread.currentThread().getContextClassLoader(); if (parent == null) 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 3d088d2b9fe..d0a4197a998 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 @@ -98,12 +98,12 @@ public class CommandLineBuilder public CommandLineBuilder() { - this(findJavaBin()); + args = new ArrayList(); } public CommandLineBuilder(String bin) { - args = new ArrayList(); + this(); args.add(bin); } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 0f75f5b0606..060eeba4837 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -90,6 +90,7 @@ public class Main } catch (UsageException e) { + System.err.println(e.getMessage()); usageExit(e.getCause(),e.getExitCode()); } catch (Throwable e) @@ -244,8 +245,9 @@ public class Main StartLog.debug("%s - %s",invoked_class,invoked_class.getPackage().getImplementationVersion()); - CommandLineBuilder cmd = args.getMainArgs(baseHome); + CommandLineBuilder cmd = args.getMainArgs(baseHome,false); String argArray[] = cmd.getArgs().toArray(new String[0]); + StartLog.debug("Command Line Args: %s",cmd.toString()); Class[] method_param_types = new Class[] { argArray.getClass() }; @@ -284,6 +286,8 @@ public class Main StartLog.debug("jetty.home=%s",baseHome.getHome()); StartLog.debug("jetty.base=%s",baseHome.getBase()); + args.addSystemProperty("jetty.home",baseHome.getHome()); + args.addSystemProperty("jetty.base",baseHome.getBase()); // ------------------------------------------------------------ // 3) Load Inis @@ -336,10 +340,10 @@ public class Main // 7) Lib & XML Expansion / Resolution args.expandModules(baseHome,activeModules); - + // 8) Resolve Extra XMLs args.resolveExtraXmls(baseHome); - + return args; } @@ -423,7 +427,7 @@ public class Main // Show Command Line to execute Jetty if (args.isDryRun()) { - CommandLineBuilder cmd = args.getMainArgs(baseHome); + CommandLineBuilder cmd = args.getMainArgs(baseHome,true); System.out.println(cmd.toString()); } @@ -442,7 +446,7 @@ public class Main // execute Jetty in another JVM if (args.isExec()) { - CommandLineBuilder cmd = args.getMainArgs(baseHome); + CommandLineBuilder cmd = args.getMainArgs(baseHome,true); ProcessBuilder pbuilder = new ProcessBuilder(cmd.getArgs()); final Process process = pbuilder.start(); Runtime.getRuntime().addShutdownHook(new Thread() 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 09045686bfa..9eb8a5ff81c 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 @@ -60,7 +60,7 @@ public class StartArgs } // TODO: might make sense to declare this in modules/base.mod - private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration.class"; + private static final String SERVER_MAIN = "org.eclipse.jetty.xml.XmlConfiguration"; private List commandLine = new ArrayList<>(); private List enabledModules = new ArrayList<>(); @@ -89,6 +89,12 @@ public class StartArgs classpath = new Classpath(); } + public void addSystemProperty(String key, String value) + { + this.systemPropertyKeys.add(key); + System.setProperty(key,value); + } + private void addUniqueXmlFile(String xmlRef, File xmlfile) throws IOException { if (!FS.canReadFile(xmlfile)) @@ -221,33 +227,38 @@ public class StartArgs return this.enabledModules; } - public CommandLineBuilder getMainArgs(BaseHome baseHome) throws IOException + public CommandLineBuilder getMainArgs(BaseHome baseHome, boolean addJavaInit) throws IOException { CommandLineBuilder cmd = new CommandLineBuilder(); - for (String x : jvmArgs) + if (addJavaInit) { - cmd.addArg(x); + cmd.addArg(CommandLineBuilder.findJavaBin()); + + for (String x : jvmArgs) + { + cmd.addArg(x); + } + + cmd.addRawArg("-Djetty.home=" + baseHome.getHome()); + cmd.addRawArg("-Djetty.base=" + baseHome.getBase()); + + // Special Stop/Shutdown properties + ensureSystemPropertySet("STOP.PORT"); + ensureSystemPropertySet("STOP.KEY"); + + // System Properties + for (String propKey : systemPropertyKeys) + { + String value = System.getProperty(propKey); + cmd.addEqualsArg("-D" + propKey,value); + } + + cmd.addArg("-cp"); + cmd.addRawArg(classpath.toString()); + cmd.addRawArg(getMainClassname()); } - cmd.addRawArg("-Djetty.home=" + baseHome.getHome()); - cmd.addRawArg("-Djetty.base=" + baseHome.getBase()); - - // Special Stop/Shutdown properties - ensureSystemPropertySet("STOP.PORT"); - ensureSystemPropertySet("STOP.KEY"); - - // System Properties - for (String propKey : systemPropertyKeys) - { - String value = System.getProperty(propKey); - cmd.addEqualsArg("-D" + propKey,value); - } - - cmd.addArg("-cp"); - cmd.addRawArg(classpath.toString()); - cmd.addRawArg(getMainClassname()); - // Check if we need to pass properties as a file if (properties.size() > 0) { diff --git a/jetty-start/src/test/resources/test-alt.xml b/jetty-start/src/test/resources/test-alt.xml deleted file mode 100644 index 38c02081e6e..00000000000 --- a/jetty-start/src/test/resources/test-alt.xml +++ /dev/null @@ -1 +0,0 @@ - From b8e1f42b379e3c046660da7e0dd79f322d824675 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Aug 2013 14:21:52 -0700 Subject: [PATCH 27/28] 414635 Modular start.d and jetty.base property + More mod cleanup + Adding cyclic module reference detection and reporting --- jetty-jndi/src/main/config/modules/jndi.mod | 3 -- jetty-plus/src/main/config/modules/plus.mod | 2 + jetty-servlet/pom.xml | 17 ++++++++ .../java/org/eclipse/jetty/start/Modules.java | 39 ++++++++++++++++++- .../org/eclipse/jetty/start/ModulesTest.java | 11 +++++- .../test/resources/assert-home-with-jvm.txt | 23 ++++++----- .../src/test/resources/assert-home.txt | 23 ++++++----- .../resources/usecases/home/modules/jndi.mod | 3 -- .../resources/usecases/home/modules/plus.mod | 2 + .../resources/usecases/home/modules/proxy.mod | 1 + .../usecases/home/modules/security.mod | 7 ++++ .../usecases/home/modules/server.mod | 1 + .../usecases/home/modules/servlet.mod | 7 ++++ .../resources/usecases/home/modules/spdy.mod | 2 + .../usecases/home/modules/webapp.mod | 2 +- .../usecases/home/modules/websocket.mod | 1 + 16 files changed, 116 insertions(+), 28 deletions(-) create mode 100644 jetty-start/src/test/resources/usecases/home/modules/security.mod create mode 100644 jetty-start/src/test/resources/usecases/home/modules/servlet.mod diff --git a/jetty-jndi/src/main/config/modules/jndi.mod b/jetty-jndi/src/main/config/modules/jndi.mod index de3087bd26f..cfdcc526142 100644 --- a/jetty-jndi/src/main/config/modules/jndi.mod +++ b/jetty-jndi/src/main/config/modules/jndi.mod @@ -3,10 +3,7 @@ # DEPEND=server -DEPEND=plus LIB=lib/jetty-jndi-${jetty.version}.jar LIB=lib/jndi/*.jar -# Annotations needs annotations configuration -etc/jetty-server.xml diff --git a/jetty-plus/src/main/config/modules/plus.mod b/jetty-plus/src/main/config/modules/plus.mod index 31d8e76b95c..caa799376a6 100644 --- a/jetty-plus/src/main/config/modules/plus.mod +++ b/jetty-plus/src/main/config/modules/plus.mod @@ -3,6 +3,8 @@ # DEPEND=server +DEPEND=security +DEPEND=jndi LIB=lib/jetty-plus-${jetty.version}.jar diff --git a/jetty-servlet/pom.xml b/jetty-servlet/pom.xml index c93342fc71c..2fb71301dc5 100644 --- a/jetty-servlet/pom.xml +++ b/jetty-servlet/pom.xml @@ -53,6 +53,23 @@ + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + config + + + + + org.codehaus.mojo findbugs-maven-plugin diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java index d72c943c741..25291aedd4c 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java @@ -29,6 +29,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Stack; /** * Access for all modules declared, as well as what is enabled. @@ -59,8 +60,6 @@ public class Modules implements Iterable */ public void buildGraph() { - // TODO: Validate / Enforce Directed Acyclic Graph - // Connect edges for (Module module : modules.values()) { @@ -75,6 +74,15 @@ public class Modules implements Iterable } } + // Verify there is no cyclic references + Stack refs = new Stack<>(); + for (Module module : modules.values()) + { + refs.push(module.getName()); + assertNoCycle(module,refs); + refs.pop(); + } + // Calculate depth of all modules for sorting later for (Module module : modules.values()) { @@ -85,6 +93,33 @@ public class Modules implements Iterable } } + private void assertNoCycle(Module module, Stack refs) + { + for (Module parent : module.getParentEdges()) + { + if (refs.contains(parent.getName())) + { + // Cycle detected. + StringBuilder err = new StringBuilder(); + err.append("A cyclic reference in the modules has been detected: "); + for (int i = 0; i < refs.size(); i++) + { + if (i > 0) + { + err.append(" -> "); + } + err.append(refs.get(i)); + } + err.append(" -> ").append(parent.getName()); + throw new IllegalStateException(err.toString()); + } + + refs.push(parent.getName()); + assertNoCycle(parent,refs); + refs.pop(); + } + } + public Integer count() { return modules.size(); diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java index 83307347f14..0d6addd7ecb 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ModulesTest.java @@ -39,7 +39,7 @@ public class ModulesTest Modules modules = new Modules(); modules.registerAll(basehome); - Assert.assertThat("Module count",modules.count(),is(24)); + Assert.assertThat("Module count",modules.count(),is(26)); } @Test @@ -63,6 +63,7 @@ public class ModulesTest // Assert names are correct, and in the right order List expectedNames = new ArrayList<>(); expectedNames.add("base"); + expectedNames.add("xml"); expectedNames.add("server"); expectedNames.add("http"); @@ -78,6 +79,7 @@ public class ModulesTest List expectedLibs = new ArrayList<>(); expectedLibs.add("lib/jetty-util-${jetty.version}.jar"); expectedLibs.add("lib/jetty-io-${jetty.version}.jar"); + expectedLibs.add("lib/jetty-xml-${jetty.version}.jar"); expectedLibs.add("lib/servlet-api-3.1.jar"); expectedLibs.add("lib/jetty-schemas-3.1.jar"); expectedLibs.add("lib/jetty-http-${jetty.version}.jar"); @@ -118,8 +120,11 @@ public class ModulesTest // Assert names are correct, and in the right order List expectedNames = new ArrayList<>(); expectedNames.add("base"); + expectedNames.add("xml"); expectedNames.add("server"); expectedNames.add("http"); + expectedNames.add("jndi"); + expectedNames.add("security"); expectedNames.add("plus"); expectedNames.add("annotations"); expectedNames.add("websocket"); @@ -136,11 +141,15 @@ public class ModulesTest List expectedLibs = new ArrayList<>(); expectedLibs.add("lib/jetty-util-${jetty.version}.jar"); expectedLibs.add("lib/jetty-io-${jetty.version}.jar"); + expectedLibs.add("lib/jetty-xml-${jetty.version}.jar"); expectedLibs.add("lib/servlet-api-3.1.jar"); expectedLibs.add("lib/jetty-schemas-3.1.jar"); expectedLibs.add("lib/jetty-http-${jetty.version}.jar"); expectedLibs.add("lib/jetty-continuation-${jetty.version}.jar"); expectedLibs.add("lib/jetty-server-${jetty.version}.jar"); + expectedLibs.add("lib/jetty-jndi-${jetty.version}.jar"); + expectedLibs.add("lib/jndi/*.jar"); + expectedLibs.add("lib/jetty-security-${jetty.version}.jar"); expectedLibs.add("lib/jetty-plus-${jetty.version}.jar"); expectedLibs.add("lib/jetty-annotations-${jetty.version}.jar"); expectedLibs.add("lib/annotations/*.jar"); 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 18337a5d691..03d38cea2d1 100644 --- a/jetty-start/src/test/resources/assert-home-with-jvm.txt +++ b/jetty-start/src/test/resources/assert-home-with-jvm.txt @@ -8,18 +8,23 @@ XML|${jetty.home}/etc/jetty-websockets.xml XML|${jetty.home}/etc/jetty-logging.xml # The LIBs we expect (order is irrelevant) -LIB|${jetty.home}/lib/jetty-http-TEST.jar -LIB|${jetty.home}/lib/jetty-util-TEST.jar -LIB|${jetty.home}/lib/jetty-schemas-3.1.jar -LIB|${jetty.home}/lib/jetty-jmx-TEST.jar LIB|${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar -LIB|${jetty.home}/lib/servlet-api-3.1.jar -LIB|${jetty.home}/lib/jetty-annotations-TEST.jar -LIB|${jetty.home}/lib/jetty-plus-TEST.jar -LIB|${jetty.home}/lib/jetty-io-TEST.jar -LIB|${jetty.home}/lib/jetty-continuation-TEST.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) # PROP|jetty.port=9090 diff --git a/jetty-start/src/test/resources/assert-home.txt b/jetty-start/src/test/resources/assert-home.txt index a0c1a8eaf37..1349723c154 100644 --- a/jetty-start/src/test/resources/assert-home.txt +++ b/jetty-start/src/test/resources/assert-home.txt @@ -7,18 +7,23 @@ 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/jetty-http-TEST.jar -LIB|${jetty.home}/lib/jetty-util-TEST.jar -LIB|${jetty.home}/lib/jetty-schemas-3.1.jar -LIB|${jetty.home}/lib/jetty-jmx-TEST.jar LIB|${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar -LIB|${jetty.home}/lib/servlet-api-3.1.jar -LIB|${jetty.home}/lib/jetty-annotations-TEST.jar -LIB|${jetty.home}/lib/jetty-plus-TEST.jar -LIB|${jetty.home}/lib/jetty-io-TEST.jar -LIB|${jetty.home}/lib/jetty-continuation-TEST.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) PROP|jetty.port=9090 diff --git a/jetty-start/src/test/resources/usecases/home/modules/jndi.mod b/jetty-start/src/test/resources/usecases/home/modules/jndi.mod index de3087bd26f..cfdcc526142 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/jndi.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/jndi.mod @@ -3,10 +3,7 @@ # DEPEND=server -DEPEND=plus LIB=lib/jetty-jndi-${jetty.version}.jar LIB=lib/jndi/*.jar -# Annotations needs annotations configuration -etc/jetty-server.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/plus.mod b/jetty-start/src/test/resources/usecases/home/modules/plus.mod index 31d8e76b95c..caa799376a6 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/plus.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/plus.mod @@ -3,6 +3,8 @@ # DEPEND=server +DEPEND=security +DEPEND=jndi LIB=lib/jetty-plus-${jetty.version}.jar diff --git a/jetty-start/src/test/resources/usecases/home/modules/proxy.mod b/jetty-start/src/test/resources/usecases/home/modules/proxy.mod index 9e2bc46db8c..5ab6e70a880 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/proxy.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/proxy.mod @@ -3,6 +3,7 @@ # DEPEND=server +DEPEND=client LIB=lib/jetty-proxy-${jetty.version}.jar diff --git a/jetty-start/src/test/resources/usecases/home/modules/security.mod b/jetty-start/src/test/resources/usecases/home/modules/security.mod new file mode 100644 index 00000000000..5a3c4a368a6 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/security.mod @@ -0,0 +1,7 @@ +# +# Jetty Security Module +# + +DEPEND=server + +LIB=lib/jetty-security-${jetty.version}.jar diff --git a/jetty-start/src/test/resources/usecases/home/modules/server.mod b/jetty-start/src/test/resources/usecases/home/modules/server.mod index 06bf6772f5b..aa6cad6b0e6 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/server.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/server.mod @@ -3,6 +3,7 @@ # DEPEND=base +DEPEND=xml LIB=lib/servlet-api-3.1.jar LIB=lib/jetty-schemas-3.1.jar diff --git a/jetty-start/src/test/resources/usecases/home/modules/servlet.mod b/jetty-start/src/test/resources/usecases/home/modules/servlet.mod new file mode 100644 index 00000000000..a427eed5478 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/home/modules/servlet.mod @@ -0,0 +1,7 @@ +# +# Jetty Servlet Module +# + +DEPEND=server + +LIB=lib/jetty-servlet-${jetty.version}.jar diff --git a/jetty-start/src/test/resources/usecases/home/modules/spdy.mod b/jetty-start/src/test/resources/usecases/home/modules/spdy.mod index 4a70136f556..1f3d5e99614 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/spdy.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/spdy.mod @@ -1,5 +1,7 @@ DEPEND=server +LIB=lib/spdy/*.jar + etc/jetty-ssl.xml etc/jetty-spdy.xml diff --git a/jetty-start/src/test/resources/usecases/home/modules/webapp.mod b/jetty-start/src/test/resources/usecases/home/modules/webapp.mod index 187db774b69..c39d5aae063 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/webapp.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/webapp.mod @@ -2,6 +2,6 @@ # Base server # -DEPEND=deploy +DEPEND=servlet LIB=lib/jetty-webapp-${jetty.version}.jar diff --git a/jetty-start/src/test/resources/usecases/home/modules/websocket.mod b/jetty-start/src/test/resources/usecases/home/modules/websocket.mod index b8571fb12aa..e61ec33e184 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/websocket.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/websocket.mod @@ -11,3 +11,4 @@ LIB=lib/websockets/*.jar # WebSocket needs websocket configuration etc/jetty-websockets.xml + From a3965633403fbf90b8abf14ab8bc77552d8a8acd Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Aug 2013 14:52:02 -0700 Subject: [PATCH 28/28] 414635 Modular start.d and jetty.base property + More work on startup of real jetty server. --- jetty-distribution/pom.xml | 2 +- .../src/main/resources/start.d/demo.ini | 2 -- jetty-jsp/pom.xml | 19 +++++++++++++++++++ jetty-jsp/src/main/config/modules/jsp.mod | 8 ++++++++ .../java/org/eclipse/jetty/start/Main.java | 19 ++++++++----------- .../org/eclipse/jetty/start/StartArgs.java | 18 ++++++++++++++++++ .../src/main/config/modules/jndi.demo.mod | 10 ++++++++++ 7 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 jetty-jsp/src/main/config/modules/jsp.mod create mode 100644 tests/test-webapps/test-jetty-webapp/src/main/config/modules/jndi.demo.mod diff --git a/jetty-distribution/pom.xml b/jetty-distribution/pom.xml index c008de54ed0..502eba080c3 100644 --- a/jetty-distribution/pom.xml +++ b/jetty-distribution/pom.xml @@ -298,7 +298,7 @@ org.eclipse.jetty org.eclipse.jetty.orbit,org.eclipse.jetty.spdy,org.eclipse.jetty.websocket,org.eclipse.jetty.toolchain - jetty-all,jetty-start,jetty-monitor + jetty-all,jetty-jsp,jetty-start,jetty-monitor jar ${assembly-directory}/lib diff --git a/jetty-distribution/src/main/resources/start.d/demo.ini b/jetty-distribution/src/main/resources/start.d/demo.ini index 037e743f2c9..bffdd8c0c54 100644 --- a/jetty-distribution/src/main/resources/start.d/demo.ini +++ b/jetty-distribution/src/main/resources/start.d/demo.ini @@ -10,7 +10,5 @@ jaas.login.conf=webapps.demo/test-jaas.d/login.conf # Activate the demo options and configurations MODULES=jndi.demo -etc/jetty-demo.xml -etc/test-realm.xml diff --git a/jetty-jsp/pom.xml b/jetty-jsp/pom.xml index b8067b473a4..04fa8c5d340 100644 --- a/jetty-jsp/pom.xml +++ b/jetty-jsp/pom.xml @@ -10,6 +10,25 @@ http://www.eclipse.org/jetty jar + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + config + + + + + + diff --git a/jetty-jsp/src/main/config/modules/jsp.mod b/jetty-jsp/src/main/config/modules/jsp.mod new file mode 100644 index 00000000000..d24dddf44d5 --- /dev/null +++ b/jetty-jsp/src/main/config/modules/jsp.mod @@ -0,0 +1,8 @@ +# +# Jetty Servlet Module +# + +DEPEND=servlet + +LIB=lib/jsp/*.jar + diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 060eeba4837..c23bae2eb01 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -263,9 +263,9 @@ public class Main // TODO } - private void listModules() + private void listModules(StartArgs args) { - // TODO Auto-generated method stub + args.getAllModules().dump(); } public StartArgs processCommandLine(String[] cmdLine) throws Exception @@ -336,6 +336,7 @@ public class Main StartLog.debug("Building Module Graph"); modules.buildGraph(); + args.setAllModules(modules); List activeModules = modules.resolveEnabled(); // 7) Lib & XML Expansion / Resolution @@ -352,11 +353,6 @@ public class Main return baseHome; } - private void showAllOptionsWithVersions() - { - // TODO - } - private void showClasspathWithVersions(Classpath classpath) { // Iterate through active classpath, and fetch Implementation Version from each entry (if present) @@ -378,19 +374,20 @@ public class Main int i = 0; for (File element : classpath.getElements()) { - System.out.printf("%2d: %20s | %s\n",i++,getVersion(element),baseHome.toShortForm(element)); + System.out.printf("%2d: %24s | %s\n",i++,getVersion(element),baseHome.toShortForm(element)); } } public void start(StartArgs args) throws IOException, InterruptedException { + StartLog.debug("StartArgs: %s",args); + // Get Desired Classpath based on user provided Active Options. Classpath classpath = args.getClasspath(); System.setProperty("java.class.path",classpath.toString()); ClassLoader cl = classpath.getClassLoader(); - StartLog.debug("java.class.path=" + System.getProperty("java.class.path")); StartLog.debug("jetty.home=" + System.getProperty("jetty.home")); StartLog.debug("jetty.base=" + System.getProperty("jetty.base")); StartLog.debug("java.home=" + System.getProperty("java.home")); @@ -407,7 +404,7 @@ public class Main } // Show the version information and return - if (args.isVersion()) + if (args.isListClasspath()) { showClasspathWithVersions(classpath); } @@ -421,7 +418,7 @@ public class Main // Show modules if (args.isListModules()) { - listModules(); + listModules(args); } // Show Command Line to execute Jetty 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 9eb8a5ff81c..a52b3b5424e 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 @@ -71,6 +71,7 @@ public class StartArgs private Properties properties = new Properties(); private Set systemPropertyKeys = new HashSet<>(); private List jvmArgs = new ArrayList<>(); + private Modules allModules; // Should the server be run? private boolean run = true; @@ -207,6 +208,11 @@ public class StartArgs } } + public Modules getAllModules() + { + return allModules; + } + public Classpath getClasspath() { return classpath; @@ -415,6 +421,13 @@ public class StartArgs run = false; return; } + + if ("--list-modules".equals(arg)) + { + listModules = true; + run = false; + return; + } if ("--dry-run".equals(arg) || "--exec-print".equals(arg)) { @@ -550,6 +563,11 @@ public class StartArgs } } + public void setAllModules(Modules allModules) + { + this.allModules = allModules; + } + @Override public String toString() { diff --git a/tests/test-webapps/test-jetty-webapp/src/main/config/modules/jndi.demo.mod b/tests/test-webapps/test-jetty-webapp/src/main/config/modules/jndi.demo.mod new file mode 100644 index 00000000000..20f7807991f --- /dev/null +++ b/tests/test-webapps/test-jetty-webapp/src/main/config/modules/jndi.demo.mod @@ -0,0 +1,10 @@ +# +# Jetty Demo Module +# + +DEPEND=jndi + +LIB=lib/jndi.demo/*.jar + +etc/test-realm.xml +