Exemplo n.º 1
0
  /**
   * Given a library file, find the configuration element that matches the current platform and
   * target
   *
   * @param lib
   * @return the configuration that matches the current platform and target
   */
  private Configuration getTargetConfiguration(Library lib) {
    String matchedConfigName = null;

    // check whether platform and target match what we support
    ArrayList<Platform> platforms = lib.getPlatforms();
    if (platforms != null) {
      for (Platform p : platforms) {
        if (p.getValue().equals(_platform)) {
          ArrayList<Target> targets = p.getTargets();

          if (targets != null) {
            for (Target t : targets) {
              if (t.getVersion().equals(_targetVersion)) {
                matchedConfigName = t.getConfigName();
              }
            }
          }
        }
      }
    }

    // make sure the config is defined
    if (matchedConfigName != null) {
      ArrayList<Configuration> configurations = lib.getConfigurations();

      for (Configuration config : configurations) {
        if (config.getName().equals(matchedConfigName)) {
          return config;
        }
      }
    }

    return null;
  }
Exemplo n.º 2
0
    /** @return the extension id found in library.xml, or null if it is not defined */
    public String getExtensionId() {
      if (_lib != null && _lib.getExtension() != null) {
        return _lib.getExtension().getId();
      }

      return null;
    }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
0
  /** Resolve features from extension repository */
  @SuppressWarnings("unchecked")
  private void resolveFeaturesFromRepository() throws Exception {
    parseRepository();

    HashSet<String> extensions = new HashSet<String>();

    // derive extensions to be built based on features on white list
    for (String featureId : _requiredFeatures) {
      ExtensionInfo info = _repositoryFeatures.get(featureId);

      if (info != null) {
        String extensionId = info.getExtensionId();

        // unable to build app that uses feature from an extension that
        // does not have an id
        // because it is not possible to resolve dependencies
        if (extensionId != null && !extensionId.isEmpty()) {
          extensions.add(extensionId);

          // if the extension has any JAR dependencies, add it to the
          // list so that it gets added to rapc classpath
          if (info.getCompiledJARPaths() != null) {
            for (String jarPath : info.getCompiledJARPaths()) {
              File jarFile = new File(jarPath);
              _compiledJARDependencies.add(jarFile.getAbsolutePath());
            }
          }
        } else {
          throw new PackageException(
              "EXCEPTION_NEED_FEATURE_FROM_UNIDENTIFIED_EXTENSION", featureId);
        }
      } else {
        // TODO temp workaround to not throw error when widgetcache
        // features cannot be found in repository
        if (!FRAMEWORK_FEATURES.contains(featureId)) {
          throw new PackageException("EXCEPTION_FEATURE_NOT_FOUND", featureId);
        }
      }
    }

    // find all extensions that need to be built with dependencies taken
    // into account
    ExtensionDependencyManager edm = new ExtensionDependencyManager(_extensionLookupTable);
    extensions = edm.resolveExtensions(extensions);

    for (String extensionId : extensions) {
      ExtensionInfo info = _extensionLookupTable.get(extensionId);
      HashSet<String> javaPaths = info.getRepositoryJavaPaths();
      copyExtensionPathsToSourceDir(javaPaths, getExtensionPath(), info.getExtensionFolder());
      _resolvedPaths.addAll((HashSet<String>) _curPaths.clone());

      HashSet<String> jsPaths = info.getRepositoryJavaScriptPaths();
      copyExtensionPathsToSourceDir(
          jsPaths,
          getJavaScriptPath()
              + File.separator
              + getEscapedEntryClass(info.getLibrary().getEntryClass())
              + File.separator,
          info.getExtensionFolder());
      _resolvedPaths.addAll((HashSet<String>) _curPaths.clone());

      _extensionJSFiles.addAll(getJSRelativePaths(_curPaths));

      // extension can be found in lookup table for sure, otherwise
      // exception would have been thrown in ExtensionDependencyManager.resolve
      Library lib = _extensionLookupTable.get(extensionId).getLibrary();
      _extensionClasses.add(lib.getEntryClass());
    }
  }