Skip to content

Commit

Permalink
No project file, multiple project files (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenWeatherford authored Jul 20, 2018
1 parent 4275c8c commit 8e07af4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
},
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"editor.formatOnSave": true
"editor.formatOnSave": true,
"tslint.autoFixOnSave": true
}
29 changes: 21 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,33 @@
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "npm",
"type": "shell",
"command": "npm",
"group": {
"kind": "build",
"isDefault": true
},
"args": [
"run",
"compile",
"--loglevel",
"silent"
],
"isBackground": true,
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$tsc-watch"
},
{
"type": "npm",
"script": "lint",
"problemMatcher": {
"base": "$tslint5",
"fileLocation": "relative"
"fileLocation": "absolute"
}
},
{
"type": "gulp",
"task": "tslint",
"problemMatcher": [
"$tslint5"
]
}
]
}
14 changes: 6 additions & 8 deletions configureWorkspace/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as gradleParser from "gradle-to-js/lib/parser";
import * as path from "path";
import * as pomParser from "pom-parser";
import * as vscode from "vscode";
import { ext } from '../extensionVariables';
import { globAsync } from '../helpers/async';
import { reporter } from '../telemetry/telemetry';
import { OS, Platform, promptForPort, quickPickOS, quickPickPlatform } from './config-utils';
Expand Down Expand Up @@ -501,17 +502,14 @@ async function findCSProjFile(folderPath: string): Promise<string> {

const projectFiles: string[] = await globAsync('**/*.csproj', { cwd: folderPath });

if (!projectFiles) {
return;
if (!projectFiles || !projectFiles.length) {
throw new Error("No .csproj file could be found.");
}

if (projectFiles.length > 1) {
const res = await vscode.window.showQuickPick(projectFiles, opt);
if (res) {
return res.slice(0, -'.csproj'.length);
} else {
return;
}
let items = projectFiles.map(p => <vscode.QuickPickItem>{ label: p });
const res = await ext.ui.showQuickPick(items, opt);
return res.label.slice(0, -'.csproj'.length);
}

return projectFiles[0].slice(0, -'.csproj'.length);
Expand Down
File renamed without changes.
80 changes: 49 additions & 31 deletions test/configure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void
assert(!fileContains(fileName, text), `Unexpected found '${text}' in file ${fileName}`);
}

async function getProjectFiles(): Promise<string[]> {
async function getFilesInProject(): Promise<string[]> {
let files = await globAsync('**/*', {
cwd: testRootFolder,
dot: true, // include files beginning with dot
Expand All @@ -77,7 +77,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void
testInEmptyFolder("No package.json", async () => {
await testConfigureDocker('Node.js', '1234');

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(projectFiles, ['Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore'], "The set of files in the project folder after configure was run is not correct.");

assertFileContains('Dockerfile', 'EXPOSE 1234');
Expand Down Expand Up @@ -118,7 +118,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void

await testConfigureDocker('Node.js', '4321');

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(projectFiles, ['package.json', 'Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore'], "The set of files in the project folder after configure was run is not correct.");

assertFileContains('Dockerfile', 'EXPOSE 4321');
Expand Down Expand Up @@ -158,7 +158,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void

await testConfigureDocker('Node.js', '4321');

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(projectFiles, ['package.json', 'Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore'], "The set of files in the project folder after configure was run is not correct.");

assertFileContains('Dockerfile', 'EXPOSE 4321');
Expand All @@ -184,19 +184,33 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void
</Project>
`;

// https://github.com/Microsoft/vscode-docker/issues/295
// testInEmptyFolder("No project file", async () => {
// await assertEx.throwsOrRejectsAsync(async () => testConfigureDocker('.NET Core Console', 'Windows', '1234'),
// { message: "No .csproj file could be found." }
// );
// });
testInEmptyFolder("No project file", async () => {
await assertEx.throwsOrRejectsAsync(async () =>
testConfigureDocker('.NET Core Console', 'Windows', '1234'),
{ message: "No .csproj file could be found." }
);
});

testInEmptyFolder("Multiple project files", async () => {
await writeFile('projectFolder1', 'aspnetapp.csproj', projectFile);
await writeFile('projectFolder2', 'aspnetapp.csproj', projectFile);
await testConfigureDocker('.NET Core Console', 'Windows', '1234', 'projectFolder2/aspnetapp.csproj');

let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(
projectFiles,
['Dockerfile', '.dockerignore', 'projectFolder1/aspnetapp.csproj', 'projectFolder2/aspnetapp.csproj'], "The set of files in the project folder after configure was run is not correct.");

assertNotFileContains('Dockerfile', 'projectFolder1/aspnetapp');
assertFileContains('Dockerfile', 'projectFolder2/aspnetapp');
});

testInEmptyFolder("Windows", async () => {
await writeFile('projectFolder', 'aspnetapp.csproj', projectFile);

await testConfigureDocker('.NET Core Console', 'Windows', '1234');

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();

// No docker-compose files
assertEx.unorderedArraysEqual(projectFiles, ['Dockerfile', '.dockerignore', 'projectFolder/aspnetapp.csproj'], "The set of files in the project folder after configure was run is not correct.");
Expand All @@ -214,7 +228,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void

await testConfigureDocker('.NET Core Console', 'Linux', '1234');

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();

// No docker-compose files
assertEx.unorderedArraysEqual(projectFiles, ['Dockerfile', '.dockerignore', 'projectFolder2/aspnetapp2.csproj'], "The set of files in the project folder after configure was run is not correct.");
Expand Down Expand Up @@ -244,20 +258,19 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void
</Project>
`;

// https://github.com/Microsoft/vscode-docker/issues/295
// testInEmptyFolder("ASP.NET Core no project file", async () => {
// await assertEx.throwsOrRejectsAsync(async () => testConfigureDocker('ASP.NET Core', 'Windows', '1234'),
// { message: "No .csproj file could be found." }
// );
// });
testInEmptyFolder("ASP.NET Core no project file", async () => {
await assertEx.throwsOrRejectsAsync(async () => testConfigureDocker('ASP.NET Core', 'Windows', '1234'),
{ message: "No .csproj file could be found." }
);
});

testInEmptyFolder("Windows", async () => {
// https://github.com/dotnet/dotnet-docker/tree/master/samples/aspnetapp
await writeFile('projectFolder', 'aspnetapp.csproj', projectFile);

await testConfigureDocker('ASP.NET Core', 'Windows', undefined /*use default port*/);

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();

// No docker-compose files
assertEx.unorderedArraysEqual(projectFiles, ['Dockerfile', '.dockerignore', 'projectFolder/aspnetapp.csproj'], "The set of files in the project folder after configure was run is not correct.");
Expand All @@ -274,7 +287,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void

await testConfigureDocker('ASP.NET Core', 'Linux', '1234');

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();

// No docker-compose files
assertEx.unorderedArraysEqual(projectFiles, ['Dockerfile', '.dockerignore', 'projectFolder2/aspnetapp2.csproj'], "The set of files in the project folder after configure was run is not correct.");
Expand All @@ -290,12 +303,17 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void
// Java

suite("Java", () => {
// https://github.com/Microsoft/vscode-docker/issues/295
// testInEmptyFolder("No pom file", async () => {
// await assertEx.throwsOrRejectsAsync(async () => testConfigureDocker('Java', '1234'),
// { message: "No .csproj file could be found." }
// );
// });
testInEmptyFolder("No pom file", async () => {
await testConfigureDocker('Java', '1234');

let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(projectFiles, ['Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore'], "The set of files in the project folder after configure was run is not correct.");

assertFileContains('Dockerfile', 'EXPOSE 1234');
assertFileContains('Dockerfile', 'ARG JAVA_OPTS');
assertFileContains('Dockerfile', 'ADD testoutput.jar testoutput.jar');
assertFileContains('Dockerfile', 'ENTRYPOINT exec java $JAVA_OPTS -jar testoutput.jar');
});

testInEmptyFolder("Empty pom file", async () => {
await writeFile('', 'pom.xml', `
Expand All @@ -304,7 +322,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void

await testConfigureDocker('Java', undefined /*port*/);

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(projectFiles, ['pom.xml', 'Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore'], "The set of files in the project folder after configure was run is not correct.");

assertFileContains('Dockerfile', 'EXPOSE 3000');
Expand Down Expand Up @@ -333,7 +351,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void

await testConfigureDocker('Java', undefined /*port*/);

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(projectFiles, ['pom.xml', 'Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore'], "The set of files in the project folder after configure was run is not correct.");

assertFileContains('Dockerfile', 'EXPOSE 3000');
Expand All @@ -348,7 +366,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void

await testConfigureDocker('Java', undefined /*port*/);

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(projectFiles, ['build.gradle', 'Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore'], "The set of files in the project folder after configure was run is not correct.");

assertFileContains('Dockerfile', 'EXPOSE 3000');
Expand Down Expand Up @@ -430,7 +448,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void

await testConfigureDocker('Java', undefined /*port*/);

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(projectFiles, ['build.gradle', 'Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore'], "The set of files in the project folder after configure was run is not correct.");

assertFileContains('Dockerfile', 'EXPOSE 3000');
Expand All @@ -447,7 +465,7 @@ suite("configure (Add Docker files to Workspace)", function (this: Suite): void
testInEmptyFolder("Python", async () => {
await testConfigureDocker('Python', undefined /*port*/);

let projectFiles = await getProjectFiles();
let projectFiles = await getFilesInProject();
assertEx.unorderedArraysEqual(projectFiles, ['Dockerfile', 'docker-compose.debug.yml', 'docker-compose.yml', '.dockerignore'], "The set of files in the project folder after configure was run is not correct.");

assertFileContains('Dockerfile', 'FROM python:alpine');
Expand Down

0 comments on commit 8e07af4

Please sign in to comment.