Skip to content

Commit 0a4e75b

Browse files
committed
Always use deno
1 parent a818dff commit 0a4e75b

File tree

5 files changed

+6
-272
lines changed

5 files changed

+6
-272
lines changed

sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/bridge/BridgeServerImpl.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
package org.sonar.plugins.javascript.bridge;
1818

1919
import static org.sonar.plugins.javascript.bridge.NetUtils.findOpenPort;
20-
import static org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.NODE_EXECUTABLE_PROPERTY;
21-
import static org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.NODE_FORCE_HOST_PROPERTY;
22-
import static org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.SKIP_NODE_PROVISIONING_PROPERTY;
2320

2421
import com.google.gson.Gson;
2522
import com.google.gson.JsonSyntaxException;
@@ -201,22 +198,6 @@ void deploy(Configuration configuration) throws IOException {
201198
} else {
202199
bundle.deploy(temporaryDeployLocation);
203200
}
204-
if (
205-
configuration.get(NODE_EXECUTABLE_PROPERTY).isPresent() ||
206-
configuration.getBoolean(SKIP_NODE_PROVISIONING_PROPERTY).orElse(false) ||
207-
configuration.getBoolean(NODE_FORCE_HOST_PROPERTY).orElse(false)
208-
) {
209-
String property;
210-
if (configuration.get(NODE_EXECUTABLE_PROPERTY).isPresent()) {
211-
property = NODE_EXECUTABLE_PROPERTY;
212-
} else if (configuration.get(SKIP_NODE_PROVISIONING_PROPERTY).isPresent()) {
213-
property = SKIP_NODE_PROVISIONING_PROPERTY;
214-
} else {
215-
property = NODE_FORCE_HOST_PROPERTY;
216-
}
217-
LOG.info("'{}' is set. Skipping embedded Node.js runtime deployment.", property);
218-
return;
219-
}
220201
embeddedNode.deploy();
221202
}
222203

sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/nodejs/NodeCommandBuilderImpl.java

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ public class NodeCommandBuilderImpl implements NodeCommandBuilder {
4444
public static final String NODE_EXECUTABLE_DEFAULT = "deno";
4545
private static final String NODE_EXECUTABLE_DEFAULT_MACOS = "package/bin/run-deno";
4646

47-
public static final String NODE_EXECUTABLE_PROPERTY = "sonar.nodejs.executable";
48-
public static final String NODE_FORCE_HOST_PROPERTY = "sonar.nodejs.forceHost";
49-
public static final String SKIP_NODE_PROVISIONING_PROPERTY = "sonar.scanner.skipNodeProvisioning";
50-
5147
private static final Pattern NODEJS_VERSION_PATTERN = Pattern.compile(
5248
"v?(\\d+)\\.(\\d+)\\.(\\d+)"
5349
);
@@ -148,8 +144,7 @@ public NodeCommandBuilder embeddedNode(EmbeddedNode embeddedNode) {
148144
*/
149145
@Override
150146
public NodeCommand build() throws NodeCommandException, IOException {
151-
String nodeExecutable = retrieveNodeExecutable(configuration);
152-
checkNodeCompatibility(nodeExecutable);
147+
String nodeExecutable = locateNode();
153148

154149
if (nodeJsArgs.isEmpty() && scriptFilename == null && args.isEmpty()) {
155150
throw new IllegalArgumentException("Missing arguments for Node.js.");
@@ -171,26 +166,6 @@ public NodeCommand build() throws NodeCommandException, IOException {
171166
);
172167
}
173168

174-
private void checkNodeCompatibility(String nodeExecutable) throws NodeCommandException {
175-
if (minNodeVersion == null) {
176-
return;
177-
}
178-
LOG.debug("Checking Node.js version");
179-
180-
// String versionString = NodeVersion.getVersion(processWrapper, nodeExecutable);
181-
// actualNodeVersion = nodeVersion(versionString);
182-
// if (!actualNodeVersion.isGreaterThanOrEqual(minNodeVersion)) {
183-
// throw new NodeCommandException(
184-
// String.format(
185-
// "Unsupported Node.JS version detected %s. Please upgrade to the latest Node.JS LTS version.",
186-
// actualNodeVersion
187-
// )
188-
// );
189-
// }
190-
//
191-
// LOG.debug("Using Node.js {}.", versionString);
192-
}
193-
194169
// Visible for testing
195170
static Version nodeVersion(String versionString) throws NodeCommandException {
196171
Matcher versionMatcher = NODEJS_VERSION_PATTERN.matcher(versionString);
@@ -207,95 +182,29 @@ static Version nodeVersion(String versionString) throws NodeCommandException {
207182
}
208183
}
209184

210-
/**
211-
* Finds a node runtime by looking into:
212-
* 1. sonar.nodejs.executable
213-
* 2. an embedded runtime bundled with the analyzer
214-
* 3. a runtime on the host
215-
* If sonar.nodejs.forceHost is enabled, 2. is ignored
216-
*
217-
* @param configuration
218-
* @return
219-
* @throws NodeCommandException
220-
* @throws IOException
221-
*/
222-
private String retrieveNodeExecutable(Configuration configuration)
223-
throws NodeCommandException, IOException {
224-
if (configuration.hasKey(NODE_EXECUTABLE_PROPERTY)) {
225-
nodeExecutableOrigin = NODE_EXECUTABLE_PROPERTY;
226-
String nodeExecutable = configuration.get(NODE_EXECUTABLE_PROPERTY).get();
227-
File file = new File(nodeExecutable);
228-
if (file.exists()) {
229-
LOG.info(
230-
"Using Node.js executable {} from property {}.",
231-
file.getAbsoluteFile(),
232-
NODE_EXECUTABLE_PROPERTY
233-
);
234-
return nodeExecutable;
235-
} else {
236-
LOG.error(
237-
"Provided Node.js executable file does not exist. Property '{}' was set to '{}'",
238-
NODE_EXECUTABLE_PROPERTY,
239-
nodeExecutable
240-
);
241-
throw new NodeCommandException("Provided Node.js executable file does not exist.");
242-
}
243-
}
244-
245-
return locateNode(isForceHost(configuration));
246-
}
247-
248-
private String locateNode(boolean isForceHost) throws IOException {
185+
private String locateNode() throws IOException {
249186
var defaultNode = NODE_EXECUTABLE_DEFAULT;
250-
if (embeddedNode.isAvailable() && !isForceHost) {
251-
LOG.info("Using embedded Node.js runtime.");
252-
defaultNode = embeddedNode.binary().toString();
253-
nodeExecutableOrigin = "embedded";
254-
} else if (processWrapper.isMac()) {
187+
if (processWrapper.isMac()) {
255188
defaultNode = locateNodeOnMac();
256189
nodeExecutableOrigin = "host";
257190
} else if (processWrapper.isWindows()) {
258191
defaultNode = locateNodeOnWindows();
259192
nodeExecutableOrigin = "host";
260193
}
261194

262-
if (isForceHost) {
263-
LOG.info("Forcing to use Node.js from the host.");
264-
nodeExecutableOrigin = "force-host";
265-
}
266-
267195
LOG.info("Using Node.js executable: '{}'.", defaultNode);
268196
return defaultNode;
269197
}
270198

271-
private static boolean isForceHost(Configuration configuration) {
272-
var forceHost = configuration.getBoolean(NODE_FORCE_HOST_PROPERTY);
273-
if (forceHost.isPresent()) {
274-
LOG.warn(
275-
"Property '{}' is deprecated and will be removed in a future version. Please use '{}' instead.",
276-
NODE_FORCE_HOST_PROPERTY,
277-
SKIP_NODE_PROVISIONING_PROPERTY
278-
);
279-
return forceHost.get();
280-
}
281-
return configuration.getBoolean(SKIP_NODE_PROVISIONING_PROPERTY).orElse(false);
282-
}
283-
284199
private String locateNodeOnMac() throws IOException {
285200
// on Mac when e.g. IntelliJ is launched from dock, node will often not be available via PATH, because PATH is configured
286201
// in .bashrc or similar, thus we launch node via 'run-node', which should load required configuration
287202
LOG.debug("Looking for Node.js in the PATH using run-node (macOS)");
288203
String defaultNode = pathResolver.resolve(NODE_EXECUTABLE_DEFAULT_MACOS);
289204
File file = new File(defaultNode);
290205
if (!file.exists()) {
291-
LOG.error(
292-
"Default Node.js executable for MacOS does not exist. Value '{}'. Consider setting Node.js location through property '{}'",
293-
defaultNode,
294-
NODE_EXECUTABLE_PROPERTY
295-
);
296-
throw new NodeCommandException(
297-
"Default Node.js executable for MacOS does not exist. " + defaultNode
298-
);
206+
LOG.error("Default Node.js executable for MacOS does not exist");
207+
throw new NodeCommandException("Default Node.js executable for MacOS does not exist.");
299208
} else {
300209
Files.setPosixFilePermissions(
301210
file.toPath(),

sonar-plugin/bridge/src/test/java/org/sonar/plugins/javascript/bridge/BridgeServerImplTest.java

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
import static org.slf4j.event.Level.DEBUG;
3131
import static org.slf4j.event.Level.INFO;
3232
import static org.slf4j.event.Level.WARN;
33-
import static org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.NODE_EXECUTABLE_PROPERTY;
34-
import static org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.NODE_FORCE_HOST_PROPERTY;
35-
import static org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.SKIP_NODE_PROVISIONING_PROPERTY;
3633

3734
import java.io.File;
3835
import java.io.IOException;
@@ -702,57 +699,6 @@ void should_omit_an_ast_if_skipAst_flag_is_set() throws Exception {
702699
assertThat(response.ast()).isNull();
703700
}
704701

705-
@Test
706-
void should_not_deploy_runtime_if_sonar_nodejs_executable_is_set() {
707-
var existingDoesntMatterScript = "logging.js";
708-
bridgeServer = createBridgeServer(existingDoesntMatterScript);
709-
context.setSettings(new MapSettings().setProperty(NODE_EXECUTABLE_PROPERTY, "whatever"));
710-
BridgeServerConfig serverConfigForExecutableProperty = BridgeServerConfig.fromSensorContext(
711-
context
712-
);
713-
assertThatThrownBy(() ->
714-
bridgeServer.startServerLazily(serverConfigForExecutableProperty)
715-
).isInstanceOf(NodeCommandException.class);
716-
717-
assertThat(logTester.logs(INFO)).contains(
718-
"'" + NODE_EXECUTABLE_PROPERTY + "' is set. Skipping embedded Node.js runtime deployment."
719-
);
720-
}
721-
722-
@Test
723-
void should_not_deploy_runtime_if_skip_node_provisioning_is_set() throws Exception {
724-
var script = "logging.js";
725-
bridgeServer = createBridgeServer(script);
726-
727-
var settings = new MapSettings().setProperty(SKIP_NODE_PROVISIONING_PROPERTY, true);
728-
context.setSettings(settings);
729-
730-
var config = BridgeServerConfig.fromSensorContext(context);
731-
bridgeServer.startServerLazily(config);
732-
733-
assertThat(logTester.logs(INFO)).contains(
734-
"'" +
735-
SKIP_NODE_PROVISIONING_PROPERTY +
736-
"' is set. Skipping embedded Node.js runtime deployment."
737-
);
738-
}
739-
740-
@Test
741-
void should_not_deploy_runtime_if_node_force_host_is_set() throws Exception {
742-
var script = "logging.js";
743-
bridgeServer = createBridgeServer(script);
744-
745-
var settings = new MapSettings().setProperty(NODE_FORCE_HOST_PROPERTY, true);
746-
context.setSettings(settings);
747-
748-
var config = BridgeServerConfig.fromSensorContext(context);
749-
bridgeServer.startServerLazily(config);
750-
751-
assertThat(logTester.logs(INFO)).contains(
752-
"'" + NODE_FORCE_HOST_PROPERTY + "' is set. Skipping embedded Node.js runtime deployment."
753-
);
754-
}
755-
756702
@Test
757703
void should_start_bridge_from_path() throws IOException, InterruptedException {
758704
bridgeServer = createBridgeServer(new BundleImpl());

sonar-plugin/bridge/src/test/java/org/sonar/plugins/javascript/nodejs/NodeCommandTest.java

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -176,35 +176,6 @@ void test_max_old_space_size_setting() throws IOException {
176176
assertThat(total_available_size).isGreaterThan(maxOldSpaceSize * 1000);
177177
}
178178

179-
@Test
180-
void test_executable_from_configuration() throws Exception {
181-
String NODE_EXECUTABLE_PROPERTY = "sonar.nodejs.executable";
182-
Path nodeExecutable = Files.createFile(tempDir.resolve("custom-node")).toAbsolutePath();
183-
MapSettings mapSettings = new MapSettings();
184-
mapSettings.setProperty(NODE_EXECUTABLE_PROPERTY, nodeExecutable.toString());
185-
Configuration configuration = mapSettings.asConfig();
186-
NodeCommand nodeCommand = builder(mockProcessWrapper)
187-
.configuration(configuration)
188-
.script("not-used")
189-
.build();
190-
nodeCommand.start();
191-
192-
List<String> value = captureProcessWrapperArgument();
193-
assertThat(value).contains(nodeExecutable.toString());
194-
assertThat(nodeCommand.getNodeExecutableOrigin()).isEqualTo(NODE_EXECUTABLE_PROPERTY);
195-
await().until(() ->
196-
logTester
197-
.logs(LoggerLevel.INFO)
198-
.contains(
199-
"Using Node.js executable " +
200-
nodeExecutable +
201-
" from property " +
202-
NODE_EXECUTABLE_PROPERTY +
203-
"."
204-
)
205-
);
206-
}
207-
208179
@Test
209180
void test_empty_configuration() throws Exception {
210181
NodeCommand nodeCommand = builder(mockProcessWrapper)
@@ -223,27 +194,6 @@ private List<String> captureProcessWrapperArgument() throws IOException {
223194
return processStartArgument.getValue();
224195
}
225196

226-
@Test
227-
void test_non_existing_node_file() throws Exception {
228-
MapSettings settings = new MapSettings();
229-
settings.setProperty("sonar.nodejs.executable", "non-existing-file");
230-
NodeCommandBuilder nodeCommand = builder(mockProcessWrapper)
231-
.configuration(settings.asConfig())
232-
.script("not-used");
233-
234-
assertThatThrownBy(nodeCommand::build)
235-
.isInstanceOf(NodeCommandException.class)
236-
.hasMessage("Provided Node.js executable file does not exist.");
237-
238-
await().until(() ->
239-
logTester
240-
.logs(LoggerLevel.ERROR)
241-
.contains(
242-
"Provided Node.js executable file does not exist. Property 'sonar.nodejs.executable' was set to 'non-existing-file'"
243-
)
244-
);
245-
}
246-
247197
@Test
248198
void test_exception_start() throws Exception {
249199
IOException cause = new IOException("Error starting process");
@@ -456,42 +406,6 @@ void test_embedded_runtime_with_forceHost_for_macos() throws Exception {
456406
assertThat(nodeCommand.getNodeExecutableOrigin()).isEqualTo("force-host");
457407
}
458408

459-
@Test
460-
void test_skipping_nodejs_provisioning_property() throws Exception {
461-
var skipNodeProvisioning = "sonar.scanner.skipNodeProvisioning";
462-
var settings = new MapSettings();
463-
settings.setProperty(skipNodeProvisioning, true);
464-
465-
var nodeCommand = builder()
466-
.configuration(settings.asConfig())
467-
.script("script.js")
468-
.pathResolver(getPathResolver())
469-
.build();
470-
471-
assertThat(logTester.logs(Level.INFO))
472-
.doesNotContain("Using embedded Node.js runtime")
473-
.contains("Forcing to use Node.js from the host.");
474-
assertThat(nodeCommand.getNodeExecutableOrigin()).isEqualTo("force-host");
475-
}
476-
477-
@Test
478-
void test_node_force_host_property_deprecation() throws Exception {
479-
var forceHostProp = "sonar.nodejs.forceHost";
480-
var settings = new MapSettings();
481-
settings.setProperty(forceHostProp, true);
482-
483-
builder()
484-
.configuration(settings.asConfig())
485-
.script("script.js")
486-
.pathResolver(getPathResolver())
487-
.build();
488-
489-
assertThat(logTester.logs(Level.WARN)).contains(
490-
"Property 'sonar.nodejs.forceHost' is deprecated and will be removed in a future version. " +
491-
"Please use 'sonar.scanner.skipNodeProvisioning' instead."
492-
);
493-
}
494-
495409
private static String resourceScript(String script) throws URISyntaxException {
496410
return new File(NodeCommandTest.class.getResource("/" + script).toURI()).getAbsolutePath();
497411
}

sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/AbstractBridgeSensor.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package org.sonar.plugins.javascript.analysis;
1818

19-
import static org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.NODE_EXECUTABLE_PROPERTY;
20-
2119
import java.io.IOException;
2220
import java.util.List;
2321
import org.slf4j.Logger;
@@ -31,7 +29,6 @@
3129
import org.sonar.plugins.javascript.bridge.BridgeServer;
3230
import org.sonar.plugins.javascript.bridge.BridgeServerConfig;
3331
import org.sonar.plugins.javascript.bridge.ServerAlreadyFailedException;
34-
import org.sonar.plugins.javascript.nodejs.NodeCommandException;
3532

3633
public abstract class AbstractBridgeSensor implements Sensor {
3734

@@ -79,22 +76,9 @@ public void execute(SensorContext sensorContext) {
7976
} catch (ServerAlreadyFailedException e) {
8077
LOG.debug(
8178
"Skipping the start of the bridge server " +
82-
"as it failed to start during the first analysis or it's not answering anymore"
79+
"as it failed to start during the first analysis or it's not answering anymore"
8380
);
8481
LOG.debug("No rules will be executed");
85-
} catch (NodeCommandException e) {
86-
logErrorOrWarn(e.getMessage(), e);
87-
throw new IllegalStateException(
88-
"Error while running Node.js. A supported version of Node.js is required for running the analysis of " +
89-
this.lang +
90-
" files. Please make sure a supported version of Node.js is available in the PATH or an executable path is provided via '" +
91-
NODE_EXECUTABLE_PROPERTY +
92-
"' property. Alternatively, you can exclude " +
93-
this.lang +
94-
" files from your analysis using the 'sonar.exclusions' configuration property. " +
95-
"See the docs for configuring the analysis environment: https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/javascript-typescript-css/",
96-
e
97-
);
9882
} catch (Exception e) {
9983
LOG.error("Failure during analysis", e);
10084
throw new IllegalStateException("Analysis of " + this.lang + " files failed", e);

0 commit comments

Comments
 (0)