Skip to content

Commit

Permalink
KARAF-1275 Refactor bundle modules
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/karaf/trunk@1302375 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cschneider committed Mar 19, 2012
1 parent c138c90 commit 0eaf935
Show file tree
Hide file tree
Showing 59 changed files with 1,204 additions and 814 deletions.
8 changes: 4 additions & 4 deletions assemblies/features/framework/pom.xml
Expand Up @@ -142,14 +142,14 @@
<groupId>org.apache.karaf.features</groupId>
<artifactId>org.apache.karaf.features.command</artifactId>
</dependency>

<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
<groupId>org.apache.karaf.bundle</groupId>
<artifactId>org.apache.karaf.bundle.command</artifactId>
</dependency>

<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.bundles</artifactId>
<artifactId>org.apache.karaf.shell.console</artifactId>
</dependency>
<dependency>
<groupId>org.apache.karaf.shell</groupId>
Expand Down
1 change: 1 addition & 0 deletions assemblies/features/spring/src/main/feature/feature.xml
Expand Up @@ -45,6 +45,7 @@
<bundle start-level="30">mvn:org.springframework.osgi/spring-osgi-extender/${spring.osgi.version}</bundle>
<bundle start-level="30">mvn:org.springframework.osgi/spring-osgi-annotation/${spring.osgi.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.spring/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.springstate/${project.version}</bundle>
</feature>

<feature name="spring-dm-web" description="Spring DM Web support" version="${spring.osgi.version}" resolver="(obr)">
Expand Down
5 changes: 4 additions & 1 deletion assemblies/features/standard/src/main/feature/feature.xml
Expand Up @@ -47,6 +47,9 @@
<bundle start-level="30">mvn:org.ops4j.pax.url/pax-url-obr/${pax.url.version}</bundle>
</feature>

<feature name="bundle">
</feature>

<feature name="config" description="Provide OSGi ConfigAdmin support" version="${project.version}">
<bundle start-level="30" start="true">mvn:org.apache.karaf.config/org.apache.karaf.config.core/${project.version}</bundle>
<bundle start-level="30" start="true">mvn:org.apache.karaf.config/org.apache.karaf.config.command/${project.version}</bundle>
Expand Down Expand Up @@ -153,7 +156,7 @@
<feature name="management" description="Provide a JMX MBeanServer and a set of MBeans in Karaf" version="${project.version}">
<bundle start-level="30">mvn:org.apache.karaf.management/org.apache.karaf.management.server/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.system/org.apache.karaf.system.management/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.management.mbeans/org.apache.karaf.management.mbeans.bundles/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.bundle/org.apache.karaf.bundle.management/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.management.mbeans/org.apache.karaf.management.mbeans.services/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.management.mbeans/org.apache.karaf.management.mbeans.packages/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.aries.jmx/org.apache.aries.jmx.api/${aries.jmx.version}</bundle>
Expand Down
File renamed without changes.
115 changes: 115 additions & 0 deletions bundle/command/pom.xml
@@ -0,0 +1,115 @@
<?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.karaf.bundle</groupId>
<artifactId>bundle</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>org.apache.karaf.bundle.command</artifactId>
<packaging>bundle</packaging>
<name>Apache Karaf :: Bundle :: Commands</name>
<description>Provides shell commands to manipulate OSGi bundles.</description>

<properties>
<appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.karaf</groupId>
<artifactId>org.apache.karaf.util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
</dependency>
<dependency>
<groupId>org.apache.karaf.bundle</groupId>
<artifactId>org.apache.karaf.bundle.core</artifactId>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.utils</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.info</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<DynamicImport-Package>
org.springframework.*
</DynamicImport-Package>
<Private-Package>
org.apache.karaf.bundle.command*,
org.apache.karaf.util,
org.apache.felix.utils.version,
org.apache.felix.utils.manifest,
!*
</Private-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

</project>
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.karaf.shell.bundles;
package org.apache.karaf.bundle.command;

import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.console.OsgiCommandSupport;
Expand All @@ -39,8 +39,10 @@ protected Object doExecute(boolean force) throws Exception {
System.err.println("Bundle " + id + " not found");
return null;
}
if (force || !ShellUtil.isASystemBundle(getBundleContext(), bundle) || ShellUtil.accessToSystemBundleIsAllowed(bundle.getBundleId(), session)) {
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;
}
Expand Down
Expand Up @@ -14,23 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.karaf.shell.bundles;
package org.apache.karaf.bundle.command;

import org.apache.karaf.shell.commands.Option;
import org.osgi.framework.Bundle;

/**
* Unique bundle command with confirmation while accessing system bundle.
*/
public abstract class BundleCommandWithConfirmation extends BundleCommand {

@Option(name = "--force", aliases = {}, description = "Forces the command to execute", required = false, multiValued = false)
@Option(name = "--force", aliases = {"-f"}, description = "Forces the command to execute", required = false, multiValued = false)
boolean force;

protected Object doExecute() throws Exception {
return doExecute(force);
}

protected abstract void doExecute(Bundle bundle) throws Exception;

}
Expand Up @@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.karaf.shell.bundles;
package org.apache.karaf.bundle.command;

import java.util.List;

import org.apache.karaf.bundle.core.BundleSelector;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.osgi.framework.Bundle;
Expand All @@ -26,18 +27,30 @@ public abstract class BundlesCommand extends OsgiCommandSupport {

@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;

BundleSelector bundleSelector;

public BundlesCommand(boolean defaultAllBundles) {
this.defaultAllBundles = defaultAllBundles;
}

protected Object doExecute() throws Exception {
doExecute(true);
return null;
}

protected Object doExecute(boolean force) throws Exception {
BundleSelector selector = new BundleSelector(getBundleContext(), session);
List<Bundle> bundles = selector.selectBundles(ids, force);
List<Bundle> bundles = bundleSelector.selectBundles(ids, this.defaultAllBundles, force);
doExecute(bundles);
return null;
}

protected abstract void doExecute(List<Bundle> bundles) throws Exception;

public void setBundleSelector(BundleSelector bundleSelector) {
this.bundleSelector = bundleSelector;
}

}
Expand Up @@ -14,18 +14,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.karaf.shell.bundles;
package org.apache.karaf.bundle.command;

import java.util.ArrayList;
import java.util.List;

import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.MultiException;
import org.osgi.framework.Bundle;

@Command(scope = "bundle", name = "start", description = "Starts bundles.")
public class Start extends BundlesCommandWithConfirmation {
/**
* Command related to bundles requiring read-write access to the bundle (including system bundle).
*/
public abstract class BundlesCommandWithConfirmation extends BundlesCommand {

@Option(name = "--force", aliases = {"-f"}, description = "Forces the command to execute", required = false, multiValued = false)
boolean force;

protected String errorMessage = "Unable to execute command on bundle ";

public BundlesCommandWithConfirmation() {
super(false);
}

protected Object doExecute() throws Exception {
doExecute(force);
return null;
}

protected void doExecute(List<Bundle> bundles) throws Exception {
if (bundles.isEmpty()) {
System.err.println("No bundles specified.");
Expand All @@ -34,12 +50,13 @@ protected void doExecute(List<Bundle> bundles) throws Exception {
List<Exception> exceptions = new ArrayList<Exception>();
for (Bundle bundle : bundles) {
try {
bundle.start();
executeOnBundle(bundle);
} catch (Exception e) {
exceptions.add(new Exception("Unable to start bundle " + bundle.getBundleId() + ": " + e.getMessage(), e));
exceptions.add(new Exception(errorMessage + bundle.getBundleId() + ": " + e.getMessage(), e));
}
}
MultiException.throwIf("Error starting bundles", exceptions);
MultiException.throwIf("Error executing command on bundles", exceptions);
}


protected abstract void executeOnBundle(Bundle bundle) throws Exception;
}
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.karaf.shell.bundles;
package org.apache.karaf.bundle.command;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -34,7 +34,6 @@

@Command(scope = "bundle", name = "capabilities", description = "Displays OSGi capabilities of a given bundles.")
public class Capabilities extends BundlesCommand {

public static final String NONSTANDARD_SERVICE_NAMESPACE = "service";

private static final String EMPTY_MESSAGE = "[EMPTY]";
Expand All @@ -44,6 +43,10 @@ public class Capabilities extends BundlesCommand {
@Option(name = "--namespace")
String namespace = "*";

public Capabilities() {
super(true);
}

@Override
protected void doExecute(List<Bundle> bundles) throws Exception {
boolean separatorNeeded = false;
Expand Down

0 comments on commit 0eaf935

Please sign in to comment.