summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2021-07-14 18:24:05 +0200
committergjoranv <gv@verizonmedia.com>2021-07-14 18:24:05 +0200
commita9b25abb250d6d1f1145882017241c30a7fcb447 (patch)
tree3b39a3bc744756fcb4310f370c2a60915701fe13 /container-core
parent34f4fa288380263975dd1b45b54847c36c6b6745 (diff)
Remove Jersey related code from the container osgi layer.
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java27
-rw-r--r--container-core/src/main/java/com/yahoo/container/di/Osgi.java5
-rw-r--r--container-core/src/main/java/com/yahoo/container/di/osgi/BundleClasses.java27
-rw-r--r--container-core/src/main/java/com/yahoo/container/di/osgi/OsgiUtil.java168
-rw-r--r--container-core/src/main/java/com/yahoo/container/di/osgi/package-info.java8
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java6
6 files changed, 0 insertions, 241 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java
index 08a468a3031..1d63fb2312a 100644
--- a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java
+++ b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java
@@ -5,7 +5,6 @@ import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.yahoo.component.AbstractComponent;
-import com.yahoo.component.ComponentSpecification;
import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.concurrent.ThreadFactoryFactory;
import com.yahoo.config.FileReference;
@@ -13,8 +12,6 @@ import com.yahoo.container.di.ComponentDeconstructor;
import com.yahoo.container.di.Container;
import com.yahoo.container.di.componentgraph.core.ComponentGraph;
import com.yahoo.container.di.config.SubscriberFactory;
-import com.yahoo.container.di.osgi.BundleClasses;
-import com.yahoo.container.di.osgi.OsgiUtil;
import com.yahoo.container.logging.AccessLog;
import com.yahoo.filedistribution.fileacquirer.FileAcquirer;
import com.yahoo.jdisc.application.OsgiFramework;
@@ -25,7 +22,6 @@ import com.yahoo.osgi.OsgiImpl;
import com.yahoo.osgi.OsgiWrapper;
import com.yahoo.statistics.Statistics;
import org.osgi.framework.Bundle;
-import org.osgi.framework.wiring.BundleWiring;
import java.util.ArrayList;
import java.util.Collection;
@@ -35,8 +31,6 @@ import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
-import static com.yahoo.collections.CollectionUtil.first;
-
/**
* For internal use only.
*
@@ -94,27 +88,6 @@ public class HandlersConfigurerDi {
platformBundleLoader = new PlatformBundleLoader(this);
}
-
- // TODO Vespa 8: Remove, only used for Jersey
- @Override
- public BundleClasses getBundleClasses(ComponentSpecification bundleSpec, Set<String> packagesToScan) {
- //Temporary hack: Using class name since ClassLoaderOsgiFramework is not available at compile time in this bundle.
- if (osgiFramework.getClass().getName().equals("com.yahoo.application.container.impl.ClassLoaderOsgiFramework")) {
- Bundle syntheticClassPathBundle = first(osgiFramework.bundles());
- ClassLoader classLoader = syntheticClassPathBundle.adapt(BundleWiring.class).getClassLoader();
-
- return new BundleClasses(
- syntheticClassPathBundle,
- OsgiUtil.getClassEntriesForBundleUsingProjectClassPathMappings(classLoader, bundleSpec, packagesToScan));
- } else {
- Bundle bundle = getBundle(bundleSpec);
- if (bundle == null)
- throw new RuntimeException("No bundle matching '" + bundleSpec + "'");
-
- return new BundleClasses(bundle, OsgiUtil.getClassEntriesInBundleClassPath(bundle, packagesToScan));
- }
- }
-
@Override
public void installPlatformBundles(Collection<String> bundlePaths) {
// Don't install physical bundles for test frameworks, where all platform bundles are on the classpath.
diff --git a/container-core/src/main/java/com/yahoo/container/di/Osgi.java b/container-core/src/main/java/com/yahoo/container/di/Osgi.java
index 940986e2f38..2ba93171081 100644
--- a/container-core/src/main/java/com/yahoo/container/di/Osgi.java
+++ b/container-core/src/main/java/com/yahoo/container/di/Osgi.java
@@ -5,11 +5,9 @@ import com.yahoo.component.ComponentSpecification;
import com.yahoo.config.FileReference;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.bundle.MockBundle;
-import com.yahoo.container.di.osgi.BundleClasses;
import org.osgi.framework.Bundle;
import java.util.Collection;
-import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
@@ -21,9 +19,6 @@ import static java.util.Collections.emptySet;
* @author ollivir
*/
public interface Osgi {
- default BundleClasses getBundleClasses(ComponentSpecification bundle, Set<String> packagesToScan) {
- return new BundleClasses(new MockBundle(), Collections.emptySet());
- }
default void installPlatformBundles(Collection<String> bundlePaths) {
System.out.println("installPlatformBundles " + bundlePaths);
diff --git a/container-core/src/main/java/com/yahoo/container/di/osgi/BundleClasses.java b/container-core/src/main/java/com/yahoo/container/di/osgi/BundleClasses.java
deleted file mode 100644
index bca3ed73d0b..00000000000
--- a/container-core/src/main/java/com/yahoo/container/di/osgi/BundleClasses.java
+++ /dev/null
@@ -1,27 +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.di.osgi;
-
-import org.osgi.framework.Bundle;
-
-import java.util.Collection;
-
-/**
- * @author ollivir
- */
-public class BundleClasses {
- private final Bundle bundle;
- private final Collection<String> classEntries;
-
- public BundleClasses(Bundle bundle, Collection<String> classEntries) {
- this.bundle = bundle;
- this.classEntries = classEntries;
- }
-
- public Bundle bundle() {
- return bundle;
- }
-
- public Collection<String> classEntries() {
- return classEntries;
- }
-}
diff --git a/container-core/src/main/java/com/yahoo/container/di/osgi/OsgiUtil.java b/container-core/src/main/java/com/yahoo/container/di/osgi/OsgiUtil.java
deleted file mode 100644
index e1854155e5b..00000000000
--- a/container-core/src/main/java/com/yahoo/container/di/osgi/OsgiUtil.java
+++ /dev/null
@@ -1,168 +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.di.osgi;
-
-import com.yahoo.component.ComponentSpecification;
-import com.yahoo.osgi.maven.ProjectBundleClassPaths;
-import com.yahoo.osgi.maven.ProjectBundleClassPaths.BundleClasspathMapping;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.wiring.BundleWiring;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-import static com.google.common.io.Files.fileTreeTraverser;
-
-/**
- * Tested by com.yahoo.application.container.jersey.JerseyTest
- *
- * @author Tony Vaagenes
- * @author ollivir
- */
-public class OsgiUtil {
- private static final Logger log = Logger.getLogger(OsgiUtil.class.getName());
- private static final String CLASS_FILE_TYPE_SUFFIX = ".class";
-
- public static Collection<String> getClassEntriesInBundleClassPath(Bundle bundle, Set<String> packagesToScan) {
- BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
-
- if (packagesToScan.isEmpty()) {
- return bundleWiring.listResources("/", "*" + CLASS_FILE_TYPE_SUFFIX,
- BundleWiring.LISTRESOURCES_LOCAL | BundleWiring.LISTRESOURCES_RECURSE);
- } else {
- List<String> ret = new ArrayList<>();
- for (String pkg : packagesToScan) {
- ret.addAll(bundleWiring.listResources(packageToPath(pkg), "*" + CLASS_FILE_TYPE_SUFFIX, BundleWiring.LISTRESOURCES_LOCAL));
- }
- return ret;
- }
- }
-
- public static Collection<String> getClassEntriesForBundleUsingProjectClassPathMappings(ClassLoader classLoader,
- ComponentSpecification bundleSpec, Set<String> packagesToScan) {
- return classEntriesFrom(bundleClassPathMapping(bundleSpec, classLoader).classPathElements, packagesToScan);
- }
-
- private static BundleClasspathMapping bundleClassPathMapping(ComponentSpecification bundleSpec, ClassLoader classLoader) {
- ProjectBundleClassPaths projectBundleClassPaths = loadProjectBundleClassPaths(classLoader);
-
- if (projectBundleClassPaths.mainBundle.bundleSymbolicName.equals(bundleSpec.getName())) {
- return projectBundleClassPaths.mainBundle;
- } else {
- log.log(Level.WARNING,
- "Dependencies of the bundle " + bundleSpec + " will not be scanned. Please file a feature request if you need this");
- return matchingBundleClassPathMapping(bundleSpec, projectBundleClassPaths.providedDependencies);
- }
- }
-
- public static BundleClasspathMapping matchingBundleClassPathMapping(ComponentSpecification bundleSpec,
- Collection<BundleClasspathMapping> providedBundlesClassPathMappings) {
- for (BundleClasspathMapping mapping : providedBundlesClassPathMappings) {
- if (mapping.bundleSymbolicName.equals(bundleSpec.getName())) {
- return mapping;
- }
- }
- throw new RuntimeException("No such bundle: " + bundleSpec);
- }
-
- private static ProjectBundleClassPaths loadProjectBundleClassPaths(ClassLoader classLoader) {
- URL classPathMappingsFileLocation = classLoader.getResource(ProjectBundleClassPaths.CLASSPATH_MAPPINGS_FILENAME);
- if (classPathMappingsFileLocation == null) {
- throw new RuntimeException("Couldn't find " + ProjectBundleClassPaths.CLASSPATH_MAPPINGS_FILENAME + " in the class path.");
- }
-
- try {
- return ProjectBundleClassPaths.load(Paths.get(classPathMappingsFileLocation.toURI()));
- } catch (IOException | URISyntaxException e) {
- throw new RuntimeException(e);
- }
- }
-
- private static Collection<String> classEntriesFrom(List<String> classPathEntries, Set<String> packagesToScan) {
- Set<String> packagePathsToScan = packagesToScan.stream().map(OsgiUtil::packageToPath).collect(Collectors.toSet());
- List<String> ret = new ArrayList<>();
-
- for (String entry : classPathEntries) {
- Path path = Paths.get(entry);
- if (Files.isDirectory(path)) {
- ret.addAll(classEntriesInPath(path, packagePathsToScan));
- } else if (Files.isRegularFile(path) && path.getFileName().toString().endsWith(".jar")) {
- ret.addAll(classEntriesInJar(path, packagePathsToScan));
- } else {
- throw new RuntimeException("Unsupported path " + path + " in the class path");
- }
- }
- return ret;
- }
-
- private static String relativePathToClass(Path rootPath, Path pathToClass) {
- Path relativePath = rootPath.relativize(pathToClass);
- return relativePath.toString();
- }
-
- private static Collection<String> classEntriesInPath(Path rootPath, Collection<String> packagePathsToScan) {
- Iterable<File> fileIterator;
- if (packagePathsToScan.isEmpty()) {
- fileIterator = fileTreeTraverser().preOrderTraversal(rootPath.toFile());
- } else {
- List<File> files = new ArrayList<>();
- for (String packagePath : packagePathsToScan) {
- for (File file : fileTreeTraverser().children(rootPath.resolve(packagePath).toFile())) {
- files.add(file);
- }
- }
- fileIterator = files;
- }
-
- List<String> ret = new ArrayList<>();
- for (File file : fileIterator) {
- if (file.isFile() && file.getName().endsWith(CLASS_FILE_TYPE_SUFFIX)) {
- ret.add(relativePathToClass(rootPath, file.toPath()));
- }
- }
- return ret;
- }
-
- private static String packagePath(String name) {
- int index = name.lastIndexOf('/');
- if (index < 0) {
- return name;
- } else {
- return name.substring(0, index);
- }
- }
-
- private static Collection<String> classEntriesInJar(Path jarPath, Set<String> packagePathsToScan) {
- Predicate<String> acceptedPackage;
- if (packagePathsToScan.isEmpty()) {
- acceptedPackage = ign -> true;
- } else {
- acceptedPackage = name -> packagePathsToScan.contains(packagePath(name));
- }
-
- try (JarFile jarFile = new JarFile(jarPath.toFile())) {
- return jarFile.stream().map(JarEntry::getName).filter(name -> name.endsWith(CLASS_FILE_TYPE_SUFFIX)).filter(acceptedPackage)
- .collect(Collectors.toList());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private static String packageToPath(String packageName) {
- return packageName.replace('.', '/');
- }
-}
diff --git a/container-core/src/main/java/com/yahoo/container/di/osgi/package-info.java b/container-core/src/main/java/com/yahoo/container/di/osgi/package-info.java
deleted file mode 100644
index 9685cf571bd..00000000000
--- a/container-core/src/main/java/com/yahoo/container/di/osgi/package-info.java
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/**
- * @author Tony Vaagenes
- */
-@ExportPackage
-package com.yahoo.container.di.osgi;
-
-import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java b/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
index 2106a1f3671..0d1a308f182 100644
--- a/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
+++ b/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
@@ -7,7 +7,6 @@ import com.yahoo.config.FileReference;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.di.ContainerTest.ComponentTakingConfig;
import com.yahoo.container.di.componentgraph.core.ComponentGraph;
-import com.yahoo.container.di.osgi.BundleClasses;
import org.junit.After;
import org.junit.Before;
import org.osgi.framework.Bundle;
@@ -57,11 +56,6 @@ public class ContainerTestBase {
}
@Override
- public BundleClasses getBundleClasses(ComponentSpecification bundle, Set<String> packagesToScan) {
- throw new UnsupportedOperationException("getBundleClasses not supported");
- }
-
- @Override
public Set<Bundle> useApplicationBundles(Collection<FileReference> bundles) {
return emptySet();
}