@@ -502,12 +502,11 @@ public static Dictionary<string, KeyValuePair<Dependency, string>> GetCurrentDep
502
502
503
503
// Extract the version from the filename.
504
504
// dep.Artifact is the name of the package (prefix)
505
- // The regular expression extracts the version number from the filename
506
- // handling filenames like foo-1.2.3-alpha.
507
- match = System . Text . RegularExpressions . Regex . Match (
508
- filenameWithoutExtension . Substring (
509
- dep . Artifact . Length + 1 ) , "^([0-9.]+)" ) ;
510
- if ( match . Success )
505
+ string artifactVersion = ExtractVersionFromFileName (
506
+ filenameWithoutExtension . Substring ( dep . Artifact . Length + 1 )
507
+ ) ;
508
+
509
+ if ( artifactVersion != null )
511
510
{
512
511
bool reportDependency = true ;
513
512
// If the AAR is exploded and it should not be, delete it and do not
@@ -527,7 +526,6 @@ public static Dictionary<string, KeyValuePair<Dependency, string>> GetCurrentDep
527
526
}
528
527
if ( reportDependency )
529
528
{
530
- string artifactVersion = match . Groups [ 1 ] . Value ;
531
529
Dependency currentDep = new Dependency (
532
530
dep . Group , dep . Artifact , artifactVersion ,
533
531
packageIds : dep . PackageIds , repositories : dep . Repositories ) ;
@@ -1038,7 +1036,10 @@ public Dictionary<string, string> CopyDependencies(
1038
1036
KeyValuePair < Dependency , string > oldDepFilenamePair ;
1039
1037
if ( currentDepsByVersionlessKey . TryGetValue ( dep . VersionlessKey ,
1040
1038
out oldDepFilenamePair ) ) {
1041
- if ( oldDepFilenamePair . Key . BestVersion != dep . BestVersion &&
1039
+ string oldVersion = ExtractVersionFromFileName (
1040
+ oldDepFilenamePair . Key . BestVersion ) ;
1041
+ string newVersion = ExtractVersionFromFileName ( dep . BestVersion ) ;
1042
+ if ( ( oldVersion == null || ( newVersion != null && oldVersion != newVersion ) ) &&
1042
1043
( confirmer == null || confirmer ( oldDepFilenamePair . Key , dep ) ) ) {
1043
1044
DeleteExistingFileOrDirectory ( oldDepFilenamePair . Value ,
1044
1045
includeMetaFiles : true ) ;
@@ -1382,5 +1383,17 @@ public Dictionary<string, Dependency> LoadDependencies(
1382
1383
}
1383
1384
return dependencyMap ;
1384
1385
}
1386
+
1387
+ /// <summary>
1388
+ /// Extracts the version number from the filename handling filenames like foo-1.2.3-alpha.
1389
+ /// </summary>
1390
+ /// <param name="filename">File name without extension to extract from.</param>
1391
+ /// <returns>The version string if extracted successfully and null otherwise.</returns>
1392
+ private static string ExtractVersionFromFileName ( string filename )
1393
+ {
1394
+ var match = System . Text . RegularExpressions . Regex . Match (
1395
+ filename , "^([0-9.]+)" ) ;
1396
+ return match . Success ? match . Groups [ 1 ] . Value : null ;
1397
+ }
1385
1398
}
1386
1399
}
0 commit comments