diff --git a/src/main/kotlin/de/itemis/mps/gradle/runmigrations/Plugin.kt b/src/main/kotlin/de/itemis/mps/gradle/runmigrations/Plugin.kt index 1cf36d4..2c597ac 100644 --- a/src/main/kotlin/de/itemis/mps/gradle/runmigrations/Plugin.kt +++ b/src/main/kotlin/de/itemis/mps/gradle/runmigrations/Plugin.kt @@ -2,6 +2,8 @@ package de.itemis.mps.gradle.runmigrations import de.itemis.mps.gradle.BasePluginExtensions import de.itemis.mps.gradle.getMPSVersion +import de.itemis.mps.gradle.runAnt +import groovy.xml.MarkupBuilder import net.swiftzer.semver.SemVer import org.gradle.api.GradleException import org.gradle.api.Plugin @@ -74,7 +76,7 @@ open class RunMigrationsMpsProjectPlugin : Plugin { } else { tasks.create("resolveMpsForMigrations") } - + tasks.named("runMigrations") { dependsOn(resolveMps) doLast { @@ -82,52 +84,119 @@ open class RunMigrationsMpsProjectPlugin : Plugin { throw GradleException("Specified MPS location does not exist or is not a directory: $mpsLocation") } - ant.withGroovyBuilder { - "path"("id" to "path.mps.ant.path",) { - // The different MPS versions need different jars. Let's just keep it simple and include all jars. - "fileset"("dir" to "$mpsLocation/lib", "includes" to "**/*.jar") - } - "taskdef"("resource" to "jetbrains/mps/build/ant/antlib.xml", "classpathref" to "path.mps.ant.path") - - val argsToMigrate = mutableListOf>().run { - add("project" to projectLocation) - add("mpsHome" to mpsLocation) - - extension.force?.let { add("force" to it) } - extension.haltOnPrecheckFailure?.let { add("haltOnPrecheckFailure" to it) } - extension.haltOnDependencyError?.let { add("haltOnDependencyError" to it) } + val buildFile = temporaryDir.resolve("build.xml") + buildFile.printWriter().use { + MarkupBuilder(it).withGroovyBuilder { + "project" { + "path"("id" to "path.mps.ant.path") { + // The different MPS versions need different jars. Let's just keep it simple and include all jars. + "fileset"("dir" to "$mpsLocation/lib", "includes" to "**/*.jar") + } + "taskdef"( + "resource" to "jetbrains/mps/build/ant/antlib.xml", + "classpathref" to "path.mps.ant.path" + ) - toTypedArray() - } + val argsToMigrate = mutableListOf>().run { + add("project" to projectLocation) + add("mpsHome" to mpsLocation) - "migrate"(*argsToMigrate) { - "macro"("name" to "mps_home", "path" to mpsLocation) + extension.force?.let { add("force" to it) } + extension.haltOnPrecheckFailure?.let { add("haltOnPrecheckFailure" to it) } + extension.haltOnDependencyError?.let { add("haltOnDependencyError" to it) } - extension.macros.forEach { - "macro"("name" to it.name, "path" to it.value) - } - - "jvmargs" { - "arg"("value" to "-Didea.log.config.file=log.xml") - "arg"("value" to "-ea") - if (extension.maxHeap != null) { - "arg"("value" to "-Xmx${extension.maxHeap}") + toTypedArray() } - } - extension.pluginsProperty.get().forEach { - // Same handling as in mps-build-backends - if (File(it.path).isAbsolute) { - "plugin"("path" to it.path, "id" to it.id) - } - else if (extension.pluginLocation != null && File(extension.pluginLocation, it.path).exists()) { - "plugin"("path" to File(extension.pluginLocation, it.path), "id" to it.id) - } else { - "plugin"("path" to mpsLocation.resolve("plugins").resolve(it.path), "id" to it.id) + "migrate"(*argsToMigrate) { + "macro"("name" to "mps_home", "path" to mpsLocation) + + extension.macros.forEach { + "macro"("name" to it.name, "path" to it.value) + } + + "jvmargs" { + "arg"("value" to "-Didea.log.config.file=log.xml") + "arg"("value" to "-ea") + + if (extension.maxHeap != null) { + "arg"("value" to "-Xmx${extension.maxHeap}") + } + + "arg"("value" to "--add-opens=java.base/java.io=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.lang=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.net=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.nio=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.nio.charset=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.text=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.time=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.util=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.util.concurrent=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/jdk.internal.vm=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/sun.security.ssl=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.base/sun.security.util=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/java.awt=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/java.awt.dnd.peer=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/java.awt.event=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/java.awt.image=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/java.awt.peer=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/javax.swing=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/sun.awt.datatransfer=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/sun.awt.image=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/sun.awt=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/sun.font=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/sun.java2d=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/sun.swing=ALL-UNNAMED") + "arg"("value" to "--add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED") + "arg"("value" to "--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED") + "arg"("value" to "--add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED") + "arg"("value" to "--add-opens=jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/com.apple.laf=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/com.apple.eawt=ALL-UNNAMED") + "arg"("value" to "--add-opens=java.desktop/com.apple.eawt.event=ALL-UNNAMED") + } + + extension.pluginsProperty.get().forEach { + // Same handling as in mps-build-backends + if (File(it.path).isAbsolute) { + "plugin"("path" to it.path, "id" to it.id) + } else if (extension.pluginLocation != null && File( + extension.pluginLocation, + it.path + ).exists() + ) { + "plugin"( + "path" to File(extension.pluginLocation, it.path), + "id" to it.id + ) + } else { + "plugin"( + "path" to mpsLocation.resolve("plugins").resolve(it.path), + "id" to it.id + ) + } + } } } } } + + val classpath = project.fileTree(mpsLocation.resolve("lib")) { + include("ant/lib/*.jar") + include("*.jar") + builtBy(resolveMps) + } + + runAnt( + extension.javaExec, temporaryDir, args = listOf(), + includeDefaultClasspath = false, + scriptClasspath = classpath + ) } } }