From 02d17edb777b31fa67b50ca8f927f14f7abd5a76 Mon Sep 17 00:00:00 2001 From: janakmulani Date: Thu, 1 Aug 2024 18:30:11 +0530 Subject: [PATCH 1/5] OWS-634: Allow deployment config to load a custom properties file --- .../jnlp/config/DeploymentConfiguration.java | 23 ++++++++++++++----- .../sourceforge/jnlp/runtime/JNLPRuntime.java | 8 ++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java index 20c9d4715..78a2899f5 100644 --- a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java +++ b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java @@ -165,10 +165,10 @@ static boolean checkUrl(final URL file) { * * @throws ConfigurationException if it encounters a fatal error. */ - public void load() throws ConfigurationException { + public void load(File... propFile) throws ConfigurationException { LOG.debug("Start DeploymentConfiguration.load()"); try { - load(true); + load(true, propFile); } catch (final MalformedURLException ex) { throw new ConfigurationException(ex.toString()); } finally { @@ -184,10 +184,14 @@ public void load() throws ConfigurationException { * resorting to the default values * @throws ConfigurationException if it encounters a fatal error. */ - public void load(final boolean fixIssues) throws ConfigurationException, MalformedURLException { + public void load(final boolean fixIssues, File... propFile ) throws ConfigurationException, MalformedURLException { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { - sm.checkRead(userDeploymentFileDescriptor.getFullPath()); + if (propFile.length > 0) { + sm.checkRead(clean(propFile[0].getAbsolutePath())); + } else { + sm.checkRead(userDeploymentFileDescriptor.getFullPath()); + } } final Map properties = Defaults.getDefaults(); @@ -202,9 +206,9 @@ public void load(final boolean fixIssues) throws ConfigurationException, Malform } /* - * Third, read the user's subdirResult deployment.properties file + * Third, read the user's subdirResult deployment.properties file or the custom config properties */ - userPropertiesFile = userDeploymentFileDescriptor.getFile(); + userPropertiesFile = propFile.length > 0 ? propFile[0] : userDeploymentFileDescriptor.getFile(); final URL userPropertiesUrl = userPropertiesFile.toURI().toURL(); final Map userProperties = loadProperties(ConfigType.USER, userPropertiesUrl, false); userComments = loadComments(userPropertiesUrl); @@ -697,4 +701,11 @@ public static String VVPossibleBrowserValues() { ConfigurationConstants.KEY_BROWSER_PATH ); } + + private static String clean(String s) { + while (s.contains(File.separator + File.separator)) { + s = s.replace(File.separator + File.separator, File.separator); + } + return s; + } } diff --git a/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java index 375f4db03..ee04ae4bb 100644 --- a/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -459,7 +459,13 @@ private static class DeploymentConfigurationHolder { static { DeploymentConfiguration config = new DeploymentConfiguration(); try { - config.load(); + final String owsUserPropertiesFilename = System.getProperty("owsUserPropertiesFilename"); + if (owsUserPropertiesFilename != null) { + LOG.debug("Loading config from file {} ", owsUserPropertiesFilename); + config.load(new File(owsUserPropertiesFilename)); + } else { + config.load(); + } config.copyTo(System.getProperties()); } catch (ConfigurationException ex) { LOG.info("Fatal error while reading the configuration, continuing with empty. Please fix"); From e7428c3224dd659f1d04e3293ca555ca7704ddcb Mon Sep 17 00:00:00 2001 From: janakmulani Date: Thu, 1 Aug 2024 22:40:03 +0530 Subject: [PATCH 2/5] OWS-634: Allow deployment config to load a custom properties file --- .../jnlp/config/DeploymentConfiguration.java | 13 +++++++------ .../net/sourceforge/jnlp/runtime/JNLPRuntime.java | 8 +------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java index 78a2899f5..0c30e1f50 100644 --- a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java +++ b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java @@ -165,10 +165,10 @@ static boolean checkUrl(final URL file) { * * @throws ConfigurationException if it encounters a fatal error. */ - public void load(File... propFile) throws ConfigurationException { + public void load() throws ConfigurationException { LOG.debug("Start DeploymentConfiguration.load()"); try { - load(true, propFile); + load(true); } catch (final MalformedURLException ex) { throw new ConfigurationException(ex.toString()); } finally { @@ -184,11 +184,12 @@ public void load(File... propFile) throws ConfigurationException { * resorting to the default values * @throws ConfigurationException if it encounters a fatal error. */ - public void load(final boolean fixIssues, File... propFile ) throws ConfigurationException, MalformedURLException { + public void load(final boolean fixIssues) throws ConfigurationException, MalformedURLException { + final String owsUserPropertiesFilePath = System.getProperty("owsUserPropertiesFilePath"); final SecurityManager sm = System.getSecurityManager(); if (sm != null) { - if (propFile.length > 0) { - sm.checkRead(clean(propFile[0].getAbsolutePath())); + if (owsUserPropertiesFilePath != null) { + sm.checkRead(owsUserPropertiesFilePath); } else { sm.checkRead(userDeploymentFileDescriptor.getFullPath()); } @@ -208,7 +209,7 @@ public void load(final boolean fixIssues, File... propFile ) throws Configuratio /* * Third, read the user's subdirResult deployment.properties file or the custom config properties */ - userPropertiesFile = propFile.length > 0 ? propFile[0] : userDeploymentFileDescriptor.getFile(); + userPropertiesFile = owsUserPropertiesFilePath != null ? new File(owsUserPropertiesFilePath) : userDeploymentFileDescriptor.getFile(); final URL userPropertiesUrl = userPropertiesFile.toURI().toURL(); final Map userProperties = loadProperties(ConfigType.USER, userPropertiesUrl, false); userComments = loadComments(userPropertiesUrl); diff --git a/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java index ee04ae4bb..375f4db03 100644 --- a/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/core/src/main/java/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -459,13 +459,7 @@ private static class DeploymentConfigurationHolder { static { DeploymentConfiguration config = new DeploymentConfiguration(); try { - final String owsUserPropertiesFilename = System.getProperty("owsUserPropertiesFilename"); - if (owsUserPropertiesFilename != null) { - LOG.debug("Loading config from file {} ", owsUserPropertiesFilename); - config.load(new File(owsUserPropertiesFilename)); - } else { - config.load(); - } + config.load(); config.copyTo(System.getProperties()); } catch (ConfigurationException ex) { LOG.info("Fatal error while reading the configuration, continuing with empty. Please fix"); From fcd4a55e9d77e153326a62ad2fc4a5e754da42e3 Mon Sep 17 00:00:00 2001 From: janakmulani Date: Wed, 28 Aug 2024 15:24:29 +0530 Subject: [PATCH 3/5] OWS-634: Allow deployment config to load a custom properties file --- .../jnlp/config/DeploymentConfiguration.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java index 0c30e1f50..2baaf8aa9 100644 --- a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java +++ b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java @@ -35,11 +35,9 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; -import java.io.Reader; import java.net.ConnectException; import java.net.MalformedURLException; import java.net.URL; -import java.net.URLConnection; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Date; @@ -65,6 +63,7 @@ public final class DeploymentConfiguration { private static final Logger LOG = LoggerFactory.getLogger(DeploymentConfiguration.class); public static final String LOCKED_POSTFIX = ".locked"; + public static final String LOCAL_DEPLOYMENT_PROPERTIES_FILE_PATH = "localDeploymentPropertiesFilePath"; private String userComments; @@ -185,11 +184,11 @@ public void load() throws ConfigurationException { * @throws ConfigurationException if it encounters a fatal error. */ public void load(final boolean fixIssues) throws ConfigurationException, MalformedURLException { - final String owsUserPropertiesFilePath = System.getProperty("owsUserPropertiesFilePath"); + final String localDeploymentPropertiesFilePath = System.getProperty(LOCAL_DEPLOYMENT_PROPERTIES_FILE_PATH); final SecurityManager sm = System.getSecurityManager(); if (sm != null) { - if (owsUserPropertiesFilePath != null) { - sm.checkRead(owsUserPropertiesFilePath); + if (localDeploymentPropertiesFilePath != null) { + sm.checkRead(localDeploymentPropertiesFilePath); } else { sm.checkRead(userDeploymentFileDescriptor.getFullPath()); } @@ -209,7 +208,7 @@ public void load(final boolean fixIssues) throws ConfigurationException, Malform /* * Third, read the user's subdirResult deployment.properties file or the custom config properties */ - userPropertiesFile = owsUserPropertiesFilePath != null ? new File(owsUserPropertiesFilePath) : userDeploymentFileDescriptor.getFile(); + userPropertiesFile = localDeploymentPropertiesFilePath != null ? new File(localDeploymentPropertiesFilePath) : userDeploymentFileDescriptor.getFile(); final URL userPropertiesUrl = userPropertiesFile.toURI().toURL(); final Map userProperties = loadProperties(ConfigType.USER, userPropertiesUrl, false); userComments = loadComments(userPropertiesUrl); From f742b345027addcae3b134bac7973179ba5e0168 Mon Sep 17 00:00:00 2001 From: janakmulani Date: Fri, 25 Oct 2024 15:32:52 +0530 Subject: [PATCH 4/5] OWS-637: Allow paths relative to USER HOME dir in deployment.properties file --- .../jnlp/config/DeploymentConfiguration.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java index 2baaf8aa9..13c0e032f 100644 --- a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java +++ b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java @@ -16,6 +16,7 @@ package net.sourceforge.jnlp.config; +import net.adoptopenjdk.icedteaweb.JavaSystemProperties; import net.adoptopenjdk.icedteaweb.config.validators.ValueValidator; import net.adoptopenjdk.icedteaweb.http.CloseableConnection; import net.adoptopenjdk.icedteaweb.http.ConnectionFactory; @@ -65,6 +66,7 @@ public final class DeploymentConfiguration { public static final String LOCKED_POSTFIX = ".locked"; public static final String LOCAL_DEPLOYMENT_PROPERTIES_FILE_PATH = "localDeploymentPropertiesFilePath"; + public static final String USER_HOME_DIR_TOKEN = "#USER_HOME_DIR#"; private String userComments; private ConfigurationException loadingException = null; @@ -214,6 +216,8 @@ public void load(final boolean fixIssues) throws ConfigurationException, Malform userComments = loadComments(userPropertiesUrl); mergeMaps(properties, userProperties); + processPropertiesWithHomeDirToken(properties); + if (fixIssues) { checkAndFixConfiguration(properties); } @@ -367,7 +371,7 @@ private void checkAndFixConfiguration(final Map initial) { try { checker.validate(setting.getValue()); } catch (final IllegalArgumentException e) { - LOG.error("Property '{}' has incorrect value \"{}\". Possible values {}.", key, setting.getValue(), checker.getPossibleValues(), e); + LOG.error("Property '{}' has incorrect value \"{}\". Possible values {}. Setting default {}", key, setting.getValue(), checker.getPossibleValues(), setting.getDefaultValue(), e); setting.setValue(setting.getDefaultValue()); } } @@ -375,6 +379,19 @@ private void checkAndFixConfiguration(final Map initial) { } } + private void processPropertiesWithHomeDirToken(final Map properties) { + for (final Map.Entry entry : properties.entrySet()) { + final String key = entry.getKey(); + final Setting setting = entry.getValue(); + final String propertyValue = setting.getValue(); + if (propertyValue != null && propertyValue.contains(USER_HOME_DIR_TOKEN)) { + final String newValue = propertyValue.replace(USER_HOME_DIR_TOKEN, JavaSystemProperties.getUserHome()); + setting.setValue(newValue); + LOG.debug("Replaced USER_HOME_DIR_TOKEN in key {} value {} default {}", key, setting.getValue(), setting.getDefaultValue()); + } + } + } + /** * Looks in the following locations: *

From cfde1db5edecc8bc28194446c58436389b2ce049 Mon Sep 17 00:00:00 2001
From: Stephan Classen 
Date: Thu, 21 Nov 2024 09:50:22 +0100
Subject: [PATCH 5/5] remove unused code

---
 .../sourceforge/jnlp/config/DeploymentConfiguration.java   | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java
index 13c0e032f..8fcb5cc86 100644
--- a/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java
+++ b/core/src/main/java/net/sourceforge/jnlp/config/DeploymentConfiguration.java
@@ -718,11 +718,4 @@ public static String VVPossibleBrowserValues() {
                 ConfigurationConstants.KEY_BROWSER_PATH
         );
     }
-
-    private static String clean(String s) {
-        while (s.contains(File.separator + File.separator)) {
-            s = s.replace(File.separator + File.separator, File.separator);
-        }
-        return s;
-    }
 }