MCPcopy Create free account
hub / github.com/cloudfoundry/java-buildpack / findJavaHome

Method findJavaHome

src/java/jres/base_jre.go:208–250  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

206}
207
208func (b *BaseJRE) findJavaHome() (string, error) {
209 entries, err := os.ReadDir(b.jreDir)
210 if err != nil {
211 return "", fmt.Errorf("failed to read JRE directory: %w", err)
212 }
213
214 for _, entry := range entries {
215 if !entry.IsDir() {
216 continue
217 }
218
219 name := entry.Name()
220 matches := false
221 for _, prefix := range b.dirPrefixes {
222 if strings.HasPrefix(name, prefix) {
223 matches = true
224 break
225 }
226 }
227 if !matches {
228 for _, exact := range b.dirExacts {
229 if name == exact {
230 matches = true
231 break
232 }
233 }
234 }
235 if !matches {
236 continue
237 }
238
239 path := filepath.Join(b.jreDir, name)
240 if _, err := os.Stat(filepath.Join(path, "bin", "java")); err == nil {
241 return path, nil
242 }
243 }
244
245 if _, err := os.Stat(filepath.Join(b.jreDir, "bin", "java")); err == nil {
246 return b.jreDir, nil
247 }
248
249 return "", fmt.Errorf("could not find valid JAVA_HOME in %s", b.jreDir)
250}
251
252func (b *BaseJRE) writeProfileDScript() error {
253 return WriteJavaHomeProfileD(b.ctx, b.jreDir, b.javaHome)

Callers 2

SupplyMethod · 0.95
FinalizeMethod · 0.95

Calls 1

NameMethod · 0.65

Tested by

no test coverage detected