-
Notifications
You must be signed in to change notification settings - Fork 0
/
mps.gradle
103 lines (91 loc) · 3.44 KB
/
mps.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
configurations {
mps {
description = 'Dependencies to add to MPS'
visible = false
}
}
task mps_compose(description: 'Copies jar-files from selected configuration to MPS solution.',
group: 'd0sl') {
doLast {
Configuration lib = configurations.getByName('mps')
String solution = 'external'
if(project.hasProperty('mpsConfiguration')) {
lib = configurations.getByName(getProperty('mpsConfiguration'))
}
if(project.hasProperty('mpsSolutionName')) {
solution = getProperty('mpsSolutionName')
}
buildMPSLib(lib, solution)
}
}
void buildMPSLib(Configuration lib, String solution) {
logging.captureStandardOutput LogLevel.QUIET
def artifacts = lib.resolvedConfiguration.resolvedArtifacts
def solutionFolder = 'solutions/' + solution
def libFolder = solutionFolder + '/lib'
// clear destination lib folder
logger.quiet('Clearing ' + libFolder + ' folder')
delete(files(libFolder))
// copying artifacts
logger.quiet('Copying ' + artifacts.size() + ' files from ' + lib.name + ' ' + libFolder)
copy {
from lib.files
into libFolder
}
logger.quiet('Reading the solution file.')
def xmlFile = file solutionFolder + '/' + solution + '.msd'
if (!xmlFile.exists()) {
throw new GradleException("Required solution file does not exist: $xmlFile.canonicalPath")
}
def xml = new XmlParser().parse(xmlFile)
logger.quiet("solution name: ${xml.@name}")
Node stubModelEntries = (Node) xml.stubModelEntries.find { true }
if(stubModelEntries == null) {
logger.quiet('Create stubModelEntries')
stubModelEntries = new Node(xml, 'stubModelEntries')
}
// clearing modelRoot && stubModelEntry
def nodesToDel = xml.models.modelRoot.findAll { true }
nodesToDel.each {
logger.quiet(' -> removing modelRoot' + it.@contentPath)
def parent = it.parent()
parent.remove(it)
}
nodesToDel = xml.stubModelEntries.stubModelEntry.findAll { true }
nodesToDel.each {
logger.quiet(' -> removing stubModelEntry' + it.@path)
def parent = it.parent()
parent.remove(it)
}
artifacts.each {
logger.quiet('Performing ' + it.id)
String artifactName = it.name
String fileName = it.name + '-' + it.moduleVersion.id.version + '.' + it.extension
// adding artifact modelRoot && stubModelEntry
logger.quiet(' -> adding modelRoot ' + '${module}/lib/' + fileName + '!')
String contentPath = '${module}/lib/' + fileName + '!'
Node models = (Node) xml.models.find { true }
Node n = new Node(models,
'modelRoot',
[contentPath: contentPath, type: 'java_classes'])
new Node(n,
'sourceRoot',
[location: '.'])
logger.quiet(' -> adding stubModelEntry ' + '${module}/lib/' + fileName)
String path = '${module}/lib/' + fileName
new Node(stubModelEntries,
'stubModelEntry',
[path: path])
}
new File(solutionFolder + '/' + solution + '.msd').withWriter {
def printer = new XmlNodePrinter(new PrintWriter(it))
printer.preserveWhitespace = true
printer.print(xml)
}
}
if(project.hasProperty('antScript')) {
def script = project.property('antScript')
ant.importBuild(script) { antTargetName ->
'mps_' + antTargetName
}
}