Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let all parsers not depend on Jenkins anymore.
Integrated all parsers into new module analysis-model. Added adapter classes for parsers of violations-lib. - [FIXED JENKINS-17434] - [FIXED JENKINS-40439]
- Loading branch information
Showing
47 changed files
with
1,237 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 0 additions & 112 deletions
112
src/main/java/edu/hm/hafner/analysis/parser/ResharperInspectCodeParser.java
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
src/main/java/edu/hm/hafner/analysis/parser/violations/AbstractViolationAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import java.io.Reader; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import se.bjurr.violations.lib.model.SEVERITY; | ||
import se.bjurr.violations.lib.model.Violation; | ||
import se.bjurr.violations.lib.parsers.ViolationsParser; | ||
|
||
import edu.hm.hafner.analysis.AbstractParser; | ||
import edu.hm.hafner.analysis.Issue; | ||
import edu.hm.hafner.analysis.IssueBuilder; | ||
import edu.hm.hafner.analysis.Issues; | ||
import edu.hm.hafner.analysis.ParsingCanceledException; | ||
import edu.hm.hafner.analysis.ParsingException; | ||
import edu.hm.hafner.analysis.Priority; | ||
|
||
/** | ||
* Adapter for {@link ViolationsParser} instances. Converts the results of an {@link ViolationsParser} into the static | ||
* analysis {@link Issues} model. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public abstract class AbstractViolationAdapter extends AbstractParser<Issue> { | ||
private static final long serialVersionUID = 7203311857999721045L; | ||
|
||
/** Determines whether the Rule property of a {@link Violation} should be used as Category or Type. */ | ||
public enum Rule {CATEGORY, TYPE} | ||
|
||
private final Rule useRuleAs; | ||
|
||
protected AbstractViolationAdapter(final Rule useRuleAs) { | ||
this.useRuleAs = useRuleAs; | ||
} | ||
|
||
@SuppressWarnings({"illegalcatch", "OverlyBroadCatchBlock"}) | ||
@Override | ||
public Issues<Issue> parse(final Reader reader, final Function<String, String> preProcessor) | ||
throws ParsingCanceledException, ParsingException { | ||
try { | ||
ViolationsParser parser = createParser(); | ||
List<Violation> violations = parser.parseReportOutput(IOUtils.toString(reader)); | ||
return convertToIssues(violations); | ||
} | ||
catch (Exception exception) { | ||
throw new ParsingException(exception); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a new parser instance. | ||
* | ||
* @return the {@link ViolationsParser} instance | ||
*/ | ||
protected abstract ViolationsParser createParser(); | ||
|
||
private Issues<Issue> convertToIssues(final List<Violation> violations) { | ||
Issues<Issue> issues = new Issues<>(); | ||
for (Violation violation : violations) { | ||
issues.add(convertToIssue(violation)); | ||
} | ||
return issues; | ||
} | ||
|
||
private Issue convertToIssue(final Violation violation) { | ||
IssueBuilder builder = new IssueBuilder(); | ||
builder.setPriority(convertSeverity(violation.getSeverity())) | ||
.setFileName(violation.getFile()) | ||
.setMessage(violation.getMessage()) | ||
.setLineStart(violation.getStartLine()) | ||
.setLineEnd(violation.getEndLine()) | ||
.setColumnStart(violation.getColumn().or(0)); | ||
String rule = violation.getRule().or(StringUtils.EMPTY); | ||
if (useRuleAs == Rule.TYPE) { | ||
builder.setType(rule); | ||
} | ||
else { | ||
builder.setCategory(rule); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
private Priority convertSeverity(final SEVERITY severity) { | ||
if (severity == SEVERITY.ERROR) { | ||
return Priority.HIGH; | ||
} | ||
if (severity == SEVERITY.WARN) { | ||
return Priority.NORMAL; | ||
} | ||
return Priority.LOW; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/hm/hafner/analysis/parser/violations/AndroidLintParserAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import se.bjurr.violations.lib.parsers.AndroidLintParser; | ||
|
||
/** | ||
* Parses Android Lint files. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public class AndroidLintParserAdapter extends AbstractViolationAdapter { | ||
/** | ||
* Creates a new instance of {@link AndroidLintParserAdapter}. | ||
*/ | ||
public AndroidLintParserAdapter() { | ||
super(Rule.CATEGORY); | ||
} | ||
|
||
@Override | ||
protected AndroidLintParser createParser() { | ||
return new AndroidLintParser(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/hm/hafner/analysis/parser/violations/CodeNarcAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import se.bjurr.violations.lib.parsers.CodeNarcParser; | ||
|
||
/** | ||
* Parses CodeNarc files. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public class CodeNarcAdapter extends AbstractViolationAdapter { | ||
/** | ||
* Creates a new instance of {@link CodeNarcAdapter}. | ||
*/ | ||
public CodeNarcAdapter() { | ||
super(Rule.TYPE); | ||
} | ||
|
||
@Override | ||
protected CodeNarcParser createParser() { | ||
return new CodeNarcParser(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/hm/hafner/analysis/parser/violations/CppCheckAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import se.bjurr.violations.lib.parsers.CPPCheckParser; | ||
|
||
/** | ||
* Parses CPPCheck files. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public class CppCheckAdapter extends AbstractViolationAdapter { | ||
/** | ||
* Creates a new instance of {@link CppCheckAdapter}. | ||
*/ | ||
public CppCheckAdapter() { | ||
super(Rule.TYPE); | ||
} | ||
|
||
@Override | ||
protected CPPCheckParser createParser() { | ||
return new CPPCheckParser(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/hm/hafner/analysis/parser/violations/DocFxAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import se.bjurr.violations.lib.parsers.DocFXParser; | ||
|
||
/** | ||
* Parses DocFX files. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public class DocFxAdapter extends AbstractViolationAdapter { | ||
/** | ||
* Creates a new instance of {@link DocFxAdapter}. | ||
*/ | ||
public DocFxAdapter() { | ||
super(Rule.TYPE); | ||
} | ||
|
||
@Override | ||
protected DocFXParser createParser() { | ||
return new DocFXParser(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/hm/hafner/analysis/parser/violations/ErrorProneAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import se.bjurr.violations.lib.parsers.GoogleErrorProneParser; | ||
|
||
/** | ||
* Parses ErrorProne files. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public class ErrorProneAdapter extends AbstractViolationAdapter { | ||
/** | ||
* Creates a new instance of {@link ErrorProneAdapter}. | ||
*/ | ||
public ErrorProneAdapter() { | ||
super(Rule.TYPE); | ||
} | ||
|
||
@Override | ||
protected GoogleErrorProneParser createParser() { | ||
return new GoogleErrorProneParser(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/hm/hafner/analysis/parser/violations/Flake8Adapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import se.bjurr.violations.lib.parsers.Flake8Parser; | ||
|
||
/** | ||
* Parses Flake8 files. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public class Flake8Adapter extends AbstractViolationAdapter { | ||
/** | ||
* Creates a new instance of {@link Flake8Adapter}. | ||
*/ | ||
public Flake8Adapter() { | ||
super(Rule.TYPE); | ||
} | ||
|
||
@Override | ||
protected Flake8Parser createParser() { | ||
return new Flake8Parser(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/hm/hafner/analysis/parser/violations/JsHintAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.hm.hafner.analysis.parser.violations; | ||
|
||
import se.bjurr.violations.lib.parsers.JSHintParser; | ||
|
||
/** | ||
* Parses JSHint files. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
public class JsHintAdapter extends AbstractViolationAdapter { | ||
/** | ||
* Creates a new instance of {@link JsHintAdapter}. | ||
*/ | ||
public JsHintAdapter() { | ||
super(Rule.TYPE); | ||
} | ||
|
||
@Override | ||
protected JSHintParser createParser() { | ||
return new JSHintParser(); | ||
} | ||
} |
Oops, something went wrong.