private static GradleContext createContext()

in analyzer/src/main/java/com/android/tools/sizereduction/analyzer/model/Project.java [61:86]


  private static GradleContext createContext(File directory, @Nullable Project parent) {
    // read the build file for the minSdkVersion
    File buildFile = new File(directory, BUILD_GRADLE);
    if (!buildFile.exists()) {
      throw new RuntimeException(
          "Invalid project directory with no gradle build file: " + buildFile.getAbsolutePath());
    }
    try {
      int defaultMinSdkVersion = parent != null ? parent.getContext().getMinSdkVersion() : 1;
      int defaultTargetSdkVersion = parent != null ? parent.getContext().getTargetSdkVersion() : 1;
      AndroidPluginVersion androidPluginVersion =
          parent != null ? parent.getContext().getAndroidPluginVersion() : null;
      String content = Files.asCharSource(buildFile, UTF_8).read();
      GradleContext.Builder builder =
          GroovyGradleParser.parseGradleBuildFile(
              content, defaultMinSdkVersion, defaultTargetSdkVersion, androidPluginVersion);
      // try to read the manifest(s) in the project to determine if this project is for an onDemand
      // module.
      File manifestFile = new File(directory, MANIFEST);
      boolean isOnDemand = manifestFile.exists() && isOnDemand(manifestFile);
      builder.setOnDemand(isOnDemand);
      return builder.build();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }