aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundle-plugin-test/integration-test/pom.xml92
-rw-r--r--bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/ExportPackageVersionTest.java72
-rw-r--r--bundle-plugin-test/pom.xml80
-rw-r--r--bundle-plugin-test/src/main/java/InDefaultPackage.java (renamed from bundle-plugin-test/test-bundles/main/src/main/java/InDefaultPackage.java)0
-rw-r--r--bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java (renamed from bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher.java)0
-rw-r--r--bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java (renamed from bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher2.java)0
-rw-r--r--bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java (renamed from bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/package-info.java)0
-rw-r--r--bundle-plugin-test/src/main/resources/configdefinitions/test.def (renamed from bundle-plugin-test/test-bundles/main/src/main/resources/configdefinitions/test.def)0
-rw-r--r--bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java (renamed from bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java)55
-rw-r--r--bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/pom.xml37
-rw-r--r--bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/explicitversion_dep/package-info.java6
-rw-r--r--bundle-plugin-test/test-bundles/artifact-version-for-exports-dep/src/main/java/ai/vespa/noversion_dep/package-info.java5
-rw-r--r--bundle-plugin-test/test-bundles/artifact-version-for-exports/pom.xml36
-rw-r--r--bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/explicitversion/package-info.java6
-rw-r--r--bundle-plugin-test/test-bundles/artifact-version-for-exports/src/main/java/ai/vespa/noversion/package-info.java5
-rw-r--r--bundle-plugin-test/test-bundles/main/pom.xml78
-rw-r--r--bundle-plugin-test/test-bundles/pom.xml75
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Analyze.java15
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassVisitor.java17
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java52
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/util/IO.java7
21 files changed, 127 insertions, 511 deletions
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 @@
-<?xml version="1.0"?>
-<!-- Copyright 2019 Yahoo Holdings. 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>bundle-plugin-test</artifactId>
- <version>7-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
- <artifactId>integration-test</artifactId>
- <version>7-SNAPSHOT</version>
- <packaging>jar</packaging>
-
- <dependencies>
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>config</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>vespajlib</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-artifact</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>com.yahoo.vespa.bundle-plugin</groupId>
- <artifactId>main</artifactId>
- <classifier>bundle</classifier>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>com.yahoo.vespa.bundle-plugin</groupId>
- <artifactId>artifact-version-for-exports</artifactId>
- <classifier>bundle</classifier>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <redirectTestOutputToFile>${test.hide}</redirectTestOutputToFile>
- <systemPropertyVariables>
- <test.bundle.path>${project.build.directory}/dependency</test.bundle.path>
- </systemPropertyVariables>
- <trimStackTrace>false</trimStackTrace>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <phase>process-test-classes</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <includeScope>compile</includeScope>
- <excludeTransitive>true</excludeTransitive>
- <stripVersion>true</stripVersion>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-</project>
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 @@
<version>7-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
- <groupId>com.yahoo.vespa.bundle-plugin</groupId>
+ <groupId>com.yahoo.vespa</groupId>
<artifactId>bundle-plugin-test</artifactId>
<version>7-SNAPSHOT</version>
- <packaging>pom</packaging>
- <modules>
- <module>integration-test</module>
- <module>test-bundles</module>
- </modules>
+ <packaging>container-plugin</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>container-dev</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>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>jrt</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <!-- Added to verify that module-info.class can be handled by bundle-plugin without throwing an exception. -->
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>2.3.0</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>bundle-plugin</artifactId>
+ <version>${project.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <Import-Package>
+ manualImport.withoutVersion,
+ manualImport.withVersion;version="12.3.4",
+ multiple.packages.with.the.same.version1;multiple.packages.with.the.same.version2;version="[1,2)"
+ </Import-Package>
+ <WebInfUrl>/WEB-INF/web.xml</WebInfUrl>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>2.9</version>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>integration-test</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>verify</id>
+ <goals>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/bundle-plugin-test/test-bundles/main/src/main/java/InDefaultPackage.java b/bundle-plugin-test/src/main/java/InDefaultPackage.java
index a650916d653..a650916d653 100644
--- a/bundle-plugin-test/test-bundles/main/src/main/java/InDefaultPackage.java
+++ b/bundle-plugin-test/src/main/java/InDefaultPackage.java
diff --git a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher.java b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java
index dddca3f4d59..dddca3f4d59 100644
--- a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher.java
+++ b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher.java
diff --git a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher2.java b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java
index 3220171de13..3220171de13 100644
--- a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/SimpleSearcher2.java
+++ b/bundle-plugin-test/src/main/java/com/yahoo/test/SimpleSearcher2.java
diff --git a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/package-info.java b/bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java
index 5774fc8d5f2..5774fc8d5f2 100644
--- a/bundle-plugin-test/test-bundles/main/src/main/java/com/yahoo/test/package-info.java
+++ b/bundle-plugin-test/src/main/java/com/yahoo/test/package-info.java
diff --git a/bundle-plugin-test/test-bundles/main/src/main/resources/configdefinitions/test.def b/bundle-plugin-test/src/main/resources/configdefinitions/test.def
index b4ba9ec518a..b4ba9ec518a 100644
--- a/bundle-plugin-test/test-bundles/main/src/main/resources/configdefinitions/test.def
+++ b/bundle-plugin-test/src/main/resources/configdefinitions/test.def
diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java b/bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java
index 3c0379952fa..932b78a5c8d 100644
--- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java
+++ b/bundle-plugin-test/src/test/java/com/yahoo/BundleIT.java
@@ -1,17 +1,16 @@
// 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;
+package com.yahoo;
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.FilenameFilter;
import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
+import java.net.URISyntaxException;
+import java.net.URL;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.jar.Attributes;
@@ -20,7 +19,6 @@ 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;
@@ -33,19 +31,16 @@ 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", ".") + "/";
-
+public class BundleIT {
private JarFile jarFile;
private Attributes mainAttributes;
@Before
public void setup() {
try {
- File componentJar = findBundleJar("main");
+ File componentJar = findBundleJar();
jarFile = new JarFile(componentJar);
Manifest manifest = jarFile.getManifest();
mainAttributes = manifest.getMainAttributes();
@@ -54,13 +49,19 @@ public class BundleTest {
}
}
- 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);
+ 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 bundlePath.toFile();
+ return componentFile[0];
}
@Test
@@ -74,7 +75,7 @@ public class BundleTest {
@Test
public void require_that_bundle_symbolic_name_matches_pom_artifactId() {
- assertThat(mainAttributes.getValue("Bundle-SymbolicName"), is("main"));
+ assertThat(mainAttributes.getValue("Bundle-SymbolicName"), is("bundle-plugin-test"));
}
@Test
@@ -140,25 +141,17 @@ public class BundleTest {
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);
-
+ 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 bundle",
- classpathMappingsEntry);
-
- Path mappingsFile = tempFolder.newFile(CLASSPATH_MAPPINGS_FILENAME).toPath();
- Files.copy(jarFile.getInputStream(classpathMappingsEntry), mappingsFile, REPLACE_EXISTING);
+ "Could not find " + CLASSPATH_MAPPINGS_FILENAME + " in the test output directory",
+ mappingsUrl);
- ProjectBundleClassPaths bundleClassPaths = ProjectBundleClassPaths.load(mappingsFile);
+ ProjectBundleClassPaths bundleClassPaths = ProjectBundleClassPaths.load(Paths.get(mappingsUrl.toURI()));
- assertThat(bundleClassPaths.mainBundle.bundleSymbolicName, is("main"));
+ assertThat(bundleClassPaths.mainBundle.bundleSymbolicName, is("bundle-plugin-test"));
Collection<String> mainBundleClassPaths = bundleClassPaths.mainBundle.classPathElements;
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 @@
-<?xml version="1.0"?>
-<!-- Copyright 2019 Yahoo Holdings. 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>7-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
- <artifactId>artifact-version-for-exports-dep</artifactId>
- <!-- TODO: Should use a fixed version different than the dependent bundle.
- But version is set to the release version by build scripts before building.
- Then, the dependent bundle will not find the artifact. Skipping this step for a sub-module seems
- impossible with the maven-versions-plugin, and cumbersome with factorylib. -->
- <version>7-SNAPSHOT</version>
- <packaging>container-plugin</packaging>
- <dependencies>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>bundle-plugin</artifactId>
- <version>${project.version}</version>
- <extensions>true</extensions>
- <configuration>
- <useArtifactVersionForExportPackages>true</useArtifactVersionForExportPackages>
- <configGenVersion>${project.version}</configGenVersion>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
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 @@
-<?xml version="1.0"?>
-<!-- Copyright 2019 Yahoo Holdings. 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>7-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
- <artifactId>artifact-version-for-exports</artifactId>
- <version>7-SNAPSHOT</version>
- <packaging>container-plugin</packaging>
- <dependencies>
- <dependency>
- <groupId>com.yahoo.vespa.bundle-plugin</groupId>
- <artifactId>artifact-version-for-exports-dep</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <useArtifactVersionForExportPackages>true</useArtifactVersionForExportPackages>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
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 @@
-<?xml version="1.0"?>
-<!-- Copyright 2019 Yahoo Holdings. 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>7-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
- <artifactId>main</artifactId>
- <version>7-SNAPSHOT</version>
- <packaging>container-plugin</packaging>
- <dependencies>
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>jrt</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <!-- Added to verify that module-info.class can be handled by bundle-plugin without throwing an exception. -->
- <groupId>javax.xml.bind</groupId>
- <artifactId>jaxb-api</artifactId>
- <version>2.3.0</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <Import-Package>
- manualImport.withoutVersion,
- manualImport.withVersion;version="12.3.4",
- multiple.packages.with.the.same.version1;multiple.packages.with.the.same.version2;version="[1,2)"
- </Import-Package>
- <WebInfUrl>/WEB-INF/web.xml</WebInfUrl>
- </configuration>
- </plugin>
- <plugin>
- <!-- Trick to copy bundle-plugin.bundle-classpath-mappings.json from target/test-classes to target/classes -->
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-bundle-classpath-mappings-from-test-to-main</id>
- <!-- NOTE: Must be done after generating classpath-mappings and before assembling the bundle (see the test-bundles pom) -->
- <phase>process-test-sources</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.outputDirectory}</outputDirectory>
- <overwrite>true</overwrite>
- <resources>
- <resource>
- <directory>${project.build.testOutputDirectory}</directory>
- <includes>
- <include>bundle-plugin.bundle-classpath-mappings.json</include>
- </includes>
- </resource>
- </resources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
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 @@
-<?xml version="1.0"?>
-<!-- Copyright 2019 Yahoo Holdings. 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>bundle-plugin-test</artifactId>
- <version>7-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
- <artifactId>test-bundles</artifactId>
- <version>7-SNAPSHOT</version>
- <packaging>pom</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <plugin>
- <!-- Trick to package bundles before test phase to allow running 'mvn test' -->
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>bundle-plugin</artifactId>
- <version>${project.version}</version>
- <executions>
- <execution>
- <id>generate-classpath-mappings</id>
- <phase>generate-test-sources</phase>
- <goals>
- <goal>generate-bundle-classpath-mappings</goal>
- </goals>
- </execution>
- <execution>
- <id>package-test-bundles</id>
- <!-- Must be done after generating classpath-mappings and copying it in the 'main' bundle. -->
- <phase>test-compile</phase>
- <goals>
- <goal>generate-osgi-manifest</goal>
- <goal>assemble-container-plugin</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <!-- Make the integration-test module use the bundle jars instead of the ordinary artifacts. -->
- <AttachBundle>true</AttachBundle>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- <modules>
- <module>artifact-version-for-exports</module>
- <module>artifact-version-for-exports-dep</module>
- <module>main</module>
- </modules>
-
- <dependencies>
- <dependency>
- <groupId>com.yahoo.vespa</groupId>
- <artifactId>container-dev</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
- <properties>
- <maven.javadoc.skip>true</maven.javadoc.skip>
- </properties>
-</project>
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Analyze.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Analyze.java
index d586f324f77..13a306a0c1c 100644
--- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Analyze.java
+++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/Analyze.java
@@ -1,18 +1,17 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.classanalysis;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
+import static com.yahoo.container.plugin.util.IO.withFileInputStream;
/**
* Main entry point for class analysis
@@ -22,20 +21,16 @@ import java.util.Optional;
*/
public class Analyze {
public static ClassFileMetaData analyzeClass(File classFile) {
- return analyzeClass(classFile, null);
- }
-
- public static ClassFileMetaData analyzeClass(File classFile, ArtifactVersion artifactVersion) {
try {
- return analyzeClass(new FileInputStream(classFile), artifactVersion);
- } catch (Exception e) {
+ return withFileInputStream(classFile, Analyze::analyzeClass);
+ } catch (RuntimeException e) {
throw new RuntimeException("An error occurred when analyzing " + classFile.getPath(), e);
}
}
- public static ClassFileMetaData analyzeClass(InputStream inputStream, ArtifactVersion artifactVersion) {
+ public static ClassFileMetaData analyzeClass(InputStream inputStream) {
try {
- AnalyzeClassVisitor visitor = new AnalyzeClassVisitor(artifactVersion);
+ AnalyzeClassVisitor visitor = new AnalyzeClassVisitor();
new ClassReader(inputStream).accept(visitor, ClassReader.SKIP_DEBUG);
return visitor.result();
} catch (IOException e) {
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassVisitor.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassVisitor.java
index e37a9caa7cc..0225c43e4b8 100644
--- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassVisitor.java
+++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/classanalysis/AnalyzeClassVisitor.java
@@ -3,7 +3,6 @@ package com.yahoo.container.plugin.classanalysis;
import com.yahoo.osgi.annotation.ExportPackage;
import com.yahoo.osgi.annotation.Version;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassVisitor;
@@ -28,11 +27,8 @@ class AnalyzeClassVisitor extends ClassVisitor implements ImportCollector {
private Set<String> imports = new HashSet<>();
private Optional<ExportPackageAnnotation> exportPackageAnnotation = Optional.empty();
- private final Optional<ArtifactVersion> defaultExportPackageVersion;
-
- AnalyzeClassVisitor(ArtifactVersion defaultExportPackageVersion) {
+ AnalyzeClassVisitor() {
super(Opcodes.ASM7);
- this.defaultExportPackageVersion = Optional.ofNullable(defaultExportPackageVersion);
}
@Override
@@ -103,14 +99,9 @@ class AnalyzeClassVisitor extends ClassVisitor implements ImportCollector {
private AnnotationVisitor visitExportPackage() {
return new AnnotationVisitor(Opcodes.ASM7) {
- private int major = defaultExportPackageVersion.map(ArtifactVersion::getMajorVersion)
- .orElse(defaultVersionValue("major"));
- private int minor = defaultExportPackageVersion.map(ArtifactVersion::getMinorVersion)
- .orElse(defaultVersionValue("minor"));
- private int micro = defaultExportPackageVersion.map(ArtifactVersion::getIncrementalVersion)
- .orElse(defaultVersionValue("micro"));
-
- // Default qualifier is the empty string.
+ private int major = defaultVersionValue("major");
+ private int minor = defaultVersionValue("minor");
+ private int micro = defaultVersionValue("micro");
private String qualifier = defaultVersionValue("qualifier");
@Override
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java
index 11a82ab7443..c23e55a9eec 100644
--- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java
+++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java
@@ -14,8 +14,6 @@ import com.yahoo.container.plugin.osgi.ImportPackages.Import;
import com.yahoo.container.plugin.util.Strings;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
@@ -46,7 +44,8 @@ import static com.yahoo.container.plugin.osgi.ExportPackages.exportsByPackageNam
import static com.yahoo.container.plugin.osgi.ImportPackages.calculateImports;
import static com.yahoo.container.plugin.util.Files.allDescendantFiles;
import static com.yahoo.container.plugin.util.IO.withFileOutputStream;
-
+import static com.yahoo.container.plugin.util.JarFiles.withInputStream;
+import static com.yahoo.container.plugin.util.JarFiles.withJarFile;
/**
* @author Tony Vaagenes
@@ -58,15 +57,6 @@ public class GenerateOsgiManifestMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}")
private MavenProject project = null;
- /**
- * If set to true, the artifact's version is used as default package version for ExportPackages.
- * Packages from included (compile scoped) artifacts will use the version for their own artifact.
- * If the package is exported with an explicit version in package-info.java, that version will be
- * used regardless of this parameter.
- */
- @Parameter(alias = "UseArtifactVersionForExportPackages", defaultValue = "false")
- private boolean useArtifactVersionForExportPackages;
-
@Parameter
private String discApplicationClass = null;
@@ -225,11 +215,8 @@ public class GenerateOsgiManifestMojo extends AbstractMojo {
Map<String, Optional<String>> manualImports, Collection<Import> imports, PackageTally pluginPackageTally) {
Map<String, String> ret = new HashMap<>();
String importPackage = Stream.concat(manualImports.entrySet().stream().map(e -> asOsgiImport(e.getKey(), e.getValue())),
- imports.stream().map(Import::asOsgiImport)).sorted()
- .collect(Collectors.joining(","));
-
- String exportPackage = osgiExportPackages(pluginPackageTally.exportedPackages()).stream().sorted()
- .collect(Collectors.joining(","));
+ imports.stream().map(Import::asOsgiImport)).sorted().collect(Collectors.joining(","));
+ String exportPackage = osgiExportPackages(pluginPackageTally.exportedPackages()).stream().sorted().collect(Collectors.joining(","));
for (Pair<String, String> element : Arrays.asList(//
Pair.of("Created-By", "vespa container maven plugin"), //
@@ -314,47 +301,34 @@ public class GenerateOsgiManifestMojo extends AbstractMojo {
artifact.getId(), artifact.getType())));
}
- private ArtifactVersion artifactVersionOrNull(String version) {
- return useArtifactVersionForExportPackages ? new DefaultArtifactVersion(version) : null;
- }
-
private PackageTally getProjectClassesTally() {
File outputDirectory = new File(project.getBuild().getOutputDirectory());
- List<ClassFileMetaData> analyzedClasses = allDescendantFiles(outputDirectory)
- .filter(file -> file.getName().endsWith(".class"))
- .map(classFile -> Analyze.analyzeClass(classFile, artifactVersionOrNull(bundleVersion)))
- .collect(Collectors.toList());
+ List<ClassFileMetaData> analyzedClasses = allDescendantFiles(outputDirectory).filter(file -> file.getName().endsWith(".class"))
+ .map(Analyze::analyzeClass).collect(Collectors.toList());
return PackageTally.fromAnalyzedClassFiles(analyzedClasses);
}
- private PackageTally definedPackages(Collection<Artifact> jarArtifacts) {
- List<PackageTally> tallies = new ArrayList<>();
- for (var artifact : jarArtifacts) {
- try {
- tallies.add(definedPackages(new JarFile(artifact.getFile()), artifactVersionOrNull(artifact.getVersion())));
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- return PackageTally.combine(tallies);
+ private static PackageTally definedPackages(Collection<Artifact> jarArtifacts) {
+ return PackageTally.combine(jarArtifacts.stream().map(ja -> withJarFile(ja.getFile(), GenerateOsgiManifestMojo::definedPackages))
+ .collect(Collectors.toList()));
}
- private static PackageTally definedPackages(JarFile jarFile, ArtifactVersion version) throws MojoExecutionException {
+ private static PackageTally definedPackages(JarFile jarFile) throws MojoExecutionException {
List<ClassFileMetaData> analyzedClasses = new ArrayList<>();
for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
JarEntry entry = entries.nextElement();
if (! entry.isDirectory() && entry.getName().endsWith(".class")) {
- analyzedClasses.add(analyzeClass(jarFile, entry, version));
+ analyzedClasses.add(analyzeClass(jarFile, entry));
}
}
return PackageTally.fromAnalyzedClassFiles(analyzedClasses);
}
- private static ClassFileMetaData analyzeClass(JarFile jarFile, JarEntry entry, ArtifactVersion version) throws MojoExecutionException {
+ private static ClassFileMetaData analyzeClass(JarFile jarFile, JarEntry entry) throws MojoExecutionException {
try {
- return Analyze.analyzeClass(jarFile.getInputStream(entry), version);
+ return withInputStream(jarFile, entry, Analyze::analyzeClass);
} catch (Exception e) {
throw new MojoExecutionException(
String.format("While analyzing the class '%s' in jar file '%s'", entry.getName(), jarFile.getName()), e);
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/IO.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/IO.java
index 654fb700a43..a1e313b920b 100644
--- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/IO.java
+++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/IO.java
@@ -13,6 +13,13 @@ import java.io.OutputStream;
* @author ollivir
*/
public class IO {
+ public static <T> T withFileInputStream(File file, ThrowingFunction<FileInputStream, T> f) {
+ try (FileInputStream fis = new FileInputStream(file)) {
+ return f.apply(fis);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
/**
* Creates a new file and all its parent directories, and provides a file output stream to the file.