From 50f898c1864dada0e8b8f96eb742947fafe4dd06 Mon Sep 17 00:00:00 2001 From: gjoranv Date: Sun, 20 Oct 2019 19:09:07 +0200 Subject: Add test with a bundle using artifact version as ExportPackages - Verify that useArtifactVersionForExportPackages is honoured also for a compile scoped bundle dependency. --- .../src/test/java/com/yahoo/BundleIT.java | 18 ++---- .../java/com/yahoo/ExportPackageVersionIT.java | 68 ++++++++++++++++++++++ 2 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionIT.java (limited to 'bundle-plugin-test/integration-test/src/test/java/com/yahoo') diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleIT.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleIT.java index 2ed1d7f0bc6..5e76b08ab9f 100644 --- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleIT.java +++ b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/BundleIT.java @@ -9,10 +9,10 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collection; import java.util.jar.Attributes; import java.util.jar.JarFile; @@ -54,19 +54,13 @@ public class BundleIT { } } - private File findBundleJar(String bundleName) { - File[] componentFile = new File(TEST_BUNDLE_PATH).listFiles(new FilenameFilter() { - @Override - public boolean accept(File file, String fileName) { - return fileName.endsWith("-bundle.jar"); - } - }); - - if (componentFile.length != 1) { - throw new RuntimeException("Failed finding component jar file"); + static File findBundleJar(String bundleName) { + Path bundlePath = Paths.get(TEST_BUNDLE_PATH, bundleName + "-bundle.jar"); + if (! Files.exists(bundlePath)) { + throw new RuntimeException("Failed finding component jar file: " + bundlePath); } - return componentFile[0]; + return bundlePath.toFile(); } @Test diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionIT.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionIT.java new file mode 100644 index 00000000000..e2cee71ca9e --- /dev/null +++ b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/ExportPackageVersionIT.java @@ -0,0 +1,68 @@ +// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.jar.Attributes; +import java.util.jar.JarFile; + +import static com.yahoo.BundleIT.findBundleJar; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; + +/** + * Verifies that the 'useArtifactVersionForExportPackages' setting for the bundle-plugin works as intended. + * + * @author gjoranv + */ +public class ExportPackageVersionIT { + + private static Attributes mainAttributes; + + @BeforeClass + public static void setup() { + try { + File componentJar = findBundleJar("artifact-version-for-exports"); + mainAttributes = new JarFile(componentJar).getManifest().getMainAttributes(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Test + public void artifact_version_without_qualifier_is_used_as_export_version() { + // Bundle-Version is artifact version without qualifier + String bundleVersion = mainAttributes.getValue("Bundle-Version"); + String expectedExport = "ai.vespa.noversion;version=" + bundleVersion; + + String exportPackage = mainAttributes.getValue("Export-Package"); + assertThat(exportPackage, containsString(expectedExport)); + + // Verify that there is no qualifier + assertThat(exportPackage, not(containsString(expectedExport + "."))); + } + + @Test + public void explicit_version_in_ExportPackage_annotation_overrides_artifact_version() { + String exportPackage = mainAttributes.getValue("Export-Package"); + assertThat(exportPackage, containsString("ai.vespa.explicitversion;version=2.4.6.RELEASE")); + } + + @Test + public void artifact_version_of_dependency_is_used_as_export_version_for_package_in_compile_scoped_dependency() { + String exportPackage = mainAttributes.getValue("Export-Package"); + // Verify against the artifact version from the test bundle's pom. + assertThat(exportPackage, containsString("ai.vespa.noversion_dep;version=3.2.1")); + } + + @Test + public void explicit_version_in_ExportPackage_annotation_overrides_artifact_version_of_compile_scoped_dependency() { + String exportPackage = mainAttributes.getValue("Export-Package"); + assertThat(exportPackage, containsString("ai.vespa.explicitversion_dep;version=3.6.9.RELEASE")); + } + +} -- cgit v1.2.3