// Build injects a script for loading the environment. func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error { if len(fn.Environment) == 0 { return nil } fn.Log.Debug("injecting prelude") var buf bytes.Buffer file := strings.Split(fn.Handler, ".")[0] method := strings.Split(fn.Handler, ".")[1] err := prelude.Execute(&buf, struct { EnvFile string HandleFile string HandleMethod string }{ EnvFile: ".env.json", HandleFile: file, HandleMethod: method, }) if err != nil { return err } fn.Handler = "_apex_index.handle" return zip.AddBytes("_apex_index.js", buf.Bytes()) }
// Build calls mvn package, add jar contents to zipfile. func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error { if fn.Runtime != RuntimeCanonical { return nil } if fn.Environment != nil { fn.Log.Debug("creating properties file") if err := p.generatePropertiesFile(fn); err != nil { return errors.New("Can't generate properties file: " + err.Error()) } } fn.Log.Debug("creating jar") mvnCmd := exec.Command("mvn", "package", "-Djar.finalName="+targetJarFile) mvnCmd.Dir = fn.Path if err := mvnCmd.Run(); err != nil { return err } expectedJarPath := filepath.Join(fn.Path, "target", targetJarFile+".jar") if _, err := os.Stat(expectedJarPath); err != nil { return errors.New("Expected jar file not found") } fn.Log.Debug("appending compiled files") reader, err := azip.OpenReader(expectedJarPath) if err != nil { return err } defer reader.Close() for _, file := range reader.File { r, err := file.Open() if err != nil { return err } b, err := ioutil.ReadAll(r) if err != nil { return err } r.Close() zip.AddBytes(file.Name, b) } if err := p.cleanProperties(fn); err != nil { return err } return nil }
// Build adds the nodejs shim files. func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error { if fn.Shim { fn.Log.Debug("add shim") if err := zip.AddBytes("index.js", shim.MustAsset("index.js")); err != nil { return err } if err := zip.AddBytes("byline.js", shim.MustAsset("byline.js")); err != nil { return err } } return nil }
// Build adds the jar contents to zipfile. func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error { if fn.Runtime != Runtime { return nil } fn.Runtime = RuntimeCanonical fn.Log.Debugf("searching for JAR (%s) in directories: %s", jarFile, strings.Join(jarSearchPaths, ", ")) expectedJarPath := findJar(fn.Path) if expectedJarPath == "" { return errors.New("Expected jar file not found") } fn.Log.Debugf("found jar path: %s", expectedJarPath) fn.Log.Debug("appending compiled files") reader, err := azip.OpenReader(expectedJarPath) if err != nil { return err } defer reader.Close() for _, file := range reader.File { r, err := file.Open() if err != nil { return err } b, err := ioutil.ReadAll(r) if err != nil { return err } r.Close() zip.AddBytes(file.Name, b) } return nil }