forked from JetBrains/MPS-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
263 lines (216 loc) · 7.76 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//will pull the groovy classes/types from nexus to the classpath
buildscript {
repositories {
maven { url 'https://projects.itemis.de/nexus/content/repositories/mbeddr' }
}
dependencies {
classpath 'de.itemis.mps:mps-gradle-plugin:1.0+'
}
}
apply plugin: 'maven-publish'
apply plugin: 'base'
import de.itemis.mps.gradle.*
task wrapper(type: Wrapper) {
gradleVersion '4.4.1'
distributionType 'all'
}
// detect if we are in a CI build
if (project.hasProperty("forceCI")) {
ext.ciBuild = true
} else {
//on teamcity we are in a CI build
if (project.hasProperty("teamcity")) {
ext.ciBuild = true
} else {
ext.ciBuild = false
}
}
// Detect jdk location, required to start ant with tools.jar on classpath otherwise javac and tests will fail
def java_home = System.properties['java.home']
def jdk_home = java_home
if (!file("$jdk_home/lib/tools.jar").isFile()) {
jdk_home = jdk_home + "/.."
}
if (!file("$jdk_home/lib/tools.jar").isFile()) {
throw new GradleException("Was not able to locate jdk home folder. Use 'jdk_home' project variable to specify JDK location explicitly. Current JAVA_HOME is: $java_home")
}
ext.jdk_home = jdk_home
// Default repository credentials
if (!project.hasProperty('nexusUsername')) {
ext.nexusUsername = ''
ext.nexusPassword = ''
}
logger.info 'Repository username: {}', project.nexusUsername
ext.dependencyRepositories = [
'https://projects.itemis.de/nexus/content/repositories/mbeddr',
'https://projects.itemis.de/nexus/content/repositories/mbeddr_snapshots',
]
// Dependency versions
ext.mpsMajor = '2017.3'
ext.mpsMinor = '5'
ext.mpsVersion = "$mpsMajor.$mpsMinor"
// artifacts version. this is the default versioning that is used
def minor = '1'
def major = '0'
if (ciBuild) {
version = GitBasedVersioning.getVersionWithCount(major, minor, System.env.BUILD_NUMBER.toInteger())
println "##teamcity[buildNumber '${version}']"
} else {
println "Local build detected, version will be SNAPSHOT"
version = "1.0-SNAPSHOT"
}
def userHome = System.properties['user.home']
def mpsPluginsDirPattern
if (System.properties['os.name'].toLowerCase().contains('mac')) {
mpsPluginsDirPattern = "$userHome/Library/Application Support/%s"
} else {
mpsPluginsDirPattern = "$userHome/.%s/config/plugins"
}
if (project.hasProperty("MPS_PATHS_SELECTOR")) {
ext.mpsPluginsDir = sprintf(mpsPluginsDirPattern, project.getProperty("MPS_PATHS_SELECTOR"))
} else {
ext.mpsPluginsDir = sprintf(mpsPluginsDirPattern, "MPS$mpsMajor")
}
ext.releaseRepository = 'https://projects.itemis.de/nexus/content/repositories/mbeddr'
ext.snapshotRepository = 'https://projects.itemis.de/nexus/content/repositories/mbeddr_snapshots'
ext.publishingRepository = version.toString().endsWith("-SNAPSHOT") ? snapshotRepository : releaseRepository
configurations {
mps
}
dependencies {
mps "com.jetbrains:mps:$mpsVersion"
}
repositories {
mavenLocal()
for (repoUrl in project.dependencyRepositories) {
maven {
url repoUrl
}
}
}
task resolveMps(type: Copy) {
dependsOn configurations.mps
from {
configurations.mps.resolve().collect { zipTree(it) }
}
into "$buildDir/mps"
}
// Ant support
configurations {
ant_lib
}
dependencies {
ant_lib "org.apache.ant:ant-junit:1.10.1"
}
// tools might be needed later for running test scripts
ext.buildScriptClasspath = project.configurations.ant_lib.fileCollection({ true }) + project.files("$project.jdk_home/lib/tools.jar")
def artifactsDir = new File(rootDir, 'artifacts')
ext.mps_home = '-Dmps.home=' + resolveMps.destinationDir.getAbsolutePath()
ext.build_dir = '-Dbuild.dir=' + file(rootProject.projectDir.absolutePath).getAbsolutePath()
ext.artifacts_dir = '-Dartifacts.root=' + artifactsDir
ext.pluginVersion = "-Dversion=" + version
ext.buildDate = "-DbuildDate=" + new Date().toString()
ext.extensions_home = '-Dextensions.home=' + rootDir
// ___________________ utilities ___________________
File scriptFile(String relativePath) {
new File("$rootDir/build/generated/$relativePath")
}
def defaultScriptArgs = [mps_home, build_dir, artifacts_dir, ext.buildDate, ext.pluginVersion]
task build_allScripts(type: BuildLanguages, dependsOn: [resolveMps]){
script scriptFile('allScripts/build.xml')
scriptArgs = defaultScriptArgs
scriptClasspath = buildScriptClasspath
}
task build_languages(type: BuildLanguages, dependsOn: [build_allScripts]){
script scriptFile('languages/build.xml')
scriptArgs = defaultScriptArgs
scriptClasspath = buildScriptClasspath
}
task run_tests(type: TestLanguages, dependsOn: build_languages) {
description "Will execute all tests from command line"
script scriptFile('tests/build.xml')
scriptArgs = defaultScriptArgs
scriptClasspath = buildScriptClasspath
}
task install_nativelibs(type: Copy, dependsOn: build_languages) {
from "$rootDir/artifacts/de.itemis.mps.extensions/"
include "de.itemis.mps.nativelibs.loader/"
into "$mpsPluginsDir"
}
task install(dependsOn: install_nativelibs) {
description "Install the required plugins into the MPS plugin repository"
group "Build Setup"
doFirst {
// check parent gradle file for definition of the variables
println "Installing required mbeddr plugins to '$mpsPluginsDir'"
if (!project.hasProperty("MPS_PATHS_SELECTOR")) {
println "To change 'MPS<>' part, pass MPS_PATHS_SELECTOR property to gradle with -PMPS_PATHS_SELECTOR=<custom path selector>"
println "The path selector only contains the the actual selector for instance \"MPS2017.3\" not the full qualifies path to the user plugin directory."
}
}
}
//
// 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
}
}
task packageAllScripts(type: Zip, dependsOn: run_tests) {
baseName 'de.itemis.mps.extensions.allScripts'
from artifactsDir
include 'de.itemis.mps.extensions.allScripts/**'
}
task packageExtensions(type: Zip, dependsOn: run_tests) {
baseName 'de.itemis.mps.extensions'
from artifactsDir
include 'de.itemis.mps.extensions/**'
}
publishing {
repositories {
maven {
url project.publishingRepository
if (project.hasProperty('nexusUsername')) {
credentials {
username project.nexusUsername
password project.nexusPassword
}
}
}
}
publications {
allScripts(MavenPublication) {
groupId 'de.itemis.mps.extensions'
artifactId 'allScripts'
artifact packageAllScripts
}
extensions(MavenPublication) {
groupId 'de.itemis.mps'
artifactId 'extensions'
artifact packageExtensions
//Pom.withProvidedDep pom, configurations.mps
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.mps.resolvedConfiguration.firstLevelModuleDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.moduleGroup)
dependencyNode.appendNode('artifactId', it.moduleName)
dependencyNode.appendNode('version', it.moduleVersion)
dependencyNode.appendNode('type', it.moduleArtifacts[0].type)
dependencyNode.appendNode('scope', 'provided')
}
}
}
}
}
defaultTasks 'build_languages'