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

Prefer abstractions over implementations for upcoming kotlin refactors #456

Merged
merged 1 commit into from
Jun 22, 2017
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 @@ -4,15 +4,15 @@ import com.uber.okbuck.composer.jvm.JvmBuckRuleComposer
import com.uber.okbuck.core.model.base.RuleType
import com.uber.okbuck.core.model.groovy.GroovyLibTarget
import com.uber.okbuck.core.util.RetrolambdaUtil
import com.uber.okbuck.rule.groovy.GroovyLibraryRule
import com.uber.okbuck.rule.java.JavaLibraryRule

final class GroovyLibraryRuleComposer extends JvmBuckRuleComposer {

private GroovyLibraryRuleComposer() {
// no instance
}

static GroovyLibraryRule compose(GroovyLibTarget target) {
static JavaLibraryRule compose(GroovyLibTarget target) {
List<String> deps = []
deps.addAll(external(target.main.externalDeps))
deps.addAll(targets(target.main.targetDeps))
Expand All @@ -26,18 +26,26 @@ final class GroovyLibraryRuleComposer extends JvmBuckRuleComposer {
providedDeps.add(RetrolambdaUtil.getRtStubJarRule())
}

new GroovyLibraryRule(
List<String> testTargets = []
if (target.test.sources) {
testTargets.add(":${test(target)}")
}

new JavaLibraryRule(
src(target),
["PUBLIC"],
deps,
target.main.sources,
[] as Set,
[] as Set,
Collections.emptySet(),
Collections.emptySet(),
providedDeps,
target.main.resourcesDir,
target.sourceCompatibility,
target.targetCompatibility,
Collections.emptyList(),
target.main.jvmArgs,
target.getExtraOpts(RuleType.GROOVY_LIBRARY))
testTargets,
target.getExtraOpts(RuleType.GROOVY_LIBRARY),
RuleType.GROOVY_LIBRARY)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import com.uber.okbuck.composer.jvm.JvmBuckRuleComposer
import com.uber.okbuck.core.model.base.RuleType
import com.uber.okbuck.core.model.groovy.GroovyLibTarget
import com.uber.okbuck.core.util.RetrolambdaUtil
import com.uber.okbuck.rule.groovy.GroovyTestRule
import com.uber.okbuck.rule.java.JavaTestRule

final class GroovyTestRuleComposer extends JvmBuckRuleComposer {

private GroovyTestRuleComposer() {
// no instance
}

static GroovyTestRule compose(GroovyLibTarget target) {
static JavaTestRule compose(GroovyLibTarget target) {
List<String> deps = []
deps.add(":${src(target)}")
deps.addAll(external(target.test.externalDeps))
Expand All @@ -27,19 +27,22 @@ final class GroovyTestRuleComposer extends JvmBuckRuleComposer {
providedDeps.add(RetrolambdaUtil.getRtStubJarRule())
}

new GroovyTestRule(
new JavaTestRule(
test(target),
["PUBLIC"],
deps,
target.test.sources,
[] as Set,
[] as Set,
Collections.emptySet(),
Collections.emptySet(),
providedDeps,
target.test.resourcesDir,
target.sourceCompatibility,
target.targetCompatibility,
Collections.emptyList(),
target.test.jvmArgs,
target.testOptions,
target.getExtraOpts(RuleType.GROOVY_TEST))
target.getExtraOpts(RuleType.GROOVY_TEST),
RuleType.GROOVY_TEST,
Arrays.asList("unit", "groovy"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.uber.okbuck.composer.jvm.JvmBuckRuleComposer
import com.uber.okbuck.core.model.base.RuleType
import com.uber.okbuck.core.model.kotlin.KotlinLibTarget
import com.uber.okbuck.rule.java.JavaLibraryRule
import com.uber.okbuck.rule.kotlin.KotlinLibraryRule

final class KotlinLibraryRuleComposer extends JvmBuckRuleComposer {

Expand All @@ -27,7 +26,7 @@ final class KotlinLibraryRuleComposer extends JvmBuckRuleComposer {
testTargets.add(":${test(target)}")
}

new KotlinLibraryRule(
new JavaLibraryRule(
src(target),
["PUBLIC"],
deps,
Expand All @@ -41,6 +40,7 @@ final class KotlinLibraryRuleComposer extends JvmBuckRuleComposer {
Collections.emptyList(),
target.main.jvmArgs,
testTargets,
target.getExtraOpts(RuleType.KOTLIN_LIBRARY))
target.getExtraOpts(RuleType.KOTLIN_LIBRARY),
RuleType.KOTLIN_LIBRARY)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.uber.okbuck.composer.jvm.JvmBuckRuleComposer
import com.uber.okbuck.core.model.base.RuleType
import com.uber.okbuck.core.model.kotlin.KotlinLibTarget
import com.uber.okbuck.rule.java.JavaTestRule
import com.uber.okbuck.rule.kotlin.KotlinTestRule

final class KotlinTestRuleComposer extends JvmBuckRuleComposer {

Expand All @@ -23,7 +22,7 @@ final class KotlinTestRuleComposer extends JvmBuckRuleComposer {
providedDeps.addAll(targets(target.testProvided.targetDeps))
providedDeps.removeAll(deps)

new KotlinTestRule(
new JavaTestRule(
test(target),
["PUBLIC"],
deps,
Expand All @@ -37,6 +36,8 @@ final class KotlinTestRuleComposer extends JvmBuckRuleComposer {
Collections.emptyList(),
target.test.jvmArgs,
target.testOptions,
target.getExtraOpts(RuleType.KOTLIN_TEST))
target.getExtraOpts(RuleType.KOTLIN_TEST),
RuleType.KOTLIN_TEST,
Arrays.asList("unit", "kotlin"))
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
package com.uber.okbuck.core.model.base;

import java.util.Arrays;
import java.util.List;

public enum RuleType {
ANDROID_BINARY,
ANDROID_BUILD_CONFIG,
ANDROID_INSTRUMENTATION_APK,
ANDROID_INSTRUMENTATION_TEST,
ANDROID_LIBRARY,
ANDROID_LIBRARY_WITH_KOTLIN("java", "kt"),
ANDROID_MANIFEST,
ANDROID_RESOURCE,
GEN_AIDL,
GENRULE,
GROOVY_LIBRARY,
GROOVY_TEST,
GROOVY_LIBRARY("groovy", "java"),
GROOVY_TEST("groovy", "java"),
JAVA_BINARY,
JAVA_LIBRARY,
JAVA_TEST,
KOTLIN_LIBRARY("kt"),
KOTLIN_TEST("kt"),
KOTLIN_LIBRARY("java", "kt"),
KOTLIN_TEST("java", "kt"),
PREBUILT_NATIVE_LIBRARY,
ROBOLECTRIC_TEST;
ROBOLECTRIC_TEST,
ROBOLECTRIC_TEST_WITH_KOTLIN("java", "kt");

private final String sourceExtension;
private final List<String> sourceExtensions;

RuleType() {
this("java");
}

RuleType(String sourceExtension) {
this.sourceExtension = sourceExtension;
RuleType(String... extensions) {
this.sourceExtensions = Arrays.asList(extensions);
}

public String getSourceExtension() {
return sourceExtension;
public List<String> getSourceExtensions() {
return sourceExtensions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,17 @@ package com.uber.okbuck.rule.android

import com.uber.okbuck.core.model.base.RuleType
import com.uber.okbuck.core.model.jvm.TestOptions
import com.uber.okbuck.rule.base.BuckRule
import com.uber.okbuck.rule.java.JavaRule
import org.apache.commons.lang.StringUtils

abstract class AndroidRule extends BuckRule {
abstract class AndroidRule extends JavaRule {

private final Set<String> mSrcSet
private final String mManifest
private final String mRobolectricManifest
private final List<String> mAnnotationProcessors
private final List<String> mAptDeps
private final List<String> mAidlRuleNames
private final String mAppClass
private final String mSourceCompatibility
private final String mTargetCompatibility
private final List<String> mPostprocessClassesCommands
private final List<String> mOptions
private final TestOptions mTestOptions
private final Set<String> mProvidedDeps
private final boolean mGenerateR2
private final String mResourcesDir
private final String mRuntimeDependency
private final List<String> mTestTargets
private final List<String> mLabels

/**
* @srcTargets , used for SqlDelight support(or other case), genrule's output will be used as src, pass empty set if not present
* @param appClass , if exopackage is enabled, pass the detected app class, otherwise, pass null
* */
AndroidRule(
RuleType ruleType,
String name,
Expand All @@ -54,58 +37,22 @@ abstract class AndroidRule extends BuckRule {
List<String> testTargets,
List<String> labels = null,
Set<String> extraOpts = []) {
super(ruleType, name, visibility, deps, extraOpts)
super(ruleType, name, visibility, deps, srcSet, annotationProcessors, aptDeps, providedDeps,
resourcesDir, sourceCompatibility, targetCompatibility, postprocessClassesCommands,
options, testOptions, testTargets, labels, extraOpts,
!StringUtils.isEmpty(appClass)
? Collections.singleton(appClass) : Collections.emptySet())

mSrcSet = srcSet
mManifest = manifest
mRobolectricManifest = robolectricManifest
mAnnotationProcessors = annotationProcessors
mAptDeps = aptDeps
mAidlRuleNames = aidlRuleNames
mAppClass = appClass
mSourceCompatibility = sourceCompatibility
mTargetCompatibility = targetCompatibility
mPostprocessClassesCommands = postprocessClassesCommands
mOptions = options
mTestOptions = testOptions
mProvidedDeps = providedDeps
mGenerateR2 = generateR2
mResourcesDir = resourcesDir
mRuntimeDependency = runtimeDependency
mTestTargets = testTargets
mLabels = labels
}

@Override
protected final void printContent(PrintStream printer) {
if (!mSrcSet.empty) {
printer.println("\tsrcs = glob([")
for (String src : mSrcSet) {
printer.println("\t\t'${src}/**/*.java',")
}

if (!StringUtils.isEmpty(mAppClass)) {
printer.println("\t], excludes = ['${mAppClass}']),")
} else {
printer.println("\t]),")
}
}

if (mTestTargets) {
printer.println("\ttests = [")
for (String testTarget : mTestTargets) {
printer.println("\t\t'${testTarget}',")
}
printer.println("\t],")
}

if (mResourcesDir) {
printer.println("\tresources = glob([")
printer.println("\t\t'${mResourcesDir}/**',")
printer.println("\t]),")

printer.println("\tresources_root = '${mResourcesDir}',")
}
super.printContent(printer)

if (!StringUtils.isEmpty(mManifest)) {
printer.println("\tmanifest = '${mManifest}',")
Expand All @@ -115,30 +62,6 @@ abstract class AndroidRule extends BuckRule {
printer.println("\trobolectric_manifest = '${mRobolectricManifest}',")
}

if (!mAnnotationProcessors.empty) {
printer.println("\tannotation_processors = [")
for (String processor : mAnnotationProcessors) {
printer.println("\t\t'${processor}',")
}
printer.println("\t],")
}

if (!mAptDeps.empty) {
printer.println("\tannotation_processor_deps = [")
for (String dep : mAptDeps.sort()) {
printer.println("\t\t'${dep}',")
}
printer.println("\t],")
}

if (!mProvidedDeps.empty) {
printer.println("\tprovided_deps = [")
for (String dep : mProvidedDeps.sort()) {
printer.println("\t\t'${dep}',")
}
printer.println("\t],")
}

if (!mAidlRuleNames.empty) {
printer.println("\texported_deps = [")
mAidlRuleNames.sort().each { String aidlRuleName ->
Expand All @@ -147,55 +70,12 @@ abstract class AndroidRule extends BuckRule {
printer.println("\t],")
}

printer.println("\tsource = '${mSourceCompatibility}',")
printer.println("\ttarget = '${mTargetCompatibility}',")

if (!mOptions.empty) {
printer.println("\textra_arguments = [")
mOptions.each { String option ->
printer.println("\t\t'${option}',")
}
printer.println("\t],")
}

if (!mPostprocessClassesCommands.empty) {
printer.println("\tpostprocess_classes_commands = [")
mPostprocessClassesCommands.each { String cmd ->
printer.println("\t\t'${cmd}',")
}
printer.println("\t],")
}

if (mGenerateR2) {
printer.println("\tfinal_r_name = 'R2',")
}

if (mRuntimeDependency) {
printer.println("\trobolectric_runtime_dependency = '${mRuntimeDependency}',")
}

if (mLabels) {
printer.println("\tlabels = [")
mLabels.each { String label ->
printer.println("\t\t'${label}',")
}
printer.println("\t],")
}

if (mTestOptions.jvmArgs) {
printer.println("\tvm_args = [")
mTestOptions.jvmArgs.each { String arg ->
printer.println("\t\t'${arg}',")
}
printer.println("\t],")
}

if (mTestOptions.env) {
printer.println("\tenv = {")
mTestOptions.env.each { String key, Object value ->
printer.println("\t\t'${key}': '${value.toString()}',")
}
printer.println("\t},")
}
}
}
Loading