-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.gradle
83 lines (73 loc) · 3.23 KB
/
scripts.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
import org.gradle.api.internal.plugins.*
import org.gradle.util.TextUtil
class StartScriptForProjectTemplateBindingFactory
implements Transformer<Map<String, String>, JavaAppStartScriptGenerationDetails> {
private boolean windows
private StartScriptTemplateBindingFactory delegate
StartScriptForProjectTemplateBindingFactory(boolean windows) {
this.windows = windows
delegate = windows ? StartScriptTemplateBindingFactory.windows() : StartScriptTemplateBindingFactory.unix()
}
Map<String, String> transform(JavaAppStartScriptGenerationDetails details) {
Map<String, String> binding = delegate.transform(details)
String cp = binding.get("classpath")
if(windows)
cp = cp.replace("%APP_HOME%\\", "")
else
cp = cp.replace("\$APP_HOME/", "")
binding.put("classpath", cp)
return binding
}
}
class UnixStartScriptForProjectGenerator extends DefaultTemplateBasedStartScriptGenerator {
UnixStartScriptForProjectGenerator() {
super(TextUtil.getUnixLineSeparator(),
new StartScriptForProjectTemplateBindingFactory(false),
utf8ClassPathResource(UnixStartScriptGenerator.class, "unixStartScript.txt"))
}
}
class WindowsStartScriptForProjectGenerator extends DefaultTemplateBasedStartScriptGenerator {
WindowsStartScriptForProjectGenerator() {
super(TextUtil.getWindowsLineSeparator(),
new StartScriptForProjectTemplateBindingFactory(true),
utf8ClassPathResource(WindowsStartScriptGenerator.class, "windowsStartScript.txt"))
}
}
class CreateStartScriptsForProject extends CreateStartScripts {
@TaskAction
void generate() {
StartScriptGenerator generator = new StartScriptGenerator(unixStartScriptGenerator, windowsStartScriptGenerator)
generator.setApplicationName(getApplicationName())
generator.setMainClassName(getMainClassName())
generator.setDefaultJvmOpts(getDefaultJvmOpts())
generator.setOptsEnvironmentVar(getOptsEnvironmentVar())
generator.setExitEnvironmentVar(getExitEnvironmentVar())
generator.setClasspath(getClasspath())
generator.setScriptRelPath('build/' + getUnixScript().getName())
generator.generateUnixScript(getUnixScript())
generator.generateWindowsScript(getWindowsScript())
}
}
task mavlc(type: CreateStartScriptsForProject, dependsOn: classes) {
description = "Creates a start script for MAVL compiler driver"
mainClassName = "mavlc.Driver"
applicationName = "mavlc"
outputDir = project.buildDir
classpath = files([file('bin/'), sourceSets.main.output.classesDirs] + configurations.runtimeClasspath)
unixStartScriptGenerator = new UnixStartScriptForProjectGenerator()
windowsStartScriptGenerator = new WindowsStartScriptForProjectGenerator()
}
task mtam(type: CreateStartScriptsForProject, dependsOn: classes) {
description = "Creates a start script for the MTAM interpreter"
mainClassName = "mtam.interpreter.InteractiveInterpreter"
applicationName = "mtam"
outputDir = project.buildDir
classpath = files([file('bin/'), sourceSets.main.output.classesDirs] + configurations.runtimeClasspath)
unixStartScriptGenerator = new UnixStartScriptForProjectGenerator()
windowsStartScriptGenerator = new WindowsStartScriptForProjectGenerator()
}
task createScripts {
description = "Creates start scripts for the MAVL compiler driver and the MTAM interpreter"
dependsOn 'mavlc'
dependsOn 'mtam'
}