Skip to content

Commit b9ddf42

Browse files
authored
Replace Bintray repo with Cloudsmith (#48)
1 parent 6551547 commit b9ddf42

File tree

9 files changed

+48
-33
lines changed

9 files changed

+48
-33
lines changed

nanoFirmwareFlasher/CC13x26x2Firmware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace nanoFramework.Tools.FirmwareFlasher
1010
{
1111
/// <summary>
12-
/// Class that handles the download of STM32 firmware files from Bintray.
12+
/// Class that handles the download of STM32 firmware files from Cloudsmith.
1313
/// </summary>
1414
internal class CC13x26x2Firmware : FirmwarePackage
1515
{

nanoFirmwareFlasher/BintrayPackageInfo.cs renamed to nanoFirmwareFlasher/CloudsmithPackageInfo.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
namespace nanoFramework.Tools.FirmwareFlasher
1010
{
1111
[Serializable]
12-
internal class BintrayPackageInfo
12+
internal class CloudsmithPackageInfo
1313
{
14-
[JsonProperty("latest_version")]
15-
public string LatestVersion { get; set; }
14+
[JsonProperty("version")]
15+
public string Version { get; set; }
16+
17+
[JsonProperty("cdn_url")]
18+
public string DownloadUrl { get; set; }
1619
}
1720
}

nanoFirmwareFlasher/Esp32Firmware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace nanoFramework.Tools.FirmwareFlasher
1313
{
1414
/// <summary>
15-
/// Class that handles the download of ESP32 firmware files from Bintray.
15+
/// Class that handles the download of ESP32 firmware files from Cloudsmith.
1616
/// </summary>
1717
internal class Esp32Firmware : FirmwarePackage
1818
{

nanoFirmwareFlasher/ExitCodes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ public enum ExitCodes : int
202202
E9004 = 9004,
203203

204204
/// <summary>
205-
/// Can't find the target in the Bintray repository.
205+
/// Can't find the target in Cloudsmith repository.
206206
/// </summary>
207-
[Display(Name = "Can't find the target in the Bintray repository.")]
207+
[Display(Name = "Can't find the target in Cloudsmith repository.")]
208208
E9005 = 9005,
209209

210210
/// <summary>

nanoFirmwareFlasher/FirmwarePackage.cs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@
55

66
using Newtonsoft.Json;
77
using System;
8+
using System.Collections.Generic;
89
using System.IO;
910
using System.IO.Compression;
1011
using System.Linq;
11-
using System.Net;
1212
using System.Net.Http;
1313
using System.Text.RegularExpressions;
14+
using System.Web;
1415

1516
namespace nanoFramework.Tools.FirmwareFlasher
1617
{
1718
/// <summary>
18-
/// Abstract base class that handles the download and extraction of firmware file from Bintray.
19+
/// Abstract base class that handles the download and extraction of firmware file from Cloudsmith.
1920
/// </summary>
2021
internal abstract class FirmwarePackage : IDisposable
2122
{
2223
// HttpClient is intended to be instantiated once per application, rather than per-use.
23-
static HttpClient _bintrayClient = new HttpClient();
24+
static HttpClient _cloudsmithClient = new HttpClient();
2425

2526
/// <summary>
26-
/// Uri of Bintray API
27+
/// Uri of Cloudsmith API
2728
/// </summary>
28-
internal const string _bintrayApiPackages = "https://api.bintray.com/packages/nfbot";
29+
internal const string _cloudsmithPackages = "https://api.cloudsmith.io/v1/packages/net-nanoframework";
2930

3031
internal const string _refTargetsDevRepo = "nanoframework-images-dev";
3132
internal const string _refTargetsStableRepo = "nanoframework-images";
@@ -68,9 +69,17 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
6869
{
6970
string fwFileName = null;
7071

72+
// query URL
73+
// https://api.cloudsmith.io/v1/packages/net-nanoframework/REPO-NAME-HERE/?page=1&query=/PACKAGE-NAME-HERE latest
74+
75+
// download URL
76+
// https://dl.cloudsmith.io/public/net-nanoframework/REPO-NAME-HERE/raw/names/PACKAGE-NAME-HERE/versions/VERSION-HERE/ST_STM32F429I_DISCOVERY-1.6.2-preview.9.zip
77+
7178
// reference targets
7279
var repoName = _stable ? _refTargetsStableRepo : _refTargetsDevRepo;
73-
string requestUri = $"{_bintrayApiPackages}/{repoName}/{_targetName}";
80+
string requestUri = $"{_cloudsmithPackages}/{repoName}/?page=1&query={_targetName} latest";
81+
82+
string downloadUrl = string.Empty;
7483

7584
// flag to signal if the work-flow step was successful
7685
bool stepSuccesful = false;
@@ -134,9 +143,12 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
134143
Console.Write($"Trying to find {_targetName} in {(_stable ? "stable" : "developement")} repository...");
135144
}
136145

137-
HttpResponseMessage response = await _bintrayClient.GetAsync(requestUri);
146+
HttpResponseMessage response = await _cloudsmithClient.GetAsync(requestUri);
138147

139-
if (response.StatusCode == HttpStatusCode.NotFound)
148+
var responseBody = await response.Content.ReadAsStringAsync();
149+
150+
// check for empty array
151+
if (responseBody == "[]")
140152
{
141153
if (Verbosity >= VerbosityLevel.Normal)
142154
{
@@ -145,12 +157,12 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
145157
}
146158

147159
// try with community targets
148-
requestUri = $"{_bintrayApiPackages}/{_communityTargetsepo}/{_targetName}";
160+
requestUri = $"{_cloudsmithPackages}/{_communityTargetsepo}/?page=1&query={_targetName} latest";
149161
repoName = _communityTargetsepo;
150162

151-
response = await _bintrayClient.GetAsync(requestUri);
163+
response = await _cloudsmithClient.GetAsync(requestUri);
152164

153-
if (response.StatusCode == HttpStatusCode.NotFound)
165+
if (responseBody == "[]")
154166
{
155167
if (Verbosity >= VerbosityLevel.Normal)
156168
{
@@ -167,24 +179,26 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
167179
Console.WriteLine($"OK");
168180
}
169181

170-
// read and parse response
171-
string responseBody = await response.Content.ReadAsStringAsync();
172-
BintrayPackageInfo packageInfo = JsonConvert.DeserializeObject<BintrayPackageInfo>(responseBody);
182+
// parse response
183+
List<CloudsmithPackageInfo> packageInfo = JsonConvert.DeserializeObject<List<CloudsmithPackageInfo>>(responseBody);
173184

174185
// if no specific version was requested, use latest available
175186
if (string.IsNullOrEmpty(_fwVersion))
176187
{
177-
_fwVersion = packageInfo.LatestVersion;
188+
_fwVersion = packageInfo.ElementAt(0).Version;
178189
}
179190

191+
// grab download URL
192+
downloadUrl = packageInfo.ElementAt(0).DownloadUrl;
193+
180194
// set exposed property
181195
Version = _fwVersion;
182196

183197
stepSuccesful = true;
184198
}
185199
catch
186200
{
187-
// exception with download, assuming it's something with network connection or Bintray API
201+
// exception with download, assuming it's something with network connection or Cloudsmith API
188202
}
189203
}
190204

@@ -222,9 +236,7 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
222236
try
223237
{
224238
// setup and perform download request
225-
requestUri = $"https://dl.bintray.com/nfbot/{repoName}/{fwFileName}";
226-
227-
using (var fwFileResponse = await _bintrayClient.GetAsync(requestUri))
239+
using (var fwFileResponse = await _cloudsmithClient.GetAsync(downloadUrl))
228240
{
229241
if (fwFileResponse.IsSuccessStatusCode)
230242
{
@@ -253,7 +265,7 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
253265
}
254266
catch
255267
{
256-
// exception with download, assuming it's something with network connection or Bintray API
268+
// exception with download, assuming it's something with network connection or Cloudsmith API
257269
}
258270
}
259271
else

nanoFirmwareFlasher/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class Options
120120
"target",
121121
Required = false,
122122
Default = null,
123-
HelpText = "Target name. This is the target name used in the GitHub and Bintray repositories.")]
123+
HelpText = "Target name. This is the target name used in the GitHub and Cloudsmith repositories.")]
124124
public string TargetName { get; set; }
125125

126126
[Option(

nanoFirmwareFlasher/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
168168
else
169169
{
170170
// other supported platforms will go here
171-
// in case a wacky target is entered by the user, the package name will be checked against Bintray repo
171+
// in case a wacky target is entered by the user, the package name will be checked against Cloudsmith repo
172172
}
173173
}
174174

@@ -587,7 +587,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
587587
// update operation requested?
588588
if (o.Update)
589589
{
590-
// this to update the device with fw from Bintray
590+
// this to update the device with fw from Cloudsmith
591591

592592
// need to take care of flash address
593593
string appFlashAddress = null;
@@ -681,7 +681,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o)
681681
// update operation requested?
682682
if (o.Update)
683683
{
684-
// this to update the device with fw from Bintray
684+
// this to update the device with fw from Cloudsmith
685685

686686
// need to take care of flash address
687687
string appFlashAddress = null;

nanoFirmwareFlasher/Stm32Firmware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace nanoFramework.Tools.FirmwareFlasher
1212
{
1313
/// <summary>
14-
/// Class that handles the download of STM32 firmware files from Bintray.
14+
/// Class that handles the download of STM32 firmware files from Cloudsmith.
1515
/// </summary>
1616
internal class Stm32Firmware : FirmwarePackage
1717
{

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "1.18.0-preview.{height}",
3+
"version": "1.19.0-preview.{height}",
44
"assemblyVersion": {
55
"precision": "revision"
66
},

0 commit comments

Comments
 (0)