mirror of
https://gitee.com/arthas/arthas.git
synced 2024-11-30 03:07:37 +08:00
change use-https to use-http; use http when under java 6. #278
This commit is contained in:
parent
96f505e83b
commit
422c240ebc
@ -18,13 +18,13 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.taobao.arthas.common.AnsiLog;
|
||||
import com.taobao.arthas.common.JavaVersionUtils;
|
||||
import com.taobao.arthas.common.SocketUtils;
|
||||
import com.taobao.middleware.cli.CLI;
|
||||
import com.taobao.middleware.cli.CommandLine;
|
||||
import com.taobao.middleware.cli.UsageMessageFormatter;
|
||||
import com.taobao.middleware.cli.annotations.Argument;
|
||||
import com.taobao.middleware.cli.annotations.CLIConfigurator;
|
||||
import com.taobao.middleware.cli.annotations.DefaultValue;
|
||||
import com.taobao.middleware.cli.annotations.Description;
|
||||
import com.taobao.middleware.cli.annotations.Name;
|
||||
import com.taobao.middleware.cli.annotations.Option;
|
||||
@ -77,7 +77,10 @@ public class Bootstrap {
|
||||
*/
|
||||
private String repoMirror = "center";
|
||||
|
||||
private boolean useHttps = true;
|
||||
/**
|
||||
* enforce use http to download arthas. default use https
|
||||
*/
|
||||
private boolean useHttp = false;
|
||||
|
||||
private boolean attachOnly = false;
|
||||
|
||||
@ -138,10 +141,10 @@ public class Bootstrap {
|
||||
this.repoMirror = repoMirror;
|
||||
}
|
||||
|
||||
@Option(longName = "use-https", flag = true)
|
||||
@Description("Use https to download, default true")
|
||||
public void setUseHttps(boolean useHttps) {
|
||||
this.useHttps = useHttps;
|
||||
@Option(longName = "use-http", flag = true)
|
||||
@Description("Enforce use http to download, default use https")
|
||||
public void setuseHttp(boolean useHttp) {
|
||||
this.useHttp = useHttp;
|
||||
}
|
||||
|
||||
@Option(longName = "attach-only", flag = true)
|
||||
@ -196,6 +199,11 @@ public class Bootstrap {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (JavaVersionUtils.isJava6()) {
|
||||
bootStrap.setuseHttp(true);
|
||||
AnsiLog.debug("Java version is 1.6, only support http, set useHttp to true.");
|
||||
}
|
||||
|
||||
// check telnet/http port
|
||||
int telnetPortPid = -1;
|
||||
int httpPortPid = -1;
|
||||
@ -291,7 +299,7 @@ public class Bootstrap {
|
||||
}
|
||||
|
||||
String remoteLastestVersion = DownloadUtils.getLastestVersion(bootStrap.getRepoMirror(),
|
||||
bootStrap.isUseHttps());
|
||||
bootStrap.isuseHttp());
|
||||
|
||||
boolean needDownload = false;
|
||||
if (localLastestVersion == null) {
|
||||
@ -314,7 +322,7 @@ public class Bootstrap {
|
||||
}
|
||||
if (needDownload) {
|
||||
// try to download arthas from remote server.
|
||||
DownloadUtils.downArthasPackaging(bootStrap.getRepoMirror(), bootStrap.isUseHttps(),
|
||||
DownloadUtils.downArthasPackaging(bootStrap.getRepoMirror(), bootStrap.isuseHttp(),
|
||||
remoteLastestVersion, arthasLibDir.getAbsolutePath());
|
||||
localLastestVersion = remoteLastestVersion;
|
||||
}
|
||||
@ -437,8 +445,8 @@ public class Bootstrap {
|
||||
return repoMirror;
|
||||
}
|
||||
|
||||
public boolean isUseHttps() {
|
||||
return useHttps;
|
||||
public boolean isuseHttp() {
|
||||
return useHttp;
|
||||
}
|
||||
|
||||
public String getTargetIp() {
|
||||
|
@ -56,8 +56,12 @@ public class DownloadUtils {
|
||||
NodeList nodeList = document.getDocumentElement().getElementsByTagName("release");
|
||||
|
||||
return nodeList.item(0).getTextContent();
|
||||
} catch (javax.net.ssl.SSLException e) {
|
||||
AnsiLog.error("TLS connect error, please try to use --use-http argument.");
|
||||
AnsiLog.error("URL: " + mavenMetaDataUrl);
|
||||
AnsiLog.error(e);
|
||||
} catch (Throwable t) {
|
||||
AnsiLog.debug("Can not read release version from: " + mavenMetaDataUrl);
|
||||
AnsiLog.error("Can not read release version from: " + mavenMetaDataUrl);
|
||||
AnsiLog.debug(t);
|
||||
} finally {
|
||||
IOUtils.close(inputStream);
|
||||
@ -65,18 +69,18 @@ public class DownloadUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getLastestVersion(String repoMirror, boolean https) {
|
||||
String repoUrl = getRepoUrl(repoMirror, https);
|
||||
public static String getLastestVersion(String repoMirror, boolean http) {
|
||||
String repoUrl = getRepoUrl(repoMirror, http);
|
||||
return readMavenReleaseVersion(MAVEN_METADATA_URL.replace("${REPO}", repoUrl));
|
||||
}
|
||||
|
||||
public static String getRepoUrl(String repoMirror, boolean https) {
|
||||
public static String getRepoUrl(String repoMirror, boolean http) {
|
||||
repoMirror = repoMirror.trim();
|
||||
String repoUrl = "";
|
||||
if (repoMirror.equals("center")) {
|
||||
repoUrl = "http://repo1.maven.org/maven2";
|
||||
repoUrl = "https://repo1.maven.org/maven2";
|
||||
} else if (repoMirror.equals("aliyun")) {
|
||||
repoUrl = "http://maven.aliyun.com/repository/public";
|
||||
repoUrl = "https://maven.aliyun.com/repository/public";
|
||||
} else {
|
||||
repoUrl = repoMirror;
|
||||
}
|
||||
@ -84,15 +88,15 @@ public class DownloadUtils {
|
||||
repoUrl = repoUrl.substring(0, repoUrl.length() - 1);
|
||||
}
|
||||
|
||||
if (https && repoUrl.startsWith("http")) {
|
||||
repoUrl = "https" + repoUrl.substring("http".length(), repoUrl.length());
|
||||
if (http && repoUrl.startsWith("https")) {
|
||||
repoUrl = "http" + repoUrl.substring("https".length(), repoUrl.length());
|
||||
}
|
||||
return repoUrl;
|
||||
}
|
||||
|
||||
public static void downArthasPackaging(String repoMirror, boolean https, String arthasVersion, String savePath)
|
||||
public static void downArthasPackaging(String repoMirror, boolean http, String arthasVersion, String savePath)
|
||||
throws ParserConfigurationException, SAXException, IOException {
|
||||
String repoUrl = getRepoUrl(repoMirror, https);
|
||||
String repoUrl = getRepoUrl(repoMirror, http);
|
||||
|
||||
File unzipDir = new File(savePath, arthasVersion + File.separator + "arthas");
|
||||
|
||||
@ -132,13 +136,17 @@ public class DownloadUtils {
|
||||
totalCount += count;
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastPrintTime > 3000) {
|
||||
AnsiLog.info("File size: {}, Downloaded size: {}", formatFileSize(fileSize),
|
||||
AnsiLog.info("File size: {}, Downloaded size: {}, Downloading ...", formatFileSize(fileSize),
|
||||
formatFileSize(totalCount));
|
||||
lastPrintTime = now;
|
||||
}
|
||||
|
||||
fout.write(data, 0, count);
|
||||
}
|
||||
} catch (javax.net.ssl.SSLException e) {
|
||||
AnsiLog.error("TLS connect error, please try to use --use-http argument.");
|
||||
AnsiLog.error("URL: " + urlString);
|
||||
AnsiLog.error(e);
|
||||
} finally {
|
||||
IOUtils.close(in);
|
||||
IOUtils.close(fout);
|
||||
|
@ -14,6 +14,7 @@ import java.util.Scanner;
|
||||
import com.taobao.arthas.common.AnsiLog;
|
||||
import com.taobao.arthas.common.ExecutingCommand;
|
||||
import com.taobao.arthas.common.IOUtils;
|
||||
import com.taobao.arthas.common.JavaVersionUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -126,8 +127,6 @@ public class ProcessUtils {
|
||||
// find java/java.exe, then try to find tools.jar
|
||||
String javaHome = System.getProperty("java.home");
|
||||
|
||||
float javaVersion = Float.parseFloat(System.getProperty("java.specification.version"));
|
||||
|
||||
// find java/java.exe
|
||||
File javaPath = findJava();
|
||||
if (javaPath == null) {
|
||||
@ -141,7 +140,7 @@ public class ProcessUtils {
|
||||
toolsJar = new File(javaHome, "../../lib/tools.jar");
|
||||
}
|
||||
|
||||
if (javaVersion < 9.0f) {
|
||||
if (JavaVersionUtils.isLessThanJava9()) {
|
||||
if (!toolsJar.exists()) {
|
||||
throw new IllegalArgumentException("Can not find tools.jar under java home: " + javaHome);
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package com.taobao.arthas.common;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hengyunabc 2018-11-21
|
||||
*
|
||||
*/
|
||||
public class JavaVersionUtils {
|
||||
public static void main(String[] args) {
|
||||
System.err.println(JavaVersionUtils.isJava8());
|
||||
}
|
||||
|
||||
private static final float javaVersion = Float.parseFloat(System.getProperty("java.specification.version"));
|
||||
|
||||
public static float javaVersion() {
|
||||
return javaVersion;
|
||||
}
|
||||
|
||||
public static boolean isJava6() {
|
||||
return Float.toString(javaVersion).equals("1.6");
|
||||
}
|
||||
|
||||
public static boolean isJava7() {
|
||||
return Float.toString(javaVersion).equals("1.7");
|
||||
}
|
||||
|
||||
public static boolean isJava8() {
|
||||
return Float.toString(javaVersion).equals("1.8");
|
||||
}
|
||||
|
||||
public static boolean isJava9() {
|
||||
return Float.toString(javaVersion).equals("9");
|
||||
}
|
||||
|
||||
public static boolean isLessThanJava9() {
|
||||
return javaVersion < 9.0f;
|
||||
}
|
||||
|
||||
public static boolean isGreaterThanJava8() {
|
||||
return javaVersion > 1.8f;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user