Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for report being created at a new location using the latest surefire plugin #347

Merged
merged 13 commits into from
Nov 21, 2024
Merged
105 changes: 69 additions & 36 deletions src/liberty/devCommands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, 2022 IBM Corporation.
* Copyright (c) 2020, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -77,18 +77,17 @@ export async function openProject(pomPath: string): Promise<void> {
export async function listAllCommands(): Promise<void> {
const libertyCommands = Array.from(COMMAND_TITLES.keys());
vscode.window.showQuickPick(libertyCommands).then(selection => {
if (!selection) {
return;
}
const command = COMMAND_TITLES.get(selection);
if ( command !== undefined )
{
vscode.commands.executeCommand(command);
} else {
// should never happen
console.error("Unable to find corresponding command for " + selection);
}

if (!selection) {
return;
}
const command = COMMAND_TITLES.get(selection);
if (command !== undefined) {
vscode.commands.executeCommand(command);
} else {
// should never happen
console.error("Unable to find corresponding command for " + selection);
}

});
}

Expand Down Expand Up @@ -130,7 +129,7 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro

export async function removeProject(): Promise<void> {
const projectProvider: ProjectProvider = ProjectProvider.getInstance();

// clicked on the empty space and workspace has more than one folders, or
// from command palette
// Display the list of current user added projects for user to select.
Expand Down Expand Up @@ -163,7 +162,7 @@ export async function removeProject(): Promise<void> {
}
});
});

}
}

Expand Down Expand Up @@ -193,11 +192,11 @@ export async function addProject(uri: vscode.Uri): Promise<void> {
// scan the folder and get a list of folders with pom.xml and build.gradle
const uris: string[] = await projectProvider.getListOfMavenAndGradleFolders(uri.fsPath);
console.log(JSON.stringify(uris));
if ( uris.length > 0) {
if (uris.length > 0) {
// present the list to add
showListOfPathsToAdd(uris);
}


} else {
// clicked on the empty space and workspace has more than one folders, or
Expand Down Expand Up @@ -399,7 +398,7 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par
if (customCommand !== undefined) {
// save command
customCommand = customCommand.trim();
if ( customCommand.length > 0 ) {
if (customCommand.length > 0) {
const projectStartCmdParam: ProjectStartCmdParam = new ProjectStartCmdParam(libProject.getPath(), customCommand);
const projectProvider: ProjectProvider = ProjectProvider.getInstance();
const dashboardData: DashboardData = helperUtil.getStorageData(projectProvider.getContext());
Expand Down Expand Up @@ -489,29 +488,25 @@ export async function openReport(reportType: string, libProject?: LibertyProject
const path = Path.dirname(libProject.getPath());
if (path !== undefined) {
let report: any;
if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) {
report = Path.join(path, "target", "site", reportType + "-report.html");
} else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) {
report = await getGradleTestReport(libProject.path, path);
}
let reportTypeLabel = reportType;
if (reportType === "gradle") {
reportTypeLabel = "test";
}
fs.exists(report, (exists) => {
if (exists) {
const panel = vscode.window.createWebviewPanel(
reportType, // Identifies the type of the webview. Used internally
libProject.getLabel() + " " + reportTypeLabel + " report", // Title of the panel displayed to the user
vscode.ViewColumn.Two, // Open the panel in the second window
{}, // Webview options
);
panel.webview.html = getReport(report); // display HTML content
} else {
const message = localize("test.report.does.not.exist.run.test.first", report);
vscode.window.showInformationMessage(message);
let showErrorMessage: boolean = true;
if (libProject.getContextValue() === LIBERTY_MAVEN_PROJECT || libProject.getContextValue() === LIBERTY_MAVEN_PROJECT_CONTAINER) {
report = getReportFile(path, "reports", reportType + ".html");
showErrorMessage = false; // show the error message only if the directory is not reports, so setting to false
if (!await checkReportAndDisplay(report, reportType, reportTypeLabel, libProject, showErrorMessage)) {
report = getReportFile(path, "site", reportType + "-report.html");
showErrorMessage = true;//report is not available in 'reports', hence show the message if report is not availabe in 'site', so setting to true
await checkReportAndDisplay(report, reportType, reportTypeLabel, libProject, showErrorMessage);
}
});
} else if (libProject.getContextValue() === LIBERTY_GRADLE_PROJECT || libProject.getContextValue() === LIBERTY_GRADLE_PROJECT_CONTAINER) {
report = await getGradleTestReport(libProject.path, path);
await checkReportAndDisplay(report, reportType, reportTypeLabel, libProject, showErrorMessage);
}


}
} else if (ProjectProvider.getInstance() && reportType) {
showProjects(reportType, openReport, reportType);
Expand Down Expand Up @@ -610,4 +605,42 @@ async function getLocalGradleWrapper(projectFolder: string): Promise<string | un
*/
function isWin(): boolean {
return process.platform.startsWith("win");
}

/*
will return the path of the report, since there are diffrent folders to look into and the file names can be different
we need to get the paths to look for dynamically
*/
function getReportFile(path: any, dir: string, filename: string): any {
return Path.join(path, "target", dir, filename);
}

/*
Function will check if the report is available within the given path and returns a boolean based on it and also
the report will be displayed if it is available
*/
function checkReportAndDisplay(report: any, reportType: string, reportTypeLabel: string, libProject: LibertyProject, showErrorMessage: boolean): Promise<boolean> {
return new Promise((resolve) => {
fs.exists(report, (exists) => {
if (exists) {
const panel = vscode.window.createWebviewPanel(
reportType, // Identifies the type of the webview. Used internally
libProject.getLabel() + " " + reportTypeLabel + " report", // Title of the panel displayed to the user
vscode.ViewColumn.Two, // Open the panel in the second window
{}, // Webview options
);
panel.webview.html = getReport(report); // display HTML content
/*
For maven projects we need to check for the report in 'reports' and 'site', we only need to show the message if it is not
available in both the locations, below condition make sure to avoid the message when its a maven project and the directory
is 'reports'
*/
} else if (showErrorMessage) {// if it is flagged to show the error message then show it else dont

const message = localize("test.report.does.not.exist.run.test.first", report);
vscode.window.showInformationMessage(message);
}
resolve(exists);
});
});
}
18 changes: 12 additions & 6 deletions src/test/MavenTestDevModeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ it('Run tests for sample maven project', async () => {
it('start maven with options from liberty dashboard', async () => {

const reportPath = path.join(utils.getMvnProjectPath(),"target","site","failsafe-report.html");
const deleteReport = await utils.deleteReports(reportPath);
expect (deleteReport).to.be.true;
const alternateReportPath = path.join(utils.getMvnProjectPath(), "target", "reports", "failsafe.html"); // new path to scan for the reports
let deleteReport = await utils.deleteReports(reportPath);
let deleteAlternateReport = await utils.deleteReports(alternateReportPath);
expect (deleteReport || deleteAlternateReport).to.be.true; // there should be a report available irrespective of the surefire versions we use , so either one needs to be true
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM);
await utils.setCustomParameter("-DhotTests=true");
await utils.delay(30000);
Expand All @@ -111,7 +113,8 @@ it('start maven with options from liberty dashboard', async () => {
{
console.log("Server succuessfully started");
let checkFile = await utils.checkIfTestReportExists(reportPath);
expect (checkFile).to.be.true;
let checkAlternateFile = await utils.checkIfTestReportExists(alternateReportPath);
expect (checkFile || checkAlternateFile).to.be.true;
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
const serverStopStatus= await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING);
if(!serverStopStatus){
Expand All @@ -129,8 +132,10 @@ it('start maven with options from liberty dashboard', async () => {
it('start maven with history from liberty dashboard', async () => {

const reportPath = path.join(utils.getMvnProjectPath(),"target","site","failsafe-report.html");
const deleteReport = await utils.deleteReports(reportPath);
expect (deleteReport).to.be.true;
const alternateReportPath = path.join(utils.getMvnProjectPath(), "target", "reports", "failsafe.html");
let deleteReport = await utils.deleteReports(reportPath);
let deleteAlternateReport = await utils.deleteReports(alternateReportPath);
expect (deleteReport || deleteAlternateReport).to.be.true;
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM);
const foundCommand = await utils.chooseCmdFromHistory("-DhotTests=true");
expect (foundCommand).to.be.true;
Expand All @@ -142,7 +147,8 @@ it('start maven with history from liberty dashboard', async () => {
{
console.log("Server succuessfully started");
let checkFile = await utils.checkIfTestReportExists(reportPath);
expect (checkFile).to.be.true;
let checkAlternateFile = await utils.checkIfTestReportExists(alternateReportPath);
expect (checkFile || checkAlternateFile).to.be.true;
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
const serverStopStatus= await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING);
if(!serverStopStatus){
Expand Down
Loading