Skip to content

[Gradle] Remove deprecated gradle api usage #2321

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

Merged
merged 5 commits into from
Jan 13, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class AntFixture extends AntTask implements Fixture {
*/
@Internal
protected File getBaseDir() {
return new File(project.buildDir, "fixtures/${name}")
return new File(getProjectLayout().buildDirectory.getAsFile().get(), "fixtures/${name}")
}

/** Returns the working directory for the process. Defaults to "cwd" inside baseDir. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.apache.tools.ant.DefaultLogger
import org.apache.tools.ant.Project
import org.gradle.api.DefaultTask
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.ProjectLayout
import org.gradle.api.tasks.TaskAction

import javax.inject.Inject
Expand All @@ -48,6 +49,11 @@ abstract class AntTask extends DefaultTask {
throw new UnsupportedOperationException();
}

@Inject
protected ProjectLayout getProjectLayout() {
throw new UnsupportedOperationException();
}

@TaskAction
final void executeTask() {
AntBuilder ant = new AntBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ import org.gradle.api.GradleException
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.process.ExecOperations
import org.gradle.process.ExecSpec

import javax.inject.Inject

import static org.elasticsearch.hadoop.gradle.util.ObjectUtil.unapplyString

abstract class HadoopMRJob extends AbstractClusterTask {
Expand All @@ -46,6 +50,14 @@ abstract class HadoopMRJob extends AbstractClusterTask {
@Input
Map<String, String> systemProperties = [:]

@Internal
ExecOperations execOperations

@Inject
HadoopMRJob(ExecOperations execOperations) {
this.execOperations = execOperations
}

void jobSetting(String key, Object value) {
jobSettings.put(key, value)
}
Expand Down Expand Up @@ -152,9 +164,9 @@ abstract class HadoopMRJob extends AbstractClusterTask {
Map<String, String> finalEnv = collectEnvVars()

// Do command
project.logger.info("Executing Command: " + commandLine)
project.logger.info("Command Env: " + finalEnv)
project.exec { ExecSpec spec ->
logger.info("Executing Command: " + commandLine)
logger.info("Command Env: " + finalEnv)
execOperations.exec { ExecSpec spec ->
spec.commandLine(commandLine)
spec.environment(finalEnv)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ import org.gradle.api.GradleException
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.process.ExecOperations
import org.gradle.process.ExecSpec

import javax.inject.Inject

import static org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.SettingsContainer.FileSettings

abstract class HiveBeeline extends AbstractClusterTask {
Expand All @@ -40,6 +44,14 @@ abstract class HiveBeeline extends AbstractClusterTask {
@Input
String hivePrincipal

@Internal
ExecOperations execOperations

@Inject
HiveBeeline(ExecOperations execOperations) {
this.execOperations = execOperations
}

void libJars(File... files) {
libJars.addAll(files)
}
Expand Down Expand Up @@ -86,8 +98,8 @@ abstract class HiveBeeline extends AbstractClusterTask {

Map<String, String> environment = collectEnvVars()

project.logger.info("Using Environment: $environment")
project.exec { ExecSpec spec ->
logger.info("Using Environment: $environment")
execOperations.exec { ExecSpec spec ->
spec.setCommandLine(commandLine)
spec.environment(environment)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.process.ExecOperations
import org.gradle.process.ExecSpec

import javax.inject.Inject

import static org.elasticsearch.hadoop.gradle.util.ObjectUtil.unapplyString

abstract class SparkApp extends AbstractClusterTask {
Expand Down Expand Up @@ -62,6 +65,14 @@ abstract class SparkApp extends AbstractClusterTask {
@Input
List<String> args = []

@Internal
ExecOperations execOperations

@Inject
SparkApp(ExecOperations execOperations) {
this.execOperations = execOperations
}

void deployMode(DeployMode mode) {
deployMode = mode
}
Expand Down Expand Up @@ -159,8 +170,8 @@ abstract class SparkApp extends AbstractClusterTask {
Map<String, String> finalEnv = collectEnvVars()

// Do command
project.logger.info("Command Env: " + finalEnv)
project.exec { ExecSpec spec ->
logger.info("Command Env: " + finalEnv)
execOperations.exec { ExecSpec spec ->
spec.commandLine(commandLine)
spec.environment(finalEnv)
}
Expand Down
18 changes: 15 additions & 3 deletions qa/kerberos/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import org.elasticsearch.hadoop.gradle.fixture.hadoop.tasks.HadoopMRJob
import org.elasticsearch.hadoop.gradle.fixture.hadoop.tasks.HiveBeeline
import org.elasticsearch.hadoop.gradle.fixture.hadoop.tasks.SparkApp

import javax.inject.Inject

apply plugin: 'es.hadoop.build'
apply plugin: 'scala'
apply plugin: HadoopFixturePlugin
Expand Down Expand Up @@ -88,6 +90,11 @@ dependencies {
// Testing jars
// =============================================================================

interface InjectedExecOps {
@Inject //@javax.inject.Inject
ExecOperations getExecOps()
}

// Disable the integration tests for Kerberos until we can find a solution to the failures due to + sign
// in the file path on CI.
boolean disableTests = false
Expand Down Expand Up @@ -142,7 +149,9 @@ if (disableTests) {
AntFixture kdcFixture = project.tasks.create('kdcFixture', AntFixture) {
dependsOn project.configurations.kdcFixture
executable = new File(project.runtimeJavaHome, 'bin/java')
env 'CLASSPATH', "${ -> project.configurations.kdcFixture.asPath }"

def fixturefileCollection = project.configurations.kdcFixture
env 'CLASSPATH', "${ -> fixturefileCollection.asPath }"
waitCondition = { fixture, ant ->
// the kdc wrapper writes the ports file when
// it's ready, so we can just wait for the file to exist
Expand Down Expand Up @@ -235,10 +244,13 @@ if (disableTests) {
File itestResourceDir = project.sourceSets.itest.resources.getSrcDirs().head()

Task setupUsers = project.tasks.create("setupUsers", DefaultTestClustersTask) {
def injected = project.objects.newInstance(InjectedExecOps)

useCluster(testClusters.integTest)
def executablePath = project.runtimeJavaHome.toString() + "/bin/java"
doLast {
project.javaexec {
executable = project.runtimeJavaHome.toString() + "/bin/java"
injected.getExecOps().javaexec {
executable = executablePath
mainClass = 'org.elasticsearch.hadoop.qa.kerberos.setup.SetupKerberosUsers'
classpath = sourceSets.main.runtimeClasspath
systemProperty('es.nodes', esAddress)
Expand Down