From e3965402bbc8e41727e640c1819735cab2ca9d18 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 9 Sep 2024 11:26:22 +0530 Subject: [PATCH 1/9] removing use of deprecated plugin conventions Signed-off-by: Arun Venmany --- .../tools/gradle/tasks/CompileJSPTask.groovy | 15 ++++--- .../gradle/utils/LooseEarApplication.groovy | 44 ++++++++++--------- .../gradle/utils/LooseWarApplication.groovy | 22 +++++----- .../gradle/KernelInstallFeatureTest.groovy | 5 +-- 4 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy index 0fd15f2cf..1d9fe5340 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy @@ -59,17 +59,20 @@ class CompileJSPTask extends AbstractFeatureTask { protected void perTaskCompileJSP(Task task) throws Exception { CompileJSPs compileJsp = new CompileJSPs() compileJsp.setInstallDir(getInstallDir(project)) - compileJsp.setTempdir(project.buildDir) - compileJsp.setDestdir(new File(project.buildDir.getAbsolutePath()+"/classes/java")) + compileJsp.setTempdir(project.getLayout().getBuildDirectory().getAsFile().get()) + compileJsp.setDestdir(new File(project.getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath()+"/classes/java")) compileJsp.setTimeout(project.liberty.jsp.jspCompileTimeout) // don't delete temporary server dir compileJsp.setCleanup(false) compileJsp.setProject(ant) compileJsp.setTaskName('antlib:net/wasdev/wlp/ant:compileJSPs') - - if (project.convention.plugins.war.webAppDirName != null) { - compileJsp.setSrcdir(project.convention.plugins.war.webAppDir) - } else { + War war; + if(project.plugins.hasPlugin("war")){ + war = (War)project.war + if ( war.webAppDirectory.asFile.get() != null) { + compileJsp.setSrcdir( war.webAppDirectory.asFile.get()) + } + }else { compileJsp.setSrcdir(new File("src/main/webapp")) } Set classpath = new HashSet(); diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy index 04ac2e57c..844f68edb 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy @@ -1,42 +1,44 @@ package io.openliberty.tools.gradle.utils -import java.io.File +import io.openliberty.tools.common.plugins.config.LooseApplication +import io.openliberty.tools.common.plugins.config.LooseConfigData +import org.apache.commons.io.FilenameUtils import org.gradle.api.Project -import org.gradle.plugins.ear.EarPluginConvention import org.gradle.api.Task import org.gradle.plugins.ear.Ear -import org.gradle.api.internal.file.FileResolver -import org.gradle.api.artifacts.Dependency -import org.w3c.dom.Element; -import org.apache.commons.io.FilenameUtils - -import io.openliberty.tools.common.plugins.config.LooseConfigData -import io.openliberty.tools.common.plugins.util.PluginExecutionException -import io.openliberty.tools.common.plugins.config.LooseApplication +import org.w3c.dom.Element public class LooseEarApplication extends LooseApplication { protected Task task; public LooseEarApplication(Task task, LooseConfigData config) { - super(task.getProject().getBuildDir().getAbsolutePath(), config) + super(task.getProject().getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath(), config) this.task = task } public void addSourceDir() throws Exception { - File sourceDir = new File(task.getProject().path.replace(":","") + "/" + task.getProject().getConvention().getPlugin(EarPluginConvention.class).getAppDirName()) - config.addDir(sourceDir, "/") + if (task.getProject().getPlugins().hasPlugin("ear")) { + Ear ear = (Ear) task.getProject().ear + File sourceDir = new File(task.getProject().path.replace(":","") + "/" + ear.getAppDirectory().getAsFile().get().getAbsolutePath()) + config.addDir(sourceDir, "/") + } } public void addApplicationXmlFile() throws Exception { - String applicationName = "/" + task.getProject().getConvention().getPlugin(EarPluginConvention.class).getDeploymentDescriptor().getFileName() - File applicationXmlFile = new File(task.getProject().path.replace(":","") + "/" + task.getProject().getConvention().getPlugin(EarPluginConvention.class).getAppDirName() + "/META-INF/" + applicationName) - if (applicationXmlFile.exists()) { - config.addFile(applicationXmlFile, "/META-INF/application.xml"); - } - else { - applicationXmlFile = new File(task.getDestinationDirectory().get().getAsFile().getParentFile().getAbsolutePath() + "/tmp/ear" + applicationName); - config.addFile(applicationXmlFile, "/META-INF/application.xml"); + if (task.getProject().getPlugins().hasPlugin("ear")) { + Ear ear = (Ear) task.getProject().ear + String applicationName = "/application.xml" + if (ear.getDeploymentDescriptor() != null){ + applicationName = "/" + ear.getDeploymentDescriptor().getFileName() + } + File applicationXmlFile = new File(task.getProject().path.replace(":", "") + "/" + ear.getAppDirectory().getAsFile().get().getAbsolutePath() + "/META-INF/" + applicationName) + if (applicationXmlFile.exists()) { + config.addFile(applicationXmlFile, "/META-INF/application.xml"); + } else { + applicationXmlFile = new File(task.getDestinationDirectory().get().getAsFile().getParentFile().getAbsolutePath() + "/tmp/ear" + applicationName); + config.addFile(applicationXmlFile, "/META-INF/application.xml"); + } } } diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy index c46e54d50..9a828bc48 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy @@ -1,27 +1,29 @@ package io.openliberty.tools.gradle.utils; -import java.io.File; -import org.gradle.api.Project; -import org.gradle.api.plugins.WarPluginConvention +import io.openliberty.tools.common.plugins.config.LooseApplication +import io.openliberty.tools.common.plugins.config.LooseConfigData import org.gradle.api.Task import org.gradle.api.tasks.bundling.War -import io.openliberty.tools.common.plugins.config.LooseConfigData -import io.openliberty.tools.common.plugins.util.PluginExecutionException -import io.openliberty.tools.common.plugins.config.LooseApplication - public class LooseWarApplication extends LooseApplication { protected Task task; public LooseWarApplication(Task task, LooseConfigData config) { - super(task.getProject().getBuildDir().getAbsolutePath(), config) + super(task.getProject().getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath(), config) this.task = task } public void addSourceDir() throws Exception { - WarPluginConvention wpc = task.getProject().getConvention().findPlugin(WarPluginConvention) - File sourceDir = new File(wpc.getWebAppDir().getAbsolutePath()) + + War war; + File sourceDir = new File("src/main/webapp") + if (task.getProject().getPlugins().hasPlugin("war")) { + war = (War) task.getProject().war + if (war.webAppDirectory.asFile.get() != null) { + sourceDir = new File(war.webAppDirectory.asFile.get().getAbsolutePath()) + } + } config.addDir(sourceDir, "/") } diff --git a/src/test/groovy/io/openliberty/tools/gradle/KernelInstallFeatureTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/KernelInstallFeatureTest.groovy index 50e1bd410..9b139622f 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/KernelInstallFeatureTest.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/KernelInstallFeatureTest.groovy @@ -1,5 +1,5 @@ /* - * (C) Copyright IBM Corporation 2018. + * (C) Copyright IBM Corporation 2018, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,7 @@ */ package io.openliberty.tools.gradle -import static junit.framework.Assert.assertEquals -import static org.junit.Assert.* +import static org.junit.Assert.assertEquals import org.junit.Before import org.junit.BeforeClass From d6de8bc1f673918a36a6cfecca1c28341a14ac23 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 9 Sep 2024 17:06:29 +0530 Subject: [PATCH 2/9] removing use of deprecated plugin conventions Signed-off-by: Arun Venmany --- .../openliberty/tools/gradle/utils/LooseWarApplication.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy index 9a828bc48..e185b157b 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy @@ -20,8 +20,8 @@ public class LooseWarApplication extends LooseApplication { File sourceDir = new File("src/main/webapp") if (task.getProject().getPlugins().hasPlugin("war")) { war = (War) task.getProject().war - if (war.webAppDirectory.asFile.get() != null) { - sourceDir = new File(war.webAppDirectory.asFile.get().getAbsolutePath()) + if (war.getWebAppDirectory().getAsFile().get() != null) { + sourceDir = new File(war.getWebAppDirectory().getAsFile().get().getAbsolutePath()) } } config.addDir(sourceDir, "/") From f80eb886ae179d85fe7fbab7b4cfce7085156645 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 9 Sep 2024 17:09:29 +0530 Subject: [PATCH 3/9] removing use of deprecated plugin conventions Signed-off-by: Arun Venmany --- .../tools/gradle/tasks/CompileJSPTask.groovy | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy index 1d9fe5340..2c3d19b34 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy @@ -15,21 +15,11 @@ */ package io.openliberty.tools.gradle.tasks -import java.io.File; -import java.text.MessageFormat; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.HashSet; - -import org.gradle.api.tasks.TaskAction +import io.openliberty.tools.ant.jsp.CompileJSPs +import org.apache.tools.ant.Project import org.gradle.api.Task -import org.gradle.api.GradleException +import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.bundling.War -import org.gradle.api.logging.LogLevel - -import org.apache.tools.ant.Project; -import io.openliberty.tools.ant.jsp.CompileJSPs; class CompileJSPTask extends AbstractFeatureTask { protected Project ant = new Project(); @@ -69,8 +59,8 @@ class CompileJSPTask extends AbstractFeatureTask { War war; if(project.plugins.hasPlugin("war")){ war = (War)project.war - if ( war.webAppDirectory.asFile.get() != null) { - compileJsp.setSrcdir( war.webAppDirectory.asFile.get()) + if ( war.getWebAppDirectory().getAsFile().get() != null) { + compileJsp.setSrcdir( war.getWebAppDirectory().getAsFile().get()) } }else { compileJsp.setSrcdir(new File("src/main/webapp")) From 10d24a3d01b351327f5425da4d804857d9c3a46f Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 10 Sep 2024 09:29:13 +0530 Subject: [PATCH 4/9] removing use of deprecated plugin conventions Signed-off-by: Arun Venmany --- .../io/openliberty/tools/gradle/tasks/DeployTask.groovy | 4 ++-- .../tools/gradle/utils/LooseEarApplication.groovy | 8 +++++++- .../tools/gradle/utils/LooseWarApplication.groovy | 7 ++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy index 00d3a5132..866a2b823 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy @@ -335,7 +335,7 @@ class DeployTask extends AbstractServerTask { } } - LooseWarApplication looseWar = new LooseWarApplication(task, config) + LooseWarApplication looseWar = new LooseWarApplication(task, config,logger) looseWar.addSourceDir() looseWar.addOutputDir(looseWar.getDocumentRoot() , task.classpath.getFiles().toArray()[0], "/WEB-INF/classes/"); @@ -403,7 +403,7 @@ class DeployTask extends AbstractServerTask { } protected void installLooseConfigEar(LooseConfigData config, Task task) throws Exception{ - LooseEarApplication looseEar = new LooseEarApplication(task, config); + LooseEarApplication looseEar = new LooseEarApplication(task, config, logger); looseEar.addSourceDir(); looseEar.addApplicationXmlFile(); diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy index 844f68edb..4d912ab03 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy @@ -5,16 +5,19 @@ import io.openliberty.tools.common.plugins.config.LooseConfigData import org.apache.commons.io.FilenameUtils import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.logging.Logger import org.gradle.plugins.ear.Ear import org.w3c.dom.Element public class LooseEarApplication extends LooseApplication { protected Task task; + protected Logger logger; - public LooseEarApplication(Task task, LooseConfigData config) { + public LooseEarApplication(Task task, LooseConfigData config, Logger logger) { super(task.getProject().getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath(), config) this.task = task + this.logger = logger } public void addSourceDir() throws Exception { @@ -40,6 +43,9 @@ public class LooseEarApplication extends LooseApplication { config.addFile(applicationXmlFile, "/META-INF/application.xml"); } } + else { + logger.warn("Project is expected to have EAR plugin. Application xml file may not be added correctly") + } } public Element addWarModule(Project proj) throws Exception { diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy index e185b157b..cdc436dc3 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy @@ -3,15 +3,18 @@ package io.openliberty.tools.gradle.utils; import io.openliberty.tools.common.plugins.config.LooseApplication import io.openliberty.tools.common.plugins.config.LooseConfigData import org.gradle.api.Task +import org.gradle.api.logging.Logger import org.gradle.api.tasks.bundling.War public class LooseWarApplication extends LooseApplication { protected Task task; + protected Logger logger; - public LooseWarApplication(Task task, LooseConfigData config) { + public LooseWarApplication(Task task, LooseConfigData config, Logger logger) { super(task.getProject().getLayout().getBuildDirectory().getAsFile().get().getAbsolutePath(), config) this.task = task + this.logger = logger } public void addSourceDir() throws Exception { @@ -23,6 +26,8 @@ public class LooseWarApplication extends LooseApplication { if (war.getWebAppDirectory().getAsFile().get() != null) { sourceDir = new File(war.getWebAppDirectory().getAsFile().get().getAbsolutePath()) } + }else { + logger.warn("Default sourcedir path to src/main/webapp as WAR plugin does not exist. Application may not work expectedly") } config.addDir(sourceDir, "/") } From db825cf9b68fef4727dd8632749528b11329b0e9 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 10 Sep 2024 10:27:05 +0530 Subject: [PATCH 5/9] removing use of deprecated base plugin conventions Signed-off-by: Arun Venmany --- build.gradle | 55 +++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index 91d669312..359a8c2a1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,14 @@ -import java.io.FileOutputStream -import java.io.IOException -import java.io.OutputStream -import java.util.Properties apply plugin: 'groovy' apply plugin: 'maven-publish' apply plugin: 'signing' apply plugin: "com.gradle.plugin-publish" -archivesBaseName = 'liberty-gradle-plugin' group = 'io.openliberty.tools' version = '3.8.4-SNAPSHOT' - +base { + archivesName='liberty-gradle-plugin' +} repositories { mavenLocal() mavenCentral() @@ -116,29 +113,29 @@ test { try { - output = new FileOutputStream("${buildDir}/gradle.properties"); + output = new FileOutputStream("${buildDir}/gradle.properties"); - if (libertyRuntime == "ol") { - runtimeGroup = "io.openliberty" - runtimeArtifactId = "openliberty-runtime" - kernelArtifactId = "openliberty-kernel" - } else { - runtimeGroup = "com.ibm.websphere.appserver.runtime" - runtimeArtifactId = "wlp-javaee7" - kernelArtifactId = "wlp-kernel" - } + if (libertyRuntime == "ol") { + runtimeGroup = "io.openliberty" + runtimeArtifactId = "openliberty-runtime" + kernelArtifactId = "openliberty-kernel" + } else { + runtimeGroup = "com.ibm.websphere.appserver.runtime" + runtimeArtifactId = "wlp-javaee7" + kernelArtifactId = "wlp-kernel" + } - // set the properties value - prop.setProperty("lgpVersion", version) - prop.setProperty("runtimeGroup", runtimeGroup) - prop.setProperty("runtimeArtifactId", runtimeArtifactId) - prop.setProperty("kernelArtifactId", kernelArtifactId) - prop.setProperty("runtimeVersion", runtimeVersion) - prop.setProperty("antVersion", libertyAntVersion) - prop.setProperty("commonVersion", libertyCommonVersion) + // set the properties value + prop.setProperty("lgpVersion", version) + prop.setProperty("runtimeGroup", runtimeGroup) + prop.setProperty("runtimeArtifactId", runtimeArtifactId) + prop.setProperty("kernelArtifactId", kernelArtifactId) + prop.setProperty("runtimeVersion", runtimeVersion) + prop.setProperty("antVersion", libertyAntVersion) + prop.setProperty("commonVersion", libertyCommonVersion) - // save properties to project root folder - prop.store(output, null) + // save properties to project root folder + prop.store(output, null) } catch (IOException io) { io.printStackTrace() @@ -181,11 +178,11 @@ pluginBundle { publishing { publications { libertyGradle (MavenPublication) { - artifactId = archivesBaseName + artifactId = base.archivesName from components.java artifact groovydocJar - artifact sourcesJar + artifact sourcesJar pom { name = 'liberty-gradle-plugin' @@ -218,7 +215,7 @@ publishing { } if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) { - + if (!version.endsWith("SNAPSHOT")) { signing { sign publishing.publications.libertyGradle From 63c0a87fe13e3303c0a3851ce8ac9bb4cc2c78f9 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 10 Sep 2024 10:30:37 +0530 Subject: [PATCH 6/9] removing use of deprecated base plugin conventions Signed-off-by: Arun Venmany --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 359a8c2a1..d87e3eede 100644 --- a/build.gradle +++ b/build.gradle @@ -178,7 +178,7 @@ pluginBundle { publishing { publications { libertyGradle (MavenPublication) { - artifactId = base.archivesName + artifactId = 'liberty-maven-plugin' from components.java artifact groovydocJar From bfd2ea90b999f2513d755228218e176b94f2656d Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 10 Sep 2024 10:43:16 +0530 Subject: [PATCH 7/9] removing use of deprecated base plugin conventions Signed-off-by: Arun Venmany --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d87e3eede..10ee9096f 100644 --- a/build.gradle +++ b/build.gradle @@ -178,7 +178,7 @@ pluginBundle { publishing { publications { libertyGradle (MavenPublication) { - artifactId = 'liberty-maven-plugin' + artifactId = 'liberty-gradle-plugin' from components.java artifact groovydocJar From 90b763297335fec6d6fe4aee940e1b9d2c262a4f Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 10 Sep 2024 21:52:07 +0530 Subject: [PATCH 8/9] incorparating review comments Signed-off-by: Arun Venmany --- build.gradle | 6 +++--- .../gradle/utils/LooseEarApplication.groovy | 18 +++++++++--------- .../gradle/utils/LooseWarApplication.groovy | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 10ee9096f..b5ea7e087 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ - apply plugin: 'groovy' apply plugin: 'maven-publish' apply plugin: 'signing' apply plugin: "com.gradle.plugin-publish" +apply plugin: 'base' group = 'io.openliberty.tools' version = '3.8.4-SNAPSHOT' @@ -113,7 +113,7 @@ test { try { - output = new FileOutputStream("${buildDir}/gradle.properties"); + output = new FileOutputStream("${project.getLayout().getBuildDirectory().getAsFile().get()}/gradle.properties"); if (libertyRuntime == "ol") { runtimeGroup = "io.openliberty" @@ -178,7 +178,7 @@ pluginBundle { publishing { publications { libertyGradle (MavenPublication) { - artifactId = 'liberty-gradle-plugin' + artifactId = base.archivesName.get() from components.java artifact groovydocJar diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy index 4d912ab03..e5968d812 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy @@ -23,28 +23,28 @@ public class LooseEarApplication extends LooseApplication { public void addSourceDir() throws Exception { if (task.getProject().getPlugins().hasPlugin("ear")) { Ear ear = (Ear) task.getProject().ear - File sourceDir = new File(task.getProject().path.replace(":","") + "/" + ear.getAppDirectory().getAsFile().get().getAbsolutePath()) + File sourceDir = new File(task.getProject().path.replace(":","") + "/" + ear.getAppDirectory().getAsFile().get().getPath()) config.addDir(sourceDir, "/") } } public void addApplicationXmlFile() throws Exception { + String applicationName = "/application.xml" + File applicationXmlFile; if (task.getProject().getPlugins().hasPlugin("ear")) { Ear ear = (Ear) task.getProject().ear - String applicationName = "/application.xml" - if (ear.getDeploymentDescriptor() != null){ + if (ear.getDeploymentDescriptor() != null) { applicationName = "/" + ear.getDeploymentDescriptor().getFileName() } - File applicationXmlFile = new File(task.getProject().path.replace(":", "") + "/" + ear.getAppDirectory().getAsFile().get().getAbsolutePath() + "/META-INF/" + applicationName) + applicationXmlFile = new File(task.getProject().path.replace(":", "") + "/" + ear.getAppDirectory().getAsFile().get().getAbsolutePath() + "/META-INF/" + applicationName) if (applicationXmlFile.exists()) { config.addFile(applicationXmlFile, "/META-INF/application.xml"); - } else { - applicationXmlFile = new File(task.getDestinationDirectory().get().getAsFile().getParentFile().getAbsolutePath() + "/tmp/ear" + applicationName); - config.addFile(applicationXmlFile, "/META-INF/application.xml"); } } - else { - logger.warn("Project is expected to have EAR plugin. Application xml file may not be added correctly") + if (applicationXmlFile == null || !applicationXmlFile.exists()) { + applicationXmlFile = new File(task.getDestinationDirectory().get().getAsFile().getParentFile().getAbsolutePath() + "/tmp/ear" + applicationName); + config.addFile(applicationXmlFile, "/META-INF/application.xml"); + logger.warn("Could not get the application.xml file location from the EAR plugin because it is not configured. The file may not be added correctly to the application archive.") } } diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy index cdc436dc3..35a74c3bf 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseWarApplication.groovy @@ -27,7 +27,7 @@ public class LooseWarApplication extends LooseApplication { sourceDir = new File(war.getWebAppDirectory().getAsFile().get().getAbsolutePath()) } }else { - logger.warn("Default sourcedir path to src/main/webapp as WAR plugin does not exist. Application may not work expectedly") + logger.warn("Could not get the webAppDirectory location from the WAR plugin because it is not configured. Using the default location src/main/webapp instead. Application may not work as expected.") } config.addDir(sourceDir, "/") } From a75a5b0e4056b4e2c3d0e7e0f9439affc3f05014 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 11 Sep 2024 09:45:20 +0530 Subject: [PATCH 9/9] incorparating review comments Signed-off-by: Arun Venmany --- .../tools/gradle/utils/LooseEarApplication.groovy | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy index e5968d812..01073ae8e 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/LooseEarApplication.groovy @@ -38,13 +38,12 @@ public class LooseEarApplication extends LooseApplication { } applicationXmlFile = new File(task.getProject().path.replace(":", "") + "/" + ear.getAppDirectory().getAsFile().get().getAbsolutePath() + "/META-INF/" + applicationName) if (applicationXmlFile.exists()) { - config.addFile(applicationXmlFile, "/META-INF/application.xml"); + config.addFile(applicationXmlFile, "/META-INF/application.xml") } } if (applicationXmlFile == null || !applicationXmlFile.exists()) { applicationXmlFile = new File(task.getDestinationDirectory().get().getAsFile().getParentFile().getAbsolutePath() + "/tmp/ear" + applicationName); - config.addFile(applicationXmlFile, "/META-INF/application.xml"); - logger.warn("Could not get the application.xml file location from the EAR plugin because it is not configured. The file may not be added correctly to the application archive.") + config.addFile(applicationXmlFile, "/META-INF/application.xml") } }