Author: alesj
Date: 2009-11-22 07:30:32 -0500 (Sun, 22 Nov 2009)
New Revision: 96681
Added:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/a/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/a/PA.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/b/
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/b/Other.java
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
Log:
[JBOSGI-149]; initial test for PackageAdmin impl.
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
===================================================================
---
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-22
06:59:19 UTC (rev 96680)
+++
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-22
12:30:32 UTC (rev 96681)
@@ -28,10 +28,13 @@
import java.util.List;
import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
import org.jboss.classloading.spi.metadata.Capability;
import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import
org.jboss.deployers.plugins.classloading.AbstractDeploymentClassLoaderPolicyModule;
import org.jboss.logging.Logger;
import org.jboss.osgi.framework.bundle.AbstractBundleState;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
@@ -39,8 +42,8 @@
import org.jboss.osgi.framework.plugins.PackageAdminServicePlugin;
import org.jboss.osgi.framework.plugins.ResolverPlugin;
import org.jboss.osgi.framework.plugins.internal.AbstractServicePlugin;
-import org.jboss.osgi.framework.resolver.ResolverBundle;
import org.jboss.osgi.framework.resolver.Resolver;
+import org.jboss.osgi.framework.resolver.ResolverBundle;
import org.jboss.osgi.spi.NotImplementedException;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -91,28 +94,17 @@
if (clazz == null)
throw new IllegalArgumentException("Null class");
- Bundle retBundle = null;
ClassLoader classLoader = clazz.getClassLoader();
- for (AbstractBundleState aux : bundleManager.getBundles())
+ Module module = ClassLoading.getModuleForClassLoader(classLoader);
+ if (module instanceof AbstractDeploymentClassLoaderPolicyModule)
{
- if (aux instanceof OSGiBundleState)
- {
- OSGiBundleState bundleState = (OSGiBundleState)aux;
-
- // The classloader is only available if the bundle
- // is in state RESOLVED or higher
- if (aux.getState() != Bundle.INSTALLED)
- {
- ClassLoader bundleLoader =
bundleState.getDeploymentUnit().getClassLoader();
- if (bundleLoader == classLoader)
- {
- retBundle = aux.getBundleInternal();
- break;
- }
- }
- }
+ AbstractDeploymentClassLoaderPolicyModule deploymentModule =
(AbstractDeploymentClassLoaderPolicyModule)module;
+ DeploymentUnit unit = deploymentModule.getDeploymentUnit();
+ OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+ if (bundleState != null && bundleState.getState() != Bundle.INSTALLED)
+ return bundleState.getBundleInternal();
}
- return retBundle;
+ return null;
}
public int getBundleType(Bundle bundle)
Added:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java
===================================================================
---
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java
(rev 0)
+++
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java 2009-11-22
12:30:32 UTC (rev 96681)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.osgi.compendium;
+
+import junit.framework.Test;
+
+import org.jboss.osgi.framework.service.internal.PackageAdminImpl;
+import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.test.osgi.compendium.support.b.Other;
+import org.jboss.test.osgi.compendium.support.a.PA;
+import org.osgi.framework.Bundle;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/**
+ * Test PackageAdmin service.
+ *
+ * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
+ */
+public class PackageAdminTestCase extends FrameworkTest
+{
+ public PackageAdminTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(PackageAdminTestCase.class);
+ }
+
+ protected PackageAdmin createPackageAdmin()
+ {
+ return new PackageAdminImpl(getBundleManager());
+ }
+
+ public void testGetBudleFromClass() throws Exception
+ {
+ Bundle bundle = assembleBundle("smoke-assembled",
"/bundles/smoke/smoke-assembled", PA.class);
+ try
+ {
+ bundle.start();
+ Class<?> paClass = assertLoadClass(bundle, PA.class);
+
+ PackageAdmin pa = createPackageAdmin();
+
+ Bundle found = pa.getBundle(paClass);
+ assertSame(bundle, found);
+
+ Bundle notFound = pa.getBundle(getClass());
+ assertNull(notFound);
+
+ Bundle other = assembleBundle("simple",
"/bundles/simple/simple-bundle1", Other.class);
+ try
+ {
+ other.start();
+ Class<?> otherClass = assertLoadClass(other, Other.class);
+
+ found = pa.getBundle(otherClass);
+ assertSame(other, found);
+ }
+ finally
+ {
+ other.uninstall();
+ }
+ }
+ finally
+ {
+ bundle.uninstall();
+ }
+ }
+}
Added:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/a/PA.java
===================================================================
---
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/a/PA.java
(rev 0)
+++
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/a/PA.java 2009-11-22
12:30:32 UTC (rev 96681)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.osgi.compendium.support.a;
+
+/**
+ * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
+ */
+public class PA
+{
+}
Added:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/b/Other.java
===================================================================
---
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/b/Other.java
(rev 0)
+++
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/compendium/support/b/Other.java 2009-11-22
12:30:32 UTC (rev 96681)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.osgi.compendium.support.b;
+
+/**
+ * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
+ */
+public class Other
+{
+}
\ No newline at end of file