Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew test

build-macos:
runs-on: macos-latest
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew test

build-windows:
runs-on: windows-latest
Expand All @@ -50,5 +50,5 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew test

7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
'Dependency Analytics' plugin supports projects using Maven, projects build on npm (Node ecosystem) and projects using Python.
Extending support for Golang and other languages is currently under progress.

## Prerequisites

This extension assumes you have the following binaries on your `PATH`:

- `node`


> **NOTE** Dependency Analytics is an online service hosted and maintained by Red Hat. This open source software will access only your manifests file(s) to learn about application dependencies before giving you the report.

## Quick Start
Expand Down
23 changes: 3 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

plugins {
id "org.jetbrains.intellij" version "0.4.21"
id 'de.undercouch.download' version '3.4.3'
}

repositories {
Expand Down Expand Up @@ -34,27 +33,11 @@ publishPlugin {
//LSP plugin causes this task to fail
buildSearchableOptions.enabled = false

task downloadFile(type: Download) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The download plugin must be removed as well

src 'https://github.com/fabric8-analytics/fabric8-analytics-lsp-server/releases/download/v0.4.20/ca-lsp-server.tar'
dest new File(buildDir, 'server.tgz')
overwrite false
}

task downloadAndUnzipFile(dependsOn: downloadFile, type: Copy) {
from tarTree(resources.bzip2(downloadFile.dest))
into new File(buildDir, 'server/server')
}

prepareSandbox {
dependsOn downloadAndUnzipFile
}

dependencies {
compile files(new File(buildDir, 'server')) {
builtBy 'downloadAndUnzipFile'
}
implementation 'com.github.ballerina-platform:lsp4intellij:master-SNAPSHOT'
implementation 'org.kohsuke:github-api:1.119'
testImplementation("junit:junit:4.12")
}

group 'org.jboss.tools.intellij'
version projectVersion // Plugin version
version projectVersion // Plugin version
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.jboss.tools.intellij.analytics;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.RoamingType;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;

@Service
@State(
name = "AnalyticsPersistentSettings",
storages = {
@Storage(file = "analytics.settings.xml", roamingType = RoamingType.DISABLED)
})
public final class AnalyticsPersistentSettings implements PersistentStateComponent<AnalyticsPersistentSettings> {

private String lspVersion;

@Override
public AnalyticsPersistentSettings getState() {
return this;
}

@Override
public void loadState(AnalyticsPersistentSettings state) {
XmlSerializerUtil.copyBean(state, this);
}

public void setLSPVersion(final String version) {
this.lspVersion = version;
}

public String getLSPVersion() {
return this.lspVersion;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.jboss.tools.intellij.analytics;

import org.kohsuke.github.GitHub;
import org.kohsuke.github.GHAsset;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHRelease;
import java.io.IOException;

public class GHReleaseDownloader {
private final GHRepository repo;

public GHReleaseDownloader(final String repository) throws IOException {
final GitHub github = GitHub.connectAnonymously();
this.repo = github.getRepository(repository);
}

public String getLatestRelease() throws IOException {
return this.repo.getLatestRelease().getTagName();
}

public String getDownloadUri(final String releaseLabel, final String fileLabel) throws IOException {
final GHRelease release = this.repo.getReleaseByTagName(releaseLabel);
final GHAsset asset = release.listAssets()
.toList()
.stream()
.filter(a -> a.getLabel().equals(fileLabel))
.findFirst()
.orElseThrow(() -> new IOException(fileLabel + ": unable to download"));
return asset.getBrowserDownloadUrl();
}
}
92 changes: 92 additions & 0 deletions src/main/java/org/jboss/tools/intellij/analytics/LSPBundle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.jboss.tools.intellij.analytics;

import java.io.File;
import java.io.IOException;

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.progress.BackgroundTaskQueue;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.util.io.HttpRequests;

import org.wso2.lsp4intellij.IntellijLanguageClient;

@Service
public final class LSPBundle {
private final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("org.jboss.tools.intellij.analytics"));
private final GHReleaseDownloader downloader;
private File cliFile;
private final BackgroundTaskQueue taskQueue;
private final Project project;

private static final Logger log = Logger.getInstance(LSPBundle.class);

static interface DownloadListener {
void downloadCompleted(final File path);
}

public LSPBundle(final Project project) {
this.project = project;
try {
this.downloader = new GHReleaseDownloader("fabric8-analytics/fabric8-analytics-lsp-server");
} catch (IOException ex) {
throw new LSPBundleException(ex.toString());
}
this.cliFile = new File(descriptor.getPath(), Platform.current.lspBundleName);
this.taskQueue = new BackgroundTaskQueue(project, "Analytics");
}

public File getCliPath() {
return this.cliFile;
}

public void download(final LSPBundle.DownloadListener listener) {
log.debug("download lsp bundle");
taskQueue.run(new Task.Backgroundable(this.project, "Analytics lsp download", true) {
@Override
public void run(final ProgressIndicator indicator) {
try {
log.info("downloading cli " + LSPBundle.this.cliFile);
downloadIfNeeded(indicator);
} catch(IOException ex) {
log.warn("failed to download cli " + LSPBundle.this.cliFile);
return;
}
ApplicationManager.getApplication().invokeAndWait(() -> {
listener.downloadCompleted(LSPBundle.this.cliFile);
});
}
});
}

private boolean isNewRelease(final String releaseLabel) {
final String currentVersion = ServiceManager.getService(AnalyticsPersistentSettings.class).getLSPVersion();
log.info(String.format("lsp version current %s, latest %s", currentVersion, releaseLabel));
return !releaseLabel.equals(currentVersion);
}

public void downloadIfNeeded(final ProgressIndicator indicator) throws IOException {
final String latestReleaseTag = this.downloader.getLatestRelease();
if (!isNewRelease(latestReleaseTag) && cliFile.exists()) {
return;
}
final String devUrl = System.getenv("ANALYTICS_LSP_FILE_PATH");
final String url = this.downloader.getDownloadUri(latestReleaseTag, Platform.current.lspBundleName);
final String actualUrl = devUrl != null ? devUrl : url;
log.info(String.format("url %s", url));
HttpRequests
.request(actualUrl)
.productNameAsUserAgent()
.saveToFile(cliFile, indicator);

cliFile.setExecutable(true);
ServiceManager.getService(AnalyticsPersistentSettings.class).setLSPVersion(latestReleaseTag);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jboss.tools.intellij.analytics;

public class LSPBundleException extends RuntimeException {
public LSPBundleException(String ex) {
super(ex);
}
}

27 changes: 27 additions & 0 deletions src/main/java/org/jboss/tools/intellij/analytics/Platform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jboss.tools.intellij.analytics;

import com.intellij.openapi.util.SystemInfo;

public class Platform {
public String lspBundleName;

private static final Platform WINDOWS = new Platform("analytics-lsp-win.exe");
private static final Platform LINUX = new Platform("analytics-lsp-linux");
private static final Platform MACOS = new Platform("analytics-lsp-macos");

private Platform(String lspBundleName) {
this.lspBundleName = lspBundleName;
}

private static Platform detect() {
if (SystemInfo.isLinux)
return LINUX;
if (SystemInfo.isWindows)
return WINDOWS;
if (SystemInfo.isMac)
return MACOS;
throw new PlatformDetectionException(SystemInfo.OS_NAME + " is not supported");
}

public static final Platform current = detect();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.jboss.tools.intellij.analytics;

public class PlatformDetectionException extends RuntimeException {
public PlatformDetectionException(String ex) {
super(ex);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.jboss.tools.intellij.analytics;

import java.io.File;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.diagnostic.Logger;
import org.wso2.lsp4intellij.IntellijLanguageClient;

public final class PostStartupActivity implements StartupActivity {
private static final Logger log = Logger.getInstance(PostStartupActivity.class);

@Override
public void runActivity(Project project) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}

final LSPBundle.DownloadListener fileDownloadListener = (final File cliFile) -> {
final String[] EXTENSIONS = {"xml", "json", "txt"};
final String[] cmds = {cliFile.toString(), "--stdio"};
for(String ext : EXTENSIONS) {
AnalyticsLanguageServerDefinition serverDefinition = new AnalyticsLanguageServerDefinition(ext, cmds);
IntellijLanguageClient.addServerDefinition(serverDefinition);
IntellijLanguageClient.addExtensionManager(ext, serverDefinition);
}
log.debug("lsp registration done {0}", cliFile);
};

log.debug("runActivity called for analytics with project {0}", project);
project.getService(LSPBundle.class).download(fileDownloadListener);
}
}
5 changes: 1 addition & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@
<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"/>
<postStartupActivity implementation="org.jboss.tools.intellij.analytics.PostStartupActivity"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for having it implemented as application component is that postStartupActivity is delayed and thus if you have opened documents when you open a project, the LSP may not be started.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works. Also intellij doc says application component is deprecated.

https://plugins.jetbrains.com/docs/intellij/plugin-components.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but deprecated does not mean removed. So my concern is that if the file is already opened then seems the LSP is started but I can't see the decorations on the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffmaury I see similar issue even without this change. Can you just try adding a dummy line in the manifest to see whether it could decorate? it is a bug for sure, just want to check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure to understand. If I comment this line out, then LSP won't be started at all. So If this is like before then we're good.

</extensions>

<application-components>
<component>
<interface-class>org.jboss.tools.intellij.analytics.AnalyticsPreloadActivity</interface-class>
<implementation-class>org.jboss.tools.intellij.analytics.AnalyticsPreloadActivity</implementation-class>
</component>
<component>
<implementation-class>org.wso2.lsp4intellij.IntellijLanguageClient</implementation-class>
</component>
Expand Down
Loading