Skip to content

Commit

Permalink
Plugin: Publish Presto thin jar which allows consumers to control dep…
Browse files Browse the repository at this point in the history
…endency graph (#49)
  • Loading branch information
shardulm94 authored and wmoustafa committed Oct 13, 2021
1 parent cdfba52 commit 0b69275
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
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);
}
}

0 comments on commit 0b69275

Please sign in to comment.