This repository has been archived by the owner on Dec 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore global.json files when emitting projects during publish to fix #…
- Loading branch information
Showing
12 changed files
with
296 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"userkey": "uservalue" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": {}, | ||
"frameworks": { | ||
"dnx451": {}, | ||
"dnxcore50": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/Microsoft.Dnx.Testing.CommonUtils/ProjectResolver/IProjectResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
|
||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Dnx.Testing | ||
{ | ||
internal interface IProjectResolver | ||
{ | ||
IEnumerable<string> SearchPaths { get; } | ||
|
||
bool TryResolveProject(string name, out Runtime.Project project); | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
test/Microsoft.Dnx.Testing.CommonUtils/ProjectResolver/ProjectResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using Microsoft.Dnx.Runtime; | ||
|
||
namespace Microsoft.Dnx.Testing | ||
{ | ||
internal class ProjectResolver : IProjectResolver | ||
{ | ||
private readonly HashSet<string> _searchPaths = new HashSet<string>(); | ||
private ILookup<string, ProjectInformation> _projects; | ||
|
||
public ProjectResolver(string projectPath) | ||
{ | ||
var rootPath = ResolveRootDirectory(projectPath); | ||
Initialize(projectPath, rootPath); | ||
} | ||
|
||
public ProjectResolver(string projectPath, string rootPath) | ||
{ | ||
Initialize(projectPath, rootPath); | ||
} | ||
|
||
public IEnumerable<string> SearchPaths | ||
{ | ||
get | ||
{ | ||
return _searchPaths; | ||
} | ||
} | ||
|
||
public bool TryResolveProject(string name, out Runtime.Project project) | ||
{ | ||
project = null; | ||
|
||
if (!_projects.Contains(name)) | ||
{ | ||
return false; | ||
} | ||
|
||
// ProjectInformation.Project is lazily evaluated only once and | ||
// it returns null when ProjectInformation.FullPath doesn't contain project.json | ||
var candidates = _projects[name].Where(p => p.Project != null); | ||
if (candidates.Count() > 1) | ||
{ | ||
var allCandidatePaths = string.Join(Environment.NewLine, candidates.Select(x => x.FullPath).OrderBy(x => x)); | ||
throw new InvalidOperationException( | ||
$"The project name '{name}' is ambiguous between the following projects:{Environment.NewLine}{allCandidatePaths}"); | ||
} | ||
|
||
project = candidates.SingleOrDefault()?.Project; | ||
return project != null; | ||
} | ||
|
||
private void Initialize(string projectPath, string rootPath) | ||
{ | ||
_searchPaths.Add(new DirectoryInfo(projectPath).Parent.FullName); | ||
|
||
GlobalSettings global; | ||
|
||
if (GlobalSettings.TryGetGlobalSettings(rootPath, out global)) | ||
{ | ||
foreach (var sourcePath in global.ProjectSearchPaths) | ||
{ | ||
_searchPaths.Add(Path.Combine(rootPath, sourcePath)); | ||
} | ||
} | ||
|
||
Func<DirectoryInfo, ProjectInformation> dirInfoToProjectInfo = d => new ProjectInformation | ||
{ | ||
// The name of the folder is the project | ||
Name = d.Name, | ||
FullPath = d.FullName | ||
}; | ||
|
||
// Resolve all of the potential projects | ||
_projects = _searchPaths.Select(path => new DirectoryInfo(path)) | ||
.Where(d => d.Exists) | ||
.SelectMany(d => new[] { d }.Concat(d.EnumerateDirectories())) | ||
.Distinct(new DirectoryInfoFullPathComparator()) | ||
.Select(dirInfoToProjectInfo) | ||
.ToLookup(d => d.Name); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
_searchPaths.Clear(); | ||
_projects = null; | ||
} | ||
|
||
public static string ResolveRootDirectory(string projectPath) | ||
{ | ||
return ProjectRootResolver.ResolveRootDirectory(projectPath); | ||
} | ||
|
||
private class ProjectInformation | ||
{ | ||
private Runtime.Project _project; | ||
private bool _initialized; | ||
private object _lockObj = new object(); | ||
|
||
public string Name { get; set; } | ||
|
||
public string FullPath { get; set; } | ||
|
||
public Runtime.Project Project | ||
{ | ||
get | ||
{ | ||
return LazyInitializer.EnsureInitialized(ref _project, ref _initialized, ref _lockObj, () => | ||
{ | ||
Runtime.Project project; | ||
Runtime.Project.TryGetProject(FullPath, out project); | ||
return project; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
private class DirectoryInfoFullPathComparator : IEqualityComparer<DirectoryInfo> | ||
{ | ||
public bool Equals(DirectoryInfo x, DirectoryInfo y) | ||
{ | ||
return string.Equals(x.FullName, y.FullName); | ||
} | ||
|
||
public int GetHashCode(DirectoryInfo obj) | ||
{ | ||
return obj.FullName.GetHashCode(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
test/Microsoft.Dnx.Tooling.FunctionalTests/DnuPublishTests2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.IO; | ||
using System.Runtime.Versioning; | ||
using Microsoft.Dnx.Runtime; | ||
using Microsoft.Dnx.Runtime.Helpers; | ||
using Microsoft.Dnx.Testing; | ||
using Microsoft.Dnx.Tooling.Publish; | ||
using Newtonsoft.Json.Linq; | ||
using Xunit; | ||
|
||
namespace Microsoft.Dnx.Tooling.FunctionalTests | ||
{ | ||
[Collection(nameof(ToolingFunctionalTestCollection))] | ||
public class DnuPublishTests2 : DnxSdkFunctionalTestBase | ||
{ | ||
[Theory] | ||
[MemberData(nameof(DnxSdks))] | ||
public void GlobalJsonInProjectDir(DnxSdk sdk) | ||
{ | ||
const string solutionName = "GlobalJsonInProjectDir"; | ||
|
||
var solution = TestUtils.GetSolution<DnuPublishTests>(sdk, solutionName); | ||
var projectPath = Path.Combine(solution.RootPath, "Project"); | ||
var outputPath = Path.Combine(solution.RootPath, "Output"); | ||
|
||
var expectedOutputProjectJson = new JObject | ||
{ | ||
["dependencies"] = new JObject { }, | ||
["frameworks"] = new JObject | ||
{ | ||
["dnx451"] = new JObject { }, | ||
["dnxcore50"] = new JObject { } | ||
} | ||
}; | ||
|
||
var expectedOutputGlobalJson = new JObject | ||
{ | ||
["userkey"] = "uservalue", | ||
["projects"] = new JArray("src"), | ||
["packages"] = "packages" | ||
}; | ||
|
||
var expectedOutputLockFile = new JObject | ||
{ | ||
["locked"] = false, | ||
["version"] = Constants.LockFileVersion, | ||
["targets"] = new JObject | ||
{ | ||
["DNX,Version=v4.5.1"] = new JObject { }, | ||
["DNXCore,Version=v5.0"] = new JObject { }, | ||
}, | ||
["libraries"] = new JObject { }, | ||
["projectFileDependencyGroups"] = new JObject | ||
{ | ||
[""] = new JArray(), | ||
["DNX,Version=v4.5.1"] = new JArray(), | ||
["DNXCore,Version=v5.0"] = new JArray() | ||
} | ||
}; | ||
var expectedOutputStructure = new Dir | ||
{ | ||
["approot"] = new Dir | ||
{ | ||
[$"src/Project"] = new Dir | ||
{ | ||
["project.json"] = expectedOutputProjectJson, | ||
["project.lock.json"] = expectedOutputLockFile | ||
}, | ||
[$"global.json"] = expectedOutputGlobalJson | ||
} | ||
}; | ||
|
||
var result = sdk.Dnu.Publish( | ||
projectPath, | ||
outputPath); | ||
result.EnsureSuccess(); | ||
|
||
var actualOutputStructure = new Dir(outputPath); | ||
DirAssert.Equal(expectedOutputStructure, actualOutputStructure); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/Microsoft.Dnx.Tooling.FunctionalTests/ToolingFunctionalTestCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Xunit; | ||
|
||
namespace Microsoft.Dnx.Tooling.FunctionalTests | ||
{ | ||
|
||
[CollectionDefinition(nameof(ToolingFunctionalTestCollection))] | ||
public class ToolingFunctionalTestCollection : ICollectionFixture<ToolingFunctionalTestFixture> | ||
{ | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test/Microsoft.Dnx.Tooling.FunctionalTests/ToolingFunctionalTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.Dnx.Testing; | ||
|
||
namespace Microsoft.Dnx.Tooling.FunctionalTests | ||
{ | ||
public class ToolingFunctionalTestFixture : IDisposable | ||
{ | ||
public ToolingFunctionalTestFixture() | ||
{ | ||
Console.WriteLine($@" | ||
Environment information: | ||
DNX_HOME: {Environment.GetEnvironmentVariable("DNX_HOME")} | ||
DNX_SDK_VERSION_FOR_TESTING: {Environment.GetEnvironmentVariable("DNX_SDK_VERSION_FOR_TESTING")} | ||
Information of DNX under testing: | ||
DNX Home: {DnxSdk.GetRuntimeHome()} | ||
DNX Version: {DnxSdkFunctionalTestBase.SdkVersionForTesting} | ||
"); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters