Skip to content

Commit

Permalink
Resolve conflicts when two csdl names have similar suffixes (#407)
Browse files Browse the repository at this point in the history
* Select best match when multiple resources match target csdl

* Fix tests

* Update VB code generation

* Make name conflict resolution more efficient
  • Loading branch information
habbes authored Sep 10, 2024
1 parent 55a4768 commit a58b8c2
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 15 deletions.
13 changes: 11 additions & 2 deletions src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5121,7 +5121,11 @@ internal override void WriteGeneratedEdmModel(string escapedEdmxString)
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down Expand Up @@ -7297,7 +7301,12 @@ End Function
Private Shared Function CreateXmlReader() As Global.System.Xml.XmlReader
Try
Dim assembly As Global.System.Reflection.Assembly = Global.System.Reflection.Assembly.GetExecutingAssembly()
Dim resourcePath As Global.System.String = Global.System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), Function(str) str.EndsWith(filePath))
' If multiple resource names end with the file name, select the shortest one.
Dim resourcePath As Global.System.String =
Global.System.Linq.Enumerable.First(
Global.System.Linq.Enumerable.OrderBy(
Global.System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), Function(name) name.EndsWith(filePath)),
Function(filteredName) filteredName.Length))
Dim stream As Global.System.IO.Stream = assembly.GetManifestResourceStream(resourcePath)
Return Global.System.Xml.XmlReader.Create(New Global.System.IO.StreamReader(stream))
Catch e As Global.System.Xml.XmlException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4683,7 +4683,11 @@ namespace <#= fullNamespace #>
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down Expand Up @@ -5870,7 +5874,12 @@ Namespace <#= fullNamespace #>
Private Shared Function CreateXmlReader() As Global.System.Xml.XmlReader
Try
Dim assembly As Global.System.Reflection.Assembly = Global.System.Reflection.Assembly.GetExecutingAssembly()
Dim resourcePath As Global.System.String = Global.System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), Function(str) str.EndsWith(filePath))
' If multiple resource names end with the file name, select the shortest one.
Dim resourcePath As Global.System.String =
Global.System.Linq.Enumerable.First(
Global.System.Linq.Enumerable.OrderBy(
Global.System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), Function(name) name.EndsWith(filePath)),
Function(filteredName) filteredName.Length))
Dim stream As Global.System.IO.Stream = assembly.GetManifestResourceStream(resourcePath)
Return Global.System.Xml.XmlReader.Create(New Global.System.IO.StreamReader(stream))
Catch e As Global.System.Xml.XmlException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,11 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(
global::System.Linq.Enumerable.Where(assembly.GetManifestResourceNames(), name => name.EndsWith(filePath)),
filteredName => filteredName.Length));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down

0 comments on commit a58b8c2

Please sign in to comment.