goals, String
/**
* Should scanner be delayed?
+ *
* @return true if goal is attached to phase and not last in a multi-module project
*/
private boolean shouldDelayExecution() {
@@ -161,9 +161,9 @@ private boolean shouldDelayExecution() {
/**
* Is this execution a 'detached' goal run from the cli. e.g. mvn sonar:sonar
- *
+ *
* See
- Default executionIds for Implied Executions
+ * Default executionIds for Implied Executions
* for explanation of command line execution id.
*
* @return true if this execution is from the command line
@@ -198,7 +198,7 @@ private boolean isSkip(Map properties) {
return true;
}
- if ("true".equalsIgnoreCase(properties.get(ScanProperties.SKIP))) {
+ if ("true".equalsIgnoreCase(properties.get(ScannerProperties.SKIP))) {
getLog().info("SonarQube Scanner analysis skipped");
return true;
}
diff --git a/src/main/java/org/sonarsource/scanner/maven/bootstrap/LogHandler.java b/src/main/java/org/sonarsource/scanner/maven/bootstrap/LogHandler.java
deleted file mode 100644
index 6ff5ed54..00000000
--- a/src/main/java/org/sonarsource/scanner/maven/bootstrap/LogHandler.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * SonarQube Scanner for Maven
- * Copyright (C) 2009-2024 SonarSource SA
- * 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 02110-1301, USA.
- */
-package org.sonarsource.scanner.maven.bootstrap;
-
-import org.apache.maven.plugin.logging.Log;
-import org.sonarsource.scanner.api.LogOutput;
-
-public class LogHandler implements LogOutput {
- private Log mavenLog;
-
- public LogHandler(Log mavenLog) {
- this.mavenLog = mavenLog;
- }
-
- @Override
- public void log(String log, Level level) {
- switch (level) {
- case TRACE:
- case DEBUG:
- mavenLog.debug(log);
- break;
- case WARN:
- mavenLog.warn(log);
- break;
- case ERROR:
- mavenLog.error(log);
- break;
- case INFO:
- default:
- mavenLog.info(log);
- break;
- }
- }
-}
diff --git a/src/main/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverter.java b/src/main/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverter.java
index 532e0055..526c3f7c 100644
--- a/src/main/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverter.java
+++ b/src/main/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverter.java
@@ -48,8 +48,8 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
-import org.sonarsource.scanner.api.ScanProperties;
-import org.sonarsource.scanner.api.ScannerProperties;
+import org.sonarsource.scanner.lib.AnalysisProperties;
+import org.sonarsource.scanner.lib.ScannerProperties;
import org.sonarsource.scanner.maven.bootstrap.MavenCompilerResolver.MavenCompilerConfiguration;
public class MavenProjectConverter {
@@ -121,7 +121,7 @@ public class MavenProjectConverter {
@Nullable
private String specifiedProjectKey;
- private final Properties envProperties;
+ private final Map envProperties;
private final MavenCompilerResolver mavenCompilerResolver;
@@ -136,7 +136,7 @@ public class MavenProjectConverter {
*/
private MavenProject root;
- public MavenProjectConverter(Log log, MavenCompilerResolver mavenCompilerResolver, Properties envProperties) {
+ public MavenProjectConverter(Log log, MavenCompilerResolver mavenCompilerResolver, Map envProperties) {
this.log = log;
this.mavenCompilerResolver = mavenCompilerResolver;
this.envProperties = envProperties;
@@ -154,8 +154,8 @@ public boolean isTestDirsOverridden() {
return testDirsIsOverridden;
}
- public Properties getEnvProperties() {
- return new Properties(envProperties);
+ public Map getEnvProperties() {
+ return new HashMap<>(envProperties);
}
Map configure(List mavenProjects, MavenProject root, Properties userProperties) throws MojoExecutionException {
@@ -167,9 +167,9 @@ Map configure(List mavenProjects, MavenProject roo
this.root = root;
configureModules(mavenProjects, propsByModule);
Map props = new HashMap<>();
- props.put(ScanProperties.PROJECT_KEY, getArtifactKey(root));
+ props.put(AnalysisProperties.PROJECT_KEY, getArtifactKey(root));
Path topLevelDir = rebuildModuleHierarchy(props, propsByModule, root, "");
- props.put(ScanProperties.PROJECT_BASEDIR, topLevelDir.toString());
+ props.put(AnalysisProperties.PROJECT_BASEDIR, topLevelDir.toString());
if (!propsByModule.isEmpty()) {
throw new IllegalStateException(UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE + " \""
+ propsByModule.keySet().iterator().next().getName() + "\" is orphan");
@@ -269,11 +269,11 @@ private static MavenProject findMavenProject(final File modulePath, Collection computeSonarQubeProperties(MavenProject pom) throws MojoExecutionException {
Map props = new HashMap<>();
defineModuleKey(pom, props);
- props.put(ScanProperties.PROJECT_VERSION, pom.getVersion());
- props.put(ScanProperties.PROJECT_NAME, pom.getName());
+ props.put(AnalysisProperties.PROJECT_VERSION, pom.getVersion());
+ props.put(AnalysisProperties.PROJECT_NAME, pom.getName());
String description = pom.getDescription();
if (description != null) {
- props.put(ScanProperties.PROJECT_DESCRIPTION, description);
+ props.put(AnalysisProperties.PROJECT_DESCRIPTION, description);
}
populateJavaAnalyzerProperties(pom, props);
@@ -286,9 +286,9 @@ private Map computeSonarQubeProperties(MavenProject pom) throws
@CheckForNull
private static String specifiedProjectKey(Properties userProperties, MavenProject root) {
- String projectKey = userProperties.getProperty(ScanProperties.PROJECT_KEY);
+ String projectKey = userProperties.getProperty(AnalysisProperties.PROJECT_KEY);
if (projectKey == null) {
- projectKey = root.getModel().getProperties().getProperty(ScanProperties.PROJECT_KEY);
+ projectKey = root.getModel().getProperties().getProperty(AnalysisProperties.PROJECT_KEY);
}
if (projectKey == null || projectKey.isEmpty()) {
return null;
@@ -302,7 +302,7 @@ private static String specifiedProjectKey(Properties userProperties, MavenProjec
* Otherwise, we use the artifact key ({@link MavenProjectConverter#getArtifactKey(MavenProject)}.
*
* @param project The maven submodule for which a key must be generated
- * @param props The existing properties where the module key will be added
+ * @param props The existing properties where the module key will be added
* @return The generated module key
*/
private String defineModuleKey(MavenProject project, Map props) {
@@ -324,7 +324,7 @@ private static void guessEncoding(MavenProject pom, Map props) {
// See http://jira.codehaus.org/browse/SONAR-2151
String encoding = MavenUtils.getSourceEncoding(pom);
if (encoding != null) {
- props.put(ScanProperties.PROJECT_SOURCE_ENCODING, encoding);
+ props.put(AnalysisProperties.PROJECT_SOURCE_ENCODING, encoding);
}
}
@@ -401,7 +401,7 @@ private static void setPropertyIfNotAlreadyExists(Map props, Str
private void synchronizeFileSystemAndOtherProps(MavenProject pom, Map props)
throws MojoExecutionException {
- props.put(ScanProperties.PROJECT_BASEDIR, pom.getBasedir().getAbsolutePath());
+ props.put(AnalysisProperties.PROJECT_BASEDIR, pom.getBasedir().getAbsolutePath());
File buildDir = getBuildDir(pom);
if (buildDir != null) {
props.put(PROPERTY_PROJECT_BUILDDIR, buildDir.getAbsolutePath());
@@ -417,24 +417,24 @@ private void synchronizeFileSystemAndOtherProps(MavenProject pom, Map mainDirs = mainSources(pom);
- props.put(ScanProperties.PROJECT_SOURCE_DIRS, MavenUtils.joinAsCsv(toPaths(mainDirs)));
+ props.put(AnalysisProperties.PROJECT_SOURCE_DIRS, MavenUtils.joinAsCsv(toPaths(mainDirs)));
List testDirs = testSources(pom);
if (!testDirs.isEmpty()) {
- props.put(ScanProperties.PROJECT_TEST_DIRS, MavenUtils.joinAsCsv(toPaths(testDirs)));
+ props.put(AnalysisProperties.PROJECT_TEST_DIRS, MavenUtils.joinAsCsv(toPaths(testDirs)));
} else {
- props.remove(ScanProperties.PROJECT_TEST_DIRS);
+ props.remove(AnalysisProperties.PROJECT_TEST_DIRS);
}
}
@@ -558,7 +558,7 @@ private List mainSources(MavenProject pom) throws MojoExecutionException {
.forEach(sources::add);
}
- return sourcePaths(pom, ScanProperties.PROJECT_SOURCE_DIRS, sources);
+ return sourcePaths(pom, AnalysisProperties.PROJECT_SOURCE_DIRS, sources);
}
/**
@@ -576,7 +576,7 @@ static Collection getPathsToPoms(MavenProject project) {
}
private List testSources(MavenProject pom) throws MojoExecutionException {
- return sourcePaths(pom, ScanProperties.PROJECT_TEST_DIRS, pom.getTestCompileSourceRoots());
+ return sourcePaths(pom, AnalysisProperties.PROJECT_TEST_DIRS, pom.getTestCompileSourceRoots());
}
private List sourcePaths(MavenProject pom, String propertyKey, Collection mavenPaths) throws MojoExecutionException {
@@ -590,8 +590,8 @@ private List sourcePaths(MavenProject pom, String propertyKey, Collection<
List paths = Arrays.asList(StringUtils.split(prop, ","));
filesOrDirs = resolvePaths(paths, pom.getBasedir());
userDefined = true;
- sourceDirsIsOverridden |= propertyKey.equals(ScanProperties.PROJECT_SOURCE_DIRS);
- testDirsIsOverridden |= propertyKey.equals(ScanProperties.PROJECT_TEST_DIRS);
+ sourceDirsIsOverridden |= propertyKey.equals(AnalysisProperties.PROJECT_SOURCE_DIRS);
+ testDirsIsOverridden |= propertyKey.equals(AnalysisProperties.PROJECT_TEST_DIRS);
} else {
removeTarget(pom, mavenPaths);
filesOrDirs = resolvePaths(mavenPaths, pom.getBasedir());
@@ -611,8 +611,8 @@ private String getPropertyByKey(String propertyKey, MavenProject pom) {
return getPropertyByKey(propertyKey, pom, userProperties, envProperties);
}
- public static String getPropertyByKey(String propertyKey, MavenProject pom, Properties userProperties, Properties envProperties) {
- String prop = StringUtils.defaultIfEmpty(userProperties.getProperty(propertyKey), envProperties.getProperty(propertyKey));
+ public static String getPropertyByKey(String propertyKey, MavenProject pom, Properties userProperties, Map envProperties) {
+ String prop = StringUtils.defaultIfEmpty(userProperties.getProperty(propertyKey), envProperties.get(propertyKey));
prop = StringUtils.defaultIfEmpty(prop, pom.getProperties().getProperty(propertyKey));
return prop;
}
diff --git a/src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapper.java b/src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapper.java
index 75ccf964..d71dce36 100644
--- a/src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapper.java
+++ b/src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapper.java
@@ -27,7 +27,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;
@@ -37,11 +36,9 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
-import org.sonarsource.scanner.api.EmbeddedScanner;
-import org.sonarsource.scanner.api.ScanProperties;
-import org.sonarsource.scanner.api.ScannerProperties;
-
-import static org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.getPropertyByKey;
+import org.sonarsource.scanner.lib.AnalysisProperties;
+import org.sonarsource.scanner.lib.ScannerEngineBootstrapper;
+import org.sonarsource.scanner.lib.ScannerEngineFacade;
/**
* Configure properties and bootstrap using SonarQube scanner API
@@ -49,62 +46,41 @@
public class ScannerBootstrapper {
static final String UNSUPPORTED_BELOW_SONARQUBE_56_MESSAGE = "With SonarQube server prior to 5.6, use sonar-maven-plugin <= 3.3";
- private static final String SONARCLOUD_HOST_URL = "https://sonarcloud.io";
private static final Pattern REPORT_PROPERTY_PATTERN = Pattern.compile("^sonar\\..*[rR]eportPaths?$");
private final Log log;
private final MavenSession session;
- private final EmbeddedScanner scanner;
+ private final ScannerEngineBootstrapper bootstrapper;
private final MavenProjectConverter mavenProjectConverter;
private String serverVersion;
- private PropertyDecryptor propertyDecryptor;
+ private final PropertyDecryptor propertyDecryptor;
- public ScannerBootstrapper(Log log, MavenSession session, EmbeddedScanner scanner, MavenProjectConverter mavenProjectConverter, PropertyDecryptor propertyDecryptor) {
+ public ScannerBootstrapper(Log log, MavenSession session, ScannerEngineBootstrapper bootstrapper, MavenProjectConverter mavenProjectConverter,
+ PropertyDecryptor propertyDecryptor) {
this.log = log;
this.session = session;
- this.scanner = scanner;
+ this.bootstrapper = bootstrapper;
this.mavenProjectConverter = mavenProjectConverter;
this.propertyDecryptor = propertyDecryptor;
}
- public void execute() throws MojoExecutionException {
- try {
- logEnvironmentInformation();
- scanner.start();
- serverVersion = scanner.serverVersion();
+ public boolean execute() throws MojoExecutionException {
+ logEnvironmentInformation();
+ try (ScannerEngineFacade engineFacade = bootstrapper.bootstrap()) {
- if (isSonarCloudUsed()) {
+ if (engineFacade.isSonarCloud()) {
log.info("Communicating with SonarCloud");
} else {
- if (serverVersion != null) {
- log.info("Communicating with SonarQube Server " + serverVersion);
- }
+ serverVersion = engineFacade.getServerVersion();
+ log.info("Communicating with SonarQube Server " + serverVersion);
checkSQVersion();
}
-
- if (log.isDebugEnabled()) {
- scanner.setGlobalProperty("sonar.verbose", "true");
- }
-
- scanner.execute(collectProperties());
+ return engineFacade.analyze(collectProperties());
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
- // TODO remove this workaround when discovering if the sevrer is SC or SQ is available through the API
- private boolean isSonarCloudUsed() {
- return session.getProjects().stream()
- // We can use EnvProperties from MavenProjectConverter as they are initialized at construction time,
- // but we can't use UserProperties from the MavenProjectConverter as they are only initialized
- // in the "collectProperties" method.
- .map(project ->
- getPropertyByKey(ScannerProperties.HOST_URL, project, session.getUserProperties(), mavenProjectConverter.getEnvProperties())
- )
- .filter(Objects::nonNull)
- .anyMatch(hostUrl -> hostUrl.startsWith(SONARCLOUD_HOST_URL));
- }
-
@VisibleForTesting
Map collectProperties()
throws MojoExecutionException {
@@ -127,9 +103,9 @@ Map collectProperties()
if (shouldCollectAllSources(userProperties)) {
log.info("Parameter " + MavenScannerProperties.PROJECT_SCAN_ALL_SOURCES + " is enabled. The scanner will attempt to collect additional sources.");
if (mavenProjectConverter.isSourceDirsOverridden()) {
- log.warn(notCollectingAdditionalSourcesBecauseOf(ScanProperties.PROJECT_SOURCE_DIRS));
+ log.warn(notCollectingAdditionalSourcesBecauseOf(AnalysisProperties.PROJECT_SOURCE_DIRS));
} else if (mavenProjectConverter.isTestDirsOverridden()) {
- log.warn(notCollectingAdditionalSourcesBecauseOf(ScanProperties.PROJECT_TEST_DIRS));
+ log.warn(notCollectingAdditionalSourcesBecauseOf(AnalysisProperties.PROJECT_TEST_DIRS));
} else {
boolean shouldCollectJavaAndKotlinSources = isUserDefinedJavaBinaries(userProperties);
collectAllSources(props, shouldCollectJavaAndKotlinSources);
@@ -162,11 +138,11 @@ private static Set excludedReportFiles(Map props) {
@VisibleForTesting
void collectAllSources(Map props, boolean shouldCollectJavaAndKotlinSources) {
- String projectBasedir = props.get(ScanProperties.PROJECT_BASEDIR);
+ String projectBasedir = props.get(AnalysisProperties.PROJECT_BASEDIR);
// Exclude the files and folders covered by sonar.sources and sonar.tests (and sonar.exclusions) as computed by the MavenConverter
// Combine all the sonar.sources at the top-level and by module
List coveredSources = props.entrySet().stream()
- .filter(k -> k.getKey().endsWith(ScanProperties.PROJECT_SOURCE_DIRS) || k.getKey().endsWith(ScanProperties.PROJECT_TEST_DIRS))
+ .filter(k -> k.getKey().endsWith(AnalysisProperties.PROJECT_SOURCE_DIRS) || k.getKey().endsWith(AnalysisProperties.PROJECT_TEST_DIRS))
.map(Map.Entry::getValue)
.filter(value -> !value.isEmpty())
.flatMap(value -> MavenUtils.splitAsCsv(value).stream())
@@ -183,9 +159,9 @@ void collectAllSources(Map props, boolean shouldCollectJavaAndKo
.map(file -> file.toAbsolutePath().toString())
.collect(Collectors.toList());
List mergedSources = new ArrayList<>();
- mergedSources.addAll(MavenUtils.splitAsCsv(props.get(ScanProperties.PROJECT_SOURCE_DIRS)));
+ mergedSources.addAll(MavenUtils.splitAsCsv(props.get(AnalysisProperties.PROJECT_SOURCE_DIRS)));
mergedSources.addAll(collectedSources);
- props.put(ScanProperties.PROJECT_SOURCE_DIRS, MavenUtils.joinAsCsv(mergedSources));
+ props.put(AnalysisProperties.PROJECT_SOURCE_DIRS, MavenUtils.joinAsCsv(mergedSources));
} catch (IOException e) {
log.warn(e);
}
diff --git a/src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerFactory.java b/src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapperFactory.java
similarity index 82%
rename from src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerFactory.java
rename to src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapperFactory.java
index 480af008..e4563bc8 100644
--- a/src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerFactory.java
+++ b/src/main/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapperFactory.java
@@ -24,7 +24,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
-import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.maven.execution.MavenSession;
@@ -32,51 +31,48 @@
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.settings.Proxy;
-import org.sonarsource.scanner.api.EmbeddedScanner;
-import org.sonarsource.scanner.api.LogOutput;
+import org.sonarsource.scanner.lib.ScannerEngineBootstrapper;
-public class ScannerFactory {
+public class ScannerBootstrapperFactory {
private static final String UNKNOWN_PROXY_PROTOCOL_MESSAGE = "Setting proxy properties:" +
" one or multiple protocols of the active proxy (id: %s) are not supported (protocols: %s).";
- private final LogOutput logOutput;
private final RuntimeInformation runtimeInformation;
private final MavenSession session;
- private final boolean debugEnabled;
private final PropertyDecryptor propertyDecryptor;
- private final Properties envProps;
+ private final Map envProps;
private final Log log;
private final MojoExecution mojoExecution;
- public ScannerFactory(LogOutput logOutput, Log log, RuntimeInformation runtimeInformation, MojoExecution mojoExecution, MavenSession session,
- Properties envProps, PropertyDecryptor propertyDecryptor) {
- this.logOutput = logOutput;
+ public ScannerBootstrapperFactory(Log log, RuntimeInformation runtimeInformation, MojoExecution mojoExecution, MavenSession session,
+ Map envProps, PropertyDecryptor propertyDecryptor) {
this.log = log;
this.runtimeInformation = runtimeInformation;
this.mojoExecution = mojoExecution;
this.session = session;
- this.debugEnabled = log.isDebugEnabled();
this.envProps = envProps;
this.propertyDecryptor = propertyDecryptor;
}
- public EmbeddedScanner create() {
+ public ScannerEngineBootstrapper create() {
setProxySystemProperties();
- EmbeddedScanner scanner = EmbeddedScanner.create("ScannerMaven", mojoExecution.getVersion() + "/" + runtimeInformation.getMavenVersion(), logOutput);
-
- scanner.addGlobalProperties(createGlobalProperties());
-
- if (debugEnabled) {
- scanner.setGlobalProperty("sonar.verbose", "true");
+ ScannerEngineBootstrapper scanner = createScannerEngineBootstrapper("ScannerMaven", mojoExecution.getVersion() + "/" + runtimeInformation.getMavenVersion());
+ scanner.addBootstrapProperties(createGlobalProperties());
+ if (log.isDebugEnabled()) {
+ scanner.setBootstrapProperty("sonar.verbose", "true");
}
return scanner;
}
+ ScannerEngineBootstrapper createScannerEngineBootstrapper(String app, String version) {
+ return ScannerEngineBootstrapper.create(app, version);
+ }
+
public Map createGlobalProperties() {
Map p = new HashMap<>();
MavenUtils.putAll(session.getCurrentProject().getProperties(), p);
- MavenUtils.putAll(envProps, p);
+ p.putAll(envProps);
MavenUtils.putAll(session.getSystemProperties(), p);
MavenUtils.putAll(session.getUserProperties(), p);
p.putAll(propertyDecryptor.decryptProperties(p));
diff --git a/src/test/java/org/sonarsource/scanner/maven/SonarQubeMojoTest.java b/src/test/java/org/sonarsource/scanner/maven/SonarQubeMojoTest.java
index 997e2322..b3263603 100644
--- a/src/test/java/org/sonarsource/scanner/maven/SonarQubeMojoTest.java
+++ b/src/test/java/org/sonarsource/scanner/maven/SonarQubeMojoTest.java
@@ -45,7 +45,6 @@
import org.assertj.core.data.MapEntry;
import org.junit.Rule;
import org.junit.Test;
-import org.sonarsource.scanner.maven.TimestampLoggerTest.TestLog;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
@@ -321,10 +320,10 @@ private File executeProject(String projectName, String goal, String... propertie
private Plugin createSonarPluginFrom(PluginDescriptor pluginDescriptor, String goal, MavenProject project) {
String version = null;
Pattern versionPattern = Pattern.compile("(?:" +
- "sonar|" +
- "org\\.codehaus\\.mojo:sonar-maven-plugin|" +
- "org\\.sonarsource\\.scanner\\.maven:sonar-maven-plugin" +
- "):([^:]+):sonar");
+ "sonar|" +
+ "org\\.codehaus\\.mojo:sonar-maven-plugin|" +
+ "org\\.sonarsource\\.scanner\\.maven:sonar-maven-plugin" +
+ "):([^:]+):sonar");
Matcher matcher = versionPattern.matcher(goal);
if (matcher.matches()) {
version = matcher.group(1);
@@ -339,7 +338,7 @@ private Plugin createSonarPluginFrom(PluginDescriptor pluginDescriptor, String g
String pluginGroupId = plugin.getGroupId();
if ((pluginGroupId == null || pluginGroupId.equals(pluginDescriptor.getGroupId())) &&
pluginDescriptor.getArtifactId().equals(plugin.getArtifactId()) &&
- plugin.getVersion() != null){
+ plugin.getVersion() != null) {
version = plugin.getVersion();
break;
}
diff --git a/src/main/java/org/sonarsource/scanner/maven/TimestampLogger.java b/src/test/java/org/sonarsource/scanner/maven/TestLog.java
similarity index 62%
rename from src/main/java/org/sonarsource/scanner/maven/TimestampLogger.java
rename to src/test/java/org/sonarsource/scanner/maven/TestLog.java
index e76bdee1..5a98d788 100644
--- a/src/main/java/org/sonarsource/scanner/maven/TimestampLogger.java
+++ b/src/test/java/org/sonarsource/scanner/maven/TestLog.java
@@ -19,102 +19,106 @@
*/
package org.sonarsource.scanner.maven;
-import java.time.LocalTime;
-import java.time.format.DateTimeFormatter;
-
+import java.util.ArrayList;
+import java.util.List;
import org.apache.maven.plugin.logging.Log;
-public class TimestampLogger implements Log {
- private final DateTimeFormatter timeFormatter;
- private final Log log;
+public class TestLog implements Log {
+ public void setLogLevel(LogLevel logLevel) {
+ this.logLevel = logLevel;
+ }
- public TimestampLogger(Log log) {
- this.log = log;
- this.timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS ");
+ public enum LogLevel {
+ DEBUG,
+ INFO,
+ WARN,
+ ERROR,
}
- @Override
- public void debug(CharSequence content) {
- log.debug(getCurrentTimeStamp() + content);
+ private LogLevel logLevel;
+ public final List logs = new ArrayList<>();
+
+ public TestLog(LogLevel logLevel) {
+ this.logLevel = logLevel;
}
@Override
- public void debug(CharSequence content, Throwable error) {
- log.debug(getCurrentTimeStamp() + content, error);
+ public boolean isDebugEnabled() {
+ return logLevel == LogLevel.DEBUG;
}
@Override
- public void info(CharSequence content) {
- log.info(getCurrentTimeStamp() + content);
+ public void debug(CharSequence content) {
+ logs.add("[DEBUG] " + content);
}
@Override
- public void info(CharSequence content, Throwable error) {
- log.info(getCurrentTimeStamp() + content, error);
+ public void debug(CharSequence content, Throwable error) {
+ debug(content);
}
@Override
- public void warn(CharSequence content) {
- log.warn(getCurrentTimeStamp() + content);
+ public void debug(Throwable error) {
+ debug(error.getMessage());
}
@Override
- public void warn(CharSequence content, Throwable error) {
- log.warn(getCurrentTimeStamp() + content, error);
+ public boolean isInfoEnabled() {
+ return logLevel == LogLevel.INFO;
}
@Override
- public void error(CharSequence content) {
- log.error(getCurrentTimeStamp() + content);
+ public void info(CharSequence content) {
+ logs.add("[INFO] " + content);
}
@Override
- public void error(CharSequence content, Throwable error) {
- log.error(getCurrentTimeStamp() + content, error);
+ public void info(CharSequence content, Throwable error) {
+ info(content);
}
- private String getCurrentTimeStamp() {
- LocalTime currentTime = LocalTime.now();
- return currentTime.format(timeFormatter);
+ @Override
+ public void info(Throwable error) {
+ info(error.getMessage());
}
@Override
- public boolean isDebugEnabled() {
- return log.isDebugEnabled();
+ public boolean isWarnEnabled() {
+ return logLevel == LogLevel.WARN;
}
@Override
- public void debug(Throwable error) {
- log.debug(getCurrentTimeStamp(), error);
+ public void warn(CharSequence content) {
+ logs.add("[WARN] " + content);
}
@Override
- public boolean isInfoEnabled() {
- return log.isInfoEnabled();
+ public void warn(CharSequence content, Throwable error) {
+ warn(content);
}
@Override
- public void info(Throwable error) {
- log.info(getCurrentTimeStamp(), error);
+ public void warn(Throwable error) {
+ warn(error.getMessage());
}
@Override
- public boolean isWarnEnabled() {
- return log.isWarnEnabled();
+ public boolean isErrorEnabled() {
+ return logLevel == LogLevel.ERROR;
}
@Override
- public void warn(Throwable error) {
- log.warn(getCurrentTimeStamp(), error);
+ public void error(CharSequence content) {
+ logs.add("[ERROR] " + content);
}
@Override
- public boolean isErrorEnabled() {
- return log.isErrorEnabled();
+ public void error(CharSequence content, Throwable error) {
+ error(content);
}
@Override
public void error(Throwable error) {
- log.error(getCurrentTimeStamp(), error);
+ error(error.getMessage());
}
}
diff --git a/src/test/java/org/sonarsource/scanner/maven/TimestampLoggerTest.java b/src/test/java/org/sonarsource/scanner/maven/TimestampLoggerTest.java
deleted file mode 100644
index 53f91911..00000000
--- a/src/test/java/org/sonarsource/scanner/maven/TimestampLoggerTest.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * SonarQube Scanner for Maven
- * Copyright (C) 2009-2024 SonarSource SA
- * 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 02110-1301, USA.
- */
-package org.sonarsource.scanner.maven;
-
-import java.time.LocalTime;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.maven.plugin.logging.Log;
-import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-class TimestampLoggerTest {
-
- @Test
- void all_messages_are_timestamped() {
- TestLog mavenLog = new TestLog(TestLog.LogLevel.DEBUG);
- TimestampLogger logger = new TimestampLogger(mavenLog);
-
- LocalTime expectedCurrentTime = LocalTime.of(10, 10, 30);
-
- try (MockedStatic localTimeMockedStatic = Mockito.mockStatic(LocalTime.class)) {
- localTimeMockedStatic.when(LocalTime::now).thenReturn(expectedCurrentTime);
-
- logger.debug("My debug message");
- logger.debug("My debug message", new IllegalArgumentException());
- logger.debug(new IllegalArgumentException());
- logger.info("My info message");
- logger.info("My info message", new IllegalArgumentException());
- logger.info(new IllegalArgumentException());
- logger.warn("My warn message");
- logger.warn("My warn message", new IllegalArgumentException());
- logger.warn(new IllegalArgumentException());
- logger.error("My error message");
- logger.error("My error message", new IllegalArgumentException());
- logger.error(new IllegalArgumentException());
- }
-
-
- assertThat(mavenLog.logs).containsOnly(
- "[DEBUG] 10:10:30.000 My debug message",
- "[DEBUG] 10:10:30.000 My debug message",
- "[DEBUG] 10:10:30.000 ",
- "[INFO] 10:10:30.000 My info message",
- "[INFO] 10:10:30.000 My info message",
- "[INFO] 10:10:30.000 ",
- "[WARN] 10:10:30.000 My warn message",
- "[WARN] 10:10:30.000 My warn message",
- "[WARN] 10:10:30.000 ",
- "[ERROR] 10:10:30.000 My error message",
- "[ERROR] 10:10:30.000 My error message",
- "[ERROR] 10:10:30.000 "
- );
- }
-
- @Test
- void log_level_matches_underlying_maven_log_level() {
- TestLog debugLevelLog = new TestLog(TestLog.LogLevel.DEBUG);
- TestLog infoLevelLog = new TestLog(TestLog.LogLevel.INFO);
- TestLog warnLevelLog = new TestLog(TestLog.LogLevel.WARN);
- TestLog errorLevelLog = new TestLog(TestLog.LogLevel.ERROR);
-
- assertThat(new TimestampLogger(debugLevelLog).isDebugEnabled()).isTrue();
- assertThat(new TimestampLogger(debugLevelLog).isInfoEnabled()).isFalse();
- assertThat(new TimestampLogger(debugLevelLog).isWarnEnabled()).isFalse();
- assertThat(new TimestampLogger(debugLevelLog).isErrorEnabled()).isFalse();
-
- assertThat(new TimestampLogger(infoLevelLog).isDebugEnabled()).isFalse();
- assertThat(new TimestampLogger(infoLevelLog).isInfoEnabled()).isTrue();
- assertThat(new TimestampLogger(infoLevelLog).isWarnEnabled()).isFalse();
- assertThat(new TimestampLogger(infoLevelLog).isErrorEnabled()).isFalse();
-
- assertThat(new TimestampLogger(warnLevelLog).isDebugEnabled()).isFalse();
- assertThat(new TimestampLogger(warnLevelLog).isInfoEnabled()).isFalse();
- assertThat(new TimestampLogger(warnLevelLog).isWarnEnabled()).isTrue();
- assertThat(new TimestampLogger(warnLevelLog).isErrorEnabled()).isFalse();
-
- assertThat(new TimestampLogger(errorLevelLog).isDebugEnabled()).isFalse();
- assertThat(new TimestampLogger(errorLevelLog).isInfoEnabled()).isFalse();
- assertThat(new TimestampLogger(errorLevelLog).isWarnEnabled()).isFalse();
- assertThat(new TimestampLogger(errorLevelLog).isErrorEnabled()).isTrue();
- }
-
- public static class TestLog implements Log {
- public enum LogLevel {
- DEBUG,
- INFO,
- WARN,
- ERROR,
- }
-
- public LogLevel logLevel;
- public final List logs = new ArrayList<>();
-
- public TestLog(LogLevel logLevel) {
- this.logLevel = logLevel;
- }
-
- public void setLogLevel(LogLevel logLevel) {
- this.logLevel = logLevel;
- }
-
- @Override
- public boolean isDebugEnabled() {
- return logLevel == LogLevel.DEBUG;
- }
-
- @Override
- public void debug(CharSequence content) {
- logs.add("[DEBUG] " + content);
- }
-
- @Override
- public void debug(CharSequence content, Throwable error) {
- debug(content);
- }
-
- @Override
- public void debug(Throwable error) {
- debug(error.getMessage());
- }
-
- @Override
- public boolean isInfoEnabled() {
- return logLevel == LogLevel.INFO;
- }
-
- @Override
- public void info(CharSequence content) {
- logs.add("[INFO] " + content);
- }
-
- @Override
- public void info(CharSequence content, Throwable error) {
- info(content);
- }
-
- @Override
- public void info(Throwable error) {
- info(error.getMessage());
- }
-
- @Override
- public boolean isWarnEnabled() {
- return logLevel == LogLevel.WARN;
- }
-
- @Override
- public void warn(CharSequence content) {
- logs.add("[WARN] " + content);
- }
-
- @Override
- public void warn(CharSequence content, Throwable error) {
- warn(content);
- }
-
- @Override
- public void warn(Throwable error) {
- warn(error.getMessage());
- }
-
- @Override
- public boolean isErrorEnabled() {
- return logLevel == LogLevel.ERROR;
- }
-
- @Override
- public void error(CharSequence content) {
- logs.add("[ERROR] " + content);
- }
-
- @Override
- public void error(CharSequence content, Throwable error) {
- error(content);
- }
-
- @Override
- public void error(Throwable error) {
- error(error.getMessage());
- }
- }
-}
diff --git a/src/test/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverterTest.java b/src/test/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverterTest.java
index 4804d97a..25758e0f 100644
--- a/src/test/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverterTest.java
+++ b/src/test/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverterTest.java
@@ -26,6 +26,7 @@
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
@@ -35,7 +36,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
-import org.sonarsource.scanner.api.ScanProperties;
+import org.sonarsource.scanner.lib.AnalysisProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
@@ -51,7 +52,7 @@ class MavenProjectConverterTest {
private Log log;
- private Properties env;
+ private final Map env = new HashMap<>();
private MavenProjectConverter projectConverter;
@@ -60,14 +61,13 @@ public void prepare() {
log = mock(Log.class);
MavenCompilerResolver mavenCompilerResolver = mock(MavenCompilerResolver.class);
when(mavenCompilerResolver.extractConfiguration(any())).thenReturn(Optional.empty());
- env = new Properties();
projectConverter = new MavenProjectConverter(log, mavenCompilerResolver, env);
}
@Test
void convertSingleModuleProject() throws Exception {
MavenProject project = createProject(new Properties(), "jar");
-
+ assertThat(projectConverter.getEnvProperties()).isEmpty();
Map props = projectConverter.configure(Collections.singletonList(project),
project, new Properties());
assertThat(props)
@@ -110,7 +110,9 @@ void shouldIncludePomIfRequested() throws Exception {
@Test
void shouldUseEnvironment() throws Exception {
env.put("sonar.projectKey", "com.foo:anotherProject");
- MavenProject project = createProject(new Properties(), "jar");
+ var projectProps = new Properties();
+ projectProps.put("project.build.sourceEncoding", "UTF-8");
+ MavenProject project = createProject(projectProps, "jar");
Map props = projectConverter.configure(Collections.singletonList(project), project, new Properties());
assertThat(props).containsEntry("sonar.projectKey", "com.foo:anotherProject")
@@ -221,14 +223,14 @@ void convertMultiModuleProject() throws Exception {
Properties userProperties = new Properties();
String userProjectKey = "user-project-key";
- userProperties.put(ScanProperties.PROJECT_KEY, userProjectKey);
+ userProperties.put(AnalysisProperties.PROJECT_KEY, userProjectKey);
Map propsWithUserProjectKey = projectConverter.configure(Arrays.asList(module12, module11, module1, module2, root),
root, userProperties);
assertThat(propsWithUserProjectKey).containsEntry("sonar.projectKey", userProjectKey);
String customProjectKey = "custom-project-key";
- root.getModel().getProperties().setProperty(ScanProperties.PROJECT_KEY, customProjectKey);
+ root.getModel().getProperties().setProperty(AnalysisProperties.PROJECT_KEY, customProjectKey);
Map propsWithCustomProjectKey = projectConverter.configure(Arrays.asList(module12, module11, module1, module2, root),
root, new Properties());
@@ -640,7 +642,7 @@ void two_modules_in_same_folder() throws Exception {
@Test
void submodules_are_not_assigned_user_provided_project_key_from_parent() throws MojoExecutionException, IOException {
Properties rootPomProperties = new Properties();
- rootPomProperties.put(ScanProperties.PROJECT_KEY, "the_greatest_project_key_there_ever_was");
+ rootPomProperties.put(AnalysisProperties.PROJECT_KEY, "the_greatest_project_key_there_ever_was");
File baseDir = temp.toFile();
baseDir.mkdirs();
MavenProject root = createProject(rootPomProperties, "pom");
@@ -662,11 +664,11 @@ void submodules_are_not_assigned_user_provided_project_key_from_parent() throws
new Properties()
);
- assertThat(properties.get(ScanProperties.PROJECT_KEY))
+ assertThat(properties.get(AnalysisProperties.PROJECT_KEY))
.isNotNull()
.isEqualTo("the_greatest_project_key_there_ever_was");
String keyPrefixForModule1 = module1.getGroupId() + ":" + module1.getArtifactId() + ".";
- assertThat(properties).doesNotContainKey(keyPrefixForModule1 + ScanProperties.PROJECT_KEY);
+ assertThat(properties).doesNotContainKey(keyPrefixForModule1 + AnalysisProperties.PROJECT_KEY);
}
@Test
diff --git a/src/test/java/org/sonarsource/scanner/maven/bootstrap/ScannerFactoryTest.java b/src/test/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapperFactoryTest.java
similarity index 66%
rename from src/test/java/org/sonarsource/scanner/maven/bootstrap/ScannerFactoryTest.java
rename to src/test/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapperFactoryTest.java
index d7508557..6a6f7c3d 100644
--- a/src/test/java/org/sonarsource/scanner/maven/bootstrap/ScannerFactoryTest.java
+++ b/src/test/java/org/sonarsource/scanner/maven/bootstrap/ScannerBootstrapperFactoryTest.java
@@ -20,6 +20,8 @@
package org.sonarsource.scanner.maven.bootstrap;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.monitor.logging.DefaultLog;
@@ -33,38 +35,37 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
-import org.sonarsource.scanner.api.EmbeddedScanner;
-import org.sonarsource.scanner.api.LogOutput;
+import org.sonarsource.scanner.lib.ScannerEngineBootstrapper;
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-class ScannerFactoryTest {
- private LogOutput logOutput;
- private RuntimeInformation runtimeInformation;
- private MojoExecution mojoExecution;
- private MavenSession mavenSession;
- private MavenProject rootProject;
- private PropertyDecryptor propertyDecryptor;
- private Properties envProps;
+class ScannerBootstrapperFactoryTest {
+ private final RuntimeInformation runtimeInformation = mock(RuntimeInformation.class, Mockito.RETURNS_DEEP_STUBS);
+ private final MojoExecution mojoExecution = mock(MojoExecution.class);
+ private final MavenSession mavenSession = mock(MavenSession.class);
+ private final MavenProject rootProject = mock(MavenProject.class);
+ private final PropertyDecryptor propertyDecryptor = new PropertyDecryptor(mock(Log.class), mock(SecDispatcher.class));
+ private final Map envProps = new HashMap<>();
+
+ private final Log log = mock(Log.class);
+ private final ScannerBootstrapperFactory underTest = spy(new ScannerBootstrapperFactory(log, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor));
+ private final ScannerEngineBootstrapper mockBootstrapper = mock(ScannerEngineBootstrapper.class);
private Proxy httpsProxy;
@BeforeEach
public void setUp() {
- logOutput = mock(LogOutput.class);
- runtimeInformation = mock(RuntimeInformation.class, Mockito.RETURNS_DEEP_STUBS);
- mavenSession = mock(MavenSession.class);
- rootProject = mock(MavenProject.class);
- mojoExecution = mock(MojoExecution.class);
- envProps = new Properties();
Properties system = new Properties();
system.put("system", "value");
@@ -80,7 +81,7 @@ public void setUp() {
when(mavenSession.getSettings()).thenReturn(new Settings());
when(rootProject.getProperties()).thenReturn(root);
when(mavenSession.getCurrentProject()).thenReturn(rootProject);
- propertyDecryptor = new PropertyDecryptor(mock(Log.class), mock(SecDispatcher.class));
+ when(underTest.createScannerEngineBootstrapper(anyString(), anyString())).thenReturn(mockBootstrapper);
// Set up default proxy
httpsProxy = new Proxy();
@@ -115,9 +116,7 @@ void http_proxy_properties_are_derived_from_maven_settings() {
settings.setProxies(Collections.singletonList(proxy));
when(mavenSession.getSettings()).thenReturn(settings);
- Log log = mock(Log.class);
- ScannerFactory factory = new ScannerFactory(logOutput, log, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor);
- factory.create();
+ underTest.create();
assertThat(System.getProperty("http.proxyHost")).isEqualTo("myhost");
assertThat(System.getProperty("https.proxyHost")).isNull();
}
@@ -128,9 +127,7 @@ void https_proxy_properties_are_derived_from_maven_settings() {
settings.setProxies(Collections.singletonList(httpsProxy));
when(mavenSession.getSettings()).thenReturn(settings);
- Log log = mock(Log.class);
- ScannerFactory factory = new ScannerFactory(logOutput, log, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor);
- factory.create();
+ underTest.create();
assertThat(System.getProperty("https.proxyHost")).isEqualTo("myhost");
assertThat(System.getProperty("https.proxyPort")).isEqualTo("443");
assertThat(System.getProperty("http.proxyUser")).isEqualTo("toto");
@@ -150,9 +147,7 @@ void http_and_https_proxy_properties_are_derived_from_maven_settings() {
settings.setProxies(Collections.singletonList(proxyWithBothProtocols));
when(mavenSession.getSettings()).thenReturn(settings);
- Log log = mock(Log.class);
- ScannerFactory factory = new ScannerFactory(logOutput, log, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor);
- factory.create();
+ underTest.create();
assertThat(System.getProperty("https.proxyHost")).isEqualTo("myhost");
assertThat(System.getProperty("https.proxyPort")).isEqualTo("443");
assertThat(System.getProperty("http.proxyHost")).isEqualTo("myhost");
@@ -167,13 +162,13 @@ void proxy_properties_are_not_set_when_no_active_proxy_is_provided() {
Settings settings = new Settings();
when(mavenSession.getSettings()).thenReturn(settings);
- Log log = spy(new DefaultLog(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG, "no-proxy")));
- ScannerFactory factory = new ScannerFactory(logOutput, log, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor);
- factory.create();
+ Log specificLog = spy(new DefaultLog(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG, "unrecognizable-protocol")));
+ var specificUnderTest = spy(new ScannerBootstrapperFactory(specificLog, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor));
+ specificUnderTest.create();
assertProxySettingsAreNotSet();
- verify(log, times(1)).debug("Skipping proxy settings: No active proxy detected.");
+ verify(specificLog, times(1)).debug("Skipping proxy settings: No active proxy detected.");
}
@Test
@@ -186,13 +181,13 @@ void proxy_properties_are_not_set_when_protocol_is_null() {
settings.setProxies(Collections.singletonList(proxyWithNullProtocol));
when(mavenSession.getSettings()).thenReturn(settings);
- Log log = spy(new DefaultLog(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG, "null-protocol-proxy")));
- ScannerFactory factory = new ScannerFactory(logOutput, log, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor);
- factory.create();
+ Log specificLog = spy(new DefaultLog(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG, "null-protocol-proxy")));
+ ScannerBootstrapperFactory specificUnderTest = spy(new ScannerBootstrapperFactory(specificLog, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor));
+ specificUnderTest.create();
assertProxySettingsAreNotSet();
- verify(log, times(1)).warn("Skipping proxy settings: an active proxy was detected (id: null-protocol-proxy) but the protocol is null.");
+ verify(specificLog, times(1)).warn("Skipping proxy settings: an active proxy was detected (id: null-protocol-proxy) but the protocol is null.");
}
@Test
@@ -205,13 +200,13 @@ void proxy_properties_are_not_set_when_protocol_is_blank() {
settings.setProxies(Collections.singletonList(proxyWithNullProtocol));
when(mavenSession.getSettings()).thenReturn(settings);
- Log log = spy(new DefaultLog(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG, "null-protocol-proxy")));
- ScannerFactory factory = new ScannerFactory(logOutput, log, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor);
- factory.create();
+ Log specificLog = spy(new DefaultLog(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG, "unrecognizable-protocol")));
+ var specificUnderTest = spy(new ScannerBootstrapperFactory(specificLog, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor));
+ specificUnderTest.create();
assertProxySettingsAreNotSet();
- verify(log, times(1)).warn("Skipping proxy settings: an active proxy was detected (id: null-protocol-proxy) but the protocol was not recognized.");
+ verify(specificLog, times(1)).warn("Skipping proxy settings: an active proxy was detected (id: null-protocol-proxy) but the protocol was not recognized.");
}
@Test
@@ -223,9 +218,9 @@ void a_warning_is_logged_when_a_proxy_protocol_is_not_supported() {
settings.setProxies(Collections.singletonList(proxyWithUnrecognizableProtocol));
when(mavenSession.getSettings()).thenReturn(settings);
- Log log = spy(new DefaultLog(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG, "unrecognizable-protocol")));
- ScannerFactory factory = new ScannerFactory(logOutput, log, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor);
- factory.create();
+ Log specificLog = spy(new DefaultLog(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG, "unrecognizable-protocol")));
+ var specificUnderTest = spy(new ScannerBootstrapperFactory(specificLog, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor));
+ specificUnderTest.create();
assertThat(System.getProperty("https.proxyHost")).isEqualTo("myhost");
assertThat(System.getProperty("https.proxyPort")).isEqualTo("443");
@@ -233,37 +228,38 @@ void a_warning_is_logged_when_a_proxy_protocol_is_not_supported() {
assertThat(System.getProperty("http.proxyPassword")).isEqualTo("some-secret");
assertThat(System.getProperty("http.nonProxyHosts")).isEqualTo("sonarcloud.io|*.sonarsource.com");
- verify(log, times(1)).isDebugEnabled();
- verify(log, times(1)).debug("Setting proxy properties");
- verify(log, times(1)).warn("Setting proxy properties: one or multiple protocols of the active proxy (id: unknown-protocol-proxy) are not supported (protocols: unknown-proto).");
+ verify(specificLog, times(1)).isDebugEnabled();
+ verify(specificLog, times(1)).debug("Setting proxy properties");
+ verify(specificLog, times(1)).warn("Setting proxy properties: one or multiple protocols of the active proxy (id: unknown-protocol-proxy) are not supported (protocols: unknown-proto).");
}
@Test
void testProperties() {
- Log log = mock(Log.class);
- ScannerFactory factory = new ScannerFactory(logOutput, log, runtimeInformation, mojoExecution, mavenSession, envProps, propertyDecryptor);
- EmbeddedScanner scanner = factory.create();
+ underTest.create();
+ verify(underTest).createScannerEngineBootstrapper("ScannerMaven", "2.0/1.0");
+ ArgumentCaptor