[jboss-cvs] JBossAS SVN: r87433 - in projects/jboss-osgi/trunk/runtime: felix/src/main/resources and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 16 11:08:34 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-04-16 11:08:34 -0400 (Thu, 16 Apr 2009)
New Revision: 87433

Added:
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStructureDeployer.java
Modified:
   projects/jboss-osgi/trunk/runtime/felix/src/main/resources/osgi-deployers-jboss-beans.xml
Log:
[JBOSGI-37] First cut of BundleStructureDeployer

Added: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStructureDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStructureDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStructureDeployer.java	2009-04-16 15:08:34 UTC (rev 87433)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.osgi.deployer;
+
+// $Id$
+
+import java.io.IOException;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.structure.ContextInfo;
+import org.jboss.deployers.vfs.plugins.structure.AbstractVFSStructureDeployer;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.context.jar.JarUtils;
+
+/**
+ * Determine the structure of a Bundle deployment.
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 16-Apr-2009
+ */
+public class BundleStructureDeployer extends AbstractVFSStructureDeployer
+{
+   /*
+    * * Sets the default relative order 9000.
+    */
+   public BundleStructureDeployer()
+   {
+      setRelativeOrder(9000);
+   }
+
+   public boolean determineStructure(StructureContext structureContext) throws DeploymentException
+   {
+      ContextInfo context = null;
+      VirtualFile file = structureContext.getFile();
+      VirtualFile root = structureContext.getRoot();
+
+      try
+      {
+         boolean trace = log.isTraceEnabled();
+
+         if (JarUtils.isArchive(file.getName()) == true && file != root)
+         {
+            if (trace)
+               log.trace("... no - ignoring child archive");
+            
+            return false;
+         }
+
+         if (isLeaf(file) == false)
+         {
+            // For non top level directories that don't look like jars
+            // we require a META-INF otherwise each subdirectory would be a subdeployment
+            if (JarUtils.isArchive(file.getName()) == false)
+            {
+               if (structureContext.isTopLevel() == false)
+               {
+                  try
+                  {
+                     VirtualFile child = file.getChild("META-INF");
+                     if (child != null)
+                     {
+                        if (trace)
+                           log.trace("... ok - non top level directory has a META-INF subdirectory");
+                     }
+                     else
+                     {
+                        if (trace)
+                           log.trace("... no - doesn't look like a jar and no META-INF subdirectory.");
+                        
+                        return false;
+                     }
+                  }
+                  catch (IOException e)
+                  {
+                     log.warn("Exception while checking if file is a jar: " + e);
+                     return false;
+                  }
+               }
+               else if (trace)
+               {
+                  log.trace("... ok - doesn't look like a jar but it is a top level directory.");
+               }
+            }
+         }
+         else if (JarUtils.isArchive(file.getName()))
+         {
+            if (trace)
+               log.trace("... ok - its an archive or at least pretending to be.");
+         }
+         else
+         {
+            if (trace)
+               log.trace("... no - not a directory or an archive.");
+            return false;
+         }
+
+         boolean valid = true;
+
+         if (isSupportsCandidateAnnotations())
+         {
+            StructureContext parentContext = structureContext.getParentContext();
+            if (parentContext != null && parentContext.isCandidateAnnotationScanning())
+               valid = checkCandidateAnnotations(structureContext, file);
+         }
+
+         if (valid)
+         {
+            // Create a context for this jar file with META-INF as the location for metadata
+            context = createContext(structureContext, "META-INF");
+
+            // The classpath is the root
+            addClassPath(structureContext, file, true, true, context);
+
+            // We try all the children as potential subdeployments
+            addAllChildren(structureContext);
+         }
+         return valid;
+      }
+      catch (Exception e)
+      {
+         // Remove the invalid context
+         if (context != null)
+            structureContext.removeChild(context);
+
+         throw DeploymentException.rethrowAsDeploymentException("Error determining structure: " + file.getName(), e);
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStructureDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/runtime/felix/src/main/resources/osgi-deployers-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/trunk/runtime/felix/src/main/resources/osgi-deployers-jboss-beans.xml	2009-04-16 14:33:50 UTC (rev 87432)
+++ projects/jboss-osgi/trunk/runtime/felix/src/main/resources/osgi-deployers-jboss-beans.xml	2009-04-16 15:08:34 UTC (rev 87433)
@@ -72,6 +72,9 @@
   <!-- The OSGi MetaData Deployer -->
   <bean name="jboss.osgi:service=BundleMetaDataDeployer" class="org.jboss.osgi.deployer.BundleMetaDataDeployer" />
   
+  <!-- The OSGi Bundle Structure Deployer -->
+  <bean name="jboss.osgi:service=BundleStructureDeployer" class="org.jboss.osgi.deployer.BundleStructureDeployer" />
+  
   <!-- The OSGi Bundle Deployer -->
   <bean name="jboss.osgi:service=BundleRealDeployer" class="org.jboss.osgi.deployer.BundleRealDeployer">
     <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>




More information about the jboss-cvs-commits mailing list