-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
164 lines (146 loc) · 4.73 KB
/
build.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
160
161
162
163
164
import java.util.concurrent.*
import java.util.zip.ZipFile
interface EmojiConstants {
def emojiVersion = '12.1'
def TWEMOJI_VERSION = '12.1.4'
def twemojiBaseUrl = "https://twemoji.maxcdn.com/v/$TWEMOJI_VERSION/svg/"
def emojiListUrl = "http://unicode.org/Public/emoji/$emojiVersion/emoji-test.txt"
def HEX_CODEPOINT_END_POSITION = 43
def STATUS_END_POSITION = 65
def EMOJI_POSITION = 67
}
class EmojiDownloader implements EmojiConstants{
File emojiListFile
File emojiDir
EmojiDownloader(File emojiRootDir) {
this.emojiDir = new File(emojiRootDir, 'resources/images/emoji')
this.emojiDir.mkdirs()
this.emojiListFile = new File(emojiRootDir, 'resources/txt/emojilist.txt')
}
def downloadEmojiList(){
if (!emojiListFile.exists()) {
emojiListFile.parentFile.mkdirs()
new URL(emojiListUrl).withInputStream{ i -> emojiListFile.withOutputStream{ it << i }}
}
return this
}
def downloadEmojiFiles(){
ExecutorService exec = Executors.newFixedThreadPool(40)
emojiListFile.eachLine('UTF-8') { String line ->
if(line.length() > EMOJI_POSITION && line.charAt(HEX_CODEPOINT_END_POSITION) == ';' && line.charAt(STATUS_END_POSITION) == '#') {
String emojiStatus = line.substring(HEX_CODEPOINT_END_POSITION + 1, STATUS_END_POSITION).trim()
if(emojiStatus != 'component') {
String hexCodes = line.substring(0, HEX_CODEPOINT_END_POSITION).trim()
String twemojiFileName = hexCodes.toLowerCase().replace(' ', '-').replaceFirst("^00", "") + '.svg';
String emojiUrl = "$twemojiBaseUrl$twemojiFileName"
def emojiFile = new File(emojiDir, twemojiFileName)
if (!emojiFile.exists()) {
exec.submit({
def get = new URL(emojiUrl).openConnection();
def getRC = get.getResponseCode();
if(getRC.equals(200)) {
emojiFile.withOutputStream{
try {
new BufferedOutputStream(it) << new BufferedInputStream(get.getInputStream())
}
catch(Exception e){
new BufferedOutputStream(it) << new BufferedInputStream(new URL(emojiUrl).openConnection().getInputStream())
}
}
}
} as Runnable)
}
}
}
}
exec.shutdown()
if(! exec.isTerminated()) {
println('Wait for downloads')
exec.awaitTermination(3600, TimeUnit.SECONDS);
}
println('Downloads completed')
return this
}
}
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'signing'
group 'org.freeplane.emoji'
version = EmojiConstants.TWEMOJI_VERSION
task downloadEmoji {
outputs.dir("${project.buildDir}/emoji/resources")
doLast {
def downloader = new EmojiDownloader(file("$buildDir/emoji"))
downloader.downloadEmojiList()
if (! downloader.emojiDir.isDirectory() || downloader.emojiDir.list().length == 0) {
downloader.downloadEmojiFiles()
}
}
}
jar {
dependsOn downloadEmoji
manifest = project.manifest {
attributes("Manifest-Version": "1.0")
}
archiveBaseName = 'twemoji'
archiveVersion = EmojiDownloader.TWEMOJI_VERSION
from (files("${project.buildDir}/emoji/resources"))
from (files("src/resources"))
}
publishing {
publications {
maven(MavenPublication) {
artifactId 'twemoji'
groupId = project.group
version = project.version
artifact jar
pom {
name = project.name
description = 'Emoji package'
url = 'https://github.com/freeplane/emoji'
scm {
url = 'https://github.com/freeplane/emoji'
connection = 'scm:git:https://github.com/freeplane/emoji.git'
developerConnection = 'scm:git:git@github.com:freeplane/emoji.git'
}
licenses {
license {
name = 'CC-BY 4.0'
url = 'https://creativecommons.org/licenses/by/4.0/'
}
}
developers {
developer {
id = 'twitter'
name = 'Twitter, Inc and other contributors'
}
developer {
id = 'dpolivaev'
name = 'Dimitry Polivaev'
email = 'dpolivaev@gmx.de'
}
}
}
}
}
repositories {
maven {
url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
credentials {
username ossrhUsername
password ossrhPassword
}
}
maven {
url = "${project.gradle.gradleUserHomeDir}/local-artifacts"
}
}
}
signing {
sign publishing.publications.maven
}
javadoc {
enabled = true
options.encoding = "UTF-8"
failOnError = false
}