Skip to content

Commit

Permalink
Merge pull request #1827 from cbridgha/VersionlessFeatureSupport
Browse files Browse the repository at this point in the history
Adding Versionless Support
  • Loading branch information
cherylking committed Sep 12, 2024
2 parents d8c90d8 + 3cfe026 commit 85242ee
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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
Expand Down Expand Up @@ -80,7 +80,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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.wasdev.wlp.maven.test.servlet.it;
package net.wasdev.wlp.test.servlet.it;

import java.io.BufferedWriter;
import java.io.File;
Expand Down Expand Up @@ -125,7 +125,7 @@ public void checkMessagesLogForIncludes() throws Exception {
} catch (Exception e) {
e.printStackTrace();
} finally {
s.close();
if (s != null) s.close();
}

//Check app name/appsDir resolved correctly during create, deploy, and start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> getSpecifiedFeatures(String containerName) throws PluginExecutionException {
protected FeaturesPlatforms getSpecifiedFeatures(String containerName) throws PluginExecutionException {
Set<String> pluginListedFeatures = getPluginListedFeatures(false);

if (util == null) {
Expand All @@ -221,19 +222,26 @@ protected Set<String> getSpecifiedFeatures(String containerName) throws PluginEx

if (util == null && noFeaturesSection) {
//No features were installed because acceptLicense parameter was not configured
return new HashSet<String>();
return new FeaturesPlatforms();
}
else if (util == null && !noFeaturesSection) {
Set<String> featuresToInstall = new HashSet<String>();
for (Feature feature : features.getFeatures()) {
featuresToInstall.add(feature.toString());
}
return featuresToInstall;
return new FeaturesPlatforms(featuresToInstall, new HashSet<String>());
}
else {
Set<String> dependencyFeatures = getDependencyFeatures();
Set<String> serverFeatures = serverDirectory.exists() ? util.getServerFeatures(serverDirectory, getLibertyDirectoryPropertyFiles()) : null;
return util.combineToSet(pluginListedFeatures, dependencyFeatures, serverFeatures);
Set<String> serverFeatures = new HashSet<String>();
Set<String> serverPlatforms = new HashSet<String>();
FeaturesPlatforms getServerResult = serverDirectory.exists() ? util.getServerFeatures(serverDirectory, getLibertyDirectoryPropertyFiles()) : null;
if (getServerResult != null) {
serverFeatures = getServerResult.getFeatures();
serverPlatforms = getServerResult.getPlatforms();
}

return new FeaturesPlatforms(util.combineToSet(pluginListedFeatures, dependencyFeatures, serverFeatures),serverPlatforms);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
Expand All @@ -33,6 +34,7 @@

import io.openliberty.tools.ant.jsp.CompileJSPs;
import io.openliberty.tools.common.plugins.util.PluginExecutionException;
import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms;
import io.openliberty.tools.maven.InstallFeatureSupport;

/**
Expand Down Expand Up @@ -166,9 +168,11 @@ private void doCompileJsps() throws MojoExecutionException {
compile.setClasspath(classpathStr);

if(initialize()) {
Set<String> installedFeatures;
Set<String> installedFeatures = new HashSet<String>();
try {
installedFeatures = getSpecifiedFeatures(null);
FeaturesPlatforms fp = getSpecifiedFeatures(null);
if (fp!=null)
installedFeatures = fp.getFeatures();
} catch (PluginExecutionException e) {
throw new MojoExecutionException("Error getting the list of specified features.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -340,6 +341,7 @@ protected List<File> getResourceDirectories(MavenProject project, File outputDir

private class DevMojoUtil extends DevUtil {
Set<String> existingFeatures;
Set<String> existingPlatforms;
Map<String, File> libertyDirPropertyFiles = new HashMap<String, File>();
List<MavenProject> upstreamMavenProjects;

Expand All @@ -359,8 +361,12 @@ 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);
if (fp != null) {
this.existingFeatures = fp.getFeatures();
this.existingPlatforms = fp.getPlatforms();
}
this.upstreamMavenProjects = upstreamMavenProjects;

setContainerEngine(this);
Expand Down Expand Up @@ -1174,7 +1180,11 @@ private void libertyDependencyWarning(boolean generateFeatures, Exception e) {
public void installFeatures(File configFile, File serverDir, boolean generateFeatures) {
try {
ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles);
Set<String> features = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles);
FeaturesPlatforms fp = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles);
Set<String> features = null;
if (fp != null) {
features = fp.getFeatures();
}
if (features != null) {
Set<String> featuresCopy = new HashSet<String>(features);

Expand Down Expand Up @@ -1221,8 +1231,15 @@ public Set<String> getExistingFeatures() {
@Override
public void updateExistingFeatures() {
ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles);
Set<String> features = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles);
FeaturesPlatforms fp = servUtil.getServerFeatures(serverDirectory, libertyDirPropertyFiles);
Set<String> features = new HashSet<String>();
Set<String> platforms = new HashSet<String>();
if (fp != null) {
features = fp.getFeatures();
platforms = fp.getPlatforms();
}
existingFeatures = features;
existingPlatforms = platforms;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -266,9 +267,9 @@ private void generateFeatures() throws MojoExecutionException, PluginExecutionEx
servUtil.setLowerCaseFeatures(false);
// get set of user defined features so they can be omitted from the generated
// file that will be written
Set<String> userDefinedFeatures = optimize ? existingFeatures
: servUtil.getServerFeatures(configDirectory, serverXmlFile, new HashMap<String, File>(),
generatedFiles);
FeaturesPlatforms fp = servUtil.getServerFeatures(configDirectory, serverXmlFile, new HashMap<String, File>(),
generatedFiles);
Set<String> userDefinedFeatures = optimize ? existingFeatures : (fp !=null) ? fp.getFeatures(): new HashSet<String>();
getLog().debug("User defined features:" + userDefinedFeatures);
servUtil.setLowerCaseFeatures(true);
if (userDefinedFeatures != null) {
Expand Down Expand Up @@ -331,23 +332,26 @@ private Set<String> getServerFeatures(ServerFeatureUtil servUtil, Set<String> ge
servUtil.setLowerCaseFeatures(false);
// if optimizing, ignore generated files when passing in existing features to
// binary scanner
Set<String> existingFeatures = servUtil.getServerFeatures(configDirectory, serverXmlFile,
FeaturesPlatforms fp = servUtil.getServerFeatures(configDirectory, serverXmlFile,
new HashMap<String, File>(), excludeGenerated ? generatedFiles : null); // pass generatedFiles to exclude them
if (existingFeatures == null) {
existingFeatures = new HashSet<String>();
}
servUtil.setLowerCaseFeatures(true);
return existingFeatures;
if (fp == null) {
return new HashSet<String>();
}
return fp.getFeatures();
}

// returns the features specified in the generated-features.xml file
private Set<String> getGeneratedFeatures(ServerFeatureUtil servUtil, File generatedFeaturesFile) {
servUtil.setLowerCaseFeatures(false);
Set<String> genFeatSet = new HashSet<String>();
servUtil.getServerXmlFeatures(genFeatSet, configDirectory,
FeaturesPlatforms result = servUtil.getServerXmlFeatures(new FeaturesPlatforms(), configDirectory,
generatedFeaturesFile, null, null);
servUtil.setLowerCaseFeatures(true);
return genFeatSet;
Set<String> features = new HashSet<String>();
if (result != null) {
features = result.getFeatures();
}
return features;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -33,6 +34,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;

/**
Expand Down Expand Up @@ -103,16 +105,21 @@ private void installFeatures() throws PluginExecutionException {
List<String> additionalJsons = getAdditionalJsonList();
Collection<Map<String,String>> keyMap = getKeyMap();
util = getInstallFeatureUtil(pluginListedEsas, propertiesList, openLibertyVersion, containerName, additionalJsons, keyMap);
Set<String> featuresToInstall = getSpecifiedFeatures(containerName);

FeaturesPlatforms fp = getSpecifiedFeatures(containerName);
Set<String> featuresToInstall = new HashSet<String>();
Set<String> platformsToInstall = new HashSet<String>();
if (fp != null) {
featuresToInstall = fp.getFeatures();
platformsToInstall = fp.getPlatforms();
}
if(!pluginListedEsas.isEmpty() && isClosedLiberty) {
installFromAnt = true;
}

if(installFromAnt) {
installFeaturesFromAnt(features.getFeatures());
} else if(util != null) {
util.installFeatures(features.isAcceptLicense(), new ArrayList<String>(featuresToInstall));
util.installFeatures(features.isAcceptLicense(), new ArrayList<String>(featuresToInstall), new ArrayList<String>(platformsToInstall));
}

}
Expand Down

0 comments on commit 85242ee

Please sign in to comment.