Java Code Examples for org.openide.filesystems.FileUtil#createFolder()

The following examples show how to use org.openide.filesystems.FileUtil#createFolder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: J2SESharabilityQueryTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    MockLookup.setLayersAndInstances(
        new org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation()
    );
    scratch = TestUtil.makeScratchDir(this);
    projdir = scratch.createFolder("proj");
    J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.6"));   //NOI18N
    helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj",null,null,null, false); //NOI18N
    J2SEProjectGenerator.setDefaultSourceLevel(null);
    sources = projdir.getFileObject("src");
    tests = projdir.getFileObject("test");
    dist = FileUtil.createFolder(projdir,"dist");
    build = FileUtil.createFolder(projdir,"build");
    pm = ProjectManager.getDefault();
    Project p = pm.findProject(projdir);
    assertTrue("Invalid project type",p instanceof J2SEProject);
    pp = (J2SEProject) p;
}
 
Example 2
Source File: ExecutionSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Callable<Process> createCreateApp(final File directory) {
    return new Callable<Process>() {

        public Process call() throws Exception {
            if (directory.exists()) {
                throw new IOException("Project directory already exists"); // NOI18N
            }

            File work = directory.getAbsoluteFile().getParentFile();
            FileUtil.createFolder(work);
            String name = directory.getName();

            String[] args;
            if (GrailsPlatform.Version.VERSION_1_1.compareTo(platform.getVersion()) <= 0) {
                args = new String[] {name, "--non-interactive"}; // NOI18N
            } else {
                args = new String[] {name};
            }

            GrailsPlatform.CommandDescriptor descriptor = GrailsPlatform.CommandDescriptor.forProject(
                    "create-app", work, null, args, null); // NOI18N

            return platform.createCommand(descriptor).call();
        }
    };
}
 
Example 3
Source File: jvmcapsWizardIterator.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private static void unZipFile(InputStream source, FileObject projectRoot) throws IOException {
    try {
        ZipInputStream str = new ZipInputStream(source);
        ZipEntry entry;
        while ((entry = str.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                FileUtil.createFolder(projectRoot, entry.getName());
            } else {
                FileObject fo = FileUtil.createData(projectRoot, entry.getName());
                if ("nbproject/project.xml".equals(entry.getName())) {
                    // Special handling for setting name of Ant-based projects; customize as needed:
                    filterProjectXML(fo, str, projectRoot.getName());
                } else {
                    writeFile(str, fo);
                }
            }
        }
    } finally {
        source.close();
    }
}
 
Example 4
Source File: EarProjectGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static AntProjectHelper importProject(File pDir, final File sDir, String name,
        Profile j2eeProfile, String serverInstanceID, final String platformName,
        String sourceLevel, final Map<FileObject, ModuleType> userModules,
        String librariesDefinition)
        throws IOException {
    FileObject projectDir = FileUtil.createFolder(pDir);
    final EarProjectGenerator earGen = new EarProjectGenerator(pDir, projectDir, name,
            j2eeProfile, serverInstanceID, sourceLevel, librariesDefinition);
    final AntProjectHelper[] h = new AntProjectHelper[1];
    
    // create project in one FS atomic action:
    FileSystem fs = projectDir.getFileSystem();
    fs.runAtomicAction(new FileSystem.AtomicAction() {
        public void run() throws IOException {
            AntProjectHelper helper = earGen.doImportProject(sDir, userModules, platformName);
            h[0] = helper;
        }});
    return h[0];
}
 
Example 5
Source File: WLPluginPropertiesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testDomainList() throws IOException {
    File dir = getDataDir();
    File registry = new File(dir, "domain-registry.xml");
    File nodeManager = new File(dir, "nodemanager.domains");

    File work = getWorkDir();
    File wlServer = new File(work, "wlserver");
    wlServer.mkdir();

    File out = new File(work, registry.getName());

    copyFile(registry, out);

    String[] ret = WLPluginProperties.getRegisteredDomainPaths(wlServer.getAbsolutePath());
    assertEquals(1, ret.length);
    assertEquals("/home/test/software/wls12120/user_projects/domains/mydomain", ret[0]);

    assertTrue(out.delete());

    FileObject folder = FileUtil.createFolder(FileUtil.toFileObject(wlServer), "common/nodemanager");
    copyFile(nodeManager, new File(FileUtil.toFile(folder), nodeManager.getName()));

    ret = WLPluginProperties.getRegisteredDomainPaths(wlServer.getAbsolutePath());
    assertEquals(1, ret.length);
    assertEquals("/home/test/software/wls1036_dev/user_projects/domains/base_domain", ret[0]);
}
 
Example 6
Source File: J2SESampleProjectGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void unzip(InputStream source, FileObject targetFolder) throws IOException {
    //installation
    ZipInputStream zip=new ZipInputStream(source);
    try {
        ZipEntry ent;
        while ((ent = zip.getNextEntry()) != null) {
            if (ent.isDirectory()) {
                FileUtil.createFolder(targetFolder, ent.getName());
            } else {
                FileObject destFile = FileUtil.createData(targetFolder,ent.getName());
                FileLock lock = destFile.lock();
                try {
                    OutputStream out = destFile.getOutputStream(lock);
                    try {
                        FileUtil.copy(zip, out);
                    } finally {
                        out.close();
                    }
                } finally {
                    lock.releaseLock();
                }
            }
        }
    } finally {
        zip.close();
    }
}
 
Example 7
Source File: SourceAnalyzerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    MockServices.setServices(CPP.class, SLQ.class);
    final FileObject wd = FileUtil.toFileObject(getWorkDir());
    assertNotNull(wd);
    src = FileUtil.createFolder(wd,"src");  //NOI18N
    assertNotNull(src);
    Lookup.getDefault().lookup(CPP.class).root = src;
    Lookup.getDefault().lookup(SLQ.class).root = src;

}
 
Example 8
Source File: FreeformSourcesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNonExistentRoot() throws Exception {
    clearWorkDir();
    final File d = getWorkDir();
    final File proj = new File (d,"proj");
    final File extSrcDir = new File (d,"ext");
    proj.mkdir();
    AntProjectHelper helper = FreeformProjectGenerator.createProject(proj, proj, "prj", null);
    Project p = ProjectManager.getDefault().findProject(helper.getProjectDirectory());

    Element data = Util.getPrimaryConfigurationData(helper);
    Document doc = data.getOwnerDocument();
    Element sf = (Element) data.insertBefore(doc.createElementNS(Util.NAMESPACE, "folders"), XMLUtil.findElement(data, "view", Util.NAMESPACE)).
            appendChild(doc.createElementNS(Util.NAMESPACE, "source-folder"));
    sf.appendChild(doc.createElementNS(Util.NAMESPACE, "label")).appendChild(doc.createTextNode("Sources"));
    sf.appendChild(doc.createElementNS(Util.NAMESPACE, "location")).appendChild(doc.createTextNode("../ext"));
    Util.putPrimaryConfigurationData(helper, data);
    ProjectManager.getDefault().saveProject(p);

    final Sources src = ProjectUtils.getSources(p);
    SourceGroup[] sgs = src.getSourceGroups(Sources.TYPE_GENERIC);
    assertEquals(1,sgs.length);
    assertEquals(p.getProjectDirectory(), sgs[0].getRootFolder());
    final FileObject extFo = FileUtil.createFolder(extSrcDir);
    sgs = src.getSourceGroups(Sources.TYPE_GENERIC);
    assertSourceGroupsEquals(new FileObject[] {p.getProjectDirectory(), extFo}, sgs);
    assertEquals(p, FileOwnerQuery.getOwner(extFo));
}
 
Example 9
Source File: ClassIndexTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testFindSymbols() throws Exception {
    final FileObject wd = FileUtil.toFileObject(getWorkDir());
    final FileObject root = FileUtil.createFolder(wd,"src");    //NOI18N
    sourcePath = ClassPathSupport.createClassPath(root);
    compilePath = ClassPathSupport.createClassPath(new URL[0]);
    bootPath = JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();
    final FileObject t1 = createJavaFile(
            root,
            "test",                                          //NOI18N
            "Test",                                          //NOI18N
            "package test;\n"+                               //NOI18N
            "public class Test { private void foo() { } }"); //NOI18N
    final FileObject t2 = createJavaFile(
            root,
            "test",                                          //NOI18N
            "foo",                                           //NOI18N
            "package test;\n"+                               //NOI18N
            "public class foo {\n"+                          //NOI18N
            "}");                                            //NOI18N
    IndexingManager.getDefault().refreshIndexAndWait(root.toURL(), null);
    final ClassIndex ci = ClasspathInfo.create(bootPath, compilePath, sourcePath).getClassIndex();
    assertNotNull(ci);
    Iterable<Symbols> result = ci.getDeclaredSymbols("foo", NameKind.SIMPLE_NAME,
        EnumSet.<ClassIndex.SearchScope>of(ClassIndex.SearchScope.SOURCE));
    Set<String> actualResult = new HashSet<String>();
    for (Symbols s : result) {
        actualResult.add(s.getEnclosingType().getQualifiedName() + ":" + s.getSymbols().toString());
    }
    assertEquals(new HashSet<String>(Arrays.asList("test.foo:[foo]", "test.Test:[foo]")), actualResult);
}
 
Example 10
Source File: ToolbarPoolDeadlockTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testWhoCreatesConstructor() throws Exception {
    FileObject root = FileUtil.getConfigRoot();
    FileObject fo = FileUtil.createFolder (root, "ToolbarsWhoCreates");
    final DataFolder df = DataFolder.findFolder(fo);
    ToolbarPool pool = new ToolbarPool(df);

    assertEquals("No children now", 0, pool.getToolbars().length);

    class Atom implements FileSystem.AtomicAction {

        FileObject m1, m2;

        public void run() throws IOException {
            m1 = FileUtil.createFolder(df.getPrimaryFile(), "m1");
            DataFolder f1 = DataFolder.findFolder(m1);
            InstanceDataObject.create(f1, "X", MyAction.class);
        }
    }
    Atom atom = new Atom();
    df.getPrimaryFile().getFileSystem().runAtomicAction(atom);
    pool.waitFinished();

    assertEquals("One toolbar is there", 1, pool.getToolbars().length);
    Toolbar tb = pool.getToolbars()[0];
    assertEquals("Pool name", "m1", tb.getName());
    assertEquals("Has one subcomponent", 1, tb.getComponents().length);
    Object o1 = tb.getComponent(0);
    if (!(o1 instanceof JButton)) {
        fail("Need JPanel " + o1);
    }
    assertEquals("And now the action is created", 1, MyAction.counter);
}
 
Example 11
Source File: AssetPackLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void addAllFiles(ProjectAssetManager source, ProjectAssetManager dest, AssetConfiguration config) {
    Element assetElement = config.getAssetElement();
    NodeList list = assetElement.getElementsByTagName("file");
    try {
        if (dest == null) {
            Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!");
            return;
        }
    } catch (Exception e) {
        Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not get project asset manager!");
        return;
    }
    for (int i = 0; i < list.getLength(); i++) {
        Element fileElem = (Element) list.item(i);
        try {
            String src = source.getAbsoluteAssetPath(fileElem.getAttribute("path"));
            if (src == null) {
                Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not find texture with manager!");
                return;
            }
            FileObject srcFile = FileUtil.toFileObject(new File(src));
            String destName = dest.getAssetFolderName() + "/" + fileElem.getAttribute("path");
            String destFolder = destName.replace("\\", "/");
            destFolder = destFolder.substring(0, destFolder.lastIndexOf("/"));
            FileObject folder = FileUtil.createFolder(new File(destFolder));
            srcFile.copy(folder, srcFile.getName(), srcFile.getExt());
        } catch (IOException ex) {
            Logger.getLogger(AssetPackLoader.class.getName()).log(Level.SEVERE, "Could not copy texture: {0}", ex.getMessage());
        }
    }
    return;
}
 
Example 12
Source File: JavaEEMavenTestBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected Project createMavenEarProject(FileObject projectDir) {
    try {
        FileObject src = FileUtil.createFolder(projectDir, "src"); //NOI18N
        FileObject main = FileUtil.createFolder(src, "main"); //NOI18N
        FileObject application = FileUtil.createFolder(main, "application"); //NOI18N
        
        PomBuilder pomBuilder = new PomBuilder();
        pomBuilder.appendPomContent(NbMavenProject.TYPE_EAR);

        return createProject(projectDir, pomBuilder.buildPom());
    } catch (IOException ex) {
        return null;
    }
}
 
Example 13
Source File: FileObjectCrawlerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDeletedFiles() throws IOException {
    FileObject root = FileUtil.createFolder(new File(getWorkDir(), "src"));
    String [] paths = new String [] {
            "org/pckg1/file1.txt",
            "org/pckg1/pckg2/file1.txt",
            "org/pckg1/pckg2/file2.txt",
            "org/pckg2/"
    };
    populateFolderStructure(root, paths);

    FileObjectCrawler crawler1 = new FileObjectCrawler(root, EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, CR, SuspendSupport.NOP);
    assertCollectedFiles("Wrong files collected", crawler1.getResources(), paths);
    assertCollectedFiles("Wrong files collected", crawler1.getAllResources(), paths);

    FileObject pckg2 = root.getFileObject("org/pckg1/pckg2");
    FileObject org = root.getFileObject("org");
    org.delete();

    FileObjectCrawler crawler2 = new FileObjectCrawler(root, new FileObject [] { pckg2 }, EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, CR, SuspendSupport.NOP);
    assertCollectedFiles("There should be no files in " + root, crawler2.getResources());
    assertNull("All resources should not be computed for subtree", crawler2.getAllResources());

    FileObjectCrawler crawler3 = new FileObjectCrawler(root, EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, CR, SuspendSupport.NOP);
    assertCollectedFiles("There should be no files in " + root, crawler3.getResources());
    assertCollectedFiles("There should be no files in " + root, crawler3.getAllResources());
    assertCollectedFiles("All files in " + root + " should be deleted", crawler3.getDeletedResources());
}
 
Example 14
Source File: WLDeploymentFactoryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDeploymentManagerCleared() throws Exception {
    File dir = getWorkDir();
    FileObject server = FileUtil.createFolder(new File(dir, "server"));
    FileObject domain = FileUtil.createFolder(new File(dir, "domain"));
    FileObject config = domain.createFolder("config");
    config.createData("config", "xml");

    String serverPath = FileUtil.toFile(server).getAbsolutePath();
    String domainPath = FileUtil.toFile(domain).getAbsolutePath();
    String url = WLDeploymentFactory.getUrl("localhost", 7001, serverPath, domainPath);
    Map<String, String> props = new HashMap<String, String>();
    props.put(WLPluginProperties.SERVER_ROOT_ATTR, serverPath);
    props.put(WLPluginProperties.DOMAIN_ROOT_ATTR, domainPath);

    InstanceProperties ip = InstanceProperties.createInstancePropertiesNonPersistent(
            url, "test", "test", "test", props);
    WLDeploymentManager manager = (WLDeploymentManager) WLDeploymentFactory.getInstance().getDisconnectedDeploymentManager(url);
    assertEquals(ip, manager.getInstanceProperties());

    InstanceProperties.removeInstance(url);
    WeakReference<InstanceProperties> ipRef = new WeakReference<InstanceProperties>(ip);
    ip = null;
    WeakReference<WLDeploymentManager> ref = new WeakReference<WLDeploymentManager>(manager);
    manager = null;

    assertGC("InstanceProperties leaking", ipRef);

    // lets indirectly touch the cache
    url = url + "_other";
    InstanceProperties.createInstancePropertiesNonPersistent(url, "test", "test", "test",
                    props);
    WLDeploymentManager managerOther = (WLDeploymentManager) WLDeploymentFactory.getInstance().getDisconnectedDeploymentManager(url);

    assertGC("WLDeploymentManager leaking", ref);
}
 
Example 15
Source File: LayoutIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void run(FileSystem layer) throws IOException {
    FileObject folder = layer.getRoot().getFileObject("Actions/Window");// NOI18N
    if (folder == null) {
        folder = FileUtil.createFolder(layer.getRoot(), "Actions/Window"); // NOI18N
    }
    String instance = packageName.replace('.','-') + "-" + name; // NOI18N
    FileObject file = folder.createData(instance, "instance"); // NOI18N
    folder = layer.getRoot().getFileObject("Menu/Window");// NOI18N
    if (folder == null) {
        folder = FileUtil.createFolder(layer.getRoot(), "Menu/Window"); // NOI18N
    }
    file = folder.createData(name, "shadow"); // NOI18N
    file.setAttribute("originalFile", "Actions/Window/" + instance + ".instance"); // NOI18N
}
 
Example 16
Source File: SaasClientCodeGenerationProviderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    targetFolder = FileUtil.createFolder(new File("/tmp/testuserdir"));
    nonhyperlinkedOut.clear();
    nonhyperlinkedErr.clear();
    hyperlinkedOut.clear();
    hyperlinkedErr.clear();
    try {
        SetupUtil.commonSetUp(super.getWorkDir());
        InputStream is = this.getClass().getResourceAsStream("JavaApplication.zip");
        TestUtils.unZipFile(is, targetFolder);
    } catch (Exception ex) {
        assertFalse("Failed with exception: "+ex.getMessage(), ex != null);
    }
    targetFO = targetFolder.getFileObject("JavaApplication/src/javaapplication/Main.java");
    assertTrue("Target File is null", targetFO != null);

    SaasServicesModel instance = SaasServicesModel.getInstance();
    SaasGroup group = instance.getRootGroup().getChildGroup("Delicious");
    WadlSaas saas = (WadlSaas) group.getServices().get(0);
    assertEquals("Bookmarking Service", saas.getDisplayName());
    method = saas.getResources().get(0).getChildResources().get(0).getMethods().get(0);
    Method m = ((WadlSaasMethod)method).getWadlMethod();
    if (m == null) {
        Exceptions.printStackTrace(new IOException("Wadl method not found"));
    }
}
 
Example 17
Source File: J2eePlatform.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void copyFiles(Map<FileObject, String> copied, Map<String, Integer> usedNames,
        FileObject jarFolder, String folderName, FileObject[] files, List<URI> content) throws IOException {

    if (files == null) {
        return;
    }

    for (FileObject jarObject : files) {
        if (!copied.containsKey(jarObject)) {
            String name = jarObject.getName() + getEntrySuffix(jarObject.getNameExt(), usedNames);
            if (jarObject.isFolder()) {
                FileObject folder = FileUtil.createFolder(jarFolder, name);
                copyFolder(jarObject, folder);
            } else {
                FileUtil.copyFile(jarObject, jarFolder, name, jarObject.getExt());
            }
            copied.put(jarObject, jarObject.getNameExt().replace(jarObject.getName(), name));
        }

        FileObject fresh = jarFolder.getFileObject(copied.get(jarObject));
        URI u = LibrariesSupport.convertFilePathToURI(folderName
                + File.separator + copied.get(jarObject));

        if (FileUtil.isArchiveFile(fresh)) {
            u = LibrariesSupport.getArchiveRoot(u);
        }

        if (!content.contains(u)) {
            content.add(u);
        }
    }
}
 
Example 18
Source File: WhiteListQueryTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testWhiteListListening_changeInLookup() throws Exception {
    final File wd = getWorkDir();
    final FileObject root1 = FileUtil.createFolder(new File (wd,"src1"));   //NOI18N
    class L extends ProxyLookup {
        public void setServices(Object... services) {
            setLookups(Lookups.fixed(services));
        }
    }
    final L lkp = new L();
    final WhiteListQueryImplementationMerged mergedWLQ = new WhiteListQueryImplementationMerged(lkp);
    assertNull(mergedWLQ.getWhiteList(root1));
    final RMIBLQuery q1 = new RMIBLQuery();
    final CustomizableWLQuery q2 = new CustomizableWLQuery();
    CustomizableWLQuery.customize(
        Collections.singleton(root1),
            "CORBA",                //NOI18N
            "CORBA-Disabled",       //NOI18N
            "No CORBA allowed",     //NOI18N
            "org.omg.CORBA"
        );
    lkp.setServices(q1);
    final WhiteListQueryImplementation.WhiteListImplementation wl = mergedWLQ.getWhiteList(root1);
    assertNotNull(wl);
    WhiteListQuery.Result res = wl.check(ElementHandle.createTypeElementHandle(ElementKind.CLASS, org.omg.CORBA.BAD_OPERATION.class.getName()), Operation.USAGE);
    assertNotNull(res);
    assertTrue(res.isAllowed());
    res = wl.check(ElementHandle.createTypeElementHandle(ElementKind.CLASS, java.rmi.Remote.class.getName()), Operation.USAGE);
    assertNotNull(res);
    assertFalse(res.isAllowed());
    final AtomicInteger cc = new AtomicInteger();
    wl.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            cc.incrementAndGet();
        }
    });
    lkp.setServices(q1, q2);
    assertEquals(1, cc.get());
    res = wl.check(ElementHandle.createTypeElementHandle(ElementKind.CLASS, org.omg.CORBA.BAD_OPERATION.class.getName()), Operation.USAGE);
    assertNotNull(res);
    assertFalse(res.isAllowed());
    res = wl.check(ElementHandle.createTypeElementHandle(ElementKind.CLASS, java.rmi.Remote.class.getName()), Operation.USAGE);
    assertNotNull(res);
    assertFalse(res.isAllowed());
}
 
Example 19
Source File: GeneratorTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
    // ensure JavaKit is present, so that NbEditorDocument is eventually created.
    // it handles PositionRefs differently than PlainDocument/PlainEditorKit.
    MockMimeLookup.setInstances(MimePath.get("text/x-java"), 
            new Reindenter.Factory(), new JavaKit());
    dataDir = SourceUtilsTestUtil.makeScratchDir(this);
    FileObject dataTargetPackage = FileUtil.createFolder(dataDir, getSourcePckg());
    assertNotNull(dataTargetPackage);
    FileObject dataSourceFolder = FileUtil.toFileObject(getDataDir()).getFileObject(getSourcePckg());
    assertNotNull(dataSourceFolder);
    deepCopy(dataSourceFolder, dataTargetPackage);
    ClassPathProvider cpp = new ClassPathProvider() {
        public ClassPath findClassPath(FileObject file, String type) {
            if (type == ClassPath.SOURCE)
                return ClassPathSupport.createClassPath(new FileObject[] {dataDir});
                if (type == ClassPath.COMPILE)
                    return ClassPathSupport.createClassPath(new FileObject[0]);
                if (type == ClassPath.BOOT)
                    return BootClassPathUtil.getBootClassPath();
                return null;
        }
    };
    SharedClassObject loader = JavaDataLoader.findObject(JavaDataLoader.class, true);
    
    SourceUtilsTestUtil.prepareTest(
            new String[] {
                "org/netbeans/modules/java/project/ui/layer.xml", 
                "org/netbeans/modules/project/ui/resources/layer.xml",
                "META-INF/generated-layer.xml"
            },
            new Object[] {loader, cpp}
    );
    
    JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
    File cacheFolder = new File(getWorkDir(), "var/cache/index");
    cacheFolder.mkdirs();
    IndexUtil.setCacheFolder(cacheFolder);
    ensureRootValid(dataDir.getURL());
    TestUtil.setupEditorMockServices();
    Main.initializeURLFactory();
}
 
Example 20
Source File: UnusedImportsTest.java    From netbeans with Apache License 2.0 3 votes vote down vote up
private void prepareTest() throws Exception {
    FileObject workdir = SourceUtilsTestUtil.makeScratchDir(this);

    src = FileUtil.createFolder(workdir, "src");

    FileObject build = FileUtil.createFolder(workdir, "build");
    FileObject cache = FileUtil.createFolder(workdir, "cache");

    CacheFolder.setCacheFolder(cache);

    SourceUtilsTestUtil.prepareTest(src, build, cache);
}