|
32 | 32 | import org.eclipse.jface.viewers.IStructuredSelection; |
33 | 33 | import org.eclipse.swt.widgets.DirectoryDialog; |
34 | 34 | import org.eclipse.swt.widgets.Shell; |
| 35 | +import org.eclipse.ui.IWorkbenchPage; |
| 36 | +import org.eclipse.ui.PartInitException; |
35 | 37 | import org.eclipse.ui.PlatformUI; |
36 | 38 | import org.eclipse.ui.console.ConsolePlugin; |
37 | 39 | import org.eclipse.ui.console.IConsole; |
| 40 | +import org.eclipse.ui.console.IConsoleConstants; |
| 41 | +import org.eclipse.ui.console.IConsoleView; |
38 | 42 | import org.eclipse.ui.console.MessageConsole; |
39 | 43 | import org.eclipse.ui.console.MessageConsoleStream; |
40 | 44 | import org.eclipse.ui.handlers.HandlerUtil; |
@@ -113,38 +117,46 @@ private IStructuredSelection getSelection(ExecutionEvent event) { |
113 | 117 | return null; |
114 | 118 | } |
115 | 119 |
|
116 | | - private int runMvnCommand(String srcProjectPath, String srcPath, String targetPath) { |
117 | | - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
118 | | - |
119 | | - MessageConsole console = new MessageConsole("Maven Command Console", null); |
120 | | - ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{console}); |
121 | | - |
122 | | - MessageConsoleStream consoleStream = console.newMessageStream(); |
123 | | - |
124 | | - try { |
125 | | - List<String> command = new ArrayList<>(); |
126 | | - command.add(getMvnCommand()); |
127 | | - command.add(getTransformCommand()); |
128 | | - command.add("-DselectedSource=" + srcPath); |
129 | | - command.add("-DselectedTarget=" + targetPath); |
130 | | - ProcessBuilder builder = new ProcessBuilder(command); |
131 | | - builder.environment().put("PATH", System.getenv("PATH")); |
132 | | - builder.directory(new File(srcProjectPath)); |
133 | | - builder.redirectErrorStream(true); |
134 | | - Process process = builder.start(); |
135 | | - |
136 | | - BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
137 | | - String line = null; |
138 | | - while ((line = reader.readLine()) != null) { |
139 | | - consoleStream.println(line); |
140 | | - } |
141 | | - |
142 | | - return process.waitFor(); |
143 | | - } catch (IOException | InterruptedException e) { |
144 | | - MessageDialog.openError(shell, "Error", "An error occurred while running the Maven command: " + e.getMessage()); |
145 | | - return -1; |
146 | | - } |
147 | | - } |
| 120 | + private int runMvnCommand(String srcProjectPath, String srcPath, String targetPath) { |
| 121 | + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
| 122 | + |
| 123 | + MessageConsole console = new MessageConsole("Maven Command Console", null); |
| 124 | + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console }); |
| 125 | + IConsoleView consoleView = null; |
| 126 | + |
| 127 | + try { |
| 128 | + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| 129 | + consoleView = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW); |
| 130 | + console.activate(); |
| 131 | + consoleView.display(console); |
| 132 | + |
| 133 | + MessageConsoleStream consoleStream = console.newMessageStream(); |
| 134 | + |
| 135 | + List<String> command = new ArrayList<>(); |
| 136 | + command.add(getMvnCommand()); |
| 137 | + command.add(getTransformCommand()); |
| 138 | + command.add("-DselectedSource=" + srcPath); |
| 139 | + command.add("-DselectedTarget=" + targetPath); |
| 140 | + ProcessBuilder builder = new ProcessBuilder(command); |
| 141 | + builder.environment().put("PATH", System.getenv("PATH")); |
| 142 | + builder.directory(new File(srcProjectPath)); |
| 143 | + builder.redirectErrorStream(true); |
| 144 | + Process process = builder.start(); |
| 145 | + |
| 146 | + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| 147 | + String line = null; |
| 148 | + while ((line = reader.readLine()) != null) { |
| 149 | + consoleStream.println(line); |
| 150 | + } |
| 151 | + |
| 152 | + return process.waitFor(); |
| 153 | + } catch (IOException | InterruptedException | PartInitException e) { |
| 154 | + MessageDialog.openError(shell, "Error", |
| 155 | + "An error occurred while running the Maven command: " + e.getMessage()); |
| 156 | + return -1; |
| 157 | + } |
| 158 | + } |
| 159 | + |
148 | 160 |
|
149 | 161 | private String getTransformCommand() { |
150 | 162 | return String.format("%s:%s:%s:run", |
|
0 commit comments