Example #1
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());
    }
  }