You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2024/01/13 08:40:31 UTC

(logging-log4j2) branch main updated: Move OSGi caches to `target` directory

This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/main by this push:
     new 848a669851 Move OSGi caches to `target` directory
848a669851 is described below

commit 848a6698512b224f7b0b9c2b95f7871566206d7a
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Sat Jan 13 09:24:49 2024 +0100

    Move OSGi caches to `target` directory
---
 log4j-osgi-test/pom.xml                            | 16 +++++++++++++
 .../log4j/osgi/tests/junit/OsgiTestRule.java       | 28 ++++++++++++----------
 log4j-osgi-test/src/test/resources/osgi.properties | 25 +++++++++++++++++++
 3 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/log4j-osgi-test/pom.xml b/log4j-osgi-test/pom.xml
index 9811094553..953e3ed7e4 100644
--- a/log4j-osgi-test/pom.xml
+++ b/log4j-osgi-test/pom.xml
@@ -135,6 +135,13 @@
     </dependency>
   </dependencies>
   <build>
+    <testResources>
+      <testResource>
+        <!-- Enable variable interpolation in resources -->
+        <filtering>true</filtering>
+        <directory>src/test/resources</directory>
+      </testResource>
+    </testResources>
     <plugins>
 
       <!--
@@ -186,6 +193,15 @@
         </configuration>
       </plugin>
 
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <configuration>
+          <!-- Property files must be encoded in ISO-8859-1 -->
+          <propertiesEncoding>ISO-8859-1</propertiesEncoding>
+        </configuration>
+      </plugin>
+
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
diff --git a/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/junit/OsgiTestRule.java b/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/junit/OsgiTestRule.java
index 9d717d0821..81a4ac4c82 100644
--- a/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/junit/OsgiTestRule.java
+++ b/log4j-osgi-test/src/test/java/org/apache/logging/log4j/osgi/tests/junit/OsgiTestRule.java
@@ -16,8 +16,11 @@
  */
 package org.apache.logging.log4j.osgi.tests.junit;
 
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
 import org.junit.rules.ExternalResource;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.launch.Framework;
@@ -50,18 +53,19 @@ public class OsgiTestRule extends ExternalResource {
 
     @Override
     protected void before() throws Throwable {
-        final Map<String, String> configMap = new HashMap<>(2);
-        // Cleans framework before first init. Subsequent init invocations do not clean framework.
-        configMap.put("org.osgi.framework.storage.clean", "onFirstInit");
-        configMap.put("felix.log.level", "4");
-        configMap.put("eclipse.log.level", "ALL");
-        // Hack to get the build working on Windows. Could try newer versions of Felix.
-        configMap.put("felix.cache.locking", "false");
-        // Delegates loading of endorsed libraries to JVM classloader
-        // config.put("org.osgi.framework.bootdelegation", "javax.*,org.w3c.*,org.xml.*");
-        framework = factory.newFramework(configMap);
-        framework.init();
-        framework.start();
+        try (final InputStream is = OsgiTestRule.class.getResourceAsStream("/osgi.properties")) {
+            final Properties props = new Properties();
+            props.load(is);
+            final Map<String, String> configMap = props.entrySet().stream()
+                    .collect(Collectors.toMap(
+                            e -> String.valueOf(e.getKey()),
+                            e -> String.valueOf(e.getValue()),
+                            (prev, next) -> next,
+                            HashMap::new));
+            framework = factory.newFramework(configMap);
+            framework.init();
+            framework.start();
+        }
     }
 
     public Framework getFramework() {
diff --git a/log4j-osgi-test/src/test/resources/osgi.properties b/log4j-osgi-test/src/test/resources/osgi.properties
new file mode 100644
index 0000000000..9016851d4e
--- /dev/null
+++ b/log4j-osgi-test/src/test/resources/osgi.properties
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+org.osgi.framework.storage.clean = onFirstInit
+felix.log.level = 4
+eclipse.log.level = ALL
+# Hack to get the build working on Windows. Could try newer versions of Felix.
+felix.cache.locking = false
+# Location of `felix-cache` directory
+felix.cache.rootdir = @project.build.directory@
+# Location of Equinox's cache
+osgi.configuration.area= @project.build.directory@/equinox-cache