Skip to content

Commit 9bc20be

Browse files
committed
Address review feedback.
1 parent e35b885 commit 9bc20be

File tree

6 files changed

+42
-32
lines changed

6 files changed

+42
-32
lines changed

src/Java.Interop.Tools.Maven/Extensions/PropertyStack.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public void Pop ()
3232

3333
public string Apply (string value)
3434
{
35+
if (stack.Count == 0 || !value.Contains ("${"))
36+
return value;
37+
3538
foreach (var property_set in stack) {
3639
foreach (var prop in property_set)
3740
value = value.Replace ($"${{{prop.Key}}}", prop.Value);

src/Java.Interop.Tools.Maven/Models/Project.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// https://github.com/mganss/XmlSchemaClassGenerator
1111
// This code was generated by XmlSchemaClassGenerator version 2.1.1057.0 using the following command:
1212
// xscgen maven-4.0.0.xsd --nullable --nc --nr
13+
// Schema from: https://maven.apache.org/xsd/maven-4.0.0.xsd
1314
namespace Java.Interop.Tools.Maven.Models
1415
{
1516

@@ -226,7 +227,7 @@ public bool LicensesSpecified
226227
/// <summary>
227228
/// <para xml:lang="en">Initializes a new instance of the <see cref="Model" /> class.</para>
228229
/// </summary>
229-
public Project()
230+
internal Project()
230231
{
231232
this._licenses = new System.Collections.ObjectModel.Collection<License>();
232233
this._developers = new System.Collections.ObjectModel.Collection<Developer>();

src/Java.Interop.Tools.Maven/Repositories/CachedMavenRepository.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ public bool TryGetFilePath (Artifact artifact, string filename, [NotNullWhen (tr
4747
return true;
4848
}
4949

50-
Directory.CreateDirectory (directory);
51-
5250
if (repository.TryGetFile (artifact, filename, out var repo_stream)) {
53-
using (var sw = File.Create (file))
54-
repo_stream!.CopyTo (sw);
51+
Directory.CreateDirectory (directory);
5552

56-
using (repo_stream) { }
53+
using (var sw = File.Create (file))
54+
using (repo_stream)
55+
repo_stream.CopyTo (sw);
5756

5857
path = file;
5958
return true;
@@ -70,13 +69,13 @@ public bool TryGetFilePath (Artifact artifact, string filename, [NotNullWhen (tr
7069
if (File.Exists (file))
7170
return file;
7271

73-
Directory.CreateDirectory (directory);
74-
7572
if (repository.TryGetFile (artifact, filename, out var repo_stream)) {
73+
Directory.CreateDirectory (directory);
74+
7675
using (var sw = File.Create (file))
77-
await repo_stream!.CopyToAsync (sw, 81920, cancellationToken);
76+
using (repo_stream)
77+
await repo_stream.CopyToAsync (sw, 81920, cancellationToken);
7878

79-
using (repo_stream) { }
8079

8180
return file;
8281
}

src/Java.Interop.Tools.Maven/Repositories/IMavenRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace Java.Interop.Tools.Maven.Repositories;
66

77
public interface IMavenRepository
88
{
9-
// This name is used for on-disk caching purposes, and thus must be compatible with file system naming rules.
9+
// The on-disk cache for this repository will be in a sub-directory with this name, and thus must be
10+
// compatible with file system naming rules. For example, "central" or "google".
1011
string Name { get; }
1112
bool TryGetFile (Artifact artifact, string filename, [NotNullWhen (true)] out Stream? stream);
1213
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Diagnostics.CodeAnalysis;
32
using System.IO;
43
using System.Net.Http;
@@ -9,30 +8,31 @@ namespace Java.Interop.Tools.Maven.Repositories;
98
public class MavenRepository : IMavenRepository
109
{
1110
readonly string base_url;
12-
readonly HttpClient client;
11+
static readonly HttpClient client;
1312

1413
public string Name { get; }
1514

1615
public MavenRepository (string baseUrl, string name)
1716
{
1817
Name = name;
19-
base_url = baseUrl;
18+
base_url = baseUrl.TrimEnd ('/');
19+
}
2020

21-
client = new HttpClient {
22-
BaseAddress = new Uri (base_url)
23-
};
21+
static MavenRepository ()
22+
{
23+
client = new HttpClient ();
2424
}
2525

2626
public bool TryGetFile (Artifact artifact, string filename, [NotNullWhen (true)] out Stream? stream)
2727
{
2828
// ex: https://repo1.maven.org/maven2/dev/chrisbanes/snapper/snapper/0.3.0/{filename}
29-
var file = $"{artifact.GroupId.Replace ('.', '/')}/{artifact.Id}/{artifact.Version}/{filename}";
29+
var file = $"{base_url}/{artifact.GroupId.Replace ('.', '/')}/{artifact.Id}/{artifact.Version}/{filename}";
3030
stream = client.GetStreamAsync (file).Result;
3131

3232
return true;
3333
}
3434

35-
public static MavenRepository Google = new MavenRepository ("https://dl.google.com/android/maven2/", "google");
35+
public static readonly MavenRepository Google = new MavenRepository ("https://dl.google.com/android/maven2/", "google");
3636

37-
public static MavenRepository Central = new MavenRepository ("https://repo1.maven.org/maven2/", "central");
37+
public static readonly MavenRepository Central = new MavenRepository ("https://repo1.maven.org/maven2/", "central");
3838
}

tests/Java.Interop.Tools.Maven-Tests/Extensions/TestDataExtensions.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ static class TestDataExtensions
77
{
88
public static Project CreateProject (Artifact artifact, Project? parent = null)
99
{
10-
var p = new Project {
11-
GroupId = artifact.GroupId,
12-
ArtifactId = artifact.Id,
13-
Version = artifact.Version,
14-
};
10+
var xml = new XDocument (
11+
new XElement ("project",
12+
new XElement ("modelVersion", "4.0.0"),
13+
new XElement ("groupId", artifact.GroupId),
14+
new XElement ("artifactId", artifact.Id),
15+
new XElement ("version", artifact.Version)
16+
)
17+
);
1518

16-
if (parent is not null)
17-
p.Parent = new Parent {
18-
GroupId = parent.GroupId,
19-
ArtifactId = parent.ArtifactId,
20-
Version = parent.Version,
21-
};
19+
if (parent is not null) {
20+
var parent_xml = new XElement ("parent",
21+
new XElement ("groupId", parent.GroupId),
22+
new XElement ("artifactId", parent.ArtifactId),
23+
new XElement ("version", parent.Version)
24+
);
2225

23-
return p;
26+
xml.Root!.Add (parent_xml);
27+
}
28+
29+
return Project.ParseXml (xml.ToString ());
2430
}
2531

2632
public static void AddProperty (this Project project, string key, string value)

0 commit comments

Comments
 (0)