[java-identity-provider] 01/02: IDP-1595 Add the ability to remove a plugins jars from the war.
Rod Widdowson
rdw at steadingsoftware.com
Tue Sep 22 12:14:36 UTC 2020
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=83ab6034c3011e5dcc0ef7ed3bb2cf7c2caa6ac0
commit 83ab6034c3011e5dcc0ef7ed3bb2cf7c2caa6ac0
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Sep 22 13:01:55 2020 +0100
IDP-1595 Add the ability to remove a plugins jars from the war.
https://issues.shibboleth.net/jira/browse/IDP-1595
---
.../idp/installer/plugin/impl/PluginInstaller.java | 20 +++++
.../plugin/impl/PluginInstallerArguments.java | 36 +++++---
.../installer/plugin/impl/PluginInstallerCLI.java | 96 ++++++++++++----------
.../installer/plugin/impl/PluginInstallerTest.java | 12 ++-
4 files changed, 109 insertions(+), 55 deletions(-)
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 28226a045..b82479410 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
@@ -250,6 +250,26 @@ public final class PluginInstaller extends AbstractInitializableComponent implem
builder.execute();
}
+ /** Remove the jars for this plugin and rebuild the war.
+ * @throws BuildException if badness occurs. */
+ public void removeJars() throws BuildException {
+ final Path myWebApp = idpHome.resolve("dist").resolve("edit-webapp-" + pluginId);
+ if (!Files.exists(myWebApp)) {
+ LOG.error("Plugin {} had no jars installed.", pluginId);
+ return;
+ }
+ InstallerSupport.setReadOnly(myWebApp, false);
+ deleteTree(myWebApp);
+ final BuildWar builder = new BuildWar(idpHome);
+ try {
+ builder.initialize();
+ } catch (final ComponentInitializationException e) {
+ throw new BuildException(e);
+ }
+ builder.execute();
+ LOG.info("Removed resources for {} from the war", pluginId);
+ }
+
/** Download any files that should not be shipped.
* @throws BuildException if badness is detected.
*/
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 27ad886f0..42aab9db7 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
@@ -66,6 +66,10 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
/** Force update version. */
@Parameter(names= {"-fu", "--force-update"})
@Nullable private String forceUpdateVersion;
+
+ /** Id to remove. */
+ @Parameter(names= {"-r", "--remove-jars"})
+ @Nullable private String removeId;
/** The {@link #forceUpdateVersion} as a {@link PluginVersion}. */
@Nullable private PluginVersion updateVersion;
@@ -89,6 +93,8 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
INSTALLDIR,
/** Install from the web. */
INSTALLREMOTE,
+ /** Remove jars from dist - web-ing. */
+ REMOVEJARS,
/** Unknown. */
UNKNOWN
};
@@ -195,26 +201,33 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
}
if (list || fullList) {
operation = OperationType.LIST;
- if (input != null) {
- getLog().error("Cannot List and Install in the same operation.");
- throw new IllegalArgumentException("Cannot List and Install in the same operation.");
+ if (input != null || removeId != null) {
+ getLog().error("Cannot List and Install or Remove in the same operation.");
+ throw new IllegalArgumentException("Cannot List and Install or Remove in the same operation.");
}
- if (updatePluginId != null) {
- getLog().error("Cannot List and Update in the same operation.");
- throw new IllegalArgumentException("Cannot List and Update in the same operation.");
+ if (updatePluginId != null || removeId != null) {
+ getLog().error("Cannot List and Update or Remove in the same operation.");
+ throw new IllegalArgumentException("Cannot List and Update or Remove in the same operation.");
}
} else if (input != null) {
- if (updatePluginId != null) {
- getLog().error("Cannot Install and Update in the same operation.");
- throw new IllegalArgumentException("Cannot List and Update in the same operation.");
+ if (updatePluginId != null || removeId != null) {
+ getLog().error("Cannot Install and Update or Remove in the same operation.");
+ throw new IllegalArgumentException("Cannot List and Update or Remove in the same operation.");
}
operation = decodeInput() ;
} else if (updatePluginId != null) {
+ if (removeId != null) {
+ getLog().error("Cannot Update and Remove in the same operation.");
+ throw new IllegalArgumentException("Cannot Update and Remove in the same operation.");
+ }
pluginId = updatePluginId;
operation = OperationType.UPDATE;
if (forceUpdateVersion != null) {
updateVersion = new PluginVersion(forceUpdateVersion);
}
+ } else if (removeId != null) {
+ pluginId = removeId;
+ operation = OperationType.REMOVEJARS;
} else {
getLog().error("Missing qualifier. Options are : -l, -fl, -i, -u");
throw new IllegalArgumentException("Missing qualifier");
@@ -264,9 +277,12 @@ public class PluginInstallerArguments extends AbstractIdPHomeAwareCommandLineArg
out.println(String.format(" %-22s %s", "-l, --list", "Brief Information of all installed plugins"));
out.println(String.format(" %-22s %s", "-fl, --full-list", "Full details of all installed plugins"));
out.println(String.format(" %-22s %s", "-i, --input <what>", "Install (file name or web address)"));
- out.println(String.format(" %-22s %s", "-u, --update <what>", "update (plugin id)"));
+ out.println(String.format(" %-22s %s", "-u, --update <PluginId>", "update"));
out.println(String.format(" %-22s %s", "-fu, --force-update <version>",
"force version to update to (requires -u)"));
+ out.println(String.format(" %-22s %s", "-r, --remove-jars <PluginId>",
+ "remove any installed jars (and other resources) from the war file. \n" +
+ "\t\t\tDOES NOT UNDO any other installation"));
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 7c7d93557..4beffa8ca 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
@@ -110,8 +110,9 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
Security.addProvider(new BouncyCastleProvider());
}
- try {
- constructPluginInstaller();
+ try (final PluginInstaller inst = new PluginInstaller()){
+ constructPluginInstaller(inst);
+
switch (args.getOperation()) {
case LIST:
doList(args.getFullList(), args.getPluginId());
@@ -135,6 +136,11 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
doUpdate(args.getPluginId() , args.getUpdateVersion());
break;
+ case REMOVEJARS:
+ installer.setPluginId(args.getPluginId());
+ installer.removeJars();
+ break;
+
default:
getLogger().error("Invalid operation");
return RC_INIT;
@@ -152,16 +158,52 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
//CheckStyle: CyclomaticComplexity OM
/** Build the installer.
- * @throws ComponentInitializationException as required*/
- private void constructPluginInstaller() throws ComponentInitializationException {
- installer= new PluginInstaller();
- installer.setIdpHome(Path.of(getApplicationContext().getEnvironment().getProperty("idp.home")));
- installer.setAcceptCert(new InstallerQuery("Accept this Certificate"));
- installer.setAcceptDownload(new InstallerQuery("Download from"));
+ * @param inst the newly created installed
+ * @throws ComponentInitializationException as required
+ */
+ private void constructPluginInstaller(final PluginInstaller inst) throws ComponentInitializationException {
+ inst.setIdpHome(Path.of(getApplicationContext().getEnvironment().getProperty("idp.home")));
+ inst.setAcceptCert(new InstallerQuery("Accept this Certificate"));
+ inst.setAcceptDownload(new InstallerQuery("Download from"));
if (getHttpClient()!= null) {
- installer.setHttpClient(getHttpClient());
+ inst.setHttpClient(getHttpClient());
+ }
+ inst.initialize();
+ installer = inst;
+ }
+
+ /** Print our more information about a plugin.
+ * Helper method for {@link #doList(boolean, String)}
+ * @param plugin what we are interested in.
+ */
+ private void printDetails(final PluginDescription plugin) {
+ log.debug("Interrogating {} ", plugin.getPluginId());
+ final PluginState state = new PluginState(plugin);
+ if (getHttpClient() != null) {
+ state.setHttpClient(getHttpClient());
+ }
+ try {
+ state.initialize();
+ } catch (final ComponentInitializationException e) {
+ log.error("Could not interrogate plugin {}", plugin.getPluginId(), e);
+ return;
+ }
+ final Map<PluginVersion, VersionInfo> versions = state.getAvailableVersions();
+ System.out.println("\tVersions ");
+ for (final Entry<PluginVersion, VersionInfo> entry : versions.entrySet()) {
+ final String downLoadDetails;
+ if (state.getUpdateBaseName(entry.getKey()) == null || state.getUpdateURL(entry.getKey())==null ) {
+ downLoadDetails = " - No download available";
+ } else {
+ downLoadDetails = "";
+ }
+ System.out.println(String.format("\t%s:\tMin=%s\tMax=%s\tSupport level: %s%s",
+ entry.getKey(),
+ entry.getValue().getMinSupported(),
+ entry.getValue().getMaxSupported(),
+ entry.getValue().getSupportLevel(),
+ downLoadDetails));
}
- installer.initialize();
}
/** List all installed plugins (or just one if provided).
@@ -281,40 +323,6 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
}
}
-
- /** Print our more information about a plugin.
- * @param plugin what we are interested in.
- */
- private void printDetails(final PluginDescription plugin) {
- log.debug("Interrogating {} ", plugin.getPluginId());
- final PluginState state = new PluginState(plugin);
- if (getHttpClient() != null) {
- state.setHttpClient(getHttpClient());
- }
- try {
- state.initialize();
- } catch (final ComponentInitializationException e) {
- log.error("Could not interrogate plugin {}", plugin.getPluginId(), e);
- return;
- }
- final Map<PluginVersion, VersionInfo> versions = state.getAvailableVersions();
- System.out.println("\tVersions ");
- for (final Entry<PluginVersion, VersionInfo> entry : versions.entrySet()) {
- final String downLoadDetails;
- if (state.getUpdateBaseName(entry.getKey()) == null || state.getUpdateURL(entry.getKey())==null ) {
- downLoadDetails = " - No download available";
- } else {
- downLoadDetails = "";
- }
- System.out.println(String.format("\t%s:\tMin=%s\tMax=%s\tSupport level: %s%s",
- entry.getKey(),
- entry.getValue().getMinSupported(),
- entry.getValue().getMaxSupported(),
- entry.getValue().getSupportLevel(),
- downLoadDetails));
- }
- }
-
/** Shim for CLI entry point: Allows the code to be run from a test.
*
* @return one of the predefines {@link AbstractCommandLine#RC_INIT},
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
index 5871b5b1d..b9c59a4fe 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
@@ -76,7 +76,17 @@ public class PluginInstallerTest extends BasePluginTest {
assertTrue(result.containsKey("net.shibboleth.plugin.test"));
}
}
-
+
+ @Test(enabled = true, dependsOnMethods ={"testListing", }) public void testRemove() throws ComponentInitializationException, IOException
+ {
+ try (final PluginInstaller inst = new PluginInstaller()) {
+ inst.setIdpHome(getIdpHome());
+ inst.setPluginId("org.example.Plugin");
+ inst.initialize();
+ inst.removeJars();
+ }
+ }
+
@Test(enabled = false) public void testUnpackZip() throws ComponentInitializationException, IOException {
try (final PluginInstaller inst = new PluginInstaller()) {
inst.setIdpHome(getIdpHome());
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list