PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/util/ProjectConverters/VisualStudioConverter.cs

#
C# | 67 lines | 55 code | 4 blank | 8 comment | 3 complexity | 5208fdebe8867ae67377663d72b7c642 MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // Copyright 2008, Charlie Poole
  3. // This is free software licensed under the NUnit license. You may
  4. // obtain a copy of the license at http://nunit.org
  5. // ****************************************************************
  6. using System;
  7. using System.IO;
  8. using NUnit.Core;
  9. using NUnit.Core.Extensibility;
  10. using NUnit.Util.Extensibility;
  11. namespace NUnit.Util.ProjectConverters
  12. {
  13. /// <summary>
  14. /// Summary description for VSProjectLoader.
  15. /// </summary>
  16. public class VisualStudioConverter : IProjectConverter
  17. {
  18. #region IProjectConverter Members
  19. public bool CanConvertFrom(string path)
  20. {
  21. return VSProject.IsProjectFile(path)|| VSProject.IsSolutionFile(path);
  22. }
  23. public NUnitProject ConvertFrom(string path)
  24. {
  25. NUnitProject project = new NUnitProject( Path.GetFullPath( path ) );
  26. if ( VSProject.IsProjectFile(path) )
  27. {
  28. VSProject vsProject = new VSProject( path );
  29. project.Add( vsProject );
  30. }
  31. else if ( VSProject.IsSolutionFile(path) )
  32. {
  33. string solutionDirectory = Path.GetDirectoryName( path );
  34. using(StreamReader reader = new StreamReader( path ))
  35. {
  36. char[] delims = { '=', ',' };
  37. char[] trimchars = { ' ', '"' };
  38. string line = reader.ReadLine();
  39. while ( line != null )
  40. {
  41. if ( line.StartsWith( "Project" ) )
  42. {
  43. string[] parts = line.Split( delims );
  44. string vsProjectPath = parts[2].Trim(trimchars);
  45. if ( VSProject.IsProjectFile( vsProjectPath ) )
  46. project.Add( new VSProject( Path.Combine( solutionDirectory, vsProjectPath ) ) );
  47. }
  48. line = reader.ReadLine();
  49. }
  50. }
  51. }
  52. project.IsDirty = false;
  53. return project;
  54. }
  55. #endregion
  56. }
  57. }