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