-
Notifications
You must be signed in to change notification settings - Fork 1
/
factory.go
117 lines (96 loc) · 2.59 KB
/
factory.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
package mgr
import (
"fmt"
"github.com/packagrio/go-common/errors"
"github.com/packagrio/go-common/pipeline"
"github.com/packagrio/publishr/pkg/config"
"net/http"
)
func Create(mgrType string, pipelineData *pipeline.Data, config config.Interface, client *http.Client) (Interface, error) {
var mgr Interface
switch mgrType {
//empty/generic package manager. Noop.
case "generic":
mgr = new(mgrGeneric)
//chef dependency managers
case "berkshelf":
mgr = new(mgrChefBerkshelf)
//golang dependency managers
case "dep":
mgr = new(mgrGolangDep)
case "glide":
mgr = new(mgrGolangGlide)
case "mod":
mgr = new(mgrGolangMod)
//node dependency managers
case "npm":
mgr = new(mgrNodeNpm)
case "yarn":
mgr = new(mgrNodeYarn)
//python dependency managers
case "pip":
mgr = new(mgrPythonPip)
//ruby dependency managers
case "bundler":
mgr = new(mgrRubyBundler)
default:
return nil, errors.ScmUnspecifiedError(fmt.Sprintf("Unknown Packager Manager Type: %s", mgrType))
}
if err := mgr.Init(pipelineData, config, client); err != nil {
return nil, err
}
return mgr, nil
}
func Detect(packageType string, pipelineData *pipeline.Data, config config.Interface, client *http.Client) (Interface, error) {
var mgrType string
mgrType = "unknown"
switch packageType {
//chef dependency managers
case "chef":
if DetectChefBerkshelf(pipelineData, config, client) {
mgrType = "berkshelf"
} else { //default
mgrType = "berkshelf"
}
//golang dependency managers
case "golang":
if DetectGolangDep(pipelineData, config, client) {
mgrType = "dep"
} else if DetectGolangGlide(pipelineData, config, client) {
mgrType = "glide"
} else if DetectGolangMod(pipelineData, config, client) {
mgrType = "mod"
} else { //default
mgrType = "mod"
}
//node dependency managers
case "node":
if DetectNodeNpm(pipelineData, config, client) {
mgrType = "npm"
} else if DetectNodeYarn(pipelineData, config, client) {
mgrType = "yarn"
} else { //default
mgrType = "npm"
}
//python dependency managers
case "python":
if DetectPythonPip(pipelineData, config, client) {
mgrType = "pip"
} else { //default
mgrType = "pip"
}
//ruby dependency managers
case "ruby":
if DetectRubyBundler(pipelineData, config, client) {
mgrType = "bundler"
} else { //default
mgrType = "bundler"
}
//empty/generic package manager. Noop.
case "generic":
mgrType = "generic"
default:
return nil, errors.MgrUnspecifiedError(fmt.Sprintf("Unknown Package Manager for Package Type (%s): %s", packageType, mgrType))
}
return Create(mgrType, pipelineData, config, client)
}