-
Notifications
You must be signed in to change notification settings - Fork 371
Fixing https://github.com/googlesamples/unity-jar-resolver/issues/48 #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -502,12 +502,11 @@ public static Dictionary<string, KeyValuePair<Dependency, string>> GetCurrentDep | |
|
||
// Extract the version from the filename. | ||
// dep.Artifact is the name of the package (prefix) | ||
// The regular expression extracts the version number from the filename | ||
// handling filenames like foo-1.2.3-alpha. | ||
match = System.Text.RegularExpressions.Regex.Match( | ||
filenameWithoutExtension.Substring( | ||
dep.Artifact.Length + 1), "^([0-9.]+)"); | ||
if (match.Success) | ||
string artifactVersion = ExtractVersionFromFileName( | ||
filenameWithoutExtension.Substring(dep.Artifact.Length + 1) | ||
); | ||
|
||
if (artifactVersion != null) | ||
{ | ||
bool reportDependency = true; | ||
// 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 | |
} | ||
if (reportDependency) | ||
{ | ||
string artifactVersion = match.Groups[1].Value; | ||
Dependency currentDep = new Dependency( | ||
dep.Group, dep.Artifact, artifactVersion, | ||
packageIds: dep.PackageIds, repositories: dep.Repositories); | ||
|
@@ -1038,7 +1036,10 @@ public Dictionary<string, string> CopyDependencies( | |
KeyValuePair<Dependency, string> oldDepFilenamePair; | ||
if (currentDepsByVersionlessKey.TryGetValue(dep.VersionlessKey, | ||
out oldDepFilenamePair)) { | ||
if (oldDepFilenamePair.Key.BestVersion != dep.BestVersion && | ||
string oldVersion = ExtractVersionFromFileName( | ||
|
||
oldDepFilenamePair.Key.BestVersion); | ||
string newVersion = ExtractVersionFromFileName(dep.BestVersion); | ||
if ((oldVersion == null || (newVersion != null && oldVersion != newVersion)) && | ||
(confirmer == null || confirmer(oldDepFilenamePair.Key, dep))) { | ||
|
||
DeleteExistingFileOrDirectory(oldDepFilenamePair.Value, | ||
includeMetaFiles: true); | ||
|
@@ -1382,5 +1383,17 @@ public Dictionary<string, Dependency> LoadDependencies( | |
} | ||
return dependencyMap; | ||
} | ||
|
||
/// <summary> | ||
/// Extracts the version number from the filename handling filenames like foo-1.2.3-alpha. | ||
/// </summary> | ||
/// <param name="filename">File name without extension to extract from.</param> | ||
/// <returns>The version string if extracted successfully and null otherwise.</returns> | ||
private static string ExtractVersionFromFileName(string filename) | ||
{ | ||
var match = System.Text.RegularExpressions.Regex.Match( | ||
filename, "^([0-9.]+)"); | ||
return match.Success ? match.Groups[1].Value : null; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you need this. The previous code attempted to extract the version from the filename and if the match succeeds then jumps into the block below and pulls the version from match.Groups[1].Value. Did you see a problem in this code path or was this just a clean up?