Skip to content

Commit

Permalink
JS-232 Introduce the analyzer property sonar.scanner.skipNodeProvisio…
Browse files Browse the repository at this point in the history
…ning (#4820)
  • Loading branch information
yassin-kammoun-sonarsource authored Sep 18, 2024
1 parent 746cfea commit 1311c47
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void embedded_node() {

var buildResult = orchestrator.executeBuild(build);
assertThat(buildResult.isSuccess()).isTrue();
assertThat(buildResult.getLogs()).contains("INFO: Using embedded Node.js runtime");
assertThat(buildResult.getLogs()).contains("INFO: Using embedded Node.js runtime.");
assertThat(buildResult.getLogsLines(l -> l.startsWith("ERROR"))).isEmpty();
orchestrator.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class NodeCommandBuilderImpl implements NodeCommandBuilder {

public static final String NODE_EXECUTABLE_PROPERTY = "sonar.nodejs.executable";
private static final String NODE_FORCE_HOST_PROPERTY = "sonar.nodejs.forceHost";
private static final String SKIP_NODE_PROVISIONING_PROPERTY = "sonar.scanner.skipNodeProvisioning";

private static final Pattern NODEJS_VERSION_PATTERN = Pattern.compile(
"v?(\\d+)\\.(\\d+)\\.(\\d+)"
Expand Down Expand Up @@ -247,20 +248,24 @@ private String retrieveNodeExecutable(Configuration configuration)
private String locateNode(boolean isForceHost) throws IOException {
var defaultNode = NODE_EXECUTABLE_DEFAULT;
if (embeddedNode.isAvailable() && !isForceHost) {
LOG.info("Using embedded Node.js runtime");
LOG.info("Using embedded Node.js runtime.");
defaultNode = embeddedNode.binary().toString();
} else if (processWrapper.isMac()) {
defaultNode = locateNodeOnMac();
} else if (processWrapper.isWindows()) {
defaultNode = locateNodeOnWindows();
}

if (isForceHost) {
LOG.info("Forcing to use Node.js from the host.");
}

LOG.info("Using Node.js executable: '{}'.", defaultNode);
return defaultNode;
}

private static boolean isForceHost(Configuration configuration) {
return configuration.getBoolean(NODE_FORCE_HOST_PROPERTY).orElse(false);
return configuration.getBoolean(NODE_FORCE_HOST_PROPERTY).orElse(configuration.getBoolean(SKIP_NODE_PROVISIONING_PROPERTY).orElse(false));
}

private String locateNodeOnMac() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,23 @@ void test_embedded_runtime_with_forceHost_for_macos() throws Exception {
.endsWith("src/test/resources/package/node_modules/run-node/run-node");
}

@Test
void test_skipping_nodejs_provisioning_property() throws Exception {
var skipNodePropvisioning = "sonar.scanner.skipNodeProvisioning";
var settings = new MapSettings();
settings.setProperty(skipNodePropvisioning, true);

builder()
.configuration(settings.asConfig())
.script("script.js")
.pathResolver(getPathResolver())
.build();

assertThat(logTester.logs(Level.INFO))
.doesNotContain("Using embedded Node.js runtime")
.contains("Forcing to use Node.js from the host.");
}

private static String resourceScript(String script) throws URISyntaxException {
return new File(NodeCommandTest.class.getResource("/" + script).toURI()).getAbsolutePath();
}
Expand Down

0 comments on commit 1311c47

Please sign in to comment.