Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
update according to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie committed Jan 31, 2017
1 parent 4bd0c85 commit 5245ec5
Show file tree
Hide file tree
Showing 22 changed files with 194 additions and 369 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.gov.justice.raml.maven.lintchecker;

/**
* Contains any configuration needed by any of the {@link LintCheckRule}s. Currently this class
* contains nothing, but to future proof the {@link LintCheckRule} interface we pass this class
* in the execute() method. Add any configuration your rule may need here.
*/
public class LintCheckConfiguration {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
*/
public interface LintCheckRule {

void execute(final Raml raml) throws LintCheckerException;
/**
* Validate that the Raml and project structure
*
* @param raml The raml file to be validated
* @param lintCheckConfiguration The global configuration that a rule may need
* @throws LintCheckerException if the validation fails
*/
void execute(final Raml raml, final LintCheckConfiguration lintCheckConfiguration) throws LintCheckerException;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package uk.gov.justice.raml.maven.lintchecker;

/**
* Exception that is thrown if any of the {@link LintCheckRule}s fail.
*/
public class LintCheckerException extends Exception {

public LintCheckerException(final String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void generate(final GenerateGoalConfig config) throws IOException {

new RamlFileParser()
.ramlOf(config.getSourceDirectory(), paths)
.stream()
.forEach(raml -> generatorFactory.instanceOf(config.getGeneratorName()).run(raml, generatorConfig));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import uk.gov.justice.raml.core.Generator;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -37,7 +38,7 @@ private Generator createGenerator(final String generatorName) {
final Constructor<?> constructor = clazz.getConstructor();
generator = (Generator) constructor.newInstance();
return generator;
} catch (final Exception e) {
} catch (final ReflectiveOperationException e) {
throw new IllegalArgumentException(String.format("Could not instantiate generator %s", generatorName), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package uk.gov.justice.raml.maven.lintchecker;

import uk.gov.justice.raml.io.FileTreeScanner;
import uk.gov.justice.raml.io.files.parser.RamlFileParser;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
import org.raml.model.Raml;

public class LintCheckGoalProcessor {

private final RamlFileParser ramlFileParser;
private final FileTreeScanner fileTreeScanner;

public LintCheckGoalProcessor(
final RamlFileParser ramlFileParser,
final FileTreeScanner fileTreeScanner) {
this.ramlFileParser = ramlFileParser;
this.fileTreeScanner = fileTreeScanner;
}

public void execute(
final File sourceDirectory,
final List<LintCheckRule> rules,
final List<String> includes,
final List<String> excludes) throws MojoExecutionException {

final Collection<Path> paths = getPaths(sourceDirectory, includes, excludes);
final Collection<Raml> ramls = ramlFileParser.ramlOf(sourceDirectory.toPath(), paths);

for (final Raml raml : ramls) {
for (final LintCheckRule rule : rules) {
try {
rule.execute(raml, new LintCheckConfiguration());
} catch (final LintCheckerException e) {
throw new MojoExecutionException("Lint checker rule failed for rule " + rule.getClass().getSimpleName(), e);
}
}
}
}

private Collection<Path> getPaths(
final File sourceDirectory,
final List<String> includes,
final List<String> excludes) throws MojoExecutionException {
try {
return fileTreeScanner.find(sourceDirectory.toPath(), toArray(includes), toArray(excludes));
} catch (final IOException e) {
throw new MojoExecutionException("Failed to find paths from source directory " + sourceDirectory.getAbsolutePath());
}
}

private String[] toArray(final List<String> list) {
return list.toArray(new String[list.size()]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package uk.gov.justice.raml.maven.lintchecker;

import uk.gov.justice.raml.io.FileTreeScanner;
import uk.gov.justice.raml.io.files.parser.RamlFileParser;
import uk.gov.justice.raml.maven.common.BasicMojo;

import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;


@Mojo(name = "lint-check")
public class LintCheckMojo extends BasicMojo {

private final RamlFileParser ramlFileParser = new RamlFileParser();
private final FileTreeScanner fileTreeScanner = new FileTreeScanner();

/**
* Array of objects that implement the LintCheckerRule interface to execute.
*/
@SuppressWarnings("unused")
@Parameter(required = true)
protected List<LintCheckRule> rules;


@Override
public void execute() throws MojoExecutionException {

final LintCheckGoalProcessor lintCheckGoalProcessor = new LintCheckGoalProcessor(
ramlFileParser,
fileTreeScanner);

lintCheckGoalProcessor.execute(
sourceDirectory,
rules,
includes,
excludes
);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5245ec5

Please sign in to comment.