Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for versionless features #905

Merged
merged 7 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,7 +100,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
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,32 @@ 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;
if (server.features.name != null) {
featuresInstalledFromAnt = new HashSet<String>(server.features.name);
return featuresInstalledFromAnt;
} else {
featuresInstalledFromAnt = new HashSet<String>();
return featuresInstalledFromAnt;
getServerFeaturesResult.getFeatures().addAll(server.features.name)
}
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 @@ -20,6 +20,9 @@ import org.apache.tools.ant.Project
import org.gradle.api.Task
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.bundling.War
import org.gradle.api.logging.LogLevel

import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms

class CompileJSPTask extends AbstractFeatureTask {
protected Project ant = new Project();
Expand Down Expand Up @@ -82,7 +85,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,16 @@ 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);
Set<String> userDefinedFeatures = optimize ? existingFeatures : new HashSet<String>();
if (!optimize) {
FeaturesPlatforms fp = servUtil.getServerFeatures(server.configDirectory, server.serverXmlFile, new HashMap<String, File>(), generatedFiles);
if (fp != null) {
userDefinedFeatures = 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,20 +240,19 @@ 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;
}

// 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, server.configDirectory,
FeaturesPlatforms fp = servUtil.getServerXmlFeatures(new FeaturesPlatforms(), server.configDirectory,
generatedFeaturesFile, null, null);
Set<String> genFeatSet = fp == null ? new HashSet<String>() : fp.getFeatures();
servUtil.setLowerCaseFeatures(true);
return genFeatSet;
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> args = new ArrayList<String>();
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<String> args = new ArrayList<String>()
args.add(task)
Expand Down
Loading
Loading