-
Notifications
You must be signed in to change notification settings - Fork 73
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
Changes from 1 commit
9bd4224
dfc4722
ff32bfa
0719536
a4904a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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) { | ||
|
@@ -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 -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
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.