From 138a47299dbe57fb99e5d59902e46f82e057ba79 Mon Sep 17 00:00:00 2001 From: TedaLIEz Date: Wed, 15 Mar 2023 11:14:23 +0800 Subject: [PATCH] feat: enable checkstyle && fix issues in entity/agent --- .../hydralab/agent/runner/smart/SmartTestUtil.java | 10 +++++----- .../agent/service/DeviceControlService.java | 2 +- .../agent/service/TestTaskEngineService.java | 2 +- common/build.gradle | 4 ++++ .../entity/agent/DeviceStateChangeRecord.java | 2 +- .../common/entity/agent/DeviceTaskControl.java | 13 +++++++++++-- .../hydralab/common/entity/agent/MobileDevice.java | 9 +++++++-- .../hydralab/common/entity/agent/Result.java | 1 + .../common/entity/agent/SmartTestParam.java | 13 +++++++------ quality/checkstyle-suppressions.xml | 11 +++++++++++ 10 files changed, 49 insertions(+), 18 deletions(-) diff --git a/agent/src/main/java/com/microsoft/hydralab/agent/runner/smart/SmartTestUtil.java b/agent/src/main/java/com/microsoft/hydralab/agent/runner/smart/SmartTestUtil.java index 614e057ba..a1949fa0f 100644 --- a/agent/src/main/java/com/microsoft/hydralab/agent/runner/smart/SmartTestUtil.java +++ b/agent/src/main/java/com/microsoft/hydralab/agent/runner/smart/SmartTestUtil.java @@ -80,11 +80,11 @@ public String runPYFunction(SmartTestParam smartTestParam, Logger logger) throws String[] runArgs = new String[7]; runArgs[0] = "python"; runArgs[1] = filePath; - runArgs[2] = smartTestParam.apkPath; - runArgs[3] = smartTestParam.deviceInfo; - runArgs[4] = smartTestParam.modelInfo; - runArgs[5] = smartTestParam.testSteps; - runArgs[6] = smartTestParam.stringTextFolder; + runArgs[2] = smartTestParam.getApkPath(); + runArgs[3] = smartTestParam.getDeviceInfo(); + runArgs[4] = smartTestParam.getModelInfo(); + runArgs[5] = smartTestParam.getTestSteps(); + runArgs[6] = smartTestParam.getStringTextFolder(); for (String tempArg : runArgs) { logger.info(tempArg); diff --git a/agent/src/main/java/com/microsoft/hydralab/agent/service/DeviceControlService.java b/agent/src/main/java/com/microsoft/hydralab/agent/service/DeviceControlService.java index 968ec0eed..8bd8a4848 100644 --- a/agent/src/main/java/com/microsoft/hydralab/agent/service/DeviceControlService.java +++ b/agent/src/main/java/com/microsoft/hydralab/agent/service/DeviceControlService.java @@ -91,7 +91,7 @@ private void captureDevicesScreenSync(Collection allDevices, boolean return; } - CountDownLatch countDownLatch = deviceTaskControl.countDownLatch; + CountDownLatch countDownLatch = deviceTaskControl.getCountDownLatch(); try { countDownLatch.await(); } catch (InterruptedException e) { diff --git a/agent/src/main/java/com/microsoft/hydralab/agent/service/TestTaskEngineService.java b/agent/src/main/java/com/microsoft/hydralab/agent/service/TestTaskEngineService.java index db13efad9..d45565b07 100644 --- a/agent/src/main/java/com/microsoft/hydralab/agent/service/TestTaskEngineService.java +++ b/agent/src/main/java/com/microsoft/hydralab/agent/service/TestTaskEngineService.java @@ -92,7 +92,7 @@ public boolean doTask(DeviceInfo deviceInfo, Logger logger) throws Exception { if (deviceTaskControl == null) { testTask.setTestDevicesCount(0); } else { - testTask.setTestDevicesCount(deviceTaskControl.devices.size()); + testTask.setTestDevicesCount(deviceTaskControl.getDevices().size()); } return testTask; } diff --git a/common/build.gradle b/common/build.gradle index 218af4917..4a63e7ad0 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -4,6 +4,8 @@ version = '0.9.5' sourceCompatibility = 11 targetCompatibility = 11 +apply from: "${project.rootDir}/quality/checkstyle.gradle" + def env = System.getProperty("env") ?: "dev" sourceSets { @@ -14,6 +16,8 @@ sourceSets { } } +classes.finalizedBy checkstyleMain + tasks.withType(JavaCompile) { options.encoding = "UTF-8" } diff --git a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/DeviceStateChangeRecord.java b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/DeviceStateChangeRecord.java index 692ad8b1a..8988cf3dd 100644 --- a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/DeviceStateChangeRecord.java +++ b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/DeviceStateChangeRecord.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -package com.microsoft.hydralab.common.entity.agent; +package com.microsoft.hydralab.common.entity.agent; import com.microsoft.hydralab.common.management.listener.MobileDeviceState; import lombok.AllArgsConstructor; diff --git a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/DeviceTaskControl.java b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/DeviceTaskControl.java index 675b0b700..6c95a8d89 100644 --- a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/DeviceTaskControl.java +++ b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/DeviceTaskControl.java @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. + package com.microsoft.hydralab.common.entity.agent; import com.microsoft.hydralab.common.entity.common.DeviceInfo; @@ -8,11 +9,19 @@ import java.util.concurrent.CountDownLatch; public class DeviceTaskControl { - public final CountDownLatch countDownLatch; - public final Set devices; + private final CountDownLatch countDownLatch; + private final Set devices; public DeviceTaskControl(CountDownLatch countDownLatch, Set devices) { this.countDownLatch = countDownLatch; this.devices = devices; } + + public CountDownLatch getCountDownLatch() { + return countDownLatch; + } + + public Set getDevices() { + return devices; + } } diff --git a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/MobileDevice.java b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/MobileDevice.java index c90df03e4..f32f79452 100644 --- a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/MobileDevice.java +++ b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/MobileDevice.java @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. + package com.microsoft.hydralab.common.entity.agent; import lombok.Data; @@ -33,8 +34,12 @@ public MobileDevice() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } MobileDevice that = (MobileDevice) o; return Objects.equals(serialNum, that.serialNum); } diff --git a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/Result.java b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/Result.java index eb3671ffb..a52169326 100644 --- a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/Result.java +++ b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/Result.java @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. + package com.microsoft.hydralab.common.entity.agent; import lombok.AllArgsConstructor; diff --git a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/SmartTestParam.java b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/SmartTestParam.java index 3a5248c43..771accf63 100644 --- a/common/src/main/java/com/microsoft/hydralab/common/entity/agent/SmartTestParam.java +++ b/common/src/main/java/com/microsoft/hydralab/common/entity/agent/SmartTestParam.java @@ -1,19 +1,20 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. + package com.microsoft.hydralab.common.entity.agent; import com.alibaba.fastjson.JSONObject; -import com.microsoft.hydralab.common.util.Const; import com.microsoft.hydralab.common.entity.common.DeviceInfo; +import com.microsoft.hydralab.common.util.Const; import lombok.Data; @Data public class SmartTestParam { - public String apkPath; - public String deviceInfo; - public String modelInfo; - public String testSteps; - public String stringTextFolder; + private String apkPath; + private String deviceInfo; + private String modelInfo; + private String testSteps; + private String stringTextFolder; public SmartTestParam(String apkPath, DeviceInfo deviceInfo, String sourceModelId, String targetModelId, int testSteps, String folderPath, String stringFolderPath) { JSONObject modelInfo = new JSONObject(); diff --git a/quality/checkstyle-suppressions.xml b/quality/checkstyle-suppressions.xml index 9d3f43144..1f75a7887 100644 --- a/quality/checkstyle-suppressions.xml +++ b/quality/checkstyle-suppressions.xml @@ -7,4 +7,15 @@ + + + + + + + + + + + \ No newline at end of file