[java-identity-provider] 03/09: Do some null cleanup in the plugin installer

Rod Widdowson rdw at steadingsoftware.com
Tue May 23 08:23:11 UTC 2023


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

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

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

commit 332f0f01f884f01bc7b8ee6f9e5fed3b2cba7a6f
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri May 19 14:41:46 2023 +0100

    Do some null cleanup in the plugin installer
---
 .../shibboleth/idp/installer/impl/BuildWar.java    |  4 +--
 .../installer/{ant => }/impl/PasswordHandler.java  |  0
 .../idp/installer/plugin/impl/PluginInstaller.java | 35 ++++++++++++++--------
 .../plugin/impl/PluginInstallerArguments.java      |  2 +-
 .../installer/plugin/impl/PluginInstallerCLI.java  |  5 +---
 .../idp/installer/plugin/impl/TrustStore.java      |  9 +++---
 .../installer/{Test.java => TestInstallerCLI.java} |  0
 7 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java
index 14126bd30..917ac9af3 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java
@@ -54,12 +54,12 @@ public final class BuildWar extends AbstractInitializableComponent {
     @Nonnull private final Logger log = LoggerFactory.getLogger(BuildWar.class);
 
     /** Location of the install for the job. */
-    private final Path targetDir;
+    @Nonnull private final Path targetDir;
 
     /** Constructor.
      * @param idpHome Where to install to.
      */
-    public BuildWar(final Path idpHome) {
+    public BuildWar(@Nonnull final Path idpHome) {
         targetDir = Constraint.isNotNull(idpHome, "IdPHome should not be null");
     }
 
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/PasswordHandler.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/PasswordHandler.java
similarity index 100%
rename from idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/PasswordHandler.java
rename to idp-installer/src/main/java/net/shibboleth/idp/installer/impl/PasswordHandler.java
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java
index 7bb5c8c9b..6fb7b981c 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstaller.java
@@ -188,6 +188,14 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
         idpHome = Constraint.isNotNull(home, "IdPHome should be non-null");
     }
 
+    /** Get a null safe idpHome.
+     * @return idpHome
+     */
+    @Nonnull private Path getIdpHome() {
+        assert idpHome!=null;
+        return idpHome;
+    }
+
     /** Set the plugin id.
      * @param id what to set.
      */
@@ -313,7 +321,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
         }
 
         if (isRebuildWar()) {
-            final BuildWar builder = new BuildWar(idpHome);
+            final BuildWar builder = new BuildWar(getIdpHome());
             try {
                 builder.initialize();
             } catch (final ComponentInitializationException e) {
@@ -365,7 +373,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
             }
 
             if (isRebuildWar()) {
-                final BuildWar builder = new BuildWar(idpHome);
+                final BuildWar builder = new BuildWar(getIdpHome());
                 try {
                     builder.initialize();
                 } catch (final ComponentInitializationException e) {
@@ -571,7 +579,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
             props.setProperty(PLUGIN_RELATIVE_PATHS_PROPERTY, "true");
             int count = 1;
             for (final Path p: copiedFiles) {
-                final Path relPath = idpHome.relativize(p);
+                final Path relPath = getIdpHome().relativize(p);
                 props.setProperty(PLUGIN_FILE_PROPERTY_PREFIX+Integer.toString(count++), relPath.toString());
             }
             final File outFile = pluginsContents.resolve(pluginId).toFile();
@@ -588,7 +596,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
      * @param props The property files
      * @return the idpHome it was installed to or null if no files installed
      */
-    private Path inferInstalledIdpHome(final Properties props) {
+    @Nullable private Path inferInstalledIdpHome(final Properties props) {
         if (props.get(PLUGIN_FILE_PROPERTY_PREFIX+"1") == null) {
             // No files
             return null;
@@ -605,7 +613,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
             }
             if (index >= 0) {
                 final String s = val.substring(0, index);
-                if (idpHome.toString().equals(s)) {
+                if (getIdpHome().toString().equals(s)) {
                     LOG.debug("Inferred install to {}", s);
                 } else {
                     LOG.info("Inferred initial install to {}", s);
@@ -656,10 +664,10 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
         while (val != null) {
             final Path valAsPath = Path.of(val);
             if (relativePaths || installedIdPHome == null) {
-                result.add(idpHome.resolve(valAsPath));
+                result.add(getIdpHome().resolve(valAsPath));
             } else {
                 final Path relPath = installedIdPHome.relativize(valAsPath);
-                final Path newPath = idpHome.resolve(relPath);
+                final Path newPath = getIdpHome().resolve(relPath);
                 result.add(newPath);
             }
             val = props.getProperty(PLUGIN_FILE_PROPERTY_PREFIX+Integer.toString(count++));
@@ -882,7 +890,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
         try (final InputStream sigStream = new BufferedInputStream(
                 new FileInputStream(base.resolve(fileName + ".asc").toFile()))) {
             final TrustStore trust = new TrustStore();
-            trust.setIdpHome(idpHome);
+            trust.setIdpHome(getIdpHome());
             trust.setTrustStore(truststore);
             trust.setPluginId(pluginId);
             trust.initialize();
@@ -920,18 +928,19 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
 
     /** {@inheritDoc} */
     protected void doInitialize() throws ComponentInitializationException {
-        if (idpHome == null) {
+        Path myIdpHome = idpHome;
+        if (myIdpHome == null) {
             throw new ComponentInitializationException("idp.home property must be set");
         }
         try {
-            assert idpHome != null;
-            idpHome = PluginInstallerSupport.canonicalPath(idpHome);
+            idpHome = myIdpHome = PluginInstallerSupport.canonicalPath(myIdpHome);
         } catch (final IOException e) {
             LOG.error("Could not canonicalize idp home", e);
             throw new ComponentInitializationException(e);
         }
-        assert idpHome != null;
-        moduleContext = new ModuleContext(idpHome.toString());
+        final String idpHomeString = myIdpHome.toString();
+        assert idpHomeString!= null;
+        moduleContext = new ModuleContext(idpHomeString);
         moduleContext.setHttpClientSecurityParameters(securityParams);
         moduleContext.setHttpClient(httpClient);
         distPath = idpHome.resolve("dist");
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerArguments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerArguments.java
index 9875ae494..d6093221e 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerArguments.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerArguments.java
@@ -386,7 +386,7 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
     }
 
     /** {@inheritDoc} */
-    public void printHelp(final PrintStream out) {
+    public void printHelp(final @Nonnull PrintStream out) {
         out.println("Plugin");
         out.println("Provides a command line interface for plugin management operations.");
         out.println();
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerCLI.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerCLI.java
index 617db4586..3d8ba16e3 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerCLI.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerCLI.java
@@ -26,8 +26,6 @@ import java.net.URL;
 import java.nio.file.Path;
 import java.security.Security;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
@@ -50,10 +48,10 @@ import org.springframework.core.io.Resource;
 
 import net.shibboleth.idp.Version;
 import net.shibboleth.idp.cli.AbstractIdPHomeAwareCommandLine;
-import net.shibboleth.idp.installer.impl.InstallationLogger;
 import net.shibboleth.idp.installer.plugin.impl.PluginState.VersionInfo;
 import net.shibboleth.idp.plugin.IdPPlugin;
 import net.shibboleth.idp.plugin.PluginSupport.SupportLevel;
+import net.shibboleth.idp.plugin.PluginVersion;
 import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.cli.AbstractCommandLine;
 import net.shibboleth.shared.collection.CollectionSupport;
@@ -62,7 +60,6 @@ import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.spring.httpclient.resource.HTTPResource;
-import net.shibboleth.idp.plugin.PluginVersion;
 
 /**
  * Command line for Plugin Installation.
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java
index d35926fb9..47a0167a5 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/TrustStore.java
@@ -93,7 +93,7 @@ import net.shibboleth.shared.primitive.LoggerFactory;
      *
      * @param what The idpHome to set.
      */
-    public void setIdpHome(final Path what) {
+    public void setIdpHome(@Nonnull final Path what) {
         checkSetterPreconditions();
         idpHome = what;
     }
@@ -114,7 +114,7 @@ import net.shibboleth.shared.primitive.LoggerFactory;
      * {@link PGPPublicKeyRingCollection#PGPPublicKeyRingCollection(InputStream,
      *   org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator)}
      */
-    private static PGPPublicKeyRingCollection loadStoreFrom(final InputStream in) throws IOException {
+    private static PGPPublicKeyRingCollection loadStoreFrom(@Nonnull final InputStream in) throws IOException {
         try (final InputStream decoded = PGPUtil.getDecoderStream(in)) {
            final ArrayList<PGPPublicKeyRing> listr = new ArrayList<>();
 
@@ -143,6 +143,7 @@ import net.shibboleth.shared.primitive.LoggerFactory;
      */
     protected void loadStore() throws IOException {
         try (final InputStream in = Files.newInputStream(store)) {
+            assert in != null;
             keyRings = loadStoreFrom(in);
         }
     }
@@ -205,8 +206,8 @@ import net.shibboleth.shared.primitive.LoggerFactory;
      * @throws IOException if the load or save fails
      */
     public void importKeyFromStream(final Signature sigForKey,
-                            final InputStream keyStream,
-                            final Predicate<String> accept) throws IOException {
+                            @Nonnull final InputStream keyStream,
+                            @Nonnull final Predicate<String> accept) throws IOException {
         final PGPPublicKeyRingCollection providedStore = loadStoreFrom(keyStream);
 
         final PGPPublicKey key = providedStore.getPublicKey(sigForKey.getSignature().getKeyID());
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/TestInstallerCLI.java
similarity index 100%
rename from idp-installer/src/test/java/net/shibboleth/idp/installer/Test.java
rename to idp-installer/src/test/java/net/shibboleth/idp/installer/TestInstallerCLI.java

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


More information about the commits mailing list