Commit f888c3a3 authored by Pierre-Yves Gibello's avatar Pierre-Yves Gibello
Browse files

Added MRL thresholds (metadata) gathering

parent 0f1a0a79
Pipeline #11047 passed with stages
in 2 minutes and 18 seconds
......@@ -11,8 +11,14 @@ import org.ow2.mrl.data.sonar.SonarHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.util.Base64;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
......@@ -165,6 +171,9 @@ public class MainCollector {
out.println(generateScancodeScript(false));
out.println(generateMKTScript(false));
// Retrieve MRL thresholds for metrics (CSV format)
out.println(generateMRLThresholdsScript(false));
out.close();
if (!outputFile.setExecutable(true)) {
LOGGER.error("Failed to make script executable: {}" + outputFile.getAbsolutePath());
......@@ -308,17 +317,16 @@ public class MainCollector {
}
/**
* Credentials, in format "user:password" (like curl "-u" parameter)
* Issues credentials, in format "user:password" (like curl "-u" parameter)
* @param project The project name
* @return The credentials
*/
public String getIssuesCredentials(String project) {
return trim(config.getProperty(project + ".issues.credentials"))
.replace("`", "\\`").replace("'", "\\'").replace("\"", "\\\"");
return formatCredentials(config.getProperty(project + ".issues.credentials"));
}
/**
* Credentials, in format "user:password" (like curl "-u" parameter)
* OMM credentials, in format "user:password" (like curl "-u" parameter)
* @param project The project name
* @return The credentials for the project (or global "omm.credentials" if none)
*/
......@@ -326,12 +334,11 @@ public class MainCollector {
String credentials = null;
if (project != null) credentials = config.getProperty(project + ".omm.credentials"); // by project
if (credentials == null) credentials = config.getProperty("omm.credentials"); // global
return trim(credentials)
.replace("`", "\\`").replace("'", "\\'").replace("\"", "\\\"");
return formatCredentials(credentials);
}
/**
* Credentials, in format "user:password" (like curl "-u" parameter)
* MKT credentials, in format "user:password" (like curl "-u" parameter)
* @param project The project name
* @return The credentials for the project (or global "omm.credentials" if none)
*/
......@@ -339,7 +346,24 @@ public class MainCollector {
String credentials = null;
if (project != null) credentials = config.getProperty(project + ".mkt.credentials"); // by project
if (credentials == null) credentials = config.getProperty("mkt.credentials"); // global
return trim(credentials)
return formatCredentials(credentials);
}
/**
* MRL metadata credentials, in format "user:password" (like curl "-u" parameter)
* @return The credentials for the project (or global "omm.credentials" if none)
*/
public String getMRLCredentials() {
return formatCredentials(config.getProperty("MRL.credentials"));
}
/**
* Parse and format credentials (may include special characters)
* @param credentials The credentials, as read from a configuration file
* @return Ready-to-use credentials for authentication
*/
private String formatCredentials(String credentials) {
return trim(credentials)
.replace("`", "\\`").replace("'", "\\'").replace("\"", "\\\"");
}
......@@ -398,6 +422,14 @@ public class MainCollector {
public String getMKTEndpoint(String project) {
return trim(config.getProperty(project + ".mkt"));
}
/**
* Retrieves MRL thresholds endpoint URL
* @return MRL thresholds endpoint URL
*/
public String getMRLEndpoint() {
return trim(config.getProperty("MRL.thresholds"));
}
/**
* Trim a string that can be null
......@@ -441,7 +473,6 @@ public class MainCollector {
/**
* Generate script part to gather issues data (single project)
*
* @return Script part to gather issues data (single project)
*/
public String generateIssuesScript(String project) {
......@@ -475,7 +506,6 @@ public class MainCollector {
/**
* Generate script to gather SonarQube data (all projects)
* By convention, data files are gathered in configured output dir, and called [project]_sonar.json
*
* @param header Include shell header in script
* @return Script to gather SonarQube data (all projects)
*/
......@@ -493,8 +523,7 @@ public class MainCollector {
}
/**
* Generate script part to gather SonarQube data (single project)
*
* Generate script part to gather SonarQube data (single project
* @return Script part to gather SonarQube data (single project)
*/
public String generateSonarScript(String project) {
......@@ -513,7 +542,6 @@ public class MainCollector {
/**
* Generate script to gather OMM data (all projects)
* By convention, data files are gathered in configured output dir, and called [project]_OMM.xml (or .csv)
*
* @param header Include shell header and creation of output directory in script
* @return Script to gather OMM data (all projects)
*/
......@@ -545,7 +573,6 @@ public class MainCollector {
/**
* Generate script part to gather OMM data (single project)
*
* @return Script part to gather OMM data (single project)
*/
public String generateOMMScript(String project) {
......@@ -565,7 +592,6 @@ public class MainCollector {
/**
* Generate script to gather MKT data (all projects)
* By convention, data files are gathered in configured output dir, and called [project]_MKT.xml
*
* @param header Include shell header in script
* @return Script to gather MKT data (all projects)
*/
......@@ -584,7 +610,6 @@ public class MainCollector {
/**
* Generate script part to gather MKT data (single project)
*
* @return Script part to gather MKT data (single project)
*/
public String generateMKTScript(String project) {
......@@ -597,7 +622,6 @@ public class MainCollector {
/**
* Generate script to gather Scancode data (all projects)
* By convention, data files are gathered in configured output dir, and called [project]_scancode.json
*
* @param header Include shell header in script
* @return Script to gather Scancode data (all projects)
*/
......@@ -616,7 +640,6 @@ public class MainCollector {
/**
* Generate script part to gather Scancode data (single project)
*
* @return Script part to gather Scancode data (single project)
*/
public String generateScancodeScript(String project) {
......@@ -628,4 +651,26 @@ public class MainCollector {
return "cp " + pathOrUrl + " " + getOutputDir(true) + project + "_scancode.json";
}
}
/**
* Generate script to gather MRL thresholds (CSV format).
* Errors are ignored.
* @param header Include shell header in script
* @return Script to gather MRL thresholds
*/
public String generateMRLThresholdsScript(boolean header) {
StringBuilder script = createScriptStringBuilder(header);
String endpoint = getMRLEndpoint();
if(endpoint.length() > 0) { // No empty string
String credentials = getMRLCredentials();
if (credentials.length() > 0) credentials = " -u " + credentials;
script.append("# Fetch MRL thresholds metadata\n");
// Ignore errors: see "||true" at the end
script.append("curl -L -X GET" + credentials + " -H \"Content-Type: text/xml\" '"
+ getMRLEndpoint() + "' > " + getOutputDir(true) + "MRL_thresholds.csv ||true\n");
} else {
script.append("# Warning: no MRL thresholds retrieved (check MRL.thresholds property)\n");
}
return script.toString();
}
}
# MRL metadata endpoints
MRL.thresholds: https://projects.dev.ow2.org/get/ow2/Project_metrics_thresholds
# Scanned projects list
projects: asm, authzforce, clif, docdoku, fractal, fusiondirectory, glpi, imixs, joram, knowage, lemonldap-ng, lutece, ocsinventory, proactive, rocket, sat4j, seedstack, sympa, spoon, telosys, waarp, weblab, xwiki, zenroom
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment