1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

[416048] [dstore] Using a remote shell does not work on Windows

7/Windows Server 2008r2
This commit is contained in:
Dave McKnight 2013-08-28 10:23:35 -04:00
parent dee9e1beaf
commit e9270848ae

View file

@ -1,337 +1,396 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2012 IBM Corporation and others. * Copyright (c) 2002, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Initial Contributors: * Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer * The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir, * component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* David McKnight (IBM) - [225507][api][breaking] RSE dstore API leaks non-API types * David McKnight (IBM) - [225507][api][breaking] RSE dstore API leaks non-API types
* David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed * David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed
* David McKnight (IBM) - [390037] [dstore] Duplicated items in the System view * David McKnight (IBM) - [390037] [dstore] Duplicated items in the System view
* David McKnight (IBM) - [396440] [dstore] fix issues with the spiriting mechanism and other memory improvements (phase 1) * David McKnight (IBM) - [396440] [dstore] fix issues with the spiriting mechanism and other memory improvements (phase 1)
*******************************************************************************/ * David McKnight (IBM) - [416048] [dstore] Using a remote shell does not work on Windows 7/Windows Server 2008r2
*******************************************************************************/
package org.eclipse.dstore.core.util;
package org.eclipse.dstore.core.util;
import java.util.ArrayList;
import java.util.ArrayList;
import org.eclipse.dstore.core.model.DE;
import org.eclipse.dstore.core.model.DataElement; import org.eclipse.dstore.core.model.DE;
import org.eclipse.dstore.core.model.DataStore; import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStoreResources; import org.eclipse.dstore.core.model.DataStore;
import org.eclipse.dstore.core.model.DataStoreResources;
/**
* This class is used to generate command object instances from command /**
* descriptors and arguments to commands. Command instances are instances of * This class is used to generate command object instances from command
* command descriptors. Each command instance contains a set of data arguments * descriptors and arguments to commands. Command instances are instances of
* and a status object, that represents the current state of a command. After a * command descriptors. Each command instance contains a set of data arguments
* command instance is created, it is referenced in the command log for the * and a status object, that represents the current state of a command. After a
* DataStore. * command instance is created, it is referenced in the command log for the
* * DataStore.
* @noextend This class is not intended to be subclassed by clients. *
* @noinstantiate This class is not intended to be instantiated by clients. * @noextend This class is not intended to be subclassed by clients.
* @since 3.0 moved from non-API to API * @noinstantiate This class is not intended to be instantiated by clients.
*/ * @since 3.0 moved from non-API to API
public class CommandGenerator */
{ public class CommandGenerator
private DataStore _dataStore = null; {
private DataElement _log = null; private DataStore _dataStore = null;
private DataElement _log = null;
/**
* Constructor /**
*/ * Constructor
public CommandGenerator() */
{ public CommandGenerator()
} {
}
/**
* Sets the associated DataStore /**
* @param dataStore the associated DataStore * Sets the associated DataStore
*/ * @param dataStore the associated DataStore
public void setDataStore(DataStore dataStore) */
{ public void setDataStore(DataStore dataStore)
_dataStore = dataStore; {
_log = _dataStore.getLogRoot(); _dataStore = dataStore;
} _log = _dataStore.getLogRoot();
}
/**
* This method logs the current command object in the DataStore command log. For each /**
* logged command, a status object is created and returned. * This method logs the current command object in the DataStore command log. For each
* @param commandObject the commandObject to log * logged command, a status object is created and returned.
* @return the status object of the command * @param commandObject the commandObject to log
*/ * @return the status object of the command
public DataElement logCommand(DataElement commandObject) */
{ public DataElement logCommand(DataElement commandObject)
try {
{ try
// create time and status objects {
StringBuffer id = new StringBuffer(commandObject.getId()); // create time and status objects
id.append(DataStoreResources.model_status); StringBuffer id = new StringBuffer(commandObject.getId());
_dataStore.createObject( id.append(DataStoreResources.model_status);
commandObject, _dataStore.createObject(
DataStoreResources.model_status, commandObject,
DataStoreResources.model_start, DataStoreResources.model_status,
"", //$NON-NLS-1$ DataStoreResources.model_start,
id.toString()); "", //$NON-NLS-1$
id.toString());
_log.addNestedData(commandObject, false);
_log.addNestedData(commandObject, false);
}
catch (Exception e) }
{ catch (Exception e)
_dataStore.trace(e); {
} _dataStore.trace(e);
}
return commandObject;
} return commandObject;
}
/**
* Creates a new command instance object from a command descriptor /**
* @param commandDescriptor the descriptor of the command to create * Creates a new command instance object from a command descriptor
* @return the new command instance * @param commandDescriptor the descriptor of the command to create
*/ * @return the new command instance
public DataElement createCommand(DataElement commandDescriptor) */
{ public DataElement createCommand(DataElement commandDescriptor)
if (commandDescriptor != null) {
{ if (commandDescriptor != null)
if (commandDescriptor.getType().equals(DE.T_COMMAND_DESCRIPTOR)) {
{ if (commandDescriptor.getType().equals(DE.T_COMMAND_DESCRIPTOR))
DataElement commandInstance = _dataStore.createObject(null, commandDescriptor.getName(), commandDescriptor.getValue(), commandDescriptor.getSource()); {
commandInstance.setDescriptor(commandDescriptor); DataElement commandInstance = _dataStore.createObject(null, commandDescriptor.getName(), commandDescriptor.getValue(), commandDescriptor.getSource());
return commandInstance; commandInstance.setDescriptor(commandDescriptor);
} return commandInstance;
else }
{ else
System.out.println("not cd -> " + commandDescriptor); //$NON-NLS-1$ {
return null; System.out.println("not cd -> " + commandDescriptor); //$NON-NLS-1$
} return null;
} }
else }
{ else
return null; {
} return null;
} }
}
private void clearDeleted(DataElement element)
{ private void clearDeleted(DataElement element)
for (int i = 0; i < element.getNestedSize(); i++) {
{ for (int i = 0; i < element.getNestedSize(); i++)
DataElement child = element.get(i).dereference(); {
if (child.isDeleted()) DataElement child = element.get(i);
{ if (child != null && child.isDeleted())
element.removeNestedData(child); {
} element.removeNestedData(child);
} }
} }
}
/**
* Creates a new command from a command descriptor and it's arguments. /**
* * Creates a new command from a command descriptor and it's arguments.
* @param commandDescriptor the command type of the new command *
* @param arguments the arguments for the command, besides the subject * @param commandDescriptor the command type of the new command
* @param dataObject the subject of the command * @param arguments the arguments for the command, besides the subject
* @param refArg indicates whether the subject should be represented as a reference or directly * @param dataObject the subject of the command
* @return the status object of the command * @param refArg indicates whether the subject should be represented as a reference or directly
*/ * @return the status object of the command
public DataElement generateCommand(DataElement commandDescriptor, ArrayList arguments, DataElement dataObject, boolean refArg) */
{ public DataElement generateCommand(DataElement commandDescriptor, ArrayList arguments, DataElement dataObject, boolean refArg)
//refArg = false; {
DataElement commandObject = createCommand(commandDescriptor); //refArg = false;
if (commandObject != null) boolean subjectIsCommand = false;
{ DataElement commandObject = createCommand(commandDescriptor);
clearDeleted(dataObject); if (commandObject != null)
{
commandObject.setAttribute(DE.A_VALUE, commandDescriptor.getName()); if (commandObject.getSource().equals("*")){ //$NON-NLS-1$
// qualify it if we can
if (refArg && !dataObject.isSpirit()) DataElement subjectDescriptor = dataObject.getDescriptor();
{ if (subjectDescriptor != null){
_dataStore.createReference(commandObject, dataObject,DataStoreResources.model_contents); if (subjectDescriptor.getType().equals(DE.T_COMMAND_DESCRIPTOR)){
} commandObject.setAttribute(DE.A_SOURCE, dataObject.getSource());
else subjectIsCommand = true;
{ }
dataObject.setPendingTransfer(true); }
if (dataObject.isSpirit() && _dataStore.isVirtual()){ }
// resurrecting spirited element
dataObject.setSpirit(false); if (dataObject.isDescriptor()){
// clear out old data - otherwise, we can end up with duplicates //System.out.println("using descriptor as command subject! - " + dataObject); //$NON-NLS-1$
dataObject.removeNestedData(); //System.out.println("Command is "+commandObject.getName()); //$NON-NLS-1$
} refArg = true;
}
commandObject.addNestedData(dataObject, false); clearDeleted(dataObject);
}
commandObject.setAttribute(DE.A_VALUE, commandDescriptor.getName());
if (arguments != null)
{ if ((refArg || subjectIsCommand) && !dataObject.isSpirit())
for (int i = 0; i < arguments.size(); i++) {
{ _dataStore.createReference(commandObject, dataObject,DataStoreResources.model_contents);
DataElement arg = (DataElement) arguments.get(i); }
if (arg != null) else
{ {
if (!arg.isUpdated() || arg.isSpirit() || !refArg) dataObject.setPendingTransfer(true);
{ if (dataObject.isSpirit() && _dataStore.isVirtual()){
commandObject.addNestedData(arg, false); // resurrecting spirited element
} dataObject.setSpirit(false);
else // clear out old data - otherwise, we can end up with duplicates
{ dataObject.removeNestedData();
_dataStore.createReference(commandObject, arg, "argument"); //$NON-NLS-1$ }
}
} commandObject.addNestedData(dataObject, false);
} }
}
if (arguments != null)
return logCommand(commandObject); {
} for (int i = 0; i < arguments.size(); i++)
else {
{ DataElement arg = (DataElement)arguments.get(i);
return null; if (arg != null)
} {
} if (!arg.isUpdated() || arg.isSpirit() || !refArg)
{
commandObject.addNestedData(arg, false);
/** }
* Creates a new command from a command descriptor and it's arguments. else
* {
* @param commandDescriptor the command type of the new command _dataStore.createReference(commandObject, arg, "argument"); //$NON-NLS-1$
* @param arg the arguement for the command, besides the subject }
* @param dataObject the subject of the command }
* @param refArg indicates whether the subject should be represented as a reference or directly }
* @return the status object of the command }
*/
public DataElement generateCommand(DataElement commandDescriptor, DataElement arg, DataElement dataObject, boolean refArg) return logCommand(commandObject);
{ }
//refArg = false; else
{
DataElement commandObject = createCommand(commandDescriptor); return null;
if (commandObject != null) }
{ }
commandObject.setAttribute(DE.A_VALUE, commandDescriptor.getName());
clearDeleted(dataObject);
if (refArg && !dataObject.isSpirit()) /**
{ * Creates a new command from a command descriptor and it's arguments.
_dataStore.createReference(commandObject, dataObject,DataStoreResources.model_contents); *
} * @param commandDescriptor the command type of the new command
else * @param arg the arguement for the command, besides the subject
{ * @param dataObject the subject of the command
dataObject.setPendingTransfer(true); * @param refArg indicates whether the subject should be represented as a reference or directly
if (dataObject.isSpirit() && _dataStore.isVirtual()){ * @return the status object of the command
// resurrecting spirited element */
dataObject.setSpirit(false); public DataElement generateCommand(DataElement commandDescriptor, DataElement arg, DataElement dataObject, boolean refArg)
// clear out old data - otherwise, we can end up with duplicates {
dataObject.removeNestedData(); //refArg = false;
} boolean subjectIsCommand = false;
commandObject.addNestedData(dataObject, false); DataElement commandObject = createCommand(commandDescriptor);
} if (commandObject != null)
{
if (!arg.isUpdated() || arg.isSpirit() || !refArg) if (commandObject.getSource().equals("*")){ //$NON-NLS-1$
{ // qualify it if we can
commandObject.addNestedData(arg, false); DataElement subjectDescriptor = dataObject.getDescriptor();
} if (subjectDescriptor != null){
else if (subjectDescriptor.getType().equals(DE.T_COMMAND_DESCRIPTOR)){
{ commandObject.setAttribute(DE.A_SOURCE, dataObject.getSource());
_dataStore.createReference(commandObject, arg, "argument"); //$NON-NLS-1$ subjectIsCommand = true;
} }
}
}
return logCommand(commandObject);
} commandObject.setAttribute(DE.A_VALUE, commandDescriptor.getName());
else
{
return null; if (dataObject.isDescriptor()){
} //System.out.println("using descriptor as command subject! - " + dataObject); //$NON-NLS-1$
} //System.out.println("Command is "+commandObject.getName()); //$NON-NLS-1$
refArg = true;
/** }
* Creates a new command from a command descriptor and it's arguments. clearDeleted(dataObject);
* if ((refArg || subjectIsCommand) && !dataObject.isSpirit())
* @param commandDescriptor the command type of the new command {
* @param dataObject the subject of the command _dataStore.createReference(commandObject, dataObject,DataStoreResources.model_contents);
* @param refArg indicates whether the subject should be represented as a reference or directly }
* @return the status object of the command else
*/ {
public DataElement generateCommand(DataElement commandDescriptor, DataElement dataObject, boolean refArg) dataObject.setPendingTransfer(true);
{ if (dataObject.isSpirit() && _dataStore.isVirtual()){
//refArg = false; // resurrecting spirited element
DataElement commandObject = createCommand(commandDescriptor); dataObject.setSpirit(false);
if (commandObject != null) // clear out old data - otherwise, we can end up with duplicates
{ dataObject.removeNestedData();
commandObject.setAttribute(DE.A_VALUE, commandDescriptor.getName()); }
commandObject.addNestedData(dataObject, false);
clearDeleted(dataObject); }
if (refArg && !dataObject.isSpirit())
{ if (!arg.isUpdated() || arg.isSpirit() || !refArg)
_dataStore.createReference(commandObject, dataObject,DataStoreResources.model_arguments); {
} commandObject.addNestedData(arg, false);
else }
{ else
dataObject.setPendingTransfer(true); {
if (dataObject.isSpirit() && _dataStore.isVirtual()){ _dataStore.createReference(commandObject, arg, "argument"); //$NON-NLS-1$
// resurrecting spirited element }
dataObject.setSpirit(false);
// clear out old data - otherwise, we can end up with duplicates
dataObject.removeNestedData(); return logCommand(commandObject);
} }
commandObject.addNestedData(dataObject, false); else
} {
return null;
return logCommand(commandObject); }
} }
else
{ /**
return null; * Creates a new command from a command descriptor and it's arguments.
} *
} * @param commandDescriptor the command type of the new command
* @param dataObject the subject of the command
/** * @param refArg indicates whether the subject should be represented as a reference or directly
* Creates a response tree for transmitting a set of data from a server to a client. * @return the status object of the command
* */
* @param document the root of the response public DataElement generateCommand(DataElement commandDescriptor, DataElement dataObject, boolean refArg)
* @param objects the data contained in the response {
* @return the response tree root //refArg = false;
*/ boolean subjectIsCommand = false;
public DataElement generateResponse(DataElement document, ArrayList objects) DataElement commandObject = createCommand(commandDescriptor);
{ if (commandObject != null)
document.addNestedData(objects, false); {
return document; if (commandObject.getSource().equals("*")){ //$NON-NLS-1$
} // qualify it if we can
DataElement subjectDescriptor = dataObject.getDescriptor();
/** if (subjectDescriptor != null){
* Creates a response tree for transmitting a set of data from a server to a client. if (subjectDescriptor.getType().equals(DE.T_COMMAND_DESCRIPTOR)){
* commandObject.setAttribute(DE.A_SOURCE, dataObject.getSource());
* @param responseType the type of data to respond with subjectIsCommand = true;
* @param dataObject the child object in the response tree }
* @return the response tree root }
*/ }
public DataElement generateResponse(String responseType, DataElement dataObject)
{ commandObject.setAttribute(DE.A_VALUE, commandDescriptor.getName());
if (dataObject != null)
{
DataElement commandObject = _dataStore.createObject(null, "RESPONSE", responseType); //$NON-NLS-1$ if (dataObject.isDescriptor()){
commandObject.addNestedData(dataObject, true); //System.out.println("using descriptor as command subject! - " + dataObject); //$NON-NLS-1$
return commandObject; //System.out.println("Command is "+commandObject.getName()); //$NON-NLS-1$
} refArg = true;
else }
{ clearDeleted(dataObject);
return null; if ((refArg || subjectIsCommand) && !dataObject.isSpirit())
} {
} _dataStore.createReference(commandObject, dataObject,DataStoreResources.model_arguments);
}
/** else
* Creates a simple response object of the specified type {
* dataObject.setPendingTransfer(true);
* @param responseType the type of data to respond with if (dataObject.isSpirit() && _dataStore.isVirtual()){
* @return the response object // resurrecting spirited element
*/ dataObject.setSpirit(false);
public DataElement generateResponse(String responseType) // clear out old data - otherwise, we can end up with duplicates
{ dataObject.removeNestedData();
DataElement commandObject = _dataStore.createObject(null, "RESPONSE", responseType); //$NON-NLS-1$ }
return commandObject; commandObject.addNestedData(dataObject, false);
} }
}
return logCommand(commandObject);
}
else
{
return null;
}
}
/**
* Creates a response tree for transmitting a set of data from a server to a client.
*
* @param document the root of the response
* @param objects the data contained in the response
* @return the response tree root
*/
public DataElement generateResponse(DataElement document, ArrayList objects)
{
document.addNestedData(objects, false);
return document;
}
/**
* Creates a response tree for transmitting a set of data from a server to a client.
*
* @param responseType the type of data to respond with
* @param dataObject the child object in the response tree
* @return the response tree root
*/
public DataElement generateResponse(String responseType, DataElement dataObject)
{
if (dataObject != null)
{
DataElement commandObject = _dataStore.createObject(null, "RESPONSE", responseType); //$NON-NLS-1$
commandObject.addNestedData(dataObject, true);
return commandObject;
}
else
{
return null;
}
}
/**
* Creates a simple response object of the specified type
*
* @param responseType the type of data to respond with
* @return the response object
*/
public DataElement generateResponse(String responseType)
{
DataElement commandObject = _dataStore.createObject(null, "RESPONSE", responseType); //$NON-NLS-1$
return commandObject;
}
public DataElement generateOOMMessage(String msg){
DataElement oomMessage = _dataStore.createObject(null, "OOM", msg); //$NON-NLS-1$
return oomMessage;
}
}