Пример #1
0
  /** Extract dependencies from module builders or modules to fill dependency graph */
  private static void processModules(
      final Map<String, Map<Date, ModuleNodeImpl>> moduleGraph,
      final Iterable<ModuleOrModuleBuilder> builders) {

    // Process nodes
    for (ModuleOrModuleBuilder momb : builders) {

      String name;
      Date rev;

      if (momb.isModule()) {
        name = momb.getModule().getName();
        rev = momb.getModule().getRevision();
      } else {
        name = momb.getModuleBuilder().getName();
        rev = momb.getModuleBuilder().getRevision();
      }

      if (rev == null) {
        rev = DEFAULT_REVISION;
      }

      if (moduleGraph.get(name) == null) {
        moduleGraph.put(name, Maps.<Date, ModuleNodeImpl>newHashMap());
      }

      if (moduleGraph.get(name).get(rev) != null) {
        ex(String.format("Module:%s with revision:%s declared twice", name, formatRevDate(rev)));
      }

      moduleGraph.get(name).put(rev, new ModuleNodeImpl(name, rev, momb));
    }
  }
Пример #2
0
 @Override
 public ModuleBuilder apply(final TopologicalSort.Node input) {
   // Cast to ModuleBuilder from Node and return
   if (input == null) {
     return null;
   }
   ModuleOrModuleBuilder moduleOrModuleBuilder = ((ModuleNodeImpl) input).getReference();
   return moduleOrModuleBuilder.getModuleBuilder();
 }
Пример #3
0
  /** Extract module:revision from module builders */
  private static void processDependencies(
      final Map<String, Map<Date, ModuleNodeImpl>> moduleGraph,
      final Iterable<ModuleOrModuleBuilder> mmbs) {
    Map<URI, ModuleOrModuleBuilder> allNS = new HashMap<>();

    // Create edges in graph
    for (ModuleOrModuleBuilder mmb : mmbs) {
      Map<String, Date> imported = Maps.newHashMap();

      String fromName;
      Date fromRevision;
      Collection<ModuleImport> imports;
      URI ns;

      if (mmb.isModule()) {
        Module module = mmb.getModule();
        fromName = module.getName();
        fromRevision = module.getRevision();
        imports = module.getImports();
        ns = module.getNamespace();
      } else {
        ModuleBuilder moduleBuilder = mmb.getModuleBuilder();
        fromName = moduleBuilder.getName();
        fromRevision = moduleBuilder.getRevision();
        imports = moduleBuilder.getImports().values();
        ns = moduleBuilder.getNamespace();
      }

      // check for existence of module with same namespace
      if (allNS.containsKey(ns)) {
        ModuleOrModuleBuilder mod = allNS.get(ns);
        String name = null;
        Date revision = null;
        if (mod.isModule()) {
          name = mod.getModule().getName();
          revision = mod.getModule().getRevision();
        } else if (mod.isModuleBuilder()) {
          name = mod.getModuleBuilder().getName();
          revision = mod.getModuleBuilder().getRevision();
        }
        if (!(fromName.equals(name))) {
          LOGGER.warn(
              "Error while sorting module [{}, {}]: module with same namespace ({}) already loaded: [{}, {}]",
              fromName,
              fromRevision,
              ns,
              name,
              revision);
        }
      } else {
        allNS.put(ns, mmb);
      }

      // no need to check if other Type of object, check is performed in
      // process modules

      if (fromRevision == null) {
        fromRevision = DEFAULT_REVISION;
      }

      for (ModuleImport imprt : imports) {
        String toName = imprt.getModuleName();
        Date toRevision = imprt.getRevision() == null ? DEFAULT_REVISION : imprt.getRevision();

        ModuleNodeImpl from = moduleGraph.get(fromName).get(fromRevision);

        ModuleNodeImpl to =
            getModuleByNameAndRevision(moduleGraph, fromName, fromRevision, toName, toRevision);

        /*
         * Check imports: If module is imported twice with different
         * revisions then throw exception
         */
        if (imported.get(toName) != null
            && !imported.get(toName).equals(toRevision)
            && !imported.get(toName).equals(DEFAULT_REVISION)
            && !toRevision.equals(DEFAULT_REVISION)) {
          ex(
              String.format(
                  "Module:%s imported twice with different revisions:%s, %s",
                  toName, formatRevDate(imported.get(toName)), formatRevDate(toRevision)));
        }

        imported.put(toName, toRevision);

        from.addEdge(to);
      }
    }
  }