import org.sonar.runner.api.EmbeddedRunner;
import org.sonar.runner.api.RunnerProperties;
import org.sonar.runner.api.ScanProperties;
+import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
+import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException;
import java.io.File;
import java.io.IOException;
+import java.util.Properties;
/**
* @goal sonar
*/
RuntimeInformation runtimeInformation;
+ /**
+ * Plexus component for the SecDispatcher
+ * @component role="org.sonatype.plexus.components.sec.dispatcher.SecDispatcher"
+ * @required
+ */
+ private SecDispatcher securityDispatcher;
+
@Override
public void execute() throws MojoExecutionException {
ArtifactVersion mavenVersion = getMavenVersion();
// Include slf4j Logger that is exposed by some Sonar components
.unmask("org.slf4j.Logger")
.unmask("org.slf4j.ILoggerFactory")
- // Exclude other slf4j classes
- // .unmask("org.slf4j.impl.")
+ // Exclude other slf4j classes
+ // .unmask("org.slf4j.impl.")
.mask("org.slf4j.")
- // Exclude logback
+ // Exclude logback
.mask("ch.qos.logback.")
.mask("org.sonar.")
- // Include everything else
+ // Include everything else
.unmask("");
runner.addExtensions(session, getLog(), lifecycleExecutor, artifactFactory, localRepository, artifactMetadataSource, artifactCollector,
dependencyTreeBuilder, projectBuilder);
if (getLog().isDebugEnabled()) {
runner.setProperty("sonar.verbose", "true");
}
+ // Replace all properties by decrypted ones if applicable
+ runner.addProperties(decryptProperties(runner.properties()));
runner.execute();
} catch (Exception e) {
throw ExceptionHandling.handle(e, getLog());
}
return null;
}
+
+ public Properties decryptProperties(Properties properties) {
+ Properties newProperties = new Properties();
+ try {
+ for (String key : properties.stringPropertyNames()) {
+ if (key.contains(".password")) {
+ try {
+ String decrypted = securityDispatcher.decrypt(properties.getProperty(key));
+ newProperties.setProperty(key, decrypted);
+ } catch (SecDispatcherException e) {
+ getLog().warn("Unable to decrypt property " + key, e);
+ }
+ }
+ }
+ } catch (Exception e) {
+ getLog().warn("Unable to decrypt properties", e);
+ }
+ return newProperties;
+ }
}
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<component-set>
+ <components>
+ <component>
+ <role>org.sonatype.plexus.components.sec.dispatcher.SecDispatcher</role>
+ <role-hint>default</role-hint>
+ <implementation>org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher</implementation>
+ <requirements>
+ <requirement>
+ <role>org.sonatype.plexus.components.cipher.PlexusCipher</role>
+ <role-hint>default</role-hint>
+ <field-name>_cipher</field-name>
+ </requirement>
+ </requirements>
+ <configuration>
+ <_configuration-file>~/.m2/settings-security.xml</_configuration-file>
+ </configuration>
+ </component>
+ <component>
+ <role>org.sonatype.plexus.components.cipher.PlexusCipher</role>
+ <role-hint>default</role-hint>
+ <implementation>org.sonatype.plexus.components.cipher.DefaultPlexusCipher</implementation>
+ </component>
+ </components>
+</component-set>