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
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@
<version>1.2.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>1.31</version>
<scope>test</scope>
<!-- TODO: remove after configuration-as-code 1.32 is released -->
<exclusions>
<exclusion>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>1.31</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/hudson/plugins/sonar/SonarInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ 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
String mojoVersion,
String additionalProperties,
String additionalAnalysisProperties,
@CheckForNull String credentialsId,
@CheckForNull Secret serverAuthenticationToken,
@CheckForNull String mojoVersion,
@CheckForNull String additionalProperties,
@CheckForNull String additionalAnalysisProperties,
TriggersConfig triggers) {
this.name = name;
this.serverUrl = serverUrl;
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