Skip to content

Commit e49d009

Browse files
Fixing #48
Using the same rule (and the same function) for extracting a version code when comparing libraries versions, as used to generate file names when storing them in Plugins/Android folder, so repetitive checks for versions with -alpha like postfixes don't misdetect them as a new version each time.
1 parent f06b70f commit e49d009

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

source/JarResolverLib/src/Google.JarResolver/PlayServicesSupport.cs

+21-8
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,11 @@ public static Dictionary<string, KeyValuePair<Dependency, string>> GetCurrentDep
502502

503503
// Extract the version from the filename.
504504
// 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)
511510
{
512511
bool reportDependency = true;
513512
// 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
527526
}
528527
if (reportDependency)
529528
{
530-
string artifactVersion = match.Groups[1].Value;
531529
Dependency currentDep = new Dependency(
532530
dep.Group, dep.Artifact, artifactVersion,
533531
packageIds: dep.PackageIds, repositories: dep.Repositories);
@@ -1038,7 +1036,10 @@ public Dictionary<string, string> CopyDependencies(
10381036
KeyValuePair<Dependency, string> oldDepFilenamePair;
10391037
if (currentDepsByVersionlessKey.TryGetValue(dep.VersionlessKey,
10401038
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)) &&
10421043
(confirmer == null || confirmer(oldDepFilenamePair.Key, dep))) {
10431044
DeleteExistingFileOrDirectory(oldDepFilenamePair.Value,
10441045
includeMetaFiles: true);
@@ -1382,5 +1383,17 @@ public Dictionary<string, Dependency> LoadDependencies(
13821383
}
13831384
return dependencyMap;
13841385
}
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+
}
13851398
}
13861399
}

0 commit comments

Comments
 (0)