-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
13 additions
and
23 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
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
30 changes: 10 additions & 20 deletions
30
src/main/java/org/fedoraproject/javapackages/validator/validators/JarValidator.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 |
---|---|---|
@@ -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; | ||
} |
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