Ejemplo n.º 1
0
  protected WizardDescriptor.Panel<WizardDescriptor>[] createPanels() {
    if (targetChooserDescriptorPanel == null) {
      TemplateWizard wiz = getWizard();
      DataObject dobj = wiz.getTemplate();
      FileObject fobj = dobj.getPrimaryFile();
      String mimeType = fobj.getMIMEType();
      MIMEExtensions extensions = MIMEExtensions.get(mimeType);
      if (extensions != null) {
        Project project = Templates.getProject(getWizard());
        Sources sources = ProjectUtils.getSources(project);
        SourceGroup[] groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
        if (MIMENames.HEADER_MIME_TYPE.equals(extensions.getMIMEType())) {
          // this is the only place where we want to differ c headers from cpp headers (creation of
          // new one)
          if (dobj.getPrimaryFile().getAttribute(C_HEADER_MIME_TYPE) != null) {
            MIMEExtensions cHeaderExtensions = MIMEExtensions.get(C_HEADER_MIME_TYPE);
            if ((cHeaderExtensions == null)
                || !C_HEADER_MIME_TYPE.equals(cHeaderExtensions.getMIMEType())) {
              System.err.println("not found extensions for C Headers"); // NOI18N
            } else {
              extensions = cHeaderExtensions;
            }
          }
        }
        String defaultExt = null; // let the chooser panel decide default extension
        if (mimeType.equals(MIMENames.SHELL_MIME_TYPE)) {
          // for shell scripts set default extension explicitly
          defaultExt = fobj.getExt();
        } else if (mimeType.equals(MIMENames.HEADER_MIME_TYPE) && fobj.getExt().length() == 0) {
          // for standard header without extension
          defaultExt = fobj.getExt();
        }

        targetChooserDescriptorPanel =
            new NewTestSimplePanel(
                project,
                groups,
                null,
                extensions,
                defaultExt,
                (String) wiz.getProperty(CND_UNITTEST_DEFAULT_NAME));
      } else {
        targetChooserDescriptorPanel = getWizard().targetChooser();
      }
    }
    @SuppressWarnings("unchecked")
    Panel<WizardDescriptor>[] panels = new WizardDescriptor.Panel[] {targetChooserDescriptorPanel};
    return panels;
  }
Ejemplo n.º 2
0
  @Override
  public Set<DataObject> instantiate(TemplateWizard wiz) throws IOException {
    UIGesturesSupport.submit(
        "USG_CND_UNIT_TESTS_SIMPLE_"
            + wiz.getTemplate().getPrimaryFile().getExt().toUpperCase()); // NOI18N

    Project project = Templates.getProject(wiz);

    Set<DataObject> dataObjects = new HashSet<DataObject>();

    if (getTestFileName() == null || getTestName() == null) {
      return dataObjects;
    }

    DataFolder targetFolder = wiz.getTargetFolder();

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CreateFromTemplateHandler.FREE_FILE_EXTENSION, true);

    List<CsmFunction> fs = new ArrayList<CsmFunction>();
    Object listObj = wiz.getProperty(CND_UNITTEST_FUNCTIONS);
    if (listObj instanceof List<?>) {
      List<?> list = (List<?>) listObj;
      for (Object obj : list) {
        if (obj instanceof CsmFunction) {
          fs.add((CsmFunction) obj);
        }
      }
    }
    FileObject rootFolder = getRootFolder();
    FSPath rootFolderFilePath = FSPath.toFSPath(rootFolder);
    params.putAll(
        CodeGenerator.generateTemplateParamsForFunctions(
            getTestFileName().replaceFirst("[.].*", ""), // NOI18N
            rootFolderFilePath,
            fs,
            ("cpp".equals(wiz.getTemplate().getPrimaryFile().getExt())
                ? CodeGenerator.Language.CPP
                : CodeGenerator.Language.C))); // NOI18N

    DataObject formDataObject =
        NewTestSimplePanel.getTemplateDataObject(
            "simpletestfile." + wiz.getTemplate().getPrimaryFile().getExt()); // NOI18N

    DataObject dataObject =
        formDataObject.createFromTemplate(targetFolder, getTestFileName(), params);

    Folder folder = null;
    Folder testsRoot = getTestsRootFolder(project);
    if (testsRoot == null) {
      testsRoot = createTestsRootFolder(project);
      MakefileUtils.createTestTargets(project);
    }
    if (testsRoot != null) {
      Folder newFolder = testsRoot.addNewFolder(true, Folder.Kind.TEST);
      newFolder.setDisplayName(getTestName());
      folder = newFolder;
    }

    if (folder == null) {
      return dataObjects;
    }

    setOptions(project, folder);

    addItemToLogicalFolder(project, folder, dataObject);

    dataObjects.add(dataObject);
    return dataObjects;
  }