Skip to content

Commit

Permalink
Merge pull request #302 from cnescatlab/dev
Browse files Browse the repository at this point in the history
Version 4.1.0
  • Loading branch information
Sancretor authored Feb 22, 2022
2 parents f03a424 + 8bde226 commit cabd9e7
Show file tree
Hide file tree
Showing 53 changed files with 3,075 additions and 1,671 deletions.
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.cnes.sonar</groupId>
<artifactId>cnesreport</artifactId>
<version>4.0.0</version>
<version>4.1.0</version>
<packaging>sonar-plugin</packaging>

<name>SonarQube CNES Report</name>
Expand Down Expand Up @@ -153,14 +153,14 @@
<!-- json parsing -->
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.7</version>
<version>2.8.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java -->
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.17.3</version>
<version>4.0.0-rc-2</version>
</dependency>
<dependency>
<!-- openxml generation -->
Expand Down Expand Up @@ -282,6 +282,7 @@
<version>1.0-beta-1</version>
<executions>
<execution>
<?m2e execute onConfiguration?>
<goals>
<goal>native2ascii</goal>
</goals>
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/fr/cnes/sonar/plugin/tools/DefaultBranch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package fr.cnes.sonar.plugin.tools;

import java.util.List;

import org.sonarqube.ws.ProjectBranches.Branch;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.projectbranches.ListRequest;

/**
* utility class used to determine the MAIN branch of a project
*/
public class DefaultBranch {

private DefaultBranch(){}

/**
* Method used to retrieve the MAIN branch from a specified project
* @param wsClient Class needed to interact with SonarQube classes
* @param project Project from which we want the MAIN branch
* @return The MAIN branch of the given project
*/
public static String getDefaultBranchFromProject(WsClient wsClient, String project) {

ListRequest request = new ListRequest().setProject(project);
List<Branch> branchesList = wsClient.projectBranches().list(request).getBranchesList();

String defaultBranch = "";

/** In theory, no need to check if the following condition is matched at least once
* because SonarQube always defines a MAIN branch inside a project
* even if the project is empty
*/
for(Branch branch: branchesList) {
if(branch.getIsMain()) {
defaultBranch = branch.getName();
}
}

return defaultBranch;
}

}
10 changes: 6 additions & 4 deletions src/main/java/fr/cnes/sonar/plugin/ws/ExportTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package fr.cnes.sonar.plugin.ws;

import fr.cnes.sonar.plugin.tools.PluginStringManager;
import fr.cnes.sonar.plugin.tools.DefaultBranch;
import fr.cnes.sonar.plugin.tools.FileTools;
import fr.cnes.sonar.plugin.tools.ZipFolder;
import fr.cnes.sonar.report.ReportCommandLine;
Expand Down Expand Up @@ -126,13 +127,16 @@ public void handle(Request request, Response response) throws BadExportationData
String mdPath = config.get("sonar.cnesreport.md.path").orElse(null);
String xlsxPath = config.get("sonar.cnesreport.xlsx.path").orElse(null);

// create a new client to talk with sonarqube's services
WsClient wsClient = WsClientFactories.getLocal().newClient(request.localConnector());

// prepare params for the report generation
List<String> reportParams = new ArrayList<>(Arrays.asList(
"report",
"-o", outputDirectory.getAbsolutePath(),
"-s", sonarUrl,
"-p", projectKey,
"-b", pBranch.isPresent()?pBranch.getValue(): StringManager.NO_BRANCH,
"-b", pBranch.isPresent()?pBranch.getValue(): DefaultBranch.getDefaultBranchFromProject(wsClient, projectKey),
"-a", request.getParam(PluginStringManager.getProperty("api.report.args.author")).getValue(),
"-t", request.getParam(PluginStringManager.getProperty("api.report.args.token")).getValue(),
"-l", pLanguage.isPresent()?pLanguage.getValue(): StringManager.getProperty(StringManager.DEFAULT_LANGUAGE)
Expand Down Expand Up @@ -175,9 +179,7 @@ public void handle(Request request, Response response) throws BadExportationData
reportParams.add("-c");
}

// create a new client to talk with sonarqube's services
WsClient wsClient = WsClientFactories.getLocal().newClient(request.localConnector());

// Execute report generation
ReportCommandLine.execute(reportParams.toArray(new String[reportParams.size()]), wsClient);

stream.setMediaType("application/zip");
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/fr/cnes/sonar/report/ReportCommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ public static void execute(final String[] args, final WsClient wsClient) throws
throw new SonarQubeException("Impossible to reach SonarQube instance.");
}

message = String.format("Detected SonarQube version: %s", server.getNormalizedVersion());
message = String.format("Detected SonarQube version: %s", server.getVersion());
LOGGER.info(message);

if(!server.isSupported()) {
throw new SonarQubeException("SonarQube instance is not supported by cnesreport.");
LOGGER.warning("This SonarQube version is not supported by this cnesreport version.");
LOGGER.warning("For further information, please refer to the compatibility matrix on the project GitHub page.");
}

// Generate the model of the report.
Expand Down
234 changes: 0 additions & 234 deletions src/main/java/fr/cnes/sonar/report/exporters/MarkdownExporter.java

This file was deleted.

Loading

0 comments on commit cabd9e7

Please sign in to comment.