diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index f548635ec8..e2a8e55211 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -16,10 +16,6 @@ dom4j 1.6.1 - - org.jboss.windup - windup-tooling-api - org.jboss.windup.config windup-config-api @@ -76,6 +72,10 @@ + + org.jboss.windup + windup-tooling-api + org.jboss.windup.utils windup-utils diff --git a/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java b/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java index f633752dca..418523a2ca 100644 --- a/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java +++ b/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java @@ -13,7 +13,7 @@ import org.jboss.windup.bootstrap.commands.CommandPhase; import org.jboss.windup.bootstrap.commands.CommandResult; import org.jboss.windup.bootstrap.commands.addons.AddImmutableAddonDirectoryCommand; -import org.jboss.windup.tooling.ExecutionBuilder; +import org.jboss.windup.tooling.ToolingRMIServer; public class ServerModeCommand implements Command { @@ -87,21 +87,10 @@ private int getServerPort() { return Integer.valueOf(serverPortString); } - private void startServer() + private void startServer() { - try - { - System.setProperty("java.rmi.server.hostname","192.168.1.2"); - //System.setProperty("java.security.policy", "all.policy"); - ExecutionBuilder executionBuilder = furnace.getAddonRegistry().getServices(ExecutionBuilder.class).get(); - ExecutionBuilder proxy = (ExecutionBuilder)UnicastRemoteObject.exportObject(executionBuilder, 0); - Registry registry = LocateRegistry.createRegistry(port); - registry.rebind(ExecutionBuilder.LOOKUP_NAME, proxy); - System.out.println("Registered ExecutionBuilder at: " + registry); - } catch (RemoteException e) { - System.out.println("Bootstrap error while registering ExecutionBuilder..."); - e.printStackTrace(); - } + System.out.println("Calling ToolingRMIServer start..."); + furnace.getAddonRegistry().getServices(ToolingRMIServer.class).get().startServer(port); } // TODO: Not sure if this is necessary, or if killing the processes is sufficient. diff --git a/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java b/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java new file mode 100644 index 0000000000..1f2f9f9053 --- /dev/null +++ b/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java @@ -0,0 +1,67 @@ +package org.jboss.windup.tooling; + +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; +import java.util.Arrays; + +import javax.inject.Inject; + +import org.jboss.forge.furnace.Furnace; + +/** + * @author Jesse Sightler + */ +public class ToolingRMIServer +{ + @Inject + private Furnace furnace; + + @Inject + private ExecutionBuilder executionBuilder; + + public void startServer(int port) + { + + System.out.println("Registering RMI Server..."); + try + { + Registry registry = LocateRegistry.getRegistry(port); + try + { + String[] registered = registry.list(); + if (Arrays.asList(registered).contains(ExecutionBuilder.LOOKUP_NAME)) + registry.unbind(ExecutionBuilder.LOOKUP_NAME); + + try + { + UnicastRemoteObject.unexportObject(executionBuilder, true); + } + catch (Throwable t) + { + System.out.println("Could not unexport due to: " + t.getMessage()); + } + } + catch (Throwable t) + { + t.printStackTrace(); + System.out.println("Registry not already there, starting..."); + registry = LocateRegistry.createRegistry(port); + } + + // System.setProperty("java.rmi.server.hostname","192.168.1.2"); + // System.setProperty("java.security.policy", "all.policy"); + // ExecutionBuilder executionBuilder = furnace.getAddonRegistry().getServices(ExecutionBuilder.class).get(); + + ExecutionBuilder proxy = (ExecutionBuilder) UnicastRemoteObject.exportObject(executionBuilder, 0); + registry.rebind(ExecutionBuilder.LOOKUP_NAME, proxy); + System.out.println("Registered ExecutionBuilder at: " + registry); + } + catch (RemoteException e) + { + System.out.println("Bootstrap error while registering ExecutionBuilder..."); + e.printStackTrace(); + } + } +}