Skip to content

Commit 8b8ac25

Browse files
authored
chore: add option for setting custom mvn path using env var (#22)
Signed-off-by: Tomer Figenblat <[email protected]>
1 parent 067edac commit 8b8ac25

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,42 @@ Excluding a package from any analysis can be achieved by marking the package for
152152

153153
<h3>Tokens</h3>
154154
<p>
155-
If you wish the report to include other vulnerabilities data and resolutions which is only available to registered users.
156-
You can include the various vulnerability vendor data token as environment variables.
155+
For including extra vulnerability data and resolutions, otherwise only available to vendor registered users. You can
156+
set the various vendor tokens as environment variables.
157157

158158
Available token environment variables:
159159
</p>
160160

161-
<ul>
162-
<li><em>CRDA_SNYK_TOKEN</em></li>
163-
</ul>
161+
<table>
162+
<tr>
163+
<th>Vendor</th>
164+
<th>Token Environment Variable</th>
165+
</tr>
166+
<tr>
167+
<td><a href="https://app.snyk.io/redhat/snyk-token">Snyk</a></td>
168+
<td>CRDA_SNYK_TOKEN</td>
169+
</tr>
170+
</table>
171+
172+
<h3>Custom Executables</h3>
173+
<p>
174+
This project uses each ecosystem's executable for creating dependency trees. These executables are expected to be
175+
present on the system PATH. If they are not, or perhaps you want to use custom ones. Use can use the following
176+
environment variables for setting custom paths for the said executables.
177+
</p>
178+
179+
<table>
180+
<tr>
181+
<th>Ecosystem</th>
182+
<th>Default</th>
183+
<th>Environment Variable</th>
184+
</tr>
185+
<tr>
186+
<td><a href="https://maven.apache.org/">Maven</a></td>
187+
<td><em>mvn</em></td>
188+
<td>CRDA_MVN_PATH</td>
189+
</tr>
190+
</table>
164191

165192
<!-- Badge links -->
166193
[0]: https://img.shields.io/github/v/release/RHEcosystemAppEng/crda-javascript-api?color=green&label=latest

src/providers/java_maven.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default { isSupported, provideComponent, provideStack }
2020
*/
2121
const ecosystem = 'maven'
2222

23+
const mvn = process.env.CRDA_MVN_PATH ? process.env.CRDA_MVN_PATH : 'mvn'
24+
2325
/**
2426
* @param {string} manifestName - the subject manifest name-type
2527
* @returns {boolean} - return true if `pom.xml` is the manifest name-type
@@ -62,13 +64,13 @@ function provideComponent(data) {
6264
*/
6365
function getGraph(manifest) {
6466
// verify maven is accessible
65-
execSync('mvn --version', err => {
67+
execSync(`${mvn} --version`, err => {
6668
if (err) {
6769
throw new Error('mvn is not accessible')
6870
}
6971
})
7072
// clean maven target
71-
execSync(`mvn -q clean -f ${manifest}`, err => {
73+
execSync(`${mvn} -q clean -f ${manifest}`, err => {
7274
if (err) {
7375
throw new Error('failed cleaning maven target')
7476
}
@@ -77,7 +79,7 @@ function getGraph(manifest) {
7779
let tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'crda_'))
7880
let tmpDepTree = path.join(tmpDir, 'mvn_deptree.txt')
7981
// build initial command
80-
let depTreeCmd = `mvn -q dependency:tree -DoutputType=dot -DoutputFile=${tmpDepTree} -f ${manifest}`
82+
let depTreeCmd = `${mvn} -q dependency:tree -DoutputType=dot -DoutputFile=${tmpDepTree} -f ${manifest}`
8183
// exclude ignored dependencies, exclude format is groupId:artifactId:scope:version.
8284
// version and scope are marked as '*' if not specified (we do not use scope yet)
8385
getDependencies(manifest).forEach(dep => {
@@ -107,7 +109,7 @@ function getGraph(manifest) {
107109
*/
108110
function getList(data) {
109111
// verify maven is accessible
110-
execSync('mvn --version', err => {
112+
execSync(`${mvn} --version`, err => {
111113
if (err) {
112114
throw new Error('mvn is not accessible')
113115
}
@@ -119,7 +121,7 @@ function getList(data) {
119121
// write target pom content to temp file
120122
fs.writeFileSync(tmpTargetPom, data)
121123
// create effective pom and save to temp file
122-
execSync(`mvn -q help:effective-pom -Doutput=${tmpEffectivePom} -f ${tmpTargetPom}`, err => {
124+
execSync(`${mvn} -q help:effective-pom -Doutput=${tmpEffectivePom} -f ${tmpTargetPom}`, err => {
123125
if (err) {
124126
throw new Error('failed creating maven effective pom')
125127
}

0 commit comments

Comments
 (0)