Skip to content

Commit 14e2c6c

Browse files
committed
more URL support and using newer cloc by default:
be able to use file protocol as a download url, or a file path using cloc 1.82 by default
1 parent c621bfd commit 14e2c6c

16 files changed

+870
-34
lines changed

DETAILS.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,24 @@ By default the cloc CLI is running in the root of the repository, you can modify
4545

4646
![Working folder is the path, where the cloc CLI will run](https://raw.githubusercontent.com/Dealogic/cloc-vsts-extension/master/screenshots/WorkingFolder.png)
4747

48-
By default the cloc CLI is downloaded from the url: `https://github.com/AlDanial/cloc/releases/download/1.80/cloc-1.80.exe`:
48+
By default the cloc CLI is downloaded from the url: `https://github.com/AlDanial/cloc/releases/download/1.82/cloc-1.82.exe`:
4949

5050
![The download URL of the cloc-cli tool](https://raw.githubusercontent.com/Dealogic/cloc-vsts-extension/master/screenshots/ClocCliDownloadURL.png)
5151

52+
But now file shares and local files are supported to such as:
53+
```
54+
file://my-file-share/public/software/cloc-1.82.exe
55+
```
56+
or
57+
```
58+
./cloc.1.82.exe
59+
```
60+
5261
## <a id="release-notes"></a>Release Notes
5362

54-
* 1.2.0 (18/06/2019)
63+
* 1.2.1 (19/06/2019)
5564
* New build/deployment badge on README page. (as build and deployment are on travis-ci.org)
65+
* File URLs are supported such as `file://my-file-share/public/software/cloc-1.82.exe` or local file path as `./cloc.1.82.exe`
5666
* 1.1.2 (13/12/2018)
5767
* Display name of the task will be used as title for the summary on build summary page
5868
* Option to modify the cloc-cli download URL

README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,24 @@ By default the cloc CLI is running in the root of the repository, you can modify
4545

4646
![Working folder is the path, where the cloc CLI will run](https://raw.githubusercontent.com/Dealogic/cloc-vsts-extension/master/screenshots/WorkingFolder.png)
4747

48-
By default the cloc CLI is downloaded from the url: `https://github.com/AlDanial/cloc/releases/download/1.80/cloc-1.80.exe`:
48+
By default the cloc CLI is downloaded from the url: `https://github.com/AlDanial/cloc/releases/download/1.82/cloc-1.82.exe`:
4949

5050
![The download URL of the cloc-cli tool](https://raw.githubusercontent.com/Dealogic/cloc-vsts-extension/master/screenshots/ClocCliDownloadURL.png)
5151

52+
But now file shares and local files are supported to such as:
53+
```
54+
file://my-file-share/public/software/cloc-1.82.exe
55+
```
56+
or
57+
```
58+
./cloc.1.82.exe
59+
```
60+
5261
## <a id="release-notes"></a>Release Notes
5362

54-
* 1.2.0 (18/06/2019)
63+
* 1.2.1 (19/06/2019)
5564
* New build/deployment badge on README page. (as build and deployment are on travis-ci.org)
65+
* File URLs are supported such as `file://my-file-share/public/software/cloc-1.82.exe` or local file path as `./cloc.1.82.exe`
5666
* 1.1.2 (13/12/2018)
5767
* Display name of the task will be used as title for the summary on build summary page
5868
* Option to modify the cloc-cli download URL

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloc-vsts-extension",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "cloc Visual Studio Team System (VTST) extension",
55
"main": "index.js",
66
"scripts": {
+28-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
1-
import * as https from "https";
2-
import * as http from "http";
31
import * as fs from "fs";
2+
import * as download from "download";
3+
import * as url from "url";
44

5-
const downloadClocCli = (clocExeDownloadUrl: string, downloadFinishedCallback: () => void) => {
6-
const clocExeFilename = "cloc.exe";
7-
const clocExeFile = fs.createWriteStream(clocExeFilename);
5+
const downloadClocCli = (clocExeDownloadUrl: string, downloadFinishedCallback: (error?: Error) => void) => {
6+
try {
7+
const clocExeFilename = "cloc.exe";
8+
const downloadUrl = url.parse(clocExeDownloadUrl);
89

9-
console.log(`Downloading cloc.exe from '${clocExeDownloadUrl}'`);
10-
https.get(clocExeDownloadUrl, (clocExeDownloadResponse: http.IncomingMessage) => {
11-
https.get(clocExeDownloadResponse.headers["location"].toString(), (redirectionResponse: http.IncomingMessage) => {
12-
const stream = redirectionResponse.pipe(clocExeFile);
13-
stream.on("close", () => {
14-
console.log(`Download is completed.`);
15-
downloadFinishedCallback();
16-
});
17-
});
18-
});
10+
console.log(`Downloading cloc.exe from:`);
11+
console.log(downloadUrl);
12+
13+
switch (downloadUrl.protocol) {
14+
case "file:":
15+
const downloadPath = url.fileURLToPath ? url.fileURLToPath(downloadUrl.href) : downloadUrl.href.slice(5);
16+
17+
console.log(`Copying file from '${downloadPath}'`);
18+
fs.copyFile(downloadPath, clocExeFilename, (err) => downloadFinishedCallback(err));
19+
break;
20+
case "http:":
21+
case "https:":
22+
download(downloadUrl.href).then((data) => fs.writeFile(clocExeFilename, data, (err) => downloadFinishedCallback(err)));
23+
break;
24+
default:
25+
console.log(`Copying file from '${downloadUrl.href}'`);
26+
fs.copyFile(downloadUrl.href, clocExeFilename, (err) => downloadFinishedCallback(err));
27+
break;
28+
}
29+
} catch (err) {
30+
downloadFinishedCallback(err);
31+
}
1932
};
2033

2134
export default downloadClocCli;

tasks/cloc-build-task/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ async function run(): Promise<void> {
3131
try {
3232
downloadClocCli(
3333
clocCliDownloadUrl,
34-
() => {
34+
(error) => {
35+
if (error) {
36+
throw error;
37+
}
38+
3539
executeClocCli(taskDisplayName, clocCliArguments);
3640
});
3741
} catch (err) {

tasks/cloc-build-task/package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloc-build-task",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "cloc Visual Studio Team System (VTST) extension",
55
"main": "index.js",
66
"scripts": {},
@@ -12,7 +12,10 @@
1212
"author": "Dealogic",
1313
"license": "MIT",
1414
"dependencies": {
15-
"azure-pipelines-task-lib": "2.7.7"
15+
"azure-pipelines-task-lib": "2.7.7",
16+
"download": "7.1.0"
1617
},
17-
"devDependencies": {}
18+
"devDependencies": {
19+
"@types/download": "6.2.4"
20+
}
1821
}

tasks/cloc-build-task/task.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"version": {
1818
"Major": 1,
1919
"Minor": 2,
20-
"Patch": 0
20+
"Patch": 1
2121
},
2222
"minimumAgentVersion": "1.95.0",
2323
"groups": [
@@ -42,7 +42,7 @@
4242
"name": "clocCliDownloadUrl",
4343
"type": "string",
4444
"label": "Download url of cloc-cli",
45-
"defaultValue": "https://github.com/AlDanial/cloc/releases/download/1.80/cloc-1.80.exe",
45+
"defaultValue": "https://github.com/AlDanial/cloc/releases/download/1.82/cloc-1.82.exe",
4646
"required": true,
4747
"helpMarkDown": "Download URL of cloc-cli. Default value: https://github.com/AlDanial/cloc/releases/download/1.80/cloc-1.80.exe",
4848
"groupName": "advanced"

tasks/cloc-build-task/tests/mockRunnerDefinitions/shared/testTaskRunner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const runTestTask = (testRunConfiguration: ITestRunConfiguration) => {
1616
}
1717

1818
if (!testRunConfiguration.clocCliDownloadUrl) {
19-
testRunConfiguration.clocCliDownloadUrl = "https://github.com/AlDanial/cloc/releases/download/1.80/cloc-1.80.exe";
19+
testRunConfiguration.clocCliDownloadUrl = "https://github.com/AlDanial/cloc/releases/download/1.82/cloc-1.82.exe";
2020
}
2121

2222
if (!testRunConfiguration.clocCliArguments) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import runTestTask from "./shared/testTaskRunner";
2+
3+
runTestTask({
4+
clocCliDownloadUrl: "./cloc-1.82.exe"
5+
});

tasks/cloc-build-task/tests/shouldProduceClocResultMdFile.ts renamed to tasks/cloc-build-task/tests/shouldWorkWithHttpDownload.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function executeTest(done: MochaDone): void {
1010
// tslint:disable-next-line:no-invalid-this
1111
this.timeout(30000);
1212

13-
const testPath = path.join(__dirname, mockRunnerDefinitions, "shouldProduceClocResultMdFile.js");
13+
const testPath = path.join(__dirname, mockRunnerDefinitions, "shouldWorkWithHttpDownload.js");
1414
const testRunner = new MockTestRunner(testPath);
1515

1616
testRunner.run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as path from "path";
2+
import { MockTestRunner } from "azure-pipelines-task-lib/mock-test";
3+
import { assert } from "chai";
4+
import * as fs from "fs";
5+
import * as os from "os";
6+
7+
const mockRunnerDefinitions = "mockRunnerDefinitions";
8+
9+
export function executeTest(done: MochaDone): void {
10+
// tslint:disable-next-line:no-invalid-this
11+
this.timeout(30000);
12+
13+
const testPath = path.join(__dirname, mockRunnerDefinitions, "shouldWorkWithLocalCloc.js");
14+
const testRunner = new MockTestRunner(testPath);
15+
16+
testRunner.run();
17+
18+
const testRunnerOutput = `${os.EOL}Test Runner output:${os.EOL}${testRunner.stdout}`;
19+
20+
assert.isTrue(fs.existsSync("tests/cloc.result.md"), testRunnerOutput);
21+
const clocResultMdFileContent = fs.readFileSync("tests/cloc.result.md", {
22+
encoding: "utf8"
23+
});
24+
25+
assert.include(clocResultMdFileContent, "SUM:|2|0|1|2", testRunnerOutput);
26+
27+
done();
28+
}

tasks/cloc-build-task/tests/suite.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as fs from "fs";
2-
import * as shouldProduceClocResultMdFile from "./shouldProduceClocResultMdFile";
2+
import * as shouldWorkWithHttpDownload from "./shouldWorkWithHttpDownload";
3+
import * as shouldWorkWithLocalCloc from "./shouldWorkWithLocalCloc";
34

45
describe("cloc build task", () => {
5-
after((done: MochaDone) => {
6+
afterEach((done: MochaDone) => {
67
const filesToDelete = [
78
"tests/cloc.exe",
89
"tests/cloc.result.md"
@@ -18,6 +19,10 @@ describe("cloc build task", () => {
1819
});
1920

2021
it(
21-
"should produce cloc.result.md file",
22-
shouldProduceClocResultMdFile.executeTest);
22+
"should work with http download url",
23+
shouldWorkWithHttpDownload.executeTest);
24+
25+
it(
26+
"should work with local file download url",
27+
shouldWorkWithLocalCloc.executeTest);
2328
});

0 commit comments

Comments
 (0)