aboutsummaryrefslogtreecommitdiffstats
path: root/bundle-plugin-test
diff options
context:
space:
mode:
authorgjoranv <gv@yahooinc.com>2023-06-09 16:52:52 +0200
committergjoranv <gv@yahooinc.com>2023-06-09 16:56:14 +0200
commit7ac829699dc908bd747f97714a1b8fc9a12ded18 (patch)
treea74c25e8ed608853657f274260fbb536ab6c5ecf /bundle-plugin-test
parentacd484916c47a0c158a29d3c77bb34b1f502b78f (diff)
Add test for non-public api manifest header..
and add new test bundle to avoid depending on proper Vespa bundles.
Diffstat (limited to 'bundle-plugin-test')
-rw-r--r--bundle-plugin-test/integration-test/pom.xml6
-rw-r--r--bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java30
-rw-r--r--bundle-plugin-test/test-bundles/export-packages-lib/pom.xml31
-rw-r--r--bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/ai/vespa/lib/non_public/package-info.java5
-rw-r--r--bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/ai/vespa/lib/public_api/package-info.java7
-rw-r--r--bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/com/yahoo/lib/non_pubilc/package-info.java5
-rw-r--r--bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/com/yahoo/lib/public_api/package-info.java7
-rw-r--r--bundle-plugin-test/test-bundles/main/pom.xml4
-rw-r--r--bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/non_public/package-info.java5
-rw-r--r--bundle-plugin-test/test-bundles/pom.xml1
10 files changed, 94 insertions, 7 deletions
diff --git a/bundle-plugin-test/integration-test/pom.xml b/bundle-plugin-test/integration-test/pom.xml
index acd075d0365..57ca134ed05 100644
--- a/bundle-plugin-test/integration-test/pom.xml
+++ b/bundle-plugin-test/integration-test/pom.xml
@@ -58,6 +58,12 @@
</dependency>
<dependency>
<groupId>com.yahoo.vespa.bundle-plugin</groupId>
+ <artifactId>export-packages-lib</artifactId>
+ <classifier>bundle</classifier>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.bundle-plugin</groupId>
<artifactId>non-public-api-usage</artifactId>
<classifier>bundle</classifier>
<version>${project.version}</version>
diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java
index 673d7d8e09e..a9b482377fa 100644
--- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java
+++ b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java
@@ -10,12 +10,15 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Arrays;
import java.util.Enumeration;
+import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -105,21 +108,38 @@ public class BundleTest {
@Test
void require_that_manifest_contains_public_api_for_this_bundle_and_embedded_bundles() {
- assertEquals("com.yahoo.test,com.yahoo.vespa.defaults", mainAttributes.getValue("X-JDisc-PublicApi-Package"));
+ var publicApiAttribute = mainAttributes.getValue("X-JDisc-PublicApi-Package");
+ assertNotNull(publicApiAttribute);
+ var publicApi = Arrays.stream(publicApiAttribute.split(",")).collect(Collectors.toSet());
+
+ var expected = List.of("ai.vespa.lib.public_api", "com.yahoo.lib.public_api", "com.yahoo.test");
+ assertEquals(expected.size(), publicApi.size());
+ expected.forEach(pkg -> assertTrue(publicApi.contains(pkg), "Public api did not contain %s".formatted(pkg)));
}
@Test
+ void require_that_manifest_contains_non_public_api_for_this_bundle_and_embedded_bundles() {
+ var nonPublicApiAttribute = mainAttributes.getValue("X-JDisc-Non-PublicApi-Export-Package");
+ assertNotNull(nonPublicApiAttribute);
+ var nonPublicApi = Arrays.stream(nonPublicApiAttribute.split(",")).collect(Collectors.toSet());
+
+ var expected = List.of("ai.vespa.lib.non_public", "com.yahoo.lib.non_public", "com.yahoo.non_public");
+ assertEquals(expected.size(), nonPublicApi.size());
+ expected.forEach(pkg -> assertTrue(nonPublicApi.contains(pkg), "Non-public api did not contain %s".formatted(pkg)));
+ }
+
+ @Test
void require_that_manifest_contains_bundle_class_path() {
String bundleClassPath = mainAttributes.getValue("Bundle-ClassPath");
assertTrue(bundleClassPath.contains(".,"));
- Pattern jrtPattern = Pattern.compile("dependencies/defaults" + snapshotOrVersionOrNone);
- assertTrue(jrtPattern.matcher(bundleClassPath).find(), "Bundle class path did not contain 'defaults''.");
+ Pattern jrtPattern = Pattern.compile("dependencies/export-packages-lib" + snapshotOrVersionOrNone);
+ assertTrue(jrtPattern.matcher(bundleClassPath).find(), "Bundle class path did not contain 'export-packages-lib''.");
}
@Test
void require_that_component_jar_file_contains_compile_artifacts() {
- String requiredDep = "dependencies/defaults";
+ String requiredDep = "dependencies/export-packages-lib";
Pattern depPattern = Pattern.compile(requiredDep + snapshotOrVersionOrNone);
ZipEntry depEntry = null;
@@ -133,7 +153,7 @@ public class BundleTest {
}
}
}
- assertNotNull(depEntry, "Component jar file did not contain 'defaults' dependency.");
+ assertNotNull(depEntry, "Component jar file did not contain 'export-packages-lib' dependency.");
}
diff --git a/bundle-plugin-test/test-bundles/export-packages-lib/pom.xml b/bundle-plugin-test/test-bundles/export-packages-lib/pom.xml
new file mode 100644
index 00000000000..09eedda0b98
--- /dev/null
+++ b/bundle-plugin-test/test-bundles/export-packages-lib/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.yahoo.vespa.bundle-plugin</groupId>
+ <artifactId>test-bundles</artifactId>
+ <version>8-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>export-packages-lib</artifactId>
+ <version>8-SNAPSHOT</version>
+ <packaging>container-plugin</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <!-- Must be an internal bundle to get manifest header for non-public export packages -->
+ <bundleType>INTERNAL</bundleType>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/ai/vespa/lib/non_public/package-info.java b/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/ai/vespa/lib/non_public/package-info.java
new file mode 100644
index 00000000000..18841cf6f37
--- /dev/null
+++ b/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/ai/vespa/lib/non_public/package-info.java
@@ -0,0 +1,5 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+@ExportPackage
+package ai.vespa.lib.non_public;
+
+import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/ai/vespa/lib/public_api/package-info.java b/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/ai/vespa/lib/public_api/package-info.java
new file mode 100644
index 00000000000..c586faf6bb6
--- /dev/null
+++ b/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/ai/vespa/lib/public_api/package-info.java
@@ -0,0 +1,7 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+@ExportPackage
+@PublicApi
+package ai.vespa.lib.public_api;
+
+import com.yahoo.api.annotations.PublicApi;
+import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/com/yahoo/lib/non_pubilc/package-info.java b/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/com/yahoo/lib/non_pubilc/package-info.java
new file mode 100644
index 00000000000..a3368af200c
--- /dev/null
+++ b/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/com/yahoo/lib/non_pubilc/package-info.java
@@ -0,0 +1,5 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+@ExportPackage
+package com.yahoo.lib.non_public;
+
+import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/com/yahoo/lib/public_api/package-info.java b/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/com/yahoo/lib/public_api/package-info.java
new file mode 100644
index 00000000000..b0ff91eb53e
--- /dev/null
+++ b/bundle-plugin-test/test-bundles/export-packages-lib/src/main/java/com/yahoo/lib/public_api/package-info.java
@@ -0,0 +1,7 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+@ExportPackage
+@PublicApi
+package com.yahoo.lib.public_api;
+
+import com.yahoo.api.annotations.PublicApi;
+import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/bundle-plugin-test/test-bundles/main/pom.xml b/bundle-plugin-test/test-bundles/main/pom.xml
index a6cf45947f3..18963343283 100644
--- a/bundle-plugin-test/test-bundles/main/pom.xml
+++ b/bundle-plugin-test/test-bundles/main/pom.xml
@@ -16,8 +16,8 @@
<packaging>container-plugin</packaging>
<dependencies>
<dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>defaults</artifactId>
+ <groupId>com.yahoo.vespa.bundle-plugin</groupId>
+ <artifactId>export-packages-lib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
diff --git a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/non_public/package-info.java b/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/non_public/package-info.java
new file mode 100644
index 00000000000..143bb7b5c86
--- /dev/null
+++ b/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/non_public/package-info.java
@@ -0,0 +1,5 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+@ExportPackage
+package com.yahoo.non_public;
+
+import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/bundle-plugin-test/test-bundles/pom.xml b/bundle-plugin-test/test-bundles/pom.xml
index 34c6b2e4540..71c0e549be6 100644
--- a/bundle-plugin-test/test-bundles/pom.xml
+++ b/bundle-plugin-test/test-bundles/pom.xml
@@ -50,6 +50,7 @@
<modules>
<module>artifact-version-for-exports</module>
<module>artifact-version-for-exports-dep</module>
+ <module>export-packages-lib</module>
<module>non-public-api-usage</module>
<module>main</module>
</modules>