You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/04/10 16:15:42 UTC
[20/59] [abbrv] [KARAF-2852] Merge bundle/command into bundle/core
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/Refresh.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Refresh.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/Refresh.java
deleted file mode 100644
index 53adaeb..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Refresh.java
+++ /dev/null
@@ -1,43 +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.karaf.bundle.command;
-
-import java.util.List;
-
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.wiring.FrameworkWiring;
-
-@Command(scope = "bundle", name = "refresh", description = "Refresh bundles.")
-@Service
-public class Refresh extends BundlesCommandWithConfirmation {
-
- public Refresh() {
- this.defaultAllBundles = false;
- }
-
- protected void doExecute(List<Bundle> bundles) throws Exception {
- FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
- wiring.refreshBundles(bundles == null || bundles.isEmpty() ? null : bundles);
- }
-
- @Override
- protected void executeOnBundle(Bundle bundle) throws Exception {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/Requirements.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Requirements.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/Requirements.java
deleted file mode 100644
index c87d4d4..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Requirements.java
+++ /dev/null
@@ -1,177 +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.karaf.bundle.command;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-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.shell.support.ShellUtil;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.wiring.BundleCapability;
-import org.osgi.framework.wiring.BundleRequirement;
-import org.osgi.framework.wiring.BundleWire;
-import org.osgi.framework.wiring.BundleWiring;
-
-@Command(scope = "bundle", name = "requirements", description = "Displays OSGi requirements of a given bundles.")
-@Service
-public class Requirements extends BundlesCommand {
-
- public static final String NONSTANDARD_SERVICE_NAMESPACE = "service";
-
- private static final String EMPTY_MESSAGE = "[EMPTY]";
- private static final String UNRESOLVED_MESSAGE = "[UNRESOLVED]";
-
- @Option(name = "--namespace")
- String namespace = "*";
-
- public Requirements() {
- super(true);
- }
-
- @Override
- protected void doExecute(List<Bundle> bundles) throws Exception {
- boolean separatorNeeded = false;
- Pattern ns = Pattern.compile(namespace.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*"));
- for (Bundle b : bundles) {
- if (separatorNeeded) {
- System.out.println("");
- }
-
- // Print out any matching generic requirements.
- BundleWiring wiring = b.adapt(BundleWiring.class);
- if (wiring != null) {
- String title = b + " requires:";
- System.out.println(title);
- System.out.println(ShellUtil.getUnderlineString(title));
- boolean matches = printMatchingRequirements(wiring, ns);
-
- // Handle service requirements separately, since they aren't part
- // of the generic model in OSGi.
- if (matchNamespace(ns, NONSTANDARD_SERVICE_NAMESPACE)) {
- matches |= printServiceRequirements(b);
- }
-
- // If there were no requirements for the specified namespace,
- // then say so.
- if (!matches) {
- System.out.println(namespace + " " + EMPTY_MESSAGE);
- }
- } else {
- System.out.println("Bundle " + b.getBundleId() + " is not resolved.");
- }
-
- separatorNeeded = true;
- }
- }
-
- private static boolean printMatchingRequirements(BundleWiring wiring, Pattern namespace) {
- List<BundleWire> wires = wiring.getRequiredWires(null);
- Map<BundleRequirement, List<BundleWire>> aggregateReqs = aggregateRequirements(namespace, wires);
- List<BundleRequirement> allReqs = wiring.getRequirements(null);
- boolean matches = false;
- for (BundleRequirement req : allReqs) {
- if (matchNamespace(namespace, req.getNamespace())) {
- matches = true;
- List<BundleWire> providers = aggregateReqs.get(req);
- if (providers != null) {
- System.out.println(req.getNamespace() + "; "
- + req.getDirectives().get(Constants.FILTER_DIRECTIVE) + " resolved by:");
- for (BundleWire wire : providers) {
- String msg;
- Object keyAttr = wire.getCapability().getAttributes().get(wire.getCapability().getNamespace());
- if (keyAttr != null) {
- msg = wire.getCapability().getNamespace() + "; "
- + keyAttr + " " + getVersionFromCapability(wire.getCapability());
- } else {
- msg = wire.getCapability().toString();
- }
- msg = " " + msg + " from " + wire.getProviderWiring().getBundle();
- System.out.println(msg);
- }
- } else {
- System.out.println(req.getNamespace() + "; "
- + req.getDirectives().get(Constants.FILTER_DIRECTIVE) + " " + UNRESOLVED_MESSAGE);
- }
- }
- }
- return matches;
- }
-
- private static Map<BundleRequirement, List<BundleWire>> aggregateRequirements(
- Pattern namespace, List<BundleWire> wires) {
- // Aggregate matching capabilities.
- Map<BundleRequirement, List<BundleWire>> map = new HashMap<BundleRequirement, List<BundleWire>>();
- for (BundleWire wire : wires) {
- if (matchNamespace(namespace, wire.getRequirement().getNamespace())) {
- List<BundleWire> providers = map.get(wire.getRequirement());
- if (providers == null) {
- providers = new ArrayList<BundleWire>();
- map.put(wire.getRequirement(), providers);
- }
- providers.add(wire);
- }
- }
- return map;
- }
-
- static boolean printServiceRequirements(Bundle b) {
- boolean matches = false;
-
- try {
- ServiceReference<?>[] refs = b.getServicesInUse();
-
- if ((refs != null) && (refs.length > 0)) {
- matches = true;
- // Print properties for each service.
- for (ServiceReference<?> ref : refs) {
- // Print object class with "namespace".
- System.out.println(
- NONSTANDARD_SERVICE_NAMESPACE
- + "; "
- + ShellUtil.getValueString(ref.getProperty("objectClass"))
- + " provided by:");
- System.out.println(" " + ref.getBundle());
- }
- }
- } catch (Exception ex) {
- System.err.println(ex.toString());
- }
-
- return matches;
- }
-
- private static String getVersionFromCapability(BundleCapability c) {
- Object o = c.getAttributes().get(Constants.VERSION_ATTRIBUTE);
- if (o == null) {
- o = c.getAttributes().get(Constants.BUNDLE_VERSION_ATTRIBUTE);
- }
- return (o == null) ? "" : o.toString();
- }
-
- private static boolean matchNamespace(Pattern namespace, String actual) {
- return namespace.matcher(actual).matches();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/Resolve.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Resolve.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/Resolve.java
deleted file mode 100644
index 720f118..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Resolve.java
+++ /dev/null
@@ -1,39 +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.karaf.bundle.command;
-
-import java.util.List;
-
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.wiring.FrameworkWiring;
-
-@Command(scope = "bundle", name = "resolve", description = "Resolve bundles.")
-@Service
-public class Resolve extends BundlesCommand {
-
- public Resolve() {
- super(true);
- }
-
- protected void doExecute(List<Bundle> bundles) throws Exception {
- FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
- wiring.resolveBundles(bundles == null || bundles.isEmpty() ? null : bundles);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/Restart.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Restart.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/Restart.java
deleted file mode 100644
index 95d5dfe..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Restart.java
+++ /dev/null
@@ -1,62 +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.karaf.bundle.command;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.karaf.shell.support.MultiException;
-import org.osgi.framework.Bundle;
-
-@Command(scope = "bundle", name = "restart", description = "Restarts bundles.")
-@Service
-public class Restart extends BundlesCommandWithConfirmation {
-
- public Restart() {
- errorMessage = "Error restarting bundle";
- }
-
- protected void doExecute(List<Bundle> bundles) throws Exception {
- if (bundles.isEmpty()) {
- System.err.println("No bundles specified.");
- return;
- }
- List<Exception> exceptions = new ArrayList<Exception>();
- for (Bundle bundle : bundles) {
- try {
- bundle.stop();
- } catch (Exception e) {
- exceptions.add(new Exception("Unable to stop bundle " + bundle.getBundleId() + ": " + e.getMessage(), e));
- }
- }
- for (Bundle bundle : bundles) {
- try {
- bundle.start();
- } catch (Exception e) {
- exceptions.add(new Exception("Unable to start bundle " + bundle.getBundleId() + ": " + e.getMessage(), e));
- }
- }
- MultiException.throwIf("Error restarting bundles", exceptions);
- }
-
- @Override
- protected void executeOnBundle(Bundle bundle) throws Exception {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/ShowBundleTree.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/ShowBundleTree.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/ShowBundleTree.java
deleted file mode 100644
index a83ce39..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/ShowBundleTree.java
+++ /dev/null
@@ -1,245 +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.karaf.bundle.command;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.felix.utils.manifest.Clause;
-import org.apache.felix.utils.manifest.Parser;
-import org.apache.felix.utils.version.VersionRange;
-import org.apache.felix.utils.version.VersionTable;
-import org.apache.karaf.bundle.command.bundletree.Node;
-import org.apache.karaf.bundle.command.bundletree.Tree;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-import org.osgi.framework.wiring.BundleCapability;
-import org.osgi.framework.wiring.BundleRevision;
-import org.osgi.framework.wiring.BundleRevisions;
-import org.osgi.framework.wiring.BundleWire;
-import org.osgi.framework.wiring.BundleWiring;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static java.lang.String.format;
-
-/**
- * Command for showing the full tree of bundles that have been used to resolve
- * a given bundle.
- */
-@Command(scope = "bundle", name = "tree-show", description = "Shows the tree of bundles based on the wiring information.")
-@Service
-public class ShowBundleTree extends BundleCommand {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ShowBundleTree.class);
- private Tree<Bundle> tree;
-
- public ShowBundleTree() {
- super(false);
- }
-
- @Override
- protected void doExecute(Bundle bundle) throws Exception {
- long start = System.currentTimeMillis();
- // let's do the real work here
- printHeader(bundle);
- tree = new Tree<Bundle>(bundle);
- createTree(bundle);
- printTree(tree);
- printDuplicatePackages(tree);
- LOGGER.debug(format("Dependency tree calculated in %d ms",
- System.currentTimeMillis() - start));
- }
-
- /**
- * Return a String representation of a bundle state
- */
- private String getState(Bundle bundle) {
- switch (bundle.getState()) {
- case Bundle.UNINSTALLED : return "UNINSTALLED";
- case Bundle.INSTALLED : return "INSTALLED";
- case Bundle.RESOLVED: return "RESOLVED";
- case Bundle.STARTING : return "STARTING";
- case Bundle.STOPPING : return "STOPPING";
- case Bundle.ACTIVE : return "ACTIVE";
- default : return "UNKNOWN";
- }
- }
-
- /*
- * Print the header
- */
- private void printHeader(Bundle bundle) {
- System.out.printf("Bundle %s [%s] is currently %s%n",
- bundle.getSymbolicName(),
- bundle.getBundleId(),
- getState(bundle));
- }
-
- /*
- * Print the dependency tree
- */
- private void printTree(Tree<Bundle> tree) {
- System.out.printf("%n");
- tree.write(System.out, new Tree.Converter<Bundle>() {
-
- public String toString(Node<Bundle> node) {
- return String.format("%s [%s]",
- node.getValue().getSymbolicName(),
- node.getValue().getBundleId());
- }
- });
- }
-
- /*
- * Check for bundles in the tree exporting the same package
- * as a possible cause for 'Unresolved constraint...' on a uses-conflict
- */
- private void printDuplicatePackages(Tree<Bundle> tree) {
- Set<Bundle> bundles = tree.flatten();
- Map<String, Set<Bundle>> exports = new HashMap<String, Set<Bundle>>();
-
- for (Bundle bundle : bundles) {
- for (BundleRevision revision : bundle.adapt(BundleRevisions.class).getRevisions()) {
- BundleWiring wiring = revision.getWiring();
- if (wiring != null) {
- List<BundleWire> wires = wiring.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);
- if (wires != null) {
- for (BundleWire wire : wires) {
- String name = wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).toString();
- if (exports.get(name) == null) {
- exports.put(name, new HashSet<Bundle>());
- }
- exports.get(name).add(bundle);
- }
- }
- }
- }
- }
-
- for (String pkg : exports.keySet()) {
- if (exports.get(pkg).size() > 1) {
- System.out.printf("%n");
- System.out.printf("WARNING: multiple bundles are exporting package %s%n", pkg);
- for (Bundle bundle : exports.get(pkg)) {
- System.out.printf("- %s%n", bundle);
- }
- }
- }
- }
-
- /*
- * Creates the bundle tree
- */
- protected void createTree(Bundle bundle) {
- if (bundle.getState() >= Bundle.RESOLVED) {
- createNode(tree);
- } else {
- createNodesForImports(tree, bundle);
- System.out.print("\nWarning: the below tree is a rough approximation of a possible resolution");
- }
- }
-
- /*
- * Creates nodes for the imports of the bundle (instead of reporting wiring information
- */
- private void createNodesForImports(Node<Bundle> node, Bundle bundle) {
- Clause[] imports = Parser.parseHeader(bundle.getHeaders().get("Import-Package"));
- Clause[] exports = Parser.parseHeader(bundle.getHeaders().get("Export-Package"));
- for (Clause i : imports) {
- boolean exported = false;
- for (Clause e : exports) {
- if (e.getName().equals(i.getName())) {
- exported = true;
- break;
- }
- }
- if (!exported) {
- createNodeForImport(node, bundle, i);
- }
- }
- }
-
- /*
- * Create a child node for a given import (by finding a matching export in the currently installed bundles)
- */
- private void createNodeForImport(Node<Bundle> node, Bundle bundle, Clause i) {
- VersionRange range = VersionRange.parseVersionRange(i.getAttribute(Constants.VERSION_ATTRIBUTE));
- boolean foundMatch = false;
- for (Bundle b : bundleContext.getBundles()) {
- BundleWiring wiring = b.adapt(BundleWiring.class);
- if (wiring != null) {
- List<BundleCapability> caps = wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
- if (caps != null) {
- for (BundleCapability cap : caps) {
- String n = getAttribute(cap, BundleRevision.PACKAGE_NAMESPACE);
- String v = getAttribute(cap, Constants.VERSION_ATTRIBUTE);
- if (i.getName().equals(n) && range.contains(VersionTable.getVersion(v))) {
- boolean existing = tree.flatten().contains(b);
- System.out.printf("- import %s: resolved using %s%n", i, b);
- foundMatch = true;
- if (!node.hasChild(b)) {
- Node<Bundle> child = node.addChild(b);
- if (!existing) {
- createNode(child);
- }
- }
- }
- }
- }
- }
- }
- if (!foundMatch) {
- System.out.printf("- import %s: WARNING - unable to find matching export%n", i);
- }
- }
-
- private String getAttribute(BundleCapability capability, String name) {
- Object o = capability.getAttributes().get(name);
- return o != null ? o.toString() : null;
- }
-
- /*
- * Creates a node in the bundle tree
- */
- private void createNode(Node<Bundle> node) {
- Bundle bundle = node.getValue();
- Collection<Bundle> exporters = new HashSet<Bundle>();
- exporters.addAll(bundleService.getWiredBundles(bundle).values());
-
- for (Bundle exporter : exporters) {
- if (node.hasAncestor(exporter)) {
- LOGGER.debug(format("Skipping %s (already exists in the current branch)", exporter));
- } else {
- boolean existing = tree.flatten().contains(exporter);
- LOGGER.debug(format("Adding %s as a dependency for %s", exporter, bundle));
- Node<Bundle> child = node.addChild(exporter);
- if (existing) {
- LOGGER.debug(format("Skipping children of %s (already exists in another branch)", exporter));
- } else {
- createNode(child);
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/Start.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Start.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/Start.java
deleted file mode 100644
index 48e90fa..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Start.java
+++ /dev/null
@@ -1,32 +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.karaf.bundle.command;
-
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.osgi.framework.Bundle;
-
-@Command(scope = "bundle", name = "start", description = "Starts bundles.")
-@Service
-public class Start extends BundlesCommandWithConfirmation {
-
- @Override
- protected void executeOnBundle(Bundle bundle) throws Exception {
- bundle.start();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/StartLevel.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/StartLevel.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/StartLevel.java
deleted file mode 100644
index 30bec0f..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/StartLevel.java
+++ /dev/null
@@ -1,64 +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.karaf.bundle.command;
-
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.startlevel.BundleStartLevel;
-
-@Command(scope = "bundle", name = "start-level", description = "Gets or sets the start level of a bundle.")
-@Service
-public class StartLevel extends BundleCommandWithConfirmation {
-
- @Argument(index = 1, name = "startLevel", description = "The bundle's new start level", required = false, multiValued = false)
- Integer level;
-
- @Reference
- Session session;
-
- protected void doExecute(Bundle bundle) throws Exception {
- // Get package instance service.
- BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class);
- if (bsl == null) {
- System.out.println("StartLevel service is unavailable.");
- return;
- }
- if (level == null) {
- System.out.println("Level " + bsl.getStartLevel());
- }
- else if ((level < 50) && (bsl.getStartLevel() > 50) && !force){
- for (;;) {
- String msg = "You are about to designate bundle as a system bundle. Do you wish to continue (yes/no): ";
- String str = session.readLine(msg, null);
- if ("yes".equalsIgnoreCase(str)) {
- bsl.setStartLevel(level);
- break;
- } else if ("no".equalsIgnoreCase(str)) {
- break;
- }
- }
-
- } else {
- bsl.setStartLevel(level);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/Stop.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Stop.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/Stop.java
deleted file mode 100644
index 0b0fed2..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Stop.java
+++ /dev/null
@@ -1,44 +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.karaf.bundle.command;
-
-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.osgi.framework.Bundle;
-
-@Command(scope = "bundle", name = "stop", description = "Stop bundles.")
-@Service
-public class Stop extends BundlesCommandWithConfirmation {
-
- @Option(name = "-t", aliases={"--transient"}, description="Keep the bundle as auto-start", required = false, multiValued = false)
- boolean transientStop;
-
- public Stop() {
- this.errorMessage = "Unable to stop bundle";
- }
-
- @Override
- protected void executeOnBundle(Bundle bundle) throws Exception {
- if (transientStop) {
- bundle.stop(Bundle.STOP_TRANSIENT);
- } else {
- bundle.stop();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/Uninstall.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Uninstall.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/Uninstall.java
deleted file mode 100644
index 67b5b14..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Uninstall.java
+++ /dev/null
@@ -1,36 +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.karaf.bundle.command;
-
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.osgi.framework.Bundle;
-
-@Command(scope = "bundle", name = "uninstall", description = "Uninstall bundles.")
-@Service
-public class Uninstall extends BundlesCommandWithConfirmation {
-
- public Uninstall() {
- this.errorMessage = "Unable to uninstall bundle";
- }
-
- @Override
- protected void executeOnBundle(Bundle bundle) throws Exception {
- bundle.uninstall();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/Update.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Update.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/Update.java
deleted file mode 100644
index 71ae74d..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Update.java
+++ /dev/null
@@ -1,48 +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.karaf.bundle.command;
-
-import java.io.InputStream;
-import java.net.URL;
-
-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.osgi.framework.Bundle;
-
-@Command(scope = "bundle", name = "update", description = "Update bundle.")
-@Service
-public class Update extends BundleCommandWithConfirmation {
-
- @Argument(index = 1, name = "location", description = "The bundles update location", required = false, multiValued = false)
- String location;
-
- protected void doExecute(Bundle bundle) throws Exception {
- InputStream is = null;
- if (location != null) {
- try {
- is = new URL(location).openStream();
- bundle.update(is);
- } finally {
- is.close();
- }
- } else {
- bundle.update();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/Watch.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Watch.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/Watch.java
deleted file mode 100644
index 9203f59..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/Watch.java
+++ /dev/null
@@ -1,128 +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.karaf.bundle.command;
-
-import java.util.List;
-
-import org.apache.karaf.bundle.core.BundleWatcher;
-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.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-
-@Command(scope = "bundle", name = "watch", description = "Watches and updates bundles", detailedDescription = "Watches the local maven repo for changes in snapshot jars and redploys changed jars")
-@Service
-public class Watch implements Action {
-
- @Argument(index = 0, name = "urls", description = "The bundle IDs or URLs", required = false, multiValued = true)
- List<String> urls;
-
- @Option(name = "-i", aliases = {}, description = "Watch interval", required = false, multiValued = false)
- private long interval;
-
- @Option(name = "--start", description = "Starts watching the selected bundles", required = false, multiValued = false)
- protected boolean start;
-
- @Option(name = "--stop", description = "Stops watching all bundles", required = false, multiValued = false)
- protected boolean stop;
-
- @Option(name = "--remove", description = "Removes bundles from the watch list", required = false, multiValued = false)
- protected boolean remove;
-
- @Option(name = "--list", description = "Displays the watch list", required = false, multiValued = false)
- protected boolean list;
-
- @Reference
- private BundleWatcher bundleWatcher;
-
- public void setBundleWatcher(BundleWatcher bundleWatcher) {
- this.bundleWatcher = bundleWatcher;
- }
-
- @Override
- public Object execute() throws Exception {
- if (start && stop) {
- System.err.println("Please use only one of --start and --stop options!");
- return null;
- }
-
- if (interval > 0) {
- System.out.println("Setting watch interval to " + interval + " ms");
- bundleWatcher.setInterval(interval);
- }
- if (stop) {
- System.out.println("Stopping watch");
- bundleWatcher.stop();
- }
- if (urls != null) {
- if (remove) {
- for (String url : urls) {
- bundleWatcher.remove(url);
- }
- } else {
- for (String url : urls) {
- bundleWatcher.add(url);
- }
- }
- }
- if (start) {
- System.out.println("Starting watch");
- bundleWatcher.start();
- }
-
- if (list) { //List the watched bundles.
- String format = "%-40s %6s %-80s";
- System.out.println(String.format(format, "URL", "ID", "Bundle Name"));
- for (String url : bundleWatcher.getWatchURLs()) {
-
- List<Bundle> bundleList = bundleWatcher.getBundlesByURL(url);
- if (bundleList != null && bundleList.size() > 0) {
- for (Bundle bundle : bundleList) {
- System.out.println(String.format(format, url, bundle.getBundleId(), bundle.getHeaders().get(Constants.BUNDLE_NAME)));
- }
- } else {
- System.out.println(String.format(format, url, "", ""));
- }
- }
- } else {
- List<String> urls = bundleWatcher.getWatchURLs();
- if (urls != null && urls.size()>0) {
- System.out.println("Watched URLs/IDs: ");
- for (String url : bundleWatcher.getWatchURLs()) {
- System.out.println(url);
- }
- } else {
- System.out.println("No watched URLs/IDs");
- }
- }
-
- return null;
- }
-
-}
-
-
-
-
-
-
-
-
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/bundletree/Node.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/bundletree/Node.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/bundletree/Node.java
deleted file mode 100644
index fe4dc2a..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/bundletree/Node.java
+++ /dev/null
@@ -1,159 +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.karaf.bundle.command.bundletree;
-
-import java.io.PrintWriter;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Represents a node in a {@link Tree}
- */
-public class Node<T> {
-
- private final T value;
- private Node<T> parent;
- private List<Node<T>> children = new LinkedList<Node<T>>();
-
- /**
- * Creates a new node. Only meant for wrapper use,
- * new nodes should be added using the {@link #addChild(Object)} method
- *
- * @param value the node value
- */
- protected Node(T value) {
- super();
- this.value = value;
- }
-
- /**
- * Creates a new node. Only meant for wrapper use,
- * new nodes should be added using the {@link #addChild(Object)} method
- *
- * @param value the node value
- */
- protected Node(T value, Node<T> parent) {
- this(value);
- this.parent = parent;
- }
-
- /**
- * Access the node's value
- */
- public T getValue() {
- return value;
- }
-
- /**
- * Access the node's child nodes
- */
- public List<Node<T>> getChildren() {
- return children;
- }
-
- /**
- * Adds a child to this node
- *
- * @param value the child's value
- * @return the child node
- */
- public Node<T> addChild(T value) {
- Node<T> node = new Node<T>(value, this);
- children.add(node);
- return node;
- }
-
- /**
- * Give a set of values in the tree.
- *
- * @return
- */
- public Set<T> flatten() {
- Set<T> result = new HashSet<T>();
- result.add(getValue());
- for (Node<T> child : getChildren()) {
- result.addAll(child.flatten());
- }
- return result;
- }
-
- /**
- * Check if the node has an ancestor that represents the given value
- *
- * @param value the node value
- * @return <code>true</code> it there's an ancestor that represents the value
- */
- public boolean hasAncestor(T value) {
- if (parent == null) {
- return false;
- } else {
- return value.equals(parent.value) || parent.hasAncestor(value);
- }
- }
-
- public boolean hasChild(T value) {
- for (Node<T> child : getChildren()) {
- if (value.equals(child.getValue())) {
- return true;
- }
- }
- return false;
- }
-
- /*
- * Write this node to the PrintWriter. It should be indented one step
- * further for every element in the indents array. If an element in the
- * array is <code>true</code>, there should be a | to connect to the next
- * sibling.
- */
- protected void write(PrintWriter writer, Tree.Converter<T> converter, boolean... indents) {
- for (boolean indent : indents) {
- writer.printf("%-3s", indent ? "|" : "");
- }
- writer.printf("+- %s%n", converter.toString(this));
- for (Node<T> child : getChildren()) {
- child.write(writer, converter, concat(indents, hasNextSibling()));
- }
- }
-
- /*
- * Is this node the last child node for its parent
- * or is there a next sibling?
- */
- private boolean hasNextSibling() {
- if (parent == null) {
- return false;
- } else {
- return parent.getChildren().size() > 1
- && parent.getChildren().indexOf(this) < parent.getChildren().size() - 1;
- }
- }
-
- /*
- * Add an element to the end of the array
- */
- private boolean[] concat(boolean[] array, boolean element) {
- boolean[] result = new boolean[array.length + 1];
- for (int i = 0 ; i < array.length ; i++) {
- result[i] = array[i];
- }
- result[array.length] = element;
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/bundletree/Tree.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/bundletree/Tree.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/bundletree/Tree.java
deleted file mode 100644
index 7a7b64e..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/bundletree/Tree.java
+++ /dev/null
@@ -1,100 +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.karaf.bundle.command.bundletree;
-
-import java.io.PrintStream;
-import java.io.PrintWriter;
-
-/**
- * Represents a tree that can be written to the console.
- *
- * The output will look like this:
- * <pre>
- * root
- * +- child1
- * | +- grandchild
- * +- child2
- * </pre>
- */
-public class Tree<T> extends Node<T> {
-
- /**
- * Creates a new tree with the given root node
- *
- * @param root the root node
- */
- public Tree(T root) {
- super(root);
- }
-
- /**
- * Write the tree to a PrintStream, using the default toString() method to output the node values
- *
- * @param stream
- */
- public void write(PrintStream stream) {
- write(new PrintWriter(stream));
- }
-
- /**
- * Write the tree to a PrintStream, using the provided converter to output the node values
- *
- * @param stream
- * @param converter
- */
- public void write(PrintStream stream, Converter<T> converter) {
- write(new PrintWriter(stream), converter);
- }
-
- /**
- * Write the tree to a PrintWriter, using the default toString() method to output the node values
- *
- * @param writer
- */
- public void write(PrintWriter writer) {
- write(writer, new Converter() {
- public String toString(Node node) {
- return node.getValue().toString();
- }
- });
- }
-
- /**
- * Write the tree to a PrintWriter, using the provided converter to output the node values
- *
- * @param writer
- * @param converter
- */
- public void write(PrintWriter writer, Converter<T> converter) {
- writer.printf("%s%n", converter.toString(this));
- for (Node<T> child : getChildren()) {
- child.write(writer, converter);
- }
- writer.flush();
- }
-
- /**
- * Interface to convert node values to string
- *
- * @param <T> the object type for the node value
- */
- public static interface Converter<T> {
-
- public String toString(Node<T> node);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/AnsiPrintingWikiVisitor.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/AnsiPrintingWikiVisitor.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/AnsiPrintingWikiVisitor.java
deleted file mode 100644
index 077cfef..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/AnsiPrintingWikiVisitor.java
+++ /dev/null
@@ -1,58 +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.karaf.bundle.command.wikidoc;
-
-import java.io.PrintStream;
-
-import org.fusesource.jansi.Ansi;
-import org.fusesource.jansi.Ansi.Attribute;
-import org.fusesource.jansi.Ansi.Color;
-
-/**
- * Translates the Wiki tags to Ansi escape sequences to display them on the console
- */
-public class AnsiPrintingWikiVisitor implements WikiVisitor {
- private PrintStream out;
-
- public AnsiPrintingWikiVisitor(PrintStream out) {
- this.out = out;
- }
-
- @Override
- public void heading(int level, String header) {
- this.out.print(Ansi.ansi().a(Attribute.INTENSITY_BOLD).a(header)
- .a(Attribute.INTENSITY_BOLD_OFF).toString());
- }
-
- @Override
- public void link(String target, String title) {
- this.out.print(Ansi.ansi().fg(Color.YELLOW)
- .a(target).fg(Color.DEFAULT));
- }
-
- @Override
- public void enumeration(String text) {
- this.out.print(Ansi.ansi().a(" * ").fg(Color.CYAN).a(text).fg(Color.DEFAULT).a(" "));
- }
-
- @Override
- public void text(String text) {
- this.out.print(text);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/WikiParser.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/WikiParser.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/WikiParser.java
deleted file mode 100644
index 8ec3d5b..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/WikiParser.java
+++ /dev/null
@@ -1,86 +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.karaf.bundle.command.wikidoc;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.StringTokenizer;
-
-/**
- * Parses wiki syntax from a reader and calls a Wikivisitor with the
- * tokens it finds
- */
-public class WikiParser {
- WikiVisitor visitor;
-
- public WikiParser(WikiVisitor visitor) {
- this.visitor = visitor;
- }
-
- public void parse(String line) {
- StringTokenizer tokenizer = new StringTokenizer(line , "[h*", true);
- while (tokenizer.hasMoreTokens()) {
- String token = tokenizer.nextToken();
- if ("[".equals(token)) {
- parseLink(tokenizer);
- } else if ("h".equals(token)) {
- parseHeading(tokenizer);
- } else if ("*".equals(token)){
- parseEnumeration(tokenizer);
- } else {
- visitor.text(token);
- }
- }
- }
-
- private void parseEnumeration(StringTokenizer tokenizer) {
- String text = tokenizer.nextToken("-\n");
- visitor.enumeration(text.trim());
- }
-
- private void parseHeading(StringTokenizer tokenizer) {
- String level = tokenizer.nextToken("123456789");
- if (!level.matches("[123456789]")) {
- visitor.text("h" + level);
- return;
- }
- String dot = tokenizer.nextToken(".\n");
- if (!".".equals(dot)) {
- visitor.text("h" + level + dot);
- return;
- }
- String heading = tokenizer.hasMoreTokens() ? tokenizer.nextToken("\n") : "";
- visitor.heading(new Integer(level), heading.trim());
- }
-
- private void parseLink(StringTokenizer tokenizer) {
- String token = tokenizer.nextToken("]");
- visitor.link(token, "");
- tokenizer.nextToken();
- }
-
- public void parse(Reader reader) throws IOException {
- BufferedReader br = new BufferedReader(reader);
- String line;
- while ((line = br.readLine()) != null) {
- parse(line);
- visitor.text("\n");
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/WikiVisitor.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/WikiVisitor.java b/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/WikiVisitor.java
deleted file mode 100644
index b4a5fb3..0000000
--- a/bundle/command/src/main/java/org/apache/karaf/bundle/command/wikidoc/WikiVisitor.java
+++ /dev/null
@@ -1,29 +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.karaf.bundle.command.wikidoc;
-
-/**
- * Will be used by WikiParser to call the respective handler when it recognizes the tag
- */
-public interface WikiVisitor {
-
- void link(String target, String title);
- void heading(int level, String title);
- void enumeration(String text);
- void text(String text);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/main/resources/OSGI-INF/bundle.info
----------------------------------------------------------------------
diff --git a/bundle/command/src/main/resources/OSGI-INF/bundle.info b/bundle/command/src/main/resources/OSGI-INF/bundle.info
deleted file mode 100644
index af2c24f..0000000
--- a/bundle/command/src/main/resources/OSGI-INF/bundle.info
+++ /dev/null
@@ -1,32 +0,0 @@
-h1. Synopsis
-
-${project.name}
-
-${project.description}
-
-Maven URL:
- [mvn:${project.groupId}/${project.artifactId}/${project.version}]
-
-h1. Description
-
-This bundle provides the low level OSGi shell commands.
-
-The following commands are available:
-* bundle:classes - Displays a list of classes contained in the bundle
-* bundle:find-class - Locates a specified class in any deployed bundle
-* bundle:headers - Display OSGi headers of a given bundle.
-* bundle:info - Display detailed information of a given bundle.
-* bundle:install - Install one or more bundles.
-* bundle:list - List all installed bundles.
-* bundle:refresh - Refresh bundles.
-* bundle:resolve - Resolve bundles.
-* bundle:restart - Stop and restart bundles.
-* bundle:start - Starts bundles.
-* bundlestart-level - Get or set the start level of a bundle.
-* bundle:stop - Stop bundles.
-* bundle:uninstall - Uninstall bundles.
-* bundle:update - Update a bundle.
-
-h1. See also
-
-Commands and Using the console sections of the Karaf User Guide
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/test/java/org/apache/karaf/bundle/command/ListServicesTest.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/test/java/org/apache/karaf/bundle/command/ListServicesTest.java b/bundle/command/src/test/java/org/apache/karaf/bundle/command/ListServicesTest.java
deleted file mode 100644
index 876f605..0000000
--- a/bundle/command/src/test/java/org/apache/karaf/bundle/command/ListServicesTest.java
+++ /dev/null
@@ -1,61 +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.karaf.bundle.command;
-
-import java.util.Arrays;
-import java.util.Collections;
-
-import org.apache.karaf.bundle.core.internal.BundleServiceImpl;
-import org.junit.Test;
-import org.osgi.framework.BundleContext;
-
-public class ListServicesTest {
-
- private ListBundleServices listServices;
-
- @SuppressWarnings("unchecked")
- public ListServicesTest() {
- listServices = new ListBundleServices();
- BundleContext bundleContext = new TestBundleFactory().createBundleContext();
- listServices.setBundleContext(bundleContext);
- listServices.setBundleService(new BundleServiceImpl(bundleContext));
- }
-
- @Test
- public void listAllShort() throws Exception {
- System.out.println("listAllShort");
- listServices.execute();
- }
-
-
- @Test
- public void listAllLong() throws Exception {
- System.out.println("listAllLong");
- listServices.ids = Arrays.asList(new String[]{"1", "2"});
- listServices.execute();
- }
-
- @Test
- public void listAllLongServiceUse() throws Exception {
- System.out.println("listAllLongServicesUse");
- listServices.ids = Arrays.asList(new String[]{"1", "2"});
- listServices.inUse = true;
- listServices.execute();
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/test/java/org/apache/karaf/bundle/command/TestBundleFactory.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/test/java/org/apache/karaf/bundle/command/TestBundleFactory.java b/bundle/command/src/test/java/org/apache/karaf/bundle/command/TestBundleFactory.java
deleted file mode 100644
index 27e4a63..0000000
--- a/bundle/command/src/test/java/org/apache/karaf/bundle/command/TestBundleFactory.java
+++ /dev/null
@@ -1,104 +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.karaf.bundle.command;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-
-public class TestBundleFactory {
- ServiceReference<?> createServiceRef(Object ... keyProp) {
- ServiceReference<?> serviceRef = createMock(ServiceReference.class);
- if (keyProp.length % 2 != 0) {
- throw new IllegalArgumentException("");
- }
- Hashtable<String, Object> keyPropMap = new Hashtable<String, Object>();
- int c = 0;
- while (c < keyProp.length) {
- String key = (String)keyProp[c++];
- Object value = (Object)keyProp[c++];
- keyPropMap.put(key, value);
- expect(serviceRef.getProperty(key)).andReturn(value).anyTimes();
- }
- expect(serviceRef.getPropertyKeys()).andReturn(Collections.list(keyPropMap.keys()).toArray(new String[]{})).anyTimes();
- return serviceRef;
- }
-
- Bundle createBundle(long id, String name) {
- Bundle bundle = createMock(Bundle.class);
- expect(bundle.getBundleId()).andReturn(id).anyTimes();
- Dictionary<String, String> headers = new Hashtable<String, String>();
- headers.put(Constants.BUNDLE_NAME, name);
- expect(bundle.getHeaders()).andReturn(headers).anyTimes();
- return bundle;
- }
-
- private Bundle[] createBundles() {
- Bundle bundle1 = createBundle(1, "Bundle A");
- Bundle bundle2 = createBundle(2, "Bundle B");
- Bundle bundle3 = createBundle(3, "Bundle C");
-
- ServiceReference<?> ref1 = createServiceRef(Constants.OBJECTCLASS, new String[]{"org.example.MyService"},
- "key1", "value1");
- ServiceReference<?> ref2 = createServiceRef(Constants.OBJECTCLASS, new String[]{"org.example.OtherService"}, "key2", 1);
-
- addRegisteredServices(bundle1, ref1, ref2);
- addRegisteredServices(bundle2, ref2);
- expect(bundle3.getRegisteredServices()).andReturn(null).anyTimes();
-
- expect(bundle1.getServicesInUse()).andReturn(null).anyTimes();
- addUsedServices(bundle2, ref1);
- addUsedServices(bundle3, ref1, ref2);
-
- expect(ref1.getUsingBundles()).andReturn(new Bundle[]{bundle2, bundle3}).anyTimes();
- expect(ref2.getUsingBundles()).andReturn(new Bundle[]{bundle3}).anyTimes();
-
- replay(bundle1, bundle2, bundle3, ref1, ref2);
- return new Bundle[] { bundle1, bundle2, bundle3 };
- }
-
- private void addUsedServices(Bundle bundle, ServiceReference<?> ... refs) {
- expect(bundle.getServicesInUse()).andReturn(refs).anyTimes();
- }
-
- private void addRegisteredServices(Bundle bundle, ServiceReference<?> ... refs) {
- expect(bundle.getRegisteredServices()).andReturn(refs).anyTimes();
- for (ServiceReference<?> ref : refs) {
- expect(ref.getBundle()).andReturn(bundle);
- }
- }
-
- public BundleContext createBundleContext() {
- BundleContext bundleContext = createMock(BundleContext.class);
- Bundle[] bundles = createBundles();
- expect(bundleContext.getBundles()).andReturn(bundles).anyTimes();
- expect(bundleContext.getBundle(0)).andReturn(null).anyTimes();
- expect(bundleContext.getBundle(1)).andReturn(bundles[0]).anyTimes();
- expect(bundleContext.getBundle(2)).andReturn(bundles[1]).anyTimes();
- replay(bundleContext);
- return bundleContext;
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/test/java/org/apache/karaf/bundle/command/bundletree/TreeTest.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/test/java/org/apache/karaf/bundle/command/bundletree/TreeTest.java b/bundle/command/src/test/java/org/apache/karaf/bundle/command/bundletree/TreeTest.java
deleted file mode 100644
index df0d7d6..0000000
--- a/bundle/command/src/test/java/org/apache/karaf/bundle/command/bundletree/TreeTest.java
+++ /dev/null
@@ -1,135 +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.karaf.bundle.command.bundletree;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.Set;
-
-import org.apache.karaf.bundle.command.bundletree.Node;
-import org.apache.karaf.bundle.command.bundletree.Tree;
-import org.junit.Test;
-
-/**
- * Test cases for {@link org.apache.karaf.shell.dev.util.Tree}
- * and {@link org.apache.karaf.shell.dev.util.Node}
- */
-public class TreeTest {
-
- @Test
- public void writeTreeWithOneChild() throws IOException {
- Tree<String> tree = new Tree<String>("root");
- tree.addChild("child");
-
- BufferedReader reader = read(tree);
-
- assertEquals("root" , reader.readLine());
- assertEquals("+- child" , reader.readLine());
- }
-
- @Test
- public void writeTreeWithOneChildAndNodeConverter() throws IOException {
- Tree<String> tree = new Tree<String>("root");
- tree.addChild("child");
-
- StringWriter writer = new StringWriter();
- tree.write(new PrintWriter(writer), new Tree.Converter<String>() {
- public String toString(Node<String> node) {
- return "my " + node.getValue();
- }
- });
-
- BufferedReader reader = new BufferedReader(new StringReader(writer.getBuffer().toString()));
-
- assertEquals("my root" , reader.readLine());
- assertEquals("+- my child" , reader.readLine());
- }
-
- @Test
- public void writeTreeWithChildAndGrandChild() throws IOException {
- Tree<String> tree = new Tree<String>("root");
- Node<String> node = tree.addChild("child");
- node.addChild("grandchild");
-
- BufferedReader reader = read(tree);
-
- assertEquals("root" , reader.readLine());
- assertEquals("+- child" , reader.readLine());
- assertEquals(" +- grandchild", reader.readLine());
- }
-
- @Test
- public void writeTreeWithTwoChildrenAndOneGrandchild() throws IOException {
- Tree<String> tree = new Tree<String>("root");
- Node<String> child = tree.addChild("child1");
- child.addChild("grandchild");
- tree.addChild("child2");
-
- BufferedReader reader = read(tree);
-
- assertEquals("root" , reader.readLine());
- assertEquals("+- child1" , reader.readLine());
- assertEquals("| +- grandchild", reader.readLine());
- assertEquals("+- child2" , reader.readLine());
- }
-
- @Test
- public void flattenTree() throws IOException {
- Tree<String> tree = new Tree<String>("root");
- Node<String> child1 = tree.addChild("child1");
- child1.addChild("grandchild");
- Node child2 = tree.addChild("child2");
- child2.addChild("grandchild");
-
- Set<String> elements = tree.flatten();
- assertNotNull(elements);
- assertEquals(4, elements.size());
- assertTrue(elements.contains("root"));
- assertTrue(elements.contains("child1"));
- assertTrue(elements.contains("child2"));
- assertTrue(elements.contains("grandchild"));
- }
-
- @Test
- public void hasAncestor() throws IOException {
- Tree<String> tree = new Tree<String>("root");
- Node<String> child1 = tree.addChild("child1");
- child1.addChild("grandchild");
- Node child2 = tree.addChild("child2");
- Node node = child2.addChild("grandchild2");
-
- assertTrue(node.hasAncestor("child2"));
- assertTrue(node.hasAncestor("root"));
- assertFalse(node.hasAncestor("child1"));
- }
-
- private BufferedReader read(Tree<String> tree) {
- StringWriter writer = new StringWriter();
- tree.write(new PrintWriter(writer));
-
- BufferedReader reader = new BufferedReader(new StringReader(writer.getBuffer().toString()));
- return reader;
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/command/src/test/java/org/apache/karaf/bundle/command/wikidoc/WikiParserTest.java
----------------------------------------------------------------------
diff --git a/bundle/command/src/test/java/org/apache/karaf/bundle/command/wikidoc/WikiParserTest.java b/bundle/command/src/test/java/org/apache/karaf/bundle/command/wikidoc/WikiParserTest.java
deleted file mode 100644
index 37101c3..0000000
--- a/bundle/command/src/test/java/org/apache/karaf/bundle/command/wikidoc/WikiParserTest.java
+++ /dev/null
@@ -1,94 +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.karaf.bundle.command.wikidoc;
-
-import java.io.IOException;
-import java.io.StringReader;
-
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class WikiParserTest {
-
- private static final String TESTDOC =
- "h1. myTestdoc\n" +
- "\n" +
- "Some text\n" +
- "* enumeration\n" +
- " some text [a link] some more text\n" +
- "h1 is no heading";
-
- private static final String HEADINGCASES =
- "h1.\n" +
- "hf.";
-
- @Test
- public void parseTestDoc() throws IOException {
- WikiVisitor visitor = EasyMock.createStrictMock(WikiVisitor.class);
- visitor.heading(1, "myTestdoc");
- EasyMock.expectLastCall();
- visitor.text("\n");
- EasyMock.expectLastCall();
- visitor.text("\n");
- EasyMock.expectLastCall();
- visitor.text("Some text");
- EasyMock.expectLastCall();
- visitor.text("\n");
- EasyMock.expectLastCall();
- visitor.enumeration("enumeration");
- EasyMock.expectLastCall();
- visitor.text("\n");
- EasyMock.expectLastCall();
- visitor.text(" some text ");
- EasyMock.expectLastCall();
- visitor.link("a link", "");
- EasyMock.expectLastCall();
- visitor.text(" some more text");
- EasyMock.expectLastCall();
- visitor.text("\n");
- EasyMock.expectLastCall();
- visitor.text("h1 is no heading");
- EasyMock.expectLastCall();
- visitor.text("\n");
- EasyMock.expectLastCall();
-
- EasyMock.replay(visitor);
- WikiParser parser = new WikiParser(visitor);
- parser.parse(new StringReader(TESTDOC));
- EasyMock.verify(visitor);
- }
-
- @Test
- public void parseHeadingSpecialCases() throws IOException {
- WikiVisitor visitor = EasyMock.createStrictMock(WikiVisitor.class);
-
- visitor.heading(1, "");
- EasyMock.expectLastCall();
- visitor.text("\n");
- EasyMock.expectLastCall();
-
- visitor.text("hf.");
- EasyMock.expectLastCall();
- visitor.text("\n");
- EasyMock.expectLastCall();
-
- EasyMock.replay(visitor);
- WikiParser parser = new WikiParser(visitor);
- parser.parse(new StringReader(HEADINGCASES));
- EasyMock.verify(visitor);
- }
-}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/core/pom.xml
----------------------------------------------------------------------
diff --git a/bundle/core/pom.xml b/bundle/core/pom.xml
index f3cccd8..b698d48 100644
--- a/bundle/core/pom.xml
+++ b/bundle/core/pom.xml
@@ -79,6 +79,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.core</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<scope>test</scope>
@@ -111,6 +117,7 @@
org.apache.karaf.bundle.core;-noimport:=true
</Export-Package>
<Private-Package>
+ org.apache.karaf.bundle.command*,
org.apache.karaf.bundle.core.internal,
org.apache.karaf.bundle.core.internal.osgi,
org.apache.karaf.util.maven,
@@ -121,6 +128,7 @@
<Bundle-Activator>
org.apache.karaf.bundle.core.internal.osgi.Activator
</Bundle-Activator>
+ <Karaf-Commands>org.apache.karaf.bundle.command.*</Karaf-Commands>
</instructions>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
new file mode 100644
index 0000000..dce0ca8
--- /dev/null
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.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.karaf.bundle.command;
+
+import org.apache.karaf.bundle.core.BundleService;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.support.ShellUtil;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Unique bundle command.
+ */
+public abstract class BundleCommand implements Action {
+
+ @Argument(index = 0, name = "id", description = "The bundle ID or name or name/version", required = true, multiValued = false)
+ String id;
+
+ boolean defaultAllBundles = true;
+
+ @Reference
+ BundleService bundleService;
+
+ @Reference
+ BundleContext bundleContext;
+
+ public BundleCommand(boolean defaultAllBundles) {
+ this.defaultAllBundles = defaultAllBundles;
+ }
+
+ public Object execute() throws Exception {
+ return doExecute(true);
+ }
+
+ protected Object doExecute(boolean force) throws Exception {
+ Bundle bundle = bundleService.getBundle(id, defaultAllBundles);
+ if (bundle != null) {
+ if (force || !ShellUtil.isASystemBundle(bundleContext, bundle)) {
+ doExecute(bundle);
+ } else {
+ System.err.println("Access to system bundle " + id + " is discouraged. You may override with -f");
+ }
+ }
+ return null;
+ }
+
+ protected abstract void doExecute(Bundle bundle) throws Exception;
+
+ public void setBundleService(BundleService bundleService) {
+ this.bundleService = bundleService;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommandWithConfirmation.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommandWithConfirmation.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommandWithConfirmation.java
new file mode 100644
index 0000000..c07a357
--- /dev/null
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommandWithConfirmation.java
@@ -0,0 +1,37 @@
+/*
+ * 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.karaf.bundle.command;
+
+import org.apache.karaf.shell.api.action.Option;
+
+/**
+ * Unique bundle command with confirmation while accessing system bundle.
+ */
+public abstract class BundleCommandWithConfirmation extends BundleCommand {
+
+ @Option(name = "--force", aliases = {"-f"}, description = "Forces the command to execute", required = false, multiValued = false)
+ boolean force;
+
+ public BundleCommandWithConfirmation() {
+ super(true);
+ }
+
+ public Object execute() throws Exception {
+ return doExecute(force);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/d0180939/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundlesCommand.java
----------------------------------------------------------------------
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundlesCommand.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundlesCommand.java
new file mode 100644
index 0000000..ff4dd53
--- /dev/null
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundlesCommand.java
@@ -0,0 +1,79 @@
+/*
+ * 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.karaf.bundle.command;
+
+import java.util.List;
+
+import org.apache.karaf.bundle.core.BundleService;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.support.ShellUtil;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+public abstract class BundlesCommand implements Action {
+
+ @Argument(index = 0, name = "ids", description = "The list of bundle (identified by IDs or name or name/version) separated by whitespaces", required = false, multiValued = true)
+ List<String> ids;
+
+ boolean defaultAllBundles = true;
+
+ @Reference
+ BundleContext bundleContext;
+
+ @Reference
+ BundleService bundleService;
+
+ public BundlesCommand(boolean defaultAllBundles) {
+ this.defaultAllBundles = defaultAllBundles;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ @Override
+ public Object execute() throws Exception {
+ doExecute(true);
+ return null;
+ }
+
+ protected Object doExecute(boolean force) throws Exception {
+ List<Bundle> bundles = bundleService.selectBundles(ids, defaultAllBundles);
+ if (!force) {
+ assertNoSystemBundles(bundles);
+ }
+ doExecute(bundles);
+ return null;
+ }
+
+ private void assertNoSystemBundles(List<Bundle> bundles) {
+ for (Bundle bundle : bundles) {
+ if (ShellUtil.isASystemBundle(bundleContext, bundle)) {
+ throw new RuntimeException("Access to system bundle " + bundle.getBundleId() + " denied. You can override with -f");
+ }
+ }
+ }
+
+ protected abstract void doExecute(List<Bundle> bundles) throws Exception;
+
+ public void setBundleService(BundleService bundleService) {
+ this.bundleService = bundleService;
+ }
+
+}