Skip to content

Commit e1c97fe

Browse files
author
James Pogran
authored
Merge pull request #491 from glennsarti/use-alternate-puppet-version
(GH-489) Use alternate puppet version
2 parents 5c8150f + a88fe54 commit e1c97fe

21 files changed

+272
-43
lines changed

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
sudo: false
33
language: cpp
44

5+
# Must be Trusty!
6+
# For some reason Xenial fails with exit code 1
7+
dist: trusty
8+
59
os:
610
- linux
711
- osx
@@ -24,6 +28,21 @@ before_install: true
2428

2529
install:
2630
- "export BUILD_VERSION=0.7.0-travis.$TRAVIS_BUILD_NUMBER"
31+
# Install PDK for Ubuntu 14.04 (Trusty)
32+
- if [ $TRAVIS_OS_NAME == "linux" ]; then
33+
wget https://apt.puppetlabs.com/puppet6-release-trusty.deb;
34+
sudo dpkg -i puppet6-release-trusty.deb;
35+
sudo apt-get update;
36+
sudo apt-get install pdk;
37+
pdk --version;
38+
fi
39+
# Install PDK for Mac (Disable homebrew auto-update)
40+
# Uses an absolute path due to shell needing to be reloaded.
41+
- if [ $TRAVIS_OS_NAME == "osx" ]; then
42+
export HOMEBREW_NO_AUTO_UPDATE=1;
43+
brew cask install puppetlabs/puppet/pdk;
44+
/opt/puppetlabs/pdk/bin/pdk --version;
45+
fi
2746
- if [ "$nodejs_version" != "" ]; then
2847
git clone --depth 1 https://github.com/creationix/nvm.git ./.nvm;
2948
source ./.nvm/nvm.sh;
@@ -41,6 +60,7 @@ install:
4160
npm install -g vsce --silent;
4261
npm install --silent;
4362
node node_modules/gulp/bin/gulp.js bump --version $BUILD_VERSION;
63+
node node_modules/gulp/bin/gulp.js initial;
4464
fi
4565

4666
script:

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- [Live Workspace Intellisense](#live-workspace-intellisense)
2525
- [Puppet Commands](#puppet-commands)
2626
- [Puppet Resource](#puppet-resource)
27-
- [Puppet Node Graph](#puppet-node-graph)
27+
- [Puppet Node Graph](#puppet-node-graph-preview)
2828
- [Puppet Development Kit Support](#puppet-development-kit-support)
2929
- [PDK Supported Versions](#pdk-supported-versions)
3030
- [PDK New Module](#pdk-new-module)
@@ -377,6 +377,18 @@ To use a custom install path for the PDK, set the `puppet.installDirectory` sett
377377
}
378378
```
379379

380+
The PDK has many versions of Puppet which can be used. Set the `puppet.editorService.puppet.version` setting to the version you would like to use, for example, if you wanted to use version 5.4.0, then set the configuration to:
381+
382+
```json
383+
{
384+
"puppet.editorService.puppet.version":"5.4.0"
385+
}
386+
```
387+
388+
You can also change the version from the status bar in Visual Studio Code. Click on the Puppet version text in the status bar and then select which Puppet version you would like to use. Note that this will require Visual Studio Code to be restarted to take effect.
389+
390+
![changing_puppet_version](https://raw.githubusercontent.com/lingua-pupuli/puppet-vscode/master/docs/assets/change-puppet-version.gif)
391+
380392
### Configure extension to use Puppet-Agent
381393

382394
To ensure that the extension uses the Puppet-Agent, set the `puppet.installType` setting to the `puppet` value like so:

appveyor.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ install:
3636
3737
Write-Host "Set the package.json version..."
3838
& node node_modules\gulp\bin\gulp.js bump --specific $ENV:APPVEYOR_BUILD_VERSION
39+
40+
Write-Host "Setting up initial configuration..."
41+
& node node_modules\gulp\bin\gulp.js initial
3942
}
43+
- cmd: choco install pdk
44+
- ps: pdk --version
4045

4146
build_script:
4247
- cmd: npm test --silent
313 KB
Loading

editor-components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"editor-services": {
3-
"release": "0.18.0"
3+
"release": "0.19.0"
44
},
55
"editor-syntax": {
66
"release": "1.3.0"

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@
365365
"default": "",
366366
"description": "The Puppet cache directory. See https://puppet.com/docs/puppet/latest/dirs_vardir.html for more information"
367367
},
368+
"puppet.editorService.puppet.version": {
369+
"type": "string",
370+
"default": "",
371+
"description": "The version of Puppet to use. For example '5.4.0'. This is generally only applicable when using the PDK installation type. If Puppet Editor Services is unable to use this version, it will default to the latest available version of Puppet."
372+
},
368373
"puppet.editorService.tcp.address": {
369374
"type": "string",
370375
"description": "The IP address or hostname of the remote Puppet Editor Service to connect to, for example 'computer.domain' or '192.168.0.1'. Only applicable when the editorService.protocol is set to tcp"

src/PuppetConnectionMenuItem.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/configuration.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ interface IRubyConfiguration {
3333
readonly pdkGemDir:string;
3434
readonly pdkRubyDir:string;
3535
readonly pdkRubyBinDir:string;
36-
readonly pdkGemVerDir:string;
36+
readonly pdkGemVerDir:string;
37+
readonly pdkPuppetVersions: string[];
3738
}
3839

3940
/** The IConnectionConfiguration interface describes the connection used to
@@ -68,11 +69,20 @@ export class AggregateConfiguration implements IAggregateConfiguration {
6869
const rubyDir = this.calculateRubyDir(puppetBaseDir);
6970

7071
let pdkInstance: pdk.IPDKRubyInstance = pdk.emptyPDKInstance();
72+
let puppetVersions: string[] = [];
7173
if (settings.installType === PuppetInstallType.PDK) {
72-
const result = pdk.pdkInstances(puppetBaseDir).latest;
74+
const pdkInfo = pdk.pdkInstances(puppetBaseDir);
75+
let result: pdk.IPDKRubyInstance;
76+
if (settings.editorService !== undefined && settings.editorService.puppet !== undefined && settings.editorService.puppet.version !== undefined) {
77+
result = pdkInfo.InstanceForPuppetVersion(settings.editorService.puppet.version);
78+
}
79+
// If we can't find the PDK instance from the puppet version or it wasn't defined, assume the latest.
80+
if (result === undefined) { result = pdkInfo.latest; }
81+
7382
// An undefined instance means that either PDK isn't installed or that
7483
// the requested version doesn't exist.
7584
if (result !== undefined) { pdkInstance = result; }
85+
puppetVersions = pdkInfo.allPuppetVersions;
7686
}
7787

7888
this.ruby = {
@@ -91,7 +101,8 @@ export class AggregateConfiguration implements IAggregateConfiguration {
91101
pdkGemDir: pdkInstance.gemDir,
92102
pdkRubyDir: pdkInstance.rubyDir,
93103
pdkRubyBinDir: pdkInstance.rubyBinDir,
94-
pdkGemVerDir: pdkInstance.gemVerDir
104+
pdkGemVerDir: pdkInstance.gemVerDir,
105+
pdkPuppetVersions: puppetVersions,
95106
};
96107

97108
this.connection = {

src/configuration/pdkResolver.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import * as path from 'path';
44
export interface IPDKRubyInstances {
55
pdkDirectory: string;
66
instances: IPDKRubyInstance[];
7+
allPuppetVersions: string[];
78
latest: IPDKRubyInstance;
9+
10+
/**
11+
* Finds the first PDK Instance that has Puppet version `puppetVersion`
12+
* @param puppetVersion The puppet version string to search for
13+
* @returns IPDKRubyInstance or undefined
14+
*/
15+
InstanceForPuppetVersion(puppetVersion: string): IPDKRubyInstance;
816
}
917

1018
export interface IPDKRubyInstance {
@@ -58,6 +66,7 @@ export function emptyPDKInstance(): IPDKRubyInstance {
5866
class PDKRubyInstances implements IPDKRubyInstances {
5967
pdkDirectory: string;
6068
private rubyInstances: IPDKRubyInstance[] = undefined;
69+
private puppetVersions: string[] = undefined;
6170

6271
constructor(
6372
pdkRootDirectory: string
@@ -82,6 +91,25 @@ class PDKRubyInstances implements IPDKRubyInstances {
8291
return this.rubyInstances;
8392
}
8493

94+
get allPuppetVersions(): string[] {
95+
if (this.puppetVersions !== undefined) { return this.puppetVersions; }
96+
this.puppetVersions = [];
97+
// This searching method isn't the most performant but as the list will probably
98+
// be very small (< 20 items) it's not a big deal and is cached anyway
99+
this.instances.forEach( (instance) => {
100+
instance.puppetVersions.forEach ( (puppetVersion) => {
101+
if (this.puppetVersions.indexOf(puppetVersion) === -1) { this.puppetVersions.push(puppetVersion); }
102+
});
103+
});
104+
return this.puppetVersions;
105+
}
106+
107+
public InstanceForPuppetVersion(puppetVersion: string): IPDKRubyInstance {
108+
return this.instances.find( (instance) => {
109+
return instance.puppetVersions.includes(puppetVersion);
110+
});
111+
}
112+
85113
// Override toString to make it look pretty
86114
toString(): string {
87115
return "[" +
@@ -147,7 +175,7 @@ class PDKRubyInstance implements IPDKRubyInstance {
147175
// the gem cache is just as easy and doesn't need to spawn a ruby process per
148176
// ruby version.
149177
fs.readdirSync(gemdir).forEach( (item) => {
150-
let pathMatch = item.match(/^puppet-(\d+\.\d+\.\d+)-/);
178+
let pathMatch = item.match(/^puppet-(\d+\.\d+\.\d+)(?:(-|$))/);
151179
if (pathMatch !== null) { this._puppetVersions.push(pathMatch[1]); }
152180
});
153181

src/extension.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ import { BoltFeature } from './feature/BoltFeature';
88
import { DebuggingFeature } from './feature/DebuggingFeature';
99
import { FormatDocumentFeature } from './feature/FormatDocumentFeature';
1010
import { NodeGraphFeature } from './feature/NodeGraphFeature';
11+
import { UpdateConfigurationFeature } from './feature/UpdateConfigurationFeature';
1112
import { PDKFeature } from './feature/PDKFeature';
1213
import { PuppetResourceFeature } from './feature/PuppetResourceFeature';
14+
import { PuppetStatusBarFeature } from './feature/PuppetStatusBarFeature';
1315
import { ConnectionHandler } from './handler';
1416
import { DockerConnectionHandler } from './handlers/docker';
1517
import { StdioConnectionHandler } from './handlers/stdio';
1618
import { TcpConnectionHandler } from './handlers/tcp';
1719
import { ConnectionType, ProtocolType } from './settings';
1820
import { ILogger } from './logging';
1921
import { OutputChannelLogger } from './logging/outputchannel';
20-
import { PuppetStatusBar } from './PuppetStatusBar';
22+
//import { PuppetStatusBar } from './PuppetStatusBar';
2123
import { legacySettings, SettingsFromWorkspace } from './settings';
2224
import { Reporter, reporter } from './telemetry/telemetry';
2325

@@ -28,7 +30,7 @@ const debugType = 'Puppet'; // don't change this
2830
let extContext: vscode.ExtensionContext;
2931
let connectionHandler: ConnectionHandler;
3032
let logger: OutputChannelLogger;
31-
let statusBar: PuppetStatusBar;
33+
//let statusBar: PuppetStatusBar;
3234
let configSettings: IAggregateConfiguration;
3335
let extensionFeatures: IFeature[] = [];
3436

@@ -48,12 +50,14 @@ export function activate(context: vscode.ExtensionContext) {
4850
});
4951
configSettings = CreateAggregrateConfiguration(settings);
5052

51-
logger = new OutputChannelLogger(configSettings.workspace.editorService.loglevel);
52-
statusBar = new PuppetStatusBar([puppetLangID, puppetFileLangID], context, logger);
53+
logger = new OutputChannelLogger(configSettings.workspace.editorService.loglevel);
54+
const statusBar = new PuppetStatusBarFeature([puppetLangID, puppetFileLangID], configSettings, logger, context);
5355

5456
extensionFeatures = [
5557
new PDKFeature(extContext, logger),
5658
new BoltFeature(extContext),
59+
new UpdateConfigurationFeature(logger, extContext),
60+
statusBar
5761
];
5862

5963
if (configSettings.workspace.editorService.enable === false){

0 commit comments

Comments
 (0)