115 lines
4.3 KiB
Java
115 lines
4.3 KiB
Java
package org.fedoraproject.javapackages.validator.validators.jp;
|
|
|
|
import java.nio.file.Path;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
import org.fedoraproject.javapackages.validator.spi.Decorated;
|
|
import org.fedoraproject.javapackages.validator.util.BytecodeVersionJarValidator;
|
|
import org.fedoraproject.javapackages.validator.util.Common;
|
|
|
|
import io.kojan.javadeptools.rpm.RpmPackage;
|
|
|
|
public class BytecodeVersionJarValidatorJP extends BytecodeVersionJarValidator {
|
|
@Override
|
|
public String getTestName() {
|
|
return "/java/jp/bytecode_version";
|
|
}
|
|
|
|
private Set<String> packagesReqVersion8 = Set.of(new String[] {
|
|
"maven",
|
|
"apache-commons-cli",
|
|
"apache-commons-codec",
|
|
"apache-commons-io",
|
|
"apache-commons-lang3",
|
|
"atinject",
|
|
"cdi-api",
|
|
"google-guice",
|
|
"guava",
|
|
"httpcomponents-client",
|
|
"httpcomponents-core",
|
|
"jakarta-annotations",
|
|
"jansi",
|
|
"jsr-305",
|
|
"maven-resolver",
|
|
"maven-shared-utils",
|
|
"maven-wagon",
|
|
"plexus-cipher",
|
|
"plexus-classworlds",
|
|
"plexus-containers",
|
|
"plexus-interpolation",
|
|
"plexus-sec-dispatcher",
|
|
"plexus-utils",
|
|
"sisu",
|
|
"slf4j",
|
|
|
|
"ant",
|
|
"antlr",
|
|
"apache-commons-net",
|
|
"bcel",
|
|
"bsf",
|
|
"jakarta-activation1",
|
|
"jakarta-mail",
|
|
"jakarta-oro",
|
|
"jdepend",
|
|
"jsch",
|
|
"jzlib",
|
|
"regexp",
|
|
"xalan-j2",
|
|
"xerces-j2",
|
|
"xml-commons-apis",
|
|
"xml-commons-resolver",
|
|
});
|
|
|
|
@Override
|
|
public void validate(RpmPackage rpm, Path jarPath, Map<Path, Version> classVersions) {
|
|
for (var entry : classVersions.entrySet()) {
|
|
Path classPath = entry.getKey();
|
|
int version = entry.getValue().major();
|
|
int maxAllowedVersion = 21;
|
|
int expected;
|
|
|
|
if (classPath.endsWith("module-info.class") || classPath.endsWith("package-info.class")) {
|
|
// pass
|
|
} else if (classPath.startsWith("META-INF/versions")) {
|
|
// JEP 238: Multi-Release JAR Files
|
|
// https://openjdk.org/jeps/238
|
|
|
|
if (version > 44 + (expected = Short.parseShort(classPath.getName(2).toString()))) {
|
|
fail("{0}: {1}: {2}: class bytecode version is {3} which is larger than {4}",
|
|
Decorated.rpm(rpm),
|
|
Decorated.custom(jarPath, DECORATION_JAR),
|
|
Decorated.struct(classPath),
|
|
Decorated.actual(version),
|
|
Decorated.expected(expected));
|
|
continue;
|
|
} else {
|
|
// pass
|
|
}
|
|
} else if (packagesReqVersion8.contains(Common.getPackageName(rpm.getInfo())) && version > 44 + 8) {
|
|
fail("{0}: {1}: {2}: class bytecode version is {3} which is larger than {4} (package is required to have a bytecode version compatible with JVM 8)",
|
|
Decorated.rpm(rpm),
|
|
Decorated.custom(jarPath, DECORATION_JAR),
|
|
Decorated.struct(classPath),
|
|
Decorated.actual(version),
|
|
Decorated.expected(44 + 8));
|
|
continue;
|
|
} else if (version > 44 + maxAllowedVersion) {
|
|
fail("{0}: {1}: {2}: class bytecode version is {3} which is larger than {4} (all packages should have bytecode version compatible with JVM {5})",
|
|
Decorated.rpm(rpm),
|
|
Decorated.custom(jarPath, DECORATION_JAR),
|
|
Decorated.struct(classPath),
|
|
Decorated.actual(version),
|
|
Decorated.expected(44 + maxAllowedVersion),
|
|
Decorated.plain(maxAllowedVersion));
|
|
continue;
|
|
}
|
|
|
|
pass("{0}: {1}: {2}: class bytecode version: {3}",
|
|
Decorated.rpm(rpm),
|
|
Decorated.custom(jarPath, DECORATION_JAR),
|
|
Decorated.struct(classPath),
|
|
Decorated.actual(version));
|
|
}
|
|
}
|
|
}
|