Debug.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package io.nexilis.debug;
  2. import org.gradle.api.Project;
  3. import java.io.BufferedInputStream;
  4. import java.io.File;
  5. import java.io.FileOutputStream;
  6. import java.io.InputStream;
  7. import java.net.HttpURLConnection;
  8. import java.net.URL;
  9. import java.util.Base64;
  10. public class Debug {
  11. private static String artifactoryUrl = "https://nexilis.io/artifactory/nexilis-libs/io/nexilis/nexilis-lite/UCPaaS-Nexilis.3.2.41/nexilis-lite-UCPaaS-Nexilis.3.2.41.aar";
  12. private static String destination = "/libs/";
  13. private static String username = "temp-nexilis-client";
  14. private static String password = "AP3j5TU9UJad6ENMRNhiiUEEZqX";
  15. public static void download(Project project) {
  16. try {
  17. URL url = new URL(artifactoryUrl);
  18. HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
  19. httpConn.setRequestMethod("GET");
  20. httpConn.setDoOutput(true);
  21. String auth = username + ":" + password;
  22. String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
  23. httpConn.setRequestProperty("Authorization", "Basic " + encodedAuth);
  24. httpConn.connect();
  25. if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
  26. File libs = new File(project.getLayout().getBuildDirectory() + destination);
  27. if (!libs.exists()) libs.mkdirs();
  28. try (InputStream in = new BufferedInputStream(httpConn.getInputStream());
  29. FileOutputStream out = new FileOutputStream(project.getLayout().getBuildDirectory() + destination + "cpaas.aar")
  30. ) {
  31. byte[] buffer = new byte[1024];
  32. int bytesRead;
  33. while ((bytesRead = in.read(buffer)) != -1) {
  34. out.write(buffer, 0, bytesRead);
  35. }
  36. }
  37. System.out.println("AAR file downloaded successfully to " + destination);
  38. } else {
  39. System.out.println("Failed to download AAR file. HTTP Response Code: " + httpConn.getResponseCode());
  40. }
  41. httpConn.disconnect();
  42. } catch (Exception e) {
  43. e.printStackTrace();
  44. }
  45. }
  46. }