mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-31 20:52:13 +01:00
Change builder domain with https and add logging
This commit is contained in:
parent
2d042820a0
commit
85e91ef079
@ -26,6 +26,8 @@ import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.utils.network.HttpConnectionManager;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
@ -58,6 +60,7 @@ import static processing.app.I18n.tr;
|
||||
* know if name is proper Java package syntax.)
|
||||
*/
|
||||
public class Platform {
|
||||
private static Logger log = LogManager.getLogger(Platform.class);
|
||||
|
||||
/**
|
||||
* Set the default L & F. While I enjoy the bounty of the sixteen possible
|
||||
@ -163,6 +166,7 @@ public class Platform {
|
||||
}
|
||||
|
||||
private native String resolveDeviceAttachedToNative(String serial);
|
||||
|
||||
private native String[] listSerialsNative();
|
||||
|
||||
public String preListAllCandidateDevices() {
|
||||
@ -173,7 +177,7 @@ public class Platform {
|
||||
return new ArrayList<>(Arrays.asList(listSerialsNative()));
|
||||
}
|
||||
|
||||
public List<String> listSerialsNames(){
|
||||
public List<String> listSerialsNames() {
|
||||
List<String> list = new LinkedList<>();
|
||||
for (String port : listSerialsNative()) {
|
||||
list.add(port.split("_")[0]);
|
||||
@ -181,39 +185,28 @@ public class Platform {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static class BoardCloudAPIid {
|
||||
public BoardCloudAPIid() { }
|
||||
private String name;
|
||||
private String architecture;
|
||||
private String id;
|
||||
public String getName() { return name; }
|
||||
public String getArchitecture() { return architecture; }
|
||||
public String getId() { return id; }
|
||||
public void setName(String tmp) { name = tmp; }
|
||||
public void setArchitecture(String tmp) { architecture = tmp; }
|
||||
public void setId(String tmp) { id = tmp; }
|
||||
}
|
||||
|
||||
public synchronized void getBoardWithMatchingVidPidFromCloud(String vid, String pid) {
|
||||
// this method is less useful in Windows < WIN10 since you need drivers to be already installed
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
try {
|
||||
URL jsonUrl = new URL("http", "api-builder.arduino.cc", 80, "/builder/v1/boards/0x"+vid+"/0x"+pid);
|
||||
URL jsonUrl = new URL(String.format("https://builder.arduino.cc/builder/v1/boards/0x%s/0x%s", vid, pid));
|
||||
|
||||
final HttpURLConnection httpConnection = new HttpConnectionManager(jsonUrl)
|
||||
.makeConnection();
|
||||
int code = httpConnection.getResponseCode();
|
||||
if (code == 404) {
|
||||
log.warn("Fail to get the Vid Pid information from the builder response code={}", code);
|
||||
return;
|
||||
}
|
||||
InputStream is = httpConnection.getInputStream();
|
||||
BoardCloudAPIid board = mapper.readValue(is, BoardCloudAPIid.class);
|
||||
log.info("Board info from the cloud {}", board);
|
||||
// Launch a popup with a link to boardmanager#board.getName()
|
||||
// replace spaces with &
|
||||
String realBoardName = board.getName().replaceAll("\\(.*?\\)", "").trim();
|
||||
String boardNameReplaced = realBoardName.replaceAll(" ", "&");
|
||||
String message = I18n.format(tr("{0}Install this package{1} to use your {2} board"), "<a href=\"http://boardsmanager/all#"+boardNameReplaced+"\">", "</a>", realBoardName);
|
||||
String message = I18n.format(tr("{0}Install this package{1} to use your {2} board"), "<a href=\"http://boardsmanager/all#" + boardNameReplaced + "\">", "</a>", realBoardName);
|
||||
BaseNoGui.setBoardManagerLink(message);
|
||||
} catch (Exception e) {
|
||||
// No connection no problem, fail silently
|
||||
@ -250,7 +243,7 @@ public class Platform {
|
||||
boardData.put("board", board);
|
||||
boardData.put("vid", vids.get(i));
|
||||
boardData.put("pid", pids.get(i));
|
||||
String extrafields = vid_pid_iSerial.substring(vidPid.length()+1);
|
||||
String extrafields = vid_pid_iSerial.substring(vidPid.length() + 1);
|
||||
String[] parts = extrafields.split("_");
|
||||
boardData.put("iserial", parts[0]);
|
||||
return boardData;
|
||||
@ -263,6 +256,58 @@ public class Platform {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class BoardCloudAPIid {
|
||||
public BoardCloudAPIid() {
|
||||
}
|
||||
|
||||
private String name;
|
||||
private String fqbn;
|
||||
private String architecture;
|
||||
private String id;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getFqbn() {
|
||||
return fqbn;
|
||||
}
|
||||
|
||||
public String getArchitecture() {
|
||||
return architecture;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setName(String tmp) {
|
||||
name = tmp;
|
||||
}
|
||||
|
||||
public void setFqbn(String fqbn) {
|
||||
this.fqbn = fqbn;
|
||||
}
|
||||
|
||||
public void setArchitecture(String tmp) {
|
||||
architecture = tmp;
|
||||
}
|
||||
|
||||
public void setId(String tmp) {
|
||||
id = tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BoardCloudAPIid{" +
|
||||
"name='" + name + '\'' +
|
||||
", fqbn='" + fqbn + '\'' +
|
||||
", architecture='" + architecture + '\'' +
|
||||
", id='" + id + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public String resolveDeviceByBoardID(Map<String, TargetPackage> packages, String boardId) {
|
||||
assert packages != null;
|
||||
assert boardId != null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user