From 987ab9970a416e6a1abdaea276a05b9d1df1b71d Mon Sep 17 00:00:00 2001 From: Arnoud Glimmerveen Date: Mon, 12 May 2025 21:14:51 +0200 Subject: [PATCH 1/3] Related to PR #420, on getting control on the logging. This changes disables Pax Exam's preference for Pax Logging, and changes it with Logback (in the latest SLF4j 1.7.x compatible version). With this change, SLF4j and Logback are now available for both the unit tests and the pax exam tests. Configured explicit versions of all 'mavenBundle's declared in the ComponentTestBase, as otherwise Pax will depend on Maven's LATEST, which is not always compatible. --- scr/pom.xml | 19 ++--------- .../scr/integration/ComponentTestBase.java | 14 +++++--- scr/src/test/resources/exam.properties | 19 +++++++++++ scr/src/test/resources/logback-test.xml | 33 +++++++++++++++++++ 4 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 scr/src/test/resources/exam.properties create mode 100644 scr/src/test/resources/logback-test.xml diff --git a/scr/pom.xml b/scr/pom.xml index 1883d19073..148a82b8ca 100644 --- a/scr/pom.xml +++ b/scr/pom.xml @@ -196,30 +196,17 @@ 2.6.2 test - - org.ops4j.pax.logging - pax-logging-api - 1.6.3 - test - - - org.ops4j.pax.logging - pax-logging-service - 1.6.3 - test - - ch.qos.logback logback-core - 1.3.15 + 1.2.12 test - + ch.qos.logback logback-classic - 1.3.12 + 1.2.12 test diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java index 39724c1b0f..7921e1b885 100644 --- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java +++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java @@ -186,16 +186,20 @@ public static Option[] configuration() CoreOptions.bundle( bundleFile.toURI().toString() ), mavenBundle( "org.ops4j.pax.tinybundles", "tinybundles", "1.0.0" ), mavenBundle( "org.osgi", "org.osgi.service.log", "1.4.0"), + mavenBundle( "org.slf4j", "slf4j-api", "1.7.32" ), + mavenBundle( "ch.qos.logback", "logback-core", "1.2.12" ), + mavenBundle( "ch.qos.logback", "logback-classic", "1.2.12" ), mavenBundle( "org.osgi", "org.osgi.util.pushstream", "1.0.0"), mavenBundle( "org.apache.felix", "org.apache.felix.configadmin", felixCaVersion ) ), - mavenBundle( "org.osgi", "org.osgi.util.promise"), - mavenBundle( "org.osgi", "org.osgi.util.function"), - mavenBundle( "org.osgi", "org.osgi.service.component"), - mavenBundle( "org.ops4j.pax.url", "pax-url-aether"), + mavenBundle( "org.osgi", "org.osgi.util.promise", "1.3.0" ), + mavenBundle( "org.osgi", "org.osgi.util.function", "1.2.0" ), + mavenBundle( "org.osgi", "org.osgi.service.component", "1.5.1" ), + mavenBundle( "org.ops4j.pax.url", "pax-url-aether", "2.6.2"), junitBundles(), frameworkProperty( "org.osgi.framework.bsnversion" ).value( bsnVersionUniqueness ), systemProperty( "ds.factory.enabled" ).value( Boolean.toString( NONSTANDARD_COMPONENT_FACTORY_BEHAVIOR ) ), systemProperty( "ds.loglevel" ).value( DS_LOGLEVEL ), - systemProperty( "ds.cache.metadata" ).value( Boolean.toString(CACHE_META_DATA) ) + systemProperty( "ds.cache.metadata" ).value( Boolean.toString(CACHE_META_DATA) ), + systemProperty( "logback.configurationFile" ).value( "src/test/resources/logback-test.xml" ) ); final Option vmOption = ( paxRunnerVmOption != null )? CoreOptions.vmOption( paxRunnerVmOption ): null; diff --git a/scr/src/test/resources/exam.properties b/scr/src/test/resources/exam.properties new file mode 100644 index 0000000000..4814f3b9c9 --- /dev/null +++ b/scr/src/test/resources/exam.properties @@ -0,0 +1,19 @@ +# 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. +# +# Prevent PAX Logging to be activated +pax.exam.logging=none \ No newline at end of file diff --git a/scr/src/test/resources/logback-test.xml b/scr/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..83171fa127 --- /dev/null +++ b/scr/src/test/resources/logback-test.xml @@ -0,0 +1,33 @@ + + + + + + + %d{HH:mm:ss.SSS} [%15.15thread] %-5level %-36.36logger{36} - %msg%n + + + + + + + + + \ No newline at end of file From 789cb77de833c350d9006c5a85f4cf587039890e Mon Sep 17 00:00:00 2001 From: Arnoud Glimmerveen Date: Tue, 13 May 2025 08:01:37 +0200 Subject: [PATCH 2/3] Added flag towards Pax Exam that ensures the Pax Exam test fails if there are unresolved bundles within the test runtime. This to avoid trying to run in a test in an inconsistent/incomplete environment (as some of the bundles were unresolved due to an incompatible version being used). --- .../org/apache/felix/scr/integration/ComponentTestBase.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java index 7921e1b885..81cb0e804d 100644 --- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java +++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java @@ -18,6 +18,7 @@ */ package org.apache.felix.scr.integration; +import static org.ops4j.pax.exam.Constants.EXAM_FAIL_ON_UNRESOLVED_KEY; import static org.ops4j.pax.exam.CoreOptions.frameworkProperty; import static org.ops4j.pax.exam.CoreOptions.junitBundles; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; @@ -199,7 +200,8 @@ public static Option[] configuration() systemProperty( "ds.factory.enabled" ).value( Boolean.toString( NONSTANDARD_COMPONENT_FACTORY_BEHAVIOR ) ), systemProperty( "ds.loglevel" ).value( DS_LOGLEVEL ), systemProperty( "ds.cache.metadata" ).value( Boolean.toString(CACHE_META_DATA) ), - systemProperty( "logback.configurationFile" ).value( "src/test/resources/logback-test.xml" ) + systemProperty( "logback.configurationFile" ).value( "src/test/resources/logback-test.xml" ), + systemProperty( EXAM_FAIL_ON_UNRESOLVED_KEY ).value( "true" ) ); final Option vmOption = ( paxRunnerVmOption != null )? CoreOptions.vmOption( paxRunnerVmOption ): null; From b61b3e4b355b247853c1b4ceb502a06a1870d4f8 Mon Sep 17 00:00:00 2001 From: Arnoud Glimmerveen Date: Wed, 14 May 2025 21:35:22 +0200 Subject: [PATCH 3/3] Replaced the static versions referenced by ComponentTestBase, with obtaining these versions from the SCR maven project itself. This relies on the depends-maven-plugin on generating a properties file, that is read by the .versionAsInProject() Pax mavenBundle option API. Needed to update two existing dependencies, and add two test dependencies in order for the bundles used to be mutually consistent versions. --- scr/pom.xml | 33 +++++++++++++++++-- .../scr/integration/ComponentTestBase.java | 24 +++++++------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/scr/pom.xml b/scr/pom.xml index 148a82b8ca..6737bc15ca 100644 --- a/scr/pom.xml +++ b/scr/pom.xml @@ -65,7 +65,6 @@ ${bundle.build.name}/${project.build.finalName}.jar - 1.9.0 8 ${java.version} @@ -121,13 +120,13 @@ org.osgi org.osgi.util.promise - 1.0.0 + 1.1.0 provided org.osgi org.osgi.util.function - 1.0.0 + 1.1.0 provided @@ -251,6 +250,18 @@ 5.0.4 test + + org.osgi + org.osgi.util.pushstream + 1.0.0 + test + + + org.apache.felix + org.apache.felix.configadmin + 1.9.0 + test + ${bundle.build.name} @@ -316,6 +327,22 @@ ${java.version} + + org.apache.servicemix.tooling + depends-maven-plugin + 1.5.0 + + + + generate-depends-file + + pre-integration-test + + ${project.build.testOutputDirectory}/META-INF/maven/dependencies.properties + + + + diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java index 81cb0e804d..19ee076e9d 100644 --- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java +++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java @@ -139,8 +139,6 @@ public abstract class ComponentTestBase //set to true to only get last 1000 lines of log. protected static boolean restrictedLogging; - protected static String felixCaVersion = System.getProperty( "felix.ca.version" ); - protected static final String PROP_NAME_FACTORY = ComponentTestBase.PROP_NAME + ".factory"; static @@ -185,17 +183,17 @@ public static Option[] configuration() final Option[] base = options( provision( CoreOptions.bundle( bundleFile.toURI().toString() ), - mavenBundle( "org.ops4j.pax.tinybundles", "tinybundles", "1.0.0" ), - mavenBundle( "org.osgi", "org.osgi.service.log", "1.4.0"), - mavenBundle( "org.slf4j", "slf4j-api", "1.7.32" ), - mavenBundle( "ch.qos.logback", "logback-core", "1.2.12" ), - mavenBundle( "ch.qos.logback", "logback-classic", "1.2.12" ), - mavenBundle( "org.osgi", "org.osgi.util.pushstream", "1.0.0"), - mavenBundle( "org.apache.felix", "org.apache.felix.configadmin", felixCaVersion ) ), - mavenBundle( "org.osgi", "org.osgi.util.promise", "1.3.0" ), - mavenBundle( "org.osgi", "org.osgi.util.function", "1.2.0" ), - mavenBundle( "org.osgi", "org.osgi.service.component", "1.5.1" ), - mavenBundle( "org.ops4j.pax.url", "pax-url-aether", "2.6.2"), + mavenBundle( "org.ops4j.pax.tinybundles", "tinybundles" ).versionAsInProject(), + mavenBundle( "org.osgi", "org.osgi.service.log" ).versionAsInProject(), + mavenBundle( "org.slf4j", "slf4j-api" ).versionAsInProject(), + mavenBundle( "ch.qos.logback", "logback-core" ).versionAsInProject(), + mavenBundle( "ch.qos.logback", "logback-classic" ).versionAsInProject(), + mavenBundle( "org.osgi", "org.osgi.util.pushstream" ).versionAsInProject(), + mavenBundle( "org.apache.felix", "org.apache.felix.configadmin" ).versionAsInProject() ), + mavenBundle( "org.osgi", "org.osgi.util.promise" ).versionAsInProject(), + mavenBundle( "org.osgi", "org.osgi.util.function" ).versionAsInProject(), + mavenBundle( "org.osgi", "org.osgi.service.component" ).versionAsInProject(), + mavenBundle( "org.ops4j.pax.url", "pax-url-aether" ).versionAsInProject(), junitBundles(), frameworkProperty( "org.osgi.framework.bsnversion" ).value( bsnVersionUniqueness ), systemProperty( "ds.factory.enabled" ).value( Boolean.toString( NONSTANDARD_COMPONENT_FACTORY_BEHAVIOR ) ), systemProperty( "ds.loglevel" ).value( DS_LOGLEVEL ),