You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2022/02/14 06:21:09 UTC
[logging-log4j2] branch master updated: Delete previous attempt at LOG4J2-2803
This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new fb954c5 Delete previous attempt at LOG4J2-2803
fb954c5 is described below
commit fb954c5d37c7e2832d8c4f724c4b56df8bdd528b
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Mon Feb 14 00:12:33 2022 -0600
Delete previous attempt at LOG4J2-2803
This helps the diff a bit.
---
log4j-core/src/main/java/module-info.java | 1 -
.../log4j/plugin/processor/BeanProcessor.java | 502 -----------------
.../src/main/java9/module-info.java | 4 +-
.../services/javax.annotation.processing.Processor | 1 -
.../log4j/plugins/test/validation/ExampleBean.java | 45 --
.../plugins/test/validation/ImplicitBean.java | 44 --
.../test/validation/ImplicitMethodBean.java | 53 --
.../plugins/test/validation/ProductionBean.java | 56 --
log4j-plugins-test/src/main/java9/module-info.java | 1 -
.../log4j/plugin/processor/BeanProcessorTest.java | 54 --
.../logging/log4j/plugins/spi/BeanManagerTest.java | 605 ---------------------
.../log4j/plugins/spi/InjectionPointTest.java | 136 -----
.../log4j/plugins/spi/InjectionTargetTest.java | 106 ----
log4j-plugins/src/main/java/module-info.java | 7 -
.../logging/log4j/plugins/DependentScoped.java | 41 --
.../org/apache/logging/log4j/plugins/Disposes.java | 37 --
.../org/apache/logging/log4j/plugins/Inject.java | 3 -
.../logging/log4j/plugins/PostConstruct.java | 36 --
.../apache/logging/log4j/plugins/PreDestroy.java | 34 --
.../org/apache/logging/log4j/plugins/Produces.java | 53 --
.../apache/logging/log4j/plugins/di/Provider.java | 22 -
.../log4j/plugins/di/model/DisposesMethod.java | 48 --
.../log4j/plugins/di/model/GenericPlugin.java | 44 --
.../log4j/plugins/di/model/InjectionTarget.java | 44 --
.../log4j/plugins/di/model/PluginModule.java | 24 -
.../log4j/plugins/di/model/PluginSource.java | 26 -
.../log4j/plugins/di/model/ProducerField.java | 51 --
.../log4j/plugins/di/model/ProducerMethod.java | 57 --
.../logging/log4j/plugins/di/package-info.java | 25 -
.../log4j/plugins/spi/AmbiguousBeanException.java | 26 -
.../org/apache/logging/log4j/plugins/spi/Bean.java | 100 ----
.../logging/log4j/plugins/spi/BeanManager.java | 296 ----------
.../log4j/plugins/spi/DefinitionException.java | 24 -
.../log4j/plugins/spi/IllegalProductException.java | 24 -
.../log4j/plugins/spi/InitializationContext.java | 54 --
.../log4j/plugins/spi/InitializationException.java | 28 -
.../log4j/plugins/spi/InjectionException.java | 28 -
.../logging/log4j/plugins/spi/InjectionPoint.java | 55 --
.../logging/log4j/plugins/spi/InjectionTarget.java | 63 ---
.../log4j/plugins/spi/InjectionTargetFactory.java | 22 -
.../log4j/plugins/spi/LoggerContextScoped.java | 35 --
.../apache/logging/log4j/plugins/spi/Producer.java | 67 ---
.../logging/log4j/plugins/spi/ProducerFactory.java | 23 -
.../log4j/plugins/spi/ResolutionException.java | 24 -
.../logging/log4j/plugins/spi/ScopeContext.java | 63 ---
.../plugins/spi/UnsatisfiedBeanException.java | 30 -
.../log4j/plugins/spi/ValidationException.java | 36 --
.../log4j/plugins/spi/impl/AbstractBean.java | 76 ---
.../log4j/plugins/spi/impl/AbstractProducer.java | 74 ---
.../plugins/spi/impl/AbstractProducerFactory.java | 42 --
.../log4j/plugins/spi/impl/DefaultBeanManager.java | 548 -------------------
.../spi/impl/DefaultInitializationContext.java | 134 -----
.../plugins/spi/impl/DefaultInjectionPoint.java | 121 -----
.../plugins/spi/impl/DefaultInjectionTarget.java | 136 -----
.../spi/impl/DefaultInjectionTargetFactory.java | 160 ------
.../plugins/spi/impl/DefaultScopeContext.java | 72 ---
.../plugins/spi/impl/DependentScopeContext.java | 58 --
.../log4j/plugins/spi/impl/FieldProducer.java | 67 ---
.../plugins/spi/impl/FieldProducerFactory.java | 44 --
.../plugins/spi/impl/InjectionTargetBean.java | 84 ---
.../logging/log4j/plugins/spi/impl/Injector.java | 111 ----
.../log4j/plugins/spi/impl/MethodProducer.java | 63 ---
.../plugins/spi/impl/MethodProducerFactory.java | 47 --
.../log4j/plugins/spi/impl/OptionalBean.java | 83 ---
.../log4j/plugins/spi/impl/ProducerBean.java | 94 ----
.../log4j/plugins/spi/impl/ProvidedBean.java | 77 ---
.../log4j/plugins/spi/impl/ProviderBean.java | 77 ---
.../logging/log4j/plugins/util/PluginLoader.java | 60 --
68 files changed, 1 insertion(+), 5385 deletions(-)
diff --git a/log4j-core/src/main/java/module-info.java b/log4j-core/src/main/java/module-info.java
index 7518de2..a743ce6 100644
--- a/log4j-core/src/main/java/module-info.java
+++ b/log4j-core/src/main/java/module-info.java
@@ -84,5 +84,4 @@ module org.apache.logging.log4j.core {
provides org.apache.logging.log4j.core.util.ContextDataProvider with org.apache.logging.log4j.core.impl.ThreadContextDataProvider;
provides org.apache.logging.log4j.spi.Provider with org.apache.logging.log4j.core.impl.Log4jProvider;
provides org.apache.logging.log4j.plugins.processor.PluginService with org.apache.logging.log4j.core.plugins.Log4jPlugins;
- provides org.apache.logging.log4j.plugins.di.model.PluginModule with org.apache.logging.log4j.core.plugins.Log4jModule;
}
diff --git a/log4j-plugin-processor/src/main/java/org/apache/logging/log4j/plugin/processor/BeanProcessor.java b/log4j-plugin-processor/src/main/java/org/apache/logging/log4j/plugin/processor/BeanProcessor.java
deleted file mode 100644
index 214330b..0000000
--- a/log4j-plugin-processor/src/main/java/org/apache/logging/log4j/plugin/processor/BeanProcessor.java
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugin.processor;
-
-import org.apache.logging.log4j.plugins.Disposes;
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Producer;
-import org.apache.logging.log4j.plugins.Qualifier;
-
-import javax.annotation.processing.AbstractProcessor;
-import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.annotation.processing.SupportedOptions;
-import javax.lang.model.SourceVersion;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.ElementKind;
-import javax.lang.model.element.ExecutableElement;
-import javax.lang.model.element.Modifier;
-import javax.lang.model.element.Name;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.element.VariableElement;
-import javax.lang.model.type.DeclaredType;
-import javax.lang.model.type.TypeMirror;
-import javax.lang.model.util.ElementFilter;
-import javax.lang.model.util.ElementKindVisitor9;
-import javax.lang.model.util.Elements;
-import javax.lang.model.util.SimpleTypeVisitor9;
-import javax.lang.model.util.Types;
-import javax.tools.StandardLocation;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.UncheckedIOException;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-@SupportedAnnotationTypes({"org.apache.logging.log4j.plugins.*", "org.apache.logging.log4j.core.config.plugins.*"})
-@SupportedOptions({"pluginPackage", "pluginClassName"})
-public class BeanProcessor extends AbstractProcessor {
- public static final String PLUGIN_MODULE_SERVICE_FILE = "META-INF/services/org.apache.logging.log4j.plugins.di.model.PluginModule";
-
- public BeanProcessor() {
- }
-
- @Override
- public SourceVersion getSupportedSourceVersion() {
- return SourceVersion.latestSupported();
- }
-
- /**
- * Collects fields and methods annotated with {@link Producer}-type annotations.
- */
- private static class ProducerAnnotationVisitor extends ElementKindVisitor9<Void, Void> {
- private final List<ProducerMethodMirror> producerMethods = new ArrayList<>();
- private final List<ProducerFieldMirror> producerFields = new ArrayList<>();
-
- @Override
- public Void visitVariableAsField(final VariableElement e, final Void unused) {
- producerFields.add(new ProducerFieldMirror(e));
- return null;
- }
-
- @Override
- public Void visitExecutableAsMethod(final ExecutableElement e, final Void unused) {
- producerMethods.add(new ProducerMethodMirror(e));
- return null;
- }
- }
-
- /**
- * Collects {@link Disposes} methods (applied to a method argument).
- */
- private static class DisposesAnnotationVisitor extends ElementKindVisitor9<Void, Void> {
- private final List<DisposesMirror> disposesParameters = new ArrayList<>();
-
- @Override
- public Void visitVariableAsParameter(final VariableElement e, final Void unused) {
- disposesParameters.add(new DisposesMirror(e));
- return null;
- }
- }
-
- /**
- * Collects {@link Inject}-annotated constructors, fields, and methods.
- */
- private static class InjectAnnotationVisitor extends ElementKindVisitor9<Void, Void> {
- private final List<InjectionTargetMirror> injectableClasses = new ArrayList<>();
-
- @Override
- public Void visitVariableAsField(final VariableElement e, final Void unused) {
- injectableClasses.add(new InjectionTargetMirror(((TypeElement) e.getEnclosingElement())));
- return null;
- }
-
- @Override
- public Void visitExecutableAsConstructor(final ExecutableElement e, final Void unused) {
- injectableClasses.add(new InjectionTargetMirror((TypeElement) e.getEnclosingElement()));
- return null;
- }
-
- @Override
- public Void visitExecutableAsMethod(final ExecutableElement e, final Void unused) {
- injectableClasses.add(new InjectionTargetMirror((TypeElement) e.getEnclosingElement()));
- return null;
- }
- }
-
- /**
- * Collects fields and method parameters annotated with {@link Qualifier}-type annotations that do not also include
- * {@link Producer}-type annotations.
- */
- private static class QualifiedAnnotationVisitor extends ElementKindVisitor9<Void, Void> {
- private final Predicate<AnnotationMirror> isProducerAnnotation;
- private final List<InjectionTargetMirror> injectableClasses = new ArrayList<>();
-
- private QualifiedAnnotationVisitor(final Predicate<AnnotationMirror> isProducerAnnotation) {
- this.isProducerAnnotation = isProducerAnnotation;
- }
-
- @Override
- public Void visitVariableAsField(final VariableElement e, final Void unused) {
- if (e.getAnnotationMirrors().stream().noneMatch(isProducerAnnotation)) {
- injectableClasses.add(new InjectionTargetMirror((TypeElement) e.getEnclosingElement()));
- }
- return null;
- }
-
- @Override
- public Void visitVariableAsParameter(final VariableElement e, final Void unused) {
- final Element enclosingExecutable = e.getEnclosingElement();
- final TypeElement typeElement = (TypeElement) enclosingExecutable.getEnclosingElement();
- if (enclosingExecutable.getKind() == ElementKind.CONSTRUCTOR ||
- enclosingExecutable.getAnnotationMirrors().stream().noneMatch(isProducerAnnotation)) {
- injectableClasses.add(new InjectionTargetMirror(typeElement));
- }
- return null;
- }
- }
-
- /**
- * Collects generic {@code @Plugin}-annotated classes. Plugins with a single constructor are considered for
- * {@link Inject} targets.
- */
- private static class PluginAnnotationVisitor extends ElementKindVisitor9<Void, Void> {
- private final List<InjectionTargetMirror> implicitPlugins = new ArrayList<>();
- private final List<GenericPluginMirror> genericPlugins = new ArrayList<>();
-
- @Override
- public Void visitTypeAsClass(final TypeElement e, final Void unused) {
- final var constructors = ElementFilter.constructorsIn(e.getEnclosedElements());
- if (constructors.size() > 1) {
- genericPlugins.add(new GenericPluginMirror(e));
- } else {
- implicitPlugins.add(new InjectionTargetMirror(e));
- }
- return null;
- }
- }
-
- /**
- * Annotation scanning mirror of {@link org.apache.logging.log4j.plugins.di.model.PluginSource}.
- */
- interface PluginSourceMirror<E extends Element> {
- E getElement();
-
- TypeElement getDeclaringElement();
-
- TypeMirror getType();
- }
-
- static class ProducerMethodMirror implements PluginSourceMirror<ExecutableElement> {
- private final ExecutableElement element;
-
- ProducerMethodMirror(final ExecutableElement element) {
- this.element = element;
- }
-
- @Override
- public ExecutableElement getElement() {
- return element;
- }
-
- @Override
- public TypeElement getDeclaringElement() {
- return (TypeElement) element.getEnclosingElement();
- }
-
- @Override
- public TypeMirror getType() {
- return element.getReturnType();
- }
- }
-
- static class ProducerFieldMirror implements PluginSourceMirror<VariableElement> {
- private final VariableElement element;
-
- ProducerFieldMirror(final VariableElement element) {
- this.element = element;
- }
-
- @Override
- public VariableElement getElement() {
- return element;
- }
-
- @Override
- public TypeElement getDeclaringElement() {
- return (TypeElement) element.getEnclosingElement();
- }
-
- @Override
- public TypeMirror getType() {
- return element.asType();
- }
- }
-
- static class InjectionTargetMirror implements PluginSourceMirror<TypeElement> {
- private final TypeElement element;
-
- InjectionTargetMirror(final TypeElement element) {
- this.element = element;
- }
-
- @Override
- public TypeElement getElement() {
- return element;
- }
-
- @Override
- public TypeElement getDeclaringElement() {
- return element;
- }
-
- @Override
- public TypeMirror getType() {
- return element.asType();
- }
- }
-
- static class DisposesMirror implements PluginSourceMirror<VariableElement> {
- private final VariableElement element;
-
- DisposesMirror(final VariableElement element) {
- this.element = element;
- }
-
- @Override
- public VariableElement getElement() {
- return element;
- }
-
- @Override
- public TypeElement getDeclaringElement() {
- return (TypeElement) element.getEnclosingElement().getEnclosingElement();
- }
-
- @Override
- public TypeMirror getType() {
- return element.asType();
- }
- }
-
- static class GenericPluginMirror implements PluginSourceMirror<TypeElement> {
- private final TypeElement element;
-
- GenericPluginMirror(final TypeElement element) {
- this.element = element;
- }
-
- @Override
- public TypeElement getElement() {
- return element;
- }
-
- @Override
- public TypeElement getDeclaringElement() {
- return element;
- }
-
- @Override
- public TypeMirror getType() {
- return element.asType();
- }
- }
-
- @Override
- public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
- if (annotations.isEmpty()) {
- return false;
- }
-
- final TypeElement[] producerAnnotations = annotations.stream()
- .filter(e -> e.getAnnotation(Producer.class) != null)
- .toArray(TypeElement[]::new);
- final var producesAnnotationVisitor = new ProducerAnnotationVisitor();
- roundEnv.getElementsAnnotatedWithAny(producerAnnotations).forEach(producesAnnotationVisitor::visit);
-
- final var disposesAnnotationVisitor = new DisposesAnnotationVisitor();
- roundEnv.getElementsAnnotatedWith(Disposes.class).forEach(disposesAnnotationVisitor::visit);
-
- final var injectAnnotationVisitor = new InjectAnnotationVisitor();
- roundEnv.getElementsAnnotatedWith(Inject.class).forEach(injectAnnotationVisitor::visit);
-
- final Types types = processingEnv.getTypeUtils();
- final var qualifiedAnnotationVisitor = new QualifiedAnnotationVisitor(annotationMirror -> {
- for (final TypeElement producerAnnotation : producerAnnotations) {
- if (types.isSameType(producerAnnotation.asType(), annotationMirror.getAnnotationType())) {
- return true;
- }
- }
- return false;
- });
- final TypeElement[] qualifierAnnotations = annotations.stream()
- .filter(e -> e.getAnnotation(Qualifier.class) != null)
- .toArray(TypeElement[]::new);
- roundEnv.getElementsAnnotatedWithAny(qualifierAnnotations).forEach(qualifiedAnnotationVisitor::visit);
-
- final TypeElement[] pluginAnnotations = annotations.stream()
- .filter(e -> e.getSimpleName().contentEquals("Plugin"))
- .toArray(TypeElement[]::new);
- final var pluginAnnotationVisitor = new PluginAnnotationVisitor();
- roundEnv.getElementsAnnotatedWithAny(pluginAnnotations).forEach(pluginAnnotationVisitor::visit);
-
- final Set<PackageElement> packageElements = new HashSet<>();
- final Set<TypeElement> declaringTypes = new HashSet<>();
-
- final Elements elements = processingEnv.getElementUtils();
- final List<PluginSourceMirror<?>> mirrors = new ArrayList<>(producesAnnotationVisitor.producerMethods);
- mirrors.addAll(producesAnnotationVisitor.producerFields);
- mirrors.addAll(injectAnnotationVisitor.injectableClasses);
- mirrors.addAll(disposesAnnotationVisitor.disposesParameters);
- mirrors.addAll(pluginAnnotationVisitor.implicitPlugins);
- mirrors.forEach(mirror -> {
- declaringTypes.add(mirror.getDeclaringElement());
- packageElements.add(elements.getPackageOf(mirror.getDeclaringElement()));
- });
-
- qualifiedAnnotationVisitor.injectableClasses.stream()
- .filter(mirror -> !declaringTypes.contains(mirror.getDeclaringElement()))
- .forEach(mirror -> {
- mirrors.add(mirror);
- declaringTypes.add(mirror.getDeclaringElement());
- packageElements.add(elements.getPackageOf(mirror.getDeclaringElement()));
- });
-
- pluginAnnotationVisitor.genericPlugins.stream()
- .filter(mirror -> !declaringTypes.contains(mirror.getDeclaringElement()))
- .forEach(mirror -> {
- mirrors.add(mirror);
- declaringTypes.add(mirror.getDeclaringElement());
- packageElements.add(elements.getPackageOf(mirror.getDeclaringElement()));
- });
-
- String packageName = processingEnv.getOptions().get("pluginPackage");
- if (packageName == null) {
- packageName = packageElements.stream()
- .map(PackageElement::getQualifiedName)
- .map(CharSequence.class::cast)
- .reduce(BeanProcessor::commonPrefix)
- .orElseThrow()
- .toString();
- }
- String className = processingEnv.getOptions().getOrDefault("pluginClassName", "Log4jModule");
- try {
- writePluginModule(packageName, className, mirrors);
- return false;
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- }
-
- private void writePluginModule(final CharSequence packageName, final CharSequence className,
- final List<PluginSourceMirror<?>> mirrors) throws IOException {
- try (final PrintWriter out = new PrintWriter(processingEnv.getFiler().createResource(
- StandardLocation.CLASS_OUTPUT, "", PLUGIN_MODULE_SERVICE_FILE).openWriter())) {
- out.println(packageName + ".plugins." + className);
- }
- try (final PrintWriter out = new PrintWriter(processingEnv.getFiler().createSourceFile(
- packageName + ".plugins." + className).openWriter())) {
- out.println("package " + packageName + ".plugins;");
- out.println();
- out.println("import org.apache.logging.log4j.plugins.di.model.*;");
- out.println();
- out.println("import java.util.List;");
- out.println("import java.util.Set;");
- out.println();
- out.println("public class " + className + " implements PluginModule {");
- out.println();
- out.println(" private final ClassLoader classLoader = getClass().getClassLoader();");
- out.println(" private final List<PluginSource> pluginSources = List.of(" + javaListOfPlugins(mirrors) + ");");
- out.println();
- out.println(" @Override");
- out.println(" public List<PluginSource> getPluginSources() {");
- out.println(" return pluginSources;");
- out.println(" }");
- out.println();
- out.println("}");
- }
- }
-
- private String javaListOfPlugins(final List<PluginSourceMirror<?>> mirrors) {
- final Elements elements = processingEnv.getElementUtils();
- final Types types = processingEnv.getTypeUtils();
- return mirrors.stream()
- .sorted(Comparator.<PluginSourceMirror<?>, String>comparing(m -> m.getClass().getName())
- .thenComparing(m -> elements.getBinaryName(m.getDeclaringElement()), CharSequence::compare))
- .map(mirror -> {
- final String declaringClassName = '"' + elements.getBinaryName(mirror.getDeclaringElement()).toString() + '"';
- final String setOfImplementedInterfaces = javaSetOfImplementedInterfaces(mirror.getType());
- if (mirror instanceof ProducerMethodMirror) {
- return "new ProducerMethod(classLoader, " + declaringClassName + ", \"" +
- mirror.getType().toString() + "\", \"" +
- mirror.getElement().getSimpleName() + "\", " +
- setOfImplementedInterfaces + ")";
- } else if (mirror instanceof ProducerFieldMirror) {
- return "new ProducerField(classLoader, " + declaringClassName + ", \"" +
- mirror.getElement().getSimpleName() + "\", " +
- setOfImplementedInterfaces + ")";
- } else if (mirror instanceof InjectionTargetMirror) {
- return "new InjectionTarget(classLoader, " + declaringClassName + ", " +
- setOfImplementedInterfaces + ")";
- } else if (mirror instanceof DisposesMirror) {
- return "new DisposesMethod(classLoader, " + declaringClassName + ", \"" +
- elements.getBinaryName((TypeElement) types.asElement(mirror.getElement().asType())) + "\")";
- } else if (mirror instanceof GenericPluginMirror) {
- return "new GenericPlugin(classLoader, " + declaringClassName + ", " +
- setOfImplementedInterfaces + ")";
- } else {
- throw new UnsupportedOperationException(mirror.getClass().getName());
- }
- })
- .collect(Collectors.joining(",\n ", "\n ", "\n "));
- }
-
- private String javaSetOfImplementedInterfaces(final TypeMirror base) {
- final Set<Name> implementedInterfaces = getImplementedInterfaces(base);
- return implementedInterfaces.isEmpty() ? "Set.of()" : "Set.of(" +
- implementedInterfaces.stream().map(name -> name + ".class").collect(Collectors.joining(", ")) +
- ")";
- }
-
- private Set<Name> getImplementedInterfaces(final TypeMirror base) {
- final Set<Name> implementedInterfaces = new LinkedHashSet<>();
- final Types types = processingEnv.getTypeUtils();
- base.accept(new SimpleTypeVisitor9<Void, Void>() {
- @Override
- public Void visitDeclared(final DeclaredType t, final Void unused) {
- for (final TypeMirror directSupertype : types.directSupertypes(t)) {
- directSupertype.accept(this, null);
- }
- t.asElement().accept(new ElementKindVisitor9<Void, Void>() {
- @Override
- public Void visitTypeAsInterface(final TypeElement e, final Void unused) {
- if (e.getModifiers().contains(Modifier.PUBLIC)) {
- implementedInterfaces.add(e.getQualifiedName());
- }
- return null;
- }
- }, null);
- return null;
- }
- }, null);
- return implementedInterfaces;
- }
-
- private static CharSequence commonPrefix(final CharSequence str1, final CharSequence str2) {
- final int minLength = Math.min(str1.length(), str2.length());
- for (int i = 0; i < minLength; i++) {
- if (str1.charAt(i) != str2.charAt(i)) {
- if (i > 1 && str1.charAt(i - 1) == '.') {
- return str1.subSequence(0, i - 1);
- } else {
- return str1.subSequence(0, i);
- }
- }
- }
- return str1.subSequence(0, minLength);
- }
-
-}
diff --git a/log4j-plugin-processor/src/main/java9/module-info.java b/log4j-plugin-processor/src/main/java9/module-info.java
index 49dbeba..dae6806 100644
--- a/log4j-plugin-processor/src/main/java9/module-info.java
+++ b/log4j-plugin-processor/src/main/java9/module-info.java
@@ -22,7 +22,5 @@ module org.apache.logging.log4j.plugin.processor {
requires org.apache.logging.log4j.plugins;
requires transitive org.osgi.framework;
- provides javax.annotation.processing.Processor with
- org.apache.logging.log4j.plugin.processor.PluginProcessor,
- org.apache.logging.log4j.plugin.processor.BeanProcessor;
+ provides javax.annotation.processing.Processor with org.apache.logging.log4j.plugin.processor.PluginProcessor;
}
diff --git a/log4j-plugin-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/log4j-plugin-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor
index 1c97759..e1c421c 100644
--- a/log4j-plugin-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor
+++ b/log4j-plugin-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor
@@ -15,4 +15,3 @@
# limitations under the license.
#
org.apache.logging.log4j.plugin.processor.PluginProcessor
-org.apache.logging.log4j.plugin.processor.BeanProcessor
diff --git a/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ExampleBean.java b/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ExampleBean.java
deleted file mode 100644
index 908cd26..0000000
--- a/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ExampleBean.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.plugins.test.validation;
-
-import java.util.Map;
-import org.apache.logging.log4j.plugins.Inject;
-
-public class ExampleBean {
- private final String alpha;
- private final int beta;
- private final Map<String, String> gamma;
-
- @Inject
- public ExampleBean(final String alpha, final int beta, final Map<String, String> gamma) {
- this.alpha = alpha;
- this.beta = beta;
- this.gamma = gamma;
- }
-
- public String getAlpha() {
- return alpha;
- }
-
- public int getBeta() {
- return beta;
- }
-
- public Map<String, String> getGamma() {
- return gamma;
- }
-}
diff --git a/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ImplicitBean.java b/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ImplicitBean.java
deleted file mode 100644
index cab90b3..0000000
--- a/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ImplicitBean.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.plugins.test.validation;
-
-import java.util.Map;
-import org.apache.logging.log4j.plugins.Named;
-
-public class ImplicitBean {
- private final String alpha;
- private final int beta;
- private final Map<String, String> gamma;
-
- public ImplicitBean(@Named final String alpha, final int beta, final Map<String, String> gamma) {
- this.alpha = alpha;
- this.beta = beta;
- this.gamma = gamma;
- }
-
- public String getAlpha() {
- return alpha;
- }
-
- public int getBeta() {
- return beta;
- }
-
- public Map<String, String> getGamma() {
- return gamma;
- }
-}
diff --git a/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ImplicitMethodBean.java b/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ImplicitMethodBean.java
deleted file mode 100644
index e3e1738..0000000
--- a/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ImplicitMethodBean.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.plugins.test.validation;
-
-import java.util.Map;
-import org.apache.logging.log4j.plugins.Named;
-
-public class ImplicitMethodBean {
- private String alpha;
- private int beta;
- private Map<String, String> gamma;
-
- public String getAlpha() {
- return alpha;
- }
-
- public ImplicitMethodBean setAlpha(@Named final String alpha) {
- this.alpha = alpha;
- return this;
- }
-
- public int getBeta() {
- return beta;
- }
-
- public ImplicitMethodBean setBeta(@Named final int beta) {
- this.beta = beta;
- return this;
- }
-
- public Map<String, String> getGamma() {
- return gamma;
- }
-
- public ImplicitMethodBean setGamma(@Named final Map<String, String> gamma) {
- this.gamma = gamma;
- return this;
- }
-}
diff --git a/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ProductionBean.java b/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ProductionBean.java
deleted file mode 100644
index bdb4e43..0000000
--- a/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/ProductionBean.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.plugins.test.validation;
-
-import org.apache.logging.log4j.plugins.Disposes;
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Produces;
-import org.apache.logging.log4j.plugins.di.Provider;
-
-public class ProductionBean {
- private final String alpha;
-
- private ProductionBean(final String alpha) {
- this.alpha = alpha;
- }
-
- public String getAlpha() {
- return alpha;
- }
-
- @Produces
- public static final String ALPHA = "hello world";
-
- public static void destroyBean(@Disposes ProductionBean bean) {
- System.out.println(bean.getAlpha());
- }
-
- public static class Builder implements Provider<ProductionBean> {
- private String alpha;
-
- @Inject
- public Builder setAlpha(String alpha) {
- this.alpha = alpha;
- return this;
- }
-
- @Override
- public ProductionBean get() {
- return new ProductionBean(alpha);
- }
- }
-}
diff --git a/log4j-plugins-test/src/main/java9/module-info.java b/log4j-plugins-test/src/main/java9/module-info.java
index 885afe6..6884125 100644
--- a/log4j-plugins-test/src/main/java9/module-info.java
+++ b/log4j-plugins-test/src/main/java9/module-info.java
@@ -21,5 +21,4 @@ module org.apache.logging.log4j.plugins.test {
requires org.apache.logging.log4j.plugins;
provides org.apache.logging.log4j.plugins.processor.PluginService with org.apache.logging.log4j.plugins.test.validation.plugins.Log4jPlugins;
- provides org.apache.logging.log4j.plugins.di.model.PluginModule with org.apache.logging.log4j.plugins.test.validation.plugins.Log4jModule;
}
diff --git a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugin/processor/BeanProcessorTest.java b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugin/processor/BeanProcessorTest.java
deleted file mode 100644
index c448467..0000000
--- a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugin/processor/BeanProcessorTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugin.processor;
-
-import org.apache.logging.log4j.plugins.di.model.DisposesMethod;
-import org.apache.logging.log4j.plugins.di.model.InjectionTarget;
-import org.apache.logging.log4j.plugins.di.model.PluginModule;
-import org.apache.logging.log4j.plugins.di.model.ProducerField;
-import org.apache.logging.log4j.plugins.test.validation.ExampleBean;
-import org.apache.logging.log4j.plugins.test.validation.FakePlugin;
-import org.apache.logging.log4j.plugins.test.validation.ImplicitBean;
-import org.apache.logging.log4j.plugins.test.validation.ImplicitMethodBean;
-import org.apache.logging.log4j.plugins.test.validation.ProductionBean;
-import org.apache.logging.log4j.plugins.test.validation.plugins.Log4jModule;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class BeanProcessorTest {
- @Test
- void smokeTests() {
- final PluginModule module = new Log4jModule();
- final var plugins = module.getPluginSources();
- assertTrue(plugins.stream().anyMatch(plugin -> plugin instanceof InjectionTarget &&
- plugin.getDeclaringClass().equals(ExampleBean.class)));
- assertTrue(plugins.stream().anyMatch(plugin -> plugin instanceof InjectionTarget &&
- plugin.getDeclaringClass().equals(ImplicitBean.class)));
- assertTrue(plugins.stream().anyMatch(plugin -> plugin instanceof InjectionTarget &&
- plugin.getDeclaringClass().equals(ImplicitMethodBean.class)));
- assertTrue(plugins.stream().anyMatch(plugin -> plugin instanceof InjectionTarget &&
- plugin.getDeclaringClass().equals(ProductionBean.Builder.class)));
- assertTrue(plugins.stream().anyMatch(plugin -> plugin instanceof ProducerField &&
- plugin.getDeclaringClass().equals(ProductionBean.class)));
- assertTrue(plugins.stream().anyMatch(plugin -> plugin instanceof DisposesMethod &&
- plugin.getDeclaringClass().equals(ProductionBean.class)));
- assertTrue(plugins.stream().anyMatch(plugin -> plugin instanceof InjectionTarget &&
- plugin.getDeclaringClass().equals(FakePlugin.class)));
- }
-}
diff --git a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/spi/BeanManagerTest.java b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/spi/BeanManagerTest.java
deleted file mode 100644
index ea850e2..0000000
--- a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/spi/BeanManagerTest.java
+++ /dev/null
@@ -1,605 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Named;
-import org.apache.logging.log4j.plugins.PostConstruct;
-import org.apache.logging.log4j.plugins.PreDestroy;
-import org.apache.logging.log4j.plugins.Produces;
-import org.apache.logging.log4j.plugins.di.Provider;
-import org.apache.logging.log4j.plugins.SingletonScoped;
-import org.apache.logging.log4j.plugins.spi.impl.DefaultBeanManager;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Test;
-
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.stream.IntStream;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-class BeanManagerTest {
-
- final BeanManager beanManager = new DefaultBeanManager();
-
- @AfterEach
- void tearDown() {
- beanManager.close();
- }
-
- @SingletonScoped
- static class SingletonBean {
- }
-
- @Test
- void defaultConstructorInjection() {
- beanManager.loadAndValidateBeans(SingletonBean.class);
- final Bean<SingletonBean> bean = beanManager.getDefaultBean(SingletonBean.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final SingletonBean value = beanManager.getValue(bean, context);
- assertNotNull(value);
- }
- }
-
- @Produces
- @Named
- static SingletonBean getSingleton() {
- return new SingletonBean();
- }
-
- static class ParameterInjectionBean {
- final SingletonBean first;
- SingletonBean second;
- SingletonBean singletonBean;
-
- @Inject
- ParameterInjectionBean(@Named("singleton") final SingletonBean first) {
- this.first = first;
- }
-
- @Inject
- void parameterInjection(@Named("singleton") final SingletonBean second, final SingletonBean singletonBean) {
- this.second = second;
- this.singletonBean = singletonBean;
- }
- }
-
- @Test
- void parameterInjection() {
- beanManager.loadAndValidateBeans(getClass(), SingletonBean.class, ParameterInjectionBean.class);
- final Bean<ParameterInjectionBean> bean = beanManager.getDefaultBean(ParameterInjectionBean.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final ParameterInjectionBean value = beanManager.getValue(bean, context);
- assertNotNull(value);
- assertNotNull(value.first);
- assertNotNull(value.second);
- assertNotNull(value.singletonBean);
- assertSame(value.first, value.second);
- assertNotSame(value.first, value.singletonBean);
- }
- }
-
- static class FieldInjectionBean {
- @Inject
- @Named("singleton")
- private SingletonBean singletonBean;
-
- @Inject
- private SingletonBean singleton;
-
- @Named("primary name")
- @Named("first alias")
- @Named("singleton")
- @Named("one more alias")
- private SingletonBean bean;
- }
-
- @Test
- void fieldInjection() {
- beanManager.loadAndValidateBeans(getClass(), SingletonBean.class, FieldInjectionBean.class);
- final Bean<FieldInjectionBean> bean = beanManager.getDefaultBean(FieldInjectionBean.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final FieldInjectionBean value = beanManager.getValue(bean, context);
- assertNotNull(value.singletonBean);
- assertNotNull(value.singleton);
- assertNotNull(value.bean);
- assertNotSame(value.singletonBean, value.singleton);
- assertSame(value.singletonBean, value.bean);
- }
- }
-
- static class ImplicitConstructorBean {
- private final SingletonBean singleton;
-
- ImplicitConstructorBean(@Named final SingletonBean singleton) {
- this.singleton = singleton;
- }
- }
-
- @Test
- void implicitConstructorInjection() {
- beanManager.loadAndValidateBeans(getClass(), SingletonBean.class, ImplicitConstructorBean.class);
- final Bean<ImplicitConstructorBean> bean = beanManager.getDefaultBean(ImplicitConstructorBean.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final ImplicitConstructorBean value = beanManager.getValue(bean, context);
- assertNotNull(value.singleton);
- }
- }
-
- static class ExplicitConstructorBean {
- private final SingletonBean singleton;
-
- @Inject
- ExplicitConstructorBean(final SingletonBean singleton) {
- this.singleton = singleton;
- }
- }
-
- @Test
- void explicitConstructorInjection() {
- beanManager.loadAndValidateBeans(getClass(), SingletonBean.class, ExplicitConstructorBean.class);
- final Bean<ExplicitConstructorBean> bean = beanManager.getDefaultBean(ExplicitConstructorBean.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final ExplicitConstructorBean value = beanManager.getValue(bean, context);
- assertNotNull(value.singleton);
- }
- }
-
- @Named("dep")
- static class DependentBean {
- }
-
- static class ScopeTestingBean {
- @Named("dep")
- DependentBean field;
-
- DependentBean first;
- DependentBean second;
-
- ScopeTestingBean(@Named("dep") DependentBean first, @Named("dep") DependentBean second) {
- this.first = first;
- this.second = second;
- }
- }
-
- @Test
- void dependentScope() {
- beanManager.loadAndValidateBeans(DependentBean.class, ScopeTestingBean.class);
- final Bean<ScopeTestingBean> bean = beanManager.getDefaultBean(ScopeTestingBean.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final ScopeTestingBean value = beanManager.getValue(bean, context);
- assertNotSame(value.field, value.first);
- assertNotSame(value.field, value.second);
- assertNotSame(value.first, value.second);
- }
- }
-
- static class StaticMethodProducerBean {
- final DependentBean first;
- final DependentBean second;
- final SingletonBean singletonBean;
-
- private StaticMethodProducerBean(final DependentBean first, final DependentBean second, final SingletonBean singletonBean) {
- this.first = first;
- this.second = second;
- this.singletonBean = singletonBean;
- }
-
- @Produces
- @Named("static")
- static StaticMethodProducerBean create(@Named("dep") final DependentBean first,
- @Named("dep") final DependentBean second,
- @Named final SingletonBean singleton) {
- return new StaticMethodProducerBean(first, second, singleton);
- }
- }
-
- @Test
- void staticMethodProducer() {
- beanManager.loadAndValidateBeans(getClass(), SingletonBean.class, DependentBean.class, StaticMethodProducerBean.class);
- final Bean<StaticMethodProducerBean> bean = beanManager.getNamedBean(StaticMethodProducerBean.class, "static").orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final StaticMethodProducerBean value = beanManager.getValue(bean, context);
- assertNotNull(value.first);
- assertNotNull(value.second);
- assertNotSame(value.first, value.second);
- assertNotNull(value.singletonBean);
- }
- }
-
- static class ProviderClassProducerBean {
- final DependentBean first;
- final DependentBean second;
- final SingletonBean singletonBean;
-
- private ProviderClassProducerBean(final DependentBean first, final DependentBean second, final SingletonBean singletonBean) {
- this.first = first;
- this.second = second;
- this.singletonBean = singletonBean;
- }
-
- @Named("builder")
- static class Builder implements Provider<ProviderClassProducerBean> {
- private DependentBean dep;
- private DependentBean bean;
- private SingletonBean singleton;
-
- @Inject
- public Builder setDep(@Named final DependentBean dep) {
- this.dep = dep;
- return this;
- }
-
- @Inject
- public Builder setBean(@Named("dep") final DependentBean bean) {
- this.bean = bean;
- return this;
- }
-
- @Inject
- public Builder setSingleton(@Named final SingletonBean singleton) {
- this.singleton = singleton;
- return this;
- }
-
- @Override
- public ProviderClassProducerBean get() {
- return new ProviderClassProducerBean(dep, bean, singleton);
- }
- }
- }
-
- @Test
- void providerClassProducer() {
- beanManager.loadAndValidateBeans(getClass(), SingletonBean.class, DependentBean.class, ProviderClassProducerBean.Builder.class);
- final Bean<ProviderClassProducerBean> bean = beanManager.getNamedBean(ProviderClassProducerBean.class, "builder").orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final ProviderClassProducerBean value = beanManager.getValue(bean, context);
- assertNotNull(value.first);
- assertNotNull(value.second);
- assertNotSame(value.first, value.second);
- assertNotNull(value.singletonBean);
- }
- }
-
- static class ProviderParameterInjectionBean {
- final DependentBean alpha;
- final DependentBean beta;
- final DependentBean gamma;
-
- @Inject
- ProviderParameterInjectionBean(@Named("dep") final Provider<DependentBean> beanProvider) {
- alpha = beanProvider.get();
- beta = beanProvider.get();
- gamma = beanProvider.get();
- }
- }
-
- @Test
- void providerParameterInjection() {
- beanManager.loadAndValidateBeans(DependentBean.class, ProviderParameterInjectionBean.class);
- final Bean<ProviderParameterInjectionBean> bean = beanManager.getDefaultBean(ProviderParameterInjectionBean.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final ProviderParameterInjectionBean value = beanManager.getValue(bean, context);
- assertNotSame(value.alpha, value.beta);
- assertNotSame(value.beta, value.gamma);
- assertNotSame(value.gamma, value.alpha);
- }
- }
-
- static class SimpleBean {
- }
-
- static class OptionalInjection {
- @Inject
- private Optional<SimpleBean> field;
- private final SimpleBean arg;
- private SimpleBean methodArg;
-
- @Inject
- OptionalInjection(final Optional<SimpleBean> arg) {
- this.arg = arg.orElse(null);
- }
-
- @Inject
- void setMethodArg(final Optional<SimpleBean> methodArg) {
- this.methodArg = methodArg.orElse(null);
- }
- }
-
- @Test
- void optionalInjectionWhenBeanIsAbsent() {
- beanManager.loadAndValidateBeans(OptionalInjection.class);
- final Bean<OptionalInjection> bean = beanManager.getDefaultBean(OptionalInjection.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final OptionalInjection value = beanManager.getValue(bean, context);
- assertTrue(value.field.isEmpty());
- assertNull(value.arg);
- assertNull(value.methodArg);
- }
- }
-
- @Test
- void optionalInjectionWhenBeanIsPresent() {
- beanManager.loadAndValidateBeans(SimpleBean.class, OptionalInjection.class);
- final Bean<OptionalInjection> bean = beanManager.getDefaultBean(OptionalInjection.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final OptionalInjection value = beanManager.getValue(bean, context);
- assertTrue(value.field.isPresent());
- assertNotNull(value.arg);
- assertNotNull(value.methodArg);
- }
- }
-
- @SingletonScoped
- static class IdGenerator {
- private final AtomicInteger current = new AtomicInteger();
-
- @Produces
- public int nextId() {
- return current.incrementAndGet();
- }
-
- public int getCurrent() {
- return current.get();
- }
- }
-
- static class PostConstructInjection {
- private int one;
- private int two;
- @Inject
- private int three;
- private int four;
- private int five;
- private int six;
- @Inject
- private IdGenerator idGenerator;
-
- @Inject
- public PostConstructInjection(final int a, final int b) {
- one = a;
- two = b;
- }
-
- @PostConstruct
- public void init() {
- six = idGenerator.nextId();
- }
-
- @Inject
- public void setValue(final int value, final Integer otherValue) {
- four = value;
- five = otherValue;
- }
-
- @PreDestroy
- public void destroy() {
- idGenerator.nextId();
- one = -1;
- }
- }
-
- @Test
- void postConstructPreDestroy() {
- beanManager.loadAndValidateBeans(IdGenerator.class, PostConstructInjection.class);
- final Bean<IdGenerator> idGeneratorBean = beanManager.getDefaultBean(IdGenerator.class).orElseThrow();
- try (var context = beanManager.createInitializationContext(null)) {
- final IdGenerator idGenerator = beanManager.getValue(idGeneratorBean, context);
- assertEquals(0, idGenerator.getCurrent());
- final Bean<PostConstructInjection> bean = beanManager.getDefaultBean(PostConstructInjection.class).orElseThrow();
- final PostConstructInjection value = beanManager.getValue(bean, context);
- assertEquals(1, value.one);
- assertEquals(2, value.two);
- assertEquals(3, value.three);
- assertEquals(4, value.four);
- assertEquals(5, value.five);
- assertEquals(6, value.six);
- bean.destroy(value, context.createDependentContext(bean));
- assertEquals(7, idGenerator.getCurrent());
- assertEquals(-1, value.one);
- }
- }
-
- @SingletonScoped
- static class DeferredSingleton {
- private final int id;
-
- @Inject
- public DeferredSingleton(final int id) {
- this.id = id;
- }
- }
-
- static class DeferredDependent {
- private final int id;
-
- @Inject
- public DeferredDependent(final int id) {
- this.id = id;
- }
- }
-
- static class DeferredProviderBean {
- @Inject
- IdGenerator generator;
-
- @Inject
- Provider<DeferredSingleton> singletonProvider;
-
- @Inject
- Provider<DeferredDependent> dependentProvider;
- }
-
- @Test
- void testDeferredProviderNotInvokedUntilInitiallyProvided() {
- beanManager.loadAndValidateBeans(IdGenerator.class, DeferredSingleton.class, DeferredDependent.class, DeferredProviderBean.class);
- final Bean<DeferredProviderBean> bean = beanManager.getDefaultBean(DeferredProviderBean.class).orElseThrow();
- try (var context = beanManager.createInitializationContext(null)) {
- final DeferredProviderBean value = beanManager.getValue(bean, context);
- final IdGenerator generator = value.generator;
- final Provider<DeferredSingleton> singletonProvider = value.singletonProvider;
- final Provider<DeferredDependent> dependentProvider = value.dependentProvider;
- assertEquals(0, generator.getCurrent());
- assertEquals(1, singletonProvider.get().id);
- assertEquals(1, generator.getCurrent());
- assertEquals(1, singletonProvider.get().id);
- assertEquals(1, generator.getCurrent());
- assertEquals(2, dependentProvider.get().id);
- assertEquals(2, generator.getCurrent());
- assertEquals(1, singletonProvider.get().id);
- assertEquals(2, generator.getCurrent());
- assertEquals(3, dependentProvider.get().id);
- assertEquals(3, generator.getCurrent());
- assertEquals(1, singletonProvider.get().id);
- assertEquals(3, generator.getCurrent());
- assertEquals(4, dependentProvider.get().id);
- assertEquals(4, generator.getCurrent());
- }
- }
-
- static class PostConstructBaseBean {
- final int baseConstructorParameterA;
- final int baseConstructorParameterB;
- @Inject
- int baseInjectedField;
- int basePostConstructValue;
- int baseInjectedParameterA;
- int baseInjectedParameterB;
- @Inject
- IdGenerator idGenerator;
-
- @Inject
- PostConstructBaseBean(int baseConstructorParameterA, int baseConstructorParameterB) {
- this.baseConstructorParameterA = baseConstructorParameterA;
- this.baseConstructorParameterB = baseConstructorParameterB;
- }
-
- @PostConstruct
- void setupBase() {
- basePostConstructValue = idGenerator.nextId();
- }
-
- @Inject
- void setValues(int e, int f) {
- this.baseInjectedParameterA = e;
- this.baseInjectedParameterB = f;
- }
- }
-
- static class PostConstructBean extends PostConstructBaseBean {
- final int implConstructorParameter;
- int implPostConstructValue;
- int implInjectedParameter;
- @Inject
- int implInjectedField;
-
- @Inject
- PostConstructBean(final int a, final int b, final int implConstructorParameter) {
- super(a, b);
- this.implConstructorParameter = implConstructorParameter;
- }
-
- @PostConstruct
- void setupBean() {
- implPostConstructValue = idGenerator.nextId();
- }
-
- @Inject
- void setImplInjectedParameter(int implInjectedParameter) {
- this.implInjectedParameter = implInjectedParameter;
- }
- }
-
- @Test
- void postConstructInheritanceOrdering() {
- beanManager.loadAndValidateBeans(IdGenerator.class, PostConstructBean.class);
- final Bean<PostConstructBean> bean = beanManager.getDefaultBean(PostConstructBean.class).orElseThrow();
- try (final var context = beanManager.createInitializationContext(null)) {
- final PostConstructBean value = beanManager.getValue(bean, context);
- int[] values = {
- value.baseConstructorParameterA,
- value.baseConstructorParameterB,
- value.implConstructorParameter,
- value.implInjectedField,
- value.baseInjectedField,
- value.implInjectedParameter,
- value.baseInjectedParameterA,
- value.baseInjectedParameterB,
- value.basePostConstructValue,
- value.implPostConstructValue
- };
- assertAll(IntStream.range(0, values.length).mapToObj(i -> () -> assertEquals(i + 1, values[i])));
- }
- }
-
- static class PreDestroyBaseBean {
- @Inject
- IdGenerator idGenerator;
- int baseValue;
-
- @PreDestroy
- void basePreDestroy() {
- baseValue = idGenerator.nextId();
- }
- }
-
- static class PreDestroyIntermediateBean extends PreDestroyBaseBean {
- int intermediateValue;
-
- @PreDestroy
- void intermediatePreDestroy() {
- intermediateValue = idGenerator.nextId();
- }
- }
-
- static class PreDestroyImplBean extends PreDestroyIntermediateBean {
- int value;
-
- @PreDestroy
- void tearDown() {
- value = idGenerator.nextId();
- }
- }
-
- @Test
- void preDestroyInheritanceOrdering() {
- beanManager.loadAndValidateBeans(IdGenerator.class, PreDestroyImplBean.class);
- final Bean<PreDestroyImplBean> bean = beanManager.getDefaultBean(PreDestroyImplBean.class).orElseThrow();
- final PreDestroyImplBean value;
- try (final var context = beanManager.createInitializationContext(bean)) {
- value = beanManager.getValue(bean, context);
- assertAll(
- () -> assertEquals(0, value.value),
- () -> assertEquals(0, value.intermediateValue),
- () -> assertEquals(0, value.baseValue)
- );
- }
- assertAll(
- () -> assertEquals(1, value.value),
- () -> assertEquals(2, value.intermediateValue),
- () -> assertEquals(3, value.baseValue)
- );
- }
-
- // TODO: add tests for other supported injection scenarios
- // TODO: add tests for hierarchical scopes
- // TODO: add tests for @Disposes
- // TODO: add tests for injecting more specific types than the available ones
-}
diff --git a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/spi/InjectionPointTest.java b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/spi/InjectionPointTest.java
deleted file mode 100644
index fa87f9a..0000000
--- a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/spi/InjectionPointTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import org.apache.logging.log4j.plugins.spi.impl.DefaultBeanManager;
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Named;
-import org.apache.logging.log4j.plugins.SingletonScoped;
-import org.apache.logging.log4j.util.Strings;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Test;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import static org.junit.jupiter.api.Assertions.assertAll;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class InjectionPointTest {
-
- @SingletonScoped
- static class SingletonInstance {
- }
-
- static class FieldBean {
- @Inject
- static SingletonInstance instance;
-
- @Inject
- SingletonInstance singletonInstance;
- }
-
- static class GenericBean<T> {
- @Inject
- SingletonInstance instance;
-
- @Inject
- T value;
- }
-
- static class ConstructedBean {
- private final String alpha;
- private final String beta;
- private final String gamma;
-
- ConstructedBean(@Named final String alpha, @Named final String beta, @Named final String gamma) {
- this.alpha = alpha;
- this.beta = beta;
- this.gamma = gamma;
- }
- }
-
- static class MethodBean {
- private SingletonInstance instance;
-
- @Inject
- public void setInstance(final SingletonInstance instance) {
- this.instance = instance;
- }
- }
-
- private final BeanManager beanManager = new DefaultBeanManager();
-
- @AfterEach
- void tearDown() {
- beanManager.close();
- }
-
- @Test
- void fieldInjectionPoints() throws Exception {
- final Field staticField = FieldBean.class.getDeclaredField("instance");
- final InjectionPoint staticInjectionPoint = beanManager.createFieldInjectionPoint(staticField, null);
- final Field instanceField = FieldBean.class.getDeclaredField("singletonInstance");
- final InjectionPoint instanceInjectionPoint = beanManager.createFieldInjectionPoint(instanceField, null);
- assertAll(
- () -> assertEquals(Strings.EMPTY, staticInjectionPoint.getName()),
- () -> assertEquals(SingletonInstance.class, staticInjectionPoint.getType()),
- () -> assertEquals(staticField, staticInjectionPoint.getElement()),
- () -> assertEquals(staticField, staticInjectionPoint.getMember()),
- () -> assertTrue(staticInjectionPoint.getBean().isEmpty()),
- () -> assertEquals(Strings.EMPTY, instanceInjectionPoint.getName()),
- () -> assertEquals(SingletonInstance.class, instanceInjectionPoint.getType()),
- () -> assertEquals(instanceField, instanceInjectionPoint.getElement()),
- () -> assertEquals(instanceField, instanceInjectionPoint.getMember()),
- () -> assertTrue(instanceInjectionPoint.getBean().isEmpty())
- );
- }
-
- @Test
- void constructorInjectionPoints() throws Exception {
- final Constructor<ConstructedBean> constructor = ConstructedBean.class.getDeclaredConstructor(String.class, String.class, String.class);
- final Collection<InjectionPoint> injectionPoints = beanManager.createExecutableInjectionPoints(constructor, null);
- final List<InjectionPoint> sorted = injectionPoints.stream()
- .sorted(Comparator.comparing(InjectionPoint::getName))
- .collect(Collectors.toList());
- assertEquals(3, sorted.size());
- final InjectionPoint alpha = sorted.get(0);
- final InjectionPoint beta = sorted.get(1);
- final InjectionPoint gamma = sorted.get(2);
- assertAll(
- () -> assertEquals("alpha", alpha.getName()),
- () -> assertEquals("beta", beta.getName()),
- () -> assertEquals("gamma", gamma.getName())
- );
- }
-
- @Test
- void methodInjectionPoints() throws Exception {
- final Method method = MethodBean.class.getDeclaredMethod("setInstance", SingletonInstance.class);
- final Collection<InjectionPoint> points = beanManager.createExecutableInjectionPoints(method, null);
- assertEquals(1, points.size());
- final InjectionPoint injectionPoint = points.iterator().next();
- assertEquals(Strings.EMPTY, injectionPoint.getName());
- }
-}
diff --git a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/spi/InjectionTargetTest.java b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/spi/InjectionTargetTest.java
deleted file mode 100644
index e9989f4..0000000
--- a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/spi/InjectionTargetTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Named;
-import org.apache.logging.log4j.plugins.Produces;
-import org.apache.logging.log4j.plugins.SingletonScoped;
-import org.apache.logging.log4j.plugins.spi.impl.DefaultBeanManager;
-import org.junit.jupiter.api.Test;
-
-import java.util.Optional;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-class InjectionTargetTest {
-
- @SingletonScoped
- static class SingletonBean {
- }
-
- @Produces
- @Named
- @SingletonScoped
- static SingletonBean foo() {
- return new SingletonBean();
- }
-
- static class InjectedSingletonBeans {
- private final SingletonBean foo;
- private SingletonBean bar;
- private SingletonBean bean;
-
- @Inject
- InjectedSingletonBeans(@Named final SingletonBean foo) {
- this.foo = foo;
- }
-
- @Inject
- void setBar(final SingletonBean bar) {
- this.bar = bar;
- }
-
- @Inject
- void setBean(@Named("foo") final SingletonBean bean) {
- this.bean = bean;
- }
- }
-
- @Test
- void singletonBeans() {
- final BeanManager beanManager = new DefaultBeanManager();
- beanManager.loadAndValidateBeans(SingletonBean.class, getClass(), InjectedSingletonBeans.class);
- final Optional<Bean<InjectedSingletonBeans>> bean = beanManager.getDefaultBean(InjectedSingletonBeans.class);
- assertTrue(bean.isPresent());
- try (InitializationContext<InjectedSingletonBeans> context = beanManager.createInitializationContext(null)) {
- final InjectedSingletonBeans beans = beanManager.getValue(bean.orElseThrow(), context);
- assertNotNull(beans);
- assertNotNull(beans.foo);
- assertNotNull(beans.bar);
- assertNotSame(beans.foo, beans.bar);
- assertSame(beans.foo, beans.bean);
- }
- }
-
- @Named("empty")
- static class EmptyBean {
- }
-
- static class DependentBeans {
- private final EmptyBean first;
- private final EmptyBean second;
-
- DependentBeans(@Named("empty") final EmptyBean first, @Named("empty") final EmptyBean second) {
- this.first = first;
- this.second = second;
- }
- }
-
- @Test
- void dependentBeans() {
- final BeanManager beanManager = new DefaultBeanManager();
- beanManager.loadAndValidateBeans(DependentBeans.class, EmptyBean.class);
- final Optional<Bean<DependentBeans>> bean = beanManager.getDefaultBean(DependentBeans.class);
- try (InitializationContext<DependentBeans> context = beanManager.createInitializationContext(null)) {
- final DependentBeans beans = beanManager.getValue(bean.orElseThrow(), context);
- assertNotNull(beans);
- assertNotSame(beans.first, beans.second);
- }
- }
-}
diff --git a/log4j-plugins/src/main/java/module-info.java b/log4j-plugins/src/main/java/module-info.java
index 62fe441..885fd2c 100644
--- a/log4j-plugins/src/main/java/module-info.java
+++ b/log4j-plugins/src/main/java/module-info.java
@@ -17,9 +17,6 @@
module org.apache.logging.log4j.plugins {
exports org.apache.logging.log4j.plugins;
exports org.apache.logging.log4j.plugins.convert;
- exports org.apache.logging.log4j.plugins.di;
- exports org.apache.logging.log4j.plugins.di.model;
- exports org.apache.logging.log4j.plugins.spi;
exports org.apache.logging.log4j.plugins.processor;
exports org.apache.logging.log4j.plugins.util;
exports org.apache.logging.log4j.plugins.validation;
@@ -33,9 +30,5 @@ module org.apache.logging.log4j.plugins {
requires static org.osgi.framework;
uses org.apache.logging.log4j.plugins.processor.PluginService;
- uses org.apache.logging.log4j.plugins.di.model.PluginModule;
- uses org.apache.logging.log4j.plugins.spi.BeanManager;
- provides org.apache.logging.log4j.plugins.spi.BeanManager with
- org.apache.logging.log4j.plugins.spi.impl.DefaultBeanManager;
}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/DependentScoped.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/DependentScoped.java
deleted file mode 100644
index 6758fe4..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/DependentScoped.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Dependent scoped beans are beans that belong to another bean. Beans with this scope are created and destroyed in
- * participation of the lifecycle of the owning bean. That is, when a bean is destroyed, any of its dependent objects
- * are destroyed; dependent beans injected into a {@linkplain Disposes disposer method} are destroyed after the method
- * is finished executing; dependent beans created to {@linkplain Produces produce} or {@linkplain Disposes dispose}
- * a bean are destroyed after the producer or disposer is finished executing; and any other dependent beans no longer
- * directly referenced by the application may be destroyed.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD})
-@Documented
-@Inherited
-@ScopeType
-public @interface DependentScoped {
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Disposes.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Disposes.java
deleted file mode 100644
index ee3855e..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Disposes.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Marks a parameter of a method to be used for disposing a {@linkplain Produces produced instance}. A disposer method
- * more generally is a non-abstract method in a bean class with one argument annotated with {@code @Disposes} to indicate
- * the injection point for the produced bean for disposal along with any other normal injectable parameters if desired.
- * A bean can have more than one disposer method, but each disposer method can only dispose of one produced type.
- * Disposer methods can be static or non-static. Disposer methods are <em>not inherited</em> by subclasses.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.PARAMETER)
-@Documented
-public @interface Disposes {
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Inject.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Inject.java
index 83eb16f..fa65586 100644
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Inject.java
+++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Inject.java
@@ -17,8 +17,6 @@
package org.apache.logging.log4j.plugins;
-import org.apache.logging.log4j.plugins.di.Provider;
-
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -44,7 +42,6 @@ import java.lang.annotation.Target;
* is ignored (e.g., for builder method chaining).
*
* @see Named
- * @see Provider
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.FIELD})
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PostConstruct.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PostConstruct.java
deleted file mode 100644
index edccc9d..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PostConstruct.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Marks a method as a post construct callback. These methods are invoked after dependency injection is complete but
- * before the injection target instance is returned. Post construct callbacks are invoked superclass-first.
- *
- * @see PreDestroy
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-@Documented
-public @interface PostConstruct {
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PreDestroy.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PreDestroy.java
deleted file mode 100644
index 9d3d19a..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PreDestroy.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Marks a method as a pre destroy callback. These methods are invoked before an instance is destroyed. These are
- * invoked subclass-first.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-@Documented
-public @interface PreDestroy {
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Produces.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Produces.java
deleted file mode 100644
index 171e020..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Produces.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Marks a method or field as a producer for bean instances. Producer methods are essentially bean factories, while
- * producer fields are bean factories that only depend on its containing bean state. This annotation works similarly
- * to the {@code @Produces} annotation in CDI or the {@code @Bean} annotation in Spring.
- * There are a few rules related to producers:
- *
- * <ul>
- * <li>Producer methods must be non-abstract methods of a bean class (static or not).</li>
- * <li>Producer fields must be from a bean class.</li>
- * <li>If the bean class's scope is different from the produced bean, then it must be a larger scope.</li>
- * <li>If producer methods return a nullable value, then it must be {@link DependentScoped}.</li>
- * <li>Producer method return type and producer field type must not be a type variable.</li>
- * <li>Producer method return type and producer field type may be parameterized only if it specifies actual types
- * or a type variable for each parameter, the latter case also required to be {@link DependentScoped}.</li>
- * <li>Beans may declare multiple producer methods and fields.</li>
- * <li>Producers are <em>not inherited</em> by subclasses.</li>
- * </ul>
- *
- * @see Disposes
- * @see <a href="https://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/Produces.html">CDI @Produces API Docs</a>
- * @see <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/Bean.html">Spring @Bean API Docs</a>
- */
-@Target({ElementType.METHOD, ElementType.FIELD})
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Producer
-public @interface Produces {
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Provider.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Provider.java
deleted file mode 100644
index 18b71dc..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Provider.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.di;
-
-public interface Provider<T> {
- T get();
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/DisposesMethod.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/DisposesMethod.java
deleted file mode 100644
index 2dbfca1..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/DisposesMethod.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.di.model;
-
-import org.apache.logging.log4j.plugins.util.PluginUtil;
-import org.apache.logging.log4j.plugins.util.Value;
-
-import java.util.Set;
-
-public class DisposesMethod implements PluginSource {
- private final Value<Class<?>> disposesType;
- private final Value<Class<?>> declaringClass;
-
- public DisposesMethod(
- final ClassLoader classLoader, final String declaringClassName, final String disposesTypeName) {
- disposesType = PluginUtil.lazyLoadClass(classLoader, disposesTypeName);
- declaringClass = PluginUtil.lazyLoadClass(classLoader, declaringClassName);
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- return declaringClass.get();
- }
-
- public Class<?> getDisposesType() {
- return disposesType.get();
- }
-
- @Override
- public Set<Class<?>> getImplementedInterfaces() {
- return Set.of();
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/GenericPlugin.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/GenericPlugin.java
deleted file mode 100644
index 27b95a0..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/GenericPlugin.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.di.model;
-
-import org.apache.logging.log4j.plugins.util.PluginUtil;
-import org.apache.logging.log4j.plugins.util.Value;
-
-import java.util.Set;
-
-public class GenericPlugin implements PluginSource {
- private final Value<Class<?>> declaringClass;
- private final Set<Class<?>> implementedInterfaces;
-
- public GenericPlugin(
- final ClassLoader classLoader, final String declaringClassName, final Set<Class<?>> implementedInterfaces) {
- declaringClass = PluginUtil.lazyLoadClass(classLoader, declaringClassName);
- this.implementedInterfaces = implementedInterfaces;
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- return declaringClass.get();
- }
-
- @Override
- public Set<Class<?>> getImplementedInterfaces() {
- return implementedInterfaces;
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/InjectionTarget.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/InjectionTarget.java
deleted file mode 100644
index 20b76ba..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/InjectionTarget.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.di.model;
-
-import org.apache.logging.log4j.plugins.util.PluginUtil;
-import org.apache.logging.log4j.plugins.util.Value;
-
-import java.util.Set;
-
-public class InjectionTarget implements PluginSource {
- private final Value<Class<?>> declaringClass;
- private final Set<Class<?>> implementedInterfaces;
-
- public InjectionTarget(
- final ClassLoader classLoader, final String className, final Set<Class<?>> implementedInterfaces) {
- declaringClass = PluginUtil.lazyLoadClass(classLoader, className);
- this.implementedInterfaces = implementedInterfaces;
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- return declaringClass.get();
- }
-
- @Override
- public Set<Class<?>> getImplementedInterfaces() {
- return implementedInterfaces;
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/PluginModule.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/PluginModule.java
deleted file mode 100644
index acbce13..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/PluginModule.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.di.model;
-
-import java.util.List;
-
-public interface PluginModule {
- List<PluginSource> getPluginSources();
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/PluginSource.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/PluginSource.java
deleted file mode 100644
index dd7325e..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/PluginSource.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.di.model;
-
-import java.util.Set;
-
-public interface PluginSource {
- Class<?> getDeclaringClass();
-
- Set<Class<?>> getImplementedInterfaces();
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/ProducerField.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/ProducerField.java
deleted file mode 100644
index 58f3d22..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/ProducerField.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.di.model;
-
-import org.apache.logging.log4j.plugins.util.PluginUtil;
-import org.apache.logging.log4j.plugins.util.Value;
-
-import java.util.Set;
-
-public class ProducerField implements PluginSource {
- private final Value<Class<?>> declaringClass;
- private final String fieldName;
- private final Set<Class<?>> implementedInterfaces;
-
- public ProducerField(
- final ClassLoader classLoader, final String declaringClassName, final String fieldName,
- final Set<Class<?>> implementedInterfaces) {
- declaringClass = PluginUtil.lazyLoadClass(classLoader, declaringClassName);
- this.fieldName = fieldName;
- this.implementedInterfaces = implementedInterfaces;
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- return declaringClass.get();
- }
-
- public String getFieldName() {
- return fieldName;
- }
-
- @Override
- public Set<Class<?>> getImplementedInterfaces() {
- return implementedInterfaces;
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/ProducerMethod.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/ProducerMethod.java
deleted file mode 100644
index 5d253f5..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/model/ProducerMethod.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.di.model;
-
-import org.apache.logging.log4j.plugins.util.PluginUtil;
-import org.apache.logging.log4j.plugins.util.Value;
-
-import java.util.Set;
-
-public class ProducerMethod implements PluginSource {
- private final Value<Class<?>> declaringClass;
- private final Value<Class<?>> returnType;
- private final String methodName;
- private final Set<Class<?>> implementedInterfaces;
-
- public ProducerMethod(
- final ClassLoader classLoader, final String declaringClassName, final String returnTypeClassName,
- final String methodName, final Set<Class<?>> implementedInterfaces) {
- declaringClass = PluginUtil.lazyLoadClass(classLoader, declaringClassName);
- returnType = PluginUtil.lazyLoadClass(classLoader, returnTypeClassName);
- this.methodName = methodName;
- this.implementedInterfaces = implementedInterfaces;
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- return declaringClass.get();
- }
-
- public Class<?> getReturnType() {
- return returnType.get();
- }
-
- public String getMethodName() {
- return methodName;
- }
-
- @Override
- public Set<Class<?>> getImplementedInterfaces() {
- return implementedInterfaces;
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/package-info.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/package-info.java
deleted file mode 100644
index 2e075fe..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/package-info.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-/**
- * Plugin scopes and dependency injection APIs. These annotations and interfaces form the public API used by plugins
- * to declare necessary dependencies of a class along with any produced objects and other lifecycle callbacks to
- * participate in the Log4j plugin system.
- *
- * @since 3.0
- */
-package org.apache.logging.log4j.plugins.di;
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/AmbiguousBeanException.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/AmbiguousBeanException.java
deleted file mode 100644
index 5d830fa..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/AmbiguousBeanException.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import java.util.Collection;
-
-public class AmbiguousBeanException extends ResolutionException {
- public AmbiguousBeanException(final Collection<? extends Bean<?>> beans, final String target) {
- super("Found " + beans.size() + " ambiguous beans for " + target + ": " + beans);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/Bean.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/Bean.java
deleted file mode 100644
index c8d511c..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/Bean.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import org.apache.logging.log4j.plugins.DependentScoped;
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Produces;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collection;
-
-/**
- * Provides lifecycle and dependency injection functionality to managed classes. A bean represents an injectable class
- * via {@link Inject} or a producer field or method via
- * {@link Produces} along with their annotation aliases. A bean has a
- * {@linkplain #getName() name} which can be the empty string to indicate a default bean. Beans provide a
- * {@linkplain #getTypes() type closure} of matching generic types to allow for injecting more complex types. The
- * {@linkplain #getScopeType() scope} of a bean controls the lifecycle of instances
- * {@linkplain #create(InitializationContext) created} and {@linkplain #destroy(Object, InitializationContext) destroyed}
- * by this bean. Dependencies are injected based on metadata exposed through
- * {@linkplain #getInjectionPoints() injection points}.
- *
- * @param <T> type of instance being managed by this bean
- */
-public interface Bean<T> {
-
- /**
- * Returns the name of this bean or an empty string to indicate a default bean.
- */
- String getName();
-
- /**
- * Returns the type closure of this bean.
- */
- Collection<Type> getTypes();
-
- default boolean hasMatchingType(final Type requiredType) {
- for (final Type type : getTypes()) {
- if (TypeUtil.typesMatch(requiredType, type)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Returns the declaring class that creates this bean. For injectable classes, this returns that class. For producing
- * methods and fields, this returns their declaring class.
- */
- Class<?> getDeclaringClass();
-
- /**
- * Returns the scope type of this bean.
- */
- Class<? extends Annotation> getScopeType();
-
- default boolean isDependentScoped() {
- return getScopeType() == DependentScoped.class;
- }
-
- /**
- * Creates a new instance of this bean. The given {@link InitializationContext} should be used by implementations
- * to track dependent objects.
- *
- * @param context the context in which the instance is being managed
- * @return a managed, initialized instance
- */
- T create(final InitializationContext<T> context);
-
- /**
- * Destroys a managed instance in the given context. Implementations should call {@link InitializationContext#close()} to
- * allow dependent objects to be destroyed.
- *
- * @param instance the managed instance to destroy
- * @param context the context in which the instance is being managed
- */
- void destroy(final T instance, final InitializationContext<T> context);
-
- /**
- * Returns the collection of injection points to inject dependencies when constructing instances of this bean.
- */
- Collection<InjectionPoint> getInjectionPoints();
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/BeanManager.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/BeanManager.java
deleted file mode 100644
index c3c6798..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/BeanManager.java
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Producer;
-import org.apache.logging.log4j.plugins.Qualifier;
-import org.apache.logging.log4j.plugins.di.model.PluginSource;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-import org.apache.logging.log4j.plugins.util.AnnotationUtil;
-import org.apache.logging.log4j.util.Strings;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Executable;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
-import java.util.ServiceLoader;
-
-/**
- * Central SPI for injecting and managing beans and their instances.
- */
-public interface BeanManager extends AutoCloseable {
-
- /**
- * Gets the configured BeanManager service for loading and unloading beans.
- */
- static BeanManager getInstance() {
- return ServiceLoader.load(BeanManager.class, BeanManager.class.getClassLoader())
- .findFirst()
- .orElseThrow(() -> new InitializationException("No BeanManager service available"));
- }
-
- /**
- * Loads beans from the given classes. This looks for injectable classes and producers in the provided classes,
- * loads them into this manager, and returns the loaded beans.
- *
- * @param beanClasses classes to load beans from
- * @return beans loaded from the given classes
- */
- Collection<Bean<?>> loadBeans(final Collection<Class<?>> beanClasses);
-
- /**
- * Scans the classpath in a given package for beans and loads bean metadata from discovered classes.
- *
- * @param classLoader ClassLoader to use for loading classes from package or null to use the default context ClassLoader
- * @param packageName package name to begin search for beans inside
- * @return beans loaded from the given package
- */
- Collection<Bean<?>> scanAndLoadBeans(final ClassLoader classLoader, final String packageName);
-
- /**
- * Loads beans from the given {@link PluginSource} instances. PluginSources are generated by the plugins annotation
- * processor to help avoid classpath scanning at runtime.
- *
- * @param pluginSources collection of PluginSource instances to load bean metadata from
- * @return beans loaded from the given sources
- */
- Collection<Bean<?>> loadBeansFromPluginSources(final Collection<PluginSource> pluginSources);
-
- /**
- * Creates a bean for an injectable bean class.
- */
- <T> Bean<T> createBean(final Class<T> beanClass);
-
- /**
- * Creates a bean for a producer field.
- *
- * @param producerField field to obtain bean instance from
- * @param owner owning bean for instance field or null for a static field
- * @return newly created bean
- */
- Bean<?> createBean(final Field producerField, final Bean<?> owner);
-
- /**
- * Creates a bean for a producer method.
- *
- * @param producerMethod method to obtain bean instance from
- * @param owner owning bean for instance method or null for a static method
- * @return newly created bean
- */
- Bean<?> createBean(final Method producerMethod, final Bean<?> owner);
-
- /**
- * Loads beans from the given classes. This looks for injectable classes and producers, registers them in this
- * manager, validates them, then returns the validated beans.
- *
- * @param beanClasses classes to load beans from
- * @throws ValidationException if any beans have validation errors
- */
- default void loadAndValidateBeans(final Class<?>... beanClasses) {
- final Collection<Bean<?>> beans = loadBeans(List.of(beanClasses));
- validateBeans(beans);
- }
-
- /**
- * Validates beans and throws a {@link ValidationException} if there are any errors.
- *
- * @param beans beans to check for validation errors
- * @throws ValidationException if any beans have validation errors
- */
- void validateBeans(final Iterable<Bean<?>> beans);
-
- /**
- * Validates the given injection point.
- *
- * @param point injection point to validate
- * @throws DefinitionException if the injection point is improperly defined
- * @throws UnsatisfiedBeanException if no beans can satisfy the injection point
- */
- void validateInjectionPoint(InjectionPoint point);
-
- /**
- * Checks if a class has exactly one injectable constructor. A constructor is <i>injectable</i> if:
- * <ol>
- * <li>it is annotated with {@link Inject}; or</li>
- * <li>it has as least one parameter annotated with a {@linkplain Qualifier qualifier annotation}; or</li>
- * <li>it is the lone no-arg constructor.</li>
- * </ol>
- *
- * @param type class to find an injectable constructor in
- * @return true if the class has exactly one injectable constructor or false otherwise
- */
- default boolean isInjectable(final Class<?> type) {
- boolean result = false;
- int injectConstructors = 0;
- final Constructor<?>[] constructors = type.getDeclaredConstructors();
- for (final Constructor<?> constructor : constructors) {
- if (constructor.isAnnotationPresent(Inject.class)) {
- injectConstructors++;
- }
- }
- if (injectConstructors <= 1) {
- if (injectConstructors == 1) {
- result = true;
- } else {
- int implicitConstructors = 0;
- for (final Constructor<?> constructor : constructors) {
- for (final Parameter parameter : constructor.getParameters()) {
- if (AnnotatedElementNameProvider.hasName(parameter)) {
- implicitConstructors++;
- break;
- }
- }
- }
- if (implicitConstructors <= 1) {
- if (implicitConstructors == 1) {
- result = true;
- } else {
- try {
- type.getDeclaredConstructor();
- result = true;
- } catch (final NoSuchMethodException ignored) {
- }
- }
- }
- }
- }
-
- return result;
- }
-
- /**
- * Checks if an element is injectable. An element is <i>injectable</i> if:
- * <ol>
- * <li>it is annotated with {@link Inject}; or</li>
- * <li>it is annotated with a {@linkplain Qualifier qualifier annotation}
- * and is not annotated with a {@link Producer} annotation.</li>
- * </ol>
- *
- * @param element field, method, or parameter to check
- * @return true if the element is injectable or false otherwise
- */
- default boolean isInjectable(final AnnotatedElement element) {
- if (element.isAnnotationPresent(Inject.class)) {
- return true;
- }
- if (AnnotationUtil.isMetaAnnotationPresent(element, Producer.class)) {
- return false;
- }
- return AnnotatedElementNameProvider.hasName(element);
- }
-
- default <T> Optional<Bean<T>> getDefaultBean(final Class<T> beanType) {
- return getNamedBean(beanType, Strings.EMPTY);
- }
-
- default <T> Optional<Bean<T>> getNamedBean(final Class<T> beanType, final String name) {
- return getBean(beanType, name, List.of());
- }
-
- <T> Optional<Bean<T>> getBean(Type type, final String name, Collection<String> aliases);
-
- /**
- * Creates an injection point for a field with an optional owning bean.
- *
- * @param field field where injection will take place
- * @param owner bean where field is located or null for static fields
- * @return an injection point describing the field
- */
- InjectionPoint createFieldInjectionPoint(final Field field, final Bean<?> owner);
-
- /**
- * Creates an injection point for a method or constructor parameter with an optional owning bean.
- *
- * @param executable method or constructor where injection will take place
- * @param parameter which parameter of that executable to create a point at
- * @param owner bean where executable is located or null for static methods
- * @return an injection point describing the parameter
- */
- InjectionPoint createParameterInjectionPoint(final Executable executable, final Parameter parameter, final Bean<?> owner);
-
- /**
- * Creates a collection of injection points for all the parameters of a method or constructor with an optional
- * owning bean.
- *
- * @param executable method or constructor where injection will take place
- * @param owner bean where executable is located or null for static methods
- * @return collection of injection points describing the executable parameters
- */
- default Collection<InjectionPoint> createExecutableInjectionPoints(final Executable executable, final Bean<?> owner) {
- final Parameter[] parameters = executable.getParameters();
- final Collection<InjectionPoint> points = new ArrayList<>(parameters.length);
- for (final Parameter parameter : parameters) {
- points.add(createParameterInjectionPoint(executable, parameter, owner));
- }
- return points;
- }
-
- /**
- * Creates an InitializationContext for a given Bean instance for use in dependency injection SPIs.
- *
- * @param bean bean to create an initialization context for (may be null to bootstrap a dependency graph)
- * @param <T> type of object created by bean
- * @return new InitializationContext for the given Bean
- */
- <T> InitializationContext<T> createInitializationContext(final Bean<T> bean);
-
- /**
- * Gets or creates the value for a given bean inside a given InitializationContext.
- *
- * @param bean bean to get or create value for
- * @param parentContext which context this bean is being used in
- * @param <T> type of value
- * @return value of the bean in the given context
- */
- <T> T getValue(final Bean<T> bean, final InitializationContext<?> parentContext);
-
- /**
- * Gets the value to use for injecting into a given InjectionPoint in a given InitializationContext.
- *
- * @param point location where injectable value would be injected
- * @param parentContext which context this value is being injected under
- * @param <T> type of injectable value
- * @return value to inject if defined or empty otherwise
- */
- <T> Optional<T> getInjectableValue(final InjectionPoint point, final InitializationContext<?> parentContext);
-
- /**
- * Destroys all the beans managed by this instance.
- */
- @Override
- void close();
-
- // TODO: API to register ScopeContexts
- // TODO: Configuration APIs
- // TODO: integrate with constraint validators
- // TODO: integrate with TypeConverters
- // TODO: need some sort of default value strategy to bridge over @PluginAttribute and optional injected values
- // TODO: add support for injecting collections and arrays
- // TODO: begin integrating with singleton beans in log4j-core
- // TODO: LoggerContext scope (sort of like a singleton/application scope with each LoggerContext)
- // TODO: configuration scope? should be similar to LoggerContext scope but can be restarted/reconfigured at runtime
- // TODO: update annotation processor to output bean descriptors for lazy loading (attempt to provide partial type closures?)
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/DefinitionException.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/DefinitionException.java
deleted file mode 100644
index 3376a92..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/DefinitionException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-public class DefinitionException extends InjectionException {
- public DefinitionException(final String message) {
- super(message);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/IllegalProductException.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/IllegalProductException.java
deleted file mode 100644
index 5a12068..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/IllegalProductException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-public class IllegalProductException extends InjectionException {
- public IllegalProductException(final String message) {
- super(message);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InitializationContext.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InitializationContext.java
deleted file mode 100644
index ff1c785..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InitializationContext.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import java.util.Optional;
-
-/**
- * Provides operations used by {@link Bean} implementations for tracking lifecycle state.
- */
-public interface InitializationContext<T> extends AutoCloseable {
- /**
- * Pushes an incomplete instance state. An instance is not completely initialized until it is returned from
- * {@link Bean#create(InitializationContext)}.
- *
- * @param incompleteInstance incompletely initialized instance
- */
- void addIncompleteInstance(final T incompleteInstance);
-
- // TODO: this API is needlessly complicated currently
- boolean isTrackingDependencies(final Bean<T> bean);
-
- void addDependentInstance(T dependentInstance);
-
- Optional<Bean<?>> getNonDependentScopedDependent();
-
- <S> Optional<S> getIncompleteInstance(Bean<S> bean);
-
- // dependent contexts share the same incomplete instances
- <D> InitializationContext<D> createDependentContext(Bean<D> bean);
-
- // independent contexts are used by producers to get their declaring bean separately
- <P> InitializationContext<P> createProducerContext(Bean<P> bean);
-
- /**
- * Destroys all dependent objects by propagating them to {@link Bean#destroy(Object, InitializationContext)}.
- */
- @Override
- void close();
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InitializationException.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InitializationException.java
deleted file mode 100644
index 8c11613..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InitializationException.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-public class InitializationException extends InjectionException {
- public InitializationException(final String message) {
- super(message);
- }
-
- public InitializationException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionException.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionException.java
deleted file mode 100644
index 1b7475f..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionException.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-public class InjectionException extends RuntimeException {
- protected InjectionException(final String message) {
- super(message);
- }
-
- protected InjectionException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionPoint.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionPoint.java
deleted file mode 100644
index 0b25cef..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionPoint.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Member;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Optional;
-
-/**
- * Represents metadata about an element in a program where a value should be injected.
- */
-public interface InjectionPoint {
-
- /**
- * Gets the generic type information of this point.
- */
- Type getType();
-
- String getName();
-
- Collection<String> getAliases();
-
- /**
- * Gets the bean where this injection point is defined or empty for static methods and fields.
- */
- Optional<Bean<?>> getBean();
-
- /**
- * Gets the field, method, or constructor where injection takes place.
- */
- Member getMember();
-
- /**
- * Gets the program element corresponding to this injection point.
- */
- AnnotatedElement getElement();
-
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionTarget.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionTarget.java
deleted file mode 100644
index bd2c82f..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionTarget.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.PostConstruct;
-import org.apache.logging.log4j.plugins.PreDestroy;
-
-/**
- * Provides lifecycle and dependency injection operations for instances of a specified type.
- *
- * @param <T> type of instance managed by this injection target
- */
-public interface InjectionTarget<T> extends Producer<T> {
-
- /**
- * Performs dependency injection on the provided instance in the given initialization context. This sets the values
- * of injected fields and calls initializer methods (i.e., fields and methods annotated with {@link Inject}).
- *
- * @param instance instance upon which to perform dependency injection
- * @param context initialization context to perform injection in
- */
- void inject(final T instance, final InitializationContext<T> context);
-
- /**
- * Invokes the {@link PostConstruct} methods of the provided instance.
- * Post construct methods are invoked starting with the highest level method and continue down the type hierarchy.
- *
- * @param instance instance upon which to invoke post construct methods
- */
- void postConstruct(final T instance);
-
- /**
- * Invokes the {@link PreDestroy} methods of the provided instance.
- * Pre destroy methods are invoked starting with the lowest level method and continue up the type hierarchy.
- *
- * @param instance instance upone which to invoke pre destroy methods
- */
- void preDestroy(final T instance);
-
- /**
- * Does nothing. This method only applies to producers.
- */
- @Override
- default void dispose(T instance) {
- // @Disposes only applies to @Produces methods and fields
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionTargetFactory.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionTargetFactory.java
deleted file mode 100644
index fbd12cf..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/InjectionTargetFactory.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-public interface InjectionTargetFactory<T> {
- InjectionTarget<T> createInjectionTarget(final Bean<T> bean);
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/LoggerContextScoped.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/LoggerContextScoped.java
deleted file mode 100644
index fb2f35b..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/LoggerContextScoped.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import org.apache.logging.log4j.plugins.ScopeType;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD})
-@Documented
-@Inherited
-@ScopeType
-public @interface LoggerContextScoped {
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/Producer.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/Producer.java
deleted file mode 100644
index fa7986f..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/Producer.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import org.apache.logging.log4j.plugins.Disposes;
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Produces;
-
-import java.util.Collection;
-
-/**
- * Provides lifecycle operations for producing instances of a specified type. Producers represent three different ways
- * to manage instances: injectable classes, producer methods, and producer fields.
- *
- * @param <T> type of instance managed by this producer
- * @see Inject
- * @see Produces
- */
-public interface Producer<T> {
-
- /**
- * Creates an instance in the given initialization context. When this represents a class, this calls the
- * constructor annotated with {@link Inject} or the default constructor.
- * When this represents a producer method, this invokes the producer method. When this represents a producer
- * field, this obtains the value of the field.
- *
- * @param context initialization context to use to create the instance
- * @return produced instance
- * @see Produces
- */
- T produce(InitializationContext<T> context);
-
- /**
- * Destroys the provided instance. When this represents a class, this does nothing. When this represents a
- * producer method or field, then this invokes the corresponding disposer method.
- *
- * @param instance instance to dispose
- * @see Disposes
- */
- void dispose(T instance);
-
- /**
- * Returns all the injection points of this producer. For a class, this returns all injected fields, bean
- * constructor parameters, and initialization method parameters. For a producer method, this returns the
- * parameters to that method.
- *
- * @return all injection points for this producer
- * @see Inject
- * @see Produces
- */
- Collection<InjectionPoint> getInjectionPoints();
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ProducerFactory.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ProducerFactory.java
deleted file mode 100644
index e31d478..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ProducerFactory.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-public interface ProducerFactory {
- // only time bean is null is static @Produces potentially?
- <T> Producer<T> createProducer(final Bean<T> bean);
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ResolutionException.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ResolutionException.java
deleted file mode 100644
index 1158d23..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ResolutionException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-public class ResolutionException extends InjectionException {
- public ResolutionException(final String message) {
- super(message);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ScopeContext.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ScopeContext.java
deleted file mode 100644
index 29b23e9..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ScopeContext.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import org.apache.logging.log4j.plugins.ScopeType;
-
-import java.lang.annotation.Annotation;
-import java.util.Optional;
-
-/**
- * Manages {@link Bean} instances within a particular {@linkplain ScopeType scope}.
- */
-public interface ScopeContext extends AutoCloseable {
-
- /**
- * Returns the {@linkplain ScopeType scope type} of this context.
- */
- Class<? extends Annotation> getScopeType();
-
- /**
- * Gets or {@linkplain Bean#create(InitializationContext) creates} a bean instance of a specific type.
- *
- * @param bean the bean to get or create an instance of
- * @param context the context to create a new instance in
- * @param <T> the instance type being managed
- * @return the new or existing instance
- */
- <T> T getOrCreate(final Bean<T> bean, final InitializationContext<T> context);
-
- /**
- * Returns an existing bean instance if it exists.
- *
- * @param bean the bean to look up an existing instance of
- * @param <T> the instance type being managed
- * @return the existing instance or empty
- */
- <T> Optional<T> getIfExists(final Bean<T> bean);
-
- /**
- * Destroys the existing bean instance of a specified type if it exists or otherwise does nothing.
- *
- * @param bean the managed type
- */
- void destroy(final Bean<?> bean);
-
- @Override
- void close();
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/UnsatisfiedBeanException.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/UnsatisfiedBeanException.java
deleted file mode 100644
index 3f12fa7..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/UnsatisfiedBeanException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import java.lang.reflect.Type;
-
-public class UnsatisfiedBeanException extends ResolutionException {
- public UnsatisfiedBeanException(final InjectionPoint point) {
- super("No beans found for " + point);
- }
-
- public UnsatisfiedBeanException(final Type type) {
- super("No beans found for type " + type);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ValidationException.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ValidationException.java
deleted file mode 100644
index 29321d1..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/ValidationException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi;
-
-import java.util.Collection;
-
-public class ValidationException extends InjectionException {
- public static ValidationException fromValidationErrors(final Collection<Throwable> validationErrors) {
- final StringBuilder sb = new StringBuilder();
- sb.append("Found ").append(validationErrors.size()).append(" error(s) in bean deployment. Errors:");
- validationErrors.forEach(error -> sb.append("\n • ").append(error.getMessage()));
- final String message = sb.toString();
- final ValidationException exception = new ValidationException(message);
- validationErrors.forEach(exception::addSuppressed);
- return exception;
- }
-
- private ValidationException(final String message) {
- super(message);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/AbstractBean.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/AbstractBean.java
deleted file mode 100644
index f8fed3c..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/AbstractBean.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Objects;
-
-abstract class AbstractBean<T> implements Bean<T> {
- private final Collection<Type> types;
- private final String name;
- private final Class<? extends Annotation> scopeType;
- private final Class<?> declaringClass;
-
- AbstractBean(final Collection<Type> types, final String name, final Class<? extends Annotation> scopeType,
- final Class<?> declaringClass) {
- this.types = types;
- this.name = name;
- this.scopeType = scopeType;
- this.declaringClass = declaringClass;
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- return declaringClass;
- }
-
- @Override
- public Collection<Type> getTypes() {
- return types;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Class<? extends Annotation> getScopeType() {
- return scopeType;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- final AbstractBean<?> that = (AbstractBean<?>) o;
- return types.equals(that.types) && name.equals(that.name) && scopeType.equals(that.scopeType) &&
- declaringClass.equals(that.declaringClass);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(types, name, scopeType, declaringClass);
- }
-
- abstract boolean isTrackingDependencies();
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/AbstractProducer.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/AbstractProducer.java
deleted file mode 100644
index 320dd5e..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/AbstractProducer.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.BeanManager;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.spi.Producer;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Objects;
-
-abstract class AbstractProducer<P, T> implements Producer<T> {
- private final BeanManager beanManager;
- private final Bean<P> producerBean;
- private final Method disposerMethod;
- private final Collection<InjectionPoint> disposerInjectionPoints;
- final Injector injector;
-
- AbstractProducer(final BeanManager beanManager, final Bean<P> producerBean, final Method disposerMethod,
- final Collection<InjectionPoint> disposerInjectionPoints) {
- this.beanManager = beanManager;
- this.producerBean = producerBean;
- this.disposerMethod = disposerMethod;
- this.disposerInjectionPoints = Objects.requireNonNull(disposerInjectionPoints);
- this.injector = new Injector(beanManager);
- }
-
- // context is managed separately as the declaring instance is only used for producing the object and is not a dependent of the bean
- InitializationContext<P> createContext() {
- return beanManager.createInitializationContext(producerBean);
- }
-
- P getProducerInstance(final InitializationContext<P> context) {
- return context.getIncompleteInstance(producerBean).orElseGet(() ->
- beanManager.getValue(producerBean, context.createProducerContext(producerBean)));
- }
-
- abstract Type getType();
-
- boolean hasDisposerMethod() {
- return disposerMethod != null;
- }
-
- @Override
- public void dispose(final T instance) {
- if (hasDisposerMethod()) {
- // as producer and disposer bean is unrelated to this bean, we need to recreate it on demand
- try (final InitializationContext<P> context = createContext()) {
- final P declaringInstance = Modifier.isStatic(disposerMethod.getModifiers()) ? null : getProducerInstance(context);
- injector.dispose(declaringInstance, disposerMethod, disposerInjectionPoints, instance, context);
- }
- }
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/AbstractProducerFactory.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/AbstractProducerFactory.java
deleted file mode 100644
index 8ac279c..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/AbstractProducerFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.spi.ProducerFactory;
-
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Objects;
-
-abstract class AbstractProducerFactory implements ProducerFactory {
- final Bean<?> declaringBean;
- final Member producerMember;
- final Method disposerMethod;
- final Collection<InjectionPoint> disposerInjectionPoints;
-
- AbstractProducerFactory(final Bean<?> declaringBean, final Member producerMember, final Method disposerMethod,
- final Collection<InjectionPoint> disposerInjectionPoints) {
- this.declaringBean = declaringBean;
- this.producerMember = Objects.requireNonNull(producerMember);
- this.disposerMethod = disposerMethod;
- this.disposerInjectionPoints = Objects.requireNonNull(disposerInjectionPoints);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultBeanManager.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultBeanManager.java
deleted file mode 100644
index 6420817..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultBeanManager.java
+++ /dev/null
@@ -1,548 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.DependentScoped;
-import org.apache.logging.log4j.plugins.Disposes;
-import org.apache.logging.log4j.plugins.Producer;
-import org.apache.logging.log4j.plugins.di.Provider;
-import org.apache.logging.log4j.plugins.ScopeType;
-import org.apache.logging.log4j.plugins.SingletonScoped;
-import org.apache.logging.log4j.plugins.di.model.PluginSource;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementAliasesProvider;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-import org.apache.logging.log4j.plugins.spi.AmbiguousBeanException;
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.BeanManager;
-import org.apache.logging.log4j.plugins.spi.DefinitionException;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InjectionException;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.spi.InjectionTargetFactory;
-import org.apache.logging.log4j.plugins.spi.ProducerFactory;
-import org.apache.logging.log4j.plugins.spi.ResolutionException;
-import org.apache.logging.log4j.plugins.spi.ScopeContext;
-import org.apache.logging.log4j.plugins.spi.UnsatisfiedBeanException;
-import org.apache.logging.log4j.plugins.spi.ValidationException;
-import org.apache.logging.log4j.plugins.util.AnnotationUtil;
-import org.apache.logging.log4j.plugins.util.LazyValue;
-import org.apache.logging.log4j.plugins.util.ResolverUtil;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-import org.apache.logging.log4j.util.Strings;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Executable;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-public class DefaultBeanManager implements BeanManager {
-
- private final Injector injector = new Injector(this);
-
- private final Collection<Bean<?>> enabledBeans = ConcurrentHashMap.newKeySet();
- private final Map<Type, Collection<Bean<?>>> beansByType = new ConcurrentHashMap<>();
- private final Collection<DisposesMethod> disposesMethods = new ArrayList<>();
- private final Map<Class<? extends Annotation>, ScopeContext> scopes = new LinkedHashMap<>();
-
- public DefaultBeanManager() {
- // TODO: need a better way to register scope contexts
- // TODO: need ThreadLocalScopeContext for LoggerContext (~ContextSelector) and ConfigurationContext scopes
- // (can potentially modify LoggerContext[Factory] to set these thread local values on construction et al.
- scopes.put(DependentScoped.class, new DependentScopeContext());
- scopes.put(SingletonScoped.class, new DefaultScopeContext(SingletonScoped.class));
- }
-
- @Override
- public Collection<Bean<?>> loadBeans(final Collection<Class<?>> beanClasses) {
- if (beanClasses.isEmpty()) {
- return Set.of();
- }
- final Collection<Bean<?>> loadedBeans = new LinkedHashSet<>();
- for (final Class<?> beanClass : beanClasses) {
- final Bean<?> bean = isInjectable(beanClass) ? createBean(beanClass) : null;
- loadDisposerMethods(beanClass, bean);
- for (Class<?> clazz = beanClass; clazz != null; clazz = clazz.getSuperclass()) {
- for (final Method method : clazz.getDeclaredMethods()) {
- if (AnnotationUtil.isMetaAnnotationPresent(method, Producer.class)) {
- method.setAccessible(true);
- loadedBeans.add(createBean(method, bean));
- }
- }
- }
- for (Class<?> clazz = beanClass; clazz != null; clazz = clazz.getSuperclass()) {
- for (final Field field : clazz.getDeclaredFields()) {
- if (AnnotationUtil.isMetaAnnotationPresent(field, Producer.class)) {
- field.setAccessible(true);
- loadedBeans.add(createBean(field, bean));
- }
- }
- }
- if (bean != null) {
- loadedBeans.add(bean);
- }
- }
- return loadedBeans;
- }
-
- @Override
- public Collection<Bean<?>> scanAndLoadBeans(final ClassLoader classLoader, final String packageName) {
- if (Strings.isBlank(packageName)) {
- return Set.of();
- }
- final ResolverUtil resolver = new ResolverUtil();
- if (classLoader != null) {
- resolver.setClassLoader(classLoader);
- }
- resolver.findInPackage(new BeanTest(this::isInjectable), packageName);
- return loadBeans(resolver.getClasses());
- }
-
- @Override
- public Collection<Bean<?>> loadBeansFromPluginSources(final Collection<PluginSource> pluginSources) {
- if (pluginSources.isEmpty()) {
- return Set.of();
- }
- // TODO: enhance PluginSource metadata to support lazy loading of classes in respective beans for implemented interfaces
- final Set<Class<?>> beanClasses = pluginSources.stream()
- .map(PluginSource::getDeclaringClass)
- .filter(Objects::nonNull)
- .collect(Collectors.toSet());
- return loadBeans(beanClasses);
- }
-
- @Override
- public <T> Bean<T> createBean(final Class<T> beanClass) {
- final Collection<Type> types = TypeUtil.getTypeClosure(beanClass);
- final String name = AnnotatedElementNameProvider.getName(beanClass);
- final Class<? extends Annotation> scopeType = getScopeType(beanClass);
- final InjectionTargetFactory<T> factory =
- new DefaultInjectionTargetFactory<>(this, injector, beanClass);
- return addBean(new InjectionTargetBean<>(types, name, scopeType, beanClass, factory));
- }
-
- @Override
- public Bean<?> createBean(final Field producerField, final Bean<?> owner) {
- final Collection<Type> types = TypeUtil.getTypeClosure(producerField.getGenericType());
- final String name = AnnotatedElementNameProvider.getName(producerField);
- final Method disposerMethod = resolveDisposerMethod(types, name, owner);
- final Collection<InjectionPoint> disposerIPs =
- disposerMethod == null ? Set.of() : createExecutableInjectionPoints(disposerMethod, owner);
- final ProducerFactory factory =
- new FieldProducerFactory(this, owner, producerField, disposerMethod, disposerIPs);
- return addBean(new ProducerBean<>(types, name, getScopeType(producerField), producerField.getDeclaringClass(), factory));
- }
-
- @Override
- public Bean<?> createBean(final Method producerMethod, final Bean<?> owner) {
- final Collection<Type> types = TypeUtil.getTypeClosure(producerMethod.getGenericReturnType());
- final String name = AnnotatedElementNameProvider.getName(producerMethod);
- final Method disposerMethod = resolveDisposerMethod(types, name, owner);
- final Collection<InjectionPoint> disposerIPs =
- disposerMethod == null ? Collections.emptySet() : createExecutableInjectionPoints(disposerMethod, owner);
- final Collection<InjectionPoint> producerIPs = createExecutableInjectionPoints(producerMethod, owner);
- final ProducerFactory factory =
- new MethodProducerFactory(this, owner, producerMethod, producerIPs, disposerMethod, disposerIPs);
- return addBean(new ProducerBean<>(types, name, getScopeType(producerMethod), producerMethod.getDeclaringClass(), factory));
- }
-
- private <T> Bean<T> addBean(final Bean<T> bean) {
- if (enabledBeans.add(bean)) {
- addBeanTypes(bean);
- }
- return bean;
- }
-
- private void addBeanTypes(final Bean<?> bean) {
- for (final Type type : bean.getTypes()) {
- addBeanType(bean, type);
- if (type instanceof ParameterizedType) {
- final Type rawType = ((ParameterizedType) type).getRawType();
- addBeanType(bean, rawType);
- } else if (type instanceof Class<?>) {
- final Class<?> clazz = (Class<?>) type;
- if (clazz.isPrimitive()) {
- addBeanType(bean, TypeUtil.getReferenceType(clazz));
- }
- }
- }
- }
-
- private void addBeanType(final Bean<?> bean, final Type type) {
- beansByType.computeIfAbsent(type, ignored -> ConcurrentHashMap.newKeySet()).add(bean);
- }
-
- private void loadDisposerMethods(final Class<?> beanClass, final Bean<?> bean) {
- for (final Method method : beanClass.getMethods()) {
- for (final Parameter parameter : method.getParameters()) {
- if (parameter.isAnnotationPresent(Disposes.class)) {
- final String name = AnnotatedElementNameProvider.getName(parameter);
- final Collection<String> aliases = AnnotatedElementAliasesProvider.getAliases(parameter);
- disposesMethods.add(new DisposesMethod(parameter.getParameterizedType(), name, aliases, bean, method));
- }
- }
- }
- }
-
- private Method resolveDisposerMethod(final Collection<Type> types, final String name, final Bean<?> disposingBean) {
- final List<Method> methods = disposesMethods.stream()
- .filter(method -> method.matches(types, name, disposingBean))
- .map(method -> method.disposesMethod)
- .collect(Collectors.toList());
- if (methods.isEmpty()) {
- return null;
- }
- if (methods.size() == 1) {
- return methods.get(0);
- }
- throw new ResolutionException("Ambiguous @Disposes methods for matching types " + types + " and name '" + name + "': " + methods);
- }
-
- @Override
- public void validateBeans(final Iterable<Bean<?>> beans) {
- final List<Throwable> errors = new ArrayList<>();
- for (final Bean<?> bean : beans) {
- for (final InjectionPoint point : bean.getInjectionPoints()) {
- try {
- validateInjectionPoint(point);
- } catch (final InjectionException e) {
- errors.add(e);
- }
- }
- }
- if (!errors.isEmpty()) {
- throw ValidationException.fromValidationErrors(errors);
- }
- }
-
- @Override
- public void validateInjectionPoint(final InjectionPoint point) {
- final AnnotatedElement element = point.getElement();
- if (AnnotationUtil.isMetaAnnotationPresent(element, Producer.class)) {
- throw new DefinitionException("Cannot inject into a @Produces element: " + element);
- }
- final Type type = point.getType();
- if (type instanceof TypeVariable<?>) {
- throw new DefinitionException("Cannot inject into a TypeVariable: " + point);
- }
- final Class<?> rawType = TypeUtil.getRawType(type);
- if (rawType.equals(InjectionPoint.class)) {
- final Bean<?> bean = point.getBean()
- .orElseThrow(() -> new DefinitionException("Cannot inject " + point + " into a non-bean"));
- if (!bean.isDependentScoped()) {
- throw new DefinitionException("Injection points can only be @DependentScoped scoped; got: " + point);
- }
- }
- if (rawType.equals(Bean.class)) {
- final Bean<?> bean = point.getBean().orElseThrow(() -> new UnsatisfiedBeanException(point));
- if (bean instanceof InjectionTargetBean<?>) {
- validateBeanInjectionPoint(point, bean.getDeclaringClass());
- } else if (bean instanceof ProducerBean<?>) {
- validateBeanInjectionPoint(point, ((ProducerBean<?>) bean).getType());
- }
- }
- final Optional<Bean<Object>> bean = getBean(point.getType(), point.getName(), point.getAliases());
- if (bean.isEmpty() && !rawType.equals(Optional.class)) {
- throw new UnsatisfiedBeanException(point);
- }
- }
-
- private void validateBeanInjectionPoint(final InjectionPoint point, final Type expectedType) {
- final Type type = point.getType();
- if (!(type instanceof ParameterizedType)) {
- throw new DefinitionException("Expected parameterized type for " + point + " but got " + expectedType);
- }
- final ParameterizedType parameterizedType = (ParameterizedType) type;
- final Type[] typeArguments = parameterizedType.getActualTypeArguments();
- if (typeArguments.length != 1) {
- throw new DefinitionException("Expected one type parameter argument for " + point + " but got " +
- Arrays.toString(typeArguments));
- }
- final Type typeArgument = typeArguments[0];
- if (!typeArgument.equals(expectedType)) {
- throw new DefinitionException("Expected type " + expectedType + " but got " + typeArgument + " in " + point);
- }
- }
-
- @Override
- public <T> Optional<Bean<T>> getBean(final Type type, final String name, final Collection<String> aliases) {
- // TODO: this will need to allow for TypeConverter usage somehow
- // first, look for an existing bean
- final Optional<Bean<T>> existingBean = getExistingOrProvidedBean(type, name, aliases);
- if (existingBean.isPresent()) {
- return existingBean;
- }
- if (type instanceof ParameterizedType) {
- final Class<?> rawType = TypeUtil.getRawType(type);
- if (rawType == Provider.class) {
- final Type actualType = ((ParameterizedType) type).getActualTypeArguments()[0];
- // if a Provider<T> is requested, we can convert an existing Bean<T> into a Bean<Provider<T>>
- final Optional<Bean<T>> actualExistingBean = getExistingBean(actualType, name, aliases);
- return actualExistingBean.map(bean -> new ProviderBean<>(type, bean, context -> () -> getValue(bean, context)))
- .map(this::addBean)
- .map(TypeUtil::cast);
- } else if (rawType == Optional.class) {
- final Type actualType = ((ParameterizedType) type).getActualTypeArguments()[0];
- // fake T like in Provider above
- final Bean<Optional<T>> optionalBean = addBean(new OptionalBean<>(type, name,
- LazyValue.forSupplier(() -> getExistingOrProvidedBean(actualType, name, aliases)),
- this::getValue));
- return Optional.of(optionalBean).map(TypeUtil::cast);
- }
- }
- return Optional.empty();
- }
-
- private <T> Optional<Bean<T>> getExistingOrProvidedBean(final Type type, final String name, final Collection<String> aliases) {
- final Optional<Bean<T>> existingBean = getExistingBean(type, name, aliases);
- if (existingBean.isPresent()) {
- return existingBean;
- }
- return getProvidedBean(type, name, aliases);
- }
-
- private <T> Optional<Bean<T>> getExistingBean(final Type type, final String name, final Collection<String> aliases) {
- final Set<Bean<T>> beans = this.<T>beansWithType(type)
- .filter(bean -> name.equalsIgnoreCase(bean.getName()) || aliases.stream().anyMatch(bean.getName()::equalsIgnoreCase))
- .collect(Collectors.toSet());
- if (beans.size() > 1) {
- throw new AmbiguousBeanException(beans, "type " + type + ", name '" + name + "', and aliases " + aliases);
- }
- return beans.isEmpty() ? Optional.empty() : Optional.of(beans.iterator().next());
- }
-
- private <T> Optional<Bean<T>> getProvidedBean(final Type providedType, final String name, final Collection<String> aliases) {
- // TODO: need a way to get @Plugin(name) for builder class (potential alias?)
- final Optional<Bean<Provider<T>>> existingBean =
- getExistingBean(TypeUtil.getParameterizedType(Provider.class, providedType), name, aliases);
- final Optional<Bean<T>> providedBean = existingBean.map(bean ->
- new ProvidedBean<>(providedType, bean, context -> getValue(bean, context)));
- return providedBean.map(this::addBean);
- }
-
- private <T> Stream<Bean<T>> beansWithType(final Type requiredType) {
- if (beansByType.containsKey(requiredType)) {
- return beansByType.get(requiredType).stream().map(TypeUtil::cast);
- }
- if (requiredType instanceof ParameterizedType) {
- return beansByType.getOrDefault(((ParameterizedType) requiredType).getRawType(), Collections.emptySet())
- .stream()
- .filter(bean -> bean.hasMatchingType(requiredType))
- .map(TypeUtil::cast);
- }
- return Stream.empty();
- }
-
- @Override
- public InjectionPoint createFieldInjectionPoint(final Field field, final Bean<?> owner) {
- Objects.requireNonNull(field);
- return DefaultInjectionPoint.forField(field, owner);
- }
-
- @Override
- public InjectionPoint createParameterInjectionPoint(final Executable executable, final Parameter parameter, final Bean<?> owner) {
- Objects.requireNonNull(executable);
- Objects.requireNonNull(parameter);
- return DefaultInjectionPoint.forParameter(executable, parameter, owner);
- }
-
- private Class<? extends Annotation> getScopeType(final AnnotatedElement element) {
- for (final Annotation annotation : element.getAnnotations()) {
- final Class<? extends Annotation> annotationType = annotation.annotationType();
- if (annotationType.isAnnotationPresent(ScopeType.class)) {
- return annotationType;
- }
- }
- if (element instanceof Field) {
- return getScopeType(((Field) element).getType());
- }
- if (element instanceof Method) {
- return getScopeType(((Method) element).getReturnType());
- }
- return DependentScoped.class;
- }
-
- @Override
- public <T> InitializationContext<T> createInitializationContext(final Bean<T> bean) {
- return new DefaultInitializationContext<>(bean);
- }
-
- @Override
- public <T> T getValue(final Bean<T> bean, final InitializationContext<?> parentContext) {
- Objects.requireNonNull(bean);
- Objects.requireNonNull(parentContext);
- final ScopeContext context = getScopeContext(bean.getScopeType());
- return context.getOrCreate(bean, parentContext.createDependentContext(bean));
- }
-
- private ScopeContext getScopeContext(final Class<? extends Annotation> scopeType) {
- final ScopeContext scopeContext = scopes.get(scopeType);
- if (scopeContext == null) {
- throw new ResolutionException("No active scope context found for scope @" + scopeType.getName());
- }
- return scopeContext;
- }
-
- @Override
- public <T> Optional<T> getInjectableValue(final InjectionPoint point, final InitializationContext<?> parentContext) {
- final Bean<T> resolvedBean = this.<T>getBean(point.getType(), point.getName(), point.getAliases())
- .orElseThrow(() -> new UnsatisfiedBeanException(point));
- final Optional<T> existingValue = point.getBean()
- .filter(bean -> !bean.equals(resolvedBean))
- .flatMap(bean -> getExistingValue(resolvedBean, bean, parentContext));
- if (existingValue.isPresent()) {
- return existingValue;
- }
- final InitializationContext<?> context =
- resolvedBean.isDependentScoped() ? parentContext : createInitializationContext(resolvedBean);
- return Optional.of(getValue(resolvedBean, context));
- }
-
- private <T> Optional<T> getExistingValue(final Bean<T> resolvedBean, final Bean<?> pointBean,
- final InitializationContext<?> parentContext) {
- if (!pointBean.isDependentScoped() || parentContext.getNonDependentScopedDependent().isPresent()) {
- final Optional<T> incompleteInstance = parentContext.getIncompleteInstance(resolvedBean);
- if (incompleteInstance.isPresent()) {
- return incompleteInstance;
- }
- return getScopeContext(resolvedBean.getScopeType()).getIfExists(resolvedBean);
- } else {
- return Optional.empty();
- }
- }
-
- @Override
- public void close() {
- beansByType.clear();
- enabledBeans.clear();
- disposesMethods.clear();
- final List<Class<? extends Annotation>> scopeTypes = new ArrayList<>(scopes.keySet());
- Collections.reverse(scopeTypes);
- for (final Class<? extends Annotation> scopeType : scopeTypes) {
- scopes.get(scopeType).close();
- }
- }
-
- private static class BeanTest implements ResolverUtil.Test {
- private final Predicate<Class<?>> isBeanClass;
-
- private BeanTest(final Predicate<Class<?>> isBeanClass) {
- this.isBeanClass = isBeanClass;
- }
-
- @Override
- public boolean matches(final Class<?> type) {
- if (isBeanClass.test(type)) {
- return true;
- }
- for (final Annotation annotation : type.getAnnotations()) {
- final String name = annotation.annotationType().getName();
- if (name.startsWith("org.apache.logging.log4j.") && name.endsWith(".plugins.Plugin")) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean matches(final URI resource) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean doesMatchClass() {
- return true;
- }
-
- @Override
- public boolean doesMatchResource() {
- return false;
- }
- }
-
- private static class DisposesMethod {
- private final Type type;
- private final String name;
- private final Collection<String> aliases;
- private final Bean<?> declaringBean;
- private final Method disposesMethod;
-
- private DisposesMethod(final Type type, final String name, final Collection<String> aliases,
- final Bean<?> declaringBean, final Method disposesMethod) {
- this.type = type;
- this.name = name;
- this.aliases = aliases;
- this.declaringBean = declaringBean;
- this.disposesMethod = disposesMethod;
- }
-
- boolean matches(final Collection<Type> types, final String name, final Bean<?> declaringBean) {
- return Objects.equals(declaringBean, this.declaringBean) && matchesName(name) && matchesType(types);
- }
-
- private boolean matchesType(final Collection<Type> types) {
- for (final Type t : types) {
- if (TypeUtil.typesMatch(type, t)) {
- return true;
- }
- }
- return false;
- }
-
- private boolean matchesName(final String name) {
- return this.name.equalsIgnoreCase(name) || aliases.stream().anyMatch(name::equalsIgnoreCase);
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o)
- return true;
- if (o == null || getClass() != o.getClass())
- return false;
- final DisposesMethod that = (DisposesMethod) o;
- return type.equals(that.type) && name.equals(that.name) && aliases.equals(that.aliases) && Objects.equals(
- declaringBean, that.declaringBean) && disposesMethod.equals(that.disposesMethod);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(type, name, aliases, declaringBean, disposesMethod);
- }
- }
-
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInitializationContext.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInitializationContext.java
deleted file mode 100644
index 9130140..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInitializationContext.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-import org.apache.logging.log4j.plugins.util.Value;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-public class DefaultInitializationContext<T> implements InitializationContext<T> {
-
- private final Bean<T> bean;
- private Map<Bean<?>, Object> incompleteInstances;
- private final List<DependentInstance<?>> dependentInstances = new CopyOnWriteArrayList<>();
- private final List<DependentInstance<?>> parentDependentInstances;
- private final InitializationContext<?> parentContext;
-
- public DefaultInitializationContext(final Bean<T> bean) {
- this(bean, null, new CopyOnWriteArrayList<>(), null);
- }
-
- private DefaultInitializationContext(final Bean<T> bean, final Map<Bean<?>, Object> incompleteInstances) {
- this(bean, incompleteInstances, new CopyOnWriteArrayList<>(), null);
- }
-
- private DefaultInitializationContext(final Bean<T> bean, final Map<Bean<?>, Object> incompleteInstances,
- final List<DependentInstance<?>> parentDependentInstances,
- final InitializationContext<?> parentContext) {
-
- this.bean = bean;
- this.incompleteInstances = incompleteInstances;
- this.parentDependentInstances = parentDependentInstances;
- this.parentContext = parentContext;
- }
-
- @Override
- public void addIncompleteInstance(final T incompleteInstance) {
- if (incompleteInstances == null) {
- incompleteInstances = new ConcurrentHashMap<>();
- }
- if (bean != null) {
- incompleteInstances.put(bean, incompleteInstance);
- }
- }
-
- @Override
- public boolean isTrackingDependencies(final Bean<T> bean) {
- return !dependentInstances.isEmpty() ||
- (bean instanceof AbstractBean<?> && ((AbstractBean<?>) bean).isTrackingDependencies());
- }
-
- @Override
- public void addDependentInstance(final T dependentInstance) {
- parentDependentInstances.add(new DependentInstance<>(bean, this, dependentInstance));
- }
-
- @Override
- public Optional<Bean<?>> getNonDependentScopedDependent() {
- if (parentContext == null || bean == null) {
- return Optional.empty();
- }
- return bean.isDependentScoped() ? parentContext.getNonDependentScopedDependent() : Optional.of(bean);
- }
-
- @Override
- public <S> InitializationContext<S> createDependentContext(final Bean<S> bean) {
- return new DefaultInitializationContext<>(bean, incompleteInstances, dependentInstances, this);
- }
-
- @Override
- public <S> InitializationContext<S> createProducerContext(final Bean<S> bean) {
- return new DefaultInitializationContext<>(bean, incompleteInstances == null ? null : new ConcurrentHashMap<>(incompleteInstances));
- }
-
- @Override
- public <S> Optional<S> getIncompleteInstance(final Bean<S> bean) {
- return Optional.ofNullable(incompleteInstances)
- .map(map -> map.get(bean))
- .map(TypeUtil::cast);
- }
-
- @Override
- public void close() {
- for (final DependentInstance<?> dependentInstance : dependentInstances) {
- if (dependentInstance.bean.equals(bean)) {
- dependentInstance.close();
- }
- }
- }
-
- private static class DependentInstance<T> implements Value<T> {
- private final Bean<T> bean;
- private final InitializationContext<T> context;
- private final T instance;
-
- private DependentInstance(final Bean<T> bean, final InitializationContext<T> context, final T instance) {
- this.bean = bean;
- this.context = context;
- this.instance = instance;
- }
-
- @Override
- public T get() {
- return instance;
- }
-
- @Override
- public void close() {
- bean.destroy(instance, context);
- }
- }
-
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInjectionPoint.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInjectionPoint.java
deleted file mode 100644
index bfe75b3..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInjectionPoint.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementAliasesProvider;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Executable;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Parameter;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Objects;
-import java.util.Optional;
-
-class DefaultInjectionPoint implements InjectionPoint {
- static DefaultInjectionPoint forField(final Field field, final Bean<?> owner) {
- return new DefaultInjectionPoint(field.getGenericType(),
- AnnotatedElementNameProvider.getName(field),
- AnnotatedElementAliasesProvider.getAliases(field),
- owner, field, field);
- }
-
- static DefaultInjectionPoint forParameter(final Executable executable, final Parameter parameter, final Bean<?> owner) {
- return new DefaultInjectionPoint(parameter.getParameterizedType(),
- AnnotatedElementNameProvider.getName(parameter),
- AnnotatedElementAliasesProvider.getAliases(parameter),
- owner, executable, parameter);
- }
-
- private final Type type;
- private final String name;
- private final Collection<String> aliases;
- private final Bean<?> bean;
- private final Member member;
- private final AnnotatedElement element;
-
- private DefaultInjectionPoint(final Type type, final String name, final Collection<String> aliases,
- final Bean<?> bean, final Member member, final AnnotatedElement element) {
- this.type = type;
- this.name = name;
- this.aliases = aliases;
- this.bean = bean;
- this.member = member;
- this.element = element;
- }
-
- @Override
- public Type getType() {
- return type;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Collection<String> getAliases() {
- return aliases;
- }
-
- @Override
- public Optional<Bean<?>> getBean() {
- return Optional.ofNullable(bean);
- }
-
- @Override
- public Member getMember() {
- return member;
- }
-
- @Override
- public AnnotatedElement getElement() {
- return element;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- final DefaultInjectionPoint that = (DefaultInjectionPoint) o;
- return Objects.equals(bean, that.bean) && member.equals(that.member) && element.equals(that.element);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(bean, member, element);
- }
-
- @Override
- public String toString() {
- return "DefaultInjectionPoint{" +
- "type=" + type +
- ", name='" + name + '\'' +
- ", aliases=" + aliases +
- ", bean=" + bean +
- ", member=" + member +
- ", element=" + element +
- '}';
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInjectionTarget.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInjectionTarget.java
deleted file mode 100644
index 90303da..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInjectionTarget.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InitializationException;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.spi.InjectionTarget;
-import org.apache.logging.log4j.plugins.Disposes;
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.Producer;
-import org.apache.logging.log4j.plugins.util.AnnotationUtil;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-class DefaultInjectionTarget<T> implements InjectionTarget<T> {
- private final Injector injector;
- private final Class<T> metaClass;
- private final Collection<InjectionPoint> injectionPoints;
- private final Constructor<T> constructor;
- private final List<Method> postConstructMethods;
- private final List<Method> preDestroyMethods;
-
- DefaultInjectionTarget(final Injector injector, final Class<T> metaClass,
- final Collection<InjectionPoint> injectionPoints, final Constructor<T> constructor,
- final List<Method> postConstructMethods, final List<Method> preDestroyMethods) {
- this.injector = injector;
- this.metaClass = metaClass;
- this.injectionPoints = Objects.requireNonNull(injectionPoints);
- this.constructor = Objects.requireNonNull(constructor);
- this.postConstructMethods = Objects.requireNonNull(postConstructMethods);
- this.preDestroyMethods = Objects.requireNonNull(preDestroyMethods);
- }
-
- @Override
- public T produce(final InitializationContext<T> context) {
- final Set<InjectionPoint> constructorInjectionPoints = injectionPoints.stream()
- .filter(point -> constructor.equals(point.getMember()))
- .collect(Collectors.toSet());
- return injector.construct(constructor, constructorInjectionPoints, context);
- }
-
- @Override
- public void inject(final T instance, final InitializationContext<T> context) {
- injectFields(instance, context);
- injectMethods(instance, context);
- }
-
- private void injectFields(final T instance, final InitializationContext<T> context) {
- injectionPoints.stream()
- .filter(point -> point.getElement() instanceof Field)
- .forEachOrdered(point -> injector.set(instance, TypeUtil.cast(point.getElement()), point, context));
- }
-
- private void injectMethods(final T instance, final InitializationContext<T> context) {
- final Set<Method> injectedMethods = new HashSet<>();
- for (final InjectionPoint point : injectionPoints) {
- final Member member = point.getMember();
- final AnnotatedElement element = point.getElement();
- if (member instanceof Method && !injectedMethods.contains(member) &&
- !AnnotationUtil.isMetaAnnotationPresent(element, Producer.class) &&
- !element.isAnnotationPresent(Disposes.class)) {
- final Method method = TypeUtil.cast(member);
- final Set<InjectionPoint> methodInjectionPoints = injectionPoints.stream()
- .filter(p -> method.equals(p.getMember()))
- .collect(Collectors.toSet());
- injector.invoke(instance, method, methodInjectionPoints, context);
- injectedMethods.add(method);
- }
- }
- for (final Method method : metaClass.getMethods()) {
- if (method.isAnnotationPresent(Inject.class) && method.getParameterCount() == 0) {
- injector.invoke(instance, method, Collections.emptySet(), context);
- }
- }
- }
-
- @Override
- public void postConstruct(final T instance) {
- for (final Method method : postConstructMethods) {
- try {
- method.invoke(instance);
- } catch (IllegalAccessException | InvocationTargetException e) {
- throw new InitializationException("Error invoking post construct method " + method.getName(), e);
- }
- }
- }
-
- @Override
- public void preDestroy(final T instance) {
- for (final Method method : preDestroyMethods) {
- try {
- method.invoke(instance);
- } catch (IllegalAccessException | InvocationTargetException e) {
- throw new InitializationException("Error invoking pre destroy method " + method.getName(), e);
- }
- }
- }
-
- @Override
- public Collection<InjectionPoint> getInjectionPoints() {
- return injectionPoints;
- }
-
- boolean hasPreDestroyMethods() {
- return !preDestroyMethods.isEmpty();
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInjectionTargetFactory.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInjectionTargetFactory.java
deleted file mode 100644
index 33d0425..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultInjectionTargetFactory.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.BeanManager;
-import org.apache.logging.log4j.plugins.spi.DefinitionException;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.spi.InjectionTarget;
-import org.apache.logging.log4j.plugins.spi.InjectionTargetFactory;
-import org.apache.logging.log4j.plugins.Inject;
-import org.apache.logging.log4j.plugins.PostConstruct;
-import org.apache.logging.log4j.plugins.PreDestroy;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.stream.Collectors;
-
-class DefaultInjectionTargetFactory<T> implements InjectionTargetFactory<T> {
- private final BeanManager beanManager;
- private final Injector injector;
- private final Class<T> type;
-
- DefaultInjectionTargetFactory(final BeanManager beanManager, final Injector injector, final Class<T> type) {
- this.beanManager = beanManager;
- this.injector = injector;
- this.type = type;
- }
-
- @Override
- public InjectionTarget<T> createInjectionTarget(final Bean<T> bean) {
- final Constructor<T> constructor = getInjectableConstructor();
- final Collection<InjectionPoint> injectionPoints =
- new LinkedHashSet<>(beanManager.createExecutableInjectionPoints(constructor, bean));
- // TODO: if field is static, validate it's using an appropriate scope (singleton?)
- getInjectableFields().forEach(field -> injectionPoints.add(beanManager.createFieldInjectionPoint(field, bean)));
- getInjectableMethods().forEach(method -> injectionPoints.addAll(beanManager.createExecutableInjectionPoints(method, bean)));
- return new DefaultInjectionTarget<>(injector, type, injectionPoints, constructor,
- getPostConstructMethods(), getPreDestroyMethods());
- }
-
- private Constructor<T> getInjectableConstructor() {
- final Constructor<?>[] allConstructors = type.getDeclaredConstructors();
- final List<Constructor<?>> injectConstructors = Arrays.stream(allConstructors)
- .filter(constructor -> constructor.isAnnotationPresent(Inject.class))
- .collect(Collectors.toList());
- if (injectConstructors.size() > 1) {
- throw new DefinitionException("Found more than one constructor with @Inject for " + type);
- }
- if (injectConstructors.size() == 1) {
- final Constructor<?> constructor = injectConstructors.get(0);
- constructor.setAccessible(true);
- return TypeUtil.cast(constructor);
- }
- final List<Constructor<?>> injectParameterConstructors = Arrays.stream(allConstructors)
- .filter(constructor -> Arrays.stream(constructor.getParameters()).anyMatch(AnnotatedElementNameProvider::hasName))
- .collect(Collectors.toList());
- if (injectParameterConstructors.size() > 1) {
- throw new DefinitionException("No @Inject constructors found and remaining constructors ambiguous for " + type);
- }
- if (injectParameterConstructors.size() == 1) {
- final Constructor<?> constructor = injectParameterConstructors.get(0);
- constructor.setAccessible(true);
- return TypeUtil.cast(constructor);
- }
- if (allConstructors.length == 1) {
- final Constructor<?> constructor = allConstructors[0];
- if (constructor.getParameterCount() == 0) {
- constructor.setAccessible(true);
- return TypeUtil.cast(constructor);
- }
- }
- try {
- return type.getDeclaredConstructor();
- } catch (final NoSuchMethodException ignored) {
- throw new DefinitionException("No candidate constructors found for " + type);
- }
- }
-
- private List<Field> getInjectableFields() {
- final List<Field> injectableFields = new ArrayList<>();
- for (Class<?> clazz = type; clazz != null; clazz = clazz.getSuperclass()) {
- for (final Field field : clazz.getDeclaredFields()) {
- if (beanManager.isInjectable(field)) {
- injectableFields.add(field);
- }
- }
- }
- final Field[] fields = injectableFields.toArray(Field[]::new);
- AccessibleObject.setAccessible(fields, true);
- return List.of(fields);
- }
-
- private List<Method> getInjectableMethods() {
- final List<Method> injectableMethods = new ArrayList<>();
- for (Class<?> clazz = type; clazz != null; clazz = clazz.getSuperclass()) {
- for (final Method method : clazz.getDeclaredMethods()) {
- if (!Modifier.isStatic(method.getModifiers()) && beanManager.isInjectable(method)) {
- injectableMethods.add(method);
- }
- }
- }
- final Method[] methods = injectableMethods.toArray(Method[]::new);
- AccessibleObject.setAccessible(methods, true);
- return List.of(methods);
- }
-
- private List<Method> getPostConstructMethods() {
- final List<Method> postConstructMethods = new ArrayList<>();
- for (Class<?> clazz = type; clazz != null; clazz = clazz.getSuperclass()) {
- for (final Method method : clazz.getDeclaredMethods()) {
- if (method.isAnnotationPresent(PostConstruct.class)) {
- postConstructMethods.add(0, method);
- }
- }
- }
- final Method[] methods = postConstructMethods.toArray(Method[]::new);
- AccessibleObject.setAccessible(methods, true);
- return List.of(methods);
- }
-
- private List<Method> getPreDestroyMethods() {
- final List<Method> preDestroyMethods = new ArrayList<>();
- for (Class<?> clazz = type; clazz != null; clazz = clazz.getSuperclass()) {
- for (final Method method : clazz.getDeclaredMethods()) {
- if (method.isAnnotationPresent(PreDestroy.class)) {
- preDestroyMethods.add(method);
- }
- }
- }
- final Method[] methods = preDestroyMethods.toArray(Method[]::new);
- AccessibleObject.setAccessible(methods, true);
- return List.of(methods);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultScopeContext.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultScopeContext.java
deleted file mode 100644
index dc86b6e..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DefaultScopeContext.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.ScopeContext;
-import org.apache.logging.log4j.plugins.util.LazyValue;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-import org.apache.logging.log4j.plugins.util.Value;
-
-import java.lang.annotation.Annotation;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class DefaultScopeContext implements ScopeContext {
- private final Map<Bean<?>, Value<?>> beanValues = new ConcurrentHashMap<>();
- private final Class<? extends Annotation> scopeType;
-
- public DefaultScopeContext(final Class<? extends Annotation> scopeType) {
- this.scopeType = Objects.requireNonNull(scopeType);
- }
-
- @Override
- public Class<? extends Annotation> getScopeType() {
- return scopeType;
- }
-
- @Override
- public <T> T getOrCreate(final Bean<T> bean, final InitializationContext<T> context) {
- final Value<T> value = TypeUtil.cast(beanValues.computeIfAbsent(bean,
- ignored -> LazyValue.forScope(() -> bean.create(context), instance -> bean.destroy(instance, context))));
- return value.get();
- }
-
- @Override
- public <T> Optional<T> getIfExists(final Bean<T> bean) {
- return Optional.ofNullable(beanValues.get(bean))
- .map(Value::get)
- .map(TypeUtil::cast);
- }
-
- @Override
- public void destroy(final Bean<?> bean) {
- beanValues.computeIfPresent(bean, (ignored, value) -> {
- value.close();
- return null;
- });
- }
-
- @Override
- public void close() {
- beanValues.keySet().forEach(this::destroy);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DependentScopeContext.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DependentScopeContext.java
deleted file mode 100644
index a42b3dc..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/DependentScopeContext.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.ScopeContext;
-import org.apache.logging.log4j.plugins.DependentScoped;
-
-import java.lang.annotation.Annotation;
-import java.util.Optional;
-
-class DependentScopeContext implements ScopeContext {
- @Override
- public Class<? extends Annotation> getScopeType() {
- return DependentScoped.class;
- }
-
- @Override
- public <T> T getOrCreate(final Bean<T> bean, final InitializationContext<T> context) {
- if (context == null) {
- return null;
- }
- final T instance = bean.create(context);
- if (context.isTrackingDependencies(bean)) {
- context.addDependentInstance(instance);
- }
- return instance;
- }
-
- @Override
- public <T> Optional<T> getIfExists(final Bean<T> bean) {
- return Optional.empty();
- }
-
- @Override
- public void destroy(final Bean<?> bean) {
- }
-
- @Override
- public void close() {
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/FieldProducer.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/FieldProducer.java
deleted file mode 100644
index 7be73e5..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/FieldProducer.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.BeanManager;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Collections;
-
-class FieldProducer<P, T> extends AbstractProducer<P, T> {
- private final Field field;
-
- FieldProducer(final BeanManager beanManager, final Bean<P> producerBean, final Field field,
- final Method disposerMethod, final Collection<InjectionPoint> disposerInjectionPoints) {
- super(beanManager, producerBean, disposerMethod, disposerInjectionPoints);
- this.field = field;
- }
-
- @Override
- Type getType() {
- return field.getType();
- }
-
- @Override
- public T produce(final InitializationContext<T> context) {
- if (Modifier.isStatic(field.getModifiers())) {
- try {
- return TypeUtil.cast(field.get(null));
- } catch (IllegalAccessException e) {
- throw new IllegalStateException(e);
- }
- }
- try (final InitializationContext<P> parentContext = createContext()) {
- return TypeUtil.cast(field.get(getProducerInstance(parentContext)));
- } catch (IllegalAccessException e) {
- throw new IllegalStateException(e);
- }
- }
-
- @Override
- public Collection<InjectionPoint> getInjectionPoints() {
- return Collections.emptySet();
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/FieldProducerFactory.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/FieldProducerFactory.java
deleted file mode 100644
index e5ea704..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/FieldProducerFactory.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.BeanManager;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.spi.Producer;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Collection;
-
-class FieldProducerFactory extends AbstractProducerFactory {
- private final BeanManager beanManager;
-
- FieldProducerFactory(final BeanManager beanManager, final Bean<?> declaringBean,
- final Field producerField, final Method disposerMethod,
- final Collection<InjectionPoint> disposerInjectionPoints) {
- super(declaringBean, producerField, disposerMethod, disposerInjectionPoints);
- this.beanManager = beanManager;
- }
-
- @Override
- public <T> Producer<T> createProducer(final Bean<T> bean) {
- final Field field = (Field) producerMember;
- return new FieldProducer<>(beanManager, declaringBean, field, disposerMethod, disposerInjectionPoints);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/InjectionTargetBean.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/InjectionTargetBean.java
deleted file mode 100644
index 06ab925..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/InjectionTargetBean.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.IllegalProductException;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.spi.InjectionTarget;
-import org.apache.logging.log4j.plugins.spi.InjectionTargetFactory;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Objects;
-
-class InjectionTargetBean<T> extends AbstractBean<T> {
- private final InjectionTarget<T> injectionTarget;
-
- InjectionTargetBean(final Collection<Type> types, final String name, final Class<? extends Annotation> scopeType,
- final Class<T> declaringClass, final InjectionTargetFactory<T> factory) {
- super(types, name, scopeType, declaringClass);
- Objects.requireNonNull(factory);
- injectionTarget = factory.createInjectionTarget(this);
- }
-
- @Override
- public Collection<InjectionPoint> getInjectionPoints() {
- return injectionTarget.getInjectionPoints();
- }
-
- @Override
- public T create(final InitializationContext<T> context) {
- final T instance = injectionTarget.produce(context);
- if (instance == null) {
- throw new IllegalProductException("Injection target created null instance: " + injectionTarget);
- }
- injectionTarget.inject(instance, context);
- injectionTarget.postConstruct(instance);
- if (isDependentScoped()) {
- context.addIncompleteInstance(instance);
- }
- return instance;
- }
-
- @Override
- public void destroy(final T instance, final InitializationContext<T> context) {
- try (context) {
- if (isDependentScoped()) {
- injectionTarget.preDestroy(instance);
- }
- }
- }
-
- @Override
- public String toString() {
- return "InjectionTargetBean{" +
- "types=" + getTypes() +
- ", scope=@" + getScopeType().getSimpleName() +
- ", name=" + getName() +
- ", declaringClass=" + getDeclaringClass() +
- '}';
- }
-
- @Override
- boolean isTrackingDependencies() {
- return injectionTarget instanceof DefaultInjectionTarget<?> &&
- ((DefaultInjectionTarget<?>) injectionTarget).hasPreDestroyMethods();
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/Injector.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/Injector.java
deleted file mode 100644
index 9e7d1d1..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/Injector.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.BeanManager;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InitializationException;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.Disposes;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-import java.util.Collection;
-import java.util.Optional;
-
-class Injector {
- private final BeanManager beanManager;
-
- Injector(final BeanManager beanManager) {
- this.beanManager = beanManager;
- }
-
- <T> T construct(final Constructor<T> constructor, final Collection<InjectionPoint> points, final InitializationContext<T> context) {
- try {
- return constructor.newInstance(createArguments(constructor.getParameters(), points, context, null));
- } catch (final IllegalAccessException | InstantiationException e) {
- throw new InitializationException("Error invoking constructor " + constructor, e);
- } catch (final InvocationTargetException e) {
- throw new InitializationException("Error invoking constructor " + constructor, e.getCause());
- }
- }
-
- <D, T> T produce(final D producerInstance, final Method producerMethod, final Collection<InjectionPoint> points, final InitializationContext<D> context) {
- try {
- return TypeUtil.cast(producerMethod.invoke(producerInstance, createArguments(producerMethod.getParameters(), points, context, null)));
- } catch (IllegalAccessException e) {
- throw new InitializationException("Error producing instance via " + producerMethod.getName(), e);
- } catch (InvocationTargetException e) {
- throw new InitializationException("Error producing instance via " + producerMethod.getName(), e.getCause());
- }
- }
-
- <T> void dispose(final T disposerInstance, final Method disposerMethod, final Collection<InjectionPoint> points, final Object instance, final InitializationContext<T> context) {
- try {
- disposerMethod.invoke(disposerInstance, createArguments(disposerMethod.getParameters(), points, context, instance));
- } catch (IllegalAccessException e) {
- throw new InitializationException("Error disposing instance via " + disposerMethod.getName(), e);
- } catch (InvocationTargetException e) {
- throw new InitializationException("Error disposing instance via " + disposerMethod.getName(), e.getCause());
- }
- }
-
- <T> void invoke(final T instance, final Method method, final Collection<InjectionPoint> points, final InitializationContext<T> context) {
- try {
- method.invoke(instance, createArguments(method.getParameters(), points, context, null));
- } catch (IllegalAccessException e) {
- throw new InitializationException("Error invoking injection method " + method.getName(), e);
- } catch (InvocationTargetException e) {
- throw new InitializationException("Error invoking injection method " + method.getName(), e.getCause());
- }
- }
-
- <D, T> void set(final D instance, final Field field, final InjectionPoint point, final InitializationContext<D> context) {
- final Optional<T> optionalValue = beanManager.getInjectableValue(point, context);
- optionalValue.ifPresent(value -> {
- try {
- field.set(instance, value);
- } catch (IllegalAccessException e) {
- throw new InitializationException("Error injecting value to field " + field.getName(), e);
- }
- });
- }
-
- private Object[] createArguments(final Parameter[] parameters, final Collection<InjectionPoint> injectionPoints,
- final InitializationContext<?> context, final Object producedInstance) {
- final Object[] arguments = new Object[parameters.length];
- for (int i = 0; i < parameters.length; i++) {
- final Parameter parameter = parameters[i];
- if (parameter.isAnnotationPresent(Disposes.class)) {
- arguments[i] = producedInstance;
- } else {
- final InjectionPoint injectionPoint = injectionPoints.stream()
- .filter(point -> parameter.equals(point.getElement()))
- .findAny()
- .orElseThrow();
- arguments[i] = beanManager.getInjectableValue(injectionPoint, context)
- .orElseThrow(() -> new UnsupportedOperationException("TODO: primitives and defaults"));
- }
- }
- return arguments;
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/MethodProducer.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/MethodProducer.java
deleted file mode 100644
index f9e1515..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/MethodProducer.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.BeanManager;
-import org.apache.logging.log4j.plugins.spi.DefinitionException;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.util.Collection;
-
-class MethodProducer<P, T> extends AbstractProducer<P, T> {
- private final Method producerMethod;
- private final Collection<InjectionPoint> producerInjectionPoints;
-
- MethodProducer(final BeanManager beanManager, final Bean<P> producerBean,
- final Method producerMethod, final Collection<InjectionPoint> producerInjectionPoints,
- final Method disposerMethod, final Collection<InjectionPoint> disposerInjectionPoints) {
- super(beanManager, producerBean, disposerMethod, disposerInjectionPoints);
- if (!Modifier.isStatic(producerMethod.getModifiers()) && producerBean == null) {
- throw new DefinitionException("Producer instance method must be in a bean");
- }
- this.producerMethod = producerMethod;
- this.producerInjectionPoints = producerInjectionPoints;
- }
-
- @Override
- Type getType() {
- return producerMethod.getGenericReturnType();
- }
-
- @Override
- public T produce(final InitializationContext<T> context) {
- try (final InitializationContext<P> parentContext = createContext()) {
- final P declaringInstance = Modifier.isStatic(producerMethod.getModifiers()) ? null : getProducerInstance(parentContext);
- return injector.produce(declaringInstance, producerMethod, producerInjectionPoints, parentContext);
- }
- }
-
- @Override
- public Collection<InjectionPoint> getInjectionPoints() {
- return producerInjectionPoints;
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/MethodProducerFactory.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/MethodProducerFactory.java
deleted file mode 100644
index bafe7dd..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/MethodProducerFactory.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.BeanManager;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.spi.Producer;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-
-import java.lang.reflect.Method;
-import java.util.Collection;
-
-class MethodProducerFactory extends AbstractProducerFactory {
- private final BeanManager beanManager;
- private final Collection<InjectionPoint> producerInjectionPoints;
-
- MethodProducerFactory(final BeanManager beanManager, final Bean<?> declaringBean,
- final Method producerMethod, final Collection<InjectionPoint> producerInjectionPoints,
- final Method disposerMethod, final Collection<InjectionPoint> disposerInjectionPoints) {
- super(declaringBean, producerMethod, disposerMethod, disposerInjectionPoints);
- this.producerInjectionPoints = producerInjectionPoints;
- this.beanManager = beanManager;
- }
-
- @Override
- public <T> Producer<T> createProducer(final Bean<T> bean) {
- final Method producerMethod = TypeUtil.cast(producerMember);
- return new MethodProducer<>(beanManager, declaringBean, producerMethod, producerInjectionPoints,
- disposerMethod, disposerInjectionPoints);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/OptionalBean.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/OptionalBean.java
deleted file mode 100644
index 76998a4..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/OptionalBean.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.DependentScoped;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-import org.apache.logging.log4j.plugins.util.Value;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-import java.util.function.BiFunction;
-
-class OptionalBean<T> implements Bean<Optional<T>> {
- private final Collection<Type> types;
- private final String name;
- private final Value<Optional<Bean<T>>> optionalBean;
- private final BiFunction<Bean<T>, InitializationContext<?>, T> getBeanValue;
-
- OptionalBean(final Type type, final String name, final Value<Optional<Bean<T>>> optionalBean,
- final BiFunction<Bean<T>, InitializationContext<?>, T> getBeanValue) {
- this.types = TypeUtil.getTypeClosure(type);
- this.name = name;
- this.optionalBean = optionalBean;
- this.getBeanValue = getBeanValue;
- }
-
- @Override
- public Collection<Type> getTypes() {
- return types;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Class<? extends Annotation> getScopeType() {
- final Optional<Class<? extends Annotation>> scopeType = optionalBean.get().map(Bean::getScopeType);
- return scopeType.orElse(DependentScoped.class);
- }
-
- @Override
- public Optional<T> create(final InitializationContext<Optional<T>> context) {
- return optionalBean.get().map(bean -> getBeanValue.apply(bean, context));
- }
-
- @Override
- public void destroy(final Optional<T> instance, final InitializationContext<Optional<T>> context) {
- context.close();
- }
-
- @Override
- public Collection<InjectionPoint> getInjectionPoints() {
- return optionalBean.get().map(Bean::getInjectionPoints).orElse(Collections.emptySet());
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- return optionalBean.get().map(Bean::getDeclaringClass).orElse(null);
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/ProducerBean.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/ProducerBean.java
deleted file mode 100644
index e617133..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/ProducerBean.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.IllegalProductException;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.spi.Producer;
-import org.apache.logging.log4j.plugins.spi.ProducerFactory;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.Objects;
-
-class ProducerBean<T> extends AbstractBean<T> {
- private final Producer<T> producer;
- private final Type type;
-
- ProducerBean(final Collection<Type> types, final String name, final Class<? extends Annotation> scopeType,
- final Class<?> declaringClass, final ProducerFactory factory) {
- super(types, name, scopeType, declaringClass);
- Objects.requireNonNull(factory);
- producer = factory.createProducer(this);
- if (producer instanceof AbstractProducer<?, ?>) {
- type = ((AbstractProducer<?, ?>) producer).getType();
- } else {
- type = types.iterator().next();
- }
- }
-
- Type getType() {
- return type;
- }
-
- @Override
- public Collection<InjectionPoint> getInjectionPoints() {
- return producer.getInjectionPoints();
- }
-
- @Override
- public T create(final InitializationContext<T> context) {
- final T instance = producer.produce(context);
- if (instance == null) {
- throw new IllegalProductException("Producer created null instance: " + producer);
- }
- // FIXME: this logic doesn't seem to be in Weld? only seems to be required in InjectionTargetBean
- if (isDependentScoped()) {
- context.addIncompleteInstance(instance);
- }
- return instance;
- }
-
- @Override
- public void destroy(final T instance, final InitializationContext<T> context) {
- try {
- if (isDependentScoped()) {
- producer.dispose(instance);
- }
- } finally {
- context.close();
- }
- }
-
- @Override
- public String toString() {
- return "ProducerBean{" +
- "types=" + getTypes() +
- ", scope=@" + getScopeType().getSimpleName() +
- ", name=" + getName() +
- ", declaringClass=" + getDeclaringClass() +
- '}';
- }
-
- @Override
- boolean isTrackingDependencies() {
- return producer instanceof AbstractProducer<?, ?> && ((AbstractProducer<?, ?>) producer).hasDisposerMethod();
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/ProvidedBean.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/ProvidedBean.java
deleted file mode 100644
index 123e226..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/ProvidedBean.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.di.Provider;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.function.Function;
-
-class ProvidedBean<T> implements Bean<T> {
- private final Collection<Type> types;
- private final Bean<Provider<T>> providerBean;
- private final Function<InitializationContext<?>, Provider<T>> providerFactory;
-
- ProvidedBean(final Type type, final Bean<Provider<T>> providerBean,
- final Function<InitializationContext<?>, Provider<T>> providerFactory) {
- this.types = TypeUtil.getTypeClosure(type);
- this.providerBean = providerBean;
- this.providerFactory = providerFactory;
- }
-
- @Override
- public T create(final InitializationContext<T> context) {
- return providerFactory.apply(context).get();
- }
-
- @Override
- public void destroy(final T instance, final InitializationContext<T> context) {
- context.close();
- }
-
- @Override
- public Collection<InjectionPoint> getInjectionPoints() {
- return providerBean.getInjectionPoints();
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- return providerBean.getDeclaringClass();
- }
-
- @Override
- public Collection<Type> getTypes() {
- return types;
- }
-
- @Override
- public String getName() {
- return providerBean.getName();
- }
-
- @Override
- public Class<? extends Annotation> getScopeType() {
- return providerBean.getScopeType();
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/ProviderBean.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/ProviderBean.java
deleted file mode 100644
index 3ba47e2..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/spi/impl/ProviderBean.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.spi.impl;
-
-import org.apache.logging.log4j.plugins.spi.Bean;
-import org.apache.logging.log4j.plugins.spi.InitializationContext;
-import org.apache.logging.log4j.plugins.spi.InjectionPoint;
-import org.apache.logging.log4j.plugins.di.Provider;
-import org.apache.logging.log4j.plugins.util.TypeUtil;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.function.Function;
-
-class ProviderBean<T> implements Bean<Provider<T>> {
- private final Collection<Type> types;
- private final Bean<T> bean;
- private final Function<InitializationContext<?>, Provider<T>> providerFactory;
-
- ProviderBean(final Type providerType, final Bean<T> bean,
- final Function<InitializationContext<?>, Provider<T>> providerFactory) {
- this.types = TypeUtil.getTypeClosure(providerType);
- this.bean = bean;
- this.providerFactory = providerFactory;
- }
-
- @Override
- public Provider<T> create(final InitializationContext<Provider<T>> context) {
- return providerFactory.apply(context);
- }
-
- @Override
- public void destroy(final Provider<T> instance, final InitializationContext<Provider<T>> context) {
- context.close();
- }
-
- @Override
- public Collection<InjectionPoint> getInjectionPoints() {
- return bean.getInjectionPoints();
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- return bean.getDeclaringClass();
- }
-
- @Override
- public Collection<Type> getTypes() {
- return types;
- }
-
- @Override
- public String getName() {
- return bean.getName();
- }
-
- @Override
- public Class<? extends Annotation> getScopeType() {
- return bean.getScopeType();
- }
-}
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginLoader.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginLoader.java
deleted file mode 100644
index 3815c26..0000000
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginLoader.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.plugins.util;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.plugins.di.model.PluginModule;
-import org.apache.logging.log4j.plugins.di.model.PluginSource;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.LoaderUtil;
-
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ServiceLoader;
-
-public class PluginLoader {
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- public static List<PluginSource> loadPluginSourcesFromMainClassLoader() {
- final List<PluginSource> sources = new ArrayList<>();
- for (final ClassLoader classLoader : LoaderUtil.getClassLoaders()) {
- sources.addAll(loadPluginSources(classLoader));
- }
- return sources;
- }
-
- public static List<PluginSource> loadPluginSources(final ClassLoader classLoader) {
- final long startTime = System.nanoTime();
- final ServiceLoader<PluginModule> serviceLoader = ServiceLoader.load(PluginModule.class, classLoader);
- final List<PluginSource> sources = new ArrayList<>();
- for (final PluginModule module : serviceLoader) {
- sources.addAll(module.getPluginSources());
- }
- final int numPlugins = sources.size();
- LOGGER.debug(() -> {
- final long endTime = System.nanoTime();
- final DecimalFormat numFormat = new DecimalFormat("#0.000000");
- return "Took " + numFormat.format((endTime - startTime) * 1e-9) +
- " seconds to load " + numPlugins +
- " plugins from " + classLoader;
- });
- return sources;
- }
-
-}