Skip to content

Commit

Permalink
Refactor Elementwise validator
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoncek committed Oct 4, 2023
1 parent f5a06bb commit 690ccff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class BytecodeVersionJarValidator extends JarValidator {
@Override
public void validateJarEntry(RpmFile rpm, CpioArchiveEntry rpmEntry, byte[] content) throws Exception {
public void acceptJarEntry(RpmFile rpm, CpioArchiveEntry rpmEntry, byte[] content) throws Exception {
var jarPath = Paths.get(rpmEntry.getName().substring(1));
var classVersions = new TreeMap<Path, Short>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected ElementwiseValidator(Predicate<RpmInfo> filter) {
}

@Override
public final void validate(Iterable<RpmFile> rpms) throws Exception {
public void validate(Iterable<RpmFile> rpms) throws Exception {
for (var rpm : rpms) {
if (filter.test(rpm.getInfo())) {
validate(rpm);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
package org.fedoraproject.javapackages.validator.validators;

import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
import org.fedoraproject.javadeptools.rpm.RpmArchiveInputStream;
import java.util.function.Predicate;

import org.fedoraproject.javadeptools.rpm.RpmFile;
import org.fedoraproject.javadeptools.rpm.RpmInfo;
import org.fedoraproject.javapackages.validator.Common;
import org.fedoraproject.javapackages.validator.RpmJarConsumer;
import org.fedoraproject.javapackages.validator.TextDecorator.Decoration;

public abstract class JarValidator extends ElementwiseValidator {
protected static final Decoration DECORATION_JAR = Decoration.bright_blue;
public abstract class JarValidator extends ElementwiseValidator implements RpmJarConsumer {
public static final Decoration DECORATION_JAR = Decoration.bright_blue;

protected JarValidator() {
super(RpmInfo::isBinaryPackage);
}

protected JarValidator(Predicate<RpmInfo> filter) {
super(filter);
}

@Override
public void validate(RpmFile rpm) throws Exception {
try (var is = new RpmArchiveInputStream(rpm)) {
for (CpioArchiveEntry rpmEntry; ((rpmEntry = is.getNextEntry()) != null);) {
if (!rpmEntry.isSymbolicLink() && rpmEntry.getName().endsWith(".jar")) {
var content = new byte[(int) rpmEntry.getSize()];

if (is.read(content) != content.length) {
throw Common.INCOMPLETE_READ;
}

validateJarEntry(rpm, rpmEntry, content);
}
}
}
accept(rpm);
}

public abstract void validateJarEntry(RpmFile rpm, CpioArchiveEntry rpmEntry, byte[] content) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class JpmsProvidesValidator extends JarValidator {
private static Pattern VERSIONS_PATTERN = Pattern.compile("META-INF/versions/\\d+/module-info\\.class");

@Override
public void validateJarEntry(RpmFile rpm, CpioArchiveEntry rpmEntry, byte[] content) throws Exception {
public void acceptJarEntry(RpmFile rpm, CpioArchiveEntry rpmEntry, byte[] content) throws Exception {
var moduleNames = new ArrayList<Pair<String, String>>();
var rpmEntryString = Common.getEntryPath(rpmEntry).toString();

Expand Down

0 comments on commit 690ccff

Please sign in to comment.