-
Notifications
You must be signed in to change notification settings - Fork 42
/
build.gradle
214 lines (182 loc) · 6.1 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
207
208
209
210
211
212
213
214
group 'com.mbeddr.'
apply plugin: 'base'
buildDir 'gradle/build'
// Project version
if (project.hasProperty('projectVersion')) {
version project.projectVersion
} else {
def gitBranchCmd
if (System.getProperty('os.name').toLowerCase().contains('windows')) {
gitBranchCmd = 'cmd /c git rev-parse --abbrev-ref HEAD'
} else {
gitBranchCmd = 'git rev-parse --abbrev-ref HEAD'
}
def gitBranch = gitBranchCmd.execute().in.text.trim().toString().replace("/","-")
if (gitBranch == null || gitBranch.empty) {
gitBranch = 'HEAD'
}
version "0.1-$gitBranch-SNAPSHOT"
}
// Dependency versions
ext.mpsVersion = '3.4.3'
ext.mbeddrVersion = 'maintenance-mps34.1.0.17905.d048a69'
// Default repository credentials
if (!project.hasProperty('nexusUsername')) {
ext.nexusUsername = ''
ext.nexusPassword = ''
}
logger.info 'Repository username: {}', project.nexusUsername
ext.releaseRepository = ''
ext.snapshotRepository = ''
ext.publishingRepository = version.toString().endsWith("-SNAPSHOT") ? snapshotRepository : releaseRepository
ext.dependencyRepositories = [
'https://projects.itemis.de/nexus/content/repositories/mbeddr',
'https://projects.itemis.de/nexus/content/repositories/mbeddr_snapshots',
]
ext.artifactsDir = new File(buildDir, 'artifacts')
ext.projectLibrariesDir = new File(buildDir, 'project-libraries')
apply plugin: 'maven-publish'
task wrapper(type: Wrapper) {
gradleVersion '3.1'
distributionType 'all'
}
configurations {
mps
mpsArtifacts
}
dependencies {
mps "com.jetbrains:mps:$mpsVersion"
mpsArtifacts "com.mbeddr:allScripts:$mbeddrVersion"
mpsArtifacts "com.mbeddr:mbeddr:$mbeddrVersion"
}
repositories {
for (repoUrl in project.dependencyRepositories) {
maven {
url repoUrl
if (project.hasProperty('nexusUsername')) {
credentials {
username project.nexusUsername
password project.nexusPassword
}
}
}
}
}
task resolveMps(type: Copy) {
def outputDir = "$buildDir/mps"
dependsOn configurations.mps
from {
configurations.mps.resolve().collect { zipTree(it) }
}
into outputDir
doFirst { delete outputDir }
}
task resolveMpsArtifacts(type: Copy) {
dependsOn configurations.mpsArtifacts
from {
configurations.mpsArtifacts.resolve().collect { zipTree(it) }
}
into artifactsDir
doFirst { delete artifactsDir }
}
task generateLibrariesXml {
def defaultsFile = file('projectlibraries.properties')
def overridesFile = file('projectlibraries.overrides.properties')
def librariesFile = file('.mps/libraries.xml')
description "Generates libraries.xml for MPS from $defaultsFile and $overridesFile (if present)"
inputs.files defaultsFile, overridesFile
outputs.file librariesFile
def properties = new Properties()
defaultsFile.withInputStream { properties.load(it) }
if (overridesFile.exists()) {
overridesFile.withInputStream { properties.load(it) }
}
doLast {
librariesFile.withWriter { writer ->
def xml = new groovy.xml.MarkupBuilder(writer)
xml.project(version: 4) {
component(name: 'ProjectLibraryManager') {
option(name: 'libraries') {
map() {
for (lib in properties.entrySet()) {
entry(key: lib.key) {
value() {
Library() {
option(name: 'name', value: lib.key)
option(name: 'path', value: lib.value)
}
}
}
}
}
}
}
}
}
}
}
task setup {
// We resolve MPS not for the users to use it but for the distribution packaging script to be able to refer to it.
dependsOn resolveMps, resolveMpsArtifacts
dependsOn generateLibrariesXml
description 'Set up MPS project libraries'
}
ant.properties['mbeddr.arduino'] = projectDir
ant.properties['build.dir'] = buildDir
ant.properties['mps.home'] = resolveMps.destinationDir
ant.properties['artifacts.root'] = resolveMpsArtifacts.destinationDir
ant.importBuild('build.xml') { target -> 'ant-' + target }
//tasks['ant-check-mps-home'].dependsOn resolveMps
tasks['ant-build-allScripts'].dependsOn resolveMps, resolveMpsArtifacts, 'ant-clean'
tasks['ant-build-arduino'].dependsOn 'ant-build-allScripts', 'ant-clean'
task packageArduino(type: Zip, dependsOn: 'ant-build-arduino') {
baseName ''
from artifactsDir
include ''
}
task packageArduinoDistribution(dependsOn: 'ant-build-arduino') {
doLast {
ant.ant(antfile: file('build/<fixme>/build-distribution.xml'), target: 'build')
}
}
publishing {
repositories {
maven {
url project.publishingRepository
if (project.hasProperty('nexusUsername')) {
credentials {
username project.nexusUsername
password project.nexusPassword
}
}
}
}
publications {
arduino(MavenPublication) {
artifactId 'arduino'
artifact packageArduino
}
}
}
// Ant <junit> task support
repositories {
mavenCentral()
}
configurations {
junitAnt
}
dependencies {
junitAnt 'junit:junit:4.12'
junitAnt('org.apache.ant:ant-junit:1.9.7') {
transitive = false
}
junitAnt('org.apache.ant:ant-junit4:1.9.7') {
transitive = false
}
}
ant.taskdef(name: 'junit', classname: 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTask',
classpath: configurations.junitAnt.asPath)
ant.taskdef(name: 'junitreport', classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
classpath: configurations.junitAnt.asPath)
assemble.dependsOn 'ant-build-arduino'
check.dependsOn 'ant-run-tests'