Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 91534 | Differences between
and this patch

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="1"/>
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 (+59 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, creating it if necessary.
1716
     * 
1717
     * @param The path from the root of the System Filesystem to the file,
1718
     *        including its name and extension.  
1719
     * @return A FileObject representing a new file created with the specified
1720
     *        path, or one representing the existing file if the file already
1721
     *        was present, or null when trying to create a non-existent folder
1722
     */ 
1723
    public static FileObject getConfigurationFile (String path, boolean create) {
1724
        if (path == null) {
1725
            throw new NullPointerException ("Null path to file"); //NOI18N
1726
        }
1727
        FileSystem sfs = Repository.getDefault().getDefaultFileSystem();
1728
        FileObject root = sfs.getRoot();
1729
        FileObject result = root.getFileObject(path);
1730
        assert result == null || result.isData();
1731
        if (result == null && create) {
1732
            try {
1733
                result = FileUtil.createData(root, path);
1734
            } catch (IOException ioe) {
1735
                Exceptions.printStackTrace(ioe);
1736
            }
1737
        }
1738
        return result;
1739
    }
1740
    
1741
    /**
1742
     * Get a folder in the System (configuration) Filesystem with the
1743
     * specified file path, creating it if necessary.
1744
     * 
1745
     * @param The path from the root of the System Filesystem to the file,
1746
     *        including its name and extension.  If the path is the
1747
     *        empty string, returns the root of the system filesystem.
1748
     * @return A FileObject representing a new file created with the specified
1749
     *        path, or one representing the existing file if the file already
1750
     *        was present, or null if an I/O error occurred when trying to
1751
     *        create a non-existent folder
1752
     */ 
1753
    public static FileObject getConfigurationFolder (String path, boolean create) {
1754
        if (path == null) {
1755
            throw new NullPointerException ("Null path");
1756
        }
1757
        FileSystem sfs = Repository.getDefault().getDefaultFileSystem();
1758
        FileObject root = sfs.getRoot();
1759
        FileObject result = "".equals(path) ?
1760
            root : root.getFileObject(path);
1761
        assert result == null || result.isFolder();
1762
        if (result == null && create) {
1763
            try {
1764
                result = FileUtil.createFolder(root, path);
1765
            } catch (IOException ioe) {
1766
                Exceptions.printStackTrace(ioe);
1767
            }
1768
        }
1769
        return result;
1770
    }
1712
}
1771
}
(-)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 / +79 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.getConfigurationFolder("folder", true);
77
        assertNotNull (f);
78
        FileObject f1 = FileUtil.getConfigurationFile ("folder/file.txt", true);
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.getConfigurationFile("somewhere/file2.txt", true);
86
        assertNotNull (f);
87
        Exception ioe = null;
88
        FileObject f1 = null;
89
        try {
90
            f1 = FileUtil.getConfigurationFile ("somewhere/file2.txt", true);
91
        } catch (Exception e) {
92
            ioe = e;
93
        }
94
        assertNull (ioe);
95
        assertNotNull (f1);
96
        assertEquals (f, f1);
97
        ioe = null;
98
        try {
99
            f = FileUtil.getConfigurationFolder ("somewhere", true);
100
        } catch (Exception e) {
101
            ioe = e;
102
        }
103
        assertNull (ioe);
104
        assertEquals (f, f1.getParent());
105
        
106
        f = FileUtil.getConfigurationFolder("folder", true);
107
        FileObject nue = f.createData ("hello.txt");
108
        assertEquals (nue, FileUtil.getConfigurationFile("folder/hello.txt", true));
109
        assertNotNull (f.getFileObject ("hello.txt"));
110
        assertTrue (f.getFileObject ("hello.txt").isData());
111
        assertFalse (f.getFileObject ("hello.txt").isFolder());
112
    }
113
    
114
    public void testCreateConfigurationFolder() throws Exception {
115
        System.out.println("testCreateConfigurationFolder");
116
        FileObject f = FileUtil.getConfigurationFolder ("other", true);
117
        assertNotNull (f);
118
        Exception ioe = null;
119
        FileObject f1 = null;
120
        try {
121
            f1 = FileUtil.getConfigurationFolder("other", true);
122
        } catch (Exception e) {
123
            ioe = e;
124
        }
125
        assertNull (ioe);
126
        assertEquals (f, f1);
127
    }
128
    
129
    public static class MyRepo extends Repository {
130
        static FileSystem sysfs;
131
        public MyRepo () {
132
            super(sysfs = FileUtil.createMemoryFileSystem());
133
            try {
134
                FileObject fld = sysfs.getRoot().createFolder("folder");
135
                fld.createData("file.txt");
136
            } catch (IOException ioe) {
137
                throw new Error (ioe);
138
            }
139
        }
140
    }
64
}
141
}

Return to bug 91534
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo