You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2017/09/19 11:00:45 UTC
[1/4] incubator-tamaya-sandbox git commit: TAMAYA-297: Added,
improved commands, improved formatting of table styled outputs.
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/java8 920538603 -> 54ff0e6f0
TAMAYA-297: Added, improved commands, improved formatting of table styled outputs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/cdd839ce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/cdd839ce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/cdd839ce
Branch: refs/heads/java8
Commit: cdd839ceb4ba73cee32f0cecb0175b26c8ca4cfd
Parents: 9205386
Author: anatole <an...@apache.org>
Authored: Tue Sep 19 12:57:10 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Sep 19 12:57:10 2017 +0200
----------------------------------------------------------------------
osgi/karaf-shell/pom.xml | 7 +-
.../karaf/shell/DefaultDisableCommand.java | 3 +-
.../karaf/shell/EvaluateCMConfigCommand.java | 63 ----------
.../tamaya/karaf/shell/GetPolicyCommand.java | 2 +-
.../tamaya/karaf/shell/HistoryClearCommand.java | 69 +++++++++++
.../tamaya/karaf/shell/HistoryGetCommand.java | 116 +++++++++++++++++++
.../apache/tamaya/karaf/shell/InfoCommand.java | 4 +-
.../tamaya/karaf/shell/PolicyGetCommand.java | 49 ++++++++
.../tamaya/karaf/shell/PolicySetCommand.java | 70 +++++++++++
.../tamaya/karaf/shell/PropertyCommand.java | 75 ------------
.../tamaya/karaf/shell/PropertyGetCommand.java | 86 ++++++++++++++
.../karaf/shell/PropertySourceCommand.java | 16 ++-
.../karaf/shell/PropertySourcesCommand.java | 13 ++-
.../tamaya/karaf/shell/SetPolicyCommand.java | 68 -----------
.../apache/tamaya/karaf/shell/StringUtil.java | 46 ++++++++
.../org/apache/tamaya/karaf/shell/commands | 15 ++-
16 files changed, 478 insertions(+), 224 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/pom.xml b/osgi/karaf-shell/pom.xml
index cb857dc..e7c1558 100644
--- a/osgi/karaf-shell/pom.xml
+++ b/osgi/karaf-shell/pom.xml
@@ -29,7 +29,7 @@
<artifactId>tamaya-karaf-shell_alpha</artifactId>
<packaging>jar</packaging>
- <name>Apache Tamaya :: Karaf :: Shell</name>
+ <name>Apache Tamaya :: OSGI :: Karaf :: Shell</name>
<description>Tamaya Karaf Shell Commands</description>
<dependencies>
@@ -44,6 +44,11 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.core</artifactId>
<version>${dependency.karaf.version}</version>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultDisableCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultDisableCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultDisableCommand.java
index 0c14da5..99461dc 100644
--- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultDisableCommand.java
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/DefaultDisableCommand.java
@@ -28,6 +28,7 @@ import org.apache.karaf.shell.api.console.CommandLine;
import org.apache.karaf.shell.api.console.Completer;
import org.apache.karaf.shell.api.console.Session;
import org.apache.karaf.shell.support.completers.StringsCompleter;
+import org.apache.tamaya.osgi.OperationMode;
import org.apache.tamaya.osgi.TamayaConfigPlugin;
import java.io.IOException;
@@ -58,7 +59,7 @@ public class DefaultDisableCommand implements Action{
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
StringsCompleter delegate = new StringsCompleter();
- for(TamayaConfigPlugin.OperationMode mode:TamayaConfigPlugin.OperationMode.values()) {
+ for(OperationMode mode: OperationMode.values()) {
delegate.getStrings().add(mode.toString());
}
return delegate.complete(session, commandLine, candidates);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/EvaluateCMConfigCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/EvaluateCMConfigCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/EvaluateCMConfigCommand.java
deleted file mode 100644
index d22022a..0000000
--- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/EvaluateCMConfigCommand.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.tamaya.karaf.shell;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-
-import java.io.IOException;
-
-@Command(scope = "tamaya", name = "cm-config", description="Show the current Tamaya configuration.")
-@Service
-public class EvaluateCMConfigCommand implements Action{
-
- @Argument(index = 0, name = "pid", description = "The component's PID.",
- required = true, multiValued = false)
- String pid = null;
-
- @Argument(index = 1, name = "location", description = "The component's configuration location.",
- required = false, multiValued = false)
- String location = null;
-
- @Reference
- private ConfigurationAdmin cm;
-
- public Object execute() throws IOException {
- Configuration config = cm.getConfiguration(pid, location);
- System.out.println("OSGI Configuration for PID: " + pid);
- System.out.println("----------------------------------------------------------");
- if(config!=null){
- System.out.println("PID: " + config.getPid());
- System.out.println("Factory-PID: " + config.getFactoryPid());
- System.out.println("Location: " + config.getBundleLocation());
- System.out.println("Change Count: " + config.getChangeCount());
- System.out.println("Properties:");
- System.out.println(config.getProperties());
- }else{
- System.out.println("No OSGI Config found for PID: " + config.getPid());
- }
- return null;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/GetPolicyCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/GetPolicyCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/GetPolicyCommand.java
index 3f1f1f0..42ebbd1 100644
--- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/GetPolicyCommand.java
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/GetPolicyCommand.java
@@ -35,7 +35,7 @@ public class GetPolicyCommand implements Action{
@Override
public Object execute() throws IOException {
- System.out.println(this.configPlugin.getOperationMode());
+ System.out.println(this.configPlugin.getDefaultOperationMode());
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryClearCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryClearCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryClearCommand.java
new file mode 100644
index 0000000..93f0dc2
--- /dev/null
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryClearCommand.java
@@ -0,0 +1,69 @@
+/*
+ * 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.tamaya.karaf.shell;
+
+import org.apache.karaf.shell.api.action.*;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+import org.apache.tamaya.osgi.ConfigHistory;
+import org.apache.tamaya.osgi.TamayaConfigPlugin;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+@Command(scope = "tamaya", name = "history-delete", description="Deletes the history of changes Tamaya applied to the OSGI configuration.")
+@Service
+public class HistoryClearCommand implements Action{
+
+ @Reference
+ private TamayaConfigPlugin configPlugin;
+
+ @Argument(index = 0, name = "pid", description = "Allows to filter on the given PID.",
+ required = false, multiValued = false)
+ String pid;
+
+ @Override
+ public Object execute() throws IOException {
+ int size = ConfigHistory.history(pid).size();
+ ConfigHistory.clearHistory(pid);
+ System.out.println("Deleted entries: " + size);
+ return null;
+ }
+
+ @Service
+ public static final class FilterCompleter implements Completer {
+
+ @Override
+ public int complete(Session session, CommandLine commandLine, List<String> candidates) {
+ StringsCompleter delegate = new StringsCompleter();
+ for(ConfigHistory.TaskType taskType:ConfigHistory.TaskType.values()) {
+ delegate.getStrings().add(taskType.toString());
+ }
+ return delegate.complete(session, commandLine, candidates);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryGetCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryGetCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryGetCommand.java
new file mode 100644
index 0000000..fd60c48
--- /dev/null
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryGetCommand.java
@@ -0,0 +1,116 @@
+/*
+ * 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.tamaya.karaf.shell;
+
+import org.apache.karaf.shell.api.action.*;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+import org.apache.tamaya.osgi.ConfigHistory;
+import org.apache.tamaya.osgi.TamayaConfigPlugin;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+@Command(scope = "tamaya", name = "history-get", description="Gets the history of changes Tamaya applied to the OSGI configuration.")
+@Service
+public class HistoryGetCommand implements Action{
+
+ @Reference
+ private TamayaConfigPlugin configPlugin;
+
+ @Argument(index = 0, name = "pid", description = "Allows to filter on the given PID.",
+ required = false, multiValued = false)
+ String pid;
+
+ @Option(name = "--type", aliases = "-t", description = "Allows to filter the events types shown.",
+ required = false, multiValued = true)
+ @Completion(FilterCompleter.class)
+ private String[] eventTypes;
+
+ @Override
+ public Object execute() throws IOException {
+ List<ConfigHistory> history = ConfigHistory.history(pid);
+ history = filterTypes(history);
+ System.out.print(StringUtil.format("Typ", 10));
+ System.out.print(StringUtil.format("PID", 30));
+ System.out.print(StringUtil.format("Key", 30));
+ System.out.print(StringUtil.format("Value", 40));
+ System.out.println(StringUtil.format("Previous Value", 40));
+ System.out.println(StringUtil.printRepeat("-", 140));
+ for(ConfigHistory h:history){
+ System.out.print(StringUtil.format(h.getType().toString(), 10));
+ System.out.print(StringUtil.format(h.getPid(), 30));
+ System.out.print(StringUtil.format(h.getKey(), 30));
+ System.out.print(StringUtil.format(String.valueOf(h.getValue()), 40));
+ System.out.println(String.valueOf(h.getPreviousValue()));
+ }
+ return null;
+ }
+
+ private List<ConfigHistory> filterPid(List<ConfigHistory> history) {
+ if(pid==null){
+ return history;
+ }
+ List<ConfigHistory> result = new ArrayList<>();
+ for(ConfigHistory h:history){
+ if(h.getPid().equals(pid)){
+ result.add(h);
+ }
+ }
+ return result;
+ }
+
+ private List<ConfigHistory> filterTypes(List<ConfigHistory> history) {
+ if(eventTypes==null){
+ return history;
+ }
+ List<ConfigHistory> result = new ArrayList<>();
+ Set<ConfigHistory.TaskType> types = new HashSet<>();
+ for(String tVal:eventTypes) {
+ types.add(ConfigHistory.TaskType.valueOf(tVal));
+ }
+ for(ConfigHistory h:history){
+ if(types.contains(h.getType())){
+ result.add(h);
+ }
+ }
+ return result;
+ }
+
+ @Service
+ public static final class FilterCompleter implements Completer {
+
+ @Override
+ public int complete(Session session, CommandLine commandLine, List<String> candidates) {
+ StringsCompleter delegate = new StringsCompleter();
+ for(ConfigHistory.TaskType taskType:ConfigHistory.TaskType.values()) {
+ delegate.getStrings().add(taskType.toString());
+ }
+ return delegate.complete(session, commandLine, candidates);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/InfoCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/InfoCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/InfoCommand.java
index f9dafed..d50e97b 100644
--- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/InfoCommand.java
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/InfoCommand.java
@@ -38,8 +38,8 @@ public class InfoCommand implements Action {
public Object execute() throws IOException {
Configuration config = ConfigurationProvider.getConfiguration();
System.out.println(config.toString() + "\n\n"
- + "OSGI OperationPolicy: " + configPlugin.getOperationMode() + '\n'
- + "Default Disabled : " + configPlugin.isDefaultDisabled());
+ + StringUtil.format("Default OperationMode:", 30) + configPlugin.getDefaultOperationMode() + '\n'
+ + StringUtil.format("Default Disabled: ", 30) + configPlugin.isDefaultDisabled());
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicyGetCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicyGetCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicyGetCommand.java
new file mode 100644
index 0000000..350c802
--- /dev/null
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicyGetCommand.java
@@ -0,0 +1,49 @@
+/*
+ * 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.tamaya.karaf.shell;
+
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+import org.apache.tamaya.osgi.TamayaConfigPlugin;
+
+import java.io.IOException;
+import java.util.List;
+
+@Command(scope = "tamaya", name = "policy-get", description="Gets the current Tamaya operation policy.")
+@Service
+public class PolicyGetCommand implements Action{
+
+ @Reference
+ private TamayaConfigPlugin configPlugin;
+
+ @Override
+ public Object execute() throws IOException {
+ System.out.println(this.configPlugin.getDefaultOperationMode());
+ return null;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicySetCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicySetCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicySetCommand.java
new file mode 100644
index 0000000..7e2af6a
--- /dev/null
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PolicySetCommand.java
@@ -0,0 +1,70 @@
+/*
+ * 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.tamaya.karaf.shell;
+
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+import org.apache.tamaya.osgi.OperationMode;
+import org.apache.tamaya.osgi.TamayaConfigPlugin;
+
+import java.io.IOException;
+import java.util.List;
+
+@Command(scope = "tamaya", name = "policy-set", description="Sets the current Tamaya operation policy.")
+@Service
+public class PolicySetCommand implements Action{
+
+ @Reference
+ private TamayaConfigPlugin configPlugin;
+
+ @Argument(index = 0, name = "operationPolicy", description = "The operation policy how Tamaya intercepts OSGI configuration.",
+ required = true, multiValued = false)
+ @Completion(OperationModeCompleter.class)
+ String policy = null;
+
+ @Override
+ public Object execute() throws IOException {
+ OperationMode opMode = OperationMode.valueOf(policy);
+ this.configPlugin.setDefaultOperationMode(opMode);
+ System.out.println("OperationMode="+opMode.toString());
+ return null;
+ }
+
+ @Service
+ public static final class OperationModeCompleter implements Completer {
+
+ @Override
+ public int complete(Session session, CommandLine commandLine, List<String> candidates) {
+ StringsCompleter delegate = new StringsCompleter();
+ for(OperationMode mode:OperationMode.values()) {
+ delegate.getStrings().add(mode.toString());
+ }
+ return delegate.complete(session, commandLine, candidates);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyCommand.java
deleted file mode 100644
index 04c792e..0000000
--- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyCommand.java
+++ /dev/null
@@ -1,75 +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.tamaya.karaf.shell;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.functions.ConfigurationFunctions;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.io.IOException;
-
-@Command(scope = "tamaya", name = "property", description="Show the current Tamaya configuration.")
-@Service
-public class PropertyCommand implements Action{
-
- @Argument(index = 0, name = "key", description = "The target property source id.",
- required = false, multiValued = false)
- String key = null;
-
- @Option(name = "propertysource", aliases = "ps", description = "The target property source id.",
- required = false, multiValued = false)
- String propertysource = null;
-
- public Object execute() throws IOException {
- Configuration config = ConfigurationProvider.getConfiguration();
- if(propertysource!=null){
- PropertySource ps = config.getContext().getPropertySource(propertysource);
- if(ps==null){
- System.out.println("No such propertysource: " + propertysource);
- }else {
- PropertyValue val = ps.get(key);
- if(val==null){
- System.out.println("PropertySource: " + propertysource + "\nUndefined key: " + key);
- }else {
- System.out.println("PropertySource: " + propertysource + "\n" +
- ps.get(key));
- }
- }
- }else{
- for(PropertySource ps:config.getContext().getPropertySources()){
- PropertyValue val = ps.get(key);
- if(val==null){
- System.out.println("PropertySource: " + propertysource + "\nUndefined key: " + key);
- }else {
- System.out.println("PropertySource: " + propertysource + "\n" +
- ps.get(key));
- }
- }
- }
- return null;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyGetCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyGetCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyGetCommand.java
new file mode 100644
index 0000000..061bcfe
--- /dev/null
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertyGetCommand.java
@@ -0,0 +1,86 @@
+/*
+ * 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.tamaya.karaf.shell;
+
+import org.apache.commons.codec.binary.StringUtils;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.util.StringEscapeUtils;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.io.IOException;
+
+@Command(scope = "tamaya", name = "property-get", description="Get a Tamaya property.")
+@Service
+public class PropertyGetCommand implements Action{
+
+ @Argument(index = 0, name = "key", description = "The target property source id.",
+ required = false, multiValued = false)
+ String key = null;
+
+ @Option(name="extended", aliases = "e", description = "Also print extended property value attributes.")
+ boolean extended;
+
+ @Option(name = "propertysource", aliases = "ps", description = "The target property source id.",
+ required = false, multiValued = false)
+ String propertysource = null;
+
+ public Object execute() throws IOException {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ if(propertysource!=null){
+ PropertySource ps = config.getContext().getPropertySource(propertysource);
+ if(ps==null){
+ System.out.println("ERR: No such propertysource: " + propertysource);
+ }else {
+ PropertyValue val = ps.get(key);
+ if(val==null){
+ System.out.println("ERR: PropertySource: " + propertysource + " - undefined key: " + key);
+ }else {
+ if(extended) {
+ System.out.println(StringUtil.format("PropertySource", 25) + StringUtil.format("Value", 25));
+ System.out.println(StringUtil.format(propertysource, 25) + StringUtil.format(val.getValue(), 55));
+ }else{
+ System.out.println(val.getValue());
+ }
+ }
+ }
+ }else{
+ System.out.println(StringUtil.format("PropertySource", 25) + StringUtil.format("Value", 25));
+ for(PropertySource ps:config.getContext().getPropertySources()){
+ PropertyValue val = ps.get(key);
+ if(val!=null){
+ if(extended) {
+ System.out.println(StringUtil.format(propertysource, 25) + StringUtil.format(val.toString(), 55));
+ }else{
+ System.out.println(StringUtil.format(propertysource, 25) + StringUtil.format(val.getValue(), 55));
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourceCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourceCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourceCommand.java
index fc42c54..c3e1c57 100644
--- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourceCommand.java
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourceCommand.java
@@ -44,12 +44,20 @@ public class PropertySourceCommand implements Action{
if(ps==null){
System.out.println("No such propertysource: " + propertysource);
}else {
- System.out.println("ID: " + ps.getName());
- System.out.println("Ordinal: " + ps.getOrdinal());
- System.out.println("Class: " + ps.getClass().getName());
+ System.out.println(StringUtil.format("ID:", 20) + ps.getName());
+ System.out.println(StringUtil.format("Ordinal:", 20) + ps.getOrdinal());
+ System.out.println(StringUtil.format("Class:", 20) + ps.getClass().getName());
System.out.println("Properties:");
+ System.out.print(StringUtil.format(" Key", 20));
+ System.out.print(StringUtil.format("Value", 20));
+ System.out.print(StringUtil.format("Source", 20));
+ System.out.println(StringUtil.format("Meta-Entries", 20));
+ System.out.println(StringUtil.printRepeat("-", 80));
for(PropertyValue pv:ps.getProperties().values()) {
- System.out.println(pv);
+ System.out.print(" " + StringUtil.format(pv.getKey(), 20));
+ System.out.print(StringUtil.format(pv.getValue(), 20));
+ System.out.print(StringUtil.format(pv.getSource(), 20));
+ System.out.println(StringUtil.format(pv.getMetaEntries().toString(), 80));
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java
index 74c5985..60289b9 100644
--- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java
@@ -35,11 +35,16 @@ public class PropertySourcesCommand implements Action{
public Object execute() throws IOException {
Configuration config = ConfigurationProvider.getConfiguration();
+ System.out.print(StringUtil.format("ID", 20));
+ System.out.print(StringUtil.format("Ordinal", 20));
+ System.out.print(StringUtil.format("Class", 40));
+ System.out.println(StringUtil.format("Property Count", 5));
+ System.out.println(StringUtil.printRepeat("-", 80));
for(PropertySource ps:config.getContext().getPropertySources()){
- System.out.println("ID: " + ps.getName());
- System.out.println("Ordinal: " + ps.getOrdinal());
- System.out.println("Class: " + ps.getClass().getName());
- System.out.println("Property Count:" + ps.getProperties().size());
+ System.out.print(StringUtil.format(ps.getName(), 20));
+ System.out.print(StringUtil.format(String.valueOf(ps.getOrdinal()), 20));
+ System.out.print(StringUtil.format(ps.getClass().getName(), 40));
+ System.out.println(StringUtil.format(String.valueOf(ps.getProperties().size()), 5));
System.out.println("---");
}
return null;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/SetPolicyCommand.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/SetPolicyCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/SetPolicyCommand.java
deleted file mode 100644
index 0a22c81..0000000
--- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/SetPolicyCommand.java
+++ /dev/null
@@ -1,68 +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.tamaya.karaf.shell;
-
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Completion;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.api.console.CommandLine;
-import org.apache.karaf.shell.api.console.Completer;
-import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.support.completers.StringsCompleter;
-import org.apache.tamaya.osgi.TamayaConfigPlugin;
-
-import java.io.IOException;
-import java.util.List;
-
-@Command(scope = "tamaya", name = "set-policy", description="Sets the current Tamaya overriding policy.")
-@Service
-public class SetPolicyCommand implements Action{
-
- @Reference
- private TamayaConfigPlugin configPlugin;
-
- @Argument(index = 0, name = "operationPolicy", description = "The operation policy how Tamaya intercepts OSGI configuration.",
- required = true, multiValued = false)
- @Completion(OperationModeCompleter.class)
- String policy = null;
-
- @Override
- public Object execute() throws IOException {
- TamayaConfigPlugin.OperationMode opMode = TamayaConfigPlugin.OperationMode.valueOf(policy);
- this.configPlugin.setOperationMode(opMode);
- return null;
- }
-
- @Service
- public static final class OperationModeCompleter implements Completer {
-
- @Override
- public int complete(Session session, CommandLine commandLine, List<String> candidates) {
- StringsCompleter delegate = new StringsCompleter();
- for(TamayaConfigPlugin.OperationMode mode:TamayaConfigPlugin.OperationMode.values()) {
- delegate.getStrings().add(mode.toString());
- }
- return delegate.complete(session, commandLine, candidates);
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/StringUtil.java
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/StringUtil.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/StringUtil.java
new file mode 100644
index 0000000..f32144b
--- /dev/null
+++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/StringUtil.java
@@ -0,0 +1,46 @@
+/*
+ * 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.tamaya.karaf.shell;
+
+/**
+ * Some String related helper methods.
+ */
+final class StringUtil {
+
+ private StringUtil(){}
+
+ public static String format(String in, int length){
+ if(in==null){
+ in = "";
+ }
+ int count = length - in.length();
+ if(count<0){
+ return in.substring(0,length-3) + "...";
+ }
+ return in + printRepeat(" ", count);
+ }
+
+ public static String printRepeat(String s, int times) {
+ StringBuilder b = new StringBuilder();
+ for(int i=0;i<times;i++){
+ b.append(s);
+ }
+ return b.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cdd839ce/osgi/karaf-shell/src/main/resources/META-INF/services/org/apache/tamaya/karaf/shell/commands
----------------------------------------------------------------------
diff --git a/osgi/karaf-shell/src/main/resources/META-INF/services/org/apache/tamaya/karaf/shell/commands b/osgi/karaf-shell/src/main/resources/META-INF/services/org/apache/tamaya/karaf/shell/commands
index 7c9fb12..d8f2000 100644
--- a/osgi/karaf-shell/src/main/resources/META-INF/services/org/apache/tamaya/karaf/shell/commands
+++ b/osgi/karaf-shell/src/main/resources/META-INF/services/org/apache/tamaya/karaf/shell/commands
@@ -17,11 +17,16 @@
# under the License.
#
org.apache.tamaya.karaf.shell.ConfigCommand
-org.apache.tamaya.karaf.shell.EvaluateCMConfigCommand
+org.apache.tamaya.karaf.shell.DefaultDisableCommand
+org.apache.tamaya.karaf.shell.GetPolicyCommand
+org.apache.tamaya.karaf.shell.HistoryClearCommand
+org.apache.tamaya.karaf.shell.HistoryGetCommand
org.apache.tamaya.karaf.shell.InfoCommand
-org.apache.tamaya.karaf.shell.PropertyCommand
+org.apache.tamaya.karaf.shell.PolicyGetCommand
+org.apache.tamaya.karaf.shell.PolicySetCommand
+org.apache.tamaya.karaf.shell.PropertyGetCommand
org.apache.tamaya.karaf.shell.PropertySourceCommand
org.apache.tamaya.karaf.shell.PropertySourcesCommand
-org.apache.tamaya.karaf.shell.SetPolicyCommand
-org.apache.tamaya.karaf.shell.GetPolicyCommand
-org.apache.tamaya.karaf.shell.DefaultDisableCommand
+
+
+
[3/4] incubator-tamaya-sandbox git commit: TAMAYA-300: Simplified
naming.
Posted by an...@apache.org.
TAMAYA-300: Simplified naming.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/39143de0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/39143de0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/39143de0
Branch: refs/heads/java8
Commit: 39143de0458ca53625ee56b234bf202a432a3214
Parents: cbd2312
Author: anatole <an...@apache.org>
Authored: Tue Sep 19 12:59:54 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Sep 19 12:59:54 2017 +0200
----------------------------------------------------------------------
osgi/common/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/39143de0/osgi/common/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/common/pom.xml b/osgi/common/pom.xml
index 9455104..fdcb7f3 100644
--- a/osgi/common/pom.xml
+++ b/osgi/common/pom.xml
@@ -29,7 +29,7 @@
<artifactId>tamaya-osgi_alpha</artifactId>
<packaging>jar</packaging>
- <name>Apache Tamaya :: OSGi Integration :: ConfigurationPlugin</name>
+ <name>Apache Tamaya :: OSGi :: ConfigurationPlugin</name>
<description>Tamaya Based OSGI ConfigurationPlugin Implementation</description>
<dependencies>
[2/4] incubator-tamaya-sandbox git commit: TAMAYA-300: Added config
history. DId a small refactoring.
Posted by an...@apache.org.
TAMAYA-300: Added config history. DId a small refactoring.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/cbd23125
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/cbd23125
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/cbd23125
Branch: refs/heads/java8
Commit: cbd23125f7f47186b651f0ff6bd0e1a1e50a4b78
Parents: cdd839c
Author: anatole <an...@apache.org>
Authored: Tue Sep 19 12:59:30 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Sep 19 12:59:30 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/tamaya/osgi/Activator.java | 9 +-
.../org/apache/tamaya/osgi/ConfigChanger.java | 170 +++++++++++++
.../org/apache/tamaya/osgi/ConfigHistory.java | 168 +++++++++++++
.../org/apache/tamaya/osgi/OperationMode.java | 31 +++
.../apache/tamaya/osgi/TamayaConfigPlugin.java | 250 +++++++------------
.../tamaya/osgi/TamayaConfigPluginTest.java | 75 ++++++
6 files changed, 542 insertions(+), 161 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cbd23125/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
index d6c5726..a1522a1 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java
@@ -44,7 +44,9 @@ public class Activator implements BundleActivator {
private static final Logger LOG = Logger.getLogger(Activator.class.getName());
- private ServiceRegistration<?> registration;
+ private ServiceRegistration<TamayaConfigPlugin> registration;
+
+ private TamayaConfigPlugin plugin;
@Override
@@ -71,11 +73,11 @@ public class Activator implements BundleActivator {
LOG.fine("Using custom ranking for Tamaya OSGI Config plugin: " + ranking);
}
props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
- TamayaConfigPlugin plugin = new TamayaConfigPlugin(context);
+ this.plugin = new TamayaConfigPlugin(context);
LOG.info("Registering Tamaya OSGI Config plugin with ranking: " + ranking);
registration = context.registerService(
TamayaConfigPlugin.class,
- plugin, props);
+ this.plugin, props);
LOG.info("Registered Tamaya OSGI Config plugin.");
configuration.update(props);
}
@@ -83,6 +85,7 @@ public class Activator implements BundleActivator {
@Override
public void stop(BundleContext context) throws Exception {
if (registration != null) {
+ context.removeBundleListener(this.plugin);
registration.unregister();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cbd23125/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
new file mode 100644
index 0000000..29c4720
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigChanger.java
@@ -0,0 +1,170 @@
+/*
+ * 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.tamaya.osgi;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Created by atsticks on 19.09.17.
+ */
+final class ConfigChanger {
+
+ private static final Logger LOG = Logger.getLogger(TamayaConfigPlugin.class.getName());
+ private static final OSGIConfigMapper DEFAULT_CONFIG_MAPPER = new DefaultOSGIConfigMapper();
+
+ private BundleContext context;
+ private ConfigurationAdmin cm;
+
+ public ConfigChanger(BundleContext context){
+ this.context = context;
+ ServiceReference<ConfigurationAdmin> cmRef = context.getServiceReference(ConfigurationAdmin.class);
+ this.cm = context.getService(cmRef);
+ }
+
+ public BundleContext getContext(){
+ return context;
+ }
+
+ public ConfigurationAdmin getConfigurationAdmin(){
+ return cm;
+ }
+
+ public void configure(String pid, Bundle bundle, OperationMode defaultOpMode) {
+ OperationMode opMode = Objects.requireNonNull(defaultOpMode);
+ String opVal = bundle.getHeaders().get("Tamaya-OperationMode");
+ if(opVal!=null){
+ opMode = OperationMode.valueOf(opVal.toUpperCase());
+ }
+ LOG.finest("Evaluating Tamaya Config for PID: " + pid);
+ ConfigHistory.configuring(pid, "operationMode="+opMode);
+ org.apache.tamaya.Configuration tamayaConfig = configMapper().getConfiguration(pid);
+ if (tamayaConfig == null) {
+ LOG.finest("No Tamaya configuration for PID: " + pid);
+ return;
+ }
+ try {
+ // TODO Check for Bundle.getLocation() usage here...
+ Configuration osgiConfig = cm.getConfiguration(pid, bundle.getLocation());
+ if(osgiConfig!=null){
+ Dictionary<String, Object> dictionary = osgiConfig.getProperties();
+ if(dictionary==null){
+ dictionary = new Hashtable<>();
+ }
+ modifyConfiguration(pid, tamayaConfig, dictionary, opMode);
+ if(!dictionary.isEmpty()) {
+ osgiConfig.update(dictionary);
+ LOG.info("Updated configuration for PID: " + pid + ": " + dictionary);
+ }
+ }
+ ConfigHistory.configured(pid, "SUCCESS");
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Failed to initialize configuration for PID: " + pid, e);
+ ConfigHistory.configured(pid, "FAILED: " + e);
+ }
+
+ }
+
+ public void modifyConfiguration(String pid, org.apache.tamaya.Configuration config, Dictionary<String, Object> dictionary, OperationMode opMode) {
+ LOG.info(() -> "Updating configuration for PID: " + pid + "...");
+ dictionary.put("tamaya.opMode", opMode.toString());
+ ConfigHistory.propertySet(pid, "tamaya.opMode", opMode.toString(), null);
+ dictionary.put("tamaya.modified.at", new Date().toString());
+ ConfigHistory.propertySet(pid, "tamaya.modified.at", dictionary.get("tamaya.modified.at"), null);
+
+ Map<String, Object> dictionaryMap = new HashMap<>();
+ Enumeration<String> keys = dictionary.keys();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement();
+ Object value = dictionary.get(key);
+ dictionaryMap.put(key, value);
+ }
+ for (Map.Entry<String, Object> dictEntry : dictionaryMap.entrySet()) {
+ Object configuredValue = config.getOrDefault(dictEntry.getKey(), dictEntry.getValue().getClass(), null);
+ switch (opMode) {
+ case EXTEND:
+ break;
+ case OVERRIDE:
+ if (configuredValue != null) {
+ LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue);
+ ConfigHistory.propertySet(pid,dictEntry.getKey(), configuredValue, dictEntry.getValue());
+ dictionary.put(dictEntry.getKey(), configuredValue);
+ }
+ break;
+ case UPDATE_ONLY:
+ if (configuredValue != null) {
+ LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue);
+ ConfigHistory.propertySet(pid,dictEntry.getKey(), configuredValue, dictEntry.getValue());
+ dictionary.put(dictEntry.getKey(), configuredValue);
+
+ }
+ }
+ }
+ for (Map.Entry<String, String> configEntry : config.getProperties().entrySet()) {
+ Object dictValue = dictionary.get(configEntry.getKey());
+ switch (opMode) {
+ case EXTEND:
+ if(dictValue==null){
+ LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue());
+ ConfigHistory.propertySet(pid,configEntry.getKey(), configEntry.getValue(), null);
+ dictionary.put(configEntry.getKey(), configEntry.getValue());
+ }
+ break;
+ case OVERRIDE:
+ LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue());
+ ConfigHistory.propertySet(pid,configEntry.getKey(), configEntry.getValue(), null);
+ dictionary.put(configEntry.getKey(), configEntry.getValue());
+ break;
+ case UPDATE_ONLY:
+ if(dictValue!=null){
+ LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue());
+ ConfigHistory.propertySet(pid,configEntry.getKey(), configEntry.getValue(), dictValue);
+ dictionary.put(configEntry.getKey(), configEntry.getValue());
+ }
+ break;
+ }
+ }
+ }
+
+ /**
+ * Loads the configuration toor mapper using the OSGIConfigRootMapper OSGI service resolving mechanism. If no
+ * such service is available it loads the default mapper.
+ * @return the mapper to be used, bever null.
+ */
+ private OSGIConfigMapper configMapper() {
+ OSGIConfigMapper mapper = null;
+ if(context!=null) {
+ ServiceReference<OSGIConfigMapper> ref = context.getServiceReference(OSGIConfigMapper.class);
+ if (ref != null) {
+ mapper = context.getService(ref);
+ }
+ }
+ if(mapper==null){
+ return DEFAULT_CONFIG_MAPPER;
+ }
+ return mapper;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cbd23125/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java
new file mode 100644
index 0000000..8fdd70a
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java
@@ -0,0 +1,168 @@
+/*
+ * 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.tamaya.osgi;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Class storing the history of changers done to the OSGI configuration by Tamaya.
+ * This class can be used in the future to restore the previous state, if needed.
+ */
+public final class ConfigHistory {
+
+ public enum TaskType{
+ PROPERTY,
+ BEGIN,
+ END,
+ }
+
+ private static int maxHistory = 10000;
+ private static List<ConfigHistory> history = new LinkedList<ConfigHistory>(){
+
+ @Override
+ public boolean add(ConfigHistory o) {
+ boolean val = super.add(o);
+ if(val && size() > maxHistory){
+ remove();
+ }
+ return val;
+ }
+ };
+
+ private long timestamp = System.currentTimeMillis();
+
+ private TaskType type;
+ private Object previousValue;
+ private Object value;
+ private String key;
+ private String pid;
+
+ private ConfigHistory(TaskType taskType, String pid){
+ this.type = Objects.requireNonNull(taskType);
+ this.pid = Objects.requireNonNull(pid);
+ }
+
+ public static ConfigHistory configuring(String pid, String info){
+ ConfigHistory h = new ConfigHistory(TaskType.BEGIN, pid)
+ .setValue(info);
+ synchronized (history){
+ history.add(h);
+ }
+ return h;
+ }
+ public static ConfigHistory configured(String pid, String info){
+ ConfigHistory h = new ConfigHistory(TaskType.END, pid)
+ .setValue(info);
+ synchronized (history){
+ history.add(h);
+ }
+ return h;
+ }
+ public static ConfigHistory propertySet(String pid, String key, Object value, Object previousValue){
+ ConfigHistory h = new ConfigHistory(TaskType.PROPERTY, pid)
+ .setKey(key)
+ .setPreviousValue(previousValue)
+ .setValue(value);
+ synchronized (history){
+ history.add(h);
+ }
+ return h;
+ }
+
+ public static List<ConfigHistory> history(){
+ return history(null);
+ }
+
+ public static void clearHistory(){
+ clearHistory(null);
+ }
+
+ public static void clearHistory(String pid){
+ synchronized (history){
+ if(pid==null || pid.isEmpty()) {
+ history.clear();
+ }else{
+ history.removeAll(history(pid));
+ }
+ }
+ }
+
+ public static List<ConfigHistory> history(String pid) {
+ if(pid==null || pid.isEmpty()){
+ return new ArrayList<>(history);
+ }
+ synchronized (history) {
+ List<ConfigHistory> result = new ArrayList<>();
+ for (ConfigHistory h : history) {
+ if (h.getPid().startsWith(pid)) {
+ result.add(h);
+ }
+ }
+ return result;
+ }
+ }
+
+ public TaskType getType(){
+ return type;
+ }
+
+ public String getPid() {
+ return pid;
+ }
+
+ public Object getPreviousValue() {
+ return previousValue;
+ }
+
+ public ConfigHistory setPreviousValue(Object previousValue) {
+ this.previousValue = previousValue;
+ return this;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public ConfigHistory setValue(Object value) {
+ this.value = value;
+ return this;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public ConfigHistory setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "ConfigHistory{" +
+ "timestamp=" + timestamp +
+ ", previousValue=" + previousValue +
+ ", value=" + value +
+ ", key='" + key + '\'' +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cbd23125/osgi/common/src/main/java/org/apache/tamaya/osgi/OperationMode.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/OperationMode.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/OperationMode.java
new file mode 100644
index 0000000..4489892
--- /dev/null
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/OperationMode.java
@@ -0,0 +1,31 @@
+/*
+ * 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.tamaya.osgi;
+
+/**
+ * Operation mode applied to the config read.
+ */
+public enum OperationMode{
+ /** Only add properties not existing in the config. */
+ EXTEND,
+ /** Override existing properties and add new properties. */
+ OVERRIDE,
+ /** Override existing properties only. */
+ UPDATE_ONLY
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cbd23125/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
index 509a3d0..1b844f0 100644
--- a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
+++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.osgi;
import org.osgi.framework.*;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ConfigurationPlugin;
import java.io.IOException;
import java.util.*;
@@ -32,48 +31,74 @@ import java.util.logging.Logger;
* Tamaya plugin that updates/extends the component configurations managed
* by {@link ConfigurationAdmin}, based on the configured {@link OperationMode}.
*/
-public class TamayaConfigPlugin {
+public class TamayaConfigPlugin implements BundleListener, ServiceListener{
static final String COMPONENTID = "TamayaConfigPlugin";
/** the logger. */
private static final Logger LOG = Logger.getLogger(TamayaConfigPlugin.class.getName());
- private static final OSGIConfigMapper DEFAULT_CONFIG_MAPPER = new DefaultOSGIConfigMapper();
private static final String TAMAYA_DISABLED = "tamaya.disabled";
private boolean disabled = false;
+ private OperationMode defaultOpMode = OperationMode.OVERRIDE;
- /**
- * Operation mode applied to the config read.
- */
- public enum OperationMode{
- /** Only add properties not existing in the config. */
- EXTEND,
- /** Only override existing properties, but do not add any new ones. */
- OVERRIDE,
- /** Override existing properties and add new properties, but do not remove
- * properties not existing in Tamaya. */
- EXTEND_AND_OVERRIDE,
- /** Use Tamaya config only. */
- SYNCH
+ private ConfigChanger configChanger;
+
+ @Override
+ public void serviceChanged(ServiceEvent event) {
+ switch(event.getType()){
+ case ServiceEvent.REGISTERED:
+ case ServiceEvent.MODIFIED:
+ configureService(event);
+ break;
+ case ServiceEvent.UNREGISTERING:
+ // unconfigure...? Corrently nothing here.
+ break;
+ }
}
- private BundleContext context;
- private OperationMode opMode = OperationMode.EXTEND_AND_OVERRIDE;
- private ConfigurationAdmin cm;
/**
* Create a new config.
* @param context the OSGI context
*/
TamayaConfigPlugin(BundleContext context) {
- this.context = context;
- ServiceReference<ConfigurationAdmin> cmRef = context.getServiceReference(ConfigurationAdmin.class);
- this.cm = context.getService(cmRef);
+ configChanger = new ConfigChanger(context);
+ initDefaultEnabled();
initDefaultOpMode();
initConfigs();
}
+ public void setDefaultDisabled(boolean disabled){
+ this.disabled = disabled;
+ setConfigValue(TAMAYA_DISABLED, disabled);
+ }
+
+ public boolean isDefaultDisabled(){
+ return disabled;
+ }
+
+ public OperationMode getDefaultOperationMode(){
+ return defaultOpMode;
+ }
+
+ public void setDefaultOperationMode(OperationMode mode){
+ this.defaultOpMode = Objects.requireNonNull(mode);
+ setConfigValue(OperationMode.class.getSimpleName(), defaultOpMode.toString());
+ }
+
+ @Override
+ public void bundleChanged(BundleEvent event) {
+ switch(event.getType()){
+ case BundleEvent.STARTING:
+ case BundleEvent.LAZY_ACTIVATION:
+// case BundleEvent.UPDATED:
+// TODO add checks for preventing endlee loop for updates here...
+ configureBundle(event.getBundle());
+ break;
+ }
+ }
+
private void initConfigs() {
// Check for matching bundles already installed...
- for(Bundle bundle:context.getBundles()){
+ for(Bundle bundle:configChanger.getContext().getBundles()){
switch(bundle.getState()){
case Bundle.ACTIVE:
configureBundle(bundle);
@@ -82,24 +107,24 @@ public class TamayaConfigPlugin {
}
}
- private void configureBundle(Bundle bundle) {
+ private void configureService(ServiceEvent event) {
// Optional MANIFEST entries
- String enabledTamaya = bundle.getHeaders().get("Tamaya-Enabled");
- String disabledTamaya = bundle.getHeaders().get("Tamaya-Disabled");
-
- if(Boolean.parseBoolean(disabledTamaya)){
- LOG.finest("Bundle is disabled for Tamaya: " + bundle.getSymbolicName());
+ Bundle bundle = event.getServiceReference().getBundle();
+ if(!isBundleEnabled(bundle)){
return;
}
- if(enabledTamaya != null && !Boolean.parseBoolean(enabledTamaya)){
- LOG.finest("Bundle is disabled for Tamaya: " + bundle.getSymbolicName());
+ String pid = (String)event.getServiceReference().getProperty("service.pid");
+ if(pid==null){
+ LOG.finest("No service pid for: " + event.getServiceReference());
return;
}
- if(disabled){
- LOG.finest("tamaya.disabled=false: not configuring bundle: " + bundle.getSymbolicName());
+ configChanger.configure(pid, event.getServiceReference().getBundle(), defaultOpMode);
+ }
+
+ private void configureBundle(Bundle bundle) {
+ if(!isBundleEnabled(bundle)){
return;
}
-
String tamayaPid = bundle.getHeaders().get("Tamaya-PID");
String pid = tamayaPid!=null?tamayaPid:bundle.getSymbolicName();
if(pid==null){
@@ -109,42 +134,31 @@ public class TamayaConfigPlugin {
LOG.finest(() -> "No PID/location for bundle " + bundle.getSymbolicName() + '('+bundle.getBundleId()+')');
return;
}
- LOG.finest("Evaluating Tamaya Config for PID: " + pid);
- org.apache.tamaya.Configuration tamayaConfig = configMapper().getConfiguration(pid);
- if (tamayaConfig == null) {
- LOG.finest("No Tamaya configuration for PID: " + pid);
- return;
- }
- try {
- // TODO Check for Bundle.getLocation() usage here...
- Configuration osgiConfig = cm.getConfiguration(pid, bundle.getLocation());
- if(osgiConfig!=null){
- Dictionary<String, Object> dictionary = osgiConfig.getProperties();
- if(dictionary==null){
- dictionary = new Hashtable<>();
- }
- modifyConfiguration(pid, tamayaConfig, dictionary);
- if(!dictionary.isEmpty()) {
- osgiConfig.update(dictionary);
- LOG.info("Updated configuration for PID: " + pid + ": " + dictionary);
- }
- }
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Failed to initialize configuration for PID: " + pid, e);
- }
+ configChanger.configure(pid, bundle, defaultOpMode);
}
- private void initDefaultOpMode() {
- String opVal = (String)getConfigValue(OperationMode.class.getName());
- if(opVal!=null){
- try{
- opMode = OperationMode.valueOf(opVal);
- }catch(Exception e){
- LOG.warning("Invalid OperationMode: " + opMode +", using default: " + opMode);
- }
+
+ public boolean isBundleEnabled(Bundle bundle){
+ // Optional MANIFEST entries
+ String enabledTamaya = bundle.getHeaders().get("Tamaya-Enabled");
+ String disabledTamaya = bundle.getHeaders().get("Tamaya-Disabled");
+
+ if(Boolean.parseBoolean(disabledTamaya)){
+ LOG.finest("Bundle is disabled for Tamaya: " + bundle.getSymbolicName());
+ return false;
}
+ if(enabledTamaya != null && !Boolean.parseBoolean(enabledTamaya)){
+ LOG.finest("Bundle is disabled for Tamaya: " + bundle.getSymbolicName());
+ return false;
+ }
+ if(disabled){
+ LOG.finest("tamaya.disabled=false: not configuring bundle: " + bundle.getSymbolicName());
+ return false;
+ }
+ return true;
}
+
private void initDefaultEnabled() {
String disabledVal = (String)getConfigValue("tamaya.disabled");
if(disabledVal==null){
@@ -160,11 +174,22 @@ public class TamayaConfigPlugin {
}
}
+ private void initDefaultOpMode() {
+ String opVal = (String)getConfigValue(OperationMode.class.getName());
+ if(opVal!=null){
+ try{
+ defaultOpMode = OperationMode.valueOf(opVal);
+ }catch(Exception e){
+ LOG.warning("Invalid OperationMode: " + opVal +", using default: " + defaultOpMode);
+ }
+ }
+ }
+
void setConfigValue(String key, Object value){
Configuration config = null;
try {
- config = cm.getConfiguration(COMPONENTID);
+ config = configChanger.getConfigurationAdmin().getConfiguration(COMPONENTID);
Dictionary<String, Object> props = null;
if (config != null
&& config.getProperties() != null) {
@@ -186,7 +211,7 @@ public class TamayaConfigPlugin {
Object getConfigValue(String key){
Configuration config = null;
try {
- config = cm.getConfiguration(COMPONENTID);
+ config = configChanger.getConfigurationAdmin().getConfiguration(COMPONENTID);
Dictionary<String, Object> props = null;
if (config != null
&& config.getProperties() != null) {
@@ -201,95 +226,4 @@ public class TamayaConfigPlugin {
return null;
}
- public OperationMode getOperationMode(){
- return opMode;
- }
-
- public void setDefaultDisabled(boolean disabled){
- this.disabled = disabled;
- setConfigValue(TAMAYA_DISABLED, disabled);
- }
-
- public boolean isDefaultDisabled(){
- return disabled;
- }
-
- public void setOperationMode(OperationMode mode){
- this.opMode = Objects.requireNonNull(mode);
- setConfigValue(OperationMode.class.getSimpleName(), opMode.toString());
- }
-
- public void modifyConfiguration(String target, org.apache.tamaya.Configuration config, Dictionary<String, Object> dictionary) {
- LOG.info(() -> "Updating configuration for " + target + "...");
- dictionary.put("tamaya.opMode", getOperationMode().toString());
- dictionary.put("tamaya.modified.at", new Date().toString());
-
- Map<String, Object> dictionaryMap = new HashMap<>();
- Enumeration<String> keys = dictionary.keys();
- while (keys.hasMoreElements()) {
- String key = keys.nextElement();
- Object value = dictionary.get(key);
- dictionaryMap.put(key, value);
- }
- for (Map.Entry<String, Object> dictEntry : dictionaryMap.entrySet()) {
- Object configuredValue = config.getOrDefault(dictEntry.getKey(), dictEntry.getValue().getClass(), null);
- switch (opMode) {
- case OVERRIDE:
- case EXTEND_AND_OVERRIDE:
- if (configuredValue != null) {
- LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue);
- dictionary.put(dictEntry.getKey(), configuredValue);
- }
- break;
- case SYNCH:
- if (configuredValue != null) {
- LOG.info(() -> "Setting key " + dictEntry.getKey() + " to " + configuredValue);
- dictionary.put(dictEntry.getKey(), configuredValue);
- } else {
- LOG.info(() -> "Removing key " + dictEntry.getKey());
- dictionary.remove(dictEntry.getKey());
- }
- }
- }
- for (Map.Entry<String, String> configEntry : config.getProperties().entrySet()) {
- Object dictValue = dictionary.get(configEntry.getKey());
- switch (opMode) {
- case EXTEND:
- case EXTEND_AND_OVERRIDE:
- LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue());
- dictionary.put(configEntry.getKey(), configEntry.getValue());
- break;
- case SYNCH:
- if (dictValue != null) {
- LOG.info(() -> "Setting key " + configEntry.getKey() + " to " + configEntry.getValue());
- dictionary.put(configEntry.getKey(), configEntry.getValue());
- } else {
- LOG.info(() -> "Removing key " + configEntry.getKey());
- dictionary.remove(configEntry.getKey());
- }
- break;
- }
- }
- }
-
- /**
- * Loads the configuration toor mapper using the OSGIConfigRootMapper OSGI service resolving mechanism. If no
- * such service is available it loads the default mapper.
- * @return the mapper to be used, bever null.
- */
- private OSGIConfigMapper configMapper() {
- OSGIConfigMapper mapper = null;
- if(context!=null) {
- ServiceReference<OSGIConfigMapper> ref = context.getServiceReference(OSGIConfigMapper.class);
- if (ref != null) {
- mapper = context.getService(ref);
- }
- }
- if(mapper==null){
- return DEFAULT_CONFIG_MAPPER;
- }
- return mapper;
- }
-
-
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/cbd23125/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java
----------------------------------------------------------------------
diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java
new file mode 100644
index 0000000..723c3d5
--- /dev/null
+++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.tamaya.osgi;
+
+import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsticks on 10.12.16.
+ */
+public class TamayaConfigPluginTest {
+
+ private TamayaConfigPlugin configAdmin = new TamayaConfigPlugin(null);
+
+ @Test
+ public void createConfigurationOverride() throws Exception {
+// Configuration config = configAdmin.createFactoryConfiguration("tamaya");
+// assertNotNull(config);
+// assertFalse(config.getProperties().isEmpty());
+// assertEquals(config.getProperties().size(), 4);
+// assertEquals(config.getProperties().get("my.testProperty1"), "success1");
+ }
+//
+// @Test
+// public void createFactoryConfigurationWithLocation() throws Exception {
+// Configuration config = configAdmin.createFactoryConfiguration("tamaya", "location");
+// assertNotNull(config);
+// assertFalse(config.getProperties().isEmpty());
+// assertEquals(config.getProperties().size(), 4);
+// assertEquals(config.getProperties().get("my.testProperty2"), "success2");
+// }
+//
+// @Test
+// public void getConfiguration() throws Exception {
+// Configuration config = configAdmin.getConfiguration("tamaya");
+// assertNotNull(config);
+// assertFalse(config.getProperties().isEmpty());
+// assertEquals(config.getProperties().size(), 4);
+// assertEquals(config.getProperties().get("my.testProperty3"), "success3");
+// }
+//
+// @Test
+// public void getConfigurationWithLocation() throws Exception {
+// Configuration config = configAdmin.getConfiguration("tamaya", "location");
+// assertNotNull(config);
+// assertFalse(config.getProperties().isEmpty());
+// assertEquals(config.getProperties().size(), 4);
+// assertEquals(config.getProperties().get("my.testProperty4"), "success4");
+// }
+//
+// @Test
+// public void listConfigurations() throws Exception {
+// Configuration[] configs = configAdmin.listConfigurations(".*");
+// assertNotNull(configs);
+// }
+
+}
\ No newline at end of file
[4/4] incubator-tamaya-sandbox git commit: TAMAYA-297: Simplified
naming.
Posted by an...@apache.org.
TAMAYA-297: Simplified naming.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/54ff0e6f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/54ff0e6f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/54ff0e6f
Branch: refs/heads/java8
Commit: 54ff0e6f019d8849c124152ff6cf13c26dc5e842
Parents: 39143de
Author: anatole <an...@apache.org>
Authored: Tue Sep 19 13:00:25 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Tue Sep 19 13:00:25 2017 +0200
----------------------------------------------------------------------
osgi/karaf-features/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/54ff0e6f/osgi/karaf-features/pom.xml
----------------------------------------------------------------------
diff --git a/osgi/karaf-features/pom.xml b/osgi/karaf-features/pom.xml
index eb4c7e1..f940767 100644
--- a/osgi/karaf-features/pom.xml
+++ b/osgi/karaf-features/pom.xml
@@ -28,7 +28,7 @@ limitations under the License.
<artifactId>tamaya-karaf-features</artifactId>
<packaging>feature</packaging>
- <name>Apache Tamaya :: Karaf :: Features</name>
+ <name>Apache Tamaya :: OSGI :: Karaf :: Features</name>
<description>Tamaya Karaf Feature Descriptor.</description>
<build>