From 9f8ff4aca565e32dbe3b1458362c9e1d531d7f88 Mon Sep 17 00:00:00 2001 From: Joaquim Alvino de Mesquita Neto Date: Mon, 16 Aug 2021 15:54:26 -0300 Subject: [PATCH] Added Jenkinsfile (#1) Adds basic Jenkinsfile to project, and fixes some file permission and multiplatform testing issues. Co-authored-by: Joaquim Neto --- Jenkinsfile | 6 +++++ gradlew | 0 .../dotnetsonar/tasks/internal/OSOps.groovy | 1 - .../internal/SonarScannerInstaller.groovy | 4 ++++ .../tasks/internal/OSOpsSpec.groovy | 3 --- .../internal/SonarScannerInstallerSpec.groovy | 8 +++---- .../gradle/dotnetsonar/utils/SpecUtils.groovy | 22 +++++++++++++++++++ 7 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 Jenkinsfile mode change 100644 => 100755 gradlew diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..d9a77bd --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,6 @@ +#!groovy +@Library('github.com/wooga/atlas-jenkins-pipeline@1.x') _ + +withCredentials([string(credentialsId: 'atlas_plugins_sonar_token', variable: 'sonar_token')]) { + buildGradlePlugin platforms: ['macos','windows', 'linux'], sonarToken: sonar_token +} diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/groovy/wooga/gradle/dotnetsonar/tasks/internal/OSOps.groovy b/src/main/groovy/wooga/gradle/dotnetsonar/tasks/internal/OSOps.groovy index 95ca700..35a79a8 100644 --- a/src/main/groovy/wooga/gradle/dotnetsonar/tasks/internal/OSOps.groovy +++ b/src/main/groovy/wooga/gradle/dotnetsonar/tasks/internal/OSOps.groovy @@ -3,7 +3,6 @@ package wooga.gradle.dotnetsonar.tasks.internal import org.gradle.api.Project import org.gradle.process.ExecSpec - class OSOps { private static String osName = System.getProperty("os.name").toLowerCase() diff --git a/src/main/groovy/wooga/gradle/dotnetsonar/tasks/internal/SonarScannerInstaller.groovy b/src/main/groovy/wooga/gradle/dotnetsonar/tasks/internal/SonarScannerInstaller.groovy index 1383c4e..b3c9670 100644 --- a/src/main/groovy/wooga/gradle/dotnetsonar/tasks/internal/SonarScannerInstaller.groovy +++ b/src/main/groovy/wooga/gradle/dotnetsonar/tasks/internal/SonarScannerInstaller.groovy @@ -42,6 +42,10 @@ class SonarScannerInstaller { unzipper.unzip(zippedFile, installationDir) def scannerFile = findScannerExecutableFile(installationDir) + scannerFile.with { + readable = true + executable = true + } return scannerFile } diff --git a/src/test/groovy/wooga/gradle/dotnetsonar/tasks/internal/OSOpsSpec.groovy b/src/test/groovy/wooga/gradle/dotnetsonar/tasks/internal/OSOpsSpec.groovy index 336f810..2e61af0 100644 --- a/src/test/groovy/wooga/gradle/dotnetsonar/tasks/internal/OSOpsSpec.groovy +++ b/src/test/groovy/wooga/gradle/dotnetsonar/tasks/internal/OSOpsSpec.groovy @@ -101,7 +101,4 @@ class OSOpsSpec extends ProjectSpec { e.message == "File ${falseFile.absolutePath} does not exists" } - - - } diff --git a/src/test/groovy/wooga/gradle/dotnetsonar/tasks/internal/SonarScannerInstallerSpec.groovy b/src/test/groovy/wooga/gradle/dotnetsonar/tasks/internal/SonarScannerInstallerSpec.groovy index 0441528..6e5bc28 100644 --- a/src/test/groovy/wooga/gradle/dotnetsonar/tasks/internal/SonarScannerInstallerSpec.groovy +++ b/src/test/groovy/wooga/gradle/dotnetsonar/tasks/internal/SonarScannerInstallerSpec.groovy @@ -1,7 +1,8 @@ package wooga.gradle.dotnetsonar.tasks.internal import nebula.test.ProjectSpec -import org.gradle.process.ExecSpec + +import static wooga.gradle.dotnetsonar.utils.SpecUtils.execDotnetApp class SonarScannerInstallerSpec extends ProjectSpec { @@ -21,10 +22,9 @@ class SonarScannerInstallerSpec extends ProjectSpec { then: "sonar scanner executable should be executing" scannerExec.exists() scannerExec.canExecute() + scannerExec.canRead() scannerExec.name == "SonarScanner.MSBuild.exe" - def execRes = new GradleShell(project).execute { ExecSpec it -> - it.executable = scannerExec.absolutePath - } + def execRes = execDotnetApp(project, scannerExec) execRes.stdOutString.contains("Using the .NET Framework version of the Scanner for MSBuild") execRes.execResult.exitValue == 1 } diff --git a/src/test/groovy/wooga/gradle/dotnetsonar/utils/SpecUtils.groovy b/src/test/groovy/wooga/gradle/dotnetsonar/utils/SpecUtils.groovy index 21adf92..fd0cf85 100644 --- a/src/test/groovy/wooga/gradle/dotnetsonar/utils/SpecUtils.groovy +++ b/src/test/groovy/wooga/gradle/dotnetsonar/utils/SpecUtils.groovy @@ -1,10 +1,32 @@ package wooga.gradle.dotnetsonar.utils import groovy.json.StringEscapeUtils +import org.gradle.api.Project +import wooga.gradle.dotnetsonar.tasks.internal.GradleShell +import wooga.gradle.dotnetsonar.tasks.internal.OSOps import wooga.gradle.dotnetsonar.tasks.internal.Shell +import wooga.gradle.dotnetsonar.tasks.internal.ShellResult + class SpecUtils { + static ShellResult execDotnetApp(Project project, File app) { + Shell shell = new GradleShell(project) + if(isWindows()) { + return shell.execute { exec -> + exec.executable = app.absolutePath + } + } else { + def mono = OSOps.findInOSPath(shell, "mono").orElseThrow { + throw new FileNotFoundException("Could not find 'mono' executable in OS path") + } + return shell.execute { exec -> + exec.executable = mono.absolutePath + exec.args = [app.absolutePath] + } + } + } + static File emptyTmpFile(String name) { File file = new File(name) file.createNewFile()