diff options
author | gjoranv <gv@yahooinc.com> | 2023-06-02 12:50:17 +0200 |
---|---|---|
committer | gjoranv <gv@yahooinc.com> | 2023-06-02 16:59:01 +0200 |
commit | 9c0eeab774895b3c3c9b218f82f71fd7314c388c (patch) | |
tree | 25935f8fc7a28940e008286d2933e2bd3a9579fd /bundle-plugin-test | |
parent | 2e86853955a19bf290efca723456619ea45cb75f (diff) |
Add test for non-PublicApi usage.
Diffstat (limited to 'bundle-plugin-test')
5 files changed, 109 insertions, 0 deletions
diff --git a/bundle-plugin-test/integration-test/pom.xml b/bundle-plugin-test/integration-test/pom.xml index 7384bf3aea6..acd075d0365 100644 --- a/bundle-plugin-test/integration-test/pom.xml +++ b/bundle-plugin-test/integration-test/pom.xml @@ -56,7 +56,14 @@ <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> + </dependency> </dependencies> + <build> <plugins> <plugin> diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/NonPublicApiDetectionTest.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/NonPublicApiDetectionTest.java new file mode 100644 index 00000000000..42ac99c65e5 --- /dev/null +++ b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/NonPublicApiDetectionTest.java @@ -0,0 +1,44 @@ +package com.yahoo.container.plugin; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Set; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.stream.Collectors; + +import static com.yahoo.container.plugin.BundleTest.findBundleJar; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author gjoranv + */ +public class NonPublicApiDetectionTest { + + private static Set<String> usedNonPublicApi; + + @BeforeAll + public static void setup() { + try { + File componentJar = findBundleJar("non-public-api-usage"); + Attributes mainAttributes = new JarFile(componentJar).getManifest().getMainAttributes(); + var nonPublicApiAttribute = mainAttributes.getValue("X-JDisc-Non-PublicApi-Import-Package"); + usedNonPublicApi = Arrays.stream(nonPublicApiAttribute.split(",")).collect(Collectors.toSet()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Test + void usage_of_non_publicApi_packages_is_detected() { + assertEquals(2, usedNonPublicApi.size()); + assertTrue(usedNonPublicApi.contains("ai.vespa.http")); + assertTrue(usedNonPublicApi.contains("com.yahoo.io")); + } + +} diff --git a/bundle-plugin-test/test-bundles/non-public-api-usage/pom.xml b/bundle-plugin-test/test-bundles/non-public-api-usage/pom.xml new file mode 100644 index 00000000000..4eeac781d43 --- /dev/null +++ b/bundle-plugin-test/test-bundles/non-public-api-usage/pom.xml @@ -0,0 +1,42 @@ +<?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>non-public-api-usage</artifactId> + <version>8-SNAPSHOT</version> + <packaging>container-plugin</packaging> + + <dependencies> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>defaults</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>vespajlib</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>com.yahoo.vespa</groupId> + <artifactId>bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + </plugins> + </build> +</project> diff --git a/bundle-plugin-test/test-bundles/non-public-api-usage/src/main/java/com/yahoo/test/UsingBothPublicApiAndNonPublicApiPackages.java b/bundle-plugin-test/test-bundles/non-public-api-usage/src/main/java/com/yahoo/test/UsingBothPublicApiAndNonPublicApiPackages.java new file mode 100644 index 00000000000..f2c64661ad6 --- /dev/null +++ b/bundle-plugin-test/test-bundles/non-public-api-usage/src/main/java/com/yahoo/test/UsingBothPublicApiAndNonPublicApiPackages.java @@ -0,0 +1,15 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.test; + +public class UsingBothPublicApiAndNonPublicApiPackages { + + com.yahoo.vespa.defaults.Defaults publicFromDefaults = null; + + com.yahoo.text.BooleanParser publicFromVespajlib = null; + + + ai.vespa.http.DomainName nonPublic1 = null; + + com.yahoo.io.ByteWriter nonPublic2 = null; + +} diff --git a/bundle-plugin-test/test-bundles/pom.xml b/bundle-plugin-test/test-bundles/pom.xml index 3af10826adc..34c6b2e4540 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>non-public-api-usage</module> <module>main</module> </modules> |