5: Rebuild description system to allow many descriptions per plugin
This commit is contained in:
@@ -25,8 +25,13 @@ public abstract class BasePlugin implements Plugin {
|
||||
protected abstract void run(File file);
|
||||
|
||||
protected void addIssue(Integer lineNumber, String line) {
|
||||
addIssue("", lineNumber, line);
|
||||
}
|
||||
|
||||
protected void addIssue(String descriptionCode, Integer lineNumber, String line) {
|
||||
Issue issue = Issue.builder()
|
||||
.issuer(this.getClass())
|
||||
.descriptionCode(descriptionCode)
|
||||
.file(file)
|
||||
.lineNumber(lineNumber)
|
||||
.line(line)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bartek.esa.core.desc.provider;
|
||||
|
||||
import com.bartek.esa.core.model.Issue;
|
||||
import com.bartek.esa.error.EsaException;
|
||||
import io.vavr.control.Try;
|
||||
|
||||
@@ -9,16 +10,17 @@ import java.util.Properties;
|
||||
|
||||
public class DescriptionProvider {
|
||||
private static final String DESCRIPTION_FILE = "description.properties";
|
||||
private final Properties properties = new Properties();
|
||||
private final Properties descriptions = new Properties();
|
||||
|
||||
@Inject
|
||||
public DescriptionProvider() {
|
||||
Optional.ofNullable(DescriptionProvider.class.getClassLoader().getResourceAsStream(DESCRIPTION_FILE))
|
||||
.ifPresent(p -> Try.run(() -> properties.load(p)).getOrElseThrow(EsaException::new));
|
||||
.ifPresent(p -> Try.run(() -> descriptions.load(p)).getOrElseThrow(EsaException::new));
|
||||
}
|
||||
|
||||
public String getDescriptionForClass(Class<?> clazz) {
|
||||
String clazzCanonicalName = properties.getProperty(clazz.getCanonicalName());
|
||||
return clazzCanonicalName != null ? clazzCanonicalName : "No description provided.";
|
||||
public String getDescriptionForIssue(Issue issue) {
|
||||
String code = issue.getIssuer().getCanonicalName() + issue.getDescriptionCode();
|
||||
String description = descriptions.getProperty(code);
|
||||
return description != null && !description.isEmpty() ? description : "No description provided.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.File;
|
||||
@Builder
|
||||
public class Issue {
|
||||
private final Class<?> issuer;
|
||||
private final String descriptionCode;
|
||||
private final File file;
|
||||
private final Integer lineNumber;
|
||||
private final String line;
|
||||
|
||||
Reference in New Issue
Block a user