Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to the latest version of the scanner library #215

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions its/src/test/java/com/sonar/maven/it/suite/JavaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void shouldPopulateLibraries() throws IOException {
File projectPom = ItUtils.locateProjectPom("shared/struts-1.3.9-diet");
MavenBuild build = MavenBuild.create(projectPom)
.setGoals(cleanPackageSonarGoal())
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
ORCHESTRATOR.executeBuild(build);

Properties generatedProps = getProps(outputProps);
Expand All @@ -84,7 +84,7 @@ void read_default_from_plugins_config() throws Exception {
File pom = ItUtils.locateProjectPom("project-default-config");
MavenBuild build = MavenBuild.create(pom)
.setGoals(cleanPackageSonarGoal())
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
ORCHESTRATOR.executeBuild(build);

Properties props = getProps(outputProps);
Expand All @@ -103,7 +103,7 @@ void setJavaVersionCompilerConfiguration() throws IOException {
File pom = ItUtils.locateProjectPom("version/compilerPluginConfig");
MavenBuild build = MavenBuild.create(pom)
.setGoals(cleanPackageSonarGoal())
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
ORCHESTRATOR.executeBuild(build);

Properties props = getProps(outputProps);
Expand All @@ -120,7 +120,7 @@ void setJavaVersionProperties() throws IOException {
File pom = ItUtils.locateProjectPom("version/properties");
MavenBuild build = MavenBuild.create(pom)
.setGoals(cleanPackageSonarGoal())
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
ORCHESTRATOR.executeBuild(build);

Properties props = getProps(outputProps);
Expand All @@ -137,7 +137,7 @@ void setJdkHomeFromCompilerExecutableConfiguration() throws IOException {
File pom = ItUtils.locateProjectPom("jdkHome/compilerPluginConfigExecutable");
MavenBuild build = MavenBuild.create(pom)
.setGoals(sonarGoal())
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
ORCHESTRATOR.executeBuild(build);

Properties props = getProps(outputProps);
Expand All @@ -155,7 +155,7 @@ void setJdkHomeFromGlobalToolchainsPlugin() throws IOException {
// Run only the toolchain goal + sonar. Can't run a true build since our toolchains paths are fake
.setGoals("toolchains:toolchain " + sonarGoal())
.addArguments("--toolchains", new File(pom.getParent(), "toolchains.xml").getAbsolutePath())
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
ORCHESTRATOR.executeBuild(build);

Properties props = getProps(outputProps);
Expand All @@ -175,7 +175,7 @@ void setJdkHomeFromCompilerToolchainsConfiguration() throws IOException {
.setExecutionDir(pom.getParentFile())
.setGoals(sonarGoal())
.addArguments("--toolchains", new File(pom.getParent(), "toolchains.xml").getAbsolutePath())
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
ORCHESTRATOR.executeBuild(build);

Properties props = getProps(outputProps);
Expand All @@ -195,7 +195,7 @@ void takeFirstToolchainIfMultipleExecutions() throws IOException {
.setExecutionDir(pom.getParentFile())
.setGoals(sonarGoal())
.addArguments("--toolchains", new File(pom.getParent(), "toolchains.xml").getAbsolutePath())
.setProperty("sonar.scanner.dumpToFile", outputProps.getAbsolutePath());
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
ORCHESTRATOR.executeBuild(build);

Properties props = getProps(outputProps);
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@
</dependency>

<dependency>
<groupId>org.sonarsource.scanner.api</groupId>
<artifactId>sonar-scanner-api</artifactId>
<version>2.16.3.1081</version>
<groupId>org.sonarsource.scanner.lib</groupId>
<artifactId>sonar-scanner-java-library</artifactId>
<version>3.0.0.144</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/it/invoker.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.dumpToFile=out.properties
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.internal.dumpToFile=out.properties
2 changes: 1 addition & 1 deletion src/it/java-compiler-context-toolchain/invoker.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
invoker.goals = --toolchains toolchains.xml toolchains:toolchain ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.dumpToFile=out.properties
invoker.goals = --toolchains toolchains.xml toolchains:toolchain ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.internal.dumpToFile=out.properties
# cannot run this IT with Maven 2 since required --toolchains option was added in 3.0-alpha-3: see MNG-3714
invoker.maven.version = 3.0+
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
invoker.goals = --toolchains toolchains.xml ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.dumpToFile=out.properties
invoker.goals = --toolchains toolchains.xml ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.internal.dumpToFile=out.properties
# Due to toolchain support
invoker.maven.version = 3.3.1+
2 changes: 1 addition & 1 deletion src/it/java-compiler-plugin-toolchain/invoker.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
invoker.goals = --toolchains toolchains.xml toolchains:toolchain ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.dumpToFile=out.properties
invoker.goals = --toolchains toolchains.xml toolchains:toolchain ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.internal.dumpToFile=out.properties
# Due to toolchain support
invoker.maven.version = 3.3.1+
Original file line number Diff line number Diff line change
@@ -1 +1 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.dumpToFile=out.properties -Dsonar.maven.scanAll=true
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:sonar -Dsonar.scanner.internal.dumpToFile=out.properties -Dsonar.maven.scanAll=true
33 changes: 16 additions & 17 deletions src/main/java/org/sonarsource/scanner/maven/SonarQubeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -35,15 +34,14 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.toolchain.ToolchainManager;
import org.sonarsource.scanner.api.EmbeddedScanner;
import org.sonarsource.scanner.api.ScanProperties;
import org.sonarsource.scanner.api.Utils;
import org.sonarsource.scanner.lib.EnvironmentConfig;
import org.sonarsource.scanner.lib.ScannerEngineBootstrapper;
import org.sonarsource.scanner.lib.ScannerProperties;
import org.sonarsource.scanner.maven.bootstrap.MavenCompilerResolver;
import org.sonarsource.scanner.maven.bootstrap.LogHandler;
import org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter;
import org.sonarsource.scanner.maven.bootstrap.PropertyDecryptor;
import org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper;
import org.sonarsource.scanner.maven.bootstrap.ScannerFactory;
import org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapperFactory;
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;

/**
Expand Down Expand Up @@ -81,33 +79,34 @@ public class SonarQubeMojo extends AbstractMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
setLog(new TimestampLogger(getLog()));

if (shouldDelayExecution()) {
getLog().info("Delaying SonarQube Scanner to the end of multi-module project");
return;
}

Properties envProps = Utils.loadEnvironmentProperties(System.getenv());
Map<String, String> envProps = EnvironmentConfig.load(System.getenv());

MavenCompilerResolver mavenCompilerResolver = new MavenCompilerResolver(session, lifecycleExecutor, getLog(), toolchainManager);
MavenProjectConverter mavenProjectConverter = new MavenProjectConverter(getLog(), mavenCompilerResolver, envProps);
LogHandler logHandler = new LogHandler(getLog());

PropertyDecryptor propertyDecryptor = new PropertyDecryptor(getLog(), securityDispatcher);

ScannerFactory runnerFactory = new ScannerFactory(logHandler, getLog(), runtimeInformation, mojoExecution, session, envProps, propertyDecryptor);
ScannerBootstrapperFactory bootstrapperFactory = new ScannerBootstrapperFactory(getLog(), runtimeInformation, mojoExecution, session, envProps, propertyDecryptor);

if (isSkip(runnerFactory.createGlobalProperties())) {
if (isSkip(bootstrapperFactory.createGlobalProperties())) {
return;
}

EmbeddedScanner runner = runnerFactory.create();
new ScannerBootstrapper(getLog(), session, runner, mavenProjectConverter, propertyDecryptor).execute();
ScannerEngineBootstrapper bootstrapper = bootstrapperFactory.create();
boolean success = new ScannerBootstrapper(getLog(), session, bootstrapper, mavenProjectConverter, propertyDecryptor).execute();
if (!success) {
throw new MojoFailureException("Analysis failed");
}
}

/**
* Should scanner be delayed?
*
* @return true if goal is attached to phase and not last in a multi-module project
*/
private boolean shouldDelayExecution() {
Expand All @@ -116,9 +115,9 @@ private boolean shouldDelayExecution() {

/**
* Is this execution a 'detached' goal run from the cli. e.g. mvn sonar:sonar
*
* <p>
* See <a href="https://maven.apache.org/guides/mini/guide-default-execution-ids.html#Default_executionIds_for_Implied_Executions">
Default executionIds for Implied Executions</a>
* Default executionIds for Implied Executions</a>
* for explanation of command line execution id.
*
* @return true if this execution is from the command line
Expand Down Expand Up @@ -153,7 +152,7 @@ private boolean isSkip(Map<String, String> 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;
}
Expand Down
120 changes: 0 additions & 120 deletions src/main/java/org/sonarsource/scanner/maven/TimestampLogger.java

This file was deleted.

This file was deleted.