Search in sources :

Example 11 with CDKServer

use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.

the class CDKLaunchController method performOverrides.

protected void performOverrides(ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
    // Overrides, things that should always match whats in server editor
    final IServer s = ServerUtil.getServer(workingCopy);
    final CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
    String workingDir = s.getAttribute(CDKServer.PROP_FOLDER, (String) null);
    workingCopy.setAttribute(ATTR_WORKING_DIR, workingDir);
    Map<String, String> env = workingCopy.getAttribute(ENVIRONMENT_VARS_KEY, (Map<String, String>) null);
    if (env == null) {
        env = new HashMap<>();
    } else {
        // no guarantee existing map is editable
        env = new HashMap<>(env);
    }
    String userKey = cdkServer.getUserEnvironmentKey();
    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.
        env.put(userKey, cdkServer.getUsername());
    } else {
        env.remove(userKey);
    }
    String vLoc = VagrantBinaryUtility.getVagrantLocation(workingCopy);
    if (vLoc != null) {
        String vagrantCmdFolder = new Path(vLoc).removeLastSegments(1).toOSString();
        CommandLocationLookupStrategy.get().ensureOnPath(env, vagrantCmdFolder);
        workingCopy.setAttribute(IExternalToolConstants.ATTR_LOCATION, vLoc);
    }
    if (Platform.getOS().equals(Platform.OS_WIN32)) {
        // We need to set the cygwin flag
        env.put("VAGRANT_DETECTED_OS", "cygwin");
    }
    workingCopy.setAttribute(ENVIRONMENT_VARS_KEY, env);
}
Also used : Path(org.eclipse.core.runtime.Path) 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 12 with CDKServer

use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.

the class CDKLaunchUtility method getEnvironment.

private static Map<String, String> getEnvironment(IServer s, ILaunchConfiguration startupConfig, boolean skipCredentials) throws CoreException {
    final CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
    // Set the environment flag
    boolean passCredentials = cdkServer.passCredentials();
    if (passCredentials && !skipCredentials) {
        String[] userPass = getUserPass(s);
        String userName = userPass[0];
        String pass = userPass[1];
        Map<String, String> existingEnvironment = startupConfig.getAttribute(ENVIRONMENT_VARS_KEY, (Map<String, String>) null);
        if (existingEnvironment == null) {
            existingEnvironment = new HashMap<>();
        }
        if (userName == null) {
            // This is an error situation and the user should be made aware
            throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "The credentials for " + s.getName() + " are invalid. No username found. Please open your server editor " + "and set your access.redhat.com credentials."));
        }
        HashMap<String, String> env = new HashMap<>(existingEnvironment);
        String userKey = cdkServer.getUserEnvironmentKey();
        env.put(userKey, userName);
        String passKey = cdkServer.getPasswordEnvironmentKey();
        if (pass == null) {
            // This is an error situation and the user should be made aware
            throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "The credentials for " + s.getName() + " are invalid. No password found for username " + cdkServer.getUsername() + " for the access.redhat.com domain. Please open your server editor " + "set your access.redhat.com credentials."));
        }
        if (passKey != null && pass != null)
            env.put(passKey, pass);
        return env;
    } else {
        return startupConfig.getAttribute(ENVIRONMENT_VARS_KEY, (Map<String, String>) null);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 13 with CDKServer

use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.

the class CDKLaunchUtility method getUserPass.

private static final String[] getUserPass(IServer server) {
    final CDKServer cdkServer = (CDKServer) server.loadAdapter(CDKServer.class, new NullProgressMonitor());
    String user = cdkServer.getUsername();
    String pass = null;
    try {
        pass = cdkServer.getPassword();
    } catch (UsernameChangedException uce) {
        pass = uce.getPassword();
        user = uce.getUser();
    }
    return new String[] { user, pass };
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) UsernameChangedException(org.jboss.tools.foundation.core.credentials.UsernameChangedException) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 14 with CDKServer

use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.

the class AbstractCDKShutdownController method shutdownViaLaunch.

private void shutdownViaLaunch() throws CoreException {
    String args = getShutdownArgs();
    String cmd = getCommandLocation();
    CDKServer cdk = (CDKServer) getServer().loadAdapter(CDKServer.class, new NullProgressMonitor());
    ILaunchConfiguration lc = getServer().getLaunchConfiguration(true, new NullProgressMonitor());
    ILaunchConfigurationWorkingCopy lc2 = new CDKLaunchUtility().createExternalToolsLaunch(getServer(), args, new Path(cmd).lastSegment(), lc, cmd, cdk.skipUnregistration());
    IProcess p = null;
    ILaunch launch = null;
    try {
        launch = lc2.launch("run", new NullProgressMonitor());
        IProcess[] all = launch.getProcesses();
        if (all.length > 0)
            p = all[0];
    } catch (CoreException ce) {
        CDKCoreActivator.pluginLog().logError(ce);
        getBehavior().setServerStarted();
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, ce.getMessage(), ce));
    }
    if (p == null) {
        getBehavior().setServerStopped();
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "Call to shutdown command has failed."));
    }
    final IProcess myProcess = p;
    IDebugEventSetListener listener = (new IDebugEventSetListener() {

        public void handleDebugEvents(DebugEvent[] events) {
            if (events != null) {
                int size = events.length;
                for (int i = 0; i < size; i++) {
                    if (myProcess != null && myProcess.equals(events[i].getSource()) && events[i].getKind() == DebugEvent.TERMINATE) {
                        processTerminated(getServer(), null);
                        DebugPlugin.getDefault().removeDebugEventListener(this);
                    }
                }
            }
        }
    });
    DebugPlugin.getDefault().addDebugEventListener(listener);
}
Also used : Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) DebugEvent(org.eclipse.debug.core.DebugEvent) CoreException(org.eclipse.core.runtime.CoreException) ILaunch(org.eclipse.debug.core.ILaunch) IProcess(org.eclipse.debug.core.model.IProcess) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 15 with CDKServer

use of org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer in project jbosstools-openshift by jbosstools.

the class CDK3ShutdownController method getShutdownArgs.

protected String getShutdownArgs() {
    IServer s = getServer();
    CDKServer cdk = null;
    if (s != null)
        cdk = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
    String profiles = CDK3LaunchController.getProfileString(getServer());
    String cmd = profiles + "stop";
    if (cdk != null) {
        boolean skipUnregistration = cdk.skipUnregistration();
        if (skipUnregistration) {
            cmd += " --skip-unregistration";
        }
    }
    return cmd;
}
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)

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