[java-identity-provider] 07/07: IDP-1595 Installer suppoer for installed modules.

Rod Widdowson rdw at steadingsoftware.com
Tue Jun 9 09:52:33 UTC 2020


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=edbc32c50e543b40b280155e0a74c53639ba2cbf

commit edbc32c50e543b40b280155e0a74c53639ba2cbf
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Jun 7 13:02:51 2020 +0100

    IDP-1595 Installer suppoer for installed modules.
    
    We do not delete the per-module edit-webapp directories when
    cleaning out the dist directory.
    
    We overlay in the per-mpodule edit-webapp directories when
    buulding the war files
    
    Additional changes update the path for a manual test (for using
    during development) and finally we delete empty folders when
    cleaning out dist.
---
 .../net/shibboleth/idp/installer/BuildWar.java     | 51 ++++++++++++++++++----
 .../shibboleth/idp/installer/CopyDistribution.java | 13 +++---
 .../shibboleth/idp/installer/InstallerSupport.java | 20 ++++++++-
 .../java/net/shibboleth/idp/installer/Test.java    |  4 +-
 4 files changed, 70 insertions(+), 18 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/BuildWar.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/BuildWar.java
index d55bf4d89..17571a1e2 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/BuildWar.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/BuildWar.java
@@ -18,7 +18,11 @@
 package net.shibboleth.idp.installer;
 
 import java.io.File;
+import java.io.IOException;
+import java.nio.file.FileSystem;
+import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.PathMatcher;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.Copy;
@@ -61,6 +65,40 @@ public final class BuildWar extends AbstractInitializableComponent {
         installerProps = props;
     }
 
+    /** Method to do a single overlay into webapp.
+     *
+     * @param from Where to copy from.
+     * @param webAppTo Where to copy to.
+     * @throws BuildException if unexpected badness occurs.
+     */
+    private void overlayWebapp(final Path from, final Path webAppTo) throws BuildException {
+        final Copy overlay = InstallerSupport.getCopyTask(from, webAppTo);
+        overlay.setOverwrite(true);
+        overlay.setPreserveLastModified(true);
+        overlay.setFailOnError(true);
+        overlay.setVerbose(log.isDebugEnabled());
+        log.info("Overlay from {} to {}", from, webAppTo);
+        overlay.execute();
+    }
+
+    /** Enumerate all the plugin webapps and deal with them.
+     * @param parent the 'dist' folder
+     * @param to target
+     * @throws BuildException as badness occurrs
+     */
+    private void overlayPluginWebapps(final Path parent, final Path to) throws BuildException {
+        final FileSystem fs = parent.getFileSystem();
+        final PathMatcher folderMatcher = fs.getPathMatcher("glob:edit-webapp-*");
+        try {
+            Files.list(parent).
+                filter(Files::isDirectory).
+                filter(e -> folderMatcher.matches(e.getFileName())).
+                forEach(e -> overlayWebapp(e, to));
+        } catch (final IOException e) {
+            throw new BuildException(e);
+        }
+    }
+
     /** Method to do the work of building the war.
      * @throws BuildException if unexpected badness occurs.
      */
@@ -73,7 +111,8 @@ public final class BuildWar extends AbstractInitializableComponent {
         InstallerSupport.deleteTree(target.resolve("webpapp"));
         final Path webAppTmp =target.resolve("webpapp.tmp");
         InstallerSupport.deleteTree(webAppTmp);
-        final Path distWebApp =  target.resolve("dist").resolve("webapp");
+        final Path dist = target.resolve("dist");
+        final Path distWebApp =  dist.resolve("webapp");
         final Copy initial = InstallerSupport.getCopyTask(distWebApp, webAppTmp);
         initial.setPreserveLastModified(true);
         initial.setFailOnError(true);
@@ -81,14 +120,8 @@ public final class BuildWar extends AbstractInitializableComponent {
         log.info("Initial populate from {} to {}", distWebApp, webAppTmp);
         initial.execute();
 
-        final Path editWebApp = target.resolve("edit-webapp");
-        final Copy overlay = InstallerSupport.getCopyTask(editWebApp, webAppTmp);
-        overlay.setOverwrite(true);
-        overlay.setPreserveLastModified(true);
-        overlay.setFailOnError(true);
-        overlay.setVerbose(log.isDebugEnabled());
-        log.info("Overlay from {} to {}", editWebApp, webAppTmp);
-        overlay.execute();
+        overlayPluginWebapps(dist, webAppTmp);
+        overlayWebapp(target.resolve("edit-webapp"), webAppTmp);
 
         final File warFileFile = warFile.toFile();
         if (warFileFile.exists() && !warFile.toFile().delete()) {
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/CopyDistribution.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/CopyDistribution.java
index 2530735a6..0c38335fe 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/CopyDistribution.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/CopyDistribution.java
@@ -71,8 +71,9 @@ public final class CopyDistribution extends AbstractInitializableComponent {
 
     /** Helper for the {@link #deleteOld()} method.
      * @param what what to delete
+     * @param excludes what to exclude
      */
-    private void delete(final Path what) {
+    private void delete(final Path what, final String excludes) {
         if (!Files.exists(what)) {
             log.debug("{} doesn't exist, nothing to delete", what);
         } else if (!Files.isDirectory(what)) {
@@ -80,7 +81,7 @@ public final class CopyDistribution extends AbstractInitializableComponent {
             throw new BuildException("Corrupt install - not a directory");
         } else {
             log.debug("Deleting {} ", what);
-            InstallerSupport.deleteTree(what);
+            InstallerSupport.deleteTree(what, excludes);
         }
     }
 
@@ -89,14 +90,14 @@ public final class CopyDistribution extends AbstractInitializableComponent {
      * @throws BuildException if badness occurs
      */
     protected void deleteOld() {
-        delete(installerProps.getTargetDir().resolve("bin").resolve("lib"));
-        delete(installerProps.getTargetDir().resolve("dist"));
-        delete(installerProps.getTargetDir().resolve("doc"));
+        delete(installerProps.getTargetDir().resolve("bin").resolve("lib"), null);
+        delete(installerProps.getTargetDir().resolve("dist"), "edit-webapp-*/**");
+        delete(installerProps.getTargetDir().resolve("doc"), null);
         final Path system = installerProps.getTargetDir().resolve("system");
         if (Files.exists(system)) {
             InstallerSupport.setReadOnly(system, false);
         }
-        delete(system);
+        delete(system, null);
     }
 
     /** Helper for the {@link #copyDist()} and
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 4450cc778..bc623b08a 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
@@ -253,6 +253,15 @@ public final class InstallerSupport {
      * @throws BuildException if badness occurs
      */
     public static void deleteTree(final Path where) throws BuildException {
+        deleteTree(where, null);
+    }
+
+    /** Delete the tree.
+     * @param where where
+     * @param excludes wildcards to exclude
+     * @throws BuildException if badness occurs
+     */
+    public static void deleteTree(final Path where, final String excludes) throws BuildException {
         if (!Files.exists(where)) {
             log.debug("Directory {} does not exist. Skipping delete.", where);
             return;
@@ -264,8 +273,17 @@ public final class InstallerSupport {
         log.debug("Deleting tree {}", where);
         final Delete delete = new Delete();
         delete.setProject(ANT_PROJECT);
-        delete.setDir(where.toFile());
         delete.setFailOnError(false);
+        delete.setIncludeEmptyDirs(true);
+        if (excludes != null) {
+            final FileSet set = new FileSet();
+            set.setExcludes(excludes);
+            set.setIncludes("**/**");
+            set.setDir(where.toFile());
+            delete.addFileset(set);
+        } else {
+            delete.setDir(where.toFile());
+        }
         // Logic for setVerbose is inverted
         // https://bz.apache.org/bugzilla/show_bug.cgi?id=63887
         delete.setVerbose(!log.isDebugEnabled());
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 dd113b242..6deac8a3d 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
@@ -46,9 +46,9 @@ public class Test {
 
         System.setProperty(InstallerPropertiesImpl.TARGET_DIR,"H:\\Downloads\\v4install");
         System.setProperty(InstallerPropertiesImpl.SOURCE_DIR,
-                "h:\\Perforce\\Juno\\New\\java-identity-provider\\idp-distribution\\target\\shibboleth-identity-provider-4.0.0-SNAPSHOT");
+                "h:\\Perforce\\Juno\\New\\java-identity-provider\\idp-distribution\\target\\shibboleth-identity-provider-4.1.0-SNAPSHOT");
         System.setProperty(InstallerPropertiesImpl.ANT_BASE_DIR,
-                "h:\\Perforce\\Juno\\New\\java-identity-provider\\idp-distribution\\target\\shibboleth-identity-provider-4.0.0-SNAPSHOT\\bin");
+                "h:\\Perforce\\Juno\\New\\java-identity-provider\\idp-distribution\\target\\shibboleth-identity-provider-4.1.0-SNAPSHOT\\bin");
         System.setProperty(InstallerPropertiesImpl.KEY_STORE_PASSWORD, "p1");
         System.setProperty(InstallerPropertiesImpl.SEALER_PASSWORD, "p1");
         System.setProperty(InstallerPropertiesImpl.HOST_NAME, "machine.org.uk");

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


More information about the commits mailing list