diff --git a/arduino-core/src/processing/app/Platform.java b/arduino-core/src/processing/app/Platform.java index 14e60edfa..b2b0bdf22 100644 --- a/arduino-core/src/processing/app/Platform.java +++ b/arduino-core/src/processing/app/Platform.java @@ -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 listSerialsNames(){ + public List listSerialsNames() { List 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"), "", "", realBoardName); + String message = I18n.format(tr("{0}Install this package{1} to use your {2} board"), "", "", 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 packages, String boardId) { assert packages != null; assert boardId != null;