-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathEasyDokkaUtils.groovy
134 lines (124 loc) · 4.58 KB
/
EasyDokkaUtils.groovy
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
/*
* 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>EasyDokkaUtils Class - utility class, thread-safe and a fast singleton
* implementation.</p>
*
* @since 1.1.0 Yokohama
* @version 1.1.0 Yokohama
* @author Alexander Savin
*/
final class EasyDokkaUtils {
private static volatile EasyDokkaUtils singleton = null
private final def project
private EasyDokkaUtils(project) {
this.project = project
}
/**
* Only method to get singleton object of EasyDokkaUtils Class
*
* @param project project
* @return thread-safe singleton
*/
static EasyDokkaUtils with(project) {
if (singleton == null) {
synchronized (EasyDokkaUtils.class) {
if (singleton == null) {
singleton = new EasyDokkaUtils(project)
}
}
}
return singleton
}
/**
* Downloads library and puts it to local repository.
*
* @param url library url
* @param path local repository path
* @param version library version
* @param name local repository file name
*/
static void downloadLib(String url, String path, String version, String name) {
File file = new File("${System.properties['user.home']}/.m2/repository/${path}/${version}/${name}")
file.parentFile.mkdirs()
if (!file.exists()) {
new URL(url).withInputStream { downloadStream ->
file.withOutputStream { fileOutputStream ->
fileOutputStream << downloadStream
}
}
}
}
/**
* Returns Java API specification link.
*
* @param currentJavaVersion current Java version
* @return Java API specification link
*/
static String getJavaAPISpecificationLink(String currentJavaVersion) {
switch (currentJavaVersion) {
case '1.5':
return 'https://docs.oracle.com/javase/1.5.0/docs/api/'
case '1.6':
return 'https://docs.oracle.com/javase/6/docs/api/'
case '1.7':
return 'https://docs.oracle.com/javase/7/docs/api/'
case '1.8':
return 'https://docs.oracle.com/javase/8/docs/api/'
case '1.9':
return 'https://docs.oracle.com/javase/9/docs/api/'
case '1.10':
case '11':
case '12':
case '13':
case '14':
return 'https://docs.oracle.com/javase/10/docs/api/'
default:
return ''
}
}
/**
* Checks Android or non-Android project.
*
* @return true if Android project, false otherwise
*/
boolean isAndroid() {
return project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library') ||
project.getPlugins().hasPlugin('com.android.feature') ||
project.getPlugins().hasPlugin('com.android.dynamic-feature') ||
project.getPlugins().hasPlugin('com.android.instantapp') ||
project.getPlugins().hasPlugin('android') ||
project.getPlugins().hasPlugin('android-library')
}
/**
* Checks Kotlin or non-Kotlin project.
*
* @return true if Kotlin project, false otherwise
*/
boolean isKotlin() {
return project.getPlugins().hasPlugin('kotlin') ||
project.getPlugins().hasPlugin('kotlin-platform-common') ||
project.getPlugins().hasPlugin('kotlin-platform-jvm') ||
project.getPlugins().hasPlugin('kotlin-platform-js') ||
project.getPlugins().hasPlugin('org.jetbrains.kotlin') ||
project.getPlugins().hasPlugin('org.jetbrains.kotlin.jvm') ||
project.getPlugins().hasPlugin('org.jetbrains.kotlin.js') ||
project.getPlugins().hasPlugin('kotlin2js') ||
project.getPlugins().hasPlugin('kotlin-android') ||
project.getPlugins().hasPlugin('kotlin-android-extensions')
}
}