[java-identity-provider] 03/03: IDP-2107 Misc V5 Installer tasks

Rod Widdowson rdw at steadingsoftware.com
Sat Jun 3 15:49:18 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=a6fc074192a9090ba5730cfd48f15281e5f0b84d

commit a6fc074192a9090ba5730cfd48f15281e5f0b84d
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Jun 3 16:45:58 2023 +0100

    IDP-2107 Misc V5 Installer tasks
    
    https://shibboleth.atlassian.net/browse/IDP-2107
    
    Stop copying *.idpnew when we populate the webapp (from the edit-webapp
    and from plugins-webapp)
    
    Stop populating the docs folder
---
 .../shibboleth/idp/installer/InstallerSupport.java | 32 +++++++++++++++-------
 .../shibboleth/idp/installer/impl/BuildWar.java    | 12 +++++---
 .../idp/installer/impl/CopyDistribution.java       |  6 +++-
 .../shibboleth/idp/installer/impl/V5Install.java   | 21 ++++++++------
 .../idp/installer/plugin/impl/PluginInstaller.java | 15 ++++++----
 .../shibboleth/idp/installer/TestInstallerCLI.java |  2 +-
 .../idp/installer/plugin/impl/BasePluginTest.java  |  7 +++--
 7 files changed, 62 insertions(+), 33 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 677846c00..cd73e2e57 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
@@ -80,7 +80,7 @@ public final class InstallerSupport {
      * @param dir what to create
      * @throws BuildException if badness occurs
      */
-    public static void createDirectory(final Path dir) throws BuildException{
+    public static void createDirectory(@Nonnull final Path dir) throws BuildException{
         if (!Files.exists(dir)) {
             try {
                 Files.createDirectories(dir);
@@ -99,13 +99,25 @@ public final class InstallerSupport {
      * @param to where to copy to
      * @return a partially populated {@link Copy} task
      */
-    public static Copy getCopyTask(final Path from, final Path to) {
+    @Nonnull public static Copy getCopyTask(@Nonnull final Path from, @Nonnull final Path to) {
+        return getCopyTask(from, to, "**/.gitkeep");
+    }
+
+    /** Copy files.  We use ant rather than {@link Files#copy(Path, Path, java.nio.file.CopyOption...)}
+     * because the latter has issues with the Windows ReadOnly Attribute, and the former is tried
+     * and tested technology.
+     * @param from where to copy from
+     * @param to where to copy to
+     * @param excludes pattern to exclude
+     * @return a partially populated {@link Copy} task
+     */
+    @Nonnull public static Copy getCopyTask(@Nonnull final Path from, @Nonnull final Path to, @Nonnull final String exclude) {
         final Copy result = new Copy();
         result.setTodir(to.toFile());
         final FileSet fromSet = new FileSet();
         fromSet.setDir(from.toFile());
-        final String[] gitkeep= {"**/.gitkeep"};
-        fromSet.appendExcludes(gitkeep);
+        final String[] excludes = {exclude};
+        fromSet.appendExcludes(excludes );
         result.setPreserveLastModified(true);
         result.addFileset(fromSet);
         result.setProject(ANT_PROJECT);
@@ -128,7 +140,7 @@ public final class InstallerSupport {
         </code>
      *
      */
-    public static void copyDirIfNotPresent(final Path from, final Path to) throws BuildException {
+    public static void copyDirIfNotPresent(@Nonnull final Path from, @Nonnull final Path to) throws BuildException {
         createDirectory(to);
         final Copy copy = new Copy();
         copy.setTodir(to.toFile());
@@ -152,7 +164,7 @@ public final class InstallerSupport {
      * @param readOnly what to set it as
      * @throws BuildException if badness occurs
      */
-    private static void setReadOnlyFile(final Path file, final boolean readOnly) throws BuildException {
+    private static void setReadOnlyFile(@Nonnull final Path file, final boolean readOnly) throws BuildException {
         if (readOnly) {
             log.debug("Setting readonly bits on file {}", file);
         } else {
@@ -182,7 +194,7 @@ public final class InstallerSupport {
      * @param readOnly what to set it as
      * @throws BuildException if badness occurs
      */
-    public static void setReadOnlyDir(final Path directory, final boolean readOnly) throws BuildException {
+    public static void setReadOnlyDir(@Nonnull final Path directory, final boolean readOnly) throws BuildException {
         if (readOnly) {
             log.debug("Recursively setting readonly bits on directory {}", directory);
         } else {
@@ -213,7 +225,7 @@ public final class InstallerSupport {
      * @param readOnly what to set it as
      * @throws BuildException if badness occurs
      */
-    public static void setReadOnly(final Path path, final boolean readOnly) throws BuildException {
+    public static void setReadOnly(@Nonnull final Path path, final boolean readOnly) throws BuildException {
         if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
             log.debug("Not windows. Not [re]setting readonly bit");
             return;
@@ -235,7 +247,7 @@ public final class InstallerSupport {
      * @param includes what to include
      * @throws BuildException if badness occurs
      */
-    public static void setMode(final Path directory, final String permissions, final String includes)
+    public static void setMode(@Nonnull final Path directory, @Nonnull final String permissions, @Nonnull final String includes)
             throws BuildException {
         if (!Files.exists(directory) ) {
             log.debug("Directory {} does not exist, not performing chmod", directory);
@@ -261,7 +273,7 @@ public final class InstallerSupport {
      * @param includes what to include
      * @throws BuildException if badness occurs
      */
-    public static void setGroup(final Path directory, final String group, final String includes)
+    public static void setGroup(@Nonnull final Path directory, @Nonnull final String group, @Nonnull final String includes)
             throws BuildException {
         if (!Files.exists(directory) ) {
             log.debug("Directory {} does not exist, not performing chgrp", directory);
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 353c6a638..9b99d89bc 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
@@ -68,11 +68,11 @@ public final class BuildWar {
      * @param webAppTo Where to copy to.
      * @throws BuildException if unexpected badness occurs.
      */
-    private void overlayWebapp(final Path from, final Path webAppTo) throws BuildException {
+    private void overlayWebapp(@Nonnull final Path from, @Nonnull final Path webAppTo) throws BuildException {
         if (!Files.exists(from)) {
             return;
         }
-        final Copy overlay = InstallerSupport.getCopyTask(from, webAppTo);
+        final Copy overlay = InstallerSupport.getCopyTask(from, webAppTo, "**/*.idpnew");
         overlay.setOverwrite(true);
         overlay.setPreserveLastModified(true);
         overlay.setFailOnError(true);
@@ -93,6 +93,7 @@ public final class BuildWar {
         InstallerSupport.deleteTree(webAppTmp);
         final Path dist = targetDir.resolve("dist");
         final Path distWebApp =  dist.resolve("webapp");
+        assert distWebApp!=null && webAppTmp != null;
         final Copy initial = InstallerSupport.getCopyTask(distWebApp, webAppTmp);
         initial.setPreserveLastModified(true);
         initial.setFailOnError(true);
@@ -100,8 +101,11 @@ public final class BuildWar {
         log.info("Initial populate from {} to {}", distWebApp, webAppTmp);
         initial.execute();
 
-        overlayWebapp(targetDir.resolve("dist").resolve("plugin-webapp"), webAppTmp);
-        overlayWebapp(targetDir.resolve("edit-webapp"), webAppTmp);
+        final Path pluginWebapp = targetDir.resolve("dist").resolve("plugin-webapp");
+        final Path editWebapp = targetDir.resolve("edit-webapp");
+        assert pluginWebapp!=null && editWebapp!=null;
+        overlayWebapp(pluginWebapp, webAppTmp);
+        overlayWebapp(editWebapp, webAppTmp);
 
         final File warFileFile = warFile.toFile();
         if (warFileFile.exists() && !warFile.toFile().delete()) {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistribution.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistribution.java
index 641ccb0b0..6db1dc271 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistribution.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistribution.java
@@ -84,7 +84,9 @@ public final class CopyDistribution {
         delete(installerProps.getTargetDir().resolve("dist"), "plugin-webapp/** plugin-contents/**");
         delete(installerProps.getTargetDir().resolve("doc"), null);
         final Path system = installerProps.getTargetDir().resolve("system");
+        assert system!=null;
         if (Files.exists(system)) {
+            assert system!=null;
             InstallerSupport.setReadOnly(system, false);
             delete(system, null);
         }
@@ -103,6 +105,7 @@ public final class CopyDistribution {
         final Path toPath =  dist.resolve(to);
         final Path fromPath = srcDist.resolve(to);
         log.debug("Copying distribution from {} to {}", fromPath, toPath);
+        assert fromPath!=null && toPath!=null;
         final Copy copy = InstallerSupport.getCopyTask(fromPath, toPath);
         copy.setOverwrite(overwrite);
         copy.execute();
@@ -125,6 +128,7 @@ public final class CopyDistribution {
      */
     protected void copyDist() {
         final Path dist = installerProps.getTargetDir().resolve("dist");
+        assert dist!=null;
         InstallerSupport.createDirectory(dist);
         final Path src = installerProps.getSourceDir();
         if (!Files.exists(src)) {
@@ -138,9 +142,9 @@ public final class CopyDistribution {
      * @throws BuildException if badness occurs
      */
     protected void copyBinDoc() {
-        distCopy(installerProps.getSourceDir(), installerProps.getTargetDir(), "doc");
         final Path fromPath = installerProps.getSourceDir().resolve("bin").resolve("lib");
         final Path toPath = installerProps.getTargetDir().resolve("dist").resolve("binlib");
+        assert fromPath!=null && toPath!=null;
         log.debug("Copying distribution from {} to {}", fromPath, toPath);
         final Copy copy = InstallerSupport.getCopyTask(fromPath, toPath);
         copy.setOverwrite(false);
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/V5Install.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/V5Install.java
index d63d0e043..f9bbe311f 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/V5Install.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/V5Install.java
@@ -175,6 +175,7 @@ public class V5Install {
         }
         try {
             final Path versFile = installerProps.getTargetDir().resolve("dist").resolve(InstallerSupport.VERSION_NAME);
+            assert versFile!=null;
             if (Files.exists(versFile) ) {
                 InstallerSupport.setReadOnly(versFile, false);
             }
@@ -490,24 +491,28 @@ public class V5Install {
      * @throws BuildException if badness occurs
      */
     protected void reprotect() throws BuildException {
-        final Path pluginContents = installerProps.getTargetDir().resolve("dist").resolve("plugin-contents");
-        final Path pluginWebapp = installerProps.getTargetDir().resolve("dist").resolve("plugin-webapp");
+        final Path dist = installerProps.getTargetDir().resolve("dist");
+        final Path pluginContents = dist.resolve("plugin-contents");
+        final Path pluginWebapp = dist.resolve("plugin-webapp");
+        assert pluginContents!=null && pluginWebapp!=null && dist != null;
 
-        InstallerSupport.setReadOnly(installerProps.getTargetDir().resolve("dist"), true);
+        InstallerSupport.setReadOnly(dist, true);
         InstallerSupport.setReadOnly(pluginContents, false);
         InstallerSupport.setReadOnly(pluginWebapp, false);
 
         if (installerProps.isSetGroupAndMode()) {
-            InstallerSupport.setMode(installerProps.getTargetDir().resolve("bin"), "755", "**/*.sh");
-            InstallerSupport.setMode(installerProps.getTargetDir().resolve("dist"), "444", "**/*");
+            final Path bin = installerProps.getTargetDir().resolve("bin");
+            final Path credentials = installerProps.getTargetDir().resolve("credentials");
+            assert bin!=null && credentials!=null;
+            InstallerSupport.setMode(bin, "755", "**/*.sh");
+            InstallerSupport.setMode(dist, "444", "**/*");
             InstallerSupport.setMode(pluginContents,  "640", "**/*");
             InstallerSupport.setMode(pluginWebapp,  "640", "**/*");
             if (currentState.getInstalledVersion() == null) {
-                InstallerSupport.setMode(installerProps.getTargetDir().resolve("credentials"),
-                        installerProps.getCredentialsKeyFileMode(), "**/*");
+                InstallerSupport.setMode(credentials, installerProps.getCredentialsKeyFileMode(), "**/*");
                 final String group = installerProps.getCredentialsGroup();
                 if (group != null) {
-                    InstallerSupport.setGroup(installerProps.getTargetDir().resolve("credentials"), group, "**/*");
+                    InstallerSupport.setGroup(credentials, group, "**/*");
                 }
             }
         }
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 3865dd9ac..e7342e9e6 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
@@ -355,6 +355,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
             LOG.warn("Installed contents for {} not found", pluginId);
         } else {
             for (final Path content: getInstalledContents()) {
+                assert content!=null;
                 if (!Files.exists(content)) {
                     continue;
                 }
@@ -925,14 +926,15 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
         moduleContext.setHttpClientSecurityParameters(securityParams);
         moduleContext.setHttpClient(httpClient);
         distPath = idpHome.resolve("dist");
-        workspacePath = distPath.resolve("plugin-workspace");
-        pluginsWebapp = distPath.resolve("plugin-webapp");
-        pluginsContents = distPath.resolve("plugin-contents");
+        final Path wsp = workspacePath = distPath.resolve("plugin-workspace");
+        final Path pwp = pluginsWebapp = distPath.resolve("plugin-webapp");
+        final Path pcp = pluginsContents = distPath.resolve("plugin-contents");
+        assert wsp!=null && pwp!=null && pcp!=null && distPath!=null;
         InstallerSupport.setReadOnly(distPath, false);
         // Just in case they have been protected
-        InstallerSupport.setMode(workspacePath, "640", "**/*");
-        InstallerSupport.setMode(pluginsWebapp, "640", "**/*");
-        InstallerSupport.setMode(pluginsContents, "640", "**/*");
+        InstallerSupport.setMode(wsp, "640", "**/*");
+        InstallerSupport.setMode(pwp, "640", "**/*");
+        InstallerSupport.setMode(pcp, "640", "**/*");
     }
 
     /** Generate a {@link URLClassLoader} which looks at the
@@ -1054,6 +1056,7 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
         InstallerSupport.deleteTree(downloadDirectory);
         InstallerSupport.deleteTree(unpackDirectory);
         InstallerSupport.deleteTree(workspacePath);
+        assert distPath!=null;
         InstallerSupport.setReadOnly(distPath, true);
     }
     
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/TestInstallerCLI.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/TestInstallerCLI.java
index 6800f8234..fd94fe5f8 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/TestInstallerCLI.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/TestInstallerCLI.java
@@ -46,7 +46,7 @@ public class TestInstallerCLI {
     public void silentInstall() {
 
         IdPInstallerCLI.runMain(new String[] {
-                "-ks", "p1",
+                "-kp", "p1",
                 "--sealerPassword", "p1",
                 "-e", "https://test.example.org/id",
                 "--hostName", "machine.org",
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/BasePluginTest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/BasePluginTest.java
index e4ad9959d..f32ecea66 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/BasePluginTest.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/BasePluginTest.java
@@ -67,11 +67,12 @@ public class BasePluginTest {
     }
 
     @AfterSuite public void teardownIdPHome() throws IOException {
-        if (idpHome == null) {
+        final Path ih = idpHome;
+        if (ih == null) {
             return;
         }
-        InstallerSupport.setReadOnly(idpHome, false);
-        InstallerSupport.deleteTree(idpHome);
+        InstallerSupport.setReadOnly(ih, false);
+        InstallerSupport.deleteTree(ih);
     }
 
     protected Path getIdpHome() {

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


More information about the commits mailing list