From 707cc4cacbac49483a4eb154f23ca41ab6a2ac60 Mon Sep 17 00:00:00 2001 From: Stefan Seemann Date: Tue, 9 Nov 2021 14:02:43 +0100 Subject: [PATCH] fix: Avoid IllegalStateException if TypeScript is downloaded/updated and BundledNodeJS not available --- pom.xml | 5 +++ .../nbm/nodejs/impl/NodeJSInstaller.java | 35 ++++++++++++++++--- src/main/resources/META-INF/adito.version | 2 +- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 988dbc5..87cd394 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,11 @@ de-adito-runconfig-api ${netbeans.version}-1.6.2 + + de.adito.nbm + de-adito-metrics-api + ${netbeans.version}-1.6.0-2 + diff --git a/src/main/java/de/adito/aditoweb/nbm/nodejs/impl/NodeJSInstaller.java b/src/main/java/de/adito/aditoweb/nbm/nodejs/impl/NodeJSInstaller.java index fb6aa9e..052dcdb 100644 --- a/src/main/java/de/adito/aditoweb/nbm/nodejs/impl/NodeJSInstaller.java +++ b/src/main/java/de/adito/aditoweb/nbm/nodejs/impl/NodeJSInstaller.java @@ -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; @@ -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() @@ -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; @@ -118,8 +122,13 @@ protected void downloadOrUpdateBundledTypeScript() throws IOException, Interrupt // prepare List 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) @@ -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++; + } + } + } } diff --git a/src/main/resources/META-INF/adito.version b/src/main/resources/META-INF/adito.version index b5b2aac..e7dacc8 100644 --- a/src/main/resources/META-INF/adito.version +++ b/src/main/resources/META-INF/adito.version @@ -1 +1 @@ -2021.1.0 \ No newline at end of file +2021.2.1 \ No newline at end of file