Exemplo n.º 1
0
  public void performAction(Node[] activatedNodes) {
    Node n = activatedNodes[0];
    Folder folder = (Folder) n.getValue("Folder"); // NOI18N
    assert folder != null;
    Node thisNode = (Node) n.getValue("This"); // NOI18N
    assert thisNode != null;
    Project project = (Project) n.getValue("Project"); // NOI18N
    assert project != null;

    ConfigurationDescriptorProvider pdp =
        project.getLookup().lookup(ConfigurationDescriptorProvider.class);
    MakeConfigurationDescriptor makeConfigurationDescriptor = pdp.getConfigurationDescriptor();
    if (!makeConfigurationDescriptor.okToChange()) {
      return;
    }

    NotifyDescriptor.InputLine dlg =
        new NotifyDescriptor.InputLine(getString("FolderNameTxt"), getString("NewFolderName"));
    dlg.setInputText(folder.suggestedNewFolderName());
    String newname = null;

    if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dlg))) {
      newname = dlg.getInputText();
    } else {
      return;
    }

    Folder newFolder = folder.addNewFolder(true);
    newFolder.setDisplayName(newname);
    MakeLogicalViewProvider.setVisible(project, newFolder);
  }
 private void setOptions(Project project, Folder testFolder) {
   ConfigurationDescriptorProvider cdp =
       project.getLookup().lookup(ConfigurationDescriptorProvider.class);
   MakeConfigurationDescriptor projectDescriptor = cdp.getConfigurationDescriptor();
   FolderConfiguration folderConfiguration =
       testFolder.getFolderConfiguration(projectDescriptor.getActiveConfiguration());
   LinkerConfiguration linkerConfiguration = folderConfiguration.getLinkerConfiguration();
   linkerConfiguration.getOutput().setValue("${TESTDIR}/" + testFolder.getPath()); // NOI18N
   CCompilerConfiguration cCompilerConfiguration = folderConfiguration.getCCompilerConfiguration();
   CCCompilerConfiguration ccCompilerConfiguration =
       folderConfiguration.getCCCompilerConfiguration();
   cCompilerConfiguration.getIncludeDirectories().add("."); // NOI18N
   ccCompilerConfiguration.getIncludeDirectories().add("."); // NOI18N
 }
  @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;
  }