Skip to content

Commit

Permalink
Implementation of TouK#113 Plugin Facility for Sputnik Processors
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkosertic committed Jan 30, 2016
1 parent 416263e commit c40da0d
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 32 deletions.
43 changes: 11 additions & 32 deletions src/main/java/pl/touk/sputnik/engine/ProcessorBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,27 @@

import org.jetbrains.annotations.NotNull;
import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;
import pl.touk.sputnik.processor.checkstyle.CheckstyleProcessor;
import pl.touk.sputnik.processor.codenarc.CodeNarcProcessor;
import pl.touk.sputnik.processor.findbugs.FindBugsProcessor;
import pl.touk.sputnik.processor.jshint.JsHintProcessor;
import pl.touk.sputnik.processor.jslint.JsLintProcessor;
import pl.touk.sputnik.processor.pmd.PmdProcessor;
import pl.touk.sputnik.processor.scalastyle.ScalastyleProcessor;
import pl.touk.sputnik.processor.sonar.SonarProcessor;
import pl.touk.sputnik.processor.ReviewProcessorFactory;
import pl.touk.sputnik.review.ReviewProcessor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;

public class ProcessorBuilder {

@NotNull
public static List<ReviewProcessor> buildProcessors(Configuration configuration) {
List<ReviewProcessor> processors = new ArrayList<>();
if (Boolean.valueOf(configuration.getProperty(GeneralOption.CHECKSTYLE_ENABLED))) {
processors.add(new CheckstyleProcessor(configuration));
}
if (Boolean.valueOf(configuration.getProperty(GeneralOption.PMD_ENABLED))) {
processors.add(new PmdProcessor(configuration));
}
if (Boolean.valueOf(configuration.getProperty(GeneralOption.FINDBUGS_ENABLED))) {
processors.add(new FindBugsProcessor(configuration));
}
if (Boolean.valueOf(configuration.getProperty(GeneralOption.SCALASTYLE_ENABLED))) {
processors.add(new ScalastyleProcessor(configuration));
}
if (Boolean.valueOf(configuration.getProperty(GeneralOption.CODE_NARC_ENABLED))) {
processors.add(new CodeNarcProcessor(configuration));
}
if (Boolean.valueOf(configuration.getProperty(GeneralOption.JSLINT_ENABLED))) {
processors.add(new JsLintProcessor(configuration));
}
if (Boolean.valueOf(configuration.getProperty(GeneralOption.JSHINT_ENABLED))) {
processors.add(new JsHintProcessor(configuration));
}
if (Boolean.valueOf(configuration.getProperty(GeneralOption.SONAR_ENABLED))) {
processors.add(new SonarProcessor(configuration));

ServiceLoader<ReviewProcessorFactory> theLoader = ServiceLoader.load(ReviewProcessorFactory.class);
Iterator<ReviewProcessorFactory> theIterator = theLoader.iterator();
while (theIterator.hasNext()) {
ReviewProcessorFactory theFactory = theIterator.next();
if (theFactory.isEnabled(configuration)) {
processors.add(theFactory.create(configuration));
}
}
return processors;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pl.touk.sputnik.processor;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.review.ReviewProcessor;

public interface ReviewProcessorFactory<T extends ReviewProcessor> {

boolean isEnabled(Configuration aConfiguration);

T create(Configuration aConfiguration);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.touk.sputnik.processor.checkstyle;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;
import pl.touk.sputnik.processor.ReviewProcessorFactory;

public class CheckstyleReviewProcessorFactory implements ReviewProcessorFactory<CheckstyleProcessor> {

@Override
public boolean isEnabled(Configuration aConfiguration) {
return Boolean.valueOf(aConfiguration.getProperty(GeneralOption.CHECKSTYLE_ENABLED));
}

@Override
public CheckstyleProcessor create(Configuration aConfiguration) {
return new CheckstyleProcessor(aConfiguration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.touk.sputnik.processor.codenarc;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;
import pl.touk.sputnik.processor.ReviewProcessorFactory;

public class NodeCardReviewProcessorFactory implements ReviewProcessorFactory<CodeNarcProcessor> {

@Override
public boolean isEnabled(Configuration aConfiguration) {
return Boolean.valueOf(aConfiguration.getProperty(GeneralOption.CODE_NARC_ENABLED));
}

@Override
public CodeNarcProcessor create(Configuration aConfiguration) {
return new CodeNarcProcessor(aConfiguration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.touk.sputnik.processor.findbugs;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;
import pl.touk.sputnik.processor.ReviewProcessorFactory;

public class FindbugsReviewProcessorFactory implements ReviewProcessorFactory<FindBugsProcessor> {

@Override
public boolean isEnabled(Configuration aConfiguration) {
return Boolean.valueOf(aConfiguration.getProperty(GeneralOption.FINDBUGS_ENABLED));
}

@Override
public FindBugsProcessor create(Configuration aConfiguration) {
return new FindBugsProcessor(aConfiguration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.touk.sputnik.processor.jshint;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;
import pl.touk.sputnik.processor.ReviewProcessorFactory;

public class JsHintReviewProcessorFactory implements ReviewProcessorFactory<JsHintProcessor> {

@Override
public boolean isEnabled(Configuration aConfiguration) {
return Boolean.valueOf(aConfiguration.getProperty(GeneralOption.JSHINT_ENABLED));
}

@Override
public JsHintProcessor create(Configuration aConfiguration) {
return new JsHintProcessor(aConfiguration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.touk.sputnik.processor.jslint;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;
import pl.touk.sputnik.processor.ReviewProcessorFactory;

public class JsLintReviewProcessorFactory implements ReviewProcessorFactory<JsLintProcessor> {

@Override
public boolean isEnabled(Configuration aConfiguration) {
return Boolean.valueOf(aConfiguration.getProperty(GeneralOption.JSLINT_ENABLED));
}

@Override
public JsLintProcessor create(Configuration aConfiguration) {
return new JsLintProcessor(aConfiguration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.touk.sputnik.processor.pmd;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;
import pl.touk.sputnik.processor.ReviewProcessorFactory;

public class PmdReviewProcessorFactory implements ReviewProcessorFactory<PmdProcessor> {

@Override
public boolean isEnabled(Configuration aConfiguration) {
return Boolean.valueOf(aConfiguration.getProperty(GeneralOption.PMD_ENABLED));
}

@Override
public PmdProcessor create(Configuration aConfiguration) {
return new PmdProcessor(aConfiguration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.touk.sputnik.processor.scalastyle;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;
import pl.touk.sputnik.processor.ReviewProcessorFactory;

public class ScalastyleReviewProcessorFactory implements ReviewProcessorFactory<ScalastyleProcessor> {

@Override
public boolean isEnabled(Configuration aConfiguration) {
return Boolean.valueOf(aConfiguration.getProperty(GeneralOption.SCALASTYLE_ENABLED));
}

@Override
public ScalastyleProcessor create(Configuration aConfiguration) {
return new ScalastyleProcessor(aConfiguration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.touk.sputnik.processor.sonar;

import pl.touk.sputnik.configuration.Configuration;
import pl.touk.sputnik.configuration.GeneralOption;
import pl.touk.sputnik.processor.ReviewProcessorFactory;

public class SonarReviewProcessorFactory implements ReviewProcessorFactory<SonarProcessor> {

@Override
public boolean isEnabled(Configuration aConfiguration) {
return Boolean.valueOf(aConfiguration.getProperty(GeneralOption.SONAR_ENABLED));
}

@Override
public SonarProcessor create(Configuration aConfiguration) {
return new SonarProcessor(aConfiguration);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pl.touk.sputnik.processor.checkstyle.CheckstyleReviewProcessorFactory
pl.touk.sputnik.processor.pmd.PmdReviewProcessorFactory
pl.touk.sputnik.processor.findbugs.FindbugsReviewProcessorFactory
pl.touk.sputnik.processor.scalastyle.ScalastyleReviewProcessorFactory
pl.touk.sputnik.processor.codenarc.NodeCardReviewProcessorFactory
pl.touk.sputnik.processor.jslint.JsLintReviewProcessorFactory
pl.touk.sputnik.processor.jshint.JsHintReviewProcessorFactory
pl.touk.sputnik.processor.sonar.SonarReviewProcessorFactory

0 comments on commit c40da0d

Please sign in to comment.