Skip to content

Commit

Permalink
fix: version 2022.3 breaks by marking PreloadingActivity for internal…
Browse files Browse the repository at this point in the history
… usage

Signed-off-by: Tomer Figenblat <[email protected]>
  • Loading branch information
TomerFi committed Mar 27, 2023
1 parent b3b58d6 commit 3f6ba37
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.File;
import java.io.IOException;

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


public File download(final ProgressIndicator indicator) throws IOException {
public File download() throws IOException {
final ActionMessage telemetry;
final String latestReleaseTag;
final File dest = new File(Platform.pluginDirectory, fileName);
Expand Down Expand Up @@ -72,7 +72,7 @@ public File download(final ProgressIndicator indicator) throws IOException {
HttpRequests
.request(url)
.productNameAsUserAgent()
.saveToFile(dest, indicator);
.saveToFile(dest, ProgressManager.getGlobalProgressIndicator());

dest.setExecutable(true);
cookies.setValue(cookieName, latestReleaseTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import java.io.File;
import java.io.IOException;
import java.util.List;

import com.intellij.ide.AppLifecycleListener;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PreloadingActivity;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.components.ServiceManager;
import org.jetbrains.annotations.NotNull;
import org.wso2.lsp4intellij.IntellijLanguageClient;

public final class PreloadLanguageServer extends PreloadingActivity {
public final class PreloadLanguageServer implements AppLifecycleListener {
private static final Logger log = Logger.getInstance(PreloadLanguageServer.class);
private final ICookie cookies = ServiceManager.getService(Settings.class);

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

@Override
public void preload(ProgressIndicator indicator) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
log.debug("lsp preload called");
try {
final String devUrl = System.getenv("ANALYTICS_LSP_FILE_PATH");
File lspBundle;
if (devUrl != null) {
lspBundle = new File(devUrl);
} else {
final GitHubReleaseDownloader bundle = new GitHubReleaseDownloader(
Platform.current.lspBundleName,
cookies,
"fabric8-analytics/fabric8-analytics-lsp-server",
false);
lspBundle = bundle.download(indicator);
public void appFrameCreated(@NotNull List<String> commandLineArgs) {
log.info("lsp preload called");
ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
final String devUrl = System.getenv("ANALYTICS_LSP_FILE_PATH");
File lspBundle;
if (devUrl != null) {
lspBundle = new File(devUrl);
} else {
final GitHubReleaseDownloader bundle = new GitHubReleaseDownloader(
Platform.current.lspBundleName,
cookies,
"fabric8-analytics/fabric8-analytics-lsp-server",
false);
lspBundle = bundle.download();

log.info("lsp binary is ready for use.");
}
attachLanguageClient(lspBundle);
} catch(IOException ex) {
log.warn("lsp download fail", ex);
}
attachLanguageClient(lspBundle);
} catch(IOException ex) {
log.warn("lsp download fail", ex);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,54 @@
******************************************************************************/
package org.jboss.tools.intellij.stackanalysis;

import com.intellij.ide.AppLifecycleListener;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PreloadingActivity;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import org.jboss.tools.intellij.analytics.GitHubReleaseDownloader;
import org.jboss.tools.intellij.analytics.ICookie;
import org.jboss.tools.intellij.analytics.Platform;
import org.jboss.tools.intellij.analytics.Settings;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.List;


public final class PreloadCli extends PreloadingActivity {
public final class PreloadCli implements AppLifecycleListener {
private static final Logger logger = Logger.getInstance(PreloadCli.class);
private final ICookie cookies = ServiceManager.getService(Settings.class);

/**
* <p> Activity need to be performed when plugin/IDE is started.</p>
*
* When IDE is started or plugin is installed setup prerequisites for plugin.
*
* @param indicator An object of ProgressIndicator
*/
@Override
public void preload(@NotNull ProgressIndicator indicator) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
public void appFrameCreated(@NotNull List<String> commandLineArgs) {
logger.info("CLI preload is called");

try {
// If Env variable is set then use binary file from value given
final String cliPath = System.getenv("CLI_FILE_PATH");

// If Env variable is not set download binary from GitHub Repo
if (cliPath == null) {
final GitHubReleaseDownloader bundle = new GitHubReleaseDownloader(
Platform.current.cliTarBallName,
cookies,
"fabric8-analytics/cli-tools",
true);

// Download the CLI tarball
bundle.download(indicator);

// Extract tar file to get CLI Binary
new SaUtils().unTarBundle(Platform.current.cliTarBallName, Cli.current.cliBinaryName);
logger.info("CLI binary is ready for use.");
ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
// If Env variable is set then use binary file from value given
final String cliPath = System.getenv("CLI_FILE_PATH");

// If Env variable is not set download binary from GitHub Repo
if (cliPath == null) {
final GitHubReleaseDownloader bundle = new GitHubReleaseDownloader(
Platform.current.cliTarBallName,
cookies,
"fabric8-analytics/cli-tools",
true);

// Download the CLI tarball
bundle.download();

// Extract tar file to get CLI Binary
new SaUtils().unTarBundle(Platform.current.cliTarBallName, Cli.current.cliBinaryName);
logger.info("CLI binary is ready for use.");
}

// Authenticate user
new SaProcessExecutor().authenticateUser();
} catch(IOException | InterruptedException e) {
logger.warn(e);
throw new ProcessCanceledException(e);
}

// Authenticate user
new SaProcessExecutor().authenticateUser();
} catch(IOException | InterruptedException e) {
logger.warn(e);
throw new ProcessCanceledException(e);
}
});
}
}
38 changes: 29 additions & 9 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,22 @@
<depends>com.redhat.devtools.intellij.telemetry</depends>

<extensions defaultExtensionNs="com.intellij">
<!-- register intellijLanguageClient as a Service -->
<applicationService serviceImplementation="org.wso2.lsp4intellij.IntellijLanguageClient"/>
<!-- register a listener on editor events, required for lsp file sync -->
<editorFactoryListener implementation="org.wso2.lsp4intellij.listeners.LSPEditorListener"/>
<fileDocumentManagerListener implementation="org.wso2.lsp4intellij.listeners.LSPFileDocumentManagerListener"/>
<!-- for displaying notifications by lsp -->
<notificationGroup id="lsp" displayType="STICKY_BALLOON"/>
<!-- for displaying the statusbar lsp icon -->
<statusBarWidgetFactory implementation="org.wso2.lsp4intellij.statusbar.LSPServerStatusWidgetFactory"
id="org.wso2.lsp4intellij.statusbar.LSPServerStatusWidgetFactory"
order="first" />
<!-- needed for code diagnostics by lsp -->
<externalAnnotator id="LSPAnnotator-xml" language="XML" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>
<externalAnnotator id="LSPAnnotator-json" language="JSON" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>
<externalAnnotator id="LSPAnnotator-txt" language="TEXT" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>
<preloadingActivity implementation="org.jboss.tools.intellij.analytics.PreloadLanguageServer"
id="org.jboss.tools.intellij.analytics.PostStartupActivity"/>
<preloadingActivity implementation="org.jboss.tools.intellij.stackanalysis.PreloadCli"
id="org.jboss.tools.intellij.analytics.PostStartupCliActivity"/>

<fileEditorProvider implementation="org.jboss.tools.intellij.stackanalysis.SaReportEditorProvider"/>
<editorTabTitleProvider implementation="org.jboss.tools.intellij.stackanalysis.SaEditorTabTitleProvider" order="first"/>
</extensions>
Expand All @@ -148,9 +157,20 @@
</group>
</actions>

<application-components>
<component>
<implementation-class>org.wso2.lsp4intellij.IntellijLanguageClient</implementation-class>
</component>
</application-components>
<applicationListeners>
<!-- required for lsp file sync -->
<listener class="org.wso2.lsp4intellij.listeners.VFSListener"
topic="com.intellij.openapi.vfs.VirtualFileListener"/>
<listener class="org.wso2.lsp4intellij.listeners.LSPProjectManagerListener"
topic="com.intellij.openapi.project.ProjectManagerListener"/>
<!-- download the lsp executable, register, and run it-->
<listener class="org.jboss.tools.intellij.analytics.PreloadLanguageServer"
topic="com.intellij.ide.AppLifecycleListener"
activeInTestMode="false"/>
<!-- download the cli executable, extract it, and authenticate with it -->
<listener class="org.jboss.tools.intellij.stackanalysis.PreloadCli"
topic="com.intellij.ide.AppLifecycleListener"
activeInTestMode="false"/>
</applicationListeners>

</idea-plugin>

0 comments on commit 3f6ba37

Please sign in to comment.