Skip to content

Commit

Permalink
Update default NuGet to 4.1.0 (#5805)
Browse files Browse the repository at this point in the history
  • Loading branch information
keithrob authored Nov 18, 2017
1 parent c798166 commit e0c8b42
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 33 deletions.
41 changes: 25 additions & 16 deletions Tasks/Common/nuget-task-common/NuGetToolGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ enum NuGetReleaseStage

const NUGET_TOOL_NAME: string = 'NuGet';
const NUGET_EXE_FILENAME: string = 'nuget.exe';
const NUGET_VERSION_4_0_0: string = '4.0.0';

export const FORCE_NUGET_4_0_0: string = 'FORCE_NUGET_4_0_0';
export const NUGET_VERSION_4_0_0: string = '4.0.0';
export const NUGET_VERSION_4_0_0_PATH_SUFFIX: string = 'NuGet/4.0.0/';
export const DEFAULT_NUGET_VERSION: string = '4.1.0';
export const DEFAULT_NUGET_PATH_SUFFIX: string = 'NuGet/4.1.0/';
export const NUGET_EXE_TOOL_PATH_ENV_VAR: string = 'NuGetExeToolPath';

export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNuGetToPath?: boolean): Promise<string> {
if (toolLib.isExplicitVersion(versionSpec)) {
// Check latest doesn't make sense when explicit version
checkLatest = false;
checkLatest = false;
taskLib.debug('Exact match expected on version: ' + versionSpec);
}
else {
Expand Down Expand Up @@ -65,7 +69,7 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu

if (!versionInfo.url)
{
taskLib.error(taskLib.loc("Error_NoUrlWasFoundWhichMatches", version));
taskLib.error(taskLib.loc("Error_NoUrlWasFoundWhichMatches", version));
throw new Error(taskLib.loc("Error_NuGetToolInstallerFailer", NUGET_TOOL_NAME));
}

Expand Down Expand Up @@ -94,12 +98,20 @@ export async function getNuGet(versionSpec: string, checkLatest?: boolean, addNu
return fullNuGetPath;
}

export async function cacheBundledNuGet_4_0_0() {
if (!toolLib.findLocalTool(NUGET_TOOL_NAME, NUGET_VERSION_4_0_0)) {
taskLib.debug('Placing bundled NuGet.exe 4.0.0 in tool lib cache');

let bundledNuGet4Location: string = getBundledNuGet_4_0_0_Location();
toolLib.cacheFile(bundledNuGet4Location, NUGET_EXE_FILENAME, NUGET_TOOL_NAME, NUGET_VERSION_4_0_0);
export async function cacheBundledNuGet() {
let cachedVersionToUse = DEFAULT_NUGET_VERSION;
let nugetPathSuffix = DEFAULT_NUGET_PATH_SUFFIX;
if (taskLib.getVariable(FORCE_NUGET_4_0_0) &&
taskLib.getVariable(FORCE_NUGET_4_0_0).toLowerCase() === "true"){
cachedVersionToUse = NUGET_VERSION_4_0_0;
nugetPathSuffix = NUGET_VERSION_4_0_0_PATH_SUFFIX;
}

if (!toolLib.findLocalTool(NUGET_TOOL_NAME, cachedVersionToUse)) {
taskLib.debug(`Placing bundled NuGet.exe ${cachedVersionToUse} in tool lib cache`);

let bundledNuGet4Location: string = getBundledNuGet_Location([nugetPathSuffix]);
toolLib.cacheFile(bundledNuGet4Location, NUGET_EXE_FILENAME, NUGET_TOOL_NAME, cachedVersionToUse);
}
}

Expand All @@ -115,10 +127,10 @@ function GetRestClientOptions(): restm.IRequestOptions

async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVersionInfo> {
taskLib.debug('Querying versions list');

let versionsUrl = 'https://dist.nuget.org/tools.json';
let rest: restm.RestClient = new restm.RestClient('vsts-tasks/NuGetToolInstaller');

let nugetVersions: INuGetVersionInfo[] = (await rest.get<INuGetVersionInfo[]>(versionsUrl, GetRestClientOptions())).result;
// x.stage is the string representation of the enum, NuGetReleaseStage.Value = number, NuGetReleaseStage[NuGetReleaseStage.Value] = string, NuGetReleaseStage[x.stage] = number
let releasedVersions: INuGetVersionInfo[] = nugetVersions.filter(x => x.stage.toString() !== NuGetReleaseStage[NuGetReleaseStage.EarlyAccessPreview]);
Expand All @@ -127,7 +139,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVer
let version: string = toolLib.evaluateVersions(versionStringsFromDist, versionSpec);
if (!version)
{
taskLib.error(taskLib.loc("Error_NoVersionWasFoundWhichMatches", versionSpec));
taskLib.error(taskLib.loc("Error_NoVersionWasFoundWhichMatches", versionSpec));
taskLib.error(taskLib.loc("Info_AvailableVersions", releasedVersions.map(x => x.version).join("; ")));
throw new Error(taskLib.loc("Error_NuGetToolInstallerFailer", NUGET_TOOL_NAME));
}
Expand All @@ -136,10 +148,7 @@ async function getLatestMatchVersionInfo(versionSpec: string): Promise<INuGetVer
}



function getBundledNuGet_4_0_0_Location(): string {
const nugetPaths: string[] = ['NuGet/4.0.0/'];

function getBundledNuGet_Location(nugetPaths: string[]): string {
let taskNodeModulesPath: string = path.dirname(__dirname);
let taskRootPath: string = path.dirname(taskNodeModulesPath);
const toolPath = commandHelper.locateTool("NuGet",
Expand Down
29 changes: 17 additions & 12 deletions Tasks/NuGetCommand/Tests/NugetMockHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import * as nugetPackUtils from "nuget-task-common/PackUtilities"
export class NugetMockHelper {
private defaultNugetVersion = '4.0.0';
private defaultNugetVersionInfo = [4,0,0,0];

constructor(
private tmr: tmrm.TaskMockRunner) {
private tmr: tmrm.TaskMockRunner) {
process.env['AGENT_HOMEDIRECTORY'] = "c:\\agent\\home\\directory";
process.env['BUILD_SOURCESDIRECTORY'] = "c:\\agent\\home\\directory\\sources",
process.env['ENDPOINT_AUTH_SYSTEMVSSCONNECTION'] = "{\"parameters\":{\"AccessToken\":\"token\"},\"scheme\":\"OAuth\"}";
process.env['ENDPOINT_URL_SYSTEMVSSCONNECTION'] = "https://example.visualstudio.com/defaultcollection";
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = "c:\\agent\\home\\directory";
process.env['SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'] = "https://example.visualstudio.com/defaultcollection";
}

public setNugetVersionInputDefault() {
}

public registerDefaultNugetVersionMock() {
this.registerNugetVersionMock(this.defaultNugetVersion, this.defaultNugetVersionInfo);
this.registerNugetToolGetterMock();
Expand All @@ -31,11 +31,16 @@ export class NugetMockHelper {
getNuGet: function(versionSpec) {
return "c:\\from\\tool\\installer\\nuget.exe";
},
cacheBundledNuGet_4_0_0: function()
{}
cacheBundledNuGet: function(){},
FORCE_NUGET_4_0_0: 'FORCE_NUGET_4_0_0',
NUGET_VERSION_4_0_0: '4.0.0',
NUGET_VERSION_4_0_0_PATH_SUFFIX: 'NuGet/4.0.0/',
DEFAULT_NUGET_VERSION: '4.1.0',
DEFAULT_NUGET_PATH_SUFFIX: 'NuGet/4.1.0/',
NUGET_EXE_TOOL_PATH_ENV_VAR: "NuGetExeToolPath"
} )
}

public registerNugetVersionMock(productVersion: string, versionInfoVersion: number[]) {
this.registerNugetVersionMockInternal(productVersion, versionInfoVersion);
this.registerMockWithMultiplePaths(['nuget-task-common/pe-parser', './pe-parser'], {
Expand All @@ -59,7 +64,7 @@ export class NugetMockHelper {
}
})
}

public registerNugetUtilityMock(projectFile: string[]) {
this.tmr.registerMock('nuget-task-common/Utility', {
getPatternsArrayFromInput: function(input) {
Expand Down Expand Up @@ -138,13 +143,13 @@ export class NugetMockHelper {
this.tmr.registerMock('vso-node-api/WebApi', {
getBearerHandler: function(token){
return {};
},
},
WebApi: function(url, handler){
return {
getCoreApi: function() {
return {
return {
vsoClient: {
getVersioningData: async function (ApiVersion, PackagingAreaName, PackageAreaId, Obj) {
getVersioningData: async function (ApiVersion, PackagingAreaName, PackageAreaId, Obj) {
return { requestUrl:"foobar" }
}
}
Expand All @@ -154,7 +159,7 @@ export class NugetMockHelper {
}
})
}

public setAnswers(a) {
a.osType["osType"] = "Windows_NT";
a.exist["c:\\agent\\home\\directory\\externals\\nuget\\nuget.exe"] = true;
Expand Down
4 changes: 4 additions & 0 deletions Tasks/NuGetCommand/make.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
{
"url": "https://vstsagenttools.blob.core.windows.net/tools/NuGet/4.0.0.2283/NuGet.zip",
"dest": "./NuGet/4.0.0/"
},
{
"url": "https://vstsagenttools.blob.core.windows.net/tools/NuGet/4.1.0/NuGet.zip",
"dest": "./NuGet/4.1.0/"
}
]
}
Expand Down
9 changes: 7 additions & 2 deletions Tasks/NuGetCommand/nugetcommandmain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ async function main(): Promise<void> {
try {
nuGetPath = process.env[nuGetGetter.NUGET_EXE_TOOL_PATH_ENV_VAR] || process.env[NUGET_EXE_CUSTOM_LOCATION];
if (!nuGetPath){
nuGetGetter.cacheBundledNuGet_4_0_0();
nuGetPath = await nuGetGetter.getNuGet("4.0.0");
let cachedVersionToUse = nuGetGetter.DEFAULT_NUGET_VERSION;
nuGetGetter.cacheBundledNuGet();
if (tl.getVariable(nuGetGetter.FORCE_NUGET_4_0_0) &&
tl.getVariable(nuGetGetter.FORCE_NUGET_4_0_0).toLowerCase() === "true") {
cachedVersionToUse = nuGetGetter.NUGET_VERSION_4_0_0;
}
nuGetPath = await nuGetGetter.getNuGet(cachedVersionToUse);
}
}
catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetCommand/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nugetcommand",
"version": "2.0.13",
"version": "2.0.15",
"description": "Restore, pack, or push NuGet packages, or run a NuGet command.",
"main": "nugetcommandmain.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetCommand/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 13
"Patch": 15
},
"runsOn": [
"Agent",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/NuGetCommand/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 13
"Patch": 15
},
"runsOn": [
"Agent",
Expand Down

0 comments on commit e0c8b42

Please sign in to comment.