Skip to content

Commit 53ebe0b

Browse files
Strum355claude
andcommitted
refactor: replace resolveMavenBinary with shared resolveBinary
Extract a reusable resolveBinary(globalBinary, localWrapper, startDir, opts) into tools.js and use it from discoverMavenModules, eliminating the one-off resolveMavenBinary function that duplicated selectToolBinary logic. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dd9e811 commit 53ebe0b

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

src/providers/java_maven.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { XMLParser } from 'fast-xml-parser'
77

88
import { getLicense } from '../license/license_utils.js'
99
import Sbom from '../sbom.js'
10-
import { getCustom, getCustomPath, getWrapperPreference, invokeCommand, traverseForWrapper } from '../tools.js'
10+
import { getCustom, invokeCommand, resolveBinary } from '../tools.js'
1111
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore } from '../workspace.js'
1212

1313
import Base_java, { ecosystem_maven } from "./base_java.js";
@@ -315,25 +315,6 @@ const DEFAULT_MAVEN_DISCOVERY_IGNORE = [
315315
'**/target/**',
316316
]
317317

318-
/**
319-
* Resolve the Maven binary, respecting wrapper preference.
320-
*
321-
* @param {string} startDir - Directory from which to start the wrapper search
322-
* @param {object} [opts={}]
323-
* @returns {string} Path to the Maven binary
324-
*/
325-
function resolveMavenBinary(startDir, opts = {}) {
326-
const localWrapper = 'mvnw' + (process.platform === 'win32' ? '.cmd' : '')
327-
const useWrapper = getWrapperPreference('mvn', opts)
328-
if (useWrapper) {
329-
const wrapper = traverseForWrapper(startDir, localWrapper)
330-
if (wrapper !== undefined) {
331-
return wrapper
332-
}
333-
}
334-
return getCustomPath('mvn', opts)
335-
}
336-
337318
/**
338319
* Discover all pom.xml manifest paths in a Maven multi-module project.
339320
*
@@ -349,7 +330,8 @@ export async function discoverMavenModules(workspaceRoot, opts = {}) {
349330
return []
350331
}
351332

352-
const mvnBin = resolveMavenBinary(root, opts)
333+
const localWrapper = 'mvnw' + (process.platform === 'win32' ? '.cmd' : '')
334+
const mvnBin = resolveBinary('mvn', localWrapper, root, opts)
353335
const visited = new Set()
354336
const manifestPaths = [rootPom]
355337

src/tools.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,25 @@ export function traverseForWrapper(startDir, wrapperName, repoRoot = undefined)
178178
}
179179
}
180180

181+
/**
182+
* Resolve a build-tool binary, preferring a wrapper when configured.
183+
*
184+
* @param {string} globalBinary - Global binary name (e.g. `mvn`, `gradle`)
185+
* @param {string} localWrapper - Wrapper filename (e.g. `mvnw`, `gradlew.bat`)
186+
* @param {string} startDir - Directory from which to start the wrapper search
187+
* @param {import('./index.js').Options} [opts={}]
188+
* @returns {string} Path to the resolved binary
189+
*/
190+
export function resolveBinary(globalBinary, localWrapper, startDir, opts = {}) {
191+
if (getWrapperPreference(globalBinary, opts)) {
192+
const wrapper = traverseForWrapper(startDir, localWrapper)
193+
if (wrapper !== undefined) {
194+
return wrapper
195+
}
196+
}
197+
return getCustomPath(globalBinary, opts)
198+
}
199+
181200
/** this method invokes command string in a process in a synchronous way.
182201
* @param {string} bin - the command to be invoked
183202
* @param {Array<string>} args - the args to pass to the binary

0 commit comments

Comments
 (0)