Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyitao committed Nov 11, 2020
1 parent 66a4491 commit 70a775d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.daxiang</groupId>
<artifactId>agent</artifactId>
<version>0.7.8</version>
<version>0.7.9</version>
<packaging>jar</packaging>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/daxiang/action/MobileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.daxiang.core.action.annotation.Action;
import com.daxiang.core.action.annotation.Param;
import com.daxiang.core.mobile.MobileDevice;
import com.daxiang.utils.HttpUtil;
import com.daxiang.utils.FileUtil;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.WaitOptions;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void switchContext(@Param(possibleValues = "[{'value': 'NATIVE_APP', 'des
public void installApp(@Param(description = "app下载地址") String appDownloadUrl) throws IOException {
Assert.hasText(appDownloadUrl, "appDownloadUrl不能为空");

File app = HttpUtil.downloadFile(appDownloadUrl);
File app = FileUtil.downloadFile(appDownloadUrl);
try {
mobileDevice.installApp(app);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.daxiang.core.mobile.android.stf.Minitouch;
import com.daxiang.core.mobile.appium.AndroidNativePageSourceHandler;
import com.daxiang.core.mobile.appium.AppiumServer;
import com.daxiang.utils.HttpUtil;
import com.daxiang.utils.Terminal;
import com.daxiang.utils.UUIDUtil;
import io.appium.java_client.android.AndroidDriver;
Expand All @@ -33,6 +32,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermission;
import java.time.Duration;
Expand Down Expand Up @@ -136,7 +136,7 @@ public void installApp(File appFile) {
// 主要因为appium server无法在安装app时,响应其他请求,所以这里用ddmlib安装
AndroidUtil.installApk(iDevice, appFile.getAbsolutePath());
} catch (InstallException e) {
throw new RuntimeException(String.format("[%s]安装app失败", getId()), e);
throw new RuntimeException(String.format("[%s]安装app失败: %s", getId(), e.getMessage()), e);
} finally {
if (!scheduleService.isShutdown()) {
scheduleService.shutdown();
Expand Down Expand Up @@ -238,7 +238,7 @@ public synchronized String getChromedriverFilePath() {
if (!chromedriverFile.exists()) {
try {
log.info("[{}]download chromedriver from {}", getId(), downloadUrl);
HttpUtil.downloadFile(downloadUrl, chromedriverFile);
FileUtils.copyURLToFile(new URL(downloadUrl), chromedriverFile);

if (!Terminal.IS_WINDOWS) {
// 权限
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/daxiang/service/AndroidService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.daxiang.core.mobile.android.AndroidUtil;
import com.daxiang.core.mobile.android.IDeviceExecuteShellCommandException;
import com.daxiang.exception.AgentException;
import com.daxiang.utils.HttpUtil;
import com.daxiang.utils.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -48,9 +48,8 @@ public void stopAdbKit(String mobileId) {

public String aaptDumpBadging(String apkDownloadUrl) {
File apkFile = null;

try {
apkFile = HttpUtil.downloadFile(apkDownloadUrl);
apkFile = FileUtil.downloadFile(apkDownloadUrl);
return AndroidUtil.aaptDumpBadging(apkFile.getAbsolutePath());
} catch (IOException e) {
log.error(e.getMessage(), e);
Expand Down Expand Up @@ -89,4 +88,4 @@ public void setIme(String mobileId, String ime) {
throw new AgentException(e.getMessage());
}
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/daxiang/utils/FileUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.daxiang.utils;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
* Created by jiangyitao.
*/
public class FileUtil {

public static File downloadFile(String url) throws IOException {
File file = new File(UUIDUtil.getUUID());
FileUtils.copyURLToFile(new URL(url), file);
return file;
}
}
35 changes: 0 additions & 35 deletions src/main/java/com/daxiang/utils/HttpUtil.java

This file was deleted.

0 comments on commit 70a775d

Please sign in to comment.