Пример #1
0
  private static HashSet<String> getRequiredFeatures(
      Hashtable<WidgetAccess, Vector<WidgetFeature>> accessTable) {
    Set<WidgetAccess> keys = accessTable.keySet();
    HashSet<String> requiredFeatures = new HashSet<String>();

    for (Object accessKey : keys) {
      Vector<WidgetFeature> features = (Vector<WidgetFeature>) accessTable.get(accessKey);

      for (Object featureObject : features) {
        WidgetFeature feature = (WidgetFeature) featureObject;
        requiredFeatures.add(feature.getID());
      }
    }

    return requiredFeatures;
  }
Пример #2
0
  /**
   * Parse a given a library.xml to find out the features it offers and store the proper set of
   * source file paths for the current platform and target
   *
   * @param libraryXML library.xml file, cannot be null
   * @param allowBackwardCompatibility true if it's parsing library.xml from an extension JAR
   * @return hashtable that contains feature id's and the paths for the source files, or null if (1)
   *     library.xml is malformed, (2) if allowBackwardCompatibility is false, and <target>,
   *     <configuration>, <platform> or <src> is not specified correctly
   * @throws Exception
   */
  private Hashtable<String, ExtensionInfo> parseFeaturesInLibraryXML(
      File libraryXML, boolean allowBackwardCompatibility) throws Exception {
    Library lib = parseLibraryXML(libraryXML);

    if (lib == null) {
      return null;
    }

    ArrayList<WidgetFeature> features = lib.getFeatures();
    HashSet<String> javaPaths = new HashSet<String>();
    HashSet<String> jsPaths = new HashSet<String>();
    Hashtable<String, ExtensionInfo> availableFeatures = new Hashtable<String, ExtensionInfo>();

    if (allowBackwardCompatibility) {
      // have to work for library.xml that doesn't contain configuration and platform elements
      File[] files = _temporaryDirectory.listFiles();

      for (File f : files) {
        javaPaths.add(f.getAbsolutePath());
      }
    } else {
      ExtensionInfo info = new ExtensionInfo(lib, javaPaths, jsPaths);
      boolean extensionIdFound = false;

      if (lib.getExtension() != null) {
        Extension extension = lib.getExtension();
        String id = extension.getId();

        if (id != null && !id.isEmpty()) {
          if (_extensionLookupTable.contains(id)) {
            // more than one library.xml contain the same extension id
            Logger.logMessage(
                LogType.WARNING, "VALIDATION_EXTENSION_DEFINED_MORE_THAN_ONCE", new String[] {id});
          }

          _extensionLookupTable.put(id, info);

          info.setExtensionFolder(libraryXML.getParentFile());

          extensionIdFound = true;
        }
      }

      if (!extensionIdFound) {
        // not considered an error, this extension might not be used
        // by the app being compiled
        Logger.logMessage(
            LogType.WARNING,
            "VALIDATION_LIBRARYXML_EXTENSION_ID_NOT_DEFINED",
            new String[] {libraryXML.getAbsolutePath()});
      }

      Configuration config = getTargetConfiguration(lib);

      if (config == null) {
        Logger.logMessage(
            LogType.WARNING,
            "VALIDATION_LIBRARYXML_NO_CONFIG",
            new String[] {libraryXML.getAbsolutePath()});
        return null;
      }

      ArrayList<Src> src = config.getSrc();

      if (src == null || src.isEmpty()) {
        Logger.logMessage(
            LogType.WARNING,
            "VALIDATION_LIBRARYXML_NO_SRC",
            new String[] {libraryXML.getAbsolutePath()});
        return null;
      }

      File extensionDir = libraryXML.getParentFile();

      for (Src s : src) {
        String path = s.getPath();

        if (s.getType().equalsIgnoreCase("text/java")) {
          javaPaths.add(extensionDir.getAbsolutePath() + File.separator + path);
        } else if (s.getType().equalsIgnoreCase("text/javascript")) {
          jsPaths.add(extensionDir.getAbsolutePath() + File.separator + path);
        }
      }
    }

    ExtensionInfo info = new ExtensionInfo(lib, javaPaths, jsPaths);

    for (WidgetFeature feature : features) {
      availableFeatures.put(feature.getID(), info);
    }

    if (lib.getCompiledJARDependencies() != null) {
      for (Jar j : lib.getCompiledJARDependencies()) {
        String path = j.getPath();
        File temp = new File(path);

        if (temp.isAbsolute()) {
          info.addCompiledJARPath(path);
        } else {
          info.addCompiledJARPath(
              libraryXML.getParentFile().getAbsolutePath() + File.separator + path);
        }
      }
    }

    return availableFeatures;
  }