Skip to content

Commit

Permalink
Added transform-cli module to support gradle transforms in okbuck (#373)
Browse files Browse the repository at this point in the history
* Added transform-cli module to support gradle transforms in okbuck

* Changes for review

* Removed gradle dependency from dependencies.gradle

* Removed non complete tests

* Added prefix and used camel case for java system properties

* Removed transform experimental flag

* Removed transform-cli from okbuck configuration
  • Loading branch information
malbano authored and kageiit committed Jan 31, 2017
1 parent a607797 commit ebcea6f
Show file tree
Hide file tree
Showing 22 changed files with 1,125 additions and 36 deletions.
17 changes: 17 additions & 0 deletions Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ okbuck {
remove = ['.buckconfig.local', "**/BUCK"]
keep = [".okbuck/**/BUCK"]
}
transform {
transforms = [
'appDebug' : [
[transform : "<FULL_QUALIFIED_CLASS_NAME_FOR_TRANSFORM_CLASS>",
configFile : "<OPTIONAL_CONFIGURATION_FILE>"]
],
]
}
experimental {
transform = true
}
}
dependencies {
transform "<TRANSFORM_DEPENDENCIES>"
}
```

Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ buildscript {
apply from: rootProject.file('dependencies.gradle')
repositories {
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath deps.build.androidPlugin
classpath deps.build.butterKnifePlugin
classpath deps.build.retrolambdaPlugin
classpath deps.build.sqlDelightPlugin
classpath deps.build.shadowJar
}
}

Expand Down Expand Up @@ -144,7 +146,7 @@ okbuck {
'libraries/common:paidRelease',
]
]
buckProjects = project.subprojects.findAll { it.name != "plugin" }
buckProjects = project.subprojects.findAll { it.name != "plugin" && it.name != "transform-cli" }

intellij {
sources = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import com.uber.okbuck.rule.base.GenRule
import org.apache.commons.io.FileUtils
import org.gradle.api.Project

import java.nio.file.Files

final class TrasformDependencyWriterRuleComposer extends AndroidBuckRuleComposer {

static final String OPT_TRANSFORM_PROVIDER_CLASS = "provider"
static final String OPT_TRANSFORM_CLASS = "transform"
static final String OPT_CONFIG_FILE = "configFile"
static final String RUNNER_MAIN_CLASS = "com.uber.transform.CliTransform"

private TrasformDependencyWriterRuleComposer() {}

Expand All @@ -24,8 +22,6 @@ final class TrasformDependencyWriterRuleComposer extends AndroidBuckRuleComposer
}

static GenRule compose(AndroidAppTarget target, Map<String, String> options) {
String runnerMainClass = target.transformRunnerClass
String providerClass = options.get(OPT_TRANSFORM_PROVIDER_CLASS)
String transformClass = options.get(OPT_TRANSFORM_CLASS)
String configFile = options.get(OPT_CONFIG_FILE)

Expand All @@ -37,27 +33,29 @@ final class TrasformDependencyWriterRuleComposer extends AndroidBuckRuleComposer
String output = "\$OUT"
List<String> cmds = [
"echo \"#!/bin/bash\" > ${output};",
"echo \"set -e\" >> ${output};",
"echo \"set -ex\" >> ${output};",

"echo \"java " +

"-Dokbuck.inJarsDir=\"\\\$1\" " +
"-Dokbuck.outJarsDir=\"\\\$2\" " +
"-Dokbuck.androidBootClasspath=\"\\\$3\" " +

"echo \"export IN_JARS_DIR=\\\$1\" >> ${output};",
"echo \"export OUT_JARS_DIR=\\\$2\" >> ${output};",
"echo \"export ANDROID_BOOTCLASSPATH=\\\$3\" >> ${output};",
(configFile != null ? "-Dokbuck.configFile=\"\$SRCS\" " : "") +
(transformClass != null ? "-Dokbuck.transformClass=\"${transformClass}\" " : "") +

configFile != null ? "echo \"export CONFIG_FILE=\$SRCS\" >> ${output};" : "",
providerClass != null ? "echo \"export TRANSFORM_PROVIDER_CLASS=${providerClass}\" >> ${output};" : "",
transformClass != null ? "echo \"export TRANSFORM_CLASS=${transformClass}\" >> ${output};" : "",
" -cp \$(location ${TransformUtil.TRANSFORM_RULE}) ${RUNNER_MAIN_CLASS}\" >> ${output};",

"echo \"java -cp \$(location ${TransformUtil.TRANSFORM_RULE}) ${runnerMainClass}\" >> ${output};",
"chmod +x ${output}"]

System.out.println("Generating rule for transform: ")
System.out.println(cmds)

return new GenRule(getTransformRuleName(target, options), input, cmds, true)
}

static getTransformRuleName(AndroidAppTarget target, Map<String, String> options) {
String providerClass = options.get(OPT_TRANSFORM_PROVIDER_CLASS)
String transformClass = options.get(OPT_TRANSFORM_CLASS)
String name = providerClass != null ? providerClass : transformClass
return transform(name, target)
return transform(options.get(OPT_TRANSFORM_CLASS), target)
}

static String getTransformConfigRuleForFile(Project project, File config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ class AndroidAppTarget extends AndroidLibTarget {
return (List<Map<String, String>>) getProp(okbuck.transform.transforms, [])
}

String getTransformRunnerClass() {
return okbuck.transform.main
}

static String getPackedProguardConfig(File file) {
ZipFile zipFile = new ZipFile(file)
ZipEntry proguardEntry = zipFile.entries().find {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@

import org.gradle.api.Project;

import java.io.File;
import java.util.Collections;

public final class TransformUtil {

private static final String CONFIGURATION_TRANSFORM = "transform";
public static final String TRANSFORM_CACHE = OkBuckGradlePlugin.DEFAULT_CACHE_PATH + "/transform";
private static final String TRANSFORM_BUCK_FILE = "transform/BUCK_FILE";

private static final String CONFIGURATION_TRANSFORM = "transform";
private static final String TRANSFORM_FOLDER = "transform/";
private static final String TRANSFORM_BUCK_FILE = "BUCK_FILE";
private static final String TRANSFORM_JAR = "transform-cli.jar";

public static final String TRANSFORM_RULE = "//" + TRANSFORM_CACHE + ":okbuck_transform";

private TransformUtil() { }

public static void fetchTransformDeps(Project project) {
new DependencyCache("transform",
DependencyCache dependencyCache = new DependencyCache("transform",
project.getRootProject(),
TRANSFORM_CACHE,
Collections.singleton(project.getConfigurations().getByName(CONFIGURATION_TRANSFORM)),
TRANSFORM_BUCK_FILE);
TRANSFORM_FOLDER + TRANSFORM_BUCK_FILE);

FileUtil.copyResourceToProject(
TRANSFORM_FOLDER + TRANSFORM_BUCK_FILE, new File(dependencyCache.getCacheDir(), "BUCK"));
FileUtil.copyResourceToProject(
TRANSFORM_FOLDER + TRANSFORM_JAR, new File(dependencyCache.getCacheDir(), TRANSFORM_JAR));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,4 @@ public class TransformExtension {
* Stores the configuration per transform. Mapping is stored as target-[transforms].
*/
public Map<String, Map<String, String>> transforms = new HashMap<>();

/**
* Transform runner class
*/
public String main;
}
Binary file not shown.
14 changes: 9 additions & 5 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
def versions = [
butterKnifeVersion: '8.4.0',
daggerVersion : '2.8',
leakCanaryVersion : '1.5',
supportVersion : '25.0.0',
butterKnifeVersion : '8.4.0',
daggerVersion : '2.8',
leakCanaryVersion : '1.5',
supportVersion : '25.0.1',
androidPluginVersion : '2.3.0-beta3',
]

def build = [
androidPlugin : 'com.android.tools.build:gradle:2.3.0-beta3',
androidPlugin : "com.android.tools.build:gradle:${versions.androidPluginVersion}",
androidPluginApi : "com.android.tools.build:gradle-api:${versions.androidPluginVersion}",
butterKnifePlugin: "com.jakewharton:butterknife-gradle-plugin:${versions.butterKnifeVersion}",
commonsIo : 'commons-io:commons-io:2.5',
commonsLang : 'commons-lang:commons-lang:2.6',
mavenArtifact : 'org.apache.maven:maven-artifact:3.3.9',
retrolambdaPlugin: 'me.tatarka:gradle-retrolambda:3.5.0',
sqlDelightPlugin : 'com.squareup.sqldelight:gradle-plugin:0.5.1',
shadowJar : "com.github.jengelman.gradle.plugins:shadow:1.2.4",
]

def buildConfig = [
Expand Down Expand Up @@ -64,6 +67,7 @@ def test = [
junit : 'junit:junit:4.12',
mockito : 'org.mockito:mockito-core:1.10.19',
robolectric : 'org.robolectric:robolectric:3.0',
assertj : 'org.assertj:assertj-core:3.6.1'
]

ext.config = [
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ include 'libraries:lintErrorLibrary'
include 'libraries:parcelable'
include 'libraries:robolectric-base'
include 'plugin'
include 'transform-cli'
34 changes: 34 additions & 0 deletions transform-cli/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apply plugin: "application"
apply plugin: "com.github.johnrengelman.shadow"

jar.manifest.attributes(
'Implementation-Title': 'Cli Transform',
'Implementation-Version': '1.0',
'Main-Class': 'com.ubercab.transform.CliTransform',
'X-Compile-Source-JDK': '1.7',
'X-Compile-Target-JDK': '1.7')

mainClassName = "com.ubercab.transform.CliTransform"

repositories {
jcenter()
}

dependencies {
compileOnly gradleApi()
compile deps.support.annotations
compile deps.build.androidPluginApi
compile deps.build.commonsIo
testCompile deps.test.junit
testCompile deps.test.mockito
testCompile deps.test.assertj
}

shadowJar {
baseName = 'transform-cli'
classifier = null
version = null
dependencies {
exclude(dependency("org.gradle:gradle:+"))
}
}
Loading

0 comments on commit ebcea6f

Please sign in to comment.