Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/Cake.Core/Packaging/PackageReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace Cake.Core.Packaging
{
Expand Down Expand Up @@ -44,6 +44,12 @@
/// <value>The package.</value>
public string Package { get; }

/// <summary>
/// Gets the package version.
/// </summary>
/// <value>The package version.</value>
public string? Version { get; }

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (macos-13)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (macos-13)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (macos-13)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 51 in src/Cake.Core/Packaging/PackageReference.cs

View workflow job for this annotation

GitHub Actions / Build (macos-13)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Initializes a new instance of the <see cref="PackageReference"/> class.
/// </summary>
Expand Down Expand Up @@ -85,11 +91,39 @@
nameof(uri));
}

Uri address;
if (Uri.TryCreate(uri.AbsolutePath, UriKind.Absolute, out address))
if (Parameters.TryGetValue("version", out var versionParameters))
{
if (versionParameters.Count == 1)
{
Version = versionParameters.FirstOrDefault();
}
else if (versionParameters.Count > 1)
{
throw new ArgumentException(
"Query string contains more than one parameter 'version'.",
nameof(uri));
}
}

if (Uri.TryCreate(uri.AbsolutePath, UriKind.Absolute, out var address))
{
Address = new Uri(address.AbsoluteUri);
}
}

/// <inheritdoc />
public override string ToString()
{
var stringBuilder = new StringBuilder();

stringBuilder.Append(Package);

if (!string.IsNullOrEmpty(Version))
{
stringBuilder.Append($" v{Version}");
}

return stringBuilder.ToString();
}
}
}
5 changes: 2 additions & 3 deletions src/Cake.Core/Scripting/ScriptProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public IReadOnlyList<FilePath> InstallAddins(
if (assemblies.Count == 0)
{
const string format = "Failed to install addin '{0}'.";
var message = string.Format(CultureInfo.InvariantCulture, format, addin.Package);
var message = string.Format(CultureInfo.InvariantCulture, format, addin);
throw new CakeException(message);
}

Expand Down Expand Up @@ -230,8 +230,7 @@ private void InstallPackages(

private void CheckPackageVersion(PackageReference packageReference, string directiveName)
{
bool existsVersionParameter = packageReference.Parameters.Any(x => x.Key.Equals("version", StringComparison.OrdinalIgnoreCase));
if (!existsVersionParameter && !_skipPackageVersionCheck)
if (string.IsNullOrWhiteSpace(packageReference.Version) && !_skipPackageVersionCheck)
{
const string message = "The '{0}' directive is attempting to install the '{1}' package \r\n" +
"without specifying a package version number. \r\n" +
Expand Down
23 changes: 23 additions & 0 deletions src/Cake.Core/Scripting/ScriptRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Cake.Core.Configuration;
Expand Down Expand Up @@ -75,16 +76,23 @@
throw new ArgumentNullException(nameof(scriptPath));
}

var preparationStopwatch = Stopwatch.StartNew();

// Make the script path absolute.
scriptPath = scriptPath.MakeAbsolute(_environment);

// Prepare the environment.
_environment.WorkingDirectory = scriptPath.GetDirectory();

// Analyze the script file.
var analyzeStopwatch = Stopwatch.StartNew();

_log.Verbose("Analyzing build script...");
var result = _analyzer.Analyze(scriptPath.GetFilename(), new ScriptAnalyzerSettings());

analyzeStopwatch.Stop();
_log.Verbose("Analyzed build script in {0}", analyzeStopwatch.Elapsed);

// Log all errors and throw
if (!result.Succeeded)
{
Expand All @@ -98,17 +106,29 @@

// Install tools.
_log.Verbose("Processing build script...");

var toolsStopwatch = Stopwatch.StartNew();

var toolsPath = GetToolPath(scriptPath.GetDirectory());
_processor.InstallTools(result.Tools, toolsPath);

toolsStopwatch.Stop();
_log.Verbose("Installed tools in {0}", toolsStopwatch.Elapsed);

// Install addins.

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (macos-13)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (macos-13)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (macos-13)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

Check failure on line 118 in src/Cake.Core/Scripting/ScriptRunner.cs

View workflow job for this annotation

GitHub Actions / Build (macos-13)

Single-line comments should not be followed by blank line (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1512.md)

var addingsStopwatch = Stopwatch.StartNew();

var addinRoot = GetAddinPath(scriptPath.GetDirectory());
var addinReferences = _processor.InstallAddins(result.Addins, addinRoot);
foreach (var addinReference in addinReferences)
{
result.References.Add(addinReference.FullPath);
}

addingsStopwatch.Stop();
_log.Verbose("Installed addins in {0}", addingsStopwatch.Elapsed);

// Create and prepare the session.
var session = _engine.CreateSession(host);

Expand Down Expand Up @@ -167,6 +187,9 @@
var defines = new HashSet<string>(result.Defines, StringComparer.Ordinal);
defines.AddRange(_conventions.GetDefaultDefines());

preparationStopwatch.Stop();
_log.Verbose("Preparation took {0}, going to execute the script", preparationStopwatch.Elapsed);

// Execute the script.
var script = new Script(result.Namespaces, result.Lines, aliases, result.UsingAliases, result.UsingStaticDirectives, defines);
session.Execute(script);
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.NuGet/Installers/InProcessInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public IReadOnlyCollection<IFile> Install(PackageReference package, PackageType

// If the installed package is not the target package, create a new PackageReference
// which is passed to the content resolver. This makes logging make more sense.
var installedPackageReference = isTargetPackage ? package : new PackageReference($"nuget:?package={packageToInstall.Id}");
var installedPackageReference = isTargetPackage ? package : new PackageReference($"nuget:?package={packageToInstall.Id}&version={packageToInstall.Version}");
var assemblies = _contentResolver.GetFiles(installPath, installedPackageReference, type);
if (assemblies.Count == 0)
{
Expand Down
Loading