diff --git a/build.gradle b/build.gradle index 91d66931..b5ea7e08 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" +apply plugin: 'base' -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("${project.getLayout().getBuildDirectory().getAsFile().get()}/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.get() 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 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 fd994410..93caae73 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy @@ -15,24 +15,15 @@ */ 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 import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms - class CompileJSPTask extends AbstractFeatureTask { protected Project ant = new Project(); @@ -61,17 +52,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.getWebAppDirectory().getAsFile().get() != null) { + compileJsp.setSrcdir( war.getWebAppDirectory().getAsFile().get()) + } + }else { compileJsp.setSrcdir(new File("src/main/webapp")) } Set classpath = new HashSet(); 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 00d3a513..866a2b82 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 04ac2e57..01073ae8 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,49 @@ 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.api.logging.Logger 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; + protected Logger logger; - public LooseEarApplication(Task task, LooseConfigData config) { - super(task.getProject().getBuildDir().getAbsolutePath(), 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 { - 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().getPath()) + 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"); + String applicationName = "/application.xml" + File applicationXmlFile; + if (task.getProject().getPlugins().hasPlugin("ear")) { + Ear ear = (Ear) task.getProject().ear + if (ear.getDeploymentDescriptor() != null) { + applicationName = "/" + ear.getDeploymentDescriptor().getFileName() + } + 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 { + if (applicationXmlFile == null || !applicationXmlFile.exists()) { applicationXmlFile = new File(task.getDestinationDirectory().get().getAsFile().getParentFile().getAbsolutePath() + "/tmp/ear" + applicationName); - config.addFile(applicationXmlFile, "/META-INF/application.xml"); + 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 c46e54d5..35a74c3b 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,34 @@ 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.logging.Logger 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; + protected Logger logger; - public LooseWarApplication(Task task, LooseConfigData config) { - super(task.getProject().getBuildDir().getAbsolutePath(), 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 { - 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.getWebAppDirectory().getAsFile().get() != null) { + sourceDir = new File(war.getWebAppDirectory().getAsFile().get().getAbsolutePath()) + } + }else { + 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, "/") } diff --git a/src/test/groovy/io/openliberty/tools/gradle/KernelInstallFeatureTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/KernelInstallFeatureTest.groovy index 50e1bd41..9b139622 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