use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.
the class CDKLaunchController method launch.
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
final IServer s = ServerUtil.getServer(configuration);
verifyServer(s);
final ControllableServerBehavior beh = (ControllableServerBehavior) JBossServerBehaviorUtils.getControllableBehavior(configuration);
beh.setServerStarting();
String vagrantLoc = VagrantBinaryUtility.getVagrantLocation(s);
if (vagrantLoc == null || !(new File(vagrantLoc).exists())) {
beh.setServerStopped();
if (vagrantLoc == null)
throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Unable to locate vagrant command. Please check the server's launch configuration on the 'Environment' tab to ensure that the command is available on your Path environment variable."));
throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Expected location of vagrant command does not exist: " + vagrantLoc));
}
CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
boolean passCredentials = cdkServer.passCredentials();
boolean skipReg = cdkServer.skipRegistration();
if (passCredentials && !skipReg) {
setBehaviourUserAndPassword(s, beh, cdkServer);
}
// Poll the server once more
IStatus stat = getCDKPoller(s).getCurrentStateSynchronous(s);
if (stat.isOK()) {
beh.setServerStarted();
((Server) beh.getServer()).setMode(ILaunchManager.RUN_MODE);
return;
}
String args = configuration.getAttribute(ATTR_ARGS, (String) null);
CDKServer cdk = (CDKServer) getServer().loadAdapter(CDKServer.class, new NullProgressMonitor());
Process p = getProcess(s, beh, args, cdk.skipRegistration());
if (p == null) {
beh.setServerStopped();
throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "Call to vagrant up has failed."));
}
IProcess process = addProcessToLaunch(p, launch, s, true);
IDebugEventSetListener debug = getDebugListener(new IProcess[] { process }, launch);
DebugPlugin.getDefault().addDebugEventListener(debug);
beh.putSharedData(AbstractStartJavaServerLaunchDelegate.PROCESS, process);
beh.putSharedData(AbstractStartJavaServerLaunchDelegate.DEBUG_LISTENER, debug);
}
use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.
the class CDKLaunchController method initialize.
public void initialize(ILaunchConfigurationWorkingCopy wc) throws CoreException {
final IServer s = ServerUtil.getServer(wc);
final CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
// for testing purposes.
// we can't mock final methods like getServer(), so we need to be creative
initialize(wc, cdkServer.getUsername(), cdkServer.getServer());
}
use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.
the class CDKLaunchController method initialize.
// NOT API! Made public for testing purposes
public void initialize(ILaunchConfigurationWorkingCopy wc, String userName, IServer server) throws CoreException {
wc.setAttribute(FLAG_INITIALIZED, true);
String workingDir = server.getAttribute(CDKServer.PROP_FOLDER, (String) null);
wc.setAttribute(ATTR_WORKING_DIR, workingDir);
CDKServer cdkServer = (CDKServer) server.loadAdapter(CDKServer.class, new NullProgressMonitor());
boolean passCredentials = cdkServer.passCredentials();
if (passCredentials) {
// These environment variables are visible AND persisted in the launch configuration.
// It is not safe to persist the password here, but rather add it on-the-fly to the
// program launch later on.
HashMap<String, String> env = new HashMap<>();
String userKey = cdkServer.getUserEnvironmentKey();
env.put(userKey, userName);
wc.setAttribute(ENVIRONMENT_VARS_KEY, env);
}
wc.setAttribute(ATTR_LOCATION, VagrantBinaryUtility.getVagrantLocation());
String args = CDKConstants.VAGRANT_CMD_UP + " " + CDKConstants.VAGRANT_FLAG_NO_COLOR;
wc.setAttribute(ATTR_ARGS, args);
}
use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.
the class CDK32LaunchControllerTest method mockServer.
private IServer mockServer() {
IServer server = mock(IServer.class);
when(server.getAttribute(CDKServer.PROP_PASS_CREDENTIALS, false)).thenReturn(Boolean.TRUE);
when(server.getAttribute(CDKServer.PROP_USER_ENV_VAR, CDKConstants.CDK_ENV_SUB_USERNAME)).thenReturn(CDKConstants.CDK_ENV_SUB_USERNAME);
when(server.getAttribute(CDK3Server.PROP_HYPERVISOR, CDK3Server.getHypervisors()[0])).thenReturn(CDK3Server.VIRTUALBOX);
when(server.getAttribute(CDK32Server.PROFILE_ID, (String) null)).thenReturn(CDK32Server.MINISHIFT_DEFAULT_PROFILE);
when(server.getAttribute(CDK3Server.MINISHIFT_FILE, (String) null)).thenReturn("/home/user/apps/minishift");
when(server.getName()).thenReturn(NAME);
CDKServer cdk = mock(CDKServer.class);
when(server.loadAdapter(eq(CDKServer.class), any(IProgressMonitor.class))).thenReturn(cdk);
when(cdk.passCredentials()).thenReturn(Boolean.TRUE);
when(cdk.getUserEnvironmentKey()).thenReturn(CDKConstants.CDK_ENV_SUB_USERNAME);
IServerType mockType = mock(IServerType.class);
when(server.getServerType()).thenReturn(mockType);
when(mockType.getId()).thenReturn(CDK32Server.CDK_V32_SERVER_TYPE);
return server;
}
use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.
the class CDK32LaunchControllerTest method testInitializeAndOverrides.
@Test
public void testInitializeAndOverrides() throws Exception {
ILaunchConfigurationWorkingCopy wc = mock(ILaunchConfigurationWorkingCopy.class);
when(wc.getAttribute(any(String.class), any(String.class))).thenAnswer(AdditionalAnswers.returnsSecondArg());
String userName = "Drumpf";
IServer server = mockServer();
when(wc.getName()).thenReturn(NAME);
ArgumentCaptor<String> keyCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> valCaptor = ArgumentCaptor.forClass(String.class);
CDKServer cdkServer = (CDKServer) server.loadAdapter(CDKServer.class, new NullProgressMonitor());
CDK3TestLaunchController controller = new CDK3TestLaunchController(server, cdkServer);
controller.initialize(wc, userName, server);
verify(wc, Mockito.times(1)).setAttribute(keyCaptor.capture(), valCaptor.capture());
List<String> allVals = valCaptor.getAllValues();
assertTrue(allVals.get(0).replace("\\", "/").endsWith(".metadata/.plugins/org.jboss.ide.eclipse.as.core"));
ArgumentCaptor<String> keyCaptor2 = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> valCaptor2 = ArgumentCaptor.forClass(String.class);
controller.performOverrides(wc);
verify(wc, Mockito.times(4)).setAttribute(keyCaptor2.capture(), valCaptor2.capture());
allVals = valCaptor2.getAllValues();
assertTrue(allVals.get(0).replace("\\", "/").endsWith(".metadata/.plugins/org.jboss.ide.eclipse.as.core"));
assertTrue(allVals.get(1).replace("\\", "/").endsWith(".metadata/.plugins/org.jboss.ide.eclipse.as.core"));
assertTrue(allVals.get(2).endsWith("/home/user/apps/minishift"));
assertTrue(allVals.get(3).endsWith("--profile minishift start --vm-driver=virtualbox"));
}
Aggregations