/**
  * Create a scratch directory for tests. Will be in /tmp or whatever, and will be empty. If you
  * just need a java.io.File use clearWorkDir + getWorkDir.
  */
 public static FileObject makeScratchDir(NbTestCase test) throws IOException {
   boolean warned = false;
   test.clearWorkDir();
   File root = test.getWorkDir();
   assert root.isDirectory() && root.list().length == 0;
   FileObject fo = FileUtil.toFileObject(root);
   if (fo != null) {
     return fo;
   } else {
     if (!warned) {
       warned = true;
       System.err.println(
           "No FileObject for "
               + root
               + " found.\n"
               + "Maybe you need ${openide/masterfs.dir}/modules/org-netbeans-modules-masterfs.jar\n"
               + "in test.unit.run.cp.extra, or make sure Lookups.metaInfServices is included in Lookup.default, so that\n"
               + "Lookup.default<URLMapper>="
               + Lookup.getDefault().lookup(new Lookup.Template(URLMapper.class)).allInstances()
               + " includes MasterURLMapper\n"
               + "e.g. by using TestUtil.setLookup(Object[]) rather than TestUtil.setLookup(Lookup).");
     }
     // For the benefit of those not using masterfs.
     LocalFileSystem lfs = new LocalFileSystem();
     try {
       lfs.setRootDirectory(root);
     } catch (PropertyVetoException e) {
       assert false : e;
     }
     Repository.getDefault().addFileSystem(lfs);
     return lfs.getRoot();
   }
 }
示例#2
0
  @Override
  protected void setUp() throws Exception {
    clearWorkDir();

    FileWriter w = new FileWriter(new File(getWorkDir(), "template.txt"));
    w.write("<html><h1>${title}</h1></html>");
    w.close();

    parameters = new HashMap<String, String>();
    parameters.put("title", "SOME_TITLE");

    LocalFileSystem lfs = new LocalFileSystem();
    lfs.setRootDirectory(getWorkDir());
    fo = lfs.findResource("template.txt");

    ScriptEngineManager mgr = new ScriptEngineManager();
    eng = mgr.getEngineByName("freemarker");
    assertNotNull("We do have such engine", eng);
    eng.getContext().setAttribute(FileObject.class.getName(), fo, ScriptContext.ENGINE_SCOPE);
    eng.getContext().getBindings(ScriptContext.ENGINE_SCOPE).putAll(parameters);

    whereTo = new File[10000];
    for (int i = 0; i < whereTo.length; i++) {
      whereTo[i] = new File(getWorkDir(), "outFile" + i + ".txt");
    }
  }
 /**
  * Copied from org.netbeans.api.project. Create a scratch directory for tests. Will be in /tmp or
  * whatever, and will be empty. If you just need a java.io.File use clearWorkDir + getWorkDir.
  */
 public static FileObject makeScratchDir(NbTestCase test) throws IOException {
   test.clearWorkDir();
   File root = test.getWorkDir();
   assert root.isDirectory() && root.list().length == 0;
   FileObject fo = FileUtil.toFileObject(root);
   if (fo != null) {
     // Presumably using masterfs.
     return fo;
   } else {
     // For the benefit of those not using masterfs.
     LocalFileSystem lfs = new LocalFileSystem();
     try {
       lfs.setRootDirectory(root);
     } catch (PropertyVetoException e) {
       assert false : e;
     }
     Repository.getDefault().addFileSystem(lfs);
     return lfs.getRoot();
   }
 }