-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathBaseConfiguration.ts
More file actions
65 lines (50 loc) · 1.65 KB
/
BaseConfiguration.ts
File metadata and controls
65 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*!
* Copyright 2018-2021 VMware, Inc.
* SPDX-License-Identifier: MIT
*/
import { MavenProfile, MavenProfilesMap } from "../maven"
import { VrealizeSettings } from "../types"
export abstract class BaseConfiguration {
vrdev: VrealizeSettings
allProfiles: MavenProfilesMap
hasActiveProfile(): boolean {
try {
return !!this.getActiveProfileImpl()
} catch (e) {
return false
}
}
get activeProfile(): MavenProfileWrapper {
return this.getActiveProfileImpl()
}
private getActiveProfileImpl(): MavenProfileWrapper {
const profileName = this.vrdev.maven.profile
if (!profileName) {
throw new Error("There is no currently active maven profile. Set the 'vrdev.maven.profile' setting")
}
if (!this.allProfiles) {
throw new Error("There are no vRO profiles in ~/.m2/settings.xml")
}
const profile = this.allProfiles[profileName]
if (!profile) {
throw new Error(`Could not find profile '${profileName}' in ~/.m2/settings.xml`)
}
return new MavenProfileWrapper(profile)
}
}
export class MavenProfileWrapper {
constructor(private profile: MavenProfile) {}
get(key: keyof MavenProfile): string {
const value = this.profile[key]
if (!value) {
throw new Error(`Missing '${key}' property in the configured maven profile.`)
}
return value
}
getOptional(key: keyof MavenProfile, defaultValue: string): string {
if (!this.profile) {
return defaultValue
}
return this.profile[key] || defaultValue
}
}