-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from kolmar/MpsExecute-task
Add MpsExecute task
- Loading branch information
Showing
13 changed files
with
396 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package de.itemis.mps.gradle | ||
|
||
import java.io.File | ||
|
||
internal object ErrorMessages { | ||
const val MUST_SET_CONFIG_OR_VERSION = "Either mpsConfig or mpsVersion needs to specified!" | ||
const val MUST_SET_VERSION_AND_LOCATION = "Setting an MPS version but no MPS location is not supported!" | ||
const val MPS_VERSION_NOT_SUPPORTED = "This version of mps-gradle-plugin only supports MPS 2020.1 and above. Please use version 1.4 with an older version of MPS." | ||
|
||
fun noMpsProjectIn(dir: File): String = "Directory does not contain an MPS project: $dir" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/main/kotlin/de/itemis/mps/gradle/tasks/MpsExecute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package de.itemis.mps.gradle.tasks | ||
|
||
import de.itemis.mps.gradle.ErrorMessages | ||
import de.itemis.mps.gradle.launcher.MpsBackendBuilder | ||
import de.itemis.mps.gradle.launcher.MpsVersionDetection | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.Directory | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.logging.LogLevel | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.MapProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.SetProperty | ||
import org.gradle.api.tasks.* | ||
import org.gradle.kotlin.dsl.newInstance | ||
import org.gradle.work.DisableCachingByDefault | ||
|
||
|
||
@DisableCachingByDefault(because = "calls arbitrary user code") | ||
abstract class MpsExecute : JavaExec() { | ||
|
||
@get:Internal | ||
abstract val mpsHome: DirectoryProperty | ||
|
||
@get:Internal | ||
abstract val mpsVersion: Property<String> | ||
|
||
@get:Internal | ||
abstract val projectLocation: DirectoryProperty | ||
|
||
@get:Classpath | ||
abstract val pluginRoots: SetProperty<Directory> | ||
|
||
@get:Internal | ||
abstract val macros: MapProperty<String, String> | ||
|
||
@get:Internal | ||
abstract val module: Property<String> | ||
|
||
@get:Internal | ||
abstract val className: Property<String> | ||
|
||
@get:Internal | ||
abstract val method: Property<String> | ||
|
||
@get:Internal | ||
abstract val methodArguments: ListProperty<String> | ||
|
||
@get:Internal | ||
val additionalExecuteBackendClasspath: ConfigurableFileCollection = | ||
objectFactory.fileCollection().from(initialExecuteBackendClasspath()) | ||
|
||
init { | ||
mpsVersion.convention(MpsVersionDetection.fromMpsHome(project.layout, providerFactory, mpsHome.asFile)) | ||
projectLocation.convention(project.layout.projectDirectory) | ||
|
||
objectFactory.newInstance(MpsBackendBuilder::class) | ||
.withMpsHomeDirectory(mpsHome) | ||
.withMpsVersion(mpsVersion) | ||
.configure(this) | ||
|
||
argumentProviders.add { | ||
mutableListOf<String>().apply { | ||
add("--project=${projectLocation.get().asFile}") | ||
|
||
pluginRoots.get().forEach { | ||
findPluginsRecursively(it.asFile).forEach { | ||
add("--plugin=${it.id}::${it.path}") | ||
} | ||
} | ||
macros.get().forEach { add("--macro=${it.key}::${it.value}") } | ||
|
||
add("--module=${module.get()}") | ||
add("--class=${className.get()}") | ||
add("--method=${method.get()}") | ||
methodArguments.get().forEach { add("--arg=$it") } | ||
|
||
val effectiveLogLevel = logging.level ?: project.logging.level ?: project.gradle.startParameter.logLevel | ||
if (effectiveLogLevel <= LogLevel.INFO) { | ||
add("--log-level=info") | ||
} | ||
} | ||
} | ||
|
||
description = "Execute specified method from a generated class to modify the MPS project" | ||
group = "execute" | ||
|
||
classpath(project.configurations.named("executeBackend")) | ||
classpath(additionalExecuteBackendClasspath) | ||
|
||
mainClass.set("de.itemis.mps.gradle.execute.MainKt") | ||
} | ||
|
||
@TaskAction | ||
override fun exec() { | ||
val projectLocationAsFile = projectLocation.get().asFile | ||
if (!projectLocationAsFile.resolve(".mps").isDirectory) { | ||
throw GradleException(ErrorMessages.noMpsProjectIn(projectLocationAsFile)) | ||
} | ||
|
||
super.exec() | ||
} | ||
|
||
private fun initialExecuteBackendClasspath() = mpsHome.asFileTree.matching { | ||
include("lib/**/*.jar") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.