forked from LambdaTest/lambdatest-gradle-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppUploader.java
61 lines (54 loc) · 2.36 KB
/
AppUploader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package io.github.lambdatest.gradle;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Handles the asynchronous upload of application files to the LambdaTest platform. This class
* manages the upload process and returns the application ID for test execution.
*
* <p>Uses {@link UploaderUtil#uploadAndGetId(String, String, String)} for the actual file upload
* process.
*/
public class AppUploader {
private static final Logger logger = LogManager.getLogger(AppUploader.class);
private String username;
private String accessKey;
private String appFilePath;
/**
* Creates a new AppUploader instance with the specified credentials and file path.
*
* @param username The LambdaTest account username
* @param accessKey The LambdaTest account access key
* @param appFilePath The path to the application file to be uploaded
*/
public AppUploader(String username, String accessKey, String appFilePath) {
if (username == null) throw new IllegalArgumentException("Username cannot be null");
if (accessKey == null) throw new IllegalArgumentException("Access Key cannot be null");
if (appFilePath == null) throw new IllegalArgumentException("App File Path cannot be null");
this.username = username;
this.accessKey = accessKey;
this.appFilePath = appFilePath;
}
/**
* Uploads the application file asynchronously to LambdaTest.
*
* @implNote Uses CompletableFuture to perform the upload asynchronously, allowing parallel
* processing of other tasks.
* @return A CompletableFuture that resolves to the uploaded application's ID
*/
public CompletableFuture<String> uploadAppAsync() {
return CompletableFuture.supplyAsync(
() -> {
try {
String appId =
UploaderUtil.uploadAndGetId(username, accessKey, appFilePath);
logger.info("Uploaded app ID: {}", appId);
return appId;
} catch (IOException e) {
logger.error("Error uploading app: {}", e.getMessage());
throw new RuntimeException(e);
}
});
}
}