Skip to content

Commit eda4722

Browse files
committed
Support for multi-folder workspaces
1 parent 229b5d0 commit eda4722

10 files changed

Lines changed: 192 additions & 47 deletions

File tree

.vscode/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
2727
"${workspaceFolder}/test_otherfolder"
2828
]
2929
},
30+
{
31+
"name": "Extension test workspace",
32+
"type": "extensionHost",
33+
"request": "launch",
34+
"runtimeExecutable": "${execPath}",
35+
"args": [
36+
"--disable-extensions",
37+
"--extensionDevelopmentPath=${workspaceFolder}",
38+
"${workspaceFolder}/workspace/workspace.code-workspace"
39+
]
40+
},
3041
{
3142
"name": "Extension Tests",
3243
"type": "extensionHost",

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to the "vscode-ant" extension will be documented in this file.
33

4+
## [0.3.0] - 2020-08-30
5+
### Added
6+
- Better support multi-folder workspaces by checking them in order for build files.
7+
48
## [0.2.2] - 2020-08-17
59
### Added
610
- Initialise command that is run when a new terminal window is created.

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Ant build output can be colorized, environment variables can be set and targets
77

88
- Bundled Ant 1.10.7 with a windows colour library by Dennis Lang (http://landenlabs.com/android/ant-color-logger/index.html).
99
- 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.
10+
- Supports multi-folder workspaces by scanning each folder in turn looking for build files.
1011
- The targets and their dependencies are visualised in a treeview and can be run from the toolbar or the context menu option.
1112
- Dependencies of dependencies are shown recursively to give a full picture of what will be run and in which order.
1213
- Targets can be sorted as they appear in the file or in alphabetical order.
@@ -96,10 +97,12 @@ The autoTarget file build.auto (or whatever is configured) should be in the json
9697

9798
## Release Notes
9899

99-
New initialise command that will execute whenever a new terminal window is created.
100-
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.
100+
Support multi-folder workspaces by scanning each folder in turn looking for build files.
101+
This is an interim solution until I have time to add full support for multiple build files being loaded at once.
101102

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

104107
## [0.2.2] - 2020-08-17
105108
### Added
@@ -111,12 +114,3 @@ Updated dependencies based on Github security reports.
111114
## [0.2.1] - 2020-05-05
112115
### Fixed
113116
- Extension missing README etc
114-
115-
## [0.2.0] - 2020-05-05
116-
### Added
117-
- Use webpack to bundle extension.
118-
- Bundle Ant 1.10.7 with windows colour library by Dennis Lang.
119-
- Configurable build file directories.
120-
- Configurable build file names.
121-
- Support for imported build targets.
122-
- Prefix window messages with ATR:.

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"displayName": "Ant Target Runner",
1414
"description": "Run Ant targets, manually & automatically, with colorized Ant output.",
15-
"version": "0.2.2",
15+
"version": "0.3.0",
1616
"publisher": "nickheap",
1717
"engines": {
1818
"vscode": "^1.18.1"
@@ -70,6 +70,14 @@
7070
"light": "dist/resources/icons/light/refresh.svg",
7171
"dark": "dist/resources/icons/dark/refresh.svg"
7272
}
73+
},
74+
{
75+
"command": "vscode-ant.setRunnerWorkspaceFolder",
76+
"title": "Set the workspace folder for the Ant runner"
77+
},
78+
{
79+
"command": "vscode-ant.setAutoWorkspaceFolder",
80+
"title": "Set the workspace folder for the Ant auto runner"
7381
}
7482
],
7583
"menus": {

src/AntTargetRunner.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ var extensionContext
99
module.exports = class AntTargetRunner {
1010
constructor (context) {
1111
extensionContext = context
12-
this.rootPath = vscode.workspace.workspaceFolders[0].uri.fsPath
1312
this.autoTargetRunner = null
1413

1514
var onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this))
1615
extensionContext.subscriptions.push(onDidChangeConfiguration)
16+
}
1717

18-
var onDidChangeWorkspaceFolders = vscode.workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders.bind(this))
19-
extensionContext.subscriptions.push(onDidChangeWorkspaceFolders)
18+
setWorkspaceFolder (workspaceFolder) {
19+
this.rootPath = workspaceFolder.uri.fsPath
2020

2121
this.getConfigOptions()
2222
}
@@ -25,10 +25,6 @@ module.exports = class AntTargetRunner {
2525
this.getConfigOptions()
2626
}
2727

28-
onDidChangeWorkspaceFolders () {
29-
this.rootPath = vscode.workspace.workspaceFolders[0].uri.fsPath
30-
}
31-
3228
async getConfigOptions () {
3329
let configOptions = vscode.workspace.getConfiguration('ant', null)
3430
this.envVarsFile = configOptions.get('envVarsFile', 'build.env')
@@ -146,6 +142,8 @@ module.exports = class AntTargetRunner {
146142
this.antTerminal = vscode.window.createTerminal({name: 'Ant Target Runner', env: envVars}) // , shellPath: 'C:\\WINDOWS\\System32\\cmd.exe' })
147143
}
148144

145+
this.antTerminal.sendText(`cd ${this.rootPath}`)
146+
149147
// send an initialise command?
150148
if (this.initialiseCommand) {
151149
this.antTerminal.sendText(`${this.initialiseCommand}`)

src/AntTreeDataProvider.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,16 @@ module.exports = class AntTreeDataProvider {
3838
path.join(context.extensionPath, 'dist', 'resources', 'icons', 'light', 'dependency.svg')
3939
)
4040

41-
this.targetRunner = null
4241
this.targets = null
4342
this.project = null
4443
this.buildFilenames = 'build.xml'
4544
this.buildFileDirectories = '.'
4645
this.eventListeners = []
4746

48-
var workspaceFolders = vscode.workspace.workspaceFolders
49-
if (workspaceFolders) {
50-
this.rootPath = workspaceFolders[0].uri.fsPath
51-
// this.watchBuildXml(workspaceFolders)
52-
this.BuildFileParser = new BuildFileParser(workspaceFolders[0].uri.fsPath)
47+
this.workspaceFolders = vscode.workspace.workspaceFolders
48+
this.workspaceFolderNumber = 0
49+
if (this.workspaceFolders) {
50+
this.setWorkspaceFolder()
5351
}
5452

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

67+
setWorkspaceFolder () {
68+
this.rootPath = this.workspaceFolders[this.workspaceFolderNumber].uri.fsPath
69+
// this.watchBuildXml(workspaceFolders)
70+
this.BuildFileParser = new BuildFileParser(this.workspaceFolders[this.workspaceFolderNumber].uri.fsPath)
71+
72+
vscode.commands.executeCommand('vscode-ant.setRunnerWorkspaceFolder', this.workspaceFolders[this.workspaceFolderNumber])
73+
vscode.commands.executeCommand('vscode-ant.setAutoWorkspaceFolder', this.workspaceFolders[this.workspaceFolderNumber])
74+
}
75+
6976
onDidChangeConfiguration () {
7077
this.getConfigOptions()
7178
this.refresh()
7279
}
7380

7481
onDidChangeWorkspaceFolders () {
75-
var workspaceFolders = vscode.workspace.workspaceFolders
76-
77-
if (workspaceFolders) {
78-
this.rootPath = workspaceFolders[0].uri.fsPath
79-
this.BuildFileParser = new BuildFileParser(workspaceFolders[0].uri.fsPath)
82+
this.workspaceFolders = vscode.workspace.workspaceFolders
83+
this.workspaceFolderNumber = 0
84+
if (this.workspaceFolders) {
85+
this.setWorkspaceFolder()
8086
}
8187

8288
this.refresh()
@@ -268,7 +274,14 @@ module.exports = class AntTreeDataProvider {
268274
try {
269275
var buildFilename = await this.BuildFileParser.findBuildFile(this.buildFileDirectories.split(','), this.buildFilenames.split(','))
270276
} catch (error) {
271-
messageHelper.showInformationMessage('Workspace has no build.xml files.')
277+
if (this.workspaceFolderNumber < (this.workspaceFolders.length - 1)) {
278+
this.workspaceFolderNumber++
279+
this.setWorkspaceFolder()
280+
this.refresh()
281+
} else {
282+
messageHelper.showInformationMessage('Workspace has no build.xml files.')
283+
}
284+
272285
return resolve([])
273286
}
274287

@@ -378,12 +391,12 @@ module.exports = class AntTreeDataProvider {
378391
}
379392

380393
runSelectedAntTarget () {
381-
if (selectedAntTarget && this.targetRunner) {
394+
if (selectedAntTarget) {
382395
var target = selectedAntTarget.name
383396
if (target.indexOf(' ') >= 0) {
384397
target = '"' + target + '"'
385398
}
386-
this.targetRunner.runAntTarget({name: target, sourceFile: selectedAntTarget.sourceFile})
399+
vscode.commands.executeCommand('vscode-ant.runAntTarget', {name: target, sourceFile: selectedAntTarget.sourceFile})
387400
}
388401
}
389402

src/AutoTargetRunner.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,32 @@ var extensionContext
99
var configOptions
1010

1111
module.exports = class AutoTargetRunner {
12-
constructor (context, targetRunner) {
12+
constructor (context) {
1313
extensionContext = context
1414

1515
this.autoFile = ''
1616

1717
this.buildFileDirectories = '.'
1818
this.autoFilename = 'build.auto'
1919

20-
this.targetRunner = targetRunner
2120
this.autoRunTasks = []
2221
this.autoTargets = []
2322

24-
var workspaceFolders = vscode.workspace.workspaceFolders
25-
if (workspaceFolders) {
26-
this.rootPath = workspaceFolders[0].uri.fsPath
23+
var onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this))
24+
extensionContext.subscriptions.push(onDidChangeConfiguration)
2725

28-
this.getConfigOptions()
29-
}
26+
}
27+
28+
async setWorkspaceFolder (workspaceFolder) {
29+
this.rootPath = workspaceFolder.uri.fsPath
30+
31+
await this.getConfigOptions()
32+
this.startWatching()
3033
}
3134

3235
startWatching () {
3336
this.watchAutoTargetsFile()
3437

35-
var onDidChangeConfiguration = vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this))
36-
extensionContext.subscriptions.push(onDidChangeConfiguration)
3738
}
3839

3940
onDidChangeConfiguration () {
@@ -70,7 +71,8 @@ module.exports = class AutoTargetRunner {
7071
this.autoRunTasks[targets] = setTimeout(() => {
7172
// console.log('Running entry for:' + targets)
7273
this.autoRunTasks[targets] = undefined
73-
this.targetRunner.runAntTarget({name: targets, sourceFile: sourceFile})
74+
// this.targetRunner.runAntTarget({name: targets, sourceFile: sourceFile})
75+
vscode.commands.executeCommand('vscode-ant.runAntTarget', {name: targets, sourceFile: sourceFile})
7476
}, delay, targets)
7577
}
7678

src/extension.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,24 @@ var antTreeDataProvider
1111
// your extension is activated the very first time the command is executed
1212
function activate (context) {
1313
antTargetRunner = new AntTargetRunner(context)
14-
autoTargetRunner = new AutoTargetRunner(context, antTargetRunner)
15-
autoTargetRunner.startWatching()
14+
autoTargetRunner = new AutoTargetRunner(context)
15+
// autoTargetRunner.startWatching()
1616

1717
antTreeDataProvider = new AntTreeDataProvider(context)
18-
antTreeDataProvider.targetRunner = antTargetRunner
18+
// antTreeDataProvider.targetRunner = antTargetRunner
1919

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

23+
var setRunnerWorkspaceFolder = vscode.commands.registerCommand('vscode-ant.setRunnerWorkspaceFolder', antTargetRunner.setWorkspaceFolder.bind(antTargetRunner))
24+
context.subscriptions.push(setRunnerWorkspaceFolder)
25+
26+
var setAutoWorkspaceFolder = vscode.commands.registerCommand('vscode-ant.setAutoWorkspaceFolder', autoTargetRunner.setWorkspaceFolder.bind(autoTargetRunner))
27+
context.subscriptions.push(setAutoWorkspaceFolder)
28+
29+
var changeWorkspaceFolder = vscode.commands.registerCommand('vscode-ant.changeWorkspaceFolder', antTargetRunner.setWorkspaceFolder.bind(antTargetRunner))
30+
context.subscriptions.push(changeWorkspaceFolder)
31+
2332
var runAntTarget = vscode.commands.registerCommand('vscode-ant.runAntTarget', antTargetRunner.nodeRunAntTarget.bind(antTargetRunner))
2433
context.subscriptions.push(runAntTarget)
2534

test2/build.xml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<project name="Test project name" default="default">
2+
<property environment="env"/>
3+
4+
<import file="macrodefs.xml"/>
5+
<import file="targets.xml"/>
6+
7+
<target name="default" depends="clean,compile,test,dist"/>
8+
9+
<target name="fold space" description="Fold space">
10+
<echo message="Folding space..."/>
11+
</target>
12+
13+
<target name="dlc" description="Show dlc!">
14+
<echo message="${env.DLC}"/>
15+
16+
17+
</target>
18+
19+
<target name="clean" description="Clean all the things!">
20+
<echo message="All the things are cleaned!"/>
21+
22+
23+
24+
25+
</target>
26+
27+
<target name="start_databases">
28+
<echo message="Databases are now running."/>
29+
30+
31+
32+
33+
34+
</target>
35+
36+
<target name="compile" depends="start_databases">
37+
<echo message="All the things are compiled!"/>
38+
39+
40+
41+
42+
43+
</target>
44+
45+
<target name="compile_foldertest" depends="start_databases">
46+
<echo message="All the foldertest things are compiled!"/>
47+
48+
49+
50+
51+
52+
</target>
53+
54+
<target
55+
name="test"
56+
depends="compile">
57+
<echo message="0 test have been run."/>
58+
59+
60+
61+
62+
63+
</target>
64+
65+
<target name="dist" depends="compile,test">
66+
<echo message="We shipped it!"/>
67+
68+
69+
70+
71+
72+
</target>
73+
74+
<target name="output_test">
75+
<echo message="This is an error." level="error"/>
76+
<echo message="This is an warning." level="warning"/>
77+
<echo message="This is an info." level="info"/>
78+
<echo message="This is an verbose." level="verbose"/>
79+
<echo message="This is an debug." level="debug"/>
80+
</target>
81+
82+
<target name="more targets with dependency" depends="more targets target">
83+
<echo message="This depends on a target in another file."/>
84+
</target>
85+
</project>

0 commit comments

Comments
 (0)