Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] Jetty Plugin Functionality / Getting rid of Jetty Hightide release at codehaus

Hi all,

following our discussion and as announced I've just done a small proof of concept. The current setup is exactly the same as it is before and additional libs/config files are places in the known places. The only thing which is new is the start.d directory which contains additional start.ini files. The syntax of these files is exactly the same as in the main start.ini file and the lines will be just treated as additional lines of the main start.ini.

E.g. for jta an additional file: "20-jta.ini"  has been placed in start.d containing the following two lines:

OPTIONS=plus,jta
etc/jetty-hightide.xml

The options will be added to the options listed in start.ini and the additional config file will be loaded as if it was configured in start.ini itself. For now I've copied over all the jta stuff from jetty hightide and wired it up with the file described above. Works just fine.

Some work needs to be done on the code still. I've some minor refactorings in mind to make the code more readable. And I've not yet tested thoroughly what happens if config files are referenced twice or in the wrong order, etc. But for a proof of concept it does it's job.

I will now evaluate aether (http://www.sonatype.com/people/2010/08/introducing-aether/) and see how we can use that to wire up jetty hightide modules, move them to mvn central and make them available for download/installation via commandline.

Attached you find a patch of the current eclipse jetty trunk adding the POC code I've written.

Cheers,
Thomas


On 11/15/11 6:48 PM, Eirik Bjørsnøs wrote:

Greg,

I think this will support our use case in an easy and simple way!

OPTIONS will inherently be additive, so the += might be superfluous. But that might be getting into bike shed territory..

Thanks,
Eirik.

Den 14. nov. 2011 05.53 skrev "Greg Wilkins" <gregw@xxxxxxxxxxx> følgende:

How about a start.d directory that contains multiple start.ini format files, that are concatenated together to form an effective start.ini ?

We'd need to add += semantics so that for a typical module, their would be file start.d/10-foo.ini

  -Dsome.foo.property=value
  OTPIONS+=foo
  etc/jetty-foo.xml


cheers




_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev



_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev

-- 
thomas becker
tbecker@xxxxxxxxxxx

http://webtide.com / http://intalio.com
(the folks behind jetty and cometd)
>From 9e7fbaaf215e58e22fd85309caa779bea437660a Mon Sep 17 00:00:00 2001
From: Thomas Becker <tbecker@xxxxxxxxxxx>
Date: Wed, 23 Nov 2011 13:02:48 +0100
Subject: [PATCH] 364501: Proof of Concept for plugin functionality

---
 .../main/java/org/eclipse/jetty/start/Main.java    |  217 ++++++++------------
 .../org/eclipse/jetty/start/StartIniParser.java    |  104 ++++++++++
 .../eclipse/jetty/start/StartIniParserTest.java    |   65 ++++++
 .../test/resources/jetty.home/start.d/10-jmx.ini   |   22 ++
 .../resources/jetty.home/start.d/20-websocket.ini  |   13 ++
 .../src/test/resources/jetty.home/start.ini        |   66 ++++++
 6 files changed, 352 insertions(+), 135 deletions(-)
 create mode 100644 jetty-start/src/main/java/org/eclipse/jetty/start/StartIniParser.java
 create mode 100644 jetty-start/src/test/java/org/eclipse/jetty/start/StartIniParserTest.java
 create mode 100644 jetty-start/src/test/resources/jetty.home/start.d/10-jmx.ini
 create mode 100644 jetty-start/src/test/resources/jetty.home/start.d/20-websocket.ini
 create mode 100644 jetty-start/src/test/resources/jetty.home/start.ini

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 4e2d611..0a7c202 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 @@ 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;
@@ -30,7 +29,6 @@ import java.lang.reflect.Method;
 import java.net.ConnectException;
 import java.net.InetAddress;
 import java.net.Socket;
-import java.security.Policy;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -40,17 +38,15 @@ import java.util.List;
 import java.util.Properties;
 import java.util.Set;
 
-
 /*-------------------------------------------*/
 /**
  * <p>
- * 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".
  * </p>
- * 
+ *
  * <p>
- * 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.
  * </p>
  */
 public class Main
@@ -70,6 +66,7 @@ public class Main
     private Set<String> _sysProps = new HashSet<String>();
     private List<String> _jvmArgs = new ArrayList<String>();
     private String _startConfig = null;
+    private StartIniParser _startIniParser = new StartIniParser();
 
     private String _jettyHome;
 
@@ -86,39 +83,39 @@ public class Main
             List<String> arguments = new ArrayList<String>();
 
             // add the command line args and look for start.ini args
-            boolean ini=false;
+            boolean ini = false;
             for (String arg : args)
             {
-                if (arg.startsWith("--ini=")||arg.equals("--ini"))
+                if (arg.startsWith("--ini=") || arg.equals("--ini"))
                 {
-                    ini=true;
-                    if (arg.length()>6)
+                    ini = true;
+                    if (arg.length() > 6)
                     {
-                        arguments.addAll(loadStartIni(arg.substring(6)));
+                        arguments.addAll(_startIniParser.loadStartIni(arg.substring(6)));
                         continue;
                     }
                 }
                 else if (arg.startsWith("--config="))
                 {
-                    _startConfig=arg.substring(9);
+                    _startConfig = arg.substring(9);
                 }
                 else
                 {
                     arguments.add(arg);
                 }
             }
-            
+
             // if no non-option inis, add the start.ini
             if (!ini)
             {
-                arguments.addAll(0,loadStartIni(null));
+                arguments.addAll(0,_startIniParser.loadStartIni(null));
             }
-            
+
             // The XML Configuration Files to initialize with
             List<String> xmls = new ArrayList<String>();
 
             // Process the arguments
-            int startup=0;
+            int startup = 0;
             for (String arg : arguments)
             {
                 if ("--help".equals(arg) || "-?".equals(arg))
@@ -149,11 +146,11 @@ public class Main
 
                 if ("--list-config".equals(arg))
                 {
-                    _listConfig=true;
+                    _listConfig = true;
                     continue;
                 }
 
-                if ("--exec-print".equals(arg)||"--dry-run".equals(arg))
+                if ("--exec-print".equals(arg) || "--dry-run".equals(arg))
                 {
                     _dryRun = true;
                     continue;
@@ -169,7 +166,7 @@ public class Main
                 if ("--daemon".equals(arg))
                 {
                     File startDir = new File(System.getProperty("jetty.logs","logs"));
-                    if (!startDir.exists() || !startDir.canWrite() )
+                    if (!startDir.exists() || !startDir.canWrite())
                         startDir = new File(".");
                     File startLog = new File(startDir,"start.log");
                     if (!startLog.exists() && !startLog.createNewFile())
@@ -193,18 +190,18 @@ public class Main
                     System.out.println("Establishing start.log on " + new Date());
                     continue;
                 }
-                
+
                 if (arg.startsWith("--pre="))
                 {
                     xmls.add(startup++,arg.substring(6));
                     continue;
                 }
-                
+
                 if (arg.startsWith("-D"))
                 {
                     String[] assign = arg.substring(2).split("=",2);
                     _sysProps.add(assign[0]);
-                    switch(assign.length)
+                    switch (assign.length)
                     {
                         case 2:
                             System.setProperty(assign[0],assign[1]);
@@ -229,7 +226,7 @@ public class Main
                 {
                     String[] assign = arg.split("=",2);
 
-                    switch(assign.length)
+                    switch (assign.length)
                     {
                         case 2:
                             if ("OPTIONS".equals(assign[0]))
@@ -249,19 +246,19 @@ public class Main
                         default:
                             break;
                     }
-                    
+
                     continue;
                 }
-                
+
                 // 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("WARN: Argument '" + arg + "' specified multiple times. Check start.ini?");
                     System.out.println("Use \"java -jar start.jar --help\" for more information.");
                 }
                 xmls.add(arg);
             }
-            
+
             start(xmls);
         }
         catch (Throwable t)
@@ -270,56 +267,6 @@ public class Main
         }
     }
 
-    /**
-     * If a start.ini is present in the CWD, then load it into the argument list.
-     */
-    private List<String> loadStartIni(String ini)
-    {
-        String jettyHome=System.getProperty("jetty.home");
-        File startIniFile = ini==null?((jettyHome!=null)?  new File(jettyHome,"start.ini"):new File("start.ini")):new File(ini);
-        if (!startIniFile.exists())
-        {
-            if (ini != null)
-            {
-                System.err.println("Warning - can't find ini file: " + ini);
-            }
-            // No start.ini found, skip load.
-            return Collections.emptyList();
-        }
-
-        List<String> args = new ArrayList<String>();
-
-        FileReader reader = null;
-        BufferedReader buf = null;
-        try
-        {
-            reader = new FileReader(startIniFile);
-            buf = new BufferedReader(reader);
-
-            String arg;
-            while ((arg = buf.readLine()) != null)
-            {
-                arg = arg.trim();
-                if (arg.length() == 0 || arg.startsWith("#"))
-                {
-                    continue;
-                }
-                args.add(arg);
-            }
-        }
-        catch (IOException e)
-        {
-            usageExit(e,ERR_UNKNOWN);
-        }
-        finally
-        {
-            close(buf);
-            close(reader);
-        }
-
-        return args;
-    }
-
     private void usage()
     {
         String usageResource = "org/eclipse/jetty/start/usage.txt";
@@ -339,10 +286,10 @@ public class Main
 
             while ((line = buf.readLine()) != null)
             {
-                if (line.endsWith("@") && line.indexOf('@')!=line.lastIndexOf('@'))
+                if (line.endsWith("@") && line.indexOf('@') != line.lastIndexOf('@'))
                 {
-                    String indent=line.substring(0,line.indexOf("@"));
-                    String info=line.substring(line.indexOf('@'),line.lastIndexOf('@'));
+                    String indent = line.substring(0,line.indexOf("@"));
+                    String info = line.substring(line.indexOf('@'),line.lastIndexOf('@'));
 
                     if (info.equals("@OPTIONS"))
                     {
@@ -352,7 +299,7 @@ public class Main
 
                         for (String option : sortedOptions)
                         {
-                            if ("*".equals(option) || option.trim().length()==0)
+                            if ("*".equals(option) || option.trim().length() == 0)
                                 continue;
                             System.out.print(indent);
                             System.out.println(option);
@@ -395,8 +342,8 @@ public class Main
                     }
                     else if (info.equals("@STARTINI"))
                     {
-                        List<String> ini = loadStartIni(null);
-                        if (ini!=null && ini.size()>0)
+                        List<String> ini = _startIniParser.loadStartIni(null);
+                        if (ini != null && ini.size() > 0)
                         {
                             for (String a : ini)
                             {
@@ -429,7 +376,7 @@ public class Main
     }
 
     public void invokeMain(ClassLoader classloader, String classname, List<String> args) throws IllegalAccessException, InvocationTargetException,
-    NoSuchMethodException, ClassNotFoundException
+            NoSuchMethodException, ClassNotFoundException
     {
         Class<?> invoked_class = null;
 
@@ -462,10 +409,12 @@ public class Main
 
         String argArray[] = args.toArray(new String[0]);
 
-        Class<?>[] method_param_types = new Class[] { argArray.getClass() };
+        Class<?>[] method_param_types = new Class[]
+        { argArray.getClass() };
 
         Method main = invoked_class.getDeclaredMethod("main",method_param_types);
-        Object[] method_params = new Object[] { argArray };
+        Object[] method_params = new Object[]
+        { argArray };
         main.invoke(null,method_params);
     }
 
@@ -492,13 +441,12 @@ public class Main
         // Setup Start / Stop Monitoring
         int port = Integer.parseInt(Config.getProperty("STOP.PORT","-1"));
         String key = Config.getProperty("STOP.KEY",null);
-        Monitor monitor=new Monitor(port,key);
-        
+        Monitor monitor = new Monitor(port,key);
 
         // Load potential Config (start.config)
         List<String> configuredXmls = loadConfig(xmls);
 
-        // No XML defined in start.config or command line.  Can't execute.
+        // 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.");
@@ -523,7 +471,7 @@ public class Main
             System.err.println("classloader.parent=" + cl.getParent());
             System.err.println("properties=" + Config.getProperties());
         }
-        
+
         // Show the usage information and return
         if (_showUsage)
         {
@@ -544,7 +492,7 @@ public class Main
             showAllOptionsWithVersions(classpath);
             return;
         }
-        
+
         if (_listConfig)
         {
             listConfig();
@@ -557,7 +505,7 @@ public class Main
             System.out.println(buildCommandLine(classpath,configuredXmls));
             return;
         }
-        
+
         // execute Jetty in another JVM
         if (_exec)
         {
@@ -565,11 +513,12 @@ public class Main
             final Process process = Runtime.getRuntime().exec(cmd);
             Runtime.getRuntime().addShutdownHook(new Thread()
             {
+                @Override
                 public void run()
                 {
                     Config.debug("Destroying " + process);
                     process.destroy();
-                }  
+                }
             });
             copyInThread(process.getErrorStream(),System.err);
             copyInThread(process.getInputStream(),System.out);
@@ -578,7 +527,7 @@ public class Main
             process.waitFor();
             return;
         }
-        
+
         if (_jvmArgs.size() > 0 || _sysProps.size() > 0)
         {
             System.err.println("WARNING: System properties and/or JVM args set.  Consider using --dry-run or --exec");
@@ -617,7 +566,7 @@ public class Main
         }
     }
 
-    private void copyInThread(final InputStream in,final OutputStream out)
+    private void copyInThread(final InputStream in, final OutputStream out)
     {
         new Thread(new Runnable()
         {
@@ -625,23 +574,23 @@ public class Main
             {
                 try
                 {
-                    byte[] buf=new byte[1024];
-                    int len=in.read(buf);
-                    while(len>0)
+                    byte[] buf = new byte[1024];
+                    int len = in.read(buf);
+                    while (len > 0)
                     {
                         out.write(buf,0,len);
-                        len=in.read(buf);
+                        len = in.read(buf);
                     }
                 }
-                catch(IOException e)
+                catch (IOException e)
                 {
                     // e.printStackTrace();
                 }
             }
-            
+
         }).start();
     }
-    
+
     private String resolveXmlConfig(String xmlFilename) throws FileNotFoundException
     {
         if (!xmlFilename.toLowerCase().endsWith(".xml"))
@@ -675,22 +624,22 @@ public class Main
     {
         StringBuilder cmd = new StringBuilder();
         cmd.append(findJavaBin());
-        for (String x:_jvmArgs)
+        for (String x : _jvmArgs)
             cmd.append(' ').append(x);
         cmd.append(" -Djetty.home=").append(_jettyHome);
-        for (String p:_sysProps)
+        for (String p : _sysProps)
         {
             cmd.append("   -D").append(p);
-            String v=System.getProperty(p);
-            if (v!=null && v.length()>0)
+            String v = System.getProperty(p);
+            if (v != null && v.length() > 0)
                 cmd.append('=').append(v);
         }
         cmd.append("   -cp ").append(classpath.toString());
         cmd.append("   ").append(_config.getMainClassname());
-        
+
         // Check if we need to pass properties as a file
         Properties properties = Config.getProperties();
-        if (properties.size()>0) 
+        if (properties.size() > 0)
         {
             File prop_file = File.createTempFile("start",".properties");
             if (!_dryRun)
@@ -698,7 +647,7 @@ public class Main
             properties.store(new FileOutputStream(prop_file),"start.jar properties");
             cmd.append(" ").append(prop_file.getAbsolutePath());
         }
-        
+
         for (String xml : xmls)
         {
             cmd.append(' ').append(xml);
@@ -875,11 +824,10 @@ public class Main
 
     private String getZipVersion(File element)
     {
-        // TODO - find version in zip file.  Look for META-INF/MANIFEST.MF ?
+        // TODO - find version in zip file. Look for META-INF/MANIFEST.MF ?
         return "";
     }
 
-
     private List<String> resolveXmlConfigs(List<String> xmls) throws FileNotFoundException
     {
         List<String> ret = new ArrayList<String>();
@@ -896,15 +844,15 @@ public class Main
         InputStream cfgstream = null;
         try
         {
-            cfgstream=getConfigStream();
-            byte[] buf=new byte[4096];
-            
-            int len=0;
-            
-            while (len>=0)
+            cfgstream = getConfigStream();
+            byte[] buf = new byte[4096];
+
+            int len = 0;
+
+            while (len >= 0)
             {
-                len=cfgstream.read(buf);
-                if (len>0)
+                len = cfgstream.read(buf);
+                if (len > 0)
                     System.out.write(buf,0,len);
             }
         }
@@ -917,13 +865,13 @@ public class Main
             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.
-     * 
+     *
+     * 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.
@@ -935,12 +883,12 @@ public class Main
         {
             // Pass in xmls.size into Config so that conditions based on "nargs" work.
             _config.setArgCount(xmls.size());
-            
-            cfgstream=getConfigStream();
-                
+
+            cfgstream = getConfigStream();
+
             // parse the config
             _config.parse(cfgstream);
-            
+
             _jettyHome = Config.getProperty("jetty.home");
             if (_jettyHome != null)
             {
@@ -975,12 +923,12 @@ public class Main
 
     private InputStream getConfigStream() throws FileNotFoundException
     {
-        String config=_startConfig;
+        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.
@@ -991,11 +939,10 @@ public class Main
         {
             cfgstream = new FileInputStream(config);
         }
-        
+
         return cfgstream;
     }
 
-
     /**
      * Stop a running jetty instance.
      */
@@ -1038,7 +985,6 @@ public class Main
             usageExit(e,ERR_UNKNOWN);
         }
     }
-    
 
     static void usageExit(Throwable t, int exit)
     {
@@ -1048,6 +994,7 @@ public class Main
         System.err.println("       java -jar start.jar --help  # for more information");
         System.exit(exit);
     }
+
     static void usageExit(int exit)
     {
         System.err.println();
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartIniParser.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIniParser.java
new file mode 100644
index 0000000..435a7fe
--- /dev/null
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartIniParser.java
@@ -0,0 +1,104 @@
+// ========================================================================
+// Copyright (c) 2009-2009 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.FileReader;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/* ------------------------------------------------------------ */
+/**
+ */
+public class StartIniParser
+{
+    /**
+     * If a start.ini is present in the CWD, then load it into the argument list.
+     */
+    public List<String> loadStartIni(String ini)
+    {
+        String jettyHome = System.getProperty("jetty.home");
+        File startIniFile = ini == null?((jettyHome != null)?new File(jettyHome,"start.ini"):new File("start.ini")):new File(ini);
+        if (!startIniFile.exists())
+        {
+            if (ini != null)
+            {
+                System.err.println("Warning - can't find ini file: " + ini);
+            }
+            // No start.ini found, skip load.
+            return Collections.emptyList();
+        }
+
+        List<String> args = new ArrayList<String>();
+
+        List<File> startIniFiles = new ArrayList<File>();
+        startIniFiles.add(startIniFile);
+        startIniFiles.addAll(getAdditionalStartIniFiles());
+
+        for (File file : startIniFiles)
+        {
+            FileReader reader = null;
+            BufferedReader buf = null;
+            try
+            {
+                reader = new FileReader(file);
+                buf = new BufferedReader(reader);
+
+                String arg;
+                while ((arg = buf.readLine()) != null)
+                {
+                    arg = arg.trim();
+                    if (arg.length() == 0 || arg.startsWith("#"))
+                    {
+                        continue;
+                    }
+                    args.add(arg);
+                }
+            }
+            catch (IOException e)
+            {
+                // usageExit(e,ERR_UNKNOWN);
+            }
+            finally
+            {
+                Main.close(buf);
+                Main.close(reader);
+            }
+        }
+
+        return args;
+    }
+
+    List<File> getAdditionalStartIniFiles()
+    {
+        String jettyHome = System.getProperty("jetty.home") == null?".":System.getProperty("jetty.home");
+        File file = new File(jettyHome + "/start.d");
+        if (file.exists())
+            return Arrays.asList(file.listFiles(new iniExtensionFilter()));
+        return Collections.emptyList();
+    }
+
+    private class iniExtensionFilter implements FilenameFilter
+    {
+        public boolean accept(File dir, String name)
+        {
+            return (name.endsWith(".ini"));
+        }
+    }
+}
diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/StartIniParserTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/StartIniParserTest.java
new file mode 100644
index 0000000..62b2d77
--- /dev/null
+++ b/jetty-start/src/test/java/org/eclipse/jetty/start/StartIniParserTest.java
@@ -0,0 +1,65 @@
+// ========================================================================
+// Copyright (c) 2009-2009 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.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.net.URL;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/* ------------------------------------------------------------ */
+/**
+ */
+public class StartIniParserTest
+{
+    StartIniParser startIniParser = new StartIniParser();
+
+    /* ------------------------------------------------------------ */
+    /**
+     * @throws java.lang.Exception
+     */
+    @Before
+    public void setUp() throws Exception
+    {
+        System.setProperty("jetty.home",this.getClass().getResource("/jetty.home").getFile());
+    }
+
+    /**
+     * Test method for {@link org.eclipse.jetty.start.StartIniParser#loadStartIni(java.lang.String)}.
+     */
+    @Test
+    public void testLoadStartIni()
+    {
+        URL startIni = this.getClass().getResource("/jetty.home/start.ini");
+        String startIniFileName = startIni.getFile();
+        List<String> args = startIniParser.loadStartIni(startIniFileName);
+        assertEquals("Expected 9 uncommented lines in start.ini",9,args.size());
+        assertEquals("First uncommented line in start.ini doesn't match expected result","OPTIONS=Server,jsp,resources,websocket,ext",args.get(0));
+    }
+
+    /**
+     * Test method for {@link org.eclipse.jetty.start.StartIniParser#getAdditionalStartIniFiles().
+     */
+    @Test
+    public void testGetAdditionalStartIniFiles()
+    {
+        List<File> files = startIniParser.getAdditionalStartIniFiles();
+        assertEquals(2,files.size());
+    }
+
+}
diff --git a/jetty-start/src/test/resources/jetty.home/start.d/10-jmx.ini b/jetty-start/src/test/resources/jetty.home/start.d/10-jmx.ini
new file mode 100644
index 0000000..356fccd
--- /dev/null
+++ b/jetty-start/src/test/resources/jetty.home/start.d/10-jmx.ini
@@ -0,0 +1,22 @@
+#===========================================================
+# Additional Jetty start.jar arguments
+# Each line of this file is prepended to the command line 
+# arguments # of a call to:
+#    java -jar start.jar [arg...]
+#===========================================================
+
+
+
+#===========================================================
+#-----------------------------------------------------------
+OPTIONS=jmx
+#-----------------------------------------------------------
+
+
+#===========================================================
+# Configuration files.
+# For a full list of available configuration files do
+#   java -jar start.jar --help
+#-----------------------------------------------------------
+etc/jetty-jmx.xml
+#===========================================================
diff --git a/jetty-start/src/test/resources/jetty.home/start.d/20-websocket.ini b/jetty-start/src/test/resources/jetty.home/start.d/20-websocket.ini
new file mode 100644
index 0000000..679a221
--- /dev/null
+++ b/jetty-start/src/test/resources/jetty.home/start.d/20-websocket.ini
@@ -0,0 +1,13 @@
+#===========================================================
+# Additional Jetty start.jar arguments
+# Each line of this file is prepended to the command line 
+# arguments # of a call to:
+#    java -jar start.jar [arg...]
+#===========================================================
+
+
+
+#===========================================================
+#-----------------------------------------------------------
+OPTIONS=websocket
+#-----------------------------------------------------------
\ No newline at end of file
diff --git a/jetty-start/src/test/resources/jetty.home/start.ini b/jetty-start/src/test/resources/jetty.home/start.ini
new file mode 100644
index 0000000..6b019e3
--- /dev/null
+++ b/jetty-start/src/test/resources/jetty.home/start.ini
@@ -0,0 +1,66 @@
+#===========================================================
+# Jetty start.jar arguments
+# Each line of this file is prepended to the command line 
+# arguments # of a call to:
+#    java -jar start.jar [arg...]
+#===========================================================
+
+
+
+#===========================================================
+# If the arguements in this file include JVM arguments 
+# (eg -Xmx512m) or JVM System properties (eg com.sun.???),
+# then these will not take affect unless the --exec 
+# parameter is included or if the output from --dry-run
+# is executed like:
+#   eval $(java -jar start.jar --dry-run)
+#
+# Below are some recommended options for Sun's JRE
+#-----------------------------------------------------------
+# --exec
+# -Dorg.apache.jasper.compiler.disablejsr199=true
+# -Dcom.sun.management.jmxremote
+# -Dorg.eclipse.jetty.util.log.IGNORED=true
+# -Dorg.eclipse.jetty.util.log.stderr.DEBUG=true
+# -Dorg.eclipse.jetty.util.log.stderr.SOURCE=true
+# -Xmx2000m
+# -Xmn512m
+# -verbose:gc
+# -XX:+PrintGCDateStamps
+# -XX:+PrintGCTimeStamps
+# -XX:+PrintGCDetails
+# -XX:+PrintTenuringDistribution
+# -XX:+PrintCommandLineFlags
+# -XX:+DisableExplicitGC
+# -XX:+UseConcMarkSweepGC
+# -XX:ParallelCMSThreads=2
+# -XX:+CMSClassUnloadingEnabled  
+# -XX:+UseCMSCompactAtFullCollection
+# -XX:CMSInitiatingOccupancyFraction=80
+#-----------------------------------------------------------
+
+
+#===========================================================
+# Start classpath OPTIONS.
+# These control what classes are on the classpath
+# for a full listing do
+#   java -jar start.jar --list-options
+#-----------------------------------------------------------
+OPTIONS=Server,jsp,resources,websocket,ext
+#-----------------------------------------------------------
+
+
+#===========================================================
+# Configuration files.
+# For a full list of available configuration files do
+#   java -jar start.jar --help
+#-----------------------------------------------------------
+etc/jetty.xml
+# etc/jetty-ssl.xml
+# etc/jetty-requestlog.xml
+etc/jetty-deploy.xml
+#etc/jetty-overlay.xml
+etc/jetty-webapps.xml
+etc/jetty-contexts.xml
+etc/jetty-testrealm.xml
+#===========================================================
-- 
1.7.4.4


Back to the top