Skip to content

Commit b4145e1

Browse files
committed
fixed package search loops
1 parent 09c0170 commit b4145e1

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/processing/mode/android/SDKDownloader.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
256256
XPath xpath = xPathfactory.newXPath();
257257
XPathExpression expr;
258258
NodeList remotePackages;
259+
boolean found;
259260

260261
// -----------------------------------------------------------------------
261262
// platform
@@ -301,6 +302,7 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
301302
// build-tools
302303
expr = xpath.compile("//remotePackage[starts-with(@path, \"build-tools;\")]");
303304
remotePackages = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
305+
found = false;
304306
if (remotePackages != null) {
305307
for(int buildTool=0; buildTool < remotePackages.getLength(); buildTool++) {
306308
NodeList childNodes = remotePackages.item(buildTool).getChildNodes();
@@ -331,19 +333,22 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
331333
urlHolder.buildToolsFilename = url.item(0).getTextContent();
332334
urlHolder.buildToolsUrl = REPOSITORY_URL + urlHolder.buildToolsFilename;
333335
urlHolder.totalSize += Integer.parseInt(size.item(0).getTextContent());
336+
found = true;
334337
break;
335338
}
336339
}
337-
break;
340+
if (found) break;
338341
}
339-
} else {
342+
}
343+
if (!found) {
340344
throw new IOException("Cannot find the build-tools");
341345
}
342346

343347
// -----------------------------------------------------------------------
344348
// tools
345349
expr = xpath.compile("//remotePackage[@path=\"tools\"]"); //Matches two items according to xml file
346350
remotePackages = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
351+
found = false;
347352
if (remotePackages != null) {
348353
NodeList childNodes = remotePackages.item(1).getChildNodes(); //Second item is the latest tools for now
349354
NodeList archives = ((Element) childNodes).getElementsByTagName("archive");
@@ -360,21 +365,24 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
360365
urlHolder.toolsFilename = url.item(0).getTextContent();
361366
urlHolder.toolsUrl = REPOSITORY_URL + urlHolder.toolsFilename;
362367
urlHolder.totalSize += Integer.parseInt(size.item(0).getTextContent());
368+
found = true;
363369
break;
364370
}
365371
}
366-
} else {
372+
}
373+
if (!found) {
367374
throw new IOException("Cannot find the tools");
368375
}
369376

370377
// -----------------------------------------------------------------------
371378
// emulator
372379
expr = xpath.compile("//remotePackage[@path=\"emulator\"]"); //Matches two items according to xml file
373380
remotePackages = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
381+
found = false;
374382
if (remotePackages != null) {
375383
for(int i = 0; i < remotePackages.getLength(); ++i) {
376384
NodeList childNodes = remotePackages.item(i).getChildNodes();
377-
385+
378386
NodeList channel = ((Element) childNodes).getElementsByTagName("channelRef");
379387
if(!channel.item(0).getAttributes().item(0).getNodeValue().equals("channel-0"))
380388
continue; //Stable channel only, skip others
@@ -388,17 +396,19 @@ private void getMainDownloadUrls(SDKUrlHolder urlHolder,
388396
NodeList os = ((Element) archive).getElementsByTagName("host-os");
389397
NodeList url = ((Element) complete.item(0)).getElementsByTagName("url");
390398
NodeList size = ((Element) complete.item(0)).getElementsByTagName("size");
391-
399+
392400
if (os.item(0).getTextContent().equals(requiredHostOs)) {
393401
urlHolder.emulatorFilename = url.item(0).getTextContent();
394402
urlHolder.emulatorUrl = REPOSITORY_URL + urlHolder.emulatorFilename;
395403
urlHolder.totalSize += Integer.parseInt(size.item(0).getTextContent());
404+
found = true;
396405
break;
397406
}
398407
}
399-
break;
408+
if (found) break;
400409
}
401-
} else {
410+
}
411+
if (!found) {
402412
throw new IOException("Cannot find the emulator");
403413
}
404414
}

0 commit comments

Comments
 (0)