Beispiel #1
0
 private void readInjectedDependencies() {
   File injectedDepFile = new File(getConfigDir(), "injectedDependencies.json");
   if (!injectedDepFile.exists()) {
     FMLLog.getLogger()
         .log(
             Level.DEBUG,
             "File {} not found. No dependencies injected",
             injectedDepFile.getAbsolutePath());
     return;
   }
   JsonParser parser = new JsonParser();
   JsonElement injectedDeps;
   try {
     injectedDeps = parser.parse(new FileReader(injectedDepFile));
     for (JsonElement el : injectedDeps.getAsJsonArray()) {
       JsonObject jo = el.getAsJsonObject();
       String modId = jo.get("modId").getAsString();
       JsonArray deps = jo.get("deps").getAsJsonArray();
       for (JsonElement dep : deps) {
         JsonObject depObj = dep.getAsJsonObject();
         String type = depObj.get("type").getAsString();
         if (type.equals("before")) {
           injectedBefore.put(
               modId, VersionParser.parseVersionReference(depObj.get("target").getAsString()));
         } else if (type.equals("after")) {
           injectedAfter.put(
               modId, VersionParser.parseVersionReference(depObj.get("target").getAsString()));
         } else {
           FMLLog.getLogger().log(Level.ERROR, "Invalid dependency type {}", type);
           throw new RuntimeException("Unable to parse type");
         }
       }
     }
   } catch (Exception e) {
     FMLLog.getLogger().log(Level.ERROR, "Unable to parse {} - skipping", injectedDepFile);
     FMLLog.getLogger().throwing(Level.ERROR, e);
     return;
   }
   FMLLog.getLogger()
       .log(
           Level.DEBUG,
           "Loaded {} injected dependencies on modIds: {}",
           injectedBefore.size(),
           injectedBefore.keySet());
 }
Beispiel #2
0
  public void computeDependencies(
      String dependencyString,
      Set<ArtifactVersion> requirements,
      List<ArtifactVersion> dependencies,
      List<ArtifactVersion> dependants) {
    if (dependencyString == null || dependencyString.length() == 0) {
      return;
    }

    boolean parseFailure = false;

    for (String dep : DEPENDENCYSPLITTER.split(dependencyString)) {
      List<String> depparts = Lists.newArrayList(DEPENDENCYPARTSPLITTER.split(dep));
      // Need two parts to the string
      if (depparts.size() != 2) {
        parseFailure = true;
        continue;
      }
      String instruction = depparts.get(0);
      String target = depparts.get(1);
      boolean targetIsAll = target.startsWith("*");

      // Cannot have an "all" relationship with anything except pure *
      if (targetIsAll && target.length() > 1) {
        parseFailure = true;
        continue;
      }

      // If this is a required element, add it to the required list
      if ("required-before".equals(instruction) || "required-after".equals(instruction)) {
        // You can't require everything
        if (!targetIsAll) {
          requirements.add(VersionParser.parseVersionReference(target));
        } else {
          parseFailure = true;
          continue;
        }
      }

      // You cannot have a versioned dependency on everything
      if (targetIsAll && target.indexOf('@') > -1) {
        parseFailure = true;
        continue;
      }
      // before elements are things we are loaded before (so they are our dependants)
      if ("required-before".equals(instruction) || "before".equals(instruction)) {
        dependants.add(VersionParser.parseVersionReference(target));
      }
      // after elements are things that load before we do (so they are out dependencies)
      else if ("required-after".equals(instruction) || "after".equals(instruction)) {
        dependencies.add(VersionParser.parseVersionReference(target));
      } else {
        parseFailure = true;
      }
    }

    if (parseFailure) {
      FMLLog.log(Level.WARN, "Unable to parse dependency string %s", dependencyString);
      throw new LoaderException(
          String.format("Unable to parse dependency string %s", dependencyString));
    }
  }