9: Fix checking package in JavaPlugin
This commit is contained in:
@@ -45,6 +45,10 @@ public abstract class BasePlugin implements Plugin {
|
||||
issues.add(issue);
|
||||
}
|
||||
|
||||
protected void addIssue(Issue issue) {
|
||||
issues.add(issue);
|
||||
}
|
||||
|
||||
protected File getOriginalFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartek.esa.core.archetype;
|
||||
|
||||
import com.bartek.esa.core.model.enumeration.Severity;
|
||||
import com.bartek.esa.core.model.object.Issue;
|
||||
import com.bartek.esa.core.xml.XmlHelper;
|
||||
import com.bartek.esa.error.EsaException;
|
||||
import com.bartek.esa.file.matcher.GlobMatcher;
|
||||
@@ -43,7 +44,14 @@ public abstract class JavaPlugin extends BasePlugin {
|
||||
Node packageValue = root.getAttributes().getNamedItem("package");
|
||||
|
||||
if(packageValue == null) {
|
||||
addIssue(Severity.ERROR, ".PACKAGE_LACK", null, null);
|
||||
Issue issue = Issue.builder()
|
||||
.issuer(JavaPlugin.class)
|
||||
.descriptionCode(".NO_PACKAGE")
|
||||
.severity(Severity.ERROR)
|
||||
.build();
|
||||
|
||||
addIssue(issue);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -26,7 +27,7 @@ public class ColorFormatter implements Formatter {
|
||||
@Override
|
||||
public void format(Set<Issue> issues) {
|
||||
AnsiConsole.systemInstall();
|
||||
if(issues.isEmpty()) {
|
||||
if (issues.isEmpty()) {
|
||||
Ansi noIssuesFound = ansi().fg(GREEN).a("No issues found.").reset();
|
||||
System.out.println(noIssuesFound);
|
||||
return;
|
||||
@@ -52,29 +53,36 @@ public class ColorFormatter implements Formatter {
|
||||
|
||||
private Ansi appendDescription(Issue issue, Ansi ansi) {
|
||||
String description = descriptionProvider.getDescriptionForIssue(issue);
|
||||
String[] lines = description.split("\n");
|
||||
String firstLine = lines[0];
|
||||
String theRestOfLines = lines.length > 1 ? "\n" + String.join("\n", Arrays.copyOfRange(lines, 1, lines.length)) : "";
|
||||
|
||||
return ansi
|
||||
.fg(getColorForSeverity(issue))
|
||||
.a(issue.getSeverity().name())
|
||||
.reset()
|
||||
.a(": ").a(description)
|
||||
.a(": ").a(firstLine)
|
||||
.fgBrightBlack().a(theRestOfLines)
|
||||
.reset()
|
||||
.a("\n");
|
||||
}
|
||||
|
||||
private Ansi appendFile(Issue issue, Ansi ansi) {
|
||||
return ansi
|
||||
.fg(GREEN)
|
||||
return Optional.ofNullable(issue.getFile())
|
||||
.map(file -> ansi
|
||||
.fg(BLUE)
|
||||
.a("File: ")
|
||||
.reset()
|
||||
.a(issue.getFile().getAbsolutePath())
|
||||
.a("\n");
|
||||
.a(file.getAbsolutePath())
|
||||
.a("\n"))
|
||||
.orElse(ansi);
|
||||
}
|
||||
|
||||
private Ansi appendLine(Issue issue, Ansi ansi) {
|
||||
Optional.ofNullable(issue.getLine())
|
||||
.ifPresent(line -> {
|
||||
ansi
|
||||
.fg(BLUE)
|
||||
.fg(CYAN)
|
||||
.a("Line");
|
||||
Optional.ofNullable(issue.getLineNumber()).ifPresentOrElse(
|
||||
number -> ansi.a(" ").a(number).a(": "),
|
||||
@@ -86,11 +94,15 @@ public class ColorFormatter implements Formatter {
|
||||
}
|
||||
|
||||
private Ansi.Color getColorForSeverity(Issue issue) {
|
||||
switch(issue.getSeverity()) {
|
||||
case INFO: return GREEN;
|
||||
case WARNING: return YELLOW;
|
||||
case ERROR: return MAGENTA;
|
||||
case VULNERABILITY: return RED;
|
||||
switch (issue.getSeverity()) {
|
||||
case INFO:
|
||||
return GREEN;
|
||||
case WARNING:
|
||||
return YELLOW;
|
||||
case ERROR:
|
||||
return MAGENTA;
|
||||
case VULNERABILITY:
|
||||
return RED;
|
||||
}
|
||||
|
||||
return RED;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class SimpleFormatter implements Formatter {
|
||||
|
||||
@Override
|
||||
public void format(Set<Issue> issues) {
|
||||
if(issues.isEmpty()) {
|
||||
if (issues.isEmpty()) {
|
||||
System.out.println("No issues found.");
|
||||
return;
|
||||
}
|
||||
@@ -50,10 +50,13 @@ public class SimpleFormatter implements Formatter {
|
||||
}
|
||||
|
||||
private void appendFile(Issue issue, StringBuilder format) {
|
||||
Optional.ofNullable(issue.getFile())
|
||||
.ifPresent(file ->
|
||||
format
|
||||
.append("File: ")
|
||||
.append(issue.getFile().getAbsolutePath())
|
||||
.append("\n");
|
||||
.append(file.getAbsolutePath())
|
||||
.append("\n")
|
||||
);
|
||||
}
|
||||
|
||||
private void appendLine(Issue issue, StringBuilder format) {
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
com.bartek.esa.core.plugin.JavaPlugin.PACKAGE_LACK=There is no package defined in AndroidManifest.xml file. Please check fix to use this tool.
|
||||
com.bartek.esa.core.archetype.JavaPlugin.NO_PACKAGE=There is no package defined in AndroidManifest.xml file. \n\
|
||||
Package should be defined as attribute of <manifest> tag.\n\
|
||||
For example: <manifest package="com.bartek.esa.test">\n\
|
||||
Please fix it to use this tool.
|
||||
Reference in New Issue
Block a user