This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 91534
Collapse All | Expand All

(-)openide/fs/apichanges.xml (+22 lines)
Lines 23-28 Link Here
23
        <apidef name="filesystems">Filesystems API</apidef>
23
        <apidef name="filesystems">Filesystems API</apidef>
24
    </apidefs>
24
    </apidefs>
25
    <changes>
25
    <changes>
26
        <change id="convenience-access-to-sfs-folders">
27
            <api name="filesystems"/>
28
            <summary>Convenience system filesystem accessor methods on FileUtil</summary>
29
            <version major="7" minor="2"/>
30
            <date day="20" month="3" year="2007"/>
31
            <author login="tboudreau"/>
32
            <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
33
            <description>
34
                <p>
35
                    Convenience methods added for looking up files/folders in
36
                    the system filesystem.  Rather than having to call
37
                    <code>Respository.getDefault().getDefaultFileSystem().getRoot().getFileObject(&quot;foo/bar&quot;)</code>,
38
                    you can simply call <code>FileUtil.getConfigurationFolder (&quot;foo/bar&quot;, false)</code>.
39
                    <a href="@TOP@/org/openide/filesystems/FileUtil.html#getConfigurationFolder(java.lang.String, boolean)">FileUtil.getConfigurationFolder(path)</a>s
40
                    and 
41
                    <a href="@TOP@/org/openide/filesystems/FileUtil.html#getConfigurationFile(java.lang.String, boolean)">FileUtil.getConfigurationFile(path)</a>
42
                    were added to the API.
43
                </p>
44
            </description>
45
            <class package="org.openide.filesystems" name="Repository"/>
46
            <issue number="91534"/>
47
        </change>
26
        <change id="add-content-to-sfs">
48
        <change id="add-content-to-sfs">
27
            <api name="filesystems"/>
49
            <api name="filesystems"/>
28
            <summary>Allow modules to dynamically add/remove layer content</summary>
50
            <summary>Allow modules to dynamically add/remove layer content</summary>
(-)openide/fs/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Specification-Version: 7.1
3
OpenIDE-Module-Specification-Version: 7.2
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
5
5
(-)openide/fs/src/org/openide/filesystems/FileUtil.java (+88 lines)
Lines 1709-1712 Link Here
1709
            return wrapFileNoCanonicalize(delegate.createFileObject(path));
1709
            return wrapFileNoCanonicalize(delegate.createFileObject(path));
1710
        }
1710
        }
1711
    }
1711
    }
1712
    
1713
    /**
1714
     * Get a data file or folder from the System (configuration) Filesystem 
1715
     * with the specified file path.
1716
     * 
1717
     * @param path The path from the root of the System Filesystem to the file,
1718
     *        including its name and extension.  
1719
     * @return A FileObject for that file in the system filesystem
1720
     */ 
1721
    public static FileObject getConfigurationFile (String path) {
1722
        if (path == null) {
1723
            throw new NullPointerException ("Null path to file"); //NOI18N
1724
        }
1725
        FileSystem sfs = Repository.getDefault().getDefaultFileSystem();
1726
        FileObject root = sfs.getRoot();
1727
        FileObject result = root.getFileObject(path);
1728
        assert result == null || result.isData() : "Not a data file: " + path; //NOI18N
1729
        return result;
1730
    }
1731
1732
    /**
1733
     * Get a data file or folder from the System (configuration) Filesystem 
1734
     * with the specified file path, creating a new empty file if the specified
1735
     * file does not exist.
1736
     * 
1737
     * @param path The path from the root of the System Filesystem to the file,
1738
     *        including its name and extension.  
1739
     * @return A FileObject for that file in the system filesystem
1740
     * @throws IOException if the file did not previously exist and could not be
1741
     *        created for some reason
1742
     */ 
1743
    public static FileObject getOrCreateConfigurationFile (String path) throws 
1744
                                                                   IOException {
1745
        FileObject result = getConfigurationFile (path);
1746
        if (result == null) {
1747
            FileSystem sfs = Repository.getDefault().getDefaultFileSystem();
1748
            FileObject root = sfs.getRoot();
1749
            result = createData(root, path);
1750
        }
1751
        return result;
1752
    }
1753
    
1754
    /**
1755
     * Get a folder in the System (configuration) Filesystem with the
1756
     * specified file path.
1757
     * 
1758
     * @param path The path from the root of the System Filesystem to the folder.
1759
     *        If the path is the empty string, returns the root of the 
1760
     *        system filesystem (do not use &quot;/&quot; for the root).
1761
     * @return A FileObject representing a new file created with the specified
1762
     *        path, or one representing the existing file if the file already
1763
     *        was present, or null if an I/O error occurred when trying to
1764
     *        create a non-existent folder
1765
     */ 
1766
    public static FileObject getConfigurationFolder (String path) {
1767
        if (path == null) {
1768
            throw new NullPointerException ("Null path"); //NOI18N
1769
        }
1770
        FileSystem sfs = Repository.getDefault().getDefaultFileSystem();
1771
        FileObject root = sfs.getRoot();
1772
        FileObject result = path.length() == 0 ? //NOI18N
1773
            root : root.getFileObject(path);
1774
        assert result == null || result.isFolder() : "Not a folder: " + path; //NOI18N
1775
        return result;
1776
    }
1777
1778
    /**
1779
     * Get a folder in the System (configuration) Filesystem with the
1780
     * specified file path, creating it if necessary.
1781
     * 
1782
     * @param path The path from the root of the System Filesystem to the folder.
1783
     *        If the path is the empty string, returns the root of the 
1784
     *        system filesystem (do not use &quot;/&quot; for the root).
1785
     * @return A FileObject representing a new file created with the specified
1786
     *        path, or one representing the existing file if the file already
1787
     *        was present, or null if an I/O error occurred when trying to
1788
     *        create a non-existent folder
1789
     * @throws IOException if an error occurs creating the folder
1790
     */ 
1791
    public static FileObject getOrCreateConfigurationFolder (String path) throws IOException {
1792
        FileObject result = getConfigurationFolder(path);
1793
        if (result == null) {
1794
            FileSystem sfs = Repository.getDefault().getDefaultFileSystem();
1795
            FileObject root = sfs.getRoot();
1796
            result = createFolder (root, path);
1797
        }
1798
        return result;
1799
    }
1712
}
1800
}
(-)openide/fs/src/org/openide/filesystems/Repository.java (-1 / +11 lines)
Lines 144-150 Link Here
144
144
145
    /**
145
    /**
146
     * Gets the NetBeans default (system, configuration) filesystem.
146
     * Gets the NetBeans default (system, configuration) filesystem.
147
     * @return the default filesystem
147
     * The System Filesystem contains runtime data that is a merge of
148
     * all of the XML layer files provided by enabled modules, and the
149
     * <code>config/</code> subfolder of the userdir on the user's disk.
150
     * 
151
     * If you want to simply get a file or folder from the system,
152
     * it is simpler to call <a href="FileUtil.html#getConfigurationFile(java.lang.String)">
153
     * FileUtil.getConfigurationFile(path)</a> or 
154
     * <a href="FileUtil.html#getConfigurationFolder(java.lang.String)">
155
     * FileUtil.getConfigurationFolder(path)</a>.
156
     * 
157
     * @return the system filesystem
148
     */
158
     */
149
    public final FileSystem getDefaultFileSystem() {
159
    public final FileSystem getDefaultFileSystem() {
150
        return system;
160
        return system;
(-)openide/fs/test/unit/src/org/openide/filesystems/FileUtilTest.java (-2 / +59 lines)
Lines 20-39 Link Here
20
package org.openide.filesystems;
20
package org.openide.filesystems;
21
21
22
import java.io.File;
22
import java.io.File;
23
import java.io.IOException;
23
import java.net.URL;
24
import java.net.URL;
24
import org.netbeans.junit.MockServices;
25
import org.netbeans.junit.MockServices;
25
import org.netbeans.junit.NbTestCase;
26
import org.netbeans.junit.NbTestCase;
26
import org.openide.util.Utilities;
27
import org.openide.util.Utilities;
28
import org.netbeans.junit.MockServices;
27
29
28
/**
30
/**
29
 * @author Jesse Glick
31
 * @author Jesse Glick, Tim Boudreau
30
 */
32
 */
31
public class FileUtilTest extends NbTestCase {
33
public class FileUtilTest extends NbTestCase {
32
34
33
    public FileUtilTest(String n) {
35
    public FileUtilTest(String n) {
34
        super(n);
36
        super(n);
35
    }
37
    }
36
38
    
39
    protected void setUp() throws java.lang.Exception {
40
        MockServices.setServices(MyRepo.class);
41
    }
42
    
37
    public void testToFileObjectSlash() throws Exception { // #98388
43
    public void testToFileObjectSlash() throws Exception { // #98388
38
        if (!Utilities.isUnix()) {
44
        if (!Utilities.isUnix()) {
39
            return;
45
            return;
Lines 60-64 Link Here
60
            }
66
            }
61
        }
67
        }
62
    }
68
    }
69
    
70
    protected String[] getResources(String testName) {
71
        return new String[] { "somefolder/somefile.txt" };
72
    }
63
73
74
    public void testGetConfigurationData() throws Exception {
75
        System.out.println("testGetConfigurationData");
76
        FileObject f = FileUtil.getOrCreateConfigurationFolder("folder");
77
        assertNotNull (f);
78
        FileObject f1 = FileUtil.getOrCreateConfigurationFile ("folder/file.txt");
79
        assertNotNull (f1);
80
        assertEquals (f1, f.getFileObject ("file.txt"));
81
    }
82
    
83
    public void testCreateConfigurationFile() throws Exception {
84
        System.out.println("testCreateConfigurationFile");
85
        FileObject f = FileUtil.getOrCreateConfigurationFile("somewhere/file2.txt");
86
        assertNotNull (f);
87
        FileObject f1 = FileUtil.getOrCreateConfigurationFile ("somewhere/file2.txt");
88
        assertNotNull (f1);
89
        assertEquals (f, f1);
90
            f = FileUtil.getOrCreateConfigurationFolder ("somewhere");
91
        assertEquals (f, f1.getParent());
92
        
93
        f = FileUtil.getOrCreateConfigurationFolder("folder");
94
        FileObject nue = f.createData ("hello.txt");
95
        assertEquals (nue, FileUtil.getOrCreateConfigurationFile("folder/hello.txt"));
96
        assertNotNull (f.getFileObject ("hello.txt"));
97
        assertTrue (f.getFileObject ("hello.txt").isData());
98
        assertFalse (f.getFileObject ("hello.txt").isFolder());
99
    }
100
    
101
    public void testCreateConfigurationFolder() throws Exception {
102
        System.out.println("testCreateConfigurationFolder");
103
        FileObject f = FileUtil.getOrCreateConfigurationFolder ("other");
104
        assertNotNull (f);
105
        FileObject f1 = FileUtil.getOrCreateConfigurationFolder("other");
106
        assertEquals (f, f1);
107
    }
108
    
109
    public static class MyRepo extends Repository {
110
        static FileSystem sysfs;
111
        public MyRepo () {
112
            super(sysfs = FileUtil.createMemoryFileSystem());
113
            try {
114
                FileObject fld = sysfs.getRoot().createFolder("folder");
115
                fld.createData("file.txt");
116
            } catch (IOException ioe) {
117
                throw new Error (ioe);
118
            }
119
        }
120
    }
64
}
121
}

Return to bug 91534