Skip to content

Commit

Permalink
Changes based on Hannes suggestions and running a linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
nizarbenalla committed Dec 20, 2024
1 parent 1cf5715 commit 95f61e6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
}
});
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface HtmlChecker extends Checker {
* @param line the line number on which the start tag for an element was found
* @param name the name of the tag
* @param attrs the attributes of the tag
* @param selfClosing whether or not the tag is self-closing
* @param selfClosing whether the tag is self-closing
*/
void startElement(int line, String name, Map<String, String> attrs, boolean selfClosing);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public boolean isOK() {
}

@Override
public void close() throws IOException {
public void close() {
report();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public boolean isOK() {
}

@Override
public void close() throws IOException {
public void close() {
if (!isOK()) {
report();
throw new RuntimeException("Found HTML files with missing doctype declaration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class ExtLinkChecker implements HtmlChecker, AutoCloseable {
private static final Path testBasePath = Path.of(System.getProperty("test.src"));
private static final Set<String> extLinks = new HashSet<>();

private static final String currentVersion = String.valueOf(Runtime.version().feature());

static {
String input = null;
try {
Expand All @@ -51,8 +53,8 @@ public class ExtLinkChecker implements HtmlChecker, AutoCloseable {
throw new RuntimeException(e);
}
extLinks.addAll(input.lines()
.map(line -> line.replaceAll("\\@\\@JAVASE_VERSION\\@\\@", String.valueOf(Runtime.version().feature())))
.filter(line -> !line.startsWith("#"))
.map(line -> line.replaceAll("\\@\\@JAVASE_VERSION\\@\\@", currentVersion))
.collect(Collectors.toUnmodifiableSet()));
}

Expand Down Expand Up @@ -107,7 +109,7 @@ private void foundReference(int line, String ref) {
String fragment = null;

// The checker runs into a problem with links that have more than one hash character.
// You cannot create a URI unless you convert the second hash character into
// You cannot create a URI unless the second hash is escaped.

int firstHashIndex = ref.indexOf('#');
int lastHashIndex = ref.lastIndexOf('#');
Expand Down Expand Up @@ -149,7 +151,7 @@ public boolean isOK() {
}

@Override
public void close() throws IOException {
public void close() {
report();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ public void report() {

int anchors = 0;
for (IDTable t : allFiles.values()) {
anchors += t.map.values().stream()
anchors += (int) t.map.values().stream()
.filter(e -> !e.getReferences().isEmpty())
.count();
}
for (IDTable t : allURIs.values()) {
anchors += t.map.values().stream()
anchors += (int) t.map.values().stream()
.filter(e -> !e.references.isEmpty())
.count();
}
Expand Down Expand Up @@ -227,7 +227,7 @@ public boolean isOK() {
}

@Override
public void close() throws IOException {
public void close() {
report();
if (!isOK()) {
throw new RuntimeException(
Expand All @@ -248,7 +248,7 @@ private void foundReference(int line, String ref) {
String fragment = null;

// The checker runs into a problem with links that have more than one hash character.
// You cannot create a URI unless you convert the second hash character into
// You cannot create a URI unless the second hash is escaped.

int firstHashIndex = ref.indexOf('#');
int lastHashIndex = ref.lastIndexOf('#');
Expand Down Expand Up @@ -364,34 +364,6 @@ Set<Position> getReferences() {
}
}

static class URIComparator implements Comparator<URI> {
final HostComparator hostComparator = new HostComparator();

@Override
public int compare(URI o1, URI o2) {
if (o1.isOpaque() || o2.isOpaque()) {
return o1.compareTo(o2);
}
String h1 = o1.getHost();
String h2 = o2.getHost();
String s1 = o1.getScheme();
String s2 = o2.getScheme();
if (h1 == null || h1.isEmpty() || s1 == null || s1.isEmpty()
|| h2 == null || h2.isEmpty() || s2 == null || s2.isEmpty()) {
return o1.compareTo(o2);
}
int v = hostComparator.compare(h1, h2);
if (v != 0) {
return v;
}
v = s1.compareTo(s2);
if (v != 0) {
return v;
}
return o1.compareTo(o2);
}
}

static class HostComparator implements Comparator<String> {
@Override
public int compare(String h1, String h2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -42,14 +41,14 @@

public class TidyChecker implements FileChecker, AutoCloseable {
private final Path TIDY;
Map<Pattern, Integer> counts = new HashMap<>();
Pattern okPattern = Pattern.compile("No warnings or errors were found.");
Pattern countPattern = Pattern.compile("([0-9]+) warnings, ([0-9]+) errors were found!.*?(Not all warnings/errors were shown.)?");
Pattern countPattern2 = Pattern.compile("Tidy found ([0-9]+) warning[s]? and ([0-9]+) error[s]?!.*?(Not all warnings/errors were shown.)?");
Pattern cssPattern = Pattern.compile("You are recommended to use CSS.*");
Pattern guardPattern = Pattern.compile("(line [0-9]+ column [0-9]+ - |[^:]+:[0-9]+:[0-9]+: )(Error|Warning):.*");
final Map<Pattern, Integer> counts = new HashMap<>();
final Pattern okPattern = Pattern.compile("No warnings or errors were found.");
final Pattern countPattern = Pattern.compile("([0-9]+) warnings, ([0-9]+) errors were found!.*?(Not all warnings/errors were shown.)?");
final Pattern countPattern2 = Pattern.compile("Tidy found ([0-9]+) warning[s]? and ([0-9]+) error[s]?!.*?(Not all warnings/errors were shown.)?");
final Pattern cssPattern = Pattern.compile("You are recommended to use CSS.*");
final Pattern guardPattern = Pattern.compile("(line [0-9]+ column [0-9]+ - |[^:]+:[0-9]+:[0-9]+: )(Error|Warning):.*");

Pattern[] patterns = {
final Pattern[] patterns = {
Pattern.compile(".*Error: <.*> is not recognized!"),
Pattern.compile(".*Error: missing quote mark for attribute value"),
Pattern.compile(".*Warning: '<' \\+ '/' \\+ letter not allowed here"),
Expand Down Expand Up @@ -135,7 +134,7 @@ public void checkFiles(List<Path> sb) {
}
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException();
}
}

Expand Down

0 comments on commit 95f61e6

Please sign in to comment.