// dealing with imported module other than root and directly importing root
  private static Collection<Module> getImportedModules(
      Map<ModuleId, Module> allModules,
      Set<Module> baseModules,
      TreeMultimap<String, Module> nameToModulesAll) {

    List<Module> relatedModules = Lists.newLinkedList();

    for (Module module : baseModules) {
      for (ModuleImport moduleImport : module.getImports()) {

        Date revisionDate =
            moduleImport.getRevision() == null
                ? nameToModulesAll.get(moduleImport.getModuleName()).first().getRevision()
                : moduleImport.getRevision();

        ModuleId key = new ModuleId(moduleImport.getModuleName(), revisionDate);
        Module importedModule = allModules.get(key);

        Preconditions.checkArgument(
            importedModule != null,
            "Invalid schema, cannot find imported module: %s from module: %s, %s, modules:%s",
            key,
            module.getQNameModule(),
            module.getName());
        relatedModules.add(importedModule);

        // calling imports recursive
        relatedModules.addAll(
            getImportedModules(
                allModules, Collections.singleton(importedModule), nameToModulesAll));
      }
    }

    return relatedModules;
  }
示例#2
0
  private void identifyDuplicates(List<ModContainer> mods) {
    TreeMultimap<ModContainer, File> dupsearch =
        TreeMultimap.create(new ModIdComparator(), Ordering.arbitrary());
    for (ModContainer mc : mods) {
      if (mc.getSource() != null) {
        dupsearch.put(mc, mc.getSource());
      }
    }

    ImmutableMultiset<ModContainer> duplist = Multisets.copyHighestCountFirst(dupsearch.keys());
    SetMultimap<ModContainer, File> dupes = LinkedHashMultimap.create();
    for (Entry<ModContainer> e : duplist.entrySet()) {
      if (e.getCount() > 1) {
        FMLLog.severe(
            "Found a duplicate mod %s at %s",
            e.getElement().getModId(), dupsearch.get(e.getElement()));
        dupes.putAll(e.getElement(), dupsearch.get(e.getElement()));
      }
    }
    if (!dupes.isEmpty()) {
      throw new DuplicateModsFoundException(dupes);
    }
  }