forked from redhat-developer/intellij-dependency-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSAIntentionAction.java
More file actions
78 lines (69 loc) · 2.92 KB
/
Copy pathSAIntentionAction.java
File metadata and controls
78 lines (69 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
* Copyright (c) 2023 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.componentanalysis;
import com.google.gson.JsonObject;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.util.IntentionFamilyName;
import com.intellij.codeInspection.util.IntentionName;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jboss.tools.intellij.report.AnalyticsReportUtils;
import org.jboss.tools.intellij.stackanalysis.SaUtils;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public class SAIntentionAction implements IntentionAction {
@Override
public @IntentionName @NotNull String getText() {
return "Detailed Vulnerability Report";
}
@Override
public @NotNull @IntentionFamilyName String getFamilyName() {
return "RHDA";
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (file == null) {
return false;
}
return "pom.xml".equals(file.getName())
|| "package.json".equals(file.getName())
|| "go.mod".equals(file.getName())
|| "requirements.txt".equals(file.getName())
|| "build.gradle".equals(file.getName())
|| "build.gradle.kts".equals(file.getName())
|| "Cargo.toml".equals(file.getName())
|| "pyproject.toml".equals(file.getName());
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
SaUtils saUtils = new SaUtils();
VirtualFile vf = file.getVirtualFile();
if (vf != null) {
JsonObject manifestDetails = saUtils.performSA(vf);
if (manifestDetails != null) {
try {
AnalyticsReportUtils analyticsReportUtils = new AnalyticsReportUtils();
analyticsReportUtils.openCustomEditor(FileEditorManager.getInstance(project), manifestDetails, project);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
@Override
public boolean startInWriteAction() {
return false;
}
}