/**
  * Tests that the framework refuses to load a bundle that requests a framework version newer than
  * the one present.
  */
 @Test(priority = -1)
 public void testCheckVersion() throws Exception {
   // The test bundles require framework 1.0, so pretend the framework is
   // older.
   FrameworkUtilTestHelpers.setFrameworkVersion(Version.parse("0.5"));
   try {
     List<URL> urls = getTestBundles();
     Assert.assertFalse(urls.isEmpty());
     ConnectorInfoManagerFactory.getInstance().getLocalManager(urls.get(0));
     Assert.fail();
   } catch (ConfigurationException e) {
     if (!e.getMessage().contains("unrecognized framework version")) {
       Assert.fail();
     }
   }
 }
  /** Final pass - create connector infos. */
  private List<ConnectorInfo> createConnectorInfo(
      Bundle parsed, List<ManifestEntry> manifestEnties) {
    List<ConnectorInfo> rv = new ArrayList<ConnectorInfo>();
    Enumeration<URL> classFiles = parsed.findEntries("/", "*.class", true);
    List<URL> propertyFiles = Collections.list(parsed.findEntries("/", "*.properties", true));

    String frameworkVersion = null;
    String bundleName = null;
    String bundleVersion = null;

    for (ManifestEntry entry : manifestEnties) {
      if (ConnectorManifestScanner.ATT_FRAMEWORK_VERSION.equals(entry.getKey())) {
        frameworkVersion = entry.getValue();
      } else if (ConnectorManifestScanner.ATT_BUNDLE_NAME.equals(entry.getKey())) {
        bundleName = entry.getValue();
      } else if (ConnectorManifestScanner.ATT_BUNDLE_VERSION.equals(entry.getKey())) {
        bundleVersion = entry.getValue();
      }
    }

    if (FrameworkUtil.getFrameworkVersion().compareTo(Version.parse(frameworkVersion)) < 0) {
      String message =
          "Bundle "
              + parsed.getLocation()
              + " requests an unrecognized framework version "
              + frameworkVersion
              + " but available is "
              + FrameworkUtil.getFrameworkVersion().getVersion();
      throw new ConfigurationException(message);
    }

    if (StringUtil.isBlank(bundleName) || StringUtil.isBlank(bundleVersion)) {
      return rv;
    }

    while (classFiles.hasMoreElements()) {

      Class<?> connectorClass = null;
      ConnectorClass options = null;
      String name = classFiles.nextElement().getFile();

      String className = name.substring(1, name.length() - ".class".length());
      className = className.replace('/', '.');
      try {
        connectorClass = parsed.loadClass(className);
        options = connectorClass.getAnnotation(ConnectorClass.class);
      } catch (Throwable e) {
        // probe for the class. this might not be an error since it
        // might be from a bundle
        // fragment ( a bundle only included by other bundles ).
        // However, we should definitely warn
        logger.warn(
            "Unable to load class {} from bundle {}. Class will be ignored and will not be listed in list of connectors.",
            new Object[] {className, parsed.getLocation()},
            e);
      }

      if (connectorClass != null && options != null) {
        if (!Connector.class.isAssignableFrom(connectorClass)) {
          throw new ConfigurationException(
              "Class " + connectorClass + " does not implement " + Connector.class.getName());
        }
        final LocalConnectorInfoImpl info = new LocalConnectorInfoImpl();
        info.setConnectorClass(connectorClass.asSubclass(Connector.class));
        try {
          info.setConnectorConfigurationClass(options.configurationClass());
          info.setConnectorDisplayNameKey(options.displayNameKey());
          info.setConnectorCategoryKey(options.categoryKey());
          info.setConnectorKey(
              new ConnectorKey(bundleName, bundleVersion, connectorClass.getName()));
          ConnectorMessagesImpl messages =
              loadMessageCatalog(propertyFiles, parsed, info.getConnectorClass());
          info.setMessages(messages);
          info.setDefaultAPIConfiguration(createDefaultAPIConfiguration(info));
          rv.add(info);
        } catch (final NoClassDefFoundError e) {
          logger.warn(
              "Unable to load configuration class of connector {} from bundle {}. Class will be ignored and will not be listed in list of connectors.",
              logger.isDebugEnabled()
                  ? new Object[] {connectorClass, parsed.getLocation(), e}
                  : new Object[] {connectorClass, parsed.getLocation()});
        } catch (final TypeNotPresentException e) {
          logger.warn(
              "Unable to load configuration class of connector {} from bundle {}. Class will be ignored and will not be listed in list of connectors.",
              logger.isDebugEnabled()
                  ? new Object[] {connectorClass, parsed.getLocation(), e}
                  : new Object[] {connectorClass, parsed.getLocation()});
        }
      }
    }
    return rv;
  }