Skip to content

Commit 6ac6bac

Browse files
Strum355claude
andcommitted
refactor: use selectToolBinary instead of resolveBinary for Maven discovery
Replace the standalone resolveBinary function with Java_maven's selectToolBinary, which also runs a --version smoke test to verify the binary is executable. Gracefully fall back to returning only the root pom.xml if Maven is not available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3d9ea4b commit 6ac6bac

2 files changed

Lines changed: 7 additions & 22 deletions

File tree

src/providers/java_maven.js

Lines changed: 7 additions & 3 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, invokeCommand, resolveBinary } from '../tools.js'
10+
import { getCustom, invokeCommand } from '../tools.js'
1111
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore } from '../workspace.js'
1212

1313
import Base_java, { ecosystem_maven } from "./base_java.js";
@@ -330,8 +330,12 @@ export async function discoverMavenModules(workspaceRoot, opts = {}) {
330330
return []
331331
}
332332

333-
const localWrapper = 'mvnw' + (process.platform === 'win32' ? '.cmd' : '')
334-
const mvnBin = resolveBinary('mvn', localWrapper, root, opts)
333+
let mvnBin
334+
try {
335+
mvnBin = new Java_maven().selectToolBinary(rootPom, opts)
336+
} catch {
337+
return [rootPom]
338+
}
335339
const visited = new Set()
336340
const manifestPaths = [rootPom]
337341

src/tools.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,6 @@ 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-
200181
/** this method invokes command string in a process in a synchronous way.
201182
* @param {string} bin - the command to be invoked
202183
* @param {Array<string>} args - the args to pass to the binary

0 commit comments

Comments
 (0)