@@ -59,18 +59,25 @@ public class UrlHelper : IUrlHelper, IDisposable
59
59
/// </summary>
60
60
/// <param name="componentName"></param>
61
61
/// <param name="componenVersion"></param>
62
+ /// <param name="bomRef"></param>
62
63
/// <returns>Components</returns>
63
- public async Task < Components > GetSourceUrlForAlpinePackage ( string componentName , string componenVersion )
64
+ public async Task < Components > GetSourceUrlForAlpinePackage ( string componentName , string componenVersion , string bomRef )
64
65
{
65
66
Components componentsData = new Components ( ) ;
66
67
try
67
68
{
68
69
string localPathforSourceRepo = GetDownloadPathForAlpineRepo ( ) ;
69
70
string fullPath = Path . Combine ( localPathforSourceRepo , "aports" ) ;
71
+ var alpineDistro = GetAlpineDistro ( bomRef ) ;
70
72
if ( ! Directory . Exists ( fullPath ) )
71
73
{
72
74
//Clone AlpineRepository
73
- CloneSource ( localPathforSourceRepo ) ;
75
+ CloneSource ( localPathforSourceRepo , alpineDistro , fullPath ) ;
76
+ }
77
+ else
78
+ {
79
+ //Checkout stable branch
80
+ CheckoutDistro ( alpineDistro , fullPath ) ;
74
81
}
75
82
76
83
AlpinePackage alpinePackSourceDetails = await GetAlpineSourceUrl ( componentName , componenVersion , localPathforSourceRepo ) ;
@@ -88,6 +95,15 @@ public async Task<Components> GetSourceUrlForAlpinePackage(string componentName,
88
95
}
89
96
return componentsData ;
90
97
}
98
+ public static string GetAlpineDistro ( string bomRef )
99
+ {
100
+
101
+ string [ ] getDistro = bomRef . Split ( "distro" ) ;
102
+ string [ ] getDestroVersion = getDistro [ 1 ] . Split ( "-" ) ;
103
+ var output = getDestroVersion [ 1 ] . Substring ( 0 , getDestroVersion [ 1 ] . Length - 2 ) ;
104
+ var distro = output + "-stable" ;
105
+ return distro ;
106
+ }
91
107
92
108
private static Task < AlpinePackage > GetAlpineSourceUrl ( string name , string version , string localPathforSourceRepo )
93
109
{
@@ -154,9 +170,11 @@ public static string GetSourceUrlForAlpine(string pkgFilePath, string sourceData
154
170
try
155
171
{
156
172
var pkgVersionLine = File . ReadLines ( pkgFilePath ) . FirstOrDefault ( x => x . StartsWith ( "pkgver" ) ) ;
173
+ var pkgNameLine = File . ReadLines ( pkgFilePath ) . FirstOrDefault ( x => x . StartsWith ( "pkgname" ) ) ;
157
174
var _commitLine = File . ReadLines ( pkgFilePath ) . FirstOrDefault ( x => x . StartsWith ( "_commit" ) ) ;
158
175
var _tzcodeverLine = File . ReadLines ( pkgFilePath ) . FirstOrDefault ( x => x . StartsWith ( "_tzcodever" ) ) ;
159
176
string pkgVersion = string . Empty ;
177
+ string pkgName = string . Empty ;
160
178
string _commitValue = string . Empty ;
161
179
string _tzcodever = string . Empty ;
162
180
@@ -165,10 +183,19 @@ public static string GetSourceUrlForAlpine(string pkgFilePath, string sourceData
165
183
string [ ] pkgVersionValue = Regex . Split ( pkgVersionLine , @"\=" ) ;
166
184
pkgVersion = pkgVersionValue [ 1 ] ;
167
185
}
186
+ if ( pkgNameLine != null )
187
+ {
188
+ string [ ] pkgNameData = Regex . Split ( pkgNameLine , @"\=" ) ;
189
+ pkgName = pkgNameData [ 1 ] ;
190
+ }
168
191
if ( _tzcodeverLine != null )
169
192
{
170
193
string [ ] _tzcodeverValue = Regex . Split ( _tzcodeverLine , @"\=" ) ;
171
194
_tzcodever = _tzcodeverValue [ 1 ] ;
195
+ if ( _tzcodeverLine . Contains ( "pkgver" ) )
196
+ {
197
+ _tzcodever = pkgVersion ;
198
+ }
172
199
}
173
200
if ( _commitLine != null )
174
201
{
@@ -179,7 +206,7 @@ public static string GetSourceUrlForAlpine(string pkgFilePath, string sourceData
179
206
{
180
207
Match url = Regex . Match ( sourceData , @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=$]*)?" ) ;
181
208
string finalUrl = url . ToString ( ) ;
182
- sourceUrl = finalUrl . Replace ( "$pkgver" , pkgVersion ) . Replace ( "$_commit" , _commitValue ) . Replace ( "$_tzcodever" , _tzcodever ) ;
209
+ sourceUrl = finalUrl . Replace ( "$pkgver" , pkgVersion ) . Replace ( "$pkgname" , pkgName ) . Replace ( "$ _commit", _commitValue ) . Replace ( "$_tzcodever" , _tzcodever ) ;
183
210
if ( pkgVersion == null && _commitValue == null && _tzcodever == null )
184
211
{
185
212
sourceUrl = string . Empty ;
@@ -203,7 +230,7 @@ public static string GetDownloadPathForAlpineRepo()
203
230
string localPathforSourceRepo = string . Empty ;
204
231
try
205
232
{
206
- localPathforSourceRepo = $ "{ Directory . GetParent ( Directory . GetCurrentDirectory ( ) ) } / ClearingTool/ DownloadedFiles/ ";
233
+ localPathforSourceRepo = $ "{ Directory . GetParent ( Directory . GetCurrentDirectory ( ) ) } \\ ClearingTool\\ DownloadedFiles\\ ";
207
234
}
208
235
catch ( IOException ex )
209
236
{
@@ -227,7 +254,7 @@ private static string GetComponentExternalIdForAlpine(string name)
227
254
return $ "{ Dataconstant . PurlCheck ( ) [ "ALPINE" ] } { Dataconstant . ForwardSlash } { name } ?arch=source";
228
255
}
229
256
230
- private static void CloneSource ( string localPathforSourceRepo )
257
+ private static void CloneSource ( string localPathforSourceRepo , string alpineDistro , string fullPath )
231
258
{
232
259
List < string > gitCommands = GetGitCloneCommands ( ) ;
233
260
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
@@ -263,7 +290,27 @@ private static void CloneSource(string localPathforSourceRepo)
263
290
process . Start ( ) ;
264
291
process . WaitForExit ( ) ;
265
292
}
293
+ if ( Directory . Exists ( fullPath ) )
294
+ {
295
+ CheckoutDistro ( alpineDistro , fullPath ) ;
296
+ }
297
+
298
+ }
266
299
300
+ private static void CheckoutDistro ( string alpineDistro , string fullPath )
301
+ {
302
+ var process = new Process
303
+ {
304
+ StartInfo = new ProcessStartInfo ( )
305
+ {
306
+ CreateNoWindow = true ,
307
+ FileName = "git" ,
308
+ Arguments = $ "checkout" + " " + alpineDistro ,
309
+ WorkingDirectory = fullPath ,
310
+ }
311
+ } ;
312
+ process . Start ( ) ;
313
+ process . WaitForExit ( ) ;
267
314
}
268
315
269
316
private static List < string > GetGitCloneCommands ( )
0 commit comments