diff --git a/jetty-distribution/pom.xml b/jetty-distribution/pom.xml index 68da23956f0..e3b23a76374 100644 --- a/jetty-distribution/pom.xml +++ b/jetty-distribution/pom.xml @@ -478,7 +478,8 @@ -jar start.jar - --ini=http,demo + --module-start-ini=server,ext,resources,jsp,annotations + --module-ini=http,demo diff --git a/jetty-server/src/main/config/modules/base.mod b/jetty-server/src/main/config/modules/base.mod deleted file mode 100644 index d3e2ab8fd04..00000000000 --- a/jetty-server/src/main/config/modules/base.mod +++ /dev/null @@ -1,8 +0,0 @@ -# -# Base Module -# - -OPTIONAL=jmx - -LIB=lib/jetty-util-${jetty.version}.jar -LIB=lib/jetty-io-${jetty.version}.jar diff --git a/jetty-server/src/main/config/modules/ext.mod b/jetty-server/src/main/config/modules/ext.mod new file mode 100644 index 00000000000..1e09cd62d8a --- /dev/null +++ b/jetty-server/src/main/config/modules/ext.mod @@ -0,0 +1,2 @@ + +LIB=lib/ext/* \ No newline at end of file diff --git a/jetty-server/src/main/config/modules/resources.mod b/jetty-server/src/main/config/modules/resources.mod new file mode 100644 index 00000000000..5782922a2e1 --- /dev/null +++ b/jetty-server/src/main/config/modules/resources.mod @@ -0,0 +1,2 @@ + +LIB=resources \ No newline at end of file diff --git a/jetty-server/src/main/config/modules/server.mod b/jetty-server/src/main/config/modules/server.mod index ea6321a6f64..3eada328e6a 100644 --- a/jetty-server/src/main/config/modules/server.mod +++ b/jetty-server/src/main/config/modules/server.mod @@ -2,15 +2,20 @@ # Base server # -DEPEND=base -DEPEND=xml OPTIONAL=jvm +OPTIONAL=jmx +OPTIONAL=ext +OPTIONAL=resources 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 +LIB=lib/jetty-xml-${jetty.version}.jar +LIB=lib/jetty-util-${jetty.version}.jar +LIB=lib/jetty-io-${jetty.version}.jar + # Annotations needs annotations configuration etc/jetty.xml @@ -20,4 +25,6 @@ INI=threads.max=200 INI=threads.timeout=60000 INI=#jetty.host=myhost.com INI=jetty.dump.start=false -INI=jetty.dump.stop=false \ No newline at end of file +INI=jetty.dump.stop=false + + diff --git a/jetty-server/src/main/config/modules/xml.mod b/jetty-server/src/main/config/modules/xml.mod deleted file mode 100644 index 949e2057117..00000000000 --- a/jetty-server/src/main/config/modules/xml.mod +++ /dev/null @@ -1,8 +0,0 @@ -# -# Jetty XML Configuration -# - -DEPEND=base - -LIB=lib/jetty-xml-${jetty.version}.jar - 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 063dfb41c6a..8e519db5a3f 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 @@ -21,6 +21,9 @@ package org.eclipse.jetty.start; import java.io.File; import java.io.FileFilter; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -45,9 +48,25 @@ public class BaseHome public BaseHome() { - String userDir = System.getProperty("user.dir"); - this.homeDir = new File(System.getProperty("jetty.home",userDir)); - this.baseDir = new File(System.getProperty("jetty.base",homeDir.getAbsolutePath())); + 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) + { + 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(System.getProperty("jetty.home",(homeDir==null?baseDir:homeDir).getAbsolutePath())); + + baseDir=baseDir.getAbsoluteFile().getCanonicalFile(); + homeDir=homeDir.getAbsoluteFile().getCanonicalFile(); + } + catch(IOException | URISyntaxException e) + { + throw new RuntimeException(e); + } } public BaseHome(File homeDir, File baseDir) 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 b59dffd5bf1..ce1fc1a7917 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 @@ -23,6 +23,7 @@ import static org.eclipse.jetty.start.UsageException.*; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -44,6 +45,7 @@ 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; import org.eclipse.jetty.start.StartArgs.DownloadArg; @@ -437,13 +439,6 @@ public class Main usage(true); } - // Various Downloads - // TODO should this only be done by init? - for (DownloadArg url : args.getDownloads()) - { - download(url); - } - // Show the version information and return if (args.isListClasspath()) { @@ -486,10 +481,17 @@ public class Main } } + // Initialize - for (String module : args.getInitialize()) + for (String module : args.getModuleStartIni()) { - initialize(args,module,true); + moduleIni(args,module,true,true); + } + + // Initialize + for (String module : args.getModuleIni()) + { + moduleIni(args,module,true,false); } // Informational command line, don't run jetty @@ -612,7 +614,7 @@ public class Main } } - private void initialize(StartArgs args, String name, boolean topLevel) throws IOException + 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"); @@ -627,13 +629,15 @@ public class Main } // 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 start_ini=null; + StartIni module_ini=null; if (ini.exists()) { - start_ini=new StartIni(ini); - if (start_ini.getLineMatches(Pattern.compile("--module=(.*, *)*"+name)).size()==0) + 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; @@ -644,34 +648,79 @@ public class Main 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())) + if (!module.isEnabled() || (transitive && has_ini_lines) || (topLevel && !ini.exists() && !appendStartIni)) { - // Create the directory if needed - if (!start_d.exists()) - start_d.mkdirs(); - // Create a new ini file for it - if (!ini.createNewFile()) + String source=null; + PrintWriter out=null; + try { - StartLog.warn("ERROR: %s cannot be initialised in %s! ",name,short_ini); - return; - } - StartLog.warn("%-15s initialised in %s (created)",name,short_ini); + 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); + } - // Create an ini file - try(PrintWriter 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)); + } + } + } } - - // Add the new ini file to the modules - start_ini=new StartIni(ini); - args.parse(baseHome, start_ini); - for (String enable:start_ini.getLineMatches(Pattern.compile("--module=.*"))) + finally { - modules.enable(enable.substring(enable.indexOf('=')+1).trim(),Collections.singletonList(short_ini)); + if (out!=null) + out.close(); } } else if (ini.exists()) @@ -689,7 +738,6 @@ public class Main // Do downloads now for (String download : module.getDownloads()) download(StartArgs.toDownloadArg(download)); - // Process dependencies from top level only if (topLevel) @@ -707,7 +755,7 @@ public class Main Collections.sort(parents,Collections.reverseOrder(new Module.DepthComparator())); for (Module m : parents) { - initialize(args,m.getName(),false); + moduleIni(args,m.getName(),false,appendStartIni); } } } 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 2637ca4073a..87c2136a660 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 @@ -146,7 +146,8 @@ public class StartArgs private Properties properties = new Properties(); private Set systemPropertyKeys = new HashSet<>(); private List jvmArgs = new ArrayList<>(); - private List initialize = 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; @@ -451,9 +452,14 @@ public class StartArgs return this.commandLine; } - public List getInitialize() + public List getModuleIni() { - return initialize; + return moduleIni; + } + + public List getModuleStartIni() + { + return moduleStartIni; } public List getDownloads() @@ -681,6 +687,9 @@ 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)) @@ -756,11 +765,20 @@ public class StartArgs return; } - if (arg.startsWith("--initialize=") || arg.startsWith("--initialise=") || arg.startsWith("--ini=")) + if (arg.startsWith("--module-ini=")) { if (!CMD_LINE_SOURCE.equals(source)) throw new UsageException(ERR_BAD_ARG,"%s not allowed in %s",arg,source); - initialize.addAll(getValues(arg)); + moduleIni.addAll(getValues(arg)); + run = false; + return; + } + + 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/main/resources/org/eclipse/jetty/start/usage.txt b/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt index 70e8e6c04d1..6c9f975e1b7 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 @@ -57,22 +57,25 @@ Module Management: o The command line o The ${jetty.base}/start.ini o The ${jetty.base}/start.d/*.ini files - o The module persistence file content at - ${jetty.base}/modules/enabled --module= Will 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. - --enable-module= - Will enable a module by adding an entry in the - module persistence file ${jetty.base}/modules/enabled - Note: Do not use within ${jetty.base}/start.ini + --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. - --disable-module= - Will attempt to disable a module by removing an entry in the - module persistence file ${jetty.base}/modules/enabled - Note: Do not use within ${jetty.base}/start.ini + --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. Startup / Shutdown Command Line: -------------------------------- @@ -154,6 +157,6 @@ Properties: Defaults: --------- - A ${jetty.base}/start.ini file may be used to specify default arguments - to start.jar. In case of a conflict between the command line, and - the contents of ${jetty.base}/start.ini, the command line will win. + A ${jetty.base}/start.ini file and/or ${jetty.base|/start.d/*.ini files may be + used to specify default arguments to start.jar. In case of a conflict between + the command line, and ini files, the command line will win. 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 4b559c0fc41..773d91be1e8 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 @@ -115,6 +115,12 @@ public class BaseHomeTest assertFileList(hb,"Files found",expected,files); } + + @Test + public void testDefault() throws IOException + { + BaseHome bh = new BaseHome(); + } @Test public void testGetFile_Both() throws IOException 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 e83e68f8ee7..ff39017e9e3 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 @@ -126,25 +126,6 @@ public class ConfigurationAssert } assertContainsUnordered("Downloads",expectedDownloads,actualDownloads); - // Validate Jvm Args / BootLib Entries - Set expectedJvmArgs = new HashSet<>(); - for (String line : textFile) - { - if (line.startsWith("BOOTLIB|") || line.startsWith("JVM|")) - { - expectedJvmArgs.add(getValue(line)); - } - } - Set actualJvmArgs = new HashSet<>(); - for (String line : args.getJvmArgs()) - { - actualJvmArgs.add(line); - } - assertContainsUnordered("JvmArgs",expectedJvmArgs,actualJvmArgs); - if (expectedJvmArgs.size() > 0) - { - Assert.assertTrue("exec has been turned on",args.isExec()); - } } private static void assertContainsUnordered(String msg, Set expectedSet, Set actualSet) 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 482a834fd12..609f815eef9 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 @@ -68,9 +68,4 @@ public class TestUseCases assertUseCase("home","base.with.db","assert-with-db.txt"); } - @Test - public void testWithModulePersistence() throws Exception - { - assertUseCase("home","base.with.module.persistence","assert-with-module-persistence.txt"); - } } diff --git a/jetty-start/src/test/resources/usecases/home/modules/npn.mod b/jetty-start/src/test/resources/usecases/home/modules/npn.mod index bca2feaccca..c32988666a4 100644 --- a/jetty-start/src/test/resources/usecases/home/modules/npn.mod +++ b/jetty-start/src/test/resources/usecases/home/modules/npn.mod @@ -1,4 +1,4 @@ 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 -BOOTLIB=-Xbootclasspath/p:lib/npn/npn-boot-1.1.5.v20130313.jar \ No newline at end of file +INI=-Xbootclasspath/p:lib/npn/npn-boot-1.1.5.v20130313.jar \ No newline at end of file