Repository navigation
Expand file tree
/
Copy pathbuild.gradle
More file actions
161 lines (135 loc) · 5.58 KB
/
Copy pathbuild.gradle
File metadata and controls
161 lines (135 loc) · 5.58 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
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
plugins {
id 'java'
id 'dev.equo.p2deps' version '1.7.8' apply false
}
version = '0.1.0'
// Eclipse doesn't manage a Maven repo, so we use this function to get the JAR from the p2 repo
// https://github.com/equodev/equo-ide/tree/main/plugin-gradle#user-plugins
apply plugin: 'dev.equo.p2deps'
p2deps {
into 'implementation', {
// Sources can be found at https://github.com/eclipse-uml2/uml2
p2repo 'https://download.eclipse.org/modeling/mdt/uml2/builds/release/5.6.1/'
install 'org.eclipse.uml2.common'
install 'org.eclipse.uml2.types'
install 'org.eclipse.uml2.uml'
install 'org.eclipse.uml2.uml.profile.standard'
install 'org.eclipse.uml2.uml.resources'
}
}
repositories {
mavenCentral()
}
dependencies {
implementation(libs.commons.cli)
implementation(libs.com.google.inject)
implementation(libs.org.eclipse.emf)
implementation(libs.org.antlr)
implementation(libs.org.eclipse.xtext)
}
sourceSets {
main.java.srcDirs = ['comodo2/src']
main.resources.srcDirs = ['comodo2/src']
}
jar {
duplicatesStrategy = 'exclude'
manifest {
attributes 'Main-Class': 'comodo2.engine.Main'
}
from {
configurations.runtimeClasspath.collect {
it.isDirectory() ? it : zipTree(it)
}
} {exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'}
}
tasks.withType(JavaCompile) {
options.compilerArgs += ['-Xlint:deprecation', '-Xlint:unchecked']
}
// #################### INSTALLATION INTO PREFIX ########################
tasks.register('install', Copy) {
def prefix = providers.gradleProperty("prefix").getOrElse("/usr/local")
def version = project.version
group = 'distribution'
description = 'Install JAR and launcher script'
// Ensure the JAR is build first
dependsOn assemble
doFirst {
println "--------------------------------------------------------"
println "Install Prefix: ${prefix}"
println "--------------------------------------------------------"
}
// Absolute path to install prefix
into {
return prefix
}
// Install jar file
into("share/java") {
from tasks.named("jar")
}
// Install launcher with substitution
into ("bin") {
from 'comodo2.in'
filter(ReplaceTokens, tokens: [
PREFIX: prefix,
VERSION: version
])
rename { String fileName ->
fileName.replace('.in', '')
}
}
}
// #################### TESTING ########################
// The testing strategy is: each target is executed on a set of models in the execute<name>Target.
// The output is then compared in test<name>Target with the reference output, usually stored under test/<name>/ref.
// RESULTS_MAPPING is used to store the results of the tests.
ext.TEST_OUTPUT_PATH = "./test/gradle-testgen"
ext.RESULTS_MAPPING = [:]
// This function defines tasks that execute the target on the test models and compares the output with the reference output
def defineTargetTestingTask(String taskName, String targetType, String inputFilePath, String modelName, String expectedOutputPath, String extraArgs = "") {
task("execute${taskName}Target", type: Exec) {
dependsOn build
group = "Execution"
description = "Run the ${targetType} target on the test models (${modelName})"
commandLine "java", "--add-opens=java.base/java.lang=ALL-UNNAMED", "-jar", file(jar.archiveFile)
args "-i", inputFilePath, "-o", "${TEST_OUTPUT_PATH}/${taskName}", "-t", targetType, "-m", modelName, "-a", extraArgs
}
task("test${taskName}Target", type: Exec) {
dependsOn "execute${taskName}Target"
group = "DiffTesting"
description = "Test the ${targetType} target by comparing its output with the reference output."
new File("${TEST_OUTPUT_PATH}").mkdirs()
def outputFilename = "${TEST_OUTPUT_PATH}/${taskName}.difflog"
standardOutput = new FileOutputStream(outputFilename)
commandLine "diff", "-rb", "${TEST_OUTPUT_PATH}/${taskName}", "${expectedOutputPath}"
ignoreExitValue = true
doLast {
def output = new FileInputStream(outputFilename).text.trim()
if (output) {
println "[FAIL] Test failure: the generated code is different from the reference code. Please check the diff in ${outputFilename}."
RESULTS_MAPPING.put(taskName, "FAIL")
} else {
RESULTS_MAPPING.put(taskName, "PASS")
println "[PASS] Test succeeded."
}
}
}
}
// Defining test tasks
defineTargetTestingTask("QPC-C", "QPC-C", "./test/qpc/model/qpc-test-model/qpc-test-model.uml", "BlinkyChoice", "./test/qpc/ref")
defineTargetTestingTask("ELT-RAD1", "ELT-RAD", "./test/elt/model/hello/EELT_ICS_ApplicationFramework.uml", "hellomalif hellomal", "./test/elt/ref/hello", "-ndgALL")
defineTargetTestingTask("ELT-RAD2", "ELT-RAD", "./test/elt/model/hello/EELT_ICS_ApplicationFramework.uml", "hellomalif2 externalif2 hellomal2", "./test/elt/ref/hello2", "-ndgALL")
// Execute all tests and returns results
task testAll {
dependsOn tasks.matching { it.group == "DiffTesting" }
doLast{
println "${RESULTS_MAPPING.size()} tests executed. Results (PASS/FAIL) by target: ${RESULTS_MAPPING}"
if (RESULTS_MAPPING.values().any { it == "FAIL" }) {
throw new GradleException("[FAIL] At least one test failed. See logs above and in ${TEST_OUTPUT_PATH}/*.difflog for details.")
} else {
println "[PASS] All tests succeeded."
}
}
}