-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.go
86 lines (74 loc) · 2.07 KB
/
library.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
package intellij
import (
"encoding/xml"
"io"
"github.com/thought-machine/please/src/core"
)
type libraryComponent struct {
XMLName xml.Name `xml:"component"`
Name string `xml:"name,attr"`
Library Library `xml:"library"`
}
// Content is a simple wrapper for a URL.
type Content struct {
XMLName xml.Name `xml:"root"`
ContentURL string `xml:"url,attr"`
}
// Library represents an IntelliJ project library, which usually consists of a jar containing classes, but can
// also contain javadocs and sources.
type Library struct {
XMLName xml.Name `xml:"library"`
Name string `xml:"name,attr"`
ClassPaths []Content `xml:"CLASSES>root"`
JavadocPaths []Content `xml:"JAVADOC>root"`
SourcePaths []Content `xml:"SOURCES>root"`
}
func newLibrary(graph *core.BuildGraph, target *core.BuildTarget) Library {
classes := []Content{}
javadocs := []Content{}
sources := []Content{}
for _, dep := range target.Sources {
label := dep.Label()
if label != nil {
depTarget := graph.TargetOrDie(*label)
if depTarget.HasLabel("maven-sources") {
for _, o := range depTarget.Outputs() {
sources = append(sources, Content{
ContentURL: "jar://$PROJECT_DIR$/../../" + depTarget.OutDir() + "/" + o + "!/",
})
}
}
if depTarget.HasLabel("maven-classes") {
for _, o := range depTarget.Outputs() {
classes = append(classes, Content{
ContentURL: "jar://$PROJECT_DIR$/../../" + depTarget.OutDir() + "/" + o + "!/",
})
}
}
if depTarget.HasLabel("maven-javadocs") {
for _, o := range depTarget.Outputs() {
javadocs = append(javadocs, Content{
ContentURL: "jar://$PROJECT_DIR$/../../" + depTarget.OutDir() + "/" + o + "!/",
})
}
}
}
}
library := Library{
Name: libraryName(target),
SourcePaths: sources,
ClassPaths: classes,
JavadocPaths: javadocs,
}
return library
}
func (library *Library) toXML(writer io.Writer) {
table := libraryComponent{
Name: "libraryTable",
Library: *library,
}
contents, err := xml.MarshalIndent(table, "", " ")
if err == nil {
writer.Write(contents)
}
}