Supply installs the memory calculator
()
| 51 | |
| 52 | // Supply installs the memory calculator |
| 53 | func (m *MemoryCalculator) Supply() error { |
| 54 | // Get memory calculator version from manifest |
| 55 | dep, err := m.ctx.Manifest.DefaultVersion("memory-calculator") |
| 56 | if err != nil { |
| 57 | return fmt.Errorf("unable to determine memory calculator version: %w", err) |
| 58 | } |
| 59 | |
| 60 | m.version = dep.Version |
| 61 | m.ctx.Log.Info("Installing Memory Calculator (%s)", m.version) |
| 62 | |
| 63 | m.LoadConfig() |
| 64 | |
| 65 | // Create bin directory |
| 66 | binDir := filepath.Join(m.jreDir, "bin") |
| 67 | if err := os.MkdirAll(binDir, 0755); err != nil { |
| 68 | return fmt.Errorf("failed to create bin directory: %w", err) |
| 69 | } |
| 70 | |
| 71 | // Download to temporary location (it's a tar.gz) |
| 72 | tempDir := filepath.Join(m.ctx.Stager.DepDir(), "tmp", "memory-calculator") |
| 73 | if err := os.MkdirAll(tempDir, 0755); err != nil { |
| 74 | return fmt.Errorf("failed to create temp directory: %w", err) |
| 75 | } |
| 76 | |
| 77 | // Install (extract) the tarball to temp directory |
| 78 | if err := m.ctx.Installer.InstallDependency(dep, tempDir); err != nil { |
| 79 | return fmt.Errorf("failed to install memory calculator: %w", err) |
| 80 | } |
| 81 | |
| 82 | // Find the extracted binary (try various possible names) |
| 83 | possibleNames := []string{ |
| 84 | "java-buildpack-memory-calculator", // v4.x format |
| 85 | "memory-calculator-linux", // older format |
| 86 | "memory-calculator-darwin", // darwin for local testing |
| 87 | } |
| 88 | |
| 89 | var calculatorBinary string |
| 90 | for _, name := range possibleNames { |
| 91 | testPath := filepath.Join(tempDir, name) |
| 92 | if _, err := os.Stat(testPath); err == nil { |
| 93 | calculatorBinary = testPath |
| 94 | break |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if calculatorBinary == "" { |
| 99 | return fmt.Errorf("could not find memory calculator binary in %s", tempDir) |
| 100 | } |
| 101 | |
| 102 | // Move to final location with version |
| 103 | finalPath := filepath.Join(binDir, fmt.Sprintf("java-buildpack-memory-calculator-%s", m.version)) |
| 104 | if err := os.Rename(calculatorBinary, finalPath); err != nil { |
| 105 | // Try copy if rename fails (cross-device link) |
| 106 | if err := copyFile(calculatorBinary, finalPath); err != nil { |
| 107 | return fmt.Errorf("failed to move memory calculator: %w", err) |
| 108 | } |
| 109 | } |
| 110 |
nothing calls this directly
no test coverage detected