Removing NuGetConfig from the first run experience and replacing the sentinel with the FirstUseNoticeSentinel when needed.

This commit is contained in:
Livar Cunha 2017-06-19 20:52:19 -07:00
parent 529d7caa79
commit a357fd7bca
15 changed files with 37 additions and 148 deletions

View file

@ -19,4 +19,4 @@ The data collected is anonymous and will be published in an aggregated form for
The .NET Core Tools telemetry feature is enabled by default. You can opt-out of the telemetry feature by setting an environment variable DOTNET_CLI_TELEMETRY_OPTOUT (for example, 'export' on macOS/Linux, 'set' on Windows) to true (for example, 'true', 1). You can read more about .NET Core tools telemetry at https://aka.ms/dotnet-cli-telemetry."
su - $SUDO_USER -c "dotnet new > /dev/null 2>&1 || true"
dotnet new > /dev/null 2>&1 || true

View file

@ -16,6 +16,17 @@ namespace Microsoft.DotNet.Configurer
Environment.GetEnvironmentVariable("DOTNET_CLI_TEST_FALLBACKFOLDER") ??
Path.Combine(new DirectoryInfo(AppContext.BaseDirectory).Parent.FullName, "NuGetFallbackFolder");
public string DotnetUserProfileFolderPath
{
get
{
string profileDir = Environment.GetEnvironmentVariable(
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "USERPROFILE" : "HOME");
return Path.Combine(profileDir, ".dotnet");
}
}
public string NuGetUserSettingsDirectory =>
NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);
}

View file

@ -41,13 +41,15 @@ namespace Microsoft.DotNet.Configurer
if (ShouldPrimeNugetCache())
{
if (_nugetCacheSentinel.UnauthorizedAccess)
{
PrintUnauthorizedAccessMessage();
}
PrintNugetCachePrimeMessage();
_nugetCachePrimer.PrimeCache();
}
else if (_nugetCacheSentinel.UnauthorizedAccess)
{
PrintUnauthorizedAccessMessage();
}
}
private bool ShouldPrintFirstTimeUseNotice()

View file

@ -14,19 +14,19 @@ namespace Microsoft.DotNet.Configurer
private readonly IFile _file;
private string _nugetCachePath;
private string _dotnetUserProfileFolderPath;
private string SentinelPath => Path.Combine(_nugetCachePath, SENTINEL);
private string SentinelPath => Path.Combine(_dotnetUserProfileFolderPath, SENTINEL);
public FirstTimeUseNoticeSentinel(CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator) :
this(cliFallbackFolderPathCalculator.CliFallbackFolderPath, FileSystemWrapper.Default.File)
this(cliFallbackFolderPathCalculator.DotnetUserProfileFolderPath, FileSystemWrapper.Default.File)
{
}
internal FirstTimeUseNoticeSentinel(string nugetCachePath, IFile file)
internal FirstTimeUseNoticeSentinel(string dotnetUserProfileFolderPath, IFile file)
{
_file = file;
_nugetCachePath = nugetCachePath;
_dotnetUserProfileFolderPath = dotnetUserProfileFolderPath;
}
public bool Exists()

View file

@ -1,10 +0,0 @@
// 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.
namespace Microsoft.DotNet.Configurer
{
public interface INuGetConfig
{
void AddCliFallbackFolder(string fallbackFolderPath);
}
}

View file

@ -143,7 +143,7 @@ Here are some options to fix this error:
---------------------
1. Re-run this command with elevated access.
2. Disabled the first run experience by setting the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to true.
3. Copy the .NET Core SDK to a non-protected location and use it from there.";
3. Copy the .NET Core SDK to a non-protected location and use it from there.
</value>
</data>
</root>

View file

@ -17,18 +17,14 @@ namespace Microsoft.DotNet.Configurer
private readonly INuGetCacheSentinel _nuGetCacheSentinel;
private readonly INuGetConfig _nuGetConfig;
private readonly CliFallbackFolderPathCalculator _cliFallbackFolderPathCalculator;
public NuGetCachePrimer(
INuGetPackagesArchiver nugetPackagesArchiver,
INuGetCacheSentinel nuGetCacheSentinel,
INuGetConfig nuGetConfig,
CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator)
: this(nugetPackagesArchiver,
nuGetCacheSentinel,
nuGetConfig,
cliFallbackFolderPathCalculator,
FileSystemWrapper.Default.File)
{
@ -37,7 +33,6 @@ namespace Microsoft.DotNet.Configurer
internal NuGetCachePrimer(
INuGetPackagesArchiver nugetPackagesArchiver,
INuGetCacheSentinel nuGetCacheSentinel,
INuGetConfig nuGetConfig,
CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator,
IFile file)
{
@ -45,8 +40,6 @@ namespace Microsoft.DotNet.Configurer
_nuGetCacheSentinel = nuGetCacheSentinel;
_nuGetConfig = nuGetConfig;
_cliFallbackFolderPathCalculator = cliFallbackFolderPathCalculator;
_file = file;
@ -63,8 +56,6 @@ namespace Microsoft.DotNet.Configurer
_nugetPackagesArchiver.ExtractArchive(nuGetFallbackFolder);
_nuGetConfig.AddCliFallbackFolder(nuGetFallbackFolder);
_nuGetCacheSentinel.CreateIfNotExists();
}

View file

@ -1,39 +0,0 @@
// 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 NuGet.Common;
using NuGet.Configuration;
using System.Linq;
namespace Microsoft.DotNet.Configurer
{
public class NuGetConfig : INuGetConfig
{
public const string FallbackPackageFolders = "packageSources";
private ISettings _settings;
public NuGetConfig(CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator)
{
_settings = new Settings(cliFallbackFolderPathCalculator.NuGetUserSettingsDirectory);
}
internal NuGetConfig(ISettings settings)
{
_settings = settings;
}
public void AddCliFallbackFolder(string fallbackFolderPath)
{
if (!IsCliFallbackFolderSet(fallbackFolderPath))
{
_settings.SetValue(FallbackPackageFolders, "CliFallbackFolder", fallbackFolderPath);
}
}
private bool IsCliFallbackFolderSet(string fallbackFolderPath)
{
return _settings.GetSettingValues(FallbackPackageFolders).Any(s => s.Value == fallbackFolderPath);
}
}
}

View file

@ -128,7 +128,7 @@ namespace Microsoft.DotNet.Cli
if (telemetryClient == null)
{
telemetryClient = new Telemetry(nugetCacheSentinel);
telemetryClient = new Telemetry(firstTimeUseNoticeSentinel);
}
}
@ -177,18 +177,16 @@ namespace Microsoft.DotNet.Cli
var nugetPackagesArchiver = new NuGetPackagesArchiver();
var environmentProvider = new EnvironmentProvider();
var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true);
var nugetConfig = new NuGetConfig(cliFallbackFolderPathCalculator);
var nugetCachePrimer = new NuGetCachePrimer(
nugetPackagesArchiver,
nugetCacheSentinel,
nugetConfig,
cliFallbackFolderPathCalculator);
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
nugetCachePrimer,
nugetCacheSentinel,
firstTimeUseNoticeSentinel,
environmentProvider,
Reporter.Output
Reporter.Output,
cliFallbackFolderPathCalculator.CliFallbackFolderPath);
dotnetConfigurer.Configure();

View file

@ -35,9 +35,9 @@ namespace Microsoft.DotNet.Cli
public Telemetry () : this(null) { }
public Telemetry(INuGetCacheSentinel sentinel) : this(sentinel, null) { }
public Telemetry(IFirstTimeUseNoticeSentinel sentinel) : this(sentinel, null) { }
public Telemetry(INuGetCacheSentinel sentinel, string sessionId)
public Telemetry(IFirstTimeUseNoticeSentinel sentinel, string sessionId)
{
Enabled = !Env.GetEnvironmentVariableAsBool(TelemetryOptout) && PermissionExists(sentinel);
@ -53,7 +53,7 @@ namespace Microsoft.DotNet.Cli
_trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry());
}
private bool PermissionExists(INuGetCacheSentinel sentinel)
private bool PermissionExists(IFirstTimeUseNoticeSentinel sentinel)
{
if (sentinel == null)
{

View file

@ -11,7 +11,8 @@ namespace Microsoft.DotNet.Tools.MSBuild
{
public sealed class MSBuildLogger : Logger
{
private readonly INuGetCacheSentinel _sentinel = new NuGetCacheSentinel(new CliFallbackFolderPathCalculator());
private readonly IFirstTimeUseNoticeSentinel _sentinel =
new FirstTimeUseNoticeSentinel(new CliFallbackFolderPathCalculator());
private readonly ITelemetry _telemetry;
public MSBuildLogger()

View file

@ -28,8 +28,10 @@ namespace Microsoft.DotNet.Tools.New
public static int Run(string[] args)
{
var sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
var telemetry = new Telemetry(new NuGetCacheSentinel(new CliFallbackFolderPathCalculator()), sessionId);
var sessionId =
Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
var telemetry =
new Telemetry(new FirstTimeUseNoticeSentinel(new CliFallbackFolderPathCalculator()), sessionId);
var logger = new TelemetryLogger(null);
if (telemetry.Enabled)

View file

@ -26,7 +26,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
private Mock<INuGetPackagesArchiver> _nugetPackagesArchiverMock;
private Mock<INuGetCacheSentinel> _nugetCacheSentinel;
private Mock<INuGetConfig> _nugetConfigMock;
private CliFallbackFolderPathCalculator _cliFallbackFolderPathCalculator;
public GivenANuGetCachePrimer()
@ -41,14 +40,11 @@ namespace Microsoft.DotNet.Configurer.UnitTests
_nugetCacheSentinel = new Mock<INuGetCacheSentinel>();
_nugetConfigMock = new Mock<INuGetConfig>();
_cliFallbackFolderPathCalculator = new CliFallbackFolderPathCalculator();
var nugetCachePrimer = new NuGetCachePrimer(
_nugetPackagesArchiverMock.Object,
_nugetCacheSentinel.Object,
_nugetConfigMock.Object,
_cliFallbackFolderPathCalculator,
_fileSystemMock.File);
@ -67,7 +63,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
var nugetCachePrimer = new NuGetCachePrimer(
nugetPackagesArchiverMock.Object,
_nugetCacheSentinel.Object,
_nugetConfigMock.Object,
_cliFallbackFolderPathCalculator,
fileSystemMock.File);
@ -76,14 +71,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
nugetPackagesArchiverMock.Verify(n => n.ExtractArchive(It.IsAny<string>()), Times.Never);
}
[Fact]
public void It_adds_the_fallback_folder_to_NuGet_Config()
{
_nugetConfigMock.Verify(n =>
n.AddCliFallbackFolder(_cliFallbackFolderPathCalculator.CliFallbackFolderPath),
Times.Exactly(1));
}
[Fact]
public void It_extracts_the_archive_to_the_fallback_folder()
{
@ -108,7 +95,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
var nugetCachePrimer = new NuGetCachePrimer(
nugetPackagesArchiveMock.Object,
nugetCacheSentinel.Object,
_nugetConfigMock.Object,
_cliFallbackFolderPathCalculator,
_fileSystemMock.File);

View file

@ -1,53 +0,0 @@
// 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.Collections.Generic;
using FluentAssertions;
using Moq;
using NuGet.Configuration;
using Xunit;
namespace Microsoft.DotNet.Configurer.UnitTests
{
public class GivenANuGetConfig
{
private const string PathToFallbackFolderAlreadySet = "some path to fallback folder";
private Mock<ISettings> _settingsMock;
private INuGetConfig _nugetConfig;
public GivenANuGetConfig()
{
_settingsMock = new Mock<ISettings>();
_settingsMock
.Setup(s => s.GetSettingValues(NuGetConfig.FallbackPackageFolders, false))
.Returns(new List<SettingValue>()
{
new SettingValue("CliFallbackFolder", PathToFallbackFolderAlreadySet, false)
});
_nugetConfig = new NuGetConfig(_settingsMock.Object);
}
[Fact]
public void ItAddsACliFallbackFolderIfOneIsNotPresentAlready()
{
const string FallbackFolderNotAlreadySet = "some path not already set";
_nugetConfig.AddCliFallbackFolder(FallbackFolderNotAlreadySet);
_settingsMock.Verify(s =>
s.SetValue(NuGetConfig.FallbackPackageFolders, "CliFallbackFolder", FallbackFolderNotAlreadySet),
Times.Exactly(1));
}
[Fact]
public void ItDoesNotAddTheCliFallbackFolderIfItIsAlreadyPresent()
{
_nugetConfig.AddCliFallbackFolder(PathToFallbackFolderAlreadySet);
_settingsMock.Verify(s =>
s.SetValue(NuGetConfig.FallbackPackageFolders, "CliFallbackFolder", PathToFallbackFolderAlreadySet),
Times.Never);
}
}
}

View file

@ -109,7 +109,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
result.Should().Fail();
result.StdOut.Should().ContainVisuallySameFragment(@"source(s): /usr/local/bin, nuget.org");
result.StdOut.Should().ContainVisuallySameFragment("NU1101");
}
[Fact]
@ -186,7 +186,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
}
}
public sealed class MockNuGetCacheSentinel : INuGetCacheSentinel
public sealed class MockNuGetCacheSentinel : IFirstTimeUseNoticeSentinel
{
private readonly Func<bool> _exists;