From a7f94169e99473a830f71cb26cf3aacdeb996d38 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Sun, 15 Sep 2019 23:00:25 -0400 Subject: [PATCH] Use finalName in generated application location in server.xml Signed-off-by: Scott Kurz --- .../runtimes/openliberty/LibertyRuntime.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/LibertyRuntime.java b/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/LibertyRuntime.java index 5042db70..007e8803 100644 --- a/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/LibertyRuntime.java +++ b/boost-maven/boost-runtimes/runtime-openliberty/src/main/java/boost/runtimes/openliberty/LibertyRuntime.java @@ -167,24 +167,35 @@ private void generateServerConfig(List boosterConfigs) th } } - private List getWarNames() { - List warNames = new ArrayList(); - - for (Artifact artifact : project.getArtifacts()) { - if (artifact.getType().equals("war")) { - warNames.add(artifact.getArtifactId() + "-" + artifact.getVersion()); - } - } + /** + * Assumes a non-WAR packaging type (like JAR) has a WAR dependency. + * We assume there's only 1 but don't check, just return the first one. + * @return + * @throws BoostException + */ + private String getWarName() throws BoostException { + String retVal = null; if (project.getPackaging().equals(ConfigConstants.WAR_PKG_TYPE)) { - if (project.getVersion() == null) { - warNames.add(project.getArtifactId()); - } else { - warNames.add(project.getArtifactId() + "-" + project.getVersion()); + retVal = project.getBuild().getFinalName(); + } else { + // JAR package "release", get WAR from dependency + for (Artifact artifact : project.getArtifacts()) { + // first WAR + if (artifact.getType().equals("war")) { + retVal = artifact.getArtifactId() + "-" + artifact.getVersion(); + break; + } + } + if (retVal == null) { + BoostLogger log = BoostLogger.getSystemStreamLogger(); + String msg = "With non-WAR packaging type, we require a WAR dependency"; + log.error(msg); + throw new BoostException(msg); } } - - return warNames; + + return retVal; } /** @@ -195,8 +206,6 @@ private List getWarNames() { */ private void generateLibertyServerConfig(List boosterConfigurators) throws Exception { - List warNames = getWarNames(); - String encryptionKey = (String) boostProperties.get(BoostProperties.AES_ENCRYPTION_KEY); LibertyServerConfigGenerator libertyConfig = new LibertyServerConfigGenerator(libertyServerPath, encryptionKey, BoostLogger.getSystemStreamLogger()); @@ -210,16 +219,9 @@ private void generateLibertyServerConfig(List boosterConf String httpsPort = (String) boostProperties.getOrDefault(BoostProperties.ENDPOINT_HTTPS_PORT, "9443"); libertyConfig.addHttpsPort(httpsPort); - - // Add war configuration if necessary - if (!warNames.isEmpty()) { - for (String warName : warNames) { - libertyConfig.addApplication(warName); - } - } else { - throw new Exception( - "No war files were found. The project must have a war packaging type or specify war dependencies."); - } + + String warName = getWarName(); + libertyConfig.addApplication(warName); // Loop through configuration objects and add config and // the corresponding Liberty feature