-
Notifications
You must be signed in to change notification settings - Fork 0
/
libraries_types.go
61 lines (49 loc) · 1.38 KB
/
libraries_types.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
package launcher
import (
"strconv"
"strings"
"github.com/brawaru/marct/maven"
)
type Artifact struct {
Download
Path string `json:"path" validate:"required"`
}
type LibraryDownloads struct {
Artifact *Artifact `json:"artifact,omitempty"`
Classifiers map[string]*Artifact `json:"classifiers,omitempty"`
}
type ExtractOptions struct {
Exclude []string `json:"exclude,omitempty"`
}
func (e *ExtractOptions) Include(name string) bool {
if e != nil {
for _, s := range e.Exclude {
if strings.HasPrefix(name, s) {
return false
}
}
}
return true
}
type Library struct {
Downloads *LibraryDownloads `json:"downloads,omitempty"`
Coordinates maven.Coordinates `json:"name"`
URL *string `json:"url,omitempty"`
Rules Rules `json:"rules,omitempty"`
Extract *ExtractOptions `json:"extract,omitempty"`
Natives map[string]string `json:"natives,omitempty"`
}
// GetMatchingNatives returns the natives matching the current running OS and arch.
func (l *Library) GetMatchingNatives() *Artifact {
if l == nil {
panic("library is nil")
}
if l.Natives == nil || l.Downloads == nil || l.Downloads.Classifiers == nil {
return nil
}
if classifierName, has := l.Natives[currentOS()]; has {
c := strings.Replace(classifierName, "${arch}", strconv.Itoa(strconv.IntSize), 1)
return l.Downloads.Classifiers[c]
}
return nil
}