Skip to content

Commit

Permalink
Fix jackson java version issue (#53)
Browse files Browse the repository at this point in the history
* qol improvments and renames

* updated properties and extension for easier use, also added buildTools block to extension

* optimize imports

* remove unused methods from osops

* removes unused method from SonarScannerFactory

* project rewrote to use dotnet/netcore as base, mono support dropped (#51)

* Add net.wooga.unity-sonarqube plugin (#52)

* initial implementation for wooga.gradle.unity-sonarqube

* adds windows dotnet installer

* update gradle to 7.6.4
  • Loading branch information
Joaquimmnetto authored Aug 6, 2024
1 parent bde8202 commit a17c12b
Show file tree
Hide file tree
Showing 44 changed files with 1,167 additions and 1,334 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ gradlePlugin {
description = 'This plugin provides tools to run sonarqube scans for .NET solutions'
implementationClass = 'wooga.gradle.dotnetsonar.DotNetSonarqubePlugin'
}
unitySonarqube {
id = 'net.wooga.unity-sonarqube'
displayName = 'Sonarqube plugin for wooga unity projects'
description = 'This plugin provides tools to run sonarqube scans for .NET unity solutions'
implementationClass = 'wooga.gradle.unitysonar.UnitySonarqubePlugin'
}
}
}

Expand All @@ -60,7 +66,11 @@ github {

dependencies {
api 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.2.0'
implementation 'net.wooga.gradle:dotnet:0.3.0'
implementation 'net.wooga.gradle:github:[3,4['
implementation 'net.wooga.gradle:unity:[4,5['
implementation 'net.wooga.gradle:asdf:[1,2['
testImplementation 'com.wooga.spock.extensions:spock-github-extension:0.4.0'
testImplementation 'org.ajoberstar.grgit:grgit-core:4.+'
testImplementation 'com.wooga.gradle:gradle-commons-test:[2,3)'
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@

package wooga.gradle.dotnetsonar

import com.wooga.gradle.test.executable.FakeExecutables
import spock.lang.Unroll
import wooga.gradle.dotnetsonar.tasks.internal.SonarScannerInstaller
import wooga.gradle.dotnetsonar.tasks.utils.PluginIntegrationSpec
import wooga.gradle.dotnetsonar.utils.SpecFakes

import static wooga.gradle.dotnetsonar.utils.SpecUtils.wasExecutedAfter
import static wooga.gradle.dotnetsonar.utils.SpecUtils.wasExecutedBefore
import static wooga.gradle.dotnetsonar.tasks.internal.SonarScannerInstaller.defaultBaseURL
import static wooga.gradle.dotnetsonar.utils.SpecUtils.wrapValueBasedOnType

import static wooga.gradle.dotnetsonar.utils.SpecUtils.*

class SonarScannerExtensionIntegrationSpec extends PluginIntegrationSpec {

def "registers custom build task for sonar scanner"() {
given: "a sonnar scanner executable"
File fakeScannerExec = SpecFakes.argReflectingFakeExecutable("sonarscanner")
given: "a sonar scanner executable"
def fakeScanner = FakeExecutables.argsReflector("sonarscanner", 0)
and: "custom task registering itself on sonar scanner extension"
buildFile << """
${forceAddObjectsToExtension(fakeScannerExec)}
${getSonarScannerExtension("sonarScannerExt")}
${forceAddObjectsToExtension(fakeScanner.executable)}
tasks.register("custom") {
sonarScannerExt.registerBuildTask(it)
sonarScanner.registerBuildTask(it)
}
"""
when: "executing custom task"
Expand All @@ -56,33 +52,37 @@ class SonarScannerExtensionIntegrationSpec extends PluginIntegrationSpec {
and: "unset sonarScannerExecutable property in the extension"

when: "running tasks dependent on sonar scanner executable"
runTasks("sonarScannerBegin")
def result = runTasks("sonarScannerBegin")

then: "dotnet sonar scanner package should be installed at default directory"
def defaultInstallDir = "build/bin/net-sonarscanner/"
new File(projectDir,
"${defaultInstallDir}/${SonarScannerInstaller.EXECUTABLE_NAME}").exists()
result.wasExecuted(":installSonarScanner")
def defaultInstallDir = "build/bin/net-sonarscanner/${defaultVersion}-netcoreapp2.0"
new File(projectDir, "${defaultInstallDir}/${SonarScannerInstaller.DLL_NAME}").exists()

where:
defaultVersion = DotNetSonarqubePluginConventions.scannerInstallVersion.defaultValue.toString()
}

@Unroll
def "installs sonar scanner version #version-net46 in #installDir"() {
def "installs sonar scanner version #version-netcoreapp2.0 in #installDir"() {
given: "installed dotnet sonarscanner plugin"
and: "no pre-existent sonarscanner executable on PATH"
and: "configured sonar scanner extension"
buildFile << """
sonarScanner {
installInfo {
version = "${version}"
installDir = "${installDir}"
installDir = ${wrapValueBasedOnType(installDir, File)}
}
}
"""
when: "running tasks dependent on sonar scanner executable"
runTasks("sonarScannerBegin")
def result = runTasks("sonarScannerBegin")

then: "dotnet sonar scanner package should be installed at default directory"
result.wasExecuted(":installSonarScanner")
new File(projectDir,
"${installDir}/${SonarScannerInstaller.EXECUTABLE_NAME}").exists()
"${installDir}/${SonarScannerInstaller.DLL_NAME}").exists()
where:
version | installDir
"5.2.2.33595" | "bin/fdlr"
Expand All @@ -98,15 +98,16 @@ class SonarScannerExtensionIntegrationSpec extends PluginIntegrationSpec {
buildFile << """
sonarScanner {
installInfo {
sourceURL = "${url}"
installDir = "${installDir}"
installURL = "${url}"
installDir = ${wrapValueBasedOnType(installDir, File)}
}
}
"""
when: "running tasks dependent on sonar scanner executable"
runTasks("sonarScannerBegin")
def result = runTasks("sonarScannerBegin")

then: "dotnet sonar scanner package should be installed at default directory"
result.wasExecuted(":installSonarScanner")
new File(projectDir,
"${installDir}/${SonarScannerInstaller.EXECUTABLE_NAME}").exists()
where:
Expand All @@ -118,20 +119,21 @@ class SonarScannerExtensionIntegrationSpec extends PluginIntegrationSpec {
def "doesn't install sonar scanner if executable already exists on extension"() {
given: "installed dotnet sonarscanner plugin"
and: "pre-existent sonarscanner executable"
def sonarScannerExec = SpecFakes.argReflectingFakeExecutable("sonarscanner.bat")
def sonarScannerExec = FakeExecutables.argsReflector("sonarscanner.bat", 0)
buildFile << """
sonarScanner {
sonarScannerExecutable = ${wrapValueBasedOnType(sonarScannerExec.absolutePath, File)}
sonarScannerExecutable = ${wrapValueBasedOnType(sonarScannerExec.executable.absolutePath, File)}
installInfo {
version = "5.2.1.31210"
}
}
"""

when: "running tasks dependent on sonar scanner executable"
runTasks("sonarScannerBegin")
def result = runTasks("sonarScannerBegin")

then: "sonar scanner should not be downloaded"
result.standardOutput.contains(":installSonarScanner SKIPPED")
def defaultInstallDir = "build/bin/net-sonarscanner/"
!new File(projectDir,
"${defaultInstallDir}/${SonarScannerInstaller.EXECUTABLE_NAME}").exists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@

package wooga.gradle.dotnetsonar.tasks

import org.gradle.process.internal.ExecException
import com.wooga.gradle.test.executable.FakeExecutables
import org.gradle.api.GradleException
import spock.lang.Unroll
import wooga.gradle.dotnetsonar.tasks.utils.PluginIntegrationSpec

import java.nio.file.Paths

import static wooga.gradle.dotnetsonar.utils.FakeExecutable.executionResults
import static wooga.gradle.dotnetsonar.utils.SpecFakes.argReflectingFakeExecutable
import static wooga.gradle.dotnetsonar.utils.SpecUtils.rootCause
import static wooga.gradle.dotnetsonar.utils.SpecUtils.wrapValueBasedOnType

class BuildSolutionTaskIntegrationSpec extends PluginIntegrationSpec {

def setup() {
def fakeSonarScannerExec = argReflectingFakeExecutable("sonarscanner", 0)
buildFile << forceAddObjectsToExtension(fakeSonarScannerExec)
def fakeSonarScanner = FakeExecutables.argsReflector("sonarscanner", 0)
buildFile << forceAddObjectsToExtension(fakeSonarScanner.executable)
}

@Unroll
def "Builds a C# solution with dotnet #subtool #extraArgs command"() {
given: "a msbuild executable"
def fakeBuildExec = argReflectingFakeExecutable("dotnet", 0)
def fakeBuild = FakeExecutables.argsReflector("dotnet-build", 0)
and: "fake solution file"
new File(projectDir, solutionPath).with {
parentFile.mkdirs()
Expand All @@ -46,18 +45,19 @@ class BuildSolutionTaskIntegrationSpec extends PluginIntegrationSpec {
and: "build file with configured task"
buildFile << """
project.tasks.create("solutionBuild", ${BuildSolution.name}) {
dotnetExecutable = ${wrapValueBasedOnType(fakeBuildExec.absolutePath, File)}
executable = ${wrapValueBasedOnType(fakeBuild.executable.absolutePath, File)}
solution = ${wrapValueBasedOnType(solutionPath, File)}
environment = ${wrapValueBasedOnType(environment, Map)}
extraArgs = ${wrapValueBasedOnType(extraArgs, List)}
additionalArguments.addAll(${wrapValueBasedOnType(extraArgs, List)})
}
"""
when:
def result = runTasksSuccessfully("solutionBuild")

then:
def buildResult = executionResults(fakeBuildExec, result)
buildResult.args == subtool + [Paths.get(projectDir.absolutePath, solutionPath).toString()] + extraArgs
def buildResult = fakeBuild.firstResult(result.standardOutput)
def args = [Paths.get(projectDir.absolutePath, solutionPath).toString()] + extraArgs
buildResult.args == subtool + args
buildResult.envs.entrySet().containsAll(environment.entrySet())

where:
Expand All @@ -66,43 +66,10 @@ class BuildSolutionTaskIntegrationSpec extends PluginIntegrationSpec {
"dir/solution.sln" | ["build"] | ["b": "c"] | ["-arg", "/arg:value"]
}


@Unroll
def "Builds a C# solution with msbuild #extraArgs command"() {
given: "a msbuild executable"
def fakeBuildExec = argReflectingFakeExecutable("msBuild", 0)
and: "fake solution file"
new File(projectDir, solutionPath).with {
parentFile.mkdirs()
createNewFile()
}
and: "build file with configured task"
buildFile << """
project.tasks.create("solutionBuild", ${BuildSolution.name}) {
msBuildExecutable = ${wrapValueBasedOnType(fakeBuildExec.absolutePath, File)}
solution = ${wrapValueBasedOnType(solutionPath, File)}
environment = ${wrapValueBasedOnType(environment, Map)}
extraArgs = ${wrapValueBasedOnType(extraArgs, List)}
}
"""
when:
def result = runTasksSuccessfully("solutionBuild")

then:
def buildResult = executionResults(fakeBuildExec, result)
buildResult.args == extraArgs + [Paths.get(projectDir.absolutePath, solutionPath).toString()]
buildResult.envs.entrySet().containsAll(environment.entrySet())

where:
solutionPath | environment | extraArgs
"solution.sln" | ["a": "b"] | []
"solution.sln" | [:] | ["-arg", "/arg:value"]
}

@Unroll
def "#tool build task fails if tool returns non-zero status"() {
def "BuildSolution task fails if tool returns non-zero status"() {
given: "a build executable"
def fakeMsBuildExec = argReflectingFakeExecutable(tool, 1)
def fakeDotnet = FakeExecutables.argsReflector("dotnet", 1)
and: "fake solution file"
new File(projectDir, solutionPath).with {
parentFile.mkdirs()
Expand All @@ -111,7 +78,7 @@ class BuildSolutionTaskIntegrationSpec extends PluginIntegrationSpec {
and: "build file with configured task"
buildFile << """
project.tasks.create("solutionBuild", ${BuildSolution.name}) {
${tool}Executable = ${wrapValueBasedOnType(fakeMsBuildExec.absolutePath, File)}
executable = ${wrapValueBasedOnType(fakeDotnet.executable.absolutePath, File)}
solution = ${wrapValueBasedOnType(solutionPath, File)}
}
"""
Expand All @@ -120,11 +87,9 @@ class BuildSolutionTaskIntegrationSpec extends PluginIntegrationSpec {

then: "should fail on execution with non-zero exit value"
def e = rootCause(result.failure)
e.getClass().name == ExecException.name
e.message.contains(fakeMsBuildExec.absolutePath)
e.getClass().name == GradleException.name
e.message.contains("exit value 1")
where:
tool << ["msBuild", "dotnet"]
solutionPath = "solution.sln"
}
}
Loading

0 comments on commit a17c12b

Please sign in to comment.