From 51b0ea05ee85917d303b12682479ee0b7414dabf Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 29 Aug 2013 08:36:15 -0700 Subject: [PATCH 01/12] jetty-start / minor cleanup of BaseHome + use canonical file more consistently --- .../org/eclipse/jetty/start/BaseHome.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) 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 8e519db5a3f..f68fd39ee00 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 @@ -50,20 +50,22 @@ public class BaseHome { try { - this.baseDir = new File(System.getProperty("jetty.base",System.getProperty("user.dir","."))); - URL jarfile=this.getClass().getClassLoader().getResource("org/eclipse/jetty/start/BaseHome.class"); - if (jarfile!=null) + this.baseDir = new File(System.getProperty("jetty.base",System.getProperty("user.dir","."))); + URL jarfile = this.getClass().getClassLoader().getResource("org/eclipse/jetty/start/BaseHome.class"); + if (jarfile != null) { - Matcher m =Pattern.compile("jar:(file:.*)!/org/eclipse/jetty/start/BaseHome.class").matcher(jarfile.toString()); + Matcher m = Pattern.compile("jar:(file:.*)!/org/eclipse/jetty/start/BaseHome.class").matcher(jarfile.toString()); if (m.matches()) - homeDir=new File(new URI(m.group(1))).getParentFile(); + { + homeDir = new File(new URI(m.group(1))).getParentFile(); + } } - homeDir = new File(System.getProperty("jetty.home",(homeDir==null?baseDir:homeDir).getAbsolutePath())); - - baseDir=baseDir.getAbsoluteFile().getCanonicalFile(); - homeDir=homeDir.getAbsoluteFile().getCanonicalFile(); + homeDir = new File(System.getProperty("jetty.home",(homeDir == null?baseDir:homeDir).getAbsolutePath())); + + baseDir = baseDir.getAbsoluteFile().getCanonicalFile(); + homeDir = homeDir.getAbsoluteFile().getCanonicalFile(); } - catch(IOException | URISyntaxException e) + catch (IOException | URISyntaxException e) { throw new RuntimeException(e); } @@ -71,8 +73,15 @@ public class BaseHome public BaseHome(File homeDir, File baseDir) { - this.homeDir = homeDir; - this.baseDir = baseDir == null?homeDir:baseDir; + try + { + this.homeDir = homeDir.getCanonicalFile(); + this.baseDir = baseDir == null?homeDir:baseDir.getCanonicalFile(); + } + catch (IOException e) + { + throw new RuntimeException(e); + } } public String getBase() From 9a40e12b700b336895b73ee1c7b8d9e3d957a61b Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 29 Aug 2013 08:36:45 -0700 Subject: [PATCH 02/12] jetty-start / import cleanup + change MODULE= to --module= in usage --- jetty-start/src/main/java/org/eclipse/jetty/start/Main.java | 5 +---- 1 file changed, 1 insertion(+), 4 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 ce1fc1a7917..6bfa718db7e 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 @@ -29,7 +29,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.OutputStream; -import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -38,13 +37,11 @@ import java.net.InetAddress; import java.net.Socket; import java.net.SocketTimeoutException; import java.net.URL; -import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Locale; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -233,7 +230,7 @@ public class Main 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 MODULES=[name,name,...] command line option will be reflected here."); + System.out.println(" changes to the --module=name command line options will be reflected here."); int i = 0; for (File element : classpath.getElements()) From fad7f94619a0a8e5a452a1cf140c2b3fec7d05ed Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 29 Aug 2013 08:53:46 -0700 Subject: [PATCH 03/12] jetty-start / removing last remnants of module persistence --- .../org/eclipse/jetty/start/StartArgs.java | 49 ------------------- .../modules/enabled | 2 - .../start.d/requestlog.ini | 2 - .../start.d/websocket.ini | 2 - .../base.with.module.persistence/start.ini | 13 ----- 5 files changed, 68 deletions(-) delete mode 100644 jetty-start/src/test/resources/usecases/base.with.module.persistence/modules/enabled delete mode 100644 jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/requestlog.ini delete mode 100644 jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/websocket.ini delete mode 100644 jetty-start/src/test/resources/usecases/base.with.module.persistence/start.ini 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 87c2136a660..7d20da9a70f 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 @@ -148,8 +148,6 @@ public class StartArgs private List jvmArgs = new ArrayList<>(); private List moduleIni = new ArrayList<>(); private List moduleStartIni = new ArrayList<>(); - private List modulePersistEnable = new ArrayList<>(); - private List modulePersistDisable = new ArrayList<>(); private Modules allModules; // Should the server be run? @@ -540,16 +538,6 @@ public class StartArgs return System.getProperty("main.class",mainclass); } - public List getModulePersistDisable() - { - return modulePersistDisable; - } - - public List getModulePersistEnable() - { - return modulePersistEnable; - } - public Properties getProperties() { return properties; @@ -648,11 +636,6 @@ public class StartArgs return listModules; } - public boolean isModulePersistenceChanging() - { - return (modulePersistDisable.size() > 0) || (modulePersistEnable.size() > 0); - } - public boolean isRun() { return run; @@ -799,28 +782,6 @@ public class StartArgs return; } - if (arg.startsWith("--enable-module=")) - { - if (!CMD_LINE_SOURCE.equals(source)) - { - throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source); - } - modulePersistEnable.addAll(getValues(arg)); - run = false; - return; - } - - if (arg.startsWith("--disable-module=")) - { - if (!CMD_LINE_SOURCE.equals(source)) - { - throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source); - } - modulePersistDisable.addAll(getValues(arg)); - run = false; - return; - } - // Start property (syntax similar to System property) if (arg.startsWith("-D")) { @@ -904,16 +865,6 @@ public class StartArgs this.allModules = allModules; } - public void setModulePersistDisable(List modulePersistDisable) - { - this.modulePersistDisable = modulePersistDisable; - } - - public void setModulePersistEnable(List modulePersistEnable) - { - this.modulePersistEnable = modulePersistEnable; - } - @Override public String toString() { diff --git a/jetty-start/src/test/resources/usecases/base.with.module.persistence/modules/enabled b/jetty-start/src/test/resources/usecases/base.with.module.persistence/modules/enabled deleted file mode 100644 index 9fe8112ed80..00000000000 --- a/jetty-start/src/test/resources/usecases/base.with.module.persistence/modules/enabled +++ /dev/null @@ -1,2 +0,0 @@ -https -websocket \ No newline at end of file diff --git a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/requestlog.ini b/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/requestlog.ini deleted file mode 100644 index 59a4ac4759e..00000000000 --- a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/requestlog.ini +++ /dev/null @@ -1,2 +0,0 @@ - ---module=requestlog diff --git a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/websocket.ini b/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/websocket.ini deleted file mode 100644 index 1b62c595977..00000000000 --- a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/websocket.ini +++ /dev/null @@ -1,2 +0,0 @@ - ---module=websocket diff --git a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.ini b/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.ini deleted file mode 100644 index 3e513e792d1..00000000000 --- a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.ini +++ /dev/null @@ -1,13 +0,0 @@ - -# this should not be picked up as there is a module persistence layer present ---module=debug ---module=ipaccess ---module=rewrite - -jetty.port=12345 - -jetty.keystore=etc/keystore -jetty.keystore.password=friendly -jetty.keymanager.password=icecream -jetty.truststore=etc/keystore -jetty.truststore.password=sundae From de4febf1b9978010e9b4d702c12eee7d25b5332a Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 29 Aug 2013 08:54:12 -0700 Subject: [PATCH 04/12] jetty-start / fixing BaseHomeTest failure --- .../org/eclipse/jetty/start/BaseHome.java | 2 +- .../org/eclipse/jetty/start/usage.txt | 27 +++++++++++-------- .../org/eclipse/jetty/start/BaseHomeTest.java | 10 ++++--- .../org/eclipse/jetty/start/TestUseCases.java | 1 - 4 files changed, 23 insertions(+), 17 deletions(-) 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 f68fd39ee00..3cd5199601b 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 @@ -76,7 +76,7 @@ public class BaseHome try { this.homeDir = homeDir.getCanonicalFile(); - this.baseDir = baseDir == null?homeDir:baseDir.getCanonicalFile(); + this.baseDir = baseDir == null?this.homeDir:baseDir.getCanonicalFile(); } catch (IOException e) { diff --git a/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt b/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt index 6c9f975e1b7..6817c422e8e 100644 --- a/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt +++ b/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt @@ -59,23 +59,28 @@ Module Management: o The ${jetty.base}/start.d/*.ini files --module= - Will temporarily enable a module from the command line. + Temporarily enable a module from the command line. Note: this can also be used in the ${jetty.base}/start.ini or ${jetty.base}/start.d/*.ini files. --module-ini= - Will enable a module by adding an ini file to the - ${jetty.base}/start.d/ directory from the template - contained in the module definition. Transitive - dependencies are followed and ini files are created - for them if they too have a ini template. + Enable a module via creation of an ini file in the + ${jetty.base}/start.d/ directory. + Uses ini template that the module itself maintains. + Transitive module dependencies are followed and all + modules that the specified module depends on are also + enabled via their own ini files in the same directory. + Note: not all modules have ini templates. --module-start-ini= - Will enable a module by appending lines to the - ${jetty.base}/start.ini file from the template - contained in the module definition. Transitive - dependencies are followed and lines are appended - for them if they too have a ini template. + Enable a module by appending lines to the + ${jetty.base}/start.ini file. + Lines that are added come from the ini template that + the module itself maintains. + Transitive module dependencies are followed and all + modules that the specified module depends on are also + enabled in the ${jetty.base}/start.ini using the same + techniques. Startup / Shutdown Command Line: -------------------------------- diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/BaseHomeTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/BaseHomeTest.java index 773d91be1e8..e7f3e956ee2 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/BaseHomeTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/BaseHomeTest.java @@ -39,7 +39,7 @@ public class BaseHomeTest { actual.add(hb.toShortForm(file)); } - Assert.assertThat(message,actual,containsInAnyOrder(expected.toArray())); + Assert.assertThat(message + ": " + Main.join(actual,", "),actual,containsInAnyOrder(expected.toArray())); } @Test @@ -76,7 +76,7 @@ public class BaseHomeTest assertFileList(hb,"Files found",expected,files); } - + @Test public void testListFiles_Filtered_OnlyHome() throws IOException { @@ -84,7 +84,7 @@ public class BaseHomeTest File baseDir = null; BaseHome hb = new BaseHome(homeDir,baseDir); - List files = hb.listFiles("/start.d", new FS.IniFilter()); + List files = hb.listFiles("/start.d",new FS.IniFilter()); List expected = new ArrayList<>(); expected.add("${jetty.home}/start.d/jmx.ini"); @@ -120,8 +120,10 @@ public class BaseHomeTest public void testDefault() throws IOException { BaseHome bh = new BaseHome(); + Assert.assertThat("Home",bh.getHome(),notNullValue()); + Assert.assertThat("Base",bh.getBase(),notNullValue()); } - + @Test public void testGetFile_Both() throws IOException { diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java index 609f815eef9..ebc67361be7 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java @@ -67,5 +67,4 @@ public class TestUseCases { assertUseCase("home","base.with.db","assert-with-db.txt"); } - } From 78dfd287e33174ca1e0b79a60d6aeafde431de5d Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 29 Aug 2013 08:59:20 -0700 Subject: [PATCH 05/12] jetty-start / DownloadArg to its own class + Main cleanup --- .../java/org/eclipse/jetty/start/Main.java | 313 +++++++++--------- .../org/eclipse/jetty/start/StartArgs.java | 125 ++----- .../jetty/start/ConfigurationAssert.java | 1 - 3 files changed, 183 insertions(+), 256 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 6bfa718db7e..1c6b616bb9b 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 @@ -45,8 +45,6 @@ import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.eclipse.jetty.start.StartArgs.DownloadArg; - /** * Main start class. *

@@ -332,6 +330,166 @@ public class Main modules.dumpEnabledTree(); } + private void moduleIni(StartArgs args, String name, boolean topLevel, boolean appendStartIni) throws IOException + { + // Find the start.d relative to the base directory only. + File start_d = baseHome.getBaseFile("start.d"); + + // Is this a module? + Modules modules = args.getAllModules(); + Module module = modules.get(name); + if (module == null) + { + StartLog.warn("ERROR: No known module for %s",name); + return; + } + + // Find any named ini file and check it follows the convention + File start_ini = baseHome.getBaseFile("start.ini"); + String short_start_ini = baseHome.toShortForm(start_ini); + File ini = new File(start_d,name + ".ini"); + String short_ini = baseHome.toShortForm(ini); + StartIni module_ini = null; + if (ini.exists()) + { + module_ini = new StartIni(ini); + if (module_ini.getLineMatches(Pattern.compile("--module=(.*, *)*" + name)).size() == 0) + { + StartLog.warn("ERROR: %s is not enabled in %s!",name,short_ini); + return; + } + } + + boolean transitive = module.isEnabled() && (module.getSources().size() == 0); + boolean has_ini_lines = module.getInitialise().size() > 0; + + // If it is not enabled or is transitive with ini template lines or toplevel and doesn't exist + if (!module.isEnabled() || (transitive && has_ini_lines) || (topLevel && !ini.exists() && !appendStartIni)) + { + String source = null; + PrintWriter out = null; + try + { + if (appendStartIni) + { + if ((!start_ini.exists() && !start_ini.createNewFile()) || !start_ini.canWrite()) + { + StartLog.warn("ERROR: Bad %s! ",start_ini); + return; + } + source = short_start_ini; + StartLog.warn("%-15s initialised in %s (appended)",name,source); + out = new PrintWriter(new FileWriter(start_ini,true)); + } + else + { + // Create the directory if needed + if (!start_d.exists()) + { + start_d.mkdirs(); + } + if (!start_d.isDirectory() || !start_d.canWrite()) + { + StartLog.warn("ERROR: Bad start.d %s! ",start_d); + return; + } + // Create a new ini file for it + if (!ini.createNewFile()) + { + StartLog.warn("ERROR: %s cannot be initialised in %s! ",name,short_ini); + return; + } + source = short_ini; + StartLog.warn("%-15s initialised in %s (created)",name,source); + out = new PrintWriter(ini); + } + + if (appendStartIni) + { + out.println(); + } + out.println("#"); + out.println("# Initialize module " + name); + out.println("#"); + Pattern p = Pattern.compile("--module=([^,]+)(,([^,]+))*"); + + out.println("--module=" + name); + args.parse("--module=" + name,source); + modules.enable(name,Collections.singletonList(source)); + for (String line : module.getInitialise()) + { + out.println(line); + args.parse(line,source); + Matcher m = p.matcher(line); + if (m.matches()) + { + for (int i = 1; i <= m.groupCount(); i++) + { + String n = m.group(i); + if (n == null) + { + continue; + } + n = n.trim(); + if ((n.length() == 0) || n.startsWith(",")) + { + continue; + } + + modules.enable(n,Collections.singletonList(source)); + } + } + } + } + finally + { + if (out != null) + { + out.close(); + } + } + } + else if (ini.exists()) + { + StartLog.info("%-15s initialised in %s",name,short_ini); + } + + // Also list other places this module is enabled + for (String source : module.getSources()) + { + if (!short_ini.equals(source)) + { + StartLog.warn("%-15s enabled in %s",name,baseHome.toShortForm(source)); + } + } + + // Do downloads now + for (String download : module.getDownloads()) + { + download(new DownloadArg(download)); + } + + // Process dependencies from top level only + if (topLevel) + { + List parents = new ArrayList<>(); + for (String parent : modules.resolveParentModulesOf(name)) + { + if (!name.equals(parent)) + { + Module m = modules.get(parent); + m.setEnabled(true); + parents.add(m); + } + } + Collections.sort(parents,Collections.reverseOrder(new Module.DepthComparator())); + for (Module m : parents) + { + moduleIni(args,m.getName(),false,appendStartIni); + } + } + } + /** * Convenience for processCommandLine(cmdLine.toArray(new String[cmdLine.size()])) */ @@ -478,19 +636,18 @@ public class Main } } - // Initialize for (String module : args.getModuleStartIni()) { moduleIni(args,module,true,true); } - + // Initialize for (String module : args.getModuleIni()) { moduleIni(args,module,true,false); } - + // Informational command line, don't run jetty if (!args.isRun()) { @@ -611,152 +768,6 @@ public class Main } } - private void moduleIni(StartArgs args, String name, boolean topLevel,boolean appendStartIni) throws IOException - { - // Find the start.d relative to the base directory only. - File start_d=baseHome.getBaseFile("start.d"); - - // Is this a module? - Modules modules=args.getAllModules(); - Module module=modules.get(name); - if (module==null) - { - StartLog.warn("ERROR: No known module for %s",name); - return; - } - - // Find any named ini file and check it follows the convention - File start_ini=baseHome.getBaseFile("start.ini"); - String short_start_ini = baseHome.toShortForm(start_ini); - File ini=new File(start_d,name+".ini"); - String short_ini = baseHome.toShortForm(ini); - StartIni module_ini=null; - if (ini.exists()) - { - module_ini=new StartIni(ini); - if (module_ini.getLineMatches(Pattern.compile("--module=(.*, *)*"+name)).size()==0) - { - StartLog.warn("ERROR: %s is not enabled in %s!",name,short_ini); - return; - } - } - - boolean transitive=module.isEnabled() && module.getSources().size()==0; - boolean has_ini_lines = module.getInitialise().size()>0; - - // If it is not enabled or is transitive with ini template lines or toplevel and doesn't exist - if (!module.isEnabled() || (transitive && has_ini_lines) || (topLevel && !ini.exists() && !appendStartIni)) - { - String source=null; - PrintWriter out=null; - try - { - if (appendStartIni) - { - if (!start_ini.exists() && !start_ini.createNewFile() || !start_ini.canWrite()) - { - StartLog.warn("ERROR: Bad %s! ",start_ini); - return; - } - source = short_start_ini; - StartLog.warn("%-15s initialised in %s (appended)",name,source); - out = new PrintWriter(new FileWriter(start_ini,true)); - } - else - { - // Create the directory if needed - if (!start_d.exists()) - start_d.mkdirs(); - if (!start_d.isDirectory() || !start_d.canWrite()) - { - StartLog.warn("ERROR: Bad start.d %s! ",start_d); - return; - } - // Create a new ini file for it - if (!ini.createNewFile()) - { - StartLog.warn("ERROR: %s cannot be initialised in %s! ",name,short_ini); - return; - } - source=short_ini; - StartLog.warn("%-15s initialised in %s (created)",name,source); - out = new PrintWriter(ini); - } - - if (appendStartIni) - out.println(); - out.println("#"); - out.println("# Initialize module "+name); - out.println("#"); - Pattern p = Pattern.compile("--module=([^,]+)(,([^,]+))*"); - - out.println("--module="+name); - args.parse("--module="+name,source); - modules.enable(name,Collections.singletonList(source)); - for (String line : module.getInitialise()) - { - out.println(line); - args.parse(line,source); - Matcher m=p.matcher(line); - if (m.matches()) - { - for (int i=1;i<=m.groupCount();i++) - { - String n=m.group(i); - if (n==null) - continue; - n=n.trim(); - if (n.length()==0||n.startsWith(",")) - continue; - - modules.enable(n,Collections.singletonList(source)); - } - } - } - } - finally - { - if (out!=null) - out.close(); - } - } - else if (ini.exists()) - { - StartLog.info("%-15s initialised in %s",name,short_ini); - } - - // Also list other places this module is enabled - for(String source:module.getSources()) - { - if (!short_ini.equals(source)) - StartLog.warn("%-15s enabled in %s",name,baseHome.toShortForm(source)); - } - - // Do downloads now - for (String download : module.getDownloads()) - download(StartArgs.toDownloadArg(download)); - - // Process dependencies from top level only - if (topLevel) - { - List parents = new ArrayList<>(); - for (String parent:modules.resolveParentModulesOf(name)) - { - if (!name.equals(parent)) - { - Module m=modules.get(parent); - m.setEnabled(true); - parents.add(m); - } - } - Collections.sort(parents,Collections.reverseOrder(new Module.DepthComparator())); - for (Module m : parents) - { - moduleIni(args,m.getName(),false,appendStartIni); - } - } - } - public void usage(boolean exit) { String usageResource = "org/eclipse/jetty/start/usage.txt"; 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 7d20da9a70f..6f891b68bed 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 @@ -39,76 +39,7 @@ import java.util.Set; */ public class StartArgs { - public static class DownloadArg - { - public String uri; - public String location; - - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (getClass() != obj.getClass()) - { - return false; - } - DownloadArg other = (DownloadArg)obj; - if (uri == null) - { - if (other.uri != null) - { - return false; - } - } - else if (!uri.equals(other.uri)) - { - return false; - } - if (location == null) - { - if (other.location != null) - { - return false; - } - } - else if (!location.equals(other.location)) - { - return false; - } - return true; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = (prime * result) + ((uri == null)?0:uri.hashCode()); - result = (prime * result) + ((location == null)?0:location.hashCode()); - return result; - } - - @Override - public String toString() - { - StringBuilder builder = new StringBuilder(); - builder.append("DownloadArg [uri="); - builder.append(uri); - builder.append(", location="); - builder.append(location); - builder.append("]"); - return builder.toString(); - } - } public static final String CMD_LINE_SOURCE = ""; - public static final String VERSION; static @@ -135,7 +66,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"; - + private List commandLine = new ArrayList<>(); private Set modules = new HashSet<>(); private Map> sources = new HashMap<>(); @@ -148,8 +79,8 @@ public class StartArgs private List jvmArgs = new ArrayList<>(); private List moduleIni = new ArrayList<>(); private List moduleStartIni = new ArrayList<>(); - private Modules allModules; + private Modules allModules; // Should the server be run? private boolean run = true; private boolean help = false; @@ -159,6 +90,7 @@ public class StartArgs private boolean listConfig = false; private boolean version = false; private boolean dryRun = false; + private boolean exec = false; public StartArgs(String[] commandLineArgs) @@ -167,30 +99,9 @@ public class StartArgs classpath = new Classpath(); } - static DownloadArg toDownloadArg(String uriLocation) - { - String parts[] = uriLocation.split(":",3); - if (parts.length != 3) - { - throw new IllegalArgumentException("Not :"); - } - if (!"http".equalsIgnoreCase(parts[0])) - { - throw new IllegalArgumentException("Download only supports http protocol"); - } - if (!parts[1].startsWith("//")) - { - throw new IllegalArgumentException("Download URI invalid: " + uriLocation); - } - DownloadArg arg = new DownloadArg(); - arg.uri = String.format("%s:%s",parts[0],parts[1]); - arg.location = parts[2]; - return arg; - } - private void addDownload(String uriLocation) { - DownloadArg arg=toDownloadArg(uriLocation); + DownloadArg arg = new DownloadArg(uriLocation); if (!downloads.contains(arg)) { downloads.add(arg); @@ -450,16 +361,6 @@ public class StartArgs return this.commandLine; } - public List getModuleIni() - { - return moduleIni; - } - - public List getModuleStartIni() - { - return moduleStartIni; - } - public List getDownloads() { @@ -538,6 +439,16 @@ public class StartArgs return System.getProperty("main.class",mainclass); } + public List getModuleIni() + { + return moduleIni; + } + + public List getModuleStartIni() + { + return moduleStartIni; + } + public Properties getProperties() { return properties; @@ -671,8 +582,10 @@ public class StartArgs public void parse(String arg, String source) { if (arg.trim().startsWith("#")) + { return; - + } + if ("--help".equals(arg) || "-?".equals(arg)) { if (!CMD_LINE_SOURCE.equals(source)) @@ -751,7 +664,9 @@ public class StartArgs if (arg.startsWith("--module-ini=")) { if (!CMD_LINE_SOURCE.equals(source)) + { throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source); + } moduleIni.addAll(getValues(arg)); run = false; return; @@ -760,7 +675,9 @@ public class StartArgs if (arg.startsWith("--module-start-ini=")) { if (!CMD_LINE_SOURCE.equals(source)) + { throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source); + } moduleStartIni.addAll(getValues(arg)); run = false; return; diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java index ff39017e9e3..8484add4c64 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java @@ -31,7 +31,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.eclipse.jetty.start.StartArgs.DownloadArg; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.junit.Assert; From ddca8bc3271917b0c62f5e9982715e1a6b7546ce Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 29 Aug 2013 20:03:42 +0200 Subject: [PATCH 06/12] Avoid StackOverflowErrors when submitting changes. These were possible on a busy server, when many new connections are created, and each triggers read interest: one connection submits the read interest change, then runs the changes, finds that another connections is created, runs it, which schedule a read interest change, and so on. Now the code is simpler, and while we always offer to the queue, it may even be faster. --- .../org/eclipse/jetty/io/SelectorManager.java | 77 ++++++++----------- 1 file changed, 31 insertions(+), 46 deletions(-) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java index c6be5ff8e41..a5757579cc4 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java @@ -362,56 +362,41 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa */ public void submit(Runnable change) { - if (isSelectorThread()) - { - if (_state.get() == State.PROCESS) - { - // We are processing, so lets handle existing changes - runChanges(); - // and then directly run the passed change without queueing it - runChange(change); - } - else - { - // We must be iterating in CHANGES or MORE_CHANGES - // state, so just append to the queue to preserve order. - _changes.offer(change); - } - } - else - { - // Otherwise we have to queue the change and possibly wakeup the selector - _changes.offer(change); - LOG.debug("Queued change {}", change); + // This method may be called from the selector thread, and therefore + // we could directly run the change without queueing, but this may + // lead to stack overflows on a busy server, so we always offer the + // change to the queue and process the state. - out: while (true) + _changes.offer(change); + LOG.debug("Queued change {}", change); + + out: while (true) + { + switch (_state.get()) { - switch (_state.get()) - { - case SELECT: - // Avoid multiple wakeup() calls if we the CAS fails - if (!_state.compareAndSet(State.SELECT, State.WAKEUP)) - continue; - wakeup(); - break out; - case CHANGES: - // Tell the selector thread that we have more changes. - // If we fail to CAS, we possibly need to wakeup(), so loop. - if (_state.compareAndSet(State.CHANGES, State.MORE_CHANGES)) - break out; + case SELECT: + // Avoid multiple wakeup() calls if we the CAS fails + if (!_state.compareAndSet(State.SELECT, State.WAKEUP)) continue; - case WAKEUP: - // Do nothing, we have already a wakeup scheduled + wakeup(); + break out; + case CHANGES: + // Tell the selector thread that we have more changes. + // If we fail to CAS, we possibly need to wakeup(), so loop. + if (_state.compareAndSet(State.CHANGES, State.MORE_CHANGES)) break out; - case MORE_CHANGES: - // Do nothing, we already notified the selector thread of more changes - break out; - case PROCESS: - // Do nothing, the changes will be run after the processing - break out; - default: - throw new IllegalStateException(); - } + continue; + case WAKEUP: + // Do nothing, we have already a wakeup scheduled + break out; + case MORE_CHANGES: + // Do nothing, we already notified the selector thread of more changes + break out; + case PROCESS: + // Do nothing, the changes will be run after the processing + break out; + default: + throw new IllegalStateException(); } } } From 8a1f12ae81bc1b6e6d6f4e1c0e3298b33beca015 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 29 Aug 2013 11:48:56 -0700 Subject: [PATCH 07/12] jetty-start / fixing build + work towards demo-base --- .../org/eclipse/jetty/start/DownloadArg.java | 107 ++++++++++++++++++ .../org/eclipse/jetty/start/ModulesTest.java | 2 +- .../resources/usecases/home/modules/demo.mod | 16 --- tests/test-webapps/test-jaas-webapp/pom.xml | 2 +- .../config/{demo => demo-base/etc}/login.conf | 2 +- .../{demo => demo-base/etc}/login.properties | 0 .../{demo => demo-base}/webapps/test-jaas.xml | 0 .../src/main/webapp/index.html | 2 +- tests/test-webapps/test-jetty-webapp/pom.xml | 2 +- .../embedded-jetty-web-for-webbundle.xml | 2 +- .../src/main/assembly/web-bundle.xml | 2 +- .../etc/demo-rewrite-rules.xml} | 20 ---- .../{demo => demo-base/etc}/override-web.xml | 0 .../{demo => demo-base/etc}/realm.properties | 0 .../{demo => demo-base/etc}/test-realm.xml | 2 +- .../src/main/config/demo-base/start.ini | 33 ++++++ .../{demo => demo-base}/webapps/test.xml | 4 +- .../src/main/config/modules/demo.mod | 20 ---- .../java/org/eclipse/jetty/TestServer.java | 2 +- .../src/main/assembly/config.xml | 4 +- .../src/main/assembly/config.xml | 4 +- 21 files changed, 155 insertions(+), 71 deletions(-) create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/DownloadArg.java delete mode 100644 jetty-start/src/test/resources/usecases/home/modules/demo.mod rename tests/test-webapps/test-jaas-webapp/src/main/config/{demo => demo-base/etc}/login.conf (65%) rename tests/test-webapps/test-jaas-webapp/src/main/config/{demo => demo-base/etc}/login.properties (100%) rename tests/test-webapps/test-jaas-webapp/src/main/config/{demo => demo-base}/webapps/test-jaas.xml (100%) rename tests/test-webapps/test-jetty-webapp/src/main/config/{demo/jetty-demo.xml => demo-base/etc/demo-rewrite-rules.xml} (80%) rename tests/test-webapps/test-jetty-webapp/src/main/config/{demo => demo-base/etc}/override-web.xml (100%) rename tests/test-webapps/test-jetty-webapp/src/main/config/{demo => demo-base/etc}/realm.properties (100%) rename tests/test-webapps/test-jetty-webapp/src/main/config/{demo => demo-base/etc}/test-realm.xml (97%) create mode 100644 tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/start.ini rename tests/test-webapps/test-jetty-webapp/src/main/config/{demo => demo-base}/webapps/test.xml (97%) delete mode 100644 tests/test-webapps/test-jetty-webapp/src/main/config/modules/demo.mod diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/DownloadArg.java b/jetty-start/src/main/java/org/eclipse/jetty/start/DownloadArg.java new file mode 100644 index 00000000000..837b33cc72d --- /dev/null +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/DownloadArg.java @@ -0,0 +1,107 @@ +// +// ======================================================================== +// 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; + +public class DownloadArg +{ + public String uri; + public String location; + + public DownloadArg(String uriLocation) + { + String parts[] = uriLocation.split(":",3); + if (parts.length != 3) + { + throw new IllegalArgumentException("Not :"); + } + if (!"http".equalsIgnoreCase(parts[0])) + { + throw new IllegalArgumentException("Download only supports http protocol"); + } + if (!parts[1].startsWith("//")) + { + throw new IllegalArgumentException("Download URI invalid: " + uriLocation); + } + this.uri = String.format("%s:%s",parts[0],parts[1]); + this.location = parts[2]; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + DownloadArg other = (DownloadArg)obj; + if (uri == null) + { + if (other.uri != null) + { + return false; + } + } + else if (!uri.equals(other.uri)) + { + return false; + } + if (location == null) + { + if (other.location != null) + { + return false; + } + } + else if (!location.equals(other.location)) + { + return false; + } + return true; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = (prime * result) + ((uri == null)?0:uri.hashCode()); + result = (prime * result) + ((location == null)?0:location.hashCode()); + return result; + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append("DownloadArg [uri="); + builder.append(uri); + builder.append(", location="); + builder.append(location); + builder.append("]"); + return builder.toString(); + } +} \ No newline at end of file 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 fadd30c2764..70aac2317b2 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 @@ -42,7 +42,7 @@ public class ModulesTest Modules modules = new Modules(); modules.registerAll(basehome); - Assert.assertThat("Module count",modules.count(),is(29)); + Assert.assertThat("Module count",modules.count(),is(28)); } @Test diff --git a/jetty-start/src/test/resources/usecases/home/modules/demo.mod b/jetty-start/src/test/resources/usecases/home/modules/demo.mod deleted file mode 100644 index af06453d839..00000000000 --- a/jetty-start/src/test/resources/usecases/home/modules/demo.mod +++ /dev/null @@ -1,16 +0,0 @@ -# -# Jetty Demo Module -# - -DEPEND=jndi -DEPEND=jaas -DEPEND=rewrite -DEPEND=client -DEPEND=annotations -DEPEND=websocket -DEPEND=webapp - -LIB=demo/lib/*.jar - -demo/test-realm.xml -demo/jetty-demo.xml diff --git a/tests/test-webapps/test-jaas-webapp/pom.xml b/tests/test-webapps/test-jaas-webapp/pom.xml index ba827d2d4b8..9e58548f569 100644 --- a/tests/test-webapps/test-jaas-webapp/pom.xml +++ b/tests/test-webapps/test-jaas-webapp/pom.xml @@ -34,7 +34,7 @@ java.security.auth.login.config - ${basedir}/src/main/config/demo/login.conf + ${basedir}/src/main/config/demo-base/etc/login.conf diff --git a/tests/test-webapps/test-jaas-webapp/src/main/config/demo/login.conf b/tests/test-webapps/test-jaas-webapp/src/main/config/demo-base/etc/login.conf similarity index 65% rename from tests/test-webapps/test-jaas-webapp/src/main/config/demo/login.conf rename to tests/test-webapps/test-jaas-webapp/src/main/config/demo-base/etc/login.conf index aa0736f41a8..a97b0eddeeb 100644 --- a/tests/test-webapps/test-jaas-webapp/src/main/config/demo/login.conf +++ b/tests/test-webapps/test-jaas-webapp/src/main/config/demo-base/etc/login.conf @@ -1,5 +1,5 @@ xyz { org.eclipse.jetty.jaas.spi.PropertyFileLoginModule required debug="true" -file="${jetty.home}/demo/login.properties"; +file="${jetty.base}/etc/login.properties"; }; diff --git a/tests/test-webapps/test-jaas-webapp/src/main/config/demo/login.properties b/tests/test-webapps/test-jaas-webapp/src/main/config/demo-base/etc/login.properties similarity index 100% rename from tests/test-webapps/test-jaas-webapp/src/main/config/demo/login.properties rename to tests/test-webapps/test-jaas-webapp/src/main/config/demo-base/etc/login.properties diff --git a/tests/test-webapps/test-jaas-webapp/src/main/config/demo/webapps/test-jaas.xml b/tests/test-webapps/test-jaas-webapp/src/main/config/demo-base/webapps/test-jaas.xml similarity index 100% rename from tests/test-webapps/test-jaas-webapp/src/main/config/demo/webapps/test-jaas.xml rename to tests/test-webapps/test-jaas-webapp/src/main/config/demo-base/webapps/test-jaas.xml diff --git a/tests/test-webapps/test-jaas-webapp/src/main/webapp/index.html b/tests/test-webapps/test-jaas-webapp/src/main/webapp/index.html index 5b4f50da8c2..521db42423e 100644 --- a/tests/test-webapps/test-jaas-webapp/src/main/webapp/index.html +++ b/tests/test-webapps/test-jaas-webapp/src/main/webapp/index.html @@ -24,7 +24,7 @@ etc/jetty-jaas.xml

-

For the jetty distribution demos, jaas is already enabled in the start.d/900-demo.ini file and sets the jaas.login.conf property to demo/login.conf for use with the demo/webapps/test-jaas.war web application.

+

For the jetty distribution demos, jaas is already enabled in the demo-base/start.ini file and sets the jaas.login.conf property to ${jetty.base}/etc/login.conf for use with the demo-base/webapps/test-jaas.war web application.

The full source of this demonstration is available here.

diff --git a/tests/test-webapps/test-jetty-webapp/pom.xml b/tests/test-webapps/test-jetty-webapp/pom.xml index 231bde47b13..9b6377b4346 100644 --- a/tests/test-webapps/test-jetty-webapp/pom.xml +++ b/tests/test-webapps/test-jetty-webapp/pom.xml @@ -147,7 +147,7 @@ Test Realm - src/main/config/demo/realm.properties + src/main/config/demo-base/etc/realm.properties diff --git a/tests/test-webapps/test-jetty-webapp/src/main/assembly/embedded-jetty-web-for-webbundle.xml b/tests/test-webapps/test-jetty-webapp/src/main/assembly/embedded-jetty-web-for-webbundle.xml index 8c10dad34b3..911b9479ff7 100644 --- a/tests/test-webapps/test-jetty-webapp/src/main/assembly/embedded-jetty-web-for-webbundle.xml +++ b/tests/test-webapps/test-jetty-webapp/src/main/assembly/embedded-jetty-web-for-webbundle.xml @@ -28,7 +28,7 @@ detected. true false /etc/webdefault.xml - /demo/override-web.xml + /etc/override-web.xml - - - - - - - - /demo/webapps - /etc/webdefault.xml - 1 - true - - - - - - - - - diff --git a/tests/test-webapps/test-jetty-webapp/src/main/config/demo/override-web.xml b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/override-web.xml similarity index 100% rename from tests/test-webapps/test-jetty-webapp/src/main/config/demo/override-web.xml rename to tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/override-web.xml diff --git a/tests/test-webapps/test-jetty-webapp/src/main/config/demo/realm.properties b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/realm.properties similarity index 100% rename from tests/test-webapps/test-jetty-webapp/src/main/config/demo/realm.properties rename to tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/realm.properties diff --git a/tests/test-webapps/test-jetty-webapp/src/main/config/demo/test-realm.xml b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/test-realm.xml similarity index 97% rename from tests/test-webapps/test-jetty-webapp/src/main/config/demo/test-realm.xml rename to tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/test-realm.xml index 97fccac33d4..d5c776ba08d 100644 --- a/tests/test-webapps/test-jetty-webapp/src/main/config/demo/test-realm.xml +++ b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/test-realm.xml @@ -12,7 +12,7 @@ Test Realm - + 0 diff --git a/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/start.ini b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/start.ini new file mode 100644 index 00000000000..66007703e2f --- /dev/null +++ b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/start.ini @@ -0,0 +1,33 @@ +# +# Example of providing a demo configuration, using a ${jetty.base} +# + +# We want to serve content over http +--module=http + +# Have webapps be deployed normally from webapps directory +--module=deploy + +# We are using annotations + jndi +--module=annotations +--module=jndi + +# Enable security via jaas, and configure it +--module=jaas +jaas.login.conf=demo/login.conf + +# Enable rewrite examples +--module=rewrite +etc/demo-rewrite-rules.xml + +# The async behavior examples use http client to access remote systems +--module=client + +# Websocket chat examples needs websocket enabled +--module=websocket + +# Create and configure the test realm +etc/test-realm.xml +demo.realm=demo/realm.properties + + diff --git a/tests/test-webapps/test-jetty-webapp/src/main/config/demo/webapps/test.xml b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/webapps/test.xml similarity index 97% rename from tests/test-webapps/test-jetty-webapp/src/main/config/demo/webapps/test.xml rename to tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/webapps/test.xml index b26d9fc178f..09f59b7ce9f 100644 --- a/tests/test-webapps/test-jetty-webapp/src/main/config/demo/webapps/test.xml +++ b/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/webapps/test.xml @@ -27,7 +27,7 @@ detected. true false /etc/webdefault.xml - /demo/override-web.xml + /etc/override-web.xml