diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2016-04-13 21:12:51 +0200 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2016-04-13 21:12:51 +0200 |
commit | 6ce0bdf71e76a14e6aedd44cb3987185816fc642 (patch) | |
tree | d5d60b8845b52cf41ec913ffcfe185b4fed09594 /core | |
parent | 68318a6e3960ffb965b77ca66e9e28ad6ea06442 (diff) | |
download | dokka-6ce0bdf71e76a14e6aedd44cb3987185816fc642.tar.gz dokka-6ce0bdf71e76a14e6aedd44cb3987185816fc642.tar.bz2 dokka-6ce0bdf71e76a14e6aedd44cb3987185816fc642.zip |
Shade Dokka's dependencies in fatjar. Resolves #46
Diffstat (limited to 'core')
-rw-r--r-- | core/build.gradle | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/core/build.gradle b/core/build.gradle index 42fa30e1..22fe2668 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,3 +1,9 @@ +import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator +import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer +import groovy.xml.XmlUtil +import org.apache.tools.zip.ZipEntry +import org.apache.tools.zip.ZipOutputStream + import javax.tools.ToolProvider group 'org.jetbrains.dokka' @@ -6,7 +12,7 @@ version dokka_version buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2' + classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3' } repositories { jcenter() @@ -76,6 +82,60 @@ jar { } } +class PluginXmlTransformer implements com.github.jengelman.gradle.plugins.shadow.transformers.Transformer { + private Map<String, Node> transformedPluginXmlFiles = new HashMap<>(); + + @Override + boolean canTransformResource(FileTreeElement fileTreeElement) { + return fileTreeElement.relativePath.segments.contains("META-INF") && fileTreeElement.name.endsWith(".xml") + } + + @Override + void transform(String path, InputStream inputStream, List<Relocator> relocators) { + Node node = new XmlParser().parse(inputStream) + relocateXml(node, relocators) + transformedPluginXmlFiles.put(path, node) + } + + @Override + boolean hasTransformedResource() { + return !transformedPluginXmlFiles.isEmpty() + } + + @Override + void modifyOutputStream(ZipOutputStream zipOutputStream) { + for (Map.Entry<String, Node> entry : transformedPluginXmlFiles.entrySet()) { + zipOutputStream.putNextEntry(new ZipEntry(entry.key)) + XmlUtil.serialize(entry.value, zipOutputStream) + } + } + + private static void relocateXml(Node node, List<Relocator> relocators) { + Map attributes = node.attributes() + for (Map.Entry entry : attributes.entrySet()) { + entry.setValue(relocateClassName((String) entry.getValue(), relocators)) + } + List<String> localText = node.localText() + if (localText.size() == 1) { + node.setValue(relocateClassName(localText[0], relocators)) + } + node.children().each { + if (it instanceof Node) { + relocateXml((Node) it, relocators) + } + } + } + + private static String relocateClassName(String className, List<Relocator> relocators) { + for (Relocator relocator : relocators) { + if (relocator.canRelocateClass(className)) { + return relocator.relocateClass(className) + } + } + return className + } +} + shadowJar { baseName = 'dokka-fatjar' classifier = '' @@ -83,6 +143,20 @@ shadowJar { dependencies { exclude(dependency('org.apache.ant:ant:1.9.6')) } + + relocate 'com', 'dokkacom' + relocate('org', 'dokkaorg') { + exclude 'org.jetbrains.dokka.**' + exclude 'org.xml.**' + } + + transform(ServiceFileTransformer) + transform(PluginXmlTransformer) + + exclude 'colorScheme/**' + exclude 'fileTemplates/**' + exclude 'inspectionDescriptions/**' + exclude 'intentionDescriptions/**' } publishing { |