9: Fix checking package in JavaPlugin
This commit is contained in:
@@ -45,6 +45,10 @@ public abstract class BasePlugin implements Plugin {
|
|||||||
issues.add(issue);
|
issues.add(issue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void addIssue(Issue issue) {
|
||||||
|
issues.add(issue);
|
||||||
|
}
|
||||||
|
|
||||||
protected File getOriginalFile() {
|
protected File getOriginalFile() {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.bartek.esa.core.archetype;
|
package com.bartek.esa.core.archetype;
|
||||||
|
|
||||||
import com.bartek.esa.core.model.enumeration.Severity;
|
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.core.xml.XmlHelper;
|
||||||
import com.bartek.esa.error.EsaException;
|
import com.bartek.esa.error.EsaException;
|
||||||
import com.bartek.esa.file.matcher.GlobMatcher;
|
import com.bartek.esa.file.matcher.GlobMatcher;
|
||||||
@@ -43,7 +44,14 @@ public abstract class JavaPlugin extends BasePlugin {
|
|||||||
Node packageValue = root.getAttributes().getNamedItem("package");
|
Node packageValue = root.getAttributes().getNamedItem("package");
|
||||||
|
|
||||||
if(packageValue == null) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.fusesource.jansi.Ansi;
|
|||||||
import org.fusesource.jansi.AnsiConsole;
|
import org.fusesource.jansi.AnsiConsole;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -26,7 +27,7 @@ public class ColorFormatter implements Formatter {
|
|||||||
@Override
|
@Override
|
||||||
public void format(Set<Issue> issues) {
|
public void format(Set<Issue> issues) {
|
||||||
AnsiConsole.systemInstall();
|
AnsiConsole.systemInstall();
|
||||||
if(issues.isEmpty()) {
|
if (issues.isEmpty()) {
|
||||||
Ansi noIssuesFound = ansi().fg(GREEN).a("No issues found.").reset();
|
Ansi noIssuesFound = ansi().fg(GREEN).a("No issues found.").reset();
|
||||||
System.out.println(noIssuesFound);
|
System.out.println(noIssuesFound);
|
||||||
return;
|
return;
|
||||||
@@ -52,29 +53,36 @@ public class ColorFormatter implements Formatter {
|
|||||||
|
|
||||||
private Ansi appendDescription(Issue issue, Ansi ansi) {
|
private Ansi appendDescription(Issue issue, Ansi ansi) {
|
||||||
String description = descriptionProvider.getDescriptionForIssue(issue);
|
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
|
return ansi
|
||||||
.fg(getColorForSeverity(issue))
|
.fg(getColorForSeverity(issue))
|
||||||
.a(issue.getSeverity().name())
|
.a(issue.getSeverity().name())
|
||||||
.reset()
|
.reset()
|
||||||
.a(": ").a(description)
|
.a(": ").a(firstLine)
|
||||||
|
.fgBrightBlack().a(theRestOfLines)
|
||||||
|
.reset()
|
||||||
.a("\n");
|
.a("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Ansi appendFile(Issue issue, Ansi ansi) {
|
private Ansi appendFile(Issue issue, Ansi ansi) {
|
||||||
return ansi
|
return Optional.ofNullable(issue.getFile())
|
||||||
.fg(GREEN)
|
.map(file -> ansi
|
||||||
.a("File: ")
|
.fg(BLUE)
|
||||||
.reset()
|
.a("File: ")
|
||||||
.a(issue.getFile().getAbsolutePath())
|
.reset()
|
||||||
.a("\n");
|
.a(file.getAbsolutePath())
|
||||||
|
.a("\n"))
|
||||||
|
.orElse(ansi);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Ansi appendLine(Issue issue, Ansi ansi) {
|
private Ansi appendLine(Issue issue, Ansi ansi) {
|
||||||
Optional.ofNullable(issue.getLine())
|
Optional.ofNullable(issue.getLine())
|
||||||
.ifPresent(line -> {
|
.ifPresent(line -> {
|
||||||
ansi
|
ansi
|
||||||
.fg(BLUE)
|
.fg(CYAN)
|
||||||
.a("Line");
|
.a("Line");
|
||||||
Optional.ofNullable(issue.getLineNumber()).ifPresentOrElse(
|
Optional.ofNullable(issue.getLineNumber()).ifPresentOrElse(
|
||||||
number -> ansi.a(" ").a(number).a(": "),
|
number -> ansi.a(" ").a(number).a(": "),
|
||||||
@@ -86,11 +94,15 @@ public class ColorFormatter implements Formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Ansi.Color getColorForSeverity(Issue issue) {
|
private Ansi.Color getColorForSeverity(Issue issue) {
|
||||||
switch(issue.getSeverity()) {
|
switch (issue.getSeverity()) {
|
||||||
case INFO: return GREEN;
|
case INFO:
|
||||||
case WARNING: return YELLOW;
|
return GREEN;
|
||||||
case ERROR: return MAGENTA;
|
case WARNING:
|
||||||
case VULNERABILITY: return RED;
|
return YELLOW;
|
||||||
|
case ERROR:
|
||||||
|
return MAGENTA;
|
||||||
|
case VULNERABILITY:
|
||||||
|
return RED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RED;
|
return RED;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class SimpleFormatter implements Formatter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void format(Set<Issue> issues) {
|
public void format(Set<Issue> issues) {
|
||||||
if(issues.isEmpty()) {
|
if (issues.isEmpty()) {
|
||||||
System.out.println("No issues found.");
|
System.out.println("No issues found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -50,10 +50,13 @@ public class SimpleFormatter implements Formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void appendFile(Issue issue, StringBuilder format) {
|
private void appendFile(Issue issue, StringBuilder format) {
|
||||||
format
|
Optional.ofNullable(issue.getFile())
|
||||||
.append("File: ")
|
.ifPresent(file ->
|
||||||
.append(issue.getFile().getAbsolutePath())
|
format
|
||||||
.append("\n");
|
.append("File: ")
|
||||||
|
.append(file.getAbsolutePath())
|
||||||
|
.append("\n")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendLine(Issue issue, StringBuilder format) {
|
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