Author: ankit
Date: 2007-10-08 16:21:46 -0400 (Mon, 08 Oct 2007)
New Revision: 87124

Modified:
   trunk/monodevelop/Core/src/MonoDevelop.Projects/ChangeLog
   
trunk/monodevelop/Core/src/MonoDevelop.Projects/MonoDevelop.Projects/DotNetProject.cs
   trunk/monodevelop/Extras/CSharpBinding/CSharpBindingCompilerManager.cs
   trunk/monodevelop/Extras/CSharpBinding/ChangeLog
   trunk/monodevelop/Extras/VBNetBinding/ChangeLog
   trunk/monodevelop/Extras/VBNetBinding/VBBindingCompilerServices.cs
   trunk/monodevelop/Extras/prj2make-sharp-lib/CSharpResourceIdBuilder.cs
   trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog
   trunk/monodevelop/Extras/prj2make-sharp-lib/Utils.cs
   trunk/monodevelop/Extras/prj2make-sharp-lib/VBNetResourceIdBuilder.cs
Log:
Add support for generating satellite assemblies for localized resources.

In Core/src/MonoDevelop.Projects:

        * MonoDevelop.Projects/DotNetProject.cs (BuildResources): New. Moved
        code for building resources from language bindings, to here.
        (GetResourceId): Likewise.
        (RegexErrorLinePos): Likewise.
        (GenerateSatelliteAssemblies): New. For localized resources.
        (GetCulture): New.
        (CultureNamesTable): New.

In Extras/CSharpBinding:

        * CSharpBindingCompilerManger.cs: Moved code for building resources to
        DotNetProject.

In Extras/VBNetBinding:

        * VBBindingCompilerServices.cs: Removed code for building resources. Its
        done by DotNetProject now.

In Extras/prj2make-sharp-lib:

        * CSharpResourceIdBuilder.cs: Handle localized resources.
        * VBNetResourceIdBuilder.cs: Handle localized resources.
        * Utils.cs (TrySplitResourceName): New.


Modified: trunk/monodevelop/Core/src/MonoDevelop.Projects/ChangeLog
===================================================================
--- trunk/monodevelop/Core/src/MonoDevelop.Projects/ChangeLog   2007-10-08 
20:10:16 UTC (rev 87123)
+++ trunk/monodevelop/Core/src/MonoDevelop.Projects/ChangeLog   2007-10-08 
20:21:46 UTC (rev 87124)
@@ -1,3 +1,13 @@
+2007-10-09  Ankit Jain  <[EMAIL PROTECTED]>
+
+       * MonoDevelop.Projects/DotNetProject.cs (BuildResources): New. Moved
+       code for building resources from language bindings, to here.
+       (GetResourceId): Likewise.
+       (RegexErrorLinePos): Likewise.
+       (GenerateSatelliteAssemblies): New. For localized resources.
+       (GetCulture): New.
+       (CultureNamesTable): New.
+
 2007-10-08  Mike Krüger <[EMAIL PROTECTED]> 
 
        * MonoDevelop.Projects.CodeGeneration/IRefactorer.cs,

Modified: 
trunk/monodevelop/Core/src/MonoDevelop.Projects/MonoDevelop.Projects/DotNetProject.cs
===================================================================
--- 
trunk/monodevelop/Core/src/MonoDevelop.Projects/MonoDevelop.Projects/DotNetProject.cs
       2007-10-08 20:10:16 UTC (rev 87123)
+++ 
trunk/monodevelop/Core/src/MonoDevelop.Projects/MonoDevelop.Projects/DotNetProject.cs
       2007-10-08 20:21:46 UTC (rev 87124)
@@ -6,7 +6,10 @@
 // </file>
 
 using System;
+using System.CodeDom.Compiler;
+using System.Globalization;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
@@ -179,7 +182,7 @@
                                monitor.ReportError (msg, null);
                                return refres;
                        }
-                       
+
                        foreach (ProjectReference pr in ProjectReferences) {
                                DefaultCompilerResult refres = null;
                                if (pr.ReferenceType == ReferenceType.Project) {
@@ -203,11 +206,16 @@
                        DotNetProjectConfiguration conf = 
(DotNetProjectConfiguration) ActiveConfiguration;
                        conf.SourceDirectory = BaseDirectory;
                        
+                       ProjectFileCollection files = ProjectFiles;
+                       ICompilerResult res = BuildResources (conf, ref files, 
monitor);
+                       if (res != null)
+                               return res;
+
                        List<string> supportAssemblies = new List<string> ();
                        CopySupportAssemblies (supportAssemblies);
-                       
+
                        try {
-                               return languageBinding.Compile (ProjectFiles, 
ProjectReferences, conf, monitor);
+                               return languageBinding.Compile (files, 
ProjectReferences, conf, monitor);
                        }
                        finally {
                                // Delete support assemblies
@@ -261,7 +269,234 @@
                                }
                        }
                }
-               
+
+               // Builds the EmbedAsResource files. If any localized resources 
are found then builds the satellite assemblies
+               // and sets @projectFiles to a cloned collection minus such 
resource files.
+               private ICompilerResult BuildResources 
(DotNetProjectConfiguration configuration, ref ProjectFileCollection 
projectFiles, IProgressMonitor monitor)
+               {
+                       string resgen = configuration.ClrVersion == 
ClrVersion.Net_2_0 ? "resgen2" : "resgen";
+                       bool cloned = false;
+                       Dictionary<string, string> resourcesByCulture = new 
Dictionary<string, string> ();
+                       foreach (ProjectFile finfo in projectFiles) {
+                               if (finfo.Subtype == Subtype.Directory || 
finfo.BuildAction != BuildAction.EmbedAsResource)
+                                       continue;
+
+                               string fname = finfo.Name;
+                               string resourceId;
+                               CompilerError ce = GetResourceId (finfo, ref 
fname, resgen, out resourceId, monitor);
+                               if (ce != null) {
+                                       CompilerResults cr = new 
CompilerResults (new TempFileCollection ());
+                                       cr.Errors.Add (ce);
+
+                                       return new DefaultCompilerResult (cr, 
String.Empty);
+                               }
+                               string culture = GetCulture (finfo.Name);
+                               if (culture == null)
+                                       continue;
+
+                               string cmd = String.Empty;
+                               if (resourcesByCulture.ContainsKey (culture))
+                                       cmd = resourcesByCulture [culture];
+
+                               cmd = String.Format ("{0} /embed:{1},{2}", cmd, 
fname, resourceId);
+                               resourcesByCulture [culture] = cmd;
+                               if (!cloned) {
+                                       // Clone only if required
+                                       ProjectFileCollection files = new 
ProjectFileCollection ();
+                                       files.AddRange (projectFiles);
+                                       projectFiles = files;
+                                       cloned = true;
+                               }
+                               projectFiles.Remove (finfo);
+                       }
+
+                       string al = configuration.ClrVersion == 
ClrVersion.Net_2_0 ? "al2" : "al";
+                       CompilerError err = GenerateSatelliteAssemblies 
(resourcesByCulture, configuration.OutputDirectory, al, DefaultNamespace, 
monitor);
+                       if (err != null) {
+                               CompilerResults cr = new CompilerResults (new 
TempFileCollection ());
+                               cr.Errors.Add (err);
+
+                               return new DefaultCompilerResult (cr, 
String.Empty);
+                       }
+
+                       return null;
+               }
+
+               CompilerError GetResourceId (ProjectFile finfo, ref string 
fname, string resgen, out string resourceId, IProgressMonitor monitor)
+               {
+                       resourceId = finfo.ResourceId;
+                       if (resourceId == null) {
+                               Console.WriteLine (GettextCatalog.GetString 
("Error: Unable to build ResourceId for {0}.", fname));
+                               monitor.Log.WriteLine (GettextCatalog.GetString 
("Error: Unable to build ResourceId for {0}.", fname));
+
+                               return new CompilerError (fname, 0, 0, 
String.Empty,
+                                               GettextCatalog.GetString 
("Unable to build ResourceId for {0}.", fname));
+                       }
+
+                       if (String.Compare (Path.GetExtension (fname), ".resx", 
true) != 0)
+                               return null;
+
+                       //Check whether resgen required
+                       FileInfo finfo_resx = new FileInfo (fname);
+                       FileInfo finfo_resources = new FileInfo 
(Path.ChangeExtension (fname, ".resources"));
+                       if (finfo_resx.LastWriteTime < 
finfo_resources.LastWriteTime) {
+                               fname = Path.ChangeExtension (fname, 
".resources");
+                               return null;
+                       }
+
+                       using (StringWriter sw = new StringWriter ()) {
+                               Console.WriteLine ("Compiling resources\n{0}$ 
{1} /compile {2}", Path.GetDirectoryName (fname), resgen, fname);
+                               monitor.Log.WriteLine (GettextCatalog.GetString 
(
+                                       "Compiling resource {0} with {1}", 
fname, resgen));
+                               ProcessWrapper pw = null;
+                               try {
+                                       ProcessStartInfo info = 
Runtime.ProcessService.CreateProcessStartInfo (
+                                                                       resgen, 
String.Format ("/compile \"{0}\"", fname),
+                                                                       
Path.GetDirectoryName (fname), false);
+
+                                       if (PlatformID.Unix == 
Environment.OSVersion.Platform)
+                                               info.EnvironmentVariables 
["MONO_IOMAP"] = "drive";
+
+                                       pw = 
Runtime.ProcessService.StartProcess (info, sw, sw, null);
+                               } catch (System.ComponentModel.Win32Exception 
ex) {
+                                       Console.WriteLine 
(GettextCatalog.GetString (
+                                               "Error while trying to invoke 
'{0}' to compile resource '{1}' :\n {2}", resgen, fname, ex.ToString ()));
+                                       monitor.Log.WriteLine 
(GettextCatalog.GetString (
+                                               "Error while trying to invoke 
'{0}' to compile resource '{1}' :\n {2}", resgen, fname, ex.Message));
+
+                                       return new CompilerError (fname, 0, 0, 
String.Empty, ex.Message);
+                               }
+
+                               //FIXME: Handle exceptions
+                               pw.WaitForOutput ();
+
+                               if (pw.ExitCode == 0) {
+                                       fname = Path.ChangeExtension (fname, 
".resources");
+                               } else {
+                                       string output = sw.ToString ();
+                                       Console.WriteLine 
(GettextCatalog.GetString (
+                                               "Unable to compile ({0}) {1} to 
.resources. \nReason: \n{2}\n",
+                                               resgen, fname, output));
+                                       monitor.Log.WriteLine 
(GettextCatalog.GetString (
+                                               "Unable to compile ({0}) {1} to 
.resources. \nReason: \n{2}\n",
+                                               resgen, fname, output));
+
+                                       //Try to get the line/pos
+                                       int line = 0;
+                                       int pos = 0;
+                                       Match match = RegexErrorLinePos.Match 
(output);
+                                       if (match.Success && match.Groups.Count 
== 3) {
+                                               try {
+                                                       line = int.Parse 
(match.Groups [1].Value);
+                                               } catch (FormatException){
+                                               }
+
+                                               try {
+                                                       pos = int.Parse 
(match.Groups [2].Value);
+                                               } catch (FormatException){
+                                               }
+                                       }
+
+                                       return new CompilerError (fname, line, 
pos, String.Empty, output);
+                               }
+                       }
+
+                       return null;
+               }
+
+               CompilerError GenerateSatelliteAssemblies (Dictionary<string, 
string> resourcesByCulture, string outputDir, string al, string defaultns, 
IProgressMonitor monitor)
+               {
+                       foreach (KeyValuePair<string, string> pair in 
resourcesByCulture) {
+                               string culture = pair.Key;
+                               string satDir = Path.Combine (outputDir, 
culture);
+                               string outputFile = defaultns + 
".resources.dll";
+
+                               //FIXME: don't regen if not required,
+                               //for that we'll need name of the .resources 
that these depend on..
+
+                               //create target dir
+                               Directory.CreateDirectory (satDir);
+
+                               using (StringWriter sw = new StringWriter ()) {
+                                       //generate assembly
+                                       string args = String.Format ("/t:lib 
{0} /out:{1} /culture:{2}", pair.Value, outputFile, culture);
+
+                                       Console.WriteLine ("Generating 
satellite assembly for '{0}' culture.\n{1}$ {2} {3}", culture, satDir, al, 
args);
+                                       monitor.Log.WriteLine 
(GettextCatalog.GetString (
+                                               "Generating satellite assembly 
for '{0}' culture with {1}", culture, al));
+                                       ProcessWrapper pw = null;
+                                       try {
+                                               ProcessStartInfo info = 
Runtime.ProcessService.CreateProcessStartInfo (
+                                                                               
al, args,
+                                                                               
satDir, false);
+
+                                               pw = 
Runtime.ProcessService.StartProcess (info, sw, sw, null);
+                                       } catch 
(System.ComponentModel.Win32Exception ex) {
+                                               Console.WriteLine 
(GettextCatalog.GetString (
+                                                       "Error while trying to 
invoke '{0}' to generate satellite assembly for '{1}' culture:\n {2}", al, 
culture, ex.ToString ()));
+                                               monitor.Log.WriteLine 
(GettextCatalog.GetString (
+                                                       "Error while trying to 
invoke '{0}' to generate satellite assembly for '{1}' culture:\n {2}", al, 
culture, ex.Message));
+
+                                               return new CompilerError ("", 
0, 0, String.Empty, ex.Message);
+                                       }
+
+                                       //FIXME: Handle exceptions
+                                       pw.WaitForOutput ();
+
+                                       if (pw.ExitCode != 0) {
+                                               string output = sw.ToString ();
+                                               Console.WriteLine 
(GettextCatalog.GetString (
+                                                       "Unable to generate 
satellite assemblies for '{0}' culture with {1}.\nReason: \n{2}\n",
+                                                       culture, al, output));
+                                               monitor.Log.WriteLine 
(GettextCatalog.GetString (
+                                                       "Unable to generate 
satellite assemblies for '{0}' culture with {1}.\nReason: \n{2}\n",
+                                                       culture, al, output));
+
+                                               return new CompilerError 
(String.Empty, 0, 0, String.Empty, output);
+                                       }
+                               }
+                       }
+
+                       return null;
+               }
+
+               //Given a filename like foo.it.resx, get 'it', if its
+               //a valid culture
+               //Note: hand-written as this can get called lotsa times
+               //Note: code duplicated in prj2make/Utils.cs as 
TrySplitResourceName
+               string GetCulture (string fname)
+               {
+                       int last_dot = -1;
+                       int culture_dot = -1;
+                       int i = fname.Length - 1;
+                       while (i >= 0) {
+                               if (fname [i] == '.') {
+                                       last_dot = i;
+                                       break;
+                               }
+                               i --;
+                       }
+                       if (i < 0)
+                               return null;
+
+                       i--;
+                       while (i >= 0) {
+                               if (fname [i] == '.') {
+                                       culture_dot = i;
+                                       break;
+                               }
+                               i --;
+                       }
+                       if (culture_dot < 0)
+                               return null;
+
+                       string culture = fname.Substring (culture_dot + 1, 
last_dot - culture_dot - 1);
+                       if (!CultureNamesTable.ContainsKey (culture))
+                               return null;
+
+                       return culture;
+               }
+
                public override string GetOutputFileName ()
                {
                        if (ActiveConfiguration != null) {
@@ -349,6 +584,7 @@
                                        Runtime.FileService.DeleteFile (file + 
".mdb");
                        }
 
+                       List<string> cultures = new List<string> ();
                        monitor.Log.WriteLine (GettextCatalog.GetString 
("Removing all .resources files"));
                        foreach (ProjectFile pfile in ProjectFiles) {
                                if (pfile.BuildAction == 
BuildAction.EmbedAsResource &&
@@ -357,7 +593,22 @@
                                        if (File.Exists (resFilename))
                                                File.Delete (resFilename);
                                }
+                               string culture = GetCulture (pfile.Name);
+                               if (culture != null)
+                                       cultures.Add (culture);
                        }
+
+                       if (cultures.Count > 0 && ActiveConfiguration != null 
&& DefaultNamespace != null) {
+                               monitor.Log.WriteLine (GettextCatalog.GetString 
("Removing all satellite assemblies"));
+                               string outputDir = 
((DotNetProjectConfiguration)ActiveConfiguration).OutputDirectory;
+                               string satelliteAsmName = DefaultNamespace + 
".resources.dll";
+
+                               foreach (string culture in cultures) {
+                                       string path = String.Format 
("{0}{3}{1}{3}{2}", outputDir, culture, satelliteAsmName, 
Path.DirectorySeparatorChar);
+                                       if (File.Exists (path))
+                                               File.Delete (path);
+                               }
+                       }
                }
 
                // Make sure that the project references are valid for the 
target clr version.
@@ -384,5 +635,32 @@
                                ProjectReferences.Add (pref);
                        }
                }
+
+               static Dictionary<string, string> cultureNamesTable;
+               static Dictionary<string, string> CultureNamesTable {
+                       get {
+                               if (cultureNamesTable == null) {
+                                       cultureNamesTable = new 
Dictionary<string, string> ();
+                                       foreach (CultureInfo ci in 
CultureInfo.GetCultures (CultureTypes.AllCultures))
+                                               cultureNamesTable [ci.Name] = 
ci.Name;
+                               }
+
+                               return cultureNamesTable;
+                       }
+               }
+
+               // Used for parsing "Line 123, position 5" errors from tools
+               // like resgen, xamlg
+               static Regex regexErrorLinePos;
+               static Regex RegexErrorLinePos {
+                       get {
+                               if (regexErrorLinePos == null)
+                                       regexErrorLinePos = new Regex (@"Line 
(\d*), position (\d*)");
+                               return regexErrorLinePos;
+                       }
+               }
+
+
+
        }
 }

Modified: trunk/monodevelop/Extras/CSharpBinding/CSharpBindingCompilerManager.cs
===================================================================
--- trunk/monodevelop/Extras/CSharpBinding/CSharpBindingCompilerManager.cs      
2007-10-08 20:10:16 UTC (rev 87123)
+++ trunk/monodevelop/Extras/CSharpBinding/CSharpBindingCompilerManager.cs      
2007-10-08 20:21:46 UTC (rev 87124)
@@ -7,8 +7,10 @@
 
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 using System.Diagnostics;
+using System.Globalization;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.CodeDom.Compiler;
@@ -138,11 +140,6 @@
                                        break;
                        }
                        
-                       string resgen = "resgen";
-                       //ClrVersion.Default ?
-                       if (configuration.ClrVersion == ClrVersion.Net_2_0)
-                               resgen = "resgen2";
-
                        foreach (ProjectFile finfo in projectFiles) {
                                if (finfo.Subtype == Subtype.Directory)
                                        continue;
@@ -152,17 +149,11 @@
                                                writer.WriteLine('"' + 
finfo.Name + '"');
                                                break;
                                        case BuildAction.EmbedAsResource:
-                                               //FIXME: Rationalize the use of 
monitor!
                                                string fname = finfo.Name;
-                                               string resourceId;
-                                               CompilerError ce = 
GetResourceId (finfo, ref fname, resgen, out resourceId, monitor);
-                                               if (ce != null) {
-                                                       CompilerResults cr = 
new CompilerResults (new TempFileCollection ());
-                                                       cr.Errors.Add (ce);
+                                               if (String.Compare 
(Path.GetExtension (fname), ".resx", true) == 0)
+                                                       fname = 
Path.ChangeExtension (fname, ".resources");
 
-                                                       return new 
DefaultCompilerResult (cr, String.Empty);
-                                               }
-                                               
writer.WriteLine(@"""/res:{0},{1}""", fname, resourceId);
+                                               
writer.WriteLine(@"""/res:{0},{1}""", fname, finfo.ResourceId);
                                                break;
                                        default:
                                                continue;
@@ -203,95 +194,13 @@
                        ICompilerResult result = ParseOutput(tf, output, error);
                        if (result.CompilerOutput.Trim () != "")
                                monitor.Log.WriteLine (result.CompilerOutput);
-                       
+
                        Runtime.FileService.DeleteFile (responseFileName);
                        Runtime.FileService.DeleteFile (output);
                        Runtime.FileService.DeleteFile (error);
                        return result;
                }
 
-               CompilerError GetResourceId (ProjectFile finfo, ref string 
fname, string resgen, out string resourceId, IProgressMonitor monitor)
-               {
-                       resourceId = finfo.ResourceId;
-                       if (resourceId == null) {
-                               Console.WriteLine (GettextCatalog.GetString 
("Error: Unable to build ResourceId for {0}.", fname));
-                               monitor.Log.WriteLine (GettextCatalog.GetString 
("Error: Unable to build ResourceId for {0}.", fname));
-
-                               return new CompilerError (fname, 0, 0, 
String.Empty,
-                                               GettextCatalog.GetString 
("Unable to build ResourceId for {0}.", fname));
-                       }
-
-                       if (String.Compare (Path.GetExtension (fname), ".resx", 
true) != 0)
-                               return null;
-
-                       //Check whether resgen required
-                       FileInfo finfo_resx = new FileInfo (fname);
-                       FileInfo finfo_resources = new FileInfo 
(Path.ChangeExtension (fname, ".resources"));
-                       if (finfo_resx.LastWriteTime < 
finfo_resources.LastWriteTime) {
-                               fname = Path.ChangeExtension (fname, 
".resources");
-                               return null;
-                       }
-
-                       using (StringWriter sw = new StringWriter ()) {
-                               Console.WriteLine ("Compiling resources\n{0}$ 
{1} /compile {2}", Path.GetDirectoryName (fname), resgen, fname);
-                               monitor.Log.WriteLine (GettextCatalog.GetString 
(
-                                       "Compiling resource {0} with {1}", 
fname, resgen));
-                               ProcessWrapper pw = null;
-                               try {
-                                       ProcessStartInfo info = 
Runtime.ProcessService.CreateProcessStartInfo (
-                                                                       resgen, 
String.Format ("/compile \"{0}\"", fname),
-                                                                       
Path.GetDirectoryName (fname), false);
-
-                                       if (PlatformID.Unix == 
Environment.OSVersion.Platform)
-                                               info.EnvironmentVariables 
["MONO_IOMAP"] = "drive";
-
-                                       pw = 
Runtime.ProcessService.StartProcess (info, sw, sw, null);
-                               } catch (System.ComponentModel.Win32Exception 
ex) {
-                                       Console.WriteLine 
(GettextCatalog.GetString (
-                                               "Error while trying to invoke 
'{0}' to compile resource '{1}' :\n {2}", resgen, fname, ex.ToString ()));
-                                       monitor.Log.WriteLine 
(GettextCatalog.GetString (
-                                               "Error while trying to invoke 
'{0}' to compile resource '{1}' :\n {2}", resgen, fname, ex.Message));
-
-                                       return new CompilerError (fname, 0, 0, 
String.Empty, ex.Message);
-                               }
-
-                               //FIXME: Handle exceptions
-                               pw.WaitForOutput ();
-
-                               if (pw.ExitCode == 0) {
-                                       fname = Path.ChangeExtension (fname, 
".resources");
-                               } else {
-                                       string output = sw.ToString ();
-                                       Console.WriteLine 
(GettextCatalog.GetString (
-                                               "Unable to compile ({0}) {1} to 
.resources. \nReason: \n{2}\n",
-                                               resgen, fname, output));
-                                       monitor.Log.WriteLine 
(GettextCatalog.GetString (
-                                               "Unable to compile ({0}) {1} to 
.resources. \nReason: \n{2}\n",
-                                               resgen, fname, output));
-
-                                       //Try to get the line/pos
-                                       int line = 0;
-                                       int pos = 0;
-                                       Match match = RegexErrorLinePos.Match 
(output);
-                                       if (match.Success && match.Groups.Count 
== 3) {
-                                               try {
-                                                       line = int.Parse 
(match.Groups [1].Value);
-                                               } catch (FormatException){
-                                               }
-
-                                               try {
-                                                       pos = int.Parse 
(match.Groups [2].Value);
-                                               } catch (FormatException){
-                                               }
-                                       }
-
-                                       return new CompilerError (fname, line, 
pos, String.Empty, output);
-                               }
-                       }
-
-                       return null;
-               }
-
                string GetCompilerName (ClrVersion version)
                {
                        string runtimeDir = 
Runtime.FileService.GetDirectoryNameWithSeparator(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory());
@@ -372,21 +281,11 @@
                        errwr.Close();
                }
 
+
                // Snatched from our codedom code :-).
                static Regex regexError = new Regex 
(@"^(\s*(?<file>.*)\((?<line>\d*)(,(?<column>\d*[\+]*))?\)(:|)\s+)*(?<level>\w+)\s*(?<number>.*):\s(?<message>.*)",
                        RegexOptions.Compiled | RegexOptions.ExplicitCapture);
 
-               // Used for parsing "Line 123, position 5" errors from tools
-               // like resgen, xamlg
-               static Regex regexErrorLinePos;
-               static Regex RegexErrorLinePos {
-                       get {
-                               if (regexErrorLinePos == null)
-                                       regexErrorLinePos = new Regex (@"Line 
(\d*), position (\d*)");
-                               return regexErrorLinePos;
-                       }
-               }
-               
                private static CompilerError CreateErrorFromString(string 
error_string)
                {
                        // When IncludeDebugInformation is true, prevents the 
debug symbols stats from braeking this.
@@ -416,5 +315,6 @@
                        error.ErrorText=match.Result("${message}");
                        return error;
                }
+
        }
 }

Modified: trunk/monodevelop/Extras/CSharpBinding/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/CSharpBinding/ChangeLog    2007-10-08 20:10:16 UTC 
(rev 87123)
+++ trunk/monodevelop/Extras/CSharpBinding/ChangeLog    2007-10-08 20:21:46 UTC 
(rev 87124)
@@ -1,3 +1,8 @@
+2007-10-09  Ankit Jain  <[EMAIL PROTECTED]>
+
+       * CSharpBindingCompilerManger.cs: Moved code for building resources to
+       DotNetProject.
+
 2007-10-08  Mike Krüger <[EMAIL PROTECTED]> 
 
        * Parser/CodeGenerator.cs: fixed "Bug 325223 - Interface refactory 
doesn't

Modified: trunk/monodevelop/Extras/VBNetBinding/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/VBNetBinding/ChangeLog     2007-10-08 20:10:16 UTC 
(rev 87123)
+++ trunk/monodevelop/Extras/VBNetBinding/ChangeLog     2007-10-08 20:21:46 UTC 
(rev 87124)
@@ -1,3 +1,8 @@
+2007-10-09  Ankit Jain  <[EMAIL PROTECTED]>
+
+       * VBBindingCompilerServices.cs: Removed code for building resources. Its
+       done by DotNetProject now.
+
 2007-10-03  Lluis Sanchez Gual <[EMAIL PROTECTED]> 
 
        * VBNetBinding.mdp: Fix warning level.

Modified: trunk/monodevelop/Extras/VBNetBinding/VBBindingCompilerServices.cs
===================================================================
--- trunk/monodevelop/Extras/VBNetBinding/VBBindingCompilerServices.cs  
2007-10-08 20:10:16 UTC (rev 87123)
+++ trunk/monodevelop/Extras/VBNetBinding/VBBindingCompilerServices.cs  
2007-10-08 20:21:46 UTC (rev 87124)
@@ -142,11 +142,6 @@
                                        writer.WriteLine(String.Concat("-r:", 
fileName));
                        }
                        
-                       string resgen = "resgen";
-                       //ClrVersion.Default ?
-                       if (configuration.ClrVersion == ClrVersion.Net_2_0)
-                               resgen = "resgen2";
-
                        // write source files and embedded resources
                        foreach (ProjectFile finfo in projectFiles) {
                                if (finfo.Subtype != Subtype.Directory) {
@@ -156,13 +151,11 @@
                                                break;
                                                
                                                case 
BuildAction.EmbedAsResource:
-                                                       //FIXME: Duplicate of 
code from CSharpBindingCompilerManager
                                                        string fname = 
finfo.Name;
-                                                       string resourceId = 
GetResourceId (finfo, ref fname, resgen, monitor);
-                                                       if (resourceId == null)
-                                                               continue;
+                                                       if (String.Compare 
(Path.GetExtension (fname), ".resx", true) == 0)
+                                                               fname = 
Path.ChangeExtension (fname, ".resources");
 
-                                                       
writer.WriteLine(@"""-resource:{0},{1}""", fname, resourceId);
+                                                       
writer.WriteLine(@"""-resource:{0},{1}""", fname, finfo.ResourceId);
                                                        break;
                                                default:
                                                        continue;
@@ -197,67 +190,6 @@
                        return result;
                }
                
-               string GetResourceId (ProjectFile finfo, ref string fname, 
string resgen, IProgressMonitor monitor)
-               {
-                       string resourceId = finfo.ResourceId;
-                       if (resourceId == null) {
-                               Console.WriteLine ("Warning: Unable to build 
ResourceId for {0}. Ignoring.", fname);
-                               monitor.Log.WriteLine ("Warning: Unable to 
build ResourceId for {0}. Ignoring.", fname);
-                               return null;
-                       }
-
-                       if (String.Compare (Path.GetExtension (fname), ".resx", 
true) != 0)
-                               return resourceId;
-
-                       //Check whether resgen required
-                       FileInfo finfo_resx = new FileInfo (fname);
-                       FileInfo finfo_resources = new FileInfo 
(Path.ChangeExtension (fname, ".resources"));
-                       if (finfo_resx.LastWriteTime < 
finfo_resources.LastWriteTime) {
-                               fname = Path.ChangeExtension (fname, 
".resources");
-                               return null;
-                       }
-
-                       using (StringWriter sw = new StringWriter ()) {
-                               Console.WriteLine ("Compiling resources\n{0}$ 
{1} /compile {2}", Path.GetDirectoryName (fname), resgen, fname);
-                               monitor.Log.WriteLine (GettextCatalog.GetString 
(
-                                       "Compiling resource {0} with {1}", 
fname, resgen));
-                               ProcessWrapper pw = null;
-                               try {
-                                       ProcessStartInfo info = 
Runtime.ProcessService.CreateProcessStartInfo (
-                                                                       resgen, 
String.Format ("/compile \"{0}\"", fname),
-                                                                       
Path.GetDirectoryName (fname), false);
-                                       if (PlatformID.Unix == 
Environment.OSVersion.Platform)
-                                               info.EnvironmentVariables 
["MONO_IOMAP"] = "drive";
-                                       pw = 
Runtime.ProcessService.StartProcess (info, sw, sw, null);
-                               } catch (System.ComponentModel.Win32Exception 
ex) {
-                                       Console.WriteLine 
(GettextCatalog.GetString (
-                                               "Error while trying to invoke 
'{0}' to compile resource '{1}' :\n {2}", resgen, fname, ex.ToString ()));
-                                       monitor.Log.WriteLine 
(GettextCatalog.GetString (
-                                               "Error while trying to invoke 
'{0}' to compile resource '{1}' :\n {2}", resgen, fname, ex.Message));
-
-                                       return null;
-                               }
-
-                               //FIXME: Handle exceptions
-                               pw.WaitForOutput ();
-
-                               if (pw.ExitCode == 0) {
-                                       fname = Path.ChangeExtension (fname, 
".resources");
-                               } else {
-                                       Console.WriteLine 
(GettextCatalog.GetString (
-                                               "Unable to compile ({0}) {1} to 
.resources. Ignoring. \nReason: \n{2}\n",
-                                               resgen, fname, sw.ToString ()));
-                                       monitor.Log.WriteLine 
(GettextCatalog.GetString (
-                                               "Unable to compile ({0}) {1} to 
.resources. Ignoring. \nReason: \n{2}\n",
-                                               resgen, fname, sw.ToString ()));
-
-                                       return null;
-                               }
-                       }
-
-                       return resourceId;
-               }
-
                // code duplication: see C# backend : 
CSharpBindingCompilerManager
                void WriteManifestFile(string fileName)
                {

Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/CSharpResourceIdBuilder.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/CSharpResourceIdBuilder.cs      
2007-10-08 20:10:16 UTC (rev 87123)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/CSharpResourceIdBuilder.cs      
2007-10-08 20:21:46 UTC (rev 87124)
@@ -29,6 +29,8 @@
 using MonoDevelop.Core;
 using MonoDevelop.Projects;
 using System;
+using System.Collections.Generic;
+using System.Globalization;
 using System.IO;
 using System.Text;
 
@@ -45,8 +47,16 @@
                                else
                                        fname = 
Runtime.FileService.NormalizeRelativePath (fname);
 
-                               if (String.Compare (Path.GetExtension (fname), 
".resx", true) == 0)
+                               if (String.Compare (Path.GetExtension (fname), 
".resx", true) == 0) {
                                        fname = Path.ChangeExtension (fname, 
".resources");
+                               } else {
+                                       string only_filename, culture, extn;
+                                       if (Utils.TrySplitResourceName (fname, 
out only_filename, out culture, out extn)) {
+                                               //remove the culture from fname
+                                               //foo.it.bmp -> foo.bmp
+                                               fname = only_filename + "." + 
extn;
+                                       }
+                               }
 
                                string rname = fname.Replace ('/', '.');
 
@@ -95,10 +105,16 @@
                                        return null;
                                }
 
+                               string culture, extn, only_filename;
+                               if (Utils.TrySplitResourceName 
(pf.RelativePath, out only_filename, out culture, out extn))
+                                       extn = "." + culture + ".resources";
+                               else
+                                       extn = ".resources";
+
                                if (ns == null)
-                                       return classname + ".resources";
+                                       return classname + extn;
                                else
-                                       return ns + '.' + classname + 
".resources";
+                                       return ns + '.' + classname + extn;
                        }
                }
 
@@ -194,5 +210,6 @@
 
                        return sb.ToString ();
                }
+
        }
 }

Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog       2007-10-08 
20:10:16 UTC (rev 87123)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/ChangeLog       2007-10-08 
20:21:46 UTC (rev 87124)
@@ -1,3 +1,9 @@
+2007-10-09  Ankit Jain  <[EMAIL PROTECTED]>
+
+       * CSharpResourceIdBuilder.cs: Handle localized resources.
+       * VBNetResourceIdBuilder.cs: Handle localized resources.
+       * Utils.cs (TrySplitResourceName): New.
+
 2007-09-28  Ankit Jain  <[EMAIL PROTECTED]>
 
        * MsPrjHelper.cs (GetContents): Set DependsOn to its absolute path.

Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/Utils.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/Utils.cs        2007-10-08 
20:10:16 UTC (rev 87123)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/Utils.cs        2007-10-08 
20:21:46 UTC (rev 87124)
@@ -30,6 +30,8 @@
 using MonoDevelop.Projects;
 
 using System;
+using System.Collections.Generic;
+using System.Globalization;
 using System.IO;
 using System.Text;
 using System.Xml;
@@ -303,5 +305,60 @@
 
                        return null;
                }
+
+               //Given a filename like foo.it.resx, splits it into - foo, it, 
resx
+               //Returns true only if a valid culture is found
+               //Note: hand-written as this can get called lotsa times
+               //Note: code duplicated in DotNetProject.GetCulture
+               public static bool TrySplitResourceName (string fname, out 
string only_filename, out string culture, out string extn)
+               {
+                       only_filename = culture = extn = null;
+
+                       int last_dot = -1;
+                       int culture_dot = -1;
+                       int i = fname.Length - 1;
+                       while (i >= 0) {
+                               if (fname [i] == '.') {
+                                       last_dot = i;
+                                       break;
+                               }
+                               i --;
+                       }
+                       if (i < 0)
+                               return false;
+
+                       i--;
+                       while (i >= 0) {
+                               if (fname [i] == '.') {
+                                       culture_dot = i;
+                                       break;
+                               }
+                               i --;
+                       }
+                       if (culture_dot < 0)
+                               return false;
+
+                       culture = fname.Substring (culture_dot + 1, last_dot - 
culture_dot - 1);
+                       if (!CultureNamesTable.ContainsKey (culture))
+                               return false;
+
+                       only_filename = fname.Substring (0, culture_dot);
+                       extn = fname.Substring (last_dot + 1);
+                       return true;
+               }
+
+               static Dictionary<string, string> cultureNamesTable;
+               static Dictionary<string, string> CultureNamesTable {
+                       get {
+                               if (cultureNamesTable == null) {
+                                       cultureNamesTable = new 
Dictionary<string, string> ();
+                                       foreach (CultureInfo ci in 
CultureInfo.GetCultures (CultureTypes.AllCultures))
+                                               cultureNamesTable [ci.Name] = 
ci.Name;
+                               }
+
+                               return cultureNamesTable;
+                       }
+               }
+
        }
 }

Modified: trunk/monodevelop/Extras/prj2make-sharp-lib/VBNetResourceIdBuilder.cs
===================================================================
--- trunk/monodevelop/Extras/prj2make-sharp-lib/VBNetResourceIdBuilder.cs       
2007-10-08 20:10:16 UTC (rev 87123)
+++ trunk/monodevelop/Extras/prj2make-sharp-lib/VBNetResourceIdBuilder.cs       
2007-10-08 20:21:46 UTC (rev 87124)
@@ -40,8 +40,16 @@
                        if (String.IsNullOrEmpty (pf.DependsOn)) {
                                string fname = pf.Name;
 
-                               if (String.Compare (Path.GetExtension (fname), 
".resx", true) == 0)
+                               if (String.Compare (Path.GetExtension (fname), 
".resx", true) == 0) {
                                        fname = Path.ChangeExtension (fname, 
".resources");
+                               } else {
+                                       string only_filename, culture, extn;
+                                       if (Utils.TrySplitResourceName (fname, 
out only_filename, out culture, out extn)) {
+                                               //remove the culture from fname
+                                               //foo.it.bmp -> foo.bmp
+                                               fname = only_filename + "." + 
extn;
+                                       }
+                               }
 
                                string rname = Path.GetFileName (fname);
 
@@ -83,11 +91,17 @@
                                        return null;
                                }
 
+                               string culture, extn, only_filename;
+                               if (Utils.TrySplitResourceName 
(pf.RelativePath, out only_filename, out culture, out extn))
+                                       extn = "." + culture + ".resources";
+                               else
+                                       extn = ".resources";
+
                                string rname;
                                if (ns == null)
-                                       rname = classname + ".resources";
+                                       rname = classname + extn;
                                else
-                                       rname = ns + '.' + classname + 
".resources";
+                                       rname = ns + '.' + classname + extn;
                                
                                if (String.IsNullOrEmpty 
(pf.Project.DefaultNamespace))
                                        return rname; 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to