Skip to content

Commit

Permalink
Adding Versionless Support
Browse files Browse the repository at this point in the history
  • Loading branch information
cbridgha committed Sep 5, 2024
1 parent d8c90d8 commit 6f39a71
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
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.getFeatures();
}

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

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void doCompileJsps() throws MojoExecutionException {
if(initialize()) {
Set<String> installedFeatures;
try {
installedFeatures = getSpecifiedFeatures(null);
installedFeatures = getSpecifiedFeatures(null).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,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);
Expand Down Expand Up @@ -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<String> features = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles);
FeaturesPlatforms fp = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles);
Set<String> features = fp.getFeatures();
if (features != null) {
Set<String> featuresCopy = new HashSet<String>(features);

Expand Down Expand Up @@ -1221,8 +1226,11 @@ 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 = fp.getFeatures();
Set<String> 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 @@ -268,7 +269,7 @@ private void generateFeatures() throws MojoExecutionException, PluginExecutionEx
// file that will be written
Set<String> userDefinedFeatures = optimize ? existingFeatures
: servUtil.getServerFeatures(configDirectory, serverXmlFile, new HashMap<String, File>(),
generatedFiles);
generatedFiles).getFeatures();
getLog().debug("User defined features:" + userDefinedFeatures);
servUtil.setLowerCaseFeatures(true);
if (userDefinedFeatures != null) {
Expand Down Expand Up @@ -331,23 +332,22 @@ 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;
return result.getFeatures();
}

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

/**
Expand Down Expand Up @@ -103,16 +104,17 @@ 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 = fp.getFeatures();
Set<String> 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 6f39a71

Please sign in to comment.