diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/Activator.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/Activator.java index 7eebd02..b983fd6 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/Activator.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/Activator.java @@ -6,6 +6,7 @@ import com.vaadin.plugin.debug.SilentExceptionFilter; import com.vaadin.plugin.launch.ServerLaunchListener; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Bundle activator that starts the REST service when the plug-in is activated and stops it on shutdown. @@ -37,8 +38,7 @@ public void start(BundleContext context) throws Exception { // Update all dotfiles with the current endpoint dotfileManager.updateAllDotfiles(); } catch (Exception e) { - System.err.println("Failed to start Vaadin Eclipse Plugin: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to start Vaadin Eclipse Plugin: " + e.getMessage(), e); // Clean up any partially initialized resources stop(context); throw e; diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotClient.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotClient.java index 97966b1..974992a 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotClient.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotClient.java @@ -12,6 +12,7 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Client for communicating with the Copilot REST service. @@ -128,7 +129,7 @@ private Optional sendForJson(String command, Object dataCommand) HttpResponse response = send(command, dataCommand); if (response.statusCode() != 200) { - System.err.println("Unexpected response (" + response.statusCode() + ") communicating with the IDE plugin: " + VaadinPluginLog.error("Unexpected response (" + response.statusCode() + ") communicating with the IDE plugin: " + response.body()); return Optional.empty(); } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotDotfileManager.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotDotfileManager.java index 8ffb14a..f739905 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotDotfileManager.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotDotfileManager.java @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Manages the .copilot-plugin dotfile for Vaadin projects. Creates the dotfile in .eclipse folder when a Vaadin project @@ -107,7 +108,7 @@ else if (delta.getKind() == IResourceDelta.CHANGED } }); } catch (CoreException e) { - e.printStackTrace(); + VaadinPluginLog.error("Error in resource change listener", e); } } else if (event.getType() == IResourceChangeEvent.PRE_CLOSE || event.getType() == IResourceChangeEvent.PRE_DELETE) { @@ -223,17 +224,16 @@ private void createDotfile(IProject project) { } } catch (CoreException e) { // Log but don't fail - refresh is not critical - System.err.println("Failed to refresh project " + project.getName() + ": " + e.getMessage()); + VaadinPluginLog.error("Failed to refresh project " + project.getName() + ": " + e.getMessage()); } }); refreshJob.setRule(project); refreshJob.schedule(100); // Small delay to ensure resource tree is unlocked - System.out.println("Created .copilot-plugin dotfile for project: " + project.getName()); + VaadinPluginLog.info("Created .copilot-plugin dotfile for project: " + project.getName()); } catch (Exception e) { - System.err.println("Failed to create dotfile for project " + project.getName() + ": " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to create dotfile for project " + project.getName() + ": " + e.getMessage(), e); } } @@ -250,11 +250,11 @@ private void removeDotfile(IProject project) { Path dotfilePath = Paths.get(projectLocation.toString(), ECLIPSE_FOLDER, DOTFILE_NAME); if (Files.exists(dotfilePath)) { Files.delete(dotfilePath); - System.out.println("Removed .copilot-plugin dotfile for project: " + project.getName()); + VaadinPluginLog.info("Removed .copilot-plugin dotfile for project: " + project.getName()); } } catch (Exception e) { - System.err.println("Failed to remove dotfile for project " + project.getName() + ": " + e.getMessage()); + VaadinPluginLog.error("Failed to remove dotfile for project " + project.getName() + ": " + e.getMessage()); } } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotRestService.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotRestService.java index 4677e5d..b1d9e1b 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotRestService.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotRestService.java @@ -43,6 +43,7 @@ import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Starts a small HTTP server for Copilot integration. @@ -74,16 +75,15 @@ public void start() throws IOException { // Get the actual port after binding int actualPort = server.getAddress().getPort(); endpoint = "http://localhost:" + actualPort + contextPath; - System.out.println("Copilot REST service started successfully!"); - System.out.println(" Main endpoint: " + endpoint); - System.out.println(" Health check: http://localhost:" + actualPort + "/health"); - System.out.println(" Server is listening on port " + actualPort); + VaadinPluginLog.info("Copilot REST service started successfully!"); + VaadinPluginLog.info(" Main endpoint: " + endpoint); + VaadinPluginLog.info(" Health check: http://localhost:" + actualPort + "/health"); + VaadinPluginLog.info(" Server is listening on port " + actualPort); // Create dotfiles for all open projects createDotFilesForOpenProjects(); } catch (IOException e) { - System.err.println("Failed to start Copilot REST service: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to start Copilot REST service: " + e.getMessage(), e); throw e; } } @@ -112,8 +112,7 @@ private void createDotFilesForOpenProjects() { } } } catch (Exception e) { - System.err.println("Failed to create dotfiles: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to create dotfiles: " + e.getMessage(), e); } } @@ -165,7 +164,7 @@ public void handle(HttpExchange exchange) throws IOException { InputStream is = exchange.getRequestBody(); String body = new String(is.readAllBytes(), StandardCharsets.UTF_8); - System.out.println("Received Copilot request: " + body); + VaadinPluginLog.debug("Received Copilot request: " + body); try { JsonObject requestJson = JsonParser.parseString(body).getAsJsonObject(); @@ -184,7 +183,7 @@ public void handle(HttpExchange exchange) throws IOException { os.write(responseBytes); } } catch (Exception e) { - e.printStackTrace(); + VaadinPluginLog.error("Error in HTTP request handler", e); byte[] errorBytes = createErrorResponse(e.getMessage()).getBytes(StandardCharsets.UTF_8); exchange.getResponseHeaders().set("Content-Type", "application/json"); exchange.sendResponseHeaders(500, errorBytes.length); @@ -195,7 +194,7 @@ public void handle(HttpExchange exchange) throws IOException { } private String handleCommand(String command, String projectBasePath, JsonObject data) { - System.out.println("Handling command: " + command + " for project: " + projectBasePath); + VaadinPluginLog.debug("Handling command: " + command + " for project: " + projectBasePath); // Find the Eclipse project IProject project = findProject(projectBasePath); @@ -259,7 +258,7 @@ private String handleWrite(IProject project, JsonObject data) { String content = data.get("content").getAsString(); String undoLabel = data.has("undoLabel") ? data.get("undoLabel").getAsString() : null; - System.out.println("Write command for project: " + project.getName() + ", file: " + fileName); + VaadinPluginLog.debug("Write command for project: " + project.getName() + ", file: " + fileName); // Convert absolute path to workspace-relative path IPath filePath = new org.eclipse.core.runtime.Path(fileName); @@ -310,16 +309,14 @@ private String handleWrite(IProject project, JsonObject data) { CopilotUndoManager.getInstance().recordOperation(finalFile, oldContent, finalContent, undoLabel); } catch (Exception e) { - System.err.println("Error writing file: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error writing file: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } return createSuccessResponse(); } catch (Exception e) { - System.err.println("Error in write handler: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error in write handler: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } } @@ -330,7 +327,7 @@ private String handleWriteBase64(IProject project, JsonObject data) { String base64Content = data.get("content").getAsString(); String undoLabel = data.has("undoLabel") ? data.get("undoLabel").getAsString() : null; - System.out.println("WriteBase64 command for project: " + project.getName() + ", file: " + fileName); + VaadinPluginLog.debug("WriteBase64 command for project: " + project.getName() + ", file: " + fileName); // Convert absolute path to workspace-relative path IPath filePath = new org.eclipse.core.runtime.Path(fileName); @@ -384,16 +381,14 @@ private String handleWriteBase64(IProject project, JsonObject data) { undoLabel, true); } catch (Exception e) { - System.err.println("Error writing base64 file: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error writing base64 file: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } return createSuccessResponse(); } catch (Exception e) { - System.err.println("Error in writeBase64 handler: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error in writeBase64 handler: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } } @@ -402,7 +397,7 @@ private String handleDelete(IProject project, JsonObject data) { try { String fileName = data.get("file").getAsString(); - System.out.println("Delete command for project: " + project.getName() + ", file: " + fileName); + VaadinPluginLog.debug("Delete command for project: " + project.getName() + ", file: " + fileName); // Convert absolute path to workspace-relative path IPath filePath = new org.eclipse.core.runtime.Path(fileName); @@ -436,29 +431,27 @@ private String handleDelete(IProject project, JsonObject data) { } finalFile.delete(true, null); - System.out.println("File deleted: " + fileName); + VaadinPluginLog.info("File deleted: " + fileName); // Record delete as setting content to empty (can be undone by recreating with // old content) CopilotUndoManager.getInstance().recordOperation(finalFile, oldContent, "", "Delete " + fileName); } catch (Exception e) { - System.err.println("Error deleting file: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error deleting file: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } return createSuccessResponse(); } catch (Exception e) { - System.err.println("Error in delete handler: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error in delete handler: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } } private String handleUndo(IProject project, JsonObject data) { - System.out.println("Undo command for project: " + project.getName()); + VaadinPluginLog.debug("Undo command for project: " + project.getName()); try { List filePaths = new ArrayList<>(); @@ -479,8 +472,7 @@ private String handleUndo(IProject project, JsonObject data) { return createResponse(response); } catch (Exception e) { - System.err.println("Error performing undo: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error performing undo: " + e.getMessage(), e); Map response = new HashMap<>(); response.put("performed", false); response.put("error", e.getMessage()); @@ -489,7 +481,7 @@ private String handleUndo(IProject project, JsonObject data) { } private String handleRedo(IProject project, JsonObject data) { - System.out.println("Redo command for project: " + project.getName()); + VaadinPluginLog.debug("Redo command for project: " + project.getName()); try { List filePaths = new ArrayList<>(); @@ -510,8 +502,7 @@ private String handleRedo(IProject project, JsonObject data) { return createResponse(response); } catch (Exception e) { - System.err.println("Error performing redo: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error performing redo: " + e.getMessage(), e); Map response = new HashMap<>(); response.put("performed", false); response.put("error", e.getMessage()); @@ -521,25 +512,23 @@ private String handleRedo(IProject project, JsonObject data) { private String handleRefresh(IProject project) { try { - System.out.println("Refresh command for project: " + project.getName()); + VaadinPluginLog.debug("Refresh command for project: " + project.getName()); // Execute refresh operation - no UI thread needed try { // Refresh the entire project project.refreshLocal(IResource.DEPTH_INFINITE, null); - System.out.println("Project refreshed: " + project.getName()); + VaadinPluginLog.info("Project refreshed: " + project.getName()); } catch (Exception e) { - System.err.println("Error refreshing project: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error refreshing project: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } return createSuccessResponse(); } catch (Exception e) { - System.err.println("Error in refresh handler: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error in refresh handler: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } } @@ -550,7 +539,7 @@ private String handleShowInIde(IProject project, JsonObject data) { int line = data.has("line") ? data.get("line").getAsInt() : 0; int column = data.has("column") ? data.get("column").getAsInt() : 0; - System.out.println("ShowInIde command for project: " + project.getName() + ", file: " + fileName + VaadinPluginLog.debug("ShowInIde command for project: " + project.getName() + ", file: " + fileName + ", line: " + line + ", column: " + column); if (line < 0 || column < 0) { @@ -581,7 +570,7 @@ private String handleShowInIde(IProject project, JsonObject data) { // Execute show in IDE operation in UI thread (only if workbench is available) if (!PlatformUI.isWorkbenchRunning()) { // In headless mode, we can't open editors - System.out.println("Workbench not available for showInIde operation"); + VaadinPluginLog.info("Workbench not available for showInIde operation"); Map response = new HashMap<>(); response.put("status", "ok"); // Still return success for testing response.put("message", "Operation would open " + fileName + " at line " + finalLine); @@ -608,7 +597,7 @@ private String handleShowInIde(IProject project, JsonObject data) { editor.selectAndReveal(offset, 0); } catch (BadLocationException e) { // If line/column is invalid, just open the file - System.err.println("Invalid line/column, opening file without navigation: " + VaadinPluginLog.warning("Invalid line/column, opening file without navigation: " + e.getMessage()); } } @@ -619,25 +608,23 @@ private String handleShowInIde(IProject project, JsonObject data) { } } - System.out.println("File opened in IDE: " + fileName + " at " + finalLine + ":" + finalColumn); + VaadinPluginLog.info("File opened in IDE: " + fileName + " at " + finalLine + ":" + finalColumn); } catch (PartInitException e) { - System.err.println("Error opening file in IDE: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error opening file in IDE: " + e.getMessage(), e); } }); return createSuccessResponse(); } catch (Exception e) { - System.err.println("Error in showInIde handler: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error in showInIde handler: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } } private String handleGetModulePaths(IProject project) { - System.out.println("GetModulePaths command for project: " + project.getName()); + VaadinPluginLog.debug("GetModulePaths command for project: " + project.getName()); Map response = new HashMap<>(); Map projectInfo = new HashMap<>(); @@ -722,8 +709,7 @@ private String handleGetModulePaths(IProject project) { } } catch (Exception e) { - System.err.println("Error getting module paths: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error getting module paths: " + e.getMessage(), e); } projectInfo.put("basePath", project.getLocation().toString()); @@ -734,7 +720,7 @@ private String handleGetModulePaths(IProject project) { } private String handleCompileFiles(IProject project, JsonObject data) { - System.out.println("CompileFiles command for project: " + project.getName()); + VaadinPluginLog.debug("CompileFiles command for project: " + project.getName()); try { // Get the list of files to compile @@ -743,20 +729,19 @@ private String handleCompileFiles(IProject project, JsonObject data) { // We trigger a build for the project project.build(org.eclipse.core.resources.IncrementalProjectBuilder.INCREMENTAL_BUILD, null); - System.out.println("Triggered incremental build for project: " + project.getName()); + VaadinPluginLog.info("Triggered incremental build for project: " + project.getName()); } return createSuccessResponse(); } catch (Exception e) { - System.err.println("Error compiling files: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error compiling files: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } } private String handleRestartApplication(IProject project, JsonObject data) { - System.out.println("RestartApplication command for project: " + project.getName()); + VaadinPluginLog.debug("RestartApplication command for project: " + project.getName()); try { String mainClass = data.has("mainClass") ? data.get("mainClass").getAsString() : null; @@ -845,7 +830,7 @@ private String handleRestartApplication(IProject project, JsonObject data) { finalConfig.launch(ILaunchManager.RUN_MODE, null); } - System.out.println("Restarted application for project: " + project.getName()); + VaadinPluginLog.info("Restarted application for project: " + project.getName()); Map response = new HashMap<>(); response.put("status", "ok"); @@ -853,7 +838,7 @@ private String handleRestartApplication(IProject project, JsonObject data) { return createResponse(response); } else { // No configuration found - this is OK, just log it - System.out.println("No launch configuration found for project: " + project.getName()); + VaadinPluginLog.info("No launch configuration found for project: " + project.getName()); Map response = new HashMap<>(); response.put("status", "ok"); @@ -862,14 +847,13 @@ private String handleRestartApplication(IProject project, JsonObject data) { } } catch (Exception e) { - System.err.println("Error restarting application: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error restarting application: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } } private String handleGetVaadinRoutes(IProject project) { - System.out.println("GetVaadinRoutes command for project: " + project.getName()); + VaadinPluginLog.debug("GetVaadinRoutes command for project: " + project.getName()); List> routes = new ArrayList<>(); @@ -878,11 +862,10 @@ private String handleGetVaadinRoutes(IProject project) { IJavaProject javaProject = JavaCore.create(project); VaadinProjectAnalyzer analyzer = new VaadinProjectAnalyzer(javaProject); routes = analyzer.findVaadinRoutes(); - System.out.println("Found " + routes.size() + " Vaadin routes"); + VaadinPluginLog.info("Found " + routes.size() + " Vaadin routes"); } } catch (Exception e) { - System.err.println("Error getting Vaadin routes: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error getting Vaadin routes: " + e.getMessage(), e); } Map response = new HashMap<>(); @@ -891,7 +874,7 @@ private String handleGetVaadinRoutes(IProject project) { } private String handleGetVaadinVersion(IProject project) { - System.out.println("GetVaadinVersion command for project: " + project.getName()); + VaadinPluginLog.debug("GetVaadinVersion command for project: " + project.getName()); try { // Check if it's a Java project @@ -942,8 +925,7 @@ private String handleGetVaadinVersion(IProject project) { return createResponse(response); } catch (Exception e) { - System.err.println("Error getting Vaadin version: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error getting Vaadin version: " + e.getMessage(), e); Map response = new HashMap<>(); response.put("version", "N/A"); return createResponse(response); @@ -951,7 +933,7 @@ private String handleGetVaadinVersion(IProject project) { } private String handleGetVaadinComponents(IProject project, JsonObject data) { - System.out.println("GetVaadinComponents command for project: " + project.getName()); + VaadinPluginLog.debug("GetVaadinComponents command for project: " + project.getName()); boolean includeMethods = data.has("includeMethods") && data.get("includeMethods").getAsBoolean(); List> components = new ArrayList<>(); @@ -961,11 +943,10 @@ private String handleGetVaadinComponents(IProject project, JsonObject data) { IJavaProject javaProject = JavaCore.create(project); VaadinProjectAnalyzer analyzer = new VaadinProjectAnalyzer(javaProject); components = analyzer.findVaadinComponents(includeMethods); - System.out.println("Found " + components.size() + " Vaadin components"); + VaadinPluginLog.info("Found " + components.size() + " Vaadin components"); } } catch (Exception e) { - System.err.println("Error getting Vaadin components: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error getting Vaadin components: " + e.getMessage(), e); } Map response = new HashMap<>(); @@ -974,7 +955,7 @@ private String handleGetVaadinComponents(IProject project, JsonObject data) { } private String handleGetVaadinEntities(IProject project, JsonObject data) { - System.out.println("GetVaadinEntities command for project: " + project.getName()); + VaadinPluginLog.debug("GetVaadinEntities command for project: " + project.getName()); boolean includeMethods = data.has("includeMethods") && data.get("includeMethods").getAsBoolean(); List> entities = new ArrayList<>(); @@ -984,11 +965,10 @@ private String handleGetVaadinEntities(IProject project, JsonObject data) { IJavaProject javaProject = JavaCore.create(project); VaadinProjectAnalyzer analyzer = new VaadinProjectAnalyzer(javaProject); entities = analyzer.findEntities(includeMethods); - System.out.println("Found " + entities.size() + " JPA entities"); + VaadinPluginLog.info("Found " + entities.size() + " JPA entities"); } } catch (Exception e) { - System.err.println("Error getting Vaadin entities: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error getting Vaadin entities: " + e.getMessage(), e); } Map response = new HashMap<>(); @@ -997,7 +977,7 @@ private String handleGetVaadinEntities(IProject project, JsonObject data) { } private String handleGetVaadinSecurity(IProject project) { - System.out.println("GetVaadinSecurity command for project: " + project.getName()); + VaadinPluginLog.debug("GetVaadinSecurity command for project: " + project.getName()); List> security = new ArrayList<>(); List> userDetails = new ArrayList<>(); @@ -1008,12 +988,11 @@ private String handleGetVaadinSecurity(IProject project) { VaadinProjectAnalyzer analyzer = new VaadinProjectAnalyzer(javaProject); security = analyzer.findSecurityConfigurations(); userDetails = analyzer.findUserDetailsServices(); - System.out.println("Found " + security.size() + " security configs and " + userDetails.size() + VaadinPluginLog.info("Found " + security.size() + " security configs and " + userDetails.size() + " user detail services"); } } catch (Exception e) { - System.err.println("Error getting Vaadin security: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error getting Vaadin security: " + e.getMessage(), e); } Map response = new HashMap<>(); @@ -1023,7 +1002,7 @@ private String handleGetVaadinSecurity(IProject project) { } private String handleReloadMavenModule(IProject project, JsonObject data) { - System.out.println("ReloadMavenModule command for project: " + project.getName()); + VaadinPluginLog.debug("ReloadMavenModule command for project: " + project.getName()); try { String moduleName = data.has("moduleName") ? data.get("moduleName").getAsString() : null; @@ -1037,25 +1016,24 @@ private String handleReloadMavenModule(IProject project, JsonObject data) { IProject moduleProject = ResourcesPlugin.getWorkspace().getRoot().getProject(moduleName); if (moduleProject != null && moduleProject.exists()) { moduleProject.refreshLocal(IResource.DEPTH_INFINITE, null); - System.out.println("Refreshed Maven module: " + moduleName); + VaadinPluginLog.info("Refreshed Maven module: " + moduleName); } } else { // Refresh the main project project.refreshLocal(IResource.DEPTH_INFINITE, null); - System.out.println("Refreshed Maven project: " + project.getName()); + VaadinPluginLog.info("Refreshed Maven project: " + project.getName()); } return createSuccessResponse(); } catch (Exception e) { - System.err.println("Error reloading Maven module: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error reloading Maven module: " + e.getMessage(), e); return createErrorResponse(e.getMessage()); } } private String handleHeartbeat(IProject project) { - System.out.println("Heartbeat command for project: " + project.getName()); + VaadinPluginLog.debug("Heartbeat command for project: " + project.getName()); Map response = new HashMap<>(); response.put("status", "alive"); response.put("version", "1.0.0"); diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotUndoManager.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotUndoManager.java index 3f52bd3..27e5709 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotUndoManager.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotUndoManager.java @@ -21,6 +21,7 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.ITextEditor; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Manages undo/redo operations for Copilot file modifications. @@ -74,8 +75,7 @@ public void recordOperation(IFile file, String oldContent, String newContent, St fileOperations.computeIfAbsent(filePath, k -> new ArrayList<>()).add(operation); } catch (Exception e) { - System.err.println("Failed to record operation: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to record operation: " + e.getMessage(), e); } } @@ -116,8 +116,7 @@ public boolean performUndo(List filePaths) { } } } catch (Exception e) { - System.err.println("Error performing undo: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error performing undo: " + e.getMessage(), e); } return performed; @@ -144,8 +143,7 @@ public boolean performRedo(List filePaths) { } } } catch (Exception e) { - System.err.println("Error performing redo: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Error performing redo: " + e.getMessage(), e); } return performed; diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotUtil.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotUtil.java index 0e4e09e..4cb6e35 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotUtil.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/CopilotUtil.java @@ -3,6 +3,7 @@ import java.util.Arrays; import java.util.UUID; import java.util.stream.Collectors; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Utility class for Copilot integration. @@ -41,10 +42,9 @@ public static void saveDotFile(String projectBasePath, int port) { props.store(fos, "Vaadin Copilot Integration Runtime Properties"); } - System.out.println("Created copilot dotfile at: " + dotFile.getAbsolutePath()); + VaadinPluginLog.info("Created copilot dotfile at: " + dotFile.getAbsolutePath()); } catch (Exception e) { - System.err.println("Failed to create copilot dotfile: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to create copilot dotfile: " + e.getMessage(), e); } } } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/builder/VaadinBuildParticipant.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/builder/VaadinBuildParticipant.java index 3244542..1ed3e45 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/builder/VaadinBuildParticipant.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/builder/VaadinBuildParticipant.java @@ -20,6 +20,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Build participant that generates files in the output folder during compilation. These files will be automatically @@ -35,23 +36,23 @@ protected IProject[] build(int kind, java.util.Map args, IProgre throws CoreException { IProject project = getProject(); - System.out.println( + VaadinPluginLog.debug( "VaadinBuildParticipant.build() called for project: " + (project != null ? project.getName() : "null")); if (project == null || !project.isAccessible()) { - System.out.println(" - Project is null or not accessible"); + VaadinPluginLog.debug(" - Project is null or not accessible"); return null; } // Check if this is a Java project if (!project.hasNature(JavaCore.NATURE_ID)) { - System.out.println(" - Not a Java project"); + VaadinPluginLog.debug(" - Not a Java project"); return null; } // Check if project has Vaadin dependencies boolean hasVaadin = hasVaadinDependency(project); - System.out.println(" - Has Vaadin dependencies: " + hasVaadin); + VaadinPluginLog.debug(" - Has Vaadin dependencies: " + hasVaadin); if (!hasVaadin) { return null; @@ -80,14 +81,14 @@ private boolean hasVaadinDependency(IProject project) { // Check for Vaadin in the filename only (not the full path) // This avoids false positives from temp directories containing "vaadin" if (filename.contains("vaadin")) { - System.out.println(" Found Vaadin dependency: " + entry.getPath()); + VaadinPluginLog.debug(" Found Vaadin dependency: " + entry.getPath()); return true; } } } } catch (Exception e) { // If we can't determine, assume no Vaadin dependency - System.err.println("Error checking for Vaadin dependencies: " + e.getMessage()); + VaadinPluginLog.error("Error checking for Vaadin dependencies: " + e.getMessage()); } return false; @@ -167,10 +168,10 @@ private void updateFlowBuildInfo(IProject project, IProgressMonitor monitor) { vaadinFolder.setDerived(true, monitor); configFolder.setDerived(true, monitor); - System.out.println("Updated flow-build-info.json in output folder: " + configFolder.getFullPath()); + VaadinPluginLog.info("Updated flow-build-info.json in output folder: " + configFolder.getFullPath()); } catch (Exception e) { - System.err.println("Failed to update flow-build-info.json: " + e.getMessage()); + VaadinPluginLog.error("Failed to update flow-build-info.json: " + e.getMessage()); } } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/builder/VaadinBuilderConfigurator.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/builder/VaadinBuilderConfigurator.java index 68ab342..6ff6a9b 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/builder/VaadinBuilderConfigurator.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/builder/VaadinBuilderConfigurator.java @@ -10,6 +10,8 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.JavaCore; +import com.vaadin.plugin.util.VaadinPluginLog; + /** * Automatically adds the Vaadin builder to Java projects. The builder itself will check for Vaadin dependencies. */ @@ -20,13 +22,13 @@ public class VaadinBuilderConfigurator implements IResourceChangeListener { public static void initialize() { if (instance == null) { instance = new VaadinBuilderConfigurator(); - System.out.println("VaadinBuilderConfigurator: Initializing..."); + VaadinPluginLog.info("VaadinBuilderConfigurator: Initializing..."); ResourcesPlugin.getWorkspace().addResourceChangeListener(instance, IResourceChangeEvent.POST_CHANGE); // Configure existing projects IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - System.out.println("VaadinBuilderConfigurator: Found " + projects.length + " projects"); + VaadinPluginLog.info("VaadinBuilderConfigurator: Found " + projects.length + " projects"); for (IProject project : projects) { instance.configureProject(project); @@ -62,15 +64,15 @@ private void processResourceDelta(IResourceDelta delta) { private void configureProject(IProject project) { try { - System.out.println("VaadinBuilderConfigurator: Checking project " + project.getName()); + VaadinPluginLog.debug("VaadinBuilderConfigurator: Checking project " + project.getName()); if (!project.isOpen()) { - System.out.println(" - Project is not open"); + VaadinPluginLog.debug(" - Project is not open"); return; } if (!project.hasNature(JavaCore.NATURE_ID)) { - System.out.println(" - Not a Java project"); + VaadinPluginLog.debug(" - Not a Java project"); return; } @@ -80,7 +82,7 @@ private void configureProject(IProject project) { // Check if builder is already present for (ICommand command : commands) { if (VaadinBuildParticipant.BUILDER_ID.equals(command.getBuilderName())) { - System.out.println(" - Builder already configured"); + VaadinPluginLog.debug(" - Builder already configured"); return; // Already configured } } @@ -96,10 +98,10 @@ private void configureProject(IProject project) { desc.setBuildSpec(newCommands); project.setDescription(desc, null); - System.out.println(" - Added Vaadin builder to project: " + project.getName()); + VaadinPluginLog.info(" - Added Vaadin builder to project: " + project.getName()); } catch (CoreException e) { - System.out.println(" - Error configuring project: " + e.getMessage()); + VaadinPluginLog.warning(" - Error configuring project: " + e.getMessage(), e); } } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/debug/SilentExceptionFilter.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/debug/SilentExceptionFilter.java index ab7aa9e..cef45f0 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/debug/SilentExceptionFilter.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/debug/SilentExceptionFilter.java @@ -6,6 +6,7 @@ import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.jdt.debug.core.IJavaExceptionBreakpoint; import org.eclipse.jdt.debug.core.IJavaThread; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Debug event listener that filters out SilentException breakpoints to prevent the debugger from stopping unnecessarily @@ -43,7 +44,7 @@ public void handleDebugEvents(DebugEvent[] events) { } } } catch (Exception e) { - System.err.println("Error handling debug event: " + e.getMessage()); + VaadinPluginLog.error("Error handling debug event: " + e.getMessage()); } } } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/hotswap/HotswapAgentManager.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/hotswap/HotswapAgentManager.java index 732b6c8..3e11d95 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/hotswap/HotswapAgentManager.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/hotswap/HotswapAgentManager.java @@ -15,6 +15,7 @@ import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Platform; import org.osgi.framework.Bundle; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Manages the Hotswap Agent installation and updates. Handles downloading, installing, and version management of @@ -51,7 +52,7 @@ private void initializePaths() { try { Files.createDirectories(vaadinHomePath); } catch (IOException e) { - System.err.println("Failed to create Vaadin home directory: " + e.getMessage()); + VaadinPluginLog.error("Failed to create Vaadin home directory: " + e.getMessage()); } } @@ -103,16 +104,15 @@ public String installHotswapAgent() { try (InputStream in = fileUrl.openStream()) { Files.copy(in, hotswapAgentPath, StandardCopyOption.REPLACE_EXISTING); } - System.out.println("Installed Hotswap Agent version: " + bundledVersion); + VaadinPluginLog.info("Installed Hotswap Agent version: " + bundledVersion); return bundledVersion; } else { - System.out.println("Hotswap Agent is up to date: " + installedVersion); + VaadinPluginLog.info("Hotswap Agent is up to date: " + installedVersion); return installedVersion; } } catch (Exception e) { - System.err.println("Failed to install Hotswap Agent: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to install Hotswap Agent: " + e.getMessage(), e); return null; } } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/hotswap/JetBrainsRuntimeManager.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/hotswap/JetBrainsRuntimeManager.java index eef3cde..46a4e80 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/hotswap/JetBrainsRuntimeManager.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/hotswap/JetBrainsRuntimeManager.java @@ -15,6 +15,7 @@ import org.eclipse.jdt.launching.IVMInstallType; import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.jdt.launching.VMStandin; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Manages JetBrains Runtime (JBR) installation and configuration. JBR is required for enhanced class redefinition @@ -56,7 +57,7 @@ private void initializePaths() { try { Files.createDirectories(jbrInstallPath); } catch (IOException e) { - System.err.println("Failed to create JBR directory: " + e.getMessage()); + VaadinPluginLog.error("Failed to create JBR directory: " + e.getMessage()); } } @@ -203,7 +204,7 @@ public IVMInstall downloadAndInstallJBR(String javaVersion, IProgressMonitor mon monitor.subTask("Downloading JBR..."); // Download logic would go here // For now, we'll just print a message - System.out.println("Would download JBR from: " + downloadUrl); + VaadinPluginLog.debug("Would download JBR from: " + downloadUrl); monitor.worked(50); @@ -220,8 +221,7 @@ public IVMInstall downloadAndInstallJBR(String javaVersion, IProgressMonitor mon return null; // Would return the installed JBR } catch (Exception e) { - System.err.println("Failed to download JBR: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to download JBR: " + e.getMessage(), e); return null; } finally { monitor.done(); @@ -260,8 +260,7 @@ private IVMInstall registerJBR(File javaHome) { return vm; } catch (Exception e) { - System.err.println("Failed to register JBR: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to register JBR: " + e.getMessage(), e); return null; } } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/launch/ServerLaunchListener.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/launch/ServerLaunchListener.java index c29e01d..11d0e5a 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/launch/ServerLaunchListener.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/launch/ServerLaunchListener.java @@ -8,6 +8,7 @@ import org.eclipse.wst.server.core.IModule; import org.eclipse.wst.server.core.IServer; import org.eclipse.wst.server.core.ServerUtil; +import com.vaadin.plugin.util.VaadinPluginLog; /** * Listener that hooks into server launch events to trigger a build for Vaadin projects. The Vaadin builder will @@ -46,7 +47,7 @@ public void launchAdded(ILaunch launch) { } catch (Exception e) { // Log but don't fail the launch - System.err.println("Failed to trigger build: " + e.getMessage()); + VaadinPluginLog.error("Failed to trigger build: " + e.getMessage()); } } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/util/ResourceReader.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/util/ResourceReader.java index 4ae95e9..563dced 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/util/ResourceReader.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/util/ResourceReader.java @@ -30,7 +30,7 @@ public static String readFlowBuildInfo() { } } } catch (IOException e) { - System.err.println("Failed to read flow-build-info.json resource: " + e.getMessage()); + VaadinPluginLog.error("Failed to read flow-build-info.json resource: " + e.getMessage()); } return null; } @@ -49,9 +49,9 @@ public static String readFlowBuildInfo() { public static void exampleUsage() { String content = readFlowBuildInfo(); if (content != null) { - System.out.println("flow-build-info.json content: " + content); + VaadinPluginLog.info("flow-build-info.json content: " + content); } else { - System.out.println("flow-build-info.json resource not found in classpath"); + VaadinPluginLog.info("flow-build-info.json resource not found in classpath"); } } } diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/util/VaadinPluginLog.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/util/VaadinPluginLog.java new file mode 100644 index 0000000..f165c61 --- /dev/null +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/util/VaadinPluginLog.java @@ -0,0 +1,68 @@ +package com.vaadin.plugin.util; + +import org.eclipse.core.runtime.ILog; + +/** + * Utility class for logging messages in the Vaadin Eclipse Plugin. + * Uses the simplified ILog.get() approach available since Eclipse 2021-03. + * Each call automatically uses the logger for the calling class's bundle. + */ +public class VaadinPluginLog { + + /** + * Logs an informational message. + * + * @param message the message to log + */ + public static void info(String message) { + ILog.get().info(message); + } + + /** + * Logs a warning message. + * + * @param message the message to log + */ + public static void warning(String message) { + ILog.get().warn(message); + } + + /** + * Logs a warning message with an exception. + * + * @param message the message to log + * @param exception the exception to log + */ + public static void warning(String message, Throwable exception) { + ILog.get().warn(message, exception); + } + + /** + * Logs an error message. + * + * @param message the message to log + */ + public static void error(String message) { + ILog.get().error(message); + } + + /** + * Logs an error message with an exception. + * + * @param message the message to log + * @param exception the exception to log + */ + public static void error(String message, Throwable exception) { + ILog.get().error(message, exception); + } + + /** + * Logs a debug message. Debug messages are always logged at INFO level + * to help diagnose issues without requiring Eclipse to be in debug mode. + * + * @param message the message to log + */ + public static void debug(String message) { + ILog.get().info("[DEBUG] " + message); + } +} \ No newline at end of file diff --git a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/wizards/NewVaadinProjectWizard.java b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/wizards/NewVaadinProjectWizard.java index cabb292..a73e7f2 100644 --- a/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/wizards/NewVaadinProjectWizard.java +++ b/vaadin-eclipse-plugin-main/src/com/vaadin/plugin/wizards/NewVaadinProjectWizard.java @@ -35,6 +35,7 @@ import org.eclipse.ui.ide.IDE; import com.vaadin.plugin.CopilotDotfileManager; +import com.vaadin.plugin.util.VaadinPluginLog; /** * New Vaadin Project creation wizard. @@ -217,7 +218,7 @@ private void deleteDirectory(Path path) throws IOException { private IProject importMavenProject(Path projectPath, String projectName, IProgressMonitor monitor) throws CoreException { // Use the regular import and then configure as Maven - System.out.println("=== Creating project and configuring Maven ==="); + VaadinPluginLog.info("=== Creating project and configuring Maven ==="); // First create the project normally IProject project = importProject(projectPath, projectName, monitor); @@ -247,12 +248,11 @@ private IProject importMavenProject(Path projectPath, String projectName, IProgr // Additional refresh to ensure all resources are visible project.refreshLocal(IResource.DEPTH_INFINITE, monitor); - System.out.println("Maven nature enabled and project configured with forced update"); - System.out.println("Has Maven nature: " + project.hasNature("org.eclipse.m2e.core.maven2Nature")); + VaadinPluginLog.info("Maven nature enabled and project configured with forced update"); + VaadinPluginLog.debug("Has Maven nature: " + project.hasNature("org.eclipse.m2e.core.maven2Nature")); } catch (Exception e) { - System.err.println("Failed to configure Maven nature: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to configure Maven nature: " + e.getMessage(), e); } return project; @@ -260,9 +260,9 @@ private IProject importMavenProject(Path projectPath, String projectName, IProgr private IProject importGradleProject(Path projectPath, String projectName, IProgressMonitor monitor) throws CoreException { - System.out.println("=== Importing Gradle project ==="); - System.out.println("Project path: " + projectPath); - System.out.println("Project name: " + projectName); + VaadinPluginLog.info("=== Importing Gradle project ==="); + VaadinPluginLog.debug("Project path: " + projectPath); + VaadinPluginLog.debug("Project name: " + projectName); IProject project = null; @@ -271,14 +271,13 @@ private IProject importGradleProject(Path projectPath, String projectName, IProg // This will throw NoClassDefFoundError if Buildship is not available project = importGradleProjectWithBuildship(projectPath, projectName, monitor); if (project != null) { - System.out.println("Gradle project imported with Buildship successfully"); + VaadinPluginLog.info("Gradle project imported with Buildship successfully"); return project; } } catch (NoClassDefFoundError | ClassNotFoundException e) { - System.out.println("Buildship not available, using basic Gradle configuration"); + VaadinPluginLog.info("Buildship not available, using basic Gradle configuration"); } catch (Exception e) { - System.err.println("Failed to import Gradle project with Buildship: " + e.getMessage()); - e.printStackTrace(); + VaadinPluginLog.error("Failed to import Gradle project with Buildship: " + e.getMessage(), e); } // Fall back to basic import @@ -377,9 +376,9 @@ private void configureBasicGradleProject(IProject project, IProgressMonitor moni private IProject importProject(Path projectPath, String projectName, IProgressMonitor monitor) throws CoreException { - System.out.println("=== Using regular Eclipse project import ==="); - System.out.println("Project path: " + projectPath); - System.out.println("Project name: " + projectName); + VaadinPluginLog.info("=== Using regular Eclipse project import ==="); + VaadinPluginLog.debug("Project path: " + projectPath); + VaadinPluginLog.debug("Project name: " + projectName); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName);