Skip to content

Commit

Permalink
Added custom rules for integration tests (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
thalescm authored Sep 11, 2019
1 parent 4024dee commit 54661fe
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ public enum ProjectType {
ANDROID_APP,
ANDROID_LIB,
JAVA_LIB,
GROOVY_LIB(RuleType.GROOVY_LIBRARY, RuleType.GROOVY_TEST),
KOTLIN_LIB(RuleType.KOTLIN_LIBRARY, RuleType.KOTLIN_TEST),
SCALA_LIB(RuleType.SCALA_LIBRARY, RuleType.SCALA_TEST),
GROOVY_LIB(RuleType.GROOVY_LIBRARY, RuleType.GROOVY_TEST, RuleType.GROOVY_INTEGRATION_TEST),
KOTLIN_LIB(RuleType.KOTLIN_LIBRARY, RuleType.KOTLIN_TEST, RuleType.KOTLIN_INTEGRATION_TEST),
SCALA_LIB(RuleType.SCALA_LIBRARY, RuleType.SCALA_TEST, RuleType.SCALA_INTEGRATION_TEST),
UNKNOWN;

private final RuleType mainRuleType;
private final RuleType testRuleType;
private final RuleType integrationTestRuleType;

ProjectType() {
this(RuleType.JAVA_LIBRARY, RuleType.JAVA_TEST);
this(RuleType.JAVA_LIBRARY, RuleType.JAVA_TEST, RuleType.JAVA_INTEGRATION_TEST);
}

ProjectType(RuleType mainRuleType, RuleType testRuleType) {
ProjectType(RuleType mainRuleType, RuleType testRuleType, RuleType integrationTestRuleType) {
this.mainRuleType = mainRuleType;
this.testRuleType = testRuleType;
this.integrationTestRuleType = integrationTestRuleType;
}

public RuleType getMainRuleType() {
Expand All @@ -28,4 +30,8 @@ public RuleType getMainRuleType() {
public RuleType getTestRuleType() {
return testRuleType;
}

public RuleType getIntegrationTestRuleType() {
return integrationTestRuleType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ public enum RuleType {
ANDROID_RESOURCE,
GROOVY_LIBRARY("groovy", "java"),
GROOVY_TEST("groovy", "java"),
GROOVY_INTEGRATION_TEST("groovy", "java"),
JAVA_ANNOTATION_PROCESSOR,
JAVA_BINARY,
JAVA_LIBRARY("java"),
JAVA_TEST("java"),
JAVA_INTEGRATION_TEST("java"),
KEYSTORE,
KOTLIN_ANDROID_LIBRARY("java", "kt"),
KOTLIN_ANDROID_MODULE("java", "kt"),
KOTLIN_LIBRARY("java", "kt"),
KOTLIN_ROBOLECTRIC_TEST("java", "kt"),
KOTLIN_TEST("java", "kt"),
KOTLIN_INTEGRATION_TEST("java", "kt"),
MANIFEST,
SCALA_LIBRARY("java", "scala"),
SCALA_TEST("java", "scala"),
SCALA_INTEGRATION_TEST("java", "scala"),
PREBUILT_JAR("binary_jar"),
PREBUILT,
PREBUILT_NATIVE_LIBRARY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public class RuleOverridesExtension {
.put(RuleType.KOTLIN_ANDROID_MODULE, OKBUCK_ANDROID_MODULES_TARGET)
.put(RuleType.KEYSTORE, OKBUCK_TARGETS_TARGET)
.put(RuleType.MANIFEST, OKBUCK_TARGETS_TARGET)
.put(RuleType.JAVA_INTEGRATION_TEST, OKBUCK_TARGETS_TARGET)
.put(RuleType.SCALA_INTEGRATION_TEST, OKBUCK_TARGETS_TARGET)
.put(RuleType.GROOVY_INTEGRATION_TEST, OKBUCK_TARGETS_TARGET)
.put(RuleType.KOTLIN_INTEGRATION_TEST, OKBUCK_TARGETS_TARGET)
.build();

private Map<String, OverrideSetting> overridesMap = Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private static List<Rule> createRules(Project project, boolean hasIntegrationTes
(JvmTarget) target,
projectType.getMainRuleType(),
projectType.getTestRuleType(),
projectType.getIntegrationTestRuleType(),
hasIntegrationTests));
break;
case ANDROID_LIB:
Expand Down Expand Up @@ -128,14 +129,15 @@ private static List<Rule> createRules(
JvmTarget target,
RuleType mainRuleType,
RuleType testRuleType,
RuleType integrationTestRuleType,
boolean hasIntegrationTests) {
List<Rule> rules = new ArrayList<>(JvmLibraryRuleComposer.compose(target, mainRuleType));

if (!target.getTest().getSources().isEmpty()) {
rules.add(JvmTestRuleComposer.compose(target, testRuleType));
}
if (hasIntegrationTests && !target.getIntegrationTest().getSources().isEmpty()) {
rules.add(JvmIntegrationTestRuleComposer.compose(target, testRuleType));
rules.add(JvmIntegrationTestRuleComposer.compose(target, integrationTestRuleType));
}

return rules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,15 @@ def okbuck_prebuilt_jar(
binary_jar = jar_path,
**kwargs
)

def okbuck_java_integration_test(**kwargs):
native.java_test(**kwargs)

def okbuck_scala_integration_test(**kwargs):
native.scala_test(**kwargs)

def okbuck_kotlin_integration_test(**kwargs):
native.kotlin_test(**kwargs)

def okbuck_groovy_integration_test(**kwargs):
native.groovy_test(**kwargs)

0 comments on commit 54661fe

Please sign in to comment.