Correct task for nanocoat.
[SquirrelJME.git] / emulators / standalone / build.gradle
blobff570b177ea43e4e8f353f574b56ad09c24a7717
1 import cc.squirreljme.plugin.general.CollateResourceJarsTask
2 import cc.squirreljme.plugin.multivm.*
3 import cc.squirreljme.plugin.multivm.ident.SourceTargetClassifier
5 import java.util.regex.Pattern
7 plugins
9         id "application"
10         id "java"
13 apply plugin: "com.github.johnrengelman.shadow"
15 description = "Standalone SquirrelJME virtual machine on Java."
16 mainClassName = "cc.squirreljme.vm.standalone.main.Main"
18 dependencies {
19         implementation project(":emulators:springcoat-vm")
20         implementation project(":emulators:nanocoat-vm")
21         
22         // Debugger tool for quick usage
23         implementation project(":tools:squirreljme-debugger")
26 java {
27         // Use a fixed version of the JVM
28         compileJava
29         {
30                 sourceCompatibility = JavaVersion.VERSION_1_8
31                 targetCompatibility = JavaVersion.VERSION_1_8
32                 
33                 // Use the default bootstrap classpath
34                 options.bootstrapClasspath = null
35                 
36         }
37         
38         // Maximize debugging
39         compileJava.options.debug = true
40         compileJava.options.debugOptions.setDebugLevel("source,lines,vars")
41         
42         // Copy settings
43         compileTestJava.options.debug = compileJava.options.debug
44         compileTestJava.options.debugOptions = compileJava.options.debugOptions
47 // Mapper for Jar names on files to straight file names
48 static Iterable<java.nio.file.Path> mapBaseNameP(Iterable<Path> input) {
49         List<java.nio.file.Path> result = new ArrayList<>()
50         
51         input.forEach({path -> result.add(path.getFileName())})
52         
53         return result;
56 static String flatClasspath(Project project) {
57         return VMHelpers.classpathAsString(mapBaseNameP(VMHelpers
58                 .runClassPath(project, new SourceTargetClassifier(
59                         SourceSet.MAIN_SOURCE_SET_NAME,
60                         VMType.SPRINGCOAT, BangletVariant.NONE,
61                         ClutterLevel.RELEASE)) as List<Path>))
64 String MERGED_PREFIX = "SQUIRRELJME.SQC"
65 String MERGED_PREFIX_DEBUG = "SQUIRRELJME-DEBUG.SQC"
67 tasks.register("collateResourceJars",
68         CollateResourceJarsTask.class,
69         processResources, ClutterLevel.RELEASE, MERGED_PREFIX)
70 tasks.register("collateResourceJarsDebug",
71         CollateResourceJarsTask.class,
72         processResources, ClutterLevel.DEBUG, MERGED_PREFIX_DEBUG)
74 // Jar Configuration
75 jar {
76         dependsOn processResources, collateResourceJars, collateResourceJarsDebug
77         mustRunAfter collateResourceJars, collateResourceJarsDebug
78         
79         // We need to set specific manifest properties
80         manifest {
81                 attributes \
82                         "X-SquirrelJME-Standalone-Main-Class":
83                                 "javax.microedition.midlet.__MainHandler__",
84                         "X-SquirrelJME-Standalone-Parameter":
85                                 "cc.squirreljme.runtime.launcher.ui.MidletMain",
86                         "X-SquirrelJME-Standalone-Classpath": project.provider({ ->
87                                         return flatClasspath(project(":modules:launcher"))
88                                 }),
89                         "X-SquirrelJME-Standalone-Library": project.provider({ ->
90                                         return VMHelpers.classpathAsString(
91                                                 mapBaseNameP(VMHelpers.fullSuiteLibraries(
92                                                         rootProject.tasks.getByName("fullSpringCoatRelease"))
93                                                         as Iterable<Path>))
94                                 }),
95                         "X-SquirrelJME-Standalone-Internal-Jar-Root": project.provider({ ->
96                                 "/" + MERGED_PREFIX + "/"}),
97                         "X-SquirrelJME-Standalone-Internal-Debug-Jar-Root": project.provider({ ->
98                                 "/" + MERGED_PREFIX_DEBUG + "/"})
99         }
102 // Configuration for ShadowJar
103 shadowJar {
104         dependsOn collateResourceJars, collateResourceJarsDebug
105         mustRunAfter collateResourceJars, collateResourceJarsDebug
106         
107         // Always SquirrelJME
108         archiveBaseName.set("squirreljme-standalone")
109         
110         // Always merge service files, otherwise multiple VMs will just not work
111         mergeServiceFiles()
112         
113         // Set the suffix of the JAR to be the OS name and arch, since there is
114         // a dynamic library within for it
115         archiveClassifier.set(project.provider({ ->
116                         String osName = System.getProperty("os.name").toLowerCase()
117                         String osArch = System.getProperty("os.arch").toLowerCase()
118                         
119                         // Normalize OS names
120                         if (osName.contains("windows"))
121                                 osName = "windows"
122                         else if (osName.contains("mac os") || osName.contains("macos"))
123                                 osName = "macos"
124                         
125                         // Make sure there are no spaces or weird characters such as for
126                         // Windows
127                         return (osName + "-" + osArch).replaceAll(
128                                 Pattern.compile("[\\s<>:\"/\\\\|?*]"), "") 
129                 }))
130         
131         // Exclude IntelliJ Annotations, they are not needed
132         exclude "org/jetbrains/annotations/*.class"
133         exclude "org/intellij/lang/annotations/*.class"
134         
135         dependencies {
136                 // Exclude IntelliJ Annotations, they are not needed
137                 exclude(dependency("org.jetbrains:annotations-java5:.*"))
138         }
141 // Shadow run tasks for the various emulator choices
142 Provider<Task> shadowJarTask = tasks.named("shadowJar")
143 [false, true].each { isDebug ->
144         [false, true].each { isCluttered ->
145                 VMType.values().each { vmType ->
146                         tasks.register("run" + vmType.vmName(VMNameFormat.PROPER_NOUN) +
147                                         (isDebug ? "Debug" : "") +
148                                         (isCluttered ? "Cluttered" : ""),
149                                 JavaExec) { sub ->
150                                 sub.dependsOn shadowJarTask
151         
152                                 sub.description = "Runs the standalone VM via " +
153                                         "${vmType.properName}" +
154                                         (isDebug ? " with debugging" : "") +
155                                         (isCluttered ? " with cluttering" : "") + ".";
156                                 sub.group = "squirreljme"
157         
158                                 sub.classpath = shadowJarTask.get().getOutputs().getFiles()
159                                 sub.mainClass = "cc.squirreljme.vm.standalone.main.Main"
160                                 if (isCluttered) {
161                                         if (isDebug) {
162                                                 sub.args = ["-Xemulator:" + 
163                                                         vmType.vmName(VMNameFormat.LOWERCASE), "-Xdebug",
164                                                         "-Xclutter:debug"]
165                                         } else {
166                                                 sub.args = ["-Xemulator:" + 
167                                                         vmType.vmName(VMNameFormat.LOWERCASE),
168                                                         "-Xclutter:debug"]
169                                         }
170                                 } else {
171                                         if (isDebug) {
172                                                 sub.args = ["-Xemulator:" + 
173                                                         vmType.vmName(VMNameFormat.LOWERCASE), "-Xdebug"]
174                                         } else {
175                                                 sub.args = ["-Xemulator:" + 
176                                                         vmType.vmName(VMNameFormat.LOWERCASE)]
177                                         }
178                                 }
179                         }
180                 }
181         }