From c9303be3a2af7af9af7f6f050fd539e0bced7196 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Tue, 10 Sep 2024 16:17:33 -0500 Subject: [PATCH 1/5] Add support for versionless features --- .github/workflows/gradle.yml | 5 ++-- .../gradle/tasks/AbstractFeatureTask.groovy | 28 +++++++++++-------- .../tools/gradle/tasks/CompileJSPTask.groovy | 12 ++++++-- .../tools/gradle/tasks/DevTask.groovy | 22 +++++++++++---- .../gradle/tasks/GenerateFeaturesTask.groovy | 15 +++++----- .../gradle/tasks/InstallFeatureTask.groovy | 8 ++++-- 6 files changed, 58 insertions(+), 32 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 6bef8a39..60025a96 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -39,7 +39,8 @@ jobs: - name: Checkout ci.common uses: actions/checkout@v3 with: - repository: OpenLiberty/ci.common + repository: cbridgha/ci.common + ref: VersionlessFeatureSupport path: ci.common - name: Checkout ci.ant uses: actions/checkout@v3 @@ -124,7 +125,7 @@ jobs: - name: Clone ci.ant, ci.common, ci.gradle repos to C drive run: | cp -r D:/a/ci.gradle/ci.gradle C:/ci.gradle - git clone https://github.com/OpenLiberty/ci.common.git C:/ci.common + git clone https://github.com/cbridgha/ci.common.git --branch VersionlessFeatureSupport --single-branch C:/ci.common git clone https://github.com/OpenLiberty/ci.ant.git C:/ci.ant # Cache mvn/gradle packages - name: Cache Maven packages diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy index 291cdc5c..4588e916 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy @@ -15,13 +15,14 @@ */ package io.openliberty.tools.gradle.tasks - import io.openliberty.tools.common.plugins.util.AbstractContainerSupportUtil import io.openliberty.tools.common.plugins.util.InstallFeatureUtil import io.openliberty.tools.common.plugins.util.InstallFeatureUtil.ProductProperties import io.openliberty.tools.common.plugins.util.PluginExecutionException import io.openliberty.tools.common.plugins.util.PluginScenarioException import io.openliberty.tools.common.plugins.util.ServerFeatureUtil +import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms + import io.openliberty.tools.gradle.utils.ArtifactDownloadUtil import org.gradle.api.artifacts.Configuration import org.gradle.api.logging.LogLevel @@ -217,33 +218,36 @@ public class AbstractFeatureTask extends AbstractServerTask { return result; } - protected Set getSpecifiedFeatures(String containerName) throws PluginExecutionException { - InstallFeatureUtil util = getInstallFeatureUtil(null, containerName); + protected FeaturesPlatforms getSpecifiedFeatures(String containerName) throws PluginExecutionException { + InstallFeatureUtil util = getInstallFeatureUtil(null, containerName) + FeaturesPlatforms getServerFeaturesResult = new FeaturesPlatforms() // if createNewInstallFeatureUtil failed to create a new InstallFeatureUtil instance, then features are installed via ant if (installFeaturesFromAnt) { - Set featuresInstalledFromAnt; + Set featuresInstalledFromAnt if (server.features.name != null) { - featuresInstalledFromAnt = new HashSet(server.features.name); - return featuresInstalledFromAnt; + featuresInstalledFromAnt = new HashSet(server.features.name) + return new FeaturesPlatforms(featuresInstalledFromAnt, new HashSet()) } else { - featuresInstalledFromAnt = new HashSet(); - return featuresInstalledFromAnt; + featuresInstalledFromAnt = new HashSet() + return getServerFeaturesResult } } def pluginListedFeatures = getPluginListedFeatures(false) def dependencyFeatures = getDependencyFeatures() - def serverFeatures = null; // if DevMode provides a server directory parameter use that for finding the server features if (serverDirectoryParam != null) { - serverFeatures = util.getServerFeatures(new File(serverDirectoryParam), getLibertyDirectoryPropertyFiles(serverDirectoryParam)) + getServerFeaturesResult = util.getServerFeatures(new File(serverDirectoryParam), getLibertyDirectoryPropertyFiles(serverDirectoryParam)) } else if (getServerDir(project).exists()) { - serverFeatures = util.getServerFeatures(getServerDir(project), getLibertyDirectoryPropertyFiles(null)) + getServerFeaturesResult = util.getServerFeatures(getServerDir(project), getLibertyDirectoryPropertyFiles(null)) } + Set serverFeatures = getServerFeaturesResult != null ? getServerFeaturesResult.getFeatures() : new HashSet() + Set serverPlatforms = getServerFeaturesResult != null ? getServerFeaturesResult.getPlatforms() : new HashSet() + Set featuresToInstall = util.combineToSet(pluginListedFeatures, dependencyFeatures, serverFeatures) - return featuresToInstall + return new FeaturesPlatforms(featuresToInstall, serverPlatforms) } /* 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 0fd15f2c..fd994410 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/CompileJSPTask.groovy @@ -28,8 +28,10 @@ import org.gradle.api.GradleException 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 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(); @@ -89,7 +91,11 @@ class CompileJSPTask extends AbstractFeatureTask { setCompileJavaSourceVersion(compileJsp, task) //Feature list - Set installedFeatures = getSpecifiedFeatures(null); + Set installedFeatures = new HashSet(); + FeaturesPlatforms fp = getSpecifiedFeatures(null); + if (fp != null) { + installedFeatures = fp.getFeatures(); + } //Set JSP Feature Version setJspVersion(compileJsp, installedFeatures); diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy index c558d544..c42116f0 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2019, 2023, 2024. + * (C) Copyright IBM Corporation 2019, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,10 +38,11 @@ import java.util.concurrent.ThreadPoolExecutor import io.openliberty.tools.ant.ServerTask import io.openliberty.tools.common.plugins.util.DevUtil -import io.openliberty.tools.common.plugins.util.InstallFeatureUtil; +import io.openliberty.tools.common.plugins.util.InstallFeatureUtil import io.openliberty.tools.common.plugins.util.PluginExecutionException import io.openliberty.tools.common.plugins.util.PluginScenarioException import io.openliberty.tools.common.plugins.util.ServerFeatureUtil +import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms import io.openliberty.tools.common.plugins.util.ServerStatusUtil import io.openliberty.tools.common.plugins.util.ProjectModule import io.openliberty.tools.common.plugins.util.BinaryScannerUtil @@ -363,6 +364,7 @@ class DevTask extends AbstractFeatureTask { private class DevTaskUtil extends DevUtil { Set existingFeatures; + Set existingPlatforms; Set existingLibertyFeatureDependencies; @@ -388,7 +390,12 @@ class DevTask extends AbstractFeatureTask { this.libertyDirPropertyFiles = AbstractServerTask.getLibertyDirectoryPropertyFiles(installDirectory, userDirectory, serverDirectory); ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles); - this.existingFeatures = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles); + FeaturesPlatforms fp = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles); + + if (fp != null) { + this.existingFeatures = fp.getFeatures() + this.existingPlatforms = fp.getPlatforms() + } this.existingLibertyFeatureDependencies = new HashSet(); @@ -823,7 +830,8 @@ class DevTask extends AbstractFeatureTask { @Override public void installFeatures(File configFile, File serverDir, boolean generateFeatures) { ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles); - Set features = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles); + FeaturesPlatforms fp = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles); + Set features = fp == null ? null : fp.getFeatures(); if (features == null) { return; @@ -885,8 +893,10 @@ class DevTask extends AbstractFeatureTask { @Override public void updateExistingFeatures() { ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles); - Set features = servUtil.getServerFeatures(getServerDir(project), libertyDirPropertyFiles); - existingFeatures = features; + FeaturesPlatforms fp = servUtil.getServerFeatures(getServerDir(project), libertyDirPropertyFiles); + + this.existingFeatures = fp == null ? new HashSet() : fp.getFeatures(); + this.existingPlatforms = fp == null ? new HashSet() : fp.getPlatforms(); } @Override diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/GenerateFeaturesTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/GenerateFeaturesTask.groovy index 8db57926..6a57fb4a 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/GenerateFeaturesTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/GenerateFeaturesTask.groovy @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2021, 2023. + * (C) Copyright IBM Corporation 2021, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import io.openliberty.tools.common.plugins.util.BinaryScannerUtil import static io.openliberty.tools.common.plugins.util.BinaryScannerUtil.*; import io.openliberty.tools.common.plugins.util.PluginExecutionException import io.openliberty.tools.common.plugins.util.ServerFeatureUtil +import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms import io.openliberty.tools.gradle.utils.ArtifactDownloadUtil import org.gradle.api.GradleException @@ -174,10 +175,11 @@ class GenerateFeaturesTask extends AbstractFeatureTask { servUtil.setLowerCaseFeatures(false); // get set of user defined features so they can be omitted from the generated file that will be written - Set userDefinedFeatures = optimize ? existingFeatures : servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap(), generatedFiles); + FeaturesPlatforms fp = optimize ? existingFeatures : servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap(), generatedFiles); + Set userDefinedFeatures = fp == null ? new HashSet() : fp.getFeatures(); logger.debug("User defined features:" + userDefinedFeatures); servUtil.setLowerCaseFeatures(true); - if (userDefinedFeatures != null) { + if (!userDefinedFeatures.isEmpty()) { missingLibertyFeatures.removeAll(userDefinedFeatures); } } @@ -233,10 +235,9 @@ class GenerateFeaturesTask extends AbstractFeatureTask { private Set getServerFeatures(ServerFeatureUtil servUtil, Set generatedFiles, boolean excludeGenerated) { servUtil.setLowerCaseFeatures(false); // if optimizing, ignore generated files when passing in existing features to binary scanner - Set existingFeatures = servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap(), excludeGenerated ? generatedFiles : null); // pass generatedFiles to exclude them - if (existingFeatures == null) { - existingFeatures = new HashSet(); - } + FeaturesPlatforms fp = servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap(), excludeGenerated ? generatedFiles : null); // pass generatedFiles to exclude them + Set existingFeatures = fp == null ? new HashSet() : fp.getFeatures(); + servUtil.setLowerCaseFeatures(true); return existingFeatures; } diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/InstallFeatureTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/InstallFeatureTask.groovy index 0e222437..5b61a0f6 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/InstallFeatureTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/InstallFeatureTask.groovy @@ -27,6 +27,7 @@ import io.openliberty.tools.common.plugins.util.InstallFeatureUtil import io.openliberty.tools.common.plugins.util.DevUtil import io.openliberty.tools.common.plugins.util.PluginExecutionException import io.openliberty.tools.common.plugins.util.PluginScenarioException +import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms class InstallFeatureTask extends AbstractFeatureTask { @@ -78,8 +79,11 @@ class InstallFeatureTask extends AbstractFeatureTask { installFeatureFromAnt(); } else { - Set featuresToInstall = getSpecifiedFeatures(containerName); - util.installFeatures(server.features.acceptLicense, new ArrayList(featuresToInstall)) + FeaturesPlatforms fp = getSpecifiedFeatures(containerName); + Set featuresToInstall = fp == null ? new HashSet() : fp.getFeatures(); + Set platformsToInstall = fp == null ? new HashSet() : fp.getPlatforms(); + + util.installFeatures(server.features.acceptLicense, new ArrayList(featuresToInstall), new ArrayList(platformsToInstall)) } } From b6ad00462be2dbaa99c72c41da9109bd12713337 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Tue, 10 Sep 2024 20:22:08 -0500 Subject: [PATCH 2/5] Couple more fixes --- .../tools/gradle/tasks/AbstractFeatureTask.groovy | 8 ++------ .../tools/gradle/tasks/GenerateFeaturesTask.groovy | 13 +++++++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy index 4588e916..8b0e7384 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractFeatureTask.groovy @@ -223,14 +223,10 @@ public class AbstractFeatureTask extends AbstractServerTask { FeaturesPlatforms getServerFeaturesResult = new FeaturesPlatforms() // if createNewInstallFeatureUtil failed to create a new InstallFeatureUtil instance, then features are installed via ant if (installFeaturesFromAnt) { - Set featuresInstalledFromAnt if (server.features.name != null) { - featuresInstalledFromAnt = new HashSet(server.features.name) - return new FeaturesPlatforms(featuresInstalledFromAnt, new HashSet()) - } else { - featuresInstalledFromAnt = new HashSet() - return getServerFeaturesResult + getServerFeaturesResult.getFeatures().addAll(server.features.name) } + return getServerFeaturesResult } def pluginListedFeatures = getPluginListedFeatures(false) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/GenerateFeaturesTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/GenerateFeaturesTask.groovy index 6a57fb4a..c7e1b5c5 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/GenerateFeaturesTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/GenerateFeaturesTask.groovy @@ -175,8 +175,13 @@ class GenerateFeaturesTask extends AbstractFeatureTask { servUtil.setLowerCaseFeatures(false); // get set of user defined features so they can be omitted from the generated file that will be written - FeaturesPlatforms fp = optimize ? existingFeatures : servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap(), generatedFiles); - Set userDefinedFeatures = fp == null ? new HashSet() : fp.getFeatures(); + Set userDefinedFeatures = optimize ? existingFeatures : new HashSet(); + if (!optimize) { + FeaturesPlatforms fp = servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap(), generatedFiles); + if (fp != null) { + userDefinedFeatures = fp.getFeatures(); + } + } logger.debug("User defined features:" + userDefinedFeatures); servUtil.setLowerCaseFeatures(true); if (!userDefinedFeatures.isEmpty()) { @@ -245,9 +250,9 @@ class GenerateFeaturesTask extends AbstractFeatureTask { // returns the features specified in the generated-features.xml file private Set getGeneratedFeatures(ServerFeatureUtil servUtil, File generatedFeaturesFile) { servUtil.setLowerCaseFeatures(false); - Set genFeatSet = new HashSet(); - servUtil.getServerXmlFeatures(genFeatSet, server.configDirectory, + FeaturesPlatforms fp = servUtil.getServerXmlFeatures(new FeaturesPlatforms(), server.configDirectory, generatedFeaturesFile, null, null); + Set genFeatSet = fp == null ? new HashSet() : fp.getFeatures(); servUtil.setLowerCaseFeatures(true); return genFeatSet; } From fbd54fc46e0352b38e90db9ae58d328815175693 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Wed, 11 Sep 2024 16:19:43 -0500 Subject: [PATCH 3/5] Add test case for versionless features --- .github/workflows/gradle.yml | 4 +- ...KernelInstallVersionlessFeatureTest.groovy | 99 +++++++++++++++++++ .../server_versionless_feature.xml | 9 ++ .../build.gradle | 24 +++++ .../build_wlp.gradle | 24 +++++ .../install_features_server.gradle | 31 ++++++ .../server_empty.xml | 5 + .../server_versionless_feature.xml | 9 ++ .../settings.gradle | 1 + 9 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy create mode 100644 src/test/resources/kernel-install-feature-test/server_versionless_feature.xml create mode 100644 src/test/resources/kernel-install-versionless-feature-test/build.gradle create mode 100644 src/test/resources/kernel-install-versionless-feature-test/build_wlp.gradle create mode 100644 src/test/resources/kernel-install-versionless-feature-test/install_features_server.gradle create mode 100644 src/test/resources/kernel-install-versionless-feature-test/server_empty.xml create mode 100644 src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature.xml create mode 100644 src/test/resources/kernel-install-versionless-feature-test/settings.gradle diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 60025a96..b7f0ea4d 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -18,7 +18,7 @@ jobs: matrix: # test against latest update of each major Java version, as well as specific updates of LTS versions: RUNTIME: [ol, wlp] - RUNTIME_VERSION: [24.0.0.6] + RUNTIME_VERSION: [24.0.0.9] java: [21, 17, 11, 8] exclude: - java: 8 @@ -101,7 +101,7 @@ jobs: matrix: # test against latest update of each major Java version, as well as specific updates of LTS versions: RUNTIME: [ol, wlp] - RUNTIME_VERSION: [24.0.0.6] + RUNTIME_VERSION: [24.0.0.9] java: [21, 17, 11, 8] exclude: - java: 8 diff --git a/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy new file mode 100644 index 00000000..c6cc7f6e --- /dev/null +++ b/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy @@ -0,0 +1,99 @@ +/* + * (C) Copyright IBM Corporation 2024. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.openliberty.tools.gradle + +import static junit.framework.Assert.assertEquals +import static org.junit.Assert.* + +import org.junit.Before +import org.junit.BeforeClass +import org.junit.Test + +import io.openliberty.tools.common.plugins.util.InstallFeatureUtil + +class KernelInstallVersionlessFeatureTest extends AbstractIntegrationTest{ + static File resourceDir = new File("build/resources/test/kernel-install-versionless-feature-test") + static File buildDir = new File(integTestDir, "/kernel-install-versionless-feature-test") + static String buildFilename = "build.gradle" + + @BeforeClass + public static void setup() { + createDir(buildDir) + createTestProject(buildDir, resourceDir, buildFilename) + } + + @Before + public void before() { + runTasks(buildDir, "libertyCreate") + copyServer("server_empty.xml") + deleteDir(new File(buildDir, "build/wlp/lib/features")) + } + + @Test + /** + * Install with only server.xml features + */ + public void testInstallVersionlessFeaturesServer() { + copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir) + runTasks(buildDir, "libertyCreate") + copyServer("server_versionless_feature.xml") + runTasks(buildDir, "installFeature") + assertInstalled("beanValidation-2.0") + assertInstalled("servlet-4.0") + assertInstalled("jpa-2.2") + assertInstalled("ejb-3.2") + assertNotInstalled("couchdb-1.0") + assertNotInstalled("distributedMap-1.0") + } + + private copyServer(String serverFile) { + copyFile(new File(resourceDir, serverFile), new File(buildDir, "build/wlp/usr/servers/defaultServer/server.xml")) + } + + private void assertInstallStatus(String feature, boolean expectation) throws Exception { + String expectationString = (expectation ? "installed" : "not installed"); + assertEquals("Feature " + feature + " was expected to be " + expectationString + " in the lib/features directory", expectation, existsInFeaturesDirectory(feature)); + String featureInfo = getFeatureInfo(); + assertEquals("Feature " + feature + " was expected to be " + expectationString + " according to productInfo featureInfo: " + featureInfo, expectation, featureInfo.contains(feature)); + } + + protected void assertInstalled(String feature) throws Exception { + assertInstallStatus(feature, true); + } + + protected void assertNotInstalled(String feature) throws Exception { + assertInstallStatus(feature, false); + } + + private boolean existsInFeaturesDirectory(String feature) { + File[] features; + File featuresDir = new File(buildDir, "build/wlp/lib/features") + + features = featuresDir.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.toLowerCase().equals("com.ibm.websphere.appserver." + feature.toLowerCase() + ".mf"); + } + }); + + return features.size() >= 1; + } + + private String getFeatureInfo() throws Exception { + File installDirectory = new File(buildDir, "build/wlp") + return InstallFeatureUtil.productInfo(installDirectory, "featureInfo"); + } + +} diff --git a/src/test/resources/kernel-install-feature-test/server_versionless_feature.xml b/src/test/resources/kernel-install-feature-test/server_versionless_feature.xml new file mode 100644 index 00000000..2435856c --- /dev/null +++ b/src/test/resources/kernel-install-feature-test/server_versionless_feature.xml @@ -0,0 +1,9 @@ + + + beanValidation + servlet + jpa + ejb + javaee-8.0 + + diff --git a/src/test/resources/kernel-install-versionless-feature-test/build.gradle b/src/test/resources/kernel-install-versionless-feature-test/build.gradle new file mode 100644 index 00000000..ab4fdcb8 --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/build.gradle @@ -0,0 +1,24 @@ +apply plugin: 'liberty' + +buildscript { + repositories{ + mavenLocal() + mavenCentral() + maven { + name = 'Sonatype Nexus Snapshots' + url = 'https://oss.sonatype.org/content/repositories/snapshots/' + } + } + dependencies { + classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion" + } +} + +repositories { + mavenLocal() + mavenCentral() +} + +liberty { + runtime = ['group': runtimeGroup,'name':kernelArtifactId,'version':runtimeVersion] +} diff --git a/src/test/resources/kernel-install-versionless-feature-test/build_wlp.gradle b/src/test/resources/kernel-install-versionless-feature-test/build_wlp.gradle new file mode 100644 index 00000000..f3747479 --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/build_wlp.gradle @@ -0,0 +1,24 @@ +apply plugin: 'liberty' + +buildscript { + repositories{ + mavenLocal() + mavenCentral() + maven { + name = 'Sonatype Nexus Snapshots' + url = 'https://oss.sonatype.org/content/repositories/snapshots/' + } + } + dependencies { + classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion" + } +} + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + libertyRuntime group: 'com.ibm.websphere.appserver.runtime', name: 'wlp-kernel', version: runtimeVersion +} diff --git a/src/test/resources/kernel-install-versionless-feature-test/install_features_server.gradle b/src/test/resources/kernel-install-versionless-feature-test/install_features_server.gradle new file mode 100644 index 00000000..09ab788b --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/install_features_server.gradle @@ -0,0 +1,31 @@ +buildscript { + repositories { + mavenLocal() + mavenCentral() + maven { + name = 'Sonatype Nexus Snapshots' + url = 'https://oss.sonatype.org/content/repositories/snapshots/' + } + } + dependencies { + classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion" + } +} + +apply plugin: 'liberty' + +repositories { + mavenCentral() +} + +dependencies { + libertyRuntime group: runtimeGroup, name: kernelArtifactId, version: runtimeVersion +} + +liberty { + server{ + features { + acceptLicense = true + } + } +} diff --git a/src/test/resources/kernel-install-versionless-feature-test/server_empty.xml b/src/test/resources/kernel-install-versionless-feature-test/server_empty.xml new file mode 100644 index 00000000..3bd4b2b8 --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/server_empty.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature.xml b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature.xml new file mode 100644 index 00000000..2435856c --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature.xml @@ -0,0 +1,9 @@ + + + beanValidation + servlet + jpa + ejb + javaee-8.0 + + diff --git a/src/test/resources/kernel-install-versionless-feature-test/settings.gradle b/src/test/resources/kernel-install-versionless-feature-test/settings.gradle new file mode 100644 index 00000000..c2d3edc1 --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/settings.gradle @@ -0,0 +1 @@ +//Empty \ No newline at end of file From 0b4c021f32606eb143c6851979def052b3512fb0 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 12 Sep 2024 10:31:07 -0500 Subject: [PATCH 4/5] More positive and negative tests --- .../gradle/AbstractIntegrationTest.groovy | 19 ++++++ ...KernelInstallVersionlessFeatureTest.groovy | 60 ++++++++++++++++++- .../server_versionless_feature_2.xml | 6 ++ ...server_versionless_feature_no_platform.xml | 5 ++ ...onless_feature_with_versioned_feature.xml} | 3 +- 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_2.xml create mode 100644 src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_no_platform.xml rename src/test/resources/{kernel-install-feature-test/server_versionless_feature.xml => kernel-install-versionless-feature-test/server_versionless_feature_with_versioned_feature.xml} (73%) diff --git a/src/test/groovy/io/openliberty/tools/gradle/AbstractIntegrationTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/AbstractIntegrationTest.groovy index 566faa06..331359c9 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/AbstractIntegrationTest.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/AbstractIntegrationTest.groovy @@ -149,6 +149,25 @@ abstract class AbstractIntegrationTest { return result } + // Use this method when the task is supposed to fail. Then the returned BuildResult can be + // checked for any expected output. + protected static BuildResult runTasksFailResult(File projectDir, String... tasks) { + List args = new ArrayList(); + for (String task: tasks) { + args.add(task); + } + args.add("-i"); + args.add("-s"); + + BuildResult result = GradleRunner.create() + .withProjectDir(projectDir) + .forwardOutput() + .withArguments(args) + .buildAndFail(); + + return result; + } + protected static boolean runTaskCheckForUpToDate(File projectDir, String task, String argument) { List args = new ArrayList() args.add(task) diff --git a/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy index c6cc7f6e..95614fe1 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/KernelInstallVersionlessFeatureTest.groovy @@ -18,10 +18,13 @@ package io.openliberty.tools.gradle import static junit.framework.Assert.assertEquals import static org.junit.Assert.* +import org.junit.After import org.junit.Before import org.junit.BeforeClass import org.junit.Test +import org.gradle.testkit.runner.BuildResult + import io.openliberty.tools.common.plugins.util.InstallFeatureUtil class KernelInstallVersionlessFeatureTest extends AbstractIntegrationTest{ @@ -41,12 +44,17 @@ class KernelInstallVersionlessFeatureTest extends AbstractIntegrationTest{ copyServer("server_empty.xml") deleteDir(new File(buildDir, "build/wlp/lib/features")) } + + @After + public void after() { + copyServer("server_empty.xml") + } @Test /** * Install with only server.xml features */ - public void testInstallVersionlessFeaturesServer() { + public void testInstallVersionlessFeaturesWithPlatformServer() { copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir) runTasks(buildDir, "libertyCreate") copyServer("server_versionless_feature.xml") @@ -58,8 +66,56 @@ class KernelInstallVersionlessFeatureTest extends AbstractIntegrationTest{ assertNotInstalled("couchdb-1.0") assertNotInstalled("distributedMap-1.0") } - + + @Test + /** + * Install with only server.xml features + */ + public void testInstallVersionlessFeaturesWithVersionedFeatureServer() { + copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir) + runTasks(buildDir, "libertyCreate") + copyServer("server_versionless_feature_with_versioned_feature.xml") + runTasks(buildDir, "installFeature") + assertInstalled("beanValidation-2.0") + assertInstalled("servlet-4.0") + assertInstalled("jpa-2.2") + assertInstalled("ejb-3.2") + assertNotInstalled("couchdb-1.0") + assertNotInstalled("distributedMap-1.0") + } + + @Test + /** + * Install with only server.xml features + */ + public void testInstallVersionlessFeaturesServerNoPlatform() { + copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir) + runTasks(buildDir, "libertyCreate") + copyServer("server_versionless_feature_no_platform.xml") + // expect failure - check for error message + BuildResult result = runTasksFailResult(buildDir, "installFeature") + String output = result.getOutput() + assertTrue(output.contains("CWWKF1516E: The platform could not be determined. The following versionless features cannot be installed: [ejb].")) + } + + //@Test + // Commented out because current failure returns + // "Cannot invoke "com.ibm.ws.kernel.feature.provisioning.ProvisioningFeatureDefinition.getSymbolicName()" because the return value of "java.util.HashMap.get(Object)" is null" + /** + * Install with only server.xml features + */ + public void testInstallVersionlessFeaturesServerNoCommonPlatform() { + copyBuildFiles(new File(resourceDir, "install_features_server.gradle"), buildDir) + runTasks(buildDir, "libertyCreate") + copyServer("server_versionless_feature_2.xml") + // expect failure - check for error message + BuildResult result = runTasksFailResult(buildDir, "installFeature") + String output = result.getOutput() + assertTrue(output.contains("CWWKF1516E: The platform could not be determined. The following versionless features cannot be installed: [servlet].")) + } + private copyServer(String serverFile) { + assertTrue(new File(resourceDir, serverFile).exists()) copyFile(new File(resourceDir, serverFile), new File(buildDir, "build/wlp/usr/servers/defaultServer/server.xml")) } diff --git a/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_2.xml b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_2.xml new file mode 100644 index 00000000..af5bd9f6 --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_2.xml @@ -0,0 +1,6 @@ + + + servlet + mpHealth-4.0 + + diff --git a/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_no_platform.xml b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_no_platform.xml new file mode 100644 index 00000000..54f13711 --- /dev/null +++ b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_no_platform.xml @@ -0,0 +1,5 @@ + + + ejb + + diff --git a/src/test/resources/kernel-install-feature-test/server_versionless_feature.xml b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_with_versioned_feature.xml similarity index 73% rename from src/test/resources/kernel-install-feature-test/server_versionless_feature.xml rename to src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_with_versioned_feature.xml index 2435856c..a8d23aec 100644 --- a/src/test/resources/kernel-install-feature-test/server_versionless_feature.xml +++ b/src/test/resources/kernel-install-versionless-feature-test/server_versionless_feature_with_versioned_feature.xml @@ -1,9 +1,8 @@ beanValidation - servlet + servlet-4.0 jpa ejb - javaee-8.0 From e58c4cf8b0cd7e45cf68d88fcee670059c9baf6d Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 12 Sep 2024 15:22:06 -0500 Subject: [PATCH 5/5] Remove temp yaml changes for common branch --- .github/workflows/gradle.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index afb3db33..fa5e2113 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -39,8 +39,7 @@ jobs: - name: Checkout ci.common uses: actions/checkout@v3 with: - repository: cbridgha/ci.common - ref: VersionlessFeatureSupport + repository: OpenLiberty/ci.common path: ci.common - name: Checkout ci.ant uses: actions/checkout@v3 @@ -125,7 +124,7 @@ jobs: - name: Clone ci.ant, ci.common, ci.gradle repos to C drive run: | cp -r D:/a/ci.gradle/ci.gradle C:/ci.gradle - git clone https://github.com/cbridgha/ci.common.git --branch VersionlessFeatureSupport --single-branch C:/ci.common + git clone https://github.com/OpenLiberty/ci.common.git C:/ci.common git clone https://github.com/OpenLiberty/ci.ant.git C:/ci.ant # Cache mvn/gradle packages - name: Cache Maven packages