Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Initial tf.exe framework (#120)
Browse files Browse the repository at this point in the history
* Initial tf.exe framework

* PR feedback

* Explicitly exclude files from code coverage
  • Loading branch information
Jeff Young authored Feb 22, 2017
1 parent 7bf5ce0 commit 66bd251
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 12 deletions.
35 changes: 32 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,38 @@ gulp.task('test-integration', function() {

gulp.task('test-coverage', function() {
//credentialstore is brought in from separate repository, exclude it here
return gulp.src(['out/src/**/*.js', '!out/src/credentialstore/**'])
//.pipe(istanbul({includeUntested: true}))
.pipe(istanbul())
//exclude the files we know we can't get coverage on (e.g., vscode, etc.)
return gulp.src(['out/src/**/*.js', '!out/src/credentialstore/**'
,'!out/src/extension.js'
,'!out/src/extensionmanager.js'
,'!out/src/team-extension.js'
,'!out/src/clients/buildclient.js'
,'!out/src/clients/coreapiclient.js'
,'!out/src/clients/feedbackclient.js'
,'!out/src/clients/gitclient.js'
,'!out/src/clients/repositoryinfoclient.js'
,'!out/src/clients/witclient.js'
,'!out/src/contexts/tfvccontext.js'
,'!out/src/helpers/settings.js'
,'!out/src/helpers/vscodeutils.js'
,'!out/src/services/telemetry.js'
,'!out/src/services/coreapi.js'
,'!out/src/tfvc/repository.js'
,'!out/src/tfvc/tfvc-extension.js'
,'!out/src/tfvc/tfvc.js'
,'!out/src/tfvc/tfvcoutput.js'
,'!out/src/tfvc/tfvcscmprovider.js'
,'!out/src/tfvc/tfvcsettings.js'
,'!out/src/tfvc/uihelper.js'
,'!out/src/tfvc/util.js'
,'!out/src/tfvc/scm/commithoverprovider.js'
,'!out/src/tfvc/scm/decorationprovider.js'
,'!out/src/tfvc/scm/model.js'
,'!out/src/tfvc/scm/resource.js'
,'!out/src/tfvc/scm/tfvccontentprovider.js'
])
.pipe(istanbul({includeUntested: true}))
//.pipe(istanbul())
.pipe(istanbul.hookRequire()) //for using node.js
.on('finish', function() {
gulp.src('out/test*/**/*.js')
Expand Down
12 changes: 12 additions & 0 deletions src/tfvc/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ export class Add implements ITfvcCommand<string[]> {
return filesAdded;
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<string[]> {
return this.ParseOutput(executionResult);
}

private getFileFromLine(line: string): string {
//There's no prefix on the filename line for the Add command
return line;
Expand Down
12 changes: 12 additions & 0 deletions src/tfvc/commands/checkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,16 @@ export class Checkin implements ITfvcCommand<string> {
return CommandHelper.GetChangesetNumber(executionResult.stdout);
}
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public ParseExeOutput(executionResult: IExecutionResult): Promise<string> {
return this.ParseOutput(executionResult);
}
}
12 changes: 12 additions & 0 deletions src/tfvc/commands/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export class Delete implements ITfvcCommand<string[]> {
return filesUndone;
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public ParseExeOutput(executionResult: IExecutionResult): Promise<string[]> {
return this.ParseOutput(executionResult);
}

private getFileFromLine(line: string): string {
//There's no prefix on the filename line for the Delete command
return line;
Expand Down
13 changes: 13 additions & 0 deletions src/tfvc/commands/findconflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ export class FindConflicts implements ITfvcCommand<IConflict[]> {

return conflicts;
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<IConflict[]> {
return this.ParseOutput(executionResult);
}

}
18 changes: 17 additions & 1 deletion src/tfvc/commands/findworkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export class FindWorkspace implements ITfvcCommand<IWorkspace> {
continue;
}

if (line.startsWith("Workspace:")) {
//CLC returns 'Workspace:', tf.exe returns 'Workspace :'
if (line.startsWith("Workspace:") || line.startsWith("Workspace :")) {
workspaceName = this.getValue(line);
} else if (line.startsWith("Collection:")) {
collectionUrl = this.getValue(line);
Expand All @@ -86,6 +87,9 @@ export class FindWorkspace implements ITfvcCommand<IWorkspace> {
}
}
}
if (mappings.length === 0) {
throw new Error("Could not find a workspace with mappings. Perhaps the wrong version of TF is being used with the selected folder?");
}

const workspace: IWorkspace = {
name: workspaceName,
Expand All @@ -97,6 +101,18 @@ export class FindWorkspace implements ITfvcCommand<IWorkspace> {
return workspace;
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<IWorkspace> {
return this.ParseOutput(executionResult);
}

/**
* This method parses a line of the form "name: value" and returns the value part.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/tfvc/commands/getfilecontent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,16 @@ export class GetFileContent implements ITfvcCommand<string> {
const lines: string[] = CommandHelper.SplitIntoLines(executionResult.stdout);
return lines.join(CommandHelper.GetNewLineCharacter(executionResult.stdout));
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<string> {
return this.ParseOutput(executionResult);
}
}
12 changes: 12 additions & 0 deletions src/tfvc/commands/getinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ export class GetInfo implements ITfvcCommand<IItemInfo[]> {
return itemInfos;
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<IItemInfo[]> {
return this.ParseOutput(executionResult);
}

private getPropertyName(name: string): string {
switch (name) {
case "server path": return "serverItem";
Expand Down
23 changes: 23 additions & 0 deletions src/tfvc/commands/getversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,27 @@ export class GetVersion implements ITfvcCommand<string> {
return "";
}
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

//TODO: Refactor this with ParseOutput (pass in just the line and the regex?)
public async ParseExeOutput(executionResult: IExecutionResult): Promise<string> {
// Throw if any errors are found in stderr or if exitcode is not 0
CommandHelper.ProcessErrors(this.GetArguments().GetCommand(), executionResult);

const lines: string[] = CommandHelper.SplitIntoLines(executionResult.stdout);
// Find just the version number and return it. Ex. Microsoft (R) TF - Team Foundation Version Control Tool, Version 14.102.25619.0
if (lines && lines.length > 0) {
let value: string = lines[0].replace(/(.*version )([\.\d]*)(.*)/i, "$2");
return value;
} else {
return "";
}
}
}
12 changes: 12 additions & 0 deletions src/tfvc/commands/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ export class Rename implements ITfvcCommand<string> {
return "";
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<string> {
return this.ParseOutput(executionResult);
}

private getFileFromLine(line: string): string {
//There's no prefix on the filename line for the Add command
return line;
Expand Down
12 changes: 12 additions & 0 deletions src/tfvc/commands/resolveconflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ export class ResolveConflicts implements ITfvcCommand<IConflict[]> {

return conflicts;
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<IConflict[]> {
return this.ParseOutput(executionResult);
}
}
24 changes: 24 additions & 0 deletions src/tfvc/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ export class Status implements ITfvcCommand<IPendingChange[]> {
return changes;
}

public GetExeArguments(): IArgumentProvider {
//return this.GetArguments();
const builder: ArgumentBuilder = new ArgumentBuilder("status", this._serverContext)
.AddSwitchWithValue("format", "detailed", false)
.AddSwitch("recursive");

if (this._localPaths && this._localPaths.length > 0) {
for (let i = 0; i < this._localPaths.length; i++) {
builder.Add(this._localPaths[i]);
}
}

return builder;
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<IPendingChange[]> {
//TODO: Parse this with format:detailed
return this.ParseOutput(executionResult);
}

private add(changes: IPendingChange[], newChange: IPendingChange, ignoreFolders: boolean) {
// Deleted files won't exist, but we still include them in the results
if (ignoreFolders && fs.existsSync(newChange.localItem)) {
Expand Down
12 changes: 12 additions & 0 deletions src/tfvc/commands/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ export class Sync implements ITfvcCommand<ISyncResults> {
}
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<ISyncResults> {
return this.ParseOutput(executionResult);
}

private getItemResults(stdout: string): ISyncItemResult[] {
let itemResults: ISyncItemResult[] = [];
let folderPath: string = "";
Expand Down
12 changes: 12 additions & 0 deletions src/tfvc/commands/undo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ export class Undo implements ITfvcCommand<string[]> {
return filesUndone;
}

public GetExeArguments(): IArgumentProvider {
return this.GetArguments();
}

public GetExeOptions(): any {
return this.GetOptions();
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<string[]> {
return this.ParseOutput(executionResult);
}

//line could be 'Undoing edit: file1.txt', 'Undoing add: file1.txt'
private getFileFromLine(line: string): string {
const prefix: string = ": "; //"Undoing edit: ", "Undoing add: ", etc.
Expand Down
3 changes: 3 additions & 0 deletions src/tfvc/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export interface IArgumentProvider {

export interface ITfvcCommand<T> {
GetArguments(): IArgumentProvider;
GetExeArguments(): IArgumentProvider;
GetOptions(): any;
GetExeOptions(): any;
ParseOutput(executionResult: IExecutionResult): Promise<T>;
ParseExeOutput(executionResult: IExecutionResult): Promise<T>;
}
17 changes: 13 additions & 4 deletions src/tfvc/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,19 @@ export class Repository {
}

public async RunCommand<T>(cmd: ITfvcCommand<T>): Promise<T> {
const result: IExecutionResult = await this.exec(cmd.GetArguments(), cmd.GetOptions());
// We will call ParseOutput to give the command a chance to handle any specific errors itself.
const output: T = await cmd.ParseOutput(result);
return output;
if (this._tfvc.isExe) {
//This is the tf.exe path
const result: IExecutionResult = await this.exec(cmd.GetExeArguments(), cmd.GetExeOptions());
// We will call ParseExeOutput to give the command a chance to handle any specific errors itself.
const output: T = await cmd.ParseExeOutput(result);
return output;
} else {
//This is the CLC path
const result: IExecutionResult = await this.exec(cmd.GetArguments(), cmd.GetOptions());
// We will call ParseOutput to give the command a chance to handle any specific errors itself.
const output: T = await cmd.ParseOutput(result);
return output;
}
}

private async exec(args: IArgumentProvider, options: any = {}): Promise<IExecutionResult> {
Expand Down
Loading

0 comments on commit 66bd251

Please sign in to comment.