Skip to content

Commit

Permalink
Make application plugin support universal (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
kageiit authored Jul 19, 2017
1 parent c3c61bf commit 1eebcc7
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.uber.okbuck.composer.jvm.JvmBuckRuleComposer
import com.uber.okbuck.core.model.android.AndroidTarget
import com.uber.okbuck.core.model.base.ProjectType
import com.uber.okbuck.core.model.base.Target
import com.uber.okbuck.core.model.java.JavaLibTarget
import com.uber.okbuck.core.model.java.JavaTarget
import com.uber.okbuck.core.util.LintUtil
import com.uber.okbuck.core.util.ProjectUtil
Expand Down Expand Up @@ -38,7 +39,7 @@ final class LintRuleComposer extends JvmBuckRuleComposer {
List<String> lintDeps = []
lintDeps.addAll(LintUtil.LINT_DEPS_RULE)
customLintTargets.each {
if (ProjectUtil.getType(it.project) == ProjectType.JAVA_APP) {
if (it instanceof JavaLibTarget && it.hasApplication()) {
lintDeps.add(binTargets(it))
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package com.uber.okbuck.composer.java
import com.uber.okbuck.composer.jvm.JvmBuckRuleComposer
import com.uber.okbuck.core.model.base.RuleType
import com.uber.okbuck.core.model.java.JavaLibTarget
import com.uber.okbuck.core.model.java.JavaTarget
import com.uber.okbuck.core.util.RetrolambdaUtil
import com.uber.okbuck.rule.base.BuckRule
import com.uber.okbuck.rule.java.JavaBinaryRule
import com.uber.okbuck.rule.java.JavaLibraryRule

final class JavaLibraryRuleComposer extends JvmBuckRuleComposer {
Expand All @@ -12,8 +15,8 @@ final class JavaLibraryRuleComposer extends JvmBuckRuleComposer {
// no instance
}

static JavaLibraryRule compose(JavaLibTarget target,
RuleType ruleType = RuleType.JAVA_LIBRARY) {
static List<BuckRule> compose(JavaLibTarget target,
RuleType ruleType = RuleType.JAVA_LIBRARY) {
List<String> deps = []
deps.addAll(external(target.main.externalDeps))
deps.addAll(targets(target.main.targetDeps))
Expand All @@ -36,7 +39,8 @@ final class JavaLibraryRuleComposer extends JvmBuckRuleComposer {
testTargets.add(":${test(target)}")
}

new JavaLibraryRule(
List<BuckRule> rules = []
rules.add(new JavaLibraryRule(
ruleType,
src(target),
["PUBLIC"],
Expand All @@ -52,5 +56,13 @@ final class JavaLibraryRuleComposer extends JvmBuckRuleComposer {
target.main.jvmArgs,
testTargets,
target.getExtraOpts(ruleType))
)

if (target.hasApplication()) {
rules.add(new JavaBinaryRule(bin(target), ["PUBLIC"], [":${src(target)}"], target.mainClass,
target.excludes, target.getExtraOpts(RuleType.JAVA_BINARY)))
}

return rules
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.uber.okbuck.composer.jvm;

import com.uber.okbuck.composer.base.BuckRuleComposer;
import com.uber.okbuck.core.model.java.JavaTarget;
import com.uber.okbuck.core.model.jvm.JvmTarget;

public class JvmBuckRuleComposer extends BuckRuleComposer {
Expand All @@ -9,6 +10,10 @@ public static String src(final JvmTarget target) {
return "src_" + target.getName();
}

public static String bin(final JvmTarget target) {
return "bin_" + target.getName();
}

public static String test(final JvmTarget target) {
return "test_" + target.getName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public enum ProjectType {
ANDROID_APP,
ANDROID_LIB,
GROOVY_LIB,
JAVA_APP,
JAVA_LIB,
KOTLIN_LIB,
SCALA_LIB,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.uber.okbuck.core.model.android.AndroidAppTarget;
import com.uber.okbuck.core.model.android.AndroidLibTarget;
import com.uber.okbuck.core.model.groovy.GroovyLibTarget;
import com.uber.okbuck.core.model.java.JavaAppTarget;
import com.uber.okbuck.core.model.java.JavaLibTarget;
import com.uber.okbuck.core.model.jvm.JvmTarget;
import com.uber.okbuck.core.model.kotlin.KotlinLibTarget;
Expand Down Expand Up @@ -75,10 +74,6 @@ public Map<String, Target> getTargets(Project project) {
projectTargets = Collections.singletonMap(JvmTarget.MAIN,
new ScalaLibTarget(project, JvmTarget.MAIN));
break;
case JAVA_APP:
projectTargets = Collections.singletonMap(JvmTarget.MAIN,
new JavaAppTarget(project, JvmTarget.MAIN));
break;
case JAVA_LIB:
projectTargets = Collections.singletonMap(JvmTarget.MAIN,
new JavaLibTarget(project, JvmTarget.MAIN));
Expand Down Expand Up @@ -106,9 +101,9 @@ public Target getTargetForOutput(Project targetProject, File artifact) {
}
break;
case GROOVY_LIB:
case JAVA_APP:
case JAVA_LIB:
case KOTLIN_LIB:
case SCALA_LIB:
result = getTargets(targetProject).values().iterator().next();
break;
default:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import com.uber.okbuck.core.model.base.Scope
import com.uber.okbuck.core.util.RetrolambdaUtil
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.ApplicationPlugin
import org.gradle.jvm.tasks.Jar
import org.jetbrains.annotations.Nullable

/**
* A java library target
Expand Down Expand Up @@ -52,4 +55,18 @@ class JavaLibTarget extends JavaTarget {
}
return cmds
}

boolean hasApplication() {
return project.plugins.hasPlugin(ApplicationPlugin)
}

@Nullable
String getMainClass() {
Object mainClass = getProject().getProperties().get("mainClassName")
return mainClass == null ? null : mainClass.toString()
}

Set<String> getExcludes() {
return ((Jar) getProject().getTasks().getByName("jar")).getExcludes()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.uber.okbuck.composer.android.KeystoreRuleComposer
import com.uber.okbuck.composer.android.LintRuleComposer
import com.uber.okbuck.composer.android.PreBuiltNativeLibraryRuleComposer
import com.uber.okbuck.composer.android.TrasformDependencyWriterRuleComposer
import com.uber.okbuck.composer.java.JavaBinaryRuleComposer
import com.uber.okbuck.composer.java.JavaLibraryRuleComposer
import com.uber.okbuck.composer.java.JavaTestRuleComposer
import com.uber.okbuck.config.BUCKFile
Expand All @@ -27,7 +26,6 @@ import com.uber.okbuck.core.model.base.ProjectType
import com.uber.okbuck.core.model.base.RuleType
import com.uber.okbuck.core.model.base.Target
import com.uber.okbuck.core.model.groovy.GroovyLibTarget
import com.uber.okbuck.core.model.java.JavaAppTarget
import com.uber.okbuck.core.model.java.JavaLibTarget
import com.uber.okbuck.core.model.kotlin.KotlinLibTarget
import com.uber.okbuck.core.model.scala.ScalaLibTarget
Expand Down Expand Up @@ -71,9 +69,6 @@ final class BuckFileGenerator {
case ProjectType.JAVA_LIB:
rules.addAll(createRules((JavaLibTarget) target))
break
case ProjectType.JAVA_APP:
rules.addAll(createRules((JavaAppTarget) target))
break
case ProjectType.GROOVY_LIB:
rules.addAll(createRules((GroovyLibTarget) target))
break
Expand Down Expand Up @@ -110,24 +105,17 @@ final class BuckFileGenerator {

private static List<BuckRule> createRules(JavaLibTarget target) {
List<BuckRule> rules = []
rules.add(JavaLibraryRuleComposer.compose(target))
rules.addAll(JavaLibraryRuleComposer.compose(target))

if (target.test.sources) {
rules.add(JavaTestRuleComposer.compose(target))
}
return rules
}

private static List<BuckRule> createRules(JavaAppTarget target) {
List<BuckRule> rules = []
rules.addAll(createRules((JavaLibTarget) target))
rules.add(JavaBinaryRuleComposer.compose(target))
return rules
}

private static List<BuckRule> createRules(GroovyLibTarget target) {
List<BuckRule> rules = []
rules.add(JavaLibraryRuleComposer.compose(target, RuleType.GROOVY_LIBRARY))
rules.addAll(JavaLibraryRuleComposer.compose(target, RuleType.GROOVY_LIBRARY))

if (target.test.sources) {
rules.add(JavaTestRuleComposer.compose(target, RuleType.GROOVY_TEST))
Expand All @@ -137,7 +125,7 @@ final class BuckFileGenerator {

private static List<BuckRule> createRules(KotlinLibTarget target) {
List<BuckRule> rules = []
rules.add(JavaLibraryRuleComposer.compose(target, RuleType.KOTLIN_LIBRARY))
rules.addAll(JavaLibraryRuleComposer.compose(target, RuleType.KOTLIN_LIBRARY))

if (target.test.sources) {
rules.add(JavaTestRuleComposer.compose(target, RuleType.KOTLIN_TEST))
Expand All @@ -147,7 +135,7 @@ final class BuckFileGenerator {

private static List<BuckRule> createRules(ScalaLibTarget target) {
List<BuckRule> rules = []
rules.add(JavaLibraryRuleComposer.compose(target, RuleType.SCALA_LIBRARY))
rules.addAll(JavaLibraryRuleComposer.compose(target, RuleType.SCALA_LIBRARY))

if (target.test.sources) {
rules.add(JavaTestRuleComposer.compose(target, RuleType.SCALA_TEST))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public static ProjectType getType(Project project) {
return ProjectType.KOTLIN_LIB;
} else if (plugins.hasPlugin(ScalaPlugin.class)) {
return ProjectType.SCALA_LIB;
} else if (plugins.hasPlugin(ApplicationPlugin.class)) {
return ProjectType.JAVA_APP;
} else if (plugins.hasPlugin(JavaPlugin.class)) {
return ProjectType.JAVA_LIB;
} else {
Expand Down
3 changes: 3 additions & 0 deletions libraries/scalalibrary/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
plugins {
id "scala"
id "application"
}

dependencies {
testCompile "org.scalatest:scalatest_2.11:3.0.3"
testCompile 'junit:junit:4.12'
}

mainClassName = "com.uber.okbuck.scala.example.Hello"
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ package com.uber.okbuck.scala.example
object DummyScala {
def hello: String = "hello"
}

object Hello extends App {
println("Hello, world")
}

0 comments on commit 1eebcc7

Please sign in to comment.