Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/ClojureProjectResolveSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/CodeMetropolis-sz10.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added demo-sz10
Empty file.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package codemetropolis.toolchain.converter.sonarqube;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import codemetropolis.toolchain.commons.cdf.CdfElement;
import codemetropolis.toolchain.commons.cdf.CdfProperty.Type;
Expand Down Expand Up @@ -33,11 +36,17 @@ public SonarQubeConverter(Map<String, String> params) {
resources = new HashMap<>();
cdfElements = new HashMap<>();
}

/**
* Method for getting the projects and turning them into cdfelements, returning a tree
* containing them all.
* */
@Override
public CdfTree createElements(String url) throws CodeMetropolisException {
resources.putAll(getResources(url));


List<SonarResource> projectResources = new ArrayList<>();
List<CdfElement> processedProjects;

CdfTree cdfTree = new CdfTree();
Iterator<Integer> iterator = resources.keySet().iterator();

Expand All @@ -48,11 +57,24 @@ public CdfTree createElements(String url) throws CodeMetropolisException {
Integer rootId = iterator.next();
SonarResource res = resources.get(rootId);
if(Scope.PRJ.equals(res.getScope())){
CdfElement projectElement = createCdfElement(res);
rootElement.addChildElement(projectElement);
projectResources.add(res);
}
}

Stream<SonarResource> resourceStream = projectResources.stream();
if(projectResources.size() > (Runtime.getRuntime().availableProcessors()) * 10){ // not a computationally intensive process, parallelization only provides an advantage when a large number of projects is being processed
resourceStream = resourceStream.parallel();
}
processedProjects = resourceStream.map(this::createCdfElement).collect(Collectors.toList());
// in some cases, a SonarResource in projectResources may have a null element in childIdList causing the above line to fail. This is (most likely) caused by parallel downloading resulting in faulty data. Rerunning the tool usually fixes this issue

for (CdfElement projectElement : processedProjects) {
rootElement.addChildElement(projectElement);
}
System.gc();
// when ran in parallel, threads sometimes free up slowly, making the next step in the converting process slow
// (in some cases making it take longer to finish printing the result to file, negating the advantage won with parallel processing the projects)
// calling gc fixes this issue in most cases

String splitDirsParam = getParameter(SPLIT_DIRS_PARAM_NAME);
if(splitDirsParam != null && Boolean.valueOf(splitDirsParam)) {
processDirHierarchy(cdfTree);
Expand All @@ -68,32 +90,42 @@ private String[] getProjectsInParams() {
}

private Map<Integer, SonarResource> getResources(String url) throws SonarConnectException {
Map<Integer, SonarResource> result = new HashMap<>();
Map<Integer, SonarResource> result;

SonarClient sonarClient = new SonarClient(url, getParameter(USERNAME_PARAM_NAME), getParameter(PASSWORD_PARAM_NAME));
sonarClient.init();

String[] projectRegexList = getProjectsInParams();
List<String> allProjects = sonarClient.getProjectKeys();
Set<String> projects = new LinkedHashSet<>();
Set<String> projects;

if(projectRegexList.length == 0) {
projects.addAll(allProjects);
projects = new LinkedHashSet<>(allProjects);
} else {
for(String p : allProjects) {
for(String regex : projectRegexList) {
if(p.matches(regex)) {
projects.add(p);
break;
}
projects = allProjects.stream().filter(p -> {
for (String regex : projectRegexList) {
if(p.matches(regex))
return true;
}
}
return false;
}).collect(Collectors.toSet());
}

for(String key : projects) {
fireConverterEvent(String.format(Resources.get("sonar_downloading_project"), key));
result.putAll(sonarClient.getProject(key));

Stream<String> projectStream = projects.stream();
if(projects.size() > (Runtime.getRuntime().availableProcessors() * 2)){
// usefulness of parallelization heavily depends on project size, which is unknown at this point.
projectStream = projectStream.parallel();
}
result = projectStream
.peek(projectKey -> fireConverterEvent(String.format(Resources.get("sonar_downloading_project"), projectKey)))
.map(projectKey -> {
try {
return sonarClient.getProject(projectKey);
} catch (SonarConnectException e) {
throw new RuntimeException(e);
}
})
.collect(HashMap::new, HashMap::putAll, Map::putAll);

return result;
}
Expand Down