TAMAYA-297: Implemented Gogo support, tested it with Apache Felix.
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/c83611c5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/c83611c5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/c83611c5 Branch: refs/heads/master Commit: c83611c5aa0c2b65c2d306628232b88e75602347 Parents: 39bf824 Author: anatole <[email protected]> Authored: Fri Sep 22 12:52:12 2017 +0200 Committer: anatole <[email protected]> Committed: Fri Sep 22 12:52:12 2017 +0200 ---------------------------------------------------------------------- osgi/felix-shell/bnd.bnd | 36 -------- osgi/felix-shell/pom.xml | 92 -------------------- osgi/gogo-shell/bnd.bnd | 34 ++++++++ osgi/gogo-shell/pom.xml | 73 ++++++++++++++++ .../org/apache/tamaya/gogo/shell/Activator.java | 91 +++++++++++++++++++ .../tamaya/gogo/shell/BackupCommands.java | 64 ++++++++++++++ .../tamaya/gogo/shell/ConfigCommands.java | 76 ++++++++++++++++ .../tamaya/gogo/shell/HistoryCommands.java | 77 ++++++++++++++++ .../tamaya/gogo/shell/SettingsCommands.java | 67 ++++++++++++++ 9 files changed, 482 insertions(+), 128 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c83611c5/osgi/felix-shell/bnd.bnd ---------------------------------------------------------------------- diff --git a/osgi/felix-shell/bnd.bnd b/osgi/felix-shell/bnd.bnd deleted file mode 100644 index 643f788..0000000 --- a/osgi/felix-shell/bnd.bnd +++ /dev/null @@ -1,36 +0,0 @@ --buildpath: \ - osgi.annotation; version=6.0.0,\ - osgi.core; version=6.0,\ - osgi.cmpn; version=6.0 - --testpath: \ - ${junit} - -javac.source: 1.8 -javac.target: 1.8 - -Bundle-Version: ${version}.${tstamp} -Bundle-Name: Apache Tamaya - Felix Shell Commands -Bundle-SymbolicName: org.apache.tamaya.osgi.felix.shell -Bundle-Description: Apacha Tamaya Configuration - Felix Shell Extensions -Bundle-Category: Implementation -Bundle-Copyright: (C) Apache Foundation -Bundle-License: Apache Licence version 2 -Bundle-Vendor: Apache Software Foundation -Bundle-ContactAddress: [email protected] -Bundle-DocURL: http://tamaya.apache.org -Export-Package: \ - org.apache.tamaya.felix.shell -Import-Package: \ - org.osgi.service.cm,\ - org.osgi.framework,\ - org.apache.tamaya,\ - org.apache.tamaya.spi,\ - org.apache.tamaya.functions,\ - org.apache.tamaya.spisupport,\ - org.apache.tamaya.osgi,\ - org.apache.felix.service.command,\ - org.apache.karaf.shell.api.console,\ - org.apache.karaf.shell.api.action,\ - org.apache.karaf.shell.api.action.lifecycle,\ - org.apache.karaf.shell.support.completers http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c83611c5/osgi/felix-shell/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/felix-shell/pom.xml b/osgi/felix-shell/pom.xml deleted file mode 100644 index d19cb08..0000000 --- a/osgi/felix-shell/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - - <!-- - - 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. - --> - - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-osgi-all</artifactId> - <version>0.4-incubating-SNAPSHOT</version> - </parent> - - <artifactId>tamaya-osgi-gogo-shell_alpha</artifactId> - <packaging>jar</packaging> - <name>Apache Tamaya :: OSGI :: Gogo :: Shell</name> - <description>Tamaya Gogo Shell Commands</description> - - <dependencies> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-osgi_alpha</artifactId> - <version>${project.parent.version}</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.framework</artifactId> - <version>5.6.1</version> - </dependency> - - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - <version>1.9.12</version> - </dependency> - - <!-- Testing --> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>java-hamcrest</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - <version>1.21.0</version> - <executions> - <execution> - <id>generate-scr-scrdescriptor</id> - <goals> - <goal>scr</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c83611c5/osgi/gogo-shell/bnd.bnd ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/bnd.bnd b/osgi/gogo-shell/bnd.bnd new file mode 100644 index 0000000..67e951a --- /dev/null +++ b/osgi/gogo-shell/bnd.bnd @@ -0,0 +1,34 @@ +-buildpath: \ + osgi.annotation; version=6.0.0,\ + osgi.core; version=6.0,\ + osgi.cmpn; version=6.0 + +-testpath: \ + ${junit} + +javac.source: 1.8 +javac.target: 1.8 + +Bundle-Activator: org.apache.tamaya.gogo.shell.Activator +Bundle-Version: ${version}.${tstamp} +Bundle-Name: Apache Tamaya - Felix Shell Commands +Bundle-SymbolicName: org.apache.tamaya.osgi.gogo.shell +Bundle-Description: Apacha Tamaya Configuration - Gogo Shell Extensions +Bundle-Category: Implementation +Bundle-Copyright: (C) Apache Foundation +Bundle-License: Apache Licence version 2 +Bundle-Vendor: Apache Software Foundation +Bundle-ContactAddress: [email protected] +Bundle-DocURL: http://tamaya.apache.org +Export-Package: \ + org.apache.tamaya.gogo.shell +Import-Package: \ + org.osgi.service.cm,\ + org.osgi.framework,\ + org.apache.tamaya,\ + org.apache.tamaya.spi,\ + org.apache.tamaya.functions,\ + org.apache.tamaya.spisupport,\ + org.apache.tamaya.osgi,\ + org.apache.tamaya.osgi.commands,\ + org.apache.felix.service.command http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c83611c5/osgi/gogo-shell/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/pom.xml b/osgi/gogo-shell/pom.xml new file mode 100644 index 0000000..1b61576 --- /dev/null +++ b/osgi/gogo-shell/pom.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <!-- + + 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. + --> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-osgi-all</artifactId> + <version>0.4-incubating-SNAPSHOT</version> + </parent> + + <artifactId>tamaya-osgi-gogo-shell_alpha</artifactId> + <packaging>jar</packaging> + <name>Apache Tamaya :: OSGI :: Gogo :: Shell</name> + <description>Tamaya Gogo Shell Commands</description> + + <dependencies> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-osgi_alpha</artifactId> + <version>${project.parent.version}</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.gogo.runtime</artifactId> + <version>1.0.8</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + <version>1.12.0</version> + </dependency> + + <!-- Testing --> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>java-hamcrest</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c83611c5/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/Activator.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/Activator.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/Activator.java new file mode 100644 index 0000000..8c07c24 --- /dev/null +++ b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/Activator.java @@ -0,0 +1,91 @@ +/* + * 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.gogo.shell; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.logging.Logger; + +/** + * Activator that registers the Tamaya commands for the Felix Gogo console used + * in Apache Felix and Equinox. + */ +public class Activator implements BundleActivator { + + private static final Logger LOG = Logger.getLogger(Activator.class.getName()); + + private ServiceRegistration<HistoryCommands> histReg; + private ServiceRegistration<ConfigCommands> configReg; + private ServiceRegistration<BackupCommands> backupReg; + private ServiceRegistration<SettingsCommands> settingsReg; + + @Override + public void start(BundleContext context) throws Exception { + LOG.finest("Registering Tamaya commands..."); + Dictionary<String, Object> props = new Hashtable<>(); + props.put("osgi.command.scope", "tamaya"); + props.put("osgi.command.function", + new String[] {"config", "property_get", + "propertysource_get","propertysources_get"}); + configReg = context.registerService( + ConfigCommands.class, + new ConfigCommands(context), props); + props.put("osgi.command.function", + new String[] {"history_get","history_delete", + "maxhistory_get", "maxhistory_set"}); + histReg = context.registerService( + HistoryCommands.class, + new HistoryCommands(context), props); + props.put("osgi.command.function", + new String[] {"backup_create","backup_delete", + "backup_get"}); + backupReg = context.registerService( + BackupCommands.class, + new BackupCommands(context), props); + props.put("osgi.command.function", + new String[] {"tamaya_disable","tamaya_policy_get", + "tamaya_policy_set","tamaya_info"}); + settingsReg = context.registerService( + SettingsCommands.class, + new SettingsCommands(context), props); + LOG.info("Registered Tamaya commands."); + } + + @Override + public void stop(BundleContext context) throws Exception { + LOG.info("Unregistering Tamaya commands."); + if (histReg != null) { + histReg.unregister(); + } + if (configReg != null) { + configReg.unregister(); + } + if (backupReg != null) { + backupReg.unregister(); + } + if (settingsReg != null) { + settingsReg.unregister(); + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c83611c5/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java new file mode 100644 index 0000000..79e4ca1 --- /dev/null +++ b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java @@ -0,0 +1,64 @@ +/* + * 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.gogo.shell; + +import org.apache.felix.service.command.Descriptor; +import org.apache.felix.service.command.Parameter; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.ConfigurationAdmin; + +import java.io.IOException; +import java.util.Objects; + +public class BackupCommands { + + private BundleContext context; + + public BackupCommands(BundleContext context){ + this.context = Objects.requireNonNull(context); + } + + private <T> T getService(Class<T> type){ + ServiceReference<T> cmRef = context.getServiceReference(type); + return context.getService(cmRef); + } + + + @Descriptor("Creates an OSGI ConfigAdmin configuration backup for a PID.") + public void backup_create(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) + @Descriptor("The PID (requred)") String pid, + @Parameter(absentValue = Parameter.UNSPECIFIED, names={"-f", "--force"}) + @Descriptor("If set any existing backup will be overriden, default is false.") Boolean force) throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.createBackup(getService(ConfigurationAdmin.class), pid, force)); + } + + @Descriptor("Deletes an OSGI ConfigAdmin configuration backup for a PID.") + public void backup_delete(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) + @Descriptor("The target PID") String pid) throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.deleteBackup(pid)); + } + + @Descriptor("Shows the contents of the OSGI ConfigAdmin configuration backup for a PID.") + public void backup_get(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) + @Descriptor("The PID (requred)") String pid) throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.listBackup(Objects.requireNonNull(pid))); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c83611c5/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java new file mode 100644 index 0000000..313caea --- /dev/null +++ b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java @@ -0,0 +1,76 @@ +/* + * 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.gogo.shell; + +import org.apache.felix.service.command.Descriptor; +import org.apache.felix.service.command.Parameter; +import org.apache.tamaya.osgi.TamayaConfigPlugin; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +import java.io.IOException; +import java.util.Objects; + +public class ConfigCommands { + + private BundleContext context; + + private <T> T getService(Class<T> type){ + ServiceReference<T> cmRef = context.getServiceReference(type); + return context.getService(cmRef); + } + + public ConfigCommands(BundleContext context){ + this.context = Objects.requireNonNull(context); + } + + @Descriptor("Shows the current Tamaya configuration.") + public void config(@Parameter(absentValue = "", names={"-s", "--section"}) + @Descriptor("The section start expression to filter.") String section, + @Parameter(absentValue = "", names={"-p", "--pid"}) + @Descriptor("The pid to filter (required).") String pid) throws IOException { + if(pid.isEmpty()){ + System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.readConfig(section)); + }else { + System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.readConfig(getService(TamayaConfigPlugin.class), pid, section)); + } + } + + + @Descriptor("Gets the detailed property values.") + public void property_get(@Parameter(absentValue = "", names={"-ps", "--propertysource"}) + @Descriptor("The property source name")String propertysource, + @Parameter(absentValue = Parameter.UNSPECIFIED, names={"-k", "--key"}) + @Descriptor("The property key")String key, + @Parameter(absentValue = "false", names={"-e", "--extended"}) + @Descriptor("Show extended info, default=false")Boolean extended) throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.getProperty(propertysource, key, extended.booleanValue())); + } + + @Descriptor("Get details of a property source.") + public void propertysource_get(@Parameter(absentValue = "", names={"-ps", "--propertysource"}) + @Descriptor("The property source name, empty returns a list of possible values")String propertysource) throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.getPropertySource(propertysource)); + } + + @Descriptor("Show details of all registered property sources.") + public void propertysources_get() throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.getPropertySourceOverview()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c83611c5/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java new file mode 100644 index 0000000..69ee19a --- /dev/null +++ b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java @@ -0,0 +1,77 @@ +/* + * 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.gogo.shell; + +import org.apache.felix.service.command.Descriptor; +import org.apache.felix.service.command.Parameter; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +import java.io.IOException; +import java.util.Objects; + +public class HistoryCommands { + + private BundleContext context; + + private <T> T getService(Class<T> type){ + ServiceReference<T> cmRef = context.getServiceReference(type); + return context.getService(cmRef); + } + + public HistoryCommands(BundleContext context){ + this.context = Objects.requireNonNull(context); + } + + @Descriptor("Deletes the history of configuration changes.") + public void history_delete(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) + @Descriptor("The PID.") String pid) throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.clearHistory(pid)); + } + + @Descriptor("Deletes the full history of configuration changes.") + public void history_delete_all() throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.clearHistory(null)); + } + + @Descriptor("Read the history of configuration changes.") + public void history_get(@Parameter(absentValue = "", names={"-p", "--pid"}) + @Descriptor("The PID.")String pid, + @Parameter(absentValue = "", names={"-t", "--eventtypes"}) + @Descriptor("The comma separated Event types to filter, valid types are " + + "PROPERTY,BEGIN,END")String eventTypes) throws IOException { + if(eventTypes.isEmpty()){ + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.getHistory(pid, null)); + }else { + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.getHistory(pid, eventTypes.split(","))); + } + } + + @Descriptor("Get the maximum configuration change history size.") + public void maxhistory_get() throws IOException { + System.out.println(String.valueOf(org.apache.tamaya.osgi.commands.HistoryCommands.getMaxHistorySize())); + } + + @Descriptor("Sets the maximum configuration change history size.") + public void maxhistory_set(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-s", "--size"}) + @Descriptor("The maximum size of history entries stored.")int maxSize) throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.setMaxHistorySize(maxSize)); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/c83611c5/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java new file mode 100644 index 0000000..78afb79 --- /dev/null +++ b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java @@ -0,0 +1,67 @@ +/* + * 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.gogo.shell; + +import org.apache.felix.service.command.Descriptor; +import org.apache.felix.service.command.Parameter; +import org.apache.tamaya.osgi.OperationMode; +import org.apache.tamaya.osgi.TamayaConfigPlugin; +import org.apache.tamaya.osgi.commands.ConfigCommands; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +import java.io.IOException; +import java.util.Objects; + +public class SettingsCommands { + + private BundleContext context; + + public SettingsCommands(BundleContext context){ + this.context = Objects.requireNonNull(context); + } + + private <T> T getService(Class<T> type){ + ServiceReference<T> cmRef = context.getServiceReference(type); + return context.getService(cmRef); + } + + @Descriptor("Allows to disable/enable Tamaya configuration by default.") + public void tamaya_disable(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-d", "--disable"}) + @Descriptor("if true Tamaya is disabled by default (default=false)") boolean disabled) throws IOException { + System.out.println(ConfigCommands.setDefaultDisabled(getService(TamayaConfigPlugin.class), disabled)); + } + + @Descriptor("Get the default Tamaya configuration policy.") + public void tamaya_policy_get() throws IOException { + System.out.println(ConfigCommands.getDefaultOpPolicy(getService(TamayaConfigPlugin.class))); + } + + @Descriptor("Set the default Tamaya configuration policy.") + public void tamaya_policy_set(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--policy"}) + @Descriptor("The policy to apply (required), one of: EXTEND, OVERRIDE, UPDATE_ONLY") OperationMode policy) throws IOException { + System.out.println(ConfigCommands.setDefaultOpPolicy(getService(TamayaConfigPlugin.class), policy.toString())); + } + + @Descriptor("Get info about the current Tamaya configuration settings.") + public void tamaya_info() throws IOException { + System.out.println(ConfigCommands.getInfo(getService(TamayaConfigPlugin.class))); + } + +} \ No newline at end of file
