Пример #1
0
 private void assertHeader(FileObject fo, String header, String expectedMimeType)
     throws IOException {
   OutputStream os = fo.getOutputStream();
   os.write(header.getBytes());
   os.close();
   assertEquals("Header " + header + " wrongly resolved.", expectedMimeType, fo.getMIMEType());
 }
Пример #2
0
 public void testRubyResolver() throws IOException {
   FileObject fo = FileUtil.createMemoryFileSystem().getRoot().createData("ruby");
   String[] validHeaders = {
     "#!/usr/bin/ruby",
     "#!/usr/bin/ruby1.8",
     "#!/usr/bin/jruby",
     "#! /usr/bin/ruby",
     "#! /usr/bin/ruby\n",
     "#! /usr/bin/ruby.exe",
     "#! /usr/bin/ruby.exe ",
     "#!C:\\programs\\ruby.exe",
     "#!C:\\programs\\ruby.exe",
     "#!/Users/tor/dev/ruby/install/ruby-1.8.5/bin/ruby\n",
     "#!/space/ruby/ruby-1.8.6-p110/bin/ruby1.8.6-p110",
     "#!/usr/bin/env jruby -J-Xmx512M",
     "#!/usr/bin/env ruby",
     "#!/usr/bin/env jruby",
     "#!/usr/bin/env.exe jruby",
     "#!D:/Development/Ruby/ruby-1.8.6-dist/bin/ruby"
   };
   String[] invalidHeaders = {
     "# !C:\\programs\\ruby.exe",
     "#!/bin/sh",
     // "#!/bin/rubystuff/bin/ksh", // mistakenly resolved as ruby file
     "#!/usr/bin/rub",
     "#!/usr/bin/",
     "#! /usr/bin/rub\ny",
     // "#! /usr/b\nin/ruby", // mistakenly resolved as ruby file
     "#/usr/bin/ruby",
     "#!/usr/bin/env.exe jrub"
   };
   for (String header : validHeaders) {
     assertHeader(fo, header, "text/x-ruby");
   }
   for (String header : invalidHeaders) {
     assertHeader(fo, header, "content/unknown");
   }
   fo = FileUtil.createMemoryFileSystem().getRoot().createData("rakefile");
   assertEquals("rakefile should be resolved.", "text/x-ruby", fo.getMIMEType());
   fo = FileUtil.createMemoryFileSystem().getRoot().createData("Rakefile");
   assertEquals("rakefile should be resolved.", "text/x-ruby", fo.getMIMEType());
   fo = FileUtil.createMemoryFileSystem().getRoot().createData("a.rb");
   assertEquals("All .rb should be resolved.", "text/x-ruby", fo.getMIMEType());
 }
  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;
  }