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

Publish Presto thin jar which allows consumers to control dependency graph #49

Merged
merged 2 commits into from
Aug 10, 2020
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 @@ -11,6 +11,7 @@
import com.linkedin.transport.codegen.SparkWrapperGenerator;
import com.linkedin.transport.plugin.packaging.DistributionPackaging;
import com.linkedin.transport.plugin.packaging.ShadedJarPackaging;
import com.linkedin.transport.plugin.packaging.ThinJarPackaging;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
Expand Down Expand Up @@ -72,7 +73,7 @@ private static Properties loadDefaultVersions() {
// converters drop dependencies with classifiers, so we apply this dependency explicitly
getDependencyConfiguration(RUNTIME_ONLY, "io.prestosql:presto-main", "presto", "tests")
),
new DistributionPackaging()),
ImmutableList.of(new ThinJarPackaging(), new DistributionPackaging())),
new Platform(
"hive",
Language.JAVA,
Expand All @@ -85,7 +86,7 @@ private static Properties loadDefaultVersions() {
getDependencyConfiguration(RUNTIME_ONLY, "com.linkedin.transport:transportable-udfs-test-hive",
"transport")
),
new ShadedJarPackaging(ImmutableList.of("org.apache.hadoop", "org.apache.hive"), null)),
ImmutableList.of(new ShadedJarPackaging(ImmutableList.of("org.apache.hadoop", "org.apache.hive"), null))),
new Platform(
"spark",
Language.SCALA,
Expand All @@ -99,9 +100,9 @@ private static Properties loadDefaultVersions() {
getDependencyConfiguration(RUNTIME_ONLY, "com.linkedin.transport:transportable-udfs-test-spark",
"transport")
),
new ShadedJarPackaging(
ImmutableList.of(new ShadedJarPackaging(
ImmutableList.of("org.apache.hadoop", "org.apache.spark"),
ImmutableList.of("com.linkedin.transport.spark.**"))
ImmutableList.of("com.linkedin.transport.spark.**")))
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class Platform {
private final Class<? extends WrapperGenerator> _wrapperGeneratorClass;
private final List<DependencyConfiguration> _defaultWrapperDependencyConfigurations;
private final List<DependencyConfiguration> _defaultTestDependencyConfigurations;
private final Packaging _packaging;
private final List<Packaging> _packaging;

public Platform(String name, Language language, Class<? extends WrapperGenerator> wrapperGeneratorClass,
List<DependencyConfiguration> defaultWrapperDependencyConfigurations,
List<DependencyConfiguration> defaultTestDependencyConfigurations, Packaging packaging) {
List<DependencyConfiguration> defaultTestDependencyConfigurations, List<Packaging> packaging) {
_name = name;
_language = language;
_wrapperGeneratorClass = wrapperGeneratorClass;
Expand Down Expand Up @@ -53,7 +53,7 @@ public List<DependencyConfiguration> getDefaultTestDependencyConfigurations() {
return _defaultTestDependencyConfigurations;
}

public Packaging getPackaging() {
public List<Packaging> getPackaging() {
return _packaging;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
Expand Down Expand Up @@ -203,7 +204,9 @@ private TaskProvider<GenerateWrappersTask> configureGenerateWrappersTask(Project
*/
private List<TaskProvider<? extends Task>> configurePackagingTasks(Project project, Platform platform,
SourceSet sourceSet, SourceSet mainSourceSet) {
return platform.getPackaging().configurePackagingTasks(project, platform, sourceSet, mainSourceSet);
return platform.getPackaging().stream()
.flatMap(p -> p.configurePackagingTasks(project, platform, sourceSet, mainSourceSet).stream())
.collect(Collectors.toList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ public List<TaskProvider<? extends Task>> configurePackagingTasks(Project projec
*/
private TaskProvider<Jar> createThinJarTask(Project project, SourceSet sourceSet, String platformName) {
/*
task <platformName>ThinJar(type: Jar, dependsOn: prestoClasses) {
classifier 'platformName'
task <platformName>DistThinJar(type: Jar, dependsOn: prestoClasses) {
classifier '<platformName>-dist-thin'
from sourceSets.<platform>.output
from sourceSets.<platform>.resources
}
*/

return project.getTasks().register(sourceSet.getTaskName(null, "thinJar"), Jar.class, task -> {
return project.getTasks().register(sourceSet.getTaskName(null, "distThinJar"), Jar.class, task -> {
task.dependsOn(project.getTasks().named(sourceSet.getClassesTaskName()));
task.setDescription("Assembles a thin jar archive containing the " + platformName
+ " classes to be included in the distribution");
task.setClassifier(platformName + "Thin");
task.setClassifier(platformName + "-dist-thin");
task.from(sourceSet.getOutput());
task.from(sourceSet.getResources());
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright 2019 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
package com.linkedin.transport.plugin.packaging;

import com.google.common.collect.ImmutableList;
import com.linkedin.transport.plugin.Platform;
import java.util.List;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.Jar;


/**
* A {@link Packaging} class which generates a Jar containing the autogenerated code for the platform
*/
public class ThinJarPackaging implements Packaging {

@Override
public List<TaskProvider<? extends Task>> configurePackagingTasks(Project project, Platform platform,
SourceSet platformSourceSet, SourceSet mainSourceSet) {
/*
task <platformName>ThinJar(type: Jar, dependsOn: prestoClasses) {
classifier '<platformName>-thin'
from sourceSets.<platform>.output
from sourceSets.<platform>.resources
}
*/

TaskProvider<? extends Task> thinJarTask =
project.getTasks().register(platformSourceSet.getTaskName(null, "thinJar"), Jar.class, task -> {
task.dependsOn(project.getTasks().named(platformSourceSet.getClassesTaskName()));
task.setDescription("Assembles a thin jar archive containing the " + platform.getName()
+ " classes to be included in the distribution");
task.setClassifier(platform.getName() + "-thin");
task.from(platformSourceSet.getOutput());
task.from(platformSourceSet.getResources());
});

project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, thinJarTask);
return ImmutableList.of(thinJarTask);
}
}