From 3dc86bb83489c934d1410cfdff63d24e6f8453f9 Mon Sep 17 00:00:00 2001
From: Attila Szegedi <attila@openjdk.org>
Date: Wed, 6 Aug 2014 11:54:50 +0200
Subject: [PATCH] 8054411: Add nashorn.args.prepend system property

Reviewed-by: hannesw, jlaskey
---
 .../internal/runtime/options/Options.java     | 25 ++++++++++++-------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java b/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java
index db755cb9a0e..ed39fa95481 100644
--- a/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java
+++ b/nashorn/src/jdk/nashorn/internal/runtime/options/Options.java
@@ -78,7 +78,10 @@ public final class Options {
     /** 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 final class Options {
      */
     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 @@ public final class Options {
         }
     }
 
+    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)) {
-- 
GitLab