1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package io.nexilis.debug;
- import org.gradle.api.Project;
- import java.io.BufferedInputStream;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.Base64;
- public class Debug {
- 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";
- private static String destination = "/libs/";
- private static String username = "temp-nexilis-client";
- private static String password = "AP3j5TU9UJad6ENMRNhiiUEEZqX";
- public static void download(Project project) {
- try {
- URL url = new URL(artifactoryUrl);
- HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
- httpConn.setRequestMethod("GET");
- httpConn.setDoOutput(true);
- String auth = username + ":" + password;
- String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
- httpConn.setRequestProperty("Authorization", "Basic " + encodedAuth);
- httpConn.connect();
- if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
- File libs = new File(project.getLayout().getBuildDirectory() + destination);
- if (!libs.exists()) libs.mkdirs();
- try (InputStream in = new BufferedInputStream(httpConn.getInputStream());
- FileOutputStream out = new FileOutputStream(project.getLayout().getBuildDirectory() + destination + "cpaas.aar")
- ) {
- byte[] buffer = new byte[1024];
- int bytesRead;
- while ((bytesRead = in.read(buffer)) != -1) {
- out.write(buffer, 0, bytesRead);
- }
- }
- System.out.println("AAR file downloaded successfully to " + destination);
- } else {
- System.out.println("Failed to download AAR file. HTTP Response Code: " + httpConn.getResponseCode());
- }
- httpConn.disconnect();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
|