diff --git a/src/main/groovy/io/openliberty/tools/gradle/extensions/LibertyExtension.groovy b/src/main/groovy/io/openliberty/tools/gradle/extensions/LibertyExtension.groovy index 28cf19d7..603414d2 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/extensions/LibertyExtension.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/extensions/LibertyExtension.groovy @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2014, 2020. + * (C) Copyright IBM Corporation 2014, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,10 @@ */ package io.openliberty.tools.gradle.extensions -import org.gradle.util.ConfigureUtil -import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.Action +import org.gradle.api.model.ObjectFactory + +import javax.inject.Inject class LibertyExtension { @@ -29,35 +31,43 @@ class LibertyExtension { // For overriding the group, name or version of the libertyRuntime installed from Maven Central repository. // Default is group 'io.openliberty', name 'openliberty-kernel' and version '[19.0.0.9,)' which gets the latest version. - Properties runtime = new Properties() + Properties runtime = new Properties(); - CompileJSPExtension jsp = new CompileJSPExtension() + CompileJSPExtension jsp - InstallExtension install = new InstallExtension() - SpringBootExtension thin = new SpringBootExtension() + InstallExtension install + SpringBootExtension thin + ServerExtension server - ServerExtension server = server = new ServerExtension() + DevExtension dev; - DevExtension dev = new DevExtension(); + @Inject + LibertyExtension(ObjectFactory objectFactory) { + this.jsp = objectFactory.newInstance(CompileJSPExtension.class) + this.install = objectFactory.newInstance(InstallExtension.class) + this.thin = objectFactory.newInstance(SpringBootExtension.class) + this.server = objectFactory.newInstance(ServerExtension.class) + this.dev = objectFactory.newInstance(DevExtension.class) + } - def jsp(Closure closure) { - ConfigureUtil.configure(closure, jsp) + def jsp(Action action) { + action.execute(jsp) } - def thin(Closure closure) { - ConfigureUtil.configure(closure, thin) + def thin(Action action) { + action.execute(thin) } - def install(Closure closure) { - ConfigureUtil.configure(closure, install) + def install(Action action) { + action.execute(install) } - def server(Closure closure){ - ConfigureUtil.configure(closure, server) + def server(Action action) { + action.execute(server) } - def dev(Closure closure) { - ConfigureUtil.configure(closure, dev) + def dev(Action action) { + action.execute(dev) } } diff --git a/src/main/groovy/io/openliberty/tools/gradle/extensions/ServerExtension.groovy b/src/main/groovy/io/openliberty/tools/gradle/extensions/ServerExtension.groovy index 14182c8c..9ced5ed3 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/extensions/ServerExtension.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/extensions/ServerExtension.groovy @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2017, 2023. + * (C) Copyright IBM Corporation 2017, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,10 @@ package io.openliberty.tools.gradle.extensions -import org.gradle.util.ConfigureUtil -import org.gradle.api.Task -import java.util.Properties +import org.gradle.api.Action +import org.gradle.api.model.ObjectFactory + +import javax.inject.Inject class ServerExtension { //Server properties @@ -51,47 +52,59 @@ class ServerExtension { int verifyAppStartTimeout = 0 - FeatureExtension features = new FeatureExtension() - UninstallFeatureExtension uninstallfeatures = new UninstallFeatureExtension() - CleanExtension cleanDir = new CleanExtension() - - DeployExtension deploy = new DeployExtension() - UndeployExtension undeploy = new UndeployExtension() - - PackageExtension packageLiberty = new PackageExtension() - DumpExtension dumpLiberty = new DumpExtension() - DumpExtension javaDumpLiberty = new DumpExtension() + FeatureExtension features + UninstallFeatureExtension uninstallfeatures + CleanExtension cleanDir + + DeployExtension deploy + UndeployExtension undeploy + + PackageExtension packageLiberty + DumpExtension dumpLiberty + DumpExtension javaDumpLiberty + + @Inject + ServerExtension(ObjectFactory objectFactory) { + this.features = objectFactory.newInstance(FeatureExtension.class) + this.uninstallfeatures = objectFactory.newInstance(UninstallFeatureExtension.class) + this.cleanDir = objectFactory.newInstance(CleanExtension.class) + this.deploy = objectFactory.newInstance(DeployExtension.class) + this.undeploy = objectFactory.newInstance(UndeployExtension.class) + this.packageLiberty = objectFactory.newInstance(PackageExtension.class) + this.dumpLiberty = objectFactory.newInstance(DumpExtension.class) + this.javaDumpLiberty = objectFactory.newInstance(DumpExtension.class) + } - def uninstallfeatures(Closure closure) { - ConfigureUtil.configure(closure, uninstallfeatures) + def uninstallfeatures(Action action) { + action.execute(uninstallfeatures) } - def features(Closure closure) { - ConfigureUtil.configure(closure, features) + def features(Action action) { + action.execute(features) } - def cleanDir(Closure closure) { - ConfigureUtil.configure(closure, cleanDir) + def cleanDir(Action action) { + action.execute(cleanDir) } - def deploy(Closure closure) { - ConfigureUtil.configure(closure, deploy) + def deploy(Action action) { + action.execute(deploy) } - def undeploy(Closure closure) { - ConfigureUtil.configure(closure, undeploy) + def undeploy(Action action) { + action.execute(undeploy) } - def packageLiberty(Closure closure) { - ConfigureUtil.configure(closure, packageLiberty) + def packageLiberty(Action action) { + action.execute(packageLiberty) } - def dumpLiberty(Closure closure) { - ConfigureUtil.configure(closure, dumpLiberty) + def dumpLiberty(Action action) { + action.execute(dumpLiberty) } - def javaDumpLiberty(Closure closure) { - ConfigureUtil.configure(closure, javaDumpLiberty) + def javaDumpLiberty(Action action) { + action.execute(javaDumpLiberty) } } diff --git a/src/test/groovy/io/openliberty/tools/gradle/InstallLiberty_DefaultNoMavenRepo.groovy b/src/test/groovy/io/openliberty/tools/gradle/InstallLiberty_DefaultNoMavenRepo.groovy index c73e9c86..47f747c0 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/InstallLiberty_DefaultNoMavenRepo.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/InstallLiberty_DefaultNoMavenRepo.groovy @@ -1,5 +1,5 @@ /* - * (C) Copyright IBM Corporation 2019 + * (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. @@ -15,15 +15,13 @@ */ package io.openliberty.tools.gradle -import static org.junit.Assert.* + import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner import org.junit.BeforeClass import org.junit.Test -import org.gradle.api.GradleException -import org.gradle.api.artifacts.ResolveException class InstallLiberty_DefaultNoMavenRepo extends AbstractIntegrationTest{ static File resourceDir = new File("build/resources/test/liberty-test") @@ -45,6 +43,6 @@ class InstallLiberty_DefaultNoMavenRepo extends AbstractIntegrationTest{ .buildAndFail() String output = result.getOutput() - assert output.contains("org.gradle.api.artifacts.ResolveException") : "Expected installLiberty to fail with ResolveException" + assert output.contains("org.gradle.internal.resolve.ModuleVersionNotFoundException") : "Expected installLiberty to fail with TypedResolveException" } }