[jboss-cvs] JBossAS SVN: r70152 - in projects/microcontainer/trunk/osgi-int: src/main/org/jboss/osgi/plugins/facade and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 27 01:00:51 EST 2008
Author: johnbailey
Date: 2008-02-27 01:00:51 -0500 (Wed, 27 Feb 2008)
New Revision: 70152
Added:
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleState.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeader.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilder.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilders.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaders.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleState.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleStateMapper.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ExportPackageHeaderBuilder.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ImportPackageHeaderBuilder.java
projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/
projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestControllerContext.java
projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestMainDeployer.java
Removed:
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java
Modified:
projects/microcontainer/trunk/osgi-int/.classpath
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleImpl.java
projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleHeaderTestCase.java
projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleImplTestCase.java
Log:
Bundle Facade Additions:
1. BundleHeaders, BundleHeader, and BundleHeaderBuilders
2. Incorporated DeploymentUnit.getMainDeployer().change(deploymentName,DeployementStage)
3. Cleaned Bundle getState using ControllerState2BundleStateMapper
Modified: projects/microcontainer/trunk/osgi-int/.classpath
===================================================================
--- projects/microcontainer/trunk/osgi-int/.classpath 2008-02-27 05:27:13 UTC (rev 70151)
+++ projects/microcontainer/trunk/osgi-int/.classpath 2008-02-27 06:00:51 UTC (rev 70152)
@@ -38,10 +38,9 @@
<classpathentry kind="src" path="/jboss-deployers-client-spi"/>
<classpathentry kind="src" path="/jboss-managed"/>
<classpathentry kind="src" path="/jboss-metatype"/>
- <classpathentry kind="src" path="/jboss-deployers-core"/>
<classpathentry kind="src" path="/jboss-deployers-vfs-spi"/>
<classpathentry kind="src" path="/jboss-kernel"/>
<classpathentry kind="var" path="M2_REPO/org/osgi/osgi_R4_core/1.0/osgi_R4_core-1.0.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/jboss-deployers-impl"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jboss-classloading"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Deleted: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java 2008-02-27 05:27:13 UTC (rev 70151)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -1,264 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.plugins.facade;
-
-import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.PACKAGE_LIST_VC;
-import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.PARAM_ATTRIB_VC;
-import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.PATH_ATTRIB_LIST_VC;
-import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.QNAME_ATTRIB_LIST_VC;
-import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.STRING_LIST_VC;
-import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.STRING_VC;
-import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.URL_VC;
-import static org.jboss.osgi.plugins.metadata.ValueCreatorUtil.VERSION_VC;
-import static org.osgi.framework.Constants.BUNDLE_ACTIVATOR;
-import static org.osgi.framework.Constants.BUNDLE_CLASSPATH;
-import static org.osgi.framework.Constants.BUNDLE_DESCRIPTION;
-import static org.osgi.framework.Constants.BUNDLE_LOCALIZATION;
-import static org.osgi.framework.Constants.BUNDLE_MANIFESTVERSION;
-import static org.osgi.framework.Constants.BUNDLE_NAME;
-import static org.osgi.framework.Constants.BUNDLE_NATIVECODE;
-import static org.osgi.framework.Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT;
-import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
-import static org.osgi.framework.Constants.BUNDLE_UPDATELOCATION;
-import static org.osgi.framework.Constants.BUNDLE_VERSION;
-import static org.osgi.framework.Constants.DYNAMICIMPORT_PACKAGE;
-import static org.osgi.framework.Constants.EXPORT_PACKAGE;
-import static org.osgi.framework.Constants.FRAGMENT_HOST;
-import static org.osgi.framework.Constants.IMPORT_PACKAGE;
-import static org.osgi.framework.Constants.REQUIRE_BUNDLE;
-
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Locale;
-import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.Map.Entry;
-
-import org.jboss.osgi.plugins.metadata.ValueCreator;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
-import org.osgi.framework.Constants;
-
-/**
- *
- * Container for Bundle headers providing localization for Manifest headers.
- *
- * @author <a href="baileyje at gmail.com">John Bailey</a>
- * @version $Revision: 1.1 $
- */
-public class BundleHeaders
-{
- private static final String LOACAIZED_HEADER_IDENTIFIER = "%";
-
- private final OSGiMetaData metaData;
-
- @SuppressWarnings("unchecked")
- private static final Map<String, ValueCreator> valueCreators = new HashMap<String, ValueCreator>();
-
- private Map<String, Object> nonLocalizedHeaders;
-
- private Map<String, Map<String, Object>> localizedHeaderMap = new HashMap<String, Map<String, Object>>();
-
- private boolean scannedForLocalized;
-
- private boolean localized;
-
- static
- {
- valueCreators.put(BUNDLE_ACTIVATOR, STRING_VC);
- valueCreators.put(BUNDLE_CLASSPATH, STRING_LIST_VC);
- valueCreators.put(BUNDLE_DESCRIPTION, STRING_VC);
- valueCreators.put(BUNDLE_LOCALIZATION, STRING_VC);
- valueCreators.put(BUNDLE_NAME, STRING_VC);
- valueCreators.put(BUNDLE_NATIVECODE, PATH_ATTRIB_LIST_VC);
- valueCreators.put(BUNDLE_REQUIREDEXECUTIONENVIRONMENT, STRING_LIST_VC);
- valueCreators.put(BUNDLE_SYMBOLICNAME, STRING_VC);
- valueCreators.put(BUNDLE_UPDATELOCATION, URL_VC);
- valueCreators.put(BUNDLE_VERSION, VERSION_VC);
- valueCreators.put(DYNAMICIMPORT_PACKAGE, PACKAGE_LIST_VC);
- valueCreators.put(EXPORT_PACKAGE, PACKAGE_LIST_VC);
- valueCreators.put(FRAGMENT_HOST, PARAM_ATTRIB_VC);
- valueCreators.put(IMPORT_PACKAGE, PACKAGE_LIST_VC);
- valueCreators.put(REQUIRE_BUNDLE, QNAME_ATTRIB_LIST_VC);
- }
-
- public BundleHeaders(OSGiMetaData metaData)
- {
- this.metaData = metaData;
- }
-
- private Map<String, Object> getNonLocalizedHeaders()
- {
- if (nonLocalizedHeaders == null)
- {
- nonLocalizedHeaders = new HashMap<String, Object>();
- if (metaData != null)
- {
- if (metaData.getBundleActivator() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_ACTIVATOR, metaData.getBundleActivator());
- }
- if (metaData.getBundleClassPath() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_CLASSPATH, metaData.getBundleClassPath());
- }
- if (metaData.getBundleDescription() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_DESCRIPTION, metaData.getBundleDescription());
- }
- if (metaData.getBundleLocalization() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_LOCALIZATION, metaData.getBundleLocalization());
- }
- if (metaData.getBundleManifestVersion() > 0)
- {
- nonLocalizedHeaders.put(BUNDLE_MANIFESTVERSION, metaData.getBundleManifestVersion());
- }
- if (metaData.getBundleName() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_NAME, metaData.getBundleName());
- }
- if (metaData.getBundleSymbolicName() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_SYMBOLICNAME, metaData.getBundleSymbolicName());
- }
- if (metaData.getBundleUpdateLocation() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_UPDATELOCATION, metaData.getBundleUpdateLocation());
- }
- if (metaData.getBundleVersion() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_VERSION, metaData.getBundleVersion());
- }
- if (metaData.getBundleNativeCode() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_NATIVECODE, metaData.getBundleNativeCode());
- }
- if (metaData.getDynamicImports() != null)
- {
- nonLocalizedHeaders.put(DYNAMICIMPORT_PACKAGE, metaData.getDynamicImports());
- }
- if (metaData.getExportPackages() != null)
- {
- nonLocalizedHeaders.put(EXPORT_PACKAGE, metaData.getExportPackages());
- }
- if (metaData.getFragmentHost() != null)
- {
- nonLocalizedHeaders.put(FRAGMENT_HOST, metaData.getFragmentHost());
- }
- if (metaData.getImportPackages() != null)
- {
- nonLocalizedHeaders.put(IMPORT_PACKAGE, metaData.getImportPackages());
- }
- if (metaData.getRequireBundles() != null)
- {
- nonLocalizedHeaders.put(REQUIRE_BUNDLE, metaData.getRequireBundles());
- }
- if (metaData.getRequiredExecutionEnvironment() != null)
- {
- nonLocalizedHeaders.put(BUNDLE_REQUIREDEXECUTIONENVIRONMENT, metaData.getRequiredExecutionEnvironment());
- }
- }
- }
- return nonLocalizedHeaders;
- }
-
- @SuppressWarnings("unchecked")
- public Dictionary getHeaders(String locale)
- {
- // TODO - Check permissions (METADATA)
- Map<String, Object> localizedHeaders = localizedHeaderMap.get(locale);
- if (localizedHeaders == null)
- {
- if (localizedHeadersFound(getNonLocalizedHeaders()))
- {
- localizedHeaders = new HashMap<String, Object>(getNonLocalizedHeaders());
-
- String bundleLocaleBase = (String) getNonLocalizedHeaders().get(Constants.BUNDLE_LOCALIZATION);
- if (bundleLocaleBase == null)
- {
- bundleLocaleBase = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
- }
- ResourceBundle resourceBundle = ResourceBundle.getBundle(bundleLocaleBase, convertToLocale(locale));
- for (Entry<String, Object> header : localizedHeaders.entrySet())
- {
- if (metaData.getMainAttribute(header.getKey()).startsWith(LOACAIZED_HEADER_IDENTIFIER))
- {
- String localizedValue = resourceBundle.getString(header.getKey());
- if (localizedValue != null)
- {
- ValueCreator valueCreator = valueCreators.get(header.getKey());
- if (valueCreator == null)
- {
- valueCreator = STRING_VC;
- }
- header.setValue(valueCreator.createValue(localizedValue));
- }
- }
- }
- localizedHeaderMap.put(locale, localizedHeaders);
- }
- else
- {
- localizedHeaders = getNonLocalizedHeaders();
- localizedHeaderMap.put(locale, getNonLocalizedHeaders());
- }
- }
- return new Hashtable(localizedHeaders);
- }
-
- private boolean localizedHeadersFound(Map<String, Object> headers)
- {
- if (scannedForLocalized == false)
- {
- for (String headerName : headers.keySet())
- {
- // Need the raw value.....
- if (metaData.getMainAttribute(headerName).startsWith(LOACAIZED_HEADER_IDENTIFIER))
- {
- localized = true;
- break;
- }
- }
- scannedForLocalized = true;
- }
- return localized;
- }
-
- private Locale convertToLocale(String localeString)
- {
- Locale locale = null;
- String[] parts = localeString.split("_");
- switch (parts.length)
- {
- case 1 :
- locale = new Locale(parts[0]);
- break;
- case 2 :
- locale = new Locale(parts[0], parts[1]);
- break;
- case 3 :
- locale = new Locale(parts[0], parts[1], parts[2]);
- }
- return locale;
- }
-}
Modified: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleImpl.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleImpl.java 2008-02-27 05:27:13 UTC (rev 70151)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleImpl.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -28,15 +28,15 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Locale;
-import java.util.Set;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
-import org.jboss.deployers.plugins.deployers.DeploymentControllerContext;
-import org.jboss.deployers.spi.DeploymentState;
-import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.jboss.osgi.plugins.facade.helpers.BundleHeaders;
+import org.jboss.osgi.plugins.facade.helpers.ControllerState2BundleStateMapper;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
@@ -55,65 +55,31 @@
protected BundleHeaders bundleHeaders;
private long lastModified = -1;
-
+
public BundleImpl(DeploymentUnit unit)
{
this.unit = unit;
+
}
public int getState()
{
- int bundleState = Bundle.UNINSTALLED;
- if (getControllerContext() != null)
- {
- ControllerState controllerState = getControllerContext().getState();
- if (ControllerState.ERROR.equals(controllerState))
- {
- bundleState = Bundle.INSTALLED; // Seems strange, but see javadoc
- }
- else if (ControllerState.NOT_INSTALLED.equals(controllerState))
- {
- bundleState = Bundle.UNINSTALLED;
- }
- else if (ControllerState.PRE_INSTALL.equals(controllerState)
- || ControllerState.DESCRIBED.equals(controllerState))
- {
- bundleState = Bundle.INSTALLED;
- }
- else if (ControllerState.INSTANTIATED.equals(controllerState)
- || ControllerState.CONFIGURED.equals(controllerState) || ControllerState.CREATE.equals(controllerState))
- {
- bundleState = Bundle.RESOLVED;
- }
- else if (ControllerState.START.equals(controllerState))
- {
- bundleState = Bundle.STARTING;
- }
- else if (ControllerState.INSTALLED.equals(controllerState))
- {
- bundleState = Bundle.ACTIVE;
- }
- }
- return bundleState;
+ return ControllerState2BundleStateMapper.mapBundleState(getControllerContext().getState()).getState();
}
public void start() throws BundleException
{
checkPermission(AdminPermission.EXECUTE);
- DeploymentControllerContext deploymentControllerContext = getControllerContext();
- DeploymentContext deploymentContext = deploymentControllerContext.getDeploymentContext();
-
try
{
- deploymentControllerContext.getController().change(getControllerContext(), ControllerState.INSTALLED);
+ DeployerClient main = unit.getMainDeployer();
+ main.change(unit.getName(), DeploymentStages.INSTALLED);
}
- catch (Throwable t)
+ catch (DeploymentException e)
{
- deploymentContext.setState(DeploymentState.ERROR);
- deploymentContext.setProblem(t);
+ throw new BundleException("Failed to start Bundle", e);
}
-
}
public void stop() throws BundleException
@@ -184,16 +150,16 @@
public Dictionary getHeaders(String locale)
{
checkPermission(AdminPermission.METADATA);
- return getBundleHeaders().getHeaders(locale);
+ if (bundleHeaders == null)
+ {
+ bundleHeaders = new BundleHeaders(unit);
+ }
+ return bundleHeaders.toDictionary();
}
public String getSymbolicName()
{
- if (getOSGIMetaData() != null)
- {
- return getOSGIMetaData().getBundleSymbolicName();
- }
- return null;
+ return (String) getControllerContext().getName();
}
public Class<?> loadClass(String name) throws ClassNotFoundException
@@ -204,7 +170,7 @@
// Verify ControllerState required to load CL resources
if (ControllerState.INSTANTIATED.equals(getControllerContext().getState()))
{
- return getClassLoader().loadClass(name);
+ return unit.getClassLoader().loadClass(name);
}
}
return null;
@@ -219,7 +185,7 @@
// Verify ControllerState required to load CL resources
if (ControllerState.INSTANTIATED.equals(getControllerContext().getState()))
{
- return getClassLoader().getResource(name);
+ return unit.getClassLoader().getResource(name);
}
}
return null;
@@ -235,7 +201,7 @@
// Verify ControllerState required to load CL resources
if (ControllerState.INSTANTIATED.equals(getControllerContext().getState()))
{
- return getClassLoader().getResources(name);
+ return unit.getClassLoader().getResources(name);
}
}
return null;
@@ -272,41 +238,11 @@
return null;
}
- private DeploymentControllerContext getControllerContext()
+ private ControllerContext getControllerContext()
{
- return unit.getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
+ return unit.getAttachment(ControllerContext.class.getName(), ControllerContext.class);
}
- private OSGiMetaData getOSGIMetaData()
- {
- OSGiMetaData metaData = null;
- Set<? extends OSGiMetaData> metaDatas = unit.getAllMetaData(OSGiMetaData.class);
- if (metaDatas != null && metaDatas.isEmpty() == false)
- {
- metaData = metaDatas.iterator().next();
- }
- return metaData;
- }
-
- private BundleHeaders getBundleHeaders()
- {
- if (bundleHeaders == null)
- {
- bundleHeaders = new BundleHeaders(getOSGIMetaData());
- }
- return bundleHeaders;
- }
-
- private ClassLoader getClassLoader()
- {
- ClassLoader classLoader = null;
- if (getControllerContext() != null)
- {
- classLoader = getControllerContext().getDeploymentContext().getClassLoader();
- }
- return classLoader;
- }
-
private void checkPermission(String adminPermission)
{
if (System.getSecurityManager() != null)
@@ -314,5 +250,4 @@
System.getSecurityManager().checkPermission(new AdminPermission(this, adminPermission));
}
}
-
}
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleState.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleState.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleState.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.facade;
+
+import org.osgi.framework.Bundle;
+
+/**
+ *
+ * A BundleState enum to wrap the non-type-safe Bundle state constants
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public enum BundleState {
+ UNINSTALLED(Bundle.UNINSTALLED), INSTALLED(Bundle.INSTALLED), RESOLVED(Bundle.RESOLVED), STARTING(Bundle.STARTING), STOPPING(
+ Bundle.STOPPING), ACTIVE(Bundle.ACTIVE);
+
+ private final int state;
+
+ /**
+ *
+ * Create a new BundleState.
+ *
+ * @param state
+ */
+ private BundleState(final int state)
+ {
+ this.state = state;
+ }
+
+ /**
+ * Get Bundle state
+ *
+ * @return
+ */
+ public int getState()
+ {
+ return state;
+ }
+
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleState.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeader.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeader.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeader.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.facade.helpers;
+
+/**
+ *
+ * BundleHeader representing a Header value for teh Bundle
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleHeader
+{
+ private final String key;
+
+ private final Object value;
+
+ /**
+ *
+ * Create a new BundleHeader.
+ *
+ * @param key
+ * @param value
+ */
+ public BundleHeader(String key, Object value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+
+ /**
+ * Get Header key
+ *
+ * @return key
+ */
+ public String getKey()
+ {
+ return key;
+ }
+
+ /**
+ * Get Header Value
+ *
+ * @return value
+ */
+ public Object getValue()
+ {
+ return value;
+ }
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilder.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilder.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilder.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.facade.helpers;
+
+
+/**
+ *
+ * Builds OSGI headers.
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public interface BundleHeaderBuilder<T>
+{
+ /**
+ * Builds the BundleHeader from a metadata object.
+ * @param
+ * @return BundleHeader
+ */
+ BundleHeader buildHeader(T metaData);
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilders.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilders.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilders.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.facade.helpers;
+
+/**
+ *
+ * A BundleHeaderBuilders - Creates a default set of BundleHeaderBuilders
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleHeaderBuilders
+{
+ public static ExportPackageHeaderBuilder EXPORT_PACKAGE_BUILDER = new ExportPackageHeaderBuilder();
+ public static ImportPackageHeaderBuilder IMPORT_PACKAGE_BUILDER = new ImportPackageHeaderBuilder();
+
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaderBuilders.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaders.java (from rev 70144, projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/BundleHeaders.java)
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaders.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaders.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.facade.helpers;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ *
+ * Container for Bundle headers providing localization for Manifest headers.
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleHeaders
+{
+ private List<BundleHeader> headers = new ArrayList<BundleHeader>();
+
+ public BundleHeaders(DeploymentUnit unit)
+ {
+ ClassLoadingMetaData classLoadingMetaData = getClassLoaderMetaData(unit);
+ if(classLoadingMetaData != null) {
+ headers.add(BundleHeaderBuilders.EXPORT_PACKAGE_BUILDER.buildHeader(classLoadingMetaData));
+ headers.add(BundleHeaderBuilders.IMPORT_PACKAGE_BUILDER.buildHeader(classLoadingMetaData));
+ /* TODO
+ *
+ * BUNDLE_CLASSPATH
+ * REQUIRE_BUNDLE
+ * DYNAMICIMPORT_PACKAGE
+ *
+ */
+
+ }
+ /* TODO
+ *
+ * BUNDLE_NAME
+ * BUNDLE_VERSION
+ * BUNDLE_ACTIVATOR
+ * BUNDLE_DESCRIPTION
+ * BUNDLE_MANIFESTVERSION
+ * BUNDLE_UPDATELOCATION - Maybe...
+ *
+ */
+ }
+
+ /**
+ * Converts the BundleHeaders into Dictionarry
+ *
+ * @return Dictionary of headers
+ */
+ public Dictionary<String, Object> toDictionary()
+ {
+ Dictionary<String, Object> headerDictionary = new Hashtable<String, Object>();
+ for (BundleHeader header : headers)
+ {
+ if(header != null)
+ {
+ headerDictionary.put(header.getKey(), header.getValue());
+ }
+ }
+ return headerDictionary;
+ }
+
+ private ClassLoadingMetaData getClassLoaderMetaData(DeploymentUnit unit)
+ {
+ Set<? extends ClassLoadingMetaData> metaDatas = unit.getAllMetaData(ClassLoadingMetaData.class);
+ if(metaDatas != null && !metaDatas.isEmpty()) {
+ return metaDatas.iterator().next();
+ }
+ return null;
+ }
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/BundleHeaders.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleState.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleState.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleState.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.facade.helpers;
+
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.osgi.plugins.facade.BundleState;
+
+/**
+ *
+ * A BundleState2DeploymentStage - Maps a DeploymentStage to BundleState
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public class ControllerState2BundleState
+{
+ private final ControllerState controllerState;
+ private final BundleState bundleState;
+
+ /**
+ *
+ * Create a new DeploymentStage2BundleState.
+ *
+ * @param deploymentStage
+ * @param bundleState
+ */
+ public ControllerState2BundleState(ControllerState controllerState, BundleState bundleState)
+ {
+ super();
+ this.controllerState = controllerState;
+ this.bundleState = bundleState;
+ }
+
+ /**
+ * Get controllerState
+ *
+ * @return
+ */
+ public ControllerState getControllerState()
+ {
+ return controllerState;
+ }
+
+ /**
+ * Get BundleState
+ *
+ * @return
+ */
+ public BundleState getBundleState()
+ {
+ return bundleState;
+ }
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleState.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleStateMapper.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleStateMapper.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleStateMapper.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.facade.helpers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.osgi.plugins.facade.BundleState;
+
+/**
+ *
+ * A DeploymentStage2BundleStateMapper - Maps a DeploymentStage to a BundleState
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public class ControllerState2BundleStateMapper
+{
+
+ private static List<ControllerState2BundleState> deploymentStage2BundleStates = new ArrayList<ControllerState2BundleState>();
+ static
+ {
+ deploymentStage2BundleStates.add(new ControllerState2BundleState(ControllerState.ERROR, BundleState.UNINSTALLED));
+ deploymentStage2BundleStates.add(new ControllerState2BundleState(ControllerState.NOT_INSTALLED, BundleState.INSTALLED));
+ deploymentStage2BundleStates.add(new ControllerState2BundleState(ControllerState.PRE_INSTALL, BundleState.INSTALLED));
+ deploymentStage2BundleStates.add(new ControllerState2BundleState(ControllerState.DESCRIBED, BundleState.INSTALLED));
+ deploymentStage2BundleStates.add(new ControllerState2BundleState(ControllerState.INSTANTIATED, BundleState.RESOLVED));
+ deploymentStage2BundleStates.add(new ControllerState2BundleState(ControllerState.CONFIGURED, BundleState.RESOLVED));
+ deploymentStage2BundleStates.add(new ControllerState2BundleState(ControllerState.CREATE, BundleState.RESOLVED));
+ deploymentStage2BundleStates.add(new ControllerState2BundleState(ControllerState.START, BundleState.STARTING));
+ deploymentStage2BundleStates.add(new ControllerState2BundleState(ControllerState.INSTALLED, BundleState.ACTIVE));
+ }
+
+ /**
+ * Given a DeploymentStage returns corresponding BundleState
+ *
+ * @param controllerState
+ * @return BundleState
+ */
+ public static BundleState mapBundleState(final ControllerState controllerState)
+ {
+ for (ControllerState2BundleState deploymentStage2BundleState : deploymentStage2BundleStates)
+ {
+ if (deploymentStage2BundleState.getControllerState().equals(controllerState))
+ {
+ return deploymentStage2BundleState.getBundleState();
+ }
+ }
+ return BundleState.UNINSTALLED;
+ }
+
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ControllerState2BundleStateMapper.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ExportPackageHeaderBuilder.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ExportPackageHeaderBuilder.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ExportPackageHeaderBuilder.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.osgi.plugins.facade.helpers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.util.Strings;
+import org.osgi.framework.Constants;
+
+/**
+ *
+ * A ExportPackageHeaderBuilder - Builds the Export-Package BundleHeader from CLassLoadingMetaData
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public class ExportPackageHeaderBuilder implements BundleHeaderBuilder<ClassLoadingMetaData>
+{
+ /**
+ * Create a new ExportPackageHeaderRetriever.
+ *
+ */
+ public ExportPackageHeaderBuilder()
+ {
+ }
+
+ /**
+ * Iterate through the ClassLoadingMetaData to check for a PackageCapabilities and create Export-Package BundleHeader.
+ *
+ * @param classLoadingMetaData
+ */
+ public BundleHeader buildHeader(ClassLoadingMetaData metaData)
+ {
+ CapabilitiesMetaData capabilitiesMetaData = metaData.getCapabilities();
+ List<Capability> capabilities = capabilitiesMetaData.getCapabilities();
+ if (capabilities != null)
+ {
+ List<String> packageAndVersions = new ArrayList<String>();
+ for (Capability capability : capabilities)
+ {
+ if (capability instanceof PackageCapability)
+ {
+ PackageCapability packageCapability = (PackageCapability) capability;
+ packageAndVersions.add(new StringBuilder().append(packageCapability.getName()).append(";version=").append(packageCapability.getVersion()).toString());
+ }
+ }
+ if (packageAndVersions.isEmpty() == false)
+ {
+ return new BundleHeader(Constants.EXPORT_PACKAGE, Strings.join(packageAndVersions.toArray(),","));
+ }
+ }
+ return null;
+ }
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ExportPackageHeaderBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ImportPackageHeaderBuilder.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ImportPackageHeaderBuilder.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ImportPackageHeaderBuilder.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.osgi.plugins.facade.helpers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.RequirementsMetaData;
+import org.jboss.util.Strings;
+import org.osgi.framework.Constants;
+
+/**
+ *
+ * A ImportPackageHeaderRetriever - Builds Import-Package BundleHeader from ClassLoadingMetaData
+ *
+ * @author <a href="baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: 1.1 $
+ */
+public class ImportPackageHeaderBuilder implements BundleHeaderBuilder<ClassLoadingMetaData>
+{
+ /**
+ * Create a new ImportPackageHeaderBuilder.
+ *
+ */
+ public ImportPackageHeaderBuilder()
+ {
+ }
+
+ /**
+ * Iterate through the ClassLoadingMetaData to check for a PackageRequirements and build Import-Package header.
+ *
+ * @param classLoadingMetaData
+ */
+ public BundleHeader buildHeader(ClassLoadingMetaData metaData)
+ {
+ RequirementsMetaData requirementsMetaData = metaData.getRequirements();
+ List<Requirement> requirements = requirementsMetaData.getRequirements();
+ if (requirements != null)
+ {
+ List<String> packageAndVersions = new ArrayList<String>();
+ for (Requirement requirement : requirements)
+ {
+ if (requirement instanceof PackageRequirement)
+ {
+ PackageRequirement packageRequirement = (PackageRequirement) requirement;
+ packageAndVersions.add(new StringBuilder().append(packageRequirement.getName()).append(";version=").append(packageRequirement.getVersionRange()).toString());
+ }
+ }
+ if (packageAndVersions.isEmpty() == false)
+ {
+ return new BundleHeader(Constants.IMPORT_PACKAGE, Strings.join(packageAndVersions.toArray(),","));
+ }
+ }
+ return null;
+ }
+}
Property changes on: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/helpers/ImportPackageHeaderBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleHeaderTestCase.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleHeaderTestCase.java 2008-02-27 05:27:13 UTC (rev 70151)
+++ projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleHeaderTestCase.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -1,33 +1,25 @@
package org.jboss.test.bundle;
-import static org.osgi.framework.Constants.BUNDLE_ACTIVATOR;
-import static org.osgi.framework.Constants.BUNDLE_CLASSPATH;
-import static org.osgi.framework.Constants.BUNDLE_DESCRIPTION;
-import static org.osgi.framework.Constants.BUNDLE_LOCALIZATION;
-import static org.osgi.framework.Constants.BUNDLE_MANIFESTVERSION;
-import static org.osgi.framework.Constants.BUNDLE_NAME;
-import static org.osgi.framework.Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT;
-import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
-import static org.osgi.framework.Constants.BUNDLE_UPDATELOCATION;
-import static org.osgi.framework.Constants.BUNDLE_VERSION;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Arrays;
import java.util.Dictionary;
-import java.util.List;
-import java.util.Locale;
import junit.framework.Test;
-import org.jboss.osgi.plugins.facade.BundleHeaders;
-import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
+import org.jboss.osgi.plugins.facade.helpers.BundleHeaders;
import org.jboss.test.bundle.metadata.AbstractManifestTestCase;
-import org.osgi.framework.Version;
+import org.osgi.framework.Constants;
public class BundleHeaderTestCase extends AbstractManifestTestCase
{
+ private BundleHeaders bundleHeaders;
public BundleHeaderTestCase(String name)
{
@@ -39,59 +31,32 @@
return suite(BundleHeaderTestCase.class);
}
- @SuppressWarnings("unchecked")
- public void testGetHeadersNoLocalization() throws Exception
+ @Override
+ protected void setUp() throws Exception
{
- Dictionary<String, Object> headers = getBundleHeaders(
- getMetaData("/org/jboss/test/bundle/metadata/SimpleManifest.mf"))
- .getHeaders(Locale.getDefault().toString());
- assertNotNull(headers);
- assertEquals(headers.get(BUNDLE_ACTIVATOR), "org.jboss.test.bundle.metadata.BundleActivator");
- List<String> classpath = Arrays.asList("test.jar", "mc.jar", "seam.jar");
- assertEquals(classpath, headers.get(BUNDLE_CLASSPATH));
- assertEquals("TestHeadersManifest", headers.get(BUNDLE_DESCRIPTION));
- assertEquals("OSGI-INF/l10n/bundle", headers.get(BUNDLE_LOCALIZATION));
- assertEquals(2, headers.get(BUNDLE_MANIFESTVERSION));
- assertEquals("TestBundle", headers.get(BUNDLE_NAME));
- assertEquals("UniqueName", headers.get(BUNDLE_SYMBOLICNAME));
- URL url = new URL("file://test.jar");
- assertEquals(url, headers.get(BUNDLE_UPDATELOCATION));
- Version version = new Version("1.2.3.GA");
- assertEquals(version, headers.get(BUNDLE_VERSION));
- List<String> env = Arrays.asList("ena", "dva", "tri");
- assertEquals(env, headers.get(BUNDLE_REQUIREDEXECUTIONENVIRONMENT));
+ super.setUp();
+ DeploymentContext deploymentContext = new AbstractDeploymentContext("aDeployment", "/test.jar");
+
+ DeploymentUnit deploymentUnit = new AbstractDeploymentUnit(deploymentContext);
+
+ ClassLoadingMetaData clMetaData = new ClassLoadingMetaData();
+ clMetaData.getCapabilities().addCapability(new PackageCapability("org.jboss.test", new Version(1,2,0)));
+ clMetaData.getCapabilities().addCapability(new PackageCapability("org.jboss.test.other", new Version(1,5,0)));
+
+
+ clMetaData.getRequirements().addRequirement(new PackageRequirement("org.jboss.test", new VersionRange(new Version(1,2,0))));
+ clMetaData.getRequirements().addRequirement(new PackageRequirement("org.jboss.test.other", new VersionRange(new Version(1,5,0),new Version(2,0,1))));
+ deploymentUnit.addAttachment(ClassLoadingMetaData.class, clMetaData);
+
+ bundleHeaders = new BundleHeaders(deploymentUnit);
}
@SuppressWarnings("unchecked")
- public void testGetHeadersWithDefaultLocalization() throws Exception
+ public void testToDictionary() throws Exception
{
- Dictionary<String, Object> headers = getBundleHeaders(
- getMetaData("/org/jboss/test/bundle/metadata/LocalizedManifest.mf")).getHeaders(
- new Locale("en", "US").toString());
+ Dictionary<String, Object> headers = bundleHeaders.toDictionary();
assertNotNull(headers);
- assertEquals(headers.get(BUNDLE_ACTIVATOR), "org.jboss.test.bundle.metadata.BundleActivator");
- List<String> classpath = Arrays.asList("test.jar", "mc.jar", "seam.jar");
- assertEquals(classpath, headers.get(BUNDLE_CLASSPATH));
- assertEquals("Description with Locale( en_US )", headers.get(BUNDLE_DESCRIPTION));
- assertEquals("OSGI-INF/l10n/bundle", headers.get(BUNDLE_LOCALIZATION));
- assertEquals(2, headers.get(BUNDLE_MANIFESTVERSION));
- assertEquals("TestBundle", headers.get(BUNDLE_NAME));
- assertEquals("DefaultSymbolicName", headers.get(BUNDLE_SYMBOLICNAME));
- URL url = new URL("file://test.jar");
- assertEquals(url, headers.get(BUNDLE_UPDATELOCATION));
- Version version = new Version("1.2.3.GA");
- assertEquals(version, headers.get(BUNDLE_VERSION));
- List<String> env = Arrays.asList("ena", "dva", "tri");
- assertEquals(env, headers.get(BUNDLE_REQUIREDEXECUTIONENVIRONMENT));
+ assertEquals("org.jboss.test;version=1.2.0,org.jboss.test.other;version=1.5.0", headers.get(Constants.EXPORT_PACKAGE));
+ assertEquals("org.jboss.test;version=[1.2.0,?),org.jboss.test.other;version=[1.5.0,2.0.1)", headers.get(Constants.IMPORT_PACKAGE));
}
-
- private OSGiMetaData getMetaData(String manifestPath) throws IOException
- {
- return new AbstractOSGiMetaData(getManifest(manifestPath));
- }
-
- private BundleHeaders getBundleHeaders(OSGiMetaData metaData)
- {
- return new BundleHeaders(metaData);
- }
}
Modified: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleImplTestCase.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleImplTestCase.java 2008-02-27 05:27:13 UTC (rev 70151)
+++ projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/BundleImplTestCase.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -1,76 +1,64 @@
package org.jboss.test.bundle;
-import java.util.jar.Manifest;
import junit.framework.Test;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
-import org.jboss.deployers.plugins.deployers.DeployersImpl;
-import org.jboss.deployers.plugins.deployers.DeploymentControllerContext;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
import org.jboss.deployers.structure.spi.DeploymentContext;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext;
import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
-import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
import org.jboss.osgi.plugins.facade.BundleImpl;
-import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
import org.jboss.test.bundle.metadata.AbstractManifestTestCase;
+import org.jboss.test.bundle.support.TestControllerContext;
+import org.jboss.test.bundle.support.TestMainDeployer;
import org.osgi.framework.Bundle;
public class BundleImplTestCase extends AbstractManifestTestCase
{
- private OSGiMetaData metaData;
private Bundle bundle;
+
private DeploymentUnit deploymentUnit;
+
private ControllerContext controllerContext;
+ private TestMainDeployer mainDeployer;
+
public BundleImplTestCase(String name)
{
super(name);
}
-
+
public static Test suite()
{
return suite(BundleImplTestCase.class);
}
-
+
@Override
protected void setUp() throws Exception
{
super.setUp();
-
- BasicBootstrap bootstrap = new BasicBootstrap();
- bootstrap.run();
-
- DeploymentContext deploymentContext = new AbstractDeploymentContext("deployment", "/");
+
+ DeploymentContext deploymentContext = new AbstractDeploymentContext("UniqueName", "/simple.jar");
deploymentUnit = new AbstractDeploymentUnit(deploymentContext);
- controllerContext = new DeploymentControllerContext(deploymentContext, new DeployersImpl(bootstrap.getKernel().getController()));
+ controllerContext = new TestControllerContext(deploymentContext);
deploymentUnit.addAttachment(ControllerContext.class.getName(), controllerContext);
+ mainDeployer = new TestMainDeployer();
+ deploymentUnit.addAttachment(MainDeployer.class.getName(), mainDeployer);
bundle = new BundleImpl(deploymentUnit);
-
- Manifest manifest = getManifest("/org/jboss/test/bundle/metadata/SimpleManifest.mf");
- metaData = new AbstractOSGiMetaData(manifest);
- deploymentUnit.addAttachment(OSGiMetaData.class, metaData);
-
- try
- {
- bootstrap.getKernel().getController().install(controllerContext);
- }
- catch (Throwable e)
- {
- throw new Exception(e);
- }
}
public void testGetBundleState() throws Exception
{
controllerContext.setState(ControllerState.ERROR);
- assertEquals(Bundle.INSTALLED, bundle.getState());
+ assertEquals(Bundle.UNINSTALLED, bundle.getState());
controllerContext.setState(ControllerState.NOT_INSTALLED);
- assertEquals(Bundle.UNINSTALLED, bundle.getState());
+ assertEquals(Bundle.INSTALLED, bundle.getState());
controllerContext.setState(ControllerState.PRE_INSTALL);
assertEquals(Bundle.INSTALLED, bundle.getState());
@@ -93,17 +81,21 @@
controllerContext.setState(ControllerState.INSTALLED);
assertEquals(Bundle.ACTIVE, bundle.getState());
}
-
+
public void testGetSymbolicName() throws Exception
{
assertEquals("UniqueName", bundle.getSymbolicName());
}
-
+
public void testStartBundle() throws Exception
{
- assertEquals(Bundle.UNINSTALLED, bundle.getState());
bundle.start();
- assertEquals(Bundle.ACTIVE, bundle.getState());
+ assertChangeRequested(deploymentUnit.getName(), DeploymentStages.INSTALLED);
}
+ public void assertChangeRequested(String deploymentName, DeploymentStage stage)
+ {
+ assertTrue(mainDeployer.changeCalled(deploymentName, stage));
+ }
+
}
Added: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestControllerContext.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestControllerContext.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestControllerContext.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.bundle.support;
+
+import java.util.Set;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.ScopeInfo;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.util.JBossStringBuilder;
+
+public class TestControllerContext implements ControllerContext
+{
+ private ControllerState state;
+
+ private DeploymentContext context;
+
+ public TestControllerContext(DeploymentContext context)
+ {
+ this.context = context;
+ }
+
+ public String toShortString()
+ {
+ return null;
+ }
+
+ public void toShortString(JBossStringBuilder arg0)
+ {
+
+ }
+
+ @Override
+ public Object clone()
+ {
+ return null;
+ }
+
+ public Set<Object> getAliases()
+ {
+ return null;
+ }
+
+ public Controller getController()
+ {
+ return null;
+ }
+
+ public DependencyInfo getDependencyInfo()
+ {
+ return null;
+ }
+
+ public Throwable getError()
+ {
+ return null;
+ }
+
+ public ControllerMode getMode()
+ {
+ return null;
+ }
+
+ public Object getName()
+ {
+ return context.getName();
+ }
+
+ public ControllerState getRequiredState()
+ {
+ return null;
+ }
+
+ public ScopeInfo getScopeInfo()
+ {
+ return null;
+ }
+
+ public ControllerState getState()
+ {
+ return state;
+ }
+
+ public Object getTarget()
+ {
+ return null;
+ }
+
+ public void install(ControllerState fromState, ControllerState toState) throws Throwable
+ {
+ }
+
+ public void setController(Controller controller)
+ {
+ }
+
+ public void setError(Throwable error)
+ {
+ }
+
+ public void setMode(ControllerMode mode)
+ {
+ }
+
+ public void setRequiredState(ControllerState state)
+ {
+ }
+
+ public void setState(ControllerState state)
+ {
+ this.state = state;
+ }
+
+ public void uninstall(ControllerState fromState, ControllerState toState)
+ {
+ }
+
+}
\ No newline at end of file
Property changes on: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestControllerContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestMainDeployer.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestMainDeployer.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestMainDeployer.java 2008-02-27 06:00:51 UTC (rev 70152)
@@ -0,0 +1,144 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.bundle.support;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.DeploymentState;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.util.graph.Graph;
+
+public class TestMainDeployer implements MainDeployer
+{
+
+ /** Create a new TestMainDeployer.
+ *
+ * @param bundleImplTestCase
+ */
+ public TestMainDeployer()
+ {
+ }
+
+ private Map<String, DeploymentStage> changesRequested = new HashMap<String, DeploymentStage>();
+
+ public void shutdown()
+ {
+
+ }
+
+ public void addDeployment(Deployment deployment) throws DeploymentException
+ {
+
+ }
+
+ public void change(String deploymentName, DeploymentStage stage) throws DeploymentException
+ {
+ changesRequested.put(deploymentName, stage);
+ }
+
+ public void checkComplete() throws DeploymentException
+ {
+
+ }
+
+ public void checkComplete(Deployment... deployment) throws DeploymentException
+ {
+
+ }
+
+ public void checkComplete(String... names) throws DeploymentException
+ {
+
+ }
+
+ public void checkStructureComplete(Deployment... deployments) throws DeploymentException
+ {
+
+ }
+
+ public void checkStructureComplete(String... names) throws DeploymentException
+ {
+
+ }
+
+ public void deploy(Deployment... deployments) throws DeploymentException
+ {
+
+ }
+
+ public Graph<Map<String, ManagedObject>> getDeepManagedObjects(String name) throws DeploymentException
+ {
+ return null;
+ }
+
+ public Deployment getDeployment(String name)
+ {
+ return null;
+ }
+
+ public DeploymentState getDeploymentState(String name)
+ {
+ return null;
+ }
+
+ public ManagedDeployment getManagedDeployment(String name) throws DeploymentException
+ {
+ return null;
+ }
+
+ public Map<String, ManagedObject> getManagedObjects(String name) throws DeploymentException
+ {
+ return null;
+ }
+
+ public Collection<Deployment> getTopLevel()
+ {
+ return null;
+ }
+
+ public void process()
+ {
+
+ }
+
+ public boolean removeDeployment(Deployment deployment) throws DeploymentException
+ {
+ return false;
+ }
+
+ public boolean removeDeployment(String name) throws DeploymentException
+ {
+ return false;
+ }
+
+ public void undeploy(Deployment... deployments) throws DeploymentException
+ {
+
+ }
+
+ public void undeploy(String... names) throws DeploymentException
+ {
+ }
+
+ public boolean changeCalled(String deploymentName, DeploymentStage stage)
+ {
+ DeploymentStage requestedChange = changesRequested.get(deploymentName);
+ if (requestedChange != null)
+ {
+ return requestedChange.equals(stage);
+ }
+ return false;
+ }
+
+}
\ No newline at end of file
Property changes on: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestMainDeployer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the jboss-cvs-commits
mailing list