Skip to content

Commit 89f0656

Browse files
authored
fix: version 2022.3 breaks by marking PreloadingActivity for internal usage (#107)
Signed-off-by: Tomer Figenblat <[email protected]>
1 parent b24697b commit 89f0656

File tree

4 files changed

+89
-77
lines changed

4 files changed

+89
-77
lines changed

src/main/java/org/jboss/tools/intellij/analytics/GitHubReleaseDownloader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.io.File;
44
import java.io.IOException;
55

6-
import com.intellij.openapi.progress.ProgressIndicator;
6+
import com.intellij.openapi.progress.ProgressManager;
77
import com.intellij.util.io.HttpRequests;
88
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage;
99
import com.intellij.openapi.diagnostic.Logger;
@@ -36,7 +36,7 @@ private boolean isNewRelease(final String releaseLabel) {
3636
}
3737

3838

39-
public File download(final ProgressIndicator indicator) throws IOException {
39+
public File download() throws IOException {
4040
final ActionMessage telemetry;
4141
final String latestReleaseTag;
4242
final File dest = new File(Platform.pluginDirectory, fileName);
@@ -72,7 +72,7 @@ public File download(final ProgressIndicator indicator) throws IOException {
7272
HttpRequests
7373
.request(url)
7474
.productNameAsUserAgent()
75-
.saveToFile(dest, indicator);
75+
.saveToFile(dest, ProgressManager.getGlobalProgressIndicator());
7676

7777
dest.setExecutable(true);
7878
cookies.setValue(cookieName, latestReleaseTag);

src/main/java/org/jboss/tools/intellij/analytics/PreloadLanguageServer.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.util.List;
56

7+
import com.intellij.ide.AppLifecycleListener;
68
import com.intellij.openapi.application.ApplicationManager;
7-
import com.intellij.openapi.application.PreloadingActivity;
8-
import com.intellij.openapi.progress.ProgressIndicator;
99
import com.intellij.openapi.diagnostic.Logger;
1010
import com.intellij.openapi.components.ServiceManager;
11+
import org.jetbrains.annotations.NotNull;
1112
import org.wso2.lsp4intellij.IntellijLanguageClient;
1213

13-
public final class PreloadLanguageServer extends PreloadingActivity {
14+
public final class PreloadLanguageServer implements AppLifecycleListener {
1415
private static final Logger log = Logger.getInstance(PreloadLanguageServer.class);
1516
private final ICookie cookies = ServiceManager.getService(Settings.class);
1617

@@ -27,27 +28,28 @@ private void attachLanguageClient(final File cliFile) {
2728
}
2829

2930
@Override
30-
public void preload(ProgressIndicator indicator) {
31-
if (ApplicationManager.getApplication().isUnitTestMode()) {
32-
return;
33-
}
34-
log.debug("lsp preload called");
35-
try {
36-
final String devUrl = System.getenv("ANALYTICS_LSP_FILE_PATH");
37-
File lspBundle;
38-
if (devUrl != null) {
39-
lspBundle = new File(devUrl);
40-
} else {
41-
final GitHubReleaseDownloader bundle = new GitHubReleaseDownloader(
42-
Platform.current.lspBundleName,
43-
cookies,
44-
"fabric8-analytics/fabric8-analytics-lsp-server",
45-
false);
46-
lspBundle = bundle.download(indicator);
31+
public void appFrameCreated(@NotNull List<String> commandLineArgs) {
32+
log.info("lsp preload called");
33+
ApplicationManager.getApplication().executeOnPooledThread(() -> {
34+
try {
35+
final String devUrl = System.getenv("ANALYTICS_LSP_FILE_PATH");
36+
File lspBundle;
37+
if (devUrl != null) {
38+
lspBundle = new File(devUrl);
39+
} else {
40+
final GitHubReleaseDownloader bundle = new GitHubReleaseDownloader(
41+
Platform.current.lspBundleName,
42+
cookies,
43+
"fabric8-analytics/fabric8-analytics-lsp-server",
44+
false);
45+
lspBundle = bundle.download();
46+
47+
log.info("lsp binary is ready for use.");
48+
}
49+
attachLanguageClient(lspBundle);
50+
} catch(IOException ex) {
51+
log.warn("lsp download fail", ex);
4752
}
48-
attachLanguageClient(lspBundle);
49-
} catch(IOException ex) {
50-
log.warn("lsp download fail", ex);
51-
}
53+
});
5254
}
5355
}

src/main/java/org/jboss/tools/intellij/stackanalysis/PreloadCli.java

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,64 +10,54 @@
1010
******************************************************************************/
1111
package org.jboss.tools.intellij.stackanalysis;
1212

13+
import com.intellij.ide.AppLifecycleListener;
1314
import com.intellij.openapi.application.ApplicationManager;
14-
import com.intellij.openapi.application.PreloadingActivity;
1515
import com.intellij.openapi.components.ServiceManager;
1616
import com.intellij.openapi.diagnostic.Logger;
1717
import com.intellij.openapi.progress.ProcessCanceledException;
18-
import com.intellij.openapi.progress.ProgressIndicator;
1918
import org.jboss.tools.intellij.analytics.GitHubReleaseDownloader;
2019
import org.jboss.tools.intellij.analytics.ICookie;
2120
import org.jboss.tools.intellij.analytics.Platform;
2221
import org.jboss.tools.intellij.analytics.Settings;
2322
import org.jetbrains.annotations.NotNull;
2423

2524
import java.io.IOException;
25+
import java.util.List;
2626

27-
28-
public final class PreloadCli extends PreloadingActivity {
27+
public final class PreloadCli implements AppLifecycleListener {
2928
private static final Logger logger = Logger.getInstance(PreloadCli.class);
3029
private final ICookie cookies = ServiceManager.getService(Settings.class);
3130

32-
/**
33-
* <p> Activity need to be performed when plugin/IDE is started.</p>
34-
*
35-
* When IDE is started or plugin is installed setup prerequisites for plugin.
36-
*
37-
* @param indicator An object of ProgressIndicator
38-
*/
3931
@Override
40-
public void preload(@NotNull ProgressIndicator indicator) {
41-
if (ApplicationManager.getApplication().isUnitTestMode()) {
42-
return;
43-
}
32+
public void appFrameCreated(@NotNull List<String> commandLineArgs) {
4433
logger.info("CLI preload is called");
45-
46-
try {
47-
// If Env variable is set then use binary file from value given
48-
final String cliPath = System.getenv("CLI_FILE_PATH");
49-
50-
// If Env variable is not set download binary from GitHub Repo
51-
if (cliPath == null) {
52-
final GitHubReleaseDownloader bundle = new GitHubReleaseDownloader(
53-
Platform.current.cliTarBallName,
54-
cookies,
55-
"fabric8-analytics/cli-tools",
56-
true);
57-
58-
// Download the CLI tarball
59-
bundle.download(indicator);
60-
61-
// Extract tar file to get CLI Binary
62-
new SaUtils().unTarBundle(Platform.current.cliTarBallName, Cli.current.cliBinaryName);
63-
logger.info("CLI binary is ready for use.");
34+
ApplicationManager.getApplication().executeOnPooledThread(() -> {
35+
try {
36+
// If Env variable is set then use binary file from value given
37+
final String cliPath = System.getenv("CLI_FILE_PATH");
38+
39+
// If Env variable is not set download binary from GitHub Repo
40+
if (cliPath == null) {
41+
final GitHubReleaseDownloader bundle = new GitHubReleaseDownloader(
42+
Platform.current.cliTarBallName,
43+
cookies,
44+
"fabric8-analytics/cli-tools",
45+
true);
46+
47+
// Download the CLI tarball
48+
bundle.download();
49+
50+
// Extract tar file to get CLI Binary
51+
new SaUtils().unTarBundle(Platform.current.cliTarBallName, Cli.current.cliBinaryName);
52+
logger.info("CLI binary is ready for use.");
53+
}
54+
55+
// Authenticate user
56+
new SaProcessExecutor().authenticateUser();
57+
} catch(IOException | InterruptedException e) {
58+
logger.warn(e);
59+
throw new ProcessCanceledException(e);
6460
}
65-
66-
// Authenticate user
67-
new SaProcessExecutor().authenticateUser();
68-
} catch(IOException | InterruptedException e) {
69-
logger.warn(e);
70-
throw new ProcessCanceledException(e);
71-
}
61+
});
7262
}
7363
}

src/main/resources/META-INF/plugin.xml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,22 @@
123123
<depends>com.redhat.devtools.intellij.telemetry</depends>
124124

125125
<extensions defaultExtensionNs="com.intellij">
126+
<!-- register intellijLanguageClient as a Service -->
127+
<applicationService serviceImplementation="org.wso2.lsp4intellij.IntellijLanguageClient"/>
128+
<!-- register a listener on editor events, required for lsp file sync -->
129+
<editorFactoryListener implementation="org.wso2.lsp4intellij.listeners.LSPEditorListener"/>
130+
<fileDocumentManagerListener implementation="org.wso2.lsp4intellij.listeners.LSPFileDocumentManagerListener"/>
131+
<!-- for displaying notifications by lsp -->
132+
<notificationGroup id="lsp" displayType="STICKY_BALLOON"/>
133+
<!-- for displaying the statusbar lsp icon -->
134+
<statusBarWidgetFactory implementation="org.wso2.lsp4intellij.statusbar.LSPServerStatusWidgetFactory"
135+
id="org.wso2.lsp4intellij.statusbar.LSPServerStatusWidgetFactory"
136+
order="first" />
137+
<!-- needed for code diagnostics by lsp -->
126138
<externalAnnotator id="LSPAnnotator-xml" language="XML" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>
127139
<externalAnnotator id="LSPAnnotator-json" language="JSON" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>
128140
<externalAnnotator id="LSPAnnotator-txt" language="TEXT" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>
129-
<preloadingActivity implementation="org.jboss.tools.intellij.analytics.PreloadLanguageServer"
130-
id="org.jboss.tools.intellij.analytics.PostStartupActivity"/>
131-
<preloadingActivity implementation="org.jboss.tools.intellij.stackanalysis.PreloadCli"
132-
id="org.jboss.tools.intellij.analytics.PostStartupCliActivity"/>
141+
133142
<fileEditorProvider implementation="org.jboss.tools.intellij.stackanalysis.SaReportEditorProvider"/>
134143
<editorTabTitleProvider implementation="org.jboss.tools.intellij.stackanalysis.SaEditorTabTitleProvider" order="first"/>
135144
</extensions>
@@ -148,9 +157,20 @@
148157
</group>
149158
</actions>
150159

151-
<application-components>
152-
<component>
153-
<implementation-class>org.wso2.lsp4intellij.IntellijLanguageClient</implementation-class>
154-
</component>
155-
</application-components>
160+
<applicationListeners>
161+
<!-- required for lsp file sync -->
162+
<listener class="org.wso2.lsp4intellij.listeners.VFSListener"
163+
topic="com.intellij.openapi.vfs.VirtualFileListener"/>
164+
<listener class="org.wso2.lsp4intellij.listeners.LSPProjectManagerListener"
165+
topic="com.intellij.openapi.project.ProjectManagerListener"/>
166+
<!-- download the lsp executable, register, and run it-->
167+
<listener class="org.jboss.tools.intellij.analytics.PreloadLanguageServer"
168+
topic="com.intellij.ide.AppLifecycleListener"
169+
activeInTestMode="false"/>
170+
<!-- download the cli executable, extract it, and authenticate with it -->
171+
<listener class="org.jboss.tools.intellij.stackanalysis.PreloadCli"
172+
topic="com.intellij.ide.AppLifecycleListener"
173+
activeInTestMode="false"/>
174+
</applicationListeners>
175+
156176
</idea-plugin>

0 commit comments

Comments
 (0)