-
Notifications
You must be signed in to change notification settings - Fork 3
/
spigot_installer.go
80 lines (70 loc) · 2.24 KB
/
spigot_installer.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
package installer
import (
"context"
"os"
"os/exec"
"path/filepath"
)
type (
SpigotInstaller struct {
}
)
var _ Installer = (*SpigotInstaller)(nil)
func init() {
Installers["spigot"] = &SpigotInstaller{}
}
const SpigotBuildToolsURI = "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
func (*SpigotInstaller) Install(path, name string, target string) (installed string, err error) {
if _, err = exec.LookPath("git"); err != nil {
return
}
var javapath string
if javapath, err = lookJavaPath(); err != nil {
return
}
if path, err = filepath.Abs(path); err != nil {
return
}
foundVersion := target
if target == "" || target == "latest" || target == "latest-snapshot" {
if target == "latest-snapshot" {
loger.Info("Warn: spigot do not support snapshot version")
}
var versions VanillaVersions
loger.Info("Getting minecraft version manifest...")
if versions, err = VanillaIns.GetVersions(); err != nil {
return
}
target = versions.Latest.Release
foundVersion += "(" + target + ")"
}
buildDir := filepath.Join(os.TempDir(), "server-installer-"+PkgVersion+".bukkit-build-tools.tmp")
loger.Infof("Getting %q...", SpigotBuildToolsURI)
buildToolJar := filepath.Join(buildDir, "BuildTools.jar")
// TODO: use cached BuildTools.Jar if possible
if err = DefaultHTTPClient.Download(SpigotBuildToolsURI, buildToolJar, 0644, nil, -1,
downloadingCallback(SpigotBuildToolsURI)); err != nil {
return
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cmd := exec.CommandContext(ctx, javapath, "-jar", "BuildTools.jar", "--compile", "spigot", "--rev", target)
cmd.Dir = buildDir
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
loger.Infof("Running %q...", cmd.String())
if err = cmd.Run(); err != nil {
loger.Infof("Build failed. Build log (if exists) moved to BuildTools.log")
os.Rename(filepath.Join(buildDir, "BuildTools.log.txt"), "BuildTools.log")
return
}
installed = filepath.Join(path, name+".jar")
if err = renameIfNotExist(filepath.Join(buildDir, "spigot-"+target+".jar"), installed, 0644); err != nil {
return
}
return
}
func (r *SpigotInstaller) ListVersions(snapshot bool) (versions []string, err error) {
versions = []string{"latest"}
return
}