diff --git a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/launch/WindupLaunchDelegate.java b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/launch/WindupLaunchDelegate.java index 512ec716..4af07328 100644 --- a/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/launch/WindupLaunchDelegate.java +++ b/plugins/org.jboss.tools.windup.ui/src/org/jboss/tools/windup/ui/internal/launch/WindupLaunchDelegate.java @@ -11,13 +11,20 @@ ******************************************************************************/ package org.jboss.tools.windup.ui.internal.launch; +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; + import javax.inject.Inject; import javax.inject.Named; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; @@ -26,17 +33,25 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; -import org.jboss.tools.windup.core.services.WindupService; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; import org.jboss.tools.windup.model.domain.ModelService; -import org.jboss.tools.windup.runtime.WindupRmiClient; -import org.jboss.tools.windup.runtime.WindupRuntimePlugin; +import org.jboss.tools.windup.runtime.kantra.KantraRunner; import org.jboss.tools.windup.ui.WindupUIPlugin; import org.jboss.tools.windup.ui.internal.Messages; import org.jboss.tools.windup.ui.internal.services.MarkerService; import org.jboss.tools.windup.ui.internal.services.ViewService; -import org.jboss.tools.windup.ui.util.WindupLauncher; -import org.jboss.tools.windup.ui.util.WindupServerCallbackAdapter; import org.jboss.tools.windup.windup.ConfigurationElement; +import org.jboss.tools.windup.windup.Pair; + +import com.google.common.collect.Lists; /** @@ -44,16 +59,17 @@ */ public class WindupLaunchDelegate implements ILaunchConfigurationDelegate { - @Inject private WindupLauncher launcher; - @Inject private WindupService windupService; @Inject private ModelService modelService; - @Inject private WindupRmiClient windupClient; @Inject private MarkerService markerService; @Inject private ViewService viewService; @Inject @Named (IServiceConstants.ACTIVE_SHELL) Shell shell; + public static KantraRunner activeRunner = null; + private static Job kantraJob = null; + private static IProgressMonitor kantraMonitor; + public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) { ConfigurationElement configuration = modelService.findConfiguration(config.getName()); if (configuration == null || configuration.getInputs().isEmpty()) { @@ -65,125 +81,111 @@ public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IPr } else { markerService.clear(); - - String jreHome = configuration.getJreHome(); - if (jreHome == null || jreHome.trim().isEmpty()) { - jreHome = WindupRuntimePlugin.computeJRELocation(); - } - - if (windupClient.isWindupServerRunning() && !windupClient.isJreRunning(jreHome)) { - StringBuilder buff = new StringBuilder(); - buff.append("Current JAVA_HOME: " + windupClient.getJavaHome()); //$NON-NLS-1$ - buff.append(System.lineSeparator()); - buff.append("Restarting using JAVA_HOME: " + jreHome); //$NON-NLS-1$ - WindupUIPlugin.getDefault().getLog().log( - new Status(IStatus.INFO, WindupUIPlugin.PLUGIN_ID, buff.toString())); - restartAndRun(configuration, jreHome); - } - - else if (!windupClient.isWindupServerRunning()) { - if (jreHome == null || jreHome.trim().isEmpty()) { - jreHome = WindupRuntimePlugin.computeJRELocation(); - } - launcher.start(new WindupServerCallbackAdapter(shell) { - @Override - public void windupNotExecutable() { - WindupUIPlugin.logErrorMessage("WindupLaunchDelegate:: unable to start the Windup."); //$NON-NLS-1$ - MessageDialog.openError(shell, - Messages.WindupNotExecutableTitle, - Messages.WindupNotExecutableInfo); - } - @Override - public void serverStart(IStatus status) { - if (status.getSeverity() == Status.ERROR) { - MessageDialog.openError(shell, - Messages.WindupStartingError, - status.getMessage()); - WindupUIPlugin.logErrorMessage("WindupLaunchDelegate:: unable to start the Windup. Message: " + status.getMessage()); //$NON-NLS-1$ - } - if (status.isOK()) { - runWindup(configuration); - } - } - @Override - public void serverShutdown(IStatus status) {} - }, jreHome); - } - else { - runWindup(configuration); - } + this.runKantra(configuration); } } - private void restartAndRun(ConfigurationElement configuration, String jreHome) { - launcher.shutdown(new WindupServerCallbackAdapter(shell) { - @Override - public void serverShutdown(IStatus status) { - Boolean shutdown; - if (status.isOK()) { - shutdown = Boolean.TRUE; - } - else { - shutdown = Boolean.FALSE; - MessageDialog.openError(shell, - Messages.WindupShuttingDownError, - status.getMessage()); - WindupUIPlugin.logErrorMessage("WindupLaunchDelegate:: unable to shutdown the Windup. " + status.getMessage()); //$NON-NLS-1$ - } - if (shutdown) { - launcher.start(new WindupServerCallbackAdapter(shell) { - @Override - public void windupNotExecutable() { - MessageDialog.openError(shell, - Messages.WindupNotExecutableTitle, - Messages.WindupNotExecutableInfo); - WindupUIPlugin.logErrorMessage("WindupLaunchDelegate:: unable to start the Windup. Script not executable."); //$NON-NLS-1$ - } - @Override - public void serverStart(IStatus status) { - if (status.getSeverity() == IStatus.ERROR || !windupClient.isWindupServerRunning()) { - StringBuilder builder = new StringBuilder(); - builder.append(Messages.WindupNotStartedMessage); - builder.append(status.getMessage()); - builder.append(System.lineSeparator()); - builder.append(System.lineSeparator()); - builder.append(Messages.WindupNotStartedDebugInfo); - builder.append(System.lineSeparator()); - builder.append(Messages.WindupStartNotStartingSolution1); - builder.append(System.lineSeparator()); - builder.append(Messages.WindupStartNotStartingSolution2); - builder.append(System.lineSeparator()); - builder.append(Messages.WindupStartNotStartingSolution3); - builder.append(System.lineSeparator()); - builder.append(Messages.WindupStartNotStartingSolution4); - builder.append(System.lineSeparator()); - builder.append(Messages.WindupStartNotStartingSolution5); - RHAMTStartupFailedDialog dialog = new RHAMTStartupFailedDialog(Display.getDefault().getActiveShell()); - dialog.open(); - WindupUIPlugin.logErrorMessage("WindupLaunchDelegate:: Failed to start the Windup. Message:" + status.getMessage()); //$NON-NLS-1$ - } - if(windupClient.isWindupServerRunning()) { - runWindup(configuration); - } - } - }, jreHome); - } + private MessageConsole findConsole(String name) { + ConsolePlugin plugin = ConsolePlugin.getDefault(); + IConsoleManager conMan = plugin.getConsoleManager(); + IConsole[] existing = conMan.getConsoles(); + for (int i = 0; i < existing.length; i++) + if (name.equals(existing[i].getName())) + return (MessageConsole) existing[i]; + MessageConsole myConsole = new MessageConsole(name, null); + conMan.addConsoles(new IConsole[]{myConsole}); + return myConsole; + } + + private void runKantra(ConfigurationElement configuration) { + if (WindupLaunchDelegate.activeRunner != null) { + WindupLaunchDelegate.activeRunner.kill(); + } + if (kantraJob != null) { + kantraJob.cancel(); + } + + MessageConsole myConsole = findConsole("kantra"); + MessageConsoleStream out = myConsole.newMessageStream(); + + Display.getDefault().syncExec(() -> { + try { + IConsoleView view = (IConsoleView)PlatformUI.getWorkbench().getActiveWorkbenchWindow(). + getActivePage().showView(IConsoleConstants.ID_CONSOLE_VIEW); + view.display(myConsole); + } catch (PartInitException e) { + WindupUIPlugin.log(e); } }); - } + + + kantraJob = new Job(NLS.bind(Messages.generate_windup_report_for, configuration.getName())) { + @Override + protected IStatus run(IProgressMonitor monitor) { + kantraMonitor = monitor; + while (!monitor.isCanceled()) {} + return Status.OK_STATUS; + } + }; + kantraJob.addJobChangeListener(new JobChangeAdapter() { + @Override + public void done(IJobChangeEvent event) { + super.done(event); + System.out.println("kantra job done"); + WindupLaunchDelegate.activeRunner.kill(); + kantraMonitor.done(); + } + }); + kantraJob.setUser(false); + kantraJob.schedule(); + + + WindupLaunchDelegate.activeRunner = new KantraRunner(); + + + Set inputs = configuration.getInputs().stream().map(i -> i.getLocation()).collect(Collectors.toSet()); + List sources = Lists.newArrayList(); + List targets = Lists.newArrayList(); + String output = configuration.getOutputLocation(); + + for (Pair pair : configuration.getOptions()) { + String name = pair.getKey(); + String value = pair.getValue(); + if (name.equals("input")) { + inputs.add(value); + } + if (name.equals("source")) { + sources.add(value); + } + if (name.equals("target")) { + targets.add(value); + } + } + if (targets.isEmpty()) { + targets.add("quarkus"); + } + if (sources.isEmpty()) { + sources.add("springboot"); + } - private void runWindup(ConfigurationElement configuration) { - Job job = new Job(NLS.bind(Messages.generate_windup_report_for, configuration.getName())) { - @Override - protected IStatus run(IProgressMonitor monitor) { - viewService.launchStarting(); - IStatus status = windupService.generateGraph(configuration, monitor); - viewService.renderReport(configuration); - markerService.generateMarkersForConfiguration(configuration); - return status; - } - }; - job.setUser(true); - job.schedule(); + viewService.launchStarting(); + Consumer onMessage = (msg) -> { + System.out.println("onMessage: " + msg); + Display.getDefault().asyncExec(() -> { + out.println(msg.toString()); + }); + }; + Consumer onComplete = (msg) -> { + System.out.println("onComplete: " + msg); + viewService.renderReport(configuration); + markerService.generateMarkersForConfiguration(configuration); + kantraJob.cancel(); + }; + Consumer onFailed = (msg) -> { + System.out.println("onFailed: " + msg); + System.out.println(msg.toString()); + kantraJob.cancel(); + }; + WindupLaunchDelegate.activeRunner.runKantra(inputs, output, sources, targets, onMessage, onComplete, onFailed); } }