Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void openCustomEditor(FileEditorManager instance, JsonObject manifestDeta
String actualFilePath = htmlFilePath.substring(7); // Remove "file://" prefix
ReportFileManager.saveReportCopy(
actualFilePath,
manifestDetails.get("manifestName").getAsString()
manifestDetails.get("manifestName").getAsString(),
project
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
******************************************************************************/
package org.jboss.tools.intellij.report;

import com.intellij.notification.NotificationGroupManager;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.Nullable;
import org.jboss.tools.intellij.settings.ApiSettingsState;

import java.io.IOException;
Expand All @@ -26,14 +30,16 @@ public class ReportFileManager {

private static final Logger LOG = Logger.getInstance(ReportFileManager.class);
private static final DateTimeFormatter TIMESTAMP_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
private static final String NOTIFICATION_GROUP_ID = "Red Hat Dependency Analytics";

/**
* Save a copy of the report to user-configured directory if specified.
*
* @param htmlFilePath Path to the temporary HTML report file
* @param manifestName Name of the manifest file (e.g., "pom.xml")
* @param project The project context for scoping notifications (maybe null)
*/
public static void saveReportCopy(String htmlFilePath, String manifestName) {
public static void saveReportCopy(String htmlFilePath, String manifestName, @Nullable Project project) {
ApiSettingsState settings = ApiSettingsState.getInstance();
String saveDirectory = settings.reportFilePath;

Expand All @@ -42,12 +48,51 @@ public static void saveReportCopy(String htmlFilePath, String manifestName) {
return;
}

Project effectiveProject = project != null && !project.isDisposed() ? project : null;

ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
Path sourcePath = Paths.get(htmlFilePath);
Path targetDir = Paths.get(saveDirectory.trim());

Files.createDirectories(targetDir);
if (!Files.exists(targetDir)) {
String message = "Report save directory does not exist: " + targetDir;
NotificationGroupManager.getInstance()
.getNotificationGroup(NOTIFICATION_GROUP_ID)
.createNotification(
"Dependency Analytics Report",
message + ". Please create the directory or update the path in Settings > Tools > Red Hat Dependency Analytics.",
NotificationType.ERROR
)
.notify(effectiveProject);
return;
}

if (!Files.isDirectory(targetDir)) {
String message = "Report save path is not a directory: " + targetDir;
NotificationGroupManager.getInstance()
.getNotificationGroup(NOTIFICATION_GROUP_ID)
.createNotification(
"Dependency Analytics Report",
message + ". Please update the path in Settings > Tools > Red Hat Dependency Analytics.",
NotificationType.ERROR
)
.notify(effectiveProject);
return;
}

if (!Files.isWritable(targetDir)) {
String message = "Report save directory is not writable: " + targetDir;
NotificationGroupManager.getInstance()
.getNotificationGroup(NOTIFICATION_GROUP_ID)
.createNotification(
"Dependency Analytics Report",
message + ". Please check directory permissions or update the path in Settings > Tools > Red Hat Dependency Analytics.",
NotificationType.ERROR
)
.notify(effectiveProject);
return;
}

String timestamp = LocalDateTime.now().format(TIMESTAMP_FORMAT);
String filename = String.format("report_%s_%s.html", manifestName, timestamp);
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Expand All @@ -56,10 +101,24 @@ public static void saveReportCopy(String htmlFilePath, String manifestName) {
Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
LOG.info("Report successfully saved to: " + targetPath);
} catch (IOException e) {
LOG.error("Failed to save report copy", e);
NotificationGroupManager.getInstance()
.getNotificationGroup(NOTIFICATION_GROUP_ID)
.createNotification(
"Dependency Analytics Report",
"Failed to save report: " + e.getMessage(),
NotificationType.ERROR
)
.notify(effectiveProject);
} catch (Exception e) {
LOG.error("Unexpected error during report save", e);
NotificationGroupManager.getInstance()
.getNotificationGroup(NOTIFICATION_GROUP_ID)
.createNotification(
"Dependency Analytics Report",
"Unexpected error saving report: " + e.getMessage(),
NotificationType.ERROR
)
.notify(effectiveProject);
}
});
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@
<depends>com.redhat.devtools.intellij.telemetry</depends>

<extensions defaultExtensionNs="com.intellij">
<notificationGroup id="Red Hat Dependency Analytics" displayType="BALLOON"/>
<fileEditorProvider implementation="org.jboss.tools.intellij.report.AnalyticsReportEditorProvider"/>
<editorTabTitleProvider implementation="org.jboss.tools.intellij.report.AnalyticsReportEditorTabTitleProvider"
order="first"/>
Expand Down
Loading