Fix bug #576579.
* CreateManifestResourceName.cs: Use TargetPath metadata, as the link
name.
* CreateCSharpManifestResourceName.cs:
* CreateVisualBasicManifestResourceName.cs: Prefer linkname over
filename, if available.
In class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks:
* CreateCSharpManifestResourceNameTest.cs:
* CreateVisualBasicManifestResourceNameTest.cs:
Add new tests for TargetPath metadata.
In class/Microsoft.Build.Tasks/Test/resources:
* junk.txt: New.
svn path=/trunk/mcs/; revision=150924
+2010-02-05 Ankit Jain <jankit@novell.com>
+
+ Fix bug #576579.
+ * CreateManifestResourceName.cs: Use TargetPath metadata, as the link
+ name.
+ * CreateCSharpManifestResourceName.cs:
+ * CreateVisualBasicManifestResourceName.cs: Prefer linkname over
+ filename, if available.
+
2010-02-04 Ankit Jain <jankit@novell.com>
* WriteLinesToFile.cs: Delete the file if there is nothing to
string dependentUponFileName,
Stream binaryStream)
{
+ string filename_to_use = String.IsNullOrEmpty (linkFileName) ? fileName : linkFileName;
if (String.IsNullOrEmpty (dependentUponFileName) || binaryStream == null)
- return GetResourceIdFromFileName (fileName, rootNamespace);
+ return GetResourceIdFromFileName (filename_to_use, rootNamespace);
string ns = null;
string classname = null;
}
if (classname == null)
- return GetResourceIdFromFileName (fileName, rootNamespace);
+ return GetResourceIdFromFileName (filename_to_use, rootNamespace);
string culture, extn, only_filename;
- if (AssignCulture.TrySplitResourceName (fileName, out only_filename, out culture, out extn))
+ if (AssignCulture.TrySplitResourceName (filename_to_use, out only_filename, out culture, out extn))
extn = "." + culture;
else
extn = String.Empty;
manifestResourceNames [i] = new TaskItem (item);
manifestResourceNames [i].ItemSpec = CreateManifestName (
- filename, null, rootNamespace,
+ filename, item.GetMetadata ("TargetPath"), rootNamespace,
dependentUponFileName, binaryStream);
} finally {
if (binaryStream != null)
string dependentUponFileName,
Stream binaryStream)
{
+ string filename_to_use = String.IsNullOrEmpty (linkFileName) ? fileName : linkFileName;
if (String.IsNullOrEmpty (dependentUponFileName) || binaryStream == null)
return GetResourceIdFromFileName
- (Path.GetFileName (fileName), rootNamespace);
+ (Path.GetFileName (filename_to_use), rootNamespace);
string ns = null;
string classname = null;
}
if (classname == null)
- return GetResourceIdFromFileName (fileName, rootNamespace);
+ return GetResourceIdFromFileName (filename_to_use, rootNamespace);
string culture, extn, only_filename;
- if (AssignCulture.TrySplitResourceName (fileName, out only_filename, out culture, out extn))
+ if (AssignCulture.TrySplitResourceName (filename_to_use, out only_filename, out culture, out extn))
extn = "." + culture;
else
extn = String.Empty;
+2010-02-05 Ankit Jain <jankit@novell.com>
+
+ * CreateCSharpManifestResourceNameTest.cs:
+ * CreateVisualBasicManifestResourceNameTest.cs:
+ Add new tests for TargetPath metadata.
+
2010-02-04 Ankit Jain <jankit@novell.com>
* WriteLinesToFileTest.cs: New.
public CreateCSharpManifestResourceNameTest ()
{
string sample_cs_path = Path.Combine ("Test", Path.Combine ("resources", "Sample.cs"));
+ string junk_file = Path.Combine ("Test", Path.Combine ("resources", "junk.txt"));
+ string curdir = Path.GetDirectoryName (Environment.CurrentDirectory);
+
+ /* {Include, LogicalName, DependentUpon, TargetPath} */
resx_no_culture_files = new string [,] {
// With dependent file
- { "foo with space.resx", null, sample_cs_path },
- { "foo with space.resx", "RandomName", sample_cs_path },
+ { "foo with space.resx", null, sample_cs_path, null },
+ { "foo with space.resx", "RandomName", sample_cs_path, null },
+ { "foo with space.resx", "RandomName", sample_cs_path, "bar with space.resx" },
+
+ // can't find a C# class in the .vb file
+ { "foo with space.resx", "RandomName", junk_file, "bar with space.resx" },
- { "Test/resources/foo with space.resx", null, "Sample.cs" },
- { "Test/resources/foo with space.resx", "RandomName", "Sample.cs" },
+ { "Test/resources/foo with space.resx", null, "Sample.cs", null },
+ { "Test/resources/foo with space.resx", "RandomName", "Sample.cs", null },
+ { "Test/resources/foo with space.resx", "RandomName", "Sample.cs", "bar with space.resx"},
// W/o dependent file
- { "foo with space.resx", null, null },
- { "foo with space.resx", "RandomName", null },
+ { "foo with space.resx", null, null, null },
+ { "foo with space.resx", "RandomName", null, null },
- { "Test/resources folder/foo with space.resx", null, null },
- { "Test/resources folder/foo with space.resx", "RandomName", null },
+ { "Test/resources folder/foo with space.resx", null, null, null },
+ { "Test/resources folder/foo with space.resx", "RandomName", null, null },
};
resx_with_culture_files = new string [,] {
// With dependent file
- { "foo with space.de.resx", null, sample_cs_path },
- { "foo with space.de.resx", "RandomName", sample_cs_path },
+ { "foo with space.de.resx", null, sample_cs_path, null },
+ { "foo with space.de.resx", "RandomName", sample_cs_path, null },
+ { "foo with space.de.resx", "RandomName", sample_cs_path, "bar with space.fr.resx" },
+
+ // can't find a C# class in the .vb file
+ { "foo with space.de.resx", "RandomName", junk_file, "bar with space.fr.resx" },
- { "Test/resources/foo with space.de.resx", null, "Sample.cs" },
- { "Test/resources/foo with space.de.resx", "RandomName", "Sample.cs" },
+ { "Test/resources/foo with space.de.resx", null, "Sample.cs", null },
+ { "Test/resources/foo with space.de.resx", "RandomName", "Sample.cs", null},
// W/o dependent file
- { "foo with space.de.resx", null, null },
- { "foo with space.de.resx", "RandomName", null },
+ { "foo with space.de.resx", null, null, null },
+ { "foo with space.de.resx", "RandomName", null, null },
- { "Test/resources folder/foo with space.de.resx", null, null },
- { "Test/resources folder/foo with space.de.resx", "RandomName", null }
+ { "Test/resources folder/foo with space.de.resx", null, null, null },
+ { "Test/resources folder/foo with space.de.resx", "RandomName", null, null }
};
non_resx_no_culture_files = new string [,] {
CheckResourceNames (resx_no_culture_files, new string [] {
// w/ dependent file
"Mono.Tests.Sample", "Mono.Tests.Sample",
+ "Mono.Tests.Sample", "bar with space",
"Mono.Tests.Sample", "Mono.Tests.Sample",
// W/o dependent file
- "foo with space", "foo with space" ,
- "Test.resources_folder.foo with space", "Test.resources_folder.foo with space"}, null);
+ "Mono.Tests.Sample", "foo with space" ,
+ "foo with space", "Test.resources_folder.foo with space",
+ "Test.resources_folder.foo with space",
+ }, null);
}
[Test]
CheckResourceNames (resx_no_culture_files, new string [] {
// With dependent file
"Mono.Tests.Sample", "Mono.Tests.Sample",
+ "Mono.Tests.Sample", "RN1.RN2.bar with space",
"Mono.Tests.Sample", "Mono.Tests.Sample",
+
// W/o dependent file
- "RN1.RN2.foo with space", "RN1.RN2.foo with space",
- "RN1.RN2.Test.resources_folder.foo with space", "RN1.RN2.Test.resources_folder.foo with space"},
+ "Mono.Tests.Sample", "RN1.RN2.foo with space",
+ "RN1.RN2.foo with space", "RN1.RN2.Test.resources_folder.foo with space",
+ "RN1.RN2.Test.resources_folder.foo with space"},
"RN1.RN2");
}
CheckResourceNames (resx_with_culture_files, new string [] {
// With dependent file
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
+ "Mono.Tests.Sample.fr", "bar with space.fr",
+
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
+
// W/o dependent file
"foo with space.de", "foo with space.de",
"Test.resources_folder.foo with space.de", "Test.resources_folder.foo with space.de" }, null);
CheckResourceNames (resx_with_culture_files, new string [] {
// With dependent file
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
+ "Mono.Tests.Sample.fr", "RN1.RN2.bar with space.fr",
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
// W/o dependent file
"RN1.RN2.foo with space.de", "RN1.RN2.foo with space.de",
CheckResourceNames (non_resx_with_culture_files, new string [] {
Path.Combine ("de", "foo with space.txt"), Path.Combine ("de", "foo with space.txt"),
Path.Combine ("de", "Test.resources_folder.foo with space.txt"), Path.Combine ("de", "Test.resources_folder.foo with space.txt")}, null);
+
}
[Test]
"RN1.RN2");
}
+ [Test]
+ public void TestExternalResourcesNoRootNamespaceWithTargetPath ()
+ {
+ CheckResourceNames (new string[,] {
+ {"../folder/foo.txt", null, null, "abc.txt"},
+ {"../folder/foo.de.txt", null, null, "xyz.txt"}},
+ new string[] { "abc.txt", "xyz.txt" }, null);
+ }
+
+ [Test]
+ public void TestExternalResourcesWithRootNamespaceWithTargetPath ()
+ {
+ CheckResourceNames (new string[,] {
+ {"../folder/foo.txt", null, null, "abc.txt"},
+ {"../folder/foo.de.txt", null, null, "xyz.txt"}},
+ new string[] { "RN.abc.txt", "RN.xyz.txt" }, "RN");
+ }
+
+ [Test]
+ public void TestExternalResourcesNoRootNamespaceNoTargetPath ()
+ {
+ CheckResourceNames (new string[,] {
+ {"../folder/foo.txt", null, null},
+ {"../folder/foo.de.txt", null, null}},
+ new string[] { "...folder.foo.txt", Path.Combine ("de", "...folder.foo.txt") }, null);
+ }
+
+ [Test]
+ public void TestExternalResourcesWithRootNamespaceNoTargetPath ()
+ {
+ CheckResourceNames (new string[,] {
+ {"../folder/foo.txt", null, null},
+ {"../folder/foo.de.txt", null, null}},
+ new string[] { "RN....folder.foo.txt", Path.Combine ("de", "RN....folder.foo.txt") }, "RN");
+ }
+
[Test]
public void TestInvalidCulture ()
{
Assert.Fail ("Build failed");
}
+ bool has_targetpaths = files.GetUpperBound (1) == 3;
BuildItemGroup group = project.GetEvaluatedItemsByName ("ResourceNames");
Assert.AreEqual (names.Length, group.Count, "A2");
for (int i = 0; i <= files.GetUpperBound (0); i++) {
Assert.AreEqual (files [i, 2] != null, group [i].HasMetadata ("DependentUpon"), "A6 #" + (i + 1));
if (files [i, 2] != null)
Assert.AreEqual (files [i, 2], group [i].GetMetadata ("DependentUpon"), "A7 #" + (i + 1));
+ if (has_targetpaths && files [i, 3] != null)
+ Assert.AreEqual (files [i, 3], group [i].GetMetadata ("TargetPath"), "A8 #" + (i + 1));
}
}
StringBuilder sb = new StringBuilder ();
sb.Append ("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
+ bool has_targetpaths = files.GetUpperBound (1) == 3;
sb.Append ("\t<ItemGroup>\n");
for (int i = 0; i <= files.GetUpperBound (0); i ++) {
sb.AppendFormat ("\t\t<ResourceFiles Include = \"{0}\">\n", files [i, 0]);
+ if (has_targetpaths && files [i, 3] != null)
+ sb.AppendFormat ("\t\t\t<TargetPath>{0}</TargetPath>\n", files [i, 3]);
if (files [i, 1] != null)
sb.AppendFormat ("\t\t\t<LogicalName>{0}</LogicalName>\n", files [i, 1]);
if (files [i, 2] != null)
+
using System;
using System.Collections.Generic;
using System.IO;
{
string [,] resx_no_culture_files, resx_with_culture_files;
- string [,] non_resx_no_culture_files, non_resx_with_culture_files;
-
+ string [,] non_resx_no_culture_files, non_resx_with_culture_files;
public CreateVisualBasicManifestResourceNameTest ()
{
+ string junk_file = Path.Combine ("Test", Path.Combine ("resources", "junk.txt"));
string sample_vb_path = Path.Combine ("Test", Path.Combine ("resources", "Sample.vb"));
+ string curdir = Path.GetDirectoryName (Environment.CurrentDirectory);
+
+ /* {Include, LogicalName, DependentUpon, TargetPath} */
resx_no_culture_files = new string [,] {
// With dependent file
- { "foo with space.resx", null, sample_vb_path },
- { "foo with space.resx", "RandomName", sample_vb_path },
+ { "foo with space.resx", null, sample_vb_path, null },
+ { "foo with space.resx", "RandomName", sample_vb_path, null },
+ { "foo with space.resx", "RandomName", sample_vb_path, "bar with space.resx" },
+
+ // can't find a C# class in the .vb file
+ { "foo with space.resx", "RandomName", junk_file, "bar with space.resx" },
- { "Test/resources/foo with space.resx", null, "Sample.vb" },
- { "Test/resources/foo with space.resx", "RandomName", "Sample.vb" },
+ { "Test/resources/foo with space.resx", null, "Sample.vb", null },
+ { "Test/resources/foo with space.resx", "RandomName", "Sample.vb", null },
+ { "Test/resources/foo with space.resx", "RandomName", "Sample.vb", "bar with space.resx"},
// W/o dependent file
- { "foo with space.resx", null, null },
- { "foo with space.resx", "RandomName", null },
+ { "foo with space.resx", null, null, null },
+ { "foo with space.resx", "RandomName", null, null },
- { "Test/resources/foo with space.resx", null, null },
- { "Test/resources/foo with space.resx", "RandomName", null },
+ { "Test/resources folder/foo with space.resx", null, null, null },
+ { "Test/resources folder/foo with space.resx", "RandomName", null, null },
};
resx_with_culture_files = new string [,] {
// With dependent file
- { "foo with space.de.resx", null, sample_vb_path },
- { "foo with space.de.resx", "RandomName", sample_vb_path },
+ { "foo with space.de.resx", null, sample_vb_path, null },
+ { "foo with space.de.resx", "RandomName", sample_vb_path, null },
+ { "foo with space.de.resx", "RandomName", sample_vb_path, "bar with space.fr.resx" },
- { "Test/resources/foo with space.de.resx", null, "Sample.vb" },
- { "Test/resources/foo with space.de.resx", "RandomName", "Sample.vb" },
+ // can't find a C# class in the .vb file
+ { "foo with space.de.resx", "RandomName", junk_file, "bar with space.fr.resx" },
+
+ { "Test/resources/foo with space.de.resx", null, "Sample.vb", null },
+ { "Test/resources/foo with space.de.resx", "RandomName", "Sample.vb", null},
// W/o dependent file
- { "foo with space.de.resx", null, null },
- { "foo with space.de.resx", "RandomName", null },
+ { "foo with space.de.resx", null, null, null },
+ { "foo with space.de.resx", "RandomName", null, null },
- { "Test/resources folder/foo with space.de.resx", null, null },
- { "Test/resources folder/foo with space.de.resx", "RandomName", null }
+ { "Test/resources folder/foo with space.de.resx", null, null, null },
+ { "Test/resources folder/foo with space.de.resx", "RandomName", null, null }
};
non_resx_no_culture_files = new string [,] {
CheckResourceNames (resx_no_culture_files, new string [] {
// w/ dependent file
"Mono.Tests.Sample", "Mono.Tests.Sample",
+ "Mono.Tests.Sample", "bar with space",
"Mono.Tests.Sample", "Mono.Tests.Sample",
// W/o dependent file
- "foo with space", "foo with space" ,
- "foo with space", "foo with space"}, null);
+ "Mono.Tests.Sample", "foo with space" ,
+ "foo with space", "foo with space",
+ "foo with space",
+ }, null);
}
[Test]
CheckResourceNames (resx_no_culture_files, new string [] {
// With dependent file
"RN1.RN2.Mono.Tests.Sample", "RN1.RN2.Mono.Tests.Sample",
+ "RN1.RN2.Mono.Tests.Sample", "RN1.RN2.bar with space",
"RN1.RN2.Mono.Tests.Sample", "RN1.RN2.Mono.Tests.Sample",
+
// W/o dependent file
+ "RN1.RN2.Mono.Tests.Sample", "RN1.RN2.foo with space",
"RN1.RN2.foo with space", "RN1.RN2.foo with space",
- "RN1.RN2.foo with space", "RN1.RN2.foo with space"},
+ "RN1.RN2.foo with space"},
"RN1.RN2");
}
CheckResourceNames (resx_with_culture_files, new string [] {
// With dependent file
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
+ "Mono.Tests.Sample.fr", "bar with space.fr",
+
"Mono.Tests.Sample.de", "Mono.Tests.Sample.de",
+
// W/o dependent file
"foo with space.de", "foo with space.de",
"foo with space.de", "foo with space.de" }, null);
CheckResourceNames (resx_with_culture_files, new string [] {
// With dependent file
"RN1.RN2.Mono.Tests.Sample.de", "RN1.RN2.Mono.Tests.Sample.de",
+ "RN1.RN2.Mono.Tests.Sample.fr", "RN1.RN2.bar with space.fr",
"RN1.RN2.Mono.Tests.Sample.de", "RN1.RN2.Mono.Tests.Sample.de",
// W/o dependent file
"RN1.RN2.foo with space.de", "RN1.RN2.foo with space.de",
CheckResourceNames (non_resx_with_culture_files, new string [] {
Path.Combine ("de", "foo with space.txt"), Path.Combine ("de", "foo with space.txt"),
Path.Combine ("de", "foo with space.txt"), Path.Combine ("de", "foo with space.txt")}, null);
+
}
[Test]
"RN1.RN2");
}
+ [Test]
+ public void TestExternalResourcesNoRootNamespaceWithTargetPath ()
+ {
+ CheckResourceNames (new string[,] {
+ {"../folder/foo.txt", null, null, "abc.txt"},
+ {"../folder/foo.de.txt", null, null, "xyz.txt"}},
+ new string[] { "abc.txt", "xyz.txt" }, null);
+ }
+
+ [Test]
+ public void TestExternalResourcesWithRootNamespaceWithTargetPath ()
+ {
+ CheckResourceNames (new string[,] {
+ {"../folder/foo.txt", null, null, "abc.txt"},
+ {"../folder/foo.de.txt", null, null, "xyz.txt"}},
+ new string[] { "RN.abc.txt", "RN.xyz.txt" }, "RN");
+ }
+
+ [Test]
+ public void TestExternalResourcesNoRootNamespaceNoTargetPath ()
+ {
+ CheckResourceNames (new string[,] {
+ {"../folder/foo.txt", null, null},
+ {"../folder/foo.de.txt", null, null}},
+ new string[] { "foo.txt", Path.Combine ("de", "foo.txt") }, null);
+ }
+
+ [Test]
+ public void TestExternalResourcesWithRootNamespaceNoTargetPath ()
+ {
+ CheckResourceNames (new string[,] {
+ {"../folder/foo.txt", null, null},
+ {"../folder/foo.de.txt", null, null}},
+ new string[] { "RN.foo.txt", Path.Combine ("de", "RN.foo.txt") }, "RN");
+ }
+
+ [Test]
+ public void TestInvalidCulture ()
+ {
+ string [,] files = new string [,] {
+ { "Foo.invalid.txt", null, null },
+ { "Foo.invalid.resx", null, null }
+ };
+ CheckResourceNames (files, new string [] {"RN1.RN2.Foo.invalid.txt", "RN1.RN2.Foo.invalid"},
+ "RN1.RN2");
+ }
+
void CheckResourceNames (string [,] files, string [] names, string rootNamespace)
{
Assert.AreEqual (files.GetUpperBound (0) + 1, names.Length, "Number of files and names must match");
Assert.Fail ("Build failed");
}
+ bool has_targetpaths = files.GetUpperBound (1) == 3;
BuildItemGroup group = project.GetEvaluatedItemsByName ("ResourceNames");
Assert.AreEqual (names.Length, group.Count, "A2");
for (int i = 0; i <= files.GetUpperBound (0); i++) {
Assert.AreEqual (files [i, 2] != null, group [i].HasMetadata ("DependentUpon"), "A6 #" + (i + 1));
if (files [i, 2] != null)
Assert.AreEqual (files [i, 2], group [i].GetMetadata ("DependentUpon"), "A7 #" + (i + 1));
+ if (has_targetpaths && files [i, 3] != null)
+ Assert.AreEqual (files [i, 3], group [i].GetMetadata ("TargetPath"), "A8 #" + (i + 1));
}
}
StringBuilder sb = new StringBuilder ();
sb.Append ("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
+ bool has_targetpaths = files.GetUpperBound (1) == 3;
sb.Append ("\t<ItemGroup>\n");
for (int i = 0; i <= files.GetUpperBound (0); i ++) {
sb.AppendFormat ("\t\t<ResourceFiles Include = \"{0}\">\n", files [i, 0]);
+ if (has_targetpaths && files [i, 3] != null)
+ sb.AppendFormat ("\t\t\t<TargetPath>{0}</TargetPath>\n", files [i, 3]);
if (files [i, 1] != null)
sb.AppendFormat ("\t\t\t<LogicalName>{0}</LogicalName>\n", files [i, 1]);
if (files [i, 2] != null)
+2010-02-05 Ankit Jain <jankit@novell.com>
+
+ * junk.txt: New.
+
2009-04-27 Ankit Jain <jankit@novell.com>
* Sample.vb: New.
--- /dev/null
+Non code file used by Create*ManifestResourceTest .