From 3fcb24e9f610aad940fe6bef22888513067f8cc1 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Wed, 11 Jan 2023 16:54:21 -0600 Subject: [PATCH 01/13] experiment--do not use --- core/pom.xml | 6 +- .../weblogic/deploy/tool/ArchiveHelper.java | 99 ++++++++++++ .../ArchiveHelperException.java | 105 ++++++++++++ .../tool/archive_helper/CommandResponse.java | 74 +++++++++ .../tool/archive_helper/CommonOptions.java | 78 +++++++++ .../archive_helper/HelpVersionProvider.java | 17 ++ .../archive_helper/list/ListAllCommand.java | 55 +++++++ .../list/ListApplicationsCommand.java | 35 ++++ .../tool/archive_helper/list/ListCommand.java | 23 +++ .../tool/archive_helper/list/ListOptions.java | 23 +++ .../archive_helper/list/ListTypeCommand.java | 49 ++++++ .../oracle/weblogic/deploy/util/ExitCode.java | 20 +++ .../deploy/util/WLSDeployArchive.java | 151 ++++++++++++++++-- .../main/python/wlsdeploy/util/exit_code.py | 17 +- .../deploy/messages/wlsdeploy_rb.properties | 10 +- installer/pom.xml | 4 + installer/src/assembly/zip.xml | 1 + pom.xml | 6 + 18 files changed, 751 insertions(+), 22 deletions(-) create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/ArchiveHelperException.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/HelpVersionProvider.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationsCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOptions.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/util/ExitCode.java diff --git a/core/pom.xml b/core/pom.xml index 510bf4c5fe..d9773eda0e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -32,6 +32,10 @@ org.yaml snakeyaml + + info.picocli + picocli + javax.xml.bind jaxb-api @@ -94,7 +98,7 @@ - antlr4-runtime-${antlr.version}.jar snakeyaml-${snakeyaml.version}.jar + antlr4-runtime-${antlr.version}.jar snakeyaml-${snakeyaml.version}.jar picocli-${picocli.version}.jar diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java new file mode 100644 index 0000000000..f0f2f696ac --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool; + +import java.io.PrintWriter; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; + +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.tool.archive_helper.HelpVersionProvider; +import oracle.weblogic.deploy.tool.archive_helper.list.ListCommand; +import oracle.weblogic.deploy.util.ExitCode; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.IParameterExceptionHandler; +import picocli.CommandLine.ParameterException; +import picocli.CommandLine.ParseResult; +import picocli.CommandLine.UnmatchedArgumentException; + +@Command( + name = "archiveHelper", + mixinStandardHelpOptions = true, + description = "%nA tool to create and modify a WebLogic Deploy Tooling archive file.%n", + versionProvider = HelpVersionProvider.class, + sortOptions = false, + subcommands = { + ListCommand.class + }, + requiredOptionMarker = '*', + usageHelpWidth = 80, + commandListHeading = "%nCommands:%n%nChoose from:%n" +) +public class ArchiveHelper { + private static final String CLASS = ArchiveHelper.class.getName(); + private static final PlatformLogger LOGGER = + WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); + + @SuppressWarnings("java:S106") + public static void main(String[] args) { + final String METHOD = "main"; + LOGGER.entering(CLASS, METHOD, (Object[]) args); + + int exitCode = executeCommand(new PrintWriter(System.out, true), + new PrintWriter(System.err, true), args); + + LOGGER.exiting(CLASS, METHOD, exitCode); + System.exit(exitCode); + } + + static int executeCommand(PrintWriter out, PrintWriter err, String... args) { + CommandLine cmd = new CommandLine(ArchiveHelper.class) + .setCaseInsensitiveEnumValuesAllowed(true) + .setToggleBooleanFlags(false) + .setUnmatchedArgumentsAllowed(false) + .setTrimQuotes(true) + //.setColorScheme(CommandLine.Help.defaultColorScheme(CommandLine.Help.Ansi.AUTO)) + .setParameterExceptionHandler(new ArgParsingExceptionHandler()) + .setOut(out) + .setErr(err); + + int exitCode = cmd.execute(args); + if (exitCode != ExitCode.USAGE_ERROR) { + CommandLine commandLine = getResponseCommandLine(cmd); + CommandResponse response = commandLine.getExecutionResult(); + if (response != null) { + exitCode = response.getStatus(); + response.printMessages(out, err); + } + } + return exitCode; + } + + private static CommandLine getResponseCommandLine(CommandLine commandLine) { + CommandLine result = commandLine; + + ParseResult parseResult = commandLine.getParseResult().subcommand(); + if (parseResult != null) { + result = getResponseCommandLine(parseResult.commandSpec().commandLine()); + } + return result; + } + + static class ArgParsingExceptionHandler implements IParameterExceptionHandler { + @Override + public int handleParseException(ParameterException ex, String[] args) { + CommandLine cmd = ex.getCommandLine(); + PrintWriter writer = cmd.getErr(); + + writer.println(ex.getMessage()); + UnmatchedArgumentException.printSuggestions(ex, writer); + ex.getCommandLine().usage(writer, cmd.getColorScheme()); + + return ExitCode.USAGE_ERROR; + } + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/ArchiveHelperException.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/ArchiveHelperException.java new file mode 100644 index 0000000000..7cf7b41313 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/ArchiveHelperException.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2023, Oracle Corporation and/or its affiliates. All rights reserved. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper; + +import oracle.weblogic.deploy.exception.BundleAwareException; +import oracle.weblogic.deploy.exception.ExceptionHelper; + +public class ArchiveHelperException extends BundleAwareException { + private static final long serialVersionUID = 1L; + + private final int exitCode; + + /** + * Constructs a default exception with exit code of 2. + */ + public ArchiveHelperException() { + this.exitCode = 2; + } + + /** + * Construct a default exception with specified exit code + * @param exitCode the exit code to use + */ + public ArchiveHelperException(int exitCode) { + this.exitCode = exitCode; + } + + /** + * Constructs a new exception with the specified message id. + * + * @param exitCode the exit code to use + * @param messageID the message ID + */ + public ArchiveHelperException(int exitCode, String messageID) { + super(messageID); + this.exitCode = exitCode; + } + + /** + * Constructs a new exception with the specified message id and parameters. + * + * @param exitCode the exit code to use + * @param messageID the message ID + * @param params the parameters to use to fill in the message tokens + */ + public ArchiveHelperException(int exitCode, String messageID, Object... params) { + super(messageID, params); + this.exitCode = exitCode; + } + + /** + * Constructs a new exception with the specified message id and cause. + * + * @param exitCode the exit code to use + * @param messageID the message ID + * @param cause the exception that triggered the creation of this exception + */ + public ArchiveHelperException(int exitCode, String messageID, Throwable cause) { + super(messageID, cause); + this.exitCode = exitCode; + } + + /** + * Constructs a new exception with passed message id, cause, and parameters. + * + * @param exitCode the exit code to use + * @param messageID the message ID + * @param cause the exception that triggered the creation of this exception + * @param params the parameters to use to fill in the message tokens + */ + public ArchiveHelperException(int exitCode, String messageID, Throwable cause, Object... params) { + super(messageID, cause, params); + this.exitCode = exitCode; + } + + /** + * Constructs a new exception with the specified cause. + * + * @param exitCode the exit code to use + * @param cause the exception that triggered the creation of this exception + */ + public ArchiveHelperException(int exitCode, Throwable cause) { + super(cause); + this.exitCode = exitCode; + } + + /** + * {@inheritDoc} + */ + @Override + public String getBundleName() { + return ExceptionHelper.getResourceBundleName(); + } + + /** + * Get the exit code associated with this exception. + * + * @return the exit code associated with this exception + */ + public int getExitCode() { + return this.exitCode; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java new file mode 100644 index 0000000000..cac554276d --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; + +public class CommandResponse { + private static final ResourceBundle RESOURCE_BUNDLE = + ResourceBundle.getBundle("oracle.weblogic.deploy.messages.wlsdeploy_rb"); + + private int status; + private List messages = new ArrayList<>(); + private List messageParamsList = new ArrayList<>(); + + public CommandResponse(int status) { + this.status = status; + } + + public CommandResponse(int status, String message, Object... messageParams) { + this.status = status; + this.messages.add(message); + this.messageParamsList.add(messageParams); + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String[] getMessages() { + String[] formattedMessages = new String[this.messages.size()]; + + for (int index = 0; index < this.messages.size(); index++) { + String message = this.messages.get(index); + if (RESOURCE_BUNDLE.containsKey(message)) { + message = String.format(message, this.messageParamsList.get(index)); + } + formattedMessages[index] = message; + } + return formattedMessages; + } + + public void addMessage(String message, Object... messageParams) { + this.messages.add(message); + this.messageParamsList.add(messageParams); + } + + public void addMessages(List messages) { + this.messages.addAll(messages); + for (int i = 0; i < messages.size(); i++) { + this.messageParamsList.add(new Object[0]); + } + } + + @SuppressWarnings("java:S106") + public void printMessages(PrintWriter out, PrintWriter err) { + PrintWriter location = out; + if (status != 0) { + location = err; + } + + for (String message : getMessages()) { + location.println(message); + } + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java new file mode 100644 index 0000000000..75fa92a10b --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper; + +import java.io.File; +import java.util.List; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.FileUtils; +import oracle.weblogic.deploy.util.StringUtils; +import oracle.weblogic.deploy.util.WLSDeployArchive; +import picocli.CommandLine; +import picocli.CommandLine.Option; +import picocli.CommandLine.Spec; +import picocli.CommandLine.Unmatched; + +public abstract class CommonOptions { + private static final String CLASS = CommonOptions.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); + + @Unmatched + List unmatchedOptions; + + @Spec + CommandLine.Model.CommandSpec spec; + + @Option( + names = { "-archive_file" }, + paramLabel = "", + required = true, + description = "Path to the archive file to use." + ) + protected String archiveFilePath; + + protected WLSDeployArchive archive; + + protected String getArchiveFilePath() { + return archiveFilePath; + } + + protected void initializeOptions() throws ArchiveHelperException { + this.archive = createArchive(); + } + + private WLSDeployArchive createArchive() throws ArchiveHelperException { + final String METHOD = "createArchive"; + LOGGER.entering(CLASS, METHOD); + + String fullArchiveFileName = FileUtils.getCanonicalPath(getArchiveFilePath()); + if (StringUtils.isEmpty(fullArchiveFileName)) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.USAGE_ERROR, "WLSDPLY-30000"); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + File fullArchiveFile = new File(fullArchiveFileName); + if (!fullArchiveFile.exists()) { + File fullArchiveParentDir = fullArchiveFile.getParentFile(); + if (!fullArchiveParentDir.exists() && !fullArchiveParentDir.mkdirs()) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30001", + fullArchiveParentDir.getAbsolutePath()); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + } else if (!fullArchiveFile.isFile()) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30002", + fullArchiveFile.getAbsolutePath()); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + return new WLSDeployArchive(fullArchiveFileName); + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/HelpVersionProvider.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/HelpVersionProvider.java new file mode 100644 index 0000000000..4c1600c475 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/HelpVersionProvider.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper; + +import oracle.weblogic.deploy.util.WebLogicDeployToolingVersion; + +import picocli.CommandLine.IVersionProvider; + +public class HelpVersionProvider implements IVersionProvider { + + @Override + public String[] getVersion() { + return new String[] { WebLogicDeployToolingVersion.getFullVersion() }; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java new file mode 100644 index 0000000000..4f9c4e1a90 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import java.util.List; +import java.util.concurrent.Callable; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; + +import oracle.weblogic.deploy.tool.archive_helper.CommonOptions; +import oracle.weblogic.deploy.tool.archive_helper.HelpVersionProvider; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; + +@Command( + name = "all", + description = "List all entries in the archive file", + mixinStandardHelpOptions = true, + versionProvider = HelpVersionProvider.class, + sortOptions = false +) +public class ListAllCommand extends CommonOptions implements Callable { + private static final String CLASS = ListAllCommand.class.getName(); + private static final PlatformLogger LOGGER = + WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + super.initializeOptions(); + + List archiveEntries = this.archive.getArchiveEntries(); + response = new CommandResponse(ExitCode.OK); + response.addMessages(archiveEntries); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ex.getLocalizedMessage(), ex); + response = new CommandResponse(ex.getExitCode(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException ex) { + LOGGER.severe("WLSDPLY-30003", ex, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30003", this.archiveFilePath, + ex.getLocalizedMessage()); + } + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationsCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationsCommand.java new file mode 100644 index 0000000000..8b120d924f --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationsCommand.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.tool.archive_helper.HelpVersionProvider; +import picocli.CommandLine.Command; + +@Command( + name = "applications", + description = "List application entries in the archive file", + mixinStandardHelpOptions = true, + versionProvider = HelpVersionProvider.class, + sortOptions = false +) +public class ListApplicationsCommand extends ListTypeCommand { + private static final String CLASS = ListApplicationsCommand.class.getName(); + private static final PlatformLogger LOGGER = + WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listApplications(); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java new file mode 100644 index 0000000000..685ede4138 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.tool.archive_helper.HelpVersionProvider; + +import picocli.CommandLine.Command; + +@Command( + name = "list", + description = "List contents of archive file", + versionProvider = HelpVersionProvider.class, + commandListHeading = "%nCommands:%n%n", + subcommands = { + ListAllCommand.class, + ListApplicationsCommand.class + }, + sortOptions = false +) +public class ListCommand { +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOptions.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOptions.java new file mode 100644 index 0000000000..58bada15c8 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOptions.java @@ -0,0 +1,23 @@ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommonOptions; +import picocli.CommandLine.Option; + +public class ListOptions extends CommonOptions { + private static final String CLASS = ListOptions.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the object of the specified type to list." + ) + String name; + + protected void initializeOptions() throws ArchiveHelperException { + super.initializeOptions(); + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommand.java new file mode 100644 index 0000000000..dddf419b2a --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommand.java @@ -0,0 +1,49 @@ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import java.util.List; +import java.util.concurrent.Callable; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.StringUtils; +import oracle.weblogic.deploy.util.WLSDeployArchive; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; + +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.APPLICATIONS; + +public abstract class ListTypeCommand extends ListOptions implements Callable { + private static final String CLASS = ListTypeCommand.class.getName(); + private static final PlatformLogger LOGGER = + WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); + + public CommandResponse listApplications() { + final String METHOD = "listApplications"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + List archiveEntries; + if (StringUtils.isEmpty(this.name)) { + archiveEntries = this.archive.getArchiveEntries(APPLICATIONS); + } else { + archiveEntries = this.archive.getArchiveEntries(APPLICATIONS, this.name); + } + response = new CommandResponse(ExitCode.OK); + response.addMessages(archiveEntries); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ex.getLocalizedMessage(), ex); + response = new CommandResponse(ex.getExitCode(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException ex) { + LOGGER.severe("WLSDPLY-30003", ex, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30003", ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/util/ExitCode.java b/core/src/main/java/oracle/weblogic/deploy/util/ExitCode.java new file mode 100644 index 0000000000..922182d237 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/util/ExitCode.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.util; + +public class ExitCode { + public static final int OK = 0; + public static final int WARNING = 1; + public static final int ERROR = 2; + public static final int ARG_VALIDATION_ERROR = 98; + public static final int USAGE_ERROR = 99; + public static final int HELP = 100; + public static final int RESTART_REQUIRED = 103; + public static final int CANCEL_CHANGES_IF_RESTART = 104; + + private ExitCode() { + // hide default constructor + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java index 1c01285cc5..8e0ae77203 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java @@ -13,6 +13,7 @@ import java.net.URL; import java.nio.file.Files; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.jar.JarFile; @@ -31,6 +32,11 @@ public class WLSDeployArchive { private static final String CLASS = WLSDeployArchive.class.getName(); + // Used by the unit tests so it requires package level scoping... + // + /* package */ + static final String ZIP_SEP = "/"; + public static final String WLSDPLY_ARCHIVE_BINARY_DIR = "wlsdeploy"; /** @@ -58,12 +64,12 @@ public class WLSDeployArchive { * Top-level archive subdirectory where all database wallets are stored in subdirectories. */ public static final String ARCHIVE_DB_WALLETS_DIR = - String.format("%s/%s/", WLSDPLY_ARCHIVE_BINARY_DIR, DB_WALLETS_DIR_NAME); + String.format("%s/%s", WLSDPLY_ARCHIVE_BINARY_DIR, DB_WALLETS_DIR_NAME); /** * Default, top-level archive subdirectory where the database wallet for the RCU database is stored. */ - public static final String DEFAULT_RCU_WALLET_PATH = ARCHIVE_DB_WALLETS_DIR + DEFAULT_RCU_WALLET_NAME; + public static final String DEFAULT_RCU_WALLET_PATH = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + DEFAULT_RCU_WALLET_NAME; /** * Top-level archive subdirectory where the atp wallet is stored. @@ -158,7 +164,8 @@ public class WLSDeployArchive { public static final String ARCHIVE_JMS_FOREIGN_SERVER_DIR = ARCHIVE_JMS_DIR + "/foreignServer"; public enum ArchiveEntryType { - SHARED_LIBRARIES, APPLICATIONS, + SHARED_LIBRARIES, + APPLICATIONS, APPLICATION_PLAN, SHLIB_PLAN, DOMAIN_LIB, @@ -172,14 +179,11 @@ public enum ArchiveEntryType { COHERENCE_CONFIG, COHERENCE_PERSISTENCE_DIR, FILE_STORE, - NODE_MANAGER_KEY_STORE + NODE_MANAGER_KEY_STORE, + DB_WALLET, + OPSS_WALLET } - // Used by the unit tests so it requires package level scoping... - // - /* package */ - static final String ZIP_SEP = "/"; - private static final String SEP = File.separator; private static final int READ_BUFFER_SIZE = 4096; private static final String COHERENCE_CONFIG_FILE_EXTENSION = ".xml"; @@ -239,6 +243,108 @@ public static boolean isClasspathEntry(String path) { return path.startsWith(ARCHIVE_CPLIB_TARGET_DIR); } + public static String getPathForType(ArchiveEntryType type) { + final String METHOD = "getPathForType"; + LOGGER.entering(CLASS, METHOD, type); + + String pathPrefix = null; + switch(type) { + case APPLICATIONS: + pathPrefix = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP; + break; + + case SHARED_LIBRARIES: + pathPrefix = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP; + break; + + case DOMAIN_LIB: + pathPrefix = ARCHIVE_DOMLIB_TARGET_DIR + ZIP_SEP; + break; + + case DOMAIN_BIN: + pathPrefix = ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP; + break; + + case CLASSPATH_LIB: + pathPrefix = ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP; + break; + + case SCRIPTS: + pathPrefix = ARCHIVE_SCRIPTS_DIR + ZIP_SEP; + break; + + case SERVER_KEYSTORE: + pathPrefix = ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP; + break; + + case MIME_MAPPING: + pathPrefix = ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP; + break; + + case COHERENCE: + pathPrefix = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP; + break; + + case JMS_FOREIGN_SERVER: + pathPrefix = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP; + break; + + case FILE_STORE: + pathPrefix = ARCHIVE_FILE_STORE_TARGET_DIR + ZIP_SEP; + break; + + case NODE_MANAGER_KEY_STORE: + pathPrefix = ARCHIVE_NODE_MANAGER_TARGET_DIR + ZIP_SEP; + break; + + case DB_WALLET: + pathPrefix = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP; + break; + + case OPSS_WALLET: + pathPrefix = ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP; + break; + + // FIXME - need to log if receiving an unknown type + } + + LOGGER.exiting(CLASS, METHOD, pathPrefix); + return pathPrefix; + } + + public static String getPathForType(ArchiveEntryType type, String name) { + final String METHOD = "getPathForType"; + LOGGER.entering(CLASS, METHOD, type, name); + + String pathPrefix = getPathForType(type); + if (!StringUtils.isEmpty(name)) { + boolean hasName = true; + boolean isAlwaysDirectory = false; + switch(type) { + case COHERENCE: + case JMS_FOREIGN_SERVER: + case FILE_STORE: + case DB_WALLET: + isAlwaysDirectory = true; + break; + + case OPSS_WALLET: + hasName = false; + break; + } + + if (pathPrefix != null && hasName) { + pathPrefix += name; + if (isAlwaysDirectory) { + pathPrefix += ZIP_SEP; + } + } + } + + LOGGER.exiting(CLASS, METHOD, pathPrefix); + return pathPrefix; + } + /** * Get the current file name for the JCSLifecycleArchive file. * @@ -263,6 +369,26 @@ public List getArchiveEntries() throws WLSDeployArchiveIOException { return entries; } + public List getArchiveEntries(ArchiveEntryType type) throws WLSDeployArchiveIOException { + final String METHOD = "getArchiveEntries"; + + LOGGER.entering(CLASS, METHOD); + List entries = getArchiveEntries(type, null); + LOGGER.exiting(CLASS, METHOD, entries); + return entries; + } + + public List getArchiveEntries(ArchiveEntryType type, String name) throws WLSDeployArchiveIOException { + final String METHOD = "getArchiveEntries"; + + LOGGER.entering(CLASS, METHOD); + String pathPrefix = getPathForType(type, name); + List entries = getZipFile().listZipEntries(pathPrefix); + + LOGGER.exiting(CLASS, METHOD, entries); + return entries; + } + /** * Determines whether the archive contains the specified file or directory. * @@ -614,10 +740,11 @@ public String extractDatabaseWallet(File domainHome, String walletName) throws W extractPath = extractRCUWallet(domainHome); } else { validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); - List zipEntries = getZipFile().listZipEntries(ARCHIVE_DB_WALLETS_DIR + walletName + ZIP_SEP); - zipEntries.remove(ARCHIVE_DB_WALLETS_DIR + walletName + ZIP_SEP); + List zipEntries = + getZipFile().listZipEntries(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName + ZIP_SEP); + zipEntries.remove(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName + ZIP_SEP); if (!zipEntries.isEmpty()) { - extractPath = ARCHIVE_DB_WALLETS_DIR + walletName + ZIP_SEP; + extractPath = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName + ZIP_SEP; extractWallet(domainHome, extractPath, zipEntries, null, null, null); extractPath = new File(domainHome, extractPath).getAbsolutePath(); } diff --git a/core/src/main/python/wlsdeploy/util/exit_code.py b/core/src/main/python/wlsdeploy/util/exit_code.py index 579e4ec196..0fdb910501 100644 --- a/core/src/main/python/wlsdeploy/util/exit_code.py +++ b/core/src/main/python/wlsdeploy/util/exit_code.py @@ -5,19 +5,20 @@ Standard exit codes for command-line utilities. """ +from oracle.weblogic.deploy.util import ExitCode as JExitCode class ExitCode(object): """ Standard exit codes for command-line utilities. """ - OK = 0 - WARNING = 1 - ERROR = 2 + OK = JExitCode.OK + WARNING = JExitCode.WARNING + ERROR = JExitCode.ERROR - ARG_VALIDATION_ERROR = 98 - USAGE_ERROR = 99 + ARG_VALIDATION_ERROR = JExitCode.ARG_VALIDATION_ERROR + USAGE_ERROR = JExitCode.USAGE_ERROR - HELP = 100 - RESTART_REQUIRED = 103 - CANCEL_CHANGES_IF_RESTART = 104 + HELP = JExitCode.HELP + RESTART_REQUIRED = JExitCode.RESTART_REQUIRED + CANCEL_CHANGES_IF_RESTART = JExitCode.CANCEL_CHANGES_IF_RESTART diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index d868d72f99..86081aba44 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -1726,4 +1726,12 @@ WLSDPLY-21003=Issue Log for {0} version {1} running WebLogic version {2} {3} mod # RCUDbinfo -WLSDPLY-22000={0} has been deprecated and will be removed in a future release, please use {1} instead \ No newline at end of file +WLSDPLY-22000={0} has been deprecated and will be removed in a future release, please use {1} instead + +#################################################################### +# Message number 30000 - 30999 Archive Helper # +#################################################################### +WLSDPLY-30000=The -archive_file argument must have a non-empty file name +WLSDPLY-30001=The -archive_file argument's parent directory {0} does not exist and could not be created +WLSDPLY-30002=The -archive_file {0} is not a file +WLSDPLY-30003=Failed to list all entries for archive file {0}: {1} diff --git a/installer/pom.xml b/installer/pom.xml index 22af7c776a..6d7b0ee76f 100644 --- a/installer/pom.xml +++ b/installer/pom.xml @@ -30,6 +30,10 @@ org.yaml snakeyaml + + info.picocli + picocli + diff --git a/installer/src/assembly/zip.xml b/installer/src/assembly/zip.xml index 357bb7f32b..1fecd51ed1 100644 --- a/installer/src/assembly/zip.xml +++ b/installer/src/assembly/zip.xml @@ -112,6 +112,7 @@ org.antlr:antlr4-runtime org.yaml:snakeyaml + info.picocli:picocli diff --git a/pom.xml b/pom.xml index c1f5db9cf7..a43d5f9a9b 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ false 4.9.3 1.33 + 4.7.0 oracle https://sonarcloud.io @@ -107,6 +108,11 @@ commons-io 2.11.0 + + info.picocli + picocli + ${picocli.version} + From 59ea1ba15259c8abffad8552ed079831691301c0 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Fri, 13 Jan 2023 19:24:40 -0600 Subject: [PATCH 02/13] intermediate checkpoint --- .../weblogic/deploy/tool/ArchiveHelper.java | 23 +- .../tool/archive_helper/CommonOptions.java | 52 ++- .../archive_helper/HelpVersionProvider.java | 17 - .../add/AddApplicationCommand.java | 78 ++++ .../tool/archive_helper/add/AddCommand.java | 28 ++ .../tool/archive_helper/add/AddOptions.java | 22 ++ .../add/AddSharedLibraryCommand.java | 77 ++++ .../add/AddStructuredApplicationCommand.java | 77 ++++ .../add/AddTypeCommandBase.java | 53 +++ .../archive_helper/list/ListAllCommand.java | 24 +- .../list/ListApplicationCommand.java | 50 +++ .../list/ListApplicationsCommand.java | 35 -- .../list/ListClasspathLibraryCommand.java | 49 +++ .../list/ListCoherenceCommand.java | 48 +++ .../tool/archive_helper/list/ListCommand.java | 32 +- .../list/ListCustomCommand.java | 49 +++ .../list/ListDatabaseWalletCommand.java | 49 +++ .../list/ListDomainBinScriptCommand.java | 49 +++ .../list/ListDomainLibraryCommand.java | 49 +++ .../list/ListFileStoreCommand.java | 49 +++ .../list/ListForeignServerCommand.java | 49 +++ .../list/ListMIMEMappingCommand.java | 49 +++ .../list/ListNodeManagerKeystoreCommand.java | 49 +++ .../list/ListOPSSWalletCommand.java | 42 ++ .../tool/archive_helper/list/ListOptions.java | 23 -- .../list/ListRCUWalletCommand.java | 43 ++ .../list/ListScriptCommand.java | 49 +++ .../list/ListServerKeystoreCommand.java | 49 +++ .../list/ListSharedLibraryCommand.java | 50 +++ .../ListStructuredApplicationCommand.java | 49 +++ .../archive_helper/list/ListTypeCommand.java | 48 --- .../list/ListTypeCommandBase.java | 57 +++ .../deploy/util/WLSDeployArchive.java | 368 +++++++++++++----- .../deploy/messages/wlsdeploy_rb.properties | 12 +- 34 files changed, 1572 insertions(+), 275 deletions(-) delete mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/HelpVersionProvider.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOptions.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java delete mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationsCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListForeignServerCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java delete mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOptions.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java delete mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommandBase.java diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java index f0f2f696ac..63b33e6ead 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java @@ -10,33 +10,38 @@ import oracle.weblogic.deploy.logging.WLSDeployLogFactory; import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; -import oracle.weblogic.deploy.tool.archive_helper.HelpVersionProvider; +import oracle.weblogic.deploy.tool.archive_helper.add.AddCommand; import oracle.weblogic.deploy.tool.archive_helper.list.ListCommand; import oracle.weblogic.deploy.util.ExitCode; import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.IParameterExceptionHandler; +import picocli.CommandLine.Option; import picocli.CommandLine.ParameterException; import picocli.CommandLine.ParseResult; import picocli.CommandLine.UnmatchedArgumentException; @Command( name = "archiveHelper", - mixinStandardHelpOptions = true, description = "%nA tool to create and modify a WebLogic Deploy Tooling archive file.%n", - versionProvider = HelpVersionProvider.class, - sortOptions = false, + commandListHeading = "%nCommands:%n", subcommands = { + AddCommand.class, ListCommand.class }, - requiredOptionMarker = '*', - usageHelpWidth = 80, - commandListHeading = "%nCommands:%n%nChoose from:%n" + sortOptions = false ) public class ArchiveHelper { + public static final String LOGGER_NAME = "wlsdeploy.tool.archive-helper"; private static final String CLASS = ArchiveHelper.class.getName(); - private static final PlatformLogger LOGGER = - WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper tool", + usageHelp = true + ) + private static boolean helpRequested = false; @SuppressWarnings("java:S106") public static void main(String[] args) { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java index 75fa92a10b..62903f6b20 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java @@ -13,26 +13,29 @@ import oracle.weblogic.deploy.util.FileUtils; import oracle.weblogic.deploy.util.StringUtils; import oracle.weblogic.deploy.util.WLSDeployArchive; -import picocli.CommandLine; + import picocli.CommandLine.Option; import picocli.CommandLine.Spec; import picocli.CommandLine.Unmatched; +import picocli.CommandLine.Model.CommandSpec; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; public abstract class CommonOptions { private static final String CLASS = CommonOptions.class.getName(); - private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); @Unmatched - List unmatchedOptions; + protected List unmatchedOptions; @Spec - CommandLine.Model.CommandSpec spec; + protected CommandSpec spec; @Option( names = { "-archive_file" }, paramLabel = "", - required = true, - description = "Path to the archive file to use." + description = "Path to the archive file to use.", + required = true ) protected String archiveFilePath; @@ -42,11 +45,11 @@ protected String getArchiveFilePath() { return archiveFilePath; } - protected void initializeOptions() throws ArchiveHelperException { - this.archive = createArchive(); + protected void initializeOptions(boolean archiveFileMustAlreadyExist) throws ArchiveHelperException { + this.archive = createArchive(archiveFileMustAlreadyExist); } - private WLSDeployArchive createArchive() throws ArchiveHelperException { + private WLSDeployArchive createArchive(boolean fileMustExist) throws ArchiveHelperException { final String METHOD = "createArchive"; LOGGER.entering(CLASS, METHOD); @@ -58,21 +61,32 @@ private WLSDeployArchive createArchive() throws ArchiveHelperException { } File fullArchiveFile = new File(fullArchiveFileName); - if (!fullArchiveFile.exists()) { - File fullArchiveParentDir = fullArchiveFile.getParentFile(); - if (!fullArchiveParentDir.exists() && !fullArchiveParentDir.mkdirs()) { - ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30001", - fullArchiveParentDir.getAbsolutePath()); - LOGGER.throwing(CLASS, METHOD, ex); - throw ex; - } - } else if (!fullArchiveFile.isFile()) { - ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30002", + if (!fullArchiveFile.isFile()) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30001", fullArchiveFile.getAbsolutePath()); LOGGER.throwing(CLASS, METHOD, ex); throw ex; } + if (fileMustExist) { + if (!fullArchiveFile.exists()) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30002", + fullArchiveFile.getAbsolutePath()); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + } else { + if (!fullArchiveFile.exists()) { + File fullArchiveParentDir = fullArchiveFile.getParentFile(); + if (!fullArchiveParentDir.exists() && !fullArchiveParentDir.mkdirs()) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, + "WLSDPLY-30003", fullArchiveParentDir.getAbsolutePath()); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + } + } + return new WLSDeployArchive(fullArchiveFileName); } } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/HelpVersionProvider.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/HelpVersionProvider.java deleted file mode 100644 index 4c1600c475..0000000000 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/HelpVersionProvider.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2023, Oracle and/or its affiliates. - * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. - */ -package oracle.weblogic.deploy.tool.archive_helper; - -import oracle.weblogic.deploy.util.WebLogicDeployToolingVersion; - -import picocli.CommandLine.IVersionProvider; - -public class HelpVersionProvider implements IVersionProvider { - - @Override - public String[] getVersion() { - return new String[] { WebLogicDeployToolingVersion.getFullVersion() }; - } -} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java new file mode 100644 index 0000000000..fdebbdc241 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; + +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "application", + description = "Add application to the archive file", + sortOptions = false +) +public class AddApplicationCommand extends AddTypeCommandBase { + private static final String CLASS = AddApplicationCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "application"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the application to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add application subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceApplication(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addApplication(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30008", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30008", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30009", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30009", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java new file mode 100644 index 0000000000..2d7c0f9e50 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +@Command( + name = "add", + description = "add items to the archive file", + commandListHeading = "%nSubcommands:%n%n", + subcommands = { + AddApplicationCommand.class, + AddSharedLibraryCommand.class, + AddStructuredApplicationCommand.class, + }, + sortOptions = false +) +public class AddCommand { + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list command", + usageHelp = true + ) + private boolean helpRequested = false; +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOptions.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOptions.java new file mode 100644 index 0000000000..a63c0ec1d2 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOptions.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommonOptions; + +import picocli.CommandLine.Option; + +public abstract class AddOptions extends CommonOptions { + @Option( + names = {"-overwrite"}, + description = "overwrite the existing entry in the archive file, if any" + ) + protected boolean overwrite; + + protected void initializeOptions() throws ArchiveHelperException { + super.initializeOptions(false); + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java new file mode 100644 index 0000000000..8de9670c05 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "sharedLibrary", + description = "Add shared library to the archive file", + sortOptions = false +) +public class AddSharedLibraryCommand extends AddTypeCommandBase { + private static final String CLASS = AddSharedLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "shared library"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the shared library to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add sharedLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceSharedLibrary(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addSharedLibrary(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30008", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30008", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30009", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30009", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java new file mode 100644 index 0000000000..847f784013 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "structuredApplication", + description = "Add structured application installation directory to the archive file", + sortOptions = false +) +public class AddStructuredApplicationCommand extends AddTypeCommandBase { + private static final String CLASS = AddStructuredApplicationCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "structured application"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the structured application installation directory to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add structuredApplication subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceStructuredApplication(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addStructuredApplication(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30008", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30008", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30009", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30009", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java new file mode 100644 index 0000000000..cdc23549f9 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; +import java.util.concurrent.Callable; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.FileUtils; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +public abstract class AddTypeCommandBase extends AddOptions implements Callable { + private static final String CLASS = AddTypeCommandBase.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + protected void initializeOptions() throws ArchiveHelperException { + super.initializeOptions(); + } + + protected File initializeOptions(String sourcePath) throws ArchiveHelperException { + final String METHOD = "initializeOptions"; + LOGGER.entering(CLASS, METHOD, sourcePath); + + initializeOptions(); + File result = getSourceLocationFile(sourcePath); + + LOGGER.exiting(CLASS, METHOD, result.getAbsolutePath()); + return result; + } + + private File getSourceLocationFile(String path) throws ArchiveHelperException { + final String METHOD = "getSourceLocationFile"; + LOGGER.entering(CLASS, METHOD, path); + + File result = FileUtils.getCanonicalFile(path); + if (!result.exists()) { + ArchiveHelperException ex = + new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30007", path); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + LOGGER.exiting(CLASS, METHOD, result.getAbsolutePath()); + return result; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java index 4f9c4e1a90..265211eac2 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java @@ -11,24 +11,30 @@ import oracle.weblogic.deploy.logging.WLSDeployLogFactory; import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; - import oracle.weblogic.deploy.tool.archive_helper.CommonOptions; -import oracle.weblogic.deploy.tool.archive_helper.HelpVersionProvider; import oracle.weblogic.deploy.util.ExitCode; import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; + import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; @Command( name = "all", description = "List all entries in the archive file", - mixinStandardHelpOptions = true, - versionProvider = HelpVersionProvider.class, sortOptions = false ) public class ListAllCommand extends CommonOptions implements Callable { private static final String CLASS = ListAllCommand.class.getName(); - private static final PlatformLogger LOGGER = - WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list all subcommand", + usageHelp = true + ) + private boolean helpRequested = false; @Override public CommandResponse call() throws Exception { @@ -37,7 +43,7 @@ public CommandResponse call() throws Exception { CommandResponse response; try { - super.initializeOptions(); + super.initializeOptions(true); List archiveEntries = this.archive.getArchiveEntries(); response = new CommandResponse(ExitCode.OK); @@ -46,8 +52,8 @@ public CommandResponse call() throws Exception { LOGGER.severe(ex.getLocalizedMessage(), ex); response = new CommandResponse(ex.getExitCode(), ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException ex) { - LOGGER.severe("WLSDPLY-30003", ex, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30003", this.archiveFilePath, + LOGGER.severe("WLSDPLY-30004", ex, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30004", this.archiveFilePath, ex.getLocalizedMessage()); } return response; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java new file mode 100644 index 0000000000..05528f393f --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; + +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.APPLICATION; + +@Command( + name = "application", + description = "List application entries in the archive file", + sortOptions = false +) +public class ListApplicationCommand extends ListTypeCommandBase { + private static final String CLASS = ListApplicationCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the application to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list application subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(APPLICATION, "application", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationsCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationsCommand.java deleted file mode 100644 index 8b120d924f..0000000000 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationsCommand.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2023, Oracle and/or its affiliates. - * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. - */ -package oracle.weblogic.deploy.tool.archive_helper.list; - -import oracle.weblogic.deploy.logging.PlatformLogger; -import oracle.weblogic.deploy.logging.WLSDeployLogFactory; -import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; -import oracle.weblogic.deploy.tool.archive_helper.HelpVersionProvider; -import picocli.CommandLine.Command; - -@Command( - name = "applications", - description = "List application entries in the archive file", - mixinStandardHelpOptions = true, - versionProvider = HelpVersionProvider.class, - sortOptions = false -) -public class ListApplicationsCommand extends ListTypeCommand { - private static final String CLASS = ListApplicationsCommand.class.getName(); - private static final PlatformLogger LOGGER = - WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); - - @Override - public CommandResponse call() throws Exception { - final String METHOD = "call"; - LOGGER.entering(CLASS, METHOD); - - CommandResponse response = listApplications(); - - LOGGER.exiting(CLASS, METHOD, response); - return response; - } -} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java new file mode 100644 index 0000000000..096f71e902 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.CLASSPATH_LIB; + +@Command( + name = "classpathLibrary", + description = "List classpath library entries in the archive file", + sortOptions = false +) +public class ListClasspathLibraryCommand extends ListTypeCommandBase { + private static final String CLASS = ListClasspathLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the classpath library to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list classpathLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(CLASSPATH_LIB, "classpath library", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java new file mode 100644 index 0000000000..a114c8ecb7 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.COHERENCE; +@Command( + name = "coherence", + description = "List Coherence entries in the archive file", + sortOptions = false +) +public class ListCoherenceCommand extends ListTypeCommandBase { + private static final String CLASS = ListCoherenceCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the Coherence cluster to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list coherence subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(COHERENCE, "Coherence cluster", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java index 685ede4138..a7e49b3a11 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java @@ -4,20 +4,40 @@ */ package oracle.weblogic.deploy.tool.archive_helper.list; -import oracle.weblogic.deploy.tool.archive_helper.HelpVersionProvider; - import picocli.CommandLine.Command; +import picocli.CommandLine.Option; @Command( name = "list", - description = "List contents of archive file", - versionProvider = HelpVersionProvider.class, - commandListHeading = "%nCommands:%n%n", + description = "List contents of the archive file", + commandListHeading = "%nSubcommands:%n%n", subcommands = { ListAllCommand.class, - ListApplicationsCommand.class + ListApplicationCommand.class, + ListClasspathLibraryCommand.class, + ListCoherenceCommand.class, + ListCustomCommand.class, + ListDatabaseWalletCommand.class, + ListDomainBinScriptCommand.class, + ListDomainLibraryCommand.class, + ListFileStoreCommand.class, + ListForeignServerCommand.class, + ListMIMEMappingCommand.class, + ListNodeManagerKeystoreCommand.class, + ListOPSSWalletCommand.class, + ListRCUWalletCommand.class, + ListScriptCommand.class, + ListServerKeystoreCommand.class, + ListSharedLibraryCommand.class, + ListStructuredApplicationCommand.class }, sortOptions = false ) public class ListCommand { + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list command", + usageHelp = true + ) + private boolean helpRequested = false; } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java new file mode 100644 index 0000000000..b179fe1621 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.CUSTOM; + +@Command( + name = "custom", + description = "List custom directory entries in the archive file", + sortOptions = false +) +public class ListCustomCommand extends ListTypeCommandBase { + private static final String CLASS = ListCustomCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the custom directory entry to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list custom subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(CUSTOM, "custom directory", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java new file mode 100644 index 0000000000..d3afe1db74 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.DB_WALLET; + +@Command( + name = "databaseWallet", + description = "List database wallet entries in the archive file", + sortOptions = false +) +public class ListDatabaseWalletCommand extends ListTypeCommandBase { + private static final String CLASS = ListDatabaseWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the database wallet to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list databaseWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(DB_WALLET, "database wallet", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java new file mode 100644 index 0000000000..88d7561132 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.DOMAIN_BIN; + +@Command( + name = "domainBinScript", + description = "List domain bin script entries in the archive file", + sortOptions = false +) +public class ListDomainBinScriptCommand extends ListTypeCommandBase { + private static final String CLASS = ListDomainBinScriptCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the domain bin script to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list domainBin subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(DOMAIN_BIN, "domain bin script", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java new file mode 100644 index 0000000000..0ff90c6e9e --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.DOMAIN_LIB; + +@Command( + name = "domainLibrary", + description = "List domain library entries in the archive file", + sortOptions = false +) +public class ListDomainLibraryCommand extends ListTypeCommandBase { + private static final String CLASS = ListDomainLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the domain library to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list domainLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(DOMAIN_LIB, "domain library", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java new file mode 100644 index 0000000000..620f6cdeff --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.FILE_STORE; + +@Command( + name = "fileStore", + description = "List file store entries in the archive file", + sortOptions = false +) +public class ListFileStoreCommand extends ListTypeCommandBase { + private static final String CLASS = ListFileStoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the file store to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list fileStore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(FILE_STORE, "file store", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListForeignServerCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListForeignServerCommand.java new file mode 100644 index 0000000000..27019a6e10 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListForeignServerCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.JMS_FOREIGN_SERVER; + +@Command( + name = "foreignServer", + description = "List JMS foreign server binding entries in the archive file", + sortOptions = false +) +public class ListForeignServerCommand extends ListTypeCommandBase { + private static final String CLASS = ListForeignServerCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the JMS foreign server binding to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list foreignServer subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(JMS_FOREIGN_SERVER, "JMS foreign server binding", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java new file mode 100644 index 0000000000..3f955d04fb --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.MIME_MAPPING; + +@Command( + name = "mimeMapping", + description = "List MIME mapping entries in the archive file", + sortOptions = false +) +public class ListMIMEMappingCommand extends ListTypeCommandBase { + private static final String CLASS = ListMIMEMappingCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the MIME mapping file to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list mimeMapping subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(MIME_MAPPING, "MIME mapping", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java new file mode 100644 index 0000000000..6d8ec00b78 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.NODE_MANAGER_KEY_STORE; + +@Command( + name = "nodeManagerKeystore", + description = "List node manager keystore entries in the archive file", + sortOptions = false +) +public class ListNodeManagerKeystoreCommand extends ListTypeCommandBase { + private static final String CLASS = ListNodeManagerKeystoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the node manager keystore file to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list nodeManagerKeystore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(NODE_MANAGER_KEY_STORE, "node manager keystore", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java new file mode 100644 index 0000000000..202e3d0ba7 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.OPSS_WALLET; + +@Command( + name = "opssWallet", + description = "List OPSS wallet entries in the archive file", + sortOptions = false +) +public class ListOPSSWalletCommand extends ListTypeCommandBase { + private static final String CLASS = ListOPSSWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list opssWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(OPSS_WALLET, "OPSS wallet", null); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOptions.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOptions.java deleted file mode 100644 index 58bada15c8..0000000000 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOptions.java +++ /dev/null @@ -1,23 +0,0 @@ -package oracle.weblogic.deploy.tool.archive_helper.list; - -import oracle.weblogic.deploy.logging.PlatformLogger; -import oracle.weblogic.deploy.logging.WLSDeployLogFactory; -import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; -import oracle.weblogic.deploy.tool.archive_helper.CommonOptions; -import picocli.CommandLine.Option; - -public class ListOptions extends CommonOptions { - private static final String CLASS = ListOptions.class.getName(); - private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); - - @Option( - names = { "-name" }, - paramLabel = "", - description = "Name of the object of the specified type to list." - ) - String name; - - protected void initializeOptions() throws ArchiveHelperException { - super.initializeOptions(); - } -} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java new file mode 100644 index 0000000000..9a0aae3771 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.DB_WALLET; + +@Command( + name = "rcuWallet", + description = "List RCU database wallet entries in the archive file", + sortOptions = false +) +public class ListRCUWalletCommand extends ListTypeCommandBase { + private static final String CLASS = ListRCUWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list rcuWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(DB_WALLET, "database wallet", DEFAULT_RCU_WALLET_NAME); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java new file mode 100644 index 0000000000..31b27d622c --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.SCRIPT; + +@Command( + name = "script", + description = "List script entries in the archive file", + sortOptions = false +) +public class ListScriptCommand extends ListTypeCommandBase { + private static final String CLASS = ListScriptCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the script to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list script subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(SCRIPT, "script", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java new file mode 100644 index 0000000000..59d090fc8f --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.SERVER_KEYSTORE; + +@Command( + name = "serverKeystore", + description = "List server keystore entries in the archive file", + sortOptions = false +) +public class ListServerKeystoreCommand extends ListTypeCommandBase { + private static final String CLASS = ListServerKeystoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the server for which to list the keystore" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list serverKeystore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(SERVER_KEYSTORE, "server keystore", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java new file mode 100644 index 0000000000..8969224b40 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; + +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.SHARED_LIBRARY; + +@Command( + name = "sharedLibrary", + description = "List shared library entries in the archive file", + sortOptions = false +) +public class ListSharedLibraryCommand extends ListTypeCommandBase { + private static final String CLASS = ListSharedLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the shared library to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list sharedLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(SHARED_LIBRARY, "shared library", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java new file mode 100644 index 0000000000..dbe7a8f980 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.STRUCTURED_APPLICATION; + +@Command( + name = "structuredApplication", + description = "List structured application entries in the archive file", + sortOptions = false +) +public class ListStructuredApplicationCommand extends ListTypeCommandBase { + private static final String CLASS = ListStructuredApplicationCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "Name of the structured application to list" + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper list structuredApplication subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response = listType(STRUCTURED_APPLICATION, "structured application", name); + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommand.java deleted file mode 100644 index 2f31cb3723..0000000000 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -package oracle.weblogic.deploy.tool.archive_helper.list; - -import java.util.List; -import java.util.concurrent.Callable; - -import oracle.weblogic.deploy.logging.PlatformLogger; -import oracle.weblogic.deploy.logging.WLSDeployLogFactory; -import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; -import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; -import oracle.weblogic.deploy.util.ExitCode; -import oracle.weblogic.deploy.util.StringUtils; -import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; - -import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.APPLICATION; - -public abstract class ListTypeCommand extends ListOptions implements Callable { - private static final String CLASS = ListTypeCommand.class.getName(); - private static final PlatformLogger LOGGER = - WLSDeployLogFactory.getLogger("wlsdeploy.tool.archive-helper"); - - public CommandResponse listApplications() { - final String METHOD = "listApplications"; - LOGGER.entering(CLASS, METHOD); - - CommandResponse response; - try { - initializeOptions(); - - List archiveEntries; - if (StringUtils.isEmpty(this.name)) { - archiveEntries = this.archive.getArchiveEntries(APPLICATION); - } else { - archiveEntries = this.archive.getArchiveEntries(APPLICATION, this.name); - } - response = new CommandResponse(ExitCode.OK); - response.addMessages(archiveEntries); - } catch (ArchiveHelperException ex) { - LOGGER.severe(ex.getLocalizedMessage(), ex); - response = new CommandResponse(ex.getExitCode(), ex.getLocalizedMessage()); - } catch (WLSDeployArchiveIOException ex) { - LOGGER.severe("WLSDPLY-30003", ex, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30003", ex.getLocalizedMessage()); - } - - LOGGER.exiting(CLASS, METHOD, response); - return response; - } -} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommandBase.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommandBase.java new file mode 100644 index 0000000000..a3dcea5e72 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommandBase.java @@ -0,0 +1,57 @@ +package oracle.weblogic.deploy.tool.archive_helper.list; + +import java.util.List; +import java.util.concurrent.Callable; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.tool.archive_helper.CommonOptions; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.StringUtils; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +public abstract class ListTypeCommandBase extends CommonOptions implements Callable { + private static final String CLASS = ListTypeCommandBase.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + protected CommandResponse listType(ArchiveEntryType type, String typeName, String name) { + final String METHOD = "listType"; + LOGGER.entering(CLASS, METHOD, type, typeName, name); + + boolean hasName = !StringUtils.isEmpty(name); + CommandResponse response; + try { + initializeOptions(true); + + List archiveEntries; + if (hasName) { + archiveEntries = this.archive.getArchiveEntries(type, name); + } else { + archiveEntries = this.archive.getArchiveEntries(type); + } + response = new CommandResponse(ExitCode.OK); + response.addMessages(archiveEntries); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ex.getLocalizedMessage(), ex); + response = new CommandResponse(ex.getExitCode(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException ex) { + if (hasName) { + LOGGER.severe("WLSDPLY-30005", ex, typeName, name, archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30005", type, name, + this.archiveFilePath, ex.getLocalizedMessage()); + } else { + LOGGER.severe("WLSDPLY-30006", ex, typeName, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30006", type, this.archiveFilePath, + ex.getLocalizedMessage()); + } + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java index 6a2d95b90c..c5f8bb4c7f 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java @@ -13,7 +13,6 @@ import java.net.URL; import java.nio.file.Files; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.jar.JarFile; @@ -164,6 +163,7 @@ public class WLSDeployArchive { public static final String ARCHIVE_JMS_FOREIGN_SERVER_DIR = ARCHIVE_JMS_DIR + "/foreignServer"; public enum ArchiveEntryType { + STRUCTURED_APPLICATION, SHARED_LIBRARY, APPLICATION, APPLICATION_PLAN, @@ -181,7 +181,8 @@ public enum ArchiveEntryType { FILE_STORE, NODE_MANAGER_KEY_STORE, DB_WALLET, - OPSS_WALLET + OPSS_WALLET, + CUSTOM } private static final String SEP = File.separator; @@ -212,6 +213,10 @@ public WLSDeployArchive(String archiveFileName) { LOGGER.exiting(CLASS, METHOD); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // public static utility methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** * Determine if the specified path string is a valid archive location. * @@ -257,6 +262,10 @@ public static String getPathForType(ArchiveEntryType type) { pathPrefix = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP; break; + case STRUCTURED_APPLICATION: + pathPrefix = ARCHIVE_STRUCT_APPS_TARGET_DIR + ZIP_SEP; + break; + case DOMAIN_LIB: pathPrefix = ARCHIVE_DOMLIB_TARGET_DIR + ZIP_SEP; break; @@ -305,6 +314,10 @@ public static String getPathForType(ArchiveEntryType type) { pathPrefix = ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP; break; + case CUSTOM: + pathPrefix = ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP; + break; + // FIXME - need to log if receiving an unknown type } @@ -504,6 +517,10 @@ public static String getNodeManagerKeyStoreArchivePath(String keystoreFile) { return getArchiveName(ARCHIVE_NODE_MANAGER_TARGET_DIR, keystoreFile); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // public utility methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** * Get the current file name for the JCSLifecycleArchive file. * @@ -773,6 +790,10 @@ public String getFileHash(String path) throws WLSDeployArchiveIOException { return result; } + /////////////////////////////////////////////////////////////////////////////////////////////// + // application methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** * This method adds an application to the archive. If an application with the same name already exists, this * method assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding @@ -790,7 +811,6 @@ public String addApplication(String appPath) throws WLSDeployArchiveIOException LOGGER.entering(CLASS, METHOD, appPath); File filePath = new File(appPath); - validateExistingFile(filePath, "appPath", getArchiveFileName(), METHOD, true); String newName = addItemToZip(ARCHIVE_APPS_TARGET_DIR, filePath); @@ -801,44 +821,28 @@ public String addApplication(String appPath) throws WLSDeployArchiveIOException /** * Replace an existing application in the archive file. * - * @param appPath the path within the archive of the app to remove - * @param tempFile the file system location of the new app to replace the existing one + * @param appPath the app name or the path within the archive of the app to replace + * @param sourceLocation the file system location of the new app to replace the existing one * @return the archive path of the new application * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist */ - public String replaceApplication(String appPath, String tempFile) throws WLSDeployArchiveIOException { + public String replaceApplication(String appPath, String sourceLocation) throws WLSDeployArchiveIOException { final String METHOD = "replaceApplication"; - LOGGER.entering(CLASS, METHOD, appPath); - getZipFile().removeZipEntry(appPath); - String newName = addApplication(tempFile); - LOGGER.exiting(CLASS, METHOD, newName); - return newName; - } + LOGGER.entering(CLASS, METHOD, appPath, sourceLocation); - public String addApplicationFolder(String appName, String appPath) - throws WLSDeployArchiveIOException { - final String METHOD = "addApplicationFolder"; - LOGGER.entering(CLASS, METHOD, appName, appPath); - File zipPath = new File(appPath); - if (zipPath.getParentFile() != null) { - zipPath = zipPath.getParentFile(); + String archivePath; + if (appPath.startsWith(ARCHIVE_APPS_TARGET_DIR + ZIP_SEP)) { + archivePath = appPath; + } else { + archivePath = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP + appPath; } - String firstPrefix = ARCHIVE_STRUCT_APPS_TARGET_DIR + "/" + appName + "/" + zipPath.getName(); - String newName = walkDownFolders(firstPrefix, zipPath); - LOGGER.exiting(CLASS, METHOD, newName); - return newName; - } - public String addApplicationPlanFolder(String appName, String planDir) - throws WLSDeployArchiveIOException { - final String METHOD = "addApplicationPathFolder"; - LOGGER.entering(CLASS, METHOD, appName, planDir); - File zipPlan = new File(planDir); - String zipPrefix = ARCHIVE_STRUCT_APPS_TARGET_DIR + "/" + appName + "/" + zipPlan.getName(); - String newName = walkDownFolders(zipPrefix, zipPlan); + getZipFile().removeZipEntries(archivePath); + String newName = addApplication(sourceLocation); LOGGER.exiting(CLASS, METHOD, newName); - return zipPrefix; + return newName; } /** @@ -858,75 +862,6 @@ public List listApplications() throws WLSDeployArchiveIOException { return result; } - /** - * Extract the named database wallet. - * - * @param domainHome the domain home directory - * @param walletName the name of the database wallet to extract (e.g., rcu) - * @return the full path to the directory containing the extracted wallet files or null, if no wallet was found. - * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files. - */ - public String extractDatabaseWallet(File domainHome, String walletName) throws WLSDeployArchiveIOException { - final String METHOD = "extractDatabaseWallet"; - - LOGGER.entering(CLASS, METHOD, domainHome, walletName); - - String extractPath = null; - if (DEFAULT_RCU_WALLET_NAME.equals(walletName)) { - // handle archive files with deprecated path, as needed - extractPath = extractRCUWallet(domainHome); - } else { - validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); - List zipEntries = - getZipFile().listZipEntries(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName + ZIP_SEP); - zipEntries.remove(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName + ZIP_SEP); - if (!zipEntries.isEmpty()) { - extractPath = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName + ZIP_SEP; - extractWallet(domainHome, extractPath, zipEntries, null, null, null); - extractPath = new File(domainHome, extractPath).getAbsolutePath(); - } - } - - LOGGER.exiting(CLASS, METHOD, extractPath); - return extractPath; - } - - /** - * Extract the OPSS wallet from the archive. - * - * @param domainHome the domain home directory - * @return the full path to the directory containing the extracted wallet files or null, if no wallet was found. - * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files. - */ - public String extractOPSSWallet(File domainHome) throws WLSDeployArchiveIOException { - final String METHOD = "extractOPSSWallet"; - - LOGGER.entering(CLASS, METHOD, domainHome); - validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); - - // Look in the updated location first - String extractPath = null; - List zipEntries = getZipFile().listZipEntries(ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP); - zipEntries.remove(ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP); - if (!zipEntries.isEmpty()) { - extractPath = ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP; - extractWallet(domainHome, extractPath, zipEntries, null, null, null); - extractPath = new File(domainHome, extractPath).getAbsolutePath(); - } else { - // Look in the deprecated location. - zipEntries = getZipFile().listZipEntries(OLD_ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP); - zipEntries.remove(OLD_ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP); - if (!zipEntries.isEmpty()) { - extractPath = OLD_ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP; - extractWallet(domainHome, extractPath, zipEntries, "WLSDPLY-01433",null, null); - extractPath = new File(domainHome, extractPath).getAbsolutePath(); - } - } - - LOGGER.exiting(CLASS, METHOD, extractPath); - return extractPath; - } - /** * Extract the specified application from the archive to the domain home directory. * @@ -949,13 +884,107 @@ public void extractApplication(String applicationPath, File domainHome) throws W appPath = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP + applicationPath; } extractFileFromZip(appPath, domainHome); + LOGGER.exiting(CLASS, METHOD); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // structured application methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Add a structured application installation directory to the archive file. + * + * @param installRoot the path to the installation directory + * @return the archive path of the new structured application installation directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the directory passed or its app subdirectory does not exist + */ + public String addStructuredApplication(String installRoot) throws WLSDeployArchiveIOException { + final String METHOD = "addApplicationFolder"; + LOGGER.entering(CLASS, METHOD, installRoot); + + File filePath = FileUtils.getCanonicalFile(installRoot); + File appDir = new File(filePath, "app"); + validateExistingDirectory(filePath, "installRoot", getArchiveFileName(), METHOD); + validateExistingDirectory(appDir, "appDir", getArchiveFileName(), METHOD); + + String newName = addItemToZip(ARCHIVE_STRUCT_APPS_TARGET_DIR, filePath); + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Replace an existing structured application installation directory in the archive file. + * + * @param appPath the app name or the path within the archive of the structured application + * installation directory to replace + * @param sourceInstallRoot the file system location of the new structured application installation directory + * to replace the existing one + * @return the archive path of the new structured application installation directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the directory passed or its app subdirectory does not exist + */ + public String replaceStructuredApplication(String appPath, String sourceInstallRoot) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceStructuredApplication"; + LOGGER.entering(CLASS, METHOD, appPath, sourceInstallRoot); + + String archivePath; + if (appPath.startsWith(ARCHIVE_STRUCT_APPS_TARGET_DIR + ZIP_SEP)) { + archivePath = appPath; + } else { + archivePath = ARCHIVE_STRUCT_APPS_TARGET_DIR + ZIP_SEP + appPath; + } + if (!archivePath.endsWith(ZIP_SEP)) { + archivePath += ZIP_SEP; + } + + getZipFile().removeZipEntries(archivePath); + String newName = addStructuredApplication(sourceInstallRoot); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + // TODO - Need to verify that discovery produces an archive that is consistent with the add/replace methods above. + // Once verified, change method name to be consistent and add javadoc. + public String addApplicationFolder(String appName, String appPath) + throws WLSDeployArchiveIOException { + final String METHOD = "addApplicationFolder"; + LOGGER.entering(CLASS, METHOD, appName, appPath); + File zipPath = new File(appPath); + if (zipPath.getParentFile() != null) { + zipPath = zipPath.getParentFile(); + } + String firstPrefix = ARCHIVE_STRUCT_APPS_TARGET_DIR + ZIP_SEP + appName + ZIP_SEP + zipPath.getName(); + String newName = walkDownFolders(firstPrefix, zipPath); + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + // TODO - Need to verify that discovery produces an archive that is consistent with the add/replace methods above. + // Once verified, change method name to be consistent and add javadoc. + public String addApplicationPlanFolder(String appName, String planDir) + throws WLSDeployArchiveIOException { + final String METHOD = "addApplicationPathFolder"; + LOGGER.entering(CLASS, METHOD, appName, planDir); + File zipPlan = new File(planDir); + String zipPrefix = ARCHIVE_STRUCT_APPS_TARGET_DIR + ZIP_SEP + appName + ZIP_SEP + zipPlan.getName(); + String newName = walkDownFolders(zipPrefix, zipPlan); + + LOGGER.exiting(CLASS, METHOD, newName); + return zipPrefix; } + /////////////////////////////////////////////////////////////////////////////////////////////// + // shared library methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** * Get the best guess of the name of the shared library as if it is in the archive file. - * This does not reconcile duplicate names and other items that require the archive file. + * This does not reconcile duplicate names and other items that require the archive file + * and is only used with discoverDomain -remote to give the user an archive path. * * @param shlibPath file name to find the name for * @return name for model archive file name @@ -977,11 +1006,40 @@ public String getSharedLibraryArchivePath(String shlibPath) { */ public String addSharedLibrary(String shlibPath) throws WLSDeployArchiveIOException { final String METHOD = "addSharedLibrary"; - File filePath = new File(shlibPath); LOGGER.entering(CLASS, METHOD, shlibPath); + + File filePath = FileUtils.getCanonicalFile(shlibPath); validateExistingFile(filePath, "shlibPath", getArchiveFileName(), METHOD, true); String newName = addItemToZip(ARCHIVE_SHLIBS_TARGET_DIR, filePath); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Replace an existing application in the archive file. + * + * @param shlibPath the shared library name or the path within the archive to replace + * @param sourceLocation the file system location of the new shared library to replace the existing one + * @return the archive path of the new shared library + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceSharedLibrary(String shlibPath, String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "replaceSharedLibrary"; + LOGGER.entering(CLASS, METHOD, shlibPath, sourceLocation); + + String archivePath; + if (shlibPath.startsWith(ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP)) { + archivePath = shlibPath; + } else { + archivePath = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP + shlibPath; + } + + getZipFile().removeZipEntries(archivePath); + String newName = addSharedLibrary(sourceLocation); + LOGGER.exiting(CLASS, METHOD, newName); return newName; } @@ -1027,6 +1085,10 @@ public void extractSharedLibrary(String sharedLibraryPath, File domainHome) thro LOGGER.exiting(CLASS, METHOD); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // domain library methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** * Get the archive file name for the Domain library file. This does not reconcile duplicate names or other * items that require the archive file. @@ -1043,20 +1105,40 @@ public String getDomainLibArchiveName(String domainLibPath) { * assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding a * numeric value onto the file's basename (e.g., mylib(1).jar, mylib(2).jar). * - * @param domainLibPath - File name representing the actual path of the archive or directory in the local or remote - * file system + * @param domainLibPath - File name representing the actual path of the archive or directory in + * the local or remote file system * @return the relative path where the library will be unpacked by the unpackApplications() method * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes * @throws IllegalArgumentException if the file or directory passed in does not exist */ public String addDomainLibLibrary(String domainLibPath) throws WLSDeployArchiveIOException { final String METHOD = "addDomainLibLibrary"; - LOGGER.entering(CLASS, METHOD, domainLibPath); + File filePath = new File(domainLibPath); validateExistingFile(filePath, "domainLibPath", getArchiveFileName(), METHOD); String newName = addItemToZip(ARCHIVE_DOMLIB_TARGET_DIR, filePath); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + public String replaceDomainLibLibrary(String domainLibPath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceDomainLibLibrary"; + LOGGER.entering(CLASS, METHOD, domainLibPath, sourceLocation); + + String archivePath; + if (domainLibPath.startsWith(ARCHIVE_DOMLIB_TARGET_DIR + ZIP_SEP)) { + archivePath = domainLibPath; + } else { + archivePath = ARCHIVE_DOMLIB_TARGET_DIR + ZIP_SEP + domainLibPath; + } + + getZipFile().removeZipEntries(archivePath); + String newName = addDomainLibLibrary(sourceLocation); + LOGGER.exiting(CLASS, METHOD, newName); return newName; } @@ -1097,6 +1179,10 @@ public void extractDomainLibLibrary(String archivePath, File extractToLocation) LOGGER.exiting(CLASS, METHOD); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // domain bin methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** * Adds a $DOMAIN_HOME/bin script to the archive. If a script with the same name already exists, this method * assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding a @@ -1488,6 +1574,75 @@ public String addNodeManagerKeyStoreFile(String keystoreFile) throws WLSDeployAr return newName; } + /** + * Extract the named database wallet. + * + * @param domainHome the domain home directory + * @param walletName the name of the database wallet to extract (e.g., rcu) + * @return the full path to the directory containing the extracted wallet files or null, if no wallet was found. + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files. + */ + public String extractDatabaseWallet(File domainHome, String walletName) throws WLSDeployArchiveIOException { + final String METHOD = "extractDatabaseWallet"; + + LOGGER.entering(CLASS, METHOD, domainHome, walletName); + + String extractPath = null; + if (DEFAULT_RCU_WALLET_NAME.equals(walletName)) { + // handle archive files with deprecated path, as needed + extractPath = extractRCUWallet(domainHome); + } else { + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + List zipEntries = + getZipFile().listZipEntries(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName + ZIP_SEP); + zipEntries.remove(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName + ZIP_SEP); + if (!zipEntries.isEmpty()) { + extractPath = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName + ZIP_SEP; + extractWallet(domainHome, extractPath, zipEntries, null, null, null); + extractPath = new File(domainHome, extractPath).getAbsolutePath(); + } + } + + LOGGER.exiting(CLASS, METHOD, extractPath); + return extractPath; + } + + /** + * Extract the OPSS wallet from the archive. + * + * @param domainHome the domain home directory + * @return the full path to the directory containing the extracted wallet files or null, if no wallet was found. + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files. + */ + public String extractOPSSWallet(File domainHome) throws WLSDeployArchiveIOException { + final String METHOD = "extractOPSSWallet"; + + LOGGER.entering(CLASS, METHOD, domainHome); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + // Look in the updated location first + String extractPath = null; + List zipEntries = getZipFile().listZipEntries(ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP); + zipEntries.remove(ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP); + if (!zipEntries.isEmpty()) { + extractPath = ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP; + extractWallet(domainHome, extractPath, zipEntries, null, null, null); + extractPath = new File(domainHome, extractPath).getAbsolutePath(); + } else { + // Look in the deprecated location. + zipEntries = getZipFile().listZipEntries(OLD_ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP); + zipEntries.remove(OLD_ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP); + if (!zipEntries.isEmpty()) { + extractPath = OLD_ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP; + extractWallet(domainHome, extractPath, zipEntries, "WLSDPLY-01433",null, null); + extractPath = new File(domainHome, extractPath).getAbsolutePath(); + } + } + + LOGGER.exiting(CLASS, METHOD, extractPath); + return extractPath; + } + /** * Return the manifest for the specified path in the archive, if present. * The path may refer to a packaged EAR/JAR/WAR, or an exploded entry. @@ -2019,6 +2174,7 @@ private String addSingleFileToZip(File itemToAdd, String preferredName, String c return newName; } + // TODO - remove me and replace calls with addItemToZip() to get the correct behavior. private String walkDownFolders(String zipPrefix, File zipPath) throws WLSDeployArchiveIOException { String newSourceName = null; if (zipPath != null) { diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index fd44a012fa..501a3a07bb 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -1731,6 +1731,12 @@ WLSDPLY-22000={0} has been deprecated and will be removed in a future release, p # Message number 30000 - 30999 Archive Helper # #################################################################### WLSDPLY-30000=The -archive_file argument must have a non-empty file name -WLSDPLY-30001=The -archive_file argument's parent directory {0} does not exist and could not be created -WLSDPLY-30002=The -archive_file {0} is not a file -WLSDPLY-30003=Failed to list all entries for archive file {0}: {1} +WLSDPLY-30001=The -archive_file {0} is not a file +WLSDPLY-30002=The -archive_file {0} does not exist +WLSDPLY-30003=The -archive_file argument's parent directory {0} does not exist and could not be created +WLSDPLY-30004=Failed to list all entries in archive file {0}: {1}. +WLSDPLY-30005=Failed to list {0} entries with name {1} in archive file {2}: {3}. +WLSDPLY-30006=Failed to list all {0} entries in archive file {1}: {2}. +WLSDPLY-30007=The -source {0} location does not exist +WLSDPLY-30008=Failed to add {0} {1} to archive file {2}: {3}. +WLSDPLY-30009=Failed to add {0} {1} with overwrite value {2} to archive file {3}: {4}. From 1bc91c67706f2eab23bef7787f3e7880c57af637 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Wed, 18 Jan 2023 15:49:35 -0600 Subject: [PATCH 03/13] intermediate checkpoint --- .../add/AddApplicationCommand.java | 10 +- .../add/AddApplicationPlanCommand.java | 77 + .../add/AddClasspathLibraryCommand.java | 77 + .../add/AddCoherenceConfigCommand.java | 85 ++ .../AddCoherencePersistenceDirCommand.java | 83 ++ .../tool/archive_helper/add/AddCommand.java | 21 +- .../archive_helper/add/AddCustomCommand.java | 77 + .../add/AddDatabaseWalletCommand.java | 85 ++ .../add/AddDomainBinScriptCommand.java | 77 + .../add/AddDomainLibraryCommand.java | 77 + .../add/AddFileStoreCommand.java | 74 + .../add/AddJMSForeignServerCommand.java | 85 ++ .../add/AddMIMEMappingCommand.java | 77 + .../add/AddNodeManagerKeystoreCommand.java | 77 + .../add/AddOPSSWalletCommand.java | 75 + .../tool/archive_helper/add/AddOptions.java | 2 +- .../add/AddRCUWalletCommand.java | 78 + .../archive_helper/add/AddScriptCommand.java | 77 + .../add/AddServerKeystoreCommand.java | 85 ++ .../add/AddSharedLibraryCommand.java | 10 +- .../add/AddSharedLibraryPlanCommand.java | 78 + .../add/AddStructuredApplicationCommand.java | 10 +- .../add/AddTypeCommandBase.java | 2 +- .../archive_helper/list/ListAllCommand.java | 2 +- .../list/ListApplicationCommand.java | 2 +- .../list/ListClasspathLibraryCommand.java | 2 +- .../list/ListCoherenceCommand.java | 10 +- .../tool/archive_helper/list/ListCommand.java | 4 +- .../list/ListCustomCommand.java | 2 +- .../list/ListDatabaseWalletCommand.java | 2 +- .../list/ListDomainBinScriptCommand.java | 2 +- .../list/ListDomainLibraryCommand.java | 2 +- .../list/ListFileStoreCommand.java | 2 +- ....java => ListJMSForeignServerCommand.java} | 21 +- .../list/ListMIMEMappingCommand.java | 2 +- .../list/ListNodeManagerKeystoreCommand.java | 2 +- .../list/ListOPSSWalletCommand.java | 2 +- .../list/ListRCUWalletCommand.java | 2 +- .../list/ListScriptCommand.java | 2 +- .../list/ListServerKeystoreCommand.java | 14 +- .../list/ListSharedLibraryCommand.java | 2 +- .../ListStructuredApplicationCommand.java | 2 +- .../list/ListTypeCommandBase.java | 38 + .../remove/RemoveApplicationCommand.java | 64 + .../archive_helper/remove/RemoveCommand.java | 25 + .../archive_helper/remove/RemoveOptions.java | 24 + .../remove/RemoveTypeCommandBase.java | 17 + .../deploy/util/WLSDeployArchive.java | 1327 ++++++++++++++--- .../deploy/messages/wlsdeploy_rb.properties | 26 +- .../deploy/tool/ArchiveHelperListTest.java | 151 ++ .../test/resources/archive-helper-test.zip | Bin 0 -> 90672 bytes 51 files changed, 2858 insertions(+), 292 deletions(-) create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationPlanCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddClasspathLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherenceConfigCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCustomCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDatabaseWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddJMSForeignServerCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddMIMEMappingCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddNodeManagerKeystoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOPSSWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddScriptCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddServerKeystoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryPlanCommand.java rename core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/{ListForeignServerCommand.java => ListJMSForeignServerCommand.java} (66%) create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOptions.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveTypeCommandBase.java create mode 100644 core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java create mode 100644 core/src/test/resources/archive-helper-test.zip diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java index fdebbdc241..d0a85f2ca0 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java @@ -20,7 +20,7 @@ @Command( name = "application", - description = "Add application to the archive file", + description = "%nAdd application to the archive file:", sortOptions = false ) public class AddApplicationCommand extends AddTypeCommandBase { @@ -61,14 +61,14 @@ public CommandResponse call() throws Exception { } response = new CommandResponse(ExitCode.OK, resultName); } catch (ArchiveHelperException ex) { - LOGGER.severe("WLSDPLY-30008", ex, TYPE, this.sourcePath, + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30008", TYPE, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { - LOGGER.severe("WLSDPLY-30009", ex, TYPE, this.sourcePath, + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30009", TYPE, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationPlanCommand.java new file mode 100644 index 0000000000..caebe1d8f2 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationPlanCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "applicationPlan", + description = "%nAdd application deployment plan to the archive file:", + sortOptions = false +) +public class AddApplicationPlanCommand extends AddTypeCommandBase { + private static final String CLASS = AddApplicationPlanCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "application deployment plan"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the application deployment plan to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add applicationPlan subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceApplicationDeploymentPlan(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addApplicationDeploymentPlan(sourceFile.getPath(), sourceFile.getName()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddClasspathLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddClasspathLibraryCommand.java new file mode 100644 index 0000000000..18d93dff92 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddClasspathLibraryCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "classpathLibrary", + description = "%nAdd classpath library to the archive file:", + sortOptions = false +) +public class AddClasspathLibraryCommand extends AddTypeCommandBase { + private static final String CLASS = AddClasspathLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "classpath library"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the classpath library to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add classpathLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceClasspathLibrary(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addClasspathLibrary(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherenceConfigCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherenceConfigCommand.java new file mode 100644 index 0000000000..ebf638fa35 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherenceConfigCommand.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "coherenceConfig", + description = "%nAdd a Coherence config file to the archive file:", + sortOptions = false +) +public class AddCoherenceConfigCommand extends AddTypeCommandBase { + private static final String CLASS = AddCoherenceConfigCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the Coherence config to add", + required = true + ) + private String sourcePath; + + @Option( + names = {"-cluster_name"}, + paramLabel = "", + description = "Coherence cluster name to use", + required = true + ) + protected String clusterName; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add coherenceConfig subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceCoherenceConfigFile(this.clusterName, sourceFile.getName(), + sourceFile.getPath()); + } else { + resultName = this.archive.addCoherenceConfigFile(this.clusterName, sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30014", ex, this.sourcePath, this.clusterName, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30014", this.sourcePath, + this.clusterName, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30015", ex, this.sourcePath, this.clusterName, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30015", this.sourcePath, + this.clusterName, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java new file mode 100644 index 0000000000..435637f598 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "coherencePersistenceDir", + description = "%nAdd a Coherence persistence directory to the archive file:", + sortOptions = false +) +public class AddCoherencePersistenceDirCommand extends AddTypeCommandBase { + private static final String CLASS = AddCoherencePersistenceDirCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = {"-cluster_name"}, + paramLabel = "", + description = "Coherence cluster name to use", + required = true + ) + protected String clusterName; + + @Option( + names = {"-type"}, + paramLabel = "", + description = "The Coherence persistence directory type to add", + required = true + ) + private String directoryType; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add coherencePersistenceDir subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceCoherencePersistenceDirectory(this.clusterName, this.directoryType); + } else { + resultName = this.archive.addCoherencePersistenceDirectory(this.clusterName, this.directoryType); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30016", ex, this.directoryType, this.clusterName, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30016", this.directoryType, + this.clusterName, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30017", ex, this.directoryType, this.clusterName, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30017", this.directoryType, + this.clusterName, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java index 2d7c0f9e50..b7770c5a55 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java @@ -9,11 +9,28 @@ @Command( name = "add", - description = "add items to the archive file", + description = "%nAdd items to the archive file:", commandListHeading = "%nSubcommands:%n%n", subcommands = { AddApplicationCommand.class, + AddApplicationPlanCommand.class, + AddClasspathLibraryCommand.class, + AddCoherenceConfigCommand.class, + AddCoherencePersistenceDirCommand.class, + AddCustomCommand.class, + AddDatabaseWalletCommand.class, + AddDomainBinScriptCommand.class, + AddDomainLibraryCommand.class, + AddFileStoreCommand.class, + AddJMSForeignServerCommand.class, + AddMIMEMappingCommand.class, + AddNodeManagerKeystoreCommand.class, + AddOPSSWalletCommand.class, + AddRCUWalletCommand.class, + AddScriptCommand.class, + AddServerKeystoreCommand.class, AddSharedLibraryCommand.class, + AddSharedLibraryPlanCommand.class, AddStructuredApplicationCommand.class, }, sortOptions = false @@ -21,7 +38,7 @@ public class AddCommand { @Option( names = { "-help" }, - description = "Get help for the archiveHelper list command", + description = "Get help for the archiveHelper add command", usageHelp = true ) private boolean helpRequested = false; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCustomCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCustomCommand.java new file mode 100644 index 0000000000..b0db46199b --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCustomCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "custom", + description = "%nAdd custom file/directory to the archive file:", + sortOptions = false +) +public class AddCustomCommand extends AddTypeCommandBase { + private static final String CLASS = AddCustomCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "custom file or directory"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the custom file or directory to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add custom subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceCustomEntry(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addCustomEntry(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDatabaseWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDatabaseWalletCommand.java new file mode 100644 index 0000000000..2d4008f242 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDatabaseWalletCommand.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "databaseWallet", + description = "%nAdd database wallet to the archive file:", + sortOptions = false +) +public class AddDatabaseWalletCommand extends AddTypeCommandBase { + private static final String CLASS = AddDatabaseWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "database wallet"; + + @Option( + names = {"-wallet_name"}, + paramLabel = "", + description = "Name used to identity this database wallet in the archive", + required = true + ) + private String walletName; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the database wallet to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add databaseWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceDatabaseWallet(this.walletName, sourceFile.getPath()); + } else { + resultName = this.archive.addDatabaseWallet(this.walletName, sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30022", ex, TYPE, this.walletName, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30022", TYPE, this.walletName, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30023", ex, TYPE, this.walletName, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30023", TYPE, this.walletName, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java new file mode 100644 index 0000000000..b86143d2fd --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "domainBinScript", + description = "%nAdd domain bin script to the archive file:", + sortOptions = false +) +public class AddDomainBinScriptCommand extends AddTypeCommandBase { + private static final String CLASS = AddDomainBinScriptCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "domain bin script"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the domain bin script to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add domainBinScript subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceDomainBinScript(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addDomainBinScript(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java new file mode 100644 index 0000000000..389faa22cd --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "domainLibrary", + description = "%nAdd domain library to the archive file:", + sortOptions = false +) +public class AddDomainLibraryCommand extends AddTypeCommandBase { + private static final String CLASS = AddDomainLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "domain library"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the domain library to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add domainLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceDomainLibLibrary(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addDomainLibLibrary(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java new file mode 100644 index 0000000000..58749877ed --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "fileStore", + description = "%nAdd empty file store directory to the archive file:", + sortOptions = false +) +public class AddFileStoreCommand extends AddTypeCommandBase { + private static final String CLASS = AddFileStoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-name" }, + paramLabel = "", + description = "File store name", + required = true + ) + protected String fileStoreName; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add fileStore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceFileStoreDirectory(this.fileStoreName); + } else { + resultName = this.archive.addFileStoreDirectory(this.fileStoreName); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30020", ex, this.fileStoreName, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30020", this.fileStoreName, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30021", ex, this.fileStoreName, this.overwrite, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30021", this.fileStoreName, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddJMSForeignServerCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddJMSForeignServerCommand.java new file mode 100644 index 0000000000..85724256e3 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddJMSForeignServerCommand.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "jmsForeignServer", + description = "%nAdd a JMS Foreign Server binding file to the archive file:", + sortOptions = false +) +public class AddJMSForeignServerCommand extends AddTypeCommandBase { + private static final String CLASS = AddJMSForeignServerCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = { "-foreign_server_name" }, + paramLabel = "", + description = "WebLogic JMS Foreign Server name", + required = true + ) + protected String jmsForeignServerName; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the JMS Foreign Server binding to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add jmsForeignServer subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceForeignServerFile(this.jmsForeignServerName, sourceFile.getName(), + sourceFile.getPath()); + } else { + resultName = this.archive.addForeignServerFile(this.jmsForeignServerName, sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30018", ex, this.sourcePath, this.jmsForeignServerName, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30018", this.sourcePath, + this.jmsForeignServerName, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30019", ex, this.sourcePath, this.jmsForeignServerName, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30019", this.sourcePath, + this.jmsForeignServerName, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddMIMEMappingCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddMIMEMappingCommand.java new file mode 100644 index 0000000000..d5522f0f26 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddMIMEMappingCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "mimeMapping", + description = "%nAdd MIME mapping file to the archive file:", + sortOptions = false +) +public class AddMIMEMappingCommand extends AddTypeCommandBase { + private static final String CLASS = AddMIMEMappingCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "MIME mapping"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the MIME mapping to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add mimeMapping subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceMimeMappingFile(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addMimeMappingFile(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddNodeManagerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddNodeManagerKeystoreCommand.java new file mode 100644 index 0000000000..43ca999c03 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddNodeManagerKeystoreCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "nodeManagerKeystore", + description = "%nAdd node manager keystore to the archive file:", + sortOptions = false +) +public class AddNodeManagerKeystoreCommand extends AddTypeCommandBase { + private static final String CLASS = AddNodeManagerKeystoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "node manager keystore"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the node manager keystore to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add nodeManagerKeystore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceNodeManagerKeyStoreFile(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addNodeManagerKeyStoreFile(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOPSSWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOPSSWalletCommand.java new file mode 100644 index 0000000000..f87f5bf9b3 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOPSSWalletCommand.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "opssWallet", + description = "%nAdd OPSS wallet to the archive file:", + sortOptions = false +) +public class AddOPSSWalletCommand extends AddTypeCommandBase { + private static final String CLASS = AddOPSSWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the OPSS wallet to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add opssWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceOPSSWallet(sourceFile.getPath()); + } else { + resultName = this.archive.addOPSSWallet(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30024", ex, this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30024", this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30025", ex, this.sourcePath, this.overwrite, this.archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30025", this.sourcePath, this.overwrite, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOptions.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOptions.java index a63c0ec1d2..433f9200a2 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOptions.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOptions.java @@ -12,7 +12,7 @@ public abstract class AddOptions extends CommonOptions { @Option( names = {"-overwrite"}, - description = "overwrite the existing entry in the archive file, if any" + description = "Overwrite the existing entry in the archive file, if any" ) protected boolean overwrite; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java new file mode 100644 index 0000000000..f614f58025 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; + +@Command( + name = "rcuWallet", + description = "%nAdd RCU database wallet to the archive file:", + sortOptions = false +) +public class AddRCUWalletCommand extends AddTypeCommandBase { + private static final String CLASS = AddRCUWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "database wallet"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the RCU database wallet to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add rcuWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceDatabaseWallet(DEFAULT_RCU_WALLET_NAME, sourceFile.getPath()); + } else { + resultName = this.archive.addDatabaseWallet(DEFAULT_RCU_WALLET_NAME, sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30022", ex, TYPE, DEFAULT_RCU_WALLET_NAME, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30022", TYPE, DEFAULT_RCU_WALLET_NAME, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30023", ex, TYPE, DEFAULT_RCU_WALLET_NAME, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30023", TYPE, DEFAULT_RCU_WALLET_NAME, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddScriptCommand.java new file mode 100644 index 0000000000..e84967b5dd --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddScriptCommand.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "script", + description = "%nAdd script to the archive file:", + sortOptions = false +) +public class AddScriptCommand extends AddTypeCommandBase { + private static final String CLASS = AddScriptCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "script"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the script to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add script subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = this.archive.replaceScript(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addScript(sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddServerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddServerKeystoreCommand.java new file mode 100644 index 0000000000..43782499f4 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddServerKeystoreCommand.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "serverKeystore", + description = "%nAdd a server keystore to the archive file:", + sortOptions = false +) +public class AddServerKeystoreCommand extends AddTypeCommandBase { + private static final String CLASS = AddServerKeystoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the server keystore to add", + required = true + ) + private String sourcePath; + + @Option( + names = {"-server_name"}, + paramLabel = "", + description = "WebLogic Server domain's server name to use", + required = true + ) + private String serverName; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add serverKeystore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = + this.archive.replaceServerKeyStoreFile(this.serverName, sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addServerKeyStoreFile(this.serverName, sourceFile.getPath()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30012", ex, this.sourcePath, this.serverName, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30012", this.sourcePath, + this.serverName, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30013", ex, this.sourcePath, this.serverName, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30013", this.sourcePath, + this.serverName, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java index 8de9670c05..bfa25c4a02 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java @@ -19,7 +19,7 @@ @Command( name = "sharedLibrary", - description = "Add shared library to the archive file", + description = "%nAdd shared library to the archive file:", sortOptions = false ) public class AddSharedLibraryCommand extends AddTypeCommandBase { @@ -60,14 +60,14 @@ public CommandResponse call() throws Exception { } response = new CommandResponse(ExitCode.OK, resultName); } catch (ArchiveHelperException ex) { - LOGGER.severe("WLSDPLY-30008", ex, TYPE, this.sourcePath, + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30008", TYPE, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { - LOGGER.severe("WLSDPLY-30009", ex, TYPE, this.sourcePath, + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30009", TYPE, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryPlanCommand.java new file mode 100644 index 0000000000..70e08b1ec8 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryPlanCommand.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.add; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "sharedLibraryPlan", + description = "%nAdd shared library deployment plan to the archive file:", + sortOptions = false +) +public class AddSharedLibraryPlanCommand extends AddTypeCommandBase { + private static final String CLASS = AddSharedLibraryPlanCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "shared library deployment plan"; + + @Option( + names = {"-source"}, + paramLabel = "", + description = "File system path to the shared library deployment plan to add", + required = true + ) + private String sourcePath; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add sharedLibraryPlan subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + File sourceFile; + try { + sourceFile = initializeOptions(this.sourcePath); + + String resultName; + if (this.overwrite) { + resultName = + this.archive.replaceSharedLibraryDeploymentPlan(sourceFile.getName(), sourceFile.getPath()); + } else { + resultName = this.archive.addSharedLibraryDeploymentPlan(sourceFile.getPath(), sourceFile.getName()); + } + response = new CommandResponse(ExitCode.OK, resultName); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, + this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, + this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, + this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java index 847f784013..59476c15bc 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java @@ -19,7 +19,7 @@ @Command( name = "structuredApplication", - description = "Add structured application installation directory to the archive file", + description = "%nAdd structured application installation directory to the archive file:", sortOptions = false ) public class AddStructuredApplicationCommand extends AddTypeCommandBase { @@ -60,14 +60,14 @@ public CommandResponse call() throws Exception { } response = new CommandResponse(ExitCode.OK, resultName); } catch (ArchiveHelperException ex) { - LOGGER.severe("WLSDPLY-30008", ex, TYPE, this.sourcePath, + LOGGER.severe("WLSDPLY-30010", ex, TYPE, this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30008", TYPE, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30010", TYPE, this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { - LOGGER.severe("WLSDPLY-30009", ex, TYPE, this.sourcePath, + LOGGER.severe("WLSDPLY-30011", ex, TYPE, this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30009", TYPE, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30011", TYPE, this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java index cdc23549f9..6e138dfb73 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java @@ -42,7 +42,7 @@ private File getSourceLocationFile(String path) throws ArchiveHelperException { File result = FileUtils.getCanonicalFile(path); if (!result.exists()) { ArchiveHelperException ex = - new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30007", path); + new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30009", path); LOGGER.throwing(CLASS, METHOD, ex); throw ex; } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java index 265211eac2..ded81d5f4b 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java @@ -22,7 +22,7 @@ @Command( name = "all", - description = "List all entries in the archive file", + description = "%nList all entries in the archive file:", sortOptions = false ) public class ListAllCommand extends CommonOptions implements Callable { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java index 05528f393f..e2a90ff9a5 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java @@ -16,7 +16,7 @@ @Command( name = "application", - description = "List application entries in the archive file", + description = "%nList application entries in the archive file:", sortOptions = false ) public class ListApplicationCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java index 096f71e902..6cf37ffb35 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java @@ -15,7 +15,7 @@ @Command( name = "classpathLibrary", - description = "List classpath library entries in the archive file", + description = "%nList classpath library entries in the archive file:", sortOptions = false ) public class ListClasspathLibraryCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java index a114c8ecb7..efa704bbca 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java @@ -14,7 +14,7 @@ import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.COHERENCE; @Command( name = "coherence", - description = "List Coherence entries in the archive file", + description = "%nList Coherence entries in the archive file:", sortOptions = false ) public class ListCoherenceCommand extends ListTypeCommandBase { @@ -22,11 +22,11 @@ public class ListCoherenceCommand extends ListTypeCommandBase { private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); @Option( - names = { "-name" }, - paramLabel = "", + names = { "-cluster_name" }, + paramLabel = "", description = "Name of the Coherence cluster to list" ) - private String name; + private String clusterName; @Option( names = { "-help" }, @@ -40,7 +40,7 @@ public CommandResponse call() throws Exception { final String METHOD = "call"; LOGGER.entering(CLASS, METHOD); - CommandResponse response = listType(COHERENCE, "Coherence cluster", name); + CommandResponse response = listType(COHERENCE, "Coherence cluster", this.clusterName); LOGGER.exiting(CLASS, METHOD, response); return response; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java index a7e49b3a11..cf56eb0dfe 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java @@ -9,7 +9,7 @@ @Command( name = "list", - description = "List contents of the archive file", + description = "%nList contents of the archive file:", commandListHeading = "%nSubcommands:%n%n", subcommands = { ListAllCommand.class, @@ -21,7 +21,7 @@ ListDomainBinScriptCommand.class, ListDomainLibraryCommand.class, ListFileStoreCommand.class, - ListForeignServerCommand.class, + ListJMSForeignServerCommand.class, ListMIMEMappingCommand.class, ListNodeManagerKeystoreCommand.class, ListOPSSWalletCommand.class, diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java index b179fe1621..0bdec90c3f 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java @@ -15,7 +15,7 @@ @Command( name = "custom", - description = "List custom directory entries in the archive file", + description = "%nList custom directory entries in the archive file:", sortOptions = false ) public class ListCustomCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java index d3afe1db74..d37665ff32 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java @@ -15,7 +15,7 @@ @Command( name = "databaseWallet", - description = "List database wallet entries in the archive file", + description = "%nList database wallet entries in the archive file:", sortOptions = false ) public class ListDatabaseWalletCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java index 88d7561132..e2cc6802a8 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java @@ -15,7 +15,7 @@ @Command( name = "domainBinScript", - description = "List domain bin script entries in the archive file", + description = "%nList domain bin script entries in the archive file:", sortOptions = false ) public class ListDomainBinScriptCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java index 0ff90c6e9e..dd81464f0b 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java @@ -15,7 +15,7 @@ @Command( name = "domainLibrary", - description = "List domain library entries in the archive file", + description = "%nList domain library entries in the archive file:", sortOptions = false ) public class ListDomainLibraryCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java index 620f6cdeff..585fa9b512 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java @@ -15,7 +15,7 @@ @Command( name = "fileStore", - description = "List file store entries in the archive file", + description = "%nList file store entries in the archive file:", sortOptions = false ) public class ListFileStoreCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListForeignServerCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListJMSForeignServerCommand.java similarity index 66% rename from core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListForeignServerCommand.java rename to core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListJMSForeignServerCommand.java index 27019a6e10..fc6be10228 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListForeignServerCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListJMSForeignServerCommand.java @@ -14,14 +14,22 @@ import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.JMS_FOREIGN_SERVER; @Command( - name = "foreignServer", - description = "List JMS foreign server binding entries in the archive file", + name = "jmsForeignServer", + description = "%nList JMS foreign server binding entries in the archive file:", sortOptions = false ) -public class ListForeignServerCommand extends ListTypeCommandBase { - private static final String CLASS = ListForeignServerCommand.class.getName(); +public class ListJMSForeignServerCommand extends ListTypeCommandBase { + private static final String CLASS = ListJMSForeignServerCommand.class.getName(); private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + @Option( + names = { "-foreign_server_name" }, + paramLabel = "", + description = "WebLogic JMS Foreign Server name", + required = true + ) + private String jmsForeignServerName; + @Option( names = { "-name" }, paramLabel = "", @@ -31,7 +39,7 @@ public class ListForeignServerCommand extends ListTypeCommandBase { @Option( names = { "-help" }, - description = "Get help for the archiveHelper list foreignServer subcommand", + description = "Get help for the archiveHelper list jmsForeignServer subcommand", usageHelp = true ) private boolean helpRequested = false; @@ -41,7 +49,8 @@ public CommandResponse call() throws Exception { final String METHOD = "call"; LOGGER.entering(CLASS, METHOD); - CommandResponse response = listType(JMS_FOREIGN_SERVER, "JMS foreign server binding", name); + CommandResponse response = listType(JMS_FOREIGN_SERVER, "JMS foreign server binding", + this.jmsForeignServerName, this.name); LOGGER.exiting(CLASS, METHOD, response); return response; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java index 3f955d04fb..87e214fcb1 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java @@ -15,7 +15,7 @@ @Command( name = "mimeMapping", - description = "List MIME mapping entries in the archive file", + description = "%nList MIME mapping entries in the archive file:", sortOptions = false ) public class ListMIMEMappingCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java index 6d8ec00b78..4dd154a5d3 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java @@ -15,7 +15,7 @@ @Command( name = "nodeManagerKeystore", - description = "List node manager keystore entries in the archive file", + description = "%nList node manager keystore entries in the archive file:", sortOptions = false ) public class ListNodeManagerKeystoreCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java index 202e3d0ba7..1a2f12e898 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java @@ -15,7 +15,7 @@ @Command( name = "opssWallet", - description = "List OPSS wallet entries in the archive file", + description = "%nList OPSS wallet entries in the archive file:", sortOptions = false ) public class ListOPSSWalletCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java index 9a0aae3771..e877dc6f79 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java @@ -16,7 +16,7 @@ @Command( name = "rcuWallet", - description = "List RCU database wallet entries in the archive file", + description = "%nList RCU database wallet entries in the archive file:", sortOptions = false ) public class ListRCUWalletCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java index 31b27d622c..9a8cf21436 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java @@ -15,7 +15,7 @@ @Command( name = "script", - description = "List script entries in the archive file", + description = "%nList script entries in the archive file:", sortOptions = false ) public class ListScriptCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java index 59d090fc8f..d70ee9d157 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java @@ -15,16 +15,24 @@ @Command( name = "serverKeystore", - description = "List server keystore entries in the archive file", + description = "%nList server keystore entries in the archive file:", sortOptions = false ) public class ListServerKeystoreCommand extends ListTypeCommandBase { private static final String CLASS = ListServerKeystoreCommand.class.getName(); private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + @Option( + names = {"-server_name"}, + paramLabel = "", + description = "WebLogic Server domain's server name to use", + required = true + ) + private String serverName; + @Option( names = { "-name" }, - paramLabel = "", + paramLabel = "", description = "Name of the server for which to list the keystore" ) private String name; @@ -41,7 +49,7 @@ public CommandResponse call() throws Exception { final String METHOD = "call"; LOGGER.entering(CLASS, METHOD); - CommandResponse response = listType(SERVER_KEYSTORE, "server keystore", name); + CommandResponse response = listType(SERVER_KEYSTORE, "server keystore", this.serverName, this.name); LOGGER.exiting(CLASS, METHOD, response); return response; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java index 8969224b40..7bad92e5ce 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java @@ -16,7 +16,7 @@ @Command( name = "sharedLibrary", - description = "List shared library entries in the archive file", + description = "%nList shared library entries in the archive file:", sortOptions = false ) public class ListSharedLibraryCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java index dbe7a8f980..07fed23db5 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java @@ -15,7 +15,7 @@ @Command( name = "structuredApplication", - description = "List structured application entries in the archive file", + description = "%nList structured application entries in the archive file:", sortOptions = false ) public class ListStructuredApplicationCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommandBase.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommandBase.java index a3dcea5e72..077c37ac18 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommandBase.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListTypeCommandBase.java @@ -54,4 +54,42 @@ protected CommandResponse listType(ArchiveEntryType type, String typeName, Strin LOGGER.exiting(CLASS, METHOD, response); return response; } + + protected CommandResponse listType(ArchiveEntryType type, String typeName, String segregationName, String name) { + final String METHOD = "listType"; + LOGGER.entering(CLASS, METHOD, type, typeName, segregationName, name); + + boolean hasName = !StringUtils.isEmpty(name); + CommandResponse response; + try { + initializeOptions(true); + + List archiveEntries; + if (hasName) { + archiveEntries = this.archive.getSegregatedArchiveEntries(type, segregationName, name); + } else { + archiveEntries = this.archive.getSegregatedArchiveEntries(type, segregationName); + } + response = new CommandResponse(ExitCode.OK); + response.addMessages(archiveEntries); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ex.getLocalizedMessage(), ex); + response = new CommandResponse(ex.getExitCode(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException ex) { + if (hasName) { + LOGGER.severe("WLSDPLY-30007", ex, typeName,segregationName, name, archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30007", type, segregationName, name, + this.archiveFilePath, ex.getLocalizedMessage()); + } else { + LOGGER.severe("WLSDPLY-30008", ex, typeName, segregationName, this.archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30008", type, segregationName, + this.archiveFilePath, ex.getLocalizedMessage()); + } + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java new file mode 100644 index 0000000000..691f143297 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import java.util.List; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; + +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.tool.archive_helper.add.AddApplicationCommand; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "application", + description = "%nRemove application from the archive file:", + sortOptions = false +) +public class RemoveApplicationCommand extends RemoveTypeCommandBase { + private static final String CLASS = AddApplicationCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "application"; + + @Option( + names = {"-name"}, + description = "Name of the application to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper add application subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + /* + CommandResponse response; + try { + initializeOptions(); + + } catch (ArchiveHelperException ex) { + + } catch (WLSDeployArchiveIOException ex) { + + } + */ + return null; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCommand.java new file mode 100644 index 0000000000..3701b032b8 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCommand.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +@Command( + name = "remove", + description = "%nRemove items to the archive file:", + commandListHeading = "%nSubcommands:%n%n", + subcommands = { + }, + sortOptions = false +) +public class RemoveCommand { + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove command", + usageHelp = true + ) + private boolean helpRequested = false; +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOptions.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOptions.java new file mode 100644 index 0000000000..c5e22ffe33 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOptions.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommonOptions; + +import picocli.CommandLine.Option; + + +public class RemoveOptions extends CommonOptions { + @Option( + names = {"-force"}, + description = "Force the remove command to succeed even if the item being removed " + + "does not exist in the archive file" + ) + protected boolean force; + + protected void initializeOptions() throws ArchiveHelperException { + super.initializeOptions(false); + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveTypeCommandBase.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveTypeCommandBase.java new file mode 100644 index 0000000000..f57c18f8fe --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveTypeCommandBase.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import java.util.concurrent.Callable; + +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; + +public abstract class RemoveTypeCommandBase extends RemoveOptions implements Callable { + + protected void initializeOptions() throws ArchiveHelperException { + super.initializeOptions(); + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java index c5f8bb4c7f..099da8c45b 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java @@ -14,6 +14,7 @@ import java.nio.file.Files; import java.security.NoSuchAlgorithmException; import java.util.List; +import java.util.ListIterator; import java.util.Map; import java.util.jar.JarFile; import java.util.jar.Manifest; @@ -70,11 +71,6 @@ public class WLSDeployArchive { */ public static final String DEFAULT_RCU_WALLET_PATH = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + DEFAULT_RCU_WALLET_NAME; - /** - * Top-level archive subdirectory where the atp wallet is stored. - */ - public static final String ARCHIVE_ATP_WALLET_PATH = WLSDPLY_ARCHIVE_BINARY_DIR + "/atpwallet"; - /** * Top-level archive subdirectory where the opss wallet is stored. */ @@ -185,6 +181,12 @@ public enum ArchiveEntryType { CUSTOM } + private enum FileOrDirectoryType { + EITHER, + FILE_ONLY, + DIRECTORY_ONLY + } + private static final String SEP = File.separator; private static final int READ_BUFFER_SIZE = 4096; private static final String COHERENCE_CONFIG_FILE_EXTENSION = ".xml"; @@ -325,45 +327,40 @@ public static String getPathForType(ArchiveEntryType type) { return pathPrefix; } - public static String getPathForType(ArchiveEntryType type, String name) { - final String METHOD = "getPathForType"; - LOGGER.entering(CLASS, METHOD, type, name); + public static String getPathForSegregationType(ArchiveEntryType type, String segregationName) { + final String METHOD = "getPathForSegregationType"; + LOGGER.entering(CLASS, METHOD, type, segregationName); + + validateNonEmptyString(segregationName, "segregationName", METHOD); String pathPrefix = getPathForType(type); - if (!StringUtils.isEmpty(name)) { - boolean hasName = true; - boolean isAlwaysDirectory = false; - switch(type) { - case COHERENCE: - case JMS_FOREIGN_SERVER: - case FILE_STORE: - case DB_WALLET: - isAlwaysDirectory = true; - break; + if (!StringUtils.isEmpty(pathPrefix)) { + pathPrefix += segregationName + ZIP_SEP; + } - case OPSS_WALLET: - hasName = false; - break; - } + LOGGER.exiting(CLASS, METHOD, pathPrefix); + return pathPrefix; + } - if (pathPrefix != null && hasName) { - pathPrefix += name; - if (isAlwaysDirectory) { - pathPrefix += ZIP_SEP; - } - } + public static String getPathForSegregationType(ArchiveEntryType type, String segregationName, String name) { + final String METHOD = "getPathForSegregationType"; + LOGGER.entering(CLASS, METHOD, type, segregationName, name); + + String pathPrefix = getPathForSegregationType(type, segregationName); + if (!StringUtils.isEmpty(pathPrefix) && !StringUtils.isEmpty(name)) { + pathPrefix += name; } LOGGER.exiting(CLASS, METHOD, pathPrefix); return pathPrefix; } - /** - * Get archive path for the application name for use in the model. - * - * @param appPath name of the application - * @return archive path for use in the model - */ + /** + * Get archive path for the application name for use in the model. + * + * @param appPath name of the application + * @return archive path for use in the model + */ public static String getApplicationArchivePath(String appPath) { return getArchiveName(ARCHIVE_APPS_TARGET_DIR, appPath); } @@ -411,7 +408,7 @@ public static String getApplicationPlanArchivePath(String planFile) { } /** - * Get the archive path of a well formed plan directory in app directory, + * Get the archive path of a well-formed plan directory in app directory, * * @param appName The application name of the app directory * @param planDir The deployment plan file directory @@ -538,33 +535,62 @@ public String getArchiveFileName() { */ public List getArchiveEntries() throws WLSDeployArchiveIOException { final String METHOD = "getArchiveEntries"; - LOGGER.entering(CLASS, METHOD); + List entries = getZipFile().listZipEntries(); + LOGGER.exiting(CLASS, METHOD, entries); return entries; } public List getArchiveEntries(ArchiveEntryType type) throws WLSDeployArchiveIOException { final String METHOD = "getArchiveEntries"; + LOGGER.entering(CLASS, METHOD, type); + + String pathPrefix = getPathForType(type); + List entries = getZipFile().listZipEntries(pathPrefix); - LOGGER.entering(CLASS, METHOD); - List entries = getArchiveEntries(type, null); LOGGER.exiting(CLASS, METHOD, entries); return entries; } public List getArchiveEntries(ArchiveEntryType type, String name) throws WLSDeployArchiveIOException { final String METHOD = "getArchiveEntries"; + LOGGER.entering(CLASS, METHOD, type, name); - LOGGER.entering(CLASS, METHOD); - String pathPrefix = getPathForType(type, name); + String pathPrefix = getPathForType(type); + FileOrDirectoryType allowedFileType = getFileType(type); + List entries = getZipListEntries(pathPrefix, name, allowedFileType); + + LOGGER.exiting(CLASS, METHOD, entries); + return entries; + } + + public List getSegregatedArchiveEntries(ArchiveEntryType type, String segregationName) + throws WLSDeployArchiveIOException { + final String METHOD = "getSegregatedArchiveEntries"; + LOGGER.entering(CLASS, METHOD, type, segregationName); + + String pathPrefix = getPathForSegregationType(type, segregationName); List entries = getZipFile().listZipEntries(pathPrefix); LOGGER.exiting(CLASS, METHOD, entries); return entries; } + public List getSegregatedArchiveEntries(ArchiveEntryType type, String segregationName, String name) + throws WLSDeployArchiveIOException { + final String METHOD = "getSegregatedArchiveEntries"; + LOGGER.entering(CLASS, METHOD, type, segregationName, name); + + String pathPrefix = getPathForSegregationType(type, segregationName); + FileOrDirectoryType allowedFileType = getFileType(type); + List entries = getZipListEntries(pathPrefix, name, allowedFileType); + + LOGGER.exiting(CLASS, METHOD, entries); + return entries; + } + /** * Determines whether the archive contains the specified file or directory. * @@ -790,6 +816,69 @@ public String getFileHash(String path) throws WLSDeployArchiveIOException { return result; } + /** + * Return the manifest for the specified path in the archive, if present. + * The path may refer to a packaged EAR/JAR/WAR, or an exploded entry. + * + * @param sourcePath the path to be checked + * @return the Manifest object, or null + * @throws WLSDeployArchiveIOException if there is a problem reading the archive, or the manifest + */ + public Manifest getManifest(String sourcePath) throws WLSDeployArchiveIOException { + try { + if (containsFile(sourcePath)) { + // a jarred app or library in the archive. + try (ZipInputStream zipStream = new ZipInputStream(getZipFile().getZipEntry(sourcePath))) { + // JarInputStream.getManifest() has problems if MANIFEST.MF is not the first entry, + // so use ZipInputStream and search for the specific entry. + ZipEntry zipEntry; + while ((zipEntry = zipStream.getNextEntry()) != null) { + if (JarFile.MANIFEST_NAME.equals(zipEntry.getName())) { + Manifest manifest = new Manifest(zipStream); + zipStream.closeEntry(); + return manifest; + } + zipStream.closeEntry(); + } + } + } else if (containsPath(sourcePath)) { + // an exploded app or library in the archive. + String manifestPath = sourcePath + "/" + JarFile.MANIFEST_NAME; + if (containsFile(manifestPath)) { + try (InputStream inStream = getZipFile().getZipEntry(manifestPath)) { + return new Manifest(inStream); + } + } + } + } catch (IOException e) { + WLSDeployArchiveIOException aioe = new WLSDeployArchiveIOException("WLSDPLY-01426", sourcePath, + getArchiveFileName(), e.getLocalizedMessage()); + LOGGER.throwing(aioe); + throw aioe; + } + return null; + } + + /** + * This method removes all binaries from the archive. This method is intended to + * be invoked by discovery to remove binaries from a previous run that might + * exist in the archive to make it possible for discovery to be truly idempotent. + * + * @throws WLSDeployArchiveIOException if an error is encountered removing the binaries + */ + public void removeAllBinaries() throws WLSDeployArchiveIOException { + getZipFile().removeZipEntries(WLSDPLY_ARCHIVE_BINARY_DIR + ZIP_SEP); + } + + /** + * Closes the underlying zip file and any open streams. + */ + public void close() { + if (getZipFile() != null) { + getZipFile().close(); + } + } + /////////////////////////////////////////////////////////////////////////////////////////////// // application methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -888,6 +977,65 @@ public void extractApplication(String applicationPath, File domainHome) throws W LOGGER.exiting(CLASS, METHOD); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // application plan methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Adds an application's deployment plan file to the archive. + * + * @param planFile the deployment plan file name + * @param preferredName the preferred name of the file to add + * @return the actual name of the file in the archive + * @throws WLSDeployArchiveIOException if an error occurs adding the file + * @throws IllegalArgumentException if the file does not exist or the preferredName was empty or null + */ + public String addApplicationDeploymentPlan(String planFile, String preferredName) + throws WLSDeployArchiveIOException { + final String METHOD = "addApplicationDeploymentPlan"; + LOGGER.entering(CLASS, METHOD, planFile, preferredName); + + File filePath = new File(planFile); + validateExistingFile(filePath, "planFile", getArchiveFileName(), METHOD); + validateNonEmptyString(preferredName, "preferredName", METHOD); + + String newName = addItemToZip(ARCHIVE_APPS_TARGET_DIR, filePath, preferredName); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Replace an application deployment plan file in the archive. + * + * @param planPath the application deployment plan name or path within the archive + * @param sourceLocation the file system location of the new application deployment plan to replace the existing one + * @return the archive path of the new application deployment plan + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceApplicationDeploymentPlan(String planPath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceApplicationDeploymentPlan"; + LOGGER.entering(CLASS, METHOD, planPath, sourceLocation); + + String archivePath; + String preferredName; + if (planPath.startsWith(ARCHIVE_APPS_TARGET_DIR + ZIP_SEP)) { + archivePath = planPath; + preferredName = planPath.substring(planPath.lastIndexOf(ZIP_SEP) + 1); + } else { + archivePath = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP + planPath; + preferredName = planPath; + } + + getZipFile().removeZipEntry(archivePath); + String newName = addApplicationDeploymentPlan(sourceLocation, preferredName); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // structured application methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1085,6 +1233,66 @@ public void extractSharedLibrary(String sharedLibraryPath, File domainHome) thro LOGGER.exiting(CLASS, METHOD); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // shared library plan methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Adds a shared library's deployment plan file to the archive. + * + * @param planFile the deployment plan file name + * @param preferredName the preferred name of the file to add + * @return the actual name of the file in the archive + * @throws WLSDeployArchiveIOException if an error occurs adding the file + * @throws IllegalArgumentException if the file does not exist or the preferredName was empty or null + */ + public String addSharedLibraryDeploymentPlan(String planFile, String preferredName) + throws WLSDeployArchiveIOException { + final String METHOD = "addSharedLibraryDeploymentPlan"; + + LOGGER.entering(CLASS, METHOD, planFile, preferredName); + File filePath = new File(planFile); + + validateExistingFile(filePath, "planFile", getArchiveFileName(), METHOD); + validateNonEmptyString(preferredName, "preferredName", METHOD); + + String newName = addItemToZip(ARCHIVE_SHLIBS_TARGET_DIR, filePath, preferredName); + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Replace a shared library deployment plan file in the archive. + * + * @param planPath the shared library deployment plan name or path within the archive + * @param sourceLocation the file system location of the new shared library deployment plan + * to replace the existing one + * @return the archive path of the new shared library deployment plan + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceSharedLibraryDeploymentPlan(String planPath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceSharedLibraryDeploymentPlan"; + LOGGER.entering(CLASS, METHOD, planPath, sourceLocation); + + String archivePath; + String preferredName; + if (planPath.startsWith(ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP)) { + archivePath = planPath; + preferredName = planPath.substring(planPath.lastIndexOf(ZIP_SEP) + 1); + } else { + archivePath = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP + planPath; + preferredName = planPath; + } + + getZipFile().removeZipEntry(archivePath); + String newName = addSharedLibraryDeploymentPlan(sourceLocation, preferredName); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // domain library methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1124,6 +1332,15 @@ public String addDomainLibLibrary(String domainLibPath) throws WLSDeployArchiveI return newName; } + /** + * Replace a $DOMAIN_HOME/lib library in the archive. + * + * @param domainLibPath the $DOMAIN_HOME/lib library name or the path within the archive to replace + * @param sourceLocation the file system location of the new $DOMAIN_HOME/lib library to replace the existing one + * @return the archive path of the new $DOMAIN_HOME/lib library + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ public String replaceDomainLibLibrary(String domainLibPath, String sourceLocation) throws WLSDeployArchiveIOException { final String METHOD = "replaceDomainLibLibrary"; @@ -1180,51 +1397,168 @@ public void extractDomainLibLibrary(String archivePath, File extractToLocation) } /////////////////////////////////////////////////////////////////////////////////////////////// - // domain bin methods // + // classpath lib methods // /////////////////////////////////////////////////////////////////////////////////////////////// /** - * Adds a $DOMAIN_HOME/bin script to the archive. If a script with the same name already exists, this method - * assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding a - * numeric value onto the file's basename (e.g., myscript(1).cmd, myscript(2).cmd). + * This method adds a classpath library to the archive. If a library with the same name already exists, this + * method assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding + * a numeric value onto the file's basename (e.g., mylib(1).jar, mylib(2).jar). * - * @param domainBinPath - File name representing the actual path of the script file in the local or remote - * file system - * @return the relative path where the script is stored within the archive + * @param libPath - File name representing the actual path of the archive or directory in the local or remote + * file system + * @return the relative path where the library will be unpacked by the unpackApplications() method * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes * @throws IllegalArgumentException if the file or directory passed in does not exist */ - public String addDomainBinScript(String domainBinPath) throws WLSDeployArchiveIOException { - final String METHOD = "addDomainBinScript"; + public String addClasspathLibrary(String libPath) throws WLSDeployArchiveIOException { + final String METHOD = "addClasspathLibrary"; + LOGGER.entering(CLASS, METHOD, libPath); - LOGGER.entering(CLASS, METHOD, domainBinPath); - File filePath = new File(domainBinPath); - validateExistingFile(filePath, "domainBinPath", getArchiveFileName(), METHOD); + File filePath = new File(libPath); + validateExistingFile(filePath, "libPath", getArchiveFileName(), METHOD, true); + + String newName = addItemToZip(ARCHIVE_CPLIB_TARGET_DIR, filePath); - String newName = addItemToZip(ARCHIVE_DOM_BIN_TARGET_DIR, filePath); LOGGER.exiting(CLASS, METHOD, newName); return newName; } /** - * Get the list of $DOMAIN_HOME/bin script names in the archive. + * Replace a classpath library in the archive. * - * @return the list of $DOMAIN_HOME/bin script names + * @param libPath the classpath library name or the path within the archive to replace + * @param sourceLocation the file system location of the new classpath library to replace the existing one + * @return the archive path of the new classpath library + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceClasspathLibrary(String libPath, String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "replaceClasspathLibrary"; + LOGGER.entering(CLASS, METHOD, libPath, sourceLocation); + + String archivePath; + if (libPath.startsWith(ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP)) { + archivePath = libPath; + } else { + archivePath = ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP + libPath; + } + + getZipFile().removeZipEntries(archivePath); + String newName = addClasspathLibrary(sourceLocation); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Get the list of classpath library names in the archive. + * + * @return the list of $DOMAIN_HOME/lib library names * @throws WLSDeployArchiveIOException if an error occurs reading the archive */ - public List listDomainBinScripts() throws WLSDeployArchiveIOException { - final String METHOD = "listDomainBinScripts"; + public List listClasspathLibraries() throws WLSDeployArchiveIOException { + final String METHOD = "listClasspathLibraries"; LOGGER.entering(CLASS, METHOD); - List result = getZipFile().listZipEntries(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP); + List result = getZipFile().listZipEntries(ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP); // Remove the top-level directory entry from the list... - result.remove(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP); + result.remove(ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP); LOGGER.exiting(CLASS, METHOD, result); return result; } /** - * Extract the specified domain bin user script to the specified location (e.g., $DOMAIN_HOME/bin). + * Extract the classpath libraries in the archive to the specified domain home directory. + * + * @param domainHome the domain home directory + * @throws WLSDeployArchiveIOException in an error occurs reading the archive or writing the files. + * @throws IllegalArgumentException if the domain home directory is not a valid, existing directory + */ + public void extractClasspathLibraries(File domainHome) throws WLSDeployArchiveIOException { + final String METHOD = "extractClasspathLibraries"; + + LOGGER.entering(CLASS, METHOD, domainHome); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + extractDirectoryFromZip(ARCHIVE_CPLIB_TARGET_DIR, domainHome); + LOGGER.exiting(CLASS, METHOD); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // domain bin methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Adds a $DOMAIN_HOME/bin script to the archive. If a script with the same name already exists, this method + * assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding a + * numeric value onto the file's basename (e.g., myscript(1).cmd, myscript(2).cmd). + * + * @param domainBinPath - File name representing the actual path of the script file in the local or remote + * file system + * @return the relative path where the script is stored within the archive + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String addDomainBinScript(String domainBinPath) throws WLSDeployArchiveIOException { + final String METHOD = "addDomainBinScript"; + + LOGGER.entering(CLASS, METHOD, domainBinPath); + File filePath = new File(domainBinPath); + validateExistingFile(filePath, "domainBinPath", getArchiveFileName(), METHOD); + + String newName = addItemToZip(ARCHIVE_DOM_BIN_TARGET_DIR, filePath); + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Replace a $DOMAIN_HOME/bin script in the archive. + * + * @param domainBinPath the $DOMAIN_HOME/bin script name or the path within the archive to replace + * @param sourceLocation the file system location of the new $DOMAIN_HOME/bin script to replace the existing one + * @return the archive path of the new $DOMAIN_HOME/bin script + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceDomainBinScript(String domainBinPath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceDomainBinScript"; + LOGGER.entering(CLASS, METHOD, domainBinPath, sourceLocation); + + String archivePath; + if (domainBinPath.startsWith(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP)) { + archivePath = domainBinPath; + } else { + archivePath = ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP + domainBinPath; + } + + getZipFile().removeZipEntries(archivePath); + String newName = addDomainBinScript(sourceLocation); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Get the list of $DOMAIN_HOME/bin script names in the archive. + * + * @return the list of $DOMAIN_HOME/bin script names + * @throws WLSDeployArchiveIOException if an error occurs reading the archive + */ + public List listDomainBinScripts() throws WLSDeployArchiveIOException { + final String METHOD = "listDomainBinScripts"; + + LOGGER.entering(CLASS, METHOD); + List result = getZipFile().listZipEntries(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP); + // Remove the top-level directory entry from the list... + result.remove(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP); + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + + /** + * Extract the specified domain bin user script to the specified location (e.g., $DOMAIN_HOME/bin). * * @param archivePath the path of the script within the archive * @param extractToLocation the location to write the file @@ -1250,62 +1584,56 @@ public void removeDomainBinScripts() throws WLSDeployArchiveIOException { LOGGER.exiting(CLASS, METHOD); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // custom methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** - * This method adds a classpath library to the archive. If a library with the same name already exists, this - * method assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding - * a numeric value onto the file's basename (e.g., mylib(1).jar, mylib(2).jar). + * Add a custom file or directory to the archive. * - * @param libPath - File name representing the actual path of the archive or directory in the local or remote - * file system - * @return the relative path where the library will be unpacked by the unpackApplications() method + * @param customEntryPath the file system path to the custom file/directory to add + * @return the relative path where the custom file/directory is stored within the archive * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes * @throws IllegalArgumentException if the file or directory passed in does not exist */ - public String addClasspathLibrary(String libPath) throws WLSDeployArchiveIOException { - final String METHOD = "addClasspathLibrary"; + public String addCustomEntry(String customEntryPath) throws WLSDeployArchiveIOException { + final String METHOD = "addCustomEntry"; + LOGGER.entering(CLASS, METHOD, customEntryPath); - LOGGER.entering(CLASS, METHOD, libPath); - File filePath = new File(libPath); + File filePath = new File(customEntryPath); + validateExistingFile(filePath, "customEntryPath", getArchiveFileName(), METHOD, true); - validateExistingFile(filePath, "libPath", getArchiveFileName(), METHOD, true); + String newName = addItemToZip(ARCHIVE_CUSTOM_TARGET_DIR, filePath); - String newName = addItemToZip(ARCHIVE_CPLIB_TARGET_DIR, filePath); LOGGER.exiting(CLASS, METHOD, newName); return newName; } /** - * Get the list of classpath library names in the archive. + * Replace a custom file/directory in the archive. * - * @return the list of $DOMAIN_HOME/lib library names - * @throws WLSDeployArchiveIOException if an error occurs reading the archive + * @param customEntryPath the custom file/directory name or the path within the archive to replace + * @param sourceLocation the file system location of the new custom file/directory to replace the existing one + * @return the archive path of the new custom file/directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist */ - public List listClasspathLibraries() throws WLSDeployArchiveIOException { - final String METHOD = "listClasspathLibraries"; - - LOGGER.entering(CLASS, METHOD); - List result = getZipFile().listZipEntries(ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP); - // Remove the top-level directory entry from the list... - result.remove(ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP); - LOGGER.exiting(CLASS, METHOD, result); - return result; - } + public String replaceCustomEntry(String customEntryPath, String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "replaceCustomEntry"; + LOGGER.entering(CLASS, METHOD, customEntryPath, sourceLocation); - /** - * Extract the classpath libraries in the archive to the specified domain home directory. - * - * @param domainHome the domain home directory - * @throws WLSDeployArchiveIOException in an error occurs reading the archive or writing the files. - * @throws IllegalArgumentException if the domain home directory is not a valid, existing directory - */ - public void extractClasspathLibraries(File domainHome) throws WLSDeployArchiveIOException { - final String METHOD = "extractClasspathLibraries"; + String archivePath; + if (customEntryPath.startsWith(ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP)) { + archivePath = customEntryPath; + } else { + archivePath = ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP + customEntryPath; + } - LOGGER.entering(CLASS, METHOD, domainHome); - validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + getZipFile().removeZipEntries(archivePath); + String newName = addCustomEntry(sourceLocation); - extractDirectoryFromZip(ARCHIVE_CPLIB_TARGET_DIR, domainHome); - LOGGER.exiting(CLASS, METHOD); + LOGGER.exiting(CLASS, METHOD, newName); + return newName; } /** @@ -1316,11 +1644,12 @@ public void extractClasspathLibraries(File domainHome) throws WLSDeployArchiveIO */ public List listCustomFiles() throws WLSDeployArchiveIOException { final String METHOD = "listCustomFiles"; - LOGGER.entering(CLASS, METHOD); + List result = getZipFile().listZipEntries(ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP); // Remove the top-level directory entry from the list... result.remove(ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP); + LOGGER.exiting(CLASS, METHOD, result); return result; } @@ -1334,105 +1663,200 @@ public List listCustomFiles() throws WLSDeployArchiveIOException { */ public void extractCustomFiles(File domainHome) throws WLSDeployArchiveIOException { final String METHOD = "extractCustomFiles"; - LOGGER.entering(CLASS, METHOD, domainHome); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); extractDirectoryFromZip(ARCHIVE_CUSTOM_TARGET_DIR, domainHome); + LOGGER.exiting(CLASS, METHOD); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // scripts methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** - * Adds an application's deployment plan file to the archive. + * Add a script file to the archive. * - * @param planFile the deployment plan file name - * @param preferredName the preferred name of the file to add + * @param scriptFile the script file to add * @return the actual name of the file in the archive * @throws WLSDeployArchiveIOException if an error occurs adding the file - * @throws IllegalArgumentException if the file does not exist or the preferredName was empty or null + * @throws IllegalArgumentException if the file does not exist */ - public String addApplicationDeploymentPlan(String planFile, String preferredName) throws WLSDeployArchiveIOException { - final String METHOD = "addApplicationDeploymentPlan"; + public String addScript(String scriptFile) throws WLSDeployArchiveIOException { + final String METHOD = "addScript"; + LOGGER.entering(CLASS, METHOD, scriptFile); - LOGGER.entering(CLASS, METHOD, planFile, preferredName); - File filePath = new File(planFile); + File filePath = new File(scriptFile); + validateExistingFile(filePath, "scriptFile", getArchiveFileName(), METHOD); - validateExistingFile(filePath, "planFile", getArchiveFileName(), METHOD); - validateNonEmptyString(preferredName, "preferredName", METHOD); + String newName = addItemToZip(ARCHIVE_SCRIPTS_DIR, filePath); - String newName = addItemToZip(ARCHIVE_APPS_TARGET_DIR, filePath, preferredName); LOGGER.exiting(CLASS, METHOD, newName); return newName; } /** - * Adds a shared library's deployment plan file to the archive. + * Replace a script file in the archive. * - * @param planFile the deployment plan file name - * @param preferredName the preferred name of the file to add - * @return the actual name of the file in the archive - * @throws WLSDeployArchiveIOException if an error occurs adding the file - * @throws IllegalArgumentException if the file does not exist or the preferredName was empty or null + * @param scriptPath the script name or the path within the archive to replace + * @param sourceLocation the file system location of the new script file to replace the existing one + * @return the archive path of the new script file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist */ - public String addSharedLibraryDeploymentPlan(String planFile, String preferredName) - throws WLSDeployArchiveIOException { - final String METHOD = "addSharedLibraryDeploymentPlan"; + public String replaceScript(String scriptPath, String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "replaceScript"; + LOGGER.entering(CLASS, METHOD, scriptPath, sourceLocation); - LOGGER.entering(CLASS, METHOD, planFile, preferredName); - File filePath = new File(planFile); + String archivePath; + if (scriptPath.startsWith(ARCHIVE_SCRIPTS_DIR + ZIP_SEP)) { + archivePath = scriptPath; + } else { + archivePath = ARCHIVE_SCRIPTS_DIR + ZIP_SEP + scriptPath; + } - validateExistingFile(filePath, "planFile", getArchiveFileName(), METHOD); - validateNonEmptyString(preferredName, "preferredName", METHOD); + getZipFile().removeZipEntry(archivePath); + String newName = addScript(sourceLocation); - String newName = addItemToZip(ARCHIVE_SHLIBS_TARGET_DIR, filePath, preferredName); LOGGER.exiting(CLASS, METHOD, newName); return newName; } + /////////////////////////////////////////////////////////////////////////////////////////////// + // server keystore methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** - * Add a script file to the archive. + * Add a Server keystore file to the server's directory in the archive. * - * @param scriptFile the script file to add - * @return the actual name of the file in the archive - * @throws WLSDeployArchiveIOException if an error occurs adding the file - * @throws IllegalArgumentException if the file does not exist + * @param serverName the Server name used to segregate the directories + * @param keystoreFile the file to add + * @return the new location of the file to use in the model + * @throws WLSDeployArchiveIOException if an error occurs while archiving the file + * @throws IllegalArgumentException if the file does not exist or the clusterName is empty or null */ - public String addScript(String scriptFile) throws WLSDeployArchiveIOException { - final String METHOD = "addScript"; + public String addServerKeyStoreFile(String serverName, String keystoreFile) throws WLSDeployArchiveIOException { + final String METHOD = "addServerKeyStoreFile"; + LOGGER.entering(CLASS, METHOD, serverName, keystoreFile); - LOGGER.entering(CLASS, METHOD, scriptFile); - File filePath = new File(scriptFile); + File filePath = new File(keystoreFile); + validateNonEmptyString(serverName, "serverName", METHOD); + validateExistingFile(filePath, "keyStoreFile", getArchiveFileName(), METHOD); + + String newName = addItemToZip(ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP + serverName, filePath); - validateExistingFile(filePath, "scriptFile", getArchiveFileName(), METHOD); - String newName = addItemToZip(ARCHIVE_SCRIPTS_DIR, filePath); LOGGER.exiting(CLASS, METHOD, newName); return newName; } /** - * Add a Server Identity Key Store file to the server's directory in the archive. + * Replace a Server keystore in the archive. + * + * @param serverName the server name used to segregate directories, or null if the keystorePath + * is includes the server name already (e.g., myserver/keystore.jks or + * wlsdeploy/servers/myserver/keystore.jks) + * @param keystorePath the keystore name (e.g., keystore.jks) or an archive path + * (e.g., myserver/keystore.jks or wlsdeploy/servers/myserver/keystore.jks) + * @param sourceLocation the file system location of the new keystore file to replace the existing one + * @return the archive path of the new server keystore file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceServerKeyStoreFile(String serverName, String keystorePath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceServerKeyStoreFile"; + LOGGER.entering(CLASS, METHOD, serverName, keystorePath, sourceLocation); + + String archivePath = null; + String computedServerName = serverName; + if (keystorePath.startsWith(ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP)) { + archivePath = keystorePath; + computedServerName = getSegregationNameFromSegregatedArchivePath(serverName, keystorePath); + } else if (!StringUtils.isEmpty(serverName)) { + if (keystorePath.startsWith(serverName + ZIP_SEP)) { + archivePath = ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP + keystorePath; + } else { + archivePath = ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP + serverName + ZIP_SEP + keystorePath; + } + } + + if (StringUtils.isEmpty(computedServerName)) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01434", keystorePath, sourceLocation); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + // If we get here, archivePath should never be null! + // + getZipFile().removeZipEntry(archivePath); + String newName = addServerKeyStoreFile(computedServerName, sourceLocation); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // node manager keystore methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Add a Node Manager keystore file to the node manager directory in the archive. * - * @param serverName the Server name used to segregate the directories * @param keystoreFile the file to add * @return the new location of the file to use in the model * @throws WLSDeployArchiveIOException if an error occurs while archiving the file - * @throws IllegalArgumentException if the file does not exist or the clusterName is empty or null + * @throws IllegalArgumentException if the file does not exist */ - public String addServerKeyStoreFile(String serverName, String keystoreFile) throws WLSDeployArchiveIOException { - final String METHOD = "addServerKeyStoreFile"; + public String addNodeManagerKeyStoreFile(String keystoreFile) throws WLSDeployArchiveIOException { + final String METHOD = "addNodeManagerKeyStoreFile"; + LOGGER.entering(CLASS, METHOD, keystoreFile); - LOGGER.entering(CLASS, METHOD, serverName, keystoreFile); File filePath = new File(keystoreFile); - - validateNonEmptyString(serverName, "serverName", METHOD); validateExistingFile(filePath, "keyStoreFile", getArchiveFileName(), METHOD); - String newName = addItemToZip(ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP + serverName, filePath); + + String newName = addItemToZip(ARCHIVE_NODE_MANAGER_TARGET_DIR, filePath); + LOGGER.exiting(CLASS, METHOD, newName); return newName; } /** - * Add a WebAppContainer mime mapping file to the archive. + * Replace a Node Manager keystore file in the archive. + * + * @param keystorePath the keystore name or the path within the archive to replace + * @param sourceLocation the file system location of the new keystore file to replace the existing one + * @return the archive path of the new node manager keystore file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceNodeManagerKeyStoreFile(String keystorePath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceNodeManagerKeyStoreFile"; + LOGGER.entering(CLASS, METHOD, keystorePath, sourceLocation); + + String archivePath; + if (keystorePath.startsWith(ARCHIVE_NODE_MANAGER_TARGET_DIR + ZIP_SEP)) { + archivePath = keystorePath; + } else { + archivePath = ARCHIVE_NODE_MANAGER_TARGET_DIR + ZIP_SEP + keystorePath; + } + + getZipFile().removeZipEntry(archivePath); + String newName = addNodeManagerKeyStoreFile(sourceLocation); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // MIME mapping keystore methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Add a WebAppContainer MIME mapping file to the archive. * * @param mimeMappingFile the file to add * @return the new location of the file to use in the model @@ -1441,16 +1865,49 @@ public String addServerKeyStoreFile(String serverName, String keystoreFile) thro */ public String addMimeMappingFile(String mimeMappingFile) throws WLSDeployArchiveIOException { final String METHOD = "addMimeMappingFile"; - LOGGER.entering(CLASS, METHOD, mimeMappingFile); - File filePath = new File(mimeMappingFile); + File filePath = new File(mimeMappingFile); validateExistingFile(filePath, "mimeMappingFile", getArchiveFileName(), METHOD); + String newName = addItemToZip(ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP, filePath); + LOGGER.exiting(CLASS, METHOD, newName); return newName; } + /** + * Replace a WebAppContainer MIME mapping file in the archive. + * + * @param mimeMappingPath the MIME mapping name or the path within the archive to replace + * @param sourceLocation the file system location of the new MIME mapping file to replace the existing one + * @return the archive path of the new MIME mapping file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceMimeMappingFile(String mimeMappingPath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceMimeMappingFile"; + LOGGER.entering(CLASS, METHOD, mimeMappingPath, sourceLocation); + + String archivePath; + if (mimeMappingPath.startsWith(ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP)) { + archivePath = mimeMappingPath; + } else { + archivePath = ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP + mimeMappingPath; + } + + getZipFile().removeZipEntry(archivePath); + String newName = addMimeMappingFile(sourceLocation); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Coherence config file methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** * Add a Coherence configuration file to the archive. * @@ -1462,34 +1919,62 @@ public String addMimeMappingFile(String mimeMappingFile) throws WLSDeployArchive */ public String addCoherenceConfigFile(String clusterName, String configFile) throws WLSDeployArchiveIOException { final String METHOD = "addCoherenceConfigFile"; - LOGGER.entering(CLASS, METHOD, clusterName, configFile); - File filePath = new File(configFile); + File filePath = new File(configFile); validateNonEmptyString(clusterName, "clusterName", METHOD); validateExistingFile(filePath, "configFile", getArchiveFileName(), METHOD); + String newName = addItemToZip(ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + clusterName, filePath); + LOGGER.exiting(CLASS, METHOD, newName); return newName; } /** - * Add a Foreign Server binding file to the archive + * Replace a Coherence configuration file in the archive. * - * @param foreignServer the Foreign Server name used to segregate the directories - * @param configFile the file or directory to add - * @return the new location of the file to use in the model - * @throws WLSDeployArchiveIOException if an error occurs while archiving the file - * @throws IllegalArgumentException if the file does not exist or the foreignServer is empty or null + * @param clusterName the Coherence cluster name used to segregate directories, or null if the configPath + * is includes the cluster name already (e.g., mycluster/coherence-cache-config.xml or + * wlsdeploy/coherence/mycluster/coherence-cache-config.xml) + * @param configPath the Coherence config name (e.g., coherence-cache-config.xml) or an archive path + * (e.g., mycluster/coherence-cache-config.xml or + * wlsdeploy/coherence/mycluster/coherence-cache-config.xml) + * @param sourceLocation the file system location of the new Coherence config file to replace the existing one + * @return the archive path of the new Coherence config file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist */ - public String addForeignServerFile(String foreignServer, String configFile) throws WLSDeployArchiveIOException { - final String METHOD = "addForeignServerFile"; + public String replaceCoherenceConfigFile(String clusterName, String configPath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceCoherenceConfigFile"; + LOGGER.entering(CLASS, METHOD, clusterName, configPath, sourceLocation); + + String archivePath = null; + String computedClusterName = clusterName; + if (configPath.startsWith(ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP)) { + archivePath = configPath; + computedClusterName = getSegregationNameFromSegregatedArchivePath(clusterName, configPath); + } else if (!StringUtils.isEmpty(clusterName)) { + if (configPath.startsWith(clusterName + ZIP_SEP)) { + archivePath = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + configPath; + } else { + archivePath = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + clusterName + ZIP_SEP + configPath; + } + } + + if (StringUtils.isEmpty(computedClusterName)) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01435", configPath, sourceLocation); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + // If we get here, archivePath should never be null! + // + getZipFile().removeZipEntry(archivePath); + String newName = addCoherenceConfigFile(computedClusterName, sourceLocation); - LOGGER.entering(CLASS, METHOD, foreignServer, configFile); - File filePath = new File(configFile); - validateNonEmptyString(foreignServer, "foreignServerName", METHOD); - validateExistingFile(filePath, "configFile", getArchiveFileName(), METHOD, true); - String newName = addItemToZip(ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServer, filePath); LOGGER.exiting(CLASS, METHOD, newName); return newName; } @@ -1516,6 +2001,10 @@ public String addCoherenceConfigFileFromUrl(String clusterName, URL urlForConfig return newName; } + /////////////////////////////////////////////////////////////////////////////////////////////// + // Coherence persistence directory file methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + /** * Add an empty directory to the archive file for the coherence cluster using the persistence directory type value. * The directory type is stored under the unique coherence cluster name. @@ -1524,6 +2013,7 @@ public String addCoherenceConfigFileFromUrl(String clusterName, URL urlForConfig * @param directoryType type of the coherence cluster persistence directory * @return unique directory name * @throws WLSDeployArchiveIOException unexpected exception adding the directory name to the archive file + * @throws IllegalArgumentException if the clusterName or directoryType is empty or null */ public String addCoherencePersistenceDirectory(String clusterName, String directoryType) throws WLSDeployArchiveIOException { @@ -1531,7 +2021,8 @@ public String addCoherencePersistenceDirectory(String clusterName, String direct LOGGER.entering(CLASS, METHOD, clusterName, directoryType); validateNonEmptyString(clusterName, "clusterName", METHOD); - validateNonEmptyString(directoryType, "fileStoreName", METHOD); + validateNonEmptyString(directoryType, "directoryType", METHOD); + String newName = addEmptyDirectoryToZip(ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + clusterName, directoryType); @@ -1540,36 +2031,226 @@ public String addCoherencePersistenceDirectory(String clusterName, String direct } /** - * Add an empty directory to the archive file using the File Store name. + * Replace an empty directory to the archive file for the coherence cluster using the persistence + * directory type value. + * + * @param clusterName name of the coherence cluster to which the persistence directory belongs + * @param directoryType type of the coherence cluster persistence directory + * @return the archive path to the new directory + * @throws WLSDeployArchiveIOException unexpected exception adding the directory name to the archive file + * @throws IllegalArgumentException if the clusterName or directoryType is empty or null + */ + public String replaceCoherencePersistenceDirectory(String clusterName, String directoryType) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceCoherencePersistenceDirectory"; + LOGGER.entering(CLASS, METHOD, clusterName, directoryType); + + validateNonEmptyString(clusterName, "clusterName", METHOD); + validateNonEmptyString(directoryType, "directoryType", METHOD); + + String clusterArchivePath = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + clusterName; + getZipFile().removeZipEntries(clusterArchivePath + ZIP_SEP + directoryType + ZIP_SEP); + String newName = addEmptyDirectoryToZip(clusterArchivePath, directoryType); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // JMS foreign server binding file methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Add a Foreign Server binding file to the archive. + * + * @param foreignServer the Foreign Server name used to segregate the directories + * @param configFile the file or directory to add + * @return the new location of the file to use in the model + * @throws WLSDeployArchiveIOException if an error occurs while archiving the file + * @throws IllegalArgumentException if the file does not exist or the foreignServer is empty or null + */ + public String addForeignServerFile(String foreignServer, String configFile) throws WLSDeployArchiveIOException { + final String METHOD = "addForeignServerFile"; + LOGGER.entering(CLASS, METHOD, foreignServer, configFile); + + File filePath = new File(configFile); + validateNonEmptyString(foreignServer, "foreignServerName", METHOD); + validateExistingFile(filePath, "configFile", getArchiveFileName(), METHOD, true); + + String newName = addItemToZip(ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServer, filePath); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Replace a Foreign Server binding file in the archive. + * + * @param foreignServerName the Foreign Server name used to segregate the directories + * @param configPath the Foreign Server binding file name or an archive path + * @param sourceLocation the file system location of the new Foreign Server binding file to replace the existing one + * @return the archive path of the new Foreign Server binding file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceForeignServerFile(String foreignServerName, String configPath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceForeignServerFile"; + LOGGER.entering(CLASS, METHOD, foreignServerName, configPath, sourceLocation); + + String archivePath = null; + String computedForeignServerName = foreignServerName; + if (configPath.startsWith(ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP)) { + archivePath = configPath; + computedForeignServerName = getSegregationNameFromSegregatedArchivePath(foreignServerName, configPath); + } else if (!StringUtils.isEmpty(foreignServerName)) { + if (configPath.startsWith(foreignServerName + ZIP_SEP)) { + archivePath = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + configPath; + } else { + archivePath = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServerName + ZIP_SEP + configPath; + } + } + + if (StringUtils.isEmpty(computedForeignServerName)) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01436", configPath, sourceLocation); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + // If we get here, archivePath should never be null! + // + getZipFile().removeZipEntry(archivePath); + String newName = addCoherenceConfigFile(computedForeignServerName, sourceLocation); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // file store methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Add an empty File Store directory to the archive file. * * @param fileStoreName name of the File Store * @return unique directory name created using the file store name * @throws WLSDeployArchiveIOException unexpected exception adding the directory name to the archive file + * @throws IllegalArgumentException if the file or directory passed in does not exist */ public String addFileStoreDirectory(String fileStoreName) throws WLSDeployArchiveIOException { final String METHOD = "addFileStoreDirectory"; LOGGER.entering(CLASS, METHOD, fileStoreName); + validateNonEmptyString(fileStoreName, "fileStoreName", METHOD); + String newName = addEmptyDirectoryToZip(ARCHIVE_FILE_STORE_TARGET_DIR, fileStoreName); + LOGGER.exiting(CLASS, METHOD, newName); return newName; } /** - * Add a Node Manager Identity Key Store file to the node manager directory in the archive. + * Replace an empty File Store directory in the archive file. * - * @param keystoreFile the file to add - * @return the new location of the file to use in the model - * @throws WLSDeployArchiveIOException if an error occurs while archiving the file - * @throws IllegalArgumentException if the file does not exist + * @param fileStorePath the File Store name or path into the archive file to replace + * @return the archive path to the new File Store directory. + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist */ - public String addNodeManagerKeyStoreFile(String keystoreFile) throws WLSDeployArchiveIOException { - final String METHOD = "addNodeManagerKeyStoreFile"; + public String replaceFileStoreDirectory(String fileStorePath) throws WLSDeployArchiveIOException { + final String METHOD = "replaceFileStoreDirectory"; + LOGGER.entering(CLASS, METHOD, fileStorePath); + + validateNonEmptyString(fileStorePath, "fileStorePath", METHOD); + + String archivePath; + if (fileStorePath.startsWith(ARCHIVE_FILE_STORE_TARGET_DIR + ZIP_SEP)) { + archivePath = fileStorePath; + } else { + archivePath = ARCHIVE_FILE_STORE_TARGET_DIR + ZIP_SEP + fileStorePath; + } + if (!archivePath.endsWith(ZIP_SEP)) { + archivePath += ZIP_SEP; + } + String computedFileStoreName = getFileStoreNameFromArchivePath(archivePath); + + getZipFile().removeZipEntries(archivePath); + String newName = addEmptyDirectoryToZip(ARCHIVE_FILE_STORE_TARGET_DIR, computedFileStoreName); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // database wallet methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Add a database wallet to the archive. + * + * @param walletName the name for this database wallet (used to segregate wallets) + * @param sourceLocation the file system location for the wallet file (zip file or single file) or directory + * @return the archive path to the wallet directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the wallet name if empty or the wallet file/directory does not exist + */ + public String addDatabaseWallet(String walletName, String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "addDatabaseWallet"; + LOGGER.entering(CLASS, METHOD, walletName, sourceLocation); + + File sourceFile = FileUtils.getCanonicalFile(sourceLocation); + validateNonEmptyString(walletName, "walletName", METHOD); + validateExistingFile(sourceFile, "sourceLocation", getArchiveFileName(), METHOD, true); + + String newName; + if (sourceFile.isDirectory()) { + newName = addItemToZip(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName, sourceFile, false); + } else { + newName = addItemToZip(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName, sourceFile); + + // When adding a file (e.g., zip file), the wallet name returned should always point + // to the wallet directory containing the file. + // + newName = getDatabaseWalletArchivePathFromAddedFile(ARCHIVE_DB_WALLETS_DIR, newName); + } + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Replace a database wallet in the archive. + * + * @param walletPath the name of archive path of the database wallet directory + * @param sourceLocation the file system location of the database wallet file/directory to replace the existing one + * @return the archive path to the wallet directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the wallet name if empty or the wallet file/directory does not exist + */ + public String replaceDatabaseWallet(String walletPath, String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "addDatabaseWallet"; + LOGGER.entering(CLASS, METHOD, walletPath, sourceLocation); + + validateNonEmptyString(walletPath, "walletPath", METHOD); + + String archivePath; + String computedWalletName; + if (walletPath.startsWith(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP)) { + archivePath = walletPath; + computedWalletName = getDatabaseWalletNameFromArchivePath(walletPath); + } else { + archivePath = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletPath; + computedWalletName = walletPath; + } + if (!archivePath.endsWith(ZIP_SEP)) { + archivePath += ZIP_SEP; + } + + getZipFile().removeZipEntries(archivePath); + String newName = addDatabaseWallet(computedWalletName, sourceLocation); - LOGGER.entering(CLASS, METHOD, keystoreFile); - File filePath = new File(keystoreFile); - validateExistingFile(filePath, "keyStoreFile", getArchiveFileName(), METHOD); - String newName = addItemToZip(ARCHIVE_NODE_MANAGER_TARGET_DIR, filePath); LOGGER.exiting(CLASS, METHOD, newName); return newName; } @@ -1581,12 +2262,15 @@ public String addNodeManagerKeyStoreFile(String keystoreFile) throws WLSDeployAr * @param walletName the name of the database wallet to extract (e.g., rcu) * @return the full path to the directory containing the extracted wallet files or null, if no wallet was found. * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files. + * @throws IllegalArgumentException if the wallet name if empty or the domain home directory does not exist */ public String extractDatabaseWallet(File domainHome, String walletName) throws WLSDeployArchiveIOException { final String METHOD = "extractDatabaseWallet"; LOGGER.entering(CLASS, METHOD, domainHome, walletName); + validateNonEmptyString(walletName, "walletName", METHOD); + String extractPath = null; if (DEFAULT_RCU_WALLET_NAME.equals(walletName)) { // handle archive files with deprecated path, as needed @@ -1607,6 +2291,50 @@ public String extractDatabaseWallet(File domainHome, String walletName) throws W return extractPath; } + /////////////////////////////////////////////////////////////////////////////////////////////// + // OPSS wallet methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Add the OPSS wallet to the archive. + * + * @param sourceLocation The file/directory to add + * @return the archive path to the OPSS wallet directory + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files. + * @throws IllegalArgumentException if the provided source location file/directory does not exist + */ + public String addOPSSWallet(String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "addOPSSWallet"; + LOGGER.entering(CLASS, METHOD, sourceLocation); + + String newName = addOPSSWallet(sourceLocation, true); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Replace the OPSS wallet in the archive. + * + * @param sourceLocation The file/directory to use to replace the existing one + * @return the archive path to the new OPSS wallet directory + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files. + * @throws IllegalArgumentException if the provided source location file/directory does not exist + */ + public String replaceOPSSWallet(String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "addOPSSWallet"; + LOGGER.entering(CLASS, METHOD, sourceLocation); + + File sourceFile = FileUtils.getCanonicalFile(sourceLocation); + validateExistingFile(sourceFile, "sourceLocation", getArchiveFileName(), METHOD, true); + + getZipFile().removeZipEntries(ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP); + String newName = addOPSSWallet(sourceLocation, false); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + /** * Extract the OPSS wallet from the archive. * @@ -1643,69 +2371,6 @@ public String extractOPSSWallet(File domainHome) throws WLSDeployArchiveIOExcept return extractPath; } - /** - * Return the manifest for the specified path in the archive, if present. - * The path may refer to a packaged EAR/JAR/WAR, or an exploded entry. - * - * @param sourcePath the path to be checked - * @return the Manifest object, or null - * @throws WLSDeployArchiveIOException if there is a problem reading the archive, or the manifest - */ - public Manifest getManifest(String sourcePath) throws WLSDeployArchiveIOException { - try { - if (containsFile(sourcePath)) { - // a jarred app or library in the archive. - try (ZipInputStream zipStream = new ZipInputStream(getZipFile().getZipEntry(sourcePath))) { - // JarInputStream.getManifest() has problems if MANIFEST.MF is not the first entry, - // so use ZipInputStream and search for the specific entry. - ZipEntry zipEntry; - while ((zipEntry = zipStream.getNextEntry()) != null) { - if (JarFile.MANIFEST_NAME.equals(zipEntry.getName())) { - Manifest manifest = new Manifest(zipStream); - zipStream.closeEntry(); - return manifest; - } - zipStream.closeEntry(); - } - } - } else if (containsPath(sourcePath)) { - // an exploded app or library in the archive. - String manifestPath = sourcePath + "/" + JarFile.MANIFEST_NAME; - if (containsFile(manifestPath)) { - try (InputStream inStream = getZipFile().getZipEntry(manifestPath)) { - return new Manifest(inStream); - } - } - } - } catch (IOException e) { - WLSDeployArchiveIOException aioe = new WLSDeployArchiveIOException("WLSDPLY-01426", sourcePath, - getArchiveFileName(), e.getLocalizedMessage()); - LOGGER.throwing(aioe); - throw aioe; - } - return null; - } - - /** - * This method removes all binaries from the archive. This method is intended to - * be invoked by discovery to remove binaries from a previous run that might - * exist in the archive to make it possible for discovery to be truly idempotent. - * - * @throws WLSDeployArchiveIOException if an error is encountered removing the binaries - */ - public void removeAllBinaries() throws WLSDeployArchiveIOException { - getZipFile().removeZipEntries(WLSDPLY_ARCHIVE_BINARY_DIR + ZIP_SEP); - } - - /** - * Closes the underlying zip file and any open streams. - */ - public void close() { - if (getZipFile() != null) { - getZipFile().close(); - } - } - /////////////////////////////////////////////////////////////////////////////////////////// // Protected Helper methods // /////////////////////////////////////////////////////////////////////////////////////////// @@ -1733,6 +2398,58 @@ protected void setZipFile(WLSDeployZipFile zipFile) { this.zipFile = zipFile; } + protected static FileOrDirectoryType getFileType(ArchiveEntryType type) { + final String METHOD = "getFileType"; + LOGGER.entering(CLASS, METHOD, type); + + FileOrDirectoryType result = FileOrDirectoryType.EITHER; + switch(type) { + case COHERENCE: + case COHERENCE_PERSISTENCE_DIR: + case DB_WALLET: + case FILE_STORE: + case OPSS_WALLET: + case STRUCTURED_APPLICATION: + result = FileOrDirectoryType.DIRECTORY_ONLY; + break; + + case COHERENCE_CONFIG: + case DOMAIN_BIN: + case JMS_FOREIGN_SERVER: + case MIME_MAPPING: + case NODE_MANAGER_KEY_STORE: + case SCRIPT: + case SERVER_KEYSTORE: + result = FileOrDirectoryType.FILE_ONLY; + break; + + // FIXME - need to log if receiving an unknown type + } + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + + protected static boolean isSegregatedType(ArchiveEntryType type) { + final String METHOD = "isSegregatedType"; + LOGGER.entering(CLASS, METHOD, type); + + boolean result = false; + switch(type) { + case COHERENCE: + case COHERENCE_CONFIG: + case COHERENCE_PERSISTENCE_DIR: + case DB_WALLET: + case JMS_FOREIGN_SERVER: + case SERVER_KEYSTORE: + result = true; + break; + } + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + protected String addEmptyDirectoryToZip(String zipPathPrefix, String directoryNameToAdd) throws WLSDeployArchiveIOException { final String METHOD = "addEmptyDirectoryToZip"; @@ -1863,6 +2580,35 @@ protected String addUrlToZip(String zipPathPrefix, URL url, String extension, bo return newName; } + protected List getZipListEntries(String prefix, String name, FileOrDirectoryType type) + throws WLSDeployArchiveIOException { + final String METHOD = "getZipListEntries"; + LOGGER.entering(CLASS, METHOD, prefix, name, type.name()); + + validateNonEmptyString(prefix, "prefix", METHOD); + validateNonEmptyString(name, "name", METHOD); + + String archivePrefix = prefix; + if (!archivePrefix.endsWith(ZIP_SEP)) { + archivePrefix += ZIP_SEP; + } + + String archivePath = archivePrefix + name; + List zipEntries = getZipFile().listZipEntries(archivePath); + + ListIterator zipEntriesIterator = zipEntries.listIterator(); + while (zipEntriesIterator.hasNext()) { + String zipEntry = zipEntriesIterator.next(); + + if (filterEntry(zipEntry, archivePrefix, name, type)) { + zipEntriesIterator.remove(); + } + } + + LOGGER.exiting(CLASS, METHOD, zipEntries); + return zipEntries; + } + protected void extractWallet(File domainHome, String extractPath, List zipEntries, String deprecationKey, String fromDir, String toDir) throws WLSDeployArchiveIOException { final String METHOD = "extractWallet"; @@ -1958,6 +2704,42 @@ protected void unzipZippedArchiveFileEntry(String zippedItemToExtract, File extr LOGGER.exiting(CLASS, METHOD); } + protected String addOPSSWallet(String sourceLocation, boolean verifyNotExists) throws WLSDeployArchiveIOException { + final String METHOD = "addOPSSWallet"; + LOGGER.entering(CLASS, METHOD, sourceLocation, verifyNotExists); + + File sourceFile = FileUtils.getCanonicalFile(sourceLocation); + validateExistingFile(sourceFile, "sourceLocation", getArchiveFileName(), METHOD, true); + + // Because there is only one OPSS wallet per domain, we have to make sure that + // there is no existing OPSS wallet in the archive prior to adding one. + // + if (verifyNotExists) { + List opssWalletEntries = getArchiveEntries(ArchiveEntryType.OPSS_WALLET); + if (!opssWalletEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01437", getArchiveFileName(), opssWalletEntries.size()); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + } + + String newName; + if (sourceFile.isDirectory()) { + newName = addItemToZip(ARCHIVE_OPSS_WALLET_PATH, sourceFile); + } else { + addItemToZip(ARCHIVE_OPSS_WALLET_PATH, sourceFile); + + // When adding a file (e.g., zip file), the wallet name returned should always point + // to the wallet directory containing the file. + // + newName = ARCHIVE_OPSS_WALLET_PATH; + } + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + protected void extractDirectoryFromZip(String directoryName, File extractToLocation) throws WLSDeployArchiveIOException { extractDirectoryFromZip(directoryName, directoryName, extractToLocation); @@ -2174,6 +2956,18 @@ private String addSingleFileToZip(File itemToAdd, String preferredName, String c return newName; } + private boolean filterEntry(String entry, String prefix, String name, FileOrDirectoryType allowedType) { + boolean result = true; + + String prefixStrippedZipEntry = entry.substring(prefix.length()); + String directoryName = name.endsWith(ZIP_SEP) ? name : name + ZIP_SEP; + if ((prefixStrippedZipEntry.startsWith(directoryName) && allowedType != FileOrDirectoryType.FILE_ONLY) || + (prefixStrippedZipEntry.equals(name) && allowedType != FileOrDirectoryType.DIRECTORY_ONLY)){ + result = false; + } + return result; + } + // TODO - remove me and replace calls with addItemToZip() to get the correct behavior. private String walkDownFolders(String zipPrefix, File zipPath) throws WLSDeployArchiveIOException { String newSourceName = null; @@ -2294,4 +3088,59 @@ private static FileInputStream getFileInputStream(File f, String itemName, Strin } return inputStream; } + + private String getSegregationNameFromSegregatedArchivePath(String segregationName, String archivePath) { + String result = null; + if (StringUtils.isEmpty(segregationName)) { + String[] pathComponents = archivePath.split(ZIP_SEP); + if (pathComponents.length > 3) { + result = pathComponents[2]; + } + } else { + result = segregationName; + } + return result; + } + + private String getFileStoreNameFromArchivePath(String archivePath) { + String result = archivePath; + + if (result.endsWith(ZIP_SEP)) { + result = result.substring(0, result.length() - 1); + } + int lastIndex = result.lastIndexOf(ZIP_SEP); + if (lastIndex != -1) { + result = result.substring(lastIndex + 1); + } + return result; + } + + private String getDatabaseWalletNameFromArchivePath(String archivePath) { + String result = archivePath; + + if (result.endsWith(ZIP_SEP)) { + result = result.substring(0, result.length() - 1); + } + if (result.startsWith(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP)) { + String[] comps = result.split(ZIP_SEP); + if (comps.length > 2) { + result = comps[2]; + } + } + return result; + } + + private String getDatabaseWalletArchivePathFromAddedFile(String walletParentPath, String walletFileName) { + String result = null; + + int fromIndex = walletParentPath.length(); + if (!walletParentPath.endsWith(ZIP_SEP)) { + fromIndex++; + } + int endIndex = walletParentPath.indexOf(ZIP_SEP, fromIndex); + if (endIndex != -1) { + result = walletFileName.substring(0, endIndex); + } + return result; + } } diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index 501a3a07bb..1c246bd2be 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -207,6 +207,10 @@ WLSDPLY-01430=Failed to extract wallet file {0} from archive file {1} because th WLSDPLY-01431=Zip slip security vulnerability detected in archive file {0} entry {1} because entry extract location {2} is not under the specified extract path {3} WLSDPLY-01432=Failed to extract zip file {0} originating from archive file entry {1} to directory {2}: {3} WLSDPLY-01433=Archive file {0} contains the OPSS wallet in a deprecated location {1}. Please move to the new location {2}. +WLSDPLY-01434=Could not determine a valid archive path with an empty server name and keystore path {0} to replace server key store file with {1} +WLSDPLY-01435=Could not determine a valid archive path with an empty cluster name and Coherence config path {0} to replace Coherence cluster config file with {1} +WLSDPLY-01436=Could not determine a valid archive path with an empty foreign server name and JMS foreign server binding path {0} to replace JMS foreign server binding file with {1} +WLSDPLY-01437=Failed to add OPSS Wallet to archive because the archive file {0} already contains an OPSS wallet with {1} entries. # oracle.weblogic.deploy.util.WLSDeployZipFile.java WLSDPLY-01500=The zip file {0} has the saved entry {1} @@ -1737,6 +1741,22 @@ WLSDPLY-30003=The -archive_file argument's parent directory {0} does not exist a WLSDPLY-30004=Failed to list all entries in archive file {0}: {1}. WLSDPLY-30005=Failed to list {0} entries with name {1} in archive file {2}: {3}. WLSDPLY-30006=Failed to list all {0} entries in archive file {1}: {2}. -WLSDPLY-30007=The -source {0} location does not exist -WLSDPLY-30008=Failed to add {0} {1} to archive file {2}: {3}. -WLSDPLY-30009=Failed to add {0} {1} with overwrite value {2} to archive file {3}: {4}. +WLSDPLY-30007=Failed to list {0} entries in {1} with name {2} in archive file {3}: {4}. +WLSDPLY-30008=Failed to list all {0} entries in {1} in archive file {2}: {3}. +WLSDPLY-30009=The -source {0} location does not exist +WLSDPLY-30010=Failed to add {0} {1} to archive file {2}: {3}. +WLSDPLY-30011=Failed to add {0} {1} with overwrite value {2} to archive file {3}: {4}. +WLSDPLY-30012=Failed to add server keystore {0} for server {1} to archive file {2}: {3}. +WLSDPLY-30013=Failed to add server keystore {0} for server {1} with overwrite value {2} to archive file {3}: {4}. +WLSDPLY-30014=Failed to add Coherence config file {0} for cluster {1} to archive file {2}: {3}. +WLSDPLY-30015=Failed to add Coherence config file {0} for cluster {1} with overwrite value {2} to archive file {3}: {4}. +WLSDPLY-30016=Failed to add Coherence persistence directory type {0} for cluster {1} to archive file {2}: {3}. +WLSDPLY-30017=Failed to add Coherence persistence directory type {0} for cluster {1} with overwrite value {2} to archive file {3}: {4}. +WLSDPLY-30018=Failed to add JMS foreign server binding file {0} for JMS foreign server {1} to archive file {2}: {3}. +WLSDPLY-30019=Failed to add JMS foreign server binding file {0} for JMS foreign server {1} with overwrite value {2} to archive file {3}: {4}. +WLSDPLY-30020=Failed to add file store directory {0} to archive file {1}: {2}. +WLSDPLY-30021=Failed to add file store directory {0} with overwrite value {1} to archive file {2}: {3}. +WLSDPLY-30022=Failed to add {0} name {1} from {2} to archive file {3}: {4}. +WLSDPLY-30023=Failed to add {0} name {1} from {2} with overwrite value {3} to archive file {4}: {5}. +WLSDPLY-30024=Failed to add OPSS wallet from {0} to archive file {1}: {2}. +WLSDPLY-30025=Failed to add OPSS wallet from {0} with overwrite value {1} to archive file {2}: {3}. diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java new file mode 100644 index 0000000000..07f11e9672 --- /dev/null +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.StandardCopyOption; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; + +import oracle.weblogic.deploy.util.WLSDeployZipFileTest; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ArchiveHelperListTest { + public static final File UNIT_TEST_SOURCE_DIR = new File(WLSDeployZipFileTest.UNIT_TEST_SOURCE_DIR); + private static final File UNIT_TEST_TARGET_DIR = + new File(new File(WLSDeployZipFileTest.UNIT_TEST_TARGET_DIR, "archiveHelper"), "list"); + + private static final Path ARCHIVE_HELPER_SOURCE_ZIP = + new File(UNIT_TEST_SOURCE_DIR, "archive-helper-test.zip").toPath(); + private static final Path ARCHIVE_HELPER_TARGET_ZIP = + new File(UNIT_TEST_TARGET_DIR, "archive-helper-test.zip").toPath(); + private static final String ARCHIVE_HELPER_VALUE = ARCHIVE_HELPER_TARGET_ZIP.toFile().getAbsolutePath(); + + private static final String[] LIST_APP_FILE_EXPECTED = new String[] {"wlsdeploy/applications/my-app.war"}; + + private static final String[] LIST_APP_DIR_EXPECTED = new String[] { + "wlsdeploy/applications/my-other-app/", + "wlsdeploy/applications/my-other-app/META-INF/", + "wlsdeploy/applications/my-other-app/META-INF/maven/", + "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/", + "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/", + "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.properties", + "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.xml", + "wlsdeploy/applications/my-other-app/META-INF/MANIFEST.MF", + "wlsdeploy/applications/my-other-app/WEB-INF/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/platform/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/platform/GetListenAddressServlet.class", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/platform/ListenAddressAndPort.class", + "wlsdeploy/applications/my-other-app/WEB-INF/web.xml", + "wlsdeploy/applications/my-other-app/WEB-INF/weblogic.xml" + }; + + private static final String[] LIST_APPS_EXPECTED = new String[LIST_APP_DIR_EXPECTED.length + 3]; + + static { + String[] files = new String[] { + "wlsdeploy/applications/my-app.war", + "wlsdeploy/applications/my-app.xml", + "wlsdeploy/applications/my-other-app.war" + }; + System.arraycopy(files, 0, LIST_APPS_EXPECTED, 0, 3); + System.arraycopy(LIST_APP_DIR_EXPECTED, 0, LIST_APPS_EXPECTED, 3, LIST_APP_DIR_EXPECTED.length); + } + + @BeforeAll + static void initialize() throws Exception { + if(!UNIT_TEST_TARGET_DIR.exists() && !UNIT_TEST_TARGET_DIR.mkdirs()) { + throw new Exception("Unable to create unit test directory: " + UNIT_TEST_TARGET_DIR); + } + Files.copy(ARCHIVE_HELPER_SOURCE_ZIP, ARCHIVE_HELPER_TARGET_ZIP, StandardCopyOption.REPLACE_EXISTING); + } + + @Test + void testListAppFile_ReturnsExpectedName() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "application", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-app.war" + }; + String expectedPath = LIST_APP_FILE_EXPECTED[0]; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(1, outputLines.length, "expected list applications my-app.war to return 1 entry"); + assertEquals(expectedPath, outputLines[0],"expected " + expectedPath); + } + + @Test + void testListAppDirectory_ReturnsExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "application", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-other-app" + }; + List expectedPaths = Arrays.asList(LIST_APP_DIR_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list applications my-other-app to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListApps_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "application", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList(LIST_APP_DIR_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + } +} diff --git a/core/src/test/resources/archive-helper-test.zip b/core/src/test/resources/archive-helper-test.zip new file mode 100644 index 0000000000000000000000000000000000000000..0bf35f2815f2932a1a619cdf24505508fd7c067b GIT binary patch literal 90672 zcmeFZ1yJ3|wmyoxLvVL@cXxLP?(S|0?k>UI-CaX)cY-?vC%8W{bIzGFxik07z3=~j zRj+Dx)ndcm#n-F5zwXuR>+YYt6fg)Bz>n8QO-9vUe)-1_GyrS>S1U&&V>>HbcRGDL zJ1cWTeJ68U8%H`7Wk>*Ee#$|^ALi@^4FCvo4F~`Lg7WsS@^64Y-XQ?U^q7<(Ml4DP z-~a$n-aaDub3ki%nzsUIUG*J)fj(3?(BIJ9F!%|&Lfu$7;RqF%GdL;X6uq@az`@KM z1kqRjAXz_15ksMUlI@P|Q5Q zICRlhGz2WWC@{FI{6ePh`gkHBoyVgq^6;4KV@c_Bm)}FfJB-wKvwfJM0R(h4g%5!& zv#ZxgAicH-r?~U-Xp1ELQ6s)~XqE{XZNWz*`vrGs82I!FjYLSGj!N|n*B=RDgXrPu z(9k8%$w-IHmh}XqkGUY_gVnk${AmQwBr5|+`59^kD57k|`zXnZ9gPw~Rn)X8bn17f zB3br$rku-(I+8svs0c`LT*g+?E~~JTTus-<@uF6G(1*tkVnc@4!MVrsRltIe!yO?n z1@Ch?W?|eua~s=7jC>J3(Gw!XMnaAgKpD1zvd*BcIETk*(NwIomYRk>N>Z}5xOi-G z(p7UujF!ilAq6v#S-iB8usU=f=4%j==84v%&^4tlxf*i+p6xx5=Zsd<{$x|q$`vAW zzeY&qS`=E)^{fJRinLcagpYccP(!{&)ZmA#(vuUqx^{bDEAgAU;n>&`p4nyM z^jms5>(q0}g;sf;@HEP*qUqMz=_<%ZX=oderXgPXfknqtj z9ag!i-1qw@QOpk{RqoZ->gU$_;K3P5lSNqBHiUC2w=*y)y4W&7%Ra|-Ew#%t^qdFL z1>+kKhvp*0b0NqIx#_l+Arq(DsvtiTWmV8Q-n4bn#&VxvnP0n-xV3h`LN2V1A=o?NijMm55T~7=vzIq+#JF3X(S7maKCX4Z4aur^x=7 z9m&y$5lVVCz!W6{aq2vmIu^&vmuY=bzt6WbbbjzBo5LL;UZF`)H+m?E$ph6wSxScq zcCig4`8~yf&Pr0MTG>^Ki3(kTm00};orh4&W0#vz=Qqbob@>lYgGl0(Hi#XCFw#*R z9UK@~L#i#~f~!w!b_oq(L?Vd{#j((Gv_N3#u`#4Zb*?D{7<+yDK@i`M-Zg+7M)H<) z(l|iZBR);*Zq3HE9xpk5Ik=CLDTAd)D~8_nUApI?{sZ zXrloss@L`DzMjtB{YD>jrjge2Zlu7B>H(Z%EL;X(d*CcSbup2BXmj$UaUsP63278T z!E01Gg^dEPA3so^!8N1`rqZD7RvCSO;Qe>T6eZ>Ki_pkY%eZ!r6bJJ!$)XT<97@N% zv9uu$zWPH!dz_Ijezo=}I^dNvGQ}N&l%nSChTrBZkDi^ZF_V`mwzVPxX&~bIN~>t2 zdir`|8)rQ8r!@kgPpKi%zrsTzEXhF?uYlu9p;dcX?uc&Cv~NE^obVLW;}Az|zHC;p zv2D@k9L$+ei_gZ?F%Hq5v6z1e$e=DIp+UetsNSNa>g#GU*8cLB@4{z%pqaFo!-sb z>hxBk$j&de(eN{w4*7k6I0G$c)2DVp&t$tggVA^~0fX<~R9y6I_ywIBu7zSF8UoD% zti*YzeUs?kTLoei&Yyku^JAzij4VhMGN~*HVGS{&)_LXrxU9tu*0Co6ef`vIGAjkS zy2c4AgBRxhm5d~5hfOMOEc~>&XhuzUM&p(kcQ~$#@q_dg3y1*bmo(+W?WZSW7*+ee zb`QYi__OH7VmvuQ%yrYqGtCQS>ApaLs0h!Y-g~OnuN2DEA3KybmXeDyzlg+>Dnxn( zLusjJBFV`;97gb!nkf79YM9xcLw^Hd^}GuN`N-!cw_{9pN)ENj**=)bn?xFl7t=U; zbltHe^iHxZEbBSA0g<~@Q_TskMi1JtEJ-;;J1+dY)CKpra?HcpwN4~kN?%r-TcRuf zJ(IfQ)Kps*$A76L-IC(&4G=8d`A+5m5K(xb*?=TAa=Z#P#T z846Hm9}@4|Yu0kRG#dS30r(*%v8dQ)_XG_|L@dkK=&=Ow)IK@*TQtd{*7o^R=|>!* z_LEq3JW%Lhia3K6A_{`+U}U>|$qHt7*sPpL#A~5Grt3H-ecm3S?f~B_G==zZ38jdv zXLVdJ-!kVZ?L=q0OxmJfwS02};nO@}`qFmSk`xdkeERYzfZ9*0{REh#)(7CK0xCxR zNlbhH^$t_-kW~3{Ec#tLwfhKicUEElr~=YaBGtq-`vK6Ipj#sobtJ{bxHur( zWJ53k%fo|M!mP7`nFn#2(|y?MgbHLD^{Si66qvY%_jMMxa4u}aUhl>Y26Ya;dp7$c zO~@8}6TKTS$==bS@)DYqmSAd3fo+%3y=*`ch)>$W58s}ixo7fIWRb3{6&6C$h zW7>3A5#`B{{xRUm$?kv#aFGB>85dE`9tSLxbr#8DgKm}ecqi@hMyAo!lZ3mfCrf%F zacB)M{=FT9&?3B0UMnDr$Bf-p{H!Y{CgfM6vQh6wRjJ+@*}R0S6MFJjYjr{!CID=M zZ35ZoOT#kPf{Fn)O(ogAnM^0Bn$Jx;!F;(IQE(kBPu1gjpt(B?BjX18ef-g=NoRJO z9uzsyaB7xx$;*7AjoHX36bD;o;QkMp@OGZ)P&?lpUHr>mdD{i%?V1r*RcuYL0 zsb*S}%Pmlpt>q67ie~(~qwGvrz{DP#sO?OuCfbNoi&endyR&d6wdDk5L8Axcb~ipv zul1mBQW4*APb2gLX+kdDmsE{`FIld~*W96M^ zR?`UW(Xyd`9>9}h#atdKZ-MgIj6eIx&Fn4hJtZZ|M)mQCy#@*PzDASEK>^IsC0fqO z6WFxPWphFpQ8gTX@pPzPZCKMy+(F_xs~ykj-sd5*u6w55AU+Dbla3+50~(dPG{ujG zSaq@#smuxbi(~;Be@&mXe6*IKSuAvWDb8-kw~E~KAm#!v%B9o(@1HFpNNKK z|3*%$;o`Rc#hgn&txxVdtee5rZpE~047B!zWJfnQSPfVWel0t&>C_q~$mQ2>!tI$& zRpRg4FE78?@`%A^ehbEEo=vQ7UM@2EEG+qrj_jMEILjTO+mV@E*D<^26F*A~m_)1{ zYKG1I%>L>CjuUa#I!}e4i*wv}`t+A}&1yOB@_Qn1I`MEUIxU7B|AuI!`0yAVP^ z;KJjj(NOdrG^*q9xI$POcDojx-@RL1;ifw%w>Pzkp>k>$oCQJ{74Px6Gwm7h8yO`%IOc$gl!)=@B2hQV5A-b zrNVE!Qoh{6z@VX1`}CgEsl0j;MnMZpd_vACc?uWvqxC|e!yX#dHELJBel6myAQqr>?8s>wFlv)_y4U9Ht#N+R5an{fcM4-C=qfm~ZpoaE(0 zMBb}3jYo%t*10SH_YcPk9-8dU`}N&*bW<8;;CxDtY`Ly~ zl&GQ|cgD-Dq)R$K5Ug~sU7gEqhj&|C`}bQi$TA+plH!e%)_vAPmd`a16wyo9X-7n+ zRh@WNcek4mTm)uz3FuPN7GV7a$?g0jf0fQY1d?y@@k9j1^v<3sP@^fiaCNrR6 zmR$C?`{sEg_%qw;jGV|QS72BzSh9o!{fJ%hWxSQC%jbfUVxz{Dkg#3p+W0(!c{QCD zH{!Gu>-J@#kdTbW`Wcd_tH)JK>Iw{p--9bggv|CPi`GP2iDPh+kP}NE)vDi?-kqZ8 z#J_4Nhe{QQ!{U+5lshWvV3aZr3@eV-1nxsFCWELvdMQ^@QPvM$lin*ckuA+>!4gQ5 z>q-_n?5YD5jr!R{5C$4SX(~Q_VTMOT|MW?=VA0M) zL5<>iWe?L~y%$-!bha|dumD_By!M7S$M3y{&FzaoMVGZ`^tToIon8>;D7ANbJ24Hn zXTCckx0PceS|l4+R_CFQw<=JjaOJO0=zGqYnG43Z0wvOec8O2nz&;4pL$+DX{<`?P z_i`_AZl8KXViSQ*KbE-a7JT(!#d&hlEH+#tW|U)r^j}|Z^WPgk%^IIN-8jDRsB+!k zecskJjURcj?tCWVK0QdAIvtWYV~B>E;K8`@wC-(}HVP*2@WxCMLV_NLY|LAi2-Kr1 zDj=2QT4K$?w&m5VAH82E)$~y7kVax)0NOKy)DjSozfypvR=4Yu-~$tZ6N!^&vV6gK zDqmEKqiOSt?D|3aKh~Lu|65te*2&D+;fFZ%o9JZlKM|eC{u=u4q^GsNrKi88r@y7A zzont&Hd|!k2-GtSZpae-XYeWkyG& zrD$lUV5Mj%$44jX6zOM~Hg+ATCC3M;rDy~pz<2Uh6HuwTiQQV#C7B#0oiZpZQ2c(CE;9 zIpXrit@x(V|Jj+Dw<9jUX&L`&MQeQ*W1IijmVaEB`2VgjTL*nZD`Q#0Cu18LeIp|WV@Jo|R3E^%4zIZQFP;9IkotpW z4rF7Cp>Gt6do%0*`;OV!TGQG&*xDI8IGGze{)?Ny|CO7t!wgXV^e6z6JTY8ec2Vfz z1@Ex)g_d&~v(fHkI#UTH#B(=Jj_x*$U29S3V}s7%D#Tcj+wF)(G+0NeoNR#ILETGs zTXs1pxps`TwT9{;6K;fbpyT=+mFn z>p*2~+huwfuZb%9h)zw(Hdu6^fj+QubzdJ4@uq8)Sah)z8jLstGW47E0dadnuAxIV z+-SmRPL7V%BoSr*8pSemFPVOOkT6RE72e1X?JFc%+sjr7s-jiCZ4h6FWw#R@=K`kV z=CUEm&~*W)NQ>(B#U5fKZj0RZj4XGt+RQPhz0TXyF78r0d3i@`s*OUG=Nb9{%gWQ$ z;d#x*)A0^hO{Pft=feOJ$QWH7x-9CbGFMzb4#N^BeXLk!+vp7;!Y`$INe< zOG5z9la`k%F69JZ9>1pTHg}inlNJov&F;aHqYdH?My@HVSHfY;# z}1a5YzPVk+;p{MS2GySnR+di z_(D<(iXX+zL!vLIH@k7ZP(g1P5QU%ml^OUiSb>iLErEkKWj1BPg7Kz1>f`h#f_%uE ziIaDAXXuQxY)H88ziV<%y-f#0tul_)e%7Fe7EJA$#f*ZNpbVp^M}NLPv2=KKYJ&G? zgCi+=KKOu{>kT$yj<|gKTy6NJ7oHsJ8TilTVCug}MKuw@zZ8f5c5?6SNt}Y{qUgdU6=olO*DQ`0086v_f`Lw2V%xf(!azc zfnP(ClCgt}m9Z1;FCFx+IsXsbOH@8moRLR(frFKyP^jJ|43mGCqa_I-kkD@tOF1g6 zm+jv>F^NkcD=rwv*d8pmg?G-l4SXjb)+d7r(>qFg-_# z&AM}qePvr`Zm|wx=s4|v9u{D5U&-kCek#D19IqyDI%0P31E=-Xa3iJ?B54)9bKqjH1*3TVU zcH~#64pWg-w5rZgk>n1EaJM9jD-lH(2HBfqh=5{dGG6JH8?@+aI-fGYSdL&(wUOlb zdU8;0g^x_6_{a)CPMB#HvarAq+vEuMI8rl8zYHkT!#qC%qyiZ{net)O?$hWl-@%SG zDP9Bz)M~FgaSu;+d=S7ElJjYwBZ$_q)7lVwMdx_88(rKR0u@oXNLym&HkkdR(cfetIbkLJ)`C_*?2c^z$undJi%fp zj0Oo5KPpdsoaB{4g4-PrQUGur-c%#+H6&yZi8=qUc##=iOecPeCm2UOr-+#EOA2#} zl2hEJT5e}dHWtzeisYvP%OIrCFPDh!>FO)j+a}~DsKCu4Fi23%kpgi!lV}%kK@b>l zyG;aQEKDoVOslW|wg~t!aNc98m!G^X0K^~x01W;Q4xHbO8UY(4d0U6SFlr)IEtRlT z(0y1nYW2TD!4{Bo#3n6)Noq9c2+;vGVoCr&s~%O@#0j-J)nTz=L9Eeb*gvpwZqHuC z-w4U4lss>tnLfRX+U~06C4)q;D5POZuiNj)*!Nz$O^@e$dA_FoXlf@kV4u&@UP%<- zgu>)7ZZ>FI)O_cXf!U1q!3k_H%bwj7^m){~Bsm~(WT*zTDT@l#S*%RD`ni1{92x2%jBqhWv6_q{PNPwkdZuP2w*}#@@qNDW;4W$~ zR%+@uO%lnmul-IrNoc#>H(Ht{vy-RtBb7!istO4KSjmnp#{Sl4=W>*a@vOHxVA*ST5C$e7lX5>WeH+$$lQ= zbwJxdF<);5<=Ur3J15gg!cz>lztYdp_2Hq!OO9&X{n%YE{0o)uk zCfo@~Dw0p8p^jGe71ZObO|A73-H_$ePT)OY7V3tke93@iapq+Qr`F!7(rCsu&p1m_ zT1GTtnFI>r%z&iC#3?5Ocf!3zV7$Ghz7rRLzH}FfzEu~nkL(5b_swMX;46Ei$A$x! zm1-kUQDmwk_{yU;J3#gbu{jJmhvtaTYAhEAEqw1H&%6~Ns)><-U$m5J| z=zP4TJb-L?bnr|wf6L@znwU_U-^z-x%y?p(idn-Wv+WEsn#uic`4Rdi&>r5OBC*WP zvY{&qxTJDfynrz6CHMd}de*-ATjuns9(m3#M$^c?0Rb?L$lCT!+z#MN~RGu?T z(X47jGvzHGDX=q3-qT>c%CSg#)jjA+cav9OFKnxWSD-KNq3cX;R>Fw@9hg~L*8C$o zT--3bPVRs^c0WoG`X)rycYS5Mh#FbOCHoa4W1AXQzL+(x2(M4hj~RSyFJHciQY7Jj zK!(|*7#6zXm0UG9XzpvC*y7k~9lCID?**{<=R+4Og zEQA}y`Rkmhf5#2pZz~uwLj$o8Qvhk^w`{EcZ58uZRfK=8pIm zvBstsA7Smic^_Y$fSDvZpZfvU;xugB%+t4feoBbH7BM9C41kwW|ea##< z^qE*$D_^`mo;WdQC8PD(e~3wU;u_<-w?~^}$LZ7<-bvm1U?4?GHp`szn9z3&{#ysZ z*?bm;b>appe_Q4fymiw5bUpvpK~}b==7#_3rKkP~r9W6TI!E`sDFrY=XMSh$9#wO_ z{9<#LvRucI7O<6iGt;fk(Osp3dR9dNuOnGch|eRVJCM9);WQOtaY+2eVv$NxbWK!c zM@qevORnxori7pAmnEo@FiA6rhN5x`ZjJ3t#|jg_hcmEvk*4%295OA z#$zldkukfC4XLz^6Tn&lcmoX_m@z?L4+b_m``sfYxj4?w*+0SX-6wr~jl{pZb(Qe? zw+!w|=JyxJaDKOr_+_bVr|)DYZEoP8@9?IT{F+&$q5SFfv0sy@pJ9K0PUsI{4fGvo zE&g$X><9V}`$=K=(WSqlCtLhp%0l_Q)3$G?j*M*#{~?UQU-uiP-24~4;x{yA%ip8n z{t24(o7m?3rg1s^+6GK-m@NMt?%7XXlKe+peM2X6mw&ij`{wo!`-4XK^@iRLw_$~# zQSjb4%>WDlK>Huz4fPGpjA;yQZA{Ef|HbAX)nNXw)yPn4aqy={IC*{t!vjHv<8L3E zAe%^9LCu;S3MYybG%-O)D^so1Y5X_Z5$maFf~lIR;D4tl-G2uDLw^1! zh~#g6{;&D@{1bi1|8qb5o}lAz^!Z_bN+A!~--i&ypGx>K-TX?LPw)OTZ2U@^A5h&= z-I!!=v6}kLes=a3C~I?TW9zp=rRFxKjz6pTKT1e`v!9$DAs=d>k*FY_njjw<+mxJ; zt{WSbk(QeSuWhb{n$Br2_nUR1rTw?Pq4z)Cr~aufQ^*pVsNu@%uB>Pb2JC zC=*-TpR4i%_=o*emEUF_qn~{I{he>aUxBUNjm-ZMuwefD&iAjL{tWn2!1{N>9D(MeI^;HtB;dXrS}-&*AN>ww=QDvAgQ%ZU6UBHl$58wUSZ+zizoMJx`4jtMoV zIb0wWLo94@)O9WX0&#cXHqr*qL>BA!0z@*zk&&0z?r|nC)X-@G&^Hke-<)qfS6|+n zjrr1^VePs&5dfk2zrIk}EDX=EX01cXC9Yyxi}bzI5ZcbWaI@pajaZ+)Xd9ZkFnV%v zbGbP^PT*b7ghw1@&YBRfg|;Xmru{z4-lo8yg8>yil{o(;7Rhz;418d~{{oU%R#uj@ zXnXTatjP3i0ON5u#`zr=RMMCJ(y)N9v8GK5alSZ#E+jOAIoR^ zaE&RE&rDFY6rU88ja$Fy3Y;9MF7(e>KkeBX2$|H=lo@D14S-w#OHg*Hw z6b?1fyZ!HrC#jB<)fXnhvO7eEM;0H3eGC^NK^Mu_p(;8H!VKTE#{qU~dRv0#mMljun-VA}5k~#9c1zg(wYr=Y=VtE+zm6Kf>-Q*_sl$ z6&Lz_aiM=8f&d(a#5RW9P5#c5wIP~?>kzb6#xfRmc>Rj&A&0Dsu!dV+6 z9L`eNfxwnW_Q?U)!}{m<)MI&HB#$1+AFa1n2#XzY{T36hwNg}oKdg6lq5%N>Frxov zRy1_|Wx}O(bhQ0tB3lb9{-X&p=T4UOEfjb4C)^UFrfF|0uVXG_1JGaT;CvRku#IYkTwc`A*14j- z8bEYVefl^thU~B{f_5^syK7D?9!lB8ibB|}p!F=Yl*Dgc3Uj&GU{rdFAvZz@SsW8* zfm*N;R?_5JV~Xo-28^wHSiXT(Pomn2Hb>R>Vc(*1Z|MZ$mBdhXHKg<;Z7uet+cP7Tnyuh!ivmYfWv*dNExwDf(3eDERpVbIhvUn9hkd-clL ze@5o{_J0zA|%NWX=$)EarYfrX@YR;T9nK4V8m;pkbqQ4TVm*&HO#KDqWKnJ;EBle zhUEtk{)Mz-5|T43fLzpF`oblhUVl`}_+2>=ZCuIrvd<0;swoQ@+#i;V*)qUnyYqru z6VNVUF87_6u4DqsKaYKX%4Xhx|D2E8gsF*dE<1CV+3(}dktI;4wg*F*WOqMEqvw+I zwN-`h)Z2z^s!$rNVoa$If~kra!4BvF!-(ET0T|uiK+UbiLFzp6`@V&VtioXblt92i z4onL+4d3yTOT0Vaw`St#?B^To6i(IgFKKva6y1IK!%&QRdIi9os>^cQ=WH3Js|`FK zo-Q~c?CW?$A+#8l+u|PJp!4|Y5YS6t2=IxtZ)VQ`_&#YAEr()i>tc(7d( zQkdbkzwz9>?^ykuG;JCIB%^JE_S{b_C~)bWE8hk5a-4`?+ocdel{|K{m5;?Zc6_vK zMT`K)s6=Q*-v*T(PC1Xr5-O8n5Luz$v)>dLOlc>4sRV~6=+7=Hp@H4NZ9Ge3b%R6? zW_{t6Pf{8%r4RR=rG*K6&=8hn(aISc>tf!GtHVvmD}2H2ag#y`mC8p*30YUD#t34s z-NMCYPNg`4f2Ix^yr0?yb_~Kc(S>Oeq=lB7bXcLKVUM-31K{mIQ=3Kkcrab=xojew zUsF|W%jy_DcqF#hwjNg^BJhXo3r{ckj0IGimPuOjj;G{NZN6yv{dmVY}8lw?PL%7v#<#hbSIraG(Hv)~xM$ z8ey0_&WKOrx~d#k^QT4xH>DPFF(F5S0E$KRPavjo&zCGUBZtk;QDAfehBm?Y-Voyg zRyQzU_o0X2$yGU6nl*6|p22a&Lr;xsE#IIBTD9=wMSySJEpST?8E%61@LfjV$Fte))?%Cw-b9Iep1}c10w$P6j@RidyTa;;8=C~=p#HI*9yM8M z>tIcV5fi{Dl!Ew*&z(TlMv;0aI{P%2M29Ul7pu>%AJB!fOX&DesFH3sLI?~FU>nch zrz8S#A)>HV7v#xPYD#pYwyg#WRL%G*4V#mBev(pY@N4S5ZA*Z8FEZ7&Y0>I{aV0<3 zA;ppid60D2sU$YY0|4hI(Vs!K^1&qcn0Yr3*N!_aXEe`3)?PR;kIFJXZ!ntOJ$Q}sU-^~sYXm*#kGQ=$zX{=d-aOeWr z8n$j5LxFaGY=B5GbyiMT=(}=v{n@W5Bzl>lRp!{RCwrvRl(`2j**tuFtN0f4`Y6vK z10~qP?>nrlhp+|?{;iN+PizBdP>ab)KesLQe%O7gRT_elZZ;p@U$i=&zGBZHmI8|E$Yhl+0at`o*Y4irpFV{&N%A?Xaj&>lbt?DR+`KK7*{x_9)8Mw&@a*2 zIpbDZ?lH*lnZ9mwGk!sYYWNFXHYOl;M~|9!uo=aGu#`SCq7vP#WJg6$BEcGW^LB!! zXIavwbGl|t>(=F>A3>z5OR`??sl?%vH)NrP195N~_06?Tsl7qr2P&;;rSP?eb+l$% zlQp%^WkKV_n5cl5RWX3}0RVEfu1DaMWUTpn(&b;>K}<-LIHe=J{bdUb(pxUN zwa%y3)otDaG-qrCoa(|z-^;RXqz~{ZwWb#^V)+O3qc2i|-}qAnW(kO{Xbx!<;aQ?dh^XGEJXZgmU_^Ye-<-ORS<`%pM08)F;8v7Hbow zPE2u(qzr$9u6SRiQZ)Ao=L3}M4CSj00cqYRcF%nKMH(dAJbi+SO?Sm4f*ISUA;hh4 zIIG*QS?mP|wrfgyMRkakE3UP1lvN}<^`ZKf%UN?)Ck>T1 zLvq5@E1QVPNte_lw4YDmgcS))wN@?>1pynsP1Xc_?`~ij%HgdbDD7)+eX_*a6 z_nIrvv7ta{hG3qYYZWhH z`cQ)6K3?k9w20-A`7z7e?e`f4C`Qe|Ftmhrny})9CPZGeyHIiJ zd$)!K3BB?mh(Zck3e)W}9@H=9Go*a2gq7C53i5ZS{Dn3B!k zfzdl2pZUgdMBx+!#30gp=@Y`_l=>Ay?w*p|#~UDXtY}=`lVe3kelfy-4L8H}9%xKd z(QZbrA-?Iu@+XWtN?Z46MeV4t+}oH6sCC@|&AH)^>H!k|a%hbeW_ES->`zR=mpEFg zS}2LI@bNmcQ*xxOBQmXx5cL@Mc}~dFmnCSL}x7U%OByLJh!~P%!^Bl_8Q31>P937WvrM?cTqOzgv|(S z3gjucb@qutnXLKt2*^xJW}+t7)Q_D^B!ybU>PH`HaMz#|;aW~Z8iS9BGNUKu)*Z+6 z+2sPIt@Qfyj9POY^EO6?29$?)1=+dJdED_+%myB`Hou>)*`H7PP#KfIQXZ2OgFtbK z$Yu|B?V*fvO>suUd@S9_GhZ;`TwUVwMPiTh9K?Wyi&~6khOKM_vCgrT; zOxvT^KQr21(2e2&Id8~6#d&m&zycy&YE9>Qtf{?{9ph%_v5e^I#hS;bgpa9V{gTF` zRpm5h4w$HiSX&b@2YX);f66s<&pT|RA7)KU{=J#owFUW&(UKLh8`lLuuL%m$ZfX1C zF+3!pZ<$&x?aGng^Bjx?)lpq&CsbD_|HI|@D%OJ&qB}qDac*|#G^vy8J42i+3u&p{ zuZx(0z9g(jUnRr8e_FI^+W6v)+YE2;+*Hero1C8yKKa75MUCJ0Sxd)wNWDbLHy?Om zu{iBA6*9gP%@)GTIn-r+jFGzd|9I|5CIf$h@4h- z>VSQO{*|sch_J47jE5>G1=S#WIGeF7^?UK^lVuaZ*Xk#_$*0tWCQaWZa_4l_{y~O&6n({dbUPOz8)t zyyXCck+eg*Gs(&hm!DJ&KKbeqEoEalK~P}ob}}a(d%l3pNDjrq_bs%_34Uci$_>7w zE}l=IeX5Ei0-2$9RS&8VUVw*3u=*xv&Bsz-A>3x<*UFPf5f`+|ECl1Zu^$!NrMF>L2mw~Wj0ux9pSVGnktrf z2ZVVWpTJ3e7G)07%{~d^6Z4A znK@yIuI+c7doP$sBr|@!$!>Mfe9^Pif$2 z5cjR4sYJ1`U(*w|A0i@dpe;V}EZ3(37Zwz|8PJJtz&sPTAc)=xP4?@DWD8*{5wCKC zDPqAfHlO8*myM29=){>i3f-UYW})zxY8JOy#v7~h(Po2U>aWy#&Ivx|I-k8gjB_ce zj={)&DFKz^7 zJU#-aRZ!z!(Y+i%vwJ>OKHoVXgI*2RuXmBl5H|0wIvsGZbtjm{J!b{^4CeXcbqI;K z>m=)bg8Y1#Xb%Cmt~*_Zh!lZ{M78ko)6jzMO3c#$$whUjKpMh)th*zfg+h+bm+yQE z`8z;vhAt>zxbm;mmRyfeKuRxy=%o7ezNQ@YRmm9alRe?#jIVjwh*jWb3xJ=EXmxAP zb51#o5g%@keYdFhLQ=-RRQU?SQfF%R0O+y15J1|5#^eshv(N`A2Xh7 zl|4!agdU75W%=09Ol@-t={`e_S<-S_L!lj`A{-_b}6Cw3`c8TTT>Rc7; zhq2im@|kglZ`py@0Vpb`N5wwK8f^cR$r-&=KY2KC}Zww7@XR<82Isx zAr3W0CW5q(H4_o|Xexufo^Wsjm$shg7JM=JQnw+zI&8%9*Hw_+()0O_ghr? zTZgDI6>QxwiQ7WMhh2NZzPD9ePGF4P#BW;soHr10BgiMeGxDr?IJi{Z$u z8ryhBSiA=3(8yx7CXjrbUd+lrRy74YtmbiXKbg4%W6QG)#H3~_1^SUC9*VXt4!1Mk zd?Ao$7~awHQ%lnMBN|W&OVr%$JnuSD;t%fFnwPyQ6__7&UkzeB!c76l zIuS;`2Gj1rgo^6jPHSZ)^JAN|sU5rr?!ImvCa)lC8U+`@9`=vK14MX&@Lj_!f0*b5 zGV2g|aNJlPbrbNj-hOqxFyJEBOn2^?wrlJ!WS|OUv>($`Vr~e(s?(bjsyesuuR|;@ zXVEsEec~;sP7-WqfzQNDB02F!b$| zQ`)bNbiVOWW!psUy!wl!0{MKaL13nwuDfJ7@9r94DL{$=Ue_|#b9*#aGF68+c^?^+ zu1a*1qwVRzAkOZz;gBona!X~*Ia9lA73*rOj=2nX5u z>&*#ixM~^)5n51NW7Gjr!zFw8BQI7^;$SGuzD<#4PJMT?3r&e3B;HAQ2B2uBhfi}> z5r8jPNCU`f#9Y`*?~~Y!Tn=jgGN%2F?#W+hk#)ph%@r53s_Iq)z`~EfD`$*rQUAy? z$zvi3LQ744^`n%2Jv~#o`NjM`Tye`lWY^`%cTZWe-8F!$DaQUs-Tg2$r+3$v733NE{&1M%DdSV$EQ91Sh&B zIl10Mug0)?Ud$7sS7LR`(^LNsd+!*eS+u3=rfsXzHY;u0wr$%+B`S?dXQgf1`K4_e zmG;Tqed3ZMK{a8QOw_?RNW5yVBz2kY9BSsvU{l)K)_noSLu?giYV78{0 z)(bMFM#F8HUeW&sEx_z3q5!D@9ceW+&Cnls4r^Qme}<>xIE3#bXokNV+O`3&v@dnb zo~mBFSjR;(3tjk?8Qjf$!ZvU{U_W$l#ezi`5LhaHuj0^zHEyw8WX$%kP-BY(aCD~kRE^_qD{o@ z+~T_tOrgRh>eq~+w=G6jWDL(}V)m7VW7sMgK=I)wywNROEBHYP6KW~AN+X_PQ($ug zo6!KEA9$~e3(uk1hw?Rg3@UNGj?l>6?vG=I-ms0hV;7$>$7vfr3~P~v780l$rn_8= zGj`XmQVO8zD18av5jiIyyOD`i)>N%*%rn=K^ejaMuRQE%2mjOqGu&&&#O)GP)}^d6 z1JM+Azxt!1dm$4NtCJr^ob&qAcHT4GV1SfNXqQf75HUOI?N=K&;b#NWa;ul%-rHGF zg;tY&=ZP&h+Y zSYeV|HE_)rUd=*a_O0KEJ`cpaiAXpOZe7khO!G_#GBJ6eqO?3P?&GVP&9T1pa#A?8 z;n%cPHS7m8Tc_JcoM(-L){G7@8=2wiYv_Cnq}EXQ&$@LIltC6pFyAw(l10EWuaLl^ z^zDdvgU_5D{v9i%k!x+g6^5J|uiYgMKZLRg-46ogf_M zFs_nVNnCS}MmAf9a-|N;q;|?L&&cO|=Nnxh3P0akmmgHb1v5vo8Z91= zKM00{NRPLrt&;52lFKi%G59jk2M2%TBx?g0q<8)4i22`}qb*TSQwR1F?yQ2B0N_Y^ z{2JEu*T4ogQkk^~!V5KCN?#`k^RWXQkR_;fG17JU9JJ<0lax;4$nBPndZv@ItK=sJBd5}mcI zB@jYVl(-ufgp0zK@FPXhb`ZI>jOL@P4oq_#s&K9oUC=+D2ob{t1)ST8CrsvsW{GC%S(jBW@s zn>Z=10xs=Xp)ZT&3?YAq1MCRTV%-8ZRbgV5?s^88H%9kC;sr6(5i50s+x^JF@ih7A zqMa$8j3TzWNl-GusOH0keq}l>gIAAkbRe2X9xy$snAbw|XBVyaCxvi^He*7Q!WgRw zX~actLP>qO?ic{)1O@he6B&7m%S(i+Rc_=aEryu3W%u<)xXBPQcCmc~P&f%38X{D| zp~3RKV8!y=bVd~92ck) z12zK0ZlZLe3a}YndulLNmfJ`=EN-ETVg!leQM()ka-J&gNO_@K31Q)YB?Q*JF;#O(V$ zxVOwdhFzUWbR?OSK2;oh_SKK_@3;+nuaa~gHCi0TQA(I^A;ELWI^w&%eZ0_1I632K zZykqk4&?7sl-bFIn_v~MYufOkgmRxMNlb4{YIHDwBNT%xtIsYLc`&@cSC&!n<&M z6Y33M*p~l}urD}uJky-zrEqvKH?cwZ+o!TN2oQ&y=e#xk-5a#q`j*Qg47TJ8&KutV z?SW+0G$)EB`@oGdZ+iTb2docYZnP+>(=CSkeJ~(^>U+K54WbAF!9mkw4uYaH!ZSe_ zXDoPC;sGK}!42y&r>W@ocz1{ub2^s_!_jZrrx#g@CitQ#q{+}KR7Esnxmzs!PvDLr zY1+OzwNxqY7)=vlNM5~OLlo+|!DkY7ovIDKO~zAYrd)TgrkIJRmgB4S7qGt9Yt~0< zd}dY#5zm`u%^ZFBpg{HG2Gw;kedlAFYJ%UmU}NEtFHeUOC-v?Duuq0So+@K^69rzN?|lAgtnPo!zN?w6P_a^ZrBm#w}f&N>QunMHVU#-Bqq0LOqcJs=de+i*>w*3O4Uq& zxcg1_BV16*I(wh4^_^6g=6#)KZRl*OojlkbRr8nAT#S^t@y4AS8vwq-AN4>8?LGH) zVCkcC;uZ8=+H1EKS|tl3b=oRph6tiW)lXbicIuP<9G_(dBJQG3iy9$%2_~hTZ_i;* ztrU%^RsX>bI6$LYPgP^5s^BKrTsfIYcGtpmfGvL7xeaZYciUz{vLkx`mlaF*bUK&M|l~S4s7=Mc|h;O4_ z*v+-jda0IBko(iabm3TPOc$*y*KdPR=7Huzp8P>$(~T#@G3w=3sv+&CWJ}7HWBAP` zBk!#M$!a@zAM;O|=Y{pKp&3udR_?pV-fl5HFIq5FmA0~60}iC<$P-?K{n;sP!ZDdehJ zWdKLLJK7wJl#{`=OzAQ6tl{1a0^qr~jLb96ouvuuRAty69>9d{p4-*;5Ow;91szAs9{?lX?sV07 zRVycQB1|+3vqpYA=Uylw&7lRl?TMG1ym*sTMI-_yDVuT$irKwS%ASyjFk|@6oF;gU z4nSEM7EI*|PX-&!G)(F8i+7BcdJnv$kyp5f!D??8D18lNDfPq!4|T95@3q&&ew4TaviHOp1u+B4L+} zuVs8FrWSuyTt@8g?pz7^Kd$WPN*4Eh>*j$875z0WtNU*c)t*ZH$L%YU@@==$Bc<4Zb19Ra#>BADnT7c8>LkS zEkZP&_6ua*@HfSr+&Ty;=uzV8D4NSGz@{82CP>m^APze#g#>TpLEo*ZYUo<}?W58a$Z`vQyYJrF%gK_sTVN;o9tARkSD zG%J_UNWLy|#grHWGLUVUfNVi}q%`{_J#twNTs5Q6Y-fw#3ib&|cB}o0hDE>7g1YD2 z2YY?ow%80euqWVFq(v!UY4>_*d@8(`%ndP_b{>K%K{UshQ~sf8=X15PmYQEt*lKP3 z-V_-4(aeq$l*4Ozb{$ZuDd`7BjswEZ9S!%0VkWs~EYK6d#Ha z4VCaZ>YrTMY)N4k%^)**&aRQlYQZ~Co;xp;D(Db(5?LE+I0aBt;H(c+O*G;x5Z zo=;xN^Im$hcfHUo(_BS_jD$KvlEZkn+X7tRb3sSvs7>OV(9V2-YnX z$zX%U$GjRK9nz}PygwtjhX~!bkv*-bQ)?w``_hBXfEXi2cWM-4<7MxIfyUnEQu?zh zdi{htzQ+giO_uY+7VD0*dV3whpl<^w@(ICRUPSvpTL4}1JgR_iH9MYWYck`x5T(x)!~SVA3u{lz){BQ4i7R8Dc`7(y<&fJ_!L2KeqR(OuV+?zp({90%8pW2`%7 zu(1nO!eHx<3rFa!hc18qCGstm`{`pY0_0eB~`eH_(9-98OPIZ{RFtp43T-;}+!^B>Do*yLn2s^vRRH-!37g2NrWjb?YAF^aG51HZXh#iqj?f(PTpo7p*T6%~KnLRM zc!Ctu26dEHa~V~fgiPmWT3|E+9`&GbkR^y0OX`9ZKTKqA1XsR25>Ij3+fhTOpySZg zyb=ILEJq9x9)1RFv8Ovb=U(Pi+cFVx#6!tGe79(Xj=*y#;`qp8p6^dZWF+cV;oV`e zA~V22T&`bM09|`}!Szwrgc?S%?loTJHzr-VDFs`_ukc>y7r$+?ALh_iEJv)s&R73V z7BV##fWXr!6r&r-;?>zTQ}-}`PH|3dXP%zF53E#R&j4OU z!Cuw5XbYosB8q&aHauyejk>*VxjU*w=6%l zj%FZVyle@z8`5Hrq;9;)7i z+KSxVGvh4n!pDQ8UtbRG#Otw1xOS7G(K`8k9iYwnLMz$)KwP|0ypRCa&5w5(6k0SR z2?)&FlMbZOD%b+tjj5iaRZvb2VkMlhy`0R}sjIwOe$L)%^Ab0~@(E)u>0|yEoe|$? zcd8@yqhznPTf!~EChAJ!SBy%PtD!hKmP8Uj(7lrh6iy};k`Iq))&#Ywi$(HEl+%u@ z^k~VRPZ2p{r}297Ra=PlyuY2{DUI4#=Bzx&PZ2rH?h{E-F8r{22oj`!`nHqJz(97;JVTmp`j{k0tgKiTyW+OPgzPh>Vx zG;9F`3av%k2yUMGp!D#=PioAd-Np%KGEfbmYA6Swd5`Rdxxz z*w)6>0U8;Z`g6a9Z1#K@lE+&~=TD@tl#6pPM29LL%=pO$suv{~3k@OKRgWXbfMkE9 zSk_cmZ2C0I>eLyP4G1u*l$7!&PY)$BSGZL`6Gve#W-xbyLD=j{6gs{ew+VnlZvg$5 zBYYM5Lvf@U>|&TCx>}%YjD`?|`St&Lg#YgoN`hZU_?g2Z-0vt~oPlru!y|lC+kZR4 zw~GFkV@i|hqlx7bbzzS@qF1%dW=PR`jDTB00}3z@rU*};7wN-NWmR3>jit7$L$eGF z4-TShsLv06X8-4d7ejDKrcd&;EZnuOp3h0QLEz0-B`PSMwRvt^!G|0Nx~D8RA-^H-K38P*yHaVD z1mPyV?`83XcF`de)9W{cCmdJWE_?eiC(c^f40aO$- z9PtTweombw)TVy8FSd-v{`&fkEwWH71S%Gh$CwHzku*NFBZRRyUjkymLMpo7*ZxxT z=WP@QuXO55Qk27Y4HNu+DjELu*Hb3Sn0B-^&_5m>G8vvn>@chsx5X0(S8WoUO2F$n z?7{7-qtlE9tw7qv{bUjwxf*(|mk~49!4NfRm5K{R+Fd>KKAb4mp0P{&>*Ybuf=7W| z%}tmk-{1`$gH%>-pN)eByhE4Ot#WJA27GaAY-Mzo&>4Q_NEk6g>{$&Emjt zO=FI>I#?efjkt4RtG+KYImlP{2(uDsUa2S6OvxOmGI0LcVLldwE$;_PvPVJ=+|wD` zx4m_bR|6Z9=hamZa~@$E2dU`Lt^eq}e;Udb0`-K9Fd!6UvF!1xQ*VE=y+mjzTkEs3 zGg@yTNe{JVAR0v)xkDYfuA7#-eqxL&pNf{CMdPLt^GpUY1w zwVQ6M7mTOVeMAB?setS&I1Pb6qPeyW&&BH3HJi+PdoU}wxx+-eJ-+z588bFi@eBS~ zQRFw|aMW3B1xn@cdSli{E|;D}>AHEj^?U^{5biyrH0?Lqi}JwE_7sL|#vf%g z=T4D4jh+Np!^I~Mt6q=2&uem!%v7Edq8bDg5P^T- z20Vt3@agUosxx)WI0}diGayPpSgv7;M^T*IMFFH~>`knx1=*{Hdl=4EK`1~Q;6Cld zL^hE}f}xClq8_`>Gvg068WEW#pihLC1n=WN#uqmNwD<8f zjoiRR@ZI24FDAx@1Htn4NxOt#yp3Lpm*O$~EZa96iYQ1B1xX=?2?C?o!3;-mPjN+d zCn%$1c1qz!7VsEW(UO}4!Y#Eq6+-PP{w zRwhu3IvXQElN?*B_{Ih#&Py4;P$Fw=%daPOflY2tQg~f++^Q^to_Q0F;ShZAIoRAA zS`L~=442XS0dFI`2`F6&;mq(%$p}0LK|LfsIu?1cyWknS#u-_U!d?90o5G4xj>-+4 z&F8nGxF1v;=SVasu^w=)f8g)~3ko-JHGG9QUW~v7vzRtf>t+YH0_|r|WInbeR~fot z2`E~+h^g1vJ~G#J+xi@3R2^daZ8}iPwNfb$URbfkr&nmycw%(<(qrf*;!WZ7D?~|? zj>$w5&_{?19LSL4uB@I#g8KqPH|{k*#GQ`TKzs+>ouznE`ZYuXKg1#uU# zrK*>5KjV){BI&KNVqW*4VSbfQGACy|yc`}lV!B zc_o{`alj<<6TZPd( z=eZUoLe}OZk1hme_+hTCTb_3@x|#;!qMUM#jc?KtNcSA5GucZsyaXodb~0dkfFtcKJKAdv`br@piS>3J%Mt=|M+u1VnJ|5aPEqhuwb7q0<#u4Q z-BOX5G68CT8=o-eel~JCxrbnYy4dVDOX9dzghht2JV6uo3l1V{WHM!_(;K$%JEO>w ze@g|0LS!>fMq2+~?n`V?UCsV#3#*Zrl>RiNkkB#6_nY#;sKMjpDVi<05PJBu_#09a`!m+~gAXuEQsC3?Wq6o`A47eR+% zM#_2|t;V_g%7!d)p0}tsfbwF^h@4s3`2zFO<1)=@!8 z1x?wb<7fFjD_SY@`WnQD+(dX>Kdkqk$-M5N_)#3e8qPKMD)OxMcbh@#xAeJe9;YyaZd1e3mDB#OBI4Qw@&%5M+kR{o5u^ zj=>BmOlgje;~e12`{Tpt!PQt+Du6Ac9)QtXb0d%+#$IyaM%-4;!bz;6hZg@HyS1-B!%Phs-WIY~F!ST#fRC8Q3FOw#aBbdi%pJXoX#gh!Ui z;S_IPzuhf9RC&S@o(yn~1>UaMByJT2`0O@A0eHGZ5f);9a7)-Xq+RhPdn7s;9=X+v zYNntfmu`i*0Oc0(YLRJ1A8yQILSf{C+vnt?x*KiKe$OJLGR?6=@kdbsOl^89j5QatAYAOu)XUrP5zz!qwI*-`4VQ(W%QzT;8TpR5t=nokyOXncdTraD zeUa^8@JowsviIGU^Fo1G%lwCSaViCuDSeD3eUO5%a@`N;UIaKuo^Tb+(jSt3I;HnI zTh*ss@@I?ZP%+z+yycJU2?;X^4 z&uk7q)jgAX|^DQ8O_j*;qOXqTWaHy*P>nuiRPifpqP1{Z568u4DR)iHlAV( zZyvip36Qw`8WsHM`rSqi@;LCiF$@7tmz2pXzA9IdwB8H9Fux;V=g7x93}dYZFDE4U=^A78-H(o8ZDP;IiBIR z@Gw~?n4XfefZUqJbw zrM#X)`LIa#ZwT>dOc5$P3O;=OmWUWwyn>g)JuGbfTd6t2%m{dD51zc1&u`EW_~%W# z3JXzSCyhK{jLr~CQ~>}j4-4a!{n61L?I&Mc!eMwLer^Ht^wZ>NOmbol4m_K{TF(Y- zEi8Vir#jhp2UL_UBfXcQVtB0vodD%VMNU=UFp6l<55gfPxGp=GP)uyR;zB1SHa1U? zl*Oq%A^yhw`?QsNkWl5o7>>wK;S??n1XueGpD_rZkes?O+71?X{@bv|fi;wsUN0FM zk7BX-8ir@ThE^sa$i_H6$g^Gn(+Vbc2qQrb1rzr&7+4FprK#J^tCE$AibzA{bbP)! zZCcGqz0iGUFttX*N`5-SaGbS9RN8Ip=dWZ2bM+b-I_C7Q$6ohCDC}zti7+jy4d%Ya z@se@k`F4;72e2?|9Ck7N_L;Ny+<9|DwU00rD;`AVn{iN-X|(Kl+E(HxHRe-NL}Yi= z@;&4D9I3bHGCF(~@(#)Lrpaq{?R5fAS@NZWkwltUE^C_SC^5E{ubLROZ^E?s#|=N- zQk)Qus(dUBU|V5zfcZ4SA93xX^+63W&rO0+6S$`k+_z7%)6^YS+@{6Kc9vZKgtn-< zMfU1C+n_v^8Q}TDlh?zPYVUoN83qcFkslTCZW;9Q9>E~(EBMj4IS~@E!b(ut$91*8 zUnj2<&X33gC16`Iv+YI#N~a~db|=s0gwn+-&t8Pc5us7E`eyVPNzgD;*7#j4ow?|2;Sa&iwSH3D&Ggi%BQDkD?{#M zP4?#6#Ca~bjVlFYgol^Q2=;(T0=1m{B828jJxfuyuJ2JOEcK2mA^ zWv_Pj$2lURrtSBg-`SRzWnp!{()_dz`&KNrDKguw83NOBJqploh-rSg8!D$BFBQO=Yg`AH$r>IL0HGU)0L04xZ4f8OVb6o12d1a&G@xqJPmHESjn|`VGV+u+g z!td_!!C3`l{qO1sRmg)@&T?4o(-^pfCA#+p27u3fx+yXrwfcHT1)PZfPheukfB$^ z9Ryd@e3c=2`~5ORjD~t6SEsh~m3Dqm^%_DBDjh-}g-+)| z=u4v;HF`?8Ru(l3^V9>hYhdi6*P~juKFCwOHNl5|8)f^riU+AZD#eX1qmO~k6WpH~ zrmS2o|7p;Ht@5@Bji@`N@~}`adbnAJK3Wv@{}i%dX84_5(_rv%kLP|kj8kGRnwmS? zy18tz`Mc?L`m~kQ5^^0{QugS0tqT&g;h~o1>?iE;E{L9)+tW+3s(qBOPD847Y0-ie&hdtAl(+jCbCc4K=TuZsWOnOetx8^7yD0gB8DnJnw#{h}?m z&dIrT-PlBdxw?zLGdjUm7e9)v^;`==nt4QFhj;0vN&UM)q;cQ#&x>T$GGH!*H&f=x zRjVx%VKU;=UBFs9+ngAUi#awYP?t`WIgC>7}8gW}0~yehM}QQu-YtSO%Eh15IW zY?ZaewXlB;%?0s!^(yT#t4h+^BAlW}qWk7+mGlo%zG(A_ftY5nJ?}1H;4hZ7ugYm% zQX}h0hZ2pxN7ZH%jMJIon37&lwg)XdzPi(oaVY)V)I~PASmN!MnaIFH#W$Plz!o;E zozY!miDy=r<1{di4YyKM#k)s4eAL2uf_zche=11wyL`@x>Ob_^yli3Gbmspv$M)@N z*6P8D|8n9c20VKs^Qk|~RaV!TS^MYs;AKttW*Ye&Qz#=T)$+qPxfN(|lKndj4fxcW zt7aWL>lD5`JLd)G!!v6uYd<3u5l*lK{LQT|8;nYX@vUjj$2Mh2=~+_a5w^g@&WOH=VzE*2@riVis}I3) z2XUqBvqw- z`7o4?`axWD+nV}?%p8AbtHT?4^o*lzzf@fKM-C>Ha5Y_KD}lIaB}JIlVaFrJ&bfND z^p0!`x4>-<*HZvhR)YvtCfwrHKAF=I(QmgO<>iM_k>%F@v=ZdFrmVZHKtN3bB0&s9 z#DX}4gh0K}rpZ4#kzTnekVdA!1VqqC$dHT_YRJIg_Lhpl65dC;Or!|$#G!~=kU%!J z+g2rbLoTa>!UP_TGk8A;=@UpfgmMIy zQ&lBZLa&Sx_{yiZlSFbR{^lnW+WWOL#u$%|LKPnWEH3Jh)fAUg1%VJOY~Z4RV=-?D zC#4OUS6x{ZCt!TXbQ&SC9qDgBIwKAo2j&DC_hyqTL5PGDm_=BKQl0WksGT2Kx7ku> zH0PTBTf+dP712S4iFg#UW_^E6KP zlJvgXCt8{zOY74YIPoUOMcHYU&F#&sr_q_rZ+^QR_8Ae(Szx5DN6P6I9yqI}9Fb`P zUQa5#6#dV*#_`;Nj5<@DsUh!GGGNSWRc4iWHqGQbU8A7L-j?r`a8FC!vg}P}^uWnd zaP*`{t)F*Bj9{-Ab8G_f$kF>guS5ZIRFELN=@#eAkytqMo&@}}?`#8E&sW@oEx-dv z-;DW|P4uBo)7#hMUM^wrv#o^)87qWZ2tHEC5^pC=h+Or%E^Y*ZrXd< zXYsx9oES^*KxH-PdWX6`^0$baZ?0=BoDCXIg|aIt`k1`!w(nrC9R#iK(WdWS^flv) zWExk6Ta*iQMbRq;UisJ31bz~sLk>jHhN^8s5R_cboDx3`5Im3eKSf@bb%LCu#1-6v5QSXc|>}4Ge^yNNg(%+L@KILL&>NfQx)0rs0*Qv9%de%j%`}?J%p!rT5B2! z8aGujsc?ElT)g8ME83*=yHcrk${@8gN574dd7LICSyufy1Xn?w;%sfQp3K~|Y-u*| zp4he@L|Vv08d>v((ZREo4Q8z;fQkEx4w3p-)RA8OAPuF6;@zq=!sLSHmi`_}Rqcuu zQmT91enhO~{~zG$v|n|zrb#{PpAqpYRjghN5lEm`=u5$ppPWTd(r_EO6e1h?ytI=hi+9LszCH9khj)>b znvfAhX^Lw4JpnvsN`&Or7O#&)le3byFO)mu7hSfJYVn364Q{%A6Z}2ee9jK5LEMlz z!ds9ZCv4ME!aKVVwZVIa^_=|Xj-};Ya)|cgPHg6B>9%7L{%&uF@gu+lsSZg4MJ_G0 zn9+FV34L=jUDuM|gE0x)_B$nf8d+aZNbW2)ZySR`Fp)L>w_*1}aX@heRYSSul5&>T zw)1Mi9=~T#&7o=GPg~d~owGz0yL>#c{FRoNnO;&@ zS~`l3caBPMj)QiHgLbuxd3A=hdv2(mt_AmRz}|m1P%bWzX^`e5lS%{-)EN@@fkhc?eriyZ&M}hxgan71T{G8Gx0>G1UoXC^uR^}-sYf6FtEDXW{;Mz|C?RP7;}x~+p_)5*IH(>d|E|B488&3l(CpUP$%Sn>NCV_CO}aV8RKgh#|NDi@RW2Rv5876SA1WwWibK zKJOCxC)LpoKaj({L%Qh3AHKWu}s$bKz3rI%zWBjcma&P!E%U7)h`L zSIl7zyYfa@NwIMxUxdhI9@lEVJl2E}N^E8OiyvtjKYnzCJEHo}|mqKch zxNuSeL-tU9TVREieT#lS7pijSYUjrp!|FQuR7sB5a_Q~$&;H5_#8)pX2M_-kCyO`q zvzJvi^YSZ{a(PqcToR84v~4Xv=>ROcdV`I5tKf~1^#(gyykzfkTrg?;HSNvWc|02c ztlL1Jp3%kuNvlKp&$E_w{dTx3(%|0KXTEUPV~VFY8E9sW3EX$i6B8<;Rot4kfKu46 zi6BfJz)R#-H&gY+Y)xrTA?fN&$Z9mE3@#w*Q9=EcRgMu_naT?62ukZm1||E(T&ixD4ae{c ztc zT?1M*IC#Llf`H!sP;}oQu-tO40aS?pT|Xl^)Hx6ifi2K5^@Tyb@I)$u`K*v|*KeL0 zGkO?w>pP+-G4xj9ZYZ6PT7%7{qTjTYm2eic-#1oTCGK-H3ho%l0PY1R=09%Bw1q~-m!?9m-ooa-sC-iA->?O zTslw9P`%4LBb!LV1MRV0c0JTKbDR}2MR@x`sb@$s9UcSA@R2$7=nQV5{%vwX(V z`5>kTCG$E}RCPGh=`;tybBdF4j=FMo$BeM&{0TWCa^Kl&Jrl$}Xmph&+;kFgflbh&oe^BKbJ}J0x2gJ=-FdvTR*xt9!;DYO8)N-<4JFm@osCW-aDAc55;^ix zC!c-W=>65jK4u!FaFw&@(s$bqk;jFiF<+C5tat?C;@f-lK}U+ndn3<&gp@Vuf|gPC z=!Q*_B#7VoJ91`m<{AMQ-+$fQWwyN0%Xe3FYbLXsq+u-Y9guCht(tJO>tyWf4|K#t zARSpz%5t9$shp%XFLY&AsJYs=U}PbW`sI`w4xCMNp=sQ50Pb_$4sgwhG9mGk11Sh>C++^@|n%5DPNUcz~ha*y_p7C+*vAu1Kw1QBj&M}N~I#f;!<3b zE_&_B^6dPj?}KMCgV-8L2YUO|qvV!xRx?qBhTP?Gt!`t*dWh4O59np1pnfcFx}0wQ zd{}GEnh?NeYihkW9~|c0AFqsFUl0?oh+^U?#hG#}4P1>TVsYxc9+ zq{#Ll?9W?duZqS;U-r{lshD0Q3P$tmnp_UtWrpgrP~KRnp$&O3_5>WPs86X)86w;K zRVJ}LO4M7G!af-#=WlHX>Ny=xE?YfN-Ci{oi}Ne?+;^S)({pjuQ{kCYWsuAtUjqy< z+6M1>P8d_P)Uot<#&tqzwA9@3qXJ!QN5LJGelGs+(>*|8zp5>;K{N=p#NZe%c8|sl znSGJR5Xi?Fenvn#5r=c=^<_vQ-kH~71?ornJ)nq!75CA^5zUNPgvKL_i5LhmzZ-n~ z>KJ@vbhhieW!OY>sXanme<%Kc#^B`aJl=U6Su{_u0xF~GfcacZ}anzx_&xJVaX74!G^!@=Hg?P(*V6&Trwo5!^&h4ci_@c@A`Ar+u+m3Y1$oHKJR}*8|M+ z`*w=QMH?-|Hbd)JzXIUEPrv zt`p_K_YV%;qYLRzWhaWE1epAi#&LB~q>YaaRit2L=M}Co^*jW{Mr8#k-xK8rF>r40 zOGakHtH4_y)4Q?K{TwaI-rf2wqF~zlgWVVv!-sE1U8L_%A#|%<7h^`rt#WDhowJ9iG2Bg8y{?U!lWap~GLH!(XAp|F=R1*ss0nUx^$3A#eCk8`fWO!(Va3 zUva}D6!(Va3Uva}D6!(Va3Uva}D6!(Va3Uva}D6!(Va3Uva}< zal>D6!(Va3Uvb0#f5Z*{tGzD)hwA_SpCVZzi3pLDEjx);Bun;P3pK`AVvJ^FON){s zDr<>~7NxWyQML&AP$;Ej4T+R25v9-XUSrJMYsQ%B`+T48|37-}^VH{4=XK6`pL6be zyXOTS0l*0whJo#W@PQoxFbEnL1Pu&=1_nU`gP?&y(7+&QU=TDg2pSj!4Ge+?20;UZ zpn*Zqz#wQ~5Hv6d8W;o(41xv*K?8%JfkDu~AZYme1Pzd_`UxTiH-L!29e7|{^$a2g z1`z{;h=D=Gz#w8^5HT=_7#Kth3?c>w5d(vWfkDK;AYxz;F))Z27(@&VA_fK#!~cgw z4D*1?t`rFuz|NzvEi?w<0)udYLAbymTwo9`FbEeIgbNJ91qR^)gK**hb;1R1V17)M zSb;Ni$}uy8SmD1&tiTQo76k$Y3d8i@Cr|(vUQ>t?B!RZ5(o@s0ZO8?J{9)uQ-18tNC+ZVwAN+?)U+KfLQW^9Kk3 zK2sb+1jvD@D@Xyr$juRl#JQpI1f}I^DGiq?Hmyu&ELMIu5;v|cC>ngIs#|CR_3k2w zXiuyY+8F7HbV1_?s`3M*C)4^j2PO|nl1MJk6Jy|n_Vjl1_Mc?A=K`dI&y2N&Isz)) z3XHx<(V*hsLshiqHmD=`AdbL#;qe3x7=j zs@b`jiBl$wRxKb3e5i_p8%jkx6@oa>Sn#1L?hq{Rp(Olq!hC+I~ zVLd0}74+e>euRsLG8a=3?TdCqdU+9)ryD^QHs}A=ZudHz(^P)?h5Zu=FRm_;iKm;2=;Zc)K+@jfqe zi#Lp&$1qGeI>SFF@r1=fLkr8oODE@qmM>0a&kseX`m>h?ED8wWUN8O7LHg}dciF*t z?;|RMF6HhZo7uqqs!FG!wwtwQjYL!w z7DF?PC?o6rp}in7z)6krK>wx!W`9osAcZ}!E^eq9Y7%xJ8dxxpe(e4OnxOrV7%!r4 zn8he&nwcRJGa<)A0gb$clk5; zu@tiAJs=<4fX?7%y|exPqWc)lU7PRiK5i8zmlR{6{dhEgd7aa{XJ34Liw(zG!Z#Kb zR97u=DYA0z2^SrGY&tYQw9`|Y6&qLC-q54b3H(y<9T+Y+_>*lH&&Hd6oGR>|%N0*l zUCl1vV^|{mflpTIyLQPLyY}o`+9lz^vP4JMmD%`Z zPId+g8x&VR!-!vx54R8qC|wu&us6)lYJryew=E9}@#i&-3`WbNjIw$jUHH1mko&OUC}FOK z{6aUsC0NDGV~*Qj+hs|ogOuDMK8ayZiu}sb~-nJE8*U@{zkd2`61kV-R*rF8n4^=)S}j}_Ho$Wu3vLThV{IZv6#3~@fVyJ?n0x4Ppxo&1H&*SB7> zsfl>>{a?c(uaO-$%e*=Q-}zKWUf!--;oEIvzM?FlmN%*Ep{jeYs?SFq|Gmn_T<3#W zUF;=!O|l=hEy&9sEFX(~@GwtG&}r_AVwZ;4_It`wvszDDT@gKGnxnnGfmKcq2XLoDa8(>u)EO|F;!l^JoH6@6!R6n|HFQgqE* zwRDalRpkN$WfAGMUZGcP@JZa*n)0t|O=1eOA9!EpV|$S&Yb%7#u~3SOVuBs1#$zV=MFqM4T7s=kC;T+n^i|F52!xn zutQTcc{H_*DLX`~=u>dFc+AOWSHXgp!oQLYo=V)|ezEi?T3f32J;F9JMac~RDdJ2) zh!PKH+lrzL$@2gL(FDf`DfNm^dZo0<4VX5ide>TJ>dl}&ZpYDlh6F+%M zV?*mxFQcGH{mRI**LpW7*;aXDvde~~eScmN?WoYLczM`V$=K+Q9>=%02f+$SczuBt z(k#Eji32Fx;A8ZM719-~g7RKCtQQ*R4QxG3R|7qf81#AztRwI@NhNz5FfFUU|H5lF zuw|qO?9;6MO@)AWm%JawV;o`#iE5~{hZnV;M2)lbQ^u&v8G zbU7p9E>qwEdsg0Blf1sheZ5VMe8;p<4O*XKR-qqW-YR$`a>z3NhEcP_#d6Dl7W10o zxeJUJ&du6`w%FI)v-nY%iJ7m8)wXBaCl;68*3jfB!ABe(YpGq<{o}&W{MszOiVTmk zCeyNvG%b!x;R8ia?+2R1wGS$_iaV&gu4S&`e;v*(uKJZ{0K^-)(I* z6i}OuGiPOv-QMil*yh{D>ErvWxJ^j7x$3e4DGuP%HaR-n?&X1;*cYRFp0*j%;+%TKr)Z})ItWBPqtUnm^;A8T~xD*5Z>9sXm-I1{iM+q?Q)F4j{r2=Y*5V1=))hzW_1`l^tt+w&LYx&^OnSI%9>A3E-{Z`_; z-Err>p5;Mbxpm(S7x3u9o5;8lpJ@MYA3ZLw;FzpUZo&F;2_Sa0jt~GM?4SV-LwmEI_uWiOfHA1Ta|VdmS<=H)!_y@`0F zZgOvzyJNFq@HVp`H7oo>?v}%L7RW+h1Amd^trFjxRz#^DeY(m^fSql_%GkqJCGNBI zbM{rQYdWHrJruU|+PRiBO;_seKU`mB!ltUBB#`3o96PkjUCU60CI8i@BR`^U#HO<{ z^P=<$`j!qKN@P1M)UhS=^}12Pyrc)id-&X1iX^hHTV?XCTG_5P@6z4jH~alOjy2w` z>*5ZS6`t3oQdSpk@hEhoOAa#Fa`<0wZ>1dz6e3wJzdrYP#rBsqJvj^H!ZeJpD95Sb zZ`H74(*%)QO0iFS3N%|N-c;6@-;&phD?FogXZdEbdGelX2JPBPSbRjG{M=4 zp(7#aP`aVlXn{)iX(~& zI*)J27!uZeo~fdHOQW>T`n0vRXOq0DU}ToTD(~~VSF`&soa4bXr=+UnSweQGnGYVh zwB}X9`_`^3HmwmMwkJ#ZmG{2NK+G~1<_S`2<@%7utbre1vz({qUBV^pZ3o3V@^iU z1@llpZP{Z8!$g^qmE|mD5fum4V3%-K8D!}+?yow%zhy)9$g-t(*#?lyhxD8`nGT!G zPx%(wdGAGU?>U7q9pllYLou}{`y{LON@#3+Ral1=I^eKKU49g`hudyRyZDLYUGmqR ze>mD%R6U95IAfNk`lGKqLCQv!m#Kc^fo?^Pk)qzx`y0*rJk?5FqXlz3jq~GeD_mc9 zRVRom<|7NL7wJDh{Evm-4vY0{PS+Qu~4|b(ZC_!o%!E)op&)pLXvS+V4AXe8MZXr_fvwMrhjg<22cL}N8 z;#}TQ!w!b0?l*`uqzPH8@Go)7du8^6^WlxiIJZNq_EqH{&l}5Cb8lj0N*!e#yr+BL zovmPGeU*TQZ4ct$F4J3^cJi$I9QBXqSj$H}g$v#;owDZ}6s#`cGFFcDacut(YX3Pr z^!VZs0jVFlR!jUV8h0r49rt8z{U+C7ZBZs)Zu83JjD&tlWYKG-g=RxzI**@sqy%ZR zdF|L;Yp0)^ITXJq_+;GBO?J-YuIFzb`dd}{@4TKB_!@og#o|uM2c?GYD&O~7W%;vw zzOqzinf>`M@0xA0wW=fr7d~GceZNyU_2K#fZaJLcvr2^M*yC_7 zmAwZ7MAh4pE7^|a7MYYk30}tk=J5ex^~cNn7woX!{p9|^ZSSmyxluyBtB&n>*OXm< z)l@*@TVv$=Mcq0dH8o8gFGL&cYstJ-k{=g-!1cLRL`YqtZlUNglk+<7gH?(TiRg7C zeeXVZ@7A~QIYY-{Zk!A7H}L(HFL6pzx(%)Gf4j!-Q(#xd2Vb**G7Jhv%Rv) ztvt>d=q2ZweUEw7bBiN)Vcmxd9A(co9P~S@y;qR^tlelb)BUn9S3SKHu(yly9PTkM z=cvmw{%-G)67{xg{z8*~ek~h(Ja3Hm>-OPU$^{Fgd!yg4HNAa>=gSEm%bvt5O?ulN zF!QfE&FTEqo_%hr`AAl#FzeMb>+h_})Qf%e&qhRZhbr?+U-z@S^)ugGiTlPR7Wm<1Mx)#bew_H=?fKIA!w2gxs>!)LR_5lI z+sP@GXz(sWu9vl5i{Fi#f{)LgpP%!hVa2YsbonLwQR}9BgcaV zV~6Xu``zdYsf<6~l~>+Zyu3VQpM~h1v-iI!1Py+6khs+T`P#!Uov_$YqT`tbA)MijVR`- zV=<5MS{?=a^Dk{PJ`G9QK9H4RmhUt)%}mH_Uh8r@q&QA^QQ*MG&e-Q4o+>>li`{SK zDUU!r=0qG%>-I=gOX1NOdY&mYz^13k(j0Wa<)O$|T$Z!f6IrQOZkXLeBS&br$% zl7p4zOEX1x{)S0tba9{WQ{3bN)ZB2i|$snl{i+sNn>laiGUfgynjC|++7Qg8CIALKvxCHpS&NwP5i z<*=9&)pEAVhKkJh7nlO~Pxs)e1$t1WG*W z-VbFU`cu?7qgl#kmle(m5=|)GWl`Mdf3u;h;;dNunvJLJXCL2?z+0RzpYq-RdSKU% zog8R2e%zPxqg(7d0$YV2)o*pm(Cpl?TV_5Y>8o*o%+a4C4-Xow+1->WwB_Qyo8CG8 zhjKh_h`r%$PwBIewvURsyQ_I6m+UPM2SJHNeybtU>)LKJb3(bIAzeZPElB#`ALJ^UY%<3S4Voh?>Me4%i!%VtABZC zdBDxRmzUHpH0-;!+n4u8nQ1n%%KGhDE9}av7U_y#`)W-$U<_;B(&$>Gvt48`Ziv*vPVF|L_XD_0`YL&Ar*l61?kIXu` zUIT-M&hOsI^Ht^ff7JM==B^fQ8c6L;wv%t3f8z9PX|G66d-)N&vGjWXYl@}z)g4A7 z+!p;`(U(t_zV1mc=@`3(!m93P7wIh-FzJ?Gf-Owctb5~p{5==HfsbeFyAg&fMi-VabDDcL2-!HFvY2*H>!R-`8cOS@Mk`@Gmo&ns%!N+1NOtlI2=jrzZvUC%F z-uJup(qmrKR;KO-;lVotX}M9~a$P!N56#Ih4$b#q-Rbj~uLo5ssI?m7ug-KcAH%p?Tma+}`Aq3qekpeQsl9&M0r1Mkj66_#i;$#H2 zPeXV5DJu|5)MQPJoVtPX7i%I3kWmxKuTc?pvWPLtsEPl(+q9%_3g8>H{FB$hxe=eW zfI|+l%iF-FDfyi`;C?t*3t=0X}N8~gx$!lLyj0cZjP17_7G|8VA}0oU_sIH_1sP&~K$PL!#|H%4W$;f`Mjz z5u2G=WS0hM+qWPJuh(oaqJsej=qT{0Pe6hLb|uJq8J&=ji-Q2VqqB((#c-i)unNRr zRdG7eF-RXYcx*eJ*_46xA;8JM2TZu*Cchhnm-ldUMx*=*H{NJ#^T| zUP&)32678yy6_^XjK1Qkhwhd7^a+UObm08c8KQE}ivPG@L6wOm&4EReo>Y*9#DK5V z%ycD9&uB*-yojno5F6=4BwjQ9o$MnP9RvcbbB5CN*-AtvTyUk|?u`(;^Zo#R@{%iU zCBSSVB|HKFEkJ5Azwd$xC4f1hw=)(8-ub1SD4;es`3jDJuWijaz^8$eE&<;H*?&U2Llpomb(wV8cUC=J=Gmy`EYzTxSMAbgIzvnoJo?4zxW?0W{Y9qW@161hK6PWK$7Lu?Vt0@-}Leb;$EYjihUN<`p2rn@JjhI{n zV4+oX1CQUAo<#py8g4nw8+{P=5#N%@;Q>=yLya7LJaN5{-mc_d^#Ptu;H5H^CA_=g z5TwZ;7_6shK{z6Dgpd4aBc0t1eJ}GujQIjZ!UEGuv?mI@;|@rk|BcGalwgCZJ5;g= zMDn`T5I0Rq#sD)4;M2VEPYMAHm7!@ddSTkHfMCSX#6Y6F-Fzm@NvCEGA?84HI5%%b~EI&TcM~kw(M3N|<@1nK>9~0UESii1$Q#;a#!b zgz>^sGmtP|{V*_6%zrFRL7d(6dOBIdavhA=>?4U-Nt%tY_ zs0`zu_yEKIi_#~sq@4!1SW=9E6*Pg8Sn$(m@+;7^L7ZT^L$@;qDS=@8o!r3Br2*md zsBLEu90M0ls%@YJn>SE!3_&{fPznxp)Y|e5GW@{Tcii@u?+Z~BVYv8JsE-# zBd`z^fP`p270Ec%UV`)xN*`sDA{E~5g7}IdM5@k4au<>G2BrUg8w~MD3&3Gu)uE2@ zhwU+-K;k>71ED9r5cg729v_qMVb>||ED5Q@&{z0x-NeQZcW6aoQ0(vt{a-2FoX0qN~U-f;ndbJ(9tIiCn{@U9`y>gmTk zi#+(qI+6gADK-lsxe6|sH2(t)DWxKrVs{eSVDLU7f|FhY$3=3^R5M^}8j7t%NXEeB z6Zg%583tg?zG>x8b}a$SpaCHCA$85xaqmTL5-NnP#T~-dBV;KO*G9VTy9eyNrxuP;4wh^3v4)C`8@Cw63R# z0qvFo_=;ku6cQfXCTLCEz(&beb42{(Y9ELbe1oNR#OPK@e9Evc6TM08-`@qr2k2?yrV(37l zeUeLDO$M$}H9LMs+P zU$7MmMSTf1Z)z(9^1_4V`!ju~-bb8HBZ3E~_Cg@n2(jq*G$KD913M#3;}Uq-li#r^ z)biz@xdPy=yBWna9C8C$rWI;6(F>_HwO;_>cN%Z^soerde$NWB5unrTDLPP$1@Hsg zX@+8IzW`!3fisSe^y&n8BT@K#pZq%9)ZPK)?yy}aPuEN#?a5j ziQ$DnWCiIjp~FHDk}$cQyvj$XdxFKCv*TQFx}$i2(XRe=8@Zehxw&0E2%)3yL`bejGB*3wZjR q2$iRMK>l7%jQ&3O-^~dTMY_E}J0}Qz+uaauh;IrA#0q6F{r(TiT$A$v literal 0 HcmV?d00001 From 3614fb9bd6f2d74dc4abb1eeb9f1af3f9a866e69 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Thu, 19 Jan 2023 10:08:44 -0600 Subject: [PATCH 04/13] unit tests for list command --- .../deploy/tool/ArchiveHelperListTest.java | 1072 ++++++++++++++++- 1 file changed, 1066 insertions(+), 6 deletions(-) diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java index 07f11e9672..0a09bb5e04 100644 --- a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java @@ -11,12 +11,19 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.logging.Level; +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.util.ExitCode; import oracle.weblogic.deploy.util.WLSDeployZipFileTest; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -53,16 +60,136 @@ public class ArchiveHelperListTest { "wlsdeploy/applications/my-other-app/WEB-INF/weblogic.xml" }; - private static final String[] LIST_APPS_EXPECTED = new String[LIST_APP_DIR_EXPECTED.length + 3]; + private static final String[] LIST_CP_LIBS_EXPECTED = new String[] { + "wlsdeploy/classpathLibraries/", + "wlsdeploy/classpathLibraries/bar.jar" + }; + + private static final String[] LIST_COH_MYCLUSTER_EXPECTED = new String[] { + "wlsdeploy/coherence/mycluster/", + "wlsdeploy/coherence/mycluster/active/", + "wlsdeploy/coherence/mycluster/snapshot/", + "wlsdeploy/coherence/mycluster/trash/", + "wlsdeploy/coherence/mycluster/cache-config.xml" + }; + + private static final String[] LIST_COH_MYCLUSTER2_EXPECTED = new String[] { + "wlsdeploy/coherence/mycluster2/", + "wlsdeploy/coherence/mycluster2/snapshot/", + "wlsdeploy/coherence/mycluster2/cache-config.xml" + }; + + private static final String[] LIST_MIME_MAPPINGS_EXPECTED = new String[] { + "wlsdeploy/config/", + "wlsdeploy/config/mimemappings.properties" + }; + + private static final String[] LIST_MIME_MAPPINGS_PROPERTIES_EXPECTED = new String[] { + "wlsdeploy/config/mimemappings.properties" + }; + + private static final String[] LIST_CUSTOM_MYDIR_EXPECTED = new String[] { + "wlsdeploy/custom/mydir/", + "wlsdeploy/custom/mydir/bar.properties" + }; + + private static final String[] LIST_CUSTOM_EXPECTED = new String[] { + "wlsdeploy/custom/", + "wlsdeploy/custom/mydir/", + "wlsdeploy/custom/mydir/bar.properties", + "wlsdeploy/custom/foo.properties" + }; + + private static final String[] LIST_RCU_WALLET_EXPECTED = new String[] { + "wlsdeploy/dbWallets/rcu/", + "wlsdeploy/dbWallets/rcu/cwallet.sso", + "wlsdeploy/dbWallets/rcu/ewallet.p12", + "wlsdeploy/dbWallets/rcu/ewallet.pem", + "wlsdeploy/dbWallets/rcu/keystore.jks", + "wlsdeploy/dbWallets/rcu/ojdbc.properties", + "wlsdeploy/dbWallets/rcu/README", + "wlsdeploy/dbWallets/rcu/sqlnet.ora", + "wlsdeploy/dbWallets/rcu/tnsnames.ora", + "wlsdeploy/dbWallets/rcu/truststore.jks" + }; + + private static final String[] LIST_WALLET1_EXPECTED = new String[] { + "wlsdeploy/dbWallets/wallet1/", + "wlsdeploy/dbWallets/wallet1/atpwallet.zip" + }; + + private static final String[] LIST_STRUCTURED_APP_WEBAPP_EXPECTED = new String[] { + "wlsdeploy/structuredApplications/webapp/", + "wlsdeploy/structuredApplications/webapp/app/", + "wlsdeploy/structuredApplications/webapp/app/META-INF/", + "wlsdeploy/structuredApplications/webapp/app/META-INF/MANIFEST.MF", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/weblogic/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/weblogic/example/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/weblogic/example/HelloServlet.class", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/hello.properties", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/web.xml", + "wlsdeploy/structuredApplications/webapp/plan/", + "wlsdeploy/structuredApplications/webapp/plan/AppFileOverrides/", + "wlsdeploy/structuredApplications/webapp/plan/AppFileOverrides/hello.properties", + "wlsdeploy/structuredApplications/webapp/plan/WEB-INF/", + "wlsdeploy/structuredApplications/webapp/plan/WEB-INF/weblogic.xml", + "wlsdeploy/structuredApplications/webapp/plan/plan.xml" + }; + + private static final String[] LIST_STRUCTURED_APP_WEBAPP1_EXPECTED = new String[] { + "wlsdeploy/structuredApplications/webapp1/", + "wlsdeploy/structuredApplications/webapp1/app/", + "wlsdeploy/structuredApplications/webapp1/app/webapp.war", + "wlsdeploy/structuredApplications/webapp1/plan1/", + "wlsdeploy/structuredApplications/webapp1/plan1/AppFileOverrides/", + "wlsdeploy/structuredApplications/webapp1/plan1/AppFileOverrides/hello.properties", + "wlsdeploy/structuredApplications/webapp1/plan1/WEB-INF/", + "wlsdeploy/structuredApplications/webapp1/plan1/WEB-INF/weblogic.xml", + "wlsdeploy/structuredApplications/webapp1/plan1/plan.xml", + "wlsdeploy/structuredApplications/webapp1/plan2/", + "wlsdeploy/structuredApplications/webapp1/plan2/AppFileOverrides/", + "wlsdeploy/structuredApplications/webapp1/plan2/AppFileOverrides/hello.properties", + "wlsdeploy/structuredApplications/webapp1/plan2/WEB-INF/", + "wlsdeploy/structuredApplications/webapp1/plan2/WEB-INF/weblogic.xml", + "wlsdeploy/structuredApplications/webapp1/plan2/plan.xml" + }; + + private static final String[] LIST_APPS_EXPECTED; + private static final String[] LIST_COH_EXPECTED; + + private static final String[] LIST_STRUCTURED_APPS_EXPECTED; static { String[] files = new String[] { + "wlsdeploy/applications/", "wlsdeploy/applications/my-app.war", "wlsdeploy/applications/my-app.xml", "wlsdeploy/applications/my-other-app.war" }; - System.arraycopy(files, 0, LIST_APPS_EXPECTED, 0, 3); - System.arraycopy(LIST_APP_DIR_EXPECTED, 0, LIST_APPS_EXPECTED, 3, LIST_APP_DIR_EXPECTED.length); + LIST_APPS_EXPECTED = new String[LIST_APP_DIR_EXPECTED.length + files.length]; + + System.arraycopy(files, 0, LIST_APPS_EXPECTED, 0, files.length); + System.arraycopy(LIST_APP_DIR_EXPECTED, 0, LIST_APPS_EXPECTED, + files.length, LIST_APP_DIR_EXPECTED.length); + + LIST_COH_EXPECTED = new String[LIST_COH_MYCLUSTER_EXPECTED.length + LIST_COH_MYCLUSTER2_EXPECTED.length + 1]; + LIST_COH_EXPECTED[0] = "wlsdeploy/coherence/"; + System.arraycopy(LIST_COH_MYCLUSTER_EXPECTED, 0, LIST_COH_EXPECTED,1, + LIST_COH_MYCLUSTER_EXPECTED.length); + System.arraycopy(LIST_COH_MYCLUSTER2_EXPECTED, 0, LIST_COH_EXPECTED, + LIST_COH_MYCLUSTER_EXPECTED.length + 1, LIST_COH_MYCLUSTER2_EXPECTED.length); + + LIST_STRUCTURED_APPS_EXPECTED = new String[LIST_STRUCTURED_APP_WEBAPP_EXPECTED.length + + LIST_STRUCTURED_APP_WEBAPP1_EXPECTED.length + 1]; + LIST_STRUCTURED_APPS_EXPECTED[0] = "wlsdeploy/structuredApplications/"; + System.arraycopy(LIST_STRUCTURED_APP_WEBAPP_EXPECTED, 0, LIST_STRUCTURED_APPS_EXPECTED, 1, + LIST_STRUCTURED_APP_WEBAPP_EXPECTED.length); + System.arraycopy(LIST_STRUCTURED_APP_WEBAPP1_EXPECTED, 0, LIST_STRUCTURED_APPS_EXPECTED, + LIST_STRUCTURED_APP_WEBAPP_EXPECTED.length + 1, LIST_STRUCTURED_APP_WEBAPP1_EXPECTED.length); } @BeforeAll @@ -71,6 +198,49 @@ static void initialize() throws Exception { throw new Exception("Unable to create unit test directory: " + UNIT_TEST_TARGET_DIR); } Files.copy(ARCHIVE_HELPER_SOURCE_ZIP, ARCHIVE_HELPER_TARGET_ZIP, StandardCopyOption.REPLACE_EXISTING); + + PlatformLogger logger = WLSDeployLogFactory.getLogger(LOGGER_NAME); + logger.setLevel(Level.OFF); + } + + @Test + void testListAppsNoArchive_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "application" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testListAppsBadArchive_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "application", + "-archive_file", + "foo.zip" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.ARG_VALIDATION_ERROR, actual, + "expected command to exit with exit code " + ExitCode.ARG_VALIDATION_ERROR); } @Test @@ -95,7 +265,7 @@ void testListAppFile_ReturnsExpectedName() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(1, outputLines.length, "expected list applications my-app.war to return 1 entry"); + assertEquals(1, outputLines.length, "expected list applications -name my-app.war to return 1 entry"); assertEquals(expectedPath, outputLines[0],"expected " + expectedPath); } @@ -122,7 +292,7 @@ void testListAppDirectory_ReturnsExpectedNames() { assertEquals(0, actual, "expected command to exit with exit code 0"); assertEquals(expectedPaths.size(), outputLines.length, - "expected list applications my-other-app to return " + expectedPaths.size() + " entries"); + "expected list applications -name my-other-app to return " + expectedPaths.size() + " entries"); for (String actualLine : outputLines) { assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); } @@ -138,7 +308,250 @@ void testListApps_ReturnsExceptedNames() { "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList(LIST_APP_DIR_EXPECTED); + List expectedPaths = Arrays.asList(LIST_APPS_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list applications to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListSharedLibraries_ReturnsNoNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String outputLines = outStringWriter.getBuffer().toString().trim(); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals("", outputLines, "expected list sharedLibrary to return nothing"); + } + + @Test + void testListSharedLibraryUnknownFile_ReturnsNoNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo.jar" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String outputLines = outStringWriter.getBuffer().toString().trim(); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals("", outputLines, "expected list sharedLibrary -name foo.jar to return nothing"); + } + + @Test + void testListClasspathLibs_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "classpathLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList(LIST_CP_LIBS_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list classpathLibrary to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListClasspathLibFile_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "classpathLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "bar.jar" + }; + List expectedPaths = Collections.singletonList("wlsdeploy/classpathLibraries/bar.jar"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list classpathLibrary to return " + expectedPaths.size() + " entry"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListCohMyCluster_ReturnedExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "coherence", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "mycluster" + }; + List expectedPaths = Arrays.asList(LIST_COH_MYCLUSTER_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list coherence -cluster_name mycluster to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListCohMyCluster2_ReturnedExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "coherence", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "mycluster2" + }; + List expectedPaths = Arrays.asList(LIST_COH_MYCLUSTER2_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list coherence -cluster_name mycluster2 to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListCoh_ReturnedExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "coherence", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList(LIST_COH_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list coherence to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListMime_ReturnedExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "mimeMapping", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList(LIST_MIME_MAPPINGS_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list mimeMapping to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListMimeMappingProperties_ReturnedExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "mimeMapping", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "mimemappings.properties" + }; + List expectedPaths = Arrays.asList(LIST_MIME_MAPPINGS_PROPERTIES_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -147,5 +560,652 @@ void testListApps_ReturnsExceptedNames() { } String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list mimeMapping to return " + expectedPaths.size() + " entry"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListCustom_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "custom", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList(LIST_CUSTOM_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list custom to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListCustomDir_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "custom", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "mydir" + }; + List expectedPaths = Arrays.asList(LIST_CUSTOM_MYDIR_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list custom to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListCustomFile_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "custom", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo.properties" + }; + List expectedPaths = Collections.singletonList("wlsdeploy/custom/foo.properties"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list custom to return " + expectedPaths.size() + " entry"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListDbWalletRCU_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "databaseWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + DEFAULT_RCU_WALLET_NAME + }; + List expectedPaths = Arrays.asList(LIST_RCU_WALLET_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, "expected list databaseWallet -name " + + DEFAULT_RCU_WALLET_NAME + " to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListRCUWallet_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "rcuWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList(LIST_RCU_WALLET_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list rcuWallet to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListWallet1Dir_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "databaseWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "wallet1" + }; + List expectedPaths = Arrays.asList(LIST_WALLET1_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list databaseWallet -name wallet1 to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListDomainBin_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "domainBinScript", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList("wlsdeploy/domainBin/", "wlsdeploy/domainBin/setUserOverrides.sh"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list domainBinScript to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListDomainBinFile_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "domainBinScript", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "setUserOverrides.sh" + }; + List expectedPaths = Collections.singletonList("wlsdeploy/domainBin/setUserOverrides.sh"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list domainBinScript -name setUserOverrides.sh to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListDomainLib_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "domainLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList("wlsdeploy/domainLibraries/", "wlsdeploy/domainLibraries/foo.jar"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list domainLibrary to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListDomainLibFile_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "domainLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo.jar" + }; + List expectedPaths = Collections.singletonList("wlsdeploy/domainLibraries/foo.jar"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list domainLibrary -name foo.jar to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListNodeManager_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "nodeManagerKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList( + "wlsdeploy/nodeManager/", + "wlsdeploy/nodeManager/nmIdentity.jks", + "wlsdeploy/nodeManager/nmTrust.jks" + ); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list nodeManagerKeystore to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListNodeManagerFile_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "nodeManagerKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "nmTrust.jks" + }; + List expectedPaths = Collections.singletonList("wlsdeploy/nodeManager/nmTrust.jks"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list nodeManagerKeystore -name nmTrust.jks to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListOPSSWallet_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "opssWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList( + "wlsdeploy/opsswallet/", + "wlsdeploy/opsswallet/opss-wallet.zip" + ); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list opssWallet to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListScripts_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "script", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList( + "wlsdeploy/scripts/", + "wlsdeploy/scripts/my_fancy_script.sh" + ); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list script to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListScriptsFile_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "script", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my_fancy_script.sh" + }; + List expectedPaths = Collections.singletonList("wlsdeploy/scripts/my_fancy_script.sh"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list script -name my_fancy_script.sh to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListServerKeystore_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-server_name", + "AdminServer" + }; + List expectedPaths = Arrays.asList( + "wlsdeploy/servers/AdminServer/", + "wlsdeploy/servers/AdminServer/identity.jks", + "wlsdeploy/servers/AdminServer/trust.jks" + ); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list serverKeystore to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListServerKeystoreFile_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-server_name", + "AdminServer", + "-name", + "trust.jks" + }; + List expectedPaths = Collections.singletonList("wlsdeploy/servers/AdminServer/trust.jks"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list serverKeystore -name trust.jks to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListFileStore_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "fileStore", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList( + "wlsdeploy/stores/", + "wlsdeploy/stores/fs1/", + "wlsdeploy/stores/fs2/", + "wlsdeploy/stores/fs3/" + ); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list fileStore to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListFileStoreDir_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "fileStore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "fs2" + }; + List expectedPaths = Collections.singletonList("wlsdeploy/stores/fs2/"); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list fileStore -name fs2 to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListStructuredAppWebapp_ReturnedExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "structuredApplication", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "webapp" + }; + List expectedPaths = Arrays.asList(LIST_STRUCTURED_APP_WEBAPP_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list structuredApplication -name webapp to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListStructuredAppWebapp1_ReturnedExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "structuredApplication", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "webapp1" + }; + List expectedPaths = Arrays.asList(LIST_STRUCTURED_APP_WEBAPP1_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list structuredApplication -name webapp1 to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } + } + + @Test + void testListStructuredApp_ReturnedExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "structuredApplication", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList(LIST_STRUCTURED_APPS_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals(expectedPaths.size(), outputLines.length, + "expected list structuredApplication to return " + expectedPaths.size() + " entries"); + for (String actualLine : outputLines) { + assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + } } } From 60b773fd5612f8ad3a971308c20be4ce623fcd73 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Fri, 20 Jan 2023 13:46:18 -0600 Subject: [PATCH 05/13] intermediate checkpoint --- .../deploy/util/WLSDeployArchive.java | 128 ++++++-- .../deploy/messages/wlsdeploy_rb.properties | 3 + .../deploy/tool/ArchiveHelperListTest.java | 259 +++++----------- .../deploy/tool/ArchiveHelperRemoveTest.java | 138 +++++++++ .../tool/ArchiveHelperTestConstants.java | 289 ++++++++++++++++++ 5 files changed, 608 insertions(+), 209 deletions(-) create mode 100644 core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java create mode 100644 core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java index 099da8c45b..6aa84ea5d3 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java @@ -293,6 +293,8 @@ public static String getPathForType(ArchiveEntryType type) { break; case COHERENCE: + case COHERENCE_CONFIG: + case COHERENCE_PERSISTENCE_DIR: pathPrefix = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP; break; @@ -320,7 +322,9 @@ public static String getPathForType(ArchiveEntryType type) { pathPrefix = ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP; break; - // FIXME - need to log if receiving an unknown type + default: + LOGGER.warning("WLSDPLY-01438", type.name()); + break; } LOGGER.exiting(CLASS, METHOD, pathPrefix); @@ -342,25 +346,12 @@ public static String getPathForSegregationType(ArchiveEntryType type, String seg return pathPrefix; } - public static String getPathForSegregationType(ArchiveEntryType type, String segregationName, String name) { - final String METHOD = "getPathForSegregationType"; - LOGGER.entering(CLASS, METHOD, type, segregationName, name); - - String pathPrefix = getPathForSegregationType(type, segregationName); - if (!StringUtils.isEmpty(pathPrefix) && !StringUtils.isEmpty(name)) { - pathPrefix += name; - } - - LOGGER.exiting(CLASS, METHOD, pathPrefix); - return pathPrefix; - } - - /** - * Get archive path for the application name for use in the model. - * - * @param appPath name of the application - * @return archive path for use in the model - */ + /** + * Get archive path for the application name for use in the model. + * + * @param appPath name of the application + * @return archive path for use in the model + */ public static String getApplicationArchivePath(String appPath) { return getArchiveName(ARCHIVE_APPS_TARGET_DIR, appPath); } @@ -977,6 +968,68 @@ public void extractApplication(String applicationPath, File domainHome) throws W LOGGER.exiting(CLASS, METHOD); } + /** + * Remove the named application from the archive file. If this is the only application + * in the archive file, the application directory entry will also be removed, if present. + * + * @param appPath The application name (e.g., foo.ear) or the archive path + * to it (e.g., wlsdeploy/applications/foo.ear) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the app is not present or an IOException occurred while + * reading the archive or writing the file + * @throws IllegalArgumentException if the appPath is null or empty + */ + public int removeApplication(String appPath) throws WLSDeployArchiveIOException { + return removeApplication(appPath, false); + } + + /** + * Remove the named application from the archive file. If this is the only application + * in the archive file, the application directory entry will also be removed, if present. + * + * @param appPath The application name (e.g., foo.ear) or the archive path + * to it (e.g., wlsdeploy/applications/foo.ear) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the app is not present (and silent = false) or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the appPath is null or empty + */ + public int removeApplication(String appPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeApplication"; + LOGGER.entering(CLASS, METHOD, appPath, silent); + + validateNonEmptyString(appPath, "appPath", METHOD); + + String archivePath; + String appName; + if (appPath.startsWith(ARCHIVE_APPS_TARGET_DIR + ZIP_SEP)) { + archivePath = appPath; + appName = getNameFromPath(archivePath, ARCHIVE_APPS_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP + appPath; + appName = appPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.APPLICATION, appName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01440", appName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.APPLICATION, ARCHIVE_APPS_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // application plan methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1036,6 +1089,8 @@ public String replaceApplicationDeploymentPlan(String planPath, String sourceLoc return newName; } + + /////////////////////////////////////////////////////////////////////////////////////////////// // structured application methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -3143,4 +3198,37 @@ private String getDatabaseWalletArchivePathFromAddedFile(String walletParentPath } return result; } + + private String getNameFromPath(String path, int startIndex) throws WLSDeployArchiveIOException { + final String METHOD = "getNameFromPath"; + LOGGER.entering(CLASS, METHOD, path, startIndex); + + String result; + if (!StringUtils.isEmpty(path) && path.length() >= startIndex) { + result = path.substring(startIndex); + } else { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01439", startIndex, path); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + + private int removeEmptyTypeDir(ArchiveEntryType type, String prefixPath) throws WLSDeployArchiveIOException { + final String METHOD = "removeEmptyTypeDir"; + LOGGER.entering(CLASS, METHOD, type.name(), prefixPath); + + List zipEntries = getArchiveEntries(type); + + int result = 0; + if (zipEntries.size() == 1 && prefixPath.equals(zipEntries.get(0))) { + getZipFile().removeZipEntry(zipEntries.get(0)); + result = 1; + } + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } } diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index 4314fb0a07..d6206f0ba1 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -211,6 +211,9 @@ WLSDPLY-01434=Could not determine a valid archive path with an empty server name WLSDPLY-01435=Could not determine a valid archive path with an empty cluster name and Coherence config path {0} to replace Coherence cluster config file with {1} WLSDPLY-01436=Could not determine a valid archive path with an empty foreign server name and JMS foreign server binding path {0} to replace JMS foreign server binding file with {1} WLSDPLY-01437=Failed to add OPSS Wallet to archive because the archive file {0} already contains an OPSS wallet with {1} entries. +WLSDPLY-01438=Failed to get path for archive type {0} because it is not a known type. +WLSDPLY-01439=Failed to get name starting at index {0} from path {1} because the path is not long enough. +WLSDPLY-01440=Failed to remove application {0} from archive file {1} because the archive file did not contain {2}. # oracle.weblogic.deploy.util.WLSDeployZipFile.java WLSDPLY-01500=The zip file {0} has the saved entry {1} diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java index 0a09bb5e04..bf5af22a54 100644 --- a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved. + * Copyright (c) 2023, Oracle Corporation and/or its affiliates. All rights reserved. * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. */ package oracle.weblogic.deploy.tool; @@ -11,7 +11,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -23,6 +22,37 @@ import org.junit.jupiter.api.Test; import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.APPLICATIONS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIBS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_JAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER2_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_FOO_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_MYDIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLET_RCU_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLET_WALLET1_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_BIN_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_LIB_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_LIB_FOO_JAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FILE_STORES_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FILE_STORES_FS2_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MIME_MAPPINGS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MIME_MAPPING_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_APP_WAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_OTHER_APP_DIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.NODE_MANAGER_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.NODE_MANAGER_TRUST_JKS_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.OPSS_WALLET_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SCRIPTS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SCRIPTS_FANCY_SCRIPT_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SERVERS_ADMIN_SERVER_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SERVERS_ADMIN_SERVER_TRUST_JKS_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APPS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APP_WEBAPP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APP_WEBAPP1_CONTENTS; import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -38,159 +68,29 @@ public class ArchiveHelperListTest { new File(UNIT_TEST_TARGET_DIR, "archive-helper-test.zip").toPath(); private static final String ARCHIVE_HELPER_VALUE = ARCHIVE_HELPER_TARGET_ZIP.toFile().getAbsolutePath(); - private static final String[] LIST_APP_FILE_EXPECTED = new String[] {"wlsdeploy/applications/my-app.war"}; - - private static final String[] LIST_APP_DIR_EXPECTED = new String[] { - "wlsdeploy/applications/my-other-app/", - "wlsdeploy/applications/my-other-app/META-INF/", - "wlsdeploy/applications/my-other-app/META-INF/maven/", - "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/", - "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/", - "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.properties", - "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.xml", - "wlsdeploy/applications/my-other-app/META-INF/MANIFEST.MF", - "wlsdeploy/applications/my-other-app/WEB-INF/", - "wlsdeploy/applications/my-other-app/WEB-INF/classes/", - "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/", - "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/", - "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/platform/", - "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/platform/GetListenAddressServlet.class", - "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/platform/ListenAddressAndPort.class", - "wlsdeploy/applications/my-other-app/WEB-INF/web.xml", - "wlsdeploy/applications/my-other-app/WEB-INF/weblogic.xml" - }; - - private static final String[] LIST_CP_LIBS_EXPECTED = new String[] { - "wlsdeploy/classpathLibraries/", - "wlsdeploy/classpathLibraries/bar.jar" - }; - - private static final String[] LIST_COH_MYCLUSTER_EXPECTED = new String[] { - "wlsdeploy/coherence/mycluster/", - "wlsdeploy/coherence/mycluster/active/", - "wlsdeploy/coherence/mycluster/snapshot/", - "wlsdeploy/coherence/mycluster/trash/", - "wlsdeploy/coherence/mycluster/cache-config.xml" - }; - - private static final String[] LIST_COH_MYCLUSTER2_EXPECTED = new String[] { - "wlsdeploy/coherence/mycluster2/", - "wlsdeploy/coherence/mycluster2/snapshot/", - "wlsdeploy/coherence/mycluster2/cache-config.xml" - }; - - private static final String[] LIST_MIME_MAPPINGS_EXPECTED = new String[] { - "wlsdeploy/config/", - "wlsdeploy/config/mimemappings.properties" - }; - - private static final String[] LIST_MIME_MAPPINGS_PROPERTIES_EXPECTED = new String[] { - "wlsdeploy/config/mimemappings.properties" - }; - - private static final String[] LIST_CUSTOM_MYDIR_EXPECTED = new String[] { - "wlsdeploy/custom/mydir/", - "wlsdeploy/custom/mydir/bar.properties" - }; - - private static final String[] LIST_CUSTOM_EXPECTED = new String[] { - "wlsdeploy/custom/", - "wlsdeploy/custom/mydir/", - "wlsdeploy/custom/mydir/bar.properties", - "wlsdeploy/custom/foo.properties" - }; - - private static final String[] LIST_RCU_WALLET_EXPECTED = new String[] { - "wlsdeploy/dbWallets/rcu/", - "wlsdeploy/dbWallets/rcu/cwallet.sso", - "wlsdeploy/dbWallets/rcu/ewallet.p12", - "wlsdeploy/dbWallets/rcu/ewallet.pem", - "wlsdeploy/dbWallets/rcu/keystore.jks", - "wlsdeploy/dbWallets/rcu/ojdbc.properties", - "wlsdeploy/dbWallets/rcu/README", - "wlsdeploy/dbWallets/rcu/sqlnet.ora", - "wlsdeploy/dbWallets/rcu/tnsnames.ora", - "wlsdeploy/dbWallets/rcu/truststore.jks" - }; - - private static final String[] LIST_WALLET1_EXPECTED = new String[] { - "wlsdeploy/dbWallets/wallet1/", - "wlsdeploy/dbWallets/wallet1/atpwallet.zip" - }; - - private static final String[] LIST_STRUCTURED_APP_WEBAPP_EXPECTED = new String[] { - "wlsdeploy/structuredApplications/webapp/", - "wlsdeploy/structuredApplications/webapp/app/", - "wlsdeploy/structuredApplications/webapp/app/META-INF/", - "wlsdeploy/structuredApplications/webapp/app/META-INF/MANIFEST.MF", - "wlsdeploy/structuredApplications/webapp/app/WEB-INF/", - "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/", - "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/", - "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/", - "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/weblogic/", - "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/weblogic/example/", - "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/weblogic/example/HelloServlet.class", - "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/hello.properties", - "wlsdeploy/structuredApplications/webapp/app/WEB-INF/web.xml", - "wlsdeploy/structuredApplications/webapp/plan/", - "wlsdeploy/structuredApplications/webapp/plan/AppFileOverrides/", - "wlsdeploy/structuredApplications/webapp/plan/AppFileOverrides/hello.properties", - "wlsdeploy/structuredApplications/webapp/plan/WEB-INF/", - "wlsdeploy/structuredApplications/webapp/plan/WEB-INF/weblogic.xml", - "wlsdeploy/structuredApplications/webapp/plan/plan.xml" - }; - - private static final String[] LIST_STRUCTURED_APP_WEBAPP1_EXPECTED = new String[] { - "wlsdeploy/structuredApplications/webapp1/", - "wlsdeploy/structuredApplications/webapp1/app/", - "wlsdeploy/structuredApplications/webapp1/app/webapp.war", - "wlsdeploy/structuredApplications/webapp1/plan1/", - "wlsdeploy/structuredApplications/webapp1/plan1/AppFileOverrides/", - "wlsdeploy/structuredApplications/webapp1/plan1/AppFileOverrides/hello.properties", - "wlsdeploy/structuredApplications/webapp1/plan1/WEB-INF/", - "wlsdeploy/structuredApplications/webapp1/plan1/WEB-INF/weblogic.xml", - "wlsdeploy/structuredApplications/webapp1/plan1/plan.xml", - "wlsdeploy/structuredApplications/webapp1/plan2/", - "wlsdeploy/structuredApplications/webapp1/plan2/AppFileOverrides/", - "wlsdeploy/structuredApplications/webapp1/plan2/AppFileOverrides/hello.properties", - "wlsdeploy/structuredApplications/webapp1/plan2/WEB-INF/", - "wlsdeploy/structuredApplications/webapp1/plan2/WEB-INF/weblogic.xml", - "wlsdeploy/structuredApplications/webapp1/plan2/plan.xml" - }; - - private static final String[] LIST_APPS_EXPECTED; - private static final String[] LIST_COH_EXPECTED; - - private static final String[] LIST_STRUCTURED_APPS_EXPECTED; - - static { - String[] files = new String[] { - "wlsdeploy/applications/", - "wlsdeploy/applications/my-app.war", - "wlsdeploy/applications/my-app.xml", - "wlsdeploy/applications/my-other-app.war" - }; - LIST_APPS_EXPECTED = new String[LIST_APP_DIR_EXPECTED.length + files.length]; - - System.arraycopy(files, 0, LIST_APPS_EXPECTED, 0, files.length); - System.arraycopy(LIST_APP_DIR_EXPECTED, 0, LIST_APPS_EXPECTED, - files.length, LIST_APP_DIR_EXPECTED.length); - - LIST_COH_EXPECTED = new String[LIST_COH_MYCLUSTER_EXPECTED.length + LIST_COH_MYCLUSTER2_EXPECTED.length + 1]; - LIST_COH_EXPECTED[0] = "wlsdeploy/coherence/"; - System.arraycopy(LIST_COH_MYCLUSTER_EXPECTED, 0, LIST_COH_EXPECTED,1, - LIST_COH_MYCLUSTER_EXPECTED.length); - System.arraycopy(LIST_COH_MYCLUSTER2_EXPECTED, 0, LIST_COH_EXPECTED, - LIST_COH_MYCLUSTER_EXPECTED.length + 1, LIST_COH_MYCLUSTER2_EXPECTED.length); - - LIST_STRUCTURED_APPS_EXPECTED = new String[LIST_STRUCTURED_APP_WEBAPP_EXPECTED.length + - LIST_STRUCTURED_APP_WEBAPP1_EXPECTED.length + 1]; - LIST_STRUCTURED_APPS_EXPECTED[0] = "wlsdeploy/structuredApplications/"; - System.arraycopy(LIST_STRUCTURED_APP_WEBAPP_EXPECTED, 0, LIST_STRUCTURED_APPS_EXPECTED, 1, - LIST_STRUCTURED_APP_WEBAPP_EXPECTED.length); - System.arraycopy(LIST_STRUCTURED_APP_WEBAPP1_EXPECTED, 0, LIST_STRUCTURED_APPS_EXPECTED, - LIST_STRUCTURED_APP_WEBAPP_EXPECTED.length + 1, LIST_STRUCTURED_APP_WEBAPP1_EXPECTED.length); - } + private static final String[] LIST_APP_FILE_EXPECTED = MY_APP_WAR_CONTENTS; + private static final String[] LIST_APP_DIR_EXPECTED = MY_OTHER_APP_DIR_CONTENTS; + private static final String[] LIST_APPS_EXPECTED = APPLICATIONS_CONTENT; + + private static final String[] LIST_CP_LIBS_EXPECTED = CLASSPATH_LIBS_CONTENT; + + private static final String[] LIST_COH_MYCLUSTER_EXPECTED = COHERENCE_MYCLUSTER_CONTENTS; + private static final String[] LIST_COH_MYCLUSTER2_EXPECTED = COHERENCE_MYCLUSTER2_CONTENTS; + private static final String[] LIST_COH_EXPECTED = COHERENCE_CONTENT; + + private static final String[] LIST_MIME_MAPPINGS_EXPECTED = MIME_MAPPINGS_CONTENT; + private static final String[] LIST_MIME_MAPPINGS_PROPERTIES_EXPECTED = MIME_MAPPING_PROPERTIES_CONTENTS; + + private static final String[] LIST_CUSTOM_MYDIR_EXPECTED = CUSTOM_MYDIR_CONTENTS; + private static final String[] LIST_CUSTOM_EXPECTED = CUSTOM_CONTENT; + + private static final String[] LIST_RCU_WALLET_EXPECTED = DATABASE_WALLET_RCU_CONTENTS; + private static final String[] LIST_WALLET1_EXPECTED = DATABASE_WALLET_WALLET1_CONTENTS; + + private static final String[] LIST_STRUCTURED_APP_WEBAPP_EXPECTED = STRUCTURED_APP_WEBAPP_CONTENTS; + private static final String[] LIST_STRUCTURED_APP_WEBAPP1_EXPECTED = STRUCTURED_APP_WEBAPP1_CONTENTS; + private static final String[] LIST_STRUCTURED_APPS_EXPECTED = STRUCTURED_APPS_CONTENT; + @BeforeAll static void initialize() throws Exception { @@ -410,7 +310,7 @@ void testListClasspathLibFile_ReturnsExceptedNames() { "-name", "bar.jar" }; - List expectedPaths = Collections.singletonList("wlsdeploy/classpathLibraries/bar.jar"); + List expectedPaths = Arrays.asList(CLASSPATH_LIB_BAR_JAR_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -636,7 +536,7 @@ void testListCustomFile_ReturnsExceptedNames() { "-name", "foo.properties" }; - List expectedPaths = Collections.singletonList("wlsdeploy/custom/foo.properties"); + List expectedPaths = Arrays.asList(CUSTOM_FOO_PROPERTIES_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -748,7 +648,7 @@ void testListDomainBin_ReturnsExceptedNames() { "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList("wlsdeploy/domainBin/", "wlsdeploy/domainBin/setUserOverrides.sh"); + List expectedPaths = Arrays.asList(DOMAIN_BIN_CONTENT); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -777,7 +677,7 @@ void testListDomainBinFile_ReturnsExceptedNames() { "-name", "setUserOverrides.sh" }; - List expectedPaths = Collections.singletonList("wlsdeploy/domainBin/setUserOverrides.sh"); + List expectedPaths = Arrays.asList(DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -804,7 +704,7 @@ void testListDomainLib_ReturnsExceptedNames() { "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList("wlsdeploy/domainLibraries/", "wlsdeploy/domainLibraries/foo.jar"); + List expectedPaths = Arrays.asList(DOMAIN_LIB_CONTENT); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -833,7 +733,7 @@ void testListDomainLibFile_ReturnsExceptedNames() { "-name", "foo.jar" }; - List expectedPaths = Collections.singletonList("wlsdeploy/domainLibraries/foo.jar"); + List expectedPaths = Arrays.asList(DOMAIN_LIB_FOO_JAR_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -860,11 +760,7 @@ void testListNodeManager_ReturnsExceptedNames() { "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList( - "wlsdeploy/nodeManager/", - "wlsdeploy/nodeManager/nmIdentity.jks", - "wlsdeploy/nodeManager/nmTrust.jks" - ); + List expectedPaths = Arrays.asList(NODE_MANAGER_CONTENT); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -893,7 +789,7 @@ void testListNodeManagerFile_ReturnsExceptedNames() { "-name", "nmTrust.jks" }; - List expectedPaths = Collections.singletonList("wlsdeploy/nodeManager/nmTrust.jks"); + List expectedPaths = Arrays.asList(NODE_MANAGER_TRUST_JKS_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -920,10 +816,7 @@ void testListOPSSWallet_ReturnsExceptedNames() { "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList( - "wlsdeploy/opsswallet/", - "wlsdeploy/opsswallet/opss-wallet.zip" - ); + List expectedPaths = Arrays.asList(OPSS_WALLET_CONTENT); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -950,10 +843,7 @@ void testListScripts_ReturnsExceptedNames() { "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList( - "wlsdeploy/scripts/", - "wlsdeploy/scripts/my_fancy_script.sh" - ); + List expectedPaths = Arrays.asList(SCRIPTS_CONTENT); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -982,7 +872,7 @@ void testListScriptsFile_ReturnsExceptedNames() { "-name", "my_fancy_script.sh" }; - List expectedPaths = Collections.singletonList("wlsdeploy/scripts/my_fancy_script.sh"); + List expectedPaths = Arrays.asList(SCRIPTS_FANCY_SCRIPT_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -1011,11 +901,7 @@ void testListServerKeystore_ReturnsExceptedNames() { "-server_name", "AdminServer" }; - List expectedPaths = Arrays.asList( - "wlsdeploy/servers/AdminServer/", - "wlsdeploy/servers/AdminServer/identity.jks", - "wlsdeploy/servers/AdminServer/trust.jks" - ); + List expectedPaths = Arrays.asList(SERVERS_ADMIN_SERVER_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -1046,7 +932,7 @@ void testListServerKeystoreFile_ReturnsExceptedNames() { "-name", "trust.jks" }; - List expectedPaths = Collections.singletonList("wlsdeploy/servers/AdminServer/trust.jks"); + List expectedPaths = Arrays.asList(SERVERS_ADMIN_SERVER_TRUST_JKS_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -1073,12 +959,7 @@ void testListFileStore_ReturnsExceptedNames() { "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList( - "wlsdeploy/stores/", - "wlsdeploy/stores/fs1/", - "wlsdeploy/stores/fs2/", - "wlsdeploy/stores/fs3/" - ); + List expectedPaths = Arrays.asList(FILE_STORES_CONTENT); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -1107,7 +988,7 @@ void testListFileStoreDir_ReturnsExceptedNames() { "-name", "fs2" }; - List expectedPaths = Collections.singletonList("wlsdeploy/stores/fs2/"); + List expectedPaths = Arrays.asList(FILE_STORES_FS2_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java new file mode 100644 index 0000000000..3474ca460b --- /dev/null +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2023, Oracle Corporation and/or its affiliates. All rights reserved. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.StandardCopyOption; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.StringUtils; +import oracle.weblogic.deploy.util.WLSDeployZipFileTest; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ArchiveHelperRemoveTest { + public static final File UNIT_TEST_SOURCE_DIR = new File(WLSDeployZipFileTest.UNIT_TEST_SOURCE_DIR); + private static final File UNIT_TEST_TARGET_DIR = + new File(new File(WLSDeployZipFileTest.UNIT_TEST_TARGET_DIR, "archiveHelper"), "remove"); + + private static final Path ARCHIVE_HELPER_SOURCE_ZIP = + new File(UNIT_TEST_SOURCE_DIR, "archive-helper-test.zip").toPath(); + private static final Path ARCHIVE_HELPER_TARGET_ZIP = + new File(UNIT_TEST_TARGET_DIR, "archive-helper-test.zip").toPath(); + private static final String ARCHIVE_HELPER_VALUE = ARCHIVE_HELPER_TARGET_ZIP.toFile().getAbsolutePath(); + + @BeforeAll + static void initialize() throws Exception { + if(!UNIT_TEST_TARGET_DIR.exists() && !UNIT_TEST_TARGET_DIR.mkdirs()) { + throw new Exception("Unable to create unit test directory: " + UNIT_TEST_TARGET_DIR); + } + + PlatformLogger logger = WLSDeployLogFactory.getLogger(LOGGER_NAME); + logger.setLevel(Level.OFF); + } + + @BeforeEach + void setup() throws Exception { + Files.copy(ARCHIVE_HELPER_SOURCE_ZIP, ARCHIVE_HELPER_TARGET_ZIP, StandardCopyOption.REPLACE_EXISTING); + } + + @Test + void testRemoveNoArchive_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "application", + "-name", + "my-app.war" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testRemoveNoApp_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "application", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + // @Test + void testRemoveExistingAppFile_ReturnsExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "application", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-app.war" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + + List remainingEntries = getRemainingEntries("list", "application", "-archive_file", ARCHIVE_HELPER_VALUE); + } + + List getRemainingEntries(String... args) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + if (outputLines.length == 0 || (outputLines.length == 1 && StringUtils.isEmpty(outputLines[0]))) { + return new ArrayList<>(); + } else { + return Arrays.asList(outputLines); + } + } +} diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java new file mode 100644 index 0000000000..e176630926 --- /dev/null +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2023, Oracle Corporation and/or its affiliates. All rights reserved. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool; + +public class ArchiveHelperTestConstants { + static final String[] MY_APP_WAR_CONTENTS = new String[] { + "wlsdeploy/applications/my-app.war" + }; + + static final String[] MY_APP_DEPLOYMENT_PLAN_CONTENTS = new String[] { + "wlsdeploy/applications/my-app.xml" + }; + + static final String[] MY_OTHER_APP_WAR_CONTENTS = new String[] { + "wlsdeploy/applications/my-other-app.war" + }; + + static final String[] MY_OTHER_APP_DIR_CONTENTS = new String[] { + "wlsdeploy/applications/my-other-app/", + "wlsdeploy/applications/my-other-app/META-INF/", + "wlsdeploy/applications/my-other-app/META-INF/maven/", + "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/", + "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/", + "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.properties", + "wlsdeploy/applications/my-other-app/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.xml", + "wlsdeploy/applications/my-other-app/META-INF/MANIFEST.MF", + "wlsdeploy/applications/my-other-app/WEB-INF/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/platform/", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/platform/GetListenAddressServlet.class", + "wlsdeploy/applications/my-other-app/WEB-INF/classes/com/oracle/platform/ListenAddressAndPort.class", + "wlsdeploy/applications/my-other-app/WEB-INF/web.xml", + "wlsdeploy/applications/my-other-app/WEB-INF/weblogic.xml" + }; + + static final String[] APPLICATIONS_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/applications/" }, + MY_OTHER_APP_DIR_CONTENTS, + MY_APP_WAR_CONTENTS, + MY_APP_DEPLOYMENT_PLAN_CONTENTS, + MY_OTHER_APP_WAR_CONTENTS + ); + + static final String[] CLASSPATH_LIB_BAR_JAR_CONTENTS = new String[] { + "wlsdeploy/classpathLibraries/bar.jar" + }; + + static final String[] CLASSPATH_LIBS_CONTENT = new String[] { + "wlsdeploy/classpathLibraries/", + "wlsdeploy/classpathLibraries/bar.jar" + }; + + static final String[] COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS = new String[] { + "wlsdeploy/coherence/mycluster/cache-config.xml" + }; + + static final String[] COHERENCE_MYCLUSTER_PERSISTENT_DIR_CONTENTS = new String[] { + "wlsdeploy/coherence/mycluster/active/", + "wlsdeploy/coherence/mycluster/snapshot/", + "wlsdeploy/coherence/mycluster/trash/" + }; + + static final String[] COHERENCE_MYCLUSTER_CONTENTS = mergeStringArrays( + new String[] { "wlsdeploy/coherence/mycluster/" }, + COHERENCE_MYCLUSTER_PERSISTENT_DIR_CONTENTS, + COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS + ); + + static final String[] COHERENCE_MYCLUSTER2_CONFIG_FILE_CONTENTS = new String[] { + "wlsdeploy/coherence/mycluster2/cache-config.xml" + }; + + static final String[] COHERENCE_MYCLUSTER2_PERSISTENT_DIR_CONTENTS = new String[] { + "wlsdeploy/coherence/mycluster2/snapshot/" + }; + + static final String[] COHERENCE_MYCLUSTER2_CONTENTS = mergeStringArrays( + new String[] { "wlsdeploy/coherence/mycluster2/" }, + COHERENCE_MYCLUSTER2_PERSISTENT_DIR_CONTENTS, + COHERENCE_MYCLUSTER2_CONFIG_FILE_CONTENTS + ); + + static final String[] COHERENCE_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/coherence/" }, + COHERENCE_MYCLUSTER_CONTENTS, + COHERENCE_MYCLUSTER2_CONTENTS + ); + + static final String[] MIME_MAPPING_PROPERTIES_CONTENTS = new String[] { + "wlsdeploy/config/mimemappings.properties" + }; + + static final String[] MIME_MAPPINGS_CONTENT = new String[] { + "wlsdeploy/config/", + "wlsdeploy/config/mimemappings.properties" + }; + + static final String[] CUSTOM_MYDIR_BAR_PROPERTIES_CONTENTS = new String[] { + "wlsdeploy/custom/mydir/bar.properties" + }; + + static final String[] CUSTOM_MYDIR_CONTENTS = mergeStringArrays( + new String[] { "wlsdeploy/custom/mydir/" }, + CUSTOM_MYDIR_BAR_PROPERTIES_CONTENTS + ); + + static final String[] CUSTOM_FOO_PROPERTIES_CONTENTS = { + "wlsdeploy/custom/foo.properties" + }; + + static final String[] CUSTOM_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/custom/" }, + CUSTOM_MYDIR_CONTENTS, + CUSTOM_FOO_PROPERTIES_CONTENTS + ); + + static final String[] DATABASE_WALLET_RCU_CONTENTS = new String[] { + "wlsdeploy/dbWallets/rcu/", + "wlsdeploy/dbWallets/rcu/cwallet.sso", + "wlsdeploy/dbWallets/rcu/ewallet.p12", + "wlsdeploy/dbWallets/rcu/ewallet.pem", + "wlsdeploy/dbWallets/rcu/keystore.jks", + "wlsdeploy/dbWallets/rcu/ojdbc.properties", + "wlsdeploy/dbWallets/rcu/README", + "wlsdeploy/dbWallets/rcu/sqlnet.ora", + "wlsdeploy/dbWallets/rcu/tnsnames.ora", + "wlsdeploy/dbWallets/rcu/truststore.jks" + }; + + static final String[] DATABASE_WALLET_WALLET1_CONTENTS = new String[] { + "wlsdeploy/dbWallets/wallet1/", + "wlsdeploy/dbWallets/wallet1/atpwallet.zip" + }; + + static final String[] DATABASE_WALLETS_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/dbWallets/" }, + DATABASE_WALLET_RCU_CONTENTS, + DATABASE_WALLET_WALLET1_CONTENTS + ); + + static final String[] DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS = new String[] { + "wlsdeploy/domainBin/setUserOverrides.sh" + }; + + static final String[] DOMAIN_BIN_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/domainBin/" }, + DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS + ); + + static final String[] DOMAIN_LIB_FOO_JAR_CONTENTS = new String[] { + "wlsdeploy/domainLibraries/foo.jar" + }; + + static final String[] DOMAIN_LIB_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/domainLibraries/" }, + DOMAIN_LIB_FOO_JAR_CONTENTS + ); + + static final String[] NODE_MANAGER_IDENTITY_JKS_CONTENTS = new String[] { + "wlsdeploy/nodeManager/nmIdentity.jks" + }; + + static final String[] NODE_MANAGER_TRUST_JKS_CONTENTS = new String[] { + "wlsdeploy/nodeManager/nmTrust.jks" + }; + + static final String[] NODE_MANAGER_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/nodeManager/" }, + NODE_MANAGER_IDENTITY_JKS_CONTENTS, + NODE_MANAGER_TRUST_JKS_CONTENTS + ); + + static final String[] OPSS_WALLET_CONTENT = new String[] { + "wlsdeploy/opsswallet/", + "wlsdeploy/opsswallet/opss-wallet.zip" + }; + + static final String[] SCRIPTS_FANCY_SCRIPT_CONTENTS = new String[] { + "wlsdeploy/scripts/my_fancy_script.sh" + }; + + static final String[] SCRIPTS_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/scripts/" }, + SCRIPTS_FANCY_SCRIPT_CONTENTS + ); + + static final String[] SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS = new String[] { + "wlsdeploy/servers/AdminServer/identity.jks" + }; + + static final String[] SERVERS_ADMIN_SERVER_TRUST_JKS_CONTENTS = new String[] { + "wlsdeploy/servers/AdminServer/trust.jks" + }; + + static final String[] SERVERS_ADMIN_SERVER_CONTENTS = mergeStringArrays( + new String[] { "wlsdeploy/servers/AdminServer/" }, + SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS, + SERVERS_ADMIN_SERVER_TRUST_JKS_CONTENTS + ); + + static final String[] SERVERS_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/servers/" }, + SERVERS_ADMIN_SERVER_CONTENTS + ); + + static final String[] FILE_STORES_FS1_CONTENTS = new String[] { + "wlsdeploy/stores/fs1/" + }; + + static final String[] FILE_STORES_FS2_CONTENTS = new String[] { + "wlsdeploy/stores/fs2/" + }; + + static final String[] FILE_STORES_FS3_CONTENTS = new String[] { + "wlsdeploy/stores/fs3/" + }; + + static final String[] FILE_STORES_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/stores/" }, + FILE_STORES_FS1_CONTENTS, + FILE_STORES_FS2_CONTENTS, + FILE_STORES_FS3_CONTENTS + ); + + static final String[] STRUCTURED_APP_WEBAPP_CONTENTS = new String[] { + "wlsdeploy/structuredApplications/webapp/", + "wlsdeploy/structuredApplications/webapp/app/", + "wlsdeploy/structuredApplications/webapp/app/META-INF/", + "wlsdeploy/structuredApplications/webapp/app/META-INF/MANIFEST.MF", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/weblogic/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/weblogic/example/", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/com/oracle/weblogic/example/HelloServlet.class", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/classes/hello.properties", + "wlsdeploy/structuredApplications/webapp/app/WEB-INF/web.xml", + "wlsdeploy/structuredApplications/webapp/plan/", + "wlsdeploy/structuredApplications/webapp/plan/AppFileOverrides/", + "wlsdeploy/structuredApplications/webapp/plan/AppFileOverrides/hello.properties", + "wlsdeploy/structuredApplications/webapp/plan/WEB-INF/", + "wlsdeploy/structuredApplications/webapp/plan/WEB-INF/weblogic.xml", + "wlsdeploy/structuredApplications/webapp/plan/plan.xml" + }; + + static final String[] STRUCTURED_APP_WEBAPP1_CONTENTS = new String[] { + "wlsdeploy/structuredApplications/webapp1/", + "wlsdeploy/structuredApplications/webapp1/app/", + "wlsdeploy/structuredApplications/webapp1/app/webapp.war", + "wlsdeploy/structuredApplications/webapp1/plan1/", + "wlsdeploy/structuredApplications/webapp1/plan1/AppFileOverrides/", + "wlsdeploy/structuredApplications/webapp1/plan1/AppFileOverrides/hello.properties", + "wlsdeploy/structuredApplications/webapp1/plan1/WEB-INF/", + "wlsdeploy/structuredApplications/webapp1/plan1/WEB-INF/weblogic.xml", + "wlsdeploy/structuredApplications/webapp1/plan1/plan.xml", + "wlsdeploy/structuredApplications/webapp1/plan2/", + "wlsdeploy/structuredApplications/webapp1/plan2/AppFileOverrides/", + "wlsdeploy/structuredApplications/webapp1/plan2/AppFileOverrides/hello.properties", + "wlsdeploy/structuredApplications/webapp1/plan2/WEB-INF/", + "wlsdeploy/structuredApplications/webapp1/plan2/WEB-INF/weblogic.xml", + "wlsdeploy/structuredApplications/webapp1/plan2/plan.xml" + }; + + static final String[] STRUCTURED_APPS_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/structuredApplications/" }, + STRUCTURED_APP_WEBAPP_CONTENTS, + STRUCTURED_APP_WEBAPP1_CONTENTS + ); + + static String[] mergeStringArrays(String[]... arrays) { + int totalSize = 0; + for (String[] array : arrays) { + totalSize += array.length; + } + + String[] result = new String[totalSize]; + int nextPos = 0; + for (String[] array : arrays) { + System.arraycopy(array, 0, result, nextPos, array.length); + nextPos += array.length; + } + return result; + } +} From ddf00d729840fa8bee3dffcdf70490c0d6299814 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Mon, 23 Jan 2023 14:48:21 -0600 Subject: [PATCH 06/13] remove first pass --- core/pom.xml | 5 + .../weblogic/deploy/tool/ArchiveHelper.java | 4 +- .../tool/archive_helper/CommandResponse.java | 7 +- .../add/AddApplicationCommand.java | 5 +- .../add/AddApplicationPlanCommand.java | 3 +- .../add/AddClasspathLibraryCommand.java | 3 +- .../add/AddCoherenceConfigCommand.java | 3 +- .../AddCoherencePersistenceDirCommand.java | 3 +- .../tool/archive_helper/add/AddCommand.java | 5 +- .../archive_helper/add/AddCustomCommand.java | 26 +- .../add/AddDatabaseWalletCommand.java | 3 +- .../add/AddDomainBinScriptCommand.java | 3 +- .../add/AddDomainLibraryCommand.java | 3 +- .../add/AddFileStoreCommand.java | 3 +- .../add/AddJMSForeignServerCommand.java | 3 +- .../add/AddMIMEMappingCommand.java | 3 +- .../add/AddNodeManagerKeystoreCommand.java | 3 +- .../add/AddOPSSWalletCommand.java | 3 +- .../add/AddRCUWalletCommand.java | 3 +- .../archive_helper/add/AddScriptCommand.java | 3 +- .../add/AddServerKeystoreCommand.java | 3 +- .../add/AddSharedLibraryCommand.java | 3 +- .../add/AddSharedLibraryPlanCommand.java | 3 +- .../add/AddStructuredApplicationCommand.java | 3 +- .../archive_helper/list/ListAllCommand.java | 3 +- .../list/ListApplicationCommand.java | 5 +- .../list/ListClasspathLibraryCommand.java | 3 +- .../list/ListCoherenceCommand.java | 3 +- .../tool/archive_helper/list/ListCommand.java | 5 +- .../list/ListCustomCommand.java | 3 +- .../list/ListDatabaseWalletCommand.java | 3 +- .../list/ListDomainBinScriptCommand.java | 3 +- .../list/ListDomainLibraryCommand.java | 3 +- .../list/ListFileStoreCommand.java | 3 +- .../list/ListJMSForeignServerCommand.java | 3 +- .../list/ListMIMEMappingCommand.java | 3 +- .../list/ListNodeManagerKeystoreCommand.java | 3 +- .../list/ListOPSSWalletCommand.java | 3 +- .../list/ListRCUWalletCommand.java | 3 +- .../list/ListScriptCommand.java | 3 +- .../list/ListServerKeystoreCommand.java | 7 +- .../list/ListSharedLibraryCommand.java | 3 +- .../ListStructuredApplicationCommand.java | 3 +- .../remove/RemoveApplicationCommand.java | 35 +- .../remove/RemoveApplicationPlanCommand.java | 74 + .../remove/RemoveClasspathLibraryCommand.java | 74 + .../remove/RemoveCoherenceConfigCommand.java | 82 + .../RemoveCoherencePersistenceDirCommand.java | 82 + .../archive_helper/remove/RemoveCommand.java | 25 +- .../remove/RemoveCustomCommand.java | 74 + .../remove/RemoveDatabaseWalletCommand.java | 75 + .../remove/RemoveDomainBinScriptCommand.java | 74 + .../remove/RemoveDomainLibraryCommand.java | 74 + .../remove/RemoveFileStoreCommand.java | 75 + .../remove/RemoveJMSForeignServerCommand.java | 82 + .../remove/RemoveMIMEMappingCommand.java | 74 + .../RemoveNodeManagerKeystoreCommand.java | 74 + .../remove/RemoveOPSSWalletCommand.java | 67 + .../remove/RemoveRCUWalletCommand.java | 69 + .../remove/RemoveScriptCommand.java | 74 + .../remove/RemoveServerKeystoreCommand.java | 82 + .../remove/RemoveSharedLibraryCommand.java | 74 + .../RemoveSharedLibraryPlanCommand.java | 74 + .../RemoveStructuredApplicationCommand.java | 74 + .../deploy/util/WLSDeployArchive.java | 1218 +++++++++++- .../deploy/messages/wlsdeploy_rb.properties | 36 + .../deploy/tool/ArchiveHelperListTest.java | 374 ++-- .../deploy/tool/ArchiveHelperRemoveTest.java | 1640 ++++++++++++++++- .../tool/ArchiveHelperTestConstants.java | 99 +- .../test/resources/archive-helper-test.zip | Bin 90672 -> 104609 bytes 70 files changed, 4750 insertions(+), 276 deletions(-) create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationPlanCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveClasspathLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherenceConfigCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherencePersistenceDirCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCustomCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDatabaseWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainBinScriptCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveFileStoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveJMSForeignServerCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveMIMEMappingCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveNodeManagerKeystoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOPSSWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveRCUWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveScriptCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveServerKeystoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryPlanCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveStructuredApplicationCommand.java diff --git a/core/pom.xml b/core/pom.xml index d9773eda0e..0f040a74e0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -52,6 +52,11 @@ junit-jupiter-engine test + + org.junit.jupiter + junit-jupiter-params + test + org.easymock easymock diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java index 63b33e6ead..491279cfe5 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java @@ -12,6 +12,7 @@ import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; import oracle.weblogic.deploy.tool.archive_helper.add.AddCommand; import oracle.weblogic.deploy.tool.archive_helper.list.ListCommand; +import oracle.weblogic.deploy.tool.archive_helper.remove.RemoveCommand; import oracle.weblogic.deploy.util.ExitCode; import picocli.CommandLine; import picocli.CommandLine.Command; @@ -27,7 +28,8 @@ commandListHeading = "%nCommands:%n", subcommands = { AddCommand.class, - ListCommand.class + ListCommand.class, + RemoveCommand.class }, sortOptions = false ) diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java index cac554276d..008770b5dd 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java @@ -5,6 +5,7 @@ package oracle.weblogic.deploy.tool.archive_helper; import java.io.PrintWriter; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; @@ -14,8 +15,8 @@ public class CommandResponse { ResourceBundle.getBundle("oracle.weblogic.deploy.messages.wlsdeploy_rb"); private int status; - private List messages = new ArrayList<>(); - private List messageParamsList = new ArrayList<>(); + private final List messages = new ArrayList<>(); + private final List messageParamsList = new ArrayList<>(); public CommandResponse(int status) { this.status = status; @@ -41,7 +42,7 @@ public String[] getMessages() { for (int index = 0; index < this.messages.size(); index++) { String message = this.messages.get(index); if (RESOURCE_BUNDLE.containsKey(message)) { - message = String.format(message, this.messageParamsList.get(index)); + message = MessageFormat.format(RESOURCE_BUNDLE.getString(message), this.messageParamsList.get(index)); } formattedMessages[index] = message; } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java index d0a85f2ca0..b38e120eb0 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java @@ -20,7 +20,10 @@ @Command( name = "application", - description = "%nAdd application to the archive file:", + header = "Add application to the archive file.", + description = "%nCommand-line options:", + footer = "%nNote: If using an Application Installation Directory, " + + "please see the archiveHelper add structuredApplication command.%n", sortOptions = false ) public class AddApplicationCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationPlanCommand.java index caebe1d8f2..19c07e85b3 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationPlanCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationPlanCommand.java @@ -19,7 +19,8 @@ @Command( name = "applicationPlan", - description = "%nAdd application deployment plan to the archive file:", + header = "Add application deployment plan to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddApplicationPlanCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddClasspathLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddClasspathLibraryCommand.java index 18d93dff92..a92a5c683b 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddClasspathLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddClasspathLibraryCommand.java @@ -19,7 +19,8 @@ @Command( name = "classpathLibrary", - description = "%nAdd classpath library to the archive file:", + header = "Add classpath library to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddClasspathLibraryCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherenceConfigCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherenceConfigCommand.java index ebf638fa35..f36ef857b0 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherenceConfigCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherenceConfigCommand.java @@ -19,7 +19,8 @@ @Command( name = "coherenceConfig", - description = "%nAdd a Coherence config file to the archive file:", + header = "Add a Coherence config file to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddCoherenceConfigCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java index 435637f598..fb1ad6ca4f 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java @@ -19,7 +19,8 @@ @Command( name = "coherencePersistenceDir", - description = "%nAdd a Coherence persistence directory to the archive file:", + header = "Add a Coherence persistence directory to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddCoherencePersistenceDirCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java index b7770c5a55..cf37e5f7eb 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCommand.java @@ -9,8 +9,9 @@ @Command( name = "add", - description = "%nAdd items to the archive file:", - commandListHeading = "%nSubcommands:%n%n", + header = "Add items to the archive file.", + description = "%nCommand-line options:", + commandListHeading = "%nSubcommands:%n", subcommands = { AddApplicationCommand.class, AddApplicationPlanCommand.class, diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCustomCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCustomCommand.java index b0db46199b..c4de59c967 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCustomCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCustomCommand.java @@ -11,15 +11,18 @@ import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.StringUtils; import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ZIP_SEP; @Command( name = "custom", - description = "%nAdd custom file/directory to the archive file:", + header = "Add custom file/directory to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddCustomCommand extends AddTypeCommandBase { @@ -29,12 +32,19 @@ public class AddCustomCommand extends AddTypeCommandBase { @Option( names = {"-source"}, - paramLabel = "", + paramLabel = "", description = "File system path to the custom file or directory to add", required = true ) private String sourcePath; + @Option( + names = {"-path"}, + paramLabel = "", + description = "Relative archive path from custom to the parent directory to use to add the file or directory, if any" + ) + private String archivePath = null; + @Option( names = { "-help" }, description = "Get help for the archiveHelper add custom subcommand", @@ -54,9 +64,17 @@ public CommandResponse call() throws Exception { String resultName; if (this.overwrite) { - resultName = this.archive.replaceCustomEntry(sourceFile.getName(), sourceFile.getPath()); + String archiveReplacementPath = ""; + if (!StringUtils.isEmpty(archivePath)) { + archiveReplacementPath = this.archivePath; + if (!archiveReplacementPath.endsWith(ZIP_SEP)) { + archiveReplacementPath += ZIP_SEP; + } + } + archiveReplacementPath += sourceFile.getName(); + resultName = this.archive.replaceCustomEntry(archiveReplacementPath, sourceFile.getPath()); } else { - resultName = this.archive.addCustomEntry(sourceFile.getPath()); + resultName = this.archive.addCustomEntry(sourceFile.getPath(), this.archivePath); } response = new CommandResponse(ExitCode.OK, resultName); } catch (ArchiveHelperException ex) { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDatabaseWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDatabaseWalletCommand.java index 2d4008f242..db21896a56 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDatabaseWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDatabaseWalletCommand.java @@ -19,7 +19,8 @@ @Command( name = "databaseWallet", - description = "%nAdd database wallet to the archive file:", + header = "Add database wallet to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddDatabaseWalletCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java index b86143d2fd..4208860709 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java @@ -19,7 +19,8 @@ @Command( name = "domainBinScript", - description = "%nAdd domain bin script to the archive file:", + header = "Add domain bin script to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddDomainBinScriptCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java index 389faa22cd..2ff1adb0bd 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java @@ -19,7 +19,8 @@ @Command( name = "domainLibrary", - description = "%nAdd domain library to the archive file:", + header = "Add domain library to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddDomainLibraryCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java index 58749877ed..4569afaff7 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java @@ -19,7 +19,8 @@ @Command( name = "fileStore", - description = "%nAdd empty file store directory to the archive file:", + header = "Add empty file store directory to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddFileStoreCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddJMSForeignServerCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddJMSForeignServerCommand.java index 85724256e3..b811dad063 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddJMSForeignServerCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddJMSForeignServerCommand.java @@ -19,7 +19,8 @@ @Command( name = "jmsForeignServer", - description = "%nAdd a JMS Foreign Server binding file to the archive file:", + header = "Add a JMS Foreign Server binding file to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddJMSForeignServerCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddMIMEMappingCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddMIMEMappingCommand.java index d5522f0f26..a5d8e048c1 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddMIMEMappingCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddMIMEMappingCommand.java @@ -19,7 +19,8 @@ @Command( name = "mimeMapping", - description = "%nAdd MIME mapping file to the archive file:", + header = "Add MIME mapping file to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddMIMEMappingCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddNodeManagerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddNodeManagerKeystoreCommand.java index 43ca999c03..6b0b80d183 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddNodeManagerKeystoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddNodeManagerKeystoreCommand.java @@ -19,7 +19,8 @@ @Command( name = "nodeManagerKeystore", - description = "%nAdd node manager keystore to the archive file:", + header = "Add node manager keystore to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddNodeManagerKeystoreCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOPSSWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOPSSWalletCommand.java index f87f5bf9b3..f7c254f0e6 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOPSSWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddOPSSWalletCommand.java @@ -19,7 +19,8 @@ @Command( name = "opssWallet", - description = "%nAdd OPSS wallet to the archive file:", + header = "Add OPSS wallet to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddOPSSWalletCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java index f614f58025..ac253a9e0b 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java @@ -20,7 +20,8 @@ @Command( name = "rcuWallet", - description = "%nAdd RCU database wallet to the archive file:", + header = "Add RCU database wallet to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddRCUWalletCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddScriptCommand.java index e84967b5dd..6d945e24b7 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddScriptCommand.java @@ -19,7 +19,8 @@ @Command( name = "script", - description = "%nAdd script to the archive file:", + header = "Add script to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddScriptCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddServerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddServerKeystoreCommand.java index 43782499f4..52d8e21815 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddServerKeystoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddServerKeystoreCommand.java @@ -19,7 +19,8 @@ @Command( name = "serverKeystore", - description = "%nAdd a server keystore to the archive file:", + header = "Add a server keystore to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddServerKeystoreCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java index bfa25c4a02..ea618b33df 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryCommand.java @@ -19,7 +19,8 @@ @Command( name = "sharedLibrary", - description = "%nAdd shared library to the archive file:", + header = "Add shared library to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddSharedLibraryCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryPlanCommand.java index 70e08b1ec8..ff0676a23f 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryPlanCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddSharedLibraryPlanCommand.java @@ -19,7 +19,8 @@ @Command( name = "sharedLibraryPlan", - description = "%nAdd shared library deployment plan to the archive file:", + header = "Add shared library deployment plan to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddSharedLibraryPlanCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java index 59476c15bc..8dc43e0dbd 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddStructuredApplicationCommand.java @@ -19,7 +19,8 @@ @Command( name = "structuredApplication", - description = "%nAdd structured application installation directory to the archive file:", + header = "Add structured application installation directory to the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class AddStructuredApplicationCommand extends AddTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java index ded81d5f4b..b227a0eb88 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListAllCommand.java @@ -22,7 +22,8 @@ @Command( name = "all", - description = "%nList all entries in the archive file:", + header = "List all entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListAllCommand extends CommonOptions implements Callable { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java index e2a90ff9a5..a7fd8616e6 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListApplicationCommand.java @@ -16,7 +16,10 @@ @Command( name = "application", - description = "%nList application entries in the archive file:", + header = "List application entries in the archive file.", + description = "%nCommand-line options:", + footer = "%nNote: If using an Application Installation Directory, " + + "please see the archiveHelper list structuredApplication command.%n", sortOptions = false ) public class ListApplicationCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java index 6cf37ffb35..f6fb705718 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListClasspathLibraryCommand.java @@ -15,7 +15,8 @@ @Command( name = "classpathLibrary", - description = "%nList classpath library entries in the archive file:", + header = "List classpath library entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListClasspathLibraryCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java index efa704bbca..820fdf7146 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCoherenceCommand.java @@ -14,7 +14,8 @@ import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.COHERENCE; @Command( name = "coherence", - description = "%nList Coherence entries in the archive file:", + header = "List Coherence entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListCoherenceCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java index cf56eb0dfe..b57b9bff87 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCommand.java @@ -9,8 +9,9 @@ @Command( name = "list", - description = "%nList contents of the archive file:", - commandListHeading = "%nSubcommands:%n%n", + header = "List contents of the archive file.", + description = "%nCommand-line options:", + commandListHeading = "%nSubcommands:%n", subcommands = { ListAllCommand.class, ListApplicationCommand.class, diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java index 0bdec90c3f..7840694d82 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java @@ -15,7 +15,8 @@ @Command( name = "custom", - description = "%nList custom directory entries in the archive file:", + header = "List custom directory entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListCustomCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java index d37665ff32..3506d5b557 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDatabaseWalletCommand.java @@ -15,7 +15,8 @@ @Command( name = "databaseWallet", - description = "%nList database wallet entries in the archive file:", + header = "List database wallet entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListDatabaseWalletCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java index e2cc6802a8..c204fa12e9 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java @@ -15,7 +15,8 @@ @Command( name = "domainBinScript", - description = "%nList domain bin script entries in the archive file:", + header = "List domain bin script entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListDomainBinScriptCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java index dd81464f0b..e7d6dc67df 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java @@ -15,7 +15,8 @@ @Command( name = "domainLibrary", - description = "%nList domain library entries in the archive file:", + header = "List domain library entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListDomainLibraryCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java index 585fa9b512..a36c5781d5 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListFileStoreCommand.java @@ -15,7 +15,8 @@ @Command( name = "fileStore", - description = "%nList file store entries in the archive file:", + header = "List file store entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListFileStoreCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListJMSForeignServerCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListJMSForeignServerCommand.java index fc6be10228..b0b11cf339 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListJMSForeignServerCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListJMSForeignServerCommand.java @@ -15,7 +15,8 @@ @Command( name = "jmsForeignServer", - description = "%nList JMS foreign server binding entries in the archive file:", + header = "List JMS foreign server binding entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListJMSForeignServerCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java index 87e214fcb1..872902573e 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListMIMEMappingCommand.java @@ -15,7 +15,8 @@ @Command( name = "mimeMapping", - description = "%nList MIME mapping entries in the archive file:", + header = "List MIME mapping entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListMIMEMappingCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java index 4dd154a5d3..bcd4af70ac 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListNodeManagerKeystoreCommand.java @@ -15,7 +15,8 @@ @Command( name = "nodeManagerKeystore", - description = "%nList node manager keystore entries in the archive file:", + header = "List node manager keystore entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListNodeManagerKeystoreCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java index 1a2f12e898..9308ccd399 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListOPSSWalletCommand.java @@ -15,7 +15,8 @@ @Command( name = "opssWallet", - description = "%nList OPSS wallet entries in the archive file:", + header = "List OPSS wallet entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListOPSSWalletCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java index e877dc6f79..8f67e3a43a 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java @@ -16,7 +16,8 @@ @Command( name = "rcuWallet", - description = "%nList RCU database wallet entries in the archive file:", + header = "List RCU database wallet entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListRCUWalletCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java index 9a8cf21436..5a5f53c881 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListScriptCommand.java @@ -15,7 +15,8 @@ @Command( name = "script", - description = "%nList script entries in the archive file:", + header = "List script entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListScriptCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java index d70ee9d157..8fb6e2732f 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerKeystoreCommand.java @@ -15,7 +15,8 @@ @Command( name = "serverKeystore", - description = "%nList server keystore entries in the archive file:", + header = "List server keystore entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListServerKeystoreCommand extends ListTypeCommandBase { @@ -32,8 +33,8 @@ public class ListServerKeystoreCommand extends ListTypeCommandBase { @Option( names = { "-name" }, - paramLabel = "", - description = "Name of the server for which to list the keystore" + paramLabel = "", + description = "Name of the keystore to list" ) private String name; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java index 7bad92e5ce..b37c2ecda2 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListSharedLibraryCommand.java @@ -16,7 +16,8 @@ @Command( name = "sharedLibrary", - description = "%nList shared library entries in the archive file:", + header = "List shared library entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListSharedLibraryCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java index 07fed23db5..eb68ea3313 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListStructuredApplicationCommand.java @@ -15,7 +15,8 @@ @Command( name = "structuredApplication", - description = "%nList structured application entries in the archive file:", + header = "List structured application entries in the archive file.", + description = "%nCommand-line options:", sortOptions = false ) public class ListStructuredApplicationCommand extends ListTypeCommandBase { diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java index 691f143297..5d4b498cd4 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java @@ -11,7 +11,6 @@ import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; -import oracle.weblogic.deploy.tool.archive_helper.add.AddApplicationCommand; import oracle.weblogic.deploy.util.ExitCode; import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; import picocli.CommandLine.Command; @@ -21,11 +20,14 @@ @Command( name = "application", - description = "%nRemove application from the archive file:", + header = "Remove application from the archive file.", + description = "%nCommand-line options:", + footer = "%nNote: If using an Application Installation Directory, " + + "please see the archiveHelper remove structuredApplication command.%n", sortOptions = false ) public class RemoveApplicationCommand extends RemoveTypeCommandBase { - private static final String CLASS = AddApplicationCommand.class.getName(); + private static final String CLASS = RemoveApplicationCommand.class.getName(); private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); private static final String TYPE = "application"; @@ -38,7 +40,7 @@ public class RemoveApplicationCommand extends RemoveTypeCommandBase { @Option( names = { "-help" }, - description = "Get help for the archiveHelper add application subcommand", + description = "Get help for the archiveHelper remove application subcommand", usageHelp = true ) private boolean helpRequested = false; @@ -48,17 +50,30 @@ public CommandResponse call() throws Exception { final String METHOD = "call"; LOGGER.entering(CLASS, METHOD); - /* CommandResponse response; try { initializeOptions(); + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeApplication(name, true); + } else { + entriesRemoved = this.archive.removeApplication(name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { - - } catch (WLSDeployArchiveIOException ex) { - + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); } - */ - return null; + + LOGGER.exiting(CLASS, METHOD, response); + return response; } } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationPlanCommand.java new file mode 100644 index 0000000000..1c79545f52 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationPlanCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "applicationPlan", + header = "Remove application deployment plan from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveApplicationPlanCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveApplicationPlanCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "application deployment plan"; + + @Option( + names = {"-name"}, + description = "Name of the application deployment plan to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove applicationPlan subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeApplicationDeploymentPlan(name, true); + } else { + entriesRemoved = this.archive.removeApplicationDeploymentPlan(name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveClasspathLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveClasspathLibraryCommand.java new file mode 100644 index 0000000000..ab80918815 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveClasspathLibraryCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "classpathLibrary", + header = "Remove classpath library from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveClasspathLibraryCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveClasspathLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "classpath library"; + + @Option( + names = {"-name"}, + description = "Name of the classpath library to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove classpathLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeClasspathLibrary(name, true); + } else { + entriesRemoved = this.archive.removeClasspathLibrary(name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherenceConfigCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherenceConfigCommand.java new file mode 100644 index 0000000000..e24faa8476 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherenceConfigCommand.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "coherenceConfig", + header = "Remove Coherence config file from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveCoherenceConfigCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveCoherenceConfigCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "Coherence config file"; + + @Option( + names = {"-cluster_name"}, + description = "Name of the Coherence cluster used to segregate the config files in the archive file", + required = true + ) + private String clusterName; + + @Option( + names = {"-name"}, + description = "Name of the Coherence config file to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove coherenceConfig subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeCoherenceConfigFile(this.clusterName, this.name, true); + } else { + entriesRemoved = this.archive.removeCoherenceConfigFile(this.clusterName, this.name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30032", TYPE, this.clusterName, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30033", ex, this.clusterName, this.name, this.archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30033", ex, this.clusterName, + this.name, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30034", ex, this.clusterName, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30034", ex, this.clusterName, this.name, + this.force, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherencePersistenceDirCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherencePersistenceDirCommand.java new file mode 100644 index 0000000000..685ab069a9 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherencePersistenceDirCommand.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "coherencePersistenceDir", + header = "Remove Coherence persistence directory from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveCoherencePersistenceDirCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveCoherencePersistenceDirCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "Coherence persistence directory"; + + @Option( + names = {"-cluster_name"}, + description = "Name of the Coherence cluster used to segregate the persistence directories in the archive file", + required = true + ) + private String clusterName; + + @Option( + names = {"-name"}, + description = "Name of the Coherence persistence directory to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove coherencePersistenceDir subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeCoherencePersistenceDirectory(this.clusterName, this.name, true); + } else { + entriesRemoved = this.archive.removeCoherencePersistenceDirectory(this.clusterName, this.name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30032", TYPE, this.clusterName, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30035", ex, this.clusterName, this.name, this.archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30035", ex, this.clusterName, + this.name, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30036", ex, this.clusterName, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30036", ex, this.clusterName, this.name, + this.force, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCommand.java index 3701b032b8..3a487e71ea 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCommand.java @@ -9,9 +9,30 @@ @Command( name = "remove", - description = "%nRemove items to the archive file:", - commandListHeading = "%nSubcommands:%n%n", + header = "Remove items to the archive file.", + description = "%nCommand-line options:", + commandListHeading = "%nSubcommands:%n", subcommands = { + RemoveApplicationCommand.class, + RemoveApplicationPlanCommand.class, + RemoveClasspathLibraryCommand.class, + RemoveCoherenceConfigCommand.class, + RemoveCoherencePersistenceDirCommand.class, + RemoveCustomCommand.class, + RemoveDatabaseWalletCommand.class, + RemoveDomainBinScriptCommand.class, + RemoveDomainLibraryCommand.class, + RemoveFileStoreCommand.class, + RemoveJMSForeignServerCommand.class, + RemoveMIMEMappingCommand.class, + RemoveNodeManagerKeystoreCommand.class, + RemoveOPSSWalletCommand.class, + RemoveRCUWalletCommand.class, + RemoveScriptCommand.class, + RemoveServerKeystoreCommand.class, + RemoveSharedLibraryCommand.class, + RemoveSharedLibraryPlanCommand.class, + RemoveStructuredApplicationCommand.class }, sortOptions = false ) diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCustomCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCustomCommand.java new file mode 100644 index 0000000000..1b96295b2c --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCustomCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "custom", + header = "Remove custom file/directory from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveCustomCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveCustomCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "custom file or directory"; + + @Option( + names = {"-name"}, + description = "Name of the custom file/directory to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove custom subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeCustomEntry(name, true); + } else { + entriesRemoved = this.archive.removeCustomEntry(name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDatabaseWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDatabaseWalletCommand.java new file mode 100644 index 0000000000..4eca129d4b --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDatabaseWalletCommand.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "databaseWallet", + header = "Remove database wallet from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveDatabaseWalletCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveDatabaseWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "database wallet"; + + @Option( + names = {"-name"}, + description = "Name of the database wallet to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove databaseWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeDatabaseWallet(this.name, true); + } else { + entriesRemoved = this.archive.removeDatabaseWallet(this.name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, + this.name, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, + this.force, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainBinScriptCommand.java new file mode 100644 index 0000000000..08ef453b90 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainBinScriptCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "domainBinScript", + header = "Remove $DOMAIN_HOME/bin script from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveDomainBinScriptCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveDomainBinScriptCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "$DOMAIN_HOME/bin script"; + + @Option( + names = {"-name"}, + description = "Name of the $DOMAIN_HOME/bin script to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove domainBinScript subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeDomainBinScript(name, true); + } else { + entriesRemoved = this.archive.removeDomainBinScript(name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainLibraryCommand.java new file mode 100644 index 0000000000..49a14cb494 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainLibraryCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "domainLibrary", + header = "Remove domain library from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveDomainLibraryCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveDomainLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "domain library"; + + @Option( + names = {"-name"}, + description = "Name of the domain library to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove domainLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeDomainLibrary(name, true); + } else { + entriesRemoved = this.archive.removeDomainLibrary(name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveFileStoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveFileStoreCommand.java new file mode 100644 index 0000000000..bee0e8eeeb --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveFileStoreCommand.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "fileStore", + header = "Remove File Store directory from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveFileStoreCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveFileStoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "File Store directory"; + + @Option( + names = {"-name"}, + description = "Name of the File Store directory to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove fileStore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeFileStoreDirectory(this.name, true); + } else { + entriesRemoved = this.archive.removeFileStoreDirectory(this.name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, + this.name, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, + this.force, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveJMSForeignServerCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveJMSForeignServerCommand.java new file mode 100644 index 0000000000..c632a7391a --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveJMSForeignServerCommand.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "jmsForeignServer", + header = "Remove JMS Foreign Server bindings file from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveJMSForeignServerCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveJMSForeignServerCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "JMS Foreign Server bindings"; + + @Option( + names = {"-foreign_server_name"}, + description = "Name of the JMS Foreign Server used to segregate the bindings in the archive file", + required = true + ) + private String foreignServerName; + + @Option( + names = {"-name"}, + description = "Name of the JMS Foreign Server bindings file to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove jmsForeignServer subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeForeignServerFile(this.foreignServerName, this.name, true); + } else { + entriesRemoved = this.archive.removeForeignServerFile(this.foreignServerName, this.name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30037", TYPE, this.foreignServerName, + this.name, entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30038", ex, this.foreignServerName, this.name, this.archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30038", ex, this.foreignServerName, + this.name, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30039", ex, this.foreignServerName, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30039", ex, this.foreignServerName, + this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveMIMEMappingCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveMIMEMappingCommand.java new file mode 100644 index 0000000000..20a704a014 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveMIMEMappingCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "mimeMapping", + header = "Remove MIME mapping file from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveMIMEMappingCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveMIMEMappingCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "MIME mapping"; + + @Option( + names = {"-name"}, + description = "Name of the MIME mapping file to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove mimeMapping subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeMimeMappingFile(this.name, true); + } else { + entriesRemoved = this.archive.removeMimeMappingFile(this.name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveNodeManagerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveNodeManagerKeystoreCommand.java new file mode 100644 index 0000000000..1c2b589213 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveNodeManagerKeystoreCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "nodeManagerKeystore", + header = "Remove node manager keystore from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveNodeManagerKeystoreCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveNodeManagerKeystoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "node manager keystore"; + + @Option( + names = {"-name"}, + description = "Name of the node manager keystore to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove nodeManagerKeystore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeNodeManagerKeystore(this.name, true); + } else { + entriesRemoved = this.archive.removeNodeManagerKeystore(this.name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOPSSWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOPSSWalletCommand.java new file mode 100644 index 0000000000..c53770ce51 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOPSSWalletCommand.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; + +@Command( + name = "opssWallet", + header = "Remove OPSS wallet from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveOPSSWalletCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveOPSSWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "OPSS wallet"; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove opssWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeOPSSWallet(true); + } else { + entriesRemoved = this.archive.removeOPSSWallet(); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30040", TYPE, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30041", ex, TYPE, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30041", ex, TYPE, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30042", ex, TYPE, this.force, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30042", ex, TYPE, + this.force, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveRCUWalletCommand.java new file mode 100644 index 0000000000..e2ad045be1 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveRCUWalletCommand.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; + +@Command( + name = "rcuWallet", + header = "Remove RCU wallet from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveRCUWalletCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveRCUWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "database wallet"; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove databaseWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeDatabaseWallet(DEFAULT_RCU_WALLET_NAME, true); + } else { + entriesRemoved = this.archive.removeDatabaseWallet(DEFAULT_RCU_WALLET_NAME); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, DEFAULT_RCU_WALLET_NAME, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, DEFAULT_RCU_WALLET_NAME, this.archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, + DEFAULT_RCU_WALLET_NAME, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, DEFAULT_RCU_WALLET_NAME, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, DEFAULT_RCU_WALLET_NAME, + this.force, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveScriptCommand.java new file mode 100644 index 0000000000..a43f627dd6 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveScriptCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "script", + header = "Remove script from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveScriptCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveScriptCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "script"; + + @Option( + names = {"-name"}, + description = "Name of the script to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove script subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeScript(this.name, true); + } else { + entriesRemoved = this.archive.removeScript(this.name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveServerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveServerKeystoreCommand.java new file mode 100644 index 0000000000..14790bed02 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveServerKeystoreCommand.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "serverKeystore", + header = "Remove server keystore from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveServerKeystoreCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveServerKeystoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "server keystore"; + + @Option( + names = {"-server_name"}, + description = "Name of the server used to segregate the keystores in the archive file", + required = true + ) + private String serverName; + + @Option( + names = {"-name"}, + description = "Name of the server keystore to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove serverKeystore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeServerKeystore(this.serverName, this.name, true); + } else { + entriesRemoved = this.archive.removeServerKeystore(this.serverName, this.name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30029", TYPE, this.serverName, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30030", ex, this.serverName, this.name, this.archiveFilePath, + ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30030", ex, this.serverName, + this.name, this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30031", ex, this.serverName, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30031", ex, this.serverName, this.name, + this.force, this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryCommand.java new file mode 100644 index 0000000000..fe91036bec --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "sharedLibrary", + header = "Remove shared library from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveSharedLibraryCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveSharedLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "shared library"; + + @Option( + names = {"-name"}, + description = "Name of the shared library to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove sharedLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeSharedLibrary(name, true); + } else { + entriesRemoved = this.archive.removeSharedLibrary(name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryPlanCommand.java new file mode 100644 index 0000000000..e64fd8c843 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryPlanCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "sharedLibraryPlan", + header = "Remove shared library deployment plan from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveSharedLibraryPlanCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveSharedLibraryPlanCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "shared library deployment plan"; + + @Option( + names = {"-name"}, + description = "Name of the shared library deployment plan to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove sharedLibraryPlan subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeSharedLibraryDeploymentPlan(name, true); + } else { + entriesRemoved = this.archive.removeSharedLibraryDeploymentPlan(name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveStructuredApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveStructuredApplicationCommand.java new file mode 100644 index 0000000000..ab2f743a19 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveStructuredApplicationCommand.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.remove; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "structuredApplication", + header = "Remove structured application from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class RemoveStructuredApplicationCommand extends RemoveTypeCommandBase { + private static final String CLASS = RemoveStructuredApplicationCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "structured application"; + + @Option( + names = {"-name"}, + description = "Name of the structured application to be removed from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper remove structuredApplication subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + int entriesRemoved; + if (this.force) { + entriesRemoved = this.archive.removeStructuredApplication(name, true); + } else { + entriesRemoved = this.archive.removeStructuredApplication(name); + } + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, + entriesRemoved, this.archiveFilePath); + } catch (ArchiveHelperException ex) { + LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + this.archiveFilePath, ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + this.archiveFilePath, ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java index 6aa84ea5d3..4f88cd74f5 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java @@ -32,10 +32,7 @@ public class WLSDeployArchive { private static final String CLASS = WLSDeployArchive.class.getName(); - // Used by the unit tests so it requires package level scoping... - // - /* package */ - static final String ZIP_SEP = "/"; + public static final String ZIP_SEP = "/"; public static final String WLSDPLY_ARCHIVE_BINARY_DIR = "wlsdeploy"; @@ -257,10 +254,12 @@ public static String getPathForType(ArchiveEntryType type) { String pathPrefix = null; switch(type) { case APPLICATION: + case APPLICATION_PLAN: pathPrefix = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP; break; case SHARED_LIBRARY: + case SHLIB_PLAN: pathPrefix = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP; break; @@ -969,8 +968,8 @@ public void extractApplication(String applicationPath, File domainHome) throws W } /** - * Remove the named application from the archive file. If this is the only application - * in the archive file, the application directory entry will also be removed, if present. + * Remove the named application from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. * * @param appPath The application name (e.g., foo.ear) or the archive path * to it (e.g., wlsdeploy/applications/foo.ear) @@ -979,13 +978,13 @@ public void extractApplication(String applicationPath, File domainHome) throws W * reading the archive or writing the file * @throws IllegalArgumentException if the appPath is null or empty */ - public int removeApplication(String appPath) throws WLSDeployArchiveIOException { + public int removeApplication(String appPath) throws WLSDeployArchiveIOException { return removeApplication(appPath, false); } /** - * Remove the named application from the archive file. If this is the only application - * in the archive file, the application directory entry will also be removed, if present. + * Remove the named application from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. * * @param appPath The application name (e.g., foo.ear) or the archive path * to it (e.g., wlsdeploy/applications/foo.ear) @@ -1089,7 +1088,67 @@ public String replaceApplicationDeploymentPlan(String planPath, String sourceLoc return newName; } + /** + * Remove the named application deployment plan from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param planPath The application deployment plan name (e.g., foo.xml) or the archive path + * to it (e.g., wlsdeploy/applications/foo.xml) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the app deployment plan is not present or an IOException occurred while + * reading the archive or writing the file + * @throws IllegalArgumentException if the planPath is null or empty + */ + public int removeApplicationDeploymentPlan(String planPath) throws WLSDeployArchiveIOException { + return removeApplicationDeploymentPlan(planPath, false); + } + + /** + * Remove the named application deployment plan from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param planPath The application deployment plan name (e.g., foo.xml) or the archive path + * to it (e.g., wlsdeploy/applications/foo.xml) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the app deployment plan is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the appPath is null or empty + */ + public int removeApplicationDeploymentPlan(String planPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeApplicationDeploymentPlan"; + LOGGER.entering(CLASS, METHOD, planPath, silent); + + validateNonEmptyString(planPath, "planPath", METHOD); + + String archivePath; + String planName; + if (planPath.startsWith(ARCHIVE_APPS_TARGET_DIR + ZIP_SEP)) { + archivePath = planPath; + planName = getNameFromPath(archivePath, ARCHIVE_APPS_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP + planPath; + planName = planPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.APPLICATION_PLAN, planName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01441", planName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.APPLICATION_PLAN, ARCHIVE_APPS_TARGET_DIR + ZIP_SEP); + LOGGER.exiting(CLASS, METHOD, result); + return result; + } /////////////////////////////////////////////////////////////////////////////////////////////// // structured application methods // @@ -1180,6 +1239,69 @@ public String addApplicationPlanFolder(String appName, String planDir) return zipPrefix; } + /** + * Remove the named structured application from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param appPath The structured application name (e.g., foo) or the archive path + * to it (e.g., wlsdeploy/structuredApplications/foo) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the structured app is not present or an IOException occurred while + * reading the archive or writing the file + * @throws IllegalArgumentException if the appPath is null or empty + */ + public int removeStructuredApplication(String appPath) throws WLSDeployArchiveIOException { + return removeStructuredApplication(appPath, false); + } + + /** + * Remove the named structured application from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param appPath The structured application name (e.g., foo) or the archive path + * to it (e.g., wlsdeploy/structuredApplications/foo) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the structured app is not present (and silent = false) or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the appPath is null or empty + */ + public int removeStructuredApplication(String appPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeStructuredApplication"; + LOGGER.entering(CLASS, METHOD, appPath, silent); + + validateNonEmptyString(appPath, "appPath", METHOD); + + String archivePath; + String appName; + if (appPath.startsWith(ARCHIVE_STRUCT_APPS_TARGET_DIR + ZIP_SEP)) { + archivePath = appPath; + appName = getNameFromPath(archivePath, ARCHIVE_STRUCT_APPS_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_STRUCT_APPS_TARGET_DIR + ZIP_SEP + appPath; + appName = appPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.STRUCTURED_APPLICATION, appName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01442", appName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.STRUCTURED_APPLICATION, + ARCHIVE_STRUCT_APPS_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // shared library methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1288,6 +1410,68 @@ public void extractSharedLibrary(String sharedLibraryPath, File domainHome) thro LOGGER.exiting(CLASS, METHOD); } + /** + * Remove the named shared library from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param libPath The shared library name (e.g., foo.war) or the archive path + * to it (e.g., wlsdeploy/sharedLibraries/foo.war) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the shared library is not present or an IOException occurred while + * reading the archive or writing the file + * @throws IllegalArgumentException if the libPath is null or empty + */ + public int removeSharedLibrary(String libPath) throws WLSDeployArchiveIOException { + return removeSharedLibrary(libPath, false); + } + + /** + * Remove the named shared library from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param libPath The shared library name (e.g., foo.war) or the archive path + * to it (e.g., wlsdeploy/sharedLibraries/foo.war) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the shared library is not present (and silent = false) or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the libPath is null or empty + */ + public int removeSharedLibrary(String libPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeSharedLibrary"; + LOGGER.entering(CLASS, METHOD, libPath, silent); + + validateNonEmptyString(libPath, "libPath", METHOD); + + String archivePath; + String appName; + if (libPath.startsWith(ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP)) { + archivePath = libPath; + appName = getNameFromPath(archivePath, ARCHIVE_SHLIBS_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP + libPath; + appName = libPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.SHARED_LIBRARY, appName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01443", appName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.SHARED_LIBRARY,ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // shared library plan methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1348,6 +1532,68 @@ public String replaceSharedLibraryDeploymentPlan(String planPath, String sourceL return newName; } + /** + * Remove the named shared library deployment plan from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param planPath The shared library deployment plan name (e.g., foo.xml) or the archive path + * to it (e.g., wlsdeploy/sharedLibraries/foo.xml) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the shared library deployment plan is not present or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the planPath is null or empty + */ + public int removeSharedLibraryDeploymentPlan(String planPath) throws WLSDeployArchiveIOException { + return removeSharedLibraryDeploymentPlan(planPath, false); + } + + /** + * Remove the named shared library deployment plan from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param planPath The shared library deployment plan name (e.g., foo.xml) or the archive path + * to it (e.g., wlsdeploy/sharedLibraries/foo.xml) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the shared library deployment plan is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the planPath is null or empty + */ + public int removeSharedLibraryDeploymentPlan(String planPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeSharedLibraryDeploymentPlan"; + LOGGER.entering(CLASS, METHOD, planPath, silent); + + validateNonEmptyString(planPath, "planPath", METHOD); + + String archivePath; + String appName; + if (planPath.startsWith(ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP)) { + archivePath = planPath; + appName = getNameFromPath(archivePath, ARCHIVE_SHLIBS_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP + planPath; + appName = planPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.SHLIB_PLAN, appName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01444", appName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.SHLIB_PLAN,ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // domain library methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1451,6 +1697,68 @@ public void extractDomainLibLibrary(String archivePath, File extractToLocation) LOGGER.exiting(CLASS, METHOD); } + /** + * Remove the named domain library from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param libPath The domain library name (e.g., foo.jar) or the archive path + * to it (e.g., wlsdeploy/domainLibraries/foo.jar) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the domain library is not present or an IOException occurred while + * reading the archive or writing the file + * @throws IllegalArgumentException if the libPath is null or empty + */ + public int removeDomainLibrary(String libPath) throws WLSDeployArchiveIOException { + return removeDomainLibrary(libPath, false); + } + + /** + * Remove the named domain library from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param libPath The domain library name (e.g., foo.jar) or the archive path + * to it (e.g., wlsdeploy/domainLibraries/foo.jar) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the domain library is not present (and silent = false) or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the libPath is null or empty + */ + public int removeDomainLibrary(String libPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeDomainLibrary"; + LOGGER.entering(CLASS, METHOD, libPath, silent); + + validateNonEmptyString(libPath, "libPath", METHOD); + + String archivePath; + String appName; + if (libPath.startsWith(ARCHIVE_DOMLIB_TARGET_DIR + ZIP_SEP)) { + archivePath = libPath; + appName = getNameFromPath(archivePath, ARCHIVE_DOMLIB_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_DOMLIB_TARGET_DIR + ZIP_SEP + libPath; + appName = libPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.DOMAIN_LIB, appName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01445", appName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.DOMAIN_LIB,ARCHIVE_DOMLIB_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // classpath lib methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1540,6 +1848,68 @@ public void extractClasspathLibraries(File domainHome) throws WLSDeployArchiveIO LOGGER.exiting(CLASS, METHOD); } + /** + * Remove the named classpath library from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param libPath The classpath library name (e.g., foo.jar) or the archive path + * to it (e.g., wlsdeploy/classpathLibraries/foo.jar) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the classpath library is not present or an IOException occurred while + * reading the archive or writing the file + * @throws IllegalArgumentException if the libPath is null or empty + */ + public int removeClasspathLibrary(String libPath) throws WLSDeployArchiveIOException { + return removeClasspathLibrary(libPath, false); + } + + /** + * Remove the named classpath library from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param libPath The classpath library name (e.g., foo.jar) or the archive path + * to it (e.g., wlsdeploy/classpathLibraries/foo.jar) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the classpath library is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the libPath is null or empty + */ + public int removeClasspathLibrary(String libPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeClasspathLibrary"; + LOGGER.entering(CLASS, METHOD, libPath, silent); + + validateNonEmptyString(libPath, "libPath", METHOD); + + String archivePath; + String appName; + if (libPath.startsWith(ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP)) { + archivePath = libPath; + appName = getNameFromPath(archivePath, ARCHIVE_CPLIB_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP + libPath; + appName = libPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.CLASSPATH_LIB, appName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01446", appName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.CLASSPATH_LIB,ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // domain bin methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1639,6 +2009,68 @@ public void removeDomainBinScripts() throws WLSDeployArchiveIOException { LOGGER.exiting(CLASS, METHOD); } + /** + * Remove the named $DOMAIN_HOME/bin script from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param scriptPath The $DOMAIN_HOME/bin script name (e.g., foo.sh) or the archive path + * to it (e.g., wlsdeploy/domainBin/foo.sh) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the $DOMAIN_HOME/bin script is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the scriptPath is null or empty + */ + public int removeDomainBinScript(String scriptPath) throws WLSDeployArchiveIOException { + return removeDomainBinScript(scriptPath, false); + } + + /** + * Remove the named $DOMAIN_HOME/bin script from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param scriptPath The $DOMAIN_HOME/bin script name (e.g., foo.sh) or the archive path + * to it (e.g., wlsdeploy/domainBin/foo.sh) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the $DOMAIN_HOME/bin script is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the scriptPath is null or empty + */ + public int removeDomainBinScript(String scriptPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeDomainBinScript"; + LOGGER.entering(CLASS, METHOD, scriptPath, silent); + + validateNonEmptyString(scriptPath, "scriptPath", METHOD); + + String archivePath; + String appName; + if (scriptPath.startsWith(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP)) { + archivePath = scriptPath; + appName = getNameFromPath(archivePath, ARCHIVE_DOM_BIN_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP + scriptPath; + appName = scriptPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.DOMAIN_BIN, appName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01447", appName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.DOMAIN_BIN,ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // custom methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1647,18 +2079,19 @@ public void removeDomainBinScripts() throws WLSDeployArchiveIOException { * Add a custom file or directory to the archive. * * @param customEntryPath the file system path to the custom file/directory to add + * @param relativePath the relative archive path name to prepend to the file or directory being added, if any * @return the relative path where the custom file/directory is stored within the archive * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes * @throws IllegalArgumentException if the file or directory passed in does not exist */ - public String addCustomEntry(String customEntryPath) throws WLSDeployArchiveIOException { + public String addCustomEntry(String customEntryPath, String relativePath) throws WLSDeployArchiveIOException { final String METHOD = "addCustomEntry"; - LOGGER.entering(CLASS, METHOD, customEntryPath); + LOGGER.entering(CLASS, METHOD, customEntryPath, relativePath); File filePath = new File(customEntryPath); validateExistingFile(filePath, "customEntryPath", getArchiveFileName(), METHOD, true); - String newName = addItemToZip(ARCHIVE_CUSTOM_TARGET_DIR, filePath); + String newName = addItemToZip(getCustomArchivePath(relativePath), filePath); LOGGER.exiting(CLASS, METHOD, newName); return newName; @@ -1685,7 +2118,7 @@ public String replaceCustomEntry(String customEntryPath, String sourceLocation) } getZipFile().removeZipEntries(archivePath); - String newName = addCustomEntry(sourceLocation); + String newName = addCustomEntry(sourceLocation, getCustomArchivePathForReplace(customEntryPath)); LOGGER.exiting(CLASS, METHOD, newName); return newName; @@ -1727,6 +2160,75 @@ public void extractCustomFiles(File domainHome) throws WLSDeployArchiveIOExcepti LOGGER.exiting(CLASS, METHOD); } + /** + * Remove the named custom file/directory from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param entryPath The custom file/directory name (e.g., mydir/foo.properties) or the archive path + * to it (e.g., wlsdeploy/custom/mydir/foo.properties) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the custom file/directory is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the entryPath is null or empty + */ + public int removeCustomEntry(String entryPath) throws WLSDeployArchiveIOException { + return removeCustomEntry(entryPath, false); + } + + /** + * Remove the named custom file/directory from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param entryPath The custom file/directory name (e.g., mydir/foo.properties) or the archive path + * to it (e.g., wlsdeploy/custom/mydir/foo.properties) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the custom file/directory is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the entryPath is null or empty + */ + @SuppressWarnings("java:S2259") + public int removeCustomEntry(String entryPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeCustomEntry"; + LOGGER.entering(CLASS, METHOD, entryPath, silent); + + validateNonEmptyString(entryPath, "entryPath", METHOD); + + String archivePath; + String appName; + if (entryPath.startsWith(ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP)) { + archivePath = entryPath; + appName = getNameFromPath(archivePath, ARCHIVE_CUSTOM_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP + entryPath; + appName = entryPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.CUSTOM, appName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01448", appName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = 0; + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + result++; + } + + String parentDir = getCustomArchivePathParentDir(appName); + if (!StringUtils.isEmpty(parentDir)) { + // Suppressing Sonar false positive... + result += removeEmptyDirs(parentDir); + } + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // scripts methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1779,6 +2281,68 @@ public String replaceScript(String scriptPath, String sourceLocation) throws WLS return newName; } + /** + * Remove the named script from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param scriptPath The script name (e.g., foo.sh) or the archive path + * to it (e.g., wlsdeploy/scripts/foo.sh) + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the script is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the scriptPath is null or empty + */ + public int removeScript(String scriptPath) throws WLSDeployArchiveIOException { + return removeScript(scriptPath, false); + } + + /** + * Remove the named script from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param scriptPath The script name (e.g., foo.sh) or the archive path + * to it (e.g., wlsdeploy/scripts/foo.sh) + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the script is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the scriptPath is null or empty + */ + public int removeScript(String scriptPath, boolean silent) throws WLSDeployArchiveIOException { + final String METHOD = "removeScript"; + LOGGER.entering(CLASS, METHOD, scriptPath, silent); + + validateNonEmptyString(scriptPath, "scriptPath", METHOD); + + String archivePath; + String appName; + if (scriptPath.startsWith(ARCHIVE_SCRIPTS_DIR + ZIP_SEP)) { + archivePath = scriptPath; + appName = getNameFromPath(archivePath, ARCHIVE_SCRIPTS_DIR.length() + 2); + } else { + archivePath = ARCHIVE_SCRIPTS_DIR + ZIP_SEP + scriptPath; + appName = scriptPath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.SCRIPT, appName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01449", appName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.SCRIPT,ARCHIVE_SCRIPTS_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // server keystore methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1853,6 +2417,64 @@ public String replaceServerKeyStoreFile(String serverName, String keystorePath, return newName; } + /** + * Remove the named server's keystore file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param serverName the name of the server used to segregate the keystore + * @param keystoreName the name of the keystore file + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the server's keystore file is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the serverName or keystoreName is null or empty + */ + public int removeServerKeystore(String serverName, String keystoreName) throws WLSDeployArchiveIOException { + return removeServerKeystore(serverName, keystoreName, false); + } + + /** + * Remove the named server's keystore file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param serverName the name of the server used to segregate the keystore + * @param keystoreName the name of the keystore file + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the server's keystore file is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the serverName or keystoreName is null or empty + */ + public int removeServerKeystore(String serverName, String keystoreName, boolean silent) + throws WLSDeployArchiveIOException { + final String METHOD = "removeServerKeystore"; + LOGGER.entering(CLASS, METHOD, serverName, keystoreName, silent); + + validateNonEmptyString(serverName, "serverName", METHOD); + validateNonEmptyString(keystoreName, "keystoreName", METHOD); + + String parentDir = ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP + serverName; + String archivePath = parentDir + ZIP_SEP + keystoreName; + + List zipEntries = + getSegregatedArchiveEntries(ArchiveEntryType.SERVER_KEYSTORE, serverName, keystoreName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01450", serverName, keystoreName, + getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyDirs(parentDir); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // node manager keystore methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1906,6 +2528,68 @@ public String replaceNodeManagerKeyStoreFile(String keystorePath, String sourceL return newName; } + /** + * Remove the named server's keystore file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param keystoreName the name of the keystore file + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the server's keystore file is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the serverName or keystoreName is null or empty + */ + public int removeNodeManagerKeystore(String keystoreName) throws WLSDeployArchiveIOException { + return removeNodeManagerKeystore(keystoreName, false); + } + + /** + * Remove the named server's keystore file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param keystorePath the name of the keystore file + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the server's keystore file is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the serverName or keystorePath is null or empty + */ + public int removeNodeManagerKeystore(String keystorePath, boolean silent) + throws WLSDeployArchiveIOException { + final String METHOD = "removeNodeManagerKeystore"; + LOGGER.entering(CLASS, METHOD, keystorePath, silent); + + validateNonEmptyString(keystorePath, "keystorePath", METHOD); + + String archivePath; + String keystoreName; + if (keystorePath.startsWith(ARCHIVE_NODE_MANAGER_TARGET_DIR + ZIP_SEP)) { + archivePath = keystorePath; + keystoreName = getNameFromPath(keystorePath, ARCHIVE_NODE_MANAGER_TARGET_DIR.length() + 2); + } else { + archivePath = ARCHIVE_NODE_MANAGER_TARGET_DIR + ZIP_SEP + keystorePath; + keystoreName = keystorePath; + } + + List zipEntries = getArchiveEntries(ArchiveEntryType.NODE_MANAGER_KEY_STORE, keystoreName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01451", keystorePath, + getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.NODE_MANAGER_KEY_STORE, + ARCHIVE_NODE_MANAGER_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // MIME mapping keystore methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1934,29 +2618,91 @@ public String addMimeMappingFile(String mimeMappingFile) throws WLSDeployArchive /** * Replace a WebAppContainer MIME mapping file in the archive. * - * @param mimeMappingPath the MIME mapping name or the path within the archive to replace - * @param sourceLocation the file system location of the new MIME mapping file to replace the existing one - * @return the archive path of the new MIME mapping file - * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes - * @throws IllegalArgumentException if the file or directory passed in does not exist + * @param mimeMappingPath the MIME mapping name or the path within the archive to replace + * @param sourceLocation the file system location of the new MIME mapping file to replace the existing one + * @return the archive path of the new MIME mapping file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the file or directory passed in does not exist + */ + public String replaceMimeMappingFile(String mimeMappingPath, String sourceLocation) + throws WLSDeployArchiveIOException { + final String METHOD = "replaceMimeMappingFile"; + LOGGER.entering(CLASS, METHOD, mimeMappingPath, sourceLocation); + + String archivePath; + if (mimeMappingPath.startsWith(ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP)) { + archivePath = mimeMappingPath; + } else { + archivePath = ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP + mimeMappingPath; + } + + getZipFile().removeZipEntry(archivePath); + String newName = addMimeMappingFile(sourceLocation); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Remove the named MIME mapping file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param mimeMappingPath the name of the MIME mapping file + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the MIME mapping file is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the mimeMappingPath is null or empty + */ + public int removeMimeMappingFile(String mimeMappingPath) throws WLSDeployArchiveIOException { + return removeMimeMappingFile(mimeMappingPath, false); + } + + /** + * Remove the named MIME mapping file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param mimeMappingPath the name of the MIME mapping file + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the MIME mapping file is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the mimeMappingPath is null or empty */ - public String replaceMimeMappingFile(String mimeMappingPath, String sourceLocation) + public int removeMimeMappingFile(String mimeMappingPath, boolean silent) throws WLSDeployArchiveIOException { - final String METHOD = "replaceMimeMappingFile"; - LOGGER.entering(CLASS, METHOD, mimeMappingPath, sourceLocation); + final String METHOD = "removeMimeMappingFile"; + LOGGER.entering(CLASS, METHOD, mimeMappingPath, silent); + + validateNonEmptyString(mimeMappingPath, "mimeMappingPath", METHOD); String archivePath; + String keystoreName; if (mimeMappingPath.startsWith(ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP)) { archivePath = mimeMappingPath; + keystoreName = getNameFromPath(mimeMappingPath, ARCHIVE_CONFIG_TARGET_DIR.length() + 2); } else { archivePath = ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP + mimeMappingPath; + keystoreName = mimeMappingPath; } - getZipFile().removeZipEntry(archivePath); - String newName = addMimeMappingFile(sourceLocation); + List zipEntries = getArchiveEntries(ArchiveEntryType.MIME_MAPPING, keystoreName); - LOGGER.exiting(CLASS, METHOD, newName); - return newName; + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01452", mimeMappingPath, + getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.MIME_MAPPING, + ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -2056,6 +2802,63 @@ public String addCoherenceConfigFileFromUrl(String clusterName, URL urlForConfig return newName; } + /** + * Remove the named Coherence config file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param clusterName the name of the Coherence cluster used for segregating the config files + * @param configFileName the name of the Coherence config file + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the config file is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the clusterName or configFileName is null or empty + */ + public int removeCoherenceConfigFile(String clusterName, String configFileName) throws WLSDeployArchiveIOException { + return removeCoherenceConfigFile(clusterName, configFileName, false); + } + + /** + * Remove the named Coherence config file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param clusterName the name of the Coherence cluster used for segregating the config files + * @param configFileName the name of the Coherence config file + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the config file is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the clusterName or configFileName is null or empty + */ + public int removeCoherenceConfigFile(String clusterName, String configFileName, boolean silent) + throws WLSDeployArchiveIOException { + final String METHOD = "removeCoherenceConfigFile"; + LOGGER.entering(CLASS, METHOD, clusterName, configFileName, silent); + + validateNonEmptyString(clusterName, "clusterName", METHOD); + validateNonEmptyString(configFileName, "configFileName", METHOD); + + String parentDir = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + clusterName; + String archivePath = parentDir + ZIP_SEP + configFileName; + + List zipEntries = + getSegregatedArchiveEntries(ArchiveEntryType.COHERENCE_CONFIG, clusterName, configFileName); + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01453", clusterName, + configFileName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyDirs(parentDir); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // Coherence persistence directory file methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -2111,6 +2914,65 @@ public String replaceCoherencePersistenceDirectory(String clusterName, String di return newName; } + /** + * Remove the named Coherence persistence directory from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param clusterName the name of the Coherence cluster used for segregating the persistence directories + * @param persistenceDirectory the name of the Coherence persistence directory + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the Coherence persistence directory is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the clusterName or persistenceDirectory is null or empty + */ + public int removeCoherencePersistenceDirectory(String clusterName, String persistenceDirectory) + throws WLSDeployArchiveIOException { + return removeCoherencePersistenceDirectory(clusterName, persistenceDirectory, false); + } + + /** + * Remove the named Coherence persistence directory from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param clusterName the name of the Coherence cluster used for segregating the config files + * @param persistenceDirectory the name of the Coherence persistence directory + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the Coherence persistence directory is not present (and silent = false) + * or an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the clusterName or persistenceDirectory is null or empty + */ + public int removeCoherencePersistenceDirectory(String clusterName, String persistenceDirectory, boolean silent) + throws WLSDeployArchiveIOException { + final String METHOD = "removeCoherencePersistenceDirectory"; + LOGGER.entering(CLASS, METHOD, clusterName, persistenceDirectory, silent); + + validateNonEmptyString(clusterName, "clusterName", METHOD); + validateNonEmptyString(persistenceDirectory, "persistenceDirectory", METHOD); + + String parentDir = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + clusterName; + String archivePath = parentDir + ZIP_SEP + persistenceDirectory; + + List zipEntries = + getSegregatedArchiveEntries(ArchiveEntryType.COHERENCE, clusterName, persistenceDirectory); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01454", clusterName, + persistenceDirectory, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyDirs(parentDir); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // JMS foreign server binding file methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -2182,6 +3044,64 @@ public String replaceForeignServerFile(String foreignServerName, String configPa return newName; } + /** + * Remove the named JMS Foreign Server bindings file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param foreignServer the name of the JMS Foreign Server used for segregating the bindings files + * @param bindingsFileName the name of the JMS Foreign Server bindings file + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the bindings file is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the foreignServer or bindingsFileName is null or empty + */ + public int removeForeignServerFile(String foreignServer, String bindingsFileName) + throws WLSDeployArchiveIOException { + return removeForeignServerFile(foreignServer, bindingsFileName, false); + } + + /** + * Remove the named JMS Foreign Server bindings file from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param foreignServer the name of the JMS Foreign Server used for segregating the bindings files + * @param bindingsFileName the name of the JMS Foreign Server bindings file + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the bindings file is not present (and silent = false) or + * an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the foreignServer or bindingsFileName is null or empty + */ + public int removeForeignServerFile(String foreignServer, String bindingsFileName, boolean silent) + throws WLSDeployArchiveIOException { + final String METHOD = "removeForeignServerFile"; + LOGGER.entering(CLASS, METHOD, foreignServer, bindingsFileName, silent); + + validateNonEmptyString(foreignServer, "foreignServer", METHOD); + validateNonEmptyString(bindingsFileName, "bindingsFileName", METHOD); + + String parentDir = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServer; + String archivePath = parentDir + ZIP_SEP + bindingsFileName; + + List zipEntries = + getSegregatedArchiveEntries(ArchiveEntryType.JMS_FOREIGN_SERVER, foreignServer, bindingsFileName); + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01455", foreignServer, + bindingsFileName, getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyDirs(parentDir); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // file store methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -2238,6 +3158,60 @@ public String replaceFileStoreDirectory(String fileStorePath) throws WLSDeployAr return newName; } + /** + * Remove the named File Store directory from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param fileStoreName the name of the File Store directory + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the File Store directory is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the fileStoreName is null or empty + */ + public int removeFileStoreDirectory(String fileStoreName) + throws WLSDeployArchiveIOException { + return removeFileStoreDirectory(fileStoreName, false); + } + + /** + * Remove the named File Store directory from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param fileStoreName the name of the File Store directory + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the File Store directory is not present (and silent = false) + * or an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the fileStoreName is null or empty + */ + public int removeFileStoreDirectory(String fileStoreName, boolean silent) + throws WLSDeployArchiveIOException { + final String METHOD = "removeFileStoreDirectory"; + LOGGER.entering(CLASS, METHOD, fileStoreName, silent); + + validateNonEmptyString(fileStoreName, "fileStoreName", METHOD); + + String archivePath = ARCHIVE_FILE_STORE_TARGET_DIR + ZIP_SEP + fileStoreName; + + List zipEntries = getArchiveEntries(ArchiveEntryType.FILE_STORE, fileStoreName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01456", fileStoreName, + getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.FILE_STORE, ARCHIVE_FILE_STORE_TARGET_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // database wallet methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -2346,6 +3320,60 @@ public String extractDatabaseWallet(File domainHome, String walletName) throws W return extractPath; } + /** + * Remove the named database wallet from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param walletName the name of the database wallet to remove + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the database wallet is not present or an IOException + * occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the walletName is null or empty + */ + public int removeDatabaseWallet(String walletName) + throws WLSDeployArchiveIOException { + return removeDatabaseWallet(walletName, false); + } + + /** + * Remove the named database wallet from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param walletName the name of the database wallet to remove + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the database wallet is not present (and silent = false) + * or an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the walletName is null or empty + */ + public int removeDatabaseWallet(String walletName, boolean silent) + throws WLSDeployArchiveIOException { + final String METHOD = "removeDatabaseWallet"; + LOGGER.entering(CLASS, METHOD, walletName, silent); + + validateNonEmptyString(walletName, "walletName", METHOD); + + String archivePath = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName; + + List zipEntries = getArchiveEntries(ArchiveEntryType.DB_WALLET, walletName); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01457", walletName, + getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + result += removeEmptyTypeDir(ArchiveEntryType.DB_WALLET, ARCHIVE_DB_WALLETS_DIR + ZIP_SEP); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // OPSS wallet methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -2426,6 +3454,52 @@ public String extractOPSSWallet(File domainHome) throws WLSDeployArchiveIOExcept return extractPath; } + /** + * Remove the OPSS wallet from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the OPSS wallet is not present or an IOException + * occurred while reading the archive or writing the file + */ + public int removeOPSSWallet() + throws WLSDeployArchiveIOException { + return removeOPSSWallet(false); + } + + /** + * Remove the OPSS wallet from the archive file. + * + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the OPSS wallet is not present (and silent = false) + * or an IOException occurred while reading the archive or writing the file + */ + public int removeOPSSWallet(boolean silent) + throws WLSDeployArchiveIOException { + final String METHOD = "removeOPSSWallet"; + LOGGER.entering(CLASS, METHOD, silent); + + String archivePath = ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP; + + List zipEntries = getArchiveEntries(ArchiveEntryType.OPSS_WALLET); + + if (!silent && zipEntries.isEmpty()) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01458", + getArchiveFileName(), archivePath); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + int result = zipEntries.size(); + for (String zipEntry : zipEntries) { + getZipFile().removeZipEntry(zipEntry); + } + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Protected Helper methods // /////////////////////////////////////////////////////////////////////////////////////////// @@ -3216,6 +4290,100 @@ private String getNameFromPath(String path, int startIndex) throws WLSDeployArch return result; } + private String getCustomArchivePath(String relativePath) { + final String METHOD = "getCustomArchivePath"; + LOGGER.entering(CLASS, METHOD, relativePath); + + String archivePath = ARCHIVE_CUSTOM_TARGET_DIR; + if (!StringUtils.isEmpty(relativePath)) { + if (!relativePath.startsWith(ZIP_SEP)) { + archivePath += ZIP_SEP; + } + archivePath += relativePath; + } + + LOGGER.exiting(CLASS, METHOD, archivePath); + return archivePath; + } + + private String getCustomArchivePathForReplace(String replacementPath) { + final String METHOD = "getCustomArchivePathForReplace"; + LOGGER.entering(CLASS, METHOD, replacementPath); + + String archivePath = replacementPath; + if (replacementPath.startsWith(ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP)) { + archivePath = replacementPath.substring(ARCHIVE_CUSTOM_TARGET_DIR.length() + 2); + } else if (replacementPath.startsWith(ZIP_SEP)) { + archivePath = replacementPath.substring(1); + } + + if (archivePath.endsWith(ZIP_SEP)) { + archivePath = archivePath.substring(0, archivePath.length() - 1); + } + + int lastZipSep = archivePath.lastIndexOf(ZIP_SEP); + if (lastZipSep != -1) { + archivePath = archivePath.substring(0, lastZipSep); + } else { + archivePath = null; + } + + LOGGER.exiting(CLASS, METHOD, archivePath); + return archivePath; + } + + private String getCustomArchivePathParentDir(String removePath) { + final String METHOD = "getCustomArchivePathParentDir"; + LOGGER.entering(CLASS, METHOD, removePath); + + String archivePath = removePath; + if (!removePath.startsWith(ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP + removePath; + } + + if (archivePath.endsWith(ZIP_SEP)) { + archivePath = archivePath.substring(0, archivePath.length() - 1); + } + + int lastZipSep = archivePath.lastIndexOf(ZIP_SEP); + if (lastZipSep != -1) { + archivePath = archivePath.substring(0, lastZipSep); + } else { + archivePath = null; + } + + LOGGER.exiting(CLASS, METHOD, archivePath); + return archivePath; + + } + + private int removeEmptyDirs(String parentDir) throws WLSDeployArchiveIOException { + final String METHOD = "removeEmptyDirs"; + LOGGER.entering(CLASS, METHOD, parentDir); + + String archivePath = parentDir; + if (!archivePath.endsWith(ZIP_SEP)) { + archivePath += ZIP_SEP; + } + + List zipEntries = getZipFile().listZipEntries(archivePath); + + int result = 0; + if (zipEntries.size() == 1 && archivePath.equals(zipEntries.get(0))) { + getZipFile().removeZipEntry(zipEntries.get(0)); + result++; + + int lastZipSep = archivePath.substring(0, archivePath.length() - 1).lastIndexOf(ZIP_SEP); + if (lastZipSep != -1) { + String newParentDir = archivePath.substring(0, lastZipSep); + result += removeEmptyDirs(newParentDir); + } + } + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + private int removeEmptyTypeDir(ArchiveEntryType type, String prefixPath) throws WLSDeployArchiveIOException { final String METHOD = "removeEmptyTypeDir"; LOGGER.entering(CLASS, METHOD, type.name(), prefixPath); diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index d6206f0ba1..f8af3744fc 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -214,6 +214,25 @@ WLSDPLY-01437=Failed to add OPSS Wallet to archive because the archive file {0} WLSDPLY-01438=Failed to get path for archive type {0} because it is not a known type. WLSDPLY-01439=Failed to get name starting at index {0} from path {1} because the path is not long enough. WLSDPLY-01440=Failed to remove application {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01441=Failed to remove application deployment plan {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01442=Failed to remove structured application {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01443=Failed to remove shared library {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01444=Failed to remove shared library deployment plan {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01445=Failed to remove domain library {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01446=Failed to remove classpath library {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01447=Failed to remove $DOMAIN_HOME/bin script {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01448=Failed to remove custom entry {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01449=Failed to remove script {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01450=Failed to remove server {0} keystore {1} from archive file {2} because the archive file did not contain {3}. +WLSDPLY-01451=Failed to remove node manager keystore {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01452=Failed to remove MIME mapping file {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01453=Failed to remove Coherence cluster {0} config file {1} from archive file {2} because the archive file did not contain {3}. +WLSDPLY-01454=Failed to remove Coherence cluster {0} persistence directory {1} from archive file {2} because the archive file did not contain {3}. +WLSDPLY-01455=Failed to remove JMS Foreign Server {0} bindings file {1} from archive file {2} because the archive file did not contain {3}. +WLSDPLY-01456=Failed to remove File Store {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01457=Failed to remove database wallet {0} from archive file {1} because the archive file did not contain {2}. +WLSDPLY-01458=Failed to remove OPSS wallet from archive file {0} because the archive file did not contain {1}. + # oracle.weblogic.deploy.util.WLSDeployZipFile.java WLSDPLY-01500=The zip file {0} has the saved entry {1} @@ -1767,3 +1786,20 @@ WLSDPLY-30022=Failed to add {0} name {1} from {2} to archive file {3}: {4}. WLSDPLY-30023=Failed to add {0} name {1} from {2} with overwrite value {3} to archive file {4}: {5}. WLSDPLY-30024=Failed to add OPSS wallet from {0} to archive file {1}: {2}. WLSDPLY-30025=Failed to add OPSS wallet from {0} with overwrite value {1} to archive file {2}: {3}. +WLSDPLY-30026=The archiveHelper remove {0} -name {1} command removed {2} entries from archive file {3}. +WLSDPLY-30027=Failed to remove {0} {1} from archive file {2}: {3}. +WLSDPLY-30028=Failed to remove {0} {1} with force value {2} from archive file {3}: {4}. +WLSDPLY-30029=The archiveHelper remove {0} -server_name {1} -name {2} command removed {3} entries from archive file {4}. +WLSDPLY-30030=Failed to remove server {0} keystore {1} from archive file {2}: {3}. +WLSDPLY-30031=Failed to remove server {0} keystore {1} with force value {2} from archive file {3}: {4}. +WLSDPLY-30032=The archiveHelper remove {0} -cluster_name {1} -name {2} command removed {3} entries from archive file {4}. +WLSDPLY-30033=Failed to remove Coherence cluster {0} config file {1} from archive file {2}: {3}. +WLSDPLY-30034=Failed to remove Coherence cluster {0} config file {1} with force value {2} from archive file {3}: {4}. +WLSDPLY-30035=Failed to remove Coherence cluster {0} persistence directory {1} from archive file {2}: {3}. +WLSDPLY-30036=Failed to remove Coherence cluster {0} persistence directory {1} with force value {2} from archive file {3}: {4}. +WLSDPLY-30037=The archiveHelper remove {0} -foreign_server_name {1} -name {2} command removed {3} entries from archive file {4}. +WLSDPLY-30038=Failed to remove JMS Foreign Server {0} bindings file {1} from archive file {2}: {3}. +WLSDPLY-30039=Failed to remove JMS Foreign Server {0} bindings file {1} with force value {2} from archive file {3}: {4}. +WLSDPLY-30040=The archiveHelper remove {0} command removed {1} entries from archive file {2}. +WLSDPLY-30041=Failed to remove {0} from archive file {1}: {2}. +WLSDPLY-30042=Failed to remove {0} with force value {1} from archive file {2}: {3}. diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java index bf5af22a54..5c869cbf6d 100644 --- a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java @@ -20,8 +20,12 @@ import oracle.weblogic.deploy.util.WLSDeployZipFileTest; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.ALL_CONTENT; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.APPLICATIONS_CONTENT; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIBS_CONTENT; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_JAR_CONTENTS; @@ -50,6 +54,9 @@ import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SCRIPTS_FANCY_SCRIPT_CONTENTS; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SERVERS_ADMIN_SERVER_CONTENTS; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SERVERS_ADMIN_SERVER_TRUST_JKS_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_LIB_WAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_OTHER_LIB_CONTENTS; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APPS_CONTENT; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APP_WEBAPP_CONTENTS; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APP_WEBAPP1_CONTENTS; @@ -68,6 +75,8 @@ public class ArchiveHelperListTest { new File(UNIT_TEST_TARGET_DIR, "archive-helper-test.zip").toPath(); private static final String ARCHIVE_HELPER_VALUE = ARCHIVE_HELPER_TARGET_ZIP.toFile().getAbsolutePath(); + private static final String[] LIST_ALL_EXPECTED = ALL_CONTENT; + private static final String[] LIST_APP_FILE_EXPECTED = MY_APP_WAR_CONTENTS; private static final String[] LIST_APP_DIR_EXPECTED = MY_OTHER_APP_DIR_CONTENTS; private static final String[] LIST_APPS_EXPECTED = APPLICATIONS_CONTENT; @@ -87,6 +96,11 @@ public class ArchiveHelperListTest { private static final String[] LIST_RCU_WALLET_EXPECTED = DATABASE_WALLET_RCU_CONTENTS; private static final String[] LIST_WALLET1_EXPECTED = DATABASE_WALLET_WALLET1_CONTENTS; + private static final String[] LIST_SHLIB_FILE_EXPECTED = SHARED_LIBS_MY_LIB_WAR_CONTENTS; + private static final String[] LIST_SHLIB_DIR_EXPECTED = SHARED_LIBS_MY_OTHER_LIB_CONTENTS; + private static final String[] LIST_SHLIB_EXPECTED = SHARED_LIBS_CONTENT; + + private static final String[] LIST_STRUCTURED_APP_WEBAPP_EXPECTED = STRUCTURED_APP_WEBAPP_CONTENTS; private static final String[] LIST_STRUCTURED_APP_WEBAPP1_EXPECTED = STRUCTURED_APP_WEBAPP1_CONTENTS; private static final String[] LIST_STRUCTURED_APPS_EXPECTED = STRUCTURED_APPS_CONTENT; @@ -103,13 +117,33 @@ static void initialize() throws Exception { logger.setLevel(Level.OFF); } - @Test - void testListAppsNoArchive_Fails() { + @ParameterizedTest + @ValueSource(strings = { + "all", + "application", + "classpathLibrary", + "coherence", + "custom", + "databaseWallet", + "domainBinScript", + "domainLibrary", + "fileStore", + "jmsForeignServer", + "mimMapping", + "nodeManagerKeystore", + "opssWallet", + "rcuWallet", + "script", + "serverKeystore", + "sharedLibrary", + "structuredApplication" + }) + void testListAppsNoArchive_Fails(String subcommand) { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[] { "list", - "application" + subcommand }; int actual = -1; @@ -122,25 +156,94 @@ void testListAppsNoArchive_Fails() { "expected command to exit with exit code " + ExitCode.USAGE_ERROR); } + @ParameterizedTest + @ValueSource(strings = { + "all", + "application", + "classpathLibrary", + "coherence", + "custom", + "databaseWallet", + "domainBinScript", + "domainLibrary", + "fileStore", + "jmsForeignServer", + "mimeMapping", + "nodeManagerKeystore", + "opssWallet", + "rcuWallet", + "script", + "serverKeystore", + "sharedLibrary", + "structuredApplication" + }) + void testListAppsBadArchive_Fails(String subcommand) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args; + switch(subcommand) { + case "jmsForeignServer": + args = new String[] { + "list", + subcommand, + "-foreign_server_name", + "foo", + "-archive_file", + "foo.zip" + }; + break; + + case "serverKeystore": + args = new String[] { + "list", + subcommand, + "-server_name", + "foo", + "-archive_file", + "foo.zip" + }; + break; + + default: + args = new String[] { + "list", + subcommand, + "-archive_file", + "foo.zip" + }; + } + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.ARG_VALIDATION_ERROR, actual, + "expected command to exit with exit code " + ExitCode.ARG_VALIDATION_ERROR); + } + @Test - void testListAppsBadArchive_Fails() { + void testListAll_ReturnedExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[] { "list", - "application", + "all", "-archive_file", - "foo.zip" + ARCHIVE_HELPER_VALUE }; + List expectedPaths = Arrays.asList(LIST_ALL_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); PrintWriter err = new PrintWriter(errStringWriter)) { actual = ArchiveHelper.executeCommand(out, err, args); } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); - assertEquals(ExitCode.ARG_VALIDATION_ERROR, actual, - "expected command to exit with exit code " + ExitCode.ARG_VALIDATION_ERROR); + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertListsHaveSameElements(expectedPaths, outputLines, "all"); } @Test @@ -155,7 +258,7 @@ void testListAppFile_ReturnsExpectedName() { "-name", "my-app.war" }; - String expectedPath = LIST_APP_FILE_EXPECTED[0]; + List expectedPaths = Arrays.asList(LIST_APP_FILE_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -165,8 +268,7 @@ void testListAppFile_ReturnsExpectedName() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(1, outputLines.length, "expected list applications -name my-app.war to return 1 entry"); - assertEquals(expectedPath, outputLines[0],"expected " + expectedPath); + assertListsHaveSameElements(expectedPaths, outputLines, "application -name my-app.war"); } @Test @@ -191,11 +293,7 @@ void testListAppDirectory_ReturnsExpectedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list applications -name my-other-app to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "application -name my-other-app"); } @Test @@ -218,15 +316,11 @@ void testListApps_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list applications to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "application"); } @Test - void testListSharedLibraries_ReturnsNoNames() { + void testListSharedLibraries_ReturnsExpectedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[] { @@ -235,16 +329,67 @@ void testListSharedLibraries_ReturnsNoNames() { "-archive_file", ARCHIVE_HELPER_VALUE }; + List expectedPaths = Arrays.asList(LIST_SHLIB_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); PrintWriter err = new PrintWriter(errStringWriter)) { actual = ArchiveHelper.executeCommand(out, err, args); } - String outputLines = outStringWriter.getBuffer().toString().trim(); + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals("", outputLines, "expected list sharedLibrary to return nothing"); + assertListsHaveSameElements(expectedPaths, outputLines, "sharedLibrary"); + } + + @Test + void testListSharedLibraryFile_ReturnsExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-lib.war" + }; + List expectedPaths = Arrays.asList(SHARED_LIBS_MY_LIB_WAR_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertListsHaveSameElements(expectedPaths, outputLines, "sharedLibrary -name my-lib.war"); + } + + @Test + void testListSharedLibraryDir_ReturnsExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-other-lib" + }; + List expectedPaths = Arrays.asList(SHARED_LIBS_MY_OTHER_LIB_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertListsHaveSameElements(expectedPaths, outputLines, "sharedLibrary -name my-other-lib"); } @Test @@ -291,11 +436,7 @@ void testListClasspathLibs_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list classpathLibrary to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "classpathLibrary"); } @Test @@ -320,11 +461,7 @@ void testListClasspathLibFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list classpathLibrary to return " + expectedPaths.size() + " entry"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "classpathLibrary -name bar.jar"); } @Test @@ -349,11 +486,7 @@ void testListCohMyCluster_ReturnedExpectedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list coherence -cluster_name mycluster to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "coherence -cluster_name mycluster"); } @Test @@ -378,11 +511,7 @@ void testListCohMyCluster2_ReturnedExpectedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list coherence -cluster_name mycluster2 to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "coherence -cluster_name mycluster2"); } @Test @@ -405,11 +534,7 @@ void testListCoh_ReturnedExpectedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list coherence to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "coherence"); } @Test @@ -432,11 +557,7 @@ void testListMime_ReturnedExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list mimeMapping to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "mimeMapping"); } @Test @@ -461,11 +582,7 @@ void testListMimeMappingProperties_ReturnedExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list mimeMapping to return " + expectedPaths.size() + " entry"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "mimeMapping -name mimemappings.properties"); } @Test @@ -488,11 +605,7 @@ void testListCustom_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list custom to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "custom"); } @Test @@ -517,11 +630,7 @@ void testListCustomDir_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list custom to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "custom -name mydir"); } @Test @@ -546,11 +655,7 @@ void testListCustomFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list custom to return " + expectedPaths.size() + " entry"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "custom -name foo.properties"); } @Test @@ -575,11 +680,7 @@ void testListDbWalletRCU_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, "expected list databaseWallet -name " + - DEFAULT_RCU_WALLET_NAME + " to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "databaseWallet -name " + DEFAULT_RCU_WALLET_NAME); } @Test @@ -602,11 +703,7 @@ void testListRCUWallet_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list rcuWallet to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "rcuWallet"); } @Test @@ -631,11 +728,7 @@ void testListWallet1Dir_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list databaseWallet -name wallet1 to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "databaseWallet -name wallet1"); } @Test @@ -658,11 +751,7 @@ void testListDomainBin_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list domainBinScript to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "domainBinScript"); } @Test @@ -687,11 +776,7 @@ void testListDomainBinFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list domainBinScript -name setUserOverrides.sh to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "domainBinScript -name setUserOverrides.sh"); } @Test @@ -714,11 +799,7 @@ void testListDomainLib_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list domainLibrary to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "domainLibrary"); } @Test @@ -743,11 +824,7 @@ void testListDomainLibFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list domainLibrary -name foo.jar to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "domainLibrary -name foo.jar"); } @Test @@ -770,11 +847,7 @@ void testListNodeManager_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list nodeManagerKeystore to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "nodeManagerKeystore"); } @Test @@ -799,11 +872,7 @@ void testListNodeManagerFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list nodeManagerKeystore -name nmTrust.jks to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "nodeManagerKeystore -name nmTrust.jks"); } @Test @@ -826,11 +895,7 @@ void testListOPSSWallet_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list opssWallet to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "opssWallet"); } @Test @@ -853,11 +918,7 @@ void testListScripts_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list script to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "script"); } @Test @@ -882,11 +943,7 @@ void testListScriptsFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list script -name my_fancy_script.sh to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "script -name my_fancy_script.sh"); } @Test @@ -911,11 +968,7 @@ void testListServerKeystore_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list serverKeystore to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "serverKeystore"); } @Test @@ -942,11 +995,7 @@ void testListServerKeystoreFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list serverKeystore -name trust.jks to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "serverKeystore -name trust.jks"); } @Test @@ -969,11 +1018,7 @@ void testListFileStore_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list fileStore to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "fileStore"); } @Test @@ -998,11 +1043,7 @@ void testListFileStoreDir_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list fileStore -name fs2 to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "fileStore -name fs2"); } @Test @@ -1027,11 +1068,7 @@ void testListStructuredAppWebapp_ReturnedExpectedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list structuredApplication -name webapp to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "structuredApplication -name webapp"); } @Test @@ -1056,11 +1093,7 @@ void testListStructuredAppWebapp1_ReturnedExpectedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list structuredApplication -name webapp1 to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); - } + assertListsHaveSameElements(expectedPaths, outputLines, "structuredApplication -name webapp1"); } @Test @@ -1083,10 +1116,15 @@ void testListStructuredApp_ReturnedExpectedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals(expectedPaths.size(), outputLines.length, - "expected list structuredApplication to return " + expectedPaths.size() + " entries"); - for (String actualLine : outputLines) { - assertTrue(expectedPaths.contains(actualLine), actualLine + " not in expected output"); + assertListsHaveSameElements(expectedPaths, outputLines, "structuredApplication"); + } + + private static void assertListsHaveSameElements(List expectedEntries, String[] actualLines, String command) { + assertEquals(expectedEntries.size(), actualLines.length, "expected list " + command + " to return " + + expectedEntries.size() + " entries"); + for (String actualLine : actualLines) { + assertTrue(expectedEntries.contains(actualLine), actualLine + " not in expected output"); } + } } diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java index 3474ca460b..6cd3a47b01 100644 --- a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java @@ -12,20 +12,55 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.logging.Level; import oracle.weblogic.deploy.logging.PlatformLogger; import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; import oracle.weblogic.deploy.util.ExitCode; import oracle.weblogic.deploy.util.StringUtils; import oracle.weblogic.deploy.util.WLSDeployZipFileTest; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.APPLICATIONS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIBS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_FOO_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_MYDIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLETS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLET_RCU_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLET_WALLET1_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_BIN_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_LIB_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FILE_STORES_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FILE_STORES_FS2_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FOREIGN_SERVERS_FS1_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MIME_MAPPINGS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_APP_DEPLOYMENT_PLAN_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_APP_WAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_OTHER_APP_DIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.NODE_MANAGER_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.NODE_MANAGER_IDENTITY_JKS_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.OPSS_WALLET_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SCRIPTS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SERVERS_ADMIN_SERVER_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_LIB_WAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_LIB_XML_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_OTHER_LIB_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APPS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APP_WEBAPP_CONTENTS; import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -41,6 +76,36 @@ public class ArchiveHelperRemoveTest { new File(UNIT_TEST_TARGET_DIR, "archive-helper-test.zip").toPath(); private static final String ARCHIVE_HELPER_VALUE = ARCHIVE_HELPER_TARGET_ZIP.toFile().getAbsolutePath(); + private static final String[] LIST_APPLICATIONS = new String[] { "application" }; + private static final String[] LIST_CLASSPATH_LIBRARIES = new String[] { "classpathLibrary" }; + private static final String[] LIST_COHERENCE_MY_CLUSTER = new String[] { + "coherence", + "-cluster_name", + "mycluster" + }; + private static final String[] LIST_CUSTOM_ENTRIES = new String[] { "custom" }; + private static final String[] LIST_DATABASE_WALLETS = new String[] { "databaseWallet" }; + private static final String[] LIST_DOMAIN_BIN_SCRIPTS = new String[] { "domainBinScript" }; + private static final String[] LIST_DOMAIN_LIBRARIES = new String[] { "domainLibrary" }; + private static final String[] LIST_FILE_STORES = new String[] { "fileStore" }; + private static final String[] LIST_FOREIGN_SERVERS_FS1 = new String[] { + "jmsForeignServer", + "-foreign_server_name", + "fs1" + }; + private static final String[] LIST_MIME_MAPPINGS = new String[] { "mimeMapping" }; + private static final String[] LIST_NODE_MANAGER_KEYSTORES = new String[] { "nodeManagerKeystore" }; + private static final String[] LIST_OPSS_WALLET = new String[] { "opssWallet" }; + private static final String[] LIST_RCU_WALLET = new String[] { "rcuWallet" }; + private static final String[] LIST_SCRIPTS = new String[] { "script" }; + private static final String[] LIST_SERVER_KEYSTORES_ADMIN_SERVER = new String[] { + "serverKeystore", + "-server_name", + "AdminServer" + }; + private static final String[] LIST_SHARED_LIBRARIES = new String[] { "sharedLibrary" }; + private static final String[] LIST_STRUCTURED_APPLICATIONS = new String[] { "structuredApplication" }; + @BeforeAll static void initialize() throws Exception { if(!UNIT_TEST_TARGET_DIR.exists() && !UNIT_TEST_TARGET_DIR.mkdirs()) { @@ -56,15 +121,39 @@ void setup() throws Exception { Files.copy(ARCHIVE_HELPER_SOURCE_ZIP, ARCHIVE_HELPER_TARGET_ZIP, StandardCopyOption.REPLACE_EXISTING); } - @Test - void testRemoveNoArchive_Fails() { + /////////////////////////////////////////////////////////////////////////////////////////////// + // parameterized // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @ParameterizedTest + @CsvSource({ + "application, missing.war", + "applicationPlan, missing.xml", + "classpathLibrary, missing.jar", + "coherenceConfig, missing.xml", + "coherencePersistenceDir, active", + "custom, missing.properties", + "databaseWallet, wallet1", + "domainBinScript, missing.sh", + "domainLibrary, missing.jar", + "fileStore, missing", + "jmsForeignServer, missing.properties", + "mimeMapping, missing.properties", + "nodeManagerKeystore, missing.jks", + "script, missing.sh", + "serverKeystore, missing.jks", + "sharedLibrary, missing.war", + "sharedLibraryPlan, missing.xml", + "structuredApplication, missingApp" + }) + void testNoArchive_Fails(String subcommand, String name) { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[] { "remove", - "application", + subcommand, "-name", - "my-app.war" + name }; int actual = -1; @@ -76,13 +165,33 @@ void testRemoveNoArchive_Fails() { "expected command to exit with exit code " + ExitCode.USAGE_ERROR); } - @Test - void testRemoveNoApp_Fails() { + @ParameterizedTest + @ValueSource(strings = { + "application", + "applicationPlan", + "classpathLibrary", + "coherenceConfig", + "coherencePersistenceDir", + "custom", + "databaseWallet", + "domainBinScript", + "domainLibrary", + "fileStore", + "jmsForeignServer", + "mimeMapping", + "nodeManagerKeystore", + "script", + "serverKeystore", + "sharedLibrary", + "sharedLibraryPlan", + "structuredApplication" + }) + void testRemoveNoName_Fails(String subcommand) { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[] { "remove", - "application", + subcommand, "-archive_file", ARCHIVE_HELPER_VALUE }; @@ -96,8 +205,49 @@ void testRemoveNoApp_Fails() { "expected command to exit with exit code " + ExitCode.USAGE_ERROR); } - // @Test - void testRemoveExistingAppFile_ReturnsExpectedResults() { + @ParameterizedTest + @CsvSource({ + "application, missing.war", + "applicationPlan, missing.xml", + "classpathLibrary, missing.jar", + "custom, missing.properties", + "databaseWallet, missing", + "domainBinScript, missing.sh", + "domainLibrary, missing.jar", + "fileStore, missing", + "mimeMapping, missing.properties", + "nodeManagerKeystore, missing.jks", + "script, missing.sh", + "sharedLibrary, missing.war", + "sharedLibraryPlan, missing.xml", + "structuredApplication, missingApp" + }) + void testRemoveMissingName_ReturnsExpectedResults(String subcommand, String name) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + subcommand, + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + name + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual,"expected command to exit with exit code " + ExitCode.ERROR); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // application // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingAppFile_ReturnsExpectedResults() throws Exception { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[] { @@ -115,24 +265,1480 @@ void testRemoveExistingAppFile_ReturnsExpectedResults() { actual = ArchiveHelper.executeCommand(out, err, args); } assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, APPLICATIONS_CONTENT, MY_APP_WAR_CONTENTS); + } + + @Test + void testRemoveExistingAppDir_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "application", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-other-app" + }; - List remainingEntries = getRemainingEntries("list", "application", "-archive_file", ARCHIVE_HELPER_VALUE); + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, APPLICATIONS_CONTENT, MY_OTHER_APP_DIR_CONTENTS); } - List getRemainingEntries(String... args) { + @Test + void testRemoveMissingAppForce_ReturnsExpectedResults() throws Exception { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "application", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo", + "-force" + }; int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); PrintWriter err = new PrintWriter(errStringWriter)) { actual = ArchiveHelper.executeCommand(out, err, args); } - String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); - if (outputLines.length == 0 || (outputLines.length == 1 && StringUtils.isEmpty(outputLines[0]))) { - return new ArrayList<>(); - } else { - return Arrays.asList(outputLines); + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, APPLICATIONS_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // application plan // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingAppPlan_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "applicationPlan", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-app.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, APPLICATIONS_CONTENT, MY_APP_DEPLOYMENT_PLAN_CONTENTS); + } + + @Test + void testRemoveMissingAppPlanForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "applicationPlan", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo.xml", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, APPLICATIONS_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // classpath library // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingClasspathLibFile_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "classpathLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "bar.jar" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only jar so the test will also remove wlsdeploy/classpathLibraries/ + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, CLASSPATH_LIBS_CONTENT, CLASSPATH_LIBS_CONTENT); + } + + @Test + void testRemoveMissingClasspathLibForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "classpathLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "missing.jar", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, CLASSPATH_LIBS_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Coherence config // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveCoherenceConfigNoClusterName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherenceConfig", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "cache-config.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testRemoveCoherenceConfigMissingClusterName_ReturnsExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherenceConfig", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "missing", + "-name", + "cache-config.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual,"expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testRemoveCoherenceConfigMissingName_ReturnsExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherenceConfig", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "mycluster", + "-name", + "missing.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual,"expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testRemoveExistingCoherenceConfig_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherenceConfig", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "mycluster", + "-name", + "cache-config.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_MY_CLUSTER, COHERENCE_MYCLUSTER_CONTENTS, + COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS); + } + + @Test + void testRemoveCoherenceConfigMissingNameForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherenceConfig", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "mycluster", + "-name", + "missing.xml", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_MY_CLUSTER, COHERENCE_MYCLUSTER_CONTENTS); + } + + @Test + void testRemoveCoherenceConfigMissingClusterNameForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherenceConfig", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "missing", + "-name", + "cache-config.xml", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_MY_CLUSTER, COHERENCE_MYCLUSTER_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Coherence persistence dir // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveCoherencePersistenceDirNoClusterName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherencePersistenceDir", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "active" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testRemoveCoherencePersistenceDirMissingClusterName_ReturnsExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherencePersistenceDir", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "missing", + "-name", + "active" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual,"expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testRemoveCoherencePersistenceDirMissingName_ReturnsExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherencePersistenceDir", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "mycluster", + "-name", + "missing" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual,"expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testRemoveExistingCoherencePersistenceDir_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherencePersistenceDir", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "mycluster", + "-name", + "active" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_MY_CLUSTER, COHERENCE_MYCLUSTER_CONTENTS, + COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS); + } + + @Test + void testRemoveCoherencePersistenceDirMissingNameForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherencePersistenceDir", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "mycluster", + "-name", + "missing.xml", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_MY_CLUSTER, COHERENCE_MYCLUSTER_CONTENTS); + } + + @Test + void testRemoveCoherencePersistenceDirMissingClusterNameForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "coherencePersistenceDir", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-cluster_name", + "missing", + "-name", + "cache-config.xml", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_MY_CLUSTER, COHERENCE_MYCLUSTER_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // custom // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingCustomFile_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "custom", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo.properties" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM_ENTRIES, CUSTOM_CONTENT, CUSTOM_FOO_PROPERTIES_CONTENTS); + } + + @Test + void testRemoveExistingCustomNestedFile_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "custom", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "mydir/bar.properties" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM_ENTRIES, CUSTOM_CONTENT, CUSTOM_MYDIR_CONTENTS); + } + + @Test + void testRemoveExistingCustomDir_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "custom", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "mydir" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM_ENTRIES, CUSTOM_CONTENT, CUSTOM_MYDIR_CONTENTS); + } + + @Test + void testRemoveMissingCustomForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "custom", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "missing", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM_ENTRIES, CUSTOM_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // database wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingDatabaseWalletZip_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "databaseWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "wallet1" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only jar so the test will also remove wlsdeploy/classpathLibraries/ + assertArchiveInExpectedState(LIST_DATABASE_WALLETS, DATABASE_WALLETS_CONTENT, DATABASE_WALLET_WALLET1_CONTENTS); + } + + @Test + void testRemoveExistingDatabaseWalletExploded_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "databaseWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + DEFAULT_RCU_WALLET_NAME + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only jar so the test will also remove wlsdeploy/classpathLibraries/ + assertArchiveInExpectedState(LIST_DATABASE_WALLETS, DATABASE_WALLETS_CONTENT, DATABASE_WALLET_RCU_CONTENTS); + } + + @Test + void testRemoveMissingDatabaseWalletForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "databaseWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "missing", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DATABASE_WALLETS, DATABASE_WALLETS_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // $DOMAIN_HOME/bin script // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingDomainBinFile_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "domainBinScript", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "setUserOverrides.sh" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only script so the test will also remove wlsdeploy/domainBin/ + assertArchiveInExpectedState(LIST_DOMAIN_BIN_SCRIPTS, DOMAIN_BIN_CONTENT, DOMAIN_BIN_CONTENT); + } + + @Test + void testRemoveMissingDomainBinForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "domainBinScript", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "missing.sh", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DOMAIN_BIN_SCRIPTS, DOMAIN_BIN_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // domain library // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingDomainLibFile_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "domainLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo.jar" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only jar so the test will also remove wlsdeploy/domainLibraries/ + assertArchiveInExpectedState(LIST_DOMAIN_LIBRARIES, DOMAIN_LIB_CONTENT, DOMAIN_LIB_CONTENT); + } + + @Test + void testRemoveMissingDomainLibForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "domainLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "missing.jar", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DOMAIN_LIBRARIES, DOMAIN_LIB_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // file store // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingFileStore_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "fileStore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "fs2" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only script so the test will also remove wlsdeploy/config/ + assertArchiveInExpectedState(LIST_FILE_STORES, FILE_STORES_CONTENT, FILE_STORES_FS2_CONTENTS); + } + + @Test + void testRemoveMissingFileStoreForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "fileStore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "missing", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FILE_STORES, FILE_STORES_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // JMS Foreign Server binding // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveForeignServerBindingNoForeignServerName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "jmsForeignServer", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "jndi.properties" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testRemoveForeignServerBindingMissingForeignServerName_ReturnsExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "jmsForeignServer", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-foreign_server_name", + "missing", + "-name", + "jndi.properties" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual,"expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testRemoveForeignServerBindingMissingName_ReturnsExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "jmsForeignServer", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-foreign_server_name", + "fs1", + "-name", + "missing.properties" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual,"expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testRemoveExistingForeignServerBinding_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "jmsForeignServer", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-foreign_server_name", + "fs1", + "-name", + "jndi.properties" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FOREIGN_SERVERS_FS1, FOREIGN_SERVERS_FS1_CONTENTS, + FOREIGN_SERVERS_FS1_CONTENTS); + } + + @Test + void testRemoveForeignServerBindingMissingNameForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "jmsForeignServer", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-foreign_server_name", + "fs1", + "-name", + "missing.properties", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FOREIGN_SERVERS_FS1, FOREIGN_SERVERS_FS1_CONTENTS); + } + + @Test + void testRemoveForeignServerBindingMissingForeignServerNameForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "jmsForeignServer", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-foreign_server_name", + "missing", + "-name", + "jndi.properties", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FOREIGN_SERVERS_FS1, FOREIGN_SERVERS_FS1_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // MIME mapping // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingMIMEMapping_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "mimeMapping", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "mimemappings.properties" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only script so the test will also remove wlsdeploy/config/ + assertArchiveInExpectedState(LIST_MIME_MAPPINGS, MIME_MAPPINGS_CONTENT, MIME_MAPPINGS_CONTENT); + } + + @Test + void testRemoveMissingMIMEMappingForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "mimeMapping", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "missing.properties", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_MIME_MAPPINGS, MIME_MAPPINGS_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // node manager keystore // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingNodeManagerKeystoreFile_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "nodeManagerKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "nmIdentity.jks" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only jar so the test will also remove wlsdeploy/domainLibraries/ + assertArchiveInExpectedState(LIST_NODE_MANAGER_KEYSTORES, NODE_MANAGER_CONTENT, + NODE_MANAGER_IDENTITY_JKS_CONTENTS); + } + + @Test + void testRemoveMissingNodeManagerKeystoreForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "nodeManagerKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "missing.jks", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_NODE_MANAGER_KEYSTORES, NODE_MANAGER_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // OPSS wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingOPSSWallet_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "opssWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only jar so the test will also remove wlsdeploy/opsswallet/ + assertArchiveInExpectedState(LIST_OPSS_WALLET, OPSS_WALLET_CONTENT, OPSS_WALLET_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // RCU wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingRCUWallet_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "rcuWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only jar so the test will also remove wlsdeploy/opsswallet/ + assertArchiveInExpectedState(LIST_DATABASE_WALLETS, DATABASE_WALLETS_CONTENT, DATABASE_WALLET_RCU_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // script // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingScript_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "script", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my_fancy_script.sh" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + // Removing the only script so the test will also remove wlsdeploy/scripts/ + assertArchiveInExpectedState(LIST_SCRIPTS, SCRIPTS_CONTENT, SCRIPTS_CONTENT); + } + + @Test + void testRemoveMissingScriptForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "script", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "missing.sh", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SCRIPTS, SCRIPTS_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // server keystore // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveServerKeystoreNoServerName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "identity.jks" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testRemoveServerKeystoreMissingServerName_ReturnsExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-server_name", + "missing", + "-name", + "identity.jks" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual,"expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testRemoveServerKeystoreMissingName_ReturnsExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-server_name", + "AdminServer", + "-name", + "missing.jks" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual,"expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testRemoveExistingServerKeystore_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-server_name", + "AdminServer", + "-name", + "identity.jks" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SERVER_KEYSTORES_ADMIN_SERVER, SERVERS_ADMIN_SERVER_CONTENTS, + SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS); + } + + @Test + void testRemoveServerKeystoreMissingNameForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-server_name", + "AdminServer", + "-name", + "missing.jks", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SERVER_KEYSTORES_ADMIN_SERVER, SERVERS_ADMIN_SERVER_CONTENTS); + } + + @Test + void testRemoveServerKeystoreMissingServerNameForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-server_name", + "missing", + "-name", + "identity.jks", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SERVER_KEYSTORES_ADMIN_SERVER, SERVERS_ADMIN_SERVER_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // shared library // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingSharedLibFile_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-lib.war" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, SHARED_LIBS_CONTENT, SHARED_LIBS_MY_LIB_WAR_CONTENTS); + } + + @Test + void testRemoveExistingSharedLibDir_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-other-lib" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, SHARED_LIBS_CONTENT, SHARED_LIBS_MY_OTHER_LIB_CONTENTS); + } + + @Test + void testRemoveMissingSharedLibForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, SHARED_LIBS_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // shared library plan // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingSharedLibPlan_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "sharedLibraryPlan", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-lib.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, SHARED_LIBS_CONTENT, SHARED_LIBS_MY_LIB_XML_CONTENTS); + } + + @Test + void testRemoveMissingSharedLibPlanForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "sharedLibraryPlan", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo.xml", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, SHARED_LIBS_CONTENT); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // structured application // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testRemoveExistingStructuredApp_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "structuredApplication", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "webapp" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_STRUCTURED_APPLICATIONS, STRUCTURED_APPS_CONTENT, + STRUCTURED_APP_WEBAPP_CONTENTS); + } + + @Test + void testRemoveMissingStructuredAppForce_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "structuredApplication", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo", + "-force" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_STRUCTURED_APPLICATIONS, STRUCTURED_APPS_CONTENT); + } + + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Private Helper Methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + private void assertArchiveInExpectedState(String[] remainingArgs, String[] originalContent, + String[]... removedContent) throws Exception { + String[] args = new String[remainingArgs.length + 3]; + args[0] = "list"; + System.arraycopy(remainingArgs, 0, args, 1, remainingArgs.length); + args[remainingArgs.length + 1] = "-archive_file"; + args[remainingArgs.length + 2] = ARCHIVE_HELPER_VALUE; + + List remainingEntries = getRemainingEntries(args); + List expectedEntries = getExpectedEntries(originalContent, removedContent); + assertEquals(expectedEntries.size(), remainingEntries.size(), "expected zip file to contain " + + expectedEntries.size()); + for (String actualLine : remainingEntries) { + assertTrue(expectedEntries.contains(actualLine), actualLine + " not in expected output"); + } + } + + private List getRemainingEntries(String... args) throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + if (actual != ExitCode.OK) { + throw new ArchiveHelperException(actual, + "Failed to get remaining entries for args = {0}", Arrays.toString(args)); + } + } + + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + if (outputLines.length == 0 || (outputLines.length == 1 && StringUtils.isEmpty(outputLines[0]))) { + return new ArrayList<>(); + } else { + return Arrays.asList(outputLines); + } + } + + private List getExpectedEntries(String[] expected, String[]... removeLists) { + List expectedPaths = new ArrayList<>(Arrays.asList(expected)); + + for (String[] removeList : removeLists) { + for (String removeItem : removeList) { + expectedPaths.remove(removeItem); + } } + return expectedPaths; } } diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java index e176630926..72df69de3b 100644 --- a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java @@ -58,12 +58,24 @@ public class ArchiveHelperTestConstants { "wlsdeploy/coherence/mycluster/cache-config.xml" }; - static final String[] COHERENCE_MYCLUSTER_PERSISTENT_DIR_CONTENTS = new String[] { - "wlsdeploy/coherence/mycluster/active/", - "wlsdeploy/coherence/mycluster/snapshot/", + static final String[] COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS = new String[] { + "wlsdeploy/coherence/mycluster/active/" + }; + + static final String[] COHERENCE_MYCLUSTER_PERSISTENT_DIR_SNAPSHOT_CONTENTS = new String[] { + "wlsdeploy/coherence/mycluster/snapshot/" + }; + + static final String[] COHERENCE_MYCLUSTER_PERSISTENT_DIR_TRASH_CONTENTS = new String[] { "wlsdeploy/coherence/mycluster/trash/" }; + static final String[] COHERENCE_MYCLUSTER_PERSISTENT_DIR_CONTENTS = mergeStringArrays( + COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS, + COHERENCE_MYCLUSTER_PERSISTENT_DIR_SNAPSHOT_CONTENTS, + COHERENCE_MYCLUSTER_PERSISTENT_DIR_TRASH_CONTENTS + ); + static final String[] COHERENCE_MYCLUSTER_CONTENTS = mergeStringArrays( new String[] { "wlsdeploy/coherence/mycluster/" }, COHERENCE_MYCLUSTER_PERSISTENT_DIR_CONTENTS, @@ -160,6 +172,33 @@ public class ArchiveHelperTestConstants { DOMAIN_LIB_FOO_JAR_CONTENTS ); + static final String[] FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_CONTENTS = new String[] { + "wlsdeploy/jms/foreignServer/fs1/jndi.properties" + }; + + static final String[] FOREIGN_SERVERS_FS1_CONTENTS = mergeStringArrays( + new String[] { "wlsdeploy/jms/foreignServer/fs1/" }, + FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_CONTENTS + ); + + static final String[] FOREIGN_SERVERS_FS2_JNDI_PROPERTIES_CONTENTS = new String[] { + "wlsdeploy/jms/foreignServer/fs2/jndi.properties" + }; + + static final String[] FOREIGN_SERVERS_FS2_CONTENTS = mergeStringArrays( + new String[] { "wlsdeploy/jms/foreignServer/fs2/" }, + FOREIGN_SERVERS_FS2_JNDI_PROPERTIES_CONTENTS + ); + + static final String[] FOREIGN_SERVERS_CONTENT = mergeStringArrays( + new String[] { + "wlsdeploy/jms/", + "wlsdeploy/jms/foreignServer/" + }, + FOREIGN_SERVERS_FS1_CONTENTS, + FOREIGN_SERVERS_FS2_CONTENTS + ); + static final String[] NODE_MANAGER_IDENTITY_JKS_CONTENTS = new String[] { "wlsdeploy/nodeManager/nmIdentity.jks" }; @@ -207,6 +246,41 @@ public class ArchiveHelperTestConstants { SERVERS_ADMIN_SERVER_CONTENTS ); + static final String[] SHARED_LIBS_MY_OTHER_LIB_CONTENTS = new String[] { + "wlsdeploy/sharedLibraries/my-other-lib/", + "wlsdeploy/sharedLibraries/my-other-lib/META-INF/", + "wlsdeploy/sharedLibraries/my-other-lib/META-INF/maven/", + "wlsdeploy/sharedLibraries/my-other-lib/META-INF/maven/oracle.jcs.lifecycle/", + "wlsdeploy/sharedLibraries/my-other-lib/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/", + "wlsdeploy/sharedLibraries/my-other-lib/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.properties", + "wlsdeploy/sharedLibraries/my-other-lib/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.xml", + "wlsdeploy/sharedLibraries/my-other-lib/META-INF/MANIFEST.MF", + "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/", + "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/classes/", + "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/classes/com/", + "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/classes/com/oracle/", + "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/classes/com/oracle/platform/", + "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/classes/com/oracle/platform/GetListenAddressServlet.class", + "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/classes/com/oracle/platform/ListenAddressAndPort.class", + "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/web.xml", + "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/weblogic.xml" + }; + + static final String[] SHARED_LIBS_MY_LIB_WAR_CONTENTS = new String[] { + "wlsdeploy/sharedLibraries/my-lib.war" + }; + + static final String[] SHARED_LIBS_MY_LIB_XML_CONTENTS = new String[] { + "wlsdeploy/sharedLibraries/my-lib.xml" + }; + + static final String[] SHARED_LIBS_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/sharedLibraries/" }, + SHARED_LIBS_MY_OTHER_LIB_CONTENTS, + SHARED_LIBS_MY_LIB_WAR_CONTENTS, + SHARED_LIBS_MY_LIB_XML_CONTENTS + ); + static final String[] FILE_STORES_FS1_CONTENTS = new String[] { "wlsdeploy/stores/fs1/" }; @@ -272,6 +346,25 @@ public class ArchiveHelperTestConstants { STRUCTURED_APP_WEBAPP1_CONTENTS ); + static final String[] ALL_CONTENT = mergeStringArrays( + APPLICATIONS_CONTENT, + CLASSPATH_LIBS_CONTENT, + COHERENCE_CONTENT, + CUSTOM_CONTENT, + DATABASE_WALLETS_CONTENT, + DOMAIN_BIN_CONTENT, + DOMAIN_LIB_CONTENT, + FILE_STORES_CONTENT, + FOREIGN_SERVERS_CONTENT, + MIME_MAPPINGS_CONTENT, + NODE_MANAGER_CONTENT, + OPSS_WALLET_CONTENT, + SCRIPTS_CONTENT, + SERVERS_CONTENT, + SHARED_LIBS_CONTENT, + STRUCTURED_APPS_CONTENT + ); + static String[] mergeStringArrays(String[]... arrays) { int totalSize = 0; for (String[] array : arrays) { diff --git a/core/src/test/resources/archive-helper-test.zip b/core/src/test/resources/archive-helper-test.zip index 0bf35f2815f2932a1a619cdf24505508fd7c067b..490e77953e92eedfdf8fc94ca699bec79f1584bc 100644 GIT binary patch delta 4768 zcmbW5ZA?>F7{|}kOIzNoB;wR^WjcrA3k5+aLqLnX3`?P`hzh8bQUnIV3PW8qS!0YF zZc*0E6Si!@%`e+D(bcWVvbZc+oG>&l+p>L|ESvjaj9C`r7PFVg9%0>bgOU1zF*2KUHtKQHue9g0GI51V37Ob?U8g##m z23krojdb*yXXg(Sfss|_KvPLd@RO306GDR{kB%Bar2FC_*?6yg+=GqX5_&BjcIX7L zHII%MAdUW)2%>S<@o^6})-SZw=Fu%lP-?u@G48>}FS_yK*(4}4-o}f+^NZ_3smbsu z2oJIA`T}^)n9w=y!N%`@fEQ0>LE)JcSeCq_A%O@w?8Sz?>p~MIxUxVfugjw+Mc86I zja?(1`Mh|OG)Ka}4X z|4sLYUz-R?O(o>%IY;*%&g$uEvmA8$xXRmglOEPCy>rV{UW}yRh2leR=?F0=sw5ri z?ct<9k%BFFW#MI=;2z4S_5=_!qqO7G`vyC`KBhsMNP%8z zQPE(_s;;e^f$nv(>NGRv&((jI_hNmIW83@~Ooy$uy0XI6U~yFPsWQ!ls5$i1iNsVpZS3 z)~|_H9C#*Uk&)r7sLqw~KIeJwW!||1gnS%FNS8)l*XrajFL-3NUNRxBNHJ$F6Yi`i zi}B5@#j>iF6G&hC1XuE?x~umf{i6sL&;KIJRBK~Eaekl%t07QnwXionTKvT^wv%kt z6VjhnLtdY>!&J`Py0tlqz9NRM z1au5cA8vbRAOb?z!I!o%_JQpF?gQ;zmVRGfzt=a2#~0r~*>G%3?pC*E4Y|@pI%FCU z@@NgYvua?&u~C0MY@jLIz!a*>g~22YFLYuX29T)|SgvasrceaSL(5BHO&kUn>bGH6 zTN#*jbX4kky9_QQ^4wx~K!Jd9g?8U-CLerb!77r)T0xkg)34Or@g`ra|@VcHl?T{#7{Gd0hA#HU=F3g!b^hChSLH)Zy ztc^__OVRGq=bZoWoFsV$K_=!8i5Z(eBqpvQGUk8RHkZ0-CSQ=q#3aINP#=AWt|4Ka zDdev0O!+*_nS`;U0kOEwIkqVpo1?%!P>+=bmuWsL@3V}rj4d;zIOlg)sFh9cYyxvc zc5Afk0)^~tm1?os5!vDFA}bCTANB(Kwkw_zRQ(hlW8xKsk72hd*o9SUXTaDtUYJO| zm0?C+@9#BXS+q$pM88dCw2{+|)mlUsFYNE@l@1cw?TV0d{@*mQtCaRu<|jE8&z(8;efe)TR%(`}M7h2BuA&T6a(iEB zR7;Q8F%qq!7m+en$)8fcOYKuAhO8xF{p_eNj15`g>aa7yw_8q@A{Xky$iO3Yh| zh$bqm_F2qmWu)RO4>K8OZI2CPawREE(MpsoDW0J=%vPMovl;FROSUlgbgLL1lh$Ok z?Xgi!uI{^e@hrF@kEJeFcY&ogrq0XMWi`(?xmj|YMDx6OD2YJaeas1Q_zw``wCfG* Q+&PAS_lpTRgJ?qj2iv}>V*mgE delta 515 zcmY+9OGq106o&JUW~!4hPB9^xL?ei(^${ju27*cB!kxHKq?EKsbrGs&A&TN78;QE` zMYxh92*EB~iNRFxZba}=3R!p6l`dRmEeM6SHxq^S-p&2LbN~OG^Cd5z-dazef))Fd zI?G2q?7~o3vtgBLA6YWga27S(GCK-uY%=VYes@s5627ye@Ie8+M6b|9V^vV$WcfZf ziyAWDs=}zmauJQPGVJt6fj1rUlu9NXv_Y4mZ_F4IPx^w!*MjCmfahU%mfs^6GvMmsngKt+Z5Vqcp5$~bCA_8jkN+?)9WRMV|6>|| zy^JZ8En6!Xp~N`+WKZH96~&A1C9(3H*qlO?<`VE_Hbmpy6zafZdaXyRt=(ku}0}$#jlkcEj From dbc26ce6ad7feae0ae5a735c1e9436cf24f8dbb2 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Mon, 23 Jan 2023 14:48:49 -0600 Subject: [PATCH 07/13] remove first pass --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 0c286d5b2c..19a2005762 100644 --- a/pom.xml +++ b/pom.xml @@ -113,6 +113,11 @@ picocli ${picocli.version} + + org.junit.jupiter + junit-jupiter-params + 5.9.2 + From d80277182869f48bd63a52d33f131dc8001c623b Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Thu, 26 Jan 2023 17:33:30 -0600 Subject: [PATCH 08/13] completing archiveHelper Java code --- .../weblogic/deploy/tool/ArchiveHelper.java | 3 + .../tool/archive_helper/CommonOptions.java | 14 +- .../add/AddApplicationCommand.java | 1 + .../add/AddDomainBinScriptCommand.java | 6 +- .../add/AddDomainLibraryCommand.java | 6 +- .../add/AddRCUWalletCommand.java | 14 +- .../extract/ExtractAllCommand.java | 64 + .../extract/ExtractApplicationCommand.java | 75 + .../ExtractApplicationPlanCommand.java | 72 + .../ExtractClasspathLibraryCommand.java | 72 + .../ExtractCoherenceConfigCommand.java | 79 + ...ExtractCoherencePersistenceDirCommand.java | 79 + .../extract/ExtractCommand.java | 47 + .../extract/ExtractCustomCommand.java | 72 + .../extract/ExtractDatabaseWalletCommand.java | 72 + .../ExtractDomainBinScriptCommand.java | 72 + .../extract/ExtractDomainLibraryCommand.java | 72 + .../extract/ExtractFileStoreCommand.java | 72 + .../ExtractJMSForeignServerCommand.java | 79 + .../extract/ExtractMIMEMappingCommand.java | 72 + .../ExtractNodeManagerKeystoreCommand.java | 72 + .../extract/ExtractOPSSWalletCommand.java | 66 + .../extract/ExtractOptions.java | 66 + .../extract/ExtractRCUWalletCommand.java | 66 + .../extract/ExtractScriptCommand.java | 72 + .../extract/ExtractServerKeystoreCommand.java | 79 + .../extract/ExtractSharedLibraryCommand.java | 72 + .../ExtractSharedLibraryPlanCommand.java | 72 + .../ExtractStructuredApplicationCommand.java | 72 + .../extract/ExtractTypeCommandBase.java | 12 + .../list/ListCustomCommand.java | 2 +- .../list/ListDomainBinScriptCommand.java | 6 +- .../list/ListDomainLibraryCommand.java | 6 +- .../list/ListRCUWalletCommand.java | 5 +- .../remove/RemoveApplicationCommand.java | 4 +- .../remove/RemoveApplicationPlanCommand.java | 4 +- .../remove/RemoveClasspathLibraryCommand.java | 4 +- .../remove/RemoveCoherenceConfigCommand.java | 4 +- .../RemoveCoherencePersistenceDirCommand.java | 4 +- .../remove/RemoveCustomCommand.java | 4 +- .../remove/RemoveDatabaseWalletCommand.java | 4 +- .../remove/RemoveDomainBinScriptCommand.java | 4 +- .../remove/RemoveDomainLibraryCommand.java | 14 +- .../remove/RemoveFileStoreCommand.java | 4 +- .../remove/RemoveJMSForeignServerCommand.java | 4 +- .../remove/RemoveMIMEMappingCommand.java | 4 +- .../RemoveNodeManagerKeystoreCommand.java | 4 +- .../remove/RemoveOPSSWalletCommand.java | 5 +- .../remove/RemoveRCUWalletCommand.java | 23 +- .../remove/RemoveScriptCommand.java | 4 +- .../remove/RemoveServerKeystoreCommand.java | 4 +- .../remove/RemoveSharedLibraryCommand.java | 4 +- .../RemoveSharedLibraryPlanCommand.java | 4 +- .../RemoveStructuredApplicationCommand.java | 4 +- .../deploy/util/WLSDeployArchive.java | 894 +++++- .../deploy/util/WLSDeployZipFile.java | 109 +- .../deploy/messages/wlsdeploy_rb.properties | 23 + .../deploy/tool/ArchiveHelperAddTest.java | 2834 +++++++++++++++++ .../deploy/tool/ArchiveHelperExtractTest.java | 1362 ++++++++ .../deploy/tool/ArchiveHelperListTest.java | 406 ++- .../deploy/tool/ArchiveHelperRemoveTest.java | 29 +- .../tool/ArchiveHelperTestConstants.java | 153 +- .../deploy/yaml/YamlTranslatorTest.java | 1 - .../test/resources/archive-helper-test.zip | Bin 104609 -> 105015 bytes 64 files changed, 7265 insertions(+), 367 deletions(-) create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractAllCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractApplicationCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractApplicationPlanCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractClasspathLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCoherenceConfigCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCoherencePersistenceDirCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCustomCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDatabaseWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDomainBinScriptCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDomainLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractFileStoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractJMSForeignServerCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractMIMEMappingCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractNodeManagerKeystoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractOPSSWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractOptions.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractRCUWalletCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractScriptCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractServerKeystoreCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractSharedLibraryCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractSharedLibraryPlanCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractStructuredApplicationCommand.java create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractTypeCommandBase.java create mode 100644 core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperAddTest.java create mode 100644 core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperExtractTest.java diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java index 491279cfe5..397f1609d5 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java @@ -11,9 +11,11 @@ import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; import oracle.weblogic.deploy.tool.archive_helper.add.AddCommand; +import oracle.weblogic.deploy.tool.archive_helper.extract.ExtractCommand; import oracle.weblogic.deploy.tool.archive_helper.list.ListCommand; import oracle.weblogic.deploy.tool.archive_helper.remove.RemoveCommand; import oracle.weblogic.deploy.util.ExitCode; + import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.IParameterExceptionHandler; @@ -28,6 +30,7 @@ commandListHeading = "%nCommands:%n", subcommands = { AddCommand.class, + ExtractCommand.class, ListCommand.class, RemoveCommand.class }, diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java index 62903f6b20..e3674f8d60 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommonOptions.java @@ -61,14 +61,14 @@ private WLSDeployArchive createArchive(boolean fileMustExist) throws ArchiveHelp } File fullArchiveFile = new File(fullArchiveFileName); - if (!fullArchiveFile.isFile()) { - ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30001", - fullArchiveFile.getAbsolutePath()); - LOGGER.throwing(CLASS, METHOD, ex); - throw ex; - } - if (fileMustExist) { + if (!fullArchiveFile.isFile()) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30001", + fullArchiveFile.getAbsolutePath()); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + if (!fullArchiveFile.exists()) { ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30002", fullArchiveFile.getAbsolutePath()); diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java index b38e120eb0..1a6cc9e765 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddApplicationCommand.java @@ -13,6 +13,7 @@ import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; import oracle.weblogic.deploy.util.ExitCode; import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; + import picocli.CommandLine.Command; import picocli.CommandLine.Option; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java index 4208860709..3f5e2f7156 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainBinScriptCommand.java @@ -19,19 +19,19 @@ @Command( name = "domainBinScript", - header = "Add domain bin script to the archive file.", + header = "Add $DOMAIN_HOME/bin script to the archive file.", description = "%nCommand-line options:", sortOptions = false ) public class AddDomainBinScriptCommand extends AddTypeCommandBase { private static final String CLASS = AddDomainBinScriptCommand.class.getName(); private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); - private static final String TYPE = "domain bin script"; + private static final String TYPE = "$DOMAIN_HOME/bin script"; @Option( names = {"-source"}, paramLabel = "", - description = "File system path to the domain bin script to add", + description = "File system path to the $DOMAIN_HOME/bin script to add", required = true ) private String sourcePath; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java index 2ff1adb0bd..d401c56fcc 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddDomainLibraryCommand.java @@ -19,19 +19,19 @@ @Command( name = "domainLibrary", - header = "Add domain library to the archive file.", + header = "Add $DOMAIN_HOME/lib library to the archive file.", description = "%nCommand-line options:", sortOptions = false ) public class AddDomainLibraryCommand extends AddTypeCommandBase { private static final String CLASS = AddDomainLibraryCommand.class.getName(); private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); - private static final String TYPE = "domain library"; + private static final String TYPE = "$DOMAIN_HOME/lib library"; @Option( names = {"-source"}, paramLabel = "", - description = "File system path to the domain library to add", + description = "File system path to the $DOMAIN_HOME/lib library to add", required = true ) private String sourcePath; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java index ac253a9e0b..602831d909 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java @@ -16,7 +16,6 @@ import picocli.CommandLine.Option; import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; -import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; @Command( name = "rcuWallet", @@ -56,20 +55,19 @@ public CommandResponse call() throws Exception { String resultName; if (this.overwrite) { - resultName = this.archive.replaceDatabaseWallet(DEFAULT_RCU_WALLET_NAME, sourceFile.getPath()); + resultName = this.archive.replaceRCUDatabaseWallet(sourceFile.getPath()); } else { - resultName = this.archive.addDatabaseWallet(DEFAULT_RCU_WALLET_NAME, sourceFile.getPath()); + resultName = this.archive.addRCUDatabaseWallet(sourceFile.getPath()); } response = new CommandResponse(ExitCode.OK, resultName); } catch (ArchiveHelperException ex) { - LOGGER.severe("WLSDPLY-30022", ex, TYPE, DEFAULT_RCU_WALLET_NAME, this.sourcePath, - this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30022", TYPE, DEFAULT_RCU_WALLET_NAME, + LOGGER.severe("WLSDPLY-30058", ex, this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30058", this.sourcePath, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { - LOGGER.severe("WLSDPLY-30023", ex, TYPE, DEFAULT_RCU_WALLET_NAME, this.sourcePath, + LOGGER.severe("WLSDPLY-30059", ex, this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30023", TYPE, DEFAULT_RCU_WALLET_NAME, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30059", this.sourcePath, this.overwrite, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractAllCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractAllCommand.java new file mode 100644 index 0000000000..c72acb52d3 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractAllCommand.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "all", + header = "Extract the contents of the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractAllCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractAllCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String ERROR_KEY = "WLSDPLY-30057"; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract all subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractAll(this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30056", + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractApplicationCommand.java new file mode 100644 index 0000000000..83f8bdbc58 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractApplicationCommand.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; + +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "application", + header = "Extract application from the archive file.", + description = "%nCommand-line options:", + footer = "%nNote: If using an Application Installation Directory, " + + "please see the archiveHelper extract structuredApplication command.%n", + sortOptions = false +) +public class ExtractApplicationCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractApplicationCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "application"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the application to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract application subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractApplication(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractApplicationPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractApplicationPlanCommand.java new file mode 100644 index 0000000000..1abb059f20 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractApplicationPlanCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "applicationPlan", + header = "Extract application deployment plan from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractApplicationPlanCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractApplicationPlanCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "application deployment plan"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the application deployment plan to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract applicationPlan subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractApplicationPlan(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractClasspathLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractClasspathLibraryCommand.java new file mode 100644 index 0000000000..126da1fd8f --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractClasspathLibraryCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "classpathLibrary", + header = "Extract classpath library from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractClasspathLibraryCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractClasspathLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "classpath library"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the classpath library to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract classpathLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractClasspathLibrary(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCoherenceConfigCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCoherenceConfigCommand.java new file mode 100644 index 0000000000..628f024392 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCoherenceConfigCommand.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "coherenceConfig", + header = "Extract Coherence config file from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractCoherenceConfigCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractCoherenceConfigCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "Coherence config"; + private static final String ERROR_KEY = "WLSDPLY-30049"; + + @Option( + names = {"-cluster_name"}, + description = "Name of the Coherence cluster used to segregate the config files in the archive file", + required = true + ) + private String clusterName; + + @Option( + names = {"-name"}, + description = "Name of the Coherence config file to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract coherenceConfig subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractCoherenceConfigFile(this.clusterName, this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30048", TYPE, this.name, + this.clusterName, this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.clusterName, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, this.clusterName, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.clusterName, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, this.clusterName, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCoherencePersistenceDirCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCoherencePersistenceDirCommand.java new file mode 100644 index 0000000000..a01ec9ae73 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCoherencePersistenceDirCommand.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "coherencePersistenceDir", + header = "Extract Coherence persistence directory from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractCoherencePersistenceDirCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractCoherencePersistenceDirCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "Coherence persistence directory"; + private static final String ERROR_KEY = "WLSDPLY-30049"; + + @Option( + names = {"-cluster_name"}, + description = "Name of the Coherence cluster used to segregate the persistence directories in the archive file", + required = true + ) + private String clusterName; + + @Option( + names = {"-name"}, + description = "Name of the Coherence persistence directory to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract coherencePersistenceDir subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractCoherencePersistenceDirectory(this.clusterName, this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30048", TYPE, this.name, this.clusterName, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.clusterName, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, this.clusterName, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.clusterName, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, this.clusterName, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCommand.java new file mode 100644 index 0000000000..7db45b3a45 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCommand.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +@Command( + name = "extract", + header = "Extract items from the archive file.", + description = "%nCommand-line options:", + commandListHeading = "%nSubcommands:%n", + subcommands = { + ExtractAllCommand.class, + ExtractApplicationCommand.class, + ExtractApplicationPlanCommand.class, + ExtractClasspathLibraryCommand.class, + ExtractCoherenceConfigCommand.class, + ExtractCoherencePersistenceDirCommand.class, + ExtractCustomCommand.class, + ExtractDatabaseWalletCommand.class, + ExtractDomainBinScriptCommand.class, + ExtractDomainLibraryCommand.class, + ExtractFileStoreCommand.class, + ExtractJMSForeignServerCommand.class, + ExtractMIMEMappingCommand.class, + ExtractNodeManagerKeystoreCommand.class, + ExtractOPSSWalletCommand.class, + ExtractRCUWalletCommand.class, + ExtractScriptCommand.class, + ExtractServerKeystoreCommand.class, + ExtractSharedLibraryCommand.class, + ExtractSharedLibraryPlanCommand.class, + ExtractStructuredApplicationCommand.class + }, + sortOptions = false +) +public class ExtractCommand { + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract command", + usageHelp = true + ) + private boolean helpRequested = false; +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCustomCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCustomCommand.java new file mode 100644 index 0000000000..a6681c4212 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractCustomCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "custom", + header = "Extract custom file/directory from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractCustomCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractCustomCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "custom file or directory"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the custom file/directory to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract custom subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractCustomEntry(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDatabaseWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDatabaseWalletCommand.java new file mode 100644 index 0000000000..d3f22c5b0c --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDatabaseWalletCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "databaseWallet", + header = "Extract database wallet from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractDatabaseWalletCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractDatabaseWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "database wallet"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the database wallet to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract databaseWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractDatabaseWalletForArchiveHelper(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDomainBinScriptCommand.java new file mode 100644 index 0000000000..5d7b2ef594 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDomainBinScriptCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "domainBinScript", + header = "Extract $DOMAIN_HOME/bin script from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractDomainBinScriptCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractDomainBinScriptCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "$DOMAIN_HOME/bin script"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the $DOMAIN_HOME/bin script to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract domainBinScript subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractDomainBinScript(this.name, this.targetDirectory, true); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDomainLibraryCommand.java new file mode 100644 index 0000000000..6cf44cb625 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractDomainLibraryCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "domainLibrary", + header = "Extract $DOMAIN_HOME/lib library from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractDomainLibraryCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractDomainLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "$DOMAIN_HOME/lib library"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the $DOMAIN_HOME/lib library to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract domainLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractDomainLibLibrary(this.name, this.targetDirectory, true); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractFileStoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractFileStoreCommand.java new file mode 100644 index 0000000000..acc0b81087 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractFileStoreCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "fileStore", + header = "Extract File Store directory from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractFileStoreCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractFileStoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "File Store directory"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the File Store directory to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract fileStore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractFileStoreDirectory(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractJMSForeignServerCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractJMSForeignServerCommand.java new file mode 100644 index 0000000000..8119721cbb --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractJMSForeignServerCommand.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "jmsForeignServer", + header = "Extract JMS Foreign Server binding file from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractJMSForeignServerCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractJMSForeignServerCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "JMS Foreign Server binding file"; + private static final String ERROR_KEY = "WLSDPLY-30051"; + + @Option( + names = {"-foreign_server_name"}, + description = "Name of the JMS Foreign Server used to segregate the config files in the archive file", + required = true + ) + private String foreignServerName; + + @Option( + names = {"-name"}, + description = "Name of the JMS Foreign Server binding file to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract jmsForeignServer subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractForeignServerFile(this.foreignServerName, this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30050", TYPE, this.name, + this.foreignServerName, this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.foreignServerName, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, this.foreignServerName, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.foreignServerName, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, this.foreignServerName, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractMIMEMappingCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractMIMEMappingCommand.java new file mode 100644 index 0000000000..9f15c0745d --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractMIMEMappingCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "mimeMapping", + header = "Extract MIME mapping file from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractMIMEMappingCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractMIMEMappingCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "MIME mapping file"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the MIME mapping file to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract mimeMapping subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractMimeMappingFile(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractNodeManagerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractNodeManagerKeystoreCommand.java new file mode 100644 index 0000000000..01704a0f75 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractNodeManagerKeystoreCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "nodeManagerKeystore", + header = "Extract node manager keystore from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractNodeManagerKeystoreCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractNodeManagerKeystoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "node manager keystore"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the node manager keystore to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract nodeManagerKeystore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractNodeManagerKeystore(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractOPSSWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractOPSSWalletCommand.java new file mode 100644 index 0000000000..f1531e64c0 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractOPSSWalletCommand.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "opssWallet", + header = "Extract OPSS database wallet from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractOPSSWalletCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractOPSSWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String SUBCOMMAND = "opssWallet"; + private static final String WALLET_TYPE = "OPSS"; + private static final String ERROR_KEY = "WLSDPLY-30055"; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract opssWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractOPSSWalletForArchiveHelper(this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30054", SUBCOMMAND, WALLET_TYPE, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, WALLET_TYPE, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, WALLET_TYPE, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, WALLET_TYPE, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, WALLET_TYPE, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractOptions.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractOptions.java new file mode 100644 index 0000000000..c01ebf137b --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractOptions.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import java.io.File; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommonOptions; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.FileUtils; +import oracle.weblogic.deploy.util.StringUtils; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +public abstract class ExtractOptions extends CommonOptions { + private static final String CLASS = ExtractOptions.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + @Option( + names = {"-target"}, + description = "The target directory to which to extract the items from the archive", + required = true + ) + protected String targetDirectoryPath; + protected File targetDirectory; + + protected void initializeOptions() throws ArchiveHelperException { + super.initializeOptions(true); + + this.targetDirectory = createTargetDirectory(); + } + + private File createTargetDirectory() throws ArchiveHelperException { + final String METHOD = "createTargetDirectory"; + LOGGER.entering(CLASS, METHOD); + + String fullTargetDirectoryName = FileUtils.getCanonicalPath(this.targetDirectoryPath); + if (StringUtils.isEmpty(fullTargetDirectoryName)) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.USAGE_ERROR, "WLSDPLY-30043"); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + File targetDirectoryFile = new File(fullTargetDirectoryName); + if (!targetDirectoryFile.isDirectory()) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30044", + targetDirectoryFile.getAbsolutePath()); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + if (!targetDirectoryFile.exists() && !targetDirectoryFile.mkdirs()) { + ArchiveHelperException ex = new ArchiveHelperException(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-30045", + targetDirectoryFile.getAbsolutePath()); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + + LOGGER.exiting(CLASS, METHOD, targetDirectoryFile); + return targetDirectoryFile; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractRCUWalletCommand.java new file mode 100644 index 0000000000..3a44e9fe6a --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractRCUWalletCommand.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "rcuWallet", + header = "Extract RCU database wallet from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractRCUWalletCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractRCUWalletCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String SUBCOMMAND = "rcuWallet"; + private static final String WALLET_TYPE = "RCU"; + private static final String ERROR_KEY = "WLSDPLY-30055"; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract rcuWallet subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractRCUDatabaseWalletForArchiveHelper(this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30054", SUBCOMMAND, WALLET_TYPE, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, WALLET_TYPE, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, WALLET_TYPE, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, WALLET_TYPE, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, WALLET_TYPE, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractScriptCommand.java new file mode 100644 index 0000000000..904f7730d3 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractScriptCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "script", + header = "Extract script from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractScriptCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractScriptCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "script"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the script to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract script subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractScript(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractServerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractServerKeystoreCommand.java new file mode 100644 index 0000000000..a22e5a43c2 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractServerKeystoreCommand.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "serverKeystore", + header = "Extract server keystore from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractServerKeystoreCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractServerKeystoreCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "server keystore"; + private static final String ERROR_KEY = "WLSDPLY-30053"; + + @Option( + names = {"-server_name"}, + description = "Name of the server used to segregate the keystores in the archive file", + required = true + ) + private String serverName; + + @Option( + names = {"-name"}, + description = "Name of the server keystore to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract serverKeystore subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractServerKeystore(this.serverName, this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30052", TYPE, this.name, this.serverName, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.serverName, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, this.serverName, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.serverName, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, this.serverName, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractSharedLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractSharedLibraryCommand.java new file mode 100644 index 0000000000..87023fa4cc --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractSharedLibraryCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "sharedLibrary", + header = "Extract shared library from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractSharedLibraryCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractSharedLibraryCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "shared library"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the shared library to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract sharedLibrary subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractSharedLibrary(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractSharedLibraryPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractSharedLibraryPlanCommand.java new file mode 100644 index 0000000000..9c0a789951 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractSharedLibraryPlanCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "sharedLibraryPlan", + header = "Extract shared library deployment plan from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractSharedLibraryPlanCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractSharedLibraryPlanCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "shared library deployment plan"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the shared library deployment plan to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract sharedLibraryPlan subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractSharedLibraryPlan(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractStructuredApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractStructuredApplicationCommand.java new file mode 100644 index 0000000000..84c9e38264 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractStructuredApplicationCommand.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.WLSDeployArchiveIOException; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; + +@Command( + name = "structuredApplication", + header = "Extract structured application installation directory from the archive file.", + description = "%nCommand-line options:", + sortOptions = false +) +public class ExtractStructuredApplicationCommand extends ExtractTypeCommandBase { + private static final String CLASS = ExtractStructuredApplicationCommand.class.getName(); + private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); + private static final String TYPE = "structured application"; + private static final String ERROR_KEY = "WLSDPLY-30047"; + + @Option( + names = {"-name"}, + description = "Name of the structured application installation directory to be extracted from the archive file", + required = true + ) + private String name; + + @Option( + names = { "-help" }, + description = "Get help for the archiveHelper extract structuredApplication subcommand", + usageHelp = true + ) + private boolean helpRequested = false; + + + @Override + public CommandResponse call() throws Exception { + final String METHOD = "call"; + LOGGER.entering(CLASS, METHOD); + + CommandResponse response; + try { + initializeOptions(); + + this.archive.extractStructuredApplication(this.name, this.targetDirectory); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30046", TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath()); + } catch (ArchiveHelperException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { + LOGGER.severe(ERROR_KEY, ex, TYPE, this.name, this.archiveFilePath, + this.targetDirectory.getPath(), ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, ERROR_KEY, TYPE, this.name, + this.archiveFilePath, this.targetDirectory.getPath(), ex.getLocalizedMessage()); + } + + LOGGER.exiting(CLASS, METHOD, response); + return response; + } +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractTypeCommandBase.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractTypeCommandBase.java new file mode 100644 index 0000000000..2131a66e9e --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractTypeCommandBase.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper.extract; + +import java.util.concurrent.Callable; + +import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; + +public abstract class ExtractTypeCommandBase extends ExtractOptions implements Callable { +} diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java index 7840694d82..35e8c3e242 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListCustomCommand.java @@ -42,7 +42,7 @@ public CommandResponse call() throws Exception { final String METHOD = "call"; LOGGER.entering(CLASS, METHOD); - CommandResponse response = listType(CUSTOM, "custom directory", name); + CommandResponse response = listType(CUSTOM, "custom file or directory", name); LOGGER.exiting(CLASS, METHOD, response); return response; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java index c204fa12e9..edf387c625 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainBinScriptCommand.java @@ -15,7 +15,7 @@ @Command( name = "domainBinScript", - header = "List domain bin script entries in the archive file.", + header = "List $DOMAIN_HOME/bin script entries in the archive file.", description = "%nCommand-line options:", sortOptions = false ) @@ -26,7 +26,7 @@ public class ListDomainBinScriptCommand extends ListTypeCommandBase { @Option( names = { "-name" }, paramLabel = "", - description = "Name of the domain bin script to list" + description = "Name of the $DOMAIN_HOME/bin script to list" ) private String name; @@ -42,7 +42,7 @@ public CommandResponse call() throws Exception { final String METHOD = "call"; LOGGER.entering(CLASS, METHOD); - CommandResponse response = listType(DOMAIN_BIN, "domain bin script", name); + CommandResponse response = listType(DOMAIN_BIN, "$DOMAIN_HOME/bin script", name); LOGGER.exiting(CLASS, METHOD, response); return response; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java index e7d6dc67df..5dc050aa58 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListDomainLibraryCommand.java @@ -15,7 +15,7 @@ @Command( name = "domainLibrary", - header = "List domain library entries in the archive file.", + header = "List $DOMAIN_HOME/lib library entries in the archive file.", description = "%nCommand-line options:", sortOptions = false ) @@ -26,7 +26,7 @@ public class ListDomainLibraryCommand extends ListTypeCommandBase { @Option( names = { "-name" }, paramLabel = "", - description = "Name of the domain library to list" + description = "Name of the $DOMAIN_HOME/lib library to list" ) private String name; @@ -42,7 +42,7 @@ public CommandResponse call() throws Exception { final String METHOD = "call"; LOGGER.entering(CLASS, METHOD); - CommandResponse response = listType(DOMAIN_LIB, "domain library", name); + CommandResponse response = listType(DOMAIN_LIB, "$DOMAIN_HOME/lib library", name); LOGGER.exiting(CLASS, METHOD, response); return response; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java index 8f67e3a43a..0917a0ce6d 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListRCUWalletCommand.java @@ -11,8 +11,7 @@ import picocli.CommandLine.Option; import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; -import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; -import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.DB_WALLET; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType.RCU_WALLET; @Command( name = "rcuWallet", @@ -36,7 +35,7 @@ public CommandResponse call() throws Exception { final String METHOD = "call"; LOGGER.entering(CLASS, METHOD); - CommandResponse response = listType(DB_WALLET, "database wallet", DEFAULT_RCU_WALLET_NAME); + CommandResponse response = listType(RCU_WALLET, "RCU database wallet", null); LOGGER.exiting(CLASS, METHOD, response); return response; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java index 5d4b498cd4..8db2e937ff 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java @@ -64,12 +64,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationPlanCommand.java index 1c79545f52..6c92828952 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationPlanCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationPlanCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveClasspathLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveClasspathLibraryCommand.java index ab80918815..da91f4f3ff 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveClasspathLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveClasspathLibraryCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherenceConfigCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherenceConfigCommand.java index e24faa8476..7f83421e9e 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherenceConfigCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherenceConfigCommand.java @@ -67,12 +67,12 @@ public CommandResponse call() throws Exception { } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30033", ex, this.clusterName, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30033", ex, this.clusterName, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30033", this.clusterName, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30034", ex, this.clusterName, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30034", ex, this.clusterName, this.name, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30034", this.clusterName, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherencePersistenceDirCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherencePersistenceDirCommand.java index 685ab069a9..862e289471 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherencePersistenceDirCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCoherencePersistenceDirCommand.java @@ -67,12 +67,12 @@ public CommandResponse call() throws Exception { } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30035", ex, this.clusterName, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30035", ex, this.clusterName, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30035", this.clusterName, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30036", ex, this.clusterName, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30036", ex, this.clusterName, this.name, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30036", this.clusterName, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCustomCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCustomCommand.java index 1b96295b2c..ef2ed4f548 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCustomCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveCustomCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDatabaseWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDatabaseWalletCommand.java index 4eca129d4b..5a01441110 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDatabaseWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDatabaseWalletCommand.java @@ -60,12 +60,12 @@ public CommandResponse call() throws Exception { } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainBinScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainBinScriptCommand.java index 08ef453b90..b9902c5295 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainBinScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainBinScriptCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainLibraryCommand.java index 49a14cb494..4f701c4f27 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveDomainLibraryCommand.java @@ -17,18 +17,18 @@ @Command( name = "domainLibrary", - header = "Remove domain library from the archive file.", + header = "Remove $DOMAIN_HOME/lib library from the archive file.", description = "%nCommand-line options:", sortOptions = false ) public class RemoveDomainLibraryCommand extends RemoveTypeCommandBase { private static final String CLASS = RemoveDomainLibraryCommand.class.getName(); private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); - private static final String TYPE = "domain library"; + private static final String TYPE = "$DOMAIN_HOME/lib library"; @Option( names = {"-name"}, - description = "Name of the domain library to be removed from the archive file", + description = "Name of the $DOMAIN_HOME/lib library to be removed from the archive file", required = true ) private String name; @@ -51,20 +51,20 @@ public CommandResponse call() throws Exception { int entriesRemoved; if (this.force) { - entriesRemoved = this.archive.removeDomainLibrary(name, true); + entriesRemoved = this.archive.removeDomainLibLibrary(name, true); } else { - entriesRemoved = this.archive.removeDomainLibrary(name); + entriesRemoved = this.archive.removeDomainLibLibrary(name); } response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, this.name, entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveFileStoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveFileStoreCommand.java index bee0e8eeeb..164512f2cc 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveFileStoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveFileStoreCommand.java @@ -60,12 +60,12 @@ public CommandResponse call() throws Exception { } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveJMSForeignServerCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveJMSForeignServerCommand.java index c632a7391a..6064f4596f 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveJMSForeignServerCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveJMSForeignServerCommand.java @@ -67,12 +67,12 @@ public CommandResponse call() throws Exception { } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30038", ex, this.foreignServerName, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30038", ex, this.foreignServerName, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30038", this.foreignServerName, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30039", ex, this.foreignServerName, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30039", ex, this.foreignServerName, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30039", this.foreignServerName, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveMIMEMappingCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveMIMEMappingCommand.java index 20a704a014..4205268bf0 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveMIMEMappingCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveMIMEMappingCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveNodeManagerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveNodeManagerKeystoreCommand.java index 1c2b589213..d20c307196 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveNodeManagerKeystoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveNodeManagerKeystoreCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOPSSWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOPSSWalletCommand.java index c53770ce51..80e1bbfdea 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOPSSWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveOPSSWalletCommand.java @@ -14,7 +14,6 @@ import picocli.CommandLine.Option; import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; -import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; @Command( name = "opssWallet", @@ -53,11 +52,11 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30041", ex, TYPE, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30041", ex, TYPE, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30041", TYPE, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30042", ex, TYPE, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30042", ex, TYPE, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30042", TYPE, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveRCUWalletCommand.java index e2ad045be1..614950982d 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveRCUWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveRCUWalletCommand.java @@ -14,7 +14,6 @@ import picocli.CommandLine.Option; import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; -import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; @Command( name = "rcuWallet", @@ -25,11 +24,10 @@ public class RemoveRCUWalletCommand extends RemoveTypeCommandBase { private static final String CLASS = RemoveRCUWalletCommand.class.getName(); private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); - private static final String TYPE = "database wallet"; @Option( names = { "-help" }, - description = "Get help for the archiveHelper remove databaseWallet subcommand", + description = "Get help for the archiveHelper remove rcuWallet subcommand", usageHelp = true ) private boolean helpRequested = false; @@ -45,21 +43,18 @@ public CommandResponse call() throws Exception { int entriesRemoved; if (this.force) { - entriesRemoved = this.archive.removeDatabaseWallet(DEFAULT_RCU_WALLET_NAME, true); + entriesRemoved = this.archive.removeRCUDatabaseWallet(true); } else { - entriesRemoved = this.archive.removeDatabaseWallet(DEFAULT_RCU_WALLET_NAME); + entriesRemoved = this.archive.removeRCUDatabaseWallet(); } - response = new CommandResponse(ExitCode.OK, "WLSDPLY-30026", TYPE, DEFAULT_RCU_WALLET_NAME, - entriesRemoved, this.archiveFilePath); + response = new CommandResponse(ExitCode.OK, "WLSDPLY-30060", entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { - LOGGER.severe("WLSDPLY-30027", ex, TYPE, DEFAULT_RCU_WALLET_NAME, this.archiveFilePath, - ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, - DEFAULT_RCU_WALLET_NAME, this.archiveFilePath, ex.getLocalizedMessage()); + LOGGER.severe("WLSDPLY-30061", ex, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30061", + this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { - LOGGER.severe("WLSDPLY-30028", ex, TYPE, DEFAULT_RCU_WALLET_NAME, this.force, - this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, DEFAULT_RCU_WALLET_NAME, + LOGGER.severe("WLSDPLY-30062", ex, this.force, this.archiveFilePath, ex.getLocalizedMessage()); + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30062", this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveScriptCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveScriptCommand.java index a43f627dd6..8bf10a7683 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveScriptCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveScriptCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveServerKeystoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveServerKeystoreCommand.java index 14790bed02..5504c30c4f 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveServerKeystoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveServerKeystoreCommand.java @@ -67,12 +67,12 @@ public CommandResponse call() throws Exception { } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30030", ex, this.serverName, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30030", ex, this.serverName, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30030", this.serverName, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30031", ex, this.serverName, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30031", ex, this.serverName, this.name, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30031", this.serverName, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryCommand.java index fe91036bec..d0440ec1ab 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryPlanCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryPlanCommand.java index e64fd8c843..de4c52ca49 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryPlanCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveSharedLibraryPlanCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveStructuredApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveStructuredApplicationCommand.java index ab2f743a19..4ef63d8815 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveStructuredApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveStructuredApplicationCommand.java @@ -59,12 +59,12 @@ public CommandResponse call() throws Exception { entriesRemoved, this.archiveFilePath); } catch (ArchiveHelperException ex) { LOGGER.severe("WLSDPLY-30027", ex, TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", ex, TYPE, this.name, + response = new CommandResponse(ex.getExitCode(), "WLSDPLY-30027", TYPE, this.name, this.archiveFilePath, ex.getLocalizedMessage()); } catch (WLSDeployArchiveIOException | IllegalArgumentException ex) { LOGGER.severe("WLSDPLY-30028", ex, TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); - response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", ex, TYPE, this.name, this.force, + response = new CommandResponse(ExitCode.ERROR, "WLSDPLY-30028", TYPE, this.name, this.force, this.archiveFilePath, ex.getLocalizedMessage()); } diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java index 4f88cd74f5..2c90b12439 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java @@ -174,6 +174,7 @@ public enum ArchiveEntryType { FILE_STORE, NODE_MANAGER_KEY_STORE, DB_WALLET, + RCU_WALLET, OPSS_WALLET, CUSTOM } @@ -313,6 +314,10 @@ public static String getPathForType(ArchiveEntryType type) { pathPrefix = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP; break; + case RCU_WALLET: + pathPrefix = DEFAULT_RCU_WALLET_PATH + ZIP_SEP; + break; + case OPSS_WALLET: pathPrefix = ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP; break; @@ -849,6 +854,24 @@ public Manifest getManifest(String sourcePath) throws WLSDeployArchiveIOExceptio return null; } + /** + * Extract the entire contents of the archive file to the domain home. + * + * @param domainHome the existing domain home directory + * @throws WLSDeployArchiveIOException if an error occurs reading the archive or writing the files. + * @throws IllegalArgumentException if the domainHome directory does not exist + */ + public void extractAll(File domainHome) throws WLSDeployArchiveIOException { + final String METHOD = "extractAll"; + LOGGER.entering(CLASS, METHOD, domainHome); + + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + extractDirectoryFromZip(WLSDPLY_ARCHIVE_BINARY_DIR + ZIP_SEP, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * This method removes all binaries from the archive. This method is intended to * be invoked by discovery to remove binaries from a previous run that might @@ -942,27 +965,31 @@ public List listApplications() throws WLSDeployArchiveIOException { } /** - * Extract the specified application from the archive to the domain home directory. + * Extract the named application from the archive to the domain home directory. * - * @param applicationPath the application path into the archive file - * @param domainHome the domain home directory + * @param appPath the application path into the archive file + * @param domainHome the domain home directory * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file - * @throws IllegalArgumentException if the file or directory passed in does not exist - * or the application path is empty + * @throws IllegalArgumentException if the domainHome directory does not exist or the appPath is empty */ - public void extractApplication(String applicationPath, File domainHome) throws WLSDeployArchiveIOException { + public void extractApplication(String appPath, File domainHome) throws WLSDeployArchiveIOException { final String METHOD = "extractApplication"; + LOGGER.entering(CLASS, METHOD, appPath); - LOGGER.entering(CLASS, METHOD, applicationPath); - validateNonEmptyString(applicationPath, "applicationPath", METHOD); + validateNonEmptyString(appPath, "appPath", METHOD); validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); - String appPath = applicationPath; - if (!applicationPath.startsWith(ARCHIVE_STRUCT_APPS_TARGET_DIR) && - !applicationPath.startsWith(ARCHIVE_APPS_TARGET_DIR)) { - appPath = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP + applicationPath; + String archivePath = appPath; + if (!appPath.startsWith(ARCHIVE_APPS_TARGET_DIR)) { + archivePath = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP + appPath; + } + + archivePath = fixupPathForDirectories(archivePath); + if (archivePath.endsWith(ZIP_SEP)) { + extractDirectoryFromZip(archivePath, domainHome); + } else { + extractFileFromZip(archivePath, domainHome); } - extractFileFromZip(appPath, domainHome); LOGGER.exiting(CLASS, METHOD); } @@ -1088,6 +1115,32 @@ public String replaceApplicationDeploymentPlan(String planPath, String sourceLoc return newName; } + /** + * Extracts the named application deployment plan from the archive into the domain home directory, + * preserving the archive directory structure. + * + * @param planPath the name of the application deployment plan file in the archive. + * @param domainHome the existing domain home directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the planPath is empty + */ + public void extractApplicationPlan(String planPath, File domainHome) throws WLSDeployArchiveIOException { + final String METHOD = "extractApplicationPlan"; + LOGGER.entering(CLASS, METHOD, planPath); + + validateNonEmptyString(planPath, "planPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = planPath; + if (!planPath.startsWith(ARCHIVE_APPS_TARGET_DIR)) { + archivePath = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP + planPath; + } + + extractFileFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named application deployment plan from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -1209,6 +1262,35 @@ public String replaceStructuredApplication(String appPath, String sourceInstallR return newName; } + /** + * Extracts the named structured application installation directory from the archive into the domain home directory, + * preserving the archive directory structure. + * + * @param appPath the name of the application installation directory in the archive. + * @param domainHome the existing domain home directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the appPath is empty + */ + public void extractStructuredApplication(String appPath, File domainHome) throws WLSDeployArchiveIOException { + final String METHOD = "extractApplicationPlan"; + LOGGER.entering(CLASS, METHOD, appPath); + + validateNonEmptyString(appPath, "appPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = appPath; + if (!appPath.startsWith(ARCHIVE_STRUCT_APPS_TARGET_DIR)) { + archivePath = ARCHIVE_STRUCT_APPS_TARGET_DIR + ZIP_SEP + appPath; + } + if (!archivePath.endsWith(ZIP_SEP)) { + archivePath += ZIP_SEP; + } + + extractDirectoryFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + // TODO - Need to verify that discovery produces an archive that is consistent with the add/replace methods above. // Once verified, change method name to be consistent and add javadoc. public String addApplicationFolder(String appName, String appPath) @@ -1387,26 +1469,33 @@ public List listSharedLibraries() throws WLSDeployArchiveIOException { } /** - * Extract the specified shared library from the archive to the domain home directory. + * Extracts the named shared library from the archive into the domain home directory, + * preserving the archive directory structure. * - * @param sharedLibraryPath the shared library path into the archive file - * @param domainHome the domain home directory + * @param libPath the name of the shared library file/directory in the archive + * @param domainHome the existing domain home directory * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file - * @throws IllegalArgumentException if the file or directory passed in does not exist - * or the application path is empty + * @throws IllegalArgumentException if the domainHome directory does not exist or the libPath is empty */ - public void extractSharedLibrary(String sharedLibraryPath, File domainHome) throws WLSDeployArchiveIOException { + public void extractSharedLibrary(String libPath, File domainHome) throws WLSDeployArchiveIOException { final String METHOD = "extractSharedLibrary"; + LOGGER.entering(CLASS, METHOD, libPath); - LOGGER.entering(CLASS, METHOD, sharedLibraryPath); - validateNonEmptyString(sharedLibraryPath, "sharedLibraryPath", METHOD); + validateNonEmptyString(libPath, "libPath", METHOD); validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); - String libPath = sharedLibraryPath; - if (!sharedLibraryPath.startsWith(ARCHIVE_SHLIBS_TARGET_DIR)) { - libPath = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP + sharedLibraryPath; + String archivePath = libPath; + if (!libPath.startsWith(ARCHIVE_SHLIBS_TARGET_DIR)) { + archivePath = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP + libPath; } - extractFileFromZip(libPath, domainHome); + + archivePath = fixupPathForDirectories(archivePath); + if (archivePath.endsWith(ZIP_SEP)) { + extractDirectoryFromZip(archivePath, domainHome); + } else { + extractFileFromZip(archivePath, domainHome); + } + LOGGER.exiting(CLASS, METHOD); } @@ -1532,6 +1621,32 @@ public String replaceSharedLibraryDeploymentPlan(String planPath, String sourceL return newName; } + /** + * Extracts the named shared library deployment plan from the archive into the domain home directory, + * preserving the archive directory structure. + * + * @param planPath the name of the shared library deployment plan file in the archive. + * @param domainHome the existing domain home directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the planPath is empty + */ + public void extractSharedLibraryPlan(String planPath, File domainHome) throws WLSDeployArchiveIOException { + final String METHOD = "extractSharedLibraryPlan"; + LOGGER.entering(CLASS, METHOD, planPath); + + validateNonEmptyString(planPath, "planPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = planPath; + if (!planPath.startsWith(ARCHIVE_SHLIBS_TARGET_DIR)) { + archivePath = ARCHIVE_SHLIBS_TARGET_DIR + ZIP_SEP + planPath; + } + + extractFileFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named shared library deployment plan from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -1681,19 +1796,48 @@ public List listDomainLibLibraries() throws WLSDeployArchiveIOException /** * Extract the specified domain library to the specified location (e.g., $DOMAIN_HOME/lib). * - * @param archivePath the path of the library within the archive - * @param extractToLocation the location to write the file - * @throws WLSDeployArchiveIOException if an IOException occurred while extracting or writing the file - * @throws IllegalArgumentException if the file or directory passed in does not exist + * @param libPath the name of the $DOMAIN_HOME/lib library within the archive + * @param extractToLocation the existing directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the extractToLocation directory does not exist or the libPath is empty */ - public void extractDomainLibLibrary(String archivePath, File extractToLocation) throws WLSDeployArchiveIOException { + public void extractDomainLibLibrary(String libPath, File extractToLocation) throws WLSDeployArchiveIOException { final String METHOD = "extractDomainLibLibrary"; + LOGGER.entering(CLASS, METHOD, libPath, extractToLocation); - LOGGER.entering(CLASS, METHOD, archivePath, extractToLocation); - validateNonEmptyString(archivePath, "archivePath", METHOD); - validateExistingDirectory(extractToLocation, "extractToLocation", getArchiveFileName(), METHOD); + extractDomainLibLibrary(libPath, extractToLocation, false); + + LOGGER.exiting(CLASS, METHOD); + } + + /** + * Extract the named $DOMAIN_HOME/lib library to the domain home location. + * + * @param libPath the name of the $DOMAIN_HOME/lib library within the archive + * @param domainHome the existing directory location to write the file + * @param preserveIntermediateDirectories if true, file is extracted with intermediate directory structure + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the libPath is empty + */ + public void extractDomainLibLibrary(String libPath, File domainHome, boolean preserveIntermediateDirectories) + throws WLSDeployArchiveIOException { + final String METHOD = "extractDomainLibLibrary"; + LOGGER.entering(CLASS, METHOD, libPath, domainHome, preserveIntermediateDirectories); + + validateNonEmptyString(libPath, "libPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + if (preserveIntermediateDirectories) { + String archivePath = libPath; + if (!libPath.startsWith(ARCHIVE_DOMLIB_TARGET_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_DOMLIB_TARGET_DIR + ZIP_SEP + libPath; + } + + extractFileFromZip(archivePath, domainHome); + } else { + extractFileFromZip(libPath, ARCHIVE_DOMLIB_TARGET_DIR, "", domainHome); + } - extractFileFromZip(archivePath, ARCHIVE_DOMLIB_TARGET_DIR, "", extractToLocation); LOGGER.exiting(CLASS, METHOD); } @@ -1708,8 +1852,8 @@ public void extractDomainLibLibrary(String archivePath, File extractToLocation) * reading the archive or writing the file * @throws IllegalArgumentException if the libPath is null or empty */ - public int removeDomainLibrary(String libPath) throws WLSDeployArchiveIOException { - return removeDomainLibrary(libPath, false); + public int removeDomainLibLibrary(String libPath) throws WLSDeployArchiveIOException { + return removeDomainLibLibrary(libPath, false); } /** @@ -1724,7 +1868,7 @@ public int removeDomainLibrary(String libPath) throws WLSDeployArchiveIOExceptio * occurred while reading the archive or writing the file * @throws IllegalArgumentException if the libPath is null or empty */ - public int removeDomainLibrary(String libPath, boolean silent) throws WLSDeployArchiveIOException { + public int removeDomainLibLibrary(String libPath, boolean silent) throws WLSDeployArchiveIOException { final String METHOD = "removeDomainLibrary"; LOGGER.entering(CLASS, METHOD, libPath, silent); @@ -1840,11 +1984,43 @@ public List listClasspathLibraries() throws WLSDeployArchiveIOException */ public void extractClasspathLibraries(File domainHome) throws WLSDeployArchiveIOException { final String METHOD = "extractClasspathLibraries"; - LOGGER.entering(CLASS, METHOD, domainHome); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); extractDirectoryFromZip(ARCHIVE_CPLIB_TARGET_DIR, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + + /** + * Extract the named classpath library from the archive into the domain home directory, + * preserving the archive directory structure. + * + * @param libPath the name of the classpath library file/directory in the archive. + * @param domainHome the existing domain home directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the libPath is empty + */ + public void extractClasspathLibrary(String libPath, File domainHome) throws WLSDeployArchiveIOException { + final String METHOD = "extractClasspathLibrary"; + LOGGER.entering(CLASS, METHOD, libPath, domainHome); + + validateNonEmptyString(libPath, "libPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = libPath; + if (!libPath.startsWith(ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_CPLIB_TARGET_DIR + ZIP_SEP + libPath; + } + archivePath = fixupPathForDirectories(archivePath); + + if (archivePath.endsWith(ZIP_SEP)) { + extractDirectoryFromZip(archivePath, domainHome); + } else { + extractFileFromZip(archivePath, domainHome); + } + LOGGER.exiting(CLASS, METHOD); } @@ -1985,19 +2161,48 @@ public List listDomainBinScripts() throws WLSDeployArchiveIOException { /** * Extract the specified domain bin user script to the specified location (e.g., $DOMAIN_HOME/bin). * - * @param archivePath the path of the script within the archive - * @param extractToLocation the location to write the file - * @throws WLSDeployArchiveIOException if an IOException occurred while extracting or writing the file - * @throws IllegalArgumentException if the file or directory passed in does not exist + * @param scriptPath the name of the $DOMAIN_HOME/bin script within the archive + * @param extractToLocation the existing directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the extractToLocation directory does not exist or the scriptPath is empty */ - public void extractDomainBinScript(String archivePath, File extractToLocation) throws WLSDeployArchiveIOException { + public void extractDomainBinScript(String scriptPath, File extractToLocation) throws WLSDeployArchiveIOException { final String METHOD = "extractDomainBinScript"; + LOGGER.entering(CLASS, METHOD, scriptPath, extractToLocation); - LOGGER.entering(CLASS, METHOD, archivePath, extractToLocation); - validateNonEmptyString(archivePath, "archivePath", METHOD); - validateExistingDirectory(extractToLocation, "extractToLocation", getArchiveFileName(), METHOD); + extractDomainBinScript(scriptPath, extractToLocation, false); + + LOGGER.exiting(CLASS, METHOD); + } + + /** + * Extract the named $DOMAIN_HOME/bin script to the domain home location. + * + * @param scriptPath the name of the $DOMAIN_HOME/bin script within the archive + * @param domainHome the existing directory location to write the file + * @param preserveIntermediateDirectories if true, file is extracted with intermediate directory structure + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the scriptPath is empty + */ + public void extractDomainBinScript(String scriptPath, File domainHome, boolean preserveIntermediateDirectories) + throws WLSDeployArchiveIOException { + final String METHOD = "extractDomainBinScript"; + LOGGER.entering(CLASS, METHOD, scriptPath, domainHome, preserveIntermediateDirectories); + + validateNonEmptyString(scriptPath, "scriptPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + if (preserveIntermediateDirectories) { + String archivePath = scriptPath; + if (!scriptPath.startsWith(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP + scriptPath; + } + + extractFileFromZip(archivePath, domainHome); + } else { + extractFileFromZip(scriptPath, ARCHIVE_DOM_BIN_TARGET_DIR, "", domainHome); + } - extractFileFromZip(archivePath, ARCHIVE_DOM_BIN_TARGET_DIR, "", extractToLocation); LOGGER.exiting(CLASS, METHOD); } @@ -2160,6 +2365,37 @@ public void extractCustomFiles(File domainHome) throws WLSDeployArchiveIOExcepti LOGGER.exiting(CLASS, METHOD); } + /** + * Extract the named custom file/directory from the archive into the domain home directory, + * preserving the archive directory structure. + * + * @param entryPath the name of the custom file/directory in the archive. + * @param domainHome the existing domain home directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the entryPath is empty + */ + public void extractCustomEntry(String entryPath, File domainHome) throws WLSDeployArchiveIOException { + final String METHOD = "extractCustomEntry"; + LOGGER.entering(CLASS, METHOD, entryPath, domainHome); + + validateNonEmptyString(entryPath, "entryPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = entryPath; + if (!entryPath.startsWith(ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_CUSTOM_TARGET_DIR + ZIP_SEP + entryPath; + } + archivePath = fixupPathForDirectories(archivePath); + + if (archivePath.endsWith(ZIP_SEP)) { + extractDirectoryFromZip(archivePath, domainHome); + } else { + extractFileFromZip(archivePath, domainHome); + } + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named custom file/directory from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -2281,6 +2517,32 @@ public String replaceScript(String scriptPath, String sourceLocation) throws WLS return newName; } + /** + * Extract the named script to the domain home location. + * + * @param scriptPath the name of the script within the archive + * @param domainHome the existing directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the scriptPath is empty + */ + public void extractScript(String scriptPath, File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractScript"; + LOGGER.entering(CLASS, METHOD, scriptPath, domainHome); + + validateNonEmptyString(scriptPath, "scriptPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = scriptPath; + if (!scriptPath.startsWith(ARCHIVE_SCRIPTS_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_SCRIPTS_DIR + ZIP_SEP + scriptPath; + } + + extractFileFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named script from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -2417,6 +2679,39 @@ public String replaceServerKeyStoreFile(String serverName, String keystorePath, return newName; } + /** + * Extract the named server's keystore file to the domain home location. + * + * @param serverName the name of the server used to segregate the keystore + * @param keystoreName the name of the keystore file + * @param domainHome the existing directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or + * the serverName or keystoreName is empty + */ + public void extractServerKeystore(String serverName, String keystoreName, File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractServerKeystore"; + LOGGER.entering(CLASS, METHOD, serverName, keystoreName, domainHome); + + validateNonEmptyString(serverName, "serverName", METHOD); + validateNonEmptyString(keystoreName, "keystoreName", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath; + if (keystoreName.startsWith(ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP)) { + archivePath = keystoreName; + } else if (keystoreName.startsWith(serverName + ZIP_SEP)) { + archivePath = ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP + keystoreName; + } else { + archivePath = ARCHIVE_SERVER_TARGET_DIR + ZIP_SEP + serverName + ZIP_SEP + keystoreName; + } + + extractFileFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named server's keystore file from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -2529,29 +2824,55 @@ public String replaceNodeManagerKeyStoreFile(String keystorePath, String sourceL } /** - * Remove the named server's keystore file from the archive file. If this is the only entry + * Extract the named node manager keystore file to the domain home location. + * + * @param keystoreName the name of the keystore file + * @param domainHome the existing directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the keystoreName is empty + */ + public void extractNodeManagerKeystore(String keystoreName, File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractNodeManagerKeystore"; + LOGGER.entering(CLASS, METHOD, keystoreName, domainHome); + + validateNonEmptyString(keystoreName, "keystoreName", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = keystoreName; + if (!keystoreName.startsWith(ARCHIVE_NODE_MANAGER_TARGET_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_NODE_MANAGER_TARGET_DIR + ZIP_SEP + keystoreName; + } + + extractFileFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + + /** + * Remove the named node manager's keystore file from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. * * @param keystoreName the name of the keystore file * @return the number of zip entries removed from the archive * @throws WLSDeployArchiveIOException if the server's keystore file is not present or an IOException * occurred while reading the archive or writing the file - * @throws IllegalArgumentException if the serverName or keystoreName is null or empty + * @throws IllegalArgumentException if the keystoreName is null or empty */ public int removeNodeManagerKeystore(String keystoreName) throws WLSDeployArchiveIOException { return removeNodeManagerKeystore(keystoreName, false); } /** - * Remove the named server's keystore file from the archive file. If this is the only entry + * Remove the named node manager's keystore file from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. * * @param keystorePath the name of the keystore file - * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist + * @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist * @return the number of zip entries removed from the archive * @throws WLSDeployArchiveIOException if the server's keystore file is not present (and silent = false) or * an IOException occurred while reading the archive or writing the file - * @throws IllegalArgumentException if the serverName or keystorePath is null or empty + * @throws IllegalArgumentException if the keystorePath is null or empty */ public int removeNodeManagerKeystore(String keystorePath, boolean silent) throws WLSDeployArchiveIOException { @@ -2643,6 +2964,32 @@ public String replaceMimeMappingFile(String mimeMappingPath, String sourceLocati return newName; } + /** + * Extract the named MIME mapping file to the domain home location. + * + * @param mappingPath the name of the MIME mapping file + * @param domainHome the existing directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the mappingPath is empty + */ + public void extractMimeMappingFile(String mappingPath, File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractMimeMappingFile"; + LOGGER.entering(CLASS, METHOD, mappingPath, domainHome); + + validateNonEmptyString(mappingPath, "mappingPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = mappingPath; + if (!mappingPath.startsWith(ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP + mappingPath; + } + + extractFileFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named MIME mapping file from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -2802,6 +3149,39 @@ public String addCoherenceConfigFileFromUrl(String clusterName, URL urlForConfig return newName; } + /** + * Extract the named Coherence cluster's config file to the domain home location. + * + * @param clusterName the name of the server used to segregate the keystore + * @param configPath the name of the keystore file + * @param domainHome the existing directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or + * the clusterName or configPath is empty + */ + public void extractCoherenceConfigFile(String clusterName, String configPath, File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractCoherenceConfigFile"; + LOGGER.entering(CLASS, METHOD, clusterName, configPath, domainHome); + + validateNonEmptyString(clusterName, "clusterName", METHOD); + validateNonEmptyString(configPath, "configPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath; + if (configPath.startsWith(ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP)) { + archivePath = configPath; + } else if (configPath.startsWith(clusterName + ZIP_SEP)) { + archivePath = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + configPath; + } else { + archivePath = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + clusterName + ZIP_SEP + configPath; + } + + extractFileFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named Coherence config file from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -2914,6 +3294,43 @@ public String replaceCoherencePersistenceDirectory(String clusterName, String di return newName; } + /** + * Extract the named Coherence cluster's persistence directory to the domain home location. + * + * @param clusterName the name of the Coherence cluster used to segregate the keystore + * @param directoryType the name of the persistence directory + * @param domainHome the existing directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or + * the clusterName or directoryType is empty + */ + public void extractCoherencePersistenceDirectory(String clusterName, String directoryType, File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractCoherencePersistenceDirectory"; + LOGGER.entering(CLASS, METHOD, clusterName, directoryType, domainHome); + + validateNonEmptyString(clusterName, "clusterName", METHOD); + validateNonEmptyString(directoryType, "directoryType", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath; + if (directoryType.startsWith(ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP)) { + archivePath = directoryType; + } else if (directoryType.startsWith(clusterName + ZIP_SEP)) { + archivePath = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + directoryType; + } else { + archivePath = ARCHIVE_COHERENCE_TARGET_DIR + ZIP_SEP + clusterName + ZIP_SEP + directoryType; + } + + if (!archivePath.endsWith(ZIP_SEP)) { + archivePath += ZIP_SEP; + } + + extractDirectoryFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named Coherence persistence directory from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -2980,21 +3397,23 @@ public int removeCoherencePersistenceDirectory(String clusterName, String persis /** * Add a Foreign Server binding file to the archive. * - * @param foreignServer the Foreign Server name used to segregate the directories - * @param configFile the file or directory to add + * @param foreignServerName the Foreign Server name used to segregate the directories + * @param bindingPath the file or directory to add * @return the new location of the file to use in the model * @throws WLSDeployArchiveIOException if an error occurs while archiving the file - * @throws IllegalArgumentException if the file does not exist or the foreignServer is empty or null + * @throws IllegalArgumentException if the file does not exist or the foreignServerName is empty or null */ - public String addForeignServerFile(String foreignServer, String configFile) throws WLSDeployArchiveIOException { + public String addForeignServerFile(String foreignServerName, String bindingPath) + throws WLSDeployArchiveIOException { final String METHOD = "addForeignServerFile"; - LOGGER.entering(CLASS, METHOD, foreignServer, configFile); + LOGGER.entering(CLASS, METHOD, foreignServerName, bindingPath); - File filePath = new File(configFile); - validateNonEmptyString(foreignServer, "foreignServerName", METHOD); - validateExistingFile(filePath, "configFile", getArchiveFileName(), METHOD, true); + validateNonEmptyString(foreignServerName, "foreignServerName", METHOD); + File filePath = new File(bindingPath); + validateExistingFile(filePath, "bindingPath", getArchiveFileName(), METHOD); - String newName = addItemToZip(ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServer, filePath); + String newName = + addItemToZip(ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServerName, filePath); LOGGER.exiting(CLASS, METHOD, newName); return newName; @@ -3004,33 +3423,35 @@ public String addForeignServerFile(String foreignServer, String configFile) thro * Replace a Foreign Server binding file in the archive. * * @param foreignServerName the Foreign Server name used to segregate the directories - * @param configPath the Foreign Server binding file name or an archive path + * @param bindingPath the Foreign Server binding file name or an archive path * @param sourceLocation the file system location of the new Foreign Server binding file to replace the existing one * @return the archive path of the new Foreign Server binding file * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes - * @throws IllegalArgumentException if the file or directory passed in does not exist + * @throws IllegalArgumentException if the file passed in does not exist or the bindingPath is empty */ - public String replaceForeignServerFile(String foreignServerName, String configPath, String sourceLocation) + public String replaceForeignServerFile(String foreignServerName, String bindingPath, String sourceLocation) throws WLSDeployArchiveIOException { final String METHOD = "replaceForeignServerFile"; - LOGGER.entering(CLASS, METHOD, foreignServerName, configPath, sourceLocation); + LOGGER.entering(CLASS, METHOD, foreignServerName, bindingPath, sourceLocation); + + validateNonEmptyString(bindingPath, "bindingPath", METHOD); String archivePath = null; String computedForeignServerName = foreignServerName; - if (configPath.startsWith(ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP)) { - archivePath = configPath; - computedForeignServerName = getSegregationNameFromSegregatedArchivePath(foreignServerName, configPath); + if (bindingPath.startsWith(ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP)) { + archivePath = bindingPath; + computedForeignServerName = getSegregationNameFromSegregatedArchivePath(foreignServerName, bindingPath); } else if (!StringUtils.isEmpty(foreignServerName)) { - if (configPath.startsWith(foreignServerName + ZIP_SEP)) { - archivePath = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + configPath; + if (bindingPath.startsWith(foreignServerName + ZIP_SEP)) { + archivePath = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + bindingPath; } else { - archivePath = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServerName + ZIP_SEP + configPath; + archivePath = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServerName + ZIP_SEP + bindingPath; } } if (StringUtils.isEmpty(computedForeignServerName)) { WLSDeployArchiveIOException ex = - new WLSDeployArchiveIOException("WLSDPLY-01436", configPath, sourceLocation); + new WLSDeployArchiveIOException("WLSDPLY-01436", bindingPath, sourceLocation); LOGGER.throwing(CLASS, METHOD, ex); throw ex; } @@ -3038,12 +3459,45 @@ public String replaceForeignServerFile(String foreignServerName, String configPa // If we get here, archivePath should never be null! // getZipFile().removeZipEntry(archivePath); - String newName = addCoherenceConfigFile(computedForeignServerName, sourceLocation); + String newName = addForeignServerFile(computedForeignServerName, sourceLocation); LOGGER.exiting(CLASS, METHOD, newName); return newName; } + /** + * Extract the named Foreign Server binding file to the domain home location. + * + * @param foreignServerName the name of the JMS Foreign Server used to segregate the bindings + * @param bindingPath the name of the binding file + * @param domainHome the existing directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or + * the foreignServerName or bindingPath is empty + */ + public void extractForeignServerFile(String foreignServerName, String bindingPath, File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractForeignServerFile"; + LOGGER.entering(CLASS, METHOD, foreignServerName, bindingPath, domainHome); + + validateNonEmptyString(foreignServerName, "foreignServerName", METHOD); + validateNonEmptyString(bindingPath, "bindingPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath; + if (bindingPath.startsWith(ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP)) { + archivePath = bindingPath; + } else if (bindingPath.startsWith(foreignServerName + ZIP_SEP)) { + archivePath = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + bindingPath; + } else { + archivePath = ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServerName + ZIP_SEP + bindingPath; + } + + extractFileFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named JMS Foreign Server bindings file from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -3158,6 +3612,36 @@ public String replaceFileStoreDirectory(String fileStorePath) throws WLSDeployAr return newName; } + /** + * Extract the named File Store directory to the domain home location. + * + * @param fileStorePath the name of the File Store directory + * @param domainHome the existing domain home directory location to write the file + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file + * @throws IllegalArgumentException if the domainHome directory does not exist or the fileStorePath is empty + */ + public void extractFileStoreDirectory(String fileStorePath, File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractFileStoreDirectory"; + LOGGER.entering(CLASS, METHOD, fileStorePath, domainHome); + + validateNonEmptyString(fileStorePath, "fileStorePath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = fileStorePath; + if (!fileStorePath.startsWith(ARCHIVE_FILE_STORE_TARGET_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_FILE_STORE_TARGET_DIR + ZIP_SEP + fileStorePath; + } + + if (!archivePath.endsWith(ZIP_SEP)) { + archivePath += ZIP_SEP; + } + + extractDirectoryFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named File Store directory from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -3229,21 +3713,26 @@ public String addDatabaseWallet(String walletName, String sourceLocation) throws final String METHOD = "addDatabaseWallet"; LOGGER.entering(CLASS, METHOD, walletName, sourceLocation); - File sourceFile = FileUtils.getCanonicalFile(sourceLocation); - validateNonEmptyString(walletName, "walletName", METHOD); - validateExistingFile(sourceFile, "sourceLocation", getArchiveFileName(), METHOD, true); + boolean verifyNotExists = DEFAULT_RCU_WALLET_NAME.equals(walletName); + String newName = addDatabaseWallet(walletName, sourceLocation, verifyNotExists); - String newName; - if (sourceFile.isDirectory()) { - newName = addItemToZip(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName, sourceFile, false); - } else { - newName = addItemToZip(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName, sourceFile); + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } - // When adding a file (e.g., zip file), the wallet name returned should always point - // to the wallet directory containing the file. - // - newName = getDatabaseWalletArchivePathFromAddedFile(ARCHIVE_DB_WALLETS_DIR, newName); - } + /** + * Add the RCU database wallet to the archive. + * + * @param sourceLocation the file system location for the wallet file (zip file or single file) or directory + * @return the archive path to the wallet directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the wallet file/directory does not exist + */ + public String addRCUDatabaseWallet(String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "addRCUDatabaseWallet"; + LOGGER.entering(CLASS, METHOD, sourceLocation); + + String newName = addDatabaseWallet(DEFAULT_RCU_WALLET_NAME, sourceLocation, true); LOGGER.exiting(CLASS, METHOD, newName); return newName; @@ -3259,7 +3748,7 @@ public String addDatabaseWallet(String walletName, String sourceLocation) throws * @throws IllegalArgumentException if the wallet name if empty or the wallet file/directory does not exist */ public String replaceDatabaseWallet(String walletPath, String sourceLocation) throws WLSDeployArchiveIOException { - final String METHOD = "addDatabaseWallet"; + final String METHOD = "replaceDatabaseWallet"; LOGGER.entering(CLASS, METHOD, walletPath, sourceLocation); validateNonEmptyString(walletPath, "walletPath", METHOD); @@ -3278,24 +3767,43 @@ public String replaceDatabaseWallet(String walletPath, String sourceLocation) th } getZipFile().removeZipEntries(archivePath); - String newName = addDatabaseWallet(computedWalletName, sourceLocation); + String newName = addDatabaseWallet(computedWalletName, sourceLocation, false); LOGGER.exiting(CLASS, METHOD, newName); return newName; } /** - * Extract the named database wallet. + * Replace the RCU database wallet in the archive. * - * @param domainHome the domain home directory + * @param sourceLocation the file system location of the database wallet file/directory to replace the existing one + * @return the archive path to the wallet directory + * @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes + * @throws IllegalArgumentException if the wallet file/directory does not exist + */ + public String replaceRCUDatabaseWallet(String sourceLocation) throws WLSDeployArchiveIOException { + final String METHOD = "replaceRCUDatabaseWallet"; + LOGGER.entering(CLASS, METHOD, sourceLocation); + + String newName = replaceDatabaseWallet(DEFAULT_RCU_WALLET_NAME, sourceLocation); + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + + /** + * Extract the named database wallet. If the named database wallet is stored as a zip inside the archive, + * this method will unzip that zip file so the result is always an expanded directory. + * + * @param domainHome the existing domain home directory * @param walletName the name of the database wallet to extract (e.g., rcu) - * @return the full path to the directory containing the extracted wallet files or null, if no wallet was found. - * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files. + * @return the full path to the directory containing the extracted wallet files or null, if no wallet was found + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files * @throws IllegalArgumentException if the wallet name if empty or the domain home directory does not exist + * @see WLSDeployArchive#extractDatabaseWalletForArchiveHelper(String, File) */ public String extractDatabaseWallet(File domainHome, String walletName) throws WLSDeployArchiveIOException { final String METHOD = "extractDatabaseWallet"; - LOGGER.entering(CLASS, METHOD, domainHome, walletName); validateNonEmptyString(walletName, "walletName", METHOD); @@ -3320,6 +3828,75 @@ public String extractDatabaseWallet(File domainHome, String walletName) throws W return extractPath; } + /** + * Extract the RCU database wallet. If the RCU database wallet is stored as a zip inside the archive, + * this method will unzip that zip file so the result is always an expanded directory. + * + * @param domainHome the existing domain home directory + * @return the full path to the directory containing the extracted wallet files or null, if no wallet was found + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files + * @throws IllegalArgumentException if the domain home directory does not exist + * @see WLSDeployArchive#extractRCUDatabaseWalletForArchiveHelper(File) + */ + public String extractRCUDatabaseWallet(File domainHome) throws WLSDeployArchiveIOException { + final String METHOD = "extractRCUDatabaseWallet"; + LOGGER.entering(CLASS, METHOD, domainHome); + + String extractPath = extractDatabaseWallet(domainHome, DEFAULT_RCU_WALLET_NAME); + + LOGGER.exiting(CLASS, METHOD, extractPath); + return extractPath; + } + + /** + * Extract the named database wallet. Unlike extractDatabaseWallet(), this method will not + * unzip the wallet if it is a zip file stored in the archive. It also does not have any + * handling of the old archive location for the rcu wallet. + * + * @param walletPath the name of the database wallet to extract (e.g., rcu) + * @param domainHome the existing domain home directory + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files + * @throws IllegalArgumentException if the wallet name if empty or the domain home directory does not exist + * @see WLSDeployArchive#extractDatabaseWallet(File, String) + */ + public void extractDatabaseWalletForArchiveHelper(String walletPath, File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractDatabaseWalletForArchiveHelper"; + LOGGER.entering(CLASS, METHOD, walletPath, domainHome); + + validateNonEmptyString(walletPath, "walletPath", METHOD); + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = walletPath; + if (!walletPath.startsWith(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP)) { + archivePath = ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + archivePath; + } + + extractDirectoryFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + + /** + * Extract the RCU database wallet. Unlike extractRCUDatabaseWallet(), this method will not + * unzip the wallet if it is a zip file stored in the archive. It also does not have any + * handling of the old archive location for the rcu wallet. + * + * @param domainHome the existing domain home directory + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files + * @throws IllegalArgumentException if the domain home directory does not exist + * @see WLSDeployArchive#extractRCUDatabaseWallet(File) + */ + public void extractRCUDatabaseWalletForArchiveHelper(File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractRCUDatabaseWalletForArchiveHelper"; + LOGGER.entering(CLASS, METHOD, domainHome); + + extractDatabaseWalletForArchiveHelper(DEFAULT_RCU_WALLET_NAME, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the named database wallet from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -3330,11 +3907,22 @@ public String extractDatabaseWallet(File domainHome, String walletName) throws W * occurred while reading the archive or writing the file * @throws IllegalArgumentException if the walletName is null or empty */ - public int removeDatabaseWallet(String walletName) - throws WLSDeployArchiveIOException { + public int removeDatabaseWallet(String walletName) throws WLSDeployArchiveIOException { return removeDatabaseWallet(walletName, false); } + /** + * Remove the RCU database wallet from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the RCU database wallet is not present or an IOException + * occurred while reading the archive or writing the file + */ + public int removeRCUDatabaseWallet() throws WLSDeployArchiveIOException { + return removeDatabaseWallet(DEFAULT_RCU_WALLET_NAME); + } + /** * Remove the named database wallet from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -3374,6 +3962,26 @@ public int removeDatabaseWallet(String walletName, boolean silent) return result; } + /** + * Remove the RCU database wallet from the archive file. If this is the only entry + * in the archive file directory, the directory entry will also be removed, if present. + * + * @param silent If false, a WLSDeployArchiveIOException is thrown is the RCU wallet does not exist + * @return the number of zip entries removed from the archive + * @throws WLSDeployArchiveIOException if the RCU database wallet is not present (and silent = false) + * or an IOException occurred while reading the archive or writing the file + */ + public int removeRCUDatabaseWallet(boolean silent) + throws WLSDeployArchiveIOException { + final String METHOD = "removeRCUDatabaseWallet"; + LOGGER.entering(CLASS, METHOD, silent); + + int result = removeDatabaseWallet(DEFAULT_RCU_WALLET_NAME, silent); + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + /////////////////////////////////////////////////////////////////////////////////////////////// // OPSS wallet methods // /////////////////////////////////////////////////////////////////////////////////////////////// @@ -3405,7 +4013,7 @@ public String addOPSSWallet(String sourceLocation) throws WLSDeployArchiveIOExce * @throws IllegalArgumentException if the provided source location file/directory does not exist */ public String replaceOPSSWallet(String sourceLocation) throws WLSDeployArchiveIOException { - final String METHOD = "addOPSSWallet"; + final String METHOD = "replaceOPSSWallet"; LOGGER.entering(CLASS, METHOD, sourceLocation); File sourceFile = FileUtils.getCanonicalFile(sourceLocation); @@ -3419,11 +4027,14 @@ public String replaceOPSSWallet(String sourceLocation) throws WLSDeployArchiveIO } /** - * Extract the OPSS wallet from the archive. + * Extract the OPSS wallet from the archive. If the OPSS wallet is stored as a zip inside the archive, + * this method will unzip that zip file so the result is always an expanded directory. * * @param domainHome the domain home directory * @return the full path to the directory containing the extracted wallet files or null, if no wallet was found. - * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files. + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files + * @throws IllegalArgumentException if the domain home directory does not exist + * @see WLSDeployArchive#extractOPSSWalletForArchiveHelper(File) */ public String extractOPSSWallet(File domainHome) throws WLSDeployArchiveIOException { final String METHOD = "extractOPSSWallet"; @@ -3454,6 +4065,29 @@ public String extractOPSSWallet(File domainHome) throws WLSDeployArchiveIOExcept return extractPath; } + /** + * Extract the OPSS wallet. Unlike extractOPSSWallet(), this method will not + * unzip the wallet if it is a zip file stored in the archive. It also does not have any + * handling of the old archive location for the OPSS wallet. + * + * @param domainHome the existing domain home directory + * @throws WLSDeployArchiveIOException if an error occurs while reading or extracting the archive files + * @throws IllegalArgumentException if the domain home directory does not exist + * @see WLSDeployArchive#extractOPSSWallet(File) + */ + public void extractOPSSWalletForArchiveHelper(File domainHome) + throws WLSDeployArchiveIOException { + final String METHOD = "extractDatabaseWalletForArchiveHelper"; + LOGGER.entering(CLASS, METHOD, domainHome); + + validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); + + String archivePath = ARCHIVE_OPSS_WALLET_PATH + ZIP_SEP; + extractDirectoryFromZip(archivePath, domainHome); + + LOGGER.exiting(CLASS, METHOD); + } + /** * Remove the OPSS wallet from the archive file. If this is the only entry * in the archive file directory, the directory entry will also be removed, if present. @@ -3833,6 +4467,44 @@ protected void unzipZippedArchiveFileEntry(String zippedItemToExtract, File extr LOGGER.exiting(CLASS, METHOD); } + protected String addDatabaseWallet(String walletName, String sourceLocation, boolean verifyNotExists) + throws WLSDeployArchiveIOException { + final String METHOD = "addDatabaseWallet"; + LOGGER.entering(CLASS, METHOD, walletName, sourceLocation, verifyNotExists); + + File sourceFile = FileUtils.getCanonicalFile(sourceLocation); + validateNonEmptyString(walletName, "walletName", METHOD); + validateExistingFile(sourceFile, "sourceLocation", getArchiveFileName(), METHOD, true); + + // Because there is only one RCU wallet per domain, we have to make sure that + // there is no existing RCU wallet in the archive prior to adding one. + // + if (verifyNotExists) { + List rcuWalletEntries = getArchiveEntries(ArchiveEntryType.RCU_WALLET); + if (!rcuWalletEntries.isEmpty()) { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01459", getArchiveFileName(), rcuWalletEntries.size()); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } + } + + String newName; + if (sourceFile.isDirectory()) { + newName = addItemToZip(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName, sourceFile, false); + } else { + newName = addItemToZip(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName, sourceFile); + + // When adding a file (e.g., zip file), the wallet name returned should always point + // to the wallet directory containing the file. + // + newName = getDatabaseWalletArchivePathFromAddedFile(ARCHIVE_DB_WALLETS_DIR, newName); + } + + LOGGER.exiting(CLASS, METHOD, newName); + return newName; + } + protected String addOPSSWallet(String sourceLocation, boolean verifyNotExists) throws WLSDeployArchiveIOException { final String METHOD = "addOPSSWallet"; LOGGER.entering(CLASS, METHOD, sourceLocation, verifyNotExists); @@ -3899,6 +4571,7 @@ protected void extractDirectoryFromZip(String fromDirectoryName, String toDirect } else { targetDirectory = targetFile.getParentFile(); } + if (!targetDirectory.exists() && !targetDirectory.mkdirs()) { WLSDeployArchiveIOException wdaioe = new WLSDeployArchiveIOException("WLSDPLY-01414", getArchiveFileName(), @@ -3917,6 +4590,11 @@ protected void extractDirectoryFromZip(String fromDirectoryName, String toDirect outputStream.close(); } } + } else { + WLSDeployArchiveIOException ex = + new WLSDeployArchiveIOException("WLSDPLY-01416", getArchiveFileName(), dirName); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; } } catch (IOException ioe) { WLSDeployArchiveIOException wdaioe = @@ -4399,4 +5077,24 @@ private int removeEmptyTypeDir(ArchiveEntryType type, String prefixPath) throws LOGGER.exiting(CLASS, METHOD, result); return result; } + + // The archiveHelper does not require that users specify a trailing / on directory names. + // As such, we have to figure out if the path is a directory and requires appending a + // trailing / to make the extraction code work properly with directories. + // + private String fixupPathForDirectories(String path) throws WLSDeployArchiveIOException { + final String METHOD = "fixupPathForDirectories"; + LOGGER.entering(CLASS, METHOD, path); + + String result = path; + if (!path.endsWith(ZIP_SEP)) { + List zipEntries = getZipFile().listZipEntries(path + ZIP_SEP); + if (zipEntries.contains(path + ZIP_SEP)) { + result = path + ZIP_SEP; + } + } + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } } diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployZipFile.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployZipFile.java index 919fb838b8..6e31b5ffe0 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployZipFile.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployZipFile.java @@ -17,6 +17,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -39,6 +40,7 @@ public class WLSDeployZipFile { private static final String CLOSE_PAREN = ")"; private static final char ZIP_SEP_CHAR = '/'; private static final String ZIP_SEP = "/"; + private static final Pattern RENAME_QUALIFIER_REGEX = Pattern.compile("^[(]([1-9]\\d*)[)]$"); private static final int READ_BUFFER_SIZE = 4096; private static final int MAX_DIGITS = Integer.toString(Integer.MAX_VALUE).length() - 1; @@ -325,7 +327,7 @@ public boolean removeZipEntries(String key) throws WLSDeployArchiveIOException { * * @param entryName the name of the entry to add * @param inputStream the InputStream that will be used to read the entry when it is saved - * @param rename whether or not to rename the entry if it conflicts with an existing entry + * @param rename whether to rename the entry if it conflicts with an existing entry * @return the entry name used to store the entry or null if the add failed due to an entry name conflict * @throws WLSDeployArchiveIOException if an IOException occurred while adding the entry */ @@ -387,7 +389,7 @@ public boolean addZipEntry(String key, InputStream inputStream) throws WLSDeploy * Add the provided directory entry to the unsaved changes list, optionally renaming it to prevent conflicts. * * @param entryName the entry name to add - * @param rename whether or not to rename the entry to prevent conflicts + * @param rename whether to rename the entry to prevent conflicts * @return the name of the added entry * @throws WLSDeployArchiveIOException if an IOException occurred while adding the entry */ @@ -398,16 +400,16 @@ public String addZipDirectoryEntry(String entryName, boolean rename) throws WLSD closeOpenZipFile(); String newEntryName = entryName; - if (!entryName.endsWith("/")) { - newEntryName = entryName + "/"; + if (!entryName.endsWith(ZIP_SEP)) { + newEntryName = entryName + ZIP_SEP; } if (rename && isRenameNecessary(newEntryName)) { LOGGER.finer("WLSDPLY-01507", entryName); - newEntryName = getNextUniqueEntryName(entryName); + newEntryName = getNextUniqueDirectoryName(entryName); LOGGER.finer("WLSDPLY-01508", entryName, newEntryName); - if (!newEntryName.endsWith("/")) { - newEntryName += "/"; + if (!newEntryName.endsWith(ZIP_SEP)) { + newEntryName += ZIP_SEP; } } @@ -484,7 +486,7 @@ public String addDirectoryZipEntries(String entryName, File directory) throws WL } if (isRenameNecessary(newEntryName)) { LOGGER.finer("WLSDPLY-01507", entryName); - newEntryName = getNextUniqueEntryName(newEntryName); + newEntryName = getNextUniqueDirectoryName(newEntryName); LOGGER.finer("WLSDPLY-01508", entryName, newEntryName); } @@ -880,14 +882,105 @@ private boolean isRenameNecessary(String entryName) throws WLSDeployArchiveIOExc boolean renameNeeded = false; Map zipEntryMap = getZipFileEntries(getFile()); + // This is tricky. If the entry is a file, then looking at the containment is sufficient. + // However, if it is a directory, the raw directory entry may or may not be in the zip. + // We need to look at each entry to see if any entries start with the entry name. + // if (zipEntryMap.containsKey(entryName)) { LOGGER.finest("WLSDPLY-01534", entryName); renameNeeded = true; + } else if (entryName.endsWith(ZIP_SEP)) { + for (String key : zipEntryMap.keySet()) { + if (key.startsWith(entryName)) { + LOGGER.finest("WLSDPLY-01534", entryName); + renameNeeded = true; + break; + } + } } LOGGER.exiting(renameNeeded); return renameNeeded; } + private String getNextUniqueDirectoryName(String directoryEntryName) throws WLSDeployArchiveIOException { + final String METHOD = "getNextUniqueDirectoryName"; + LOGGER.entering(CLASS, METHOD, directoryEntryName); + + String entryNameBase = directoryEntryName; + if (directoryEntryName.endsWith(ZIP_SEP)) { + entryNameBase = directoryEntryName.substring(0, directoryEntryName.length() - 1); + } + LOGGER.finer("WLSDPLY-01542", directoryEntryName, entryNameBase); + Map zipEntriesMap = getZipFileEntries(getFile()); + + int highestNumberFound = -1; + for (String zipEntryKey : zipEntriesMap.keySet()) { + String nextNumberString = directoryEntryReallyMatches(zipEntryKey, entryNameBase); + + if (!StringUtils.isEmpty(nextNumberString)) { + int number; + try { + number = Integer.parseInt(nextNumberString); + } catch (NumberFormatException ex) { + WLSDeployArchiveIOException ex1 = new WLSDeployArchiveIOException("WLSDPLY-01543", + nextNumberString, ex, ex.getLocalizedMessage()); + LOGGER.throwing(CLASS, METHOD, ex1); + throw ex1; + } + if (number > highestNumberFound) { + highestNumberFound = number; + } + } + } + + String result = entryNameBase; + if (highestNumberFound != -1) { + int number = highestNumberFound + 1; + result += OPEN_PAREN + number + CLOSE_PAREN; + } + + LOGGER.exiting(CLASS, METHOD, result); + return result; + } + + // This method is kind of hacky in that it combines two purposes for efficiency purposes. + // First, we need to make sure that the entry really matches the directoryBaseName. Using an example + // base name of wlsdeploy/applications/foo, entry should match only for the following cases: + // + // - wlsdeploy/applications/foo/* + // - wlsdeploy/applications/foo(####)/* + // + // We must not match the following cases: + // + // - wlsdeploy/applications/foo + // - wlsdeploy/applications/foobar/* + // - wlsdeploy/applications/foo(####)* + // - wlsdeploy/applications/foo(####)*/* + // + // Second, it returns the renaming number found in the entry if there was a match or null + // if no match was found. + // + private String directoryEntryReallyMatches(String entry, String directoryBaseName) { + final String METHOD = "directoryEntryReallyMatches"; + LOGGER.entering(CLASS, METHOD, entry, directoryBaseName); + + String reallyMatches = null; + if (entry.startsWith(directoryBaseName) && entry.length() > directoryBaseName.length()) { + String entryRemainder = entry.substring(directoryBaseName.length()); + if (entryRemainder.startsWith(ZIP_SEP)) { + reallyMatches = "0"; + } else if (entryRemainder.startsWith("(") && entryRemainder.contains(ZIP_SEP)) { + entryRemainder = entryRemainder.substring(0, entryRemainder.indexOf(ZIP_SEP)); + Matcher matcher = RENAME_QUALIFIER_REGEX.matcher(entryRemainder); + if (matcher.matches()) { + reallyMatches = matcher.group(1); + } + } + } + + LOGGER.exiting(CLASS, METHOD, reallyMatches); + return reallyMatches; + } private String getNextUniqueEntryName(String entryName) throws WLSDeployArchiveIOException { final String METHOD = "getNextUniqueEntryName"; diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index ae80b1bc92..e15e75c34b 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -232,6 +232,7 @@ WLSDPLY-01455=Failed to remove JMS Foreign Server {0} bindings file {1} from arc WLSDPLY-01456=Failed to remove File Store {0} from archive file {1} because the archive file did not contain {2}. WLSDPLY-01457=Failed to remove database wallet {0} from archive file {1} because the archive file did not contain {2}. WLSDPLY-01458=Failed to remove OPSS wallet from archive file {0} because the archive file did not contain {1}. +WLSDPLY-01459=Failed to add RCU Wallet to archive because the archive file {0} already contains an RCU wallet with {1} entries. # oracle.weblogic.deploy.util.WLSDeployZipFile.java @@ -278,6 +279,8 @@ WLSDPLY-01538=Stripped entry {0} has a key of {1} WLSDPLY-01539=Unexpected exception closing input stream for entry {0}: {1} WLSDPLY-01540=Closing the input stream for zip file {0} and zip entry {1} failed: {2} WLSDPLY-01541=Closing the input stream for file {0} failed: {1} +WLSDPLY-01542=Parsing directoryEntryName {0} resulted in a entryNameBase of {1} +WLSDPLY-01543=Failed to parse the directory rename number {0} into an integer: {1} # wlsdeploy/util/model_config.py WLSDPLY-01570=WDT Properties file not located or unable to load file at {0}. Internal defaults taken. : {1} @@ -1804,3 +1807,23 @@ WLSDPLY-30039=Failed to remove JMS Foreign Server {0} bindings file {1} with for WLSDPLY-30040=The archiveHelper remove {0} command removed {1} entries from archive file {2}. WLSDPLY-30041=Failed to remove {0} from archive file {1}: {2}. WLSDPLY-30042=Failed to remove {0} with force value {1} from archive file {2}: {3}. +WLSDPLY-30043=The -target argument must have a non-empty directory name +WLSDPLY-30044=The -target argument {0} is not a directory +WLSDPLY-30045=The -target directory {0} does not exist and could not be created +WLSDPLY-30046=The archiveHelper extract {0} extracted {1} from archive file {2} to target directory {3}. +WLSDPLY-30047=Failed to extract {0} {1} from archive file {2} to target directory {3}: {4}. +WLSDPLY-30048=The archiveHelper extract {0} extracted {1} for cluster {2} from archive file {3} to target directory {4}. +WLSDPLY-30049=Failed to extract {0} {1} for cluster {2} from archive file {3} to target directory {4}: {5}. +WLSDPLY-30050=The archiveHelper extract {0} extracted {1} for JMS Foreign Server {2} from archive file {3} to target directory {4}. +WLSDPLY-30051=Failed to extract {0} {1} for JMS Foreign Server {2} from archive file {3} to target directory {4}: {5}. +WLSDPLY-30052=The archiveHelper extract {0} extracted {1} for server {2} from archive file {3} to target directory {4}. +WLSDPLY-30053=Failed to extract {0} {1} for server {2} from archive file {3} to target directory {4}: {5}. +WLSDPLY-30054=The archiveHelper extract {0} extracted the {1} wallet from archive file {2} to target directory {3}. +WLSDPLY-30055=Failed to extract the {0} wallet from archive file {1} to target directory {2}: {3}. +WLSDPLY-30056=The archiveHelper extract all extracted everything from archive file {0} to target directory {1}. +WLSDPLY-30057=Failed to extract everything from archive file {0} to target directory {1}: {2}. +WLSDPLY-30058=Failed to add the RCU wallet from {0} to archive file {1}: {2}. +WLSDPLY-30059=Failed to add the RCU wallet from {0} with overwrite value {1} to archive file {2}: {3}. +WLSDPLY-30060=The archiveHelper remove rcuWallet command removed {0} entries from archive file {1}. +WLSDPLY-30061=Failed to remove RCU database wallet from archive file {0}: {1}. +WLSDPLY-30062=Failed to remove RCU database wallet with force value {0} from archive file {1}: {2}. diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperAddTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperAddTest.java new file mode 100644 index 0000000000..9185d60784 --- /dev/null +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperAddTest.java @@ -0,0 +1,2834 @@ +/* + * Copyright (c) 2023, Oracle Corporation and/or its affiliates. All rights reserved. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.ListIterator; +import java.util.logging.Level; +import java.util.stream.Collectors; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.FileUtils; +import oracle.weblogic.deploy.util.StringUtils; +import oracle.weblogic.deploy.util.WLSDeployArchive; +import oracle.weblogic.deploy.util.WLSDeployArchive.ArchiveEntryType; +import oracle.weblogic.deploy.util.WLSDeployZipFileTest; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_DIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_DIR_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_JAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_JAR_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_CONFIG_FILE_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_FOO_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_FOO_PROPERTIES_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_MYDIR_BAR_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_MYDIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_MYDIR_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLET_RCU_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLET_WALLET1_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLET_WALLET1_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_BIN_SET_USER_OVERRIDES_SH_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_LIB_FOO_JAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_LIB_FOO_JAR_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FILE_STORES_FS1_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FILE_STORES_FS1_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MIME_MAPPING_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MIME_MAPPING_PROPERTIES_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_APP_DEPLOYMENT_PLAN_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_APP_DEPLOYMENT_PLAN_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_APP_WAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_APP_WAR_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_OTHER_APP_DIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_OTHER_APP_DIR_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.NODE_MANAGER_IDENTITY_JKS_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.NODE_MANAGER_IDENTITY_JKS_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.OPSS_WALLET_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SCRIPTS_FANCY_SCRIPT_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SCRIPTS_FANCY_SCRIPT_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SERVERS_ADMIN_SERVER_IDENTITY_JKS_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_LIB_WAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_LIB_WAR_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_LIB_XML_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_LIB_XML_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_OTHER_LIB_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_OTHER_LIB_DUP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APP_WEBAPP_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APP_WEBAPP_DUP_CONTENTS; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ZIP_SEP; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ArchiveHelperAddTest { + public static final File UNIT_TEST_SOURCE_DIR = new File(WLSDeployZipFileTest.UNIT_TEST_SOURCE_DIR); + private static final File UNIT_TEST_TARGET_DIR = + new File(new File(WLSDeployZipFileTest.UNIT_TEST_TARGET_DIR, "archiveHelper"), "add"); + private static final File SOURCE_ROOT_VALUE = FileUtils.getCanonicalFile(UNIT_TEST_TARGET_DIR); + + private static final Path ARCHIVE_HELPER_SOURCE_ZIP = + new File(UNIT_TEST_SOURCE_DIR, "archive-helper-test.zip").toPath(); + private static final Path NEW_ARCHIVE_TARGET_ZIP = + new File(UNIT_TEST_TARGET_DIR, "new-archive.zip").toPath(); + private static final String NEW_ARCHIVE_VALUE = NEW_ARCHIVE_TARGET_ZIP.toFile().getAbsolutePath(); + + private static final String[] EMPTY_ARRAY = new String[0]; + private static final String[] LIST_APPLICATIONS = new String[] { "application" }; + private static final String[] LIST_APPLICATION_PLANS = LIST_APPLICATIONS; + private static final String[] LIST_CLASSPATH_LIBRARIES = new String[] { "classpathLibrary" }; + private static final String[] LIST_COHERENCE_CONFIGS = new String[] { "coherence" }; + private static final String[] LIST_COHERENCE_PERSISTENCE_DIRS = LIST_COHERENCE_CONFIGS; + private static final String[] LIST_CUSTOM = new String[] { "custom" }; + private static final String[] LIST_DATABASE_WALLETS = new String[] { "databaseWallet" }; + private static final String[] LIST_DOMAIN_BIN_SCRIPTS = new String[] { "domainBinScript" }; + private static final String[] LIST_DOMAIN_LIBRARIES = new String[] { "domainLibrary" }; + private static final String[] LIST_FILE_STORES = new String[] { "fileStore" }; + private static final String[] LIST_FOREIGN_SERVERS = new String[] { + "jmsForeignServer", + "-foreign_server_name", + "fs1" + }; + private static final String[] LIST_MIME_MAPPINGS = new String[] { "mimeMapping" }; + private static final String[] LIST_NODE_MANAGER_KEYSTORES = new String[] { "nodeManagerKeystore" }; + private static final String[] LIST_OPSS_WALLET = new String[] { "opssWallet" }; + private static final String[] LIST_RCU_WALLET = new String[] { "rcuWallet" }; + private static final String[] LIST_SCRIPTS = new String[] { "script" }; + private static final String[] LIST_SERVER_KEYSTORES = new String[] { + "serverKeystore", + "-server_name", + "AdminServer" + }; + private static final String[] LIST_SHARED_LIBRARIES = new String[] { "sharedLibrary" }; + private static final String[] LIST_SHARED_LIBRARIES_PLANS = LIST_SHARED_LIBRARIES; + private static final String[] LIST_STRUCTURED_APPLICATIONS = new String[] { "structuredApplication" }; + + @BeforeAll + static void initialize() throws Exception { + PlatformLogger logger = WLSDeployLogFactory.getLogger(LOGGER_NAME); + logger.setLevel(Level.OFF); + + if(!UNIT_TEST_TARGET_DIR.exists() && !UNIT_TEST_TARGET_DIR.mkdirs()) { + throw new Exception("Unable to create unit test directory: " + UNIT_TEST_TARGET_DIR); + } + + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "all", + "-archive_file", + ARCHIVE_HELPER_SOURCE_ZIP.toFile().getAbsolutePath(), + "-target", + FileUtils.getCanonicalPath(UNIT_TEST_TARGET_DIR) + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual, "ArchiveHelperAddTest initialization failed."); + } + + @BeforeEach + void setup() throws Exception { + File targetArchiveFile = NEW_ARCHIVE_TARGET_ZIP.toFile(); + if (targetArchiveFile.exists() && !targetArchiveFile.delete()) { + throw new Exception("setup() failed to delete file " + targetArchiveFile.getPath()); + } + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // parameterized // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @ParameterizedTest + @CsvSource({ + "application, missing.war", + "applicationPlan, missing.xml", + "classpathLibrary, missing.jar", + "coherenceConfig, missing.xml", + "custom, missing", + "databaseWallet, missing", + "domainBinScript, missing.sh", + "domainLibrary, missing.jar", + "jmsForeignServer, missing.properties", + "mimeMapping, missing.properties", + "nodeManagerKeystore, missing.jks", + "opssWallet, missing.zip", + "rcuWallet, missing", + "script, missing.sh", + "serverKeystore, missing.jks", + "sharedLibrary, missing.war", + "sharedLibraryPlan, missing.xml", + "structuredApplication, missing" + }) + void testAddNoArchive_Fails(String subcommand, String source) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + subcommand, + "-source", + source + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @ParameterizedTest + @ValueSource(strings = { + "application", + "applicationPlan", + "classpathLibrary", + "coherenceConfig", + "custom", + "databaseWallet", + "domainBinScript", + "domainLibrary", + "jmsForeignServer", + "mimeMapping", + "nodeManagerKeystore", + "opssWallet", + "rcuWallet", + "script", + "serverKeystore", + "sharedLibrary", + "sharedLibraryPlan", + "structuredApplication" + }) + void testAddNoSource_Fails(String subcommand) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + subcommand, + "-archive_file", + NEW_ARCHIVE_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @ParameterizedTest + @CsvSource({ + "application, missing.war", + "applicationPlan, missing.xml", + "classpathLibrary, missing.jar", + "custom, missing", + "domainBinScript, missing.sh", + "domainLibrary, missing.jar", + "mimeMapping, missing.properties", + "nodeManagerKeystore, missing.jks", + "opssWallet, missing.zip", + "rcuWallet, missing", + "script, missing.sh", + "sharedLibrary, missing.war", + "sharedLibraryPlan, missing.xml", + "structuredApplication, missing" + }) + void testAddBadSource_Fails(String subcommand, String source) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + subcommand, + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + source + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.ARG_VALIDATION_ERROR, actual, + "expected command to exit with exit code " + ExitCode.ARG_VALIDATION_ERROR); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // application // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewApplicationFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "application", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.APPLICATION, "my-app.war") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, EMPTY_ARRAY, MY_APP_WAR_CONTENTS); + } + + @Test + void testAddApplicationFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "application", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.APPLICATION, "my-app.war") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, EMPTY_ARRAY, MY_APP_WAR_CONTENTS); + } + + @Test + void testAddApplicationFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "application", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.APPLICATION, "my-app.war") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, EMPTY_ARRAY, MY_APP_WAR_CONTENTS, MY_APP_WAR_DUP_CONTENTS); + } + + @Test + void testAddNewApplicationDir_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "application", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.APPLICATION, "my-other-app") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, EMPTY_ARRAY, MY_OTHER_APP_DIR_CONTENTS); + } + + @Test + void testAddApplicationDirOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "application", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.APPLICATION, "my-other-app") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, EMPTY_ARRAY, MY_OTHER_APP_DIR_CONTENTS); + } + + @Test + void testAddApplicationDirTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "application", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.APPLICATION, "my-other-app") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATIONS, EMPTY_ARRAY, MY_OTHER_APP_DIR_CONTENTS, + MY_OTHER_APP_DIR_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // application plan // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewApplicationPlanFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "applicationPlan", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.APPLICATION_PLAN, "my-app.xml") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATION_PLANS, EMPTY_ARRAY, MY_APP_DEPLOYMENT_PLAN_CONTENTS); + } + + @Test + void testAddApplicationPlanFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "applicationPlan", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.APPLICATION_PLAN, "my-app.xml") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATION_PLANS, EMPTY_ARRAY, MY_APP_DEPLOYMENT_PLAN_CONTENTS); + } + + @Test + void testAddApplicationPlanFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "applicationPlan", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.APPLICATION_PLAN, "my-app.xml") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_APPLICATION_PLANS, EMPTY_ARRAY, MY_APP_DEPLOYMENT_PLAN_CONTENTS, + MY_APP_DEPLOYMENT_PLAN_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // classpath library // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewClasspathLibraryFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "classpathLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CLASSPATH_LIB, "bar.jar") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, EMPTY_ARRAY, CLASSPATH_LIB_BAR_JAR_CONTENTS); + } + + @Test + void testAddClasspathLibraryFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "classpathLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CLASSPATH_LIB, "bar.jar") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, EMPTY_ARRAY, CLASSPATH_LIB_BAR_JAR_CONTENTS); + } + + @Test + void testAddClasspathLibraryFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "classpathLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CLASSPATH_LIB, "bar.jar") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, EMPTY_ARRAY, CLASSPATH_LIB_BAR_JAR_CONTENTS, + CLASSPATH_LIB_BAR_JAR_DUP_CONTENTS); + } + + @Test + void testAddNewClasspathLibraryDir_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "classpathLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CLASSPATH_LIB, "bar") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, EMPTY_ARRAY, CLASSPATH_LIB_BAR_DIR_CONTENTS); + } + + @Test + void testAddClasspathLibraryDirOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "classpathLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CLASSPATH_LIB, "bar") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, EMPTY_ARRAY, CLASSPATH_LIB_BAR_DIR_CONTENTS); + } + + @Test + void testAddClasspathLibraryDirTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "classpathLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CLASSPATH_LIB, "bar") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, EMPTY_ARRAY, CLASSPATH_LIB_BAR_DIR_CONTENTS, + CLASSPATH_LIB_BAR_DIR_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Coherence config // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddCoherenceConfigBadSource_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherenceConfig", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-cluster_name", + "mycluster", + "-source", + "missing.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.ARG_VALIDATION_ERROR, actual, + "expected command to exit with exit code " + ExitCode.ARG_VALIDATION_ERROR); + } + + @Test + void testAddCoherenceConfigNoCluster_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherenceConfig", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + "missing.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testAddNewCoherenceConfigFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherenceConfig", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-cluster_name", + "mycluster", + "-source", + getSegregatedSourcePath(ArchiveEntryType.COHERENCE_CONFIG, "mycluster", "cache-config.xml") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_CONFIGS, EMPTY_ARRAY, COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS); + } + + @Test + void testAddCoherenceConfigFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherenceConfig", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-cluster_name", + "mycluster", + "-source", + getSegregatedSourcePath(ArchiveEntryType.COHERENCE_CONFIG, "mycluster", "cache-config.xml") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_CONFIGS, EMPTY_ARRAY, COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS); + } + + @Test + void testAddCoherenceConfigFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherenceConfig", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-cluster_name", + "mycluster", + "-source", + getSegregatedSourcePath(ArchiveEntryType.COHERENCE_CONFIG, "mycluster", "cache-config.xml") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_CONFIGS, EMPTY_ARRAY, COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS, + COHERENCE_MYCLUSTER_CONFIG_FILE_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Coherence persistence dir // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddCoherencePersistenceDirNoType_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherencePersistenceDir", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-cluster_name", + "mycluster" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testAddCoherencePersistenceDirNoCluster_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherencePersistenceDir", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + "missing.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testAddNewCoherencePersistenceDir_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherencePersistenceDir", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-cluster_name", + "mycluster", + "-type", + "active" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_PERSISTENCE_DIRS, EMPTY_ARRAY, + COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS); + } + + @Test + void testAddCoherencePersistenceDirOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherencePersistenceDir", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-cluster_name", + "mycluster", + "-type", + "active" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_PERSISTENCE_DIRS, EMPTY_ARRAY, + COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS); + } + + @Test + void testAddCoherencePersistenceDirTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "coherencePersistenceDir", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-cluster_name", + "mycluster", + "-type", + "active" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_COHERENCE_PERSISTENCE_DIRS, EMPTY_ARRAY, + COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS, + COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // custom // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewCustomFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "custom", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CUSTOM, "foo.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM, EMPTY_ARRAY, CUSTOM_FOO_PROPERTIES_CONTENTS); + } + + @Test + void testAddNewCustomNestedFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "custom", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-path", + "mydir", + "-source", + getSourcePath(ArchiveEntryType.CUSTOM, "mydir/bar.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM, EMPTY_ARRAY, CUSTOM_MYDIR_BAR_PROPERTIES_CONTENTS); + } + + @Test + void testAddCustomFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "custom", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CUSTOM, "foo.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM, EMPTY_ARRAY, CUSTOM_FOO_PROPERTIES_CONTENTS); + } + + @Test + void testAddCustomFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "custom", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CUSTOM, "foo.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM, EMPTY_ARRAY, CUSTOM_FOO_PROPERTIES_CONTENTS, + CUSTOM_FOO_PROPERTIES_DUP_CONTENTS); + } + + @Test + void testAddNewCustomDir_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "custom", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CUSTOM, "mydir") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM, EMPTY_ARRAY, CUSTOM_MYDIR_CONTENTS); + } + + @Test + void testAddCustomDirOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "custom", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CUSTOM, "mydir") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM, EMPTY_ARRAY, CUSTOM_MYDIR_CONTENTS); + } + + @Test + void testAddCustomDirTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "custom", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.CUSTOM, "mydir") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CUSTOM, EMPTY_ARRAY, CUSTOM_MYDIR_CONTENTS, CUSTOM_MYDIR_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // database wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddDatabaseWalletNoWalletName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "databaseWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + "missing" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testAddDatabaseWalletBadSource_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "databaseWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-wallet_name", + "wallet1", + "-source", + "missing" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.ARG_VALIDATION_ERROR, actual, + "expected command to exit with exit code " + ExitCode.ARG_VALIDATION_ERROR); + } + + + @Test + void testAddNewDatabaseWalletDir_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "databaseWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-wallet_name", + "wallet1", + "-source", + getSourcePath(ArchiveEntryType.DB_WALLET, "wallet1") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DATABASE_WALLETS, EMPTY_ARRAY, DATABASE_WALLET_WALLET1_CONTENTS); + } + + @Test + void testAddDatabaseWalletDirOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "databaseWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-wallet_name", + "wallet1", + "-source", + getSourcePath(ArchiveEntryType.DB_WALLET, "wallet1") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DATABASE_WALLETS, EMPTY_ARRAY, DATABASE_WALLET_WALLET1_CONTENTS); + } + + @Test + void testAddDatabaseWalletDirTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "databaseWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-wallet_name", + "wallet1", + "-source", + getSourcePath(ArchiveEntryType.DB_WALLET, "wallet1") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DATABASE_WALLETS, EMPTY_ARRAY, DATABASE_WALLET_WALLET1_CONTENTS, + DATABASE_WALLET_WALLET1_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // $DOMAIN_HOME/bin script // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewDomainBinFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "domainBinScript", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.DOMAIN_BIN, "setUserOverrides.sh") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DOMAIN_BIN_SCRIPTS, EMPTY_ARRAY, DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS); + } + + @Test + void testAddDomainBinFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "domainBinScript", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.DOMAIN_BIN, "setUserOverrides.sh") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DOMAIN_BIN_SCRIPTS, EMPTY_ARRAY, DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS); + } + + @Test + void testAddDomainBinFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "domainBinScript", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.DOMAIN_BIN, "setUserOverrides.sh") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DOMAIN_BIN_SCRIPTS, EMPTY_ARRAY, DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS, + DOMAIN_BIN_SET_USER_OVERRIDES_SH_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // $DOMAIN_HOME/lib library // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewDomainLibFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "domainLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.DOMAIN_LIB, "foo.jar") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DOMAIN_LIBRARIES, EMPTY_ARRAY, DOMAIN_LIB_FOO_JAR_CONTENTS); + } + + @Test + void testAddDomainLibFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "domainLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.DOMAIN_LIB, "foo.jar") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DOMAIN_LIBRARIES, EMPTY_ARRAY, DOMAIN_LIB_FOO_JAR_CONTENTS); + } + + @Test + void testAddDomainLibFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "domainLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.DOMAIN_LIB, "foo.jar") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_DOMAIN_LIBRARIES, EMPTY_ARRAY, DOMAIN_LIB_FOO_JAR_CONTENTS, + DOMAIN_LIB_FOO_JAR_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // file store // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddFileStoreNoArchive_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "fileStore", + "-name", + "fs1" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testAddFileStoreNoName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "fileStore", + "-archive_file", + NEW_ARCHIVE_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testAddNewFileStoreDir_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "fileStore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-name", + "fs1" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FILE_STORES, EMPTY_ARRAY, FILE_STORES_FS1_CONTENTS); + } + + @Test + void testAddFileStoreDirOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "fileStore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-name", + "fs1" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FILE_STORES, EMPTY_ARRAY, FILE_STORES_FS1_CONTENTS); + } + + @Test + void testAddFileStoreDirTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "fileStore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-name", + "fs1" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FILE_STORES, EMPTY_ARRAY, FILE_STORES_FS1_CONTENTS, + FILE_STORES_FS1_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // JMS Foreign Server binding // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddForeignServerBindingNoForeignServerName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "jmsForeignServer", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + "missing" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testAddForeignServerBindingBadSource_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "jmsForeignServer", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-foreign_server_name", + "fs1", + "-source", + "missing" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.ARG_VALIDATION_ERROR, actual, + "expected command to exit with exit code " + ExitCode.ARG_VALIDATION_ERROR); + } + + @Test + void testAddNewForeignServerBinding_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "jmsForeignServer", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-foreign_server_name", + "fs1", + "-source", + getSegregatedSourcePath(ArchiveEntryType.JMS_FOREIGN_SERVER, "fs1", "jndi.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FOREIGN_SERVERS, EMPTY_ARRAY, FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_CONTENTS); + } + + @Test + void testAddForeignServerBindingOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "jmsForeignServer", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-foreign_server_name", + "fs1", + "-source", + getSegregatedSourcePath(ArchiveEntryType.JMS_FOREIGN_SERVER, "fs1", "jndi.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FOREIGN_SERVERS, EMPTY_ARRAY, FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_CONTENTS); + } + + @Test + void testAddForeignServerBindingTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "jmsForeignServer", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-foreign_server_name", + "fs1", + "-source", + getSegregatedSourcePath(ArchiveEntryType.JMS_FOREIGN_SERVER, "fs1", "jndi.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_FOREIGN_SERVERS, EMPTY_ARRAY, FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_CONTENTS, + FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // MIME mapping // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewMIMEMappingFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "mimeMapping", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.MIME_MAPPING, "mimemappings.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_MIME_MAPPINGS, EMPTY_ARRAY, MIME_MAPPING_PROPERTIES_CONTENTS); + } + + @Test + void testAddMIMEMappingFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "mimeMapping", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.MIME_MAPPING, "mimemappings.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_MIME_MAPPINGS, EMPTY_ARRAY, MIME_MAPPING_PROPERTIES_CONTENTS); + } + + @Test + void testAddMIMEMappingFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "mimeMapping", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.MIME_MAPPING, "mimemappings.properties") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_MIME_MAPPINGS, EMPTY_ARRAY, MIME_MAPPING_PROPERTIES_CONTENTS, + MIME_MAPPING_PROPERTIES_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // node manager keystore // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewNodeManagerKeystore_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "nodeManagerKeystore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.NODE_MANAGER_KEY_STORE, "nmIdentity.jks") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_NODE_MANAGER_KEYSTORES, EMPTY_ARRAY, NODE_MANAGER_IDENTITY_JKS_CONTENTS); + } + + @Test + void testAddNodeManagerKeystoreOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "nodeManagerKeystore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.NODE_MANAGER_KEY_STORE, "nmIdentity.jks") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_NODE_MANAGER_KEYSTORES, EMPTY_ARRAY, NODE_MANAGER_IDENTITY_JKS_CONTENTS); + } + + @Test + void testAddNodeManagerKeystoreTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "nodeManagerKeystore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.NODE_MANAGER_KEY_STORE, "nmIdentity.jks") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_NODE_MANAGER_KEYSTORES, EMPTY_ARRAY, NODE_MANAGER_IDENTITY_JKS_CONTENTS, + NODE_MANAGER_IDENTITY_JKS_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // OPSS wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewOPSSWallet_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "opssWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.OPSS_WALLET, "opss-wallet.zip") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_OPSS_WALLET, EMPTY_ARRAY, OPSS_WALLET_CONTENT); + } + + @Test + void testAddOPSSWalletOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "opssWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.OPSS_WALLET, "opss-wallet.zip") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_OPSS_WALLET, EMPTY_ARRAY, OPSS_WALLET_CONTENT); + } + + @Test + void testAddOPSSWalletTwice_Fails() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "opssWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.OPSS_WALLET, "opss-wallet.zip") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.ERROR, actual, "expected command to return " + ExitCode.ERROR); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // RCU wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewRCUWallet_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "rcuWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.RCU_WALLET, "") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_RCU_WALLET, EMPTY_ARRAY, DATABASE_WALLET_RCU_CONTENTS); + } + + @Test + void testAddRCUWalletOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "rcuWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.RCU_WALLET, "") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_RCU_WALLET, EMPTY_ARRAY, DATABASE_WALLET_RCU_CONTENTS); + } + + @Test + void testAddRCUWalletTwice_Fails() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "rcuWallet", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.RCU_WALLET, "") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.ERROR, actual, "expected command to return " + ExitCode.ERROR); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // script // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewScript_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "script", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SCRIPT, "my_fancy_script.sh") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SCRIPTS, EMPTY_ARRAY, SCRIPTS_FANCY_SCRIPT_CONTENTS); + } + + @Test + void testAddScriptOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "script", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SCRIPT, "my_fancy_script.sh") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SCRIPTS, EMPTY_ARRAY, SCRIPTS_FANCY_SCRIPT_CONTENTS); + } + + @Test + void testAddScriptTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "script", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SCRIPT, "my_fancy_script.sh") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SCRIPTS, EMPTY_ARRAY, SCRIPTS_FANCY_SCRIPT_CONTENTS, + SCRIPTS_FANCY_SCRIPT_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // server keystore // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddServerKeystoreNoServerName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "serverKeystore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + "missing" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testAddServerKeystoreBadSource_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "serverKeystore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-server_name", + "AdminServer", + "-source", + "missing" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.ARG_VALIDATION_ERROR, actual, + "expected command to exit with exit code " + ExitCode.ARG_VALIDATION_ERROR); + } + + @Test + void testAddNewServerKeystore_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "serverKeystore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-server_name", + "AdminServer", + "-source", + getSegregatedSourcePath(ArchiveEntryType.SERVER_KEYSTORE, "AdminServer", "identity.jks") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SERVER_KEYSTORES, EMPTY_ARRAY, SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS); + } + + @Test + void testAddServerKeystoreOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "serverKeystore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-server_name", + "AdminServer", + "-source", + getSegregatedSourcePath(ArchiveEntryType.SERVER_KEYSTORE, "AdminServer", "identity.jks") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SERVER_KEYSTORES, EMPTY_ARRAY, SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS); + } + + @Test + void testAddServerKeystoreTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "serverKeystore", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-server_name", + "AdminServer", + "-source", + getSegregatedSourcePath(ArchiveEntryType.SERVER_KEYSTORE, "AdminServer", "identity.jks") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SERVER_KEYSTORES, EMPTY_ARRAY, SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS, + SERVERS_ADMIN_SERVER_IDENTITY_JKS_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // shared library // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewSharedLibraryFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "sharedLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SHARED_LIBRARY, "my-lib.war") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, EMPTY_ARRAY, SHARED_LIBS_MY_LIB_WAR_CONTENTS); + } + + @Test + void testAddSharedLibraryFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "sharedLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SHARED_LIBRARY, "my-lib.war") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, EMPTY_ARRAY, SHARED_LIBS_MY_LIB_WAR_CONTENTS); + } + + @Test + void testAddSharedLibraryFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "sharedLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SHARED_LIBRARY, "my-lib.war") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, EMPTY_ARRAY, SHARED_LIBS_MY_LIB_WAR_CONTENTS, + SHARED_LIBS_MY_LIB_WAR_DUP_CONTENTS); + } + + @Test + void testAddNewSharedLibraryDir_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "sharedLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SHARED_LIBRARY, "my-other-lib") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, EMPTY_ARRAY, SHARED_LIBS_MY_OTHER_LIB_CONTENTS); + } + + @Test + void testAddSharedLibraryDirOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "sharedLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SHARED_LIBRARY, "my-other-lib") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, EMPTY_ARRAY, SHARED_LIBS_MY_OTHER_LIB_CONTENTS); + } + + @Test + void testAddSharedLibraryDirTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "sharedLibrary", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SHARED_LIBRARY, "my-other-lib") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES, EMPTY_ARRAY, SHARED_LIBS_MY_OTHER_LIB_CONTENTS, + SHARED_LIBS_MY_OTHER_LIB_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // shared library plan // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewSharedLibraryPlanFile_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "sharedLibraryPlan", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SHLIB_PLAN, "my-lib.xml") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES_PLANS, EMPTY_ARRAY, SHARED_LIBS_MY_LIB_XML_CONTENTS); + } + + @Test + void testAddSharedLibraryPlanFileOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "sharedLibraryPlan", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SHLIB_PLAN, "my-lib.xml") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES_PLANS, EMPTY_ARRAY, SHARED_LIBS_MY_LIB_XML_CONTENTS); + } + + @Test + void testAddSharedLibraryPlanFileTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "sharedLibraryPlan", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.SHLIB_PLAN, "my-lib.xml") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_SHARED_LIBRARIES_PLANS, EMPTY_ARRAY, SHARED_LIBS_MY_LIB_XML_CONTENTS, + SHARED_LIBS_MY_LIB_XML_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // structured application // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testAddNewStructuredApplication_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "structuredApplication", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.STRUCTURED_APPLICATION, "webapp") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_STRUCTURED_APPLICATIONS, EMPTY_ARRAY, STRUCTURED_APP_WEBAPP_CONTENTS); + } + + @Test + void testAddStructuredApplicationOverwrite_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "structuredApplication", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.STRUCTURED_APPLICATION, "webapp") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + String[] overwriteArgs = getOverwriteArgs(args); + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, overwriteArgs); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_STRUCTURED_APPLICATIONS, EMPTY_ARRAY, STRUCTURED_APP_WEBAPP_CONTENTS); + } + + @Test + void testAddStructuredApplicationTwice_ReturnsExceptedResult() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "add", + "structuredApplication", + "-archive_file", + NEW_ARCHIVE_VALUE, + "-source", + getSourcePath(ArchiveEntryType.STRUCTURED_APPLICATION, "webapp") + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to return " + ExitCode.OK); + assertArchiveInExpectedState(LIST_STRUCTURED_APPLICATIONS, EMPTY_ARRAY, STRUCTURED_APP_WEBAPP_CONTENTS, + STRUCTURED_APP_WEBAPP_DUP_CONTENTS); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // private helper methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + private String getSourcePath(ArchiveEntryType type, String sourceName) { + String relativePath = WLSDeployArchive.getPathForType(type) + sourceName; + File result = new File(SOURCE_ROOT_VALUE, relativePath); + return FileUtils.getCanonicalPath(result); + } + + private String getSegregatedSourcePath(ArchiveEntryType type, String segregationName, String sourceName) { + String relativePath = WLSDeployArchive.getPathForSegregationType(type, segregationName) + sourceName; + File result = new File(SOURCE_ROOT_VALUE, relativePath); + return FileUtils.getCanonicalPath(result); + } + + private void assertArchiveInExpectedState(String[] actualArgs, String[] originalContent, + String[]... addedContent) throws Exception { + String[] args = new String[actualArgs.length + 3]; + args[0] = "list"; + System.arraycopy(actualArgs, 0, args, 1, actualArgs.length); + args[actualArgs.length + 1] = "-archive_file"; + args[actualArgs.length + 2] = NEW_ARCHIVE_VALUE; + + List actualEntries = getActualEntries(args); + List expectedEntries = getExpectedEntries(originalContent, addedContent); + assertEquals(expectedEntries.size(), actualEntries.size(), "expected zip file to contain " + + expectedEntries.size()); + for (String actualLine : actualEntries) { + assertTrue(expectedEntries.contains(actualLine), actualLine + " not in expected output"); + } + } + + private List getActualEntries(String... args) throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + if (actual != ExitCode.OK) { + throw new ArchiveHelperException(actual, + "Failed to get actual entries for args = {0}", Arrays.toString(args)); + } + } + + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + if (outputLines.length == 0 || (outputLines.length == 1 && StringUtils.isEmpty(outputLines[0]))) { + return new ArrayList<>(); + } else { + return Arrays.asList(outputLines); + } + } + + private List getExpectedEntries(String[] expected, String[]... addLists) { + List expectedPaths = new ArrayList<>(Arrays.asList(expected)); + + for (String[] addList : addLists) { + Collections.addAll(expectedPaths, addList); + } + return removeEmptyIntermediateDirectories(expectedPaths); + } + + private List removeEmptyIntermediateDirectories(List entries) { + List directoryList = entries.stream().filter(s -> s.endsWith(ZIP_SEP)).collect(Collectors.toList()); + + ListIterator directoryIterator = directoryList.listIterator(); + while (directoryIterator.hasNext()) { + String directory = directoryIterator.next(); + + boolean removeFromList = true; + for (String entry : entries) { + if (!entry.equals(directory) && entry.startsWith(directory)) { + removeFromList = false; + break; + } + } + if (removeFromList) { + directoryIterator.remove(); + } + } + + List results = new ArrayList<>(entries); + results.removeAll(directoryList); + return results; + } + + private String[] getOverwriteArgs(String[] args) { + String[] result = new String[args.length + 1]; + System.arraycopy(args, 0, result, 0, args.length); + result[args.length] = "-overwrite"; + return result; + } +} diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperExtractTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperExtractTest.java new file mode 100644 index 0000000000..3fdc8d72e7 --- /dev/null +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperExtractTest.java @@ -0,0 +1,1362 @@ +/* + * Copyright (c) 2023, Oracle Corporation and/or its affiliates. All rights reserved. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; + +import oracle.weblogic.deploy.logging.PlatformLogger; +import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.util.ExitCode; +import oracle.weblogic.deploy.util.FileUtils; +import oracle.weblogic.deploy.util.WLSDeployZipFileTest; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; + +import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.ALL_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_DIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_JAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_FOO_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CUSTOM_MYDIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLET_RCU_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DATABASE_WALLET_WALLET1_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.DOMAIN_LIB_FOO_JAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MIME_MAPPING_PROPERTIES_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_APP_DEPLOYMENT_PLAN_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_OTHER_APP_DIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.MY_OTHER_APP_WAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.NODE_MANAGER_IDENTITY_JKS_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.OPSS_WALLET_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SCRIPTS_FANCY_SCRIPT_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_LIB_WAR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_LIB_XML_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.SHARED_LIBS_MY_OTHER_LIB_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.STRUCTURED_APP_WEBAPP_CONTENTS; +import static oracle.weblogic.deploy.util.WLSDeployArchive.DEFAULT_RCU_WALLET_NAME; +import static oracle.weblogic.deploy.util.WLSDeployArchive.ZIP_SEP; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ArchiveHelperExtractTest { + public static final File UNIT_TEST_SOURCE_DIR = new File(WLSDeployZipFileTest.UNIT_TEST_SOURCE_DIR); + private static final File UNIT_TEST_TARGET_DIR = + new File(new File(WLSDeployZipFileTest.UNIT_TEST_TARGET_DIR, "archiveHelper"), "extract"); + private static final String TARGET_VALUE = FileUtils.getCanonicalPath(UNIT_TEST_TARGET_DIR); + private static final File WLSDEPLOY_TARGET_DIR = new File(UNIT_TEST_TARGET_DIR, "wlsdeploy"); + + private static final Path ARCHIVE_HELPER_SOURCE_ZIP = + new File(UNIT_TEST_SOURCE_DIR, "archive-helper-test.zip").toPath(); + private static final Path ARCHIVE_HELPER_TARGET_ZIP = + new File(UNIT_TEST_TARGET_DIR, "archive-helper-test.zip").toPath(); + private static final String ARCHIVE_HELPER_VALUE = ARCHIVE_HELPER_TARGET_ZIP.toFile().getAbsolutePath(); + + @BeforeAll + static void initialize() throws Exception { + if(!UNIT_TEST_TARGET_DIR.exists() && !UNIT_TEST_TARGET_DIR.mkdirs()) { + throw new Exception("Unable to create unit test directory: " + UNIT_TEST_TARGET_DIR); + } + Files.copy(ARCHIVE_HELPER_SOURCE_ZIP, ARCHIVE_HELPER_TARGET_ZIP, StandardCopyOption.REPLACE_EXISTING); + + PlatformLogger logger = WLSDeployLogFactory.getLogger(LOGGER_NAME); + logger.setLevel(Level.OFF); + } + + @BeforeEach + void setup() { + if (WLSDEPLOY_TARGET_DIR.exists()) { + FileUtils.deleteDirectory(WLSDEPLOY_TARGET_DIR); + } + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // parameterized // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @ParameterizedTest + @CsvSource({ + "application, missing.war", + "applicationPlan, missing.xml", + "classpathLibrary, missing.jar", + "coherenceConfig, missing.xml", + "coherencePersistenceDir, missing", + "custom, missing", + "databaseWallet, missing", + "domainBinScript, missing.sh", + "domainLibrary, missing.jar", + "fileStore, missing", + "jmsForeignServer, missing.properties", + "mimeMapping, missing.properties", + "nodeManagerKeystore, missing.jks", + "script, missing.sh", + "serverKeystore, missing.jks", + "sharedLibrary, missing.war", + "sharedLibraryPlan, missing.xml", + "structuredApplication, missing" + }) + void testExtractNoArchive_Fails(String subcommand, String name) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + subcommand, + "-target", + TARGET_VALUE, + "-name", + name + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @ParameterizedTest + @CsvSource({ + "application, missing.war", + "applicationPlan, missing.xml", + "classpathLibrary, missing.jar", + "coherenceConfig, missing.xml", + "coherencePersistenceDir, missing", + "custom, missing", + "databaseWallet, missing", + "domainBinScript, missing.sh", + "domainLibrary, missing.jar", + "fileStore, missing", + "jmsForeignServer, missing.properties", + "mimeMapping, missing.properties", + "nodeManagerKeystore, missing.jks", + "script, missing.sh", + "serverKeystore, missing.jks", + "sharedLibrary, missing.war", + "sharedLibraryPlan, missing.xml", + "structuredApplication, missing" + }) + void testExtractNoTarget_Fails(String subcommand, String name) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + subcommand, + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + name + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @ParameterizedTest + @ValueSource(strings = { + "application", + "applicationPlan", + "classpathLibrary", + "coherenceConfig", + "coherencePersistenceDir", + "custom", + "databaseWallet", + "domainBinScript", + "domainLibrary", + "fileStore", + "jmsForeignServer", + "mimeMapping", + "nodeManagerKeystore", + "script", + "serverKeystore", + "sharedLibrary", + "sharedLibraryPlan", + "structuredApplication" + }) + void testExtractNoName_Fails(String subcommand) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + subcommand, + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @ParameterizedTest + @CsvSource({ + "application, missing.war", + "applicationPlan, missing.xml", + "classpathLibrary, missing.jar", + "custom, missing", + "databaseWallet, missing", + "domainBinScript, missing.sh", + "domainLibrary, missing.jar", + "fileStore, missing", + "mimeMapping, missing.properties", + "nodeManagerKeystore, missing.jks", + "script, missing.sh", + "sharedLibrary, missing.war", + "sharedLibraryPlan, missing.xml", + "structuredApplication, missing" + }) + void testExtractBadName_Fails(String subcommand, String name) { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + subcommand, + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + name + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual, + "expected command to exit with exit code " + ExitCode.ERROR); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // all // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractAllNoArchive_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "all", + "-target", + TARGET_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testExtractAllNoTarget_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "all", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testExtractAll_ProducesExpectedResults() { + assertExtractDirectoryIsClean(); + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "all", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE + }; + List expectedPaths = Arrays.asList(ALL_CONTENT); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // application // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingApplicationFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "application", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "my-other-app.war" + }; + List expectedPaths = Arrays.asList(MY_OTHER_APP_WAR_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + @Test + void testExtractExistingApplicationDir_ProducesExpectedResults() { + assertExtractDirectoryIsClean(); + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "application", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "my-other-app" + }; + List expectedPaths = Arrays.asList(MY_OTHER_APP_DIR_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // application plan // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingApplicationPlanFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "applicationPlan", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "my-app.xml" + }; + List expectedPaths = Arrays.asList(MY_APP_DEPLOYMENT_PLAN_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // classpath library // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingClasspathLibraryFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "classpathLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "bar.jar" + }; + List expectedPaths = Arrays.asList(CLASSPATH_LIB_BAR_JAR_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + @Test + void testExtractExistingClasspathLibraryDir_ProducesExpectedResults() { + assertExtractDirectoryIsClean(); + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "classpathLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "bar" + }; + List expectedPaths = Arrays.asList(CLASSPATH_LIB_BAR_DIR_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Coherence config // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractCoherenceConfigBadClusterName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "coherenceConfig", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-cluster_name", + "missing", + "-name", + "cache-config.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual, + "expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testExtractCoherenceConfigBadName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "coherenceConfig", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-cluster_name", + "mycluster", + "-name", + "missing.xml" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual, + "expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testExtractExistingCoherenceConfigFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "coherenceConfig", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-cluster_name", + "mycluster", + "-name", + "cache-config.xml" + }; + List expectedPaths = Arrays.asList(COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Coherence persistence directory // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractCoherencePersistenceDirBadClusterName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "coherencePersistenceDir", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-cluster_name", + "missing", + "-name", + "active" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual, + "expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testExtractCoherencePersistenceDirBadName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "coherencePersistenceDir", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-cluster_name", + "mycluster", + "-name", + "missing" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual, + "expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testExtractExistingCoherencePersistenceDir_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "coherencePersistenceDir", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-cluster_name", + "mycluster", + "-name", + "active" + }; + List expectedPaths = Arrays.asList(COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // custom // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingCustomFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "custom", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "foo.properties" + }; + List expectedPaths = Arrays.asList(CUSTOM_FOO_PROPERTIES_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + @Test + void testExtractExistingCustomDir_ProducesExpectedResults() { + assertExtractDirectoryIsClean(); + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "custom", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "mydir" + }; + List expectedPaths = Arrays.asList(CUSTOM_MYDIR_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // database wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingDatabaseWalletFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "databaseWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "wallet1" + }; + List expectedPaths = Arrays.asList(DATABASE_WALLET_WALLET1_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + @Test + void testExtractExistingDatabaseWalletDir_ProducesExpectedResults() { + assertExtractDirectoryIsClean(); + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "databaseWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + DEFAULT_RCU_WALLET_NAME + }; + List expectedPaths = Arrays.asList(DATABASE_WALLET_RCU_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // $DOMAIN_HOME/bin script // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingDomainBinScript_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "domainBinScript", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "setUserOverrides.sh" + }; + List expectedPaths = Arrays.asList(DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // $DOMAIN_HOME/lib library // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingDomainLibraryFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "domainLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "foo.jar" + }; + List expectedPaths = Arrays.asList(DOMAIN_LIB_FOO_JAR_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // JMS Foreign Server binding // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractForeignServerBindingBadForeignServerName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "jmsForeignServer", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-foreign_server_name", + "missing", + "-name", + "jndi.properties" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual, + "expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testExtractForeignServerBindingBadName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "jmsForeignServer", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-foreign_server_name", + "fs1", + "-name", + "missing.properties" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual, + "expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testExtractExistingForeignServerBindingFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "jmsForeignServer", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-foreign_server_name", + "fs1", + "-name", + "jndi.properties" + }; + List expectedPaths = Arrays.asList(FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // MIME mapping // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingMIMEMappingFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "mimeMapping", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "mimemappings.properties" + }; + List expectedPaths = Arrays.asList(MIME_MAPPING_PROPERTIES_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.OK, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // node manager keystore // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingNodeManagerKeystoreFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "nodeManagerKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "nmIdentity.jks" + }; + List expectedPaths = Arrays.asList(NODE_MANAGER_IDENTITY_JKS_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // OPSS wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractOPSSWalletNoArchive_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "opssWallet", + "-target", + TARGET_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testExtractOPSSWalletNoTarget_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "opssWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testExtractExistingOPSSWallet_ProducesExpectedResults() { + assertExtractDirectoryIsClean(); + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "opssWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE + }; + List expectedPaths = Arrays.asList(OPSS_WALLET_CONTENT); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // RCU wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractRCUWalletNoArchive_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "rcuWallet", + "-target", + TARGET_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testExtractRCUWalletNoTarget_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "rcuWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(ExitCode.USAGE_ERROR, actual, + "expected command to exit with exit code " + ExitCode.USAGE_ERROR); + } + + @Test + void testExtractExistingRCUWallet_ProducesExpectedResults() { + assertExtractDirectoryIsClean(); + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "rcuWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE + }; + List expectedPaths = Arrays.asList(DATABASE_WALLET_RCU_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // script // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingScriptFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "script", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "my_fancy_script.sh" + }; + List expectedPaths = Arrays.asList(SCRIPTS_FANCY_SCRIPT_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // server keystore // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractServerKeystoreBadServerName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-server_name", + "missing", + "-name", + "identity.jks" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual, + "expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testExtractServerKeystoreBadName_Fails() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-server_name", + "AdminServer", + "-name", + "missing.jks" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.ERROR, actual, + "expected command to exit with exit code " + ExitCode.ERROR); + } + + @Test + void testExtractExistingServerKeystoreFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "serverKeystore", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-server_name", + "AdminServer", + "-name", + "identity.jks" + }; + List expectedPaths = Arrays.asList(SERVERS_ADMIN_SERVER_IDENTITY_JKS_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // shared library // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingSharedLibraryFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "my-lib.war" + }; + List expectedPaths = Arrays.asList(SHARED_LIBS_MY_LIB_WAR_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + @Test + void testExtractExistingSharedLibraryDir_ProducesExpectedResults() { + assertExtractDirectoryIsClean(); + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "my-other-lib" + }; + List expectedPaths = Arrays.asList(SHARED_LIBS_MY_OTHER_LIB_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // shared library plan // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingSharedLibraryPlanFile_ProducesExpectedResults() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "sharedLibraryPlan", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "my-lib.xml" + }; + List expectedPaths = Arrays.asList(SHARED_LIBS_MY_LIB_XML_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // structured application // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testExtractExistingStructuredApplicationDir_ProducesExpectedResults() { + assertExtractDirectoryIsClean(); + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "extract", + "structuredApplication", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-target", + TARGET_VALUE, + "-name", + "webapp" + }; + List expectedPaths = Arrays.asList(STRUCTURED_APP_WEBAPP_CONTENTS); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertExtractedFilesMatch(expectedPaths); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // private helper methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + + private void assertExtractDirectoryIsClean() { + assertFalse(WLSDEPLOY_TARGET_DIR.exists(), "expected " + WLSDEPLOY_TARGET_DIR.getPath() + + " have been deleted prior to the test"); + } + + private void assertExtractedFilesMatch(List expectedPaths) { + for (String expectedPath : expectedPaths) { + File expectedFile = FileUtils.getCanonicalFile(new File(UNIT_TEST_TARGET_DIR, expectedPath)); + String expectedFilePath = FileUtils.getCanonicalPath(expectedFile); + + assertTrue(expectedFile.exists(), "expected " + expectedFilePath + " to exist"); + if (expectedPath.endsWith(ZIP_SEP)) { + assertTrue(expectedFile.isDirectory(), "expected " + expectedFilePath + " to be a directory"); + } else { + assertTrue(expectedFile.isFile(), "expected " + expectedFilePath + " to be a file"); + } + } + } +} diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java index 5c869cbf6d..c7a0f16224 100644 --- a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperListTest.java @@ -117,6 +117,10 @@ static void initialize() throws Exception { logger.setLevel(Level.OFF); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // parameterized // + /////////////////////////////////////////////////////////////////////////////////////////////// + @ParameterizedTest @ValueSource(strings = { "all", @@ -138,7 +142,7 @@ static void initialize() throws Exception { "sharedLibrary", "structuredApplication" }) - void testListAppsNoArchive_Fails(String subcommand) { + void testListNoArchive_Fails(String subcommand) { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[] { @@ -177,7 +181,7 @@ void testListAppsNoArchive_Fails(String subcommand) { "sharedLibrary", "structuredApplication" }) - void testListAppsBadArchive_Fails(String subcommand) { + void testListBadArchive_Fails(String subcommand) { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args; @@ -223,6 +227,10 @@ void testListAppsBadArchive_Fails(String subcommand) { "expected command to exit with exit code " + ExitCode.ARG_VALIDATION_ERROR); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // all // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test void testListAll_ReturnedExceptedNames() { StringWriter outStringWriter = new StringWriter(); @@ -246,6 +254,10 @@ void testListAll_ReturnedExceptedNames() { assertListsHaveSameElements(expectedPaths, outputLines, "all"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // application // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test void testListAppFile_ReturnsExpectedName() { StringWriter outStringWriter = new StringWriter(); @@ -319,102 +331,9 @@ void testListApps_ReturnsExceptedNames() { assertListsHaveSameElements(expectedPaths, outputLines, "application"); } - @Test - void testListSharedLibraries_ReturnsExpectedNames() { - StringWriter outStringWriter = new StringWriter(); - StringWriter errStringWriter = new StringWriter(); - String[] args = new String[] { - "list", - "sharedLibrary", - "-archive_file", - ARCHIVE_HELPER_VALUE - }; - List expectedPaths = Arrays.asList(LIST_SHLIB_EXPECTED); - - int actual = -1; - try (PrintWriter out = new PrintWriter(outStringWriter); - PrintWriter err = new PrintWriter(errStringWriter)) { - actual = ArchiveHelper.executeCommand(out, err, args); - } - String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); - - assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "sharedLibrary"); - } - - @Test - void testListSharedLibraryFile_ReturnsExpectedNames() { - StringWriter outStringWriter = new StringWriter(); - StringWriter errStringWriter = new StringWriter(); - String[] args = new String[] { - "list", - "sharedLibrary", - "-archive_file", - ARCHIVE_HELPER_VALUE, - "-name", - "my-lib.war" - }; - List expectedPaths = Arrays.asList(SHARED_LIBS_MY_LIB_WAR_CONTENTS); - - int actual = -1; - try (PrintWriter out = new PrintWriter(outStringWriter); - PrintWriter err = new PrintWriter(errStringWriter)) { - actual = ArchiveHelper.executeCommand(out, err, args); - } - String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); - - assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "sharedLibrary -name my-lib.war"); - } - - @Test - void testListSharedLibraryDir_ReturnsExpectedNames() { - StringWriter outStringWriter = new StringWriter(); - StringWriter errStringWriter = new StringWriter(); - String[] args = new String[] { - "list", - "sharedLibrary", - "-archive_file", - ARCHIVE_HELPER_VALUE, - "-name", - "my-other-lib" - }; - List expectedPaths = Arrays.asList(SHARED_LIBS_MY_OTHER_LIB_CONTENTS); - - int actual = -1; - try (PrintWriter out = new PrintWriter(outStringWriter); - PrintWriter err = new PrintWriter(errStringWriter)) { - actual = ArchiveHelper.executeCommand(out, err, args); - } - String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); - - assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "sharedLibrary -name my-other-lib"); - } - - @Test - void testListSharedLibraryUnknownFile_ReturnsNoNames() { - StringWriter outStringWriter = new StringWriter(); - StringWriter errStringWriter = new StringWriter(); - String[] args = new String[] { - "list", - "sharedLibrary", - "-archive_file", - ARCHIVE_HELPER_VALUE, - "-name", - "foo.jar" - }; - - int actual = -1; - try (PrintWriter out = new PrintWriter(outStringWriter); - PrintWriter err = new PrintWriter(errStringWriter)) { - actual = ArchiveHelper.executeCommand(out, err, args); - } - String outputLines = outStringWriter.getBuffer().toString().trim(); - - assertEquals(0, actual, "expected command to exit with exit code 0"); - assertEquals("", outputLines, "expected list sharedLibrary -name foo.jar to return nothing"); - } + /////////////////////////////////////////////////////////////////////////////////////////////// + // classpath library // + /////////////////////////////////////////////////////////////////////////////////////////////// @Test void testListClasspathLibs_ReturnsExceptedNames() { @@ -464,6 +383,10 @@ void testListClasspathLibFile_ReturnsExceptedNames() { assertListsHaveSameElements(expectedPaths, outputLines, "classpathLibrary -name bar.jar"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // Coherence // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test void testListCohMyCluster_ReturnedExpectedNames() { StringWriter outStringWriter = new StringWriter(); @@ -537,17 +460,21 @@ void testListCoh_ReturnedExpectedNames() { assertListsHaveSameElements(expectedPaths, outputLines, "coherence"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // custom // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test - void testListMime_ReturnedExceptedNames() { + void testListCustom_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "mimeMapping", + "custom", "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList(LIST_MIME_MAPPINGS_EXPECTED); + List expectedPaths = Arrays.asList(LIST_CUSTOM_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -557,22 +484,22 @@ void testListMime_ReturnedExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "mimeMapping"); + assertListsHaveSameElements(expectedPaths, outputLines, "custom"); } @Test - void testListMimeMappingProperties_ReturnedExceptedNames() { + void testListCustomDir_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "mimeMapping", + "custom", "-archive_file", ARCHIVE_HELPER_VALUE, "-name", - "mimemappings.properties" + "mydir" }; - List expectedPaths = Arrays.asList(LIST_MIME_MAPPINGS_PROPERTIES_EXPECTED); + List expectedPaths = Arrays.asList(LIST_CUSTOM_MYDIR_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -582,20 +509,22 @@ void testListMimeMappingProperties_ReturnedExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "mimeMapping -name mimemappings.properties"); + assertListsHaveSameElements(expectedPaths, outputLines, "custom -name mydir"); } @Test - void testListCustom_ReturnsExceptedNames() { + void testListCustomFile_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", "custom", "-archive_file", - ARCHIVE_HELPER_VALUE + ARCHIVE_HELPER_VALUE, + "-name", + "foo.properties" }; - List expectedPaths = Arrays.asList(LIST_CUSTOM_EXPECTED); + List expectedPaths = Arrays.asList(CUSTOM_FOO_PROPERTIES_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -605,22 +534,26 @@ void testListCustom_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "custom"); + assertListsHaveSameElements(expectedPaths, outputLines, "custom -name foo.properties"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // database wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test - void testListCustomDir_ReturnsExceptedNames() { + void testListDbWalletRCU_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "custom", + "databaseWallet", "-archive_file", ARCHIVE_HELPER_VALUE, "-name", - "mydir" + DEFAULT_RCU_WALLET_NAME }; - List expectedPaths = Arrays.asList(LIST_CUSTOM_MYDIR_EXPECTED); + List expectedPaths = Arrays.asList(LIST_RCU_WALLET_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -630,22 +563,22 @@ void testListCustomDir_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "custom -name mydir"); + assertListsHaveSameElements(expectedPaths, outputLines, "databaseWallet -name " + DEFAULT_RCU_WALLET_NAME); } @Test - void testListCustomFile_ReturnsExceptedNames() { + void testListWallet1Dir_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "custom", + "databaseWallet", "-archive_file", ARCHIVE_HELPER_VALUE, "-name", - "foo.properties" + "wallet1" }; - List expectedPaths = Arrays.asList(CUSTOM_FOO_PROPERTIES_CONTENTS); + List expectedPaths = Arrays.asList(LIST_WALLET1_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -655,22 +588,49 @@ void testListCustomFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "custom -name foo.properties"); + assertListsHaveSameElements(expectedPaths, outputLines, "databaseWallet -name wallet1"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // $DOMAIN_HOME/bin script // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test - void testListDbWalletRCU_ReturnsExceptedNames() { + void testListDomainBin_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "databaseWallet", + "domainBinScript", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList(DOMAIN_BIN_CONTENT); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertListsHaveSameElements(expectedPaths, outputLines, "domainBinScript"); + } + + @Test + void testListDomainBinFile_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "domainBinScript", "-archive_file", ARCHIVE_HELPER_VALUE, "-name", - DEFAULT_RCU_WALLET_NAME + "setUserOverrides.sh" }; - List expectedPaths = Arrays.asList(LIST_RCU_WALLET_EXPECTED); + List expectedPaths = Arrays.asList(DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -680,20 +640,24 @@ void testListDbWalletRCU_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "databaseWallet -name " + DEFAULT_RCU_WALLET_NAME); + assertListsHaveSameElements(expectedPaths, outputLines, "domainBinScript -name setUserOverrides.sh"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // $DOMAIN_HOME/lib library // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test - void testListRCUWallet_ReturnsExceptedNames() { + void testListDomainLib_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "rcuWallet", + "domainLibrary", "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList(LIST_RCU_WALLET_EXPECTED); + List expectedPaths = Arrays.asList(DOMAIN_LIB_CONTENT); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -703,22 +667,22 @@ void testListRCUWallet_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "rcuWallet"); + assertListsHaveSameElements(expectedPaths, outputLines, "domainLibrary"); } @Test - void testListWallet1Dir_ReturnsExceptedNames() { + void testListDomainLibFile_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "databaseWallet", + "domainLibrary", "-archive_file", ARCHIVE_HELPER_VALUE, "-name", - "wallet1" + "foo.jar" }; - List expectedPaths = Arrays.asList(LIST_WALLET1_EXPECTED); + List expectedPaths = Arrays.asList(DOMAIN_LIB_FOO_JAR_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -728,20 +692,24 @@ void testListWallet1Dir_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "databaseWallet -name wallet1"); + assertListsHaveSameElements(expectedPaths, outputLines, "domainLibrary -name foo.jar"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // file store // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test - void testListDomainBin_ReturnsExceptedNames() { + void testListFileStore_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "domainBinScript", + "fileStore", "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList(DOMAIN_BIN_CONTENT); + List expectedPaths = Arrays.asList(FILE_STORES_CONTENT); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -751,22 +719,22 @@ void testListDomainBin_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "domainBinScript"); + assertListsHaveSameElements(expectedPaths, outputLines, "fileStore"); } @Test - void testListDomainBinFile_ReturnsExceptedNames() { + void testListFileStoreDir_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "domainBinScript", + "fileStore", "-archive_file", ARCHIVE_HELPER_VALUE, "-name", - "setUserOverrides.sh" + "fs2" }; - List expectedPaths = Arrays.asList(DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS); + List expectedPaths = Arrays.asList(FILE_STORES_FS2_CONTENTS); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -776,20 +744,24 @@ void testListDomainBinFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "domainBinScript -name setUserOverrides.sh"); + assertListsHaveSameElements(expectedPaths, outputLines, "fileStore -name fs2"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // MIME mappings // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test - void testListDomainLib_ReturnsExceptedNames() { + void testListMime_ReturnedExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "domainLibrary", + "mimeMapping", "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList(DOMAIN_LIB_CONTENT); + List expectedPaths = Arrays.asList(LIST_MIME_MAPPINGS_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -799,22 +771,22 @@ void testListDomainLib_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "domainLibrary"); + assertListsHaveSameElements(expectedPaths, outputLines, "mimeMapping"); } @Test - void testListDomainLibFile_ReturnsExceptedNames() { + void testListMimeMappingProperties_ReturnedExceptedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); String[] args = new String[]{ "list", - "domainLibrary", + "mimeMapping", "-archive_file", ARCHIVE_HELPER_VALUE, "-name", - "foo.jar" + "mimemappings.properties" }; - List expectedPaths = Arrays.asList(DOMAIN_LIB_FOO_JAR_CONTENTS); + List expectedPaths = Arrays.asList(LIST_MIME_MAPPINGS_PROPERTIES_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -824,9 +796,14 @@ void testListDomainLibFile_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "domainLibrary -name foo.jar"); + assertListsHaveSameElements(expectedPaths, outputLines, "mimeMapping -name mimemappings.properties"); } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // node manager keystore // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test void testListNodeManager_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); @@ -875,6 +852,10 @@ void testListNodeManagerFile_ReturnsExceptedNames() { assertListsHaveSameElements(expectedPaths, outputLines, "nodeManagerKeystore -name nmTrust.jks"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // OPSS wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test void testListOPSSWallet_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); @@ -898,6 +879,37 @@ void testListOPSSWallet_ReturnsExceptedNames() { assertListsHaveSameElements(expectedPaths, outputLines, "opssWallet"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // RCU wallet // + /////////////////////////////////////////////////////////////////////////////////////////////// + + @Test + void testListRCUWallet_ReturnsExceptedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[]{ + "list", + "rcuWallet", + "-archive_file", + ARCHIVE_HELPER_VALUE + }; + List expectedPaths = Arrays.asList(LIST_RCU_WALLET_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertListsHaveSameElements(expectedPaths, outputLines, "rcuWallet"); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // script // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test void testListScripts_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); @@ -946,6 +958,10 @@ void testListScriptsFile_ReturnsExceptedNames() { assertListsHaveSameElements(expectedPaths, outputLines, "script -name my_fancy_script.sh"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // server keystore // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test void testListServerKeystore_ReturnsExceptedNames() { StringWriter outStringWriter = new StringWriter(); @@ -998,17 +1014,21 @@ void testListServerKeystoreFile_ReturnsExceptedNames() { assertListsHaveSameElements(expectedPaths, outputLines, "serverKeystore -name trust.jks"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // shared library // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test - void testListFileStore_ReturnsExceptedNames() { + void testListSharedLibraries_ReturnsExpectedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); - String[] args = new String[]{ + String[] args = new String[] { "list", - "fileStore", + "sharedLibrary", "-archive_file", ARCHIVE_HELPER_VALUE }; - List expectedPaths = Arrays.asList(FILE_STORES_CONTENT); + List expectedPaths = Arrays.asList(LIST_SHLIB_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -1018,22 +1038,22 @@ void testListFileStore_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "fileStore"); + assertListsHaveSameElements(expectedPaths, outputLines, "sharedLibrary"); } @Test - void testListFileStoreDir_ReturnsExceptedNames() { + void testListSharedLibraryFile_ReturnsExpectedNames() { StringWriter outStringWriter = new StringWriter(); StringWriter errStringWriter = new StringWriter(); - String[] args = new String[]{ + String[] args = new String[] { "list", - "fileStore", + "sharedLibrary", "-archive_file", ARCHIVE_HELPER_VALUE, "-name", - "fs2" + "my-lib.war" }; - List expectedPaths = Arrays.asList(FILE_STORES_FS2_CONTENTS); + List expectedPaths = Arrays.asList(LIST_SHLIB_FILE_EXPECTED); int actual = -1; try (PrintWriter out = new PrintWriter(outStringWriter); @@ -1043,9 +1063,62 @@ void testListFileStoreDir_ReturnsExceptedNames() { String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); assertEquals(0, actual, "expected command to exit with exit code 0"); - assertListsHaveSameElements(expectedPaths, outputLines, "fileStore -name fs2"); + assertListsHaveSameElements(expectedPaths, outputLines, "sharedLibrary -name my-lib.war"); } + @Test + void testListSharedLibraryDir_ReturnsExpectedNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "my-other-lib" + }; + List expectedPaths = Arrays.asList(LIST_SHLIB_DIR_EXPECTED); + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String[] outputLines = outStringWriter.getBuffer().toString().trim().split(System.lineSeparator()); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertListsHaveSameElements(expectedPaths, outputLines, "sharedLibrary -name my-other-lib"); + } + + @Test + void testListSharedLibraryUnknownFile_ReturnsNoNames() { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "list", + "sharedLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "foo.jar" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + String outputLines = outStringWriter.getBuffer().toString().trim(); + + assertEquals(0, actual, "expected command to exit with exit code 0"); + assertEquals("", outputLines, "expected list sharedLibrary -name foo.jar to return nothing"); + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // structured application // + /////////////////////////////////////////////////////////////////////////////////////////////// + @Test void testListStructuredAppWebapp_ReturnedExpectedNames() { StringWriter outStringWriter = new StringWriter(); @@ -1119,12 +1192,15 @@ void testListStructuredApp_ReturnedExpectedNames() { assertListsHaveSameElements(expectedPaths, outputLines, "structuredApplication"); } + /////////////////////////////////////////////////////////////////////////////////////////////// + // private helper methods // + /////////////////////////////////////////////////////////////////////////////////////////////// + private static void assertListsHaveSameElements(List expectedEntries, String[] actualLines, String command) { assertEquals(expectedEntries.size(), actualLines.length, "expected list " + command + " to return " + expectedEntries.size() + " entries"); for (String actualLine : actualLines) { assertTrue(expectedEntries.contains(actualLine), actualLine + " not in expected output"); } - } } diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java index 6cd3a47b01..b4baed99c1 100644 --- a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperRemoveTest.java @@ -31,6 +31,8 @@ import static oracle.weblogic.deploy.tool.ArchiveHelper.LOGGER_NAME; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.APPLICATIONS_CONTENT; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIBS_CONTENT; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_DIR_CONTENTS; +import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.CLASSPATH_LIB_BAR_JAR_CONTENTS; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_CONTENTS; import static oracle.weblogic.deploy.tool.ArchiveHelperTestConstants.COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS; @@ -385,8 +387,29 @@ void testRemoveExistingClasspathLibFile_ReturnsExpectedResults() throws Exceptio actual = ArchiveHelper.executeCommand(out, err, args); } assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); - // Removing the only jar so the test will also remove wlsdeploy/classpathLibraries/ - assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, CLASSPATH_LIBS_CONTENT, CLASSPATH_LIBS_CONTENT); + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, CLASSPATH_LIBS_CONTENT, CLASSPATH_LIB_BAR_JAR_CONTENTS); + } + + @Test + void testRemoveExistingClasspathLibDir_ReturnsExpectedResults() throws Exception { + StringWriter outStringWriter = new StringWriter(); + StringWriter errStringWriter = new StringWriter(); + String[] args = new String[] { + "remove", + "classpathLibrary", + "-archive_file", + ARCHIVE_HELPER_VALUE, + "-name", + "bar" + }; + + int actual = -1; + try (PrintWriter out = new PrintWriter(outStringWriter); + PrintWriter err = new PrintWriter(errStringWriter)) { + actual = ArchiveHelper.executeCommand(out, err, args); + } + assertEquals(ExitCode.OK, actual,"expected command to exit with exit code " + ExitCode.OK); + assertArchiveInExpectedState(LIST_CLASSPATH_LIBRARIES, CLASSPATH_LIBS_CONTENT, CLASSPATH_LIB_BAR_DIR_CONTENTS); } @Test @@ -923,7 +946,7 @@ void testRemoveMissingDomainBinForce_ReturnsExpectedResults() throws Exception { } /////////////////////////////////////////////////////////////////////////////////////////////// - // domain library // + // $DOMAIN_HOME/lib library // /////////////////////////////////////////////////////////////////////////////////////////////// @Test diff --git a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java index 72df69de3b..7029a8d8c1 100644 --- a/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java +++ b/core/src/test/java/oracle/weblogic/deploy/tool/ArchiveHelperTestConstants.java @@ -9,10 +9,18 @@ public class ArchiveHelperTestConstants { "wlsdeploy/applications/my-app.war" }; + static final String[] MY_APP_WAR_DUP_CONTENTS = new String[] { + "wlsdeploy/applications/my-app(1).war" + }; + static final String[] MY_APP_DEPLOYMENT_PLAN_CONTENTS = new String[] { "wlsdeploy/applications/my-app.xml" }; + static final String[] MY_APP_DEPLOYMENT_PLAN_DUP_CONTENTS = new String[] { + "wlsdeploy/applications/my-app(1).xml" + }; + static final String[] MY_OTHER_APP_WAR_CONTENTS = new String[] { "wlsdeploy/applications/my-other-app.war" }; @@ -37,6 +45,26 @@ public class ArchiveHelperTestConstants { "wlsdeploy/applications/my-other-app/WEB-INF/weblogic.xml" }; + static final String[] MY_OTHER_APP_DIR_DUP_CONTENTS = new String[] { + "wlsdeploy/applications/my-other-app(1)/", + "wlsdeploy/applications/my-other-app(1)/META-INF/", + "wlsdeploy/applications/my-other-app(1)/META-INF/maven/", + "wlsdeploy/applications/my-other-app(1)/META-INF/maven/oracle.jcs.lifecycle/", + "wlsdeploy/applications/my-other-app(1)/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/", + "wlsdeploy/applications/my-other-app(1)/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.properties", + "wlsdeploy/applications/my-other-app(1)/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.xml", + "wlsdeploy/applications/my-other-app(1)/META-INF/MANIFEST.MF", + "wlsdeploy/applications/my-other-app(1)/WEB-INF/", + "wlsdeploy/applications/my-other-app(1)/WEB-INF/classes/", + "wlsdeploy/applications/my-other-app(1)/WEB-INF/classes/com/", + "wlsdeploy/applications/my-other-app(1)/WEB-INF/classes/com/oracle/", + "wlsdeploy/applications/my-other-app(1)/WEB-INF/classes/com/oracle/platform/", + "wlsdeploy/applications/my-other-app(1)/WEB-INF/classes/com/oracle/platform/GetListenAddressServlet.class", + "wlsdeploy/applications/my-other-app(1)/WEB-INF/classes/com/oracle/platform/ListenAddressAndPort.class", + "wlsdeploy/applications/my-other-app(1)/WEB-INF/web.xml", + "wlsdeploy/applications/my-other-app(1)/WEB-INF/weblogic.xml" + }; + static final String[] APPLICATIONS_CONTENT = mergeStringArrays( new String[] { "wlsdeploy/applications/" }, MY_OTHER_APP_DIR_CONTENTS, @@ -45,23 +73,46 @@ public class ArchiveHelperTestConstants { MY_OTHER_APP_WAR_CONTENTS ); + static final String[] CLASSPATH_LIB_BAR_DIR_CONTENTS = new String[] { + "wlsdeploy/classpathLibraries/bar/", + "wlsdeploy/classpathLibraries/bar/Foo.class" + }; + + static final String[] CLASSPATH_LIB_BAR_DIR_DUP_CONTENTS = new String[] { + "wlsdeploy/classpathLibraries/bar(1)/", + "wlsdeploy/classpathLibraries/bar(1)/Foo.class" + }; + static final String[] CLASSPATH_LIB_BAR_JAR_CONTENTS = new String[] { "wlsdeploy/classpathLibraries/bar.jar" }; - static final String[] CLASSPATH_LIBS_CONTENT = new String[] { - "wlsdeploy/classpathLibraries/", - "wlsdeploy/classpathLibraries/bar.jar" + static final String[] CLASSPATH_LIB_BAR_JAR_DUP_CONTENTS = new String[] { + "wlsdeploy/classpathLibraries/bar(1).jar" }; + static final String[] CLASSPATH_LIBS_CONTENT = mergeStringArrays( + new String[] { "wlsdeploy/classpathLibraries/" }, + CLASSPATH_LIB_BAR_DIR_CONTENTS, + CLASSPATH_LIB_BAR_JAR_CONTENTS + ); + static final String[] COHERENCE_MYCLUSTER_CONFIG_FILE_CONTENTS = new String[] { "wlsdeploy/coherence/mycluster/cache-config.xml" }; + static final String[] COHERENCE_MYCLUSTER_CONFIG_FILE_DUP_CONTENTS = new String[] { + "wlsdeploy/coherence/mycluster/cache-config(1).xml" + }; + static final String[] COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_CONTENTS = new String[] { "wlsdeploy/coherence/mycluster/active/" }; + static final String[] COHERENCE_MYCLUSTER_PERSISTENT_DIR_ACTIVE_DUP_CONTENTS = new String[] { + "wlsdeploy/coherence/mycluster/active(1)/" + }; + static final String[] COHERENCE_MYCLUSTER_PERSISTENT_DIR_SNAPSHOT_CONTENTS = new String[] { "wlsdeploy/coherence/mycluster/snapshot/" }; @@ -106,6 +157,10 @@ public class ArchiveHelperTestConstants { "wlsdeploy/config/mimemappings.properties" }; + static final String[] MIME_MAPPING_PROPERTIES_DUP_CONTENTS = new String[] { + "wlsdeploy/config/mimemappings(1).properties" + }; + static final String[] MIME_MAPPINGS_CONTENT = new String[] { "wlsdeploy/config/", "wlsdeploy/config/mimemappings.properties" @@ -120,10 +175,19 @@ public class ArchiveHelperTestConstants { CUSTOM_MYDIR_BAR_PROPERTIES_CONTENTS ); + static final String[] CUSTOM_MYDIR_DUP_CONTENTS = new String[] { + "wlsdeploy/custom/mydir(1)/", + "wlsdeploy/custom/mydir(1)/bar.properties" + }; + static final String[] CUSTOM_FOO_PROPERTIES_CONTENTS = { "wlsdeploy/custom/foo.properties" }; + static final String[] CUSTOM_FOO_PROPERTIES_DUP_CONTENTS = { + "wlsdeploy/custom/foo(1).properties" + }; + static final String[] CUSTOM_CONTENT = mergeStringArrays( new String[] { "wlsdeploy/custom/" }, CUSTOM_MYDIR_CONTENTS, @@ -148,6 +212,11 @@ public class ArchiveHelperTestConstants { "wlsdeploy/dbWallets/wallet1/atpwallet.zip" }; + static final String[] DATABASE_WALLET_WALLET1_DUP_CONTENTS = new String[] { + "wlsdeploy/dbWallets/wallet1(1)/", + "wlsdeploy/dbWallets/wallet1(1)/atpwallet.zip" + }; + static final String[] DATABASE_WALLETS_CONTENT = mergeStringArrays( new String[] { "wlsdeploy/dbWallets/" }, DATABASE_WALLET_RCU_CONTENTS, @@ -158,6 +227,10 @@ public class ArchiveHelperTestConstants { "wlsdeploy/domainBin/setUserOverrides.sh" }; + static final String[] DOMAIN_BIN_SET_USER_OVERRIDES_SH_DUP_CONTENTS = new String[] { + "wlsdeploy/domainBin/setUserOverrides(1).sh" + }; + static final String[] DOMAIN_BIN_CONTENT = mergeStringArrays( new String[] { "wlsdeploy/domainBin/" }, DOMAIN_BIN_SET_USER_OVERRIDES_SH_CONTENTS @@ -167,6 +240,10 @@ public class ArchiveHelperTestConstants { "wlsdeploy/domainLibraries/foo.jar" }; + static final String[] DOMAIN_LIB_FOO_JAR_DUP_CONTENTS = new String[] { + "wlsdeploy/domainLibraries/foo(1).jar" + }; + static final String[] DOMAIN_LIB_CONTENT = mergeStringArrays( new String[] { "wlsdeploy/domainLibraries/" }, DOMAIN_LIB_FOO_JAR_CONTENTS @@ -176,6 +253,10 @@ public class ArchiveHelperTestConstants { "wlsdeploy/jms/foreignServer/fs1/jndi.properties" }; + static final String[] FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_DUP_CONTENTS = new String[] { + "wlsdeploy/jms/foreignServer/fs1/jndi(1).properties" + }; + static final String[] FOREIGN_SERVERS_FS1_CONTENTS = mergeStringArrays( new String[] { "wlsdeploy/jms/foreignServer/fs1/" }, FOREIGN_SERVERS_FS1_JNDI_PROPERTIES_CONTENTS @@ -203,6 +284,10 @@ public class ArchiveHelperTestConstants { "wlsdeploy/nodeManager/nmIdentity.jks" }; + static final String[] NODE_MANAGER_IDENTITY_JKS_DUP_CONTENTS = new String[] { + "wlsdeploy/nodeManager/nmIdentity(1).jks" + }; + static final String[] NODE_MANAGER_TRUST_JKS_CONTENTS = new String[] { "wlsdeploy/nodeManager/nmTrust.jks" }; @@ -222,6 +307,10 @@ public class ArchiveHelperTestConstants { "wlsdeploy/scripts/my_fancy_script.sh" }; + static final String[] SCRIPTS_FANCY_SCRIPT_DUP_CONTENTS = new String[] { + "wlsdeploy/scripts/my_fancy_script(1).sh" + }; + static final String[] SCRIPTS_CONTENT = mergeStringArrays( new String[] { "wlsdeploy/scripts/" }, SCRIPTS_FANCY_SCRIPT_CONTENTS @@ -231,6 +320,10 @@ public class ArchiveHelperTestConstants { "wlsdeploy/servers/AdminServer/identity.jks" }; + static final String[] SERVERS_ADMIN_SERVER_IDENTITY_JKS_DUP_CONTENTS = new String[] { + "wlsdeploy/servers/AdminServer/identity(1).jks" + }; + static final String[] SERVERS_ADMIN_SERVER_TRUST_JKS_CONTENTS = new String[] { "wlsdeploy/servers/AdminServer/trust.jks" }; @@ -266,14 +359,42 @@ public class ArchiveHelperTestConstants { "wlsdeploy/sharedLibraries/my-other-lib/WEB-INF/weblogic.xml" }; + static final String[] SHARED_LIBS_MY_OTHER_LIB_DUP_CONTENTS = new String[] { + "wlsdeploy/sharedLibraries/my-other-lib(1)/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/META-INF/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/META-INF/maven/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/META-INF/maven/oracle.jcs.lifecycle/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.properties", + "wlsdeploy/sharedLibraries/my-other-lib(1)/META-INF/maven/oracle.jcs.lifecycle/get-listen-address-app/pom.xml", + "wlsdeploy/sharedLibraries/my-other-lib(1)/META-INF/MANIFEST.MF", + "wlsdeploy/sharedLibraries/my-other-lib(1)/WEB-INF/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/WEB-INF/classes/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/WEB-INF/classes/com/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/WEB-INF/classes/com/oracle/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/WEB-INF/classes/com/oracle/platform/", + "wlsdeploy/sharedLibraries/my-other-lib(1)/WEB-INF/classes/com/oracle/platform/GetListenAddressServlet.class", + "wlsdeploy/sharedLibraries/my-other-lib(1)/WEB-INF/classes/com/oracle/platform/ListenAddressAndPort.class", + "wlsdeploy/sharedLibraries/my-other-lib(1)/WEB-INF/web.xml", + "wlsdeploy/sharedLibraries/my-other-lib(1)/WEB-INF/weblogic.xml" + }; + static final String[] SHARED_LIBS_MY_LIB_WAR_CONTENTS = new String[] { "wlsdeploy/sharedLibraries/my-lib.war" }; + static final String[] SHARED_LIBS_MY_LIB_WAR_DUP_CONTENTS = new String[] { + "wlsdeploy/sharedLibraries/my-lib(1).war" + }; + static final String[] SHARED_LIBS_MY_LIB_XML_CONTENTS = new String[] { "wlsdeploy/sharedLibraries/my-lib.xml" }; + static final String[] SHARED_LIBS_MY_LIB_XML_DUP_CONTENTS = new String[] { + "wlsdeploy/sharedLibraries/my-lib(1).xml" + }; + static final String[] SHARED_LIBS_CONTENT = mergeStringArrays( new String[] { "wlsdeploy/sharedLibraries/" }, SHARED_LIBS_MY_OTHER_LIB_CONTENTS, @@ -285,6 +406,10 @@ public class ArchiveHelperTestConstants { "wlsdeploy/stores/fs1/" }; + static final String[] FILE_STORES_FS1_DUP_CONTENTS = new String[] { + "wlsdeploy/stores/fs1(1)/" + }; + static final String[] FILE_STORES_FS2_CONTENTS = new String[] { "wlsdeploy/stores/fs2/" }; @@ -322,6 +447,28 @@ public class ArchiveHelperTestConstants { "wlsdeploy/structuredApplications/webapp/plan/plan.xml" }; + static final String[] STRUCTURED_APP_WEBAPP_DUP_CONTENTS = new String[] { + "wlsdeploy/structuredApplications/webapp(1)/", + "wlsdeploy/structuredApplications/webapp(1)/app/", + "wlsdeploy/structuredApplications/webapp(1)/app/META-INF/", + "wlsdeploy/structuredApplications/webapp(1)/app/META-INF/MANIFEST.MF", + "wlsdeploy/structuredApplications/webapp(1)/app/WEB-INF/", + "wlsdeploy/structuredApplications/webapp(1)/app/WEB-INF/classes/", + "wlsdeploy/structuredApplications/webapp(1)/app/WEB-INF/classes/com/", + "wlsdeploy/structuredApplications/webapp(1)/app/WEB-INF/classes/com/oracle/", + "wlsdeploy/structuredApplications/webapp(1)/app/WEB-INF/classes/com/oracle/weblogic/", + "wlsdeploy/structuredApplications/webapp(1)/app/WEB-INF/classes/com/oracle/weblogic/example/", + "wlsdeploy/structuredApplications/webapp(1)/app/WEB-INF/classes/com/oracle/weblogic/example/HelloServlet.class", + "wlsdeploy/structuredApplications/webapp(1)/app/WEB-INF/classes/hello.properties", + "wlsdeploy/structuredApplications/webapp(1)/app/WEB-INF/web.xml", + "wlsdeploy/structuredApplications/webapp(1)/plan/", + "wlsdeploy/structuredApplications/webapp(1)/plan/AppFileOverrides/", + "wlsdeploy/structuredApplications/webapp(1)/plan/AppFileOverrides/hello.properties", + "wlsdeploy/structuredApplications/webapp(1)/plan/WEB-INF/", + "wlsdeploy/structuredApplications/webapp(1)/plan/WEB-INF/weblogic.xml", + "wlsdeploy/structuredApplications/webapp(1)/plan/plan.xml" + }; + static final String[] STRUCTURED_APP_WEBAPP1_CONTENTS = new String[] { "wlsdeploy/structuredApplications/webapp1/", "wlsdeploy/structuredApplications/webapp1/app/", diff --git a/core/src/test/java/oracle/weblogic/deploy/yaml/YamlTranslatorTest.java b/core/src/test/java/oracle/weblogic/deploy/yaml/YamlTranslatorTest.java index 488d4bebab..6e0293c4d4 100644 --- a/core/src/test/java/oracle/weblogic/deploy/yaml/YamlTranslatorTest.java +++ b/core/src/test/java/oracle/weblogic/deploy/yaml/YamlTranslatorTest.java @@ -494,7 +494,6 @@ public void testLexicalError() { String text = "abc:\n xyz: - aa-bb\n"; InputStream stream = new ByteArrayInputStream(text.getBytes(UTF_8)); YamlStreamTranslator translator = new YamlStreamTranslator("String", stream); - System.out.println("translator = " + translator.toString()); translator.parse(); fail("Test must raise YamlException when model has a lexical error"); diff --git a/core/src/test/resources/archive-helper-test.zip b/core/src/test/resources/archive-helper-test.zip index 490e77953e92eedfdf8fc94ca699bec79f1584bc..555784233c85c3992550446a95ea7841b2abe292 100644 GIT binary patch delta 342 zcmZ3uk!|}HHr@blW)?065D3V#n9OJ=J^7swFHdL)Cj)bb*@a{v-ss3=#$2}8VzQf= zG5dna7m|T^@RjXPGhnQY>d*AcbJLs>Vx%f2dcdYQ7Z_P z4g=c)CA225Hd7YUcgxS$OU_9wE{1CWYMOqKkx_;j=$z?GqZzG1&Y13)!6>u+e>7tT z7sw^kv(gwHnSss#tK5Dnjq$MIv}8suup<^0Gm5hdFuZk~7R@+$t(hVx&@rqG%rJ8m zFB(Rw&@%A7^Noj+3`(&C&bGh8p6rI?4UJ$BMYPCflP?GfY|Or4I(e3v zz~o>vHOAS~H?S}&G|w{IKFf^ppUQNDCPu004!Mkc)9Ygx6{cU0Wz^q(E`~9JYkFro mqrh~tbVifuSJD~fw*$F{4MkYl7=WM|2*27eFieYP1o8kR7%G?m From c5a974e6631e0486c56d4d8d17f64ad8365a3c15 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Thu, 26 Jan 2023 20:33:15 -0600 Subject: [PATCH 09/13] first cut at shell scripts --- installer/src/main/bin/archiveHelper.cmd | 50 +++++++++++++++++++++++ installer/src/main/bin/archiveHelper.sh | 39 ++++++++++++++++++ installer/src/main/bin/shared.cmd | 13 +++++- installer/src/main/bin/shared.sh | 12 +++++- installer/src/main/etc/logging.properties | 1 + 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 installer/src/main/bin/archiveHelper.cmd create mode 100755 installer/src/main/bin/archiveHelper.sh diff --git a/installer/src/main/bin/archiveHelper.cmd b/installer/src/main/bin/archiveHelper.cmd new file mode 100644 index 0000000000..c089ebf524 --- /dev/null +++ b/installer/src/main/bin/archiveHelper.cmd @@ -0,0 +1,50 @@ +@ECHO OFF +@rem ************************************************************************** +@rem archiveHelper.cmd +@rem +@rem Copyright (c) 2023, Oracle Corporation and/or its affiliates. +@rem Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +@rem +@rem NAME +@rem archiveHelper.sh - WLS Deploy tool to support creating and editing an archive file. +@rem +@rem DESCRIPTION +@rem This script provides add, extract, list, and replace functionality for +@rem working with an archive file. +@rem +@rem This script uses the following variables: +@rem +@rem JAVA_HOME - The location of the JDK to use. The caller must set +@rem this variable to a valid Java 7 (or later) JDK. +@rem +@rem WLSDEPLOY_HOME - The location of the WLS Deploy installation. +@rem If the caller sets this, the callers location will be +@rem honored provided it is an existing directory. +@rem Otherwise, the location will be calculated from the +@rem location of this script. +@rem + +SETLOCAL + +SET WLSDEPLOY_PROGRAM_NAME=archiveHelper + +SET SCRIPT_PATH=%~dp0 +FOR %%i IN ("%SCRIPT_PATH%") DO SET SCRIPT_PATH=%%~fsi +IF %SCRIPT_PATH:~-1%==\ SET SCRIPT_PATH=%SCRIPT_PATH:~0,-1% + +SET MIN_JDK_VERSION=7 +SET "WLSDEPLOY_LOG_HANDLERS=java.util.logging.FileHandler" + +call "%SCRIPT_PATH%\shared.cmd" :javaOnlySetup %MIN_JDK_VERSION% quiet + +%JAVA_HOME%\bin\java -Djava.util.logging.config.class=%LOG_CONFIG_CLASS% oracle.weblogic.deploy.tool.ArchiveHelper %* +SET RETURN_CODE=%ERRORLEVEL% + +:exit_script +IF DEFINED USE_CMD_EXIT ( + EXIT %RETURN_CODE% +) ELSE ( + EXIT /B %RETURN_CODE% +) + +ENDLOCAL diff --git a/installer/src/main/bin/archiveHelper.sh b/installer/src/main/bin/archiveHelper.sh new file mode 100755 index 0000000000..72151d9ef4 --- /dev/null +++ b/installer/src/main/bin/archiveHelper.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# ***************************************************************************** +# archiveHelper.sh +# +# Copyright (c) 2023, Oracle Corporation and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +# +# NAME +# archiveHelper.sh - WLS Deploy tool to support creating and editing an archive file. +# +# DESCRIPTION +# This script provides add, extract, list, and replace functionality for +# working with an archive file. +# +# This script uses the following variables: +# +# JAVA_HOME - The location of the JDK to use. The caller must set +# this variable to a valid Java 7 (or later) JDK. +# +# WLSDEPLOY_HOME - The location of the WLS Deploy installation. +# If the caller sets this, the callers location will be +# honored provided it is an existing directory. +# Otherwise, the location will be calculated from the +# location of this script. +# + +WLSDEPLOY_PROGRAM_NAME="archiveHelper"; export WLSDEPLOY_PROGRAM_NAME + +scriptPath=$(dirname "$0") + +. "$scriptPath/shared.sh" + +umask 27 +minJdkVersion=7 + +WLSDEPLOY_LOG_HANDLERS="java.util.logging.FileHandler"; export WLSDEPLOY_LOG_HANDLERS +javaOnlySetup $minJdkVersion "quiet" + +"${JAVA_HOME}/bin/java" "-Djava.util.logging.config.class=${LOG_CONFIG_CLASS}" oracle.weblogic.deploy.tool.ArchiveHelper "$@" diff --git a/installer/src/main/bin/shared.cmd b/installer/src/main/bin/shared.cmd index d3f1771b66..246a1c831b 100644 --- a/installer/src/main/bin/shared.cmd +++ b/installer/src/main/bin/shared.cmd @@ -21,6 +21,7 @@ GOTO :ENDFUNCTIONS @rem JDK with the specified level or higher (and that it isn't OpenJDK). SET MIN_JDK_VERSION=%1 + SET QUIET_ARG=%2 IF NOT DEFINED JAVA_HOME ( ECHO Please set the JAVA_HOME environment variable to point to a Java 8 installation >&2 @@ -106,7 +107,9 @@ GOTO :ENDFUNCTIONS IF %JVM_SUPPORTED% NEQ 1 ( EXIT /B 2 ) ELSE ( - ECHO JDK version is %JVM_FULL_VERSION%, setting JAVA_VENDOR to Sun... + IF "%QUIET_ARG%"!="quiet" ( + ECHO JDK version is %JVM_FULL_VERSION%, setting JAVA_VENDOR to Sun... + ) IF "%JAVA_VENDOR%"=="" SET JAVA_VENDOR=Sun ) GOTO :EOF @@ -207,6 +210,14 @@ GOTO :EOF ) GOTO :EOF +:javaOnlySetup + CALL :javaSetup %1 %2 + + CALL :variableSetup + + SET "CLASSPATH=%WLSDEPLOY_HOME%/lib/weblogic-deploy-core.jar" +GOTO :EOF + :runWlst @REM run a WLST script. SET WLST_SCRIPT=%1 diff --git a/installer/src/main/bin/shared.sh b/installer/src/main/bin/shared.sh index ba988afd5e..94945604bc 100644 --- a/installer/src/main/bin/shared.sh +++ b/installer/src/main/bin/shared.sh @@ -64,7 +64,9 @@ javaSetup() { echo "You are using an unsupported JDK version ${JVM_FULL_VERSION}" >&2 exit 2 else - echo "JDK version is ${JVM_FULL_VERSION}" + if [ "$2" != "quiet" ]; then + echo "JDK version is ${JVM_FULL_VERSION}" + fi fi } @@ -171,6 +173,14 @@ variableSetup() { fi } +javaOnlySetup() { + javaSetup "$1" "$2" + + variableSetup + + CLASSPATH="${WLSDEPLOY_HOME}/lib/weblogic-deploy-core.jar"; export CLASSPATH +} + runWlst() { # run a WLST script. wlstScript=$1 diff --git a/installer/src/main/etc/logging.properties b/installer/src/main/etc/logging.properties index f6ad4ecf96..541bc5fd37 100644 --- a/installer/src/main/etc/logging.properties +++ b/installer/src/main/etc/logging.properties @@ -14,3 +14,4 @@ wlsdeploy.mbean.utils.level=FINE wlsdeploy.util.level=FINER wlsdeploy.versions.level=FINE wlsdeploy.wlst.level=FINER +wlsdeploy.tool.archive-helper=FINER From 3c0e6ecaddf6efd1a9d4b2e8420513c688c38d21 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Thu, 26 Jan 2023 21:07:02 -0600 Subject: [PATCH 10/13] fixing Windows script issue --- installer/src/main/bin/shared.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/src/main/bin/shared.cmd b/installer/src/main/bin/shared.cmd index 246a1c831b..ac1b193ada 100644 --- a/installer/src/main/bin/shared.cmd +++ b/installer/src/main/bin/shared.cmd @@ -107,7 +107,7 @@ GOTO :ENDFUNCTIONS IF %JVM_SUPPORTED% NEQ 1 ( EXIT /B 2 ) ELSE ( - IF "%QUIET_ARG%"!="quiet" ( + IF NOT "%QUIET_ARG%"=="quiet" ( ECHO JDK version is %JVM_FULL_VERSION%, setting JAVA_VENDOR to Sun... ) IF "%JAVA_VENDOR%"=="" SET JAVA_VENDOR=Sun From 34be74cbeb5c3f15782c104cd575ea441906e83b Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Thu, 26 Jan 2023 21:22:33 -0600 Subject: [PATCH 11/13] cleaning up Sonar code smells --- .../add/AddCoherencePersistenceDirCommand.java | 2 -- .../archive_helper/add/AddFileStoreCommand.java | 2 -- .../archive_helper/add/AddRCUWalletCommand.java | 1 - .../archive_helper/add/AddTypeCommandBase.java | 4 ---- .../remove/RemoveApplicationCommand.java | 2 -- .../remove/RemoveTypeCommandBase.java | 4 ---- .../weblogic/deploy/util/WLSDeployArchive.java | 16 +++++++++++++--- .../weblogic/deploy/util/WLSDeployZipFile.java | 2 +- 8 files changed, 14 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java index fb1ad6ca4f..7c0a1210e0 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddCoherencePersistenceDirCommand.java @@ -4,8 +4,6 @@ */ package oracle.weblogic.deploy.tool.archive_helper.add; -import java.io.File; - import oracle.weblogic.deploy.logging.PlatformLogger; import oracle.weblogic.deploy.logging.WLSDeployLogFactory; import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java index 4569afaff7..b1ca556ab5 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddFileStoreCommand.java @@ -4,8 +4,6 @@ */ package oracle.weblogic.deploy.tool.archive_helper.add; -import java.io.File; - import oracle.weblogic.deploy.logging.PlatformLogger; import oracle.weblogic.deploy.logging.WLSDeployLogFactory; import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java index 602831d909..928390e3e7 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddRCUWalletCommand.java @@ -26,7 +26,6 @@ public class AddRCUWalletCommand extends AddTypeCommandBase { private static final String CLASS = AddRCUWalletCommand.class.getName(); private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); - private static final String TYPE = "database wallet"; @Option( names = {"-source"}, diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java index 6e138dfb73..fab1f3120a 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddTypeCommandBase.java @@ -20,10 +20,6 @@ public abstract class AddTypeCommandBase extends AddOptions implements Callable< private static final String CLASS = AddTypeCommandBase.class.getName(); private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger(LOGGER_NAME); - protected void initializeOptions() throws ArchiveHelperException { - super.initializeOptions(); - } - protected File initializeOptions(String sourcePath) throws ArchiveHelperException { final String METHOD = "initializeOptions"; LOGGER.entering(CLASS, METHOD, sourcePath); diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java index 8db2e937ff..062a1c38ee 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveApplicationCommand.java @@ -4,8 +4,6 @@ */ package oracle.weblogic.deploy.tool.archive_helper.remove; -import java.util.List; - import oracle.weblogic.deploy.logging.PlatformLogger; import oracle.weblogic.deploy.logging.WLSDeployLogFactory; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveTypeCommandBase.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveTypeCommandBase.java index f57c18f8fe..0e664bf020 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveTypeCommandBase.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveTypeCommandBase.java @@ -10,8 +10,4 @@ import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; public abstract class RemoveTypeCommandBase extends RemoveOptions implements Callable { - - protected void initializeOptions() throws ArchiveHelperException { - super.initializeOptions(); - } } diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java index 2c90b12439..9f1e297983 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java @@ -4165,28 +4165,34 @@ protected static FileOrDirectoryType getFileType(ArchiveEntryType type) { final String METHOD = "getFileType"; LOGGER.entering(CLASS, METHOD, type); - FileOrDirectoryType result = FileOrDirectoryType.EITHER; + FileOrDirectoryType result; switch(type) { case COHERENCE: case COHERENCE_PERSISTENCE_DIR: case DB_WALLET: case FILE_STORE: case OPSS_WALLET: + case RCU_WALLET: case STRUCTURED_APPLICATION: result = FileOrDirectoryType.DIRECTORY_ONLY; break; + case APPLICATION_PLAN: case COHERENCE_CONFIG: case DOMAIN_BIN: + case DOMAIN_LIB: case JMS_FOREIGN_SERVER: case MIME_MAPPING: case NODE_MANAGER_KEY_STORE: case SCRIPT: case SERVER_KEYSTORE: + case SHLIB_PLAN: result = FileOrDirectoryType.FILE_ONLY; break; - // FIXME - need to log if receiving an unknown type + default: + result = FileOrDirectoryType.EITHER; + break; } LOGGER.exiting(CLASS, METHOD, result); @@ -4197,7 +4203,7 @@ protected static boolean isSegregatedType(ArchiveEntryType type) { final String METHOD = "isSegregatedType"; LOGGER.entering(CLASS, METHOD, type); - boolean result = false; + boolean result; switch(type) { case COHERENCE: case COHERENCE_CONFIG: @@ -4207,6 +4213,10 @@ protected static boolean isSegregatedType(ArchiveEntryType type) { case SERVER_KEYSTORE: result = true; break; + + default: + result = false; + break; } LOGGER.exiting(CLASS, METHOD, result); diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployZipFile.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployZipFile.java index 6e31b5ffe0..b696113210 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployZipFile.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployZipFile.java @@ -40,7 +40,7 @@ public class WLSDeployZipFile { private static final String CLOSE_PAREN = ")"; private static final char ZIP_SEP_CHAR = '/'; private static final String ZIP_SEP = "/"; - private static final Pattern RENAME_QUALIFIER_REGEX = Pattern.compile("^[(]([1-9]\\d*)[)]$"); + private static final Pattern RENAME_QUALIFIER_REGEX = Pattern.compile("^\\(([1-9]\\d*)\\)$"); private static final int READ_BUFFER_SIZE = 4096; private static final int MAX_DIGITS = Integer.toString(Integer.MAX_VALUE).length() - 1; From b5240e4370e7fd8189e6ffb32315e1dad0d06ce5 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Thu, 26 Jan 2023 22:35:52 -0600 Subject: [PATCH 12/13] adding version support for archiveHelper --- .../weblogic/deploy/tool/ArchiveHelper.java | 11 +++++++++- .../ArchiveHelperVersionProvider.java | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/ArchiveHelperVersionProvider.java diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java index 397f1609d5..7432372e84 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java @@ -9,6 +9,7 @@ import oracle.weblogic.deploy.logging.PlatformLogger; import oracle.weblogic.deploy.logging.WLSDeployLogFactory; +import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperVersionProvider; import oracle.weblogic.deploy.tool.archive_helper.CommandResponse; import oracle.weblogic.deploy.tool.archive_helper.add.AddCommand; import oracle.weblogic.deploy.tool.archive_helper.extract.ExtractCommand; @@ -34,7 +35,8 @@ ListCommand.class, RemoveCommand.class }, - sortOptions = false + sortOptions = false, + versionProvider = ArchiveHelperVersionProvider.class ) public class ArchiveHelper { public static final String LOGGER_NAME = "wlsdeploy.tool.archive-helper"; @@ -48,6 +50,13 @@ public class ArchiveHelper { ) private static boolean helpRequested = false; + @Option( + names = { "-version" }, + description = "Get the WebLogic Deploy Tooling version", + versionHelp = true + ) + private static boolean versionRequested = false; + @SuppressWarnings("java:S106") public static void main(String[] args) { final String METHOD = "main"; diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/ArchiveHelperVersionProvider.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/ArchiveHelperVersionProvider.java new file mode 100644 index 0000000000..039616e473 --- /dev/null +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/ArchiveHelperVersionProvider.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + */ +package oracle.weblogic.deploy.tool.archive_helper; + +import oracle.weblogic.deploy.util.WebLogicDeployToolingVersion; + +import picocli.CommandLine.IVersionProvider; + +public class ArchiveHelperVersionProvider implements IVersionProvider { + @Override + public String[] getVersion() { + return new String[] { + "WebLogic Deploy Tooling version: " + WebLogicDeployToolingVersion.getVersion(), + "Build: " + WebLogicDeployToolingVersion.getBuildRevision() + ":" + + WebLogicDeployToolingVersion.getBuildTimestamp() + }; + } +} From 8539a73799d6bad6c892627f7669716dc552b8d4 Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Fri, 27 Jan 2023 09:54:24 -0600 Subject: [PATCH 13/13] review feedback --- .../src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java | 1 - .../weblogic/deploy/tool/archive_helper/CommandResponse.java | 1 - 2 files changed, 2 deletions(-) diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java index 7432372e84..caf84926ba 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/ArchiveHelper.java @@ -75,7 +75,6 @@ static int executeCommand(PrintWriter out, PrintWriter err, String... args) { .setToggleBooleanFlags(false) .setUnmatchedArgumentsAllowed(false) .setTrimQuotes(true) - //.setColorScheme(CommandLine.Help.defaultColorScheme(CommandLine.Help.Ansi.AUTO)) .setParameterExceptionHandler(new ArgParsingExceptionHandler()) .setOut(out) .setErr(err); diff --git a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java index 008770b5dd..16d318a582 100644 --- a/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java +++ b/core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/CommandResponse.java @@ -61,7 +61,6 @@ public void addMessages(List messages) { } } - @SuppressWarnings("java:S106") public void printMessages(PrintWriter out, PrintWriter err) { PrintWriter location = out; if (status != 0) {