diff options
author | Yigit Boyar <yboyar@google.com> | 2015-10-08 17:11:14 -0700 |
---|---|---|
committer | Yigit Boyar <yboyar@google.com> | 2015-10-09 11:32:09 -0700 |
commit | 5cc6ea2e84b7c310fbb355ce76001648132a80cb (patch) | |
tree | c7c8158c67559aa8360e1f8efe001be52a40c9dd /gradlePlugin | |
parent | 09aeb26073fc8a98263806f53e44819ebe5046c6 (diff) | |
download | data-binding-5cc6ea2e84b7c310fbb355ce76001648132a80cb.tar.gz |
Allow loading older versions
This CL adds configuration to gradlePlugin build file to
force different versions on the library and baseAdapters.
This allows us to update jcenter builds w/o needing an
SDK release.
I've not moved these to command line params because it
is prebuilt and could become inconsistent if one runs
w/ command line params and then forgets them while running
tests etc. This is a process we should only use while
making one-off patches.
Change-Id: I80bc2daf6a921a8dde03a90022873a620acafd45
Diffstat (limited to 'gradlePlugin')
-rw-r--r-- | gradlePlugin/build.gradle | 15 | ||||
-rw-r--r-- | gradlePlugin/src/main/java/android/databinding/tool/DataBinderPlugin.java | 63 |
2 files changed, 64 insertions, 14 deletions
diff --git a/gradlePlugin/build.gradle b/gradlePlugin/build.gradle index 88d8c877..5469597e 100644 --- a/gradlePlugin/build.gradle +++ b/gradlePlugin/build.gradle @@ -21,10 +21,21 @@ targetCompatibility = config.javaSourceCompatibility tasks.create(name : 'copyBuildVersion') << { - def buildVersionFile = new File(sourceSets.main.output.resourcesDir,"data_binding_build_info") + def props = new Properties(); + def buildVersionFile = new File(sourceSets.main.output.resourcesDir,"data_binding_build_info.properties") buildVersionFile.delete() println "writing build version file" - buildVersionFile << project.version + props.put("myVersion", project.version) + // in case of emergency, uncomment and modify but never commit! + // props.put("library", "1.0-rc3") + // props.put("adapters", "1.0-rc3") + + def outStream = new FileOutputStream(buildVersionFile) + try { + props.store(outStream, "") + } finally { + outStream.close() + } } tasks['uploadArchives'].dependsOn('copyBuildVersion') diff --git a/gradlePlugin/src/main/java/android/databinding/tool/DataBinderPlugin.java b/gradlePlugin/src/main/java/android/databinding/tool/DataBinderPlugin.java index 7b8dae78..238e360b 100644 --- a/gradlePlugin/src/main/java/android/databinding/tool/DataBinderPlugin.java +++ b/gradlePlugin/src/main/java/android/databinding/tool/DataBinderPlugin.java @@ -58,6 +58,7 @@ import java.io.InputStream; import java.lang.reflect.Field; import java.util.Arrays; import java.util.List; +import java.util.Properties; import javax.tools.Diagnostic; import javax.xml.bind.JAXBException; @@ -125,14 +126,12 @@ public class DataBinderPlugin implements Plugin<Project> { } setupLogger(project); - String myVersion = readMyVersion(); - logD("data binding plugin version is %s", myVersion); - if (StringUtils.isEmpty(myVersion)) { - throw new IllegalStateException("cannot read version of the plugin :/"); - } + Versions versions = readMyVersion(); + logD("data binding plugin versions are: %s", versions); printEncodedErrors = resolvePrintEncodedErrors(project); ScopedException.encodeOutput(printEncodedErrors); - project.getDependencies().add("compile", "com.android.databinding:library:" + myVersion); + project.getDependencies() + .add("compile", "com.android.databinding:library:" + versions.getLibraryVersion()); boolean addAdapters = true; if (project.hasProperty("ext")) { Object ext = project.getProperties().get("ext"); @@ -145,10 +144,11 @@ public class DataBinderPlugin implements Plugin<Project> { } } if (addAdapters) { - project.getDependencies() - .add("compile", "com.android.databinding:adapters:" + myVersion); + project.getDependencies().add("compile", + "com.android.databinding:adapters:" + versions.getAdaptersVersion()); } - project.getDependencies().add("provided", "com.android.databinding:compiler:" + myVersion); + project.getDependencies().add("provided", + "com.android.databinding:compiler:" + versions.getCompilerVersion()); project.afterEvaluate(new Action<Project>() { @Override public void execute(Project project) { @@ -175,11 +175,13 @@ public class DataBinderPlugin implements Plugin<Project> { }); } - String readMyVersion() { + Versions readMyVersion() { try { - InputStream stream = getClass().getResourceAsStream("/data_binding_build_info"); + Properties props = new Properties(); + InputStream stream = getClass().getResourceAsStream("/data_binding_build_info.properties"); try { - return IOUtils.toString(stream, "utf-8").trim(); + props.load(stream); + return new Versions(props); } finally { IOUtils.closeQuietly(stream); } @@ -379,4 +381,41 @@ public class DataBinderPlugin implements Plugin<Project> { private String formatLog(String s, Object... args) { return "[data binding plugin]: " + String.format(s, args); } + + private class Versions { + + Properties properties; + String myVersion; + + public Versions(Properties properties) { + this.properties = properties; + myVersion = properties.getProperty("myVersion"); + if (myVersion == null) { + throw new IllegalStateException("cannot read data binding plugin version"); + } + } + + public String getCompilerVersion() { + return properties.getProperty("compiler", myVersion); + } + + public String getAdaptersVersion() { + return properties.getProperty("adapters", myVersion); + } + + public String getLibraryVersion() { + return properties.getProperty("library", myVersion); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("[Data Binding Versions:"); + sb.append(" plugin:").append(myVersion); + sb.append(" compiler:").append(getCompilerVersion()); + sb.append(" adapters:").append(getAdaptersVersion()); + sb.append(" library:").append(getLibraryVersion()); + return sb.append("]").toString(); + } + } } |