builder:RuleReadmeLoader: added rule documentation fragment loader

This commit is contained in:
Paul Campbell 2017-01-05 16:31:27 +00:00
parent 44603084fa
commit fb02dc5f88
2 changed files with 57 additions and 0 deletions

View file

@ -0,0 +1,36 @@
package net.kemitix.checkstyle.ruleset.builder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;
/**
* Default README fragment loader.
*
* @author Paul Campbell (paul.campbell@hubio.com)
*/
@Slf4j
@Component
@RequiredArgsConstructor
class DefaultRuleReadmeLoader implements RuleReadmeLoader {
private final TemplateProperties templateProperties;
@Override
public Stream<String> load(final Rule rule) {
try {
final Path resolve = templateProperties.getReadmeFragments()
.resolve(rule.getName() + ".md");
log.info("Loading fragment: {}", resolve);
return Stream.concat(Stream.of(String.format("%n#### [%s](%s)", rule.getName(), rule.getUri())),
Files.lines(resolve));
} catch (IOException e) {
return Stream.empty();
}
}
}

View file

@ -0,0 +1,21 @@
package net.kemitix.checkstyle.ruleset.builder;
import java.util.stream.Stream;
/**
* Loads README fragment for rule.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@FunctionalInterface
interface RuleReadmeLoader {
/**
* Loads the README fragment for rule.
*
* @param rule The Rule.
*
* @return A Stream of the readme fragment.
*/
Stream<String> load(Rule rule);
}