-
Notifications
You must be signed in to change notification settings - Fork 88
/
desktop.gradle
162 lines (133 loc) · 5.4 KB
/
desktop.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
/*
* Copyright 2015, 2016 Ether.Camp Inc. (US)
* This file is part of Ethereum Harmony.
*
* Ethereum Harmony is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Ethereum Harmony is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Ethereum Harmony. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Tasks:
* - desktop
* - githubRelease
*/
apply plugin: 'co.riiid.gradle' // upload to github releases
project.ext.productName = "EthereumHarmony"
project.ext.versionNameValue = "2.3";
project.ext.buildNumberFilePath = System.getProperty('user.home') + "/harmony.desktop.number.properties"
// Build number is zero for debug or incremented for release
project.ext.buildNumber = 0;
// pass via -PgithubToken=1234567890
def githubAccessToken = project.hasProperty('githubToken') ? project.property('githubToken') : System.getenv('githubToken')
// Increase version code if releasing binaries for QA or Production
if (project.gradle.startParameter.taskNames.indexOf('desktop') > -1) {
buildNumber = getNextBuildNumber()
}
// Check github token presence
if (project.gradle.startParameter.taskNames.indexOf('githubRelease') > -1) {
if (!githubAccessToken) {
throw new RuntimeException("Please set github access token via -PgithubToken=1234567890")
}
buildNumber = getCurrentBuildNumber()
println("Using github token " + githubAccessToken.substring(0, 6) + "...")
}
github {
baseUrl = "https://api.github.com"
owner = "ether-camp"
repo = "ethereum-harmony"
token = "$githubAccessToken"
tagName = "v${versionNameValue}b${buildNumber}"
name = "${productName} $versionNameValue Build $buildNumber"
draft = true
body = """
# Implemented:
...
"""
assets = getBinFileNames()
}
/**
* Create installers.
* Note: license must be set either in env variable or passed via `-PINSTALL4J_LICENSE=AAAAAAA`
*/
task desktop() {
doLast {
String license = project.hasProperty('INSTALL4J_LICENSE') ? project.property('INSTALL4J_LICENSE') : System.getenv('INSTALL4J_LICENSE')
if (license == null) {
throw new GradleException('License must be provided') // or remove it from command line
}
task unpackJar(type: Exec) {
workingDir "build/libs"
commandLine "jar", "xf", "harmony.ether.camp.jar"
}
// ** Workaround for Windows installer **
// Ages ago at MS-DOS days, Microsoft defined a short list of reserved words that cannot be used as first part of a filename.
// That list still lasts now with Windows 10 and it includes: NUL, CON, PRN, AUX, COM1, COM2, COM3, COM4, COM5, COM6, COM7,
// COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9.
// Datamaps source code cointains files named like nul.json, nul.topo.json, and so on, so when the installer tries to extract
// those files it fails with a "Could not create this file" error. To fix this we remove the whole src/ folder containing
// the offending files.
task cleanUpDatamaps(type: Delete) {
delete "./build/libs/BOOT-INF/classes/static/bower_components/datamaps/src/"
}
task createInstaller(type: Exec) {
workingDir "."
commandLine "install4jc", "--license", license, "EthereumHarmony.install4j", "-r", (versionNameValue + '.' + buildNumber)
}
unpackJar.execute();
cleanUpDatamaps.execute();
createInstaller.execute();
// rename to proper pattern
final versionNormal = "${versionNameValue}.${buildNumber}"
final versionUnderscored = versionNormal.replaceAll("\\.", "_")
getBinFileNames().each {
final String to = it;
final String from = to.replace(versionNormal, versionUnderscored)
new File(from).renameTo(new File(to))
}
}
}
desktop.dependsOn bootRepackage
def getBinFileNames() {
return ["build/${productName}-macos-${versionNameValue}.${buildNumber}.dmg",
"build/${productName}-windows-x64-${versionNameValue}.${buildNumber}.exe"]
}
def getNextBuildNumber() {
String key = 'build.number'
def props = new Properties()
int result = 0
File file = file(buildNumberFilePath)
if (file.exists()) {
file.withInputStream { props.load(it) }
if (props) {
result = Integer.parseInt(props[key]) + 1
}
}
ant.propertyfile(file: buildNumberFilePath) {
entry(key: key, value: result)
}
println('Next build number is ' + result + ' from ' + buildNumberFilePath)
return result
}
def getCurrentBuildNumber() {
String key = 'build.number'
def props = new Properties()
int buildNumber = 0
File file = file(buildNumberFilePath)
if (file.exists()) {
file.withInputStream { props.load(it) }
if (props) {
buildNumber = Integer.parseInt(props[key])
}
}
println('Current build number is ' + buildNumber + ' from ' + buildNumberFilePath)
return buildNumber
}