forked from klassm/andFHEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
206 lines (159 loc) · 6.26 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* AndFHEM - Open Source Android application to control a FHEM home automation
* server.
*
* Copyright (c) 2011, Matthias Klass or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU GENERAL PUBLIC LICENSE, as published by the Free Software Foundation.
*
* This program 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 this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
apply plugin: 'java'
apply plugin: com.smokejumperit.gradle.ExecPlugin
ext {
targetDir = new File('target')
binDir = new File('bin')
}
buildscript {
repositories {
mavenCentral()
mavenRepo url: 'http://repo.open.med.harvard.edu/nexus/content/groups/public'
mavenRepo url: 'http://repo.smokejumperit.com'
}
dependencies {
classpath 'com.smokejumperit:gradle-plugins:0.8.2'
classpath 'com.google.gdata:gdata-sites-2.0:1.40.3'
classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'
}
}
allprojects {
apply plugin: 'idea'
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: 'java'
}
task readKeystorePassword << {
def read = readFromConsole("Please enter the keystore password!")
project.ext.storePassword = read
}
task readAliasPassword << {
def read = readFromConsole("Please enter the alias password!")
project.ext.aliasPassword = read
}
task readPasswords(dependsOn: [readAliasPassword, readKeystorePassword]) << {}
def readFromConsole(notifyText) {
Console console = System.console()
console.printf("\n")
console.printf(">> " + notifyText + "\n")
return console.readPassword()
}
task uploadToGoogleSites(dependsOn: readAliasPassword) << {
uploadApkToGoogleSites();
}
task deleteBuildDirectories << {
delete 'bin', 'target'
}
task mkdirs(dependsOn: 'deleteBuildDirectories') << {
targetDir.mkdir()
binDir.mkdir()
}
task copy(type: Copy, dependsOn: 'mkdirs') {
from 'app'
into 'target'
}
task buildGoogle << {
build('GOOGLE', "google-release.apk")
}
buildGoogle.dependsOn readPasswords
buildGoogle.dependsOn copy
task buildAmazon << {
build('AMAZON', "amazon-release.apk")
}
buildAmazon.dependsOn readPasswords
buildAmazon.dependsOn copy
task buildAll(dependsOn: [buildGoogle, buildAmazon]) << {}
task release(dependsOn: [buildAll, uploadToGoogleSites])
def build(billingProvider, targetFilename) {
def storeProperty = "-Dkey.store.password=" + project.storePassword
def aliasProperty = "-Dkey.alias.password=" + project.aliasPassword
project.execIn(new File('.'), "cp", "target/src/li/klass/fhem/application.properties", 'target/src/li/klass/fhem/application.properties.temp')
def propertiesFile = new File('target/src/li/klass/fhem/application.properties')
def content = propertiesFile.getText('UTF-8').replaceAll("<BILLING.PROVIDER>", billingProvider)
propertiesFile.write(content, 'UTF-8')
project.execIn(new File('target'), "ant", "release", storeProperty, aliasProperty)
def targetPath = "bin/" + targetFilename
project.execIn(new File('.'), "mv", "target/bin/andFHEM-release.apk", targetPath)
// write back the old placeholder value!
project.execIn(new File('.'), "mv", "target/src/li/klass/fhem/application.properties.temp", 'target/src/li/klass/fhem/application.properties')
}
build.dependsOn(release)
/*************************************
* GOOGLE SITES
*********************************** */
import com.google.gdata.client.*;
import com.google.gdata.client.sites.*;
import com.google.gdata.data.*;
import com.google.gdata.data.acl.*;
import com.google.gdata.data.media.*;
import com.google.gdata.data.sites.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;
import com.google.gdata.client.sites.SitesService
import com.google.gdata.data.Link.*
import javax.activation.MimetypesFileTypeMap
def uploadApkToGoogleSites() {
def attachmentContentFeedUrl = "https://sites.google.com/feeds/content/site/andfhem/"
def service = new SitesService("li.klass-andFHEM-v1");
service.setUserCredentials("[email protected]", '' + project.aliasPassword);
def contentFeed = service.getFeed(new URL(attachmentContentFeedUrl), ContentFeed.class)
def entries = contentFeed.getEntries()
for (e in entries) {
def href = e.getRevisionLink().getHref()
def id = href.substring(href.lastIndexOf("/") + 1)
def fileTitle = e.getTitle().getText()
if (fileTitle.equals("google-release.apk")) {
deleteGoogleSitesAttachment(service, id)
}
}
updateGoogleSitesAPK(service)
}
def deleteGoogleSitesAttachment(service, id) {
def attachment = service.getEntry(new URL("https://sites.google.com/feeds/content/site/andfhem/" + id + "?with-mappings=true"), FileCabinetPageEntry.class)
attachment.delete();
}
def updateGoogleSitesAPK(service) {
def title = "google-release.apk"
def description = ""
def mediaTypes = new MimetypesFileTypeMap()
mediaTypes.addMimeTypes("application/vnd.android.package-archive")
def file = new File("bin/google-release.apk")
def newAttachment = new AttachmentEntry();
newAttachment.setMediaSource(new MediaFileSource(file, mediaTypes.getContentType(file)));
newAttachment.setTitle(new PlainTextConstruct(title));
newAttachment.setSummary(new PlainTextConstruct(description));
service.insert(new URL("https://sites.google.com/feeds/content/site/andfhem/"), newAttachment);
}
/*************************************
* IDEA
*********************************** */
idea.project.ipr {
withXml { provider ->
provider.node.component.find { it.@name == 'VcsDirectoryMappings' }.mapping.@vcs = 'Git'
}
}