Skip to content

Commit

Permalink
Cache extracted runtime (#4179)
Browse files Browse the repository at this point in the history
Co-authored-by: Tibor Blenessy <[email protected]>
  • Loading branch information
ilia-kebets-sonarsource and saberduck authored Sep 20, 2023
1 parent 53d0f42 commit 8b28a90
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"angular.js:test/helpers/support.js": [
16
],
"angular.js:test/ng/compileSpec.fixture.js": [
688
],
"angular.js:test/ng/compileSpec.js": [
688
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,25 @@
"javascript-test-sources:src/ace/src/mouse/touch_handler.js": [
59
],
"javascript-test-sources:src/ace/src/scrollbar.js": [
125,
130,
223
],
"javascript-test-sources:src/ace/src/scrollbar_test.js": [
13
],
"javascript-test-sources:src/ace/src/snippets.js": [
270
],
"javascript-test-sources:src/ace/src/test/all_browser.js": [
11,
116
],
"javascript-test-sources:src/ace/src/virtual_renderer.js": [
1159,
1167
],
"javascript-test-sources:src/ace/static.js": [
33
],
Expand All @@ -129,6 +139,15 @@
123,
124
],
"javascript-test-sources:src/ecmascript6/Ghost/core/server/models/post.js": [
329
],
"javascript-test-sources:src/ecmascript6/Ghost/core/server/models/tag.js": [
68
],
"javascript-test-sources:src/ecmascript6/Ghost/core/server/models/user.js": [
184
],
"javascript-test-sources:src/ecmascript6/ecmascript6-today/7-rest-params/js/rest-spread.js": [
25
],
Expand All @@ -141,6 +160,8 @@
],
"javascript-test-sources:src/ecmascript6/router/third_party/brick/brick-1.0.1.byob.js": [
337,
572,
575,
877,
1412,
1637,
Expand Down
2 changes: 0 additions & 2 deletions its/ruling/src/test/expected/js/p5.js/javascript-S1874.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"p5.js:docs/yuidoc-p5-theme/assets/js/reference.js": [
2433,
2433,
2535,
3895,
4316,
4316,
4503,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ static void runRulingTest(
.setProperty("sonar.javascript.node.maxspace", "2048")
.setProperty("sonar.javascript.maxFileSize", "4000")
.setProperty("sonar.cpd.exclusions", "**/*")
.setProperty("sonar.internal.analysis.failFast", "true")
.setDebugLogs(true);
.setProperty("sonar.internal.analysis.failFast", "true");

orchestrator.executeBuild(build);
assertThat(differencesPath).hasContent("");
Expand Down
24 changes: 24 additions & 0 deletions sonar-plugin/sonar-javascript-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@
<resource>win-x64/node.exe.xz</resource>
<file>${project.build.directory}/node/win-x64/node.exe.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>win-x64/version.txt</resource>
<file>${project.build.directory}/node/win-x64/version.txt</file>
</transformer>
</transformers>
</configuration>
</execution>
Expand All @@ -188,6 +192,10 @@
<resource>linux-x64/node.xz</resource>
<file>${project.build.directory}/node/linux-x64/node.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>linux-x64/version.txt</resource>
<file>${project.build.directory}/node/linux-x64/version.txt</file>
</transformer>
</transformers>
</configuration>
</execution>
Expand All @@ -212,6 +220,10 @@
<resource>darwin-arm64/node.xz</resource>
<file>${project.build.directory}/node/darwin-arm64/node.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>darwin-arm64/version.txt</resource>
<file>${project.build.directory}/node/darwin-arm64/version.txt</file>
</transformer>
</transformers>
</configuration>
</execution>
Expand All @@ -236,14 +248,26 @@
<resource>win-x64/node.exe.xz</resource>
<file>${project.build.directory}/node/win-x64/node.exe.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>win-x64/version.txt</resource>
<file>${project.build.directory}/node/win-x64/version.txt</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>linux-x64/node.xz</resource>
<file>${project.build.directory}/node/linux-x64/node.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>linux-x64/version.txt</resource>
<file>${project.build.directory}/node/linux-x64/version.txt</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>darwin-arm64/node.xz</resource>
<file>${project.build.directory}/node/darwin-arm64/node.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>darwin-arm64/version.txt</resource>
<file>${project.build.directory}/node/darwin-arm64/version.txt</file>
</transformer>
</transformers>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.sonar.plugins.javascript.bridge.BundleImpl;
import org.sonar.plugins.javascript.bridge.CssRuleSensor;
import org.sonar.plugins.javascript.bridge.EmbeddedNode;
import org.sonar.plugins.javascript.bridge.Environment;
import org.sonar.plugins.javascript.bridge.HtmlSensor;
import org.sonar.plugins.javascript.bridge.JsTsChecks;
import org.sonar.plugins.javascript.bridge.JsTsSensor;
Expand Down Expand Up @@ -152,7 +153,8 @@ public void define(Context context) {
AnalysisProcessor.class,
YamlSensor.class,
HtmlSensor.class,
EmbeddedNode.class
EmbeddedNode.class,
Environment.class
);

context.addExtensions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ private enum Status {
public static final String SONARJS_EXISTING_NODE_PROCESS_PORT =
"SONARJS_EXISTING_NODE_PROCESS_PORT";
private static final Gson GSON = new Gson();

private static final String DEPLOY_LOCATION = "bridge-bundle";
private static final String BRIDGE_DEPLOY_LOCATION = "bridge-bundle";

private final HttpClient client;
private final NodeCommandBuilder nodeCommandBuilder;
Expand All @@ -87,7 +86,7 @@ private enum Status {
private Status status = Status.NOT_STARTED;
private final RulesBundles rulesBundles;
private final NodeDeprecationWarning deprecationWarning;
private final Path deployLocation;
private final Path temporaryDeployLocation;
private final Monitoring monitoring;
private final EmbeddedNode embeddedNode;
private static final int HEARTBEAT_INTERVAL_SECONDS = 5;
Expand Down Expand Up @@ -134,7 +133,7 @@ public BridgeServerImpl(
this.rulesBundles = rulesBundles;
this.deprecationWarning = deprecationWarning;
this.hostAddress = InetAddress.getLoopbackAddress().getHostAddress();
this.deployLocation = tempFolder.newDir(DEPLOY_LOCATION).toPath();
this.temporaryDeployLocation = tempFolder.newDir(BRIDGE_DEPLOY_LOCATION).toPath();
this.monitoring = monitoring;
this.heartbeatService = Executors.newSingleThreadScheduledExecutor();
this.embeddedNode = embeddedNode;
Expand Down Expand Up @@ -163,9 +162,14 @@ int getTimeoutSeconds() {
return timeoutSeconds;
}

/**
* Extracts the bridge files and node.js runtime (if included)
*
* @throws IOException
*/
void deploy() throws IOException {
bundle.deploy(deployLocation);
embeddedNode.deployNode(deployLocation);
bundle.deploy(temporaryDeployLocation);
embeddedNode.deploy();
}

void startServer(SensorContext context, List<Path> deployedBundles) throws IOException {
Expand Down Expand Up @@ -292,7 +296,7 @@ public void startServerLazily(SensorContext context) throws IOException {
throw new ServerAlreadyFailedException();
}
deploy();
List<Path> deployedBundles = rulesBundles.deploy(deployLocation.resolve("package"));
List<Path> deployedBundles = rulesBundles.deploy(temporaryDeployLocation.resolve("package"));
rulesBundles
.getUcfgRulesBundle()
.ifPresent(rulesBundle -> PluginInfo.setUcfgPluginVersion(rulesBundle.bundleVersion()));
Expand Down
Loading

0 comments on commit 8b28a90

Please sign in to comment.