Address PR feedback.

This commit is contained in:
Eric Erhardt 2016-04-27 16:18:07 -05:00
parent e2dcb968eb
commit a09f6788af
3 changed files with 53 additions and 37 deletions

View file

@ -0,0 +1,48 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
namespace Microsoft.DotNet.ProjectModel
{
internal static class ProjectPath
{
public static string NormalizeProjectDirectoryPath(string path)
{
string fullPath = Path.GetFullPath(path);
if (IsProjectFilePath(fullPath))
{
return Path.GetDirectoryName(fullPath);
}
else if (IsDirectoryContainingProjectFile(fullPath))
{
return fullPath;
}
return null;
}
public static string NormalizeProjectFilePath(string path)
{
if (!path.EndsWith(Project.FileName))
{
path = Path.Combine(path, Project.FileName);
}
return Path.GetFullPath(path);
}
private static bool IsProjectFilePath(string path)
{
return File.Exists(path) &&
string.Equals(Path.GetFileName(path), Project.FileName, StringComparison.OrdinalIgnoreCase);
}
private static bool IsDirectoryContainingProjectFile(string path)
{
return Directory.Exists(path) && File.Exists(Path.Combine(path, Project.FileName));
}
}
}

View file

@ -64,7 +64,7 @@ namespace Microsoft.DotNet.ProjectModel
public static Project GetProject(string projectPath, ProjectReaderSettings settings = null)
{
projectPath = NormalizeProjectFilePath(projectPath);
projectPath = ProjectPath.NormalizeProjectFilePath(projectPath);
var name = Path.GetFileName(Path.GetDirectoryName(projectPath));
@ -233,38 +233,6 @@ namespace Microsoft.DotNet.ProjectModel
return project;
}
internal static string NormalizeProjectDirectoryPath(string path)
{
if (File.Exists(path) &&
string.Equals(Path.GetFileName(path), Project.FileName, StringComparison.OrdinalIgnoreCase))
{
string directoryName = Path.GetDirectoryName(path);
if (string.IsNullOrEmpty(directoryName))
{
directoryName = Directory.GetCurrentDirectory();
}
return Path.GetFullPath(directoryName);
}
else if (Directory.Exists(path) &&
File.Exists(Path.Combine(path, Project.FileName)))
{
return Path.GetFullPath(path);
}
return null;
}
internal static string NormalizeProjectFilePath(string path)
{
if (!path.EndsWith(Project.FileName))
{
path = Path.Combine(path, Project.FileName);
}
return Path.GetFullPath(path);
}
private static NuGetVersion SpecifySnapshot(string version, string snapshotValue)
{
if (version.EndsWith("-*"))

View file

@ -107,7 +107,7 @@ namespace Microsoft.DotNet.ProjectModel
public void AddProject(string path)
{
var projectPath = ProjectReader.NormalizeProjectDirectoryPath(path);
var projectPath = ProjectPath.NormalizeProjectDirectoryPath(path);
if (projectPath != null)
{
@ -228,7 +228,7 @@ namespace Microsoft.DotNet.ProjectModel
public ProjectContextCollection GetProjectContextCollection(string projectPath)
{
var normalizedPath = ProjectReader.NormalizeProjectDirectoryPath(projectPath);
var normalizedPath = ProjectPath.NormalizeProjectDirectoryPath(projectPath);
if (normalizedPath == null)
{
return null;
@ -242,7 +242,7 @@ namespace Microsoft.DotNet.ProjectModel
private FileModelEntry<Project> GetProjectCore(string projectDirectory)
{
var normalizedPath = ProjectReader.NormalizeProjectDirectoryPath(projectDirectory);
var normalizedPath = ProjectPath.NormalizeProjectDirectoryPath(projectDirectory);
if (normalizedPath == null)
{
return null;
@ -256,7 +256,7 @@ namespace Microsoft.DotNet.ProjectModel
private LockFile GetLockFile(string projectDirectory)
{
var normalizedPath = ProjectReader.NormalizeProjectDirectoryPath(projectDirectory);
var normalizedPath = ProjectPath.NormalizeProjectDirectoryPath(projectDirectory);
if (normalizedPath == null)
{
return null;