-
Notifications
You must be signed in to change notification settings - Fork 162
/
compiled_package.go
94 lines (73 loc) · 2.34 KB
/
compiled_package.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
package pkg
import (
"fmt"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type CompiledPackage struct {
name string
fingerprint string
osVersionSlug string
Dependencies []*CompiledPackage // todo privatize
dependencyNames []string
archivePath string
archiveSHA1 string
}
func NewCompiledPackageWithoutArchive(name, fp, osVersionSlug, sha1 string, dependencyNames []string) *CompiledPackage {
return &CompiledPackage{
name: name,
fingerprint: fp,
osVersionSlug: osVersionSlug,
archiveSHA1: sha1,
Dependencies: []*CompiledPackage{},
dependencyNames: dependencyNames,
}
}
func NewCompiledPackageWithArchive(name, fp, osVersionSlug, path, sha1 string, dependencyNames []string) *CompiledPackage {
return &CompiledPackage{
name: name,
fingerprint: fp,
osVersionSlug: osVersionSlug,
archivePath: path,
archiveSHA1: sha1,
Dependencies: []*CompiledPackage{},
dependencyNames: dependencyNames,
}
}
func (p CompiledPackage) String() string { return p.Name() }
func (p CompiledPackage) Name() string { return p.name }
func (p CompiledPackage) Fingerprint() string { return p.fingerprint }
func (p CompiledPackage) OSVersionSlug() string { return p.osVersionSlug }
func (p CompiledPackage) ArchivePath() string {
if len(p.archivePath) == 0 {
errMsg := "Internal inconsistency: Compiled package '%s/%s' does not have archive path"
panic(fmt.Sprintf(errMsg, p.name, p.fingerprint))
}
return p.archivePath
}
func (p CompiledPackage) ArchiveSHA1() string { return p.archiveSHA1 }
func (p *CompiledPackage) AttachDependencies(compiledPkgs []*CompiledPackage) error {
for _, pkgName := range p.dependencyNames {
var found bool
for _, compiledPkg := range compiledPkgs {
if compiledPkg.Name() == pkgName {
p.Dependencies = append(p.Dependencies, compiledPkg)
found = true
break
}
}
if !found {
errMsg := "Expected to find compiled package '%s' since it's a dependency of compiled package '%s'"
return bosherr.Errorf(errMsg, pkgName, p.name)
}
}
return nil
}
func (p *CompiledPackage) DependencyNames() []string { return p.dependencyNames }
func (p *CompiledPackage) Deps() []Compilable {
var coms []Compilable
for _, dep := range p.Dependencies {
coms = append(coms, dep)
}
return coms
}
func (p *CompiledPackage) IsCompiled() bool { return true }