/** * 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(); } }
/** * 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(); } }