/** {@inheritDoc} */
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();

    TemplateParameter templ = (TemplateParameter) argument;
    ImplementationSettings implSettings = templ.getImplSettings();
    Implementation impl = templ.getImpl();
    SoftPkg softPkg = (SoftPkg) impl.eContainer();
    String PREFIX =
        gov.redhawk.ide.codegen.util.CodegenFileHelper.getPreferredFilePrefix(
            softPkg, implSettings);
    boolean hasSddsPort = false;
    Date date = new Date(System.currentTimeMillis());
    EList<Provides> provides =
        softPkg.getDescriptor().getComponent().getComponentFeatures().getPorts().getProvides();

    for (Provides entry : provides) {
      if (entry.getRepID().contains("BULKIO/dataSDDS")) {
        hasSddsPort = true;
      }
    }

    stringBuffer.append(TEXT_1);
    stringBuffer.append(ModelUtil.getSpdFileName(softPkg));
    stringBuffer.append(TEXT_2);
    stringBuffer.append(date.toString());

    String[] output;
    IProduct product = Platform.getProduct();
    if (product != null) {
      output = product.getProperty("aboutText").split("\n");

      stringBuffer.append(TEXT_3);
      stringBuffer.append(output[0]);
      stringBuffer.append(TEXT_4);
      stringBuffer.append(output[1]);
      stringBuffer.append(TEXT_5);
      stringBuffer.append(output[2]);
    }

    stringBuffer.append(TEXT_6);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_7);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_8);
    if (!templ.isDevice()) {
      stringBuffer.append(TEXT_9);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_10);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_11);
      stringBuffer.append(TEXT_12);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_13);
    } else {
      stringBuffer.append(TEXT_14);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_15);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_16);
      stringBuffer.append(TEXT_17);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_18);
      stringBuffer.append(TEXT_19);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_20);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_21);
      stringBuffer.append(TEXT_22);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_23);
      stringBuffer.append(TEXT_24);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_25);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_26);
      stringBuffer.append(TEXT_27);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_28);
      stringBuffer.append(TEXT_29);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_30);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_31);
      stringBuffer.append(TEXT_32);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_33);
    }
    stringBuffer.append(TEXT_34);
    stringBuffer.append(TEXT_35);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_36);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_37);
    if (hasSddsPort) {
      stringBuffer.append(TEXT_38);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_39);
      stringBuffer.append(PREFIX);
      stringBuffer.append(TEXT_40);
    }
    stringBuffer.append(TEXT_41);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_42);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_43);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_44);
    stringBuffer.append(TEXT_45);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_46);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_47);
    stringBuffer.append(TEXT_48);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_49);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_50);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_51);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_52);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_53);
    stringBuffer.append(PREFIX);
    stringBuffer.append(TEXT_54);
    stringBuffer.append(TEXT_55);
    return stringBuffer.toString();
  }
コード例 #2
0
  public String generate(Object argument) throws CoreException {
    final StringBuffer stringBuffer = new StringBuffer();

    final TemplateParameter param = (TemplateParameter) argument;
    final EMap<String, ImplementationSettings> settings =
        ((WaveDevSettings) param.getImplSettings().eContainer().eContainer()).getImplSettings();
    final String name = param.getSoftPkg().getName();
    final String version;
    if (param.getSoftPkg().getVersion() != null
        && param.getSoftPkg().getVersion().trim().length() != 0) {
      version = param.getSoftPkg().getVersion();
    } else {
      version = "1.0.0";
    }

    // Interfaces
    final Set<String> interfaceNamespaces = new HashSet<String>();
    final List<Interface> interfaces =
        param.getSoftPkg().getDescriptor().getComponent().getInterfaces().getInterface();
    final Pattern idlPattern = Pattern.compile("^IDL:(\\w+)/");
    for (Interface iface : interfaces) {
      final Matcher match = idlPattern.matcher(iface.getRepid());
      if (match.find()) {
        if (!"CF".equals(match.group(1))) {
          interfaceNamespaces.add(match.group(1));
        }
      }
    }

    // Language
    boolean hasCpp = false, hasJava = false, hasPython = false;
    for (final Implementation impl : param.getSoftPkg().getImplementation()) {
      final String language = impl.getProgrammingLanguage().getName();
      if ("C++".equals(language)) {
        hasCpp = true;
      } else if ("Java".equals(language)) {
        hasJava = true;
      } else if ("Python".equals(language)) {
        hasPython = true;
      }
    }

    // Strings that depend on project type
    final String sdrrootFolder;
    final String projectType;
    final SoftwareComponent scd = param.getSoftPkg().getDescriptor().getComponent();
    final ComponentType componentType = SoftwareComponent.Util.getWellKnownComponentType(scd);
    switch (componentType) {
      case RESOURCE:
        sdrrootFolder = "dom/components";
        projectType = "Component";
        break;
      case DEVICE:
        sdrrootFolder = "dev/devices";
        projectType = "Device";
        break;
      case SERVICE:
        sdrrootFolder = "dev/services";
        projectType = "Service";
        break;
      default:
        // For backwards compatibility, support non-spec strings the IDE used to generate
        try {
          if (scd != null && scd.getComponentType() != null) {
            final String compTypeStr = scd.getComponentType();
            if (compTypeStr.equals("executabledevice") || compTypeStr.equals("loadabledevice")) {
              sdrrootFolder = "dev/devices";
              projectType = "Device";
              break;
            }
          }
        } catch (NullPointerException e) {
          // PASS
        }
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                Activator.PLUGIN_ID,
                "Template file does not support the specified project type"));
    }

    stringBuffer.append(TEXT_1);
    stringBuffer.append(name);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(projectType);
    stringBuffer.append(TEXT_3);

    if (param.getSoftPkg().getTitle() != null
        && param.getSoftPkg().getTitle().trim().length() > 0) {

      stringBuffer.append(TEXT_4);
      stringBuffer.append(param.getSoftPkg().getTitle());
      stringBuffer.append(TEXT_5);
    }
    stringBuffer.append(TEXT_6);
    stringBuffer.append(version);
    stringBuffer.append(TEXT_7);
    stringBuffer.append(projectType);
    stringBuffer.append(TEXT_8);

    if (interfaceNamespaces.size() > 0) {
      boolean foundOther = false;
      // these interfaces are available through the redhawk install
      //  so no additional rpms are needed
      for (String ifaceNamespace : interfaceNamespaces) {
        if ((!ifaceNamespace.equals("CF"))
            && (!ifaceNamespace.equals("PortTypes"))
            && (!ifaceNamespace.equals("ExtendedEvent"))
            && (!ifaceNamespace.equals("ExtendedCF"))
            && (!ifaceNamespace.equals("StandardEvent"))
            && (!ifaceNamespace.equals("WKP"))) {
          foundOther = true;
          break;
        }
      }
      if (foundOther) {

        stringBuffer.append(TEXT_9);

        for (String ifaceNamespace : interfaceNamespaces) {
          if ((!ifaceNamespace.equals("CF"))
              && (!ifaceNamespace.equals("PortTypes"))
              && (!ifaceNamespace.equals("ExtendedEvent"))
              && (!ifaceNamespace.equals("ExtendedCF"))
              && (!ifaceNamespace.equals("StandardEvent"))
              && (!ifaceNamespace.equals("WKP"))) {

            stringBuffer.append(TEXT_10);
            stringBuffer.append(ifaceNamespace.toLowerCase());
            stringBuffer.append(TEXT_11);
          }
        }

        stringBuffer.append(TEXT_12);

        for (String ifaceNamespace : interfaceNamespaces) {
          if ((!ifaceNamespace.equals("CF"))
              && (!ifaceNamespace.equals("PortTypes"))
              && (!ifaceNamespace.equals("ExtendedEvent"))
              && (!ifaceNamespace.equals("ExtendedCF"))
              && (!ifaceNamespace.equals("StandardEvent"))
              && (!ifaceNamespace.equals("WKP"))) {

            stringBuffer.append(TEXT_13);
            stringBuffer.append(ifaceNamespace.toLowerCase());
            stringBuffer.append(TEXT_14);
          }
        }

        stringBuffer.append(TEXT_15);
      }
    }
    if (!hasCpp && (hasJava | hasPython)) {

      stringBuffer.append(TEXT_16);
    }
    if (hasCpp) {

      stringBuffer.append(TEXT_17);
    }
    if (hasJava) {

      stringBuffer.append(TEXT_18);
    }
    if (hasPython) {

      stringBuffer.append(TEXT_19);
    }

    stringBuffer.append(TEXT_20);

    if (param.getSoftPkg().getDescription() != null) {

      stringBuffer.append(TEXT_21);
      stringBuffer.append(param.getSoftPkg().getDescription());

    } else {

      stringBuffer.append(TEXT_22);
      stringBuffer.append(projectType);
      stringBuffer.append(TEXT_23);
    }

    stringBuffer.append(TEXT_24);

    for (final Implementation impl : param.getSoftPkg().getImplementation()) {
      final ImplementationSettings implSettings = settings.get(impl.getId());
      if (implSettings == null) {
        continue;
      }

      stringBuffer.append(TEXT_25);
      stringBuffer.append(impl.getId());
      stringBuffer.append(TEXT_26);
      stringBuffer.append(implSettings.getOutputDir());
      stringBuffer.append(TEXT_27);
      stringBuffer.append(sdrrootFolder);
      stringBuffer.append(TEXT_28);
      stringBuffer.append(name);
      stringBuffer.append(TEXT_29);
      stringBuffer.append(implSettings.getOutputDir());
      stringBuffer.append(TEXT_30);
    }

    stringBuffer.append(TEXT_31);

    for (final Implementation impl : param.getSoftPkg().getImplementation()) {
      final ImplementationSettings implSettings = settings.get(impl.getId());
      if (implSettings == null) {
        continue;
      }

      stringBuffer.append(TEXT_32);
      stringBuffer.append(impl.getId());
      stringBuffer.append(TEXT_33);
      stringBuffer.append(implSettings.getOutputDir());
      stringBuffer.append(TEXT_34);
      stringBuffer.append(sdrrootFolder);
      stringBuffer.append(TEXT_35);
      stringBuffer.append(name);
      stringBuffer.append(TEXT_36);
      stringBuffer.append(implSettings.getOutputDir());
      stringBuffer.append(TEXT_37);
    }

    stringBuffer.append(TEXT_38);
    stringBuffer.append(sdrrootFolder);
    stringBuffer.append(TEXT_39);
    stringBuffer.append(sdrrootFolder);
    stringBuffer.append(TEXT_40);
    stringBuffer.append(ModelUtil.getSpdFileName(param.getSoftPkg()));

    if (param.getSoftPkg().getPropertyFile() != null) {

      stringBuffer.append(TEXT_41);
      stringBuffer.append(sdrrootFolder);
      stringBuffer.append(TEXT_42);
      stringBuffer.append(ModelUtil.getPrfFileName(param.getSoftPkg().getPropertyFile()));
    }

    stringBuffer.append(TEXT_43);
    stringBuffer.append(sdrrootFolder);
    stringBuffer.append(TEXT_44);
    stringBuffer.append(ModelUtil.getScdFileName(param.getSoftPkg()));

    for (final Implementation impl : param.getSoftPkg().getImplementation()) {
      final ImplementationSettings implSettings = settings.get(impl.getId());
      if (implSettings == null) {
        continue;
      }

      stringBuffer.append(TEXT_45);
      stringBuffer.append(sdrrootFolder);
      stringBuffer.append(TEXT_46);
      stringBuffer.append(implSettings.getOutputDir());
    }

    return stringBuffer.toString();
  }