From d9f4351623e616f8df85e73b45f9e42bd221fb6f Mon Sep 17 00:00:00 2001 From: gjoranv Date: Wed, 23 Oct 2019 12:11:12 +0200 Subject: Revert "Gjoranv/artifact version for exports3" --- bundle-plugin-test/integration-test/pom.xml | 92 ----------- .../com/yahoo/container/plugin/BundleTest.java | 172 --------------------- .../container/plugin/ExportPackageVersionTest.java | 72 --------- bundle-plugin-test/pom.xml | 80 +++++++++- .../src/main/java/InDefaultPackage.java | 3 + .../main/java/com/yahoo/test/SimpleSearcher.java | 37 +++++ .../main/java/com/yahoo/test/SimpleSearcher2.java | 28 ++++ .../src/main/java/com/yahoo/test/package-info.java | 6 + .../src/main/resources/configdefinitions/test.def | 4 + .../src/test/java/com/yahoo/BundleIT.java | 165 ++++++++++++++++++++ .../artifact-version-for-exports-dep/pom.xml | 37 ----- .../ai/vespa/explicitversion_dep/package-info.java | 6 - .../java/ai/vespa/noversion_dep/package-info.java | 5 - .../artifact-version-for-exports/pom.xml | 36 ----- .../ai/vespa/explicitversion/package-info.java | 6 - .../main/java/ai/vespa/noversion/package-info.java | 5 - bundle-plugin-test/test-bundles/main/pom.xml | 78 ---------- .../main/src/main/java/InDefaultPackage.java | 3 - .../main/java/com/yahoo/test/SimpleSearcher.java | 37 ----- .../main/java/com/yahoo/test/SimpleSearcher2.java | 28 ---- .../src/main/java/com/yahoo/test/package-info.java | 6 - .../src/main/resources/configdefinitions/test.def | 4 - bundle-plugin-test/test-bundles/pom.xml | 75 --------- 23 files changed, 317 insertions(+), 668 deletions(-) delete mode 100644 bundle-plugin-test/integration-test/pom.xml delete mode 100644 bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java delete mode 100644 bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/ExportPackageVersionTest.java create mode 100644 bundle-plugin-test/src/main/java/InDefaultPackage.java create mode 100644 bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java create mode 100644 bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java create mode 100644 bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java create mode 100644 bundle-plugin-test/src/main/resources/configdefinitions/test.def create mode 100644 bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java delete mode 100644 bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/pom.xml delete mode 100644 bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/explicitversion_dep/package-info.java delete mode 100644 bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/noversion_dep/package-info.java delete mode 100644 bundle-plugin-test/test-bundles/artifact-version-for-exports/pom.xml delete mode 100644 bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/explicitversion/package-info.java delete mode 100644 bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/noversion/package-info.java delete mode 100644 bundle-plugin-test/test-bundles/main/pom.xml delete mode 100644 bundle-plugin-test/test-bundles/main/src/main/java/InDefaultPackage.java delete mode 100644 bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher.java delete mode 100644 bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher2.java delete mode 100644 bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/package-info.java delete mode 100644 bundle-plugin-test/test-bundles/main/src/main/resources/configdefinitions/test.def delete mode 100644 bundle-plugin-test/test-bundles/pom.xml (limited to 'bundle-plugin-test') diff --git a/bundle-plugin-test/integration-test/pom.xml b/bundle-plugin-test/integration-test/pom.xml deleted file mode 100644 index 42d3b0e4d62..00000000000 --- a/bundle-plugin-test/integration-test/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - 4.0.0 - - com.yahoo.vespa.bundle-plugin - bundle-plugin-test - 7-SNAPSHOT - ../pom.xml - - integration-test - 7-SNAPSHOT - jar - - - - com.yahoo.vespa - config - ${project.version} - test - - - com.yahoo.vespa - vespajlib - ${project.version} - test - - - junit - junit - test - - - org.apache.maven - maven-artifact - test - - - - com.yahoo.vespa.bundle-plugin - main - bundle - ${project.version} - - - com.yahoo.vespa.bundle-plugin - artifact-version-for-exports - bundle - ${project.version} - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - ${test.hide} - - ${project.build.directory}/dependency - - false - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - process-test-classes - - copy-dependencies - - - compile - true - true - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - 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 deleted file mode 100644 index 3c0379952fa..00000000000 --- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.plugin; - -import com.yahoo.osgi.maven.ProjectBundleClassPaths; -import com.yahoo.vespa.config.VespaVersion; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import java.io.File; -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; -import java.util.jar.Manifest; -import java.util.zip.ZipEntry; - -import static com.yahoo.osgi.maven.ProjectBundleClassPaths.CLASSPATH_MAPPINGS_FILENAME; -import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; -import static org.hamcrest.CoreMatchers.allOf; -import static org.hamcrest.CoreMatchers.anyOf; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.endsWith; -import static org.hamcrest.CoreMatchers.hasItems; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; - -/** - * Verifies the bundle jar file built and its manifest. - * - * @author Tony Vaagenes - */ -public class BundleTest { - static final String TEST_BUNDLE_PATH = System.getProperty("test.bundle.path", ".") + "/"; - - private JarFile jarFile; - private Attributes mainAttributes; - - @Before - public void setup() { - try { - File componentJar = findBundleJar("main"); - jarFile = new JarFile(componentJar); - Manifest manifest = jarFile.getManifest(); - mainAttributes = manifest.getMainAttributes(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - 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 bundlePath.toFile(); - } - - @Test - public void require_that_bundle_version_is_added_to_manifest() { - String bundleVersion = mainAttributes.getValue("Bundle-Version"); - - // Because of snapshot builds, we can only verify the major version. - int majorBundleVersion = Integer.valueOf(bundleVersion.substring(0, bundleVersion.indexOf('.'))); - assertThat(majorBundleVersion, is(VespaVersion.major)); - } - - @Test - public void require_that_bundle_symbolic_name_matches_pom_artifactId() { - assertThat(mainAttributes.getValue("Bundle-SymbolicName"), is("main")); - } - - @Test - public void require_that_manifest_contains_inferred_imports() { - String importPackage = mainAttributes.getValue("Import-Package"); - - // From SimpleSearcher - assertThat(importPackage, containsString("com.yahoo.prelude.hitfield")); - assertThat(importPackage, containsString("org.json")); - - // From SimpleSearcher2 - assertThat(importPackage, containsString("com.yahoo.processing")); - assertThat(importPackage, containsString("com.yahoo.metrics.simple")); - assertThat(importPackage, containsString("com.google.inject")); - } - - @Test - public void require_that_manifest_contains_manual_imports() { - String importPackage = mainAttributes.getValue("Import-Package"); - - assertThat(importPackage, containsString("manualImport.withoutVersion")); - assertThat(importPackage, containsString("manualImport.withVersion;version=\"12.3.4\"")); - - for (int i=1; i<=2; ++i) - assertThat(importPackage, containsString("multiple.packages.with.the.same.version" + i + ";version=\"[1,2)\"")); - } - - @Test - public void require_that_manifest_contains_exports() { - String exportPackage = mainAttributes.getValue("Export-Package"); - assertThat(exportPackage, containsString("com.yahoo.test;version=1.2.3.RELEASE")); - } - - @Test - // TODO: use another jar than jrt, which now pulls in a lot of dependencies that pollute the manifest of the - // generated bundle. (It's compile scoped in pom.xml to be added to the bundle-cp.) - public void require_that_manifest_contains_bundle_class_path() { - String bundleClassPath = mainAttributes.getValue("Bundle-ClassPath"); - assertThat(bundleClassPath, containsString(".,")); - // If bundle-plugin-test is compiled in a mvn command that also built jrt, - // the jrt artifact is jrt.jar, otherwise the installed and versioned artifact - // is used: jrt-7-SNAPSHOT.jar. - assertThat(bundleClassPath, anyOf( - containsString("dependencies/jrt-7-SNAPSHOT.jar"), - containsString("dependencies/jrt.jar"))); - } - - @Test - public void require_that_component_jar_file_contains_compile_artifacts() { - ZipEntry versionedEntry = jarFile.getEntry("dependencies/jrt-7-SNAPSHOT.jar"); - ZipEntry unversionedEntry = jarFile.getEntry("dependencies/jrt.jar"); - if (versionedEntry == null) { - assertNotNull(unversionedEntry); - } else { - assertNull(unversionedEntry); - } - } - - - @Test - public void require_that_web_inf_url_is_propagated_to_the_manifest() { - String webInfUrl = mainAttributes.getValue("WebInfUrl"); - assertThat(webInfUrl, containsString("/WEB-INF/web.xml")); - } - - // TODO Vespa 8: Remove, the classpath mappings file is only needed for jersey resources to work in the application test framework. - // When this test is removed, also remove the maven-resources-plugin from the 'main' test bundle's pom. - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - @SuppressWarnings("unchecked") - @Test - public void bundle_class_path_mappings_are_generated() throws Exception { - ZipEntry classpathMappingsEntry = jarFile.getEntry(CLASSPATH_MAPPINGS_FILENAME); - - assertNotNull( - "Could not find " + CLASSPATH_MAPPINGS_FILENAME + " in the test bundle", - classpathMappingsEntry); - - Path mappingsFile = tempFolder.newFile(CLASSPATH_MAPPINGS_FILENAME).toPath(); - Files.copy(jarFile.getInputStream(classpathMappingsEntry), mappingsFile, REPLACE_EXISTING); - - ProjectBundleClassPaths bundleClassPaths = ProjectBundleClassPaths.load(mappingsFile); - - assertThat(bundleClassPaths.mainBundle.bundleSymbolicName, is("main")); - - Collection mainBundleClassPaths = bundleClassPaths.mainBundle.classPathElements; - - assertThat(mainBundleClassPaths, - hasItems( - endsWith("target/classes"), - anyOf( - allOf(containsString("jrt"), containsString(".jar"), containsString("m2/repository")), - containsString("jrt/target/jrt.jar")))); - } -} diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/ExportPackageVersionTest.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/ExportPackageVersionTest.java deleted file mode 100644 index 66f36e32f39..00000000000 --- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/ExportPackageVersionTest.java +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.plugin; - -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.container.plugin.BundleTest.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 ExportPackageVersionTest { - - private static Attributes mainAttributes; - private static String bundleVersion; - - @BeforeClass - public static void setup() { - try { - File componentJar = findBundleJar("artifact-version-for-exports"); - mainAttributes = new JarFile(componentJar).getManifest().getMainAttributes(); - bundleVersion = mainAttributes.getValue("Bundle-Version"); - - } 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 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"); - - // TODO: This test should have checked for a fixed version of the dependency bundle, different than the main bundle version. - // See comment in the dependency bundle's pom.xml for why this is not the case. - assertThat(exportPackage, containsString("ai.vespa.noversion_dep;version=" + bundleVersion)); - } - - @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")); - } - -} diff --git a/bundle-plugin-test/pom.xml b/bundle-plugin-test/pom.xml index b27f6edc5f8..3ba9bf7b4b6 100644 --- a/bundle-plugin-test/pom.xml +++ b/bundle-plugin-test/pom.xml @@ -11,12 +11,80 @@ 7-SNAPSHOT ../parent/pom.xml - com.yahoo.vespa.bundle-plugin + com.yahoo.vespa bundle-plugin-test 7-SNAPSHOT - pom - - integration-test - test-bundles - + container-plugin + + + junit + junit + test + + + com.yahoo.vespa + container-dev + ${project.version} + provided + + + com.yahoo.vespa + vespajlib + ${project.version} + provided + + + org.json + json + provided + + + com.yahoo.vespa + jrt + ${project.version} + + + + javax.xml.bind + jaxb-api + 2.3.0 + + + + + + com.yahoo.vespa + bundle-plugin + ${project.version} + true + + + manualImport.withoutVersion, + manualImport.withVersion;version="12.3.4", + multiple.packages.with.the.same.version1;multiple.packages.with.the.same.version2;version="[1,2)" + + /WEB-INF/web.xml + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.9 + + + integration-test + + integration-test + + + + verify + + verify + + + + + + diff --git a/bundle-plugin-test/src/main/java/InDefaultPackage.java b/bundle-plugin-test/src/main/java/InDefaultPackage.java new file mode 100644 index 00000000000..a650916d653 --- /dev/null +++ b/bundle-plugin-test/src/main/java/InDefaultPackage.java @@ -0,0 +1,3 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +public class InDefaultPackage {} diff --git a/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java new file mode 100644 index 00000000000..dddca3f4d59 --- /dev/null +++ b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java @@ -0,0 +1,37 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.test; + +import com.yahoo.prelude.hitfield.XMLString; +import com.yahoo.search.Query; +import com.yahoo.search.Result; +import com.yahoo.search.Searcher; +import com.yahoo.search.result.Hit; +import com.yahoo.search.searchchain.Execution; +import com.yahoo.text.BooleanParser; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * A searcher adding a new hit. + * + * @author Joe Developer + */ +public class SimpleSearcher extends Searcher { + + public Result search(Query query,Execution execution) { + try { + BooleanParser.parseBoolean("true"); + XMLString xmlString = new XMLString(""); + + Hit hit = new Hit("Hello world!"); + hit.setField("json", new JSONObject().put("price", 42).toString()); + + Result result = execution.search(query); + result.hits().add(hit); + return result; + + } catch (JSONException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java new file mode 100644 index 00000000000..3220171de13 --- /dev/null +++ b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java @@ -0,0 +1,28 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.test; + + +/** + * Test class for integration tests. Used to verify that nested classes are visited. + * + * Do not replace the fully qualified class names with imports! + */ +public class SimpleSearcher2 extends SimpleSearcher { + public void dummy() {} + + private class InnerClassProcessor extends com.yahoo.processing.Processor { + @Override + public com.yahoo.processing.Response process(com.yahoo.processing.Request request, + com.yahoo.processing.execution.Execution execution) { + return null; + } + } + + private static class NestedStaticClass { + private com.yahoo.metrics.simple.Counter counter; + + @com.google.inject.Inject + public NestedStaticClass() { } + } + +} diff --git a/bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java b/bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java new file mode 100644 index 00000000000..5774fc8d5f2 --- /dev/null +++ b/bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java @@ -0,0 +1,6 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +@ExportPackage(version = @Version(major = 1, minor = 2, micro = 3, qualifier = "RELEASE")) +package com.yahoo.test; + +import com.yahoo.osgi.annotation.ExportPackage; +import com.yahoo.osgi.annotation.Version; diff --git a/bundle-plugin-test/src/main/resources/configdefinitions/test.def b/bundle-plugin-test/src/main/resources/configdefinitions/test.def new file mode 100644 index 00000000000..b4ba9ec518a --- /dev/null +++ b/bundle-plugin-test/src/main/resources/configdefinitions/test.def @@ -0,0 +1,4 @@ +# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +namespace=example + +exampleKey string default="exampleValue" diff --git a/bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java b/bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java new file mode 100644 index 00000000000..932b78a5c8d --- /dev/null +++ b/bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java @@ -0,0 +1,165 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo; + +import com.yahoo.osgi.maven.ProjectBundleClassPaths; +import com.yahoo.vespa.config.VespaVersion; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; + +import static com.yahoo.osgi.maven.ProjectBundleClassPaths.CLASSPATH_MAPPINGS_FILENAME; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.anyOf; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.endsWith; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + +/** + * Verifies the bundle jar file built and its manifest. + * @author Tony Vaagenes + */ +public class BundleIT { + private JarFile jarFile; + private Attributes mainAttributes; + + @Before + public void setup() { + try { + File componentJar = findBundleJar(); + jarFile = new JarFile(componentJar); + Manifest manifest = jarFile.getManifest(); + mainAttributes = manifest.getMainAttributes(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private File findBundleJar() { + File[] componentFile = new File("target").listFiles(new FilenameFilter() { + @Override + public boolean accept(File file, String fileName) { + return fileName.endsWith("-deploy.jar") || fileName.endsWith("-jar-with-dependencies.jar"); + } + }); + + if (componentFile.length != 1) { + throw new RuntimeException("Failed finding component jar file"); + } + + return componentFile[0]; + } + + @Test + public void require_that_bundle_version_is_added_to_manifest() { + String bundleVersion = mainAttributes.getValue("Bundle-Version"); + + // Because of snapshot builds, we can only verify the major version. + int majorBundleVersion = Integer.valueOf(bundleVersion.substring(0, bundleVersion.indexOf('.'))); + assertThat(majorBundleVersion, is(VespaVersion.major)); + } + + @Test + public void require_that_bundle_symbolic_name_matches_pom_artifactId() { + assertThat(mainAttributes.getValue("Bundle-SymbolicName"), is("bundle-plugin-test")); + } + + @Test + public void require_that_manifest_contains_inferred_imports() { + String importPackage = mainAttributes.getValue("Import-Package"); + + // From SimpleSearcher + assertThat(importPackage, containsString("com.yahoo.prelude.hitfield")); + assertThat(importPackage, containsString("org.json")); + + // From SimpleSearcher2 + assertThat(importPackage, containsString("com.yahoo.processing")); + assertThat(importPackage, containsString("com.yahoo.metrics.simple")); + assertThat(importPackage, containsString("com.google.inject")); + } + + @Test + public void require_that_manifest_contains_manual_imports() { + String importPackage = mainAttributes.getValue("Import-Package"); + + assertThat(importPackage, containsString("manualImport.withoutVersion")); + assertThat(importPackage, containsString("manualImport.withVersion;version=\"12.3.4\"")); + + for (int i=1; i<=2; ++i) + assertThat(importPackage, containsString("multiple.packages.with.the.same.version" + i + ";version=\"[1,2)\"")); + } + + @Test + public void require_that_manifest_contains_exports() { + String exportPackage = mainAttributes.getValue("Export-Package"); + assertThat(exportPackage, containsString("com.yahoo.test;version=1.2.3.RELEASE")); + } + + @Test + // TODO: use another jar than jrt, which now pulls in a lot of dependencies that pollute the manifest of the + // generated bundle. (It's compile scoped in pom.xml to be added to the bundle-cp.) + public void require_that_manifest_contains_bundle_class_path() { + String bundleClassPath = mainAttributes.getValue("Bundle-ClassPath"); + assertThat(bundleClassPath, containsString(".,")); + // If bundle-plugin-test is compiled in a mvn command that also built jrt, + // the jrt artifact is jrt.jar, otherwise the installed and versioned artifact + // is used: jrt-7-SNAPSHOT.jar. + assertThat(bundleClassPath, anyOf( + containsString("dependencies/jrt-7-SNAPSHOT.jar"), + containsString("dependencies/jrt.jar"))); + } + + @Test + public void require_that_component_jar_file_contains_compile_artifacts() { + ZipEntry versionedEntry = jarFile.getEntry("dependencies/jrt-7-SNAPSHOT.jar"); + ZipEntry unversionedEntry = jarFile.getEntry("dependencies/jrt.jar"); + if (versionedEntry == null) { + assertNotNull(unversionedEntry); + } else { + assertNull(unversionedEntry); + } + } + + + @Test + public void require_that_web_inf_url_is_propagated_to_the_manifest() { + String webInfUrl = mainAttributes.getValue("WebInfUrl"); + assertThat(webInfUrl, containsString("/WEB-INF/web.xml")); + } + + @SuppressWarnings("unchecked") + @Test + public void bundle_class_path_mappings_are_generated() throws URISyntaxException, IOException { + URL mappingsUrl = getClass().getResource("/" + CLASSPATH_MAPPINGS_FILENAME); + assertNotNull( + "Could not find " + CLASSPATH_MAPPINGS_FILENAME + " in the test output directory", + mappingsUrl); + + ProjectBundleClassPaths bundleClassPaths = ProjectBundleClassPaths.load(Paths.get(mappingsUrl.toURI())); + + assertThat(bundleClassPaths.mainBundle.bundleSymbolicName, is("bundle-plugin-test")); + + Collection mainBundleClassPaths = bundleClassPaths.mainBundle.classPathElements; + + assertThat(mainBundleClassPaths, + hasItems( + endsWith("target/classes"), + anyOf( + allOf(containsString("jrt"), containsString(".jar"), containsString("m2/repository")), + containsString("jrt/target/jrt.jar")))); + } +} diff --git a/bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/pom.xml b/bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/pom.xml deleted file mode 100644 index 34b250ae927..00000000000 --- a/bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - 4.0.0 - - com.yahoo.vespa.bundle-plugin - test-bundles - 7-SNAPSHOT - ../pom.xml - - artifact-version-for-exports-dep - - 7-SNAPSHOT - container-plugin - - - - - - com.yahoo.vespa - bundle-plugin - ${project.version} - true - - true - ${project.version} - - - - - diff --git a/bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/explicitversion_dep/package-info.java b/bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/explicitversion_dep/package-info.java deleted file mode 100644 index 3eea8b11f1e..00000000000 --- a/bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/explicitversion_dep/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage(version = @Version(major = 3, minor = 6, micro = 9, qualifier = "RELEASE")) -package ai.vespa.explicitversion_dep; - -import com.yahoo.osgi.annotation.ExportPackage; -import com.yahoo.osgi.annotation.Version; diff --git a/bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/noversion_dep/package-info.java b/bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/noversion_dep/package-info.java deleted file mode 100644 index 794e177f7e7..00000000000 --- a/bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/noversion_dep/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage -package ai.vespa.noversion_dep; - -import com.yahoo.osgi.annotation.ExportPackage; diff --git a/bundle-plugin-test/test-bundles/artifact-version-for-exports/pom.xml b/bundle-plugin-test/test-bundles/artifact-version-for-exports/pom.xml deleted file mode 100644 index 619189cd874..00000000000 --- a/bundle-plugin-test/test-bundles/artifact-version-for-exports/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - 4.0.0 - - com.yahoo.vespa.bundle-plugin - test-bundles - 7-SNAPSHOT - ../pom.xml - - artifact-version-for-exports - 7-SNAPSHOT - container-plugin - - - com.yahoo.vespa.bundle-plugin - artifact-version-for-exports-dep - ${project.version} - - - - - - com.yahoo.vespa - bundle-plugin - true - - true - - - - - diff --git a/bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/explicitversion/package-info.java b/bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/explicitversion/package-info.java deleted file mode 100644 index 96cf6a3bf85..00000000000 --- a/bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/explicitversion/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage(version = @Version(major = 2, minor = 4, micro = 6, qualifier = "RELEASE")) -package ai.vespa.explicitversion; - -import com.yahoo.osgi.annotation.ExportPackage; -import com.yahoo.osgi.annotation.Version; diff --git a/bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/noversion/package-info.java b/bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/noversion/package-info.java deleted file mode 100644 index e7e11e39889..00000000000 --- a/bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/noversion/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage -package ai.vespa.noversion; - -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 deleted file mode 100644 index c9c9ea270eb..00000000000 --- a/bundle-plugin-test/test-bundles/main/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - 4.0.0 - - com.yahoo.vespa.bundle-plugin - test-bundles - 7-SNAPSHOT - ../pom.xml - - main - 7-SNAPSHOT - container-plugin - - - org.json - json - provided - - - com.yahoo.vespa - jrt - ${project.version} - - - - javax.xml.bind - jaxb-api - 2.3.0 - - - - - - com.yahoo.vespa - bundle-plugin - true - - - manualImport.withoutVersion, - manualImport.withVersion;version="12.3.4", - multiple.packages.with.the.same.version1;multiple.packages.with.the.same.version2;version="[1,2)" - - /WEB-INF/web.xml - - - - - maven-resources-plugin - - - copy-bundle-classpath-mappings-from-test-to-main - - process-test-sources - - copy-resources - - - ${project.build.outputDirectory} - true - - - ${project.build.testOutputDirectory} - - bundle-plugin.bundle-classpath-mappings.json - - - - - - - - - - diff --git a/bundle-plugin-test/test-bundles/main/src/main/java/InDefaultPackage.java b/bundle-plugin-test/test-bundles/main/src/main/java/InDefaultPackage.java deleted file mode 100644 index a650916d653..00000000000 --- a/bundle-plugin-test/test-bundles/main/src/main/java/InDefaultPackage.java +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -public class InDefaultPackage {} diff --git a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher.java b/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher.java deleted file mode 100644 index dddca3f4d59..00000000000 --- a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.test; - -import com.yahoo.prelude.hitfield.XMLString; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.Searcher; -import com.yahoo.search.result.Hit; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.text.BooleanParser; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * A searcher adding a new hit. - * - * @author Joe Developer - */ -public class SimpleSearcher extends Searcher { - - public Result search(Query query,Execution execution) { - try { - BooleanParser.parseBoolean("true"); - XMLString xmlString = new XMLString(""); - - Hit hit = new Hit("Hello world!"); - hit.setField("json", new JSONObject().put("price", 42).toString()); - - Result result = execution.search(query); - result.hits().add(hit); - return result; - - } catch (JSONException e) { - throw new RuntimeException(e); - } - } -} diff --git a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher2.java b/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher2.java deleted file mode 100644 index 3220171de13..00000000000 --- a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher2.java +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.test; - - -/** - * Test class for integration tests. Used to verify that nested classes are visited. - * - * Do not replace the fully qualified class names with imports! - */ -public class SimpleSearcher2 extends SimpleSearcher { - public void dummy() {} - - private class InnerClassProcessor extends com.yahoo.processing.Processor { - @Override - public com.yahoo.processing.Response process(com.yahoo.processing.Request request, - com.yahoo.processing.execution.Execution execution) { - return null; - } - } - - private static class NestedStaticClass { - private com.yahoo.metrics.simple.Counter counter; - - @com.google.inject.Inject - public NestedStaticClass() { } - } - -} diff --git a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/package-info.java b/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/package-info.java deleted file mode 100644 index 5774fc8d5f2..00000000000 --- a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage(version = @Version(major = 1, minor = 2, micro = 3, qualifier = "RELEASE")) -package com.yahoo.test; - -import com.yahoo.osgi.annotation.ExportPackage; -import com.yahoo.osgi.annotation.Version; diff --git a/bundle-plugin-test/test-bundles/main/src/main/resources/configdefinitions/test.def b/bundle-plugin-test/test-bundles/main/src/main/resources/configdefinitions/test.def deleted file mode 100644 index b4ba9ec518a..00000000000 --- a/bundle-plugin-test/test-bundles/main/src/main/resources/configdefinitions/test.def +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -namespace=example - -exampleKey string default="exampleValue" diff --git a/bundle-plugin-test/test-bundles/pom.xml b/bundle-plugin-test/test-bundles/pom.xml deleted file mode 100644 index 712ccb5542e..00000000000 --- a/bundle-plugin-test/test-bundles/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - 4.0.0 - - com.yahoo.vespa.bundle-plugin - bundle-plugin-test - 7-SNAPSHOT - ../pom.xml - - test-bundles - 7-SNAPSHOT - pom - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - - - - com.yahoo.vespa - bundle-plugin - ${project.version} - - - generate-classpath-mappings - generate-test-sources - - generate-bundle-classpath-mappings - - - - package-test-bundles - - test-compile - - generate-osgi-manifest - assemble-container-plugin - - - - - - true - - - - - - - artifact-version-for-exports - artifact-version-for-exports-dep - main - - - - - com.yahoo.vespa - container-dev - ${project.version} - provided - - - - - true - - -- cgit v1.2.3