Search in sources :

Example 6 with CDKServer

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer) Server(org.eclipse.wst.server.core.internal.Server) IServer(org.eclipse.wst.server.core.IServer) IProcess(org.eclipse.debug.core.model.IProcess) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) CoreException(org.eclipse.core.runtime.CoreException) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) IControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior) File(java.io.File) IProcess(org.eclipse.debug.core.model.IProcess) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 7 with CDKServer

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());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServer(org.eclipse.wst.server.core.IServer) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 8 with CDKServer

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);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 9 with CDKServer

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;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IServerType(org.eclipse.wst.server.core.IServerType) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 10 with CDKServer

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"));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServer(org.eclipse.wst.server.core.IServer) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer) Test(org.junit.Test)

Aggregations

CDKServer (org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)17 IServer (org.eclipse.wst.server.core.IServer)11 CoreException (org.eclipse.core.runtime.CoreException)5 HashMap (java.util.HashMap)4 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 IDebugEventSetListener (org.eclipse.debug.core.IDebugEventSetListener)3 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)3 IProcess (org.eclipse.debug.core.model.IProcess)3 File (java.io.File)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Path (org.eclipse.core.runtime.Path)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 Server (org.eclipse.wst.server.core.internal.Server)2 ControllableServerBehavior (org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior)2 UsernameChangedException (org.jboss.tools.foundation.core.credentials.UsernameChangedException)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Map (java.util.Map)1