-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathecosystem.go
More file actions
67 lines (59 loc) · 1.66 KB
/
ecosystem.go
File metadata and controls
67 lines (59 loc) · 1.66 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
66
67
package runtime
import (
"github.com/ActiveState/cli/pkg/buildplan"
ecosys "github.com/ActiveState/cli/pkg/runtime/ecosystem"
)
type ecosystem interface {
Init(runtimePath string, buildplan *buildplan.BuildPlan) error
Namespaces() []string
Add(artifact *buildplan.Artifact, artifactSrcPath string) ([]string, error)
Remove(artifact *buildplan.Artifact) error
Apply() error
}
var availableEcosystems []func() ecosystem
func init() {
availableEcosystems = []func() ecosystem{
func() ecosystem { return &ecosys.Java{} },
func() ecosystem { return &ecosys.JavaScript{} },
func() ecosystem { return &ecosys.Rust{} },
func() ecosystem { return &ecosys.DotNet{} },
func() ecosystem { return &ecosys.Golang{} },
}
}
func artifactMatchesEcosystem(a *buildplan.Artifact, e ecosystem) bool {
for _, namespace := range e.Namespaces() {
for _, i := range a.Ingredients {
if i.Namespace == namespace {
return true
}
}
}
return false
}
func namespacesMatchesEcosystem(namespaces []string, e ecosystem) bool {
for _, namespace := range e.Namespaces() {
for _, n := range namespaces {
if n == namespace {
return true
}
}
}
return false
}
func filterEcosystemMatchingArtifact(artifact *buildplan.Artifact, ecosystems []ecosystem) ecosystem {
for _, ecosystem := range ecosystems {
if artifactMatchesEcosystem(artifact, ecosystem) {
return ecosystem
}
}
return nil
}
func filterEcosystemsMatchingNamespaces(ecosystems []ecosystem, namespaces []string) []ecosystem {
result := []ecosystem{}
for _, ecosystem := range ecosystems {
if namespacesMatchesEcosystem(namespaces, ecosystem) {
result = append(result, ecosystem)
}
}
return result
}