# HG changeset patch
# User attila
# Date 1407318890 -7200
# Node ID e60692e4f736959b02d6990bc5c89267b536b1a5
# Parent  1a5e1de71e5761323517e3e06a58cfe97d705751
8054411: Add nashorn.args.prepend system property
Reviewed-by: hannesw, jlaskey

diff -r 1a5e1de71e57 -r e60692e4f736 nashorn/src/jdk/nashorn/internal/runtime/options/Options.java
--- a/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java	Wed Aug 06 11:02:14 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java	Wed Aug 06 11:54:50 2014 +0200
@@ -78,7 +78,10 @@
     /** The options map of enabled options */
     private final TreeMap<String, Option<?>> options;
 
-    /** System property that can be used for command line option propagation */
+    /** System property that can be used to prepend options to the explicitly specified command line. */
+    private static final String NASHORN_ARGS_PREPEND_PROPERTY = "nashorn.args.prepend";
+
+    /** System property that can be used to append options to the explicitly specified command line. */
     private static final String NASHORN_ARGS_PROPERTY = "nashorn.args";
 
     /**
@@ -419,15 +422,9 @@
      */
     public void process(final String[] args) {
         final LinkedList<String> argList = new LinkedList<>();
+        addSystemProperties(NASHORN_ARGS_PREPEND_PROPERTY, argList);
         Collections.addAll(argList, args);
-
-        final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null);
-        if (extra != null) {
-            final StringTokenizer st = new StringTokenizer(extra);
-            while (st.hasMoreTokens()) {
-                argList.add(st.nextToken());
-            }
-        }
+        addSystemProperties(NASHORN_ARGS_PROPERTY, argList);
 
         while (!argList.isEmpty()) {
             final String arg = argList.remove(0);
@@ -509,6 +506,16 @@
         }
     }
 
+    private static void addSystemProperties(final String sysPropName, final List<String> argList) {
+        final String sysArgs = getStringProperty(sysPropName, null);
+        if (sysArgs != null) {
+            final StringTokenizer st = new StringTokenizer(sysArgs);
+            while (st.hasMoreTokens()) {
+                argList.add(st.nextToken());
+            }
+        }
+    }
+
     private static OptionTemplate getOptionTemplate(final String key) {
         for (final OptionTemplate t : Options.validOptions) {
             if (t.matches(key)) {