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;
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations