forked from nhaarman/ListViewAnimations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
87 lines (73 loc) · 2.62 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
import java.util.regex.Pattern
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
def isReleaseBuild() {
println version
return version.contains("SNAPSHOT") == false
}
allprojects {
group = 'com.nhaarman.listviewanimations'
version = VERSION_NAME
repositories {
mavenCentral()
}
tasks.withType(Compile) {
options.encoding = 'UTF-8'
}
}
task('increaseVersionCode') << {
def files = new File[2];
files[0] = file("library/AndroidManifest.xml")
files[1] = file("example/AndroidManifest.xml")
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
for (int i = 0; i < files.length; ++i) {
def manifestText = files[i].getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def currentVersionCode = Long.parseLong(matcher.group(1));
def versionCode = Long.parseLong(new Date().format('yyyyMMdd') + "1")
while (versionCode <= currentVersionCode) {
++versionCode
}
println(versionCode)
def manifestContent = matcher.replaceAll("versionCode=\"" + versionCode + "\"")
files[i].write(manifestContent)
}
}
task('syncVersionName') << {
def manifestFiles = new File[2];
manifestFiles[0] = file("library/AndroidManifest.xml")
manifestFiles[1] = file("example/AndroidManifest.xml")
def pattern = Pattern.compile("versionName=\"(.+)\"")
for (int i = 0; i < manifestFiles.length; ++i) {
def manifestText = manifestFiles[i].getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def manifestContent = matcher.replaceAll("versionName=\"" + version + "\"")
manifestFiles[i].write(manifestContent)
}
def readmeFile = file("README.md")
def readmeText = readmeFile.getText()
def matcher = pattern.matcher(readmeText)
matcher.find()
def previousVersion = matcher.group(1)
def readmeContent = readmeText.replaceAll(previousVersion, version)
pattern = Pattern.compile("repostart -->(.+)<!-- repoend", Pattern.DOTALL)
matcher = pattern.matcher(readmeContent)
matcher.find()
def repo = isReleaseBuild() ? "\n\t\t" : "\n\t\tmaven {\n\t\t\turl \"https://oss.sonatype.org/content/repositories/snapshots\"\n\t\t}\n\t\t";
readmeContent = matcher.replaceAll("repostart -->" + repo + "<!-- repoend")
readmeFile.write(readmeContent)
}
tasks.whenTaskAdded { task ->
if (task.name == 'generateReleaseBuildConfig') {
task.dependsOn 'increaseVersionCode'
}
}
apply plugin: 'android-reporting'