1111
1212package org .jboss .tools .intellij .exhort ;
1313
14+ import com .intellij .ide .plugins .PluginManagerCore ;
15+ import com .intellij .openapi .application .ApplicationInfo ;
1416import com .intellij .openapi .components .Service ;
1517import com .intellij .openapi .diagnostic .Logger ;
18+ import com .intellij .openapi .extensions .PluginDescriptor ;
19+ import com .intellij .openapi .extensions .PluginId ;
1620import com .redhat .exhort .Api ;
1721import com .redhat .exhort .api .AnalysisReport ;
1822import com .redhat .exhort .impl .ExhortApi ;
@@ -32,7 +36,7 @@ public final class ApiService {
3236 private static final Logger LOG = Logger .getInstance (ApiService .class );
3337
3438 enum TelemetryKeys {
35- MANIFEST , ECOSYSTEM , PLATFORM ;
39+ MANIFEST , ECOSYSTEM , PLATFORM , RHDA_TOKEN ;
3640
3741 @ Override
3842 public String toString () {
@@ -55,14 +59,14 @@ public Path getStackAnalysis(final String packageManager, final String manifestN
5559 telemetryMsg .property (TelemetryKeys .ECOSYSTEM .toString (), packageManager );
5660 telemetryMsg .property (TelemetryKeys .PLATFORM .toString (), System .getProperty ("os.name" ));
5761 telemetryMsg .property (TelemetryKeys .MANIFEST .toString (), manifestName );
62+ telemetryMsg .property (TelemetryKeys .RHDA_TOKEN .toString (), ApiSettingsState .getInstance ().rhdaToken );
5863
5964 try {
60- ApiSettingsState .getInstance ().setApiOptions ();
61- LOG .info ("Perform stack analysis" );
65+ setRequestProperties (manifestName );
6266 var htmlContent = exhortApi .stackAnalysisHtml (manifestPath );
6367 var tmpFile = Files .createTempFile ("exhort_" , ".html" );
6468 Files .write (tmpFile , htmlContent .get ());
65- LOG . info ( "Finish stack analysis" );
69+
6670 telemetryMsg .send ();
6771 return tmpFile ;
6872
@@ -78,19 +82,18 @@ public AnalysisReport getComponentAnalysis(final String packageManager, final St
7882 telemetryMsg .property (TelemetryKeys .ECOSYSTEM .toString (), packageManager );
7983 telemetryMsg .property (TelemetryKeys .PLATFORM .toString (), System .getProperty ("os.name" ));
8084 telemetryMsg .property (TelemetryKeys .MANIFEST .toString (), manifestName );
85+ telemetryMsg .property (TelemetryKeys .RHDA_TOKEN .toString (), ApiSettingsState .getInstance ().rhdaToken );
8186
8287 try {
83- ApiSettingsState . getInstance (). setApiOptions ( );
88+ setRequestProperties ( manifestName );
8489 CompletableFuture <AnalysisReport > componentReport ;
85- LOG .info ("Perform component analysis" );
8690 if ("go.mod" .equals (manifestName ) || "requirements.txt" .equals (manifestName )) {
8791 var manifestContent = Files .readAllBytes (Paths .get (manifestPath ));
8892 componentReport = exhortApi .componentAnalysis (manifestName , manifestContent );
8993 } else {
9094 componentReport = exhortApi .componentAnalysis (manifestPath );
9195 }
9296 AnalysisReport report = componentReport .get ();
93- LOG .info ("Finish component analysis" );
9497 telemetryMsg .send ();
9598 return report ;
9699 } catch (IOException | InterruptedException | ExecutionException ex ) {
@@ -108,4 +111,104 @@ public AnalysisReport getComponentAnalysis(final String packageManager, final St
108111 }
109112 return null ;
110113 }
114+
115+ private void setRequestProperties (final String manifestName ) {
116+ String ideName = ApplicationInfo .getInstance ().getFullApplicationName ();
117+ PluginDescriptor pluginDescriptor = PluginManagerCore .getPlugin (PluginId .getId ("org.jboss.tools.intellij.analytics" ));
118+ if (pluginDescriptor != null ) {
119+ String pluginName = pluginDescriptor .getName () + " " + pluginDescriptor .getVersion ();
120+ System .setProperty ("RHDA_SOURCE" , ideName + " / " + pluginName );
121+ } else {
122+ System .setProperty ("RHDA_SOURCE" , ideName );
123+ }
124+
125+ ApiSettingsState settings = ApiSettingsState .getInstance ();
126+ System .setProperty ("RHDA_TOKEN" , settings .rhdaToken );
127+
128+ if (settings .mvnPath != null && !settings .mvnPath .isBlank ()) {
129+ System .setProperty ("EXHORT_MVN_PATH" , settings .mvnPath );
130+ } else {
131+ System .clearProperty ("EXHORT_MVN_PATH" );
132+ }
133+ if (settings .javaPath != null && !settings .javaPath .isBlank ()) {
134+ System .setProperty ("JAVA_HOME" , settings .javaPath );
135+ } else {
136+ System .clearProperty ("JAVA_HOME" );
137+ }
138+ if (settings .npmPath != null && !settings .npmPath .isBlank ()) {
139+ System .setProperty ("EXHORT_NPM_PATH" , settings .npmPath );
140+ } else {
141+ System .clearProperty ("EXHORT_NPM_PATH" );
142+ }
143+ if (settings .nodePath != null && !settings .nodePath .isBlank ()) {
144+ System .setProperty ("NODE_HOME" , settings .nodePath );
145+ } else {
146+ System .clearProperty ("NODE_HOME" );
147+ }
148+ if (settings .goPath != null && !settings .goPath .isBlank ()) {
149+ System .setProperty ("EXHORT_GO_PATH" , settings .goPath );
150+ } else {
151+ System .clearProperty ("EXHORT_GO_PATH" );
152+ }
153+ if ("go.mod" .equals (manifestName )) {
154+ if (settings .goMatchManifestVersions ) {
155+ System .setProperty ("MATCH_MANIFEST_VERSIONS" , "true" );
156+ } else {
157+ System .clearProperty ("MATCH_MANIFEST_VERSIONS" );
158+ }
159+ }
160+ if (settings .usePython2 ) {
161+ if (settings .pythonPath != null && !settings .pythonPath .isBlank ()) {
162+ System .setProperty ("EXHORT_PYTHON_PATH" , settings .pythonPath );
163+ } else {
164+ System .clearProperty ("EXHORT_PYTHON_PATH" );
165+ }
166+ if (settings .pipPath != null && !settings .pipPath .isBlank ()) {
167+ System .setProperty ("EXHORT_PIP_PATH" , settings .pipPath );
168+ } else {
169+ System .clearProperty ("EXHORT_PIP_PATH" );
170+ }
171+ System .clearProperty ("EXHORT_PYTHON3_PATH" );
172+ System .clearProperty ("EXHORT_PIP3_PATH" );
173+ } else {
174+ if (settings .pythonPath != null && !settings .pythonPath .isBlank ()) {
175+ System .setProperty ("EXHORT_PYTHON3_PATH" , settings .pythonPath );
176+ } else {
177+ System .clearProperty ("EXHORT_PYTHON3_PATH" );
178+ }
179+ if (settings .pipPath != null && !settings .pipPath .isBlank ()) {
180+ System .setProperty ("EXHORT_PIP3_PATH" , settings .pipPath );
181+ } else {
182+ System .clearProperty ("EXHORT_PIP3_PATH" );
183+ }
184+ System .clearProperty ("EXHORT_PYTHON_PATH" );
185+ System .clearProperty ("EXHORT_PIP_PATH" );
186+ }
187+ if (settings .usePythonVirtualEnv ) {
188+ System .setProperty ("EXHORT_PYTHON_VIRTUAL_ENV" , "true" );
189+ if (settings .pythonInstallBestEfforts ) {
190+ System .setProperty ("EXHORT_PYTHON_INSTALL_BEST_EFFORTS" , "true" );
191+ } else {
192+ System .clearProperty ("EXHORT_PYTHON_INSTALL_BEST_EFFORTS" );
193+ }
194+ } else {
195+ System .clearProperty ("EXHORT_PYTHON_VIRTUAL_ENV" );
196+ System .clearProperty ("EXHORT_PYTHON_INSTALL_BEST_EFFORTS" );
197+ }
198+ if ("requirements.txt" .equals (manifestName )) {
199+ if (settings .pythonMatchManifestVersions ) {
200+ System .setProperty ("MATCH_MANIFEST_VERSIONS" , "true" );
201+ } else {
202+ System .clearProperty ("MATCH_MANIFEST_VERSIONS" );
203+ }
204+ }
205+ if (!"go.mod" .equals (manifestName ) && !"requirements.txt" .equals (manifestName )) {
206+ System .clearProperty ("MATCH_MANIFEST_VERSIONS" );
207+ }
208+ if (settings .snykToken != null && !settings .snykToken .isBlank ()) {
209+ System .setProperty ("EXHORT_SNYK_TOKEN" , settings .snykToken );
210+ } else {
211+ System .clearProperty ("EXHORT_SNYK_TOKEN" );
212+ }
213+ }
111214}
0 commit comments