Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Contributor

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?

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
Expand All @@ -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);
Expand Down Expand Up @@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency.BestVersion should be the version string so in both cases this will be either a version string or an empty string see https://github.com/googlesamples/unity-jar-resolver/blob/master/source/JarResolverLib/src/Google.JarResolver/Dependency.cs#L158

Why did you need to change this to extract the version from the filename? Are you seeing a file name sneak into this version field?

oldDepFilenamePair.Key.BestVersion);
string newVersion = ExtractVersionFromFileName(dep.BestVersion);
if ((oldVersion == null || (newVersion != null && oldVersion != newVersion)) &&
(confirmer == null || confirmer(oldDepFilenamePair.Key, dep))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stack trace reported in bug #48 starts here and bubbles up through to Resolver1_1.AarPathToPackageName where - from your report - the filename was null and therefore caused a null reference exception. Which suggests https://github.com/googlesamples/unity-jar-resolver/blob/master/source/PlayServicesResolver/src/ResolverVer1_1.cs#L723 is returning a null path (as artifactPath) instead.

DeleteExistingFileOrDirectory(oldDepFilenamePair.Value,
includeMetaFiles: true);
Expand Down Expand Up @@ -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;
}
}
}