/
feature.go
175 lines (142 loc) · 4.33 KB
/
feature.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package coremgt
import (
"fmt"
"jplugins/simplefile"
"path"
"strings"
"github.com/forj-oss/go-git"
goversion "github.com/hashicorp/go-version"
)
const (
featureType = "feature"
)
// Feature describe details on Feature.
type Feature struct {
Version string
name string
rules map[string]goversion.Constraints
}
// NewFeature return a feature object
func NewFeature() (ret *Feature) {
ret = new(Feature)
return
}
// String return the string representation of the plugin
func (p *Feature) String() string {
if p == nil {
return "nil"
}
ruleShown := make([]string, len(p.rules))
index := 0
for _, rule := range p.rules {
ruleShown[index] = rule.String()
index++
}
return fmt.Sprintf("%s:%s %s (constraints: %s)", featureType, p.name, p.Version, strings.Join(ruleShown, ", "))
}
// GetVersion return the plugin Version struct.
func (p *Feature) GetVersion() (_ VersionStruct, _ error) {
return
}
// SetFrom set data from an array of fields
func (p *Feature) SetFrom(fields ...string) (err error) {
fieldsSize := len(fields)
if fieldsSize < 2 {
err = fmt.Errorf("Invalid data type. Requires type (field 1) as '%s' and feature name (field 2)", featureType)
return
}
if fields[0] != featureType {
err = fmt.Errorf("Invalid data type. Must be '%s'", featureType)
return
}
p.name = fields[1]
return
}
// CompleteFromContext nothing to complete.
func (p *Feature) CompleteFromContext(_ *ElementsType) (_ error) {
return
}
// GetType return the internal type string
func (p *Feature) GetType() string {
return featureType
}
// Name return the Name property
func (p *Feature) Name() string {
return p.name
}
// ChainElement load the feature details (groovy and plugins)
func (p *Feature) ChainElement(context *ElementsType) (ret *ElementsType, _ error) {
if p == nil || context == nil {
return
}
ret = NewElementsType()
ret.AddSupport(pluginType, groovyType)
ret.AddSupportContext(groovyType, "featureName", p.Name())
ret.SetFeaturesPath(context.repoPath)
ret.noRecursiveChain()
ret.SetRepository(context.ref)
if !context.useLocal {
return nil, fmt.Errorf("Git clone of repository not currently implemented. Do git task and use --features-repo-path")
}
if err := git.RunInPath(context.repoPath, func() error {
if git.Do("rev-parse", "--git-dir") != 0 {
return fmt.Errorf("Not a valid GIT repository")
}
return nil
}); err != nil {
return nil, fmt.Errorf("Issue with '%s', %s", context.repoPath, err)
}
featureFile := path.Join(context.repoPath, p.Name(), p.Name()+".desc")
simpleFile := simplefile.NewSimpleFile(featureFile, 3)
err := simpleFile.Read(":", func(fields []string) (err error) {
_, err = ret.Add(fields...)
return
})
if err != nil {
return nil, fmt.Errorf("Unable to read feature file '%s'. %s", featureFile, err)
}
return
}
// Merge execute a merge between 2 features and keep the one corresponding to the constraint given
// It is based on 3 policies: choose oldest, keep existing and choose newest
func (p *Feature) Merge(_ *ElementsType, _ Element, _ int) (_ bool, _ error) {
return
}
// IsFixed indicates if the plugin version is fixed.
func (p *Feature) IsFixed() (_ bool) {
return
}
// GetParents return the list of features which depends on this feature.
func (p *Feature) GetParents() (_ Elements) {
return
}
// GetDependencies return the list of features depedencies required by this feature.
func (p *Feature) GetDependencies() (_ Elements) {
return
}
// GetDependenciesFromContext return the list of features depedencies required by this feature.
func (p *Feature) GetDependenciesFromContext(*ElementsType) (_ Elements) {
return
}
// SetVersionConstraintFromDepConstraint add a constraint to match the
// dependency version constraints
func (p *Feature) SetVersionConstraintFromDepConstraint(*ElementsType, Element) (_ error) {
return
}
// IsVersionCandidate return true systematically
func (p *Feature) IsVersionCandidate(version *goversion.Version) bool {
return true
}
func (p *Feature) RemoveDependencyTo(depElement Element) {
}
func (p *Feature) AddDependencyTo(depElement Element) {
}
func (p *Feature) DefineLatestPossibleVersion(context *ElementsType) (_ error) {
return
}
func (p *Feature) AsNewPluginsStatusDetails(context *ElementsType) (sd *pluginsStatusDetails) {
return
}
func (p *Feature) AsNewGrooviesStatusDetails(context *ElementsType) (sd *GroovyStatusDetails) {
return
}