Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users/sachinma/dotnetcorebugfix #3282

Merged
merged 4 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions Tasks/DotNetCoreCLI/Tests/mock-findfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export function findFiles (projects: string, includeFolder: boolean) : string[]
return ["web/project.json", "web2/project.json", "web.tests/project.json", "lib/project.json"];
}

if (projects == "**/project.json;**/*.csproj") {
return ["web/project.json", "web2/project.json", "web.tests/project.json", "lib/project.json"];
}

if (projects == "*fail*/project.json") {
return [];
}
Expand Down
87 changes: 45 additions & 42 deletions Tasks/DotNetCoreCLI/dotnetcore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import tl = require("vsts-task-lib/task");
import path = require("path");
import fs = require("fs");
import ffl = require('find-files-legacy/findfiles.legacy');
var gulp = require('gulp');
var zip = require('gulp-zip');
var archiver = require('archiver');

export class dotNetExe {
private command: string;
private projects: string;
private arguments: string;
private publishWebProjects: boolean;
private zipAfterPublish: boolean;
private outputArgument: string;
private remainingArgument: string;
private outputArgument: string = "";
private remainingArgument: string[] = [];

constructor() {
this.command = tl.getInput("command");
Expand All @@ -23,7 +22,7 @@ export class dotNetExe {
}

public async execute() {
tl.setResourcePath(path.join( __dirname, "task.json"));
tl.setResourcePath(path.join(__dirname, "task.json"));
var dotnetPath = tl.which("dotnet", true);

this.extractOutputArgument();
Expand All @@ -32,15 +31,23 @@ export class dotNetExe {
var projectFiles = [""];
if (this.projects || (this.isPublishCommand() && this.publishWebProjects)) {
projectFiles = this.getProjectFiles();
}
}

for (var fileIndex in projectFiles) {
var projectFile = projectFiles[fileIndex];
try {
var dotnet = tl.tool(dotnetPath);
dotnet.arg(this.command);
dotnet.arg(projectFile);
dotnet.line(this.getCommandArguments(projectFile));
if (this.remainingArgument.length > 0) {
dotnet.arg(this.remainingArgument);
}

if (this.isPublishCommand() && this.outputArgument) {
var output = dotNetExe.getModifiedOutputForProjectFile(this.outputArgument, projectFile);
dotnet.arg("--output");
dotnet.arg(output);
}

var result = dotnet.execSync();
if (result.code != 0) {
Expand All @@ -51,8 +58,7 @@ export class dotNetExe {

await this.zipAfterPublishIfRequired(projectFile);
}
catch (err)
{
catch (err) {
tl.setResult(1, err.message);
}
}
Expand Down Expand Up @@ -88,41 +94,40 @@ export class dotNetExe {
}
}

private zip (source: string, target: string) {
private zip(source: string, target: string) {
tl.debug("Zip arguments: Source: " + source + " , target: " + target);

return new Promise((resolve, reject) => {
gulp.src(path.join(source, '**', '*'))
.pipe(zip(path.basename(target)))
.pipe(gulp.dest(path.dirname(target))).on('end', function(error){
error ? reject(tl.loc("zipFailed", error)) : resolve("");
})});
}
var output = fs.createWriteStream(target);

private getCommandArguments(projectFile: string): string {
if (this.isPublishCommand() && this.outputArgument) {
var output = dotNetExe.getModifiedOutputForProjectFile(this.outputArgument, projectFile);
var commandArgument = this.remainingArgument + ' --output "' + output + '"';
tl.debug("CommandArguments: " + commandArgument);
return commandArgument;
}
output.on('close', function () {
tl.debug('Successfully created archive ' + target);
resolve(target);
});

output.on('error', function(error) {
reject(error);
});

return this.arguments;
var archive = archiver('zip');
archive.pipe(output);
archive.directory(source, '/');
archive.finalize();
});
}

private extractOutputArgument(): void {
if (!this.isPublishCommand() || !this.arguments) {
if (!this.arguments || !this.arguments.trim()) {
return;
}

this.outputArgument = this.remainingArgument = "";

var argString = this.arguments.trim();
var isOutputOption = false;
var inQuotes = false;
var escaped = false;
var arg = '';
var i = 0;
var append = function (c) {
var append = function(c) {
// we only escape double quotes.
if (escaped && c !== '"') {
arg += '\\';
Expand All @@ -134,7 +139,7 @@ export class dotNetExe {
arg = '';
for (; i < argString.length; i++) {
var c = argString.charAt(i);
if (isOutputOption && c === '"') {
if (c === '"') {
if (!escaped) {
inQuotes = !inQuotes;
}
Expand All @@ -143,7 +148,7 @@ export class dotNetExe {
}
continue;
}
if (c === "\\" && inQuotes) {
if (c === "\\" && inQuotes && !escaped) {
escaped = true;
continue;
}
Expand All @@ -165,29 +170,27 @@ export class dotNetExe {

var token = nextArg();
while (token) {
if (isOutputOption) {
var tokenUpper = token.toUpperCase();
if (this.isPublishCommand() && (tokenUpper === "--OUTPUT" || tokenUpper === "-O")) {
isOutputOption = true;
}
else if (isOutputOption) {
this.outputArgument = token;
isOutputOption = false;
}
else {
var tokenUpper = token.toUpperCase();
if (tokenUpper === "--OUTPUT" || tokenUpper === "-O") {
isOutputOption = true;
}
else {
this.remainingArgument += (" " + token);
}
this.remainingArgument.push(token);
}

token = nextArg();
}
}

private getProjectFiles(): string [] {
private getProjectFiles(): string[] {
var projectPattern = this.projects;
var searchWebProjects = this.isPublishCommand() && this.publishWebProjects;
if (searchWebProjects) {
projectPattern = "**/project.json";
projectPattern = "**/project.json;**/*.csproj";
}

var projectFiles = ffl.findFiles(projectPattern, false);
Expand All @@ -199,7 +202,7 @@ export class dotNetExe {
if (searchWebProjects) {
projectFiles = projectFiles.filter(function(file, index, files): boolean {
var directory = path.dirname(file);
return tl.exist(path.join(directory, "web.config"))
return tl.exist(path.join(directory, "web.config"))
|| tl.exist(path.join(directory, "wwwroot"));
});

Expand All @@ -215,7 +218,7 @@ export class dotNetExe {
return this.command === "publish";
}

private static getModifiedOutputForProjectFile(outputBase: string, projectFile: string) : string {
private static getModifiedOutputForProjectFile(outputBase: string, projectFile: string): string {
return path.join(outputBase, path.basename(path.dirname(projectFile)));
}
}
Expand Down
3 changes: 1 addition & 2 deletions Tasks/DotNetCoreCLI/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"vsts-task-lib": "^0.9.20",
"q": "^1.4.1",
"vso-node-api": "^5.0.5",
"gulp": "^3.9.1",
"gulp-zip": "^3.2.0"
"archiver": "1.2.0"
}
}
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreCLI/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"demands": [],
"version": {
"Major": 0,
"Minor": 2,
"Minor": 3,
"Patch": 0
},
"minimumAgentVersion": "1.95.0",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreCLI/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"demands": [],
"version": {
"Major": 0,
"Minor": 2,
"Minor": 3,
"Patch": 0
},
"minimumAgentVersion": "1.95.0",
Expand Down