Browse Source

Fixed exception when opening a solution containing web projects.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1194 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
e378b90e2e
  1. 5
      src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs
  2. 19
      src/Main/Base/Project/Src/Project/AbstractProject.cs
  3. 7
      src/Main/Base/Project/Src/Project/IProject.cs
  4. 4
      src/Main/Base/Project/Src/Project/MSBuildProject.cs
  5. 4
      src/Main/Base/Project/Src/Project/MissingProject.cs
  6. 6
      src/Main/Base/Project/Src/Project/Solution/ProjectSection.cs
  7. 42
      src/Main/Base/Project/Src/Project/Solution/Solution.cs
  8. 17
      src/Main/Base/Project/Src/Project/Solution/SolutionFolder.cs
  9. 4
      src/Main/Base/Project/Src/Project/UnknownProject.cs
  10. 6
      src/Main/Base/Project/Src/Services/LanguageBinding/LanguageBindingService.cs
  11. 11
      src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs
  12. 3
      src/Main/Core/Test/AddInTreeTests/ExtPathTests.cs

5
src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs

@ -563,11 +563,16 @@ namespace ICSharpCode.SharpDevelop.Gui
foreach (string file in files) { foreach (string file in files) {
if (File.Exists(file)) { if (File.Exists(file)) {
IProjectLoader loader = ProjectService.GetProjectLoader(file);
if (loader != null) {
FileUtility.ObservedLoad(new NamedFileOperationDelegate(loader.Load), file);
} else {
FileService.OpenFile(file); FileService.OpenFile(file);
} }
} }
} }
} }
}
protected virtual void OnViewOpened(ViewContentEventArgs e) protected virtual void OnViewOpened(ViewContentEventArgs e)
{ {

19
src/Main/Base/Project/Src/Project/AbstractProject.cs

@ -29,9 +29,10 @@ namespace ICSharpCode.SharpDevelop.Project
protected List<ProjectItem> items = new List<ProjectItem>(); protected List<ProjectItem> items = new List<ProjectItem>();
protected List<string> imports = new List<string>(); protected List<string> imports = new List<string>();
readonly List<ProjectSection> projectSections = new List<ProjectSection>();
protected string fileName; string fileName;
protected string language; string language;
[Browsable(false)] [Browsable(false)]
public Dictionary<string, PropertyGroup> Configurations { public Dictionary<string, PropertyGroup> Configurations {
@ -153,6 +154,16 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
/// <summary>
/// Gets a list of property sections stored in the solution file.
/// </summary>
[Browsable(false)]
public List<ProjectSection> ProjectSections {
get {
return projectSections;
}
}
/// <summary> /// <summary>
/// Gets the list of MSBuild Imports. /// Gets the list of MSBuild Imports.
/// </summary> /// </summary>
@ -172,7 +183,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (fileName == null) { if (fileName == null) {
return String.Empty; return String.Empty;
} }
return Path.GetFullPath(fileName); return fileName;
} }
set { set {
fileName = value; fileName = value;
@ -188,7 +199,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (fileName == null) { if (fileName == null) {
return String.Empty; return String.Empty;
} }
directoryName = Path.GetFullPath(Path.GetDirectoryName(fileName)); directoryName = Path.GetDirectoryName(fileName);
} }
return directoryName; return directoryName;
} }

7
src/Main/Base/Project/Src/Project/IProject.cs

@ -30,6 +30,13 @@ namespace ICSharpCode.SharpDevelop.Project
get; get;
} }
/// <summary>
/// Gets a list of property sections stored in the solution file.
/// </summary>
List<ProjectSection> ProjectSections {
get;
}
/// <summary> /// <summary>
/// Marks a project for needing recompilation. /// Marks a project for needing recompilation.
/// </summary> /// </summary>

4
src/Main/Base/Project/Src/Project/MSBuildProject.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.SharpDevelop.Project
configurations["Release|*"]["DebugSymbols"] = "False"; configurations["Release|*"]["DebugSymbols"] = "False";
configurations["Release|*"]["DebugType"] = "None"; configurations["Release|*"]["DebugType"] = "None";
fileName = information.OutputProjectFileName; this.FileName = Path.GetFullPath(information.OutputProjectFileName);
} }
public override bool CanCompile(string fileName) public override bool CanCompile(string fileName)
@ -82,7 +82,7 @@ namespace ICSharpCode.SharpDevelop.Project
protected void SetupProject(string projectFileName) protected void SetupProject(string projectFileName)
{ {
this.fileName = projectFileName; this.FileName = Path.GetFullPath(projectFileName);
using (MSBuildFileReader reader = new MSBuildFileReader(projectFileName)) { using (MSBuildFileReader reader = new MSBuildFileReader(projectFileName)) {
reader.WhitespaceHandling = WhitespaceHandling.Significant; reader.WhitespaceHandling = WhitespaceHandling.Significant;
reader.MoveToContent(); // we have to skip over the XmlDeclaration (if it exists) reader.MoveToContent(); // we have to skip over the XmlDeclaration (if it exists)

4
src/Main/Base/Project/Src/Project/MissingProject.cs

@ -24,9 +24,9 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
public MissingProject(string fileName) public MissingProject(string fileName, string title)
{ {
Name = Path.GetFileNameWithoutExtension(fileName); Name = title;
FileName = fileName; FileName = fileName;
IdGuid = "{" + Guid.NewGuid().ToString() + "}"; IdGuid = "{" + Guid.NewGuid().ToString() + "}";
} }

6
src/Main/Base/Project/Src/Project/Solution/ProjectSection.cs

@ -55,17 +55,17 @@ namespace ICSharpCode.SharpDevelop.Project
} }
static Regex sectionPattern = new Regex("\\s*(?<Key>.*\\S)\\s*=\\s*(?<Value>.*\\S)\\s*", RegexOptions.Compiled); static Regex sectionPattern = new Regex("\\s*(?<Key>.*\\S)\\s*=\\s*(?<Value>.*\\S)\\s*", RegexOptions.Compiled);
public static ProjectSection ReadGlobalSection(StreamReader sr, string name, string sectionType) public static ProjectSection ReadGlobalSection(TextReader sr, string name, string sectionType)
{ {
return ReadSection(sr, name, sectionType, "EndGlobalSection"); return ReadSection(sr, name, sectionType, "EndGlobalSection");
} }
public static ProjectSection ReadProjectSection(StreamReader sr, string name, string sectionType) public static ProjectSection ReadProjectSection(TextReader sr, string name, string sectionType)
{ {
return ReadSection(sr, name, sectionType, "EndProjectSection"); return ReadSection(sr, name, sectionType, "EndProjectSection");
} }
static ProjectSection ReadSection(StreamReader sr, string name, string sectionType, string endTag) static ProjectSection ReadSection(TextReader sr, string name, string sectionType, string endTag)
{ {
ProjectSection newFolder = new ProjectSection(name, sectionType); ProjectSection newFolder = new ProjectSection(name, sectionType);
while (true) { while (true) {

42
src/Main/Base/Project/Src/Project/Solution/Solution.cs

@ -271,23 +271,14 @@ namespace ICSharpCode.SharpDevelop.Project
projectSection.AppendLine(); projectSection.AppendLine();
if (currentFolder is IProject) { if (currentFolder is IProject) {
// IProject project = (IProject)currentFolder; IProject project = (IProject)currentFolder;
// currently nothing to do. (I don't know if projects may have sections). // Web projects can have sections
SaveProjectSections(project.ProjectSections, projectSection);
} else if (currentFolder is SolutionFolder) { } else if (currentFolder is SolutionFolder) {
SolutionFolder folder = (SolutionFolder)currentFolder; SolutionFolder folder = (SolutionFolder)currentFolder;
foreach (ProjectSection section in folder.Sections) { SaveProjectSections(folder.Sections, projectSection);
projectSection.Append("\tProjectSection(");
projectSection.Append(section.Name);
projectSection.Append(") = ");
projectSection.Append(section.SectionType);
projectSection.Append(Environment.NewLine);
section.AppendSection(projectSection, "\t\t");
projectSection.Append("\tEndProjectSection");
projectSection.Append(Environment.NewLine);
}
foreach (ISolutionFolder subFolder in folder.Folders) { foreach (ISolutionFolder subFolder in folder.Folders) {
stack.Push(subFolder); stack.Push(subFolder);
@ -339,6 +330,22 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
static void SaveProjectSections(IEnumerable<ProjectSection> sections, StringBuilder projectSection)
{
foreach (ProjectSection section in sections) {
projectSection.Append("\tProjectSection(");
projectSection.Append(section.Name);
projectSection.Append(") = ");
projectSection.Append(section.SectionType);
projectSection.Append(Environment.NewLine);
section.AppendSection(projectSection, "\t\t");
projectSection.Append("\tEndProjectSection");
projectSection.Append(Environment.NewLine);
}
}
static Regex versionPattern = new Regex("Microsoft Visual Studio Solution File, Format Version\\s+(?<Version>.*)", RegexOptions.Compiled); static Regex versionPattern = new Regex("Microsoft Visual Studio Solution File, Format Version\\s+(?<Version>.*)", RegexOptions.Compiled);
static Regex projectLinePattern = new Regex("Project\\(\"(?<ProjectGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\"", RegexOptions.Compiled); static Regex projectLinePattern = new Regex("Project\\(\"(?<ProjectGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\"", RegexOptions.Compiled);
@ -432,14 +439,19 @@ namespace ICSharpCode.SharpDevelop.Project
if (match.Success) { if (match.Success) {
string projectGuid = match.Result("${ProjectGuid}"); string projectGuid = match.Result("${ProjectGuid}");
string title = match.Result("${Title}"); string title = match.Result("${Title}");
string location = Path.Combine(solutionDirectory, match.Result("${Location}")); string location = match.Result("${Location}");
string guid = match.Result("${Guid}"); string guid = match.Result("${Guid}");
if (!FileUtility.IsUrl(location)) {
location = Path.Combine(solutionDirectory, location);
}
if (projectGuid == FolderGuid) { if (projectGuid == FolderGuid) {
SolutionFolder newFolder = SolutionFolder.ReadFolder(sr, title, location, guid); SolutionFolder newFolder = SolutionFolder.ReadFolder(sr, title, location, guid);
newSolution.AddFolder(newFolder); newSolution.AddFolder(newFolder);
} else { } else {
IProject newProject = LanguageBindingService.LoadProject(location, title, projectGuid); IProject newProject = LanguageBindingService.LoadProject(location, title, projectGuid);
ReadProjectSections(sr, newProject.ProjectSections);
newProject.IdGuid = guid; newProject.IdGuid = guid;
newSolution.AddFolder(newProject); newSolution.AddFolder(newProject);
} }

17
src/Main/Base/Project/Src/Project/Solution/SolutionFolder.cs

@ -117,9 +117,20 @@ namespace ICSharpCode.SharpDevelop.Project
#endregion #endregion
static Regex sectionHeaderPattern = new Regex("\\s*ProjectSection\\((?<Name>.*)\\)\\s*=\\s*(?<Type>.*)", RegexOptions.Compiled); static Regex sectionHeaderPattern = new Regex("\\s*ProjectSection\\((?<Name>.*)\\)\\s*=\\s*(?<Type>.*)", RegexOptions.Compiled);
public static SolutionFolder ReadFolder(StreamReader sr, string title, string location, string guid)
public static SolutionFolder ReadFolder(TextReader sr, string title, string location, string guid)
{ {
SolutionFolder newFolder = new SolutionFolder(title, location, guid); SolutionFolder newFolder = new SolutionFolder(title, location, guid);
ReadProjectSections(sr, newFolder.Sections);
return newFolder;
}
/// <summary>
/// Reads project sections from the TextReader until the line "EndProject" is found and saves
/// them into the specified sectionList.
/// </summary>
public static void ReadProjectSections(TextReader sr, ICollection<ProjectSection> sectionList)
{
while (true) { while (true) {
string line = sr.ReadLine(); string line = sr.ReadLine();
if (line == null || line.Trim() == "EndProject") { if (line == null || line.Trim() == "EndProject") {
@ -127,11 +138,9 @@ namespace ICSharpCode.SharpDevelop.Project
} }
Match match = sectionHeaderPattern.Match(line); Match match = sectionHeaderPattern.Match(line);
if (match.Success) { if (match.Success) {
newFolder.Sections.Add(ProjectSection.ReadProjectSection(sr, match.Result("${Name}"), match.Result("${Type}"))); sectionList.Add(ProjectSection.ReadProjectSection(sr, match.Result("${Name}"), match.Result("${Type}")));
} }
} }
return newFolder;
} }
} }
} }

4
src/Main/Base/Project/Src/Project/UnknownProject.cs

@ -24,9 +24,9 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
public UnknownProject(string fileName) public UnknownProject(string fileName, string title)
{ {
Name = Path.GetFileNameWithoutExtension(fileName); Name = title;
FileName = fileName; FileName = fileName;
IdGuid = "{" + Guid.NewGuid().ToString() + "}"; IdGuid = "{" + Guid.NewGuid().ToString() + "}";
} }

6
src/Main/Base/Project/Src/Services/LanguageBinding/LanguageBindingService.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.Core
{ {
IProject newProject; IProject newProject;
if (!File.Exists(location)) { if (!File.Exists(location)) {
newProject = new MissingProject(location); newProject = new MissingProject(location, title);
newProject.TypeGuid = projectTypeGuid; newProject.TypeGuid = projectTypeGuid;
} else { } else {
ILanguageBinding binding = LanguageBindingService.GetBindingPerProjectFile(location); ILanguageBinding binding = LanguageBindingService.GetBindingPerProjectFile(location);
@ -93,11 +93,11 @@ namespace ICSharpCode.Core
newProject = binding.LoadProject(location, title); newProject = binding.LoadProject(location, title);
} catch (XmlException ex) { } catch (XmlException ex) {
MessageService.ShowError("Error loading " + location + ":\n" + ex.Message); MessageService.ShowError("Error loading " + location + ":\n" + ex.Message);
newProject = new UnknownProject(location); newProject = new UnknownProject(location, title);
newProject.TypeGuid = projectTypeGuid; newProject.TypeGuid = projectTypeGuid;
} }
} else { } else {
newProject = new UnknownProject(location); newProject = new UnknownProject(location, title);
newProject.TypeGuid = projectTypeGuid; newProject.TypeGuid = projectTypeGuid;
} }
} }

11
src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

@ -103,6 +103,10 @@ namespace ICSharpCode.Core
return result; return result;
} }
public static bool IsUrl(string path)
{
return path.IndexOf(':') >= 2;
}
/// <summary> /// <summary>
/// Converts a given absolute path and a given base path to a path that leads /// Converts a given absolute path and a given base path to a path that leads
@ -110,8 +114,15 @@ namespace ICSharpCode.Core
/// </summary> /// </summary>
public static string GetRelativePath(string baseDirectoryPath, string absPath) public static string GetRelativePath(string baseDirectoryPath, string absPath)
{ {
if (IsUrl(absPath) || IsUrl(baseDirectoryPath)){
return absPath;
}
try {
baseDirectoryPath = Path.GetFullPath(baseDirectoryPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); baseDirectoryPath = Path.GetFullPath(baseDirectoryPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
absPath = Path.GetFullPath(absPath); absPath = Path.GetFullPath(absPath);
} catch (Exception ex) {
throw new ArgumentException("GetRelativePath error '" + baseDirectoryPath + "' -> '" + absPath + "'", ex);
}
string[] bPath = baseDirectoryPath.Split(separators); string[] bPath = baseDirectoryPath.Split(separators);
string[] aPath = absPath.Split(separators); string[] aPath = absPath.Split(separators);

3
src/Main/Core/Test/AddInTreeTests/ExtPathTests.cs

@ -56,6 +56,9 @@ namespace ICSharpCode.Core.Tests.AddInTreeTests.Tests
Assert.AreEqual(@"blub", FileUtility.GetRelativePath(@"C:\hello\.\..\A", @"C:\.\a\blub")); Assert.AreEqual(@"blub", FileUtility.GetRelativePath(@"C:\hello\.\..\A", @"C:\.\a\blub"));
Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\HELlo", @"C:\.\blub\.\..\.\a\.\blub")); Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\HELlo", @"C:\.\blub\.\..\.\a\.\blub"));
Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\heLLo\A\..", @"C:\.\blub\.\..\.\a\.\blub")); Assert.AreEqual(@"..\a\blub", FileUtility.GetRelativePath(@"C:\.\.\.\.\heLLo\A\..", @"C:\.\blub\.\..\.\a\.\blub"));
// Project filename could be an URL
Assert.AreEqual("http://example.com/vdir/", FileUtility.GetRelativePath("C:\\temp", "http://example.com/vdir/"));
} }
[Test] [Test]

Loading…
Cancel
Save