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