Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
namespace Microsoft.NET.Build.Tasks
{
/// <summary>
/// Represents an error that is neither avoidable in all cases nor indicative of a bug in this library.
/// It will be logged as a plain build error without the exception type or stack.
/// </summary>
internal class BuildErrorException : Exception
{
public BuildErrorException()
{
}
public BuildErrorException(string message) : base(message)
{
}
public BuildErrorException(string message, Exception innerException) : base(message, innerException)
{
}
public BuildErrorException(string format, params string[] args)
: this(string.Format(CultureInfo.CurrentCulture, format, args))
{
}
}
}

View File

@ -0,0 +1,62 @@
// 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;
using Microsoft.Build.Framework;
using NuGet.Common;
using NuGet.ProjectModel;
namespace Microsoft.NET.Build.Tasks
{
internal class LockFileCache
{
private IBuildEngine4 _buildEngine;
public LockFileCache(IBuildEngine4 buildEngine)
{
_buildEngine = buildEngine;
}
public LockFile GetLockFile(string path)
{
if (!Path.IsPathRooted(path))
{
throw new BuildErrorException("Assets file path '{0}' is not rooted. Only full paths are supported.", path);
}
string lockFileKey = GetTaskObjectKey(path);
LockFile result;
object existingLockFileTaskObject = _buildEngine.GetRegisteredTaskObject(lockFileKey, RegisteredTaskObjectLifetime.Build);
if (existingLockFileTaskObject == null)
{
result = LoadLockFile(path);
_buildEngine.RegisterTaskObject(lockFileKey, result, RegisteredTaskObjectLifetime.Build, true);
}
else
{
result = (LockFile)existingLockFileTaskObject;
}
return result;
}
private static string GetTaskObjectKey(string lockFilePath)
{
return $"{nameof(LockFileCache)}:{lockFilePath}";
}
private LockFile LoadLockFile(string path)
{
if (!File.Exists(path))
{
throw new BuildErrorException("Assets file '{0}' not found. Run a NuGet package restore to generate this file.", path);
}
// TODO - https://github.com/dotnet/sdk/issues/18 adapt task logger to Nuget Logger
return LockFileUtilities.GetLockFile(path, NullLogger.Instance);
}
}
}