Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pkg/java/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ func (o *Opts) download() error {
log.Debugf("existing JDK '%s' is up-to-date", check.Locked.Source)
return nil
}
log.Infof("preparing new JDK at dir '%s'", o.jdkDir())
if err = o.prepare(err); err != nil {
return err
}
if err := lock.Lock(); err != nil {
return err
}
log.Infof("prepared new JDK at dir '%s'", o.jdkDir())
return nil
}

func (o *Opts) prepare(err error) error {
if err := pathx.DeleteIfExists(o.jdkDir()); err != nil {
return err
}
url := o.DownloadURL
for search, replace := range o.DownloadURLReplacements {
url = strings.ReplaceAll(url, search, replace)
Expand All @@ -94,10 +109,6 @@ func (o *Opts) download() error {
if _, err = filex.UnarchiveWithChanged(archiveFile, o.jdkDir()); err != nil {
return err
}
if err := lock.Lock(); err != nil {
return err
}
log.Infof("unarchived new JDK at dir '%s'", o.jdkDir())
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/oak_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func (or OakRun) JarFile() string {
}

func (or OakRun) prepare() error {
if err := pathx.DeleteIfExists(or.Dir()); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without it when updating e.g

    #url: "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.18%2B10/OpenJDK11U-jdk_[[.Arch]]_[[.Os]]_hotspot_11.0.18_10.[[.ArchiveExt]]"
    url: "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u432-b06/OpenJDK8U-jdk_[[.Arch]]_[[.Os]]_hotspot_8u432b06.[[.ArchiveExt]]"
  

then old Java was in use because previously unpacked was still there

return err
}
jarFile := or.JarFile()
log.Infof("downloading Oak Run JAR from URL '%s' to file '%s'", or.DownloadURL, jarFile)
if err := httpx.DownloadOnce(or.DownloadURL, jarFile); err != nil {
Expand Down
9 changes: 3 additions & 6 deletions pkg/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ func (s SDK) Prepare() error {
}

func (s SDK) prepare(zipFile string) error {
err := pathx.Delete(s.Dir())
if err != nil {
if err := pathx.DeleteIfExists(s.Dir()); err != nil {
return err
}
err = s.unpackSdk(zipFile)
if err != nil {
if err := s.unpackSdk(zipFile); err != nil {
return err
}
err = s.unpackDispatcher()
if err != nil {
if err := s.unpackDispatcher(); err != nil {
return err
}
return nil
Expand Down
13 changes: 8 additions & 5 deletions pkg/vault_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (v VaultCli) lock() osx.Lock[VaultCliLock] {
return osx.NewLock(v.dir()+"/lock/create.yml", func() (VaultCliLock, error) { return VaultCliLock{DownloadURL: v.DownloadURL}, nil })
}

func (v VaultCli) prepare() error {
func (v VaultCli) Prepare() error {
lock := v.lock()
check, err := lock.State()
if err != nil {
Expand All @@ -60,7 +60,7 @@ func (v VaultCli) prepare() error {
return nil
}
log.Infof("preparing new Vault '%s'", v.DownloadURL)
err = v.install()
err = v.prepare()
if err != nil {
return err
}
Expand All @@ -77,7 +77,10 @@ func (v VaultCli) archiveFile() string {
return pathx.Canonical(fmt.Sprintf("%s/%s", v.dir(), filepath.Base(v.DownloadURL)))
}

func (v VaultCli) install() error {
func (v VaultCli) prepare() error {
if err := pathx.DeleteIfExists(v.dir()); err != nil {
return err
}
archiveFile := v.archiveFile()
log.Infof("downloading Vault from URL '%s' to file '%s'", v.DownloadURL, archiveFile)
if err := httpx.DownloadOnce(v.DownloadURL, archiveFile); err != nil {
Expand All @@ -94,8 +97,8 @@ func (v VaultCli) install() error {
}

func (v VaultCli) CommandShell(args []string) error {
if err := v.prepare(); err != nil {
return fmt.Errorf("cannot run Vault command: %w", err)
if err := v.Prepare(); err != nil {
return fmt.Errorf("cannot prepare Vault before running command: %w", err)
}
cmd := execx.CommandShell(args)
cmd.Dir = v.execDir()
Expand Down