From 9c79c7ef712bce87224014fb04c472e174584763 Mon Sep 17 00:00:00 2001 From: Tomer Figenblat Date: Mon, 29 May 2023 10:50:37 +0300 Subject: [PATCH] feat: use new backend for java pom manifests stack analysis Signed-off-by: Tomer Figenblat --- .github/workflows/IJ-latest.yml | 9 ++- .github/workflows/IJ.yml | 12 +++- .github/workflows/ci.yml | 14 ++++- .github/workflows/release.yml | 5 +- .github/workflows/stage.yml | 5 +- build.gradle | 8 +++ .../jboss/tools/intellij/crda/ApiService.java | 60 +++++++++++++++++++ .../intellij/stackanalysis/SaAction.java | 23 ++++++- 8 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/jboss/tools/intellij/crda/ApiService.java diff --git a/.github/workflows/IJ-latest.yml b/.github/workflows/IJ-latest.yml index ef7c6e8..c54be67 100644 --- a/.github/workflows/IJ-latest.yml +++ b/.github/workflows/IJ-latest.yml @@ -6,7 +6,7 @@ name: Latest IJ on: schedule: - cron: "0 0 * * *" - + jobs: build: @@ -23,7 +23,12 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew build --continue -PideaVersion=LATEST-EAP-SNAPSHOT + run: > + ./gradlew build + --continue + -PideaVersion=LATEST-EAP-SNAPSHOT + -Pgpr.username=${{ github.actor }} + -Pgpr.token=${{ secrets.GITHUB_TOKEN }} - uses: actions/upload-artifact@v2 if: always() with: diff --git a/.github/workflows/IJ.yml b/.github/workflows/IJ.yml index e0515a4..9a4718e 100644 --- a/.github/workflows/IJ.yml +++ b/.github/workflows/IJ.yml @@ -27,7 +27,11 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew buildPlugin -PideaVersion=${{ matrix.IJ }} + run: > + ./gradlew buildPlugin + -PideaVersion=${{ matrix.IJ }} + -Pgpr.username=${{ github.actor }} + -Pgpr.token=${{ secrets.GITHUB_TOKEN }} verify: runs-on: ubuntu-latest @@ -44,7 +48,11 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew runPluginVerifier -PideaVersion=IC-2022.1 + run: > + ./gradlew runPluginVerifier + -PideaVersion=IC-2022.1 + -Pgpr.username=${{ github.actor }} + -Pgpr.token=${{ secrets.GITHUB_TOKEN }} - name: Upload report uses: actions/upload-artifact@v2 if: always() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f4aa7a..1db5938 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,10 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew test + run: > + ./gradlew test + -Pgpr.username=${{ github.actor }} + -Pgpr.token=${{ secrets.GITHUB_TOKEN }} build-macos: runs-on: macos-latest @@ -40,7 +43,10 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew test + run: > + ./gradlew test + -Pgpr.username=${{ github.actor }} + -Pgpr.token=${{ secrets.GITHUB_TOKEN }} build-windows: runs-on: windows-latest @@ -56,5 +62,7 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle + env: + GITHUB_USERNAME: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: ./gradlew test - diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c369def..eba296a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,10 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew buildPlugin + run: > + ./gradlew buildPlugin + -Pgpr.username=${{ github.actor }} + -Pgpr.token=${{ secrets.GITHUB_TOKEN }} - name: Get the version id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index 69dfad5..bf958cd 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -26,7 +26,10 @@ jobs: - name: Build plugin with Gradle uses: gradle/gradle-build-action@v2 with: - arguments: buildPlugin + arguments: | + buildPlugin + -Pgpr.username=${{ github.actor }} + -Pgpr.token=${{ secrets.GITHUB_TOKEN }} - name: Upload distribution archive as artifact uses: actions/upload-artifact@v3 diff --git a/build.gradle b/build.gradle index 1479f4d..b48425b 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,13 @@ repositories { dirs buildDir } maven { url 'https://jitpack.io' } + maven { + url 'https://maven.pkg.github.com/RHEcosystemAppEng/crda-java-api' + credentials { + username = project.findProperty("gpr.username") ?: System.getenv("GITHUB_USERNAME") + password = project.findProperty("gpr.token") ?: System.getenv("GITHUB_TOKEN") + } + } } apply plugin: 'idea' @@ -48,6 +55,7 @@ dependencies { } implementation 'org.kohsuke:github-api:1.314' implementation 'org.apache.commons:commons-compress:1.21' + implementation 'com.redhat.crda:crda-java-api:0.0.1-SNAPSHOT' testImplementation('junit:junit:4.13.1') } diff --git a/src/main/java/org/jboss/tools/intellij/crda/ApiService.java b/src/main/java/org/jboss/tools/intellij/crda/ApiService.java new file mode 100644 index 0000000..e517aac --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/crda/ApiService.java @@ -0,0 +1,60 @@ +package org.jboss.tools.intellij.crda; + +import com.intellij.openapi.components.Service; +import com.redhat.crda.Api; +import com.redhat.crda.impl.CrdaApi; +import com.redhat.crda.tools.Ecosystem; +import org.jboss.tools.intellij.analytics.TelemetryService; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.ExecutionException; + +@Service(Service.Level.PROJECT) +public final class ApiService { + enum TelemetryKeys { + MANIFEST, ECOSYSTEM, PLATFORM; + + @Override + public String toString() { + return this.name().toLowerCase(); + } + } + + private final Api crdaApi; + + public ApiService() { + this(new CrdaApi()); + } + + ApiService(Api crdaApi) { + this.crdaApi = crdaApi; + } + + public Path getStackAnalysis( + final Ecosystem.PackageManager packageManager, + final String manifestName, + final String manifestPath + ) throws RuntimeException { + + var telemetryMsg = TelemetryService.instance().action("stack-analysis"); + telemetryMsg.property(TelemetryKeys.ECOSYSTEM.toString(), packageManager.toString()); + telemetryMsg.property(TelemetryKeys.PLATFORM.toString(), System.getProperty("os.name")); + telemetryMsg.property(TelemetryKeys.MANIFEST.toString(), manifestName); + + try { + var htmlContent = crdaApi.stackAnalysisHtmlAsync(manifestPath); + var tmpFile = Files.createTempFile("crda_", ".html"); + Files.write(tmpFile, htmlContent.get()); + + telemetryMsg.send(); + return tmpFile; + + } catch (IOException | InterruptedException | ExecutionException exc) { + telemetryMsg.error(exc); + telemetryMsg.send(); + throw new RuntimeException(exc); + } + } +} diff --git a/src/main/java/org/jboss/tools/intellij/stackanalysis/SaAction.java b/src/main/java/org/jboss/tools/intellij/stackanalysis/SaAction.java index 14e0520..e1bd831 100644 --- a/src/main/java/org/jboss/tools/intellij/stackanalysis/SaAction.java +++ b/src/main/java/org/jboss/tools/intellij/stackanalysis/SaAction.java @@ -16,19 +16,27 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; +import org.jboss.tools.intellij.crda.ApiService; +import com.redhat.crda.tools.Ecosystem; import org.jboss.tools.intellij.analytics.Platform; import org.jetbrains.annotations.NotNull; - public class SaAction extends AnAction { private static final Logger logger = Logger.getInstance(SaAction.class); + private final ApiService apiService; + + public SaAction() { + apiService = ServiceManager.getService(ApiService.class); + } + /** *

Intellij Plugin Action implementation for triggering SA.

* @@ -43,7 +51,16 @@ public void actionPerformed(@NotNull AnActionEvent event) { VirtualFile manifestFile = event.getData(PlatformDataKeys.VIRTUAL_FILE); // Get SA report for given manifest file. - JsonObject saReportJson = saUtils.getReport(manifestFile.getPath()); + String reportLink; + if ("pom.xml".equals(manifestFile.getName())) { + reportLink = apiService.getStackAnalysis( + Ecosystem.PackageManager.MAVEN, + manifestFile.getName(), + manifestFile.getPath() + ).toUri().toString(); + } else { + reportLink = saUtils.getReport(manifestFile.getPath()).get("report_link").getAsString(); + } // Manifest file details to be saved in temp file which will be used while opening Report tab JsonObject manifestDetails = new JsonObject(); @@ -51,7 +68,7 @@ public void actionPerformed(@NotNull AnActionEvent event) { manifestDetails.addProperty("manifestName", manifestFile.getName()); manifestDetails.addProperty("manifestPath", manifestFile.getPath()); manifestDetails.addProperty("manifestFileParent", manifestFile.getParent().getName()); - manifestDetails.addProperty("report_link", saReportJson.get("report_link").getAsString()); + manifestDetails.addProperty("report_link", reportLink); manifestDetails.addProperty("manifestNameWithoutExtension", manifestFile.getNameWithoutExtension()); // Open custom editor window which will load SA Report in browser attached to it.