You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pk...@apache.org on 2020/07/20 13:17:56 UTC

[felix-dev] branch master updated: [configurator] Unchanged bundle does not obey force policy

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

pkriens pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 57837d6  [configurator] Unchanged bundle does not obey force policy
     new e0cd72e  Merge pull request #35 from pkriens/master
57837d6 is described below

commit 57837d649545533aa9d4e860ad5445c2924c9a41
Author: Peter Kriens <Pe...@aqute.biz>
AuthorDate: Thu Jul 16 17:03:02 2020 +0200

    [configurator] Unchanged bundle does not obey force policy
    
    The force policy indicates that a bundle's configuration should
    always override any local changes.
    
    However, the code contained an optimization that if the configuration
    in a bundle was unchanged, it would ignore its configuration
    completely, ignoring any force policies.
    
    This patch overrides the optimization in ConfigList for records
    where the policy is set to force.
    
    - A test is added that failed on the current bundle and now passes
    - The OSGi Test Suite has been run on the code, the XML file is
      included in the patch
---
 .gitignore                                         |   4 +-
 ...TEST-org.osgi.test.cases.configurator-7.0.0.xml | 116 +++++++++++++++++++++
 .../felix/configurator/impl/model/ConfigList.java  |   5 +-
 .../felix/configurator/impl/ConfiguratorTest.java  |  34 ++++++
 configurator/src/test/resources/bundles/3.json     |   6 ++
 5 files changed, 163 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index a03bc09..3f1f936 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,6 @@ maven-eclipse.xml
 .idea/
 *~
 dependency-reduced-pom.xml
-.DS_Store
\ No newline at end of file
+.DS_Store
+/.metadata/
+/workspace/
diff --git a/configurator/TEST-org.osgi.test.cases.configurator-7.0.0.xml b/configurator/TEST-org.osgi.test.cases.configurator-7.0.0.xml
new file mode 100644
index 0000000..59e5eac
--- /dev/null
+++ b/configurator/TEST-org.osgi.test.cases.configurator-7.0.0.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<testsuite hostname="Zuse.local" name="test.org.osgi.test.cases.configurator" target="reference:file:/Users/aqute/Ws/apache/felix-dev/workspace/test-configurator/org.osgi.test.cases.configurator.jar" timestamp="2020-07-16T15:56:37.385" framework="org.eclipse.osgi_3.13.0.v20180409-1500 [0]" framework-version="3.13.0.v20180409-1500" tests="26" failures="0" errors="0" time="1.490">
+  <properties>
+    <property name="java.vendor" value="Azul Systems, Inc."/>
+    <property name="sun.java.launcher" value="SUN_STANDARD"/>
+    <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
+    <property name="os.name" value="Mac OS X"/>
+    <property name="sun.boot.class.path" value="/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Ho [...]
+    <property name="tester.continuous" value="false"/>
+    <property name="user.country.format" value="NL"/>
+    <property name="report" value="true"/>
+    <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
+    <property name="launcher.runpath" value="/Users/aqute/.m2/repository/org/slf4j/slf4j-simple/1.7.30/slf4j-simple-1.7.30.jar,/Users/aqute/.m2/repository/org/eclipse/platform/org.eclipse.osgi/3.13.0/org.eclipse.osgi-3.13.0.jar,/Users/aqute/Ws/apache/felix-dev/workspace/cnf/cache/5.2.0/bnd-cache/biz.aQute.launcher/biz.aQute.launcher-5.2.0.jar,/Users/aqute/Ws/apache/felix-dev/workspace/cnf/local/biz.aQute.junit/biz.aQute.junit-5.2.0.jar"/>
+    <property name="java.runtime.version" value="1.8.0_212-b04"/>
+    <property name="launch.services" value="true"/>
+    <property name="launch.notificationPort" value="-1"/>
+    <property name="launcher.properties" value="/Users/aqute/Ws/apache/felix-dev/workspace/test-configurator/target/launch7353276599438126822.properties"/>
+    <property name="org.osgi.test.cases.configurator.bundles" value="/Users/aqute/Ws/apache/felix-dev/workspace/test-configurator/target/test-configurator.jar,/Users/aqute/.m2/repository/org/glassfish/javax.json/1.1.4/javax.json-1.1.4.jar,/Users/aqute/.m2/repository/org/apache/felix/org.apache.felix.converter/1.0.12/org.apache.felix.converter-1.0.12.jar,/Users/aqute/.m2/repository/org/apache/felix/org.apache.felix.configadmin/1.9.16/org.apache.felix.configadmin-1.9.16.jar,/Users/aqute/.m [...]
+    <property name="user.name" value="aqute"/>
+    <property name="launch.bundles" value="/Users/aqute/Ws/apache/felix-dev/configurator/target/org.apache.felix.configurator-1.0.11-SNAPSHOT.jar,/Users/aqute/Ws/apache/felix-dev/workspace/test-configurator/target/test-configurator.jar,/Users/aqute/.m2/repository/org/apache/felix/org.apache.felix.cm.json/1.0.2/org.apache.felix.cm.json-1.0.2.jar,/Users/aqute/.m2/repository/org/apache/felix/org.apache.felix.configadmin/1.9.16/org.apache.felix.configadmin-1.9.16.jar,/Users/aqute/.m2/reposit [...]
+    <property name="equinox.use.ds" value="true"/>
+    <property name="tester.trace" value="true"/>
+    <property name="user.language" value="en"/>
+    <property name="sun.boot.library.path" value="/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib"/>
+    <property name="org.osgi.framework.system.capabilities.extra" value="osgi.contract;osgi.contract=JavaJSONP;version:Version=&quot;1.1.0&quot;,osgi.native;osgi.native.osname:List&lt;String&gt;=&quot;MacOSX,Mac OS X&quot;;osgi.native.osversion:Version=&quot;10.15.5&quot;;osgi.native.processor:List&lt;String&gt;=&quot;x86-64,amd64,em64t,x86_64&quot;;osgi.native.language=en_US"/>
+    <property name="java.version" value="1.8.0_212"/>
+    <property name="user.timezone" value="Europe/Paris"/>
+    <property name="launch.framework.restart.count" value="0"/>
+    <property name="tester.dir" value="/Users/aqute/Ws/apache/felix-dev/workspace/test-configurator/target/test-reports"/>
+    <property name="sun.arch.data.model" value="64"/>
+    <property name="tester.unresolved" value="true"/>
+    <property name="http.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
+    <property name="java.endorsed.dirs" value="/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/endorsed"/>
+    <property name="sun.cpu.isalist" value=""/>
+    <property name="sun.jnu.encoding" value="UTF-8"/>
+    <property name="file.encoding.pkg" value="sun.io"/>
+    <property name="launch.noreferences" value="false"/>
+    <property name="org.osgi.framework.storage.clean" value="onFirstInit"/>
+    <property name="file.separator" value="/"/>
+    <property name="java.specification.name" value="Java Platform API Specification"/>
+    <property name="java.class.version" value="52.0"/>
+    <property name="user.country" value="US"/>
+    <property name="java.home" value="/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre"/>
+    <property name="java.vm.info" value="mixed mode"/>
+    <property name="os.version" value="10.15.5"/>
+    <property name="path.separator" value=":"/>
+    <property name="java.vm.version" value="25.212-b04"/>
+    <property name="java.awt.printerjob" value="sun.lwawt.macosx.CPrinterJob"/>
+    <property name="sun.io.unicode.encoding" value="UnicodeBig"/>
+    <property name="awt.toolkit" value="sun.lwawt.macosx.LWCToolkit"/>
+    <property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
+    <property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
+    <property name="user.home" value="/Users/aqute"/>
+    <property name="java.specification.vendor" value="Oracle Corporation"/>
+    <property name="java.library.path" value="/Users/aqute/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:."/>
+    <property name="java.vendor.url" value="http://www.azulsystems.com/"/>
+    <property name="launch.framework.restart" value="false"/>
+    <property name="java.vm.vendor" value="Azul Systems, Inc."/>
+    <property name="gopherProxySet" value="false"/>
+    <property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
+    <property name="tester.port" value="53957"/>
+    <property name="sun.java.command" value="aQute.launcher.pre.EmbeddedLauncher"/>
+    <property name="java.class.path" value="/Users/aqute/Ws/apache/felix-dev/workspace/cnf/cache/5.2.0/bnd-cache/biz.aQute.launcher/biz.aQute.launcher.pre.jar"/>
+    <property name="launch.system.capabilities" value="osgi.contract;osgi.contract=JavaJSONP;version:Version=&quot;1.1.0&quot;,osgi.native;osgi.native.osname:List&lt;String&gt;=&quot;MacOSX,Mac OS X&quot;;osgi.native.osversion:Version=&quot;10.15.5&quot;;osgi.native.processor:List&lt;String&gt;=&quot;x86-64,amd64,em64t,x86_64&quot;;osgi.native.language=en_US"/>
+    <property name="launch.name" value="bnd.bnd"/>
+    <property name="launch.timeout" value="0"/>
+    <property name="launch.keep" value="false"/>
+    <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
+    <property name="java.vm.specification.version" value="1.8"/>
+    <property name="sun.cpu.endian" value="little"/>
+    <property name="sun.os.patch.level" value="unknown"/>
+    <property name="java.io.tmpdir" value="/var/folders/z8/0_lqm23n62s80gq9hwt7zy200000gq/T/"/>
+    <property name="java.vendor.url.bug" value="http://www.azulsystems.com/support/"/>
+    <property name="launch.activation.eager" value="false"/>
+    <property name="java.awt.graphicsenv" value="sun.awt.CGraphicsEnvironment"/>
+    <property name="os.arch" value="x86_64"/>
+    <property name="java.ext.dirs" value="/Users/aqute/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java"/>
+    <property name="user.dir" value="/Users/aqute/Ws/apache/felix-dev/workspace/test-configurator"/>
+    <property name="launch.trace" value="true"/>
+    <property name="line.separator" value="
+"/>
+    <property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
+    <property name="launch.embedded" value="false"/>
+    <property name="org.osgi.framework.system.packages.extra" value="org.slf4j.impl;version=&quot;1.7.30&quot;,org.eclipse.core.runtime.adaptor;x-friends:=&quot;org.eclipse.core.runtime&quot;,org.eclipse.core.runtime.internal.adaptor;x-internal:=true,org.eclipse.equinox.log;version=&quot;1.0&quot;;uses:=&quot;org.osgi.framework,org.osgi.service.log&quot;,org.eclipse.osgi.container;version=&quot;1.3&quot;;uses:=&quot;org.eclipse.osgi.report.resolution,  org.osgi.framework.wiring,  org.osg [...]
+    <property name="launch.activators" value="aQute.junit.Activator"/>
+    <property name="file.encoding" value="UTF-8"/>
+    <property name="launch.system.packages" value="org.slf4j.impl;version=&quot;1.7.30&quot;,org.eclipse.core.runtime.adaptor;x-friends:=&quot;org.eclipse.core.runtime&quot;,org.eclipse.core.runtime.internal.adaptor;x-internal:=true,org.eclipse.equinox.log;version=&quot;1.0&quot;;uses:=&quot;org.osgi.framework,org.osgi.service.log&quot;,org.eclipse.osgi.container;version=&quot;1.3&quot;;uses:=&quot;org.eclipse.osgi.report.resolution,  org.osgi.framework.wiring,  org.osgi.framework.startl [...]
+    <property name="java.specification.version" value="1.8"/>
+  </properties>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorInitTestCase" name="testInitialConfigRequiresVersion" time="0.115"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorInitTestCase" name="testInitialConfigRequiresSymbolicname" time="0.74"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorInitTestCase" name="testInitialConfigFile" time="0.88"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorInitTestCase" name="testInitialConfig" time="0.79"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testExplicitDatatypes" time="0.81"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testCollectionsImplicit" time="0.17"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testForceOverwrite2" time="0.61"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testNoRequirement" time="0.3"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testForceOverwrite" time="0.12"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testArraysSpecificBoxed" time="0.50"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testOverwriteRemove" time="0.52"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testConfigNestingForce" time="0.46"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testOverwrite" time="0.24"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testArraysSpecificPrimitive" time="0.41"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testFactoryConfigurations" time="0.43"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testConfigNestingNoForce" time="0.64"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testRanking" time="0.33"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testImplicitDatatypes" time="0.46"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testArraysBasic" time="0.8"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testCollectionsSpecific" time="0.15"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testIgnoreRemove" time="0.46"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testUpdateConfigBundle" time="0.47"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testIgnoreComments" time="0.46"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testBinaries" time="0.19"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testBasicConfigurationLifecycle" time="0.96"/>
+  <testcase classname="org.osgi.test.cases.configurator.junit.ConfiguratorTestCase" name="testIgnoreOverwrite" time="0.5"/>
+</testsuite>
\ No newline at end of file
diff --git a/configurator/src/main/java/org/apache/felix/configurator/impl/model/ConfigList.java b/configurator/src/main/java/org/apache/felix/configurator/impl/model/ConfigList.java
index 7cd0c57..8d43696 100644
--- a/configurator/src/main/java/org/apache/felix/configurator/impl/model/ConfigList.java
+++ b/configurator/src/main/java/org/apache/felix/configurator/impl/model/ConfigList.java
@@ -118,7 +118,10 @@ public class ConfigList implements Serializable, Iterable<Config> {
                 if ( current.getBundleId() == cfg.getBundleId()
                   && current.getProperties().equals(cfg.getProperties()) ) {
                     if ( current.getState() == ConfigState.UNINSTALL ) {
-                        cfg.setState(ConfigState.INSTALLED);
+                    	
+                    	if ( cfg.getPolicy()!=ConfigPolicy.FORCE)
+                    		cfg.setState(ConfigState.INSTALLED);
+                    	
                         current.setState(ConfigState.UNINSTALLED);
                     }
                     break;
diff --git a/configurator/src/test/java/org/apache/felix/configurator/impl/ConfiguratorTest.java b/configurator/src/test/java/org/apache/felix/configurator/impl/ConfiguratorTest.java
index f67628d..9410cee 100644
--- a/configurator/src/test/java/org/apache/felix/configurator/impl/ConfiguratorTest.java
+++ b/configurator/src/test/java/org/apache/felix/configurator/impl/ConfiguratorTest.java
@@ -20,6 +20,7 @@ package org.apache.felix.configurator.impl;
 
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -109,6 +110,39 @@ public class ConfiguratorTest {
         when(bundleContext.getBundle(id)).thenReturn(b);
         return b;
     }
+    
+    @Test public void testUpdateForceWithoutBundleChanges() throws Exception {
+        final Bundle bV1 = setupBundle(3, "3");
+        final Bundle bV2 = setupBundle(3, "3");
+        when(bV2.getLastModified()).thenReturn(lastModified);
+        lastModified++;
+
+        Configuration a = mock(Configuration.class);
+        when(configurationAdmin.getConfiguration("a", "?")).thenReturn(a);
+
+        when(a.getChangeCount()).thenReturn(1L);
+        configurator.processAddBundle(bV1);
+        configurator.process();
+
+        when(configurationAdmin.listConfigurations("(" + Constants.SERVICE_PID + "=a)"))
+                .thenReturn(new Configuration[] { a });
+
+        final Dictionary<String, Object> aProps = new Hashtable<>();
+        aProps.put("foo", "foo");
+        verify(a).updateIfDifferent(aProps);
+
+        final Dictionary<String, Object> modifiedOutside = new Hashtable<>();
+        modifiedOutside.put("foo", "bar");
+        when(a.getProperties()).thenReturn(modifiedOutside);
+
+        when(a.getChangeCount()).thenReturn(2L);
+
+        verify(a, times(1)).updateIfDifferent(aProps);
+
+        configurator.processAddBundle(bV2);
+        configurator.process();
+        verify(a, times(2)).updateIfDifferent(aProps);
+    }
 
     @Test public void testSimpleAddRemove() throws Exception {
         final Bundle b = setupBundle(1);
diff --git a/configurator/src/test/resources/bundles/3.json b/configurator/src/test/resources/bundles/3.json
new file mode 100644
index 0000000..d18d6ad
--- /dev/null
+++ b/configurator/src/test/resources/bundles/3.json
@@ -0,0 +1,6 @@
+{
+    "a" : {
+              ":configurator:policy" : "force",
+              "foo" : "foo"
+          }
+}