generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #133 from amosproj/Feature/103-Error-message-if-co…
…mpanion-Gradle-plugin-for-MutationMate-is-missing Feature/103 error message if companion gradle plugin for mutation mate is missing
- Loading branch information
Showing
21 changed files
with
643 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
{ | ||
"extends": "recommended", | ||
"rules": { | ||
"BlankLineBeforePackage": { | ||
"enabled": false | ||
}, | ||
"JUnitPublicNonTestMethod": { | ||
"enabled": false | ||
}, | ||
"MethodName": { | ||
"enabled": false | ||
}, | ||
"CatchException": { | ||
"enabled": false | ||
} | ||
"extends": "recommended", | ||
"rules": { | ||
"BlankLineBeforePackage": { | ||
"enabled": false | ||
}, | ||
"JUnitPublicNonTestMethod": { | ||
"enabled": false | ||
}, | ||
"MethodName": { | ||
"enabled": false | ||
}, | ||
"CatchException": { | ||
"enabled": false | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -61,4 +61,3 @@ rules: | |
new-lines: | ||
type: unix | ||
trailing-spaces: disable | ||
|
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 |
---|---|---|
|
@@ -37,3 +37,6 @@ bin/ | |
|
||
# MacOS | ||
.DS_Store | ||
|
||
# Groovy SDK | ||
lib |
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 |
---|---|---|
|
@@ -10,4 +10,3 @@ | |
|
||
# These are Windows script files and should use crlf | ||
*.bat text eol=crlf | ||
|
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
30 changes: 30 additions & 0 deletions
30
...c/main/kotlin/com/amos/pitmutationmate/pitmutationmate/plugincheck/PluginCheckerGroovy.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,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2023 | ||
|
||
package com.amos.pitmutationmate.pitmutationmate.plugincheck | ||
|
||
import org.codehaus.groovy.ast.CodeVisitorSupport | ||
import org.codehaus.groovy.ast.expr.MethodCallExpression | ||
|
||
class PluginCheckerGroovy : CodeVisitorSupport() { | ||
|
||
var pitestPluginAvailable = false | ||
var companionPluginAvailable = false | ||
|
||
override fun visitMethodCallExpression(call: MethodCallExpression?) { | ||
val method = call?.methodAsString | ||
if (method.equals("plugins") || method.equals("apply") || method.equals("version")) { | ||
super.visitMethodCallExpression(call) | ||
} else if (method.equals("id")) { | ||
if (call != null) { | ||
val pluginName = call.arguments.text | ||
if (pluginName.contains("pitest")) { | ||
pitestPluginAvailable = true | ||
} | ||
if (pluginName.contains("io.github.amosproj.pitmutationmate.override")) { | ||
companionPluginAvailable = true | ||
} | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...c/main/kotlin/com/amos/pitmutationmate/pitmutationmate/plugincheck/PluginCheckerKotlin.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,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2023 | ||
|
||
package com.amos.pitmutationmate.pitmutationmate.plugincheck | ||
|
||
import org.jetbrains.kotlin.idea.structuralsearch.visitor.KotlinRecursiveElementVisitor | ||
import org.jetbrains.kotlin.psi.KtCallExpression | ||
|
||
class PluginCheckerKotlin : KotlinRecursiveElementVisitor() { | ||
|
||
var pitestPluginAvailable = false | ||
var companionPluginAvailable = false | ||
|
||
override fun visitCallExpression(expression: KtCallExpression) { | ||
val method = expression.calleeExpression?.text | ||
if (method.equals("plugins")) { | ||
expression.acceptChildren(this) | ||
} | ||
if (method.equals("id")) { | ||
if (expression.valueArgumentList != null) { | ||
for (arg in expression.valueArgumentList!!.arguments) { | ||
val pluginName = arg.text | ||
if (pluginName.contains("pitest")) { | ||
pitestPluginAvailable = true | ||
} | ||
if (pluginName.contains("io.github.amosproj.pitmutationmate.override")) { | ||
companionPluginAvailable = true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
.../main/kotlin/com/amos/pitmutationmate/pitmutationmate/plugincheck/StartupPluginChecker.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,113 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2023 | ||
|
||
package com.amos.pitmutationmate.pitmutationmate.plugincheck | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.startup.ProjectActivity | ||
import com.intellij.openapi.ui.Messages | ||
import com.intellij.openapi.vfs.LocalFileSystem | ||
import com.intellij.psi.PsiManager | ||
import org.apache.commons.io.IOUtils | ||
import org.codehaus.groovy.ast.builder.AstBuilder | ||
import java.io.File | ||
import java.io.FileInputStream | ||
|
||
class StartupPluginChecker : ProjectActivity { | ||
|
||
override suspend fun execute(project: Project) { | ||
ApplicationManager.getApplication().invokeLater { | ||
checkGroovyBuildFile(project) | ||
checkKotlinBuildFile(project) | ||
} | ||
} | ||
|
||
private fun checkKotlinBuildFile(project: Project) { | ||
val buildFileName = "build.gradle.kts" | ||
val kotlinBuildFile = File(project.basePath + "/$buildFileName") | ||
if (kotlinBuildFile.exists()) { | ||
val virtualFile = LocalFileSystem.getInstance().findFileByIoFile(kotlinBuildFile) | ||
if (virtualFile != null) { | ||
val psiFile = PsiManager.getInstance(project).findFile(virtualFile) | ||
val pluginCheckerKotlin = PluginCheckerKotlin() | ||
psiFile?.node?.psi?.accept(pluginCheckerKotlin) | ||
val pitestPluginText = "id(\"info.solidsoft.pitest\") version \"x.y.z\"" | ||
val companionPluginText = "id(\"io.github.amosproj.pitmutationmate.override\") version \"x.y.z\"" | ||
throwErrorMessage( | ||
pluginCheckerKotlin.pitestPluginAvailable, | ||
pluginCheckerKotlin.companionPluginAvailable, | ||
buildFileName, | ||
project, | ||
pitestPluginText, | ||
companionPluginText | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun checkGroovyBuildFile(project: Project) { | ||
val buildFileName = "build.gradle" | ||
val groovyBuildFile = File(project.basePath + "/$buildFileName") | ||
if (groovyBuildFile.exists()) { | ||
val builder = AstBuilder() | ||
val nodes = builder.buildFromString( | ||
IOUtils.toString( | ||
FileInputStream(groovyBuildFile), | ||
"UTF-8" | ||
) | ||
) | ||
val pluginCheckerGroovy = PluginCheckerGroovy() | ||
for (node in nodes) { | ||
node.visit(pluginCheckerGroovy) | ||
} | ||
val pitestPluginText = "id 'info.solidsoft.pitest' version 'x.y.z'" | ||
val companionPluginText = "id 'io.github.amosproj.pitmutationmate.override' version 'x.y.z'" | ||
throwErrorMessage( | ||
pluginCheckerGroovy.pitestPluginAvailable, | ||
pluginCheckerGroovy.companionPluginAvailable, | ||
buildFileName, | ||
project, | ||
pitestPluginText, | ||
companionPluginText | ||
) | ||
} | ||
} | ||
|
||
private fun throwErrorMessage( | ||
pitestPluginAvailable: Boolean, | ||
companionPluginAvailable: Boolean, | ||
buildFileName: String, | ||
project: Project, | ||
pitestPluginText: String, | ||
companionPluginText: String | ||
) { | ||
var errorMessage = "" | ||
if (!pitestPluginAvailable) { | ||
errorMessage += String.format( | ||
ERROR_MESSAGE_PITEST_PLUGIN_MISSING, | ||
buildFileName, | ||
pitestPluginText | ||
) | ||
} | ||
if (!companionPluginAvailable) { | ||
errorMessage += String.format( | ||
ERROR_MESSAGE_COMPANION_PLUGIN_MISSING, | ||
buildFileName, | ||
companionPluginText | ||
) | ||
} | ||
if (errorMessage.isNotEmpty()) { | ||
Messages.showErrorDialog(project, errorMessage, ERROR_MESSAGE_TITLE) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val ERROR_MESSAGE_TITLE = "Plugins for PITMutationPlugin are missing" | ||
private const val ERROR_MESSAGE_PITEST_PLUGIN_MISSING = "The pitest gradle Plugin is missing.\n" + | ||
"Please add a Gradle Pitest Plugin to the %s file like the following:\n" + | ||
"%s\nAnd see the pitest docs for missing configurations of pitest\n\n" | ||
private const val ERROR_MESSAGE_COMPANION_PLUGIN_MISSING = "The Companion Plugin is missing.\n" + | ||
"Please add the following line to your %s file:\n%s\n\n" | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
pitmutationmate/src/test/kotlin/com/amos/pitmutationmate/pitmutationmate/PluginCeckerTest.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,58 @@ | ||
// SPDX-License-Identifier: MIT | ||
// SPDX-FileCopyrightText: 2023 | ||
|
||
package com.amos.pitmutationmate.pitmutationmate | ||
|
||
import com.amos.pitmutationmate.pitmutationmate.plugincheck.PluginCheckerGroovy | ||
import org.apache.commons.io.IOUtils | ||
import org.codehaus.groovy.ast.builder.AstBuilder | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
import java.io.FileInputStream | ||
|
||
class PluginCeckerTest { | ||
|
||
private fun runPluginCheckerForTestFile(testFile: String): PluginCheckerGroovy { | ||
val builder = AstBuilder() | ||
val testFile = File("src/test/resources/test_build_scripts/$testFile") | ||
val nodes = builder.buildFromString( | ||
IOUtils.toString( | ||
FileInputStream(testFile), | ||
"UTF-8" | ||
) | ||
) | ||
val pluginCheck = PluginCheckerGroovy() | ||
for (node in nodes) { | ||
node.visit(pluginCheck) | ||
} | ||
return pluginCheck | ||
} | ||
|
||
@Test | ||
fun checkTestBuildFile1_groovy() { | ||
val pluginCheck = runPluginCheckerForTestFile("testbuild1.gradle") | ||
assert(pluginCheck.pitestPluginAvailable) | ||
assert(pluginCheck.companionPluginAvailable) | ||
} | ||
|
||
@Test | ||
fun checkTestBuildFile2_groovy() { | ||
val pluginCheck = runPluginCheckerForTestFile("testbuild2.gradle") | ||
assert(!pluginCheck.pitestPluginAvailable) | ||
assert(pluginCheck.companionPluginAvailable) | ||
} | ||
|
||
@Test | ||
fun checkTestBuildFile3_groovy() { | ||
val pluginCheck = runPluginCheckerForTestFile("testbuild3.gradle") | ||
assert(pluginCheck.pitestPluginAvailable) | ||
assert(!pluginCheck.companionPluginAvailable) | ||
} | ||
|
||
@Test | ||
fun checkTestBuildFile4_groovy() { | ||
val pluginCheck = runPluginCheckerForTestFile("testbuild4.gradle") | ||
assert(!pluginCheck.pitestPluginAvailable) | ||
assert(!pluginCheck.companionPluginAvailable) | ||
} | ||
} |
Oops, something went wrong.