Skip to content

Commit

Permalink
Add support for versionless features
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Sep 10, 2024
1 parent cb9336f commit c9303be
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 32 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -217,33 +218,36 @@ public class AbstractFeatureTask extends AbstractServerTask {
return result;
}

protected Set<String> 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<String> featuresInstalledFromAnt;
Set<String> featuresInstalledFromAnt
if (server.features.name != null) {
featuresInstalledFromAnt = new HashSet<String>(server.features.name);
return featuresInstalledFromAnt;
featuresInstalledFromAnt = new HashSet<String>(server.features.name)
return new FeaturesPlatforms(featuresInstalledFromAnt, new HashSet<String>())
} else {
featuresInstalledFromAnt = new HashSet<String>();
return featuresInstalledFromAnt;
featuresInstalledFromAnt = new HashSet<String>()
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<String> serverFeatures = getServerFeaturesResult != null ? getServerFeaturesResult.getFeatures() : new HashSet<String>()
Set<String> serverPlatforms = getServerFeaturesResult != null ? getServerFeaturesResult.getPlatforms() : new HashSet<String>()

Set<String> featuresToInstall = util.combineToSet(pluginListedFeatures, dependencyFeatures, serverFeatures)
return featuresToInstall
return new FeaturesPlatforms(featuresToInstall, serverPlatforms)
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -89,7 +91,11 @@ class CompileJSPTask extends AbstractFeatureTask {
setCompileJavaSourceVersion(compileJsp, task)

//Feature list
Set<String> installedFeatures = getSpecifiedFeatures(null);
Set<String> installedFeatures = new HashSet<String>();
FeaturesPlatforms fp = getSpecifiedFeatures(null);
if (fp != null) {
installedFeatures = fp.getFeatures();
}

//Set JSP Feature Version
setJspVersion(compileJsp, installedFeatures);
Expand Down
22 changes: 16 additions & 6 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -363,6 +364,7 @@ class DevTask extends AbstractFeatureTask {
private class DevTaskUtil extends DevUtil {

Set<String> existingFeatures;
Set<String> existingPlatforms;

Set<String> existingLibertyFeatureDependencies;

Expand All @@ -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<String>();

Expand Down Expand Up @@ -823,7 +830,8 @@ class DevTask extends AbstractFeatureTask {
@Override
public void installFeatures(File configFile, File serverDir, boolean generateFeatures) {
ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles);
Set<String> features = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles);
FeaturesPlatforms fp = servUtil.getServerFeatures(serverDir, libertyDirPropertyFiles);
Set<String> features = fp == null ? null : fp.getFeatures();

if (features == null) {
return;
Expand Down Expand Up @@ -885,8 +893,10 @@ class DevTask extends AbstractFeatureTask {
@Override
public void updateExistingFeatures() {
ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles);
Set<String> features = servUtil.getServerFeatures(getServerDir(project), libertyDirPropertyFiles);
existingFeatures = features;
FeaturesPlatforms fp = servUtil.getServerFeatures(getServerDir(project), libertyDirPropertyFiles);

this.existingFeatures = fp == null ? new HashSet<String>() : fp.getFeatures();
this.existingPlatforms = fp == null ? new HashSet<String>() : fp.getPlatforms();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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<String> userDefinedFeatures = optimize ? existingFeatures : servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap<String, File>(), generatedFiles);
FeaturesPlatforms fp = optimize ? existingFeatures : servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap<String, File>(), generatedFiles);
Set<String> userDefinedFeatures = fp == null ? new HashSet<String>() : fp.getFeatures();
logger.debug("User defined features:" + userDefinedFeatures);
servUtil.setLowerCaseFeatures(true);
if (userDefinedFeatures != null) {
if (!userDefinedFeatures.isEmpty()) {
missingLibertyFeatures.removeAll(userDefinedFeatures);
}
}
Expand Down Expand Up @@ -233,10 +235,9 @@ class GenerateFeaturesTask extends AbstractFeatureTask {
private Set<String> getServerFeatures(ServerFeatureUtil servUtil, Set<String> generatedFiles, boolean excludeGenerated) {
servUtil.setLowerCaseFeatures(false);
// if optimizing, ignore generated files when passing in existing features to binary scanner
Set<String> existingFeatures = servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap<String, File>(), excludeGenerated ? generatedFiles : null); // pass generatedFiles to exclude them
if (existingFeatures == null) {
existingFeatures = new HashSet<String>();
}
FeaturesPlatforms fp = servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap<String, File>(), excludeGenerated ? generatedFiles : null); // pass generatedFiles to exclude them
Set<String> existingFeatures = fp == null ? new HashSet<String>() : fp.getFeatures();

servUtil.setLowerCaseFeatures(true);
return existingFeatures;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -78,8 +79,11 @@ class InstallFeatureTask extends AbstractFeatureTask {
installFeatureFromAnt();
}
else {
Set<String> featuresToInstall = getSpecifiedFeatures(containerName);
util.installFeatures(server.features.acceptLicense, new ArrayList<String>(featuresToInstall))
FeaturesPlatforms fp = getSpecifiedFeatures(containerName);
Set<String> featuresToInstall = fp == null ? new HashSet<String>() : fp.getFeatures();
Set<String> platformsToInstall = fp == null ? new HashSet<String>() : fp.getPlatforms();

util.installFeatures(server.features.acceptLicense, new ArrayList<String>(featuresToInstall), new ArrayList<String>(platformsToInstall))
}
}

Expand Down

0 comments on commit c9303be

Please sign in to comment.