From 04ac3f24da924571a8982737da02777c52bc2723 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Tue, 24 May 2016 17:48:51 +0200 Subject: [PATCH] SONARJNKNS-250 Properly save SQ Scanner selection on jobs --- its/pom.xml | 12 +++- .../com/sonar/it/jenkins/JenkinsTest.java | 12 ++-- .../sonar/it/jenkins/JenkinsWithoutMaven.java | 49 +++++++++------ .../orchestrator/JenkinsOrchestrator.java | 61 ++++++++++--------- .../plugins/sonar/SonarRunnerBuilder.java | 57 ++++++++++------- .../SonarRunnerBuilderSQRunnerSlicer.java | 6 +- .../plugins/sonar/SonarRunnerBuilderTest.java | 13 ++-- .../SonarRunnerBuilderSQRunnerSlicerTest.java | 9 ++- 8 files changed, 129 insertions(+), 90 deletions(-) diff --git a/its/pom.xml b/its/pom.xml index 6bc60ed1..372bcb53 100644 --- a/its/pom.xml +++ b/its/pom.xml @@ -32,12 +32,12 @@ org.sonarsource.orchestrator sonar-orchestrator - 3.10.1 + 3.11-build502 org.seleniumhq.selenium selenium-server - 2.45.0 + 2.53.0 @@ -59,6 +59,14 @@ ${jenkins.runtimeVersion} war + + + + org.sonarsource.scanner.cli + sonar-scanner-cli + 2.6.1 + zip + diff --git a/its/src/test/java/com/sonar/it/jenkins/JenkinsTest.java b/its/src/test/java/com/sonar/it/jenkins/JenkinsTest.java index 5d2d01f5..3e0aabc9 100644 --- a/its/src/test/java/com/sonar/it/jenkins/JenkinsTest.java +++ b/its/src/test/java/com/sonar/it/jenkins/JenkinsTest.java @@ -26,17 +26,16 @@ import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.locator.Location; import com.sonar.orchestrator.locator.URLLocation; - import java.io.File; import java.net.MalformedURLException; import java.net.URL; - import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.sonar.wsclient.services.PropertyUpdateQuery; import org.sonar.wsclient.services.ResourceQuery; + import static org.fest.assertions.Assertions.assertThat; import static org.junit.Assume.assumeFalse; @@ -62,7 +61,8 @@ public static void setUpJenkins() throws MalformedURLException { .installPlugin(URLLocation.create(new URL("http://mirrors.jenkins-ci.org/plugins/filesystem_scm/1.20/filesystem_scm.hpi"))) .installPlugin(sqJenkinsPluginLocation) .configureMavenInstallation() - .configureSonarRunner2_4Installation() + // Single installation + .configureSQScannerInstallation("2.4", 0) .configureMsBuildSQScanner_installation() .configureSonarInstallation(orchestrator); jenkins.checkSavedSonarInstallation(orchestrator); @@ -149,7 +149,7 @@ public void testFreestyleJobWithSonarRunner() throws Exception { String projectKey = "abacus-runner"; assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(projectKey))).isNull(); jenkins - .newFreestyleJobWithSonarRunner(jobName, "-X", new File("projects", "abacus"), + .newFreestyleJobWithSQScanner(jobName, "-X", new File("projects", "abacus"), null, "sonar.projectKey", projectKey, "sonar.projectVersion", "1.0", "sonar.projectName", "Abacus", @@ -186,7 +186,7 @@ public void testFreestyleJobWithSonarRunnerAndBranch() throws Exception { String projectKey = "abacus-runner:branch"; assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(projectKey))).isNull(); BuildResult result = jenkins - .newFreestyleJobWithSonarRunner(jobName, "-X -Duseless=Y -e", new File("projects", "abacus"), + .newFreestyleJobWithSQScanner(jobName, "-X -Duseless=Y -e", new File("projects", "abacus"), null, "sonar.projectKey", "abacus-runner", "sonar.projectVersion", "1.0", "sonar.projectName", "Abacus", @@ -211,7 +211,7 @@ public void testFreestyleJobWithTask() throws Exception { assumeFalse(orchestrator.getServer().version().isGreaterThanOrEquals("5.2")); String jobName = "refresh-views"; BuildResult result = jenkins - .newFreestyleJobWithSonarRunner(jobName, null, new File("projects", "abacus"), "sonar.task", "views") + .newFreestyleJobWithSQScanner(jobName, null, new File("projects", "abacus"), null, "sonar.task", "views") .executeJobQuietly(jobName); // Since views is not installed assertThat(result.getLogs()).contains("Task views does not exist"); diff --git a/its/src/test/java/com/sonar/it/jenkins/JenkinsWithoutMaven.java b/its/src/test/java/com/sonar/it/jenkins/JenkinsWithoutMaven.java index e97e5a31..73acc73a 100644 --- a/its/src/test/java/com/sonar/it/jenkins/JenkinsWithoutMaven.java +++ b/its/src/test/java/com/sonar/it/jenkins/JenkinsWithoutMaven.java @@ -21,10 +21,15 @@ import com.sonar.it.jenkins.orchestrator.JenkinsOrchestrator; import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SynchronousAnalyzer; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.locator.Location; import com.sonar.orchestrator.locator.URLLocation; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -32,11 +37,6 @@ import org.sonar.wsclient.services.PropertyUpdateQuery; import org.sonar.wsclient.services.ResourceQuery; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; - import static org.fest.assertions.Assertions.assertThat; public class JenkinsWithoutMaven { @@ -62,7 +62,8 @@ public static void setUpJenkins() throws IOException { .installPlugin(URLLocation.create(new URL("http://mirrors.jenkins-ci.org/plugins/filesystem_scm/1.20/filesystem_scm.hpi"))) .installPlugin(sqJenkinsPluginLocation) .configureMavenInstallation() - .configureSonarRunner2_4Installation() + .configureSQScannerInstallation("2.4", 0) + .configureSQScannerInstallation("2.6.1", 1) .configureMsBuildSQScanner_installation() .configureSonarInstallation(orchestrator); jenkins.checkSavedSonarInstallation(orchestrator); @@ -75,29 +76,43 @@ public void resetData() throws Exception { } @Test - public void testFreestyleJobWithSonarRunner() throws Exception { - String jobName = "abacus-runner"; - String projectKey = "abacus-runner"; + public void testFreestyleJobWithSonarRunner_use_sq_scanner_2_4() throws Exception { + String jobName = "abacus-runner-sq-2.4"; + String projectKey = "abacus-runner-2.4"; assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(projectKey))).isNull(); - jenkins - .newFreestyleJobWithSonarRunner(jobName, "-X", new File("projects", "abacus"), + BuildResult result = jenkins + .newFreestyleJobWithSQScanner(jobName, "-v", new File("projects", "abacus"), "2.4", "sonar.projectKey", projectKey, "sonar.projectVersion", "1.0", "sonar.projectName", "Abacus", "sonar.sources", "src/main/java") .executeJob(jobName); - waitForComputationOnSQServer(); - assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(projectKey))).isNotNull(); - assertSonarUrlOnJob(jobName, projectKey); - jenkins.assertQGOnProjectPage(jobName); + + assertThat(result.getLogs()).contains("SonarQube Runner 2.4"); } - + + @Test + public void testFreestyleJobWithSonarRunner_use_sq_scanner_2_6_1() throws Exception { + String jobName = "abacus-runner-sq-2.6.1"; + String projectKey = "abacus-runner-2.6.1"; + assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(projectKey))).isNull(); + BuildResult result = jenkins + .newFreestyleJobWithSQScanner(jobName, "-v", new File("projects", "abacus"), "2.6.1", + "sonar.projectKey", projectKey, + "sonar.projectVersion", "1.0", + "sonar.projectName", "Abacus", + "sonar.sources", "src/main/java") + .executeJob(jobName); + + assertThat(result.getLogs()).contains("SonarQube Scanner 2.6.1"); + } + @Test public void testNoSonarPublisher() { String jobName = "no Sonar Publisher"; jenkins.assertNoSonarPublisher(jobName, new File("projects", "noPublisher")); } - + private void assertSonarUrlOnJob(String jobName, String projectKey) { assertThat(jenkins.getSonarUrlOnJob(jobName)).startsWith(orchestrator.getServer().getUrl()); assertThat(jenkins.getSonarUrlOnJob(jobName)).endsWith(projectKey); diff --git a/its/src/test/java/com/sonar/it/jenkins/orchestrator/JenkinsOrchestrator.java b/its/src/test/java/com/sonar/it/jenkins/orchestrator/JenkinsOrchestrator.java index d026d14e..2b2b20f9 100644 --- a/its/src/test/java/com/sonar/it/jenkins/orchestrator/JenkinsOrchestrator.java +++ b/its/src/test/java/com/sonar/it/jenkins/orchestrator/JenkinsOrchestrator.java @@ -19,8 +19,6 @@ */ package com.sonar.it.jenkins.orchestrator; -import javax.annotation.Nullable; - import com.google.common.base.Function; import com.sonar.it.jenkins.orchestrator.container.JenkinsDistribution; import com.sonar.it.jenkins.orchestrator.container.JenkinsServer; @@ -37,8 +35,6 @@ import com.sonar.orchestrator.util.NetworkUtils; import com.sonar.orchestrator.version.Version; import hudson.cli.CLI; -import static org.fest.assertions.Assertions.assertThat; - import java.io.File; import java.io.IOException; import java.net.URL; @@ -47,7 +43,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; - +import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; import org.apache.commons.io.output.WriterOutputStream; import org.apache.commons.lang.StringUtils; @@ -62,7 +58,6 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; -import org.openqa.selenium.internal.Locatable; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.WebDriverWait; @@ -71,6 +66,8 @@ import org.sonar.wsclient.jsonsimple.JSONValue; import org.sonar.wsclient.qualitygate.QualityGates; +import static org.fest.assertions.Assertions.assertThat; + public class JenkinsOrchestrator extends SingleStartExternalResource { private static final Logger LOG = LoggerFactory.getLogger(JenkinsOrchestrator.class); @@ -247,7 +244,8 @@ public JenkinsOrchestrator newFreestyleJobWithMaven(String jobName, File project return this; } - public JenkinsOrchestrator newFreestyleJobWithSonarRunner(String jobName, @Nullable String additionalArgs, File projectPath, String... properties) { + public JenkinsOrchestrator newFreestyleJobWithSQScanner(String jobName, @Nullable String additionalArgs, File projectPath, @Nullable String sqScannerVersion, + String... properties) { newFreestyleJobConfig(jobName, projectPath); findElement(buttonByText("Add build step")).click(); @@ -264,6 +262,10 @@ public JenkinsOrchestrator newFreestyleJobWithSonarRunner(String jobName, @Nulla } setTextValue(findElement(By.name("_.properties")), builder.toString()); + if (sqScannerVersion != null) { + select(findElement(By.name("sonar.sonarScannerName")), getSQScannerInstallName(sqScannerVersion)); + } + if (additionalArgs != null) { setTextValue(findElement(By.name("_.additionalArguments")), additionalArgs); } @@ -296,7 +298,6 @@ public JenkinsOrchestrator newFreestyleJobWithMsBuildSQRunner(String jobName, @N private void activateSonarPostBuildMaven(String branch) { WebElement addPostBuildButton = findElement(buttonByText("Add post-build action")); - scrollToElement(addPostBuildButton); addPostBuildButton.click(); findElement(By.linkText("SonarQube analysis with Maven")).click(); // Here we need to wait for the Sonar step to be really activated @@ -319,7 +320,6 @@ public JenkinsOrchestrator configureMavenInstallation() { driver.get(server.getUrl() + "/configure"); WebElement addMavenButton = findElement(buttonByText("Add Maven")); - scrollToElement(addMavenButton); addMavenButton.click(); setTextValue(findElement(By.name("_.name")), "Maven"); findElement(By.name("hudson-tools-InstallSourceProperty")).click(); @@ -330,49 +330,54 @@ public JenkinsOrchestrator configureMavenInstallation() { } /** - * Scroll to element plus some additional scroll to make element visible even with Jenkins bottom floating bar + * Scroll so that element is centered to make element visible even with Jenkins bottom/top floating bars */ - public void scrollToElement(WebElement e) { - Locatable element = (Locatable) e; - Point p = element.getCoordinates().inViewPort(); + public WebElement scrollTo(WebElement e) { JavascriptExecutor js = (JavascriptExecutor) driver; - js.executeScript("window.scrollTo(" + p.getX() + "," + (p.getY() + 250) + ");"); + js.executeScript( + "const element = arguments[0]; const elementRect = element.getBoundingClientRect(); const absoluteElementTop = elementRect.top + window.pageYOffset; const top = absoluteElementTop - (window.innerHeight / 2); window.scrollTo(0, top);", + e); // Give the time for the floating bar to move at the bottom try { Thread.sleep(1000); } catch (InterruptedException e1) { e1.printStackTrace(); } + return e; } - public JenkinsOrchestrator configureSonarRunner2_4Installation() { + public JenkinsOrchestrator configureSQScannerInstallation(String version, int index) { driver.get(server.getUrl() + "/configure"); WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.textToBePresentInElement(By.id("footer"), "Page generated")); SonarScannerInstaller installer = new SonarScannerInstaller(config.fileSystem()); - File runnerScript = installer.install(Version.create("2.4"), config.fileSystem().workspace()); + File runnerScript = installer.install(Version.create(version), config.fileSystem().workspace(), true); - WebElement addSonarRunnerButton = findElement(buttonByText("Add SonarQube Scanner")); - scrollToElement(addSonarRunnerButton); - addSonarRunnerButton.click(); - setTextValue(findElement(By.name("_.name")), "Sonar Scanner"); - findElement(By.name("hudson-tools-InstallSourceProperty")).click(); - WebElement homeDir = findElement(By.name("_.home")); + if (index > 0) { + findElement(buttonByText("SonarQube Scanner installations...")).click(); + } + + findElement(buttonByText("Add SonarQube Scanner")).click(); + setTextValue(findElement(By.name("_.name"), index), getSQScannerInstallName(version)); + findElement(By.name("hudson-tools-InstallSourceProperty"), index).click(); + WebElement homeDir = findElement(By.name("_.home"), index); setTextValue(homeDir, runnerScript.getParentFile().getParentFile().getAbsolutePath()); findElement(buttonByText("Save")).click(); return this; } + private String getSQScannerInstallName(String version) { + return "SonarQube Scanner " + version; + } + public JenkinsOrchestrator configureMsBuildSQScanner_installation() { driver.get(server.getUrl() + "/configure"); WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.textToBePresentInElement(By.id("footer"), "Page generated")); - WebElement addMSBuildSQRunnerButton = findElement(buttonByText("Add SonarQube Scanner for MSBuild")); - scrollToElement(addMSBuildSQRunnerButton); - addMSBuildSQRunnerButton.click(); + findElement(buttonByText("Add SonarQube Scanner for MSBuild")).click(); setTextValue(findElement(By.name("_.name")), "SQ runner"); findElement(buttonByText("Save")).click(); @@ -556,7 +561,7 @@ public WebDriver getDriver() { public WebElement findElement(By by) { try { - return driver.findElement(by); + return scrollTo(driver.findElement(by)); } catch (NoSuchElementException e) { System.err.println("Element not found. Save screenshot to: target/no_such_element.png"); takeScreenshot(new File("target/no_such_element.png")); @@ -575,7 +580,7 @@ public void assertNoElement(By by) { public WebElement findElement(By by, int index) { try { List elms = driver.findElements(by); - return elms.get(index); + return scrollTo(elms.get(index)); } catch (NoSuchElementException e) { System.err.println("Element not found. Save screenshot to: target/no_such_element.png"); takeScreenshot(new File("target/no_such_element.png")); @@ -612,7 +617,7 @@ public void assertNoSonarPublisher(String jobName, File projectPath) { newFreestyleJobConfig(jobName, projectPath); WebElement addPostBuildButton = findElement(buttonByText("Add post-build action")); - scrollToElement(addPostBuildButton); + scrollTo(addPostBuildButton); addPostBuildButton.click(); findElement(By.linkText("SonarQube analysis with Maven")).click(); assertNoElement(By.xpath("//div[@descriptorid='hudson.plugins.sonar.SonarPublisher']")); diff --git a/src/main/java/hudson/plugins/sonar/SonarRunnerBuilder.java b/src/main/java/hudson/plugins/sonar/SonarRunnerBuilder.java index c35a1550..fb3b9970 100644 --- a/src/main/java/hudson/plugins/sonar/SonarRunnerBuilder.java +++ b/src/main/java/hudson/plugins/sonar/SonarRunnerBuilder.java @@ -33,40 +33,37 @@ */ package hudson.plugins.sonar; -import hudson.plugins.sonar.utils.BuilderUtils; - import com.google.common.annotations.VisibleForTesting; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; import hudson.Launcher; import hudson.Util; -import hudson.model.Action; -import hudson.model.BuildListener; -import hudson.model.TaskListener; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; +import hudson.model.Action; +import hudson.model.BuildListener; import hudson.model.Computer; import hudson.model.JDK; import hudson.model.Run; +import hudson.model.TaskListener; import hudson.plugins.sonar.action.SonarMarkerAction; +import hudson.plugins.sonar.utils.BuilderUtils; import hudson.plugins.sonar.utils.ExtendedArgumentListBuilder; import hudson.plugins.sonar.utils.Logger; import hudson.plugins.sonar.utils.SonarUtils; import hudson.tasks.BuildStepDescriptor; import hudson.tasks.Builder; import hudson.util.ArgumentListBuilder; -import jenkins.model.Jenkins; -import jenkins.tasks.SimpleBuildStep; -import org.apache.commons.lang.StringUtils; -import org.kohsuke.stapler.DataBoundConstructor; - -import javax.annotation.Nullable; - import java.io.IOException; import java.io.StringReader; import java.util.Map.Entry; import java.util.Properties; +import javax.annotation.Nullable; +import jenkins.model.Jenkins; +import jenkins.tasks.SimpleBuildStep; +import org.apache.commons.lang.StringUtils; +import org.kohsuke.stapler.DataBoundConstructor; /** * @since 1.7 @@ -97,8 +94,16 @@ public class SonarRunnerBuilder extends Builder implements SimpleBuildStep { /** * Identifies {@link SonarRunnerInstallation} to be used. * @since 2.0 + * @deprecated since 2.5 + */ + @Deprecated + private transient String sonarRunnerName; + + /** + * Identifies {@link SonarRunnerInstallation} to be used. + * @since 2.5 */ - private String sonarRunnerName; + private String sonarScannerName; /** * Optional task to run @@ -107,10 +112,10 @@ public class SonarRunnerBuilder extends Builder implements SimpleBuildStep { private final String task; @DataBoundConstructor - public SonarRunnerBuilder(String installationName, String sonarRunnerName, String project, String properties, String javaOpts, String jdk, String task, + public SonarRunnerBuilder(String installationName, String sonarScannerName, String project, String properties, String javaOpts, String jdk, String task, String additionalArguments) { this.installationName = installationName; - this.sonarRunnerName = sonarRunnerName; + this.sonarScannerName = sonarScannerName; this.javaOpts = javaOpts; this.project = project; this.properties = properties; @@ -133,12 +138,12 @@ public void setInstallationName(String installationName) { /** * @return name of {@link hudson.plugins.sonar.SonarRunnerInstallation} */ - public String getSonarRunnerName() { - return Util.fixNull(sonarRunnerName); + public String getSonarScannerName() { + return Util.fixNull(sonarScannerName); } - public void setSonarRunnerName(String sonarRunnerName) { - this.sonarRunnerName = sonarRunnerName; + public void setSonarScannerName(String sonarScannerName) { + this.sonarScannerName = sonarScannerName; } /** @@ -196,7 +201,7 @@ public DescriptorImpl getDescriptor() { public SonarRunnerInstallation getSonarRunnerInstallation() { for (SonarRunnerInstallation sri : getDescriptor().getSonarRunnerInstallations()) { - if (sonarRunnerName != null && sonarRunnerName.equals(sri.getName())) { + if (sonarScannerName != null && sonarScannerName.equals(sri.getName())) { return sri; } } @@ -258,7 +263,7 @@ private boolean performInternal(Run run, FilePath workspace, Launcher laun handleErrors(run, listener, sri, startTime, e); r = -1; } - + // with workflows, we don't have realtime access to build logs, so url might be null // if the analyis doesn't succeed, it will also be null SonarUtils.addBuildInfoTo(run, getSonarInstallation().getName()); @@ -333,7 +338,7 @@ boolean populateConfiguration(ExtendedArgumentListBuilder args, Run build, args.appendMasked("sonar.jdbc.username", si.getDatabaseLogin()); args.appendMasked("sonar.jdbc.password", si.getDatabasePassword()); args.append("sonar.host.url", si.getServerUrl()); - if(StringUtils.isNotBlank(si.getServerAuthenticationToken())) { + if (StringUtils.isNotBlank(si.getServerAuthenticationToken())) { args.appendMasked("sonar.login", si.getServerAuthenticationToken()); } else if (StringUtils.isNotBlank(si.getSonarLogin())) { args.appendMasked("sonar.login", si.getSonarLogin()); @@ -404,6 +409,14 @@ public Action getProjectAction(AbstractProject project) { return new SonarMarkerAction(); } + protected Object readResolve() { + // Migrate old field to new field + if (sonarRunnerName != null) { + sonarScannerName = sonarRunnerName; + } + return this; + } + @Extension public static final class DescriptorImpl extends BuildStepDescriptor { diff --git a/src/main/java/hudson/plugins/sonar/configurationslicing/SonarRunnerBuilderSQRunnerSlicer.java b/src/main/java/hudson/plugins/sonar/configurationslicing/SonarRunnerBuilderSQRunnerSlicer.java index 37ea9221..81f72403 100644 --- a/src/main/java/hudson/plugins/sonar/configurationslicing/SonarRunnerBuilderSQRunnerSlicer.java +++ b/src/main/java/hudson/plugins/sonar/configurationslicing/SonarRunnerBuilderSQRunnerSlicer.java @@ -49,7 +49,7 @@ protected static class SonarRunnerBuilderSQRunnerSlicerSpec extends AbstractSona @Override public String getName() { - return "SonarQube (Build Step) - SonarQube Runner Slicer"; + return "SonarQube (Build Step) - SonarQube Scanner Slicer"; } @Override @@ -59,12 +59,12 @@ public String getUrl() { @Override protected String doGetValue(SonarRunnerBuilder builder) { - return defaultValueIfBlank(builder.getSonarRunnerName()); + return defaultValueIfBlank(builder.getSonarScannerName()); } @Override protected void doSetValue(SonarRunnerBuilder builder, String value) { - builder.setSonarRunnerName(nullIfDefaultValue(value)); + builder.setSonarScannerName(nullIfDefaultValue(value)); } @Override diff --git a/src/test/java/hudson/plugins/sonar/SonarRunnerBuilderTest.java b/src/test/java/hudson/plugins/sonar/SonarRunnerBuilderTest.java index 108a31a1..53a4d555 100644 --- a/src/test/java/hudson/plugins/sonar/SonarRunnerBuilderTest.java +++ b/src/test/java/hudson/plugins/sonar/SonarRunnerBuilderTest.java @@ -36,13 +36,15 @@ import com.google.common.annotations.VisibleForTesting; import hudson.EnvVars; import hudson.FilePath; -import hudson.model.BuildListener; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; +import hudson.model.BuildListener; import hudson.model.Node; import hudson.plugins.sonar.utils.ExtendedArgumentListBuilder; import hudson.scm.SCM; import hudson.util.ArgumentListBuilder; +import java.io.File; +import java.io.IOException; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; @@ -53,9 +55,6 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import java.io.File; -import java.io.IOException; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; @@ -111,7 +110,7 @@ public void additionalArgs() { SonarRunnerBuilder builder = new SonarRunnerBuilder(null, null, "myCustomProjectSettings.properties", null, null, null, null, "-X -e"); builder.addAdditionalArguments(args, inst); assertThat(args.toString()).isEqualTo("-Y -Dkey=value -X -e"); - + builder = new SonarRunnerBuilder(null, null, "myCustomProjectSettings.properties", null, null, null, null, "-X"); args.clear(); builder.addAdditionalArguments(args, inst); @@ -124,7 +123,7 @@ private void assertEmptyInsteadOfNull(SonarRunnerBuilder builder) { assertThat(builder.getJavaOpts()).isEmpty(); assertThat(builder.getProject()).isEmpty(); assertThat(builder.getProperties()).isEmpty(); - assertThat(builder.getSonarRunnerName()).isEmpty(); + assertThat(builder.getSonarScannerName()).isEmpty(); assertThat(builder.getAdditionalArguments()).isEmpty(); } @@ -159,7 +158,7 @@ public void shouldPopulateSonarLoginPasswordParameters51() throws IOException, I .contains("-Dsonar.password=sonarpassword") .doesNotContain("-Dsonar.login=token"); } - + @Test public void shouldPopulateSonarLoginPasswordParameters53() throws IOException, InterruptedException { SonarInstallation installation = mock(SonarInstallation.class); diff --git a/src/test/java/hudson/plugins/sonar/configurationslicing/SonarRunnerBuilderSQRunnerSlicerTest.java b/src/test/java/hudson/plugins/sonar/configurationslicing/SonarRunnerBuilderSQRunnerSlicerTest.java index cbbee303..f7051774 100644 --- a/src/test/java/hudson/plugins/sonar/configurationslicing/SonarRunnerBuilderSQRunnerSlicerTest.java +++ b/src/test/java/hudson/plugins/sonar/configurationslicing/SonarRunnerBuilderSQRunnerSlicerTest.java @@ -35,13 +35,12 @@ import hudson.model.FreeStyleProject; import hudson.plugins.sonar.SonarRunnerBuilder; -import org.junit.Rule; -import org.junit.Test; -import org.jvnet.hudson.test.JenkinsRule; - import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; import static org.assertj.core.api.Assertions.assertThat; @@ -71,7 +70,7 @@ public void changeJobAdditionalProperties() throws Exception { newValues.add("SQ Runner 2.4"); spec.setValues(project, newValues); - assertThat(mySonar.getSonarRunnerName()).isEqualTo("SQ Runner 2.4"); + assertThat(mySonar.getSonarScannerName()).isEqualTo("SQ Runner 2.4"); } }