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();
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")) {
- decrypt(properties, newProperties, key);
- }
- }
- } catch (Exception e) {
- getLog().warn("Unable to decrypt properties", e);
- }
- return newProperties;
- }
-
- private void decrypt(Properties properties, Properties newProperties, String key) {
- try {
- String decrypted = securityDispatcher.decrypt(properties.getProperty(key));
- newProperties.setProperty(key, decrypted);
- } catch (SecDispatcherException e) {
- getLog().warn("Unable to decrypt property " + key, e);
- }
- }
}
+++ /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>