aboutsummaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2022-01-11 14:44:25 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2022-01-11 14:44:25 +0100
commite18b53f89116e8153e2023b3da55ee4c52443648 (patch)
tree1ba8befe70bef068da3cbe225c1bfcbdb78b3706 /config-model
parent82b4b0662519090c5bad8d95bca5f98ea07ae1b9 (diff)
Misc cleanup
Propagate jar file as method parameter. Fix linting warning on generic cast. Cleanup exception handling.
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComponentValidator.java44
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComponentValidatorTest.java10
2 files changed, 22 insertions, 32 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComponentValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComponentValidator.java
index 21e396959a7..66fe9308ae7 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComponentValidator.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComponentValidator.java
@@ -2,11 +2,12 @@
package com.yahoo.vespa.model.application.validation;
import com.yahoo.config.application.api.ApplicationPackage;
+import com.yahoo.config.application.api.ComponentInfo;
+import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.path.Path;
import com.yahoo.vespa.model.VespaModel;
-import com.yahoo.config.application.api.ComponentInfo;
-import com.yahoo.config.application.api.DeployLogger;
+
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
@@ -16,49 +17,39 @@ import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.logging.Level;
-import java.util.zip.ZipException;
/**
* A validator for bundles. Uses BND library for some of the validation (not active yet)
*
* @author hmusum
- * @since 2010-11-11
+ * @author bjorncs
*/
public class ComponentValidator extends Validator {
- private JarFile jarFile;
- public ComponentValidator() {
- }
-
- public ComponentValidator(JarFile jarFile) {
- this.jarFile = jarFile;
- }
+ public ComponentValidator() {}
@Override
public void validate(VespaModel model, DeployState deployState) {
ApplicationPackage app = deployState.getApplicationPackage();
for (ComponentInfo info : app.getComponentsInfo(deployState.getVespaVersion())) {
try {
- this.jarFile = new JarFile(app.getFileReference(Path.fromString(info.getPathRelativeToAppDir())));
- } catch (ZipException e) {
- throw new IllegalArgumentException("Error opening jar file '" + info.getPathRelativeToAppDir() +
- "'. Please check that this is a valid jar file");
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- validateAll(deployState.getDeployLogger());
+ 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) {
- e.printStackTrace();
+ throw new IllegalArgumentException(
+ "Failed to validate JAR file '" + info.getPathRelativeToAppDir() + "'", e);
}
}
}
- public void validateAll(DeployLogger deployLogger) throws IOException {
- validateOSGIHeaders(deployLogger);
+ void validateJarFile(DeployLogger deployLogger, JarFile jarFile) throws IOException {
+ validateOSGIHeaders(deployLogger, jarFile);
}
- public void validateOSGIHeaders(DeployLogger deployLogger) throws IOException {
+ public void validateOSGIHeaders(DeployLogger deployLogger, JarFile jarFile) throws IOException {
Manifest mf = jarFile.getManifest();
if (mf == null) {
throw new IllegalArgumentException("Non-existing or invalid manifest in " + jarFile.getName());
@@ -67,9 +58,8 @@ public class ComponentValidator extends Validator {
// Check for required OSGI headers
Attributes attributes = mf.getMainAttributes();
HashSet<String> mfAttributes = new HashSet<>();
- for (Object attributeSet : attributes.entrySet()) {
- Map.Entry<Object, Object> e = (Map.Entry<Object, Object>) attributeSet;
- mfAttributes.add(e.getKey().toString());
+ for (Map.Entry<Object,Object> entry : attributes.entrySet()) {
+ mfAttributes.add(entry.getKey().toString());
}
List<String> requiredOSGIHeaders = Arrays.asList(
"Bundle-ManifestVersion", "Bundle-Name", "Bundle-SymbolicName", "Bundle-Version");
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComponentValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComponentValidatorTest.java
index a375621d391..7045af60fc9 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComponentValidatorTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComponentValidatorTest.java
@@ -21,8 +21,8 @@ public class ComponentValidatorTest {
public void basicComponentValidation() throws Exception {
// Valid jar file
JarFile ok = new JarFile(new File(JARS_DIR + "ok.jar"));
- ComponentValidator componentValidator = new ComponentValidator(ok);
- componentValidator.validateAll(new BaseDeployLogger());
+ ComponentValidator componentValidator = new ComponentValidator();
+ componentValidator.validateJarFile(new BaseDeployLogger(), ok);
// No manifest
validateWithException("nomanifest.jar", "Non-existing or invalid manifest in " + JARS_DIR + "nomanifest.jar");
@@ -31,8 +31,8 @@ public class ComponentValidatorTest {
private void validateWithException(String jarName, String exceptionMessage) throws IOException {
try {
JarFile jarFile = new JarFile(JARS_DIR + jarName);
- ComponentValidator componentValidator = new ComponentValidator(jarFile);
- componentValidator.validateAll(new BaseDeployLogger());
+ ComponentValidator componentValidator = new ComponentValidator();
+ componentValidator.validateJarFile(new BaseDeployLogger(), jarFile);
assert (false);
} catch (IllegalArgumentException e) {
assertEquals(e.getMessage(), exceptionMessage);
@@ -50,7 +50,7 @@ public class ComponentValidatorTest {
}
};
- new ComponentValidator(new JarFile(JARS_DIR + "snapshot_bundle.jar")).validateAll(logger);
+ new ComponentValidator().validateJarFile(logger, new JarFile(JARS_DIR + "snapshot_bundle.jar"));
assertTrue(buffer.toString().contains("Deploying snapshot bundle"));
}
}