diff options
author | gjoranv <gv@verizonmedia.com> | 2021-07-14 13:52:18 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2021-07-14 13:52:18 +0200 |
commit | 934119027d314fc403858e475fca1a33047af206 (patch) | |
tree | 9d1f987d21aa64cebab6cb78f2a6012c5852dc92 /bundle-plugin/src/main/java/com/yahoo/container | |
parent | 3534840687517be5d8f90af0a7bde4ebb43bc06a (diff) |
Remove the GenerateBundleClassPathMappingsMojo and tests.
Diffstat (limited to 'bundle-plugin/src/main/java/com/yahoo/container')
2 files changed, 0 insertions, 196 deletions
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 -> [.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); - } - } -} |