forked from smooth80/flutter-intellij
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJxBrowserUtils.java
85 lines (70 loc) · 3.03 KB
/
JxBrowserUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright 2020 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
package io.flutter.utils;
import com.intellij.openapi.util.SystemInfo;
// import com.intellij.util.system.CpuArch;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class JxBrowserUtils {
private static final String JXBROWSER_FILE_PREFIX = "jxbrowser";
private static final String JXBROWSER_FILE_VERSION = "7.17";
private static final String JXBROWSER_FILE_SUFFIX = "jar";
public static final String LICENSE_PROPERTY_NAME = "jxbrowser.license.key";
public String getPlatformFileName() throws FileNotFoundException {
String name = "";
if (SystemInfo.isMac) {
name = "mac";
} else if (SystemInfo.isWindows) {
if (SystemInfo.is32Bit) {
name = "win32";
} else if (SystemInfo.is64Bit) {
name = "win64";
}
} else if (SystemInfo.isLinux && SystemInfo.is64Bit) {
name = "linux64";
}
if (name.isEmpty()) {
throw new FileNotFoundException("Unable to find matching JxBrowser platform file for: " + SystemInfo.getOsNameAndVersion());
}
return String.format("%s-%s-%s.%s", JXBROWSER_FILE_PREFIX, name, JXBROWSER_FILE_VERSION, JXBROWSER_FILE_SUFFIX);
}
public String getApiFileName() {
return String.format("%s-%s.%s", JXBROWSER_FILE_PREFIX, JXBROWSER_FILE_VERSION, JXBROWSER_FILE_SUFFIX);
}
public String getSwingFileName() {
return String.format("%s-swing-%s.%s", JXBROWSER_FILE_PREFIX, JXBROWSER_FILE_VERSION, JXBROWSER_FILE_SUFFIX);
}
public String getDistributionLink(String fileName) {
return "https://storage.googleapis.com/flutter_infra/flutter/intellij/jxbrowser/" + fileName;
}
public String getJxBrowserKey() throws FileNotFoundException {
if (JxBrowserUtils.class.getResource("/jxbrowser/jxbrowser.properties") == null) {
throw new FileNotFoundException("jxbrowser.properties file does not exist");
}
final Properties properties = new Properties();
try {
properties.load(JxBrowserUtils.class.getResourceAsStream("/jxbrowser/jxbrowser.properties"));
}
catch (IOException ex) {
throw new FileNotFoundException("Unable to load properties of JxBrowser key file");
}
final String value = properties.getProperty(LICENSE_PROPERTY_NAME);
if (value == null) {
throw new FileNotFoundException("No value for JxBrowser key exists");
}
return value;
}
public boolean licenseIsSet() {
return System.getProperty(JxBrowserUtils.LICENSE_PROPERTY_NAME) != null;
}
public boolean isM1Mac() {
// Return default false value for earlier IntelliJ versions that do not have the CpuArch method (211.4961.30).
// It's possible a user could be using an earlier IntelliJ version with an M1 mac, but for that case we can't detect
// that the system is the problem and will serve a more generic error message.
return false; // return SystemInfo.isMac && CpuArch.isArm64();
}
}