Skip to content

Commit cd4dfae

Browse files
authored
Merge pull request #2149 from jmyersmsft/nugetFindUncFix
Pick up missed PR feedback commit from Master version of previous PR
2 parents 83adf80 + 8054f2b commit cd4dfae

File tree

5 files changed

+48
-42
lines changed

5 files changed

+48
-42
lines changed

Tasks/Common/nuget-task-common/NuGetToolRunner.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,24 @@ export function createNuGetToolRunner(nuGetExePath: string, settings: NuGetEnvir
9191
return runner;
9292
}
9393

94-
export interface LocateOptions {
95-
optional?: boolean;
96-
userPath?: string;
94+
interface LocateOptions {
95+
/** if true, search along the system path in addition to the hard-coded NuGet tool paths */
9796
fallbackToSystemPath?: boolean;
97+
98+
/** Array of filenames to use when searching for the tool. Defaults to the tool name. */
99+
toolFilenames?: string[];
98100
}
99101

100-
export function locateTool(tool: string | string[], opts?: LocateOptions) {
101-
let toolVariants: string[] = typeof tool === 'string' ? [tool] : tool;
102+
function locateTool(tool: string, opts?: LocateOptions) {
102103
let searchPath = ["externals/nuget", "agent/Worker/Tools/NuGetCredentialProvider", "agent/Worker/Tools"];
103104
let agentRoot = tl.getVariable("Agent.HomeDirectory");
104105

105106
opts = opts || {};
107+
opts.toolFilenames = opts.toolFilenames || [tool];
106108

107109
tl.debug(`looking for tool ${tool}`)
108110

109-
if (opts.userPath) {
110-
tl.debug(`using user-supplied path ${opts.userPath}`)
111-
tl.checkPath(opts.userPath, toolVariants[0]);
112-
return opts.userPath;
113-
}
114-
115-
for (let thisVariant of toolVariants)
111+
for (let thisVariant of opts.toolFilenames)
116112
{
117113
tl.debug(`looking for tool variant ${thisVariant}`);
118114

@@ -136,9 +132,29 @@ export function locateTool(tool: string | string[], opts?: LocateOptions) {
136132
tl.debug("not found");
137133
}
138134

139-
if (!opts.optional) {
140-
throw new Error(tl.loc("NGCommon_UnableToFindTool", toolVariants[0]));
135+
return null;
136+
}
137+
138+
export function locateNuGetExe(userNuGetExePath: string): string {
139+
if (userNuGetExePath) {
140+
tl.debug(`using user-supplied NuGet path ${userNuGetExePath}`)
141+
tl.checkPath(userNuGetExePath, 'NuGet');
142+
return userNuGetExePath;
143+
}
144+
145+
var toolPath = locateTool('NuGet', {
146+
fallbackToSystemPath: os.platform() !== 'win32',
147+
toolFilenames: ['nuget.exe', 'NuGet.exe', 'nuget', 'NuGet']
148+
});
149+
150+
151+
if (!toolPath) {
152+
throw new Error(tl.loc("NGCommon_UnableToFindTool", 'NuGet'));
141153
}
142154

143-
return null;
155+
return toolPath;
156+
}
157+
158+
export function locateCredentialProvider(): string {
159+
return locateTool('CredentialProvider.TeamBuild.exe');
144160
}

Tasks/Common/nuget-task-common/Utility.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ export function resolveFilterSpec(filterSpec: string, basePath?: string, allowEm
4444

4545
export function resolveWildcardPath(pattern: string, allowEmptyWildcardMatch?: boolean): string[] {
4646
let isWindows = os.platform() === 'win32';
47-
let toPosixPath = (path: string) => path;
48-
let toNativePath = (path: string) => path;
49-
if (isWindows) {
50-
// minimatch assumes paths use /, so on Windows, make paths use /
51-
// This needs to be done both to the pattern and to the filenames.
52-
toPosixPath = (path: string) => path.replace(/\\/g, "/");
53-
54-
// tl.find always returns forward slashes. This is problematic with UNC paths because NuGet
55-
// interprets that as a switch argument instead of a path.
56-
toNativePath = (path: string) => path.replace(/\//g, "\\");
57-
}
5847

5948
// Resolve files for the specified value or pattern
6049
var filesList: string[];
@@ -93,9 +82,9 @@ export function resolveWildcardPath(pattern: string, allowEmptyWildcardMatch?: b
9382
var allFiles = tl.find(findPathRoot);
9483

9584
// Now matching the pattern against all files
96-
// Turn off a bunch of minimatch features to replicate the be
85+
// Turn off a bunch of minimatch features to replicate the behavior of Find-Files in the old PowerShell tasks
9786
let patternFilter = tl.filter(
98-
toPosixPath(pattern), {
87+
pattern, {
9988
matchBase: true,
10089
nobrace: true,
10190
noext: true,
@@ -105,13 +94,20 @@ export function resolveWildcardPath(pattern: string, allowEmptyWildcardMatch?: b
10594
dot: isWindows
10695
});
10796

108-
filesList = allFiles.filter((file, index, array) => patternFilter(toPosixPath(file), index, array));
97+
filesList = allFiles.filter(patternFilter);
10998

11099
// Fail if no matching .sln files were found
111100
if (!allowEmptyWildcardMatch && (!filesList || filesList.length == 0)) {
112101
throw new Error('No matching files were found with search pattern: ' + pattern);
113102
}
114103
}
115104

116-
return filesList.map(toNativePath);
105+
if (!isWindows)
106+
{
107+
return filesList;
108+
}
109+
else
110+
{
111+
return filesList.map(file => file.split("/").join("\\"));
112+
}
117113
}

Tasks/NuGetInstaller/nugetinstaller.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ if (!tl.filePathSupplied('nuGetPath')) {
6666
var serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
6767

6868
//find nuget location to use
69-
var nuGetExeVariants = ['nuget.exe', 'NuGet.exe', 'nuget', 'NuGet']
70-
var nuGetPathToUse = ngToolRunner.locateTool(nuGetExeVariants, {userPath: userNuGetPath, fallbackToSystemPath: os.platform() !== 'win32'});
71-
var credProviderPath = ngToolRunner.locateTool('CredentialProvider.TeamBuild.exe', {optional: true});
69+
var nuGetPathToUse = ngToolRunner.locateNuGetExe(userNuGetPath);
70+
var credProviderPath = ngToolRunner.locateCredentialProvider();
7271

7372
var credProviderDir: string = null;
7473
if (credProviderPath) {

Tasks/NugetPublisher/nugetpublisher.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ if (!tl.filePathSupplied('nuGetPath')) {
6363
var serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
6464

6565
//find nuget location to use
66-
var nuGetExeVariants = ['nuget.exe', 'NuGet.exe', 'nuget', 'NuGet']
67-
var nuGetPathToUse = ngToolRunner.locateTool(nuGetExeVariants, {userPath: userNuGetPath, fallbackToSystemPath: os.platform() !== 'win32'});
68-
var credProviderPath = ngToolRunner.locateTool('CredentialProvider.TeamBuild.exe', {optional: true});
66+
var nuGetPathToUse = ngToolRunner.locateNuGetExe(userNuGetPath);
67+
var credProviderPath = ngToolRunner.locateCredentialProvider();
6968

7069
var credProviderDir: string = null;
7170
if (credProviderPath) {

definitions/nuget-task-common.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,8 @@ declare module 'nuget-task-common/NuGetToolRunner' {
101101
exec(options?: IExecOptions): Q.Promise<number>;
102102
}
103103
export function createNuGetToolRunner(nuGetExePath: string, settings: NuGetEnvironmentSettings): NuGetToolRunner;
104-
export interface LocateOptions {
105-
optional?: boolean;
106-
userPath?: string;
107-
fallbackToSystemPath?: boolean;
108-
}
109-
export function locateTool(tool: string | string[], opts?: LocateOptions): string;
104+
export function locateNuGetExe(userNuGetExePath: string): string;
105+
export function locateCredentialProvider(): string;
110106

111107
}
112108
declare module 'nuget-task-common/NuGetConfigHelper' {

0 commit comments

Comments
 (0)