Exemple #1
0
  public IProcess execute(final Command command, IPipe in, IPipe out) throws CoreException {
    ExecutionNode node = new ExecutionNode();
    node.command = (Command) EcoreUtil.copy(command);
    node.input = in == null ? createPipe().close(Status.OK_STATUS) : in;
    node.output = out == null ? createPipe() : out;
    node.process = new Process(this, node.input, node.output);

    try {
      commands.put(node);
    } catch (InterruptedException e) {
      throw new CoreException(
          new Status(
              Status.ERROR,
              EclTcpClientPlugin.PLUGIN_ID,
              "Failed to execute ecl command: " + command.getClass().getName(),
              e));
    }

    return node.process;
  }
  // TODO ! need new presentation of set-text-selection command or hide args
  protected void convertSimple(Command command, ICommandFormatter formatter, boolean hasInput) {
    String commandName = CoreUtils.getScriptletNameByClass(command.eClass());
    formatter.addCommandName(commandName);

    Map<EStructuralFeature, Command> bindingMap = new HashMap<EStructuralFeature, Command>();
    for (Binding b : command.getBindings()) {
      bindingMap.put(b.getFeature(), b.getCommand());
    }

    List<EStructuralFeature> attributes = CoreUtils.getFeatures(command.eClass());

    boolean forced = false;
    boolean bigTextCommand =
        commandName.equals("upload-file") || commandName.equals("match-binary");

    for (EStructuralFeature feature : attributes) {
      if (feature.getEAnnotation(CoreUtils.INTERNAL_ANN) != null) continue;
      if (feature.getEAnnotation(CoreUtils.INPUT_ANN) != null && hasInput) continue;
      String name = feature.getName();
      if (isForced(commandName, name)) forced = true;
      Object val = command.eGet(feature);
      boolean skippped = true;
      Object defaultValue = feature.getDefaultValue();
      boolean isDefault = val == null || val.equals(defaultValue);
      if (!isDefault) {
        if (feature instanceof EAttribute) {
          EAttribute attr = (EAttribute) feature;
          String type = attr.getEAttributeType().getInstanceTypeName();
          if (val instanceof List<?>) {
            List<?> list = (List<?>) val;
            for (Object o : list) {
              String value = convertValue(o, type);
              if (value != null) {
                formatter.addAttrName(name, forced);
                formatter.addAttrValue(value);
                skippped = false;
              }
            }
          } else {
            if (val.equals(true)) {
              forced = true;
              formatter.addAttrName(name, forced);
            } else {
              String value = convertValue(val, type);
              if (value != null) {
                formatter.addAttrName(name, forced);
                if (bigTextCommand) formatter.addAttrValueWithLineBreak(value);
                else formatter.addAttrValue(value);
                skippped = false;
              }
            }
          }
        } else {
          EReference ref = (EReference) feature;
          EClass eclass = ref.getEReferenceType();
          if (eclass.getEPackage() == CorePackage.eINSTANCE
              && eclass.getClassifierID() == CorePackage.COMMAND) {
            boolean singleLine = !(val instanceof Sequence);
            formatter.addAttrName(name, forced);
            formatter.openGroup(singleLine);
            doConvert((Command) val, formatter, true);
            formatter.closeGroup(singleLine);
            skippped = false;
          } else {
            IParamConverter<?> converter =
                ParamConverterManager.getInstance().getConverter(eclass.getInstanceClass());
            if (converter != null) {
              try {
                String strVal = String.format("\"%s\"", converter.convertToCode(val));
                formatter.addAttrValue(strVal);
              } catch (CoreException e) {
                CorePlugin.log(e.getStatus());
              }
            }
          }
        }
      } else {
        Command c = bindingMap.get(feature);
        if (c != null) {
          formatter.addAttrName(name, forced);
          formatter.openExec();
          doConvert(c, formatter, hasInput);
          formatter.closeExec();
          skippped = false;
        }
      }
      if (skippped) forced = true;
    }
  }