Skip to content

Commit 7b8a54c

Browse files
committed
Address review feedback.
1 parent 9b71bd2 commit 7b8a54c

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ public class Package
348348
public class NuGetPackageVersionFinder
349349
{
350350
readonly LockFile lock_file;
351-
readonly Regex tag = new Regex ("artifact_versioned=(?<GroupId>.+)?:(?<ArtifactId>.+?):(?<Version>.+)\\s?", RegexOptions.Compiled);
352-
readonly Regex tag2 = new Regex ("artifact=(?<GroupId>.+)?:(?<ArtifactId>.+?):(?<Version>.+)\\s?", RegexOptions.Compiled);
351+
readonly static Regex tag = new Regex (@"artifact(?:_versioned)?=(?<GroupId>[^:\s;,]+):(?<ArtifactId>[^:\s;,]+):(?<Version>[^:\s;,]+)", RegexOptions.Compiled, TimeSpan.FromSeconds (1));
353352

354353
NuGetPackageVersionFinder (LockFile lockFile)
355354
{
@@ -402,25 +401,24 @@ void AddArtifactsFromNuspec (List<Artifact> artifacts, string nugetPackagePath,
402401
var reader = new NuGet.Packaging.NuspecReader (nuspec);
403402
var tags = reader.GetTags ();
404403

405-
// Try the first tag format
406-
AddMatchesToCollection (artifacts, tag.Matches (tags));
407-
408-
// Try the second tag format
409-
AddMatchesToCollection (artifacts, tag2.Matches (tags));
404+
AddArtifactsFromNuspecTags (artifacts, tags);
410405

411406
// TODO: Define a well-known file that can be included in the package like "java-package.txt"
412407
}
413408

414-
void AddMatchesToCollection (List<Artifact> list, MatchCollection? matches)
409+
public static void AddArtifactsFromNuspecTags (List<Artifact> artifacts, string tags)
415410
{
411+
// Try the first tag format
412+
var matches = tag.Matches (tags);
413+
416414
if (matches is null || matches.Count == 0)
417415
return;
418416

419417
foreach (Match match in matches) {
420418
var artifact = new Artifact (match.Groups ["GroupId"].Value, match.Groups ["ArtifactId"].Value, match.Groups ["Version"].Value);
421419

422-
if (!list.Any (a => a.VersionedArtifactString == artifact.VersionedArtifactString))
423-
list.Add (artifact);
420+
if (!artifacts.Any (a => a.VersionedArtifactString == artifact.VersionedArtifactString))
421+
artifacts.Add (artifact);
424422
}
425423
}
426424
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/JavaDependencyVerificationTests.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void DependencyFulfilledByProjectReferenceExplicitMetadata ()
212212
],
213213
ProjectReferences = [
214214
CreateAndroidLibraryTaskItem ("Google.Material.Core.csproj", null, "com.google.android:material-core:1.0"),
215-
CreateAndroidLibraryTaskItem ("Google.Material.Foo.csproj", null, "org.jetbrains.kotlin:kotlin-stdlib:2.0.0,com.google.android:material-foo:1.0"),
215+
CreateAndroidLibraryTaskItem ("Google.Material.Foo.csproj", null, "org.jetbrains.kotlin:kotlin-stdlib:2.0.0;com.google.android:material-foo:1.0"),
216216
],
217217
};
218218

@@ -238,7 +238,7 @@ public void DependencyFulfilledByPackageReferenceExplicitMetadata ()
238238
],
239239
PackageReferences = [
240240
CreateAndroidLibraryTaskItem ("Xamarin.Google.Material.Core", null, "com.google.android:material-core:1.0"),
241-
CreateAndroidLibraryTaskItem ("Xamarin.Google.Material.Foo", null, "org.jetbrains.kotlin:kotlin-stdlib:2.0.0,com.google.android:material-foo:1.0"),
241+
CreateAndroidLibraryTaskItem ("Xamarin.Google.Material.Foo", null, "org.jetbrains.kotlin:kotlin-stdlib:2.0.0 com.google.android:material-foo:1.0"),
242242
],
243243
};
244244

@@ -264,7 +264,7 @@ public void DependencyIgnored ()
264264
],
265265
IgnoredDependencies = [
266266
CreateAndroidLibraryTaskItem ("com.google.android:material-core:1.0"),
267-
CreateAndroidLibraryTaskItem ("org.jetbrains.kotlin:kotlin-stdlib:2.0.0,com.google.android:material-foo:1.0"),
267+
CreateAndroidLibraryTaskItem ("org.jetbrains.kotlin:kotlin-stdlib:2.0.0\r\ncom.google.android:material-foo:1.0"),
268268
],
269269
};
270270

@@ -320,6 +320,26 @@ public void DependencyWithoutVersionNotFulfilled ()
320320
Assert.AreEqual ("Java dependency 'com.google.android:material-core' is not satisfied.", engine.Errors [0].Message);
321321
}
322322

323+
[TestCase ("artifact_versioned=androidx.core:core:1.2.0", "androidx.core:core:1.2.0")]
324+
[TestCase ("artifact_versioned=androidx.core:core", "")] // Invalid specification
325+
[TestCase ("artifact_versioned=androidx.core:core:1.2.0 artifact_versioned=androidx.core:core:1.2.0", "androidx.core:core:1.2.0")] // Duplicates are ignored
326+
[TestCase ("artifact_versioned=androidx.core:core:1.2.0 artifact_versioned=androidx.window.extensions.core:core:1.0.0", "androidx.core:core:1.2.0|androidx.window.extensions.core:core:1.0.0")]
327+
[TestCase ("artifact_versioned=androidx.core:core:1.2.0 artifact=androidx.window.extensions.core:core:1.13.1", "androidx.core:core:1.2.0|androidx.window.extensions.core:core:1.13.1")]
328+
[TestCase ("artifact=androidx.core:core:1.2.0 artifact=androidx.window.extensions.core:core:1.13.1", "androidx.core:core:1.2.0|androidx.window.extensions.core:core:1.13.1")]
329+
public void AddArtifactsFromNuspecTagsTests (string tags, string expected)
330+
{
331+
var results = new List<Artifact> ();
332+
333+
NuGetPackageVersionFinder.AddArtifactsFromNuspecTags (results, tags);
334+
335+
if (!expected.HasValue ()) {
336+
Assert.IsEmpty (results);
337+
return;
338+
}
339+
340+
Assert.AreEqual (expected, string.Join ("|", results.Select (p => p.VersionedArtifactString)));
341+
}
342+
323343
TaskItem CreateAndroidLibraryTaskItem (string name, string? manifest = null, string? javaArtifact = null)
324344
{
325345
var item = new TaskItem (name);

src/Xamarin.Android.Build.Tasks/Utilities/MavenExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Xamarin.Android.Tasks;
1818
static class MavenExtensions
1919
{
2020
static readonly char [] separator = [':'];
21-
static readonly char [] artifacts_separators = [';', ',', '\r', '\n'];
21+
static readonly char [] artifacts_separators = [';', ',', '\r', '\n', '\t', ' '];
2222

2323
/// <summary>
2424
/// Shortcut for !string.IsNullOrWhiteSpace (s)

0 commit comments

Comments
 (0)