Skip to content

Commit

Permalink
Allow to force an installation path for java using option `ìnstallPat…
Browse files Browse the repository at this point in the history
…h` (#81)

* Allow to force an installation path for java using option `ìnstallPath`

* typo

* [MegaLinter] Apply linters fixes

---------

Co-authored-by: nvuillam <[email protected]>
  • Loading branch information
nvuillam and nvuillam authored Aug 29, 2024
1 parent 3524e56 commit b1ea860
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased] (beta, main branch content)

## [v1.4.0] - 2024-08-30

- Allow to force an installation path for java using option `installPath`

## [v1.3.0] - 2024-08-20

- Add [github-dependents-info](https://github.com/nvuillam/github-dependents-info)
Expand Down
11 changes: 11 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Installs a JRE copy for the app
| [options.type] | <code>string</code> | <code>&quot;jre&quot;</code> | Binary Type (`jre`/`jdk`) |
| [options.heap_size] | <code>string</code> | | Heap Size (`normal`/`large`) |
| [options.vendor] | <code>string</code> | | defaults to adoptopenjdk (`adoptopenjdk`/`eclipse`) |
| [options.installPath] | <code>string</code> | | Where to install java (default process.cwd()) |


**Example**
```js
Expand All @@ -62,4 +64,13 @@ njre.install(11, { os: 'aix', arch: 'ppc64', openjdk_impl: 'openj9' })
.catch(err => {
// Handle the error
})

// or custom ones
njre.install(17, { os: 'aix', arch: 'amd64', openjdk_impl: 'openj9', installPath: "/home/tmp/java" })
.then(dir => {
// Do stuff
})
.catch(err => {
// Handle the error
})
```
7 changes: 4 additions & 3 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ function verify(file) {
});
}

function move(file) {
function move(file, installPath) {
return new Promise((resolve, reject) => {
const newFile = path.join(
path.dirname(require.main.filename),
path.dirname(installPath),
file.split(path.sep).slice(-1)[0],
);

Expand Down Expand Up @@ -193,6 +193,7 @@ function install(version = 8, options = {}) {
type = "jre",
heap_size = "normal",
vendor = "adoptopenjdk",
installPath = require?.main?.filename || process.cwd(),
} = options;

options = { ...options, openjdk_impl, release, type, heap_size, vendor };
Expand Down Expand Up @@ -281,7 +282,7 @@ function install(version = 8, options = {}) {
.then((location) => followToAdoptium(location))
.then((location) => downloadAll(tmpdir, location))
.then(verify)
.then(move)
.then((file) => move(file, installPath))
.then(extract);
}

Expand Down

0 comments on commit b1ea860

Please sign in to comment.