Skip to content

Commit

Permalink
Support for multi-folder workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
NickHeap2 committed Aug 30, 2020
1 parent 229b5d0 commit eda4722
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 47 deletions.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
"${workspaceFolder}/test_otherfolder"
]
},
{
"name": "Extension test workspace",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/workspace/workspace.code-workspace"
]
},
{
"name": "Extension Tests",
"type": "extensionHost",
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to the "vscode-ant" extension will be documented in this file.

## [0.3.0] - 2020-08-30
### Added
- Better support multi-folder workspaces by checking them in order for build files.

## [0.2.2] - 2020-08-17
### Added
- Initialise command that is run when a new terminal window is created.
Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ant build output can be colorized, environment variables can be set and targets

- Bundled Ant 1.10.7 with a windows colour library by Dennis Lang (http://landenlabs.com/android/ant-color-logger/index.html).
- Searches for build.xml in the root directory (but you can configure it to look eleswhere) on startup and loads the targets ready to run.
- Supports multi-folder workspaces by scanning each folder in turn looking for build files.
- The targets and their dependencies are visualised in a treeview and can be run from the toolbar or the context menu option.
- Dependencies of dependencies are shown recursively to give a full picture of what will be run and in which order.
- Targets can be sorted as they appear in the file or in alphabetical order.
Expand Down Expand Up @@ -96,10 +97,12 @@ The autoTarget file build.auto (or whatever is configured) should be in the json

## Release Notes

New initialise command that will execute whenever a new terminal window is created.
I'm using this myself to call 'chcp 65001' to set windows code page to UTF-8 so I can get tick marks in my ablunit output.
Support multi-folder workspaces by scanning each folder in turn looking for build files.
This is an interim solution until I have time to add full support for multiple build files being loaded at once.

Updated dependencies based on Github security reports.
## [0.3.0] - 2020-08-30
### Added
- Better support workspaces by checking them in order for build files.

## [0.2.2] - 2020-08-17
### Added
Expand All @@ -111,12 +114,3 @@ Updated dependencies based on Github security reports.
## [0.2.1] - 2020-05-05
### Fixed
- Extension missing README etc

## [0.2.0] - 2020-05-05
### Added
- Use webpack to bundle extension.
- Bundle Ant 1.10.7 with windows colour library by Dennis Lang.
- Configurable build file directories.
- Configurable build file names.
- Support for imported build targets.
- Prefix window messages with ATR:.
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"displayName": "Ant Target Runner",
"description": "Run Ant targets, manually & automatically, with colorized Ant output.",
"version": "0.2.2",
"version": "0.3.0",
"publisher": "nickheap",
"engines": {
"vscode": "^1.18.1"
Expand Down Expand Up @@ -70,6 +70,14 @@
"light": "dist/resources/icons/light/refresh.svg",
"dark": "dist/resources/icons/dark/refresh.svg"
}
},
{
"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"
}
],
"menus": {
Expand Down
12 changes: 5 additions & 7 deletions src/AntTargetRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ var extensionContext
module.exports = class AntTargetRunner {
constructor (context) {
extensionContext = context
this.rootPath = vscode.workspace.workspaceFolders[0].uri.fsPath
this.autoTargetRunner = null

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

var onDidChangeWorkspaceFolders = vscode.workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders.bind(this))
extensionContext.subscriptions.push(onDidChangeWorkspaceFolders)
setWorkspaceFolder (workspaceFolder) {
this.rootPath = workspaceFolder.uri.fsPath

this.getConfigOptions()
}
Expand All @@ -25,10 +25,6 @@ module.exports = class AntTargetRunner {
this.getConfigOptions()
}

onDidChangeWorkspaceFolders () {
this.rootPath = vscode.workspace.workspaceFolders[0].uri.fsPath
}

async getConfigOptions () {
let configOptions = vscode.workspace.getConfiguration('ant', null)
this.envVarsFile = configOptions.get('envVarsFile', 'build.env')
Expand Down Expand Up @@ -146,6 +142,8 @@ module.exports = class AntTargetRunner {
this.antTerminal = vscode.window.createTerminal({name: 'Ant Target Runner', env: envVars}) // , shellPath: 'C:\\WINDOWS\\System32\\cmd.exe' })
}

this.antTerminal.sendText(`cd ${this.rootPath}`)

// send an initialise command?
if (this.initialiseCommand) {
this.antTerminal.sendText(`${this.initialiseCommand}`)
Expand Down
41 changes: 27 additions & 14 deletions src/AntTreeDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,16 @@ module.exports = class AntTreeDataProvider {
path.join(context.extensionPath, 'dist', 'resources', 'icons', 'light', 'dependency.svg')
)

this.targetRunner = null
this.targets = null
this.project = null
this.buildFilenames = 'build.xml'
this.buildFileDirectories = '.'
this.eventListeners = []

var workspaceFolders = vscode.workspace.workspaceFolders
if (workspaceFolders) {
this.rootPath = workspaceFolders[0].uri.fsPath
// this.watchBuildXml(workspaceFolders)
this.BuildFileParser = new BuildFileParser(workspaceFolders[0].uri.fsPath)
this.workspaceFolders = vscode.workspace.workspaceFolders
this.workspaceFolderNumber = 0
if (this.workspaceFolders) {
this.setWorkspaceFolder()
}

// event for notify of change of data
Expand All @@ -66,17 +64,25 @@ module.exports = class AntTreeDataProvider {
this.getConfigOptions()
}

setWorkspaceFolder () {
this.rootPath = this.workspaceFolders[this.workspaceFolderNumber].uri.fsPath
// this.watchBuildXml(workspaceFolders)
this.BuildFileParser = new BuildFileParser(this.workspaceFolders[this.workspaceFolderNumber].uri.fsPath)

vscode.commands.executeCommand('vscode-ant.setRunnerWorkspaceFolder', this.workspaceFolders[this.workspaceFolderNumber])
vscode.commands.executeCommand('vscode-ant.setAutoWorkspaceFolder', this.workspaceFolders[this.workspaceFolderNumber])
}

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

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

if (workspaceFolders) {
this.rootPath = workspaceFolders[0].uri.fsPath
this.BuildFileParser = new BuildFileParser(workspaceFolders[0].uri.fsPath)
this.workspaceFolders = vscode.workspace.workspaceFolders
this.workspaceFolderNumber = 0
if (this.workspaceFolders) {
this.setWorkspaceFolder()
}

this.refresh()
Expand Down Expand Up @@ -268,7 +274,14 @@ module.exports = class AntTreeDataProvider {
try {
var buildFilename = await this.BuildFileParser.findBuildFile(this.buildFileDirectories.split(','), this.buildFilenames.split(','))
} catch (error) {
messageHelper.showInformationMessage('Workspace has no build.xml files.')
if (this.workspaceFolderNumber < (this.workspaceFolders.length - 1)) {
this.workspaceFolderNumber++
this.setWorkspaceFolder()
this.refresh()
} else {
messageHelper.showInformationMessage('Workspace has no build.xml files.')
}

return resolve([])
}

Expand Down Expand Up @@ -378,12 +391,12 @@ module.exports = class AntTreeDataProvider {
}

runSelectedAntTarget () {
if (selectedAntTarget && this.targetRunner) {
if (selectedAntTarget) {
var target = selectedAntTarget.name
if (target.indexOf(' ') >= 0) {
target = '"' + target + '"'
}
this.targetRunner.runAntTarget({name: target, sourceFile: selectedAntTarget.sourceFile})
vscode.commands.executeCommand('vscode-ant.runAntTarget', {name: target, sourceFile: selectedAntTarget.sourceFile})
}
}

Expand Down
22 changes: 12 additions & 10 deletions src/AutoTargetRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,32 @@ var extensionContext
var configOptions

module.exports = class AutoTargetRunner {
constructor (context, targetRunner) {
constructor (context) {
extensionContext = context

this.autoFile = ''

this.buildFileDirectories = '.'
this.autoFilename = 'build.auto'

this.targetRunner = targetRunner
this.autoRunTasks = []
this.autoTargets = []

var workspaceFolders = vscode.workspace.workspaceFolders
if (workspaceFolders) {
this.rootPath = workspaceFolders[0].uri.fsPath
var onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this))
extensionContext.subscriptions.push(onDidChangeConfiguration)

this.getConfigOptions()
}
}

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

await this.getConfigOptions()
this.startWatching()
}

startWatching () {
this.watchAutoTargetsFile()

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

onDidChangeConfiguration () {
Expand Down Expand Up @@ -70,7 +71,8 @@ module.exports = class AutoTargetRunner {
this.autoRunTasks[targets] = setTimeout(() => {
// console.log('Running entry for:' + targets)
this.autoRunTasks[targets] = undefined
this.targetRunner.runAntTarget({name: targets, sourceFile: sourceFile})
// this.targetRunner.runAntTarget({name: targets, sourceFile: sourceFile})
vscode.commands.executeCommand('vscode-ant.runAntTarget', {name: targets, sourceFile: sourceFile})
}, delay, targets)
}

Expand Down
15 changes: 12 additions & 3 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ var antTreeDataProvider
// your extension is activated the very first time the command is executed
function activate (context) {
antTargetRunner = new AntTargetRunner(context)
autoTargetRunner = new AutoTargetRunner(context, antTargetRunner)
autoTargetRunner.startWatching()
autoTargetRunner = new AutoTargetRunner(context)
// autoTargetRunner.startWatching()

antTreeDataProvider = new AntTreeDataProvider(context)
antTreeDataProvider.targetRunner = antTargetRunner
// antTreeDataProvider.targetRunner = antTargetRunner

var antRunnerView = vscode.window.createTreeView('antRunnerView', {treeDataProvider: antTreeDataProvider})
context.subscriptions.push(antRunnerView)

var setRunnerWorkspaceFolder = vscode.commands.registerCommand('vscode-ant.setRunnerWorkspaceFolder', antTargetRunner.setWorkspaceFolder.bind(antTargetRunner))
context.subscriptions.push(setRunnerWorkspaceFolder)

var setAutoWorkspaceFolder = vscode.commands.registerCommand('vscode-ant.setAutoWorkspaceFolder', autoTargetRunner.setWorkspaceFolder.bind(autoTargetRunner))
context.subscriptions.push(setAutoWorkspaceFolder)

var changeWorkspaceFolder = vscode.commands.registerCommand('vscode-ant.changeWorkspaceFolder', antTargetRunner.setWorkspaceFolder.bind(antTargetRunner))
context.subscriptions.push(changeWorkspaceFolder)

var runAntTarget = vscode.commands.registerCommand('vscode-ant.runAntTarget', antTargetRunner.nodeRunAntTarget.bind(antTargetRunner))
context.subscriptions.push(runAntTarget)

Expand Down
85 changes: 85 additions & 0 deletions test2/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<project name="Test project name" default="default">
<property environment="env"/>

<import file="macrodefs.xml"/>
<import file="targets.xml"/>

<target name="default" depends="clean,compile,test,dist"/>

<target name="fold space" description="Fold space">
<echo message="Folding space..."/>
</target>

<target name="dlc" description="Show dlc!">
<echo message="${env.DLC}"/>


</target>

<target name="clean" description="Clean all the things!">
<echo message="All the things are cleaned!"/>




</target>

<target name="start_databases">
<echo message="Databases are now running."/>





</target>

<target name="compile" depends="start_databases">
<echo message="All the things are compiled!"/>





</target>

<target name="compile_foldertest" depends="start_databases">
<echo message="All the foldertest things are compiled!"/>





</target>

<target
name="test"
depends="compile">
<echo message="0 test have been run."/>





</target>

<target name="dist" depends="compile,test">
<echo message="We shipped it!"/>





</target>

<target name="output_test">
<echo message="This is an error." level="error"/>
<echo message="This is an warning." level="warning"/>
<echo message="This is an info." level="info"/>
<echo message="This is an verbose." level="verbose"/>
<echo message="This is an debug." level="debug"/>
</target>

<target name="more targets with dependency" depends="more targets target">
<echo message="This depends on a target in another file."/>
</target>
</project>
Loading

0 comments on commit eda4722

Please sign in to comment.