// Path: henson-plugin/src/main/java/dart/henson/plugin/generator/HensonNavigatorGenerator.java
// public class HensonNavigatorGenerator {
// 
//   public String generateHensonNavigatorClass(Set<String> targetActivities, String packageName) {
//     String packageStatement = "package " + packageName + ";\n";
// 
//     StringBuilder importStatement = new StringBuilder("import android.content.Context;\n");
//     targetActivities
//         .stream()
//         .forEach(
//             targetActivity -> {
//               importStatement.append(format("import %s__IntentBuilder;\n", targetActivity));
//             });
// 
//     String classStartStatement = "public class HensonNavigator {\n";
//     StringBuilder methodStatement = new StringBuilder();
//     targetActivities
//         .stream()
//         .forEach(
//             targetActivity -> {
//               String targetActivitySimpleName =
//                   targetActivity.substring(
//                       1 + targetActivity.lastIndexOf('.'), targetActivity.length());
//               String targetActivityCapitalizedName =
//                   dart.henson.plugin.util.StringUtil.capitalize(targetActivitySimpleName);
//               methodStatement.append(
//                   format(
//                       "  public static %s__IntentBuilder.InitialState goto%s(Context context) {\n",
//                       targetActivityCapitalizedName,
//                       targetActivityCapitalizedName,
//                       targetActivityCapitalizedName));
//               methodStatement.append(
//                   format(
//                       "    return %s__IntentBuilder.getInitialState(context);\n",
//                       targetActivityCapitalizedName));
//               methodStatement.append("  }\n");
//             });
//     String classEndStatement = "}\n";
//     return new StringBuilder()
//         .append(packageStatement)
//         .append(importStatement)
//         .append(classStartStatement)
//         .append(methodStatement)
//         .append(classEndStatement)
//         .toString();
//   }
// }


import static com.android.build.gradle.internal.publishing.AndroidArtifacts.ARTIFACT_TYPE;
import static java.util.Collections.singletonList;
import com.android.build.gradle.api.BaseVariant;
import com.android.build.gradle.internal.publishing.AndroidArtifacts;
import com.google.common.collect.Streams;
import dart.henson.plugin.generator.HensonNavigatorGenerator;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.attributes.AttributeContainer;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.file.UnionFileCollection;
import org.gradle.api.logging.Logger;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.compile.JavaCompile;

  @TaskAction
  public void generateHensonNavigator() {
    TaskProvider<JavaCompile> javaCompiler = variant.getJavaCompileProvider();
    FileCollection variantCompileClasspath = getJarDependencies();
    FileCollection uft =
        new UnionFileCollection(
            javaCompiler.get().getSource(), project.fileTree(destinationFolder));
    javaCompiler.get().setSource(uft);
    logger.debug("Analyzing configuration: " + variantCompileClasspath.getFiles());
    Set<String> targetActivities = new HashSet<>();
    Streams.stream(variantCompileClasspath)
        .forEach(
            dependency -> {
              logger.debug("Detected dependency: {}", dependency.getAbsolutePath());
              if (dependency.getName().endsWith(".jar")) {
                logger.debug("Detected navigation API dependency: {}", dependency.getName());
                if (!dependency.exists()) {
                  logger.debug("Dependency jar doesn't exist {}", dependency.getAbsolutePath());
                } else {
                  File file = dependency.getAbsoluteFile();
                  List<String> entries = getJarContent(file);
                  entries.forEach(
                      entry -> {
                        if (entry.matches(".*__IntentBuilder.class")) {
                          logger.debug("Detected intent builder: {}", entry);
                          String targetActivityFQN =
                              entry
                                  .substring(0, entry.length() - "__IntentBuilder.class".length())
                                  .replace('/', '.');
// Path: henson-plugin/src/main/java/dart/henson/plugin/generator/HensonNavigatorGenerator.java
// public class HensonNavigatorGenerator {
// 
//   public String generateHensonNavigatorClass(Set<String> targetActivities, String packageName) {
//     String packageStatement = "package " + packageName + ";\n";
// 
//     StringBuilder importStatement = new StringBuilder("import android.content.Context;\n");
//     targetActivities
//         .stream()
//         .forEach(
//             targetActivity -> {
//               importStatement.append(format("import %s__IntentBuilder;\n", targetActivity));
//             });
// 
//     String classStartStatement = "public class HensonNavigator {\n";
//     StringBuilder methodStatement = new StringBuilder();
//     targetActivities
//         .stream()
//         .forEach(
//             targetActivity -> {
//               String targetActivitySimpleName =
//                   targetActivity.substring(
//                       1 + targetActivity.lastIndexOf('.'), targetActivity.length());
//               String targetActivityCapitalizedName =
//                   dart.henson.plugin.util.StringUtil.capitalize(targetActivitySimpleName);
//               methodStatement.append(
//                   format(
//                       "  public static %s__IntentBuilder.InitialState goto%s(Context context) {\n",
//                       targetActivityCapitalizedName,
//                       targetActivityCapitalizedName,
//                       targetActivityCapitalizedName));
//               methodStatement.append(
//                   format(
//                       "    return %s__IntentBuilder.getInitialState(context);\n",
//                       targetActivityCapitalizedName));
//               methodStatement.append("  }\n");
//             });
//     String classEndStatement = "}\n";
//     return new StringBuilder()
//         .append(packageStatement)
//         .append(importStatement)
//         .append(classStartStatement)
//         .append(methodStatement)
//         .append(classEndStatement)
//         .toString();
//   }
// }


// Path: henson-plugin/src/main/java/dart/henson/plugin/internal/GenerateHensonNavigatorTask.java
import static com.android.build.gradle.internal.publishing.AndroidArtifacts.ARTIFACT_TYPE;
import static java.util.Collections.singletonList;
import com.android.build.gradle.api.BaseVariant;
import com.android.build.gradle.internal.publishing.AndroidArtifacts;
import com.google.common.collect.Streams;
import dart.henson.plugin.generator.HensonNavigatorGenerator;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.attributes.AttributeContainer;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.file.UnionFileCollection;
import org.gradle.api.logging.Logger;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.compile.JavaCompile;


  @TaskAction
  public void generateHensonNavigator() {
    TaskProvider<JavaCompile> javaCompiler = variant.getJavaCompileProvider();
    FileCollection variantCompileClasspath = getJarDependencies();
    FileCollection uft =
        new UnionFileCollection(
            javaCompiler.get().getSource(), project.fileTree(destinationFolder));
    javaCompiler.get().setSource(uft);
    logger.debug("Analyzing configuration: " + variantCompileClasspath.getFiles());
    Set<String> targetActivities = new HashSet<>();
    Streams.stream(variantCompileClasspath)
        .forEach(
            dependency -> {
              logger.debug("Detected dependency: {}", dependency.getAbsolutePath());
              if (dependency.getName().endsWith(".jar")) {
                logger.debug("Detected navigation API dependency: {}", dependency.getName());
                if (!dependency.exists()) {
                  logger.debug("Dependency jar doesn't exist {}", dependency.getAbsolutePath());
                } else {
                  File file = dependency.getAbsoluteFile();
                  List<String> entries = getJarContent(file);
                  entries.forEach(
                      entry -> {
                        if (entry.matches(".*__IntentBuilder.class")) {
                          logger.debug("Detected intent builder: {}", entry);
                          String targetActivityFQN =
                              entry
                                  .substring(0, entry.length() - "__IntentBuilder.class".length())
                                  .replace('/', '.');
                          targetActivities.add(targetActivityFQN);