Search in sources :

Example 1 with CDKServer

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

the class CDKLaunchEnvironmentUtil method createEnvironment.

public static Map<String, String> createEnvironment(IServer server, String password, String user) {
    Map<String, String> launchEnv = null;
    try {
        ILaunchConfiguration wc = server.getLaunchConfiguration(false, new NullProgressMonitor());
        if (wc != null)
            launchEnv = wc.getAttribute(IExternalLaunchConstants.ENVIRONMENT_VARS_KEY, (Map<String, String>) null);
    } catch (CoreException ce) {
        CDKCoreActivator.pluginLog().logWarning("Unable to load environment for vagrant status call. System environment will be used instead.");
    }
    HashMap<String, String> systemEnv = new HashMap<>(System.getenv());
    if (launchEnv != null) {
        Iterator<String> it = launchEnv.keySet().iterator();
        String k = null;
        while (it.hasNext()) {
            k = it.next();
            systemEnv.put(k, launchEnv.get(k));
        }
    }
    CDKServer cdkServer = (CDKServer) server.loadAdapter(CDKServer.class, new NullProgressMonitor());
    boolean passCredentials = cdkServer.passCredentials();
    String userKey = cdkServer.getUserEnvironmentKey();
    String passKey = cdkServer.getPasswordEnvironmentKey();
    if (passCredentials) {
        systemEnv.put(userKey, user);
        systemEnv.put(passKey, password);
    } else {
        systemEnv.remove(userKey);
        systemEnv.remove(passKey);
    }
    return systemEnv;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 2 with CDKServer

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

the class CDKLaunchEnvironmentUtil method createEnvironment.

public static Map<String, String> createEnvironment(IServer server, boolean skipCredentials) {
    CDKServer cdkServer = (CDKServer) server.loadAdapter(CDKServer.class, new NullProgressMonitor());
    boolean passCredentials = cdkServer.passCredentials();
    String pass = null;
    if (passCredentials && !skipCredentials) {
        try {
            pass = cdkServer.getPassword();
        } catch (UsernameChangedException uce) {
            return createEnvironment(server, uce.getPassword(), uce.getUser());
        }
    }
    return createEnvironment(server, 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 3 with CDKServer

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

the class CDK3LaunchController method performOverrides.

@Override
protected void performOverrides(ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
    // Overrides, things that should always match whats in server editor
    final IServer s = getServerFromLaunch(workingCopy);
    final CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
    performOverrides(workingCopy, s, cdkServer);
}
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 4 with CDKServer

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

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

Example 5 with CDKServer

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

the class CDK3LaunchController method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    final IServer s = ServerUtil.getServer(configuration);
    if (s == null) {
        throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Unable to locate server from launch configuration."));
    }
    final ControllableServerBehavior beh = (ControllableServerBehavior) JBossServerBehaviorUtils.getControllableBehavior(configuration);
    beh.setServerStarting();
    String minishiftLoc = MinishiftBinaryUtility.getMinishiftLocation(s);
    if (minishiftLoc == null || !(new File(minishiftLoc).exists())) {
        beh.setServerStopped();
        if (minishiftLoc == null)
            throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Unable to locate minishift command. Please set a correct value in the server editor."));
        throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Expected location of minishift command does not exist: " + minishiftLoc + "\nPlease set a correct value in the server editor."));
    }
    CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
    boolean passCredentials = cdkServer.passCredentials();
    boolean skipReg = cdkServer.skipRegistration();
    if (passCredentials && !skipReg) {
        handleCredentialsDuringLaunch(s, cdkServer, beh);
    }
    // Poll the server once more
    IStatus stat = getCDKPoller(s).getCurrentStateSynchronous(s);
    if (stat.isOK()) {
        beh.setServerStarted();
        ((Server) beh.getServer()).setMode("run");
        return;
    }
    String args = configuration.getAttribute(ATTR_ARGS, (String) null);
    // Add listener first
    IDebugEventSetListener debug = getDebugListener(launch);
    DebugPlugin.getDefault().addDebugEventListener(debug);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.DEBUG_LISTENER, debug);
    Process p = null;
    try {
        CDKServer cdk = (CDKServer) getServer().loadAdapter(CDKServer.class, new NullProgressMonitor());
        p = new CDKLaunchUtility().callMinishiftConsole(s, args, getStartupLaunchName(s), cdk.skipRegistration());
    } catch (IOException ioe) {
        CDKCoreActivator.pluginLog().logError(ioe);
        beh.setServerStopped();
        DebugPlugin.getDefault().removeDebugEventListener(debug);
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, ioe.getMessage(), ioe));
    }
    if (p == null) {
        beh.setServerStopped();
        DebugPlugin.getDefault().removeDebugEventListener(debug);
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "Call to minishift up has failed."));
    }
    IProcess process = addProcessToLaunch(p, launch, s, false, minishiftLoc);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.PROCESS, process);
}
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) CDK3Server(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDK3Server) IServer(org.eclipse.wst.server.core.IServer) CDK32Server(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDK32Server) IProcess(org.eclipse.debug.core.model.IProcess) IOException(java.io.IOException) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) CoreException(org.eclipse.core.runtime.CoreException) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) File(java.io.File) IProcess(org.eclipse.debug.core.model.IProcess) 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