Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
"${workspaceFolder}/workspace/workspace.code-workspace"
]
},
{
"name": "Extension test ablunit",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"D:/workspaces/nickheap2/ablunit-mods/ablunit-mods"
]
},
{
"name": "Extension Tests",
"type": "extensionHost",
Expand Down
7,246 changes: 4,002 additions & 3,244 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 22 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@
}
},
{
"command": "vscode-ant.setRunnerWorkspaceFolder",
"title": "Set the workspace folder for the Ant runner"
"command": "vscode-ant.setRunnerWorkspaceFolder",
"title": "Set the workspace folder for the Ant runner"
},
{
"command": "vscode-ant.setAutoWorkspaceFolder",
"title": "Set the workspace folder for the Ant auto runner"
"command": "vscode-ant.setAutoWorkspaceFolder",
"title": "Set the workspace folder for the Ant auto runner"
},
{
"command": "vscode-ant.buildFilesChanged",
"title": "Signal build files have changed for tree view"
}
],
"menus": {
Expand Down Expand Up @@ -174,10 +178,10 @@
"description": "Command to call when new output console is initialised on win32 platform."
},
"ant.initialiseCommandOnLinux": {
"type": "string",
"default": "",
"description": "Command to call when new output console is initialised on linux platform."
}
"type": "string",
"default": "",
"description": "Command to call when new output console is initialised on linux platform."
}
}
}
},
Expand All @@ -193,15 +197,17 @@
"webpack-dev": "webpack --mode development --watch"
},
"devDependencies": {
"@types/mocha": "^7.0.2",
"@types/node": "^13.13.15",
"@types/vscode": "^1.18.0",
"@types/mocha": "^8.0.3",
"@types/node": "^14.14.6",
"@types/vscode": "^1.50.0",
"chai": "^4.2.0",
"copy-webpack-plugin": "^6.0.3",
"eslint": "^6.8.0",
"vscode-test": "^1.4.0",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
"copy-webpack-plugin": "^6.2.1",
"eslint": "^7.12.1",
"npm": "^6.14.8",
"vscode": "^1.1.37",
"vscode-test": "^1.4.1",
"webpack": "^5.3.2",
"webpack-cli": "^4.1.0"
},
"dependencies": {
"dotenv": "^8.2.0",
Expand Down
195 changes: 195 additions & 0 deletions src/AntBuildFileProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
const vscode = require('vscode')
// const _ = require('lodash')
const filehelper = require('./filehelper')
const path = require('path')
const BuildFileParser = require('./BuildFileParser.js')
const messageHelper = require('./messageHelper')
const AntTargetRunner = require('./AntTargetRunner')

var configOptions

module.exports = class AntBuildFileProvider {
constructor (context) {
this.extensionContext = context

// trap config and workspaces changes to pass updates
var onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this))
this.extensionContext.subscriptions.push(onDidChangeConfiguration)

var onDidChangeWorkspaceFolders = vscode.workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders.bind(this))
this.extensionContext.subscriptions.push(onDidChangeWorkspaceFolders)

this.BuildFileParser = new BuildFileParser('')

this.buildFilenames = 'build.xml'
this.buildFileDirectories = '.'
this.eventListeners = []
this.buildFiles = []

this.workspaceFolders = vscode.workspace.workspaceFolders

this.getConfigOptions()
this.refresh()
}

onDidChangeConfiguration () {
this.getConfigOptions()
this.refresh()
}

onDidChangeWorkspaceFolders () {
this.workspaceFolders = vscode.workspace.workspaceFolders

this.refresh()
}

findBuildFileOfWorkspace (workspaceRootPath, searchDirectories, searchFileNames) {
return new Promise(async (resolve, reject) => {
try {
var filename = await filehelper.findfirstFile(workspaceRootPath, searchDirectories, searchFileNames)
resolve(filename)
} catch (error) {
return reject(new Error('No build file found!'))
}
})
}

getConfigOptions () {
configOptions = vscode.workspace.getConfiguration('ant', null)
this.sortTargetsAlphabetically = configOptions.get('sortTargetsAlphabetically', 'true')
this.buildFilenames = configOptions.get('buildFilenames', 'build.xml')
if (this.buildFilenames === '' || typeof this.buildFilenames === 'undefined') {
this.buildFilenames = 'build.xml'
}
this.buildFileDirectories = configOptions.get('buildFileDirectories', '.')
if (this.buildFileDirectories === '' || typeof this.buildFileDirectories === 'undefined') {
this.buildFileDirectories = '.'
}
}

getWorkspaceBuildFiles () {
return new Promise(async (resolve, reject) => {
this.buildFiles = []

// check for empty workspace
if (!this.workspaceFolders) {
return resolve(this.buildFiles)
}

// loop workspace folders
for (const workspaceFolder of this.workspaceFolders) {
const workspaceFolderPath = workspaceFolder.uri.fsPath
try {
var buildFilename = await this.findBuildFileOfWorkspace(workspaceFolderPath, this.buildFileDirectories.split(','), this.buildFilenames.split(','))
} catch (error) {
// TODO - what do we add here?
continue
}

var fullBuildFilename = path.join(workspaceFolderPath, buildFilename)

try {
var buildFileObj = await this.BuildFileParser.parseBuildFile(fullBuildFilename)
} catch (error) {
messageHelper.showErrorMessage(`Error reading ${buildFilename} !`)
// return reject(new Error('Error reading build.xml!: ' + error))

var errorFile = {
buildFilename: buildFilename,
fullBuildFilename: fullBuildFilename,
projectDetails: {},
buildTargets: [],
buildSourceFiles: [],
errorMessage: 'Error reading file!'
}
this.buildFiles.push(errorFile)

continue
}

try {
var buildFile = {
buildFilename: buildFilename,
fullBuildFilename: fullBuildFilename,
projectDetails: {},
buildTargets: [],
buildSourceFiles: []
}
buildFile.projectDetails = this.BuildFileParser.getProjectDetails(buildFileObj)

var [buildTargets, buildSourceFiles] = await this.BuildFileParser.getTargets(fullBuildFilename, buildFileObj, [], [])
buildFile.buildTargets = buildTargets
buildFile.buildSourceFiles = buildSourceFiles

// create an ant target runnner for this build file
buildFile.antTargetRunner = new AntTargetRunner(this.extensionContext)
buildFile.antTargetRunner.setWorkspaceFolder(workspaceFolderPath)

messageHelper.showInformationMessage(`Targets loaded from ${fullBuildFilename} !`)

// const buildSourceFiles = _.uniq(_.map(buildTargets, 'sourceFile'))
for (const buildSourceFile of buildFile.buildSourceFiles) {
this.watchBuildFile(workspaceFolderPath, buildSourceFile)
}

this.buildFiles.push(buildFile)
} catch (error) {
messageHelper.showErrorMessage(`Error getting targets from ${fullBuildFilename} !`)
continue
// return reject(new Error('Error parsing build.xml!:' + error))
}
}
if (this.buildFileDirectories.length === 0) {
messageHelper.showInformationMessage('Workspace has no ant build files.')
}
return resolve(this.buildFiles)
})
}

async refresh () {
// clean up target runners
for (const buildFile of this.buildFiles) {
delete buildFile.antTargetRunner
}

// remove event listeners
for (const eventListener of this.eventListeners) {
eventListener.didChangeListener.dispose()
eventListener.didDeleteListener.dispose()
eventListener.didCreateListener.dispose()
eventListener.fileSystemWatcher.dispose()
}
this.eventListeners = []

await this.getWorkspaceBuildFiles()
vscode.commands.executeCommand('vscode-ant.buildFilesChanged', this.buildFiles)
}

removeSubscription (item) {
this.extensionContext.subscriptions.splice(this.extensionContext.subscriptions.indexOf(item), 1)
}

watchBuildFile (rootPath, buildFileName) {
const buildFile = filehelper.getRootFile(rootPath, buildFileName)
this.watchFile(buildFile)
}

watchFile (globPattern) {
var fileSystemWatcher = vscode.workspace.createFileSystemWatcher(globPattern)
this.extensionContext.subscriptions.push(fileSystemWatcher)

this.eventListeners.push({
filename: globPattern,
fileSystemWatcher: fileSystemWatcher,
didChangeListener: fileSystemWatcher.onDidChange(() => {
this.refresh()
}, this, this.extensionContext.subscriptions),
didDeleteListener: fileSystemWatcher.onDidDelete(() => {
this.refresh()
}, this, this.extensionContext.subscriptions),
didCreateListener: fileSystemWatcher.onDidCreate(() => {
this.refresh()
}, this, this.extensionContext.subscriptions)
})
}
}
54 changes: 21 additions & 33 deletions src/AntTargetRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const dotenv = require('dotenv')
const filehelper = require('./filehelper')
const fs = require('fs')
const path = require('path')
const _ = require('lodash')

var extensionContext

Expand All @@ -11,12 +12,16 @@ module.exports = class AntTargetRunner {
extensionContext = context
this.autoTargetRunner = null

var onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this))
const onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this))
extensionContext.subscriptions.push(onDidChangeConfiguration)

// target runner needs to know when the terminal closes
const terminalClosed = vscode.window.onDidCloseTerminal(this.terminalClosed.bind(this))
context.subscriptions.push(terminalClosed)
}

setWorkspaceFolder (workspaceFolder) {
this.rootPath = workspaceFolder.uri.fsPath
this.rootPath = workspaceFolder

this.getConfigOptions()
}
Expand Down Expand Up @@ -70,27 +75,18 @@ module.exports = class AntTargetRunner {
this.envVarsFile = 'build.env'
}

this.envVarsFile = await filehelper.findfirstFile(this.rootPath, this.buildFileDirectories.split(','), this.envVarsFile.split(','))
try {
this.envVarsFile = await filehelper.findfirstFile(this.rootPath, this.buildFileDirectories.split(','), this.envVarsFile.split(','))
} catch (error) {
// it's fine if this doesn't exist
}

if (this.antTerminal) {
this.antTerminal.dispose()
this.antTerminal = null
}
}

nodeRunAntTarget (context) {
if (!context) {
return
}

var target = context.name
if (target.indexOf(' ') >= 0) {
target = '"' + target + '"'
}

this.runAntTarget({ name: target, sourceFile: context.sourceFile })
}

runAntTarget (context) {
if (!context) {
return
Expand All @@ -99,6 +95,15 @@ module.exports = class AntTargetRunner {
const targets = context.name
const buildFile = context.sourceFile

if (!this.antTerminal) {
this.antTerminal = _.find(vscode.window.terminals, (o) => {
if (o.name === 'Ant Target Runner') {
return true
}
return false
})
}

if (!this.antTerminal) {
var envVars = {}
if (this.envVarsFile && filehelper.pathExists(filehelper.getRootFile(this.rootPath, this.envVarsFile))) {
Expand Down Expand Up @@ -159,23 +164,6 @@ module.exports = class AntTargetRunner {
this.antTerminal.show(true)
}

revealDefinition (target) {
vscode.workspace.openTextDocument(filehelper.getRootFile(this.rootPath, target.sourceFile))
.then((document) => {
return vscode.window.showTextDocument(document)
})
.then((textEditor) => {
// find the line
let text = textEditor.document.getText()
let regexp = new RegExp('target[.\\s]+name[\\s]*=["\']' + target.name + '["\']', 'gm')
let offset = regexp.exec(text)
if (offset) {
let position = textEditor.document.positionAt(offset.index)
textEditor.revealRange(new vscode.Range(position, position), vscode.TextEditorRevealType.InCenter)
}
})
}

terminalClosed (terminal) {
if (terminal.name === this.antTerminal.name) {
this.antTerminal.dispose()
Expand Down
Loading