From 37ad8effcd80b9aa199959ffced70fbda1860744 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Mon, 7 Jan 2019 16:00:05 +0300 Subject: [PATCH] markwon-bundle gradle script --- app/build.gradle | 9 ++++++- build.gradle | 1 - markwon-bundle.gradle | 59 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 markwon-bundle.gradle diff --git a/app/build.gradle b/app/build.gradle index 51dd6d43..88169fb2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.application' +apply from: '../markwon-bundle.gradle' android { @@ -26,6 +27,12 @@ android { } } +ext.markwon = [ + 'version': '3.0.0-SNAPSHOT', + 'includeAll': true, + 'exclude': ['ext-latex', 'core'] +] + dependencies { implementation project(':markwon-core') @@ -48,4 +55,4 @@ dependencies { annotationProcessor it['prism4j-bundler'] annotationProcessor it['dagger-compiler'] } -} +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 66ba2c0f..c1df183c 100644 --- a/build.gradle +++ b/build.gradle @@ -85,7 +85,6 @@ ext { 'junit' : 'junit:junit:4.12', 'robolectric': 'org.robolectric:robolectric:3.8', 'ix-java' : 'com.github.akarnokd:ixjava:1.0.0', - 'gson' : 'com.google.code.gson:gson:2.8.5', 'commons-io' : 'commons-io:commons-io:2.6', 'mockito' : 'org.mockito:mockito-core:2.21.0' ] diff --git a/markwon-bundle.gradle b/markwon-bundle.gradle new file mode 100644 index 00000000..603404d6 --- /dev/null +++ b/markwon-bundle.gradle @@ -0,0 +1,59 @@ +// await project initialization and check for markwon object then +// (so we do not have to force users to put `apply from` block at the bottom +// of a build.gradle file) +project.afterEvaluate { + + if (!project.hasProperty('markwon')) { + throw new RuntimeException("No `markwon` property object is found. " + + "Define it with `ext.markwon = [prop: value]`") + } + + final def markwon = project.markwon + if (!(markwon instanceof Map)) { + throw new RuntimeException("`markwon` object property must be of type Map. " + + "Groovy short-hand to define: `[:]`.") + } + + final def version = markwon.version + final def includeAll = markwon.computeIfAbsent('includeAll', { false }) + final def artifacts + if (includeAll) { + + // cannot exclude core + final def exclude = markwon.computeIfAbsent('exclude', { [] }) \ + .unique() \ + .findAll { 'core' != it } + + artifacts = [ + 'core', + 'ext-latex', + 'ext-strikethrough', + 'ext-tables', + 'ext-tasklist', + 'html', + 'image-gif', + 'image-okhttp', + 'image-svg', + 'recycler', + 'syntax-highlight' + ].findAll { !exclude.contains(it) } + + } else { + artifacts = (markwon.containsKey('artifacts') ? markwon.artifacts : ['core']).with { + // add implicit core artifact + if (!it.contains('core')) { + it.add('core') + } + return it + } + } + + if (!version) { + throw new RuntimeException("Please specify version of Markwon, for example: " + + "`ext.markwon = [ 'version': '1.0.0']`") + } + + artifacts.forEach { + project.dependencies.add('implementation', "ru.noties.markwon:$it:$version") + } +} \ No newline at end of file