[java-idp-jetty-base] 05/09: IDP-2297 Explore extending the Plugin and Module Infrastructure to allow Jetty installation

Rod Widdowson rdw at steadingsoftware.com
Sat Aug 10 15:04:33 UTC 2024


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

rdw pushed a commit to branch dev/IDP-2297
in repository java-idp-jetty-base.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-jetty-base.git;a=commit;h=f8edc9c1f8bd0cd29d8fac2866d86d99fd0f00c7

commit f8edc9c1f8bd0cd29d8fac2866d86d99fd0f00c7
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jul 30 16:58:31 2024 +0100

    IDP-2297 Explore extending the Plugin and Module Infrastructure to allow Jetty installation
    
    https://shibboleth.atlassian.net/browse/IDP-2297
    
    Add a jetty-base module.
---
 jetty-base-impl/pom.xml                            |  6 +++
 .../idp/jettybase/plugin/JettyBaseModule.java      | 61 ++++++++++++++++++++++
 .../idp/jettybase/plugin/JettyBasePlugin.java      | 13 +++++
 .../shibboleth/idp/jettybase/plugin/Version.java   | 46 ++++++++++++++++
 .../services/net.shibboleth.idp.module.IdPModule   |  1 +
 .../{jetty-base => }/etc/jetty-requestlog.xml      |  0
 .../module/jetty-base/credentials/.gitkeep         |  0
 .../idp/jettybase/module/jetty-base/logs/.gitkeep  |  0
 .../jettybase/module/jetty-base/static/.gitkeep    |  0
 .../idp/jettybase/module/jetty-base/tmp/.gitkeep   |  0
 .../module/{jetty-base => }/modules/idp.mod        |  0
 .../module/{jetty-base => }/resources/logback.xml  |  0
 .../module/{jetty-base => }/start.d/custom.ini     |  0
 .../module/{jetty-base => }/start.d/idp.ini        |  0
 .../module/{jetty-base => }/webapps/idp.xml        |  0
 .../module/{jetty-base => }/webapps/static.xml     |  0
 .../idp/jettybase/plugin/module.properties         | 32 ++++++++++++
 pom.xml                                            |  2 +-
 18 files changed, 160 insertions(+), 1 deletion(-)

diff --git a/jetty-base-impl/pom.xml b/jetty-base-impl/pom.xml
index 15d7422..91a520a 100644
--- a/jetty-base-impl/pom.xml
+++ b/jetty-base-impl/pom.xml
@@ -28,6 +28,12 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>${slf4j.groupId}</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
     </dependencies>
 
     <build>
diff --git a/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/JettyBaseModule.java b/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/JettyBaseModule.java
new file mode 100644
index 0000000..bbd671b
--- /dev/null
+++ b/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/JettyBaseModule.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed 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.jettybase.plugin;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+
+import org.slf4j.Logger;
+
+import net.shibboleth.idp.Version;
+import net.shibboleth.idp.module.impl.PluginIdPModule;
+import net.shibboleth.profile.module.ModuleContext;
+import net.shibboleth.profile.module.ModuleException;
+import net.shibboleth.shared.primitive.LoggerFactory;
+
+public class JettyBaseModule extends PluginIdPModule {
+
+    /** Class logger. */
+    @Nonnull private Logger log = LoggerFactory.getLogger(JettyBaseModule.class);
+
+    /**
+     * Constructor.
+     */
+    public JettyBaseModule() throws IOException, ModuleException {
+        super(Version.getVersion(), JettyBaseModule.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull
+    public Map<ModuleResource, ResourceResult> enable(@Nonnull ModuleContext moduleContext) throws ModuleException {
+        final Map<ModuleResource, ResourceResult> result = super.enable(moduleContext);
+        final Path jettyBase = Path.of(moduleContext.getInstallLocation()).resolve("jetty-base");
+        log.debug("Creating directories (if needed): 'credentials', 'logs', 'static', 'tmp' below {}", jettyBase);
+        try {
+            Files.createDirectory(jettyBase.resolve("credentials"));
+            Files.createDirectory(jettyBase.resolve("logs"));
+            Files.createDirectory(jettyBase.resolve("static"));
+            Files.createDirectory(jettyBase.resolve("tmp"));
+        } catch (final IOException e) {
+            log.error("Create Directory failed", e);
+            throw new ModuleException(e);
+        }
+        return result;
+    }
+}
diff --git a/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/JettyBasePlugin.java b/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/JettyBasePlugin.java
index 83c7c2f..dd340f3 100644
--- a/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/JettyBasePlugin.java
+++ b/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/JettyBasePlugin.java
@@ -15,9 +15,13 @@
 package net.shibboleth.idp.jettybase.plugin;
 
 import java.io.IOException;
+import java.util.Set;
 
+import net.shibboleth.idp.module.IdPModule;
 import net.shibboleth.idp.plugin.impl.FirstPartyIdPPlugin;
+import net.shibboleth.profile.module.ModuleException;
 import net.shibboleth.profile.plugin.PluginException;
+import net.shibboleth.shared.collection.CollectionSupport;
 
 /**Details about the Nashorn scripting plugin.  */
 public class JettyBasePlugin extends FirstPartyIdPPlugin {
@@ -27,5 +31,14 @@ public class JettyBasePlugin extends FirstPartyIdPPlugin {
      */
     public JettyBasePlugin() throws PluginException, IOException {
         super(JettyBasePlugin.class);
+        try {
+            final Set<IdPModule> modules = CollectionSupport.singleton(new JettyBaseModule());
+            setEnableOnInstall(modules);
+            setDisableOnRemoval(modules);
+        } catch (final IOException e) {
+            throw e;
+        } catch (final ModuleException e) {
+            throw new PluginException(e);
+        }
     }
 }
diff --git a/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/Version.java b/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/Version.java
new file mode 100644
index 0000000..fdc1813
--- /dev/null
+++ b/jetty-base-impl/src/main/java/net/shibboleth/idp/jettybase/plugin/Version.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed 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.jettybase.plugin;
+
+import javax.annotation.Nullable;
+
+/** Class for getting and printing the version of the plugin. */
+public final class Version {
+
+    /** Plugin version. */
+    @Nullable private static final String VERSION = Version.class.getPackage().getImplementationVersion();
+
+    /** Constructor. */
+    private Version() {
+    }
+
+    /**
+     * Main entry point to program.
+     *
+     * @param args command line arguments
+     */
+    public static void main(final String[] args) {
+        System.out.println(VERSION);
+    }
+
+    /**
+     * Get the version of the IdP.
+     *
+     * @return version of the IdP
+     */
+    @Nullable public static String getVersion() {
+        return VERSION;
+    }
+}
diff --git a/jetty-base-impl/src/main/resources/META-INF/services/net.shibboleth.idp.module.IdPModule b/jetty-base-impl/src/main/resources/META-INF/services/net.shibboleth.idp.module.IdPModule
new file mode 100644
index 0000000..6fc30c3
--- /dev/null
+++ b/jetty-base-impl/src/main/resources/META-INF/services/net.shibboleth.idp.module.IdPModule
@@ -0,0 +1 @@
+net.shibboleth.idp.jettybase.plugin.JettyBaseModule
\ No newline at end of file
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/etc/jetty-requestlog.xml b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/etc/jetty-requestlog.xml
similarity index 100%
rename from jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/etc/jetty-requestlog.xml
rename to jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/etc/jetty-requestlog.xml
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/credentials/.gitkeep b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/credentials/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/logs/.gitkeep b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/logs/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/static/.gitkeep b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/static/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/tmp/.gitkeep b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/tmp/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/modules/idp.mod b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/modules/idp.mod
similarity index 100%
rename from jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/modules/idp.mod
rename to jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/modules/idp.mod
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/resources/logback.xml b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/resources/logback.xml
similarity index 100%
rename from jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/resources/logback.xml
rename to jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/resources/logback.xml
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/start.d/custom.ini b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/start.d/custom.ini
similarity index 100%
rename from jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/start.d/custom.ini
rename to jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/start.d/custom.ini
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/start.d/idp.ini b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/start.d/idp.ini
similarity index 100%
rename from jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/start.d/idp.ini
rename to jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/start.d/idp.ini
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/webapps/idp.xml b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/webapps/idp.xml
similarity index 100%
rename from jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/webapps/idp.xml
rename to jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/webapps/idp.xml
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/webapps/static.xml b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/webapps/static.xml
similarity index 100%
rename from jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/jetty-base/webapps/static.xml
rename to jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/module/webapps/static.xml
diff --git a/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/plugin/module.properties b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/plugin/module.properties
new file mode 100644
index 0000000..9b944be
--- /dev/null
+++ b/jetty-base-impl/src/main/resources/net/shibboleth/idp/jettybase/plugin/module.properties
@@ -0,0 +1,32 @@
+# Properties defining this module.
+
+# Class to Module ID mappings
+net.shibboleth.idp.plugin.jettybase.JettyBaseModule = jetty.base.module
+
+# Module Owner
+jetty.base.plugin = net.shibboleth.idp.plugin.jettybase
+
+jetty.base.module.name = Jetty Base Module
+jetty.base.module.desc = Configures jetty  
+
+
+jetty.base.module.1.src = /net/shibboleth/idp/jettybase/module/etc/jetty-requestlog.xml
+jetty.base.module.1.dest = jetty-base/etc/jetty-requestlog.xml
+
+jetty.base.module.2.src = /net/shibboleth/idp/jettybase/module/modules/idp.mod
+jetty.base.module.2.dest = jetty-base/modules/idp.mod
+
+jetty.base.module.3.src = /net/shibboleth/idp/jettybase/module/resources/logback.xml
+jetty.base.module.3.dest = jetty-base/resources/logback.xml
+
+jetty.base.module.4.src = /net/shibboleth/idp/jettybase/module/start.d/custom.ini
+jetty.base.module.4.dest = jetty-base/start.d/custom.ini
+
+jetty.base.module.5.src = /net/shibboleth/idp/jettybase/module/start.d/idp.ini
+jetty.base.module.5.dest = jetty-base/start.d/idp.ini
+
+jetty.base.module.6.src = /net/shibboleth/idp/jettybase/module/webapps/idp.xml
+jetty.base.module.6.dest = jetty-base/webapps/idp.xml
+
+jetty.base.module.7.src = /net/shibboleth/idp/jettybase/module/webapps/static.xml
+jetty.base.module.7.dest = jetty-base/webapps/static.xml
diff --git a/pom.xml b/pom.xml
index 7b3bb3d..011ada6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
 
     <name>Jetty base plugin Parent Project</name>
     <groupId>net.shibboleth.idp.plugin.jetty-base</groupId>
-    <artifactId>jetty-base-parent</artifactId>
+    <artifactId>jetty-base-plugin-parent</artifactId>
     <packaging>pom</packaging>
     <version>12.0.11-SNAPSHOT</version>
 

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


More information about the commits mailing list