From d4c30771a13f9f3df9edf234fe324ca4dad8b3cb Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Wed, 12 Jan 2022 18:00:11 +0100 Subject: Create test jars in unit test instead of using pre-made Unpack checked-in test JARs and package to JARs in test case instead. Don't use full path in produced warning/error messages. --- .../application/validation/BundleValidator.java | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java') diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java index b6b9190fedf..04d4ac35e6a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java @@ -12,6 +12,7 @@ import com.yahoo.path.Path; import com.yahoo.vespa.model.VespaModel; import java.io.IOException; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -40,29 +41,29 @@ public class BundleValidator extends Validator { public void validate(VespaModel model, DeployState deployState) { ApplicationPackage app = deployState.getApplicationPackage(); for (ComponentInfo info : app.getComponentsInfo(deployState.getVespaVersion())) { + Path path = Path.fromString(info.getPathRelativeToAppDir()); try { - Path path = Path.fromString(info.getPathRelativeToAppDir()); DeployLogger deployLogger = deployState.getDeployLogger(); deployLogger.log(Level.FINE, String.format("Validating bundle at '%s'", path)); JarFile jarFile = new JarFile(app.getFileReference(path)); validateJarFile(deployLogger, jarFile); } catch (IOException e) { throw new IllegalArgumentException( - "Failed to validate JAR file '" + info.getPathRelativeToAppDir() + "'", e); + "Failed to validate JAR file '" + path.last() + "'", e); } } } void validateJarFile(DeployLogger deployLogger, JarFile jarFile) throws IOException { Manifest manifest = jarFile.getManifest(); - String jarPath = jarFile.getName(); + String filename = Paths.get(jarFile.getName()).getFileName().toString(); if (manifest == null) { - throw new IllegalArgumentException("Non-existing or invalid manifest in " + jarPath); + throw new IllegalArgumentException("Non-existing or invalid manifest in " + filename); } - validateManifest(deployLogger, jarPath, manifest); + validateManifest(deployLogger, filename, manifest); } - void validateManifest(DeployLogger deployLogger, String jarPath, Manifest mf) { + private void validateManifest(DeployLogger deployLogger, String filename, Manifest mf) { // Check for required OSGI headers Attributes attributes = mf.getMainAttributes(); HashSet mfAttributes = new HashSet<>(); @@ -74,21 +75,21 @@ public class BundleValidator extends Validator { for (String header : requiredOSGIHeaders) { if (!mfAttributes.contains(header)) { throw new IllegalArgumentException("Required OSGI header '" + header + - "' was not found in manifest in '" + jarPath + "'"); + "' was not found in manifest in '" + filename + "'"); } } if (attributes.getValue("Bundle-Version").endsWith(".SNAPSHOT")) { - deployLogger.logApplicationPackage(Level.WARNING, "Deploying snapshot bundle " + jarPath + + deployLogger.logApplicationPackage(Level.WARNING, "Deploying snapshot bundle " + filename + ".\nTo use this bundle, you must include the qualifier 'SNAPSHOT' in the version specification in services.xml."); } if (attributes.getValue("Import-Package") != null) { - validateImportedPackages(deployLogger, jarPath, mf); + validateImportedPackages(deployLogger, filename, mf); } } - private static void validateImportedPackages(DeployLogger deployLogger, String jarPath, Manifest manifest) { + private static void validateImportedPackages(DeployLogger deployLogger, String filename, Manifest manifest) { Domain osgiHeaders = Domain.domain(manifest); Parameters importPackage = osgiHeaders.getImportPackage(); Map> deprecatedPackagesInUse = new HashMap<>(); @@ -112,7 +113,7 @@ public class BundleValidator extends Validator { String.format("For JAR file '%s': \n" + "Manifest imports the following Java packages from '%s': %s. \n" + "%s", - jarPath, artifact.name, packagesInUse, artifact.description)); + filename, artifact.name, packagesInUse, artifact.description)); }); } -- cgit v1.2.3