Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serverAuthenticationToken being required for configuration via CasC #124

Closed
wants to merge 10 commits into from
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,21 @@
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.7.0</version>
</dependency>
<scope>test</scope>
tom-vanbraband-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>1.32</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>1.32</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/hudson/plugins/sonar/SonarInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public SonarInstallation(String name,
public SonarInstallation(
String name,
String serverUrl,
@Nullable String credentialsId,
@Nullable Secret serverAuthenticationToken,
Smasherr marked this conversation as resolved.
Show resolved Hide resolved
@Nullable String webhookSecretId,
String mojoVersion,
String additionalProperties,
String additionalAnalysisProperties,
@CheckForNull String credentialsId,
@CheckForNull Secret serverAuthenticationToken,
@CheckForNull String webhookSecretId,
@CheckForNull String mojoVersion,
@CheckForNull String additionalProperties,
@CheckForNull String additionalAnalysisProperties,
TriggersConfig triggers) {
this.name = name;
this.serverUrl = serverUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import javax.annotation.CheckForNull;

/**
* Represents a SonarQube Scanner installation in a system.
*/
public class SonarRunnerInstallation extends ToolInstallation implements EnvironmentSpecific<SonarRunnerInstallation>, NodeSpecific<SonarRunnerInstallation> {
private static final long serialVersionUID = 1L;

@DataBoundConstructor
public SonarRunnerInstallation(String name, String home, List<? extends ToolProperty<?>> properties) {
public SonarRunnerInstallation(String name, @CheckForNull String home, List<? extends ToolProperty<?>> properties) {
super(Util.fixEmptyAndTrim(name), Util.fixEmptyAndTrim(home), properties);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/hudson/plugins/sonar/model/TriggersConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.List;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.CheckForNull;

/**
* @author Evgeny Mandrikov
* @since 1.2
Expand All @@ -59,7 +61,7 @@ public TriggersConfig() {
}

@DataBoundConstructor
public TriggersConfig(boolean skipScmCause, boolean skipUpstreamCause, String envVar) {
public TriggersConfig(boolean skipScmCause, boolean skipUpstreamCause, @CheckForNull String envVar) {
this.skipScmCause = skipScmCause;
this.skipUpstreamCause = skipUpstreamCause;
this.envVar = envVar;
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/hudson/plugins/sonar/casc/CasCTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* SonarQube Scanner for Jenkins
* Copyright (C) 2007-2019 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package hudson.plugins.sonar.casc;

import hudson.plugins.sonar.SonarGlobalConfiguration;
import hudson.plugins.sonar.SonarInstallation;
import io.jenkins.plugins.casc.misc.RoundTripAbstractTest;
import jenkins.model.GlobalConfiguration;
import org.jvnet.hudson.test.RestartableJenkinsRule;

import static org.assertj.core.api.Assertions.assertThat;

public class CasCTest extends RoundTripAbstractTest {

@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule restartableJenkinsRule, String s) {
SonarInstallation installation = GlobalConfiguration.all()
.get(SonarGlobalConfiguration.class)
.getInstallations()[0];
assertThat(installation).isNotNull();
}

@Override
protected String stringInLogExpected() {
return "credentialsId = test-id";
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we forgot to link to our contribution guidelines for this project. Sorry about that.

Could you please reformat this code so it follows our code style (config for Eclipse and IntelliJ available here)? From the looks of it, I think only the indentation should be corrected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we forgot to link to our contribution guidelines for this project. Sorry about that.

Could you please reformat this code so it follows our code style (config for Eclipse and IntelliJ available here)? From the looks of it, I think only the indentation should be corrected.

Checkstyle? 🙂

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
unclassified:
sonarglobalconfiguration:
buildWrapperEnabled: true
installations:
- name: "TEST"
credentialsId: "test-id"
serverUrl: "http://url:9000"
triggers:
skipScmCause: true
skipUpstreamCause: true
Smasherr marked this conversation as resolved.
Show resolved Hide resolved