diff --git a/bin/as.sh b/bin/as.sh index a053e20aa..c4846a555 100755 --- a/bin/as.sh +++ b/bin/as.sh @@ -42,7 +42,7 @@ SESSION_TIMEOUT=300 USE_VERSION= # maven repo to download arthas -REPO_MIRROR="center" +REPO_MIRROR= # use http to download arthas USE_HTTP=false @@ -580,6 +580,13 @@ parse_arguments() fi fi + if [ -z ${REPO_MIRROR} ]; then + REPO_MIRROR="center" + # if timezone is +0800, set REPO_MIRROR to aliyun + if [[ -x "$(command -v date)" ]] && [[ $(date +%z) == "+0800" ]]; then + REPO_MIRROR="aliyun" + fi + fi # check pid if [ -z ${TARGET_PID} ] && [ ${BATCH_MODE} = false ]; then diff --git a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java index ad5e89d1d..62efe532b 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java +++ b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java @@ -11,6 +11,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.TimeZone; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.InputMismatchException; @@ -88,9 +90,9 @@ public class Bootstrap { private boolean versions; /** - * download from maven center repository by default + * download from maven repository. if timezone is +0800, default value is 'aliyun', else is 'center'. */ - private String repoMirror = "center"; + private String repoMirror; /** * enforce use http to download arthas. default use https @@ -226,6 +228,15 @@ public class Bootstrap { System.exit(0); } + if (bootstrap.getRepoMirror() == null || bootstrap.getRepoMirror().trim().isEmpty()) { + bootstrap.setRepoMirror("center"); + // if timezone is +0800, default repo mirror is aliyun + if (TimeUnit.MILLISECONDS.toHours(TimeZone.getDefault().getOffset(System.currentTimeMillis())) == 8) { + bootstrap.setRepoMirror("aliyun"); + } + } + AnsiLog.debug("Repo mirror:" + bootstrap.getRepoMirror()); + if (bootstrap.isVersions()) { if (mavenMetaData == null) { mavenMetaData = DownloadUtils.readMavenMetaData(bootstrap.getRepoMirror(), bootstrap.isuseHttp());