[java-identity-provider] branch master updated: Reapply precious fix, with correct code

Rod Widdowson rdw at steadingsoftware.com
Fri Oct 11 11:18:02 EDT 2019


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=f0cbffe4bc77345af7d11685960e6e3ff56f3e2a

The following commit(s) were added to refs/heads/master by this push:
       new  f0cbffe   Reapply precious fix, with correct code
f0cbffe is described below

commit f0cbffe4bc77345af7d11685960e6e3ff56f3e2a
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Oct 11 16:17:37 2019 +0100

    Reapply precious fix, with correct code
---
 .../idp/installer/impl/PropertiesWithComments.java | 61 ++++++++++++++++++----
 .../idp/installer/impl/package-info.java           |  6 +--
 2 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/PropertiesWithComments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/PropertiesWithComments.java
index 2e84c6c..87e17c2 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/PropertiesWithComments.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/PropertiesWithComments.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package net.shibboleth.idp.installer;
+package net.shibboleth.idp.installer.impl;
 
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
@@ -34,15 +34,13 @@ import java.util.Properties;
 import javax.annotation.Nonnull;
 
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
-import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
 /**
  * A package which is similar to Properties, but allows comments to be preserved. We use the Properties package to parse
  * the non-comment lines.
  */
- at Deprecated public class PropertiesWithComments {
+public class PropertiesWithComments {
 
     /**
      * The contents.
@@ -55,6 +53,15 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
     /** The properties bit. */
     private Map<String, CommentedProperty> properties;
 
+    /** Name Replacement info. */
+    private final Properties nameReplacement = new Properties();
+
+    /** Have we loaded data?.
+     *
+     * We cannot load the replacement names after the file load.
+     * */
+    private boolean loadedData;
+
     /**
      * Add a property, either as a key/value pair or as a key/comment pair.
      * 
@@ -75,15 +82,38 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
         parser.load(new ByteArrayInputStream(modifiedLine.getBytes()));
         if (!parser.isEmpty()) {
-            final String propName = StringSupport.trimOrNull(parser.stringPropertyNames().iterator().next());
+            String propName = StringSupport.trimOrNull(parser.stringPropertyNames().iterator().next());
             if (propName != null) {
+                
+                String outputLine = line;
+                final String value = parser.getProperty(propName);
+                
+                final String newPropName = StringSupport.trimOrNull(nameReplacement.getProperty(propName));
+
+                if (newPropName != null && !newPropName.isEmpty()) {
+                    // Change the line
+                    if (isComment) {
+                        if (newPropName.contains(propName)) {
+                            // We can only replace once
+                            outputLine = outputLine.replace(propName, newPropName);
+                        } else {
+                            while (outputLine.contains(propName)) {
+                                outputLine = outputLine.replace(propName, newPropName);
+                            }
+                        }
+                    }
+                    // and the property name
+                    propName = newPropName;
+                }
+                
+                
                 final CommentedProperty commentedProperty;
 
                 if (isComment) {
-                    commentedProperty = new CommentedProperty(propName, line, true);
+                    commentedProperty = new CommentedProperty(propName, outputLine, true);
 
                 } else {
-                    commentedProperty = new CommentedProperty(propName, parser.getProperty(propName), false);
+                    commentedProperty = new CommentedProperty(propName, value, false);
 
                 }
                 properties.put(propName, commentedProperty);
@@ -93,7 +123,18 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
             contents.add(line);
         }
         parser.clear();
-
+    }
+    
+    /** Read the name replacement data. 
+    * 
+    * @param input what to read
+    * @throws IOException if readline fails
+    */
+    public void loadNameReplacement(final InputStream input) throws IOException {
+        if (loadedData) {
+            throw new IOException("Cannot load name replacement after the data");
+        }
+        nameReplacement.load(input);
     }
 
     /**
@@ -103,7 +144,6 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
      * @throws IOException if readline fails
      */
     public void load(final InputStream input) throws IOException {
-        DeprecationSupport.warn(ObjectType.CLASS, this.getClass().getName(), null , ".impl");
         final BufferedReader reader = new BufferedReader(new InputStreamReader(input));
         contents = new ArrayList<>();
         properties = new HashMap<>();
@@ -126,6 +166,7 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
             }
             s = reader.readLine();
         }
+        loadedData = true;
     }
 
     /**
@@ -232,7 +273,7 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
                 writer.write(value);
             } else {
                 writer.write(property);
-                writer.write("= ");
+                writer.write("=");
                 writer.write(value);
             }
         }
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/package-info.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/package-info.java
index 5173817..7f5bd0b 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/package-info.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/package-info.java
@@ -14,10 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 /**
- * OLD Deprecated. Classes of use during installation.
- * Use the .impl versions
+ * Classes of use during installation.
  */
-package net.shibboleth.idp.installer;
 
+package net.shibboleth.idp.installer.impl;
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list