-
Notifications
You must be signed in to change notification settings - Fork 5
/
dokka.gradle
159 lines (149 loc) · 7.69 KB
/
dokka.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright 2018 Vorlonsoft LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* <p>EasyDokkaPlugin Gradle Script plugin</p>
* <p>Plugin to generate documentation by Dokka documentation engine
* in Javadoc or other formats for Java, Kotlin, Android and non-Android
* projects. It's very easy, you don't need to add to dependencies
* section additional classpath or think about compatibility issues,
* you don't need additional repositories also.</p>
*
* @since 1.0.0 Tokyo
* @version 1.1.0 Yokohama
* @author Alexander Savin
*/
Class EasyDokka = new GroovyClassLoader(getClass().getClassLoader()).parseClass(EasyDokkaInitializer.downloadGroovyClass('https://raw.github.com/Vorlonsoft/EasyDokkaPlugin/master/EasyDokka.groovy', 'EasyDokka.groovy'))
Class EasyDokkaUtils = new GroovyClassLoader(getClass().getClassLoader()).parseClass(EasyDokkaInitializer.downloadGroovyClass('https://raw.github.com/Vorlonsoft/EasyDokkaPlugin/master/EasyDokkaUtils.groovy', 'EasyDokkaUtils.groovy'))
afterEvaluate { project ->
final boolean androidOs = EasyDokkaUtils.with(project).isAndroid()
final boolean kotlinLanguage = EasyDokkaUtils.with(project).isKotlin()
final String dokkaFatJarVersion = EasyDokka.with(project).getDokkaFatJarVersion()
final String dokkaFatJarPath = 'org/jetbrains/dokka/dokka-fatjar'
final String dokkaOutputFormat = EasyDokka.with(project).getDokkaOutputFormat()
final String javaAPISpecificationLink = EasyDokkaUtils.getJavaAPISpecificationLink(JavaVersion.current().toString())
task easyDokkaInitializer {
EasyDokkaUtils.downloadLib("https://jcenter.bintray.com/${dokkaFatJarPath}/${dokkaFatJarVersion}/dokka-fatjar-${dokkaFatJarVersion}.pom",
dokkaFatJarPath, dokkaFatJarVersion, "dokka-fatjar-${dokkaFatJarVersion}.pom")
EasyDokkaUtils.downloadLib("https://jcenter.bintray.com/${dokkaFatJarPath}/${dokkaFatJarVersion}/dokka-fatjar-${dokkaFatJarVersion}.jar",
dokkaFatJarPath, dokkaFatJarVersion, "dokka-fatjar-${dokkaFatJarVersion}.jar")
}
task dokkaJavadocsJar(type: GradleBuild) {
description 'Generates the documentation by Dokka in Javadoc or other formats.'
tasks = ['clean', 'easyDokkaJar']
}
task easyDokka(type: Exec, dependsOn: easyDokkaInitializer) {
description 'Generates the documentation by Dokka.'
final byte srcDirsJavaNumber
final byte srcDirsKotlinNumber
final byte classpathNumber
final String classpath
final String srcDirOne
final String srcDirTwo
final String srcDirThree
String links
if (androidOs) {
srcDirsJavaNumber = (byte) ((android.sourceSets.main.java.srcDirs != null) ? android.sourceSets.main.java.srcDirs.size() : 0)
srcDirsKotlinNumber = (byte) ((kotlinLanguage && (android.sourceSets.main.kotlin.srcDirs != null)) ? android.sourceSets.main.kotlin.srcDirs.size() : 0)
classpathNumber = (byte) ((android.getBootClasspath() != null) ? android.getBootClasspath().size() : 0)
classpath = (classpathNumber > 0) ? android.getBootClasspath()[0] : ''
srcDirOne = (srcDirsJavaNumber > 0) ? android.sourceSets.main.java.srcDirs[0] : ''
srcDirTwo = (srcDirsJavaNumber > 1) ? android.sourceSets.main.java.srcDirs[1] : ''
srcDirThree = (srcDirsKotlinNumber > 0) ? android.sourceSets.main.kotlin.srcDirs[0] : ''
links = 'https://developer.android.com/reference/^https://developer.android.com/reference/package-list^^' +
"file:///${android.sdkDirectory}/docs/reference/^file:///${android.sdkDirectory}/docs/reference/package-list^^" +
"${javaAPISpecificationLink}^${javaAPISpecificationLink}"
if (javaAPISpecificationLink == 'https://docs.oracle.com/javase/10/docs/api/') {
links += 'element-list'
} else {
links += 'package-list'
}
if (srcDirsJavaNumber > 0) {
mkdir android.sourceSets.main.java.srcDirs[0]
if (srcDirsJavaNumber > 1) {
mkdir android.sourceSets.main.java.srcDirs[1]
}
}
if (srcDirsKotlinNumber > 0) {
mkdir android.sourceSets.main.kotlin.srcDirs[0]
}
} else {
srcDirsJavaNumber = (byte) ((sourceSets.main.java.srcDirs != null) ? sourceSets.main.java.srcDirs.size() : 0)
srcDirsKotlinNumber = (byte) ((kotlinLanguage && (sourceSets.main.kotlin.srcDirs != null)) ? sourceSets.main.kotlin.srcDirs.size() : 0)
classpathNumber = 0
classpath = ''
srcDirOne = (srcDirsJavaNumber > 0) ? sourceSets.main.java.srcDirs[0] : ''
srcDirTwo = (srcDirsJavaNumber > 1) ? sourceSets.main.java.srcDirs[1] : ''
srcDirThree = (srcDirsKotlinNumber > 0) ? sourceSets.main.kotlin.srcDirs[0] : ''
links = javaAPISpecificationLink
if (srcDirsJavaNumber > 0) {
mkdir sourceSets.main.java.srcDirs[0]
if (srcDirsJavaNumber > 1) {
mkdir sourceSets.main.java.srcDirs[1]
}
}
if (srcDirsKotlinNumber > 0) {
mkdir sourceSets.main.kotlin.srcDirs[0]
}
}
if (srcDirsJavaNumber + srcDirsKotlinNumber > 0) {
commandLine 'java', '-jar',
"${System.properties['user.home']}/.m2/repository/${dokkaFatJarPath}/${dokkaFatJarVersion}/dokka-fatjar-${dokkaFatJarVersion}.jar",
srcDirOne, srcDirTwo, srcDirThree, '-output', "${buildDir}/${dokkaOutputFormat}", '-format', dokkaOutputFormat, '-links', links,
(classpathNumber > 0) ? '-classpath' : '', (classpathNumber > 0) ? classpath : ''
} else {
commandLine 'java', '-jar',
"${System.properties['user.home']}/.m2/repository/${dokkaFatJarPath}/${dokkaFatJarVersion}/dokka-fatjar-${dokkaFatJarVersion}.jar"
}
}
task easyDokkaJar(type: Jar, dependsOn: easyDokka) {
description 'Archives the documentation created by Dokka.'
classifier = dokkaOutputFormat
destinationDir = buildDir
from "${buildDir}/${dokkaOutputFormat}"
}
}
/**
* <p>EasyDokkaInitializer Class - class with EasyDokkaPlugin Gradle Script plugin initializers.</p>
*
* @since 1.1.0 Yokohama
* @version 1.1.0 Yokohama
* @author Alexander Savin
*/
final class EasyDokkaInitializer {
private EasyDokkaInitializer() {
throw new AssertionError()
}
/**
* Downloads Groovy Class source file
*
* @param url Groovy Class source file url
* @param name Groovy Class source file local repository name
* @return Groovy Class source file
*/
static File downloadGroovyClass(String url, String name) {
File file = new File("${System.properties['user.home']}/.m2/repository/com/vorlonsoft/EasyDokkaPlugin/${name}")
file.parentFile.mkdirs()
if (file.exists()) {
file.delete()
}
new URL(url).withInputStream { downloadStream ->
file.withOutputStream { fileOutputStream ->
fileOutputStream << downloadStream
}
}
return file
}
}