Skip to content

Commit

Permalink
Merge pull request #13 from lequal/dev
Browse files Browse the repository at this point in the history
Release 1.5.0
  • Loading branch information
louisjdmartin authored Sep 12, 2019
2 parents 1d769b5 + c96a3c7 commit 2057ef2
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 120 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This plugin is free software; you can redistribute it and/or modify it under the
<td><b>2.0.0</b></td>
<td><b>2.1.0</b></td>
<td><b>2.2.0</b></td>
<td><b>3.x.x</b></td>
</tr>
<tr>
<td><b>1.0.0</b></td>
Expand All @@ -46,6 +47,7 @@ This plugin is free software; you can redistribute it and/or modify it under the
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td><b>1.1.0</b></td>
Expand All @@ -55,6 +57,7 @@ This plugin is free software; you can redistribute it and/or modify it under the
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td><b>1.2.0</b></td>
Expand All @@ -64,6 +67,7 @@ This plugin is free software; you can redistribute it and/or modify it under the
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td><b>1.3.0</b></td>
Expand All @@ -73,6 +77,7 @@ This plugin is free software; you can redistribute it and/or modify it under the
<td>x</td>
<td>x</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td><b>1.4.0</b></td>
Expand All @@ -82,6 +87,17 @@ This plugin is free software; you can redistribute it and/or modify it under the
<td>-</td>
<td>-</td>
<td>x</td>
<td>x</td>
</tr>
<tr>
<td><b>1.5.0</b></td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>x</td>
<td>x</td>
</tr>
</table>

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<groupId>fr.cnes.sonar.plugins.scan</groupId>
<artifactId>sonar-cnes-scan-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>1.4</version>
<version>1.5</version>

<name>SonarQube CNES Scan Plugin</name>
<description>CNES plugin for SonarQube that launches analysis directly from the web interface and export reports.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.apiVersion>6.7.1</sonar.apiVersion>
<sonar.apiVersion>7.9</sonar.apiVersion>
<sonar.sslr-squid-bridge.version>2.6.1</sonar.sslr-squid-bridge.version>
<sonar-packaging-maven-plugin.version>1.17</sonar-packaging-maven-plugin.version>
<commons-lang.version>3.7</commons-lang.version>
Expand All @@ -21,7 +21,7 @@
<jdk.min.version>1.8</jdk.min.version>
<pluginUrl>https://cnes.fr</pluginUrl>
<pluginOrganizationName>CNES</pluginOrganizationName>
<jacoco.version>0.8.0</jacoco.version>
<jacoco.version>0.8.4</jacoco.version>
</properties>

<licenses>
Expand Down
68 changes: 0 additions & 68 deletions sonar-cnes-scan-plugin.iml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.utils.text.JsonWriter;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsComponents.SearchProjectsWsResponse;
import org.sonarqube.ws.WsQualityGates;
import org.sonarqube.ws.Components;
import org.sonarqube.ws.Qualitygates;
import org.sonarqube.ws.Qualityprofiles;
import org.sonarqube.ws.client.*;
import org.sonarqube.ws.client.component.SearchProjectsRequest;
import org.sonarqube.ws.client.project.CreateRequest;
import org.sonarqube.ws.client.qualitygate.SelectWsRequest;
import org.sonarqube.ws.client.qualityprofile.AddProjectRequest;
import org.sonarqube.ws.client.components.SearchProjectsRequest;
import org.sonarqube.ws.client.projects.CreateRequest;
import org.sonarqube.ws.client.qualitygates.SelectRequest;
import org.sonarqube.ws.client.qualityprofiles.AddProjectRequest;
import org.sonarqube.ws.client.qualityprofiles.SearchRequest;

import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -111,8 +111,12 @@ public void handle(final Request request, final Response response) throws IOExce
final String name = request.mandatoryParam(
StringManager.string(StringManager.PROJECT_PARAM_NAME_NAME));
// quality profiles of the project to create
final String qualityProfiles = request.mandatoryParam(
StringManager.string(StringManager.PROJECT_PARAM_PROFILES_NAME));
String qualityProfiles = request.getParam(
StringManager.string(StringManager.PROJECT_PARAM_PROFILES_NAME)).getValue();
// Set default value for quality profiles
if (qualityProfiles == null){
qualityProfiles = "";
}
// quality gate of the project to create
final String qualityGate = request.mandatoryParam(
StringManager.string(StringManager.PROJECT_PARAM_GATE_NAME));
Expand Down Expand Up @@ -176,12 +180,11 @@ private Status createProject(final WsClient wsClient, final String key, final St
if (!checkProjectExists(wsClient, key)) {

// prepare a request to ask for the creation of a project
final CreateRequest.Builder requestBuilder = CreateRequest.builder();
requestBuilder.setKey(key);
final CreateRequest requestBuilder = new CreateRequest();
requestBuilder.setProject(key);
requestBuilder.setName(name);
final CreateRequest projectCreateRequest = requestBuilder.build();
// make the project creation request to the server
wsClient.projects().create(projectCreateRequest);
wsClient.projects().create(requestBuilder);
// log success
log(String.format(SUCCESS_PROJECT, name));
status.setMessage(String.format(SUCCESS_PROJECT, name));
Expand Down Expand Up @@ -215,14 +218,14 @@ private boolean checkProjectExists(final WsClient wsClient, final String project

// request to get all projects
final SearchProjectsRequest searchProjectsRequest =
SearchProjectsRequest.builder().setPageSize(PAGE_SIZE).build();
final SearchProjectsWsResponse searchProjectsResponse =
new SearchProjectsRequest().setPs(String.valueOf(PAGE_SIZE));
final Components.SearchProjectsWsResponse searchProjectsResponse =
wsClient.components().searchProjects(searchProjectsRequest);

// iterate on projects
final Iterator<WsComponents.Component> iterator =
final Iterator<Components.Component> iterator =
searchProjectsResponse.getComponentsList().iterator();
WsComponents.Component current;
Components.Component current;

// browse all projects until find the good one
while(iterator.hasNext() && !exist) {
Expand Down Expand Up @@ -276,22 +279,22 @@ private Status setQualityProfiles(final WsClient wsClient, final String key,
// Filter to select only one result, example:
// if you search key to, you can get [to, toto]
// so we have to filter the response's list
final org.sonarqube.ws.client.qualityprofile.SearchWsRequest searchWsRequest =
new org.sonarqube.ws.client.qualityprofile.SearchWsRequest();
final List<QualityProfile> qpList = wsClient.qualityProfiles()

final SearchRequest searchWsRequest =
new SearchRequest();
final List<Qualityprofiles.SearchWsResponse.QualityProfile> qpList = wsClient.qualityprofiles()
.search(searchWsRequest).getProfilesList();
final QualityProfile profile = findQPByKey(qpList, profileKey);
final Qualityprofiles.SearchWsResponse.QualityProfile profile = findQPByKey(qpList, profileKey);

// if there is at means one result we linked it to the project
if(profile!=null) {
// create the link (the request) between the current profile and the project
final AddProjectRequest addProjectRequest = AddProjectRequest.builder()
final AddProjectRequest addProjectRequest = new AddProjectRequest()
.setLanguage(profile.getLanguage())
.setProjectKey(key)
.setQualityProfile(profile.getName())
.build();
.setProject(key)
.setQualityProfile(profile.getName());
// execute the previous request
wsClient.qualityProfiles().addProject(addProjectRequest);
wsClient.qualityprofiles().addProject(addProjectRequest);
// log result
log(String.format(SUCCESS_QUALITYPROFILE, profileKey));
tmpStatus.setMessage(String.format(SUCCESS_QUALITYPROFILE, profileKey));
Expand Down Expand Up @@ -340,25 +343,25 @@ private Status setQualityGate(final WsClient wsClient, final String key,
gson.fromJson(json , QualityGate[].class));

// fill out Sonar Quality Gates
final List<WsQualityGates.QualityGate> qualityGates = new ArrayList<>();
WsQualityGates.QualityGate.Builder qualityGateBuilder;
final List<Qualitygates.QualityGate> qualityGates = new ArrayList<>();
Qualitygates.QualityGate.Builder qualityGateBuilder;
for (final QualityGate q : modelQGList) {
// build and add a new quality gate from model
qualityGateBuilder = WsQualityGates.QualityGate.newBuilder();
qualityGateBuilder.setId(q.getId());
qualityGateBuilder = Qualitygates.QualityGate.newBuilder();
qualityGateBuilder.setId(Long.parseLong(q.getId()));
qualityGateBuilder.setName(q.getName());
qualityGates.add(qualityGateBuilder.build());
}


// look for the wanted quality gate
final WsQualityGates.QualityGate qg = findQGByName(qualityGates, qualityGateName);
final Qualitygates.QualityGate qg = findQGByName(qualityGates, qualityGateName);

if(qg != null) {
// if we found the quality gate we link it to the project
final SelectWsRequest selectWsRequest = new SelectWsRequest()
.setGateId(Long.parseLong(qg.getId())).setProjectKey(key);
wsClient.qualityGates().associateProject(selectWsRequest);
final SelectRequest selectWsRequest = new SelectRequest()
.setGateId(String.valueOf(qg.getId())).setProjectKey(key);
wsClient.qualitygates().select(selectWsRequest);
// setting is a success
status.setSuccess(true);
log(String.format(SUCCESS_QUALITYGATE, qualityGateName));
Expand All @@ -382,14 +385,14 @@ private Status setQualityGate(final WsClient wsClient, final String key,
* @param qualityGateName name of the quality gate to find
* @return the corresponding quality gate or null
*/
private WsQualityGates.QualityGate findQGByName(final List<WsQualityGates.QualityGate> qualityGates,
private Qualitygates.QualityGate findQGByName(final List<Qualitygates.QualityGate> qualityGates,
final String qualityGateName) {
// result that will be returned
WsQualityGates.QualityGate qualityGate = null;
Qualitygates.QualityGate qualityGate = null;

// iterator on the quality gate list
final Iterator<WsQualityGates.QualityGate> iterator = qualityGates.iterator();
WsQualityGates.QualityGate current;
final Iterator<Qualitygates.QualityGate> iterator = qualityGates.iterator();
Qualitygates.QualityGate current;

while(iterator.hasNext() && qualityGate==null) {
current = iterator.next();
Expand All @@ -408,14 +411,14 @@ private WsQualityGates.QualityGate findQGByName(final List<WsQualityGates.Qualit
* @param qualityProfileKey key of the quality profile to find
* @return the corresponding quality profile or null
*/
private QualityProfile findQPByKey(final List<QualityProfile> qualityProfiles,
final String qualityProfileKey) {
private Qualityprofiles.SearchWsResponse.QualityProfile findQPByKey(final List<Qualityprofiles.SearchWsResponse.QualityProfile> qualityProfiles,
final String qualityProfileKey) {
// result that will be returned
QualityProfile qualityProfile = null;
Qualityprofiles.SearchWsResponse.QualityProfile qualityProfile = null;

// iterator on the quality gate list
final Iterator<QualityProfile> iterator = qualityProfiles.iterator();
QualityProfile current;
final Iterator<Qualityprofiles.SearchWsResponse.QualityProfile> iterator = qualityProfiles.iterator();
Qualityprofiles.SearchWsResponse.QualityProfile current;

while(iterator.hasNext() && qualityProfile==null) {
current = iterator.next();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fr/cnes/sonar/plugins/scan/ws/CnesWs.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ private void projectAction(final NewController controller) {
newParam = project.createParam(
StringManager.string(StringManager.PROJECT_PARAM_PROFILES_NAME));
newParam.setDescription(StringManager.string(StringManager.PROJECT_PARAM_PROFILES_DESC));
newParam.setRequired(true);
newParam.setDefaultValue("");
newParam.setRequired(false);
// quality gate parameter
newParam = project.createParam(StringManager.string(StringManager.PROJECT_PARAM_GATE_NAME));
newParam.setDescription(StringManager.string(StringManager.PROJECT_PARAM_GATE_DESC));
Expand Down
Loading

0 comments on commit 2057ef2

Please sign in to comment.