MCPcopy
hub / github.com/perkeep/perkeep / main

Function main

dev/update_closure_compiler.go:42–139  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40var rgxVersion = regexp.MustCompile(`.*Version: (.*) \(revision.*`)
41
42func main() {
43
44 // check JRE presence
45 _, err := exec.LookPath("java")
46 if err != nil {
47 log.Fatal("Didn't find 'java' in $PATH. The Java Runtime Environment is needed to run the closure compiler.\n")
48 }
49
50 srcRoot, err := osutil.PkSourceRoot()
51 if err != nil {
52 log.Fatalf("source root folder not found: %v", err)
53 }
54 destDir := filepath.Join(srcRoot, "tmp", "closure-compiler")
55 // check if compiler already exists
56 jarFile := filepath.Join(destDir, "compiler.jar")
57 _, err = os.Stat(jarFile)
58 if err == nil {
59 // if compiler exists, check version
60 cmd := exec.Command("java", "-jar", jarFile, "--version", "--help", "2>&1")
61 output, _ := cmd.CombinedOutput()
62 m := rgxVersion.FindStringSubmatch(string(output))
63 if m == nil {
64 log.Fatalf("Could not find compiler version in %q", output)
65 }
66 if m[1] == compilerVersion {
67 log.Printf("compiler already at version %v , nothing to do.", compilerVersion)
68 os.Exit(0)
69 }
70 if err := os.Remove(jarFile); err != nil {
71 log.Fatalf("Could not remove %v: %v", jarFile, err)
72 }
73 } else {
74 if !os.IsNotExist(err) {
75 log.Fatalf("Could not stat %v: %v", jarFile, err)
76 }
77 }
78
79 // otherwise, download compiler
80 log.Printf("Getting closure compiler version %s.\n", compilerVersion)
81 if err := os.MkdirAll(destDir, 0755); err != nil {
82 log.Fatal(err)
83 }
84 if err := os.Chdir(destDir); err != nil {
85 log.Fatal(err)
86 }
87 zipFilename := "compiler-" + compilerVersion + ".zip"
88 compilerURL := compilerDirURL + zipFilename
89 resp, err := http.Get(compilerURL)
90 if err != nil {
91 log.Fatal(err)
92 }
93 defer resp.Body.Close()
94 f, err := os.Create(zipFilename)
95 if err != nil {
96 log.Fatal(err)
97 }
98 if _, err := io.Copy(f, resp.Body); err != nil {
99 log.Fatal(err)

Callers

nothing calls this directly

Calls 13

PkSourceRootFunction · 0.92
FatalMethod · 0.80
PrintfMethod · 0.80
CreateMethod · 0.80
LookPathMethod · 0.65
FatalfMethod · 0.65
StatMethod · 0.65
CommandMethod · 0.65
RemoveMethod · 0.65
MkdirAllMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected