Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* SonarQube Scanner for Gradle
* Copyright (C) 2015-2021 SonarSource
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonarqube.gradle;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import javax.annotation.Nullable;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.internal.plugins.DslObject;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.plugins.GroovyBasePlugin;
import org.gradle.api.plugins.GroovyPlugin;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.reporting.SingleFileReport;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetOutput;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.testing.Test;
import org.gradle.testing.jacoco.plugins.JacocoPlugin;
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension;
import org.gradle.testing.jacoco.tasks.JacocoReport;
import org.gradle.util.GradleVersion;
import org.sonarsource.scanner.api.Utils;
import static org.sonarqube.gradle.SonarUtils.appendProp;
import static org.sonarqube.gradle.SonarUtils.exists;
import static org.sonarqube.gradle.SonarUtils.isAndroidProject;
import static org.sonarqube.gradle.SonarUtils.nonEmptyOrNull;
import static org.sonarqube.gradle.SonarUtils.setMainClasspathProps;
import static org.sonarqube.gradle.SonarUtils.setTestClasspathProps;
public class SonarPropertyComputer {
private static final Logger LOGGER = Logging.getLogger(SonarPropertyComputer.class);
private static final Pattern TEST_RESULT_FILE_PATTERN = Pattern.compile("TESTS?-.*\\.xml");
static final String SONAR_SOURCES_PROP = "sonar.sources";
static final String SONAR_TESTS_PROP = "sonar.tests";
private final Map> actionBroadcastMap;
private final Project targetProject;
public SonarPropertyComputer(Map> actionBroadcastMap, Project targetProject) {
this.actionBroadcastMap = actionBroadcastMap;
this.targetProject = targetProject;
}
public Map computeSonarProperties() {
Map properties = new LinkedHashMap<>();
computeSonarProperties(targetProject, properties, "");
if (properties.containsKey("sonar.projectBaseDir")) {
properties.put("sonar.projectBaseDir", SonarUtils.findProjectBaseDir(properties));
}
return properties;
}
private void computeSonarProperties(Project project, Map properties, String prefix) {
SonarQubeExtension extension = project.getExtensions().getByType(SonarQubeExtension.class);
if (extension.isSkipProject()) {
return;
}
Map rawProperties = new LinkedHashMap<>();
addGradleDefaults(project, rawProperties);
if (isAndroidProject(project)) {
AndroidUtils.configureForAndroid(project, extension.getAndroidVariant(), rawProperties);
}
ActionBroadcast actionBroadcast = actionBroadcastMap.get(project.getPath());
if (actionBroadcast != null) {
evaluateSonarPropertiesBlocks(actionBroadcast, rawProperties);
}
if (project.equals(targetProject)) {
addEnvironmentProperties(rawProperties);
addSystemProperties(rawProperties);
}
rawProperties.putIfAbsent(SONAR_SOURCES_PROP, "");
if (project.equals(targetProject)) {
rawProperties.putIfAbsent("sonar.projectKey", computeProjectKey());
} else {
String projectKey = (String) properties.get("sonar.projectKey");
rawProperties.putIfAbsent("sonar.moduleKey", projectKey + project.getPath());
}
convertProperties(rawProperties, prefix, properties);
List enabledChildProjects = project.getChildProjects().values().stream()
.filter(p -> !p.getExtensions().getByType(SonarQubeExtension.class).isSkipProject())
.collect(Collectors.toList());
List skippedChildProjects = project.getChildProjects().values().stream()
.filter(p -> p.getExtensions().getByType(SonarQubeExtension.class).isSkipProject())
.collect(Collectors.toList());
if (!skippedChildProjects.isEmpty()) {
LOGGER.debug("Skipping collecting SonarQube properties on: " + skippedChildProjects.toArray(new Project[0]));
}
if (enabledChildProjects.isEmpty()) {
return;
}
List moduleIds = new ArrayList<>();
for (Project childProject : enabledChildProjects) {
String moduleId = childProject.getPath();
moduleIds.add(moduleId);
String modulePrefix = (prefix.length() > 0) ? (prefix + "." + moduleId) : moduleId;
computeSonarProperties(childProject, properties, modulePrefix);
}
properties.put(convertKey("sonar.modules", prefix), String.join(",", moduleIds));
}
private static void evaluateSonarPropertiesBlocks(ActionBroadcast super SonarQubeProperties> propertiesActions, Map properties) {
SonarQubeProperties sqProperties = new SonarQubeProperties(properties);
propertiesActions.execute(sqProperties);
}
private static void convertProperties(Map rawProperties, final String projectPrefix, final Map properties) {
for (Map.Entry entry : rawProperties.entrySet()) {
String value = convertValue(entry.getValue());
if (value != null) {
properties.put(convertKey(entry.getKey(), projectPrefix), value);
}
}
}
private static String convertKey(String key, final String projectPrefix) {
return projectPrefix.isEmpty() ? key : (projectPrefix + "." + key);
}
private static String convertValue(@Nullable Object value) {
if (value == null) {
return null;
}
if (value instanceof Iterable>) {
String joined = StreamSupport.stream(((Iterable