~ubuntu-branches/ubuntu/natty/monodevelop/natty

« back to all changes in this revision

Viewing changes to src/addins/prj2make-sharp-lib/SlnFileFormat.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-03-29 23:36:33 UTC
  • mto: (1.5.1 sid)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: james.westby@ubuntu.com-20080329233633-l550uuwvfh1e68at
Tags: upstream-1.0+dfsg
ImportĀ upstreamĀ versionĀ 1.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
                {
65
65
                        if (String.Compare (Path.GetExtension (file), ".sln", true) != 0)
66
66
                                return false;
67
 
                        string version = GetSlnFileVersion (file);
 
67
                        string tmp;
 
68
                        string version = GetSlnFileVersion (file, out tmp);
68
69
                        return version == "9.00" || version == "10.00";
69
70
                }
70
71
                
113
114
                                }
114
115
                        } catch (Exception ex) {
115
116
                                monitor.ReportError (GettextCatalog.GetString ("Could not save solution: {0}", file), ex);
116
 
                                Console.WriteLine ("Could not save solution: {0}, {1}", file, ex);
 
117
                                LoggingService.LogError (GettextCatalog.GetString ("Could not save solution: {0}", file), ex);
117
118
 
118
119
                                if (!String.IsNullOrEmpty (tmpfilename))
119
120
                                        File.Delete (tmpfilename);
128
129
                        using (StreamWriter sw = new StreamWriter (file, false, Encoding.UTF8)) {
129
130
                                sw.NewLine = "\r\n";
130
131
 
131
 
                                sw.WriteLine ();
132
 
                                //Write Header
133
 
                                sw.WriteLine ("Microsoft Visual Studio Solution File, Format Version 9.00");
134
 
 
135
 
                                sw.WriteLine ("# Visual Studio 2005");
136
 
 
137
 
                                //Write the projects
138
 
                                monitor.BeginTask (GettextCatalog.GetString ("Saving projects"), 1);
139
 
                                WriteProjects (c, c.BaseDirectory, sw, monitor);
140
 
                                monitor.EndTask ();
141
 
 
142
132
                                SlnData slnData = GetSlnData (c);
143
133
                                if (slnData == null) {
144
134
                                        // If a non-msbuild project is being converted by just
145
135
                                        // changing the fileformat, then create the SlnData for it
146
136
                                        slnData = new SlnData ();
147
137
                                        c.ExtendedProperties [typeof (SlnFileFormat)] = slnData;
148
 
                                } else {
149
 
                                        //Write the lines for unknownProjects
150
 
                                        foreach (string l in slnData.UnknownProjects)
151
 
                                                sw.WriteLine (l);
152
138
                                }
153
139
 
 
140
                                sw.WriteLine ();
 
141
                                //Write Header
 
142
                                sw.WriteLine ("Microsoft Visual Studio Solution File, Format Version " + slnData.VersionString);
 
143
                                sw.WriteLine (slnData.HeaderComment);
 
144
 
 
145
                                //Write the projects
 
146
                                monitor.BeginTask (GettextCatalog.GetString ("Saving projects"), 1);
 
147
                                WriteProjects (c, c.BaseDirectory, sw, monitor);
 
148
                                monitor.EndTask ();
 
149
 
 
150
                                //Write the lines for unknownProjects
 
151
                                foreach (string l in slnData.UnknownProjects)
 
152
                                        sw.WriteLine (l);
 
153
 
154
154
                                //Write the Globals
155
155
                                sw.WriteLine ("Global");
156
156
 
213
213
                                                continue;
214
214
                                        }
215
215
 
216
 
                                        if (!MSBuildFileFormat.ProjectTypeGuids.ContainsKey (project.LanguageName)) {
 
216
                                        if (!MSBuildFileFormat.LanguageTypeGuids.ContainsKey (project.LanguageName)) {
217
217
                                                // FIXME: Should not happen, temp
218
218
                                                monitor.ReportWarning (GettextCatalog.GetString ("Saving for project {0} not supported. Ignoring.",
219
219
                                                        ce.FileName));
240
240
                                        l = msbData.Extra;
241
241
 
242
242
                                        writer.WriteLine (@"Project(""{0}"") = ""{1}"", ""{2}"", ""{3}""",
243
 
                                                MSBuildFileFormat.ProjectTypeGuids [project.LanguageName],
 
243
                                                MSBuildFileFormat.LanguageTypeGuids [project.LanguageName],
244
244
                                                project.Name, 
245
245
                                                FileService.NormalizeRelativePath (FileService.AbsoluteToRelativePath (
246
246
                                                        baseDirectory, project.FileName)).Replace ('/', '\\'),
252
252
                                                // Solution folder
253
253
                                                slnData = new SlnData ();
254
254
                                                c.ExtendedProperties [typeof (SlnFileFormat)] = slnData;
 
255
                                                SlnData data = GetSlnData (combine);
 
256
                                                if (data != null) {
 
257
                                                        slnData.VersionString = data.VersionString;
 
258
                                                        slnData.HeaderComment = data.HeaderComment;
 
259
                                                }
255
260
                                        }
256
261
 
257
262
                                        l = slnData.Extra;
306
311
                                                        //      1. Invalid setting
307
312
                                                        //      2. New imported project, which doesn't yet have
308
313
                                                        //         a config named rootConfigName
309
 
                                                        Console.WriteLine ("Known Problem: Invalid setting. Ignoring.");
 
314
                                                        LoggingService.LogDebug ("Known Problem: Invalid setting. Ignoring.");
310
315
                                                        continue;
311
316
                                                }
312
317
 
390
395
                //
391
396
                Combine LoadSolution (string fileName, IProgressMonitor monitor)
392
397
                {
393
 
                        string version = GetSlnFileVersion (fileName);
 
398
                        string headerComment;
 
399
                        string version = GetSlnFileVersion (fileName, out headerComment);
394
400
                        if (version != "9.00" && version != "10.00")
395
401
                                throw new UnknownProjectVersionException (fileName, version);
396
402
 
410
416
                                combine.FileFormat = new MSBuildFileFormat ();
411
417
                                data = new SlnData ();
412
418
                                combine.ExtendedProperties [typeof (SlnFileFormat)] = data;
 
419
                                data.VersionString = version;
 
420
                                data.HeaderComment = headerComment;
413
421
 
414
422
                                string s = null;
415
423
                                projectSections = new List<Section> ();
479
487
 
480
488
                                        SlnData slnData = new SlnData (projectGuid);
481
489
                                        folder.ExtendedProperties [typeof (SlnFileFormat)] = slnData;
 
490
                                        slnData.VersionString = data.VersionString;
 
491
                                        slnData.HeaderComment = data.HeaderComment;
482
492
 
483
493
                                        slnData.Extra = lines.GetRange (sec.Start + 1, sec.Count - 2);
484
494
 
487
497
                                        continue;
488
498
                                }
489
499
 
490
 
                                if (!MSBuildFileFormat.ProjectTypeGuids.ContainsValue (projTypeGuid)) {
491
 
                                        LoggingService.LogDebug (GettextCatalog.GetString (
 
500
                                if (!MSBuildFileFormat.LanguageTypeGuids.ContainsValue (projTypeGuid)) {
 
501
                                        LoggingService.LogWarning (GettextCatalog.GetString (
492
502
                                                "Unknown project type guid '{0}' on line #{1}. Ignoring.",
493
503
                                                projTypeGuid,
494
504
                                                sec.Start + 1));
498
508
                                        continue;
499
509
                                }
500
510
 
501
 
                                if (!projectPath.StartsWith("http://") &&
502
 
                                        (projectPath.EndsWith (".csproj") || projectPath.EndsWith (".vbproj")))
503
 
                                {
504
 
                                        DotNetProject project = null;
505
 
                                        string path = SlnMaker.MapPath (Path.GetDirectoryName (fileName), projectPath);
506
 
                                        if (String.IsNullOrEmpty (path)) {
507
 
                                                monitor.ReportWarning (GettextCatalog.GetString (
508
 
                                                        "Invalid project path found in {0} : {1}", fileName, projectPath));
509
 
                                                Console.WriteLine (GettextCatalog.GetString (
510
 
                                                        "Invalid project path found in {0} : {1}", fileName, projectPath));
511
 
 
 
511
                                if (projectPath.StartsWith("http://")) {
 
512
                                        monitor.ReportWarning (GettextCatalog.GetString (
 
513
                                                "{0}({1}): Projects with non-local source (http://...) not supported. '{2}'.",
 
514
                                                fileName, sec.Start + 1, projectPath));
 
515
                                        data.UnknownProjects.AddRange (lines.GetRange (sec.Start, sec.Count));
 
516
                                        continue;
 
517
                                }
 
518
 
 
519
                                DotNetProject project = null;
 
520
                                string path = SlnMaker.MapPath (Path.GetDirectoryName (fileName), projectPath);
 
521
                                if (String.IsNullOrEmpty (path)) {
 
522
                                        monitor.ReportWarning (GettextCatalog.GetString (
 
523
                                                "Invalid project path found in {0} : {1}", fileName, projectPath));
 
524
                                        LoggingService.LogWarning (GettextCatalog.GetString (
 
525
                                                "Invalid project path found in {0} : {1}", fileName, projectPath));
 
526
 
 
527
                                        continue;
 
528
                                }
 
529
 
 
530
                                projectPath = Path.GetFullPath (path);
 
531
                                try {
 
532
                                        project = Services.ProjectService.ReadCombineEntry (projectPath, monitor) as DotNetProject;
 
533
                                        if (project == null) {
 
534
                                                LoggingService.LogError ("Internal Error: Didn't get the expected DotNetProject for {0} project.",
 
535
                                                        projectPath);
512
536
                                                continue;
513
537
                                        }
514
538
 
515
 
                                        projectPath = Path.GetFullPath (path);
516
 
                                        try {
517
 
                                                project = Services.ProjectService.ReadCombineEntry (projectPath, monitor) as DotNetProject;
518
 
                                                if (project == null) {
519
 
                                                        Console.WriteLine ("Internal Error: Didn't get the expected DotNetProject for {0} project.",
520
 
                                                                projectPath);
521
 
                                                        continue;
522
 
                                                }
523
 
 
524
 
                                                MSBuildData msdata = Utils.GetMSBuildData (project);
525
 
                                                entries [projectGuid] = project;
526
 
                                                data.ProjectsByGuid [msdata.Guid] = project;
527
 
 
528
 
                                                msdata.Extra = lines.GetRange (sec.Start + 1, sec.Count - 2);
529
 
                                        } catch (Exception e) {
530
 
                                                Console.WriteLine ("Error while trying to load the project {0}", projectPath);
531
 
                                                Console.WriteLine (e);
532
 
                                                monitor.ReportWarning (GettextCatalog.GetString (
533
 
                                                        "Error while trying to load the project {0}. Exception : {1}", projectPath, e.Message));
534
 
 
535
 
                                                if (project == null)
536
 
                                                        data.UnknownProjects.AddRange (lines.GetRange (sec.Start, sec.Count));
537
 
                                        }
538
 
                                        continue;
 
539
                                        MSBuildData msdata = Utils.GetMSBuildData (project);
 
540
                                        entries [projectGuid] = project;
 
541
                                        data.ProjectsByGuid [msdata.Guid] = project;
 
542
 
 
543
                                        msdata.Extra = lines.GetRange (sec.Start + 1, sec.Count - 2);
 
544
                                } catch (Exception e) {
 
545
                                        LoggingService.LogError (GettextCatalog.GetString (
 
546
                                                                "Error while trying to load the project {0}. Exception : {1}",
 
547
                                                                projectPath, e.ToString ()));
 
548
                                        monitor.ReportWarning (GettextCatalog.GetString (
 
549
                                                "Error while trying to load the project {0}. Exception : {1}", projectPath, e.Message));
 
550
 
 
551
                                        if (project == null)
 
552
                                                data.UnknownProjects.AddRange (lines.GetRange (sec.Start, sec.Count));
539
553
                                }
540
 
                                //FIXME: Non .csproj/.vbproj projects not supported (yet)
541
 
                                monitor.ReportWarning (GettextCatalog.GetString (
542
 
                                        "{0}({1}): Unsupported or unrecognized project : '{2}'. See logs.", fileName, sec.Start + 1, projectPath));
543
 
 
544
 
                                data.UnknownProjects.AddRange (lines.GetRange (sec.Start, sec.Count));
545
554
                        }
546
555
                        monitor.EndTask ();
547
556
 
679
688
 
680
689
                                string [] parts = s.Split (new char [] {'='}, 2);
681
690
                                if (parts.Length < 2) {
682
 
                                        Console.WriteLine ("{0} ({1}) : Warning: Invalid format. Ignoring", sln.FileName, lineNum + 1);
 
691
                                        LoggingService.LogDebug ("{0} ({1}) : Invalid format. Ignoring", sln.FileName, lineNum + 1);
683
692
                                        continue;
684
693
                                }
685
694
 
694
703
                                        action = "Build.0";
695
704
                                        left = left.Substring (0, left.Length - 8);
696
705
                                } else { 
697
 
                                        Console.WriteLine ("{0} ({1}) : Warning: Unknown action. Only ActiveCfg & Build.0 supported.",
698
 
                                                sln.FileName, lineNum + 1);
 
706
                                        LoggingService.LogWarning (GettextCatalog.GetString ("{0} ({1}) : Unknown action. Only ActiveCfg & Build.0 supported.",
 
707
                                                sln.FileName, lineNum + 1));
699
708
                                        continue;
700
709
                                }
701
710
 
702
711
                                string [] t = left.Split (new char [] {'.'}, 2);
703
712
                                if (t.Length < 2) {
704
 
                                        Console.WriteLine ("{0} ({1}) : Warning: Invalid format of the left side. Ignoring",
 
713
                                        LoggingService.LogDebug ("{0} ({1}) : Invalid format of the left side. Ignoring",
705
714
                                                sln.FileName, lineNum + 1);
706
715
                                        continue;
707
716
                                }
714
723
                                                // already warned
715
724
                                                continue;
716
725
 
717
 
                                        Console.WriteLine ("{0} ({1}) : Warning: Project with guid = '{2}' not found or not loaded. Ignoring", 
718
 
                                                sln.FileName, lineNum + 1, projGuid);
 
726
                                        LoggingService.LogWarning (GettextCatalog.GetString ("{0} ({1}) : Project with guid = '{2}' not found or not loaded. Ignoring", 
 
727
                                                sln.FileName, lineNum + 1, projGuid));
719
728
                                        ignoredProjects [projGuid] = projGuid;
720
729
                                        continue;
721
730
                                }
818
827
 
819
828
                                if (pair.Key.IndexOf ('|') < 0) {
820
829
                                        //Config must of the form ConfigName|Platform
821
 
                                        Console.WriteLine ("{0} ({1}) : Invalid config name '{2}'", combine.FileName, lineNum + 1, pair.Key);
 
830
                                        LoggingService.LogError (GettextCatalog.GetString ("{0} ({1}) : Invalid config name '{2}'", combine.FileName, lineNum + 1, pair.Key));
822
831
                                        continue;
823
832
                                }
824
833
                                
844
853
 
845
854
                                if (!entries.ContainsKey (pair.Value)) {
846
855
                                        //Container not found
847
 
                                        LoggingService.LogDebug ("Project with guid '{0}' not found.", pair.Value);
 
856
                                        LoggingService.LogWarning (GettextCatalog.GetString ("Project with guid '{0}' not found.", pair.Value));
848
857
                                        continue;
849
858
                                }
850
859
 
851
860
                                if (!entries.ContainsKey (pair.Key)) {
852
861
                                        //Containee not found
853
 
                                        LoggingService.LogDebug ("Project with guid '{0}' not found.", pair.Key);
 
862
                                        LoggingService.LogWarning (GettextCatalog.GetString ("Project with guid '{0}' not found.", pair.Key));
854
863
                                        continue;
855
864
                                }
856
865
 
898
907
                }
899
908
 
900
909
                // Utility function to determine the sln file version
901
 
                string GetSlnFileVersion(string strInSlnFile)
 
910
                string GetSlnFileVersion(string strInSlnFile, out string headerComment)
902
911
                {
903
912
                        string strVersion = null;
904
913
                        string strInput = null;
 
914
                        headerComment = null;
905
915
                        Match match;
906
916
                        StreamReader reader = new StreamReader(strInSlnFile);
907
917
                        
920
930
                        if (match.Success)
921
931
                        {
922
932
                                strVersion = match.Groups[1].Value;
 
933
                                headerComment = reader.ReadLine ();
923
934
                        }
924
935
                        
925
936
                        // Close the stream