From 6f39a712bb32064e45f2e1ab7c091883a8821245 Mon Sep 17 00:00:00 2001 From: Chuck Bridgham Date: Thu, 5 Sep 2024 13:52:51 -0400 Subject: [PATCH] Adding Versionless Support --- .../tools/maven/InstallFeatureSupport.java | 18 +++++++++++++----- .../tools/maven/jsp/CompileJspMojo.java | 2 +- .../tools/maven/server/DevMojo.java | 16 ++++++++++++---- .../maven/server/GenerateFeaturesMojo.java | 18 +++++++++--------- .../tools/maven/server/InstallFeatureMojo.java | 8 +++++--- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/InstallFeatureSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/InstallFeatureSupport.java index 0e78d800f..98aec429a 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/InstallFeatureSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/InstallFeatureSupport.java @@ -30,6 +30,7 @@ import io.openliberty.tools.ant.FeatureManagerTask.Feature; import io.openliberty.tools.common.plugins.util.InstallFeatureUtil; import io.openliberty.tools.common.plugins.util.InstallFeatureUtil.ProductProperties; +import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms; import io.openliberty.tools.common.plugins.util.PluginExecutionException; import io.openliberty.tools.common.plugins.util.PluginScenarioException; import io.openliberty.tools.maven.server.types.Features; @@ -211,7 +212,7 @@ protected boolean initialize() throws MojoExecutionException { * @param containerName The container name if the features should be installed in a container. Otherwise null. * @return Set of Strings containing the specified Liberty features */ - protected Set getSpecifiedFeatures(String containerName) throws PluginExecutionException { + protected FeaturesPlatforms getSpecifiedFeatures(String containerName) throws PluginExecutionException { Set pluginListedFeatures = getPluginListedFeatures(false); if (util == null) { @@ -221,19 +222,26 @@ protected Set getSpecifiedFeatures(String containerName) throws PluginEx if (util == null && noFeaturesSection) { //No features were installed because acceptLicense parameter was not configured - return new HashSet(); + return new FeaturesPlatforms(); } else if (util == null && !noFeaturesSection) { Set featuresToInstall = new HashSet(); for (Feature feature : features.getFeatures()) { featuresToInstall.add(feature.toString()); } - return featuresToInstall; + return new FeaturesPlatforms(featuresToInstall, new HashSet()); } else { Set dependencyFeatures = getDependencyFeatures(); - Set serverFeatures = serverDirectory.exists() ? util.getServerFeatures(serverDirectory, getLibertyDirectoryPropertyFiles()) : null; - return util.combineToSet(pluginListedFeatures, dependencyFeatures, serverFeatures); + Set serverFeatures = new HashSet(); + Set serverPlatforms = new HashSet(); + FeaturesPlatforms getServerResult = serverDirectory.exists() ? util.getServerFeatures(serverDirectory, getLibertyDirectoryPropertyFiles()) : null; + if (getServerResult != null) { + serverFeatures = getServerResult.getFeatures(); + serverPlatforms = getServerResult.getFeatures(); + } + + return new FeaturesPlatforms(util.combineToSet(pluginListedFeatures, dependencyFeatures, serverFeatures),serverPlatforms); } } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java index 1db2b1237..275c1c5b9 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java @@ -168,7 +168,7 @@ private void doCompileJsps() throws MojoExecutionException { if(initialize()) { Set installedFeatures; try { - installedFeatures = getSpecifiedFeatures(null); + installedFeatures = getSpecifiedFeatures(null).getFeatures(); } catch (PluginExecutionException e) { throw new MojoExecutionException("Error getting the list of specified features.", e); } 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 9a519707d..760da0946 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 @@ -72,6 +72,7 @@ import io.openliberty.tools.common.plugins.util.PluginScenarioException; import io.openliberty.tools.common.plugins.util.ProjectModule; 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.maven.BasicSupport; import io.openliberty.tools.maven.applications.DeployMojoSupport; @@ -340,6 +341,7 @@ protected List getResourceDirectories(MavenProject project, File outputDir private class DevMojoUtil extends DevUtil { Set existingFeatures; + Set existingPlatforms; Map libertyDirPropertyFiles = new HashMap(); List upstreamMavenProjects; @@ -359,8 +361,10 @@ public DevMojoUtil(File installDir, File userDir, File serverDirectory, File sou this.libertyDirPropertyFiles = BasicSupport.getLibertyDirectoryPropertyFiles(installDir, userDir, serverDirectory); - ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles); - this.existingFeatures = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles); + ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles); + FeaturesPlatforms fp = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles); + this.existingFeatures = fp.getFeatures(); + this.existingPlatforms = fp.getPlatforms(); this.upstreamMavenProjects = upstreamMavenProjects; setContainerEngine(this); @@ -1174,7 +1178,8 @@ private void libertyDependencyWarning(boolean generateFeatures, Exception e) { public void installFeatures(File configFile, File serverDir, boolean generateFeatures) { try { ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles); - Set features = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles); + FeaturesPlatforms fp = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles); + Set features = fp.getFeatures(); if (features != null) { Set featuresCopy = new HashSet(features); @@ -1221,8 +1226,11 @@ public Set getExistingFeatures() { @Override public void updateExistingFeatures() { ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles); - Set features = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles); + FeaturesPlatforms fp = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles); + Set features = fp.getFeatures(); + Set platforms = fp.getPlatforms(); existingFeatures = features; + existingPlatforms = platforms; } @Override diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/GenerateFeaturesMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/GenerateFeaturesMojo.java index 82c51bc65..c2807a068 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/GenerateFeaturesMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/GenerateFeaturesMojo.java @@ -43,6 +43,7 @@ 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.maven.ServerFeatureSupport; /** @@ -268,7 +269,7 @@ private void generateFeatures() throws MojoExecutionException, PluginExecutionEx // file that will be written Set userDefinedFeatures = optimize ? existingFeatures : servUtil.getServerFeatures(configDirectory, serverXmlFile, new HashMap(), - generatedFiles); + generatedFiles).getFeatures(); getLog().debug("User defined features:" + userDefinedFeatures); servUtil.setLowerCaseFeatures(true); if (userDefinedFeatures != null) { @@ -331,23 +332,22 @@ private Set getServerFeatures(ServerFeatureUtil servUtil, Set ge servUtil.setLowerCaseFeatures(false); // if optimizing, ignore generated files when passing in existing features to // binary scanner - Set existingFeatures = servUtil.getServerFeatures(configDirectory, serverXmlFile, + FeaturesPlatforms fp = servUtil.getServerFeatures(configDirectory, serverXmlFile, new HashMap(), excludeGenerated ? generatedFiles : null); // pass generatedFiles to exclude them - if (existingFeatures == null) { - existingFeatures = new HashSet(); - } servUtil.setLowerCaseFeatures(true); - return existingFeatures; + if (fp == null) { + return new HashSet(); + } + return fp.getFeatures(); } // 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, configDirectory, + FeaturesPlatforms result = servUtil.getServerXmlFeatures(new FeaturesPlatforms(), configDirectory, generatedFeaturesFile, null, null); servUtil.setLowerCaseFeatures(true); - return genFeatSet; + return result.getFeatures(); } /** diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/InstallFeatureMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/InstallFeatureMojo.java index d651d5c81..b045ac140 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/InstallFeatureMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/InstallFeatureMojo.java @@ -33,6 +33,7 @@ import io.openliberty.tools.common.plugins.util.DevUtil; import io.openliberty.tools.common.plugins.util.InstallFeatureUtil; import io.openliberty.tools.common.plugins.util.PluginExecutionException; +import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms; import io.openliberty.tools.common.plugins.util.InstallFeatureUtil.ProductProperties; /** @@ -103,8 +104,9 @@ private void installFeatures() throws PluginExecutionException { List additionalJsons = getAdditionalJsonList(); Collection> keyMap = getKeyMap(); util = getInstallFeatureUtil(pluginListedEsas, propertiesList, openLibertyVersion, containerName, additionalJsons, keyMap); - Set featuresToInstall = getSpecifiedFeatures(containerName); - + FeaturesPlatforms fp = getSpecifiedFeatures(containerName); + Set featuresToInstall = fp.getFeatures(); + Set platformsToInstall = fp.getPlatforms(); if(!pluginListedEsas.isEmpty() && isClosedLiberty) { installFromAnt = true; } @@ -112,7 +114,7 @@ private void installFeatures() throws PluginExecutionException { if(installFromAnt) { installFeaturesFromAnt(features.getFeatures()); } else if(util != null) { - util.installFeatures(features.isAcceptLicense(), new ArrayList(featuresToInstall)); + util.installFeatures(features.isAcceptLicense(), new ArrayList(featuresToInstall), new ArrayList(platformsToInstall)); } }