package com.uber.okbuck.core.util;

import com.uber.okbuck.composer.base.BuckRuleComposer;
import com.uber.okbuck.core.dependency.DependencyCache;
import com.uber.okbuck.core.dependency.OExternalDependency;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency;

public final class ProguardUtil {

  private static final String PROGUARD_GROUP = "net.sf.proguard";
  private static final String PROGUARD_MODULE = "proguard-base";

  private ProguardUtil() {}

  @Nullable
  public static String getProguardJarPath(Project project) {
    String proguardVersion =
        ProjectUtil.findVersionInClasspath(project, PROGUARD_GROUP, PROGUARD_MODULE);

    Configuration proguardConfiguration =
        project
            .getConfigurations()
            .detachedConfiguration(
                new DefaultExternalModuleDependency(
                    PROGUARD_GROUP, PROGUARD_MODULE, proguardVersion));

    DependencyCache cache = new DependencyCache(project, ProjectUtil.getDependencyManager(project));
    Set<OExternalDependency> dependencies = cache.build(proguardConfiguration);

    Optional<OExternalDependency> proguardDependency =
        dependencies
            .stream()
            .filter(
                dependency ->
                    dependency.getGroup().equals(PROGUARD_GROUP)
                        && dependency.getName().equals(PROGUARD_MODULE))
            .findAny();

    return proguardDependency.map(BuckRuleComposer::external).orElse(null);
  }
}

@@ -29,16 +29,62 @@
 .util;%0A%0A
+import com.google.errorprone.annotations.Var;%0A
 import c
@@ -130,16 +130,16 @@
 mposer;%0A
-
 import c
@@ -596,16 +596,86 @@
 guard%22;%0A
+  private static final String PROGUARD_NEW_GROUP = %22com.guardsquare%22;%0A
   privat
@@ -838,16 +838,21 @@
 ) %7B%0A    
+@Var 
 String p
@@ -864,24 +864,225 @@
 rdVersion =%0A
+        ProjectUtil.findVersionInClasspath(project, PROGUARD_NEW_GROUP, PROGUARD_MODULE);%0A    @Var String currentGroup = PROGUARD_NEW_GROUP;%0A%0A    if (proguardVersion == null) %7B%0A      proguardVersion =%0A
         Proj
@@ -1155,16 +1155,61 @@
 ODULE);%0A
+      currentGroup = PROGUARD_GROUP;%0A    %7D%0A%0A%0A
 %0A    Con
@@ -1401,30 +1401,28 @@
         
-PROGUARD_GROUP
+currentGroup
 , PROGUA
@@ -1795,32 +1795,33 @@
                 
+(
 dependency.getGr
@@ -1848,16 +1848,69 @@
 D_GROUP)
+ %7C%7C dependency.getGroup().equals(PROGUARD_NEW_GROUP))
 %0A       

Allow substituting the new proguard namespace (#914)