415826 start.jar replace --enable with --module-ini

Added --module-ini and --module-start-ini
jetty.base is set from user.dir
jetty.home is set from start.jar dir
This commit is contained in:
Greg Wilkins 2013-08-29 12:37:50 +10:00
parent e5b4f37b62
commit aec807804d
14 changed files with 166 additions and 100 deletions

View File

@ -478,7 +478,8 @@
<arguments>
<argument>-jar</argument>
<argument>start.jar</argument>
<argument>--ini=http,demo</argument>
<argument>--module-start-ini=server,ext,resources,jsp,annotations</argument>
<argument>--module-ini=http,demo</argument>
</arguments>
</configuration>
</plugin>

View File

@ -1,8 +0,0 @@
#
# Base Module
#
OPTIONAL=jmx
LIB=lib/jetty-util-${jetty.version}.jar
LIB=lib/jetty-io-${jetty.version}.jar

View File

@ -0,0 +1,2 @@
LIB=lib/ext/*

View File

@ -0,0 +1,2 @@
LIB=resources

View File

@ -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
@ -21,3 +26,5 @@ INI=threads.timeout=60000
INI=#jetty.host=myhost.com
INI=jetty.dump.start=false
INI=jetty.dump.stop=false

View File

@ -1,8 +0,0 @@
#
# Jetty XML Configuration
#
DEPEND=base
LIB=lib/jetty-xml-${jetty.version}.jar

View File

@ -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)

View File

@ -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))
{
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;
}
StartLog.warn("%-15s initialised in %s (created)",name,short_ini);
// Create an ini file
try(PrintWriter out = new PrintWriter(ini))
{
out.println("# Initialize module "+name);
out.println("--module="+name);
for (String line : module.getInitialise())
out.println(line);
source=short_ini;
StartLog.warn("%-15s initialised in %s (created)",name,source);
out = new PrintWriter(ini);
}
// 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=.*")))
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())
{
modules.enable(enable.substring(enable.indexOf('=')+1).trim(),Collections.singletonList(short_ini));
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())
@ -690,7 +739,6 @@ public class Main
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);
}
}
}

View File

@ -146,7 +146,8 @@ public class StartArgs
private Properties properties = new Properties();
private Set<String> systemPropertyKeys = new HashSet<>();
private List<String> jvmArgs = new ArrayList<>();
private List<String> initialize = new ArrayList<>();
private List<String> moduleIni = new ArrayList<>();
private List<String> moduleStartIni = new ArrayList<>();
private List<String> modulePersistEnable = new ArrayList<>();
private List<String> modulePersistDisable = new ArrayList<>();
private Modules allModules;
@ -451,9 +452,14 @@ public class StartArgs
return this.commandLine;
}
public List<String> getInitialize()
public List<String> getModuleIni()
{
return initialize;
return moduleIni;
}
public List<String> getModuleStartIni()
{
return moduleStartIni;
}
public List<DownloadArg> 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;
}

View File

@ -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=<modulename>
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=<modulename>
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=<modulename>
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=<modulename>
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=<modulename>
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.

View File

@ -116,6 +116,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
{

View File

@ -126,25 +126,6 @@ public class ConfigurationAssert
}
assertContainsUnordered("Downloads",expectedDownloads,actualDownloads);
// Validate Jvm Args / BootLib Entries
Set<String> expectedJvmArgs = new HashSet<>();
for (String line : textFile)
{
if (line.startsWith("BOOTLIB|") || line.startsWith("JVM|"))
{
expectedJvmArgs.add(getValue(line));
}
}
Set<String> 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<String> expectedSet, Set<String> actualSet)

View File

@ -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");
}
}

View File

@ -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
INI=-Xbootclasspath/p:lib/npn/npn-boot-1.1.5.v20130313.jar