summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java39
-rw-r--r--bundle-plugin-test/test-bundles/main/pom.xml26
-rw-r--r--bundle-plugin-test/test-bundles/pom.xml7
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateBundleClassPathMappingsMojo.java116
-rw-r--r--bundle-plugin/src/main/java/com/yahoo/container/plugin/osgi/ProjectBundleClassPaths.java80
5 files changed, 0 insertions, 268 deletions
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 35a95ed3d89..a39896928c8 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
@@ -1,19 +1,15 @@
// 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.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
@@ -22,13 +18,7 @@ import java.util.jar.Manifest;
import java.util.regex.Pattern;
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.assertThat;
@@ -152,33 +142,4 @@ 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);
-
- 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<String> mainBundleClassPaths = bundleClassPaths.mainBundle.classPathElements;
-
- assertThat(mainBundleClassPaths,
- hasItems(
- endsWith("target/classes"),
- anyOf(
- allOf(containsString("/jrt-"), containsString(".jar")),
- containsString("/jrt.jar"))));
- }
}
diff --git a/bundle-plugin-test/test-bundles/main/pom.xml b/bundle-plugin-test/test-bundles/main/pom.xml
index 190e1c9d90f..c315318453e 100644
--- a/bundle-plugin-test/test-bundles/main/pom.xml
+++ b/bundle-plugin-test/test-bundles/main/pom.xml
@@ -42,32 +42,6 @@
<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
index 712ccb5542e..ab19b3578c5 100644
--- a/bundle-plugin-test/test-bundles/pom.xml
+++ b/bundle-plugin-test/test-bundles/pom.xml
@@ -30,13 +30,6 @@
<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>
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateBundleClassPathMappingsMojo.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateBundleClassPathMappingsMojo.java
deleted file mode 100644
index e94e05512aa..00000000000
--- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateBundleClassPathMappingsMojo.java
+++ /dev/null
@@ -1,116 +0,0 @@
-// 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.mojo;
-
-import com.google.common.base.Preconditions;
-import com.yahoo.container.plugin.bundle.AnalyzeBundle;
-import com.yahoo.container.plugin.osgi.ProjectBundleClassPaths;
-import com.yahoo.container.plugin.osgi.ProjectBundleClassPaths.BundleClasspathMapping;
-import com.yahoo.container.plugin.util.Artifacts;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.annotations.ResolutionScope;
-import org.apache.maven.project.MavenProject;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-/**
- * Generates mapping from Bundle-SymbolicName to classpath elements, e.g myBundle -&gt; [.m2/repository/com/mylib/Mylib.jar,
- * myBundleProject/target/classes] The mapping in stored in a json file.
- *
- * @author Tony Vaagenes
- * @author ollivir
- */
-@Mojo(name = "generate-bundle-classpath-mappings", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, threadSafe = true)
-public class GenerateBundleClassPathMappingsMojo extends AbstractMojo {
- @Parameter(defaultValue = "${project}")
- private MavenProject project = null;
-
- //TODO: Combine with com.yahoo.container.plugin.mojo.GenerateOsgiManifestMojo.bundleSymbolicName
- @Parameter(alias = "Bundle-SymbolicName", defaultValue = "${project.artifactId}")
- private String bundleSymbolicName = null;
-
- /* Sample output -- target/test-classes/bundle-plugin.bundle-classpath-mappings.json
- {
- "mainBundle": {
- "bundleSymbolicName": "bundle-plugin-test",
- "classPathElements": [
- "/Users/tonyv/Repos/vespa/bundle-plugin-test/target/classes",
- "/Users/tonyv/.m2/repository/com/yahoo/vespa/jrt/7-SNAPSHOT/jrt-7-SNAPSHOT.jar",
- "/Users/tonyv/.m2/repository/com/yahoo/vespa/annotations/7-SNAPSHOT/annotations-7-SNAPSHOT.jar"
- ]
- },
- "providedDependencies": [
- {
- "bundleSymbolicName": "jrt",
- "classPathElements": [
- "/Users/tonyv/.m2/repository/com/yahoo/vespa/jrt/7-SNAPSHOT/jrt-7-SNAPSHOT.jar"
- ]
- }
- ]
- }
- */
- @Override
- public void execute() throws MojoExecutionException {
- Preconditions.checkNotNull(bundleSymbolicName);
-
- Artifacts.ArtifactSet artifacts = Artifacts.getArtifacts(project);
- List<Artifact> embeddedArtifacts = artifacts.getJarArtifactsToInclude();
- List<Artifact> providedJarArtifacts = artifacts.getJarArtifactsProvided();
-
- List<File> embeddedArtifactsFiles = embeddedArtifacts.stream().map(Artifact::getFile).collect(Collectors.toList());
-
- List<String> classPathElements = Stream.concat(Stream.of(outputDirectory()), embeddedArtifactsFiles.stream())
- .map(File::getAbsolutePath).collect(Collectors.toList());
-
- ProjectBundleClassPaths classPathMappings = new ProjectBundleClassPaths(
- new BundleClasspathMapping(bundleSymbolicName, classPathElements),
- providedJarArtifacts.stream().map(f -> createDependencyClasspathMapping(f)).filter(Optional::isPresent).map(Optional::get)
- .collect(Collectors.toList()));
-
- try {
- ProjectBundleClassPaths.save(testOutputPath().resolve(ProjectBundleClassPaths.CLASSPATH_MAPPINGS_FILENAME), classPathMappings);
- } catch (IOException e) {
- throw new MojoExecutionException("Error saving to file " + testOutputPath(), e);
- }
- }
-
- private File outputDirectory() {
- return new File(project.getBuild().getOutputDirectory());
- }
-
- private Path testOutputPath() {
- return Paths.get(project.getBuild().getTestOutputDirectory());
- }
-
- /* TODO:
- * 1) add the dependencies of the artifact in the future(i.e. dependencies of dependencies)
- * or
- * 2) obtain bundles with embedded dependencies from the maven repository,
- * and support loading classes from the nested jar files in those bundles.
- */
- Optional<BundleClasspathMapping> createDependencyClasspathMapping(Artifact artifact) {
- return bundleSymbolicNameForArtifact(artifact)
- .map(name -> new BundleClasspathMapping(name, Arrays.asList(artifact.getFile().getAbsolutePath())));
- }
-
- private static Optional<String> bundleSymbolicNameForArtifact(Artifact artifact) {
- if (artifact.getFile().getName().endsWith(".jar")) {
- return AnalyzeBundle.bundleSymbolicName(artifact.getFile());
- } else {
- // Not the best heuristic. The other alternatives are parsing the pom file or
- // storing information in target/classes when building the provided bundles.
- return Optional.of(artifact.getArtifactId());
- }
- }
-}
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/osgi/ProjectBundleClassPaths.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/osgi/ProjectBundleClassPaths.java
deleted file mode 100644
index 42033f6ac73..00000000000
--- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/osgi/ProjectBundleClassPaths.java
+++ /dev/null
@@ -1,80 +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.osgi;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Represents the bundles in a maven project and the classpath elements
- * corresponding to code that would end up in the bundle.
- *
- * @author Tony Vaagenes
- * @author bjorncs
- */
-public class ProjectBundleClassPaths {
- public static final String CLASSPATH_MAPPINGS_FILENAME = "bundle-plugin.bundle-classpath-mappings.json";
-
- private static final ObjectMapper mapper = new ObjectMapper();
-
- @JsonProperty("mainBundle") public final BundleClasspathMapping mainBundle;
- @JsonProperty("providedDependencies") public final List<BundleClasspathMapping> providedDependencies;
-
- @JsonCreator
- public ProjectBundleClassPaths(@JsonProperty("mainBundle") BundleClasspathMapping mainBundle,
- @JsonProperty("providedDependencies") List<BundleClasspathMapping> providedDependencies) {
- this.mainBundle = mainBundle;
- this.providedDependencies = providedDependencies;
- }
-
- public static void save(Path path, ProjectBundleClassPaths mappings) throws IOException {
- Files.createDirectories(path.getParent());
- mapper.writeValue(path.toFile(), mappings);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- ProjectBundleClassPaths that = (ProjectBundleClassPaths) o;
- return Objects.equals(mainBundle, that.mainBundle) &&
- Objects.equals(providedDependencies, that.providedDependencies);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(mainBundle, providedDependencies);
- }
-
- public static class BundleClasspathMapping {
- @JsonProperty("bundleSymbolicName") public final String bundleSymbolicName;
- @JsonProperty("classPathElements") public final List<String> classPathElements;
-
- @JsonCreator
- public BundleClasspathMapping(@JsonProperty("bundleSymbolicName") String bundleSymbolicName,
- @JsonProperty("classPathElements") List<String> classPathElements) {
- this.bundleSymbolicName = bundleSymbolicName;
- this.classPathElements = classPathElements;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- BundleClasspathMapping that = (BundleClasspathMapping) o;
- return Objects.equals(bundleSymbolicName, that.bundleSymbolicName) &&
- Objects.equals(classPathElements, that.classPathElements);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(bundleSymbolicName, classPathElements);
- }
- }
-}