Skip to content

Commit

Permalink
fix: extension settings
Browse files Browse the repository at this point in the history
Signed-off-by: Ilona Shishov <[email protected]>
  • Loading branch information
IlonaShishov committed Dec 19, 2023
1 parent badc749 commit 03fd430
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 65 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,43 +202,43 @@
"description": "Path to a local file where the Red Hat Dependency Analytics report will be saved.",
"scope": "window"
},
"mvn.executable.path": {
"redHatDependencyAnalytics.mvn.executable.path": {
"type": "string",
"default": "",
"description": "Specifies absolute path of mvn executable.",
"scope": "window"
},
"npm.executable.path": {
"redHatDependencyAnalytics.npm.executable.path": {
"type": "string",
"default": "",
"description": "Specifies absolute path of npm executable.",
"scope": "window"
},
"go.executable.path": {
"redHatDependencyAnalytics.go.executable.path": {
"type": "string",
"default": "",
"description": "Specifies absolute path of go executable.",
"scope": "window"
},
"python3.executable.path": {
"redHatDependencyAnalytics.python3.executable.path": {
"type": "string",
"default": "",
"description": "Specifies absolute path of python3 executable, python3 takes precedence over python.",
"scope": "window"
},
"pip3.executable.path": {
"redHatDependencyAnalytics.pip3.executable.path": {
"type": "string",
"default": "",
"description": "Specifies absolute path of pip3 executable, pip3 takes precedence over pip.",
"scope": "window"
},
"python.executable.path": {
"redHatDependencyAnalytics.python.executable.path": {
"type": "string",
"default": "",
"description": "Specifies absolute path of python executable, python3 takes precedence over python.",
"scope": "window"
},
"pip.executable.path": {
"redHatDependencyAnalytics.pip.executable.path": {
"type": "string",
"default": "",
"description": "Specifies absolute path of pip executable, pip3 takes precedence over pip.",
Expand Down Expand Up @@ -284,7 +284,7 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@fabric8-analytics/fabric8-analytics-lsp-server": "^0.8.1-ea.6",
"@fabric8-analytics/fabric8-analytics-lsp-server": "^0.8.1-ea.7",
"@redhat-developer/vscode-redhat-telemetry": "^0.7.0",
"@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.4",
"fs": "^0.0.1-security",
Expand Down
43 changes: 15 additions & 28 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as vscode from 'vscode';

import { GlobalState } from './constants';
import { GlobalState, defaultRhdaReportFilePath } from './constants';
import * as commands from './commands';
import { getTelemetryId } from './redhatTelemetry';

Expand Down Expand Up @@ -35,15 +35,15 @@ class Config {

/**
* Creates an instance of the Config class.
* Initializes the instance with default extension workspace settings.
* Initializes the instance with default extension settings.
*/
constructor() {
this.loadData();
this.setProcessEnv();
}

/**
* Retrieves RHDA configuration settings from the workspace.
* Retrieves RHDA configuration settings.
* @returns The RHDA configuration settings.
* @private
*/
Expand All @@ -52,37 +52,24 @@ class Config {
}

/**
* Retrieves the path for an executable from the workspace.
* @param exe The name of the executable.
* @returns The path of the executable if specified in the workspace configuration, otherwise the default value.
* @private
*/
private getExecutableConfig(exe: string): string {
const exePath: string = vscode.workspace
.getConfiguration(`${exe}.executable`)
.get<string>('path');
return exePath ? exePath : exe;
}

/**
* Loads configuration settings from the workspace.
* Loads configuration settings.
*/
loadData() {
const apiConfig = this.getRhdaConfig();
const rhdaConfig = this.getRhdaConfig();

this.triggerFullStackAnalysis = commands.TRIGGER_FULL_STACK_ANALYSIS;
this.triggerRHRepositoryRecommendationNotification = commands.TRIGGER_REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION;
this.utmSource = GlobalState.UTM_SOURCE;
this.exhortSnykToken = apiConfig.exhortSnykToken;
this.matchManifestVersions = apiConfig.matchManifestVersions ? 'true' : 'false';
this.rhdaReportFilePath = apiConfig.redHatDependencyAnalyticsReportFilePath;
this.exhortMvnPath = this.getExecutableConfig(this.DEFAULT_MVN_EXECUTABLE);
this.exhortNpmPath = this.getExecutableConfig(this.DEFAULT_NPM_EXECUTABLE);
this.exhortGoPath = this.getExecutableConfig(this.DEFAULT_GO_EXECUTABLE);
this.exhortPython3Path = this.getExecutableConfig(this.DEFAULT_PYTHON3_EXECUTABLE);
this.exhortPip3Path = this.getExecutableConfig(this.DEFAULT_PIP3_EXECUTABLE);
this.exhortPythonPath = this.getExecutableConfig(this.DEFAULT_PYTHON_EXECUTABLE);
this.exhortPipPath = this.getExecutableConfig(this.DEFAULT_PIP_EXECUTABLE);
this.exhortSnykToken = rhdaConfig.exhortSnykToken;
this.matchManifestVersions = rhdaConfig.matchManifestVersions ? 'true' : 'false';
this.rhdaReportFilePath = rhdaConfig.redHatDependencyAnalyticsReportFilePath || defaultRhdaReportFilePath;
this.exhortMvnPath = rhdaConfig.mvn.executable.path || this.DEFAULT_MVN_EXECUTABLE;
this.exhortNpmPath = rhdaConfig.npm.executable.path || this.DEFAULT_NPM_EXECUTABLE;
this.exhortGoPath = rhdaConfig.go.executable.path || this.DEFAULT_GO_EXECUTABLE;
this.exhortPython3Path = rhdaConfig.python3.executable.path || this.DEFAULT_PYTHON3_EXECUTABLE;
this.exhortPip3Path = rhdaConfig.pip3.executable.path || this.DEFAULT_PIP3_EXECUTABLE;
this.exhortPythonPath = rhdaConfig.python.executable.path || this.DEFAULT_PYTHON_EXECUTABLE;
this.exhortPipPath = rhdaConfig.pip.executable.path || this.DEFAULT_PIP_EXECUTABLE;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/dependencyReportPanel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';

import * as templates from './template';
import { Titles, defaultRhdaReportFilePath } from './constants';
import { Titles } from './constants';
import { globalConfig } from './config';
import * as fs from 'fs';

Expand Down Expand Up @@ -162,11 +162,11 @@ export class DependencyReportPanel {
* @private
*/
private _disposeReport() {
const reportfilePath = globalConfig.rhdaReportFilePath || defaultRhdaReportFilePath;
if (fs.existsSync(reportfilePath)) {
const reportFilePath = globalConfig.rhdaReportFilePath;
if (fs.existsSync(reportFilePath)) {
// Delete temp stackAnalysisReport file
fs.unlinkSync(reportfilePath);
console.log(`File ${reportfilePath} has been deleted.`);
fs.unlinkSync(reportFilePath);
console.log(`File ${reportFilePath} has been deleted.`);
}
}
}
2 changes: 1 addition & 1 deletion test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ suite('Config module', () => {
sandbox.restore();
});

test('should initialize Config properties with default extension workspace settings', async () => {
test('should initialize Config properties with default extension settings', async () => {

expect(globalConfig.triggerFullStackAnalysis).to.eq(commands.TRIGGER_FULL_STACK_ANALYSIS);
expect(globalConfig.triggerRHRepositoryRecommendationNotification).to.eq(commands.TRIGGER_REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION);
Expand Down
18 changes: 0 additions & 18 deletions test/dependencyReportPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as sinonChai from 'sinon-chai';
import * as vscode from 'vscode';
import * as fs from 'fs';

import { globalConfig } from '../src/config';
import { DependencyReportPanel } from '../src/dependencyReportPanel';
import * as Templates from '../src/template';
import { defaultRhdaReportFilePath } from '../src/constants';
Expand Down Expand Up @@ -81,29 +80,12 @@ suite('DependencyReportPanel Modules', () => {
});

test('dispose should dispose of current panel with RHDA report path setting', async () => {
globalConfig.rhdaReportFilePath = 'mockFilePath'

const existsSyncStub = sandbox.stub(fs, 'existsSync').returns(true);
const unlinkSyncStub = sandbox.stub(fs, 'unlinkSync');

DependencyReportPanel.currentPanel.dispose();

expect(existsSyncStub).to.be.calledWith('mockFilePath');
expect(unlinkSyncStub).to.be.calledWith('mockFilePath');
expect(DependencyReportPanel.data).equals(null);
expect(DependencyReportPanel.currentPanel).equals(undefined);
});

test('dispose should dispose of current panel with default RHDA report path', async () => {
globalConfig.rhdaReportFilePath = ''

const existsSyncStub = sandbox.stub(fs, 'existsSync').returns(true);
const unlinkSyncStub = sandbox.stub(fs, 'unlinkSync');

DependencyReportPanel.createOrShowWebviewPanel();

DependencyReportPanel.currentPanel.dispose();

expect(existsSyncStub).to.be.calledWith(defaultRhdaReportFilePath);
expect(unlinkSyncStub).to.be.calledWith(defaultRhdaReportFilePath);
expect(DependencyReportPanel.data).equals(null);
Expand Down

0 comments on commit 03fd430

Please sign in to comment.