-
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.
- Loading branch information
1 parent
f16f039
commit 6478154
Showing
11 changed files
with
606 additions
and
21 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
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,6 +1,12 @@ | ||
package de.itemis.mps.gradle | ||
|
||
/** | ||
* Dummy empty plugin that lets us use `plugins` block rather than `buildscript` to put the task classes | ||
* A side effect of this plugin is that it lets us use `plugins` block rather than `buildscript` to put the task classes | ||
* ([RunAntScript], [BuildLanguages], etc.) onto the classpath. | ||
*/ | ||
|
||
val modelcheckBackend by configurations.creating | ||
|
||
modelcheckBackend.defaultDependencies { | ||
add(dependencies.create("de.itemis.mps.build-backends:modelcheck:${MPS_BUILD_BACKENDS_VERSION}")) | ||
} |
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,160 @@ | ||
package de.itemis.mps.gradle.tasks | ||
|
||
import de.itemis.mps.gradle.launcher.MpsBackendLauncher | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.file.* | ||
import org.gradle.api.logging.LogLevel | ||
import org.gradle.api.provider.* | ||
import org.gradle.api.tasks.* | ||
import org.gradle.kotlin.dsl.* | ||
import org.gradle.language.base.plugins.LifecycleBasePlugin | ||
import org.gradle.process.CommandLineArgumentProvider | ||
import java.io.File | ||
|
||
@CacheableTask | ||
abstract class MpsCheck : JavaExec(), VerificationTask { | ||
|
||
// Having our own private launcher instance means we don't need to apply the launcher plugin. This works as long | ||
// as the launcher remains stateless. | ||
private val backendLauncher: MpsBackendLauncher = objectFactory.newInstance(MpsBackendLauncher::class) | ||
|
||
@get:InputDirectory | ||
@get:PathSensitive(PathSensitivity.NONE) | ||
val mpsHome: DirectoryProperty = objectFactory.directoryProperty() | ||
|
||
@get:Input | ||
@get:Optional | ||
val mpsVersion: Property<String> = objectFactory.property<String>() | ||
.convention(backendLauncher.mpsVersionFromMpsHome(mpsHome.asFile)) | ||
|
||
@get:Internal("only modules and models matter, covered by #sources") | ||
val projectLocation: DirectoryProperty = | ||
objectFactory.directoryProperty().convention(project.layout.projectDirectory) | ||
|
||
@get:Classpath | ||
val pluginRoots: SetProperty<Directory> = objectFactory.setProperty() | ||
|
||
@get:Internal("Folder macros are ignored for the purposes of up-to-date checks and caching") | ||
val folderMacros: MapProperty<String, Directory> = objectFactory.mapProperty() | ||
|
||
@get:Input | ||
val varMacros: MapProperty<String, String> = objectFactory.mapProperty() | ||
|
||
@get:Input | ||
val models: ListProperty<String> = objectFactory.listProperty() | ||
|
||
@get:Input | ||
val modules: ListProperty<String> = objectFactory.listProperty() | ||
|
||
@get:Input | ||
val excludeModels: ListProperty<String> = objectFactory.listProperty() | ||
|
||
@get:Input | ||
val excludeModules: ListProperty<String> = objectFactory.listProperty() | ||
|
||
@get:Input | ||
val warningAsError: Property<Boolean> = objectFactory.property<Boolean>().convention(false) | ||
|
||
@get:OutputFile | ||
val junitFile: RegularFileProperty = objectFactory.fileProperty() | ||
.convention(project.layout.buildDirectory.map { it.file("TEST-${this@MpsCheck.name}.xml") }) | ||
|
||
@get:Input | ||
val junitFormat: Property<String> = objectFactory.property<String>().convention("module-and-model") | ||
|
||
@get:Internal("covered by classpath") | ||
val additionalModelcheckBackendClasspath: ConfigurableFileCollection = | ||
objectFactory.fileCollection().from(initialModelcheckBackendClasspath()) | ||
|
||
@Suppress("unused") | ||
@InputFiles | ||
@SkipWhenEmpty | ||
@PathSensitive(PathSensitivity.NONE) | ||
protected val sources: Provider<FileCollection> = projectLocation.map { | ||
it.asFileTree.matching { | ||
exclude(project.layout.buildDirectory.get().asFile.relativeTo(projectLocation.get().asFile).path + "/**") | ||
include("**/*.msd") | ||
include("**/*.mpsr") | ||
include("**/*.mps") | ||
} | ||
} | ||
|
||
init { | ||
backendLauncher.configureJavaForMpsVersion(this, mpsHome.map { it.asFile }, mpsVersion) | ||
argumentProviders.add(CommandLineArgumentProvider { | ||
val result = mutableListOf<String>() | ||
|
||
result.add("--project=${projectLocation.get().asFile}") | ||
|
||
pluginRoots.get().flatMap { findPluginsRecursively(it.asFile) } | ||
.mapTo(result) { "--plugin=${it.id}::${it.path}" } | ||
folderMacros.get().mapTo(result) { "--macro=${it.key}::${it.value.asFile}" } | ||
varMacros.get().mapTo(result) { "--macro=${it.key}::${it.value}" } | ||
|
||
// Only a limited subset of checkers is registered in MPS environment, IDEA environment is necessary for | ||
// proper checking. | ||
result.add("--environment=IDEA") | ||
|
||
result.addAll(models.get().map { "--model=$it" }) | ||
result.addAll(modules.get().map { "--module=$it" }) | ||
result.addAll(excludeModels.get().map { "--exclude-model=$it" }) | ||
result.addAll(excludeModules.get().map { "--exclude-module=$it" }) | ||
|
||
if (warningAsError.get()) { | ||
result.add("--warning-as-error") | ||
} | ||
|
||
if (ignoreFailures) { | ||
result.add("--error-no-fail") | ||
} | ||
|
||
if (junitFile.isPresent) { | ||
result.add("--result-file=${junitFile.get().asFile}") | ||
} | ||
|
||
if (junitFormat.isPresent) { | ||
result.add("--result-format=${junitFormat.get()}") | ||
} | ||
|
||
val effectiveLogLevel = logging.level ?: project.logging.level ?: project.gradle.startParameter.logLevel | ||
if (effectiveLogLevel <= LogLevel.INFO) { | ||
result.add("--log-level=info") | ||
} | ||
|
||
result | ||
}) | ||
|
||
group = LifecycleBasePlugin.VERIFICATION_GROUP | ||
|
||
classpath(project.configurations.named("modelcheckBackend")) | ||
classpath(additionalModelcheckBackendClasspath) | ||
|
||
mainClass.set("de.itemis.mps.gradle.modelcheck.MainKt") | ||
} | ||
|
||
override fun exec() { | ||
val projectLocationAsFile = projectLocation.get().asFile | ||
if (!projectLocationAsFile.resolve(".mps").isDirectory) { | ||
throw GradleException(MpsCheckErrors.noMpsProjectIn(projectLocationAsFile)) | ||
} | ||
|
||
super.exec() | ||
} | ||
|
||
private fun initialModelcheckBackendClasspath() = mpsHome.asFileTree.matching { | ||
include("lib/**/*.jar") | ||
|
||
// add only minimal number of plugins jars that are required by the modelcheck code | ||
// (to avoid conflicts with plugin classloader if custom configured plugins are loaded) | ||
// mps-httpsupport: we need it to print the node url to the console. | ||
// mps-modelchecker: contains used UnresolvedReferencesChecker | ||
// git4idea: has to be on classpath as bundled plugin to be loaded (since 2019.3) | ||
include("plugins/mps-modelchecker/**/*.jar") | ||
include("plugins/mps-httpsupport/**/*.jar") | ||
include("plugins/git4idea/**/*.jar") | ||
} | ||
} | ||
|
||
internal object MpsCheckErrors { | ||
fun noMpsProjectIn(dir: File): String = "Directory does not contain an MPS project: " + dir | ||
} |
Oops, something went wrong.