forked from multi-os-engine/moe-natjgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
175 lines (153 loc) · 5.72 KB
/
build.gradle
File metadata and controls
175 lines (153 loc) · 5.72 KB
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
/*
Copyright 2014-2016 Intel Corporation
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
http://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.
*/
apply plugin: 'idea'
apply plugin: 'eclipse'
allprojects { subproject ->
String customRepo = System.getenv("MOE_MAVEN_ADDR")
if ((customRepo == null) || (customRepo.length() == 0)) {
customRepo = System.getenv("MOE_HOME")
}
if ((customRepo != null) && (customRepo.length() > 0)) {
subproject.repositories {
maven {
url(customRepo)
}
}
}
subproject.afterEvaluate {
// Lookup publish task
Task publishTask
try {
publishTask = subproject.tasks.getByName('publish')
} catch (UnknownTaskException ex) {
return
}
def versionDict = subproject.ext.moeVersion
// Do a sanity check right before the publish task!
// DO NOT SKIP!
def sanityCheck = subproject.tasks.create("publishSanityCheck") << {
def v = subproject.publishing.publications.mavenJava.version
if (v != moeGetVersion(subproject)) {
throw new GradleException("Resolved version is illegal!")
}
}
subproject.tasks.getByName('jar').dependsOn sanityCheck
// Set mode: dev or release
boolean hasQualifier = project.hasProperty("moe.publish.qualifier")
versionDict['dev'] = !hasQualifier
if (hasQualifier) {
String qual = project.property("moe.publish.qualifier")
if ("alpha".equals(qual) || "final".equals(qual)) {
versionDict['qualifier'] = qual
} else {
throw new GradleException("Unknown qualifier: '$qual'")
}
// Update build number
def projectName = subproject.ext.moeProject
def buildNumberEnv = "${projectName}_BUILD_NUMBER"
def buildNumberVal = System.getenv(buildNumberEnv)
if (buildNumberVal != null) {
versionDict['build'] = Integer.parseInt(buildNumberVal)
} else {
// Add dummy target repo
subproject.publishing.repositories {
maven {
url('/invalid directory')
}
}
return
}
}
// Update version number
subproject.publishing.publications.mavenJava.version = moeGetVersion(subproject)
// Update publish repository
subproject.publishing.repositories {
if (versionDict['dev'] == Boolean.TRUE) {
mavenLocal()
} else {
if (versionDict['qualifier'] == null) {
throw new GradleException("Unexpected state")
} else {
String mvnAddr = getRequiredEnv('PUBLISH_TARGET_REPO_ADDR')
String mvnUser = getRequiredEnv('PUBLISH_TARGET_REPO_USER')
String mvnPass = getRequiredEnv('PUBLISH_TARGET_REPO_PASS')
maven {
url mvnAddr
if (mvnUser.length() > 0) {
credentials {
username = mvnUser
password = mvnPass
}
}
}
}
}
}
}
}
def getRequiredEnv(name) {
String env = System.getenv(name)
if (env == null) {
throw new GradleException("Env $name is not set")
}
return env
}
def initMOEProject(project, versionComponents) {
if (project == null) {
throw new NullPointerException("Project cannot be null")
}
if (versionComponents == null) {
throw new NullPointerException("Version components cannot be null")
}
if (!(versionComponents instanceof Map)) {
throw new NullPointerException("Version components must be a map")
}
def versionDict = project.ext.moeVersion
// Set major version
def vComp = versionComponents.vMajor
if (vComp == null) {
throw new NullPointerException("vMajor is not defined!")
}
versionDict['major'] = vComp
// Set minor version
vComp = versionComponents.vMinor
if (vComp == null) {
throw new NullPointerException("vMinor is not defined!")
}
versionDict['minor'] = vComp
// Set patch version
vComp = versionComponents.vPatch
if (vComp == null) {
throw new NullPointerException("vPatch is not defined!")
}
versionDict['patch'] = vComp
}
def moeGetVersion(project) {
def v = project.ext.moeVersion
if (v['dev'] == Boolean.TRUE) {
return "${v['major']}.${v['minor']}.${v['patch']}.dev-SNAPSHOT"
} else {
def q = v['qualifier']
if (q != null) {
if (v['build'] == null) {
def projectName = project.ext.moeProject
def buildNumberEnv = "${projectName}_BUILD_NUMBER"
throw new GradleException("Builds with qualifiers MUST have a build number!"
+ " Env $buildNumberEnv is not set!")
}
return "${v['major']}.${v['minor']}.${v['patch']}.${q}-${v['build']}"
} else {
throw new GradleException('Non-dev builds MUST have a qualifier')
}
}
}