From dd1ff153f630ba647f59a6ba35468b8e3a80e319 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Thu, 28 Jan 2021 15:53:41 -0500 Subject: [PATCH 1/2] Use separate folder for devc specific loose app --- .../tools/maven/applications/DeployMojo.java | 26 ++++++++++++++++--- .../maven/applications/DeployMojoSupport.java | 4 +-- .../tools/maven/server/DevMojo.java | 5 +--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java index 67ec95b2c..3c7de12f6 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java @@ -34,6 +34,7 @@ import io.openliberty.tools.common.plugins.config.ApplicationXmlDocument; import io.openliberty.tools.common.plugins.config.LooseConfigData; import io.openliberty.tools.common.plugins.config.ServerConfigDocument; +import io.openliberty.tools.common.plugins.util.DevUtil; /** * Copy applications to the specified directory of the Liberty server. @@ -190,18 +191,30 @@ private void installLooseApplication(MavenProject proj) throws Exception { String application = looseConfigFileName.substring(0, looseConfigFileName.length() - 4); File destDir = new File(serverDirectory, getAppsDirectory()); File looseConfigFile = new File(destDir, looseConfigFileName); - LooseConfigData config = new LooseConfigData(); + + File devcDestDir = new File(new File(project.getBuild().getDirectory(), DevUtil.DEVC_HIDDEN_FOLDER), getAppsDirectory()); + File devcLooseConfigFile = new File(devcDestDir, looseConfigFileName); + + LooseConfigData config; switch (proj.getPackaging()) { case "war": validateAppConfig(application, proj.getArtifactId()); log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName)); - installLooseConfigWar(proj, config); + config = new LooseConfigData(); + installLooseConfigWar(proj, config, false); installAndVerifyApp(config, looseConfigFile, application); + if (proj.getProperties().containsKey("container")) { + // install another copy that is container specific + config = new LooseConfigData(); + installLooseConfigWar(proj, config, true); + config.toXmlFile(devcLooseConfigFile); + } break; case "ear": validateAppConfig(application, proj.getArtifactId()); log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName)); + config = new LooseConfigData(); installLooseConfigEar(proj, config); installAndVerifyApp(config, looseConfigFile, application); break; @@ -209,8 +222,15 @@ private void installLooseApplication(MavenProject proj) throws Exception { if (mavenWarPluginExists(proj) || new File(proj.getBasedir(), "src/main/webapp").exists()) { validateAppConfig(application, proj.getArtifactId()); log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName)); - installLooseConfigWar(proj, config); + config = new LooseConfigData(); + installLooseConfigWar(proj, config, false); installAndVerifyApp(config, looseConfigFile, application); + if (proj.getProperties().containsKey("container")) { + // install another copy that is container specific + config = new LooseConfigData(); + installLooseConfigWar(proj, config, true); + config.toXmlFile(devcLooseConfigFile); + } } else { log.debug("The liberty-assembly project does not contain the maven-war-plugin or src/main/webapp does not exist."); } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java index acd423d49..d6f9d36d1 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java @@ -104,7 +104,7 @@ protected void installApp(Artifact artifact) throws Exception { } // install war project artifact using loose application configuration file - protected void installLooseConfigWar(MavenProject proj, LooseConfigData config) throws Exception { + protected void installLooseConfigWar(MavenProject proj, LooseConfigData config, boolean container) throws Exception { // return error if webapp contains java source but it is not compiled yet. File dir = new File(proj.getBuild().getOutputDirectory()); if (!dir.exists() && containsJavaSource(proj)) { @@ -112,7 +112,7 @@ protected void installLooseConfigWar(MavenProject proj, LooseConfigData config) MessageFormat.format(messages.getString("error.project.not.compile"), proj.getId())); } - if (proj.getProperties().containsKey("container")) { + if (container) { try { // Set up the config to replace the absolute path names with ${variable}/target type references config.setProjectRoot(proj.getBasedir().getCanonicalPath()); diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index b50ba2ca8..703e32610 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -231,7 +231,7 @@ private class DevMojoUtil extends DevUtil { public DevMojoUtil(File installDir, File userDir, File serverDirectory, File sourceDirectory, File testSourceDirectory, File configDirectory, File projectDirectory, List resourceDirs, JavaCompilerOptions compilerOptions, String mavenCacheLocation) throws IOException { - super(serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, projectDirectory, resourceDirs, hotTests, + super(new File(project.getBuild().getDirectory()), serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, projectDirectory, resourceDirs, hotTests, skipTests, skipUTs, skipITs, project.getArtifactId(), serverStartTimeout, verifyTimeout, verifyTimeout, ((long) (compileWait * 1000L)), libertyDebug, false, false, pollingTest, container, dockerfile, dockerRunOpts, dockerBuildTimeout, skipDefaultPorts, compilerOptions, keepTempDockerfile, mavenCacheLocation); @@ -348,9 +348,6 @@ public ServerTask getServerTask() throws Exception { // Setup server task serverTask = initializeJava(); copyConfigFiles(); - if (container) { - generateDevModeConfig(project.getBasedir().getCanonicalPath(), HEADER); - } serverTask.setClean(clean); if (libertyDebug) { setLibertyDebugPort(libertyDebugPort); From 5b07d1b0bdaac4a4ad444ea58f874532689017f4 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Fri, 29 Jan 2021 14:39:12 -0500 Subject: [PATCH 2/2] Refactor --- .../io/openliberty/tools/maven/applications/DeployMojo.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java index 3c7de12f6..5973d1eef 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java @@ -195,13 +195,12 @@ private void installLooseApplication(MavenProject proj) throws Exception { File devcDestDir = new File(new File(project.getBuild().getDirectory(), DevUtil.DEVC_HIDDEN_FOLDER), getAppsDirectory()); File devcLooseConfigFile = new File(devcDestDir, looseConfigFileName); - LooseConfigData config; + LooseConfigData config = new LooseConfigData(); switch (proj.getPackaging()) { case "war": validateAppConfig(application, proj.getArtifactId()); log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName)); - config = new LooseConfigData(); installLooseConfigWar(proj, config, false); installAndVerifyApp(config, looseConfigFile, application); if (proj.getProperties().containsKey("container")) { @@ -214,7 +213,6 @@ private void installLooseApplication(MavenProject proj) throws Exception { case "ear": validateAppConfig(application, proj.getArtifactId()); log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName)); - config = new LooseConfigData(); installLooseConfigEar(proj, config); installAndVerifyApp(config, looseConfigFile, application); break; @@ -222,7 +220,6 @@ private void installLooseApplication(MavenProject proj) throws Exception { if (mavenWarPluginExists(proj) || new File(proj.getBasedir(), "src/main/webapp").exists()) { validateAppConfig(application, proj.getArtifactId()); log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName)); - config = new LooseConfigData(); installLooseConfigWar(proj, config, false); installAndVerifyApp(config, looseConfigFile, application); if (proj.getProperties().containsKey("container")) {