Skip to content

Commit 85e91ef

Browse files
author
Mattia Bertorello
committed
Change builder domain with https and add logging
1 parent 2d04282 commit 85e91ef

File tree

1 file changed

+62
-17
lines changed

1 file changed

+62
-17
lines changed

Diff for: arduino-core/src/processing/app/Platform.java

+62-17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import cc.arduino.utils.network.HttpConnectionManager;
2727
import com.fasterxml.jackson.databind.DeserializationFeature;
2828
import com.fasterxml.jackson.databind.ObjectMapper;
29+
import org.apache.logging.log4j.LogManager;
30+
import org.apache.logging.log4j.Logger;
2931
import processing.app.debug.TargetBoard;
3032
import processing.app.debug.TargetPackage;
3133
import processing.app.debug.TargetPlatform;
@@ -58,6 +60,7 @@
5860
* know if name is proper Java package syntax.)
5961
*/
6062
public class Platform {
63+
private static Logger log = LogManager.getLogger(Platform.class);
6164

6265
/**
6366
* Set the default L & F. While I enjoy the bounty of the sixteen possible
@@ -163,6 +166,7 @@ private static void loadLib(File lib) {
163166
}
164167

165168
private native String resolveDeviceAttachedToNative(String serial);
169+
166170
private native String[] listSerialsNative();
167171

168172
public String preListAllCandidateDevices() {
@@ -173,47 +177,36 @@ public List<String> listSerials() {
173177
return new ArrayList<>(Arrays.asList(listSerialsNative()));
174178
}
175179

176-
public List<String> listSerialsNames(){
180+
public List<String> listSerialsNames() {
177181
List<String> list = new LinkedList<>();
178182
for (String port : listSerialsNative()) {
179183
list.add(port.split("_")[0]);
180184
}
181185
return list;
182186
}
183187

184-
public static class BoardCloudAPIid {
185-
public BoardCloudAPIid() { }
186-
private String name;
187-
private String architecture;
188-
private String id;
189-
public String getName() { return name; }
190-
public String getArchitecture() { return architecture; }
191-
public String getId() { return id; }
192-
public void setName(String tmp) { name = tmp; }
193-
public void setArchitecture(String tmp) { architecture = tmp; }
194-
public void setId(String tmp) { id = tmp; }
195-
}
196-
197188
public synchronized void getBoardWithMatchingVidPidFromCloud(String vid, String pid) {
198189
// this method is less useful in Windows < WIN10 since you need drivers to be already installed
199190
ObjectMapper mapper = new ObjectMapper();
200191
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
201192
try {
202-
URL jsonUrl = new URL("http", "api-builder.arduino.cc", 80, "/builder/v1/boards/0x"+vid+"/0x"+pid);
193+
URL jsonUrl = new URL(String.format("https://builder.arduino.cc/builder/v1/boards/0x%s/0x%s", vid, pid));
203194

204195
final HttpURLConnection httpConnection = new HttpConnectionManager(jsonUrl)
205196
.makeConnection();
206197
int code = httpConnection.getResponseCode();
207198
if (code == 404) {
199+
log.warn("Fail to get the Vid Pid information from the builder response code={}", code);
208200
return;
209201
}
210202
InputStream is = httpConnection.getInputStream();
211203
BoardCloudAPIid board = mapper.readValue(is, BoardCloudAPIid.class);
204+
log.info("Board info from the cloud {}", board);
212205
// Launch a popup with a link to boardmanager#board.getName()
213206
// replace spaces with &
214207
String realBoardName = board.getName().replaceAll("\\(.*?\\)", "").trim();
215208
String boardNameReplaced = realBoardName.replaceAll(" ", "&");
216-
String message = I18n.format(tr("{0}Install this package{1} to use your {2} board"), "<a href=\"http://boardsmanager/all#"+boardNameReplaced+"\">", "</a>", realBoardName);
209+
String message = I18n.format(tr("{0}Install this package{1} to use your {2} board"), "<a href=\"http://boardsmanager/all#" + boardNameReplaced + "\">", "</a>", realBoardName);
217210
BaseNoGui.setBoardManagerLink(message);
218211
} catch (Exception e) {
219212
// No connection no problem, fail silently
@@ -250,7 +243,7 @@ public synchronized Map<String, Object> resolveDeviceByVendorIdProductId(String
250243
boardData.put("board", board);
251244
boardData.put("vid", vids.get(i));
252245
boardData.put("pid", pids.get(i));
253-
String extrafields = vid_pid_iSerial.substring(vidPid.length()+1);
246+
String extrafields = vid_pid_iSerial.substring(vidPid.length() + 1);
254247
String[] parts = extrafields.split("_");
255248
boardData.put("iserial", parts[0]);
256249
return boardData;
@@ -263,6 +256,58 @@ public synchronized Map<String, Object> resolveDeviceByVendorIdProductId(String
263256
return null;
264257
}
265258

259+
public static class BoardCloudAPIid {
260+
public BoardCloudAPIid() {
261+
}
262+
263+
private String name;
264+
private String fqbn;
265+
private String architecture;
266+
private String id;
267+
268+
public String getName() {
269+
return name;
270+
}
271+
272+
public String getFqbn() {
273+
return fqbn;
274+
}
275+
276+
public String getArchitecture() {
277+
return architecture;
278+
}
279+
280+
public String getId() {
281+
return id;
282+
}
283+
284+
public void setName(String tmp) {
285+
name = tmp;
286+
}
287+
288+
public void setFqbn(String fqbn) {
289+
this.fqbn = fqbn;
290+
}
291+
292+
public void setArchitecture(String tmp) {
293+
architecture = tmp;
294+
}
295+
296+
public void setId(String tmp) {
297+
id = tmp;
298+
}
299+
300+
@Override
301+
public String toString() {
302+
return "BoardCloudAPIid{" +
303+
"name='" + name + '\'' +
304+
", fqbn='" + fqbn + '\'' +
305+
", architecture='" + architecture + '\'' +
306+
", id='" + id + '\'' +
307+
'}';
308+
}
309+
}
310+
266311
public String resolveDeviceByBoardID(Map<String, TargetPackage> packages, String boardId) {
267312
assert packages != null;
268313
assert boardId != null;

0 commit comments

Comments
 (0)