|
import * as vscode from 'vscode'; |
|
import * as os from 'os'; |
|
import * as fs from 'fs'; |
|
import * as path from 'path'; |
|
import * as child_process from 'child_process'; |
|
|
|
let tccDotJar = 'tcc-9.x.x.jar'; |
|
|
|
let client: string; |
|
let clientRoot: string; |
|
|
|
export function activate(context: vscode.ExtensionContext) { |
|
tccDotJar = path.join(context.extensionPath, tccDotJar); |
|
let disposable = vscode.commands.registerCommand('vscode-teamcity-remote-run.remote-run', remoteRun); |
|
context.subscriptions.push(disposable); |
|
|
|
const config = vscode.workspace.getConfiguration('vscode-teamcity-remote-run'); |
|
if (config && config.workspace) { |
|
|
|
child_process.exec(`p4 info`, async (err, stdout, stderr) => { |
|
if (err) { |
|
vscode.window.showErrorMessage(err.message); |
|
return; |
|
} |
|
|
|
const infos = stdout.split(/\r?\n/); |
|
infos.forEach(info => { |
|
if (info.startsWith('Client name: ')) { |
|
client = info.substring(13); |
|
} |
|
if (info.startsWith('Client root: ')) { |
|
clientRoot = info.substring(13); |
|
} |
|
}); |
|
}); |
|
} |
|
} |
|
|
|
async function remoteRun() { |
|
if (client && clientRoot) { |
|
child_process.exec(`p4 info`, async (err, stdout, stderr) => { |
|
if (err) { |
|
vscode.window.showErrorMessage(err.message); |
|
return; |
|
} |
|
const infos = stdout.split('\n'); |
|
}); |
|
|
|
child_process.exec(`p4 changes -c ${client} -s pending`, async (err, stdout, stderr) => { |
|
if (err) { |
|
vscode.window.showErrorMessage(err.message); |
|
return; |
|
} |
|
const pendingChangelists = stdout.split(/\r?\n/) |
|
.filter(change => change.startsWith('Change ')) |
|
.map((change) => change.split(' ')[1]); |
|
const pendingChangelist = await vscode.window.showQuickPick(pendingChangelists, { |
|
placeHolder: 'Select pending changelist' |
|
}); |
|
if (pendingChangelist) { |
|
child_process.exec(`p4 -ztag opened -C ${client} -c ${pendingChangelist}`, async (err, stdout, stderr) => { |
|
if (err) { |
|
vscode.window.showErrorMessage(err.message); |
|
return; |
|
} |
|
const pendingChangelistFiles = stdout.split(/\r?\n/) |
|
.filter(change => change.startsWith('... clientFile ')) |
|
.map((change) => change.split(' ')[2]) |
|
.map(change => change.replace(`//${client}`, `${clientRoot}`)) |
|
.map(change => change.replace(/\//g, path.sep).replace(/\\/g, path.sep)); |
|
child_process.exec(`java -jar ${tccDotJar} info -p InfoArchive_212`, async (err, stdout, stderr) => { |
|
if (err) { |
|
vscode.window.showErrorMessage(err.message); |
|
return; |
|
} |
|
const configIds = stdout.split(/\r?\n/) |
|
.filter(change => change.trim().length > 0) |
|
.map((change) => change.split(' ')[0]); |
|
do { |
|
configIds.shift(); |
|
} while (configIds.length > 0 && configIds[0] !== 'id'); |
|
if (configIds.length > 0) { |
|
configIds.shift(); |
|
} |
|
if (configIds.length > 0) { |
|
const configId = await vscode.window.showQuickPick(configIds, { |
|
placeHolder: 'Select target build to run Remote run' |
|
}); |
|
if (configId) { |
|
const tempFolderForWorkspace = fs.mkdtempSync(path.join(os.tmpdir(), `${client}-`)); |
|
const pendingChangelistFilelistFile = path.join(tempFolderForWorkspace, `p4-changelist-${pendingChangelist}.filelist`); |
|
fs.writeFileSync(pendingChangelistFilelistFile, pendingChangelistFiles.join('\n')); |
|
vscode.window.showInformationMessage(`java -jar ${tccDotJar} run -n --force-compatibility-check -c ${configId} -p InfoArchive_212 -m 'Remote run for changelist ${pendingChangelist}' @${pendingChangelistFilelistFile}`); |
|
} |
|
} |
|
}); |
|
}); |
|
} |
|
}); |
|
} |
|
} |
|
|
|
// this method is called when your extension is deactivated |
|
export function deactivate() {} |