gradle-wrapper

16:36:00.298 INFO  jd.cli.Main - Decompiling gradle-wrapper.jar
package org.gradle.wrapper;

class Download$1 {}

/* Location:
 * Qualified Name:     org.gradle.wrapper.Download.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.net.Authenticator;
import java.net.PasswordAuthentication;

class Download$SystemPropertiesProxyAuthenticator
  extends Authenticator
{
  protected PasswordAuthentication getPasswordAuthentication()
  {
    return new PasswordAuthentication(System.getProperty("http.proxyUser"), System.getProperty("http.proxyPassword", "").toCharArray());
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.Download.SystemPropertiesProxyAuthenticator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.File;
import java.net.URI;

public abstract interface IDownload
{
  public abstract void download(URI paramURI, File paramFile)
    throws Exception;
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.IDownload
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.Closeable;

public class ExclusiveFileAccessManager
{
  public static final String LOCK_FILE_SUFFIX = ".lck";
  private final int timeoutMs;
  private final int pollIntervalMs;
  
  public ExclusiveFileAccessManager(int timeoutMs, int pollIntervalMs)
  {
    this.timeoutMs = timeoutMs;
    this.pollIntervalMs = pollIntervalMs;
  }
  
  /* Error */
  public <T> T access(java.io.File exclusiveFile, java.util.concurrent.Callable<T> task)
  {
    // Byte code:
    //   0: new 4	java/io/File
    //   3: dup
    //   4: aload_1
    //   5: invokevirtual 5	java/io/File:getParentFile	()Ljava/io/File;
    //   8: new 6	java/lang/StringBuilder
    //   11: dup
    //   12: invokespecial 7	java/lang/StringBuilder:<init>	()V
    //   15: aload_1
    //   16: invokevirtual 8	java/io/File:getName	()Ljava/lang/String;
    //   19: invokevirtual 9	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   22: ldc 10
    //   24: invokevirtual 9	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   27: invokevirtual 11	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   30: invokespecial 12	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   33: astore_3
    //   34: aload_3
    //   35: invokevirtual 5	java/io/File:getParentFile	()Ljava/io/File;
    //   38: invokevirtual 13	java/io/File:mkdirs	()Z
    //   41: pop
    //   42: aconst_null
    //   43: astore 4
    //   45: aconst_null
    //   46: astore 5
    //   48: invokestatic 14	java/lang/System:currentTimeMillis	()J
    //   51: lstore 6
    //   53: aconst_null
    //   54: astore 8
    //   56: aload 8
    //   58: ifnonnull +70 -> 128
    //   61: invokestatic 14	java/lang/System:currentTimeMillis	()J
    //   64: lload 6
    //   66: aload_0
    //   67: getfield 2	org/gradle/wrapper/ExclusiveFileAccessManager:timeoutMs	I
    //   70: i2l
    //   71: ladd
    //   72: lcmp
    //   73: ifge +55 -> 128
    //   76: new 15	java/io/RandomAccessFile
    //   79: dup
    //   80: aload_3
    //   81: ldc 16
    //   83: invokespecial 17	java/io/RandomAccessFile:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   86: astore 4
    //   88: aload 4
    //   90: invokevirtual 18	java/io/RandomAccessFile:getChannel	()Ljava/nio/channels/FileChannel;
    //   93: astore 5
    //   95: aload 5
    //   97: invokevirtual 19	java/nio/channels/FileChannel:tryLock	()Ljava/nio/channels/FileLock;
    //   100: astore 8
    //   102: aload 8
    //   104: ifnonnull -48 -> 56
    //   107: aload 5
    //   109: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   112: aload 4
    //   114: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   117: aload_0
    //   118: getfield 3	org/gradle/wrapper/ExclusiveFileAccessManager:pollIntervalMs	I
    //   121: i2l
    //   122: invokestatic 21	java/lang/Thread:sleep	(J)V
    //   125: goto -69 -> 56
    //   128: aload 8
    //   130: ifnonnull +45 -> 175
    //   133: new 22	java/lang/RuntimeException
    //   136: dup
    //   137: new 6	java/lang/StringBuilder
    //   140: dup
    //   141: invokespecial 7	java/lang/StringBuilder:<init>	()V
    //   144: ldc 23
    //   146: invokevirtual 9	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   149: aload_0
    //   150: getfield 2	org/gradle/wrapper/ExclusiveFileAccessManager:timeoutMs	I
    //   153: invokevirtual 24	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
    //   156: ldc 25
    //   158: invokevirtual 9	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   161: aload_1
    //   162: invokevirtual 26	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   165: invokevirtual 9	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   168: invokevirtual 11	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   171: invokespecial 27	java/lang/RuntimeException:<init>	(Ljava/lang/String;)V
    //   174: athrow
    //   175: aload_2
    //   176: invokeinterface 28 1 0
    //   181: astore 9
    //   183: aload 8
    //   185: invokevirtual 29	java/nio/channels/FileLock:release	()V
    //   188: aload 5
    //   190: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   193: aconst_null
    //   194: astore 5
    //   196: aload 4
    //   198: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   201: aconst_null
    //   202: astore 4
    //   204: aload 5
    //   206: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   209: aload 4
    //   211: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   214: aload 9
    //   216: areturn
    //   217: astore 10
    //   219: aload 8
    //   221: invokevirtual 29	java/nio/channels/FileLock:release	()V
    //   224: aload 5
    //   226: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   229: aconst_null
    //   230: astore 5
    //   232: aload 4
    //   234: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   237: aconst_null
    //   238: astore 4
    //   240: aload 10
    //   242: athrow
    //   243: astore 6
    //   245: aload 6
    //   247: instanceof 22
    //   250: ifeq +9 -> 259
    //   253: aload 6
    //   255: checkcast 22	java/lang/RuntimeException
    //   258: athrow
    //   259: new 22	java/lang/RuntimeException
    //   262: dup
    //   263: aload 6
    //   265: invokespecial 31	java/lang/RuntimeException:<init>	(Ljava/lang/Throwable;)V
    //   268: athrow
    //   269: astore 11
    //   271: aload 5
    //   273: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   276: aload 4
    //   278: invokestatic 20	org/gradle/wrapper/ExclusiveFileAccessManager:maybeCloseQuietly	(Ljava/io/Closeable;)V
    //   281: aload 11
    //   283: athrow
    // Line number table:
    //   Java source line #39	-> byte code offset #0
    //   Java source line #40	-> byte code offset #34
    //   Java source line #41	-> byte code offset #42
    //   Java source line #42	-> byte code offset #45
    //   Java source line #45	-> byte code offset #48
    //   Java source line #46	-> byte code offset #53
    //   Java source line #48	-> byte code offset #56
    //   Java source line #49	-> byte code offset #76
    //   Java source line #50	-> byte code offset #88
    //   Java source line #51	-> byte code offset #95
    //   Java source line #53	-> byte code offset #102
    //   Java source line #54	-> byte code offset #107
    //   Java source line #55	-> byte code offset #112
    //   Java source line #56	-> byte code offset #117
    //   Java source line #60	-> byte code offset #128
    //   Java source line #61	-> byte code offset #133
    //   Java source line #65	-> byte code offset #175
    //   Java source line #67	-> byte code offset #183
    //   Java source line #69	-> byte code offset #188
    //   Java source line #70	-> byte code offset #193
    //   Java source line #71	-> byte code offset #196
    //   Java source line #72	-> byte code offset #201
    //   Java source line #81	-> byte code offset #204
    //   Java source line #82	-> byte code offset #209
    //   Java source line #67	-> byte code offset #217
    //   Java source line #69	-> byte code offset #224
    //   Java source line #70	-> byte code offset #229
    //   Java source line #71	-> byte code offset #232
    //   Java source line #72	-> byte code offset #237
    //   Java source line #74	-> byte code offset #243
    //   Java source line #75	-> byte code offset #245
    //   Java source line #76	-> byte code offset #253
    //   Java source line #78	-> byte code offset #259
    //   Java source line #81	-> byte code offset #269
    //   Java source line #82	-> byte code offset #276
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	284	0	this	ExclusiveFileAccessManager
    //   0	284	1	exclusiveFile	java.io.File
    //   0	284	2	task	java.util.concurrent.Callable<T>
    //   33	48	3	lockFile	java.io.File
    //   43	234	4	randomAccessFile	java.io.RandomAccessFile
    //   46	226	5	channel	java.nio.channels.FileChannel
    //   51	14	6	startAt	long
    //   243	21	6	e	Exception
    //   54	166	8	lock	java.nio.channels.FileLock
    //   181	34	9	localObject1	Object
    //   217	24	10	localObject2	Object
    //   269	13	11	localObject3	Object
    // Exception table:
    //   from	to	target	type
    //   175	183	217	finally
    //   217	219	217	finally
    //   48	204	243	java/lang/Exception
    //   217	243	243	java/lang/Exception
    //   48	204	269	finally
    //   217	271	269	finally
  }
  
  private static void maybeCloseQuietly(Closeable closeable)
  {
    if (closeable != null) {
      try
      {
        closeable.close();
      }
      catch (Exception ignore) {}
    }
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.ExclusiveFileAccessManager
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.net.URI;

public class WrapperConfiguration
{
  private URI distribution;
  private String distributionBase = "GRADLE_USER_HOME";
  private String distributionPath = "wrapper/dists";
  private String zipBase = "GRADLE_USER_HOME";
  private String zipPath = "wrapper/dists";
  
  public URI getDistribution()
  {
    return distribution;
  }
  
  public void setDistribution(URI distribution)
  {
    this.distribution = distribution;
  }
  
  public String getDistributionBase()
  {
    return distributionBase;
  }
  
  public void setDistributionBase(String distributionBase)
  {
    this.distributionBase = distributionBase;
  }
  
  public String getDistributionPath()
  {
    return distributionPath;
  }
  
  public void setDistributionPath(String distributionPath)
  {
    this.distributionPath = distributionPath;
  }
  
  public String getZipBase()
  {
    return zipBase;
  }
  
  public void setZipBase(String zipBase)
  {
    this.zipBase = zipBase;
  }
  
  public String getZipPath()
  {
    return zipPath;
  }
  
  public void setZipPath(String zipPath)
  {
    this.zipPath = zipPath;
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.WrapperConfiguration
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SystemPropertiesHandler
{
  public static Map<String, String> getSystemProperties(File propertiesFile)
  {
    Map<String, String> propertyMap = new HashMap();
    if (!propertiesFile.isFile()) {
      return propertyMap;
    }
    Properties properties = new Properties();
    try
    {
      FileInputStream inStream = new FileInputStream(propertiesFile);
      try
      {
        properties.load(inStream);
      }
      finally
      {
        inStream.close();
      }
    }
    catch (IOException e)
    {
      throw new RuntimeException("Error when loading properties file=" + propertiesFile, e);
    }
    Pattern pattern = Pattern.compile("systemProp\\.(.*)");
    for (Object argument : properties.keySet())
    {
      Matcher matcher = pattern.matcher(argument.toString());
      if (matcher.find())
      {
        String key = matcher.group(1);
        if (key.length() > 0) {
          propertyMap.put(key, properties.get(argument).toString());
        }
      }
    }
    return propertyMap;
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.SystemPropertiesHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.File;
import java.math.BigInteger;
import java.net.URI;
import java.security.MessageDigest;

public class PathAssembler
{
  public static final String GRADLE_USER_HOME_STRING = "GRADLE_USER_HOME";
  public static final String PROJECT_STRING = "PROJECT";
  private File gradleUserHome;
  
  public PathAssembler() {}
  
  public PathAssembler(File gradleUserHome)
  {
    this.gradleUserHome = gradleUserHome;
  }
  
  public LocalDistribution getDistribution(WrapperConfiguration configuration)
  {
    String baseName = getDistName(configuration.getDistribution());
    String distName = removeExtension(baseName);
    String rootDirName = rootDirName(distName, configuration);
    File distDir = new File(getBaseDir(configuration.getDistributionBase()), configuration.getDistributionPath() + "/" + rootDirName);
    File distZip = new File(getBaseDir(configuration.getZipBase()), configuration.getZipPath() + "/" + rootDirName + "/" + baseName);
    return new LocalDistribution(distDir, distZip);
  }
  
  private String rootDirName(String distName, WrapperConfiguration configuration)
  {
    String urlHash = getMd5Hash(configuration.getDistribution().toString());
    return String.format("%s/%s", new Object[] { distName, urlHash });
  }
  
  private String getMd5Hash(String string)
  {
    try
    {
      MessageDigest messageDigest = MessageDigest.getInstance("MD5");
      byte[] bytes = string.getBytes();
      messageDigest.update(bytes);
      return new BigInteger(1, messageDigest.digest()).toString(32);
    }
    catch (Exception e)
    {
      throw new RuntimeException("Could not hash input string.", e);
    }
  }
  
  private String removeExtension(String name)
  {
    int p = name.lastIndexOf(".");
    if (p < 0) {
      return name;
    }
    return name.substring(0, p);
  }
  
  private String getDistName(URI distUrl)
  {
    String path = distUrl.getPath();
    int p = path.lastIndexOf("/");
    if (p < 0) {
      return path;
    }
    return path.substring(p + 1);
  }
  
  private File getBaseDir(String base)
  {
    if (base.equals("GRADLE_USER_HOME")) {
      return gradleUserHome;
    }
    if (base.equals("PROJECT")) {
      return new File(System.getProperty("user.dir"));
    }
    throw new RuntimeException("Base: " + base + " is unknown");
  }
  
  public class LocalDistribution
  {
    private final File distZip;
    private final File distDir;
    
    public LocalDistribution(File distDir, File distZip)
    {
      this.distDir = distDir;
      this.distZip = distZip;
    }
    
    public File getDistributionDir()
    {
      return distDir;
    }
    
    public File getZipFile()
    {
      return distZip;
    }
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.PathAssembler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Install
{
  public static final String DEFAULT_DISTRIBUTION_PATH = "wrapper/dists";
  private final IDownload download;
  private final PathAssembler pathAssembler;
  private final ExclusiveFileAccessManager exclusiveFileAccessManager = new ExclusiveFileAccessManager(120000, 200);
  
  public Install(IDownload download, PathAssembler pathAssembler)
  {
    this.download = download;
    this.pathAssembler = pathAssembler;
  }
  
  public File createDist(WrapperConfiguration configuration)
    throws Exception
  {
    final URI distributionUrl = configuration.getDistribution();
    
    PathAssembler.LocalDistribution localDistribution = pathAssembler.getDistribution(configuration);
    final File distDir = localDistribution.getDistributionDir();
    final File localZipFile = localDistribution.getZipFile();
    
    (File)exclusiveFileAccessManager.access(localZipFile, new Callable()
    {
      public File call()
        throws Exception
      {
        File markerFile = new File(localZipFile.getParentFile(), localZipFile.getName() + ".ok");
        if ((distDir.isDirectory()) && (markerFile.isFile())) {
          return Install.this.getDistributionRoot(distDir, distDir.getAbsolutePath());
        }
        boolean needsDownload = !localZipFile.isFile();
        if (needsDownload)
        {
          File tmpZipFile = new File(localZipFile.getParentFile(), localZipFile.getName() + ".part");
          tmpZipFile.delete();
          System.out.println("Downloading " + distributionUrl);
          download.download(distributionUrl, tmpZipFile);
          tmpZipFile.renameTo(localZipFile);
        }
        List<File> topLevelDirs = Install.this.listDirs(distDir);
        for (File dir : topLevelDirs)
        {
          System.out.println("Deleting directory " + dir.getAbsolutePath());
          Install.this.deleteDir(dir);
        }
        System.out.println("Unzipping " + localZipFile.getAbsolutePath() + " to " + distDir.getAbsolutePath());
        Install.this.unzip(localZipFile, distDir);
        
        File root = Install.this.getDistributionRoot(distDir, distributionUrl.toString());
        Install.this.setExecutablePermissions(root);
        markerFile.createNewFile();
        
        return root;
      }
    });
  }
  
  private File getDistributionRoot(File distDir, String distributionDescription)
  {
    List<File> dirs = listDirs(distDir);
    if (dirs.isEmpty()) {
      throw new RuntimeException(String.format("Gradle distribution '%s' does not contain any directories. Expected to find exactly 1 directory.", new Object[] { distributionDescription }));
    }
    if (dirs.size() != 1) {
      throw new RuntimeException(String.format("Gradle distribution '%s' contains too many directories. Expected to find exactly 1 directory.", new Object[] { distributionDescription }));
    }
    return (File)dirs.get(0);
  }
  
  private List<File> listDirs(File distDir)
  {
    List<File> dirs = new ArrayList();
    if (distDir.exists()) {
      for (File file : distDir.listFiles()) {
        if (file.isDirectory()) {
          dirs.add(file);
        }
      }
    }
    return dirs;
  }
  
  private void setExecutablePermissions(File gradleHome)
  {
    if (isWindows()) {
      return;
    }
    File gradleCommand = new File(gradleHome, "bin/gradle");
    String errorMessage = null;
    try
    {
      ProcessBuilder pb = new ProcessBuilder(new String[] { "chmod", "755", gradleCommand.getCanonicalPath() });
      Process p = pb.start();
      if (p.waitFor() == 0)
      {
        System.out.println("Set executable permissions for: " + gradleCommand.getAbsolutePath());
      }
      else
      {
        BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
        Formatter stdout = new Formatter();
        String line;
        while ((line = is.readLine()) != null) {
          stdout.format("%s%n", new Object[] { line });
        }
        errorMessage = stdout.toString();
      }
    }
    catch (IOException e)
    {
      errorMessage = e.getMessage();
    }
    catch (InterruptedException e)
    {
      errorMessage = e.getMessage();
    }
    if (errorMessage != null)
    {
      System.out.println("Could not set executable permissions for: " + gradleCommand.getAbsolutePath());
      System.out.println("Please do this manually if you want to use the Gradle UI.");
    }
  }
  
  private boolean isWindows()
  {
    String osName = System.getProperty("os.name").toLowerCase(Locale.US);
    if (osName.indexOf("windows") > -1) {
      return true;
    }
    return false;
  }
  
  private boolean deleteDir(File dir)
  {
    if (dir.isDirectory())
    {
      String[] children = dir.list();
      for (int i = 0; i < children.length; i++)
      {
        boolean success = deleteDir(new File(dir, children[i]));
        if (!success) {
          return false;
        }
      }
    }
    return dir.delete();
  }
  
  private void unzip(File zip, File dest)
    throws IOException
  {
    ZipFile zipFile = new ZipFile(zip);
    try
    {
      Enumeration entries = zipFile.entries();
      while (entries.hasMoreElements())
      {
        ZipEntry entry = (ZipEntry)entries.nextElement();
        if (entry.isDirectory())
        {
          new File(dest, entry.getName()).mkdirs();
        }
        else
        {
          OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(new File(dest, entry.getName())));
          try
          {
            copyInputStream(zipFile.getInputStream(entry), outputStream);
          }
          finally {}
        }
      }
    }
    finally
    {
      zipFile.close();
    }
  }
  
  private void copyInputStream(InputStream in, OutputStream out)
    throws IOException
  {
    byte[] buffer = new byte['?'];
    int len;
    while ((len = in.read(buffer)) >= 0) {
      out.write(buffer, 0, len);
    }
    in.close();
    out.close();
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.Install
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.File;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;

public class BootstrapMainStarter
{
  public void start(String[] args, File gradleHome)
    throws Exception
  {
    File gradleJar = findLauncherJar(gradleHome);
    URLClassLoader contextClassLoader = new URLClassLoader(new URL[] { gradleJar.toURI().toURL() }, ClassLoader.getSystemClassLoader().getParent());
    Thread.currentThread().setContextClassLoader(contextClassLoader);
    Class<?> mainClass = contextClassLoader.loadClass("org.gradle.launcher.GradleMain");
    Method mainMethod = mainClass.getMethod("main", new Class[] { String[].class });
    mainMethod.invoke(null, new Object[] { args });
  }
  
  private File findLauncherJar(File gradleHome)
  {
    for (File file : new File(gradleHome, "lib").listFiles()) {
      if (file.getName().matches("gradle-launcher-.*\\.jar")) {
        return file;
      }
    }
    throw new RuntimeException(String.format("Could not locate the Gradle launcher JAR in Gradle distribution '%s'.", new Object[] { gradleHome }));
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.BootstrapMainStarter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Formatter;
import java.util.Properties;

public class WrapperExecutor
{
  public static final String DISTRIBUTION_URL_PROPERTY = "distributionUrl";
  public static final String DISTRIBUTION_BASE_PROPERTY = "distributionBase";
  public static final String ZIP_STORE_BASE_PROPERTY = "zipStoreBase";
  public static final String DISTRIBUTION_PATH_PROPERTY = "distributionPath";
  public static final String ZIP_STORE_PATH_PROPERTY = "zipStorePath";
  private final Properties properties;
  private final File propertiesFile;
  private final Appendable warningOutput;
  private final WrapperConfiguration config = new WrapperConfiguration();
  
  public static WrapperExecutor forProjectDirectory(File projectDir, Appendable warningOutput)
  {
    return new WrapperExecutor(new File(projectDir, "gradle/wrapper/gradle-wrapper.properties"), new Properties(), warningOutput);
  }
  
  public static WrapperExecutor forWrapperPropertiesFile(File propertiesFile, Appendable warningOutput)
  {
    if (!propertiesFile.exists()) {
      throw new RuntimeException(String.format("Wrapper properties file '%s' does not exist.", new Object[] { propertiesFile }));
    }
    return new WrapperExecutor(propertiesFile, new Properties(), warningOutput);
  }
  
  WrapperExecutor(File propertiesFile, Properties properties, Appendable warningOutput)
  {
    this.properties = properties;
    this.propertiesFile = propertiesFile;
    this.warningOutput = warningOutput;
    if (propertiesFile.exists()) {
      try
      {
        loadProperties(propertiesFile, properties);
        config.setDistribution(prepareDistributionUri());
        config.setDistributionBase(getProperty("distributionBase", config.getDistributionBase()));
        config.setDistributionPath(getProperty("distributionPath", config.getDistributionPath()));
        config.setZipBase(getProperty("zipStoreBase", config.getZipBase()));
        config.setZipPath(getProperty("zipStorePath", config.getZipPath()));
      }
      catch (Exception e)
      {
        throw new RuntimeException(String.format("Could not load wrapper properties from '%s'.", new Object[] { propertiesFile }), e);
      }
    }
  }
  
  private URI prepareDistributionUri()
    throws URISyntaxException
  {
    URI source = readDistroUrl();
    if (source.getScheme() == null) {
      return new File(propertiesFile.getParentFile(), source.getSchemeSpecificPart()).toURI();
    }
    return source;
  }
  
  private URI readDistroUrl()
    throws URISyntaxException
  {
    if (properties.getProperty("distributionUrl") != null) {
      return new URI(getProperty("distributionUrl"));
    }
    return readDistroUrlDeprecatedWay();
  }
  
  private URI readDistroUrlDeprecatedWay()
    throws URISyntaxException
  {
    String distroUrl = null;
    try
    {
      distroUrl = getProperty("urlRoot") + "/" + getProperty("distributionName") + "-" + getProperty("distributionVersion") + "-" + getProperty("distributionClassifier") + ".zip";
      
      Formatter formatter = new Formatter();
      formatter.format("Wrapper properties file '%s' contains deprecated entries 'urlRoot', 'distributionName', 'distributionVersion' and 'distributionClassifier'. These will be removed soon. Please use '%s' instead.%n", new Object[] { propertiesFile, "distributionUrl" });
      warningOutput.append(formatter.toString());
    }
    catch (Exception e)
    {
      reportMissingProperty("distributionUrl");
    }
    return new URI(distroUrl);
  }
  
  private static void loadProperties(File propertiesFile, Properties properties)
    throws IOException
  {
    InputStream inStream = new FileInputStream(propertiesFile);
    try
    {
      properties.load(inStream);
    }
    finally
    {
      inStream.close();
    }
  }
  
  public URI getDistribution()
  {
    return config.getDistribution();
  }
  
  public WrapperConfiguration getConfiguration()
  {
    return config;
  }
  
  public void execute(String[] args, Install install, BootstrapMainStarter bootstrapMainStarter)
    throws Exception
  {
    File gradleHome = install.createDist(config);
    bootstrapMainStarter.start(args, gradleHome);
  }
  
  private String getProperty(String propertyName)
  {
    return getProperty(propertyName, null);
  }
  
  private String getProperty(String propertyName, String defaultValue)
  {
    String value = properties.getProperty(propertyName);
    if (value != null) {
      return value;
    }
    if (defaultValue != null) {
      return defaultValue;
    }
    return reportMissingProperty(propertyName);
  }
  
  private String reportMissingProperty(String propertyName)
  {
    throw new RuntimeException(String.format("No value with key '%s' specified in wrapper properties file '%s'.", new Object[] { propertyName, propertiesFile }));
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.WrapperExecutor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.Map;
import java.util.Properties;
import org.gradle.cli.CommandLineParser;
import org.gradle.cli.SystemPropertiesCommandLineConverter;

public class GradleWrapperMain
{
  public static final String DEFAULT_GRADLE_USER_HOME = System.getProperty("user.home") + "/.gradle";
  public static final String GRADLE_USER_HOME_PROPERTY_KEY = "gradle.user.home";
  public static final String GRADLE_USER_HOME_ENV_KEY = "GRADLE_USER_HOME";
  
  public static void main(String[] args)
    throws Exception
  {
    File wrapperJar = wrapperJar();
    File propertiesFile = wrapperProperties(wrapperJar);
    File rootDir = rootDir(wrapperJar);
    
    Properties systemProperties = System.getProperties();
    systemProperties.putAll(parseSystemPropertiesFromArgs(args));
    
    addSystemProperties(rootDir);
    
    WrapperExecutor wrapperExecutor = WrapperExecutor.forWrapperPropertiesFile(propertiesFile, System.out);
    wrapperExecutor.execute(args, new Install(new Download("gradlew", wrapperVersion()), new PathAssembler(gradleUserHome())), new BootstrapMainStarter());
  }
  
  private static Map<String, String> parseSystemPropertiesFromArgs(String[] args)
  {
    SystemPropertiesCommandLineConverter converter = new SystemPropertiesCommandLineConverter();
    CommandLineParser commandLineParser = new CommandLineParser();
    converter.configure(commandLineParser);
    commandLineParser.allowUnknownOptions();
    return (Map)converter.convert(commandLineParser.parse(args));
  }
  
  private static void addSystemProperties(File rootDir)
  {
    System.getProperties().putAll(SystemPropertiesHandler.getSystemProperties(new File(gradleUserHome(), "gradle.properties")));
    System.getProperties().putAll(SystemPropertiesHandler.getSystemProperties(new File(rootDir, "gradle.properties")));
  }
  
  private static File rootDir(File wrapperJar)
  {
    return wrapperJar.getParentFile().getParentFile().getParentFile();
  }
  
  private static File wrapperProperties(File wrapperJar)
  {
    return new File(wrapperJar.getParent(), wrapperJar.getName().replaceFirst("\\.jar$", ".properties"));
  }
  
  private static File wrapperJar()
  {
    URI location;
    try
    {
      location = GradleWrapperMain.class.getProtectionDomain().getCodeSource().getLocation().toURI();
    }
    catch (URISyntaxException e)
    {
      throw new RuntimeException(e);
    }
    if (!location.getScheme().equals("file")) {
      throw new RuntimeException(String.format("Cannot determine classpath for wrapper Jar from codebase '%s'.", new Object[] { location }));
    }
    return new File(location.getPath());
  }
  
  /* Error */
  static String wrapperVersion()
  {
    // Byte code:
    //   0: ldc_w 43
    //   3: ldc 60
    //   5: invokevirtual 61	java/lang/Class:getResourceAsStream	(Ljava/lang/String;)Ljava/io/InputStream;
    //   8: astore_0
    //   9: aload_0
    //   10: ifnonnull +13 -> 23
    //   13: new 49	java/lang/RuntimeException
    //   16: dup
    //   17: ldc 62
    //   19: invokespecial 57	java/lang/RuntimeException:<init>	(Ljava/lang/String;)V
    //   22: athrow
    //   23: new 63	java/util/Properties
    //   26: dup
    //   27: invokespecial 64	java/util/Properties:<init>	()V
    //   30: astore_1
    //   31: aload_1
    //   32: aload_0
    //   33: invokevirtual 65	java/util/Properties:load	(Ljava/io/InputStream;)V
    //   36: aload_1
    //   37: ldc 66
    //   39: invokevirtual 67	java/util/Properties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
    //   42: astore_2
    //   43: aload_2
    //   44: ifnonnull +13 -> 57
    //   47: new 49	java/lang/RuntimeException
    //   50: dup
    //   51: ldc 68
    //   53: invokespecial 57	java/lang/RuntimeException:<init>	(Ljava/lang/String;)V
    //   56: athrow
    //   57: aload_2
    //   58: astore_3
    //   59: aload_0
    //   60: invokevirtual 69	java/io/InputStream:close	()V
    //   63: aload_3
    //   64: areturn
    //   65: astore 4
    //   67: aload_0
    //   68: invokevirtual 69	java/io/InputStream:close	()V
    //   71: aload 4
    //   73: athrow
    //   74: astore_0
    //   75: new 49	java/lang/RuntimeException
    //   78: dup
    //   79: ldc 71
    //   81: aload_0
    //   82: invokespecial 72	java/lang/RuntimeException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   85: athrow
    // Line number table:
    //   Java source line #90	-> byte code offset #0
    //   Java source line #91	-> byte code offset #9
    //   Java source line #92	-> byte code offset #13
    //   Java source line #94	-> byte code offset #23
    //   Java source line #96	-> byte code offset #31
    //   Java source line #97	-> byte code offset #36
    //   Java source line #98	-> byte code offset #43
    //   Java source line #99	-> byte code offset #47
    //   Java source line #101	-> byte code offset #57
    //   Java source line #103	-> byte code offset #59
    //   Java source line #105	-> byte code offset #74
    //   Java source line #106	-> byte code offset #75
    // Local variable table:
    //   start	length	slot	name	signature
    //   8	60	0	resourceAsStream	java.io.InputStream
    //   74	8	0	e	Exception
    //   30	7	1	buildReceipt	Properties
    //   42	16	2	versionNumber	String
    //   65	7	4	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   31	59	65	finally
    //   65	67	65	finally
    //   0	63	74	java/lang/Exception
    //   65	74	74	java/lang/Exception
  }
  
  private static File gradleUserHome()
  {
    String gradleUserHome = System.getProperty("gradle.user.home");
    if (gradleUserHome != null) {
      return new File(gradleUserHome);
    }
    if ((gradleUserHome = System.getenv("GRADLE_USER_HOME")) != null) {
      return new File(gradleUserHome);
    }
    return new File(DEFAULT_GRADLE_USER_HOME);
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.GradleWrapperMain
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.File;
import java.io.PrintStream;
import java.net.URI;
import java.util.List;
import java.util.concurrent.Callable;

class Install$1
  implements Callable<File>
{
  Install$1(Install paramInstall, File paramFile1, File paramFile2, URI paramURI) {}
  
  public File call()
    throws Exception
  {
    File markerFile = new File(val$localZipFile.getParentFile(), val$localZipFile.getName() + ".ok");
    if ((val$distDir.isDirectory()) && (markerFile.isFile())) {
      return Install.access$000(this$0, val$distDir, val$distDir.getAbsolutePath());
    }
    boolean needsDownload = !val$localZipFile.isFile();
    if (needsDownload)
    {
      File tmpZipFile = new File(val$localZipFile.getParentFile(), val$localZipFile.getName() + ".part");
      tmpZipFile.delete();
      System.out.println("Downloading " + val$distributionUrl);
      Install.access$100(this$0).download(val$distributionUrl, tmpZipFile);
      tmpZipFile.renameTo(val$localZipFile);
    }
    List<File> topLevelDirs = Install.access$200(this$0, val$distDir);
    for (File dir : topLevelDirs)
    {
      System.out.println("Deleting directory " + dir.getAbsolutePath());
      Install.access$300(this$0, dir);
    }
    System.out.println("Unzipping " + val$localZipFile.getAbsolutePath() + " to " + val$distDir.getAbsolutePath());
    Install.access$400(this$0, val$localZipFile, val$distDir);
    
    File root = Install.access$000(this$0, val$distDir, val$distributionUrl.toString());
    Install.access$500(this$0, root);
    markerFile.createNewFile();
    
    return root;
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.Install.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.File;

public class PathAssembler$LocalDistribution
{
  private final File distZip;
  private final File distDir;
  
  public PathAssembler$LocalDistribution(PathAssembler paramPathAssembler, File distDir, File distZip)
  {
    this.distDir = distDir;
    this.distZip = distZip;
  }
  
  public File getDistributionDir()
  {
    return distDir;
  }
  
  public File getZipFile()
  {
    return distZip;
  }
}

/* Location:
 * Qualified Name:     org.gradle.wrapper.PathAssembler.LocalDistribution
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.gradle.wrapper;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;

public class Download
  implements IDownload
{
  private static final int PROGRESS_CHUNK = 20000;
  private static final int BUFFER_SIZE = 10000;
  private final String applicationName;
  private final String applicationVersion;
  
  public Download(String applicationName, String applicationVersion)
  {
    this.applicationName = applicationName;
    this.applicationVersion = applicationVersion;
    configureProxyAuthentication();
  }
  
  private void configureProxyAuthentication()
  {
    if (System.getProperty("http.proxyUser") != null) {
      Authenticator.setDefault(new SystemPropertiesProxyAuthenticator(null));
    }
  }
  
  public void download(URI address, File destination)
    throws Exception
  {
    destination.getParentFile().mkdirs();
    downloadInternal(address, destination);
  }
  
  private void downloadInternal(URI address, File destination)
    throws Exception
  {
    OutputStream out = null;
    
    InputStream in = null;
    try
    {
      URL url = address.toURL();
      out = new BufferedOutputStream(new FileOutputStream(destination));
      URLConnection conn = url.openConnection();
      String userAgentValue = calculateUserAgent();
      conn.setRequestProperty("User-Agent", userAgentValue);
      in = conn.getInputStream();
      byte[] buffer = new byte['?'];
      
      long progressCounter = 0L;
      int numRead;
      while ((numRead = in.read(buffer)) != -1)
      {
        progressCounter += numRead;
        if (progressCounter / 20000L > 0L)
        {
          System.out.print(".");
          progressCounter -= 20000L;
        }
        out.write(buffer, 0, numRead);
      }
    }
    finally
    {
      System.out.println("");
      if (in != null) {
        in.close();
      }
      if (out != null) {
        out.close();
      }
    }
  }
  
  private String calculateUserAgent()
  {
    String appVersion = applicationVersion;
    
    String javaVe
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd