Skip to content

Commit f9ee1bd

Browse files
committed
less generics in guidelines
1 parent cb66f38 commit f9ee1bd

File tree

12 files changed

+89
-92
lines changed

12 files changed

+89
-92
lines changed

src/main/java/de/rub/nds/scanner/core/execution/Scanner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected SiteReportRater getSiteReportRater() {
127127
*
128128
* @return A list of guidelines.
129129
*/
130-
protected List<Guideline<ReportT>> getGuidelines() {
130+
protected List<Guideline> getGuidelines() {
131131
return List.of();
132132
}
133133

@@ -191,9 +191,9 @@ public ReportT scan() {
191191

192192
// Guideline Evaluation
193193
LOGGER.debug("Retrieving guidelines for evaluation");
194-
List<Guideline<ReportT>> guidelines = getGuidelines();
194+
List<Guideline> guidelines = getGuidelines();
195195
LOGGER.debug("Got a total of {} guidelines to evaluate", guidelines.size());
196-
for (Guideline<ReportT> guideline : guidelines) {
196+
for (Guideline guideline : guidelines) {
197197
LOGGER.debug("Executing evaluation of guideline '{}'", guideline.getName());
198198
GuidelineChecker<ReportT> checker = new GuidelineChecker<>(guideline);
199199
checker.fillReport(report);

src/main/java/de/rub/nds/scanner/core/guideline/FailedCheckGuidelineResult.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ public FailedCheckGuidelineResult(String checkName, GuidelineAdherence adherence
2323
public FailedCheckGuidelineResult(String checkName, GuidelineAdherence adherence, String hint) {
2424
super(checkName, adherence, hint);
2525
}
26+
27+
@Override
28+
public String toString() {
29+
return "Failed guideline check: " + getHint();
30+
}
2631
}

src/main/java/de/rub/nds/scanner/core/guideline/Guideline.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99
package de.rub.nds.scanner.core.guideline;
1010

11-
import de.rub.nds.scanner.core.report.ScanReport;
1211
import jakarta.xml.bind.annotation.*;
1312
import java.io.Serializable;
1413
import java.util.ArrayList;
@@ -18,19 +17,19 @@
1817
@XmlRootElement(name = "guideline")
1918
@XmlType(propOrder = {"name", "link", "checks"})
2019
@XmlAccessorType(XmlAccessType.FIELD)
21-
public class Guideline<ReportT extends ScanReport> implements Serializable {
20+
public class Guideline implements Serializable {
2221

2322
private String name;
2423
private String link;
2524

2625
@XmlAnyElement(lax = true)
27-
private List<GuidelineCheck<ReportT>> checks;
26+
private List<GuidelineCheck> checks;
2827

2928
/** Private no-arg constructor to please JAXB */
3029
@SuppressWarnings("unused")
3130
private Guideline() {}
3231

33-
public Guideline(String name, String link, List<GuidelineCheck<ReportT>> checks) {
32+
public Guideline(String name, String link, List<GuidelineCheck> checks) {
3433
this.name = name;
3534
this.link = link;
3635
this.checks = new ArrayList<>(checks);
@@ -77,7 +76,7 @@ public void setLink(String link) {
7776
*
7877
* @return an unmodifiable list of guideline checks
7978
*/
80-
public List<GuidelineCheck<ReportT>> getChecks() {
79+
public List<GuidelineCheck> getChecks() {
8180
return checks != null ? Collections.unmodifiableList(checks) : Collections.emptyList();
8281
}
8382

@@ -86,7 +85,7 @@ public List<GuidelineCheck<ReportT>> getChecks() {
8685
*
8786
* @param check the guideline check to add
8887
*/
89-
public void addCheck(GuidelineCheck<ReportT> check) {
88+
public void addCheck(GuidelineCheck check) {
9089
if (checks == null) {
9190
checks = new ArrayList<>();
9291
}

src/main/java/de/rub/nds/scanner/core/guideline/GuidelineCheck.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.apache.logging.log4j.Logger;
1616

1717
@XmlAccessorType(XmlAccessType.FIELD)
18-
public abstract class GuidelineCheck<ReportT extends ScanReport> {
18+
public abstract class GuidelineCheck {
1919

2020
private static final Logger LOGGER = LogManager.getLogger();
2121

@@ -46,19 +46,20 @@ public GuidelineCheck(
4646
* @param report the scan report to evaluate
4747
* @return the result of the guideline check evaluation
4848
*/
49-
public abstract GuidelineCheckResult evaluate(ReportT report);
49+
public abstract <ReportT extends ScanReport> GuidelineCheckResult evaluate(ReportT report);
5050

5151
/**
5252
* Checks if the report satisfies the condition required for this guideline check.
5353
*
5454
* @param report the scan report to check against the condition
5555
* @return true if the condition is satisfied or no condition is set, false otherwise
5656
*/
57-
public boolean passesCondition(ReportT report) {
57+
public <ReportT extends ScanReport> boolean passesCondition(ReportT report) {
5858
return this.passesCondition(report, this.condition);
5959
}
6060

61-
private boolean passesCondition(ReportT report, GuidelineCheckCondition condition) {
61+
private <ReportT extends ScanReport> boolean passesCondition(
62+
ReportT report, GuidelineCheckCondition condition) {
6263
if (condition == null) {
6364
return true;
6465
}

src/main/java/de/rub/nds/scanner/core/guideline/GuidelineChecker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class GuidelineChecker<ReportT extends ScanReport> {
1818

1919
protected static final Logger LOGGER = LogManager.getLogger();
2020

21-
private final Guideline<ReportT> guideline;
21+
private final Guideline guideline;
2222

23-
public GuidelineChecker(Guideline<ReportT> guideline) {
23+
public GuidelineChecker(Guideline guideline) {
2424
this.guideline = guideline;
2525
}
2626

@@ -32,7 +32,7 @@ public GuidelineChecker(Guideline<ReportT> guideline) {
3232
*/
3333
public void fillReport(ReportT report) {
3434
List<GuidelineCheckResult> results = new ArrayList<>();
35-
for (GuidelineCheck<ReportT> check : guideline.getChecks()) {
35+
for (GuidelineCheck check : guideline.getChecks()) {
3636
GuidelineCheckResult result;
3737
if (!check.passesCondition(report)) {
3838
result =

src/main/java/de/rub/nds/scanner/core/guideline/GuidelineIO.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package de.rub.nds.scanner.core.guideline;
1010

1111
import de.rub.nds.scanner.core.probe.AnalyzedProperty;
12-
import de.rub.nds.scanner.core.report.ScanReport;
1312
import de.rub.nds.scanner.core.util.JaxbSerializer;
1413
import jakarta.xml.bind.JAXBContext;
1514
import jakarta.xml.bind.JAXBException;
@@ -33,8 +32,7 @@
3332
import org.reflections.util.ConfigurationBuilder;
3433
import org.reflections.util.FilterBuilder;
3534

36-
public final class GuidelineIO<ReportT extends ScanReport>
37-
extends JaxbSerializer<Guideline<ReportT>> {
35+
public final class GuidelineIO extends JaxbSerializer<Guideline> {
3836

3937
private Logger LOGGER = LogManager.getLogger();
4038

@@ -112,11 +110,11 @@ private static List<String> listXmlFiles(ClassLoader classLoader, String folder)
112110
return xmlFilePaths;
113111
}
114112

115-
public List<Guideline<ReportT>> readGuidelines(ClassLoader classLoader, String subFolder) {
113+
public List<Guideline> readGuidelines(ClassLoader classLoader, String subFolder) {
116114

117115
LOGGER.debug("Loading guidelines from files...");
118116

119-
List<Guideline<ReportT>> guidelines = new ArrayList<>();
117+
List<Guideline> guidelines = new ArrayList<>();
120118

121119
try {
122120
// Get all files in guideline folder

src/test/java/de/rub/nds/scanner/core/execution/ScannerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static class TestScanner extends Scanner<TestReport, TestProbe, TestAfterProbe,
145145
private TestReport reportToReturn;
146146
private boolean checkPrerequisites = true;
147147
private SiteReportRater rater;
148-
private List<Guideline<TestReport>> guidelines = new ArrayList<>();
148+
private List<Guideline> guidelines = new ArrayList<>();
149149

150150
TestScanner(ExecutorConfig config) {
151151
super(config);
@@ -200,7 +200,7 @@ protected SiteReportRater getSiteReportRater() {
200200
}
201201

202202
@Override
203-
protected List<Guideline<TestReport>> getGuidelines() {
203+
protected List<Guideline> getGuidelines() {
204204
return guidelines;
205205
}
206206

@@ -216,7 +216,7 @@ public void setSiteReportRater(SiteReportRater rater) {
216216
this.rater = rater;
217217
}
218218

219-
public void setGuidelines(List<Guideline<TestReport>> guidelines) {
219+
public void setGuidelines(List<Guideline> guidelines) {
220220
this.guidelines = guidelines;
221221
}
222222

@@ -357,8 +357,8 @@ public void testScanWithGuidelines() {
357357
TestReport report;
358358
try (TestScanner scanner = new TestScanner(executorConfig)) {
359359

360-
Guideline<TestReport> guideline =
361-
new Guideline<>("TestGuideline", "http://example.com", new ArrayList<>());
360+
Guideline guideline =
361+
new Guideline("TestGuideline", "http://example.com", new ArrayList<>());
362362

363363
scanner.setGuidelines(List.of(guideline));
364364
report = scanner.scan();

src/test/java/de/rub/nds/scanner/core/guideline/GuidelineCheckTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public String getRemoteName() {
6464
}
6565
}
6666

67-
private static class ConcreteGuidelineCheck extends GuidelineCheck<TestScanReport> {
67+
private static class ConcreteGuidelineCheck extends GuidelineCheck {
6868
private final GuidelineAdherence fixedResult;
6969

7070
public ConcreteGuidelineCheck(String name, RequirementLevel level) {
@@ -85,7 +85,7 @@ public ConcreteGuidelineCheck(
8585
}
8686

8787
@Override
88-
public GuidelineCheckResult evaluate(TestScanReport report) {
88+
public <ReportT extends ScanReport> GuidelineCheckResult evaluate(ReportT report) {
8989
return new FailedCheckGuidelineResult(getName(), fixedResult);
9090
}
9191
}

src/test/java/de/rub/nds/scanner/core/guideline/GuidelineCheckerTest.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,40 +77,40 @@ public String getRemoteName() {
7777
}
7878
}
7979

80-
private static class PassingCheck extends GuidelineCheck<TestScanReport> {
80+
private static class PassingCheck extends GuidelineCheck {
8181
public PassingCheck(String name) {
8282
super(name, RequirementLevel.MUST);
8383
}
8484

8585
@Override
86-
public GuidelineCheckResult evaluate(TestScanReport report) {
86+
public <ReportT extends ScanReport> GuidelineCheckResult evaluate(ReportT report) {
8787
return new FailedCheckGuidelineResult(getName(), GuidelineAdherence.ADHERED);
8888
}
8989
}
9090

91-
private static class FailingCheck extends GuidelineCheck<TestScanReport> {
91+
private static class FailingCheck extends GuidelineCheck {
9292
public FailingCheck(String name) {
9393
super(name, RequirementLevel.MUST);
9494
}
9595

9696
@Override
97-
public GuidelineCheckResult evaluate(TestScanReport report) {
97+
public <ReportT extends ScanReport> GuidelineCheckResult evaluate(ReportT report) {
9898
return new FailedCheckGuidelineResult(getName(), GuidelineAdherence.VIOLATED);
9999
}
100100
}
101101

102-
private static class ConditionalCheck extends GuidelineCheck<TestScanReport> {
102+
private static class ConditionalCheck extends GuidelineCheck {
103103
public ConditionalCheck(String name, GuidelineCheckCondition condition) {
104104
super(name, RequirementLevel.SHOULD, condition);
105105
}
106106

107107
@Override
108-
public GuidelineCheckResult evaluate(TestScanReport report) {
108+
public <ReportT extends ScanReport> GuidelineCheckResult evaluate(ReportT report) {
109109
return new FailedCheckGuidelineResult(getName(), GuidelineAdherence.ADHERED);
110110
}
111111
}
112112

113-
private static class ExceptionThrowingCheck extends GuidelineCheck<TestScanReport> {
113+
private static class ExceptionThrowingCheck extends GuidelineCheck {
114114
private final RuntimeException exception;
115115

116116
public ExceptionThrowingCheck(String name, RuntimeException exception) {
@@ -119,12 +119,12 @@ public ExceptionThrowingCheck(String name, RuntimeException exception) {
119119
}
120120

121121
@Override
122-
public GuidelineCheckResult evaluate(TestScanReport report) {
122+
public <ReportT extends ScanReport> GuidelineCheckResult evaluate(ReportT report) {
123123
throw exception;
124124
}
125125
}
126126

127-
private Guideline<TestScanReport> guideline;
127+
private Guideline guideline;
128128
private TestScanReport report;
129129

130130
@BeforeEach
@@ -134,9 +134,9 @@ void setUp() {
134134

135135
@Test
136136
void testFillReportWithPassingChecks() {
137-
List<GuidelineCheck<TestScanReport>> checks =
137+
List<GuidelineCheck> checks =
138138
Arrays.asList(new PassingCheck("Check1"), new PassingCheck("Check2"));
139-
guideline = new Guideline<>("Test Guideline", "https://test.com", checks);
139+
guideline = new Guideline("Test Guideline", "https://test.com", checks);
140140
GuidelineChecker<TestScanReport> checker = new GuidelineChecker<>(guideline);
141141

142142
checker.fillReport(report);
@@ -152,12 +152,12 @@ void testFillReportWithPassingChecks() {
152152

153153
@Test
154154
void testFillReportWithFailingChecks() {
155-
List<GuidelineCheck<TestScanReport>> checks =
155+
List<GuidelineCheck> checks =
156156
Arrays.asList(
157157
new PassingCheck("Check1"),
158158
new FailingCheck("Check2"),
159159
new FailingCheck("Check3"));
160-
guideline = new Guideline<>("Test Guideline", "https://test.com", checks);
160+
guideline = new Guideline("Test Guideline", "https://test.com", checks);
161161
GuidelineChecker<TestScanReport> checker = new GuidelineChecker<>(guideline);
162162

163163
checker.fillReport(report);
@@ -174,11 +174,11 @@ void testFillReportWithUnmetConditions() {
174174
TestAnalyzedProperty property = new TestAnalyzedProperty("TestProp");
175175
GuidelineCheckCondition condition = new GuidelineCheckCondition(property, TestResults.TRUE);
176176

177-
List<GuidelineCheck<TestScanReport>> checks =
177+
List<GuidelineCheck> checks =
178178
Arrays.asList(
179179
new PassingCheck("Check1"),
180180
new ConditionalCheck("ConditionalCheck", condition));
181-
guideline = new Guideline<>("Test Guideline", "https://test.com", checks);
181+
guideline = new Guideline("Test Guideline", "https://test.com", checks);
182182
GuidelineChecker<TestScanReport> checker = new GuidelineChecker<>(guideline);
183183

184184
// Set condition to false
@@ -202,9 +202,9 @@ void testFillReportWithMetConditions() {
202202
TestAnalyzedProperty property = new TestAnalyzedProperty("TestProp");
203203
GuidelineCheckCondition condition = new GuidelineCheckCondition(property, TestResults.TRUE);
204204

205-
List<GuidelineCheck<TestScanReport>> checks =
205+
List<GuidelineCheck> checks =
206206
Arrays.asList(new ConditionalCheck("ConditionalCheck", condition));
207-
guideline = new Guideline<>("Test Guideline", "https://test.com", checks);
207+
guideline = new Guideline("Test Guideline", "https://test.com", checks);
208208
GuidelineChecker<TestScanReport> checker = new GuidelineChecker<>(guideline);
209209

210210
// Set condition to true
@@ -222,12 +222,12 @@ void testFillReportWithMetConditions() {
222222
@Test
223223
void testFillReportWithExceptionThrowingCheck() {
224224
RuntimeException exception = new RuntimeException("Test exception");
225-
List<GuidelineCheck<TestScanReport>> checks =
225+
List<GuidelineCheck> checks =
226226
Arrays.asList(
227227
new PassingCheck("Check1"),
228228
new ExceptionThrowingCheck("ExceptionCheck", exception),
229229
new PassingCheck("Check3"));
230-
guideline = new Guideline<>("Test Guideline", "https://test.com", checks);
230+
guideline = new Guideline("Test Guideline", "https://test.com", checks);
231231
GuidelineChecker<TestScanReport> checker = new GuidelineChecker<>(guideline);
232232

233233
checker.fillReport(report);
@@ -247,10 +247,10 @@ void testFillReportWithExceptionThrowingCheck() {
247247
@Test
248248
void testFillReportWithError() {
249249
Error error = new OutOfMemoryError("Test error");
250-
List<GuidelineCheck<TestScanReport>> checks =
250+
List<GuidelineCheck> checks =
251251
Arrays.asList(
252252
new ExceptionThrowingCheck("ErrorCheck", new RuntimeException(error)));
253-
guideline = new Guideline<>("Test Guideline", "https://test.com", checks);
253+
guideline = new Guideline("Test Guideline", "https://test.com", checks);
254254
GuidelineChecker<TestScanReport> checker = new GuidelineChecker<>(guideline);
255255

256256
checker.fillReport(report);
@@ -265,7 +265,7 @@ void testFillReportWithError() {
265265

266266
@Test
267267
void testFillReportWithEmptyChecks() {
268-
guideline = new Guideline<>("Test Guideline", "https://test.com", new ArrayList<>());
268+
guideline = new Guideline("Test Guideline", "https://test.com", new ArrayList<>());
269269
GuidelineChecker<TestScanReport> checker = new GuidelineChecker<>(guideline);
270270

271271
checker.fillReport(report);
@@ -280,13 +280,13 @@ void testFillReportWithMixedResults() {
280280
TestAnalyzedProperty property = new TestAnalyzedProperty("TestProp");
281281
GuidelineCheckCondition condition = new GuidelineCheckCondition(property, TestResults.TRUE);
282282

283-
List<GuidelineCheck<TestScanReport>> checks =
283+
List<GuidelineCheck> checks =
284284
Arrays.asList(
285285
new PassingCheck("PassCheck"),
286286
new FailingCheck("FailCheck"),
287287
new ConditionalCheck("UnmetConditionCheck", condition),
288288
new ExceptionThrowingCheck("ExceptionCheck", new RuntimeException("Test")));
289-
guideline = new Guideline<>("Mixed Guideline", "https://mixed.com", checks);
289+
guideline = new Guideline("Mixed Guideline", "https://mixed.com", checks);
290290
GuidelineChecker<TestScanReport> checker = new GuidelineChecker<>(guideline);
291291

292292
// Set condition to false

0 commit comments

Comments
 (0)