Skip to content

Commit 0318771

Browse files
authored
feat: use new backend for java pom manifests stack analysis (#118)
Signed-off-by: Tomer Figenblat <tfigenbl@redhat.com>
1 parent acbba34 commit 0318771

8 files changed

Lines changed: 124 additions & 12 deletions

File tree

.github/workflows/IJ-latest.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name: Latest IJ
66
on:
77
schedule:
88
- cron: "0 0 * * *"
9-
9+
1010
jobs:
1111

1212
build:
@@ -23,7 +23,12 @@ jobs:
2323
- name: Grant execute permission for gradlew
2424
run: chmod +x gradlew
2525
- name: Build with Gradle
26-
run: ./gradlew build --continue -PideaVersion=LATEST-EAP-SNAPSHOT
26+
run: >
27+
./gradlew build
28+
--continue
29+
-PideaVersion=LATEST-EAP-SNAPSHOT
30+
-Pgpr.username=${{ github.actor }}
31+
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
2732
- uses: actions/upload-artifact@v2
2833
if: always()
2934
with:

.github/workflows/IJ.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ jobs:
2727
- name: Grant execute permission for gradlew
2828
run: chmod +x gradlew
2929
- name: Build with Gradle
30-
run: ./gradlew buildPlugin -PideaVersion=${{ matrix.IJ }}
30+
run: >
31+
./gradlew buildPlugin
32+
-PideaVersion=${{ matrix.IJ }}
33+
-Pgpr.username=${{ github.actor }}
34+
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
3135
3236
verify:
3337
runs-on: ubuntu-latest
@@ -44,7 +48,11 @@ jobs:
4448
- name: Grant execute permission for gradlew
4549
run: chmod +x gradlew
4650
- name: Build with Gradle
47-
run: ./gradlew runPluginVerifier -PideaVersion=IC-2022.1
51+
run: >
52+
./gradlew runPluginVerifier
53+
-PideaVersion=IC-2022.1
54+
-Pgpr.username=${{ github.actor }}
55+
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
4856
- name: Upload report
4957
uses: actions/upload-artifact@v2
5058
if: always()

.github/workflows/ci.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ jobs:
2424
- name: Grant execute permission for gradlew
2525
run: chmod +x gradlew
2626
- name: Build with Gradle
27-
run: ./gradlew test
27+
run: >
28+
./gradlew test
29+
-Pgpr.username=${{ github.actor }}
30+
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
2831
2932
build-macos:
3033
runs-on: macos-latest
@@ -40,7 +43,10 @@ jobs:
4043
- name: Grant execute permission for gradlew
4144
run: chmod +x gradlew
4245
- name: Build with Gradle
43-
run: ./gradlew test
46+
run: >
47+
./gradlew test
48+
-Pgpr.username=${{ github.actor }}
49+
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
4450
4551
build-windows:
4652
runs-on: windows-latest
@@ -56,5 +62,7 @@ jobs:
5662
- name: Grant execute permission for gradlew
5763
run: chmod +x gradlew
5864
- name: Build with Gradle
65+
env:
66+
GITHUB_USERNAME: ${{ github.actor }}
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5968
run: ./gradlew test
60-

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ jobs:
1717
- name: Grant execute permission for gradlew
1818
run: chmod +x gradlew
1919
- name: Build with Gradle
20-
run: ./gradlew buildPlugin
20+
run: >
21+
./gradlew buildPlugin
22+
-Pgpr.username=${{ github.actor }}
23+
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
2124
- name: Get the version
2225
id: get_version
2326
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}

.github/workflows/stage.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ jobs:
2626
- name: Build plugin with Gradle
2727
uses: gradle/gradle-build-action@v2
2828
with:
29-
arguments: buildPlugin
29+
arguments: |
30+
buildPlugin
31+
-Pgpr.username=${{ github.actor }}
32+
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
3033
3134
- name: Upload distribution archive as artifact
3235
uses: actions/upload-artifact@v3

build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ repositories {
99
dirs buildDir
1010
}
1111
maven { url 'https://jitpack.io' }
12+
maven {
13+
url 'https://maven.pkg.github.com/RHEcosystemAppEng/crda-java-api'
14+
credentials {
15+
username = project.findProperty("gpr.username") ?: System.getenv("GITHUB_USERNAME")
16+
password = project.findProperty("gpr.token") ?: System.getenv("GITHUB_TOKEN")
17+
}
18+
}
1219
}
1320

1421
apply plugin: 'idea'
@@ -48,6 +55,7 @@ dependencies {
4855
}
4956
implementation 'org.kohsuke:github-api:1.314'
5057
implementation 'org.apache.commons:commons-compress:1.21'
58+
implementation 'com.redhat.crda:crda-java-api:0.0.1-SNAPSHOT'
5159
testImplementation('junit:junit:4.13.1')
5260
}
5361

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.jboss.tools.intellij.crda;
2+
3+
import com.intellij.openapi.components.Service;
4+
import com.redhat.crda.Api;
5+
import com.redhat.crda.impl.CrdaApi;
6+
import com.redhat.crda.tools.Ecosystem;
7+
import org.jboss.tools.intellij.analytics.TelemetryService;
8+
9+
import java.io.IOException;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.util.concurrent.ExecutionException;
13+
14+
@Service(Service.Level.PROJECT)
15+
public final class ApiService {
16+
enum TelemetryKeys {
17+
MANIFEST, ECOSYSTEM, PLATFORM;
18+
19+
@Override
20+
public String toString() {
21+
return this.name().toLowerCase();
22+
}
23+
}
24+
25+
private final Api crdaApi;
26+
27+
public ApiService() {
28+
this(new CrdaApi());
29+
}
30+
31+
ApiService(Api crdaApi) {
32+
this.crdaApi = crdaApi;
33+
}
34+
35+
public Path getStackAnalysis(
36+
final Ecosystem.PackageManager packageManager,
37+
final String manifestName,
38+
final String manifestPath
39+
) throws RuntimeException {
40+
41+
var telemetryMsg = TelemetryService.instance().action("stack-analysis");
42+
telemetryMsg.property(TelemetryKeys.ECOSYSTEM.toString(), packageManager.toString());
43+
telemetryMsg.property(TelemetryKeys.PLATFORM.toString(), System.getProperty("os.name"));
44+
telemetryMsg.property(TelemetryKeys.MANIFEST.toString(), manifestName);
45+
46+
try {
47+
var htmlContent = crdaApi.stackAnalysisHtmlAsync(manifestPath);
48+
var tmpFile = Files.createTempFile("crda_", ".html");
49+
Files.write(tmpFile, htmlContent.get());
50+
51+
telemetryMsg.send();
52+
return tmpFile;
53+
54+
} catch (IOException | InterruptedException | ExecutionException exc) {
55+
telemetryMsg.error(exc);
56+
telemetryMsg.send();
57+
throw new RuntimeException(exc);
58+
}
59+
}
60+
}

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@
1616
import com.intellij.openapi.actionSystem.AnAction;
1717
import com.intellij.openapi.actionSystem.PlatformDataKeys;
1818
import com.intellij.openapi.actionSystem.CommonDataKeys;
19+
import com.intellij.openapi.components.ServiceManager;
1920
import com.intellij.openapi.diagnostic.Logger;
2021
import com.intellij.openapi.fileEditor.FileEditorManager;
2122
import com.intellij.openapi.ui.Messages;
2223
import com.intellij.openapi.vfs.VirtualFile;
2324
import com.intellij.psi.PsiFile;
2425

26+
import org.jboss.tools.intellij.crda.ApiService;
27+
import com.redhat.crda.tools.Ecosystem;
2528
import org.jboss.tools.intellij.analytics.Platform;
2629
import org.jetbrains.annotations.NotNull;
2730

28-
2931
public class SaAction extends AnAction {
3032
private static final Logger logger = Logger.getInstance(SaAction.class);
3133

34+
private final ApiService apiService;
35+
36+
public SaAction() {
37+
apiService = ServiceManager.getService(ApiService.class);
38+
}
39+
3240
/**
3341
* <p>Intellij Plugin Action implementation for triggering SA.</p>
3442
*
@@ -43,15 +51,24 @@ public void actionPerformed(@NotNull AnActionEvent event) {
4351
VirtualFile manifestFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
4452

4553
// Get SA report for given manifest file.
46-
JsonObject saReportJson = saUtils.getReport(manifestFile.getPath());
54+
String reportLink;
55+
if ("pom.xml".equals(manifestFile.getName())) {
56+
reportLink = apiService.getStackAnalysis(
57+
Ecosystem.PackageManager.MAVEN,
58+
manifestFile.getName(),
59+
manifestFile.getPath()
60+
).toUri().toString();
61+
} else {
62+
reportLink = saUtils.getReport(manifestFile.getPath()).get("report_link").getAsString();
63+
}
4764

4865
// Manifest file details to be saved in temp file which will be used while opening Report tab
4966
JsonObject manifestDetails = new JsonObject();
5067
manifestDetails.addProperty("showParent", false);
5168
manifestDetails.addProperty("manifestName", manifestFile.getName());
5269
manifestDetails.addProperty("manifestPath", manifestFile.getPath());
5370
manifestDetails.addProperty("manifestFileParent", manifestFile.getParent().getName());
54-
manifestDetails.addProperty("report_link", saReportJson.get("report_link").getAsString());
71+
manifestDetails.addProperty("report_link", reportLink);
5572
manifestDetails.addProperty("manifestNameWithoutExtension", manifestFile.getNameWithoutExtension());
5673

5774
// Open custom editor window which will load SA Report in browser attached to it.

0 commit comments

Comments
 (0)