[java-identity-provider] branch master updated: IDP-1499 New V4 Installer: fix class protection

Rod Widdowson rdw at steadingsoftware.com
Sat Oct 12 09:22:25 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=8da7596c49bc21d5ab4798c7f602cd59166a849c

The following commit(s) were added to refs/heads/master by this push:
       new  8da7596   IDP-1499 New V4 Installer:  fix class protection
8da7596 is described below

commit 8da7596c49bc21d5ab4798c7f602cd59166a849c
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Oct 12 14:16:11 2019 +0100

    IDP-1499 New V4 Installer:  fix class protection
    
    https://issues.shibboleth.net/jira/browse/IDP-1499
    
    Allow PropertiesWithComments to be used elsewhere
    Allow InstallerSupport to be used elsewhere
    Remove legacy classes
---
 .../shibboleth/idp/installer/InstallerSupport.java |  13 +-
 .../idp/installer/PropertiesWithComments.java      |  18 +-
 .../idp/installer/impl/PropertiesWithComments.java | 281 ---------------------
 .../idp/installer/impl/package-info.java           |  21 --
 4 files changed, 7 insertions(+), 326 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
index 45f4e1f..45b0fe6 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
@@ -57,7 +57,7 @@ public final class InstallerSupport {
      * @param dir what to create
      * @throws BuildException if bad ness occurs
      */
-    protected static void createDirectory(final Path dir) throws BuildException{
+    public static void createDirectory(final Path dir) throws BuildException{
         if (!Files.exists(dir)) {
             try {
                 Files.createDirectories(dir);
@@ -76,7 +76,7 @@ public final class InstallerSupport {
      * @param to where to copy to
      * @return a partially populated {@link Copy} task
      */
-    protected static Copy getCopyTask(final Path from, final Path to) {
+    public static Copy getCopyTask(final Path from, final Path to) {
         final Copy result = new Copy();
         result.setTodir(to.toFile());
         final FileSet fromSet = new FileSet();
@@ -101,7 +101,7 @@ public final class InstallerSupport {
         </code>
      *
      */
-    protected static void copyDirIfNotPresent(final Path from, final Path to) throws BuildException {
+    public static void copyDirIfNotPresent(final Path from, final Path to) throws BuildException {
         createDirectory(to);
         final Copy copy = new Copy();
         copy.setTodir(to.toFile());
@@ -123,7 +123,7 @@ public final class InstallerSupport {
      * @param directory where
      * @param readOnly what to set it as
      */
-    protected static void setReadOnly(final Path directory, final boolean readOnly) {
+    public static void setReadOnly(final Path directory, final boolean readOnly) {
         final Attrib attrib = new Attrib();
         attrib.setReadonly(readOnly);
         final FileSet where = new FileSet();
@@ -138,7 +138,7 @@ public final class InstallerSupport {
      * @param where where
      * @throws BuildException if badness occurrs
      */
-    protected static void deleteTree(final Path where) throws BuildException {
+    public static void deleteTree(final Path where) throws BuildException {
         if (!Files.exists(where)) {
             log.debug("Directory {} does not exist. Skipping delete.", where);
             return;
@@ -158,12 +158,11 @@ public final class InstallerSupport {
      * @param destFile where to
      * @return the jar task
      */
-    protected static Jar createJarTask(final Path baseDir, final Path destFile) {
+    public static Jar createJarTask(final Path baseDir, final Path destFile) {
         final Jar jarTask = new Jar();
         jarTask.setBasedir(baseDir.toFile());
         jarTask.setDestFile(destFile.toFile());
         jarTask.setProject(InstallerSupport.ANT_PROJECT);
         return jarTask;
     }
-    
 }
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java
index 0143de0..101eeda 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java
@@ -67,22 +67,6 @@ public final class PropertiesWithComments {
         nameReplacement = new Properties();
     }
 
-    /** Constructor.
-     * @param replacements what to set.
-     */
-    public PropertiesWithComments(final Properties replacements) {
-        nameReplacement = replacements;
-    }
-
-    /** Constructor.
-     * @param input what to set.
-     * @throws IOException id the stream could not be loaded
-     */
-    public PropertiesWithComments(final InputStream input) throws IOException {
-        nameReplacement = new Properties();
-        nameReplacement.load(input);
-    }
-
     /**
      * Add a property, either as a key/value pair or as a key/comment pair.
      * 
@@ -259,7 +243,7 @@ public final class PropertiesWithComments {
      * It may be a commented property from a line like this "#prop=value" or a property prop=value.
      * 
      */
-    private class CommentedProperty {
+    private static class CommentedProperty {
 
         /** The property name. */
         private final String property;
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
deleted file mode 100644
index 87e17c2..0000000
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/PropertiesWithComments.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.shibboleth.idp.installer.impl;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.annotation.Nonnull;
-
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-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.
- */
-public class PropertiesWithComments {
-
-    /**
-     * The contents.
-     * 
-     * Each {@link Object} is either a string (a non-property line) or a {@link CommentedProperty}
-     * (an optionally commented property definition).
-     */
-    private List<Object> contents;
-
-    /** 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.
-     * 
-     * @param line what to look at
-     * @param isComment whether this is a comment or not.
-     * @throws IOException when badness happens.
-     */
-    protected void addCommentedProperty(@Nonnull @NotEmpty final String line, final boolean isComment)
-            throws IOException {
-        final Properties parser = new Properties();
-        final String modifiedLine;
-
-        if (isComment) {
-            modifiedLine = line.substring(1);
-        } else {
-            modifiedLine = line;
-        }
-
-        parser.load(new ByteArrayInputStream(modifiedLine.getBytes()));
-        if (!parser.isEmpty()) {
-            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, outputLine, true);
-
-                } else {
-                    commentedProperty = new CommentedProperty(propName, value, false);
-
-                }
-                properties.put(propName, commentedProperty);
-                contents.add(commentedProperty);
-            }
-        } else {
-            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);
-    }
-
-    /**
-     * Read the input stream into our structures.
-     * 
-     * @param input what to read
-     * @throws IOException if readline fails
-     */
-    public void load(final InputStream input) throws IOException {
-        final BufferedReader reader = new BufferedReader(new InputStreamReader(input));
-        contents = new ArrayList<>();
-        properties = new HashMap<>();
-
-        String s = reader.readLine();
-
-        while (s != null) {
-            final String what = StringSupport.trimOrNull(s);
-            if (what == null) {
-                contents.add("");
-            } else if (what.startsWith("#")) {
-                if (what.contains("=")) {
-                    addCommentedProperty(s, true);
-                } else {
-                    contents.add(what);
-                }
-            } else {
-
-                addCommentedProperty(s, false);
-            }
-            s = reader.readLine();
-        }
-        loadedData = true;
-    }
-
-    /**
-     * Put the output to the supplied stream.
-     * 
-     * @param output where to write
-     * @throws IOException is the write fails
-     */
-    public void store(final OutputStream output) throws IOException {
-        final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
-
-        for (final Object o : contents) {
-            if (o instanceof String) {
-                writer.write((String) o);
-            } else if (o instanceof CommentedProperty) {
-                final CommentedProperty commentedProperty = (CommentedProperty) o;
-                commentedProperty.write(writer);
-            }
-            writer.newLine();
-        }
-        writer.flush();
-        writer.close();
-        output.close();
-    }
-
-    /**
-     * Replace the supplied property or stuff it at the bottom of the list.
-     * 
-     * @param propName the name of the property to replace
-     * @param newPropValue the value to replace
-     * @return true if the property was replaced false if it was added
-     */
-    public boolean replaceProperty(final String propName, final String newPropValue) {
-
-        CommentedProperty p = properties.get(propName);
-        if (null != p) {
-            p.setValue(newPropValue);
-            return true;
-        }
-        p = new CommentedProperty(propName, newPropValue, false);
-        contents.add(p);
-        properties.put(propName, p);
-        return false;
-    }
-
-    /**
-     * Append a comment to the list.
-     * 
-     * @param what what to add
-     */
-    public void addComment(final String what) {
-        contents.add("# " + what);
-    }
-
-    /**
-     * A POJO which looks like a property.
-     * 
-     * It may be a commented property from a line like this "#prop=value" or a property prop=value.
-     * 
-     */
-    protected class CommentedProperty {
-
-        /** The property name. */
-        private final String property;
-
-        /** The value - or the entire line if this is a comment. */
-        private String value;
-
-        /** Whether this is a comment or a value. */
-        private boolean isComment;
-
-        /**
-         * Constructor.
-         * 
-         * @param prop the property name.
-         * @param val the value or the entire line if this was a comment.
-         * @param comment whether this is a comment.
-         */
-        CommentedProperty(final String prop, final String val, final boolean comment) {
-            property = prop;
-            value = val;
-            isComment = comment;
-        }
-
-        /**
-         * Set a new value.
-         * 
-         * @param newValue what to set
-         */
-        protected void setValue(final String newValue) {
-            value = newValue;
-            isComment = false;
-        }
-
-        /**
-         * Write ourselves to the writer.
-         * 
-         * @param writer what to write with
-         * @throws IOException from the writer
-         */
-        protected void write(final BufferedWriter writer) throws IOException {
-
-            if (isComment) {
-                writer.write(value);
-            } else {
-                writer.write(property);
-                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
deleted file mode 100644
index 7f5bd0b..0000000
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * Classes of use during installation.
- */
-
-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