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

Build plugin with platform specific JDK #69

Merged
merged 5 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -7,18 +7,26 @@ buildscript {
apply plugin: 'java'
apply plugin: 'com.linkedin.transport.plugin'

println 'Running build for Hive, Presto & Spark'
transport.engines = ['hive', 'presto', 'spark']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This put the onus on the client to decide which engines to run with Java 8 and which to run with Java 11. However the client is currently abstracted away from the engine version numbers, so I don't think the decision about toolchains should be upto the client. I think Transport should be handling this within the TransportPlugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! but I am not sure if it is possible to control the jdk version from inside the plugin. I will explore the option you suggested below. If that works, it would be the best way forward.

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
}

// If the license plugin is applied, disable license checks for the autogenerated source sets
tasks.whenTaskAdded { task ->
if (task.name.startsWith("licensePresto")
|| task.name.startsWith("licenseHive")
|| task.name.startsWith("licenseSpark")) {
task.enabled = false
}
}

dependencies {
// TODO: Reference all external dependencies from a single gradle file
compile('com.google.guava:guava:24.1-jre')
compile('org.apache.commons:commons-io:1.3.2')
}

// If the license plugin is applied, disable license checks for the autogenerated source sets
plugins.withId('com.github.hierynomus.license') {
licenseHive.enabled = false
licensePresto.enabled = false
licenseSpark.enabled = false
}

// TODO: Add a debugPlatform flag to allow debugging specific test methods in IntelliJ
// for a particular platform other than default
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static Properties loadDefaultVersions() {
getDependencyConfiguration(RUNTIME_ONLY, "com.linkedin.transport:transportable-udfs-test-generic", "transport")
);

static final List<Platform> DEFAULT_PLATFORMS = ImmutableList.of(
static final Platform PRESTO_PLATFORM =
new Platform(
"presto",
Language.JAVA,
Expand All @@ -73,7 +73,9 @@ private static Properties loadDefaultVersions() {
// converters drop dependencies with classifiers, so we apply this dependency explicitly
getDependencyConfiguration(RUNTIME_ONLY, "io.prestosql:presto-main", "presto", "tests")
),
ImmutableList.of(new ThinJarPackaging(), new DistributionPackaging())),
ImmutableList.of(new ThinJarPackaging(), new DistributionPackaging()));

static final Platform HIVE_PLATFORM =
new Platform(
"hive",
Language.JAVA,
Expand All @@ -86,7 +88,9 @@ private static Properties loadDefaultVersions() {
getDependencyConfiguration(RUNTIME_ONLY, "com.linkedin.transport:transportable-udfs-test-hive",
"transport")
),
ImmutableList.of(new ShadedJarPackaging(ImmutableList.of("org.apache.hadoop", "org.apache.hive"), null))),
ImmutableList.of(new ShadedJarPackaging(ImmutableList.of("org.apache.hadoop", "org.apache.hive"), null)));

static final Platform SPARK_PLATFORM =
new Platform(
"spark",
Language.SCALA,
Expand All @@ -102,9 +106,7 @@ private static Properties loadDefaultVersions() {
),
ImmutableList.of(new ShadedJarPackaging(
ImmutableList.of("org.apache.hadoop", "org.apache.spark"),
ImmutableList.of("com.linkedin.transport.spark.**")))
)
);
ImmutableList.of("com.linkedin.transport.spark.**"))));

private static DependencyConfiguration getDependencyConfiguration(ConfigurationType configurationType,
String module, String platform) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
Expand All @@ -23,6 +26,7 @@
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.scala.ScalaPlugin;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.testing.Test;
import org.gradle.language.base.plugins.LifecycleBasePlugin;
Expand All @@ -47,26 +51,31 @@
*/
public class TransportPlugin implements Plugin<Project> {

private static final String HIVE_ENGINE = "hive";
private static final String SPARK_ENGINE = "spark";
private static final String PRESTO_ENGINE = "presto";

public void apply(Project project) {

TransportPluginConfig extension = project.getExtensions().create("transport", TransportPluginConfig.class, project);
AtomicReference<SourceSet> mainSourceSet = new AtomicReference<>();
AtomicReference<SourceSet> testSourceSet = new AtomicReference<>();

project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
project.getPlugins().apply(ScalaPlugin.class);
project.getPlugins().apply(DistributionPlugin.class);
project.getConfigurations().create(ShadowBasePlugin.getCONFIGURATION_NAME());

JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(extension.mainSourceSetName);
SourceSet testSourceSet = javaConvention.getSourceSets().getByName(extension.testSourceSetName);
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
mainSourceSet.set(sourceSets.getByName(extension.mainSourceSetName));
testSourceSet.set(sourceSets.getByName(extension.testSourceSetName));

configureBaseSourceSets(project, mainSourceSet, testSourceSet);
Defaults.DEFAULT_PLATFORMS.forEach(
platform -> configurePlatform(project, platform, mainSourceSet, testSourceSet, extension.outputDirFile));
configureBaseSourceSets(project, mainSourceSet.get(), testSourceSet.get());
});

// Disable Jacoco for platform test tasks as it is known to cause issues with Presto and Hive tests
project.getPlugins().withType(JacocoPlugin.class, (jacocoPlugin) -> {
Defaults.DEFAULT_PLATFORMS.forEach(platform -> {
Arrays.asList(Defaults.PRESTO_PLATFORM, Defaults.HIVE_PLATFORM).forEach(platform -> {
project.getTasksByName(testTaskName(platform), true).forEach(task -> {
JacocoTaskExtension jacocoExtension = task.getExtensions().findByType(JacocoTaskExtension.class);
if (jacocoExtension != null) {
Expand All @@ -75,6 +84,32 @@ public void apply(Project project) {
});
});
});

// Process this after the client configures the 'engine' plugin parameter
project.afterEvaluate(p -> {
if (extension.engines == null || extension.engines.isEmpty()) {
throw new InvalidUserDataException("Please specify engines");
}

// Isolate engine/platform dependencies
extension.engines.forEach(engine -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that the user will have to run two build for every project, one build for Trino and a second build for Spark, Hive. I would prefer something which does not involve such special handling in user code.

Gradle allows setting toolchains on a task level. I think we should modify TransportPlugin to set Java 11 toolchain for Trino sourceset's compileJava and test tasks. With this, we can handle everything within the same Gradle build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! thanks for the pointer. I will take a further look if this is feasible.

if (engine.equalsIgnoreCase(HIVE_ENGINE)) {
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
configurePlatform(project, Defaults.HIVE_PLATFORM, mainSourceSet.get(), testSourceSet.get(), extension.outputDirFile);
});

} else if (engine.equalsIgnoreCase(SPARK_ENGINE)) {
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
configurePlatform(project, Defaults.SPARK_PLATFORM, mainSourceSet.get(), testSourceSet.get(), extension.outputDirFile);
});

} else if (engine.equalsIgnoreCase(PRESTO_ENGINE)) {
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
configurePlatform(project, Defaults.PRESTO_PLATFORM, mainSourceSet.get(), testSourceSet.get(), extension.outputDirFile);
});
}
});
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.linkedin.transport.plugin;

import java.io.File;
import java.util.List;
import org.gradle.api.Project;


Expand Down Expand Up @@ -33,6 +34,11 @@ public class TransportPluginConfig {
* The output code-gen directory, relative the to the project directory.
*/
public File outputDirFile;
/**
* The execution engines for which the udf artifacts need to be built.
* (The client configures this while applying the transport plugin)
*/
public List<String> engines;

/**
* Create a config object from the gradle {@link Project}.
Expand Down