0 Replies Latest reply on Oct 7, 2009 1:29 PM by thomas.diesler

    Handling of Bundle-ClassPath

    thomas.diesler

      The Bundle-ClassPath is now handles in OSGiClassLoaderFactory like this

      https://jira.jboss.org/jira/browse/JBOSGI-162

       public ClassLoaderPolicy createClassLoaderPolicy()
       {
       VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit)unit;
       OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
       VirtualFile[] roots = getClassLoaderPolicyRoots(bundleState, vfsUnit);
       return new OSGiClassLoaderPolicy(bundleState, roots);
       }
      
       private VirtualFile[] getClassLoaderPolicyRoots(OSGiBundleState bundleState, VFSDeploymentUnit vfsUnit)
       {
       VirtualFile root = vfsUnit.getRoot();
      
       // If there is no Bundle-ClassPath in the manifest, simply use the root
       List<String> bundleClassPath = bundleState.getOSGiMetaData().getBundleClassPath();
       if (bundleClassPath == null)
       {
       return new VirtualFile[] { root };
       }
      
       log.debug("Bundle-ClassPath: " + bundleClassPath);
      
       // Add a vfs root for every Bundle-ClassPath element
       List<VirtualFile> rootsList = new ArrayList<VirtualFile>();
       for (String path : bundleClassPath)
       {
       if (path.equals("."))
       {
       rootsList.add(root);
       }
       else
       {
       try
       {
       VirtualFile child = root.getChild(path);
       rootsList.add(child);
       }
       catch (IOException ex)
       {
       throw new IllegalArgumentException("Cannot find class path '" + path + "' in: " + root);
       }
       }
       }
      
       VirtualFile[] rootsArray = new VirtualFile[rootsList.size()];
       rootsList.toArray(rootsArray);
      
       return rootsArray;
       }
      


      Note, I create a policy root entry for every bundle class path token.