Skip to content
This repository has been archived by the owner on Aug 21, 2021. It is now read-only.

Commit

Permalink
Migrated from deprecated systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
deepy committed Jun 3, 2019
1 parent ecf53be commit 495b70d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
26 changes: 18 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
<sonar.version>6.7</sonar.version>
<sonar.pluginName>Crowd</sonar.pluginName>
<sonar.pluginClass>org.sonar.plugins.crowd.CrowdPlugin</sonar.pluginClass>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand Down Expand Up @@ -119,14 +121,22 @@

<build>
<plugins>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.17</version>
<extensions>true</extensions>
<configuration>
<pluginClass>${sonar.pluginClass}</pluginClass>
</configuration>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.17</version>
<extensions>true</extensions>
<configuration>
<pluginClass>${sonar.pluginClass}</pluginClass>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
32 changes: 10 additions & 22 deletions src/main/java/org/sonar/plugins/crowd/CrowdConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package org.sonar.plugins.crowd;

import org.sonar.api.config.Settings;
import org.sonar.api.config.Configuration;
import org.sonar.api.server.ServerSide;

/**
Expand All @@ -32,54 +32,42 @@ public class CrowdConfiguration {
static final String KEY_CROWD_APP_NAME = "crowd.application";
static final String KEY_CROWD_APP_PASSWORD = "crowd.password";
static final String FALLBACK_NAME = "sonar";
private final Settings settings;
private final Configuration settings;

/**
* Creates new instance of CrowdConfiguration.
*
* @param settings configuration
*/
public CrowdConfiguration(Settings settings) {
public CrowdConfiguration(Configuration settings) {
this.settings = settings;
}

private String get(String key, Settings settings, String fallback) {
String value = settings.getString(key);
if (value == null) {
return fallback;
}
return value;
}

private String getAndValidate(String key, Settings settings) {
String value = settings.getString(key);
if (value == null) {
throw new IllegalArgumentException(key + " is not set");
}
return value;
}

/**
* The name that the application will use when authenticating with the Crowd server.<br>
* Uses the settings key {@value #KEY_CROWD_APP_NAME}
*/
public String getCrowdApplicationName() {
return get(KEY_CROWD_APP_NAME, settings, FALLBACK_NAME);
return settings.get(KEY_CROWD_APP_NAME).orElse(FALLBACK_NAME);
}

/**
* The password that the application will use when authenticating with the Crowd server.<br>
* Uses the settings key {@value #KEY_CROWD_APP_PASSWORD}
*/
public String getCrowdApplicationPassword() {
return getAndValidate(KEY_CROWD_APP_PASSWORD, settings);
return settings
.get(KEY_CROWD_APP_PASSWORD)
.orElseThrow(() -> new IllegalArgumentException(KEY_CROWD_APP_PASSWORD + " is not set"));
}

/**
* The base URL of the crowd server, e.g. <a href="http://127.0.0.1:8095/crowd">http://127.0.0.1:8095/crowd</a>}.<br>
* Uses the settings key {@value #KEY_CROWD_URL}
*/
public String getCrowdUrl() {
return getAndValidate(KEY_CROWD_URL, settings);
return settings
.get(KEY_CROWD_URL)
.orElseThrow(() -> new IllegalArgumentException(KEY_CROWD_URL + " is not set"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ public class CrowdConfigurationTest {
@Test(expected = IllegalArgumentException.class)
public void crowdUrlMissing() {
MapSettings settings = new MapSettings();
new CrowdConfiguration(settings).getCrowdUrl();
new CrowdConfiguration(settings.asConfig()).getCrowdUrl();
}

@Test(expected = IllegalArgumentException.class)
public void applicationPasswordMissing() {
MapSettings settings = new MapSettings();
settings.setProperty(CrowdConfiguration.KEY_CROWD_URL, "http://localhost:8095");
new CrowdConfiguration(settings).getCrowdApplicationPassword();
new CrowdConfiguration(settings.asConfig()).getCrowdApplicationPassword();
}

@Test
public void usesFallbackForUnsetApplicationName() {
MapSettings settings = new MapSettings();
settings.setProperty(CrowdConfiguration.KEY_CROWD_URL, "http://localhost:8095");
settings.setProperty(CrowdConfiguration.KEY_CROWD_APP_PASSWORD, "secret");
CrowdConfiguration crowdConfiguration = new CrowdConfiguration(settings);
CrowdConfiguration crowdConfiguration = new CrowdConfiguration(settings.asConfig());
assertThat(crowdConfiguration.getCrowdApplicationName(), is(CrowdConfiguration.FALLBACK_NAME));
}

Expand All @@ -55,7 +55,7 @@ public void createsClientProperties() {
settings.setProperty(CrowdConfiguration.KEY_CROWD_URL, "http://localhost:8095");
settings.setProperty(CrowdConfiguration.KEY_CROWD_APP_NAME, "SonarQube");
settings.setProperty(CrowdConfiguration.KEY_CROWD_APP_PASSWORD, "secret");
CrowdConfiguration crowdConfiguration = new CrowdConfiguration(settings);
CrowdConfiguration crowdConfiguration = new CrowdConfiguration(settings.asConfig());

assertThat(crowdConfiguration.getCrowdUrl(), is("http://localhost:8095"));
assertThat(crowdConfiguration.getCrowdApplicationName(), is("SonarQube"));
Expand Down

0 comments on commit 495b70d

Please sign in to comment.