Skip to content
This repository was archived by the owner on Dec 18, 2017. It is now read-only.

Commit 73b00ff

Browse files
committedSep 17, 2015
Ignore global.json files when emitting projects during publish to fix #2656
1 parent b8fc4b2 commit 73b00ff

File tree

12 files changed

+288
-11
lines changed

12 files changed

+288
-11
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "1.0.0-beta7"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"dependencies": {},
3+
"frameworks": {
4+
"dnx451": {},
5+
"dnxcore50": {}
6+
}
7+
}

‎src/Microsoft.Dnx.Runtime/ProjectFilesCollection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.Dnx.Runtime
1212
public class ProjectFilesCollection
1313
{
1414
public static readonly string[] DefaultCompileBuiltInPatterns = new[] { @"**/*.cs" };
15-
public static readonly string[] DefaultPublishExcludePatterns = new[] { @"obj/**/*.*", @"bin/**/*.*", @"**/.*/**" };
15+
public static readonly string[] DefaultPublishExcludePatterns = new[] { @"obj/**/*.*", @"bin/**/*.*", @"**/.*/**", @"**/global.json" };
1616
public static readonly string[] DefaultPreprocessPatterns = new[] { @"compiler/preprocess/**/*.cs" };
1717
public static readonly string[] DefaultSharedPatterns = new[] { @"compiler/shared/**/*.cs" };
1818
public static readonly string[] DefaultResourcesBuiltInPatterns = new[] { @"compiler/resources/**/*", "**/*.resx" };

‎test/Microsoft.Dnx.Testing.CommonUtils/DnxSdk/DnxSdk.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class DnxSdk
2828

2929
public static string GetRuntimeHome()
3030
{
31-
var homePath = Environment.ExpandEnvironmentVariables(Environment.GetEnvironmentVariable("DNX_HOME"));
31+
var dnxHomePath = Environment.GetEnvironmentVariable("DNX_HOME");
32+
var homePath = string.IsNullOrEmpty(dnxHomePath) ? null : Environment.ExpandEnvironmentVariables(dnxHomePath);
3233

3334
if (string.IsNullOrEmpty(homePath))
3435
{

‎test/Microsoft.Dnx.Testing.CommonUtils/ProjectExtensions.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33

44
using System;
55
using System.IO;
6+
using Microsoft.Dnx.Runtime;
67
using Newtonsoft.Json.Linq;
78

89
namespace Microsoft.Dnx.Testing
910
{
1011
public static class ProjectExtensions
1112
{
12-
public static string GetBinPath(this Runtime.Project project)
13+
public static string GetBinPath(this Project project)
1314
{
1415
return Path.Combine(project.ProjectDirectory, "bin");
1516
}
1617

17-
public static string GetLocalPackagesDir(this Runtime.Project project)
18+
public static string GetLocalPackagesDir(this Project project)
1819
{
1920
return Path.Combine(project.ProjectDirectory, "packages");
2021
}
2122

22-
public static void UpdateProjectFile(this Runtime.Project project, Action<JObject> updateContents)
23+
public static void UpdateProjectFile(this Project project, Action<JObject> updateContents)
2324
{
2425
JsonUtils.UpdateJson(project.ProjectFilePath, updateContents);
2526
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Threading;
9+
using Microsoft.Dnx.Runtime;
10+
11+
namespace Microsoft.Dnx.Testing
12+
{
13+
internal class ProjectResolver
14+
{
15+
private readonly HashSet<string> _searchPaths = new HashSet<string>();
16+
private ILookup<string, ProjectInformation> _projects;
17+
18+
public ProjectResolver(string projectPath)
19+
{
20+
var rootPath = ResolveRootDirectory(projectPath);
21+
Initialize(projectPath, rootPath);
22+
}
23+
24+
public ProjectResolver(string projectPath, string rootPath)
25+
{
26+
Initialize(projectPath, rootPath);
27+
}
28+
29+
public IEnumerable<string> SearchPaths
30+
{
31+
get
32+
{
33+
return _searchPaths;
34+
}
35+
}
36+
37+
public bool TryResolveProject(string name, out Project project)
38+
{
39+
project = null;
40+
41+
if (!_projects.Contains(name))
42+
{
43+
return false;
44+
}
45+
46+
// ProjectInformation.Project is lazily evaluated only once and
47+
// it returns null when ProjectInformation.FullPath doesn't contain project.json
48+
var candidates = _projects[name].Where(p => p.Project != null);
49+
if (candidates.Count() > 1)
50+
{
51+
var allCandidatePaths = string.Join(Environment.NewLine, candidates.Select(x => x.FullPath).OrderBy(x => x));
52+
throw new InvalidOperationException(
53+
$"The project name '{name}' is ambiguous between the following projects:{Environment.NewLine}{allCandidatePaths}");
54+
}
55+
56+
project = candidates.SingleOrDefault()?.Project;
57+
return project != null;
58+
}
59+
60+
private void Initialize(string projectPath, string rootPath)
61+
{
62+
_searchPaths.Add(new DirectoryInfo(projectPath).Parent.FullName);
63+
64+
GlobalSettings global;
65+
66+
if (GlobalSettings.TryGetGlobalSettings(rootPath, out global))
67+
{
68+
foreach (var sourcePath in global.ProjectSearchPaths)
69+
{
70+
_searchPaths.Add(Path.Combine(rootPath, sourcePath));
71+
}
72+
}
73+
74+
Func<DirectoryInfo, ProjectInformation> dirInfoToProjectInfo = d => new ProjectInformation
75+
{
76+
// The name of the folder is the project
77+
Name = d.Name,
78+
FullPath = d.FullName
79+
};
80+
81+
// Resolve all of the potential projects
82+
_projects = _searchPaths.Select(path => new DirectoryInfo(path))
83+
.Where(d => d.Exists)
84+
.SelectMany(d => new[] { d }.Concat(d.EnumerateDirectories()))
85+
.Distinct(new DirectoryInfoFullPathComparator())
86+
.Select(dirInfoToProjectInfo)
87+
.ToLookup(d => d.Name);
88+
}
89+
90+
public void Clear()
91+
{
92+
_searchPaths.Clear();
93+
_projects = null;
94+
}
95+
96+
public static string ResolveRootDirectory(string projectPath)
97+
{
98+
return ProjectRootResolver.ResolveRootDirectory(projectPath);
99+
}
100+
101+
private class ProjectInformation
102+
{
103+
private Project _project;
104+
private bool _initialized;
105+
private object _lockObj = new object();
106+
107+
public string Name { get; set; }
108+
109+
public string FullPath { get; set; }
110+
111+
public Project Project
112+
{
113+
get
114+
{
115+
return LazyInitializer.EnsureInitialized(ref _project, ref _initialized, ref _lockObj, () =>
116+
{
117+
Project project;
118+
Project.TryGetProject(FullPath, out project);
119+
return project;
120+
});
121+
}
122+
}
123+
}
124+
125+
private class DirectoryInfoFullPathComparator : IEqualityComparer<DirectoryInfo>
126+
{
127+
public bool Equals(DirectoryInfo x, DirectoryInfo y)
128+
{
129+
return string.Equals(x.FullName, y.FullName);
130+
}
131+
132+
public int GetHashCode(DirectoryInfo obj)
133+
{
134+
return obj.FullName.GetHashCode();
135+
}
136+
}
137+
}
138+
}

‎test/Microsoft.Dnx.Testing.CommonUtils/Solution.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.IO;
77
using System.Linq;
88
using Microsoft.Dnx.Runtime;
9-
using Microsoft.Dnx.Tooling;
109

1110
namespace Microsoft.Dnx.Testing
1211
{
@@ -28,7 +27,7 @@ public Solution(string rootPath)
2827

2928
public string RootPath { get; private set; }
3029

31-
public IEnumerable<Runtime.Project> Projects
30+
public IEnumerable<Project> Projects
3231
{
3332
get
3433
{

‎test/Microsoft.Dnx.Testing.CommonUtils/project.json

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
"Newtonsoft.Json": "6.0.6",
66
"xunit.runner.aspnet": "2.0.0-aspnet-*"
77
},
8-
"compile": [
9-
"../../src/Microsoft.Dnx.Tooling/ProjectResolver.cs",
10-
"../../src/Microsoft.Dnx.Tooling/IProjectResolver.cs"
11-
],
128
"frameworks": {
139
"dnx451": { },
1410
"dnxcore50": { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.IO;
5+
using System.Runtime.Versioning;
6+
using Microsoft.Dnx.Runtime;
7+
using Microsoft.Dnx.Runtime.Helpers;
8+
using Microsoft.Dnx.Testing;
9+
using Microsoft.Dnx.Tooling.Publish;
10+
using Newtonsoft.Json.Linq;
11+
using Xunit;
12+
13+
namespace Microsoft.Dnx.Tooling.FunctionalTests
14+
{
15+
[Collection(nameof(ToolingFunctionalTestCollection))]
16+
public class DnuPublishTests2 : DnxSdkFunctionalTestBase
17+
{
18+
[Theory]
19+
[MemberData(nameof(DnxSdks))]
20+
public void GlobalJsonInProjectDir(DnxSdk sdk)
21+
{
22+
const string solutionName = "GlobalJsonInProjectDir";
23+
24+
var solution = TestUtils.GetSolution<DnuPublishTests>(sdk, solutionName);
25+
var projectPath = Path.Combine(solution.RootPath, "Project");
26+
var outputPath = Path.Combine(solution.RootPath, "Output");
27+
28+
var expectedOutputProjectJson = new JObject
29+
{
30+
["dependencies"] = new JObject { },
31+
["frameworks"] = new JObject
32+
{
33+
["dnx451"] = new JObject { },
34+
["dnxcore50"] = new JObject { }
35+
}
36+
};
37+
38+
var expectedOutputGlobalJson = new JObject
39+
{
40+
["sdk"] = new JObject
41+
{
42+
["version"] = "1.0.0-beta7"
43+
},
44+
["projects"] = new JArray("src"),
45+
["packages"] = "packages"
46+
};
47+
48+
var expectedOutputLockFile = new JObject
49+
{
50+
["locked"] = false,
51+
["version"] = Constants.LockFileVersion,
52+
["targets"] = new JObject
53+
{
54+
["DNX,Version=v4.5.1"] = new JObject { },
55+
["DNXCore,Version=v5.0"] = new JObject { },
56+
},
57+
["libraries"] = new JObject { },
58+
["projectFileDependencyGroups"] = new JObject
59+
{
60+
[""] = new JArray(),
61+
["DNX,Version=v4.5.1"] = new JArray(),
62+
["DNXCore,Version=v5.0"] = new JArray()
63+
}
64+
};
65+
var expectedOutputStructure = new Dir
66+
{
67+
["approot"] = new Dir
68+
{
69+
[$"src/Project"] = new Dir
70+
{
71+
["project.json"] = expectedOutputProjectJson,
72+
["project.lock.json"] = expectedOutputLockFile
73+
},
74+
[$"global.json"] = expectedOutputGlobalJson
75+
}
76+
};
77+
78+
var result = sdk.Dnu.Publish(
79+
projectPath,
80+
outputPath);
81+
result.EnsureSuccess();
82+
83+
var actualOutputStructure = new Dir(outputPath);
84+
DirAssert.Equal(expectedOutputStructure, actualOutputStructure);
85+
}
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Xunit;
5+
6+
namespace Microsoft.Dnx.Tooling.FunctionalTests
7+
{
8+
9+
[CollectionDefinition(nameof(ToolingFunctionalTestCollection))]
10+
public class ToolingFunctionalTestCollection : ICollectionFixture<ToolingFunctionalTestFixture>
11+
{
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Microsoft.Dnx.Testing;
6+
7+
namespace Microsoft.Dnx.Tooling.FunctionalTests
8+
{
9+
public class ToolingFunctionalTestFixture : IDisposable
10+
{
11+
public ToolingFunctionalTestFixture()
12+
{
13+
Console.WriteLine($@"
14+
Environment information:
15+
DNX_HOME: {Environment.GetEnvironmentVariable("DNX_HOME")}
16+
DNX_SDK_VERSION_FOR_TESTING: {Environment.GetEnvironmentVariable("DNX_SDK_VERSION_FOR_TESTING")}
17+
18+
Information of DNX under testing:
19+
DNX Home: {DnxSdk.GetRuntimeHome()}
20+
DNX Version: {DnxSdkFunctionalTestBase.SdkVersionForTesting}
21+
");
22+
}
23+
24+
public void Dispose()
25+
{
26+
27+
}
28+
}
29+
}

‎test/Microsoft.Dnx.Tooling.FunctionalTests/project.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"Microsoft.AspNet.Testing": "1.0.0-*",
44
"Microsoft.Dnx.CommonTestUtils": "1.0.0-*",
55
"Microsoft.Dnx.Runtime.Sources": "1.0.0-*",
6+
"Microsoft.Dnx.Testing.CommonUtils": "1.0.0-*",
67
"Microsoft.Dnx.Tooling": "1.0.0-*",
78
"xunit.runner.aspnet": "2.0.0-aspnet-*"
89
},

0 commit comments

Comments
 (0)
This repository has been archived.