Skip to content

Commit

Permalink
Rename GlobalConfigDataForSonarInstance to SonarInstance.java
Browse files Browse the repository at this point in the history
  • Loading branch information
kirk-fitz committed Sep 10, 2024
1 parent ba34596 commit 7c21d92
Show file tree
Hide file tree
Showing 23 changed files with 115 additions and 161 deletions.
17 changes: 7 additions & 10 deletions src/main/java/org/quality/gates/jenkins/plugin/BuildDecision.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class BuildDecision {

private final QualityGatesProvider qualityGatesProvider;

public BuildDecision(GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance) {
public BuildDecision(SonarInstance globalConfigDataForSonarInstance) {
qualityGatesProvider = new QualityGatesProvider(globalConfigDataForSonarInstance);
}

Expand All @@ -17,9 +17,7 @@ public BuildDecision(QualityGatesProvider qualityGatesProvider) {
}

public boolean getStatus(
GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance,
JobConfigData jobConfigData,
BuildListener listener)
SonarInstance globalConfigDataForSonarInstance, JobConfigData jobConfigData, BuildListener listener)
throws QGException {
try {
return qualityGatesProvider
Expand All @@ -30,8 +28,7 @@ public boolean getStatus(
}
}

GlobalConfigDataForSonarInstance chooseSonarInstance(
GlobalSonarQualityGatesConfiguration globalConfig, JobConfigData jobConfigData) {
SonarInstance chooseSonarInstance(GlobalSonarQualityGatesConfiguration globalConfig, JobConfigData jobConfigData) {
if (globalConfig.fetchListOfGlobalConfigData().isEmpty()) {
return noSonarInstance(jobConfigData);
} else if (globalConfig.fetchListOfGlobalConfigData().size() == 1) {
Expand All @@ -41,12 +38,12 @@ GlobalConfigDataForSonarInstance chooseSonarInstance(
return multipleSonarInstances(jobConfigData.getSonarInstanceName(), globalConfig);
}

private GlobalConfigDataForSonarInstance noSonarInstance(JobConfigData jobConfigData) {
private SonarInstance noSonarInstance(JobConfigData jobConfigData) {
jobConfigData.setSonarInstanceName("");
return new GlobalConfigDataForSonarInstance();
return new SonarInstance();
}

private GlobalConfigDataForSonarInstance singleSonarInstance(
private SonarInstance singleSonarInstance(
GlobalSonarQualityGatesConfiguration globalConfig, JobConfigData jobConfigData) {
var globalConfigDataForSonarInstance =
globalConfig.fetchListOfGlobalConfigData().get(0);
Expand All @@ -55,7 +52,7 @@ private GlobalConfigDataForSonarInstance singleSonarInstance(
return globalConfigDataForSonarInstance;
}

public GlobalConfigDataForSonarInstance multipleSonarInstances(
public SonarInstance multipleSonarInstances(
String instanceName, GlobalSonarQualityGatesConfiguration globalConfig) {
return globalConfig.getSonarInstanceByName(instanceName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

public class GlobalConfigurationService {

private List<GlobalConfigDataForSonarInstance> listOfGlobalConfigInstances;
private List<SonarInstance> listOfGlobalConfigInstances;

public void setListOfGlobalConfigInstances(List<GlobalConfigDataForSonarInstance> listOfGlobalConfigInstances) {
public void setListOfGlobalConfigInstances(List<SonarInstance> listOfGlobalConfigInstances) {
this.listOfGlobalConfigInstances = listOfGlobalConfigInstances;
}

protected List<GlobalConfigDataForSonarInstance> instantiateGlobalConfigData(JSONObject json) {
protected List<SonarInstance> instantiateGlobalConfigData(JSONObject json) {
listOfGlobalConfigInstances = new ArrayList<>();
var globalDataConfigs = (JSON) json.opt("listOfGlobalConfigData");

Expand Down Expand Up @@ -61,17 +61,17 @@ protected void addGlobalConfigDataForSonarInstance(JSONObject globalConfigData)
var url = globalConfigData.optString("url");

if (!"".equals(name)) {
GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance;
SonarInstance globalConfigDataForSonarInstance;
var token = globalConfigData.optString("token");
if (StringUtils.isNotEmpty(token)) {
globalConfigDataForSonarInstance = new GlobalConfigDataForSonarInstance(
globalConfigDataForSonarInstance = new SonarInstance(
name,
url,
Secret.fromString(Util.fixEmptyAndTrim(globalConfigData.optString("token"))),
timeToWait,
maxWaitTime);
} else {
globalConfigDataForSonarInstance = new GlobalConfigDataForSonarInstance(
globalConfigDataForSonarInstance = new SonarInstance(
name,
url,
globalConfigData.optString("account"),
Expand All @@ -87,7 +87,7 @@ protected void addGlobalConfigDataForSonarInstance(JSONObject globalConfigData)
}

protected boolean containsGlobalConfigWithName(String name) {
for (GlobalConfigDataForSonarInstance globalConfigDataInstance : listOfGlobalConfigInstances) {
for (SonarInstance globalConfigDataInstance : listOfGlobalConfigInstances) {
if (globalConfigDataInstance.getName().equals(name)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Symbol("sonarQualityGates")
public class GlobalSonarQualityGatesConfiguration extends GlobalConfiguration {

private List<GlobalConfigDataForSonarInstance> listOfGlobalConfigData;
private List<SonarInstance> listOfGlobalConfigData;

private final GlobalConfigurationService globalConfigurationService;

Expand All @@ -24,24 +24,22 @@ public GlobalSonarQualityGatesConfiguration() {
}

public GlobalSonarQualityGatesConfiguration(
List<GlobalConfigDataForSonarInstance> listOfGlobalConfigData,
GlobalConfigurationService globalConfigurationService) {
List<SonarInstance> listOfGlobalConfigData, GlobalConfigurationService globalConfigurationService) {
this.listOfGlobalConfigData = listOfGlobalConfigData;
this.globalConfigurationService = globalConfigurationService;
}

public List<GlobalConfigDataForSonarInstance> getListOfGlobalConfigData() {
public List<SonarInstance> getListOfGlobalConfigData() {
load();
return listOfGlobalConfigData;
}

public List<GlobalConfigDataForSonarInstance> fetchListOfGlobalConfigData() {
public List<SonarInstance> fetchListOfGlobalConfigData() {
return listOfGlobalConfigData;
}

@DataBoundSetter
public void setGlobalConfigDataForSonarInstances(
List<GlobalConfigDataForSonarInstance> globalConfigDataForSonarInstances) {
public void setGlobalConfigDataForSonarInstances(List<SonarInstance> globalConfigDataForSonarInstances) {
this.listOfGlobalConfigData = globalConfigDataForSonarInstances;
}

Expand All @@ -61,8 +59,8 @@ public FormValidation doCheckName(@QueryParameter String name) {
return FormValidation.ok();
}

public GlobalConfigDataForSonarInstance getSonarInstanceByName(String name) {
for (GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance : listOfGlobalConfigData) {
public SonarInstance getSonarInstanceByName(String name) {
for (SonarInstance globalConfigDataForSonarInstance : listOfGlobalConfigData) {
if (name.equals(globalConfigDataForSonarInstance.getName())) {
return globalConfigDataForSonarInstance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public class JobConfigurationService {
public ListBoxModel getListOfSonarInstanceNames(GlobalSonarQualityGatesConfiguration globalConfig) {
var listBoxModel = new ListBoxModel();

for (GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance :
globalConfig.fetchListOfGlobalConfigData()) {
for (SonarInstance globalConfigDataForSonarInstance : globalConfig.fetchListOfGlobalConfigData()) {
listBoxModel.add(globalConfigDataForSonarInstance.getName());
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/quality/gates/jenkins/plugin/QGBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class QGBuilder extends Builder {

private final JobExecutionService jobExecutionService;

private GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance;
private SonarInstance globalConfigDataForSonarInstance;

@DataBoundConstructor
public QGBuilder(JobConfigData jobConfigData, GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance) {
public QGBuilder(JobConfigData jobConfigData, SonarInstance globalConfigDataForSonarInstance) {
this.jobConfigData = jobConfigData;
this.buildDecision = new BuildDecision(globalConfigDataForSonarInstance);
this.jobExecutionService = new JobExecutionService();
Expand All @@ -34,7 +34,7 @@ protected QGBuilder(
BuildDecision buildDecision,
JobExecutionService jobExecutionService,
JobConfigurationService jobConfigurationService,
GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance) {
SonarInstance globalConfigDataForSonarInstance) {
this.jobConfigData = jobConfigData;
this.buildDecision = buildDecision;
this.jobExecutionService = jobExecutionService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class QGPublisher extends Recorder {

private final JobExecutionService jobExecutionService;

private GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance;
private SonarInstance globalConfigDataForSonarInstance;

@DataBoundConstructor
public QGPublisher(JobConfigData jobConfigData, GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance) {
public QGPublisher(JobConfigData jobConfigData, SonarInstance globalConfigDataForSonarInstance) {
this.jobConfigData = jobConfigData;
this.buildDecision = new BuildDecision(globalConfigDataForSonarInstance);
this.jobExecutionService = new JobExecutionService();
Expand All @@ -35,7 +35,7 @@ public QGPublisher(
BuildDecision buildDecision,
JobExecutionService jobExecutionService,
JobConfigurationService jobConfigurationService,
GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance) {
SonarInstance globalConfigDataForSonarInstance) {
this.jobConfigData = jobConfigData;
this.buildDecision = buildDecision;
this.jobConfigurationService = jobConfigurationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

public class GlobalConfigDataForSonarInstance extends AbstractDescribableImpl<GlobalConfigDataForSonarInstance> {
public class SonarInstance extends AbstractDescribableImpl<SonarInstance> {

public static final String DEFAULT_URL = "http://localhost:9000";

Expand All @@ -32,15 +32,15 @@ public class GlobalConfigDataForSonarInstance extends AbstractDescribableImpl<Gl

private int maxWaitTime;

public GlobalConfigDataForSonarInstance() {
public SonarInstance() {
this.name = "";
this.sonarUrl = "";
this.username = "";
this.pass = "";
}

@DataBoundConstructor
public GlobalConfigDataForSonarInstance(
public SonarInstance(
String name, String sonarUrl, String username, Secret secretPass, int timeToWait, int maxWaitTime) {
this.name = name;
this.sonarUrl = sonarUrl;
Expand All @@ -50,15 +50,14 @@ public GlobalConfigDataForSonarInstance(
this.maxWaitTime = maxWaitTime;
}

public GlobalConfigDataForSonarInstance(String name, String sonarUrl, String username, String pass) {
public SonarInstance(String name, String sonarUrl, String username, String pass) {
this.name = name;
this.sonarUrl = sonarUrl;
this.username = username;
this.pass = pass;
}

public GlobalConfigDataForSonarInstance(
String name, String sonarUrl, Secret token, int timeToWait, int maxWaitTime) {
public SonarInstance(String name, String sonarUrl, Secret token, int timeToWait, int maxWaitTime) {
this.name = name;
this.sonarUrl = sonarUrl;
this.token = token;
Expand Down Expand Up @@ -130,7 +129,7 @@ public void setToken(String token) {
}

@Extension
public static class DescriptorImpl extends Descriptor<GlobalConfigDataForSonarInstance> {}
public static class DescriptorImpl extends Descriptor<SonarInstance> {}

@Override
public boolean equals(Object o) {
Expand All @@ -142,7 +141,7 @@ public boolean equals(Object o) {
return false;
}

var that = (GlobalConfigDataForSonarInstance) o;
var that = (SonarInstance) o;

if (name != null ? !name.equals(that.name) : that.name != null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import hudson.model.BuildListener;
import org.apache.commons.lang.ArrayUtils;
import org.json.JSONException;
import org.quality.gates.jenkins.plugin.GlobalConfigDataForSonarInstance;
import org.quality.gates.jenkins.plugin.JobConfigData;
import org.quality.gates.jenkins.plugin.QGException;
import org.quality.gates.jenkins.plugin.SonarInstance;

public class QualityGatesProvider {

Expand All @@ -20,7 +20,7 @@ public class QualityGatesProvider {

private final SonarInstanceValidationService sonarInstanceValidationService;

public QualityGatesProvider(GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance) {
public QualityGatesProvider(SonarInstance globalConfigDataForSonarInstance) {
this.qualityGateResponseParser = new QualityGateResponseParser();
this.sonarHttpRequester = SonarHttpRequesterFactory.getSonarHttpRequester(globalConfigDataForSonarInstance);
this.sonarInstanceValidationService = new SonarInstanceValidationService();
Expand All @@ -36,9 +36,7 @@ public QualityGatesProvider(
}

public QualityGatesStatus getAPIResultsForQualityGates(
JobConfigData jobConfigData,
GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance,
BuildListener listener)
JobConfigData jobConfigData, SonarInstance globalConfigDataForSonarInstance, BuildListener listener)
throws JSONException, InterruptedException {
var validatedData = sonarInstanceValidationService.validateData(globalConfigDataForSonarInstance);
var taskAnalysisRunning = true;
Expand Down Expand Up @@ -86,8 +84,7 @@ public QualityGatesStatus getAPIResultsForQualityGates(
return qualityGateResponseParser.getQualityGateResultFromJSON(requesterResult);
}

private String getRequesterResult(
JobConfigData jobConfigData, GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance)
private String getRequesterResult(JobConfigData jobConfigData, SonarInstance globalConfigDataForSonarInstance)
throws QGException {
return sonarHttpRequester.getAPIInfo(jobConfigData, globalConfigDataForSonarInstance);
}
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/org/quality/gates/sonar/api/SonarHttpRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.quality.gates.jenkins.plugin.GlobalConfigDataForSonarInstance;
import org.quality.gates.jenkins.plugin.JobConfigData;
import org.quality.gates.jenkins.plugin.QGException;
import org.quality.gates.jenkins.plugin.SonarInstance;

/**
* @author arkanjoms
Expand All @@ -38,13 +38,13 @@ public abstract class SonarHttpRequester {

/**
* Cached client context for lazy login.
* @see #loginApi(GlobalConfigDataForSonarInstance)
* @see #loginApi(SonarInstance)
*/
private transient HttpClientContext httpClientContext;

/**
* Cached client for lazy login.
* @see #loginApi(GlobalConfigDataForSonarInstance)
* @see #loginApi(SonarInstance)
*/
private transient CloseableHttpClient httpClient;

Expand All @@ -64,7 +64,7 @@ public void setLogged(boolean logged) {
this.logged = logged;
}

private void loginApi(GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance) {
private void loginApi(SonarInstance globalConfigDataForSonarInstance) {
httpClientContext = HttpClientContext.create();

if (StringUtils.isNotEmpty(globalConfigDataForSonarInstance.getToken().getPlainText())) {
Expand Down Expand Up @@ -143,8 +143,7 @@ private String executeGetRequest(CloseableHttpClient client, HttpGet request) th
}
}

String getAPITaskInfo(JobConfigData configData, GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance)
throws QGException {
String getAPITaskInfo(JobConfigData configData, SonarInstance globalConfigDataForSonarInstance) throws QGException {
checkLogged(globalConfigDataForSonarInstance);

var sonarProjectKey = getSonarApiTaskInfoParameter(configData, globalConfigDataForSonarInstance);
Expand All @@ -160,10 +159,9 @@ String getAPITaskInfo(JobConfigData configData, GlobalConfigDataForSonarInstance
protected abstract String getSonarApiTaskInfoUrl();

protected abstract String getSonarApiTaskInfoParameter(
JobConfigData jobConfigData, GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance);
JobConfigData jobConfigData, SonarInstance globalConfigDataForSonarInstance);

String getAPIInfo(JobConfigData configData, GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance)
throws QGException {
String getAPIInfo(JobConfigData configData, SonarInstance globalConfigDataForSonarInstance) throws QGException {
checkLogged(globalConfigDataForSonarInstance);

var sonarApiQualityGates = globalConfigDataForSonarInstance.getSonarUrl()
Expand All @@ -175,8 +173,7 @@ String getAPIInfo(JobConfigData configData, GlobalConfigDataForSonarInstance glo

protected abstract String getSonarApiQualityGatesStatusUrl();

protected String getComponentId(
JobConfigData configData, GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance) {
protected String getComponentId(JobConfigData configData, SonarInstance globalConfigDataForSonarInstance) {
checkLogged(globalConfigDataForSonarInstance);

var sonarApiQualityGates = globalConfigDataForSonarInstance.getSonarUrl()
Expand All @@ -189,7 +186,7 @@ protected String getComponentId(
return component.getComponent().getId();
}

private void checkLogged(GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance) {
private void checkLogged(SonarInstance globalConfigDataForSonarInstance) {
if (!isLogged()) {
loginApi(globalConfigDataForSonarInstance);
}
Expand Down
Loading

0 comments on commit 7c21d92

Please sign in to comment.