Skip to content

Commit

Permalink
Update Gradle plugin to add neededPermissions and deviceActions (#226)
Browse files Browse the repository at this point in the history
* Update Gradle plugin to add neededPermissions and deviceActions;
Upgrade plugin to 1.0.43;
  • Loading branch information
olivershen-wow committed Jan 16, 2023
1 parent 7b9ebdb commit 4d2061a
Show file tree
Hide file tree
Showing 15 changed files with 993 additions and 651 deletions.
3 changes: 2 additions & 1 deletion gradle_plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ext {
}

dependencies {
testImplementation 'org.mockito:mockito-core:3.12.4'
implementation "org.apache.commons:commons-lang3:3.4"
implementation gradleApi()
implementation "commons-io:commons-io:2.11.0"
Expand All @@ -34,7 +35,7 @@ dependencies {
}

// plugin publishing related
version = '1.0.41'
version = '1.0.45'
group = 'com.microsoft.hydralab'
// alter group to this when publish to local, in order to distinguish local version and gradle plugin portal version
//group = 'com.microsoft.hydralab.local'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.
package com.microsoft.hydralab

import com.microsoft.hydralab.entity.HydraLabAPIConfig
import com.microsoft.hydralab.utils.HydraLabClientUtils
import org.apache.commons.lang3.StringUtils
import org.gradle.api.Plugin
Expand Down Expand Up @@ -102,7 +103,7 @@ class ClientUtilsPlugin implements Plugin<Project> {
}
}

HydraLabClientUtils.HydraLabAPIConfig apiConfig = HydraLabClientUtils.HydraLabAPIConfig.defaultAPI()
HydraLabAPIConfig apiConfig = new HydraLabAPIConfig()

if (project.hasProperty('hydraLabAPISchema')) {
apiConfig.schema = project.hydraLabAPISchema
Expand Down Expand Up @@ -149,6 +150,13 @@ class ClientUtilsPlugin implements Plugin<Project> {
if (project.hasProperty('needClearData')) {
apiConfig.needClearData = Boolean.parseBoolean(project.needClearData)
}
if (project.hasProperty('neededPermissions')) {
apiConfig.neededPermissions = project.neededPermissions.split(", +")
}
if (project.hasProperty('deviceActions')) {
// add quotes back as quotes in gradle plugins will be replaced by blanks
apiConfig.deviceActionsStr = project.deviceActions.replace("\\", "\"")
}

requiredParamCheck(runningType, appPath, testAppPath, deviceIdentifier, runTimeOutSeconds, testSuiteName, apiConfig)

Expand All @@ -165,47 +173,47 @@ class ClientUtilsPlugin implements Plugin<Project> {
}
}

private void requiredParamCheck(String runningType, String appPath, String testAppPath, String deviceIdentifier, String runTimeOutSeconds, String testSuiteName, HydraLabClientUtils.HydraLabAPIConfig apiConfig) {
void requiredParamCheck(String runningType, String appPath, String testAppPath, String deviceIdentifier, String runTimeOutSeconds, String testSuiteName, HydraLabAPIConfig apiConfig) {
if (StringUtils.isBlank(runningType)
|| StringUtils.isBlank(appPath)
|| StringUtils.isBlank(apiConfig.pkgName)
|| StringUtils.isBlank(deviceIdentifier)
|| StringUtils.isBlank(runTimeOutSeconds)
|| StringUtils.isBlank(apiConfig.authToken)
) {
throw new Exception('Required params not provided! Make sure the following params are all provided correctly: authToken, appPath, pkgName, runningType, deviceIdentifier, runTimeOutSeconds.')
throw new IllegalArgumentException('Required params not provided! Make sure the following params are all provided correctly: authToken, appPath, pkgName, runningType, deviceIdentifier, runTimeOutSeconds.')
}

// running type specified params
switch (runningType) {
case "INSTRUMENTATION":
if (StringUtils.isBlank(testAppPath)) {
throw new Exception('Required param testAppPath not provided!')
throw new IllegalArgumentException('Required param testAppPath not provided!')
}
if (StringUtils.isBlank(apiConfig.testPkgName)) {
throw new Exception('Required param testPkgName not provided!')
throw new IllegalArgumentException('Required param testPkgName not provided!')
}
if (apiConfig.testScope != TestScope.PACKAGE && apiConfig.testScope != TestScope.CLASS) {
break
}
if (StringUtils.isBlank(testSuiteName)) {
throw new Exception('Required param testSuiteName not provided!')
throw new IllegalArgumentException('Required param testSuiteName not provided!')
}
break
case "APPIUM":
if (StringUtils.isBlank(testAppPath)) {
throw new Exception('Required param testAppPath not provided!')
throw new IllegalArgumentException('Required param testAppPath not provided!')
}
if (StringUtils.isBlank(testSuiteName)) {
throw new Exception('Required param testSuiteName not provided!')
throw new IllegalArgumentException('Required param testSuiteName not provided!')
}
break
case "APPIUM_CROSS":
if (StringUtils.isBlank(testAppPath)) {
throw new Exception('Required param testAppPath not provided!')
throw new IllegalArgumentException('Required param testAppPath not provided!')
}
if (StringUtils.isBlank(testSuiteName)) {
throw new Exception('Required param testSuiteName not provided!')
throw new IllegalArgumentException('Required param testSuiteName not provided!')
}
break
case "SMART":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.microsoft.hydralab.entity;

public class AttachmentInfo {
public String fileName;
public String filePath;
public String fileType;
public String loadType;
public String loadDir;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.microsoft.hydralab.entity;

import com.google.gson.JsonObject;
import java.util.Date;

public class BlobFileInfo {
public String fileId;
public String fileType;
public String fileName;
public String blobUrl;
public String blobPath;
public long fileLen;
public String md5;
public String loadDir;
public String loadType;
public JsonObject fileParser;
public Date createTime;
public Date updateTime;


public interface fileType {
String WINDOWS_APP = "WINAPP";
String COMMOM_FILE = "COMMON";
String AGENT_PACKAGE = "PACKAGE";
String APP_FILE = "APP";
String TEST_APP_FILE = "TEST_APP";
}

public interface loadType {
String CPOY = "COPY";
String UNZIP = "UNZIP";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.microsoft.hydralab.entity;

import java.util.List;

public class DeviceTestResult {
public String id;
public String deviceSerialNumber;
public String deviceName;
public String instrumentReportPath;
public String controlLogPath;
public String instrumentReportBlobUrl;
public String testXmlReportBlobUrl;
public String logcatBlobUrl;
public String testGifBlobUrl;

public List<BlobFileInfo> attachments;

public String crashStackId;
public String errorInProcess;

public String crashStack;

public int totalCount;
public int failCount;
public boolean success;
public long testStartTimeMillis;
public long testEndTimeMillis;

@Override
public String toString() {
return "{" +
"SN='" + deviceSerialNumber + '\'' +
", totalCase:" + totalCount +
", failCase:" + failCount +
", success:" + success +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.microsoft.hydralab.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

// todo: split into APIConfig/deviceConfig/testConfig
public class HydraLabAPIConfig {
public String schema = "https";
public String host = "";
public String contextPath = "";
public String authToken = "";
public boolean onlyAuthPost = true;
public String checkCenterVersionAPIPath = "/api/center/info";
public String checkCenterAliveAPIPath = "/api/center/isAlive";
public String getBlobSAS = "/api/package/getSAS";
public String uploadAPKAPIPath = "/api/package/add";
public String addAttachmentAPIPath = "/api/package/addAttachment";
public String generateAccessKeyAPIPath = "/api/deviceGroup/generate?deviceIdentifier=%s";
public String runTestAPIPath = "/api/test/task/run/";
public String testStatusAPIPath = "/api/test/task/";
public String cancelTestTaskAPIPath = "/api/test/task/cancel/%s?reason=%s";
public String testPortalTaskInfoPath = "/portal/index.html?redirectUrl=/info/task/";
public String testPortalTaskDeviceVideoPath = "/portal/index.html?redirectUrl=/info/videos/";
public String pkgName = "";
public String testPkgName = "";
public String groupTestType = "SINGLE";
public String pipelineLink = "";
public String frameworkType = "JUnit4";
public int maxStepCount = 100;
public int deviceTestCount = -1;
public boolean needUninstall = true;
public boolean needClearData = true;
public String teamName = "";
public String testRunnerName = "androidx.test.runner.AndroidJUnitRunner";
public String testScope = "";
public List<String> neededPermissions = new ArrayList<>();
public String deviceActionsStr = "";

public String getBlobSASUrl() {
return String.format(Locale.US, "%s://%s%s%s", schema, host, contextPath, getBlobSAS);
}

public String checkCenterAliveUrl() {
return String.format(Locale.US, "%s://%s%s%s", schema, host, contextPath, checkCenterAliveAPIPath);
}

public String getUploadUrl() {
return String.format(Locale.US, "%s://%s%s%s", schema, host, contextPath, uploadAPKAPIPath);
}

public String getAddAttachmentUrl() {
return String.format(Locale.US, "%s://%s%s%s", schema, host, contextPath, addAttachmentAPIPath);
}

public String getGenerateAccessKeyUrl() {
return String.format(Locale.US, "%s://%s%s%s", schema, host, contextPath, generateAccessKeyAPIPath);
}

public String getRunTestUrl() {
return String.format(Locale.US, "%s://%s%s%s", schema, host, contextPath, runTestAPIPath);
}

public String getTestStatusUrl(String testTaskId) {
return String.format(Locale.US, "%s://%s%s%s%s", schema, host, contextPath, testStatusAPIPath, testTaskId);
}

public String getCancelTestTaskUrl() {
return String.format(Locale.US, "%s://%s%s%s", schema, host, contextPath, cancelTestTaskAPIPath);
}

public String getTestReportUrl(String testTaskId) {
return String.format(Locale.US, "%s://%s%s%s%s", schema, host, contextPath, testPortalTaskInfoPath, testTaskId);
}

public String getDeviceTestVideoUrl(String id) {
return String.format(Locale.US, "%s://%s%s%s%s", schema, host, contextPath, testPortalTaskDeviceVideoPath, id);
}

@Override
public String toString() {
return "HydraLabAPIConfig:\n" +
"pkgName=" + pkgName + ",\n" +
"testPkgName=" + testPkgName + ",\n" +
"groupTestType=" + groupTestType + ",\n" +
"pipelineLink=" + pipelineLink + ",\n" +
"frameworkType=" + frameworkType + ",\n" +
"maxStepCount=" + maxStepCount + ",\n" +
"deviceTestCount=" + deviceTestCount + ",\n" +
"needUninstall=" + needUninstall + ",\n" +
"needClearData=" + needClearData + ",\n" +
"teamName=" + teamName + ",\n" +
"testRunnerName=" + testRunnerName + ",\n" +
"testScope=" + testScope + ",\n" +
"neededPermissions=" + (neededPermissions != null ? neededPermissions.toString() : "") + ",\n" +
"deviceActionsStr=" + deviceActionsStr;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.microsoft.hydralab.entity;

import java.util.Date;
import java.util.List;

public class TestTask {
public String id;
public List<DeviceTestResult> deviceTestResults;
public int testDevicesCount;
public Date startDate;
public Date endDate;
public int totalTestCount;
public int totalFailCount;
public String testSuite;
public String reportImagePath;
public String status;
public String testErrorMsg;
public String message;
public int retryTime;

@Override
public String toString() {
return "TestTask{" +
"id='" + id + '\'' +
", testDevicesCount=" + testDevicesCount +
", startDate=" + startDate +
", totalTestCount=" + totalTestCount +
", status='" + status + '\'' +
'}';
}

public interface TestStatus {
String RUNNING = "running";
String FINISHED = "finished";
String CANCELED = "canceled";
String EXCEPTION = "error";
String WAITING = "waiting";
}
}

0 comments on commit 4d2061a

Please sign in to comment.