Skip to content

Commit

Permalink
Add mock build task
Browse files Browse the repository at this point in the history
  • Loading branch information
Adadov committed Dec 26, 2024
1 parent 9b54160 commit 3e61327
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 9 deletions.
27 changes: 24 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"Snippets",
"Other"
],
"activationEvents": [],
"activationEvents": [
"onCommand:workbench.action.tasks.runTask"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
Expand All @@ -43,7 +45,26 @@
"scope": "resource"
}
}
}
},
"inputs": [
{
"id": "fversion",
"description": "Version number ?",
"default": "41",
"type": "promptString"
}
],
"taskDefinitions": [
{
"type": "custombuildscript",
"properties": {
"fversion": {
"type": "string",
"description": "Fedora Version"
}
}
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
Expand All @@ -60,4 +81,4 @@
"@vscode/test-electron": "^2.4.1",
"eslint": "^8.57.1"
}
}
}
65 changes: 65 additions & 0 deletions src/customTaskProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import * as vscode from 'vscode';

interface CustomBuildTaskDefinition extends vscode.TaskDefinition {

}

export class CustomBuildTaskProvider implements vscode.TaskProvider {
static CustomBuildScriptType = 'custombuildscript';
private tasks?: vscode.Task[];

// We use a CustomExecution task when state needs to be shared across runs of the task or when
// the task requires use of some VS Code API to run.
// If you don't need to share state between runs and if you don't need to execute VS Code API in your task,
// then a simple ShellExecution or ProcessExecution should be enough.
// Since our build has this shared state, the CustomExecution is used below.
private sharedState: string | undefined;

private definition = {
type: CustomBuildTaskProvider.CustomBuildScriptType
};

constructor(private workspaceRoot: string) { }

public async provideTasks(): Promise<vscode.Task[]> {
return this.getTasks();
}

public resolveTask(_task: vscode.Task): vscode.Task | undefined {
return _task;
}

private getTasks(): vscode.Task[] {
// // In our fictional build, we have two build flavors
// const flavors: string[] = ['32', '64'];
// // Each flavor can have some options.
// const flags: string[][] = [['watch', 'incremental'], ['incremental'], []];

this.tasks = [];
// flavors.forEach(flavor => {
// flags.forEach(flagGroup => {
this.tasks!.push(this.getTask("40"));
this.tasks!.push(this.getTask("41"));
// });
// });
return this.tasks;
}

private getTask(fversion: string): vscode.Task {

const termExec = new vscode.ShellExecution(`echo "vers: ${fversion}"; mock -r fedora-${fversion}-x86_64 --spec ` + '${file}' + ` --sources ~/rpmbuild/SOURCES '-D disable_source_fetch %nil'`);
return new vscode.Task(this.definition, vscode.TaskScope.Workspace, `run mock fedora ${fversion} `,
CustomBuildTaskProvider.CustomBuildScriptType, termExec);
// return new vscode.Task(definition, vscode.TaskScope.Workspace, `run mock fedora 41`,
// CustomBuildTaskProvider.CustomBuildScriptType, new vscode.ShellExecution(async (): Promise<vscode.Pseudoterminal> => {
// // When the task is executed, this callback will run. Here, we setup for running the task.
// return new CustomBuildTaskTerminal(this.workspaceRoot, () => this.sharedState, (state: string) => this.sharedState = state);
// }));
}
}
;
27 changes: 21 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import * as vscode from 'vscode';
import { exec } from "child_process";
import { ExtensionContext, workspace, commands, window, SnippetString } from "vscode";
import { CustomBuildTaskProvider } from './customTaskProvider';

export function activate(context: ExtensionContext) {
const settings = workspace.getConfiguration('rpmspecChangelog');
let customTaskProvider: vscode.Disposable | undefined;

let disposable = commands.registerTextEditorCommand(
export function activate(context: vscode.ExtensionContext) {
const settings = vscode.workspace.getConfiguration('rpmspecChangelog');
const workspaceRoot = (vscode.workspace.workspaceFolders && (vscode.workspace.workspaceFolders.length > 0))
? vscode.workspace.workspaceFolders[0].uri.fsPath : undefined;
if (!workspaceRoot) {
return;
}
customTaskProvider = vscode.tasks.registerTaskProvider(CustomBuildTaskProvider.CustomBuildScriptType, new CustomBuildTaskProvider(workspaceRoot));

let disposable = vscode.commands.registerTextEditorCommand(
"extension.insertRPMSpecChangelog",
async () => {
const currentDocument = window.activeTextEditor;
const currentDocument = vscode.window.activeTextEditor;

if (!currentDocument) {
return;
Expand All @@ -29,7 +38,7 @@ export function activate(context: ExtensionContext) {
console.log(curdate);
console.log(settings.get('obtainNameAndEmailFromGit'));

const snippet = new SnippetString("* " + curdate);
const snippet = new vscode.SnippetString("* " + curdate);

var email, name;

Expand Down Expand Up @@ -74,3 +83,9 @@ export function activate(context: ExtensionContext) {

context.subscriptions.push(disposable);
}

export function deactivate(): void {
if (customTaskProvider) {
customTaskProvider.dispose();
}
}

0 comments on commit 3e61327

Please sign in to comment.