TAMAYA-297: Fixed Karaf imports, aligned command names.
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/c2becbfd Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/c2becbfd Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/c2becbfd Branch: refs/heads/master Commit: c2becbfd43e7a0566ec2623a6f4064a0d15363e4 Parents: c83611c Author: anatole <anat...@apache.org> Authored: Fri Sep 22 22:36:24 2017 +0200 Committer: anatole <anat...@apache.org> Committed: Fri Sep 22 22:36:24 2017 +0200 ---------------------------------------------------------------------- .../tamaya/osgi/commands/HistoryCommands.java | 95 ++++++++++++++++++++ .../apache/tamaya/osgi/commands/StringUtil.java | 46 ++++++++++ .../felix/shell/PropertySourceCommand.java | 42 --------- osgi/karaf-shell/bnd.bnd | 1 + osgi/karaf-shell/pom.xml | 2 +- .../tamaya/karaf/shell/BackupCreateCommand.java | 19 +--- .../tamaya/karaf/shell/BackupDeleteCommand.java | 11 +-- .../tamaya/karaf/shell/BackupListCommand.java | 35 +------- .../tamaya/karaf/shell/ConfigCommand.java | 23 +++-- .../karaf/shell/DefaultDisableCommand.java | 5 +- .../tamaya/karaf/shell/GetPolicyCommand.java | 5 +- .../tamaya/karaf/shell/HistoryClearCommand.java | 69 -------------- .../karaf/shell/HistoryDeleteCommand.java | 41 +++++++++ .../tamaya/karaf/shell/HistoryGetCommand.java | 52 +---------- .../karaf/shell/HistoryMaxsizeCommand.java | 38 ++++++++ .../karaf/shell/HistorySizeGetCommand.java | 47 ---------- .../karaf/shell/HistorySizeSetCommand.java | 14 +-- .../apache/tamaya/karaf/shell/InfoCommand.java | 9 +- .../tamaya/karaf/shell/PolicyGetCommand.java | 12 +-- .../tamaya/karaf/shell/PolicySetCommand.java | 9 +- .../tamaya/karaf/shell/PropertyGetCommand.java | 38 +------- .../karaf/shell/PropertySourceCommand.java | 27 +----- .../karaf/shell/PropertySourcesCommand.java | 19 +--- .../apache/tamaya/karaf/shell/StringUtil.java | 46 ---------- 24 files changed, 279 insertions(+), 426 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java new file mode 100644 index 0000000..ce73423 --- /dev/null +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java @@ -0,0 +1,95 @@ +/* + * 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.commands; + +import org.apache.tamaya.osgi.ConfigHistory; +import org.apache.tamaya.osgi.TamayaConfigPlugin; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + + +/** + * Utility class implementing the available change history related commands. + */ +public final class HistoryCommands{ + + /** Singleton constructor. */ + private HistoryCommands(){} + + public static String clearHistory(String pid) throws IOException { + int size = ConfigHistory.history(pid).size(); + ConfigHistory.clearHistory(pid); + return "Deleted entries: " + size; + } + + public static String getHistory(String pid, String... events) throws IOException { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + List<ConfigHistory> history = ConfigHistory.history(pid); + history = filterTypes(history, events); + pw.print(StringUtil.format("Typ", 10)); + pw.print(StringUtil.format("PID", 30)); + pw.print(StringUtil.format("Key", 30)); + pw.print(StringUtil.format("Value", 40)); + pw.println(StringUtil.format("Previous Value", 40)); + pw.println(StringUtil.printRepeat("-", 140)); + for(ConfigHistory h:history){ + pw.print(StringUtil.format(h.getType().toString(), 10)); + pw.print(StringUtil.format(h.getPid(), 30)); + pw.print(StringUtil.format(h.getKey(), 30)); + pw.print(StringUtil.format(String.valueOf(h.getValue()), 40)); + pw.println(String.valueOf(h.getPreviousValue())); + } + return pw.toString(); + } + + public static int getMaxHistorySize(){ + return ConfigHistory.getMaxHistory(); + } + + public static String setMaxHistorySize(int maxSize){ + ConfigHistory.setMaxHistory(maxSize); + return "history.maxSize="+maxSize; + } + + private static List<ConfigHistory> filterTypes(List<ConfigHistory> history, String... eventTypes) { + if(eventTypes==null || eventTypes.length==0){ + return history; + } + List<ConfigHistory> result = new ArrayList<>(); + Set<ConfigHistory.TaskType> types = new HashSet<>(); + for(String tt:eventTypes) { + types.add(ConfigHistory.TaskType.valueOf(tt)); + } + for(ConfigHistory h:history){ + if(types.contains(h.getType())){ + result.add(h); + } + } + return result; + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/StringUtil.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/StringUtil.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/StringUtil.java new file mode 100644 index 0000000..b6819e8 --- /dev/null +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/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.osgi.commands; + +/** + * 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/c2becbfd/osgi/felix-shell/src/main/java/org/apache/tamaya/felix/shell/PropertySourceCommand.java ---------------------------------------------------------------------- diff --git a/osgi/felix-shell/src/main/java/org/apache/tamaya/felix/shell/PropertySourceCommand.java b/osgi/felix-shell/src/main/java/org/apache/tamaya/felix/shell/PropertySourceCommand.java deleted file mode 100644 index 0b48850..0000000 --- a/osgi/felix-shell/src/main/java/org/apache/tamaya/felix/shell/PropertySourceCommand.java +++ /dev/null @@ -1,42 +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.felix.shell; - -import org.apache.felix.scr.annotations.Service; -import org.apache.tamaya.osgi.commands.ConfigCommands; -import org.osgi.service.component.annotations.Component; - -import java.io.IOException; - -@Component( - immediate = true, - property = { - "osgi.command.scope=tamaya:propertysource", - "osgi.command.function=propertysource" - }, - service=PropertySourceCommand.class -) -@Service -public class PropertySourceCommand{ - - public String propertysource(String propertysource) throws IOException { - return ConfigCommands.getPropertySource(propertysource); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/karaf-shell/bnd.bnd ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/bnd.bnd b/osgi/karaf-shell/bnd.bnd index a7c8013..3bed7ca 100644 --- a/osgi/karaf-shell/bnd.bnd +++ b/osgi/karaf-shell/bnd.bnd @@ -29,6 +29,7 @@ Import-Package: \ org.apache.tamaya.functions,\ org.apache.tamaya.spisupport,\ org.apache.tamaya.osgi,\ + org.apache.tamaya.osgi.commands,\ org.apache.felix.service.command,\ org.apache.karaf.shell.api.console,\ org.apache.karaf.shell.api.action,\ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/karaf-shell/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/pom.xml b/osgi/karaf-shell/pom.xml index e7c1558..a11a1a5 100644 --- a/osgi/karaf-shell/pom.xml +++ b/osgi/karaf-shell/pom.xml @@ -27,7 +27,7 @@ <version>0.4-incubating-SNAPSHOT</version> </parent> - <artifactId>tamaya-karaf-shell_alpha</artifactId> + <artifactId>tamaya-osgi-karaf-shell_alpha</artifactId> <packaging>jar</packaging> <name>Apache Tamaya :: OSGI :: Karaf :: Shell</name> <description>Tamaya Karaf Shell Commands</description> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java index 3346e80..e2c6ca7 100644 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java @@ -24,15 +24,14 @@ 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.osgi.InitialState; -import org.apache.tamaya.osgi.TamayaConfigPlugin; +import org.apache.tamaya.osgi.commands.BackupCommands; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; -import org.osgi.service.component.annotations.Reference; import java.io.IOException; import java.util.Dictionary; -@Command(scope = "tamaya", name = "backup-create", description="Creates a backup of a current OSGI configuration.") +@Command(scope = "tamaya", name = "tm_backup_create", description="Creates a backup of a current OSGI configuration.") @Service public class BackupCreateCommand implements Action{ @@ -49,19 +48,7 @@ public class BackupCreateCommand implements Action{ @Override public Object execute() throws IOException { - Configuration cfg = cm.getConfiguration(pid); - if(cfg!=null){ - Dictionary<String,?> props = cfg.getProperties(); - if(props!=null){ - if(replace || !InitialState.contains(pid)){ - InitialState.set(pid, props); - System.out.println("Backup created, PID = " + pid); - BackupListCommand.printProps(props); - return null; - } - } - } - System.out.println("No Config found, PID = " + pid); + System.out.println(BackupCommands.createBackup(cm, pid, replace)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java index 2c3f4be..58dd826 100644 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java @@ -23,10 +23,11 @@ import org.apache.karaf.shell.api.action.Argument; import org.apache.karaf.shell.api.action.Command; import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.tamaya.osgi.InitialState; +import org.apache.tamaya.osgi.commands.BackupCommands; import java.io.IOException; -@Command(scope = "tamaya", name = "backup-delete", description="Deletes the OSGI configuration backup of Tamya.") +@Command(scope = "tamaya", name = "tm_backup_delete", description="Deletes the OSGI configuration backup of Tamya.") @Service public class BackupDeleteCommand implements Action{ @@ -36,13 +37,7 @@ public class BackupDeleteCommand implements Action{ @Override public Object execute() throws IOException { - if("*".equals(pid)){ - InitialState.removeAll(); - System.out.println("All Backups deleted."); - }else { - InitialState.remove(pid); - System.out.println("Backup deleted: " + pid); - } + System.out.println(BackupCommands.deleteBackup(pid)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java index d252586..781f2b9 100644 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java @@ -22,14 +22,11 @@ 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.Service; -import org.apache.tamaya.osgi.InitialState; +import org.apache.tamaya.osgi.commands.BackupCommands; import java.io.IOException; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Map; -@Command(scope = "tamaya", name = "backup-list", description="Gets the OSGI configuration before Tamya applied changes.") +@Command(scope = "tamaya", name = "tm_backup_list", description="List the backed-up OSGI configuration before Tamya applied changes.") @Service public class BackupListCommand implements Action{ @@ -39,34 +36,8 @@ public class BackupListCommand implements Action{ @Override public Object execute() throws IOException { - if(pid!=null){ - Dictionary<String, ?> props = InitialState.get(pid); - if(props==null){ - System.out.println("No backup found: " + pid); - }else{ - System.out.println("PID: " + pid); - printProps(props); - } - }else { - for(Map.Entry<String, Dictionary<String,?>> en: InitialState.get().entrySet()){ - System.out.println("PID: " + en.getKey()); - printProps(en.getValue()); - } - } + System.out.println(BackupCommands.listBackup(pid)); return null; } - public static void printProps(Dictionary<String, ?> props) { - System.out.print(StringUtil.format(" Key", 50)); - System.out.println(StringUtil.format(" Value", 50)); - System.out.println(" " + StringUtil.printRepeat("-", 100)); - Enumeration<String> keys = props.keys(); - while(keys.hasMoreElements()){ - String key = keys.nextElement(); - System.out.print(" " + StringUtil.format(key, 50)); - System.out.println(" " + StringUtil.format(String.valueOf(props.get(key)), 50)); - } - System.out.println(); - } - } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/ConfigCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/ConfigCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/ConfigCommand.java index 84a862c..3732f0a 100644 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/ConfigCommand.java +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/ConfigCommand.java @@ -21,14 +21,17 @@ 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.osgi.TamayaConfigPlugin; +import org.apache.tamaya.osgi.commands.ConfigCommands; import java.io.IOException; -@Command(scope = "tamaya", name = "config", description="Show the current Tamaya configuration.") +@Command(scope = "tamaya", name = "tm_config", description="Show the current Tamaya configuration.") @Service public class ConfigCommand implements Action{ @@ -36,14 +39,20 @@ public class ConfigCommand implements Action{ required = false, multiValued = false) String section = null; + @Option(name = "pid", aliases={"-p.--pid"}, description = "Apply filtering for the given OSGI component PID.", + required = false, multiValued = false) + String pid = null; + + @org.apache.karaf.shell.api.action.lifecycle.Reference + TamayaConfigPlugin configPlugin; + + public Object execute() throws IOException { - Configuration config = ConfigurationProvider.getConfiguration(); - if(section!=null){ - return config - .with(ConfigurationFunctions.section(section)) - .query(ConfigurationFunctions.textInfo()); + if(pid!=null){ + System.out.println(ConfigCommands.readConfig(configPlugin, pid, section)); + }else { + System.out.println(ConfigCommands.readConfig(section)); } - System.out.println(config.query(ConfigurationFunctions.textInfo())); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 99461dc..8d455a7 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 @@ -30,11 +30,12 @@ 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 org.apache.tamaya.osgi.commands.ConfigCommands; import java.io.IOException; import java.util.List; -@Command(scope = "tamaya", name = "disable-by-default", description="Disables Tamaya by default for all bundles/services (default=false)." + +@Command(scope = "tamaya", name = "tm_disable", description="Disables Tamaya by default for all bundles/services (default=false)." + " Disabling it allows to explicitly enable bundles using 'Tamaya-Enable^manifest entries.") @Service public class DefaultDisableCommand implements Action{ @@ -49,7 +50,7 @@ public class DefaultDisableCommand implements Action{ @Override public Object execute() throws IOException { - this.configPlugin.setDefaultDisabled(disabled); + System.out.println(ConfigCommands.setDefaultDisabled(configPlugin, disabled)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 42ebbd1..8ccb5a4 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 @@ -23,10 +23,11 @@ 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.apache.tamaya.osgi.TamayaConfigPlugin; +import org.apache.tamaya.osgi.commands.ConfigCommands; import java.io.IOException; -@Command(scope = "tamaya", name = "get-policy", description="Get the current Tamaya overriding policy.") +@Command(scope = "tamaya", name = "tm_policy", description="Get the current Tamaya overriding policy.") @Service public class GetPolicyCommand implements Action{ @@ -35,7 +36,7 @@ public class GetPolicyCommand implements Action{ @Override public Object execute() throws IOException { - System.out.println(this.configPlugin.getDefaultOperationMode()); + System.out.println(ConfigCommands.getDefaultOpPolicy(configPlugin)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 deleted file mode 100644 index 93f0dc2..0000000 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryClearCommand.java +++ /dev/null @@ -1,69 +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.*; -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/c2becbfd/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteCommand.java new file mode 100644 index 0000000..4930e2f --- /dev/null +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryDeleteCommand.java @@ -0,0 +1,41 @@ +/* + * 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.Service; +import org.apache.tamaya.osgi.commands.HistoryCommands; + +import java.io.IOException; + +@Command(scope = "tamaya", name = "tm_history_delete", description="Deletes the history of changes Tamaya applied to the OSGI configuration.") +@Service +public class HistoryDeleteCommand implements Action{ + + @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 { + System.out.println(HistoryCommands.clearHistory(pid)); + return null; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 index fd60c48..7f99031 100644 --- 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 @@ -27,14 +27,12 @@ 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 org.apache.tamaya.osgi.commands.HistoryCommands; 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.") +@Command(scope = "tamaya", name = "tm_history", description="Gets the history of changes Tamaya applied to the OSGI configuration.") @Service public class HistoryGetCommand implements Action{ @@ -52,54 +50,10 @@ public class HistoryGetCommand implements Action{ @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())); - } + System.out.println(HistoryCommands.getHistory(pid, eventTypes)); 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 { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeCommand.java new file mode 100644 index 0000000..92424d1 --- /dev/null +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistoryMaxsizeCommand.java @@ -0,0 +1,38 @@ +/* + * 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.Service; +import org.apache.tamaya.osgi.ConfigHistory; +import org.apache.tamaya.osgi.commands.HistoryCommands; + +import java.io.IOException; + +@Command(scope = "tamaya", name = "tm_history_maxsize", description="Gets the maximal size of stored history entries.") +@Service +public class HistoryMaxsizeCommand implements Action{ + + @Override + public Object execute() throws IOException { + System.out.println(HistoryCommands.getMaxHistorySize()); + return null; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistorySizeGetCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistorySizeGetCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistorySizeGetCommand.java deleted file mode 100644 index 3658191..0000000 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistorySizeGetCommand.java +++ /dev/null @@ -1,47 +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.*; -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-size-get", description="Gets the maximal size of stored history entries.") -@Service -public class HistorySizeGetCommand implements Action{ - - @Override - public Object execute() throws IOException { - System.out.println(ConfigHistory.getMaxHistory()); - return null; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistorySizeSetCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistorySizeSetCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistorySizeSetCommand.java index ed6ff5a..5d7ffb7 100644 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistorySizeSetCommand.java +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/HistorySizeSetCommand.java @@ -21,21 +21,14 @@ 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.ConfigHistory; -import org.apache.tamaya.osgi.OperationMode; import org.apache.tamaya.osgi.TamayaConfigPlugin; +import org.apache.tamaya.osgi.commands.HistoryCommands; import java.io.IOException; -import java.util.List; -@Command(scope = "tamaya", name = "history-size-set", description="Sets the maximal size of Tamaya history entries.") +@Command(scope = "tamaya", name = "history_maxsize_set", description="Sets the maximal size of Tamaya history entries.") @Service public class HistorySizeSetCommand implements Action{ @@ -48,8 +41,7 @@ public class HistorySizeSetCommand implements Action{ @Override public Object execute() throws IOException { - ConfigHistory.setMaxHistory(maxSize); - System.out.println("ConfigHistory.maxSize="+maxSize); + System.out.println(HistoryCommands.setMaxHistorySize(maxSize)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 d50e97b..e954957 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 @@ -27,8 +27,10 @@ import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.osgi.TamayaConfigPlugin; +import org.apache.tamaya.osgi.commands.ConfigCommands; +import org.apache.tamaya.osgi.commands.HistoryCommands; -@Command(scope = "tamaya", name = "info", description="Show he current Tamaya status.") +@Command(scope = "tamaya", name = "tm_info", description="Show he current Tamaya status.") @Service public class InfoCommand implements Action { @@ -36,10 +38,7 @@ public class InfoCommand implements Action { private TamayaConfigPlugin configPlugin; public Object execute() throws IOException { - Configuration config = ConfigurationProvider.getConfiguration(); - System.out.println(config.toString() + "\n\n" - + StringUtil.format("Default OperationMode:", 30) + configPlugin.getDefaultOperationMode() + '\n' - + StringUtil.format("Default Disabled: ", 30) + configPlugin.isDefaultDisabled()); + System.out.println(ConfigCommands.getInfo(configPlugin)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 index 350c802..72e4ccc 100644 --- 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 @@ -19,21 +19,15 @@ 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 org.apache.tamaya.osgi.commands.ConfigCommands; import java.io.IOException; -import java.util.List; -@Command(scope = "tamaya", name = "policy-get", description="Gets the current Tamaya operation policy.") +@Command(scope = "tamaya", name = "tm_policy", description="Gets the current Tamaya operation policy.") @Service public class PolicyGetCommand implements Action{ @@ -42,7 +36,7 @@ public class PolicyGetCommand implements Action{ @Override public Object execute() throws IOException { - System.out.println(this.configPlugin.getDefaultOperationMode()); + System.out.println(ConfigCommands.getDefaultOpPolicy(configPlugin)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 index 7e2af6a..2d2b478 100644 --- 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 @@ -30,27 +30,26 @@ 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 org.apache.tamaya.osgi.commands.ConfigCommands; import java.io.IOException; import java.util.List; -@Command(scope = "tamaya", name = "policy-set", description="Sets the current Tamaya operation policy.") +@Command(scope = "tamaya", name = "tamaya_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.", + @Argument(index = 0, name = "tm_policy_set", 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()); + System.out.println(ConfigCommands.setDefaultOpPolicy(configPlugin, policy)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 index 061bcfe..cda1a2b 100644 --- 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 @@ -18,22 +18,20 @@ */ 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.osgi.commands.ConfigCommands; 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.") +@Command(scope = "tamaya", name = "tm_property", description="Get a Tamaya property.") @Service public class PropertyGetCommand implements Action{ @@ -49,37 +47,7 @@ public class PropertyGetCommand implements Action{ 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)); - } - } - } - } + System.out.println(ConfigCommands.getProperty(propertysource, key, extended)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 c3e1c57..3a2f695 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 @@ -24,12 +24,13 @@ import org.apache.karaf.shell.api.action.Command; import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.osgi.commands.ConfigCommands; import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; import java.io.IOException; -@Command(scope = "tamaya", name = "propertysource", description="Show the current Tamaya entries of a propertysource.") +@Command(scope = "tamaya", name = "tm_propertysource", description="Show the current Tamaya entries of a propertysource.") @Service public class PropertySourceCommand implements Action{ @@ -38,29 +39,7 @@ public class PropertySourceCommand implements Action{ 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 { - 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.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)); - } - } - } + System.out.println(ConfigCommands.getPropertySource(propertysource)); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 60289b9..315e9a9 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 @@ -19,34 +19,21 @@ 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.Service; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.osgi.commands.ConfigCommands; import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; import java.io.IOException; -@Command(scope = "tamaya", name = "propertysources", description="Get a list of currently registered propertysources.") +@Command(scope = "tamaya", name = "tm_propertysources", description="Get a list of currently registered propertysources.") @Service 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.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("---"); - } + System.out.println(ConfigCommands.getPropertySourceOverview()); return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c2becbfd/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 deleted file mode 100644 index f32144b..0000000 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/StringUtil.java +++ /dev/null @@ -1,46 +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; - -/** - * 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(); - } -}