Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
fix: Avoid IllegalStateException if TypeScript is downloaded/updated …
Browse files Browse the repository at this point in the history
…and BundledNodeJS not available
  • Loading branch information
ses1112 committed Nov 9, 2021
1 parent 5b65f98 commit 707cc4c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<artifactId>de-adito-runconfig-api</artifactId>
<version>${netbeans.version}-1.6.2</version>
</dependency>
<dependency>
<groupId>de.adito.nbm</groupId>
<artifactId>de-adito-metrics-api</artifactId>
<version>${netbeans.version}-1.6.0-2</version>
</dependency>

<!-- ADITO Utils -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package de.adito.aditoweb.nbm.nodejs.impl;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import de.adito.aditoweb.nbm.metrics.api.IMetricProxyFactory;
import de.adito.aditoweb.nbm.metrics.api.types.*;
import de.adito.aditoweb.nbm.nbide.nbaditointerface.javascript.node.*;
import de.adito.aditoweb.nbm.nodejs.impl.options.NodeJSOptions;
import de.adito.aditoweb.nbm.nodejs.impl.options.downloader.INodeJSDownloader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.*;
import org.netbeans.api.progress.*;
import org.openide.util.NbBundle;
import org.openide.windows.OnShowing;
Expand All @@ -30,6 +32,7 @@ public class NodeJSInstaller implements Runnable
.setNameFormat("tNodeJSInstaller-%d")
.setPriority(Thread.MIN_PRIORITY)
.build());
private final _NodeJSDownloadRetryHandler retryHandler = IMetricProxyFactory.proxy(new _NodeJSDownloadRetryHandler());

@Override
public void run()
Expand Down Expand Up @@ -108,7 +111,8 @@ protected void downloadBundledNodeJS() throws IOException
})
protected void downloadOrUpdateBundledTypeScript() throws IOException, InterruptedException, TimeoutException
{
File target = BundledNodeJS.getInstance().getBundledNodeJSContainer();
BundledNodeJS bundledNode = BundledNodeJS.getInstance();
File target = bundledNode.getBundledNodeJSContainer();
if (!target.exists())
return;

Expand All @@ -118,8 +122,13 @@ protected void downloadOrUpdateBundledTypeScript() throws IOException, Interrupt

// prepare
List<String> packagesToInstall = IBundledPackages.getPreinstalledPackages();
INodeJSExecutor executor = BundledNodeJS.getInstance().getBundledExecutor();
INodeJSEnvironment environment = BundledNodeJS.getInstance().getBundledEnvironment();
INodeJSExecutor executor = bundledNode.getBundledExecutor();

// try it multiple times, sometimes no NodeJS is available
if (!bundledNode.isBundledEnvironmentAvailable())
retryHandler.retryBundledNodeJsDownload();

INodeJSEnvironment environment = bundledNode.getBundledEnvironment();

// download and install all "preinstalled" packages, so they will be available at runtime
for (String pkg : packagesToInstall)
Expand Down Expand Up @@ -188,4 +197,22 @@ private void _updateIntegrity(@NotNull File pTarget, @NotNull String pVersion)
}
}

/**
* Extra class, so we can count and analyze the retries for downloading bundled nodejs
*/
private class _NodeJSDownloadRetryHandler
{
@Counted(name = "nodejs.bundled.download.retryhandler")
public void retryBundledNodeJsDownload() throws IOException
{
BundledNodeJS bundledNode = BundledNodeJS.getInstance();

int countRetries = 0;
while (!bundledNode.isBundledEnvironmentAvailable() && countRetries < 3)
{
downloadBundledNodeJS();
countRetries++;
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/adito.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021.1.0
2021.2.1

0 comments on commit 707cc4c

Please sign in to comment.