[java-identity-provider] 02/07: IDP-1499 Installer: make CurentState an interface and hide implementation.

Rod Widdowson rdw at steadingsoftware.com
Sat Oct 19 08:04:11 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=502a0eaa0bcf7096a718385690da77bfa563ef06

commit 502a0eaa0bcf7096a718385690da77bfa563ef06
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Oct 18 13:15:07 2019 +0100

    IDP-1499 Installer: make CurentState an interface and hide implementation.
    
    https://issues.shibboleth.net/jira/browse/IDP-1499
---
 .../idp/installer/CurrentInstallState.java         | 81 ++--------------------
 .../net/shibboleth/idp/installer/Installer.java    |  3 +-
 .../CurrentInstallStateImpl.java}                  | 41 +++++------
 .../idp/installer/impl/package-info.java           | 21 ++++++
 .../java/net/shibboleth/idp/installer/Test.java    |  3 +-
 5 files changed, 48 insertions(+), 101 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
index 8673020..addd684 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
@@ -17,99 +17,28 @@
 
 package net.shibboleth.idp.installer;
 
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Properties;
-
 import javax.annotation.Nullable;
 
 import org.apache.tools.ant.BuildException;
-import org.slf4j.LoggerFactory;
 
-import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.component.InitializableComponent;
 
 /** Tells the installers about the current install state. */
-final class CurrentInstallState extends AbstractInitializableComponent {
-
-    /** Where we are installing to. */
-    private final Path targetDir;
-    
-    /** Whether the IdP properties file exists.*/
-    private boolean idpPropertiesPresent;
-
-    /** Whether the LDAP properties file exists.*/
-    private boolean ldapPropertiesPresent;
-    
-    /** Old Version. */
-    private String oldVersion;
-    
-    /** Constructor.
-     * @param installerProps the installer situation.
-     */
-    protected CurrentInstallState(final InstallerProperties installerProps) {
-        targetDir = installerProps.getTargetDir();
-    }
-    
-    /** {@inheritDoc} */
-    protected void doInitialize() throws ComponentInitializationException {
-        super.doInitialize();
-        idpPropertiesPresent = Files.exists(targetDir.resolve("conf").resolve("idp.properties"));
-        ldapPropertiesPresent = Files.exists(targetDir.resolve("conf").resolve("ldap.properties"));
-        final Path conf = targetDir.resolve("conf");
-        if (!Files.exists(conf.resolve("relying-party.xml"))) {
-            // No relying party, no install
-            oldVersion = null;
-            return;
-        }
-        
-        if (!Files.exists(conf.resolve("idp.properties"))) {
-            throw new ComponentInitializationException("V2 Installation detected");
-        }
-
-        final Path currentInstall = targetDir.resolve("dist").resolve(InstallerSupport.VERSION_NAME);
-        if (!Files.exists(currentInstall)) {
-            oldVersion= "3";
-            return;
-        }
-        final Properties vers = new Properties(1);
-        try {
-            vers.load(new FileInputStream(currentInstall.toFile()));
-        } catch (final IOException e) {
-            LoggerFactory.getLogger(CurrentInstallState.class).
-                error("Could not load {}", currentInstall.toAbsolutePath(), e);
-            throw new ComponentInitializationException(e);
-        }
-        oldVersion = vers.getProperty(InstallerSupport.VERSION_NAME);
-        if (null == oldVersion) {
-            LoggerFactory.getLogger(CurrentInstallState.class).
-            error("Failed loading {}", currentInstall.toAbsolutePath());
-            throw new ComponentInitializationException("File " + InstallerSupport.VERSION_NAME +
-                    " did not contain property " + InstallerSupport.VERSION_NAME);
-        }
-    }
+public interface CurrentInstallState extends InitializableComponent {
 
     /** What is the installer version.
      * @return "3" for a V3 install, null for a new install or the value we write during last install.
      * @throws BuildException if we find an inconsistency
      */
-    @Nullable protected String getInstalledVersion() {
-        return oldVersion;
-    }
+    @Nullable String getInstalledVersion() throws BuildException;
     
     /** Was idp.properties present in the target file when we started the install?
      * @return if it was.
      */
-    protected boolean isIdPPropertiesPresent() {
-        return idpPropertiesPresent;
-    }
+    boolean isIdPPropertiesPresent();
 
     /** Was ldapp.properties present in the target file when we started the install?
      * @return if it was.
      */
-    protected boolean isLDAPPropertiesPresent() {
-        return ldapPropertiesPresent;
-    }
+    boolean isLDAPPropertiesPresent();
 }
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/Installer.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/Installer.java
index eeaf52b..e075c7b 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/Installer.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/Installer.java
@@ -20,6 +20,7 @@ package net.shibboleth.idp.installer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import net.shibboleth.idp.installer.impl.CurrentInstallStateImpl;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 
 /**
@@ -53,7 +54,7 @@ public final class Installer {
         }
         final InstallerProperties ip = new InstallerPropertiesImpl(!copyInstall);
         ip.initialize();
-        final CurrentInstallState is = new CurrentInstallState(ip);
+        final CurrentInstallState is = new CurrentInstallStateImpl(ip);
         is.initialize();
 
         if (copyInstall) {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java
similarity index 78%
copy from idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
copy to idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java
index 8673020..8d44a9e 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package net.shibboleth.idp.installer;
+package net.shibboleth.idp.installer.impl;
 
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -25,34 +25,36 @@ import java.util.Properties;
 
 import javax.annotation.Nullable;
 
-import org.apache.tools.ant.BuildException;
 import org.slf4j.LoggerFactory;
 
+import net.shibboleth.idp.installer.CurrentInstallState;
+import net.shibboleth.idp.installer.InstallerProperties;
+import net.shibboleth.idp.installer.InstallerSupport;
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 
 /** Tells the installers about the current install state. */
-final class CurrentInstallState extends AbstractInitializableComponent {
+public final class CurrentInstallStateImpl extends AbstractInitializableComponent implements CurrentInstallState {
 
     /** Where we are installing to. */
     private final Path targetDir;
-    
+
     /** Whether the IdP properties file exists.*/
     private boolean idpPropertiesPresent;
 
     /** Whether the LDAP properties file exists.*/
     private boolean ldapPropertiesPresent;
-    
+
     /** Old Version. */
     private String oldVersion;
-    
+
     /** Constructor.
      * @param installerProps the installer situation.
      */
-    protected CurrentInstallState(final InstallerProperties installerProps) {
+    public CurrentInstallStateImpl(final InstallerProperties installerProps) {
         targetDir = installerProps.getTargetDir();
     }
-    
+
     /** {@inheritDoc} */
     protected void doInitialize() throws ComponentInitializationException {
         super.doInitialize();
@@ -78,38 +80,31 @@ final class CurrentInstallState extends AbstractInitializableComponent {
         try {
             vers.load(new FileInputStream(currentInstall.toFile()));
         } catch (final IOException e) {
-            LoggerFactory.getLogger(CurrentInstallState.class).
+            LoggerFactory.getLogger(CurrentInstallStateImpl.class).
                 error("Could not load {}", currentInstall.toAbsolutePath(), e);
             throw new ComponentInitializationException(e);
         }
         oldVersion = vers.getProperty(InstallerSupport.VERSION_NAME);
         if (null == oldVersion) {
-            LoggerFactory.getLogger(CurrentInstallState.class).
+            LoggerFactory.getLogger(CurrentInstallStateImpl.class).
             error("Failed loading {}", currentInstall.toAbsolutePath());
             throw new ComponentInitializationException("File " + InstallerSupport.VERSION_NAME +
                     " did not contain property " + InstallerSupport.VERSION_NAME);
         }
     }
 
-    /** What is the installer version.
-     * @return "3" for a V3 install, null for a new install or the value we write during last install.
-     * @throws BuildException if we find an inconsistency
-     */
-    @Nullable protected String getInstalledVersion() {
+    /** {@inheritDoc} */
+    @Nullable public String getInstalledVersion() {
         return oldVersion;
     }
     
-    /** Was idp.properties present in the target file when we started the install?
-     * @return if it was.
-     */
-    protected boolean isIdPPropertiesPresent() {
+    /** {@inheritDoc} */
+    public boolean isIdPPropertiesPresent() {
         return idpPropertiesPresent;
     }
 
-    /** Was ldapp.properties present in the target file when we started the install?
-     * @return if it was.
-     */
-    protected boolean isLDAPPropertiesPresent() {
+    /** {@inheritDoc} */
+    public boolean isLDAPPropertiesPresent() {
         return ldapPropertiesPresent;
     }
 }
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
new file mode 100644
index 0000000..0606649
--- /dev/null
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+/**
+ * Implementation classes for installation.
+ */
+
+package net.shibboleth.idp.installer.impl;
\ No newline at end of file
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java
index 963aae9..4643e6a 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java
@@ -24,6 +24,7 @@ import javax.annotation.Nonnull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import net.shibboleth.idp.installer.impl.CurrentInstallStateImpl;
 import net.shibboleth.idp.installer.metadata.impl.MetadataGeneratorImpl;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 
@@ -53,7 +54,7 @@ public class Test {
 
         final InstallerProperties ip = new InstallerPropertiesImpl(false);
         ip.initialize();
-        final CurrentInstallState is = new CurrentInstallState(ip);
+        final CurrentInstallStateImpl is = new CurrentInstallStateImpl(ip);
         is.initialize();
 
         final CopyDistribution dist = new CopyDistribution(ip, is);

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


More information about the commits mailing list