This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new f5b5d0b922 [LOG4J2-3546] Switch from `osgi.serviceloader` to
`Activator`
f5b5d0b922 is described below
commit f5b5d0b922e164117b732ceffe0313a2424c980f
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Sun Jul 3 21:04:11 2022 +0200
[LOG4J2-3546] Switch from `osgi.serviceloader` to `Activator`
Switches `log4j-to-slf4j` and `log4j-to-jul` from using the Service
Loader Mediator to registering their provider themselves. This way they
can be used in minimal OSGI systems.
Newer tests in `log4j-osgi` are written using PAX Exam in order to
provide a larger OSGI environment.
---
.../logging/log4j/util/ProviderActivator.java | 55 +++++++++++
.../apache/logging/log4j/core/osgi/Activator.java | 23 ++---
log4j-osgi/pom.xml | 106 ++++++++++++++++++++-
.../log4j/osgi/tests/AbstractLoadBundleTest.java | 37 +++----
.../logging/log4j/osgi/tests/JULProviderTest.java | 72 ++++++++++++++
.../log4j/osgi/tests/SLF4JProviderTest.java | 71 ++++++++++++++
.../log4j/osgi/tests/junit/BundleTestInfo.java | 71 --------------
log4j-to-jul/pom.xml | 11 +--
.../org/apache/logging/log4j/tojul/Activator.java | 26 +++++
log4j-to-slf4j/pom.xml | 11 +--
.../java/org/apache/logging/slf4j/Activator.java | 28 ++++++
pom.xml | 24 +++++
12 files changed, 408 insertions(+), 127 deletions(-)
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderActivator.java
b/log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderActivator.java
new file mode 100644
index 0000000000..2e561caed8
--- /dev/null
+++
b/log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderActivator.java
@@ -0,0 +1,55 @@
+/*
+ * 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.util;
+
+import java.util.Hashtable;
+
+import org.apache.logging.log4j.spi.Provider;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Utility class to register Log4j2 providers in an OSGI environment.
+ */
+public abstract class ProviderActivator implements BundleActivator {
+
+ public static final String API_VERSION = "APIVersion";
+
+ private final Provider provider;
+ private ServiceRegistration<Provider> providerRegistration = null;
+
+ protected ProviderActivator(final Provider provider) {
+ this.provider = provider;
+ }
+
+ @Override
+ public void start(final BundleContext context) throws Exception {
+ final Hashtable<String, String> props = new Hashtable<>();
+ props.put(API_VERSION, provider.getVersions());
+ providerRegistration = context.registerService(Provider.class,
provider, props);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ if (providerRegistration != null) {
+ providerRegistration.unregister();
+ }
+ }
+
+}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/osgi/Activator.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/osgi/Activator.java
index a00e484cca..9c1288cd43 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/osgi/Activator.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/osgi/Activator.java
@@ -18,7 +18,6 @@
package org.apache.logging.log4j.core.osgi;
import java.util.Collection;
-import java.util.Hashtable;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.logging.log4j.LogManager;
@@ -29,11 +28,10 @@ import
org.apache.logging.log4j.core.impl.ThreadContextDataInjector;
import org.apache.logging.log4j.core.impl.ThreadContextDataProvider;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.ContextDataProvider;
-import org.apache.logging.log4j.spi.Provider;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.PropertiesUtil;
+import org.apache.logging.log4j.util.ProviderActivator;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.InvalidSyntaxException;
@@ -45,24 +43,23 @@ import org.osgi.framework.wiring.BundleWiring;
/**
* OSGi BundleActivator.
*/
-public final class Activator implements BundleActivator,
SynchronousBundleListener {
+public final class Activator extends ProviderActivator implements
SynchronousBundleListener {
private static final Logger LOGGER = StatusLogger.getLogger();
private final AtomicReference<BundleContext> contextRef = new
AtomicReference<>();
- ServiceRegistration provideRegistration = null;
- ServiceRegistration contextDataRegistration = null;
+ private ServiceRegistration<ContextDataProvider> contextDataRegistration =
null;
+
+ public Activator() {
+ super(new Log4jProvider());
+ }
@Override
public void start(final BundleContext context) throws Exception {
- final Provider provider = new Log4jProvider();
- final Hashtable<String, String> props = new Hashtable<>();
- props.put("APIVersion", "2.60");
+ super.start(context);
final ContextDataProvider threadContextProvider = new
ThreadContextDataProvider();
- provideRegistration =
context.registerService(Provider.class.getName(), provider, props);
- contextDataRegistration =
context.registerService(ContextDataProvider.class.getName(),
threadContextProvider,
- null);
+ contextDataRegistration =
context.registerService(ContextDataProvider.class, threadContextProvider, null);
loadContextProviders(context);
// allow the user to override the default ContextSelector (e.g., by
using BasicContextSelector for a global cfg)
if
(PropertiesUtil.getProperties().getStringProperty(Constants.LOG4J_CONTEXT_SELECTOR)
== null) {
@@ -114,10 +111,10 @@ public final class Activator implements BundleActivator,
SynchronousBundleListen
@Override
public void stop(final BundleContext context) throws Exception {
- provideRegistration.unregister();
contextDataRegistration.unregister();
this.contextRef.compareAndSet(context, null);
LogManager.shutdown();
+ super.stop(context);
}
@Override
diff --git a/log4j-osgi/pom.xml b/log4j-osgi/pom.xml
index 7e2ee5eb7e..31bec57510 100644
--- a/log4j-osgi/pom.xml
+++ b/log4j-osgi/pom.xml
@@ -32,8 +32,57 @@
<projectDir>/osgi</projectDir>
<module.name>org.apache.logging.log4j.osgi</module.name>
<maven.doap.skip>true</maven.doap.skip>
+ <pax.exam.version>4.13.5</pax.exam.version>
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-1.2-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-to-jul</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-to-slf4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j.samples</groupId>
+ <artifactId>log4j-samples-configuration</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<!-- Place Felix before Equinox because Felix is signed. / also place it
before org.osgi.core so that its versions of the OSGi classes are used -->
<dependency>
<groupId>org.apache.felix</groupId>
@@ -43,7 +92,6 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
@@ -59,15 +107,39 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <version>${pax.exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-spi</artifactId>
+ <version>${pax.exam.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-native</artifactId>
+ <version>${pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-assembly</artifactId>
+ <version>${pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
@@ -109,6 +181,30 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <!-- PAX logging has a copy of Log4j2 API-->
+ <pax.exam.logging>false</pax.exam.logging>
+
<java.protocol.handler.pkgs>org.ops4j.pax.url</java.protocol.handler.pkgs>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>exam-maven-plugin</artifactId>
+ <version>${pax.exam.version}</version>
+ <executions>
+ <execution>
+ <phase>generate-test-resources</phase>
+ <goals>
+ <goal>generate-link-files</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
<reporting>
diff --git
a/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/AbstractLoadBundleTest.java
b/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/AbstractLoadBundleTest.java
index 41dc963f6e..acc123291d 100644
---
a/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/AbstractLoadBundleTest.java
+++
b/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/AbstractLoadBundleTest.java
@@ -23,14 +23,12 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.apache.logging.log4j.osgi.tests.junit.BundleTestInfo;
import org.apache.logging.log4j.osgi.tests.junit.OsgiRule;
+import org.apache.logging.log4j.util.ServiceLoaderUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -47,18 +45,8 @@ public abstract class AbstractLoadBundleTest {
private BundleContext bundleContext;
- private final BundleTestInfo bundleTestInfo;
-
- private Path here;
-
@Rule
public OsgiRule osgi = new OsgiRule(getFactory());
- /**
- * Constructs a test for a given bundle.
- */
- public AbstractLoadBundleTest() {
- this.bundleTestInfo = new BundleTestInfo();
- }
/**
* Called before each @Test.
@@ -66,36 +54,33 @@ public abstract class AbstractLoadBundleTest {
@Before
public void before() throws BundleException {
bundleContext = osgi.getFramework().getBundleContext();
+ }
- here = Paths.get(".").toAbsolutePath().normalize();
+ private Bundle installBundle(String symbolicName) throws BundleException {
+ // The links are generated by 'exam-maven-plugin'
+ final String url = String.format("link:classpath:%s.link",
symbolicName);
+ return bundleContext.installBundle(url);
}
private Bundle getApiBundle() throws BundleException {
- final Path apiPath =
here.resolveSibling("log4j-api").resolve("target").resolve("log4j-api-" +
bundleTestInfo.getVersion() + ".jar");
- return bundleContext.installBundle(apiPath.toUri().toString());
+ return installBundle("org.apache.logging.log4j.api");
}
private Bundle getCoreBundle() throws BundleException {
- final Path corePath =
here.resolveSibling("log4j-core").resolve("target").resolve("log4j-core-" +
bundleTestInfo.getVersion() + ".jar");
- return bundleContext.installBundle(corePath.toUri().toString());
+ return installBundle("org.apache.logging.log4j.core");
}
private Bundle getDummyBundle() throws BundleException {
- final Path dumyPath =
here.resolveSibling("log4j-samples").resolve("log4j-samples-configuration").resolve("target").resolve("log4j-samples-configuration-"
+ bundleTestInfo.getVersion() + ".jar");
- return bundleContext.installBundle(dumyPath.toUri().toString());
+ return
installBundle("org.apache.logging.log4j.samples.log4j-samples-configuration");
}
private Bundle get12ApiBundle() throws BundleException {
- final Path apiPath =
here.resolveSibling("log4j-1.2-api").resolve("target").resolve("log4j-1.2-api-"
+ bundleTestInfo.getVersion() + ".jar");
- return bundleContext.installBundle(apiPath.toUri().toString());
+ return installBundle("org.apache.logging.log4j.1.2-api");
}
private Bundle getApiTestsBundle() throws BundleException {
- final Path apiTestsPath = here.resolveSibling("log4j-api")
- .resolve("target")
- .resolve("log4j-api-" + bundleTestInfo.getVersion() + "-tests.jar");
- return bundleContext.installBundle(apiTestsPath.toUri().toString());
+ return installBundle("org.apache.logging.log4j.api.tests");
}
protected abstract FrameworkFactory getFactory();
diff --git
a/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/JULProviderTest.java
b/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/JULProviderTest.java
new file mode 100644
index 0000000000..5e918bfe6d
--- /dev/null
+++
b/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/JULProviderTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.osgi.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.linkBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import javax.inject.Inject;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.spi.LoggerContextFactory;
+import org.apache.logging.log4j.tojul.JULLoggerContextFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class JULProviderTest {
+
+ @Inject
+ private BundleContext context;
+
+ @Configuration
+ public Option[] config() {
+ return options(
+ linkBundle("org.apache.logging.log4j.api"),
+ linkBundle("org.apache.logging.log4j.to-jul"),
+ // required by Pax Exam's logging
+ linkBundle("slf4j.api"),
+ linkBundle("ch.qos.logback.classic"),
+ linkBundle("ch.qos.logback.core"),
+ junitBundles());
+ }
+
+ @Test
+ public void testJulFactoryResolves() {
+ final Optional<Bundle> julBundle = Stream.of(context.getBundles())
+ .filter(b ->
"org.apache.logging.log4j.to-jul".equals(b.getSymbolicName()))
+ .findAny();
+ assertTrue(julBundle.isPresent());
+ final LoggerContextFactory factory = LogManager.getFactory();
+ assertEquals(JULLoggerContextFactory.class, factory.getClass());
+ }
+}
diff --git
a/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/SLF4JProviderTest.java
b/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/SLF4JProviderTest.java
new file mode 100644
index 0000000000..4546b7bb04
--- /dev/null
+++
b/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/SLF4JProviderTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.osgi.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.linkBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import javax.inject.Inject;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.spi.LoggerContextFactory;
+import org.apache.logging.slf4j.SLF4JLoggerContextFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class SLF4JProviderTest {
+
+ @Inject
+ private BundleContext context;
+
+ @Configuration
+ public Option[] config() {
+ return options(
+ linkBundle("org.apache.logging.log4j.api"),
+ linkBundle("org.apache.logging.log4j.to-slf4j"),
+ linkBundle("slf4j.api"),
+ linkBundle("ch.qos.logback.classic"),
+ linkBundle("ch.qos.logback.core"),
+ junitBundles());
+ }
+
+ @Test
+ public void testSlf4jFactoryResolves() {
+ final Optional<Bundle> slf4jBundle = Stream.of(context.getBundles())
+ .filter(b ->
"org.apache.logging.log4j.to-slf4j".equals(b.getSymbolicName()))
+ .findAny();
+ assertTrue(slf4jBundle.isPresent());
+ final LoggerContextFactory factory = LogManager.getFactory();
+ assertEquals(SLF4JLoggerContextFactory.class, factory.getClass());
+ }
+}
diff --git
a/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/junit/BundleTestInfo.java
b/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/junit/BundleTestInfo.java
deleted file mode 100644
index 9a4f8a8173..0000000000
---
a/log4j-osgi/src/test/java/org/apache/logging/log4j/osgi/tests/junit/BundleTestInfo.java
+++ /dev/null
@@ -1,71 +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.osgi.tests.junit;
-
-import java.io.FileReader;
-import java.io.IOException;
-
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-/**
- * Provides tests with bundle information. Reads the {@code pom.xml} in the
current directory to get project settings.
- */
-public class BundleTestInfo {
-
- private final MavenProject project;
-
- /**
- * Constructs a new helper objects and initializes itself.
- */
- public BundleTestInfo() {
- try (final FileReader reader = new FileReader("pom.xml")) {
- // get a raw POM view, not a fully realized POM object.
- final Model model = new MavenXpp3Reader().read(reader);
- this.project = new MavenProject(model);
- } catch (final IOException | XmlPullParserException e) {
- throw new IllegalStateException("Could not read pom.xml", e);
- }
- }
-
- /**
- * Gets the Maven artifact ID.
- *
- * @return the Maven artifact ID.
- */
- public String getArtifactId() {
- return project.getArtifactId();
- }
-
- /**
- * Gets the Maven version String.
- *
- * @return the Maven version String.
- */
- public String getVersion() {
- return project.getVersion();
- }
-
- @Override
- public String toString() {
- return "BundleTestInfo [project=" + project + "]";
- }
-
-}
diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml
index 756d5a1348..661831e8ad 100644
--- a/log4j-to-jul/pom.xml
+++ b/log4j-to-jul/pom.xml
@@ -40,6 +40,10 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
@@ -81,13 +85,8 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
+
<Bundle-Activator>org.apache.logging.log4j.tojul.Activator</Bundle-Activator>
<Export-Package>org.apache.logging.log4j.tojul</Export-Package>
- <Require-Capability>
-
osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)"
- </Require-Capability>
- <Provide-Capability>
-
osgi.serviceloader;osgi.serviceloader=org.apache.logging.log4j.spi.Provider
- </Provide-Capability>
</instructions>
</configuration>
</plugin>
diff --git
a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java
b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java
new file mode 100644
index 0000000000..47cc1f3bf3
--- /dev/null
+++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java
@@ -0,0 +1,26 @@
+/*
+ * 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.tojul;
+
+import org.apache.logging.log4j.util.ProviderActivator;
+
+public class Activator extends ProviderActivator {
+
+ public Activator() {
+ super(new JULProvider());
+ }
+}
diff --git a/log4j-to-slf4j/pom.xml b/log4j-to-slf4j/pom.xml
index 7e9651467e..1750f506b4 100644
--- a/log4j-to-slf4j/pom.xml
+++ b/log4j-to-slf4j/pom.xml
@@ -42,6 +42,10 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
@@ -94,13 +98,8 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
+
<Bundle-Activator>org.apache.logging.slf4j.Activator</Bundle-Activator>
<Export-Package>org.apache.logging.slf4j</Export-Package>
- <Require-Capability>
-
osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)"
- </Require-Capability>
- <Provide-Capability>
-
osgi.serviceloader;osgi.serviceloader=org.apache.logging.log4j.spi.Provider
- </Provide-Capability>
</instructions>
</configuration>
</plugin>
diff --git
a/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/Activator.java
b/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/Activator.java
new file mode 100644
index 0000000000..fc997e5061
--- /dev/null
+++ b/log4j-to-slf4j/src/main/java/org/apache/logging/slf4j/Activator.java
@@ -0,0 +1,28 @@
+/*
+ * 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.slf4j;
+
+import org.apache.logging.log4j.util.ProviderActivator;
+
+public class Activator extends ProviderActivator {
+
+ public Activator() {
+ super(new SLF4JProvider());
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 39271830ac..42fb899629 100644
--- a/pom.xml
+++ b/pom.xml
@@ -302,6 +302,7 @@
<xmlunitVersion>2.9.0</xmlunitVersion>
<!-- Java EE 8 artifacts -->
<javax.activation.version>1.2.0</javax.activation.version>
+ <javax.inject.version>1</javax.inject.version>
<javax.jms.version>2.0.1</javax.jms.version>
<javax.jsp.version>2.3.3</javax.jsp.version>
<javax.mail.version>1.6.2</javax.mail.version>
@@ -333,6 +334,13 @@
</pluginRepositories>
<dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-bom</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@@ -467,6 +475,16 @@
<artifactId>log4j-jcl</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-to-jul</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-to-slf4j</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
@@ -713,6 +731,12 @@
<version>${javax.activation.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>${javax.inject.version}</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>