Skip to content

Commit

Permalink
Cleanup of configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
sertic committed Feb 17, 2016
1 parent 2f365e7 commit d60b40b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.mirkosertic.mavensonarsputnik;

import java.io.File;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -29,19 +28,18 @@ public class MavenEnvironment {
private final ArtifactFactory artifactFactory;
private final ArtifactMetadataSource artifactMetadataSource;
private final ArtifactCollector artifactCollector;
private final File sonarConfiguration;
private final RuntimeInformation runtimeInformation;

public static void initialize(MavenSession aMavenSession, BuildPluginManager aBuildPluginManager, Log aLog,
DependencyTreeBuilder aDependencyTreeBuilder, ArtifactRepository aLocalRepository,
SecDispatcher aSecurityDispatcher, MavenProjectBuilder aProjectBuilder,
LifecycleExecutor aLifecycleExecutor, ArtifactFactory aArtifactFactory,
ArtifactMetadataSource aArtifactMetadataSource, ArtifactCollector aArtifactCollector, File aSonarConfiguration, RuntimeInformation aRuntimeInformation) {
ArtifactMetadataSource aArtifactMetadataSource, ArtifactCollector aArtifactCollector, RuntimeInformation aRuntimeInformation) {
ENVIRONMENT.set(new MavenEnvironment(aMavenSession, aBuildPluginManager, aLog,
aDependencyTreeBuilder, aLocalRepository,
aSecurityDispatcher, aProjectBuilder,
aLifecycleExecutor, aArtifactFactory,
aArtifactMetadataSource, aArtifactCollector, aSonarConfiguration, aRuntimeInformation));
aArtifactMetadataSource, aArtifactCollector, aRuntimeInformation));
}

public static MavenEnvironment get() {
Expand All @@ -52,7 +50,7 @@ public MavenEnvironment(MavenSession aMavenSession, BuildPluginManager aBuildPlu
DependencyTreeBuilder aDependencyTreeBuilder, ArtifactRepository aLocalRepository,
SecDispatcher aSecurityDispatcher, MavenProjectBuilder aProjectBuilder,
LifecycleExecutor aLifecycleExecutor, ArtifactFactory aArtifactFactory,
ArtifactMetadataSource aArtifactMetadataSource, ArtifactCollector aArtifactCollector, File aSonarConfiguration, RuntimeInformation aRuntimeInformation) {
ArtifactMetadataSource aArtifactMetadataSource, ArtifactCollector aArtifactCollector, RuntimeInformation aRuntimeInformation) {
mavenSession = aMavenSession;
buildPluginManager = aBuildPluginManager;
log = aLog;
Expand All @@ -64,7 +62,6 @@ public MavenEnvironment(MavenSession aMavenSession, BuildPluginManager aBuildPlu
artifactFactory = aArtifactFactory;
artifactMetadataSource = aArtifactMetadataSource;
artifactCollector = aArtifactCollector;
sonarConfiguration = aSonarConfiguration;
runtimeInformation = aRuntimeInformation;
}

Expand Down Expand Up @@ -115,8 +112,4 @@ public ArtifactMetadataSource getArtifactMetadataSource() {
public ArtifactCollector getArtifactCollector() {
return artifactCollector;
}

public File getSonarConfiguration() {
return sonarConfiguration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ public class MavenSonarSputnikMojo extends AbstractMojo {
@Parameter(defaultValue = "${sputnikConfiguration}", required = true)
private File sputnikConfiguration;

/**
* The Sonar configuration property file.
*/
@Parameter(defaultValue = "${sonarConfiguration}", required = true)
private File sonarConfiguration;

@Component
private ArtifactFactory artifactFactory;

Expand Down Expand Up @@ -136,7 +130,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
dependencyTreeBuilder, localRepository,
securityDispatcher, projectBuilder,
lifecycleExecutor, artifactFactory,
artifactMetadataSource, artifactCollector, sonarConfiguration, runtimeInformation);
artifactMetadataSource, artifactCollector, runtimeInformation);

Configuration theConfiguration = ConfigurationBuilder.initFromProperties(theSputnikProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,20 @@ private void processSingleDependency(File aPomXML, NodeList aVulnerabilities, Re
for (int k=0;k<theLines.size();k++) {
String theSingleLine = theLines.get(k);
if (theSingleLine.contains("<artifactId>" + aMavenIdentifier.getArtifactId() + "</artifactId")) {
Violation theViolation = new Violation(aReviewFile.getReviewFilename(), k+1, theCompleteComment,
severity);
aResult.add(theViolation);
theSomethingFound = true;

boolean theGroupIdFound = false;
if (k>0) {
theGroupIdFound = theGroupIdFound || theLines.get(k-1).contains("<groupId>" + aMavenIdentifier.getGroupId() + "</groupId");
}
if (k<theLines.size() - 1) {
theGroupIdFound = theGroupIdFound || theLines.get(k+1).contains("<groupId>" + aMavenIdentifier.getGroupId() + "</groupId");
}
if (theGroupIdFound) {
Violation theViolation = new Violation(aReviewFile.getReviewFilename(), k + 1, theCompleteComment,
severity);
aResult.add(theViolation);
theSomethingFound = true;
}
}
}

Expand Down
26 changes: 24 additions & 2 deletions src/main/java/pl/touk/sputnik/processor/sonar/SonarProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.annotations.VisibleForTesting;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.ConfigurationOption;
import pl.touk.sputnik.review.Review;
import pl.touk.sputnik.review.ReviewException;
import pl.touk.sputnik.review.ReviewFile;
Expand All @@ -37,6 +38,23 @@ public class SonarProcessor implements ReviewProcessor {

private static final String PROCESSOR_NAME = "Sonar";

public final static ConfigurationOption SONAR_CONFIGURATION = new ConfigurationOption() {
@Override
public String getKey() {
return "sonar.configurationFile";
}

@Override
public String getDescription() {
return "Sonar configuration file";
}

@Override
public String getDefaultValue() {
return "";
}
};

private final Configuration configuration;

public SonarProcessor(@NotNull final Configuration aConfiguration) {
Expand Down Expand Up @@ -73,8 +91,12 @@ public ReviewResult process(@NotNull Review review) {

Properties theSonarConfigurationToAdd = new Properties();
theSonarConfigurationToAdd.load(getClass().getResourceAsStream("/default-sonar.properties"));
try (InputStream theStream = new FileInputStream(theEnvironment.getSonarConfiguration())) {
theSonarConfigurationToAdd.load(theStream);

String theSonarConfiguration = configuration.getProperty(SONAR_CONFIGURATION);
if (!StringUtils.isEmpty(theSonarConfiguration)) {
try (InputStream theStream = new FileInputStream(new File(theSonarConfiguration))) {
theSonarConfigurationToAdd.load(theStream);
}
}

theRunner.addGlobalProperties(theSonarConfigurationToAdd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ private String getIssueFilePath(String issueComponent, Map<String, Component> co
}
return file;
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/default-sputnik.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jshint.enabled=false
jshint.configurationFile=jshint.json
sonar.enabled=true
sonar.verbose=false
sonar.configurationFile=
pitest.enabled=true
pitest.configurationFile=
owaspdependencycheck.enabled=true
Expand Down

0 comments on commit d60b40b

Please sign in to comment.