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
13 apply plugin: "com.github.johnrengelman.shadow"
15 description = "Standalone SquirrelJME virtual machine on Java."
16 mainClassName = "cc.squirreljme.vm.standalone.main.Main"
19 implementation project(":emulators:springcoat-vm")
20 implementation project(":emulators:nanocoat-vm")
22 // Debugger tool for quick usage
23 implementation project(":tools:squirreljme-debugger")
27 // Use a fixed version of the JVM
30 sourceCompatibility = JavaVersion.VERSION_1_8
31 targetCompatibility = JavaVersion.VERSION_1_8
33 // Use the default bootstrap classpath
34 options.bootstrapClasspath = null
39 compileJava.options.debug = true
40 compileJava.options.debugOptions.setDebugLevel("source,lines,vars")
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<>()
51 input.forEach({path -> result.add(path.getFileName())})
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)
76 dependsOn processResources, collateResourceJars, collateResourceJarsDebug
77 mustRunAfter collateResourceJars, collateResourceJarsDebug
79 // We need to set specific manifest properties
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"))
89 "X-SquirrelJME-Standalone-Library": project.provider({ ->
90 return VMHelpers.classpathAsString(
91 mapBaseNameP(VMHelpers.fullSuiteLibraries(
92 rootProject.tasks.getByName("fullSpringCoatRelease"))
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 + "/"})
102 // Configuration for ShadowJar
104 dependsOn collateResourceJars, collateResourceJarsDebug
105 mustRunAfter collateResourceJars, collateResourceJarsDebug
107 // Always SquirrelJME
108 archiveBaseName.set("squirreljme-standalone")
110 // Always merge service files, otherwise multiple VMs will just not work
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()
119 // Normalize OS names
120 if (osName.contains("windows"))
122 else if (osName.contains("mac os") || osName.contains("macos"))
125 // Make sure there are no spaces or weird characters such as for
127 return (osName + "-" + osArch).replaceAll(
128 Pattern.compile("[\\s<>:\"/\\\\|?*]"), "")
131 // Exclude IntelliJ Annotations, they are not needed
132 exclude "org/jetbrains/annotations/*.class"
133 exclude "org/intellij/lang/annotations/*.class"
136 // Exclude IntelliJ Annotations, they are not needed
137 exclude(dependency("org.jetbrains:annotations-java5:.*"))
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" : ""),
150 sub.dependsOn shadowJarTask
152 sub.description = "Runs the standalone VM via " +
153 "${vmType.properName}" +
154 (isDebug ? " with debugging" : "") +
155 (isCluttered ? " with cluttering" : "") + ".";
156 sub.group = "squirreljme"
158 sub.classpath = shadowJarTask.get().getOutputs().getFiles()
159 sub.mainClass = "cc.squirreljme.vm.standalone.main.Main"
162 sub.args = ["-Xemulator:" +
163 vmType.vmName(VMNameFormat.LOWERCASE), "-Xdebug",
166 sub.args = ["-Xemulator:" +
167 vmType.vmName(VMNameFormat.LOWERCASE),
172 sub.args = ["-Xemulator:" +
173 vmType.vmName(VMNameFormat.LOWERCASE), "-Xdebug"]
175 sub.args = ["-Xemulator:" +
176 vmType.vmName(VMNameFormat.LOWERCASE)]