Lines 60-82
import org.netbeans.modules.masterfs.fil
Link Here
|
60 |
import org.netbeans.modules.masterfs.filebasedfs.utils.FileInfo; |
60 |
import org.netbeans.modules.masterfs.filebasedfs.utils.FileInfo; |
61 |
import org.netbeans.modules.masterfs.providers.AnnotationProvider; |
61 |
import org.netbeans.modules.masterfs.providers.AnnotationProvider; |
62 |
import org.netbeans.modules.masterfs.providers.ProvidedExtensions; |
62 |
import org.netbeans.modules.masterfs.providers.ProvidedExtensions; |
|
|
63 |
import org.openide.filesystems.FileChangeListener; |
63 |
import org.openide.filesystems.FileObject; |
64 |
import org.openide.filesystems.FileObject; |
64 |
import org.openide.filesystems.FileSystem; |
65 |
import org.openide.filesystems.FileSystem; |
|
|
66 |
import org.openide.filesystems.FileBasedFileSystemsSPI; |
65 |
import org.openide.filesystems.FileUtil; |
67 |
import org.openide.filesystems.FileUtil; |
66 |
import org.openide.util.Exceptions; |
68 |
import org.openide.util.Exceptions; |
|
|
69 |
import org.openide.util.Lookup; |
67 |
import org.openide.util.actions.SystemAction; |
70 |
import org.openide.util.actions.SystemAction; |
68 |
|
71 |
|
69 |
/** |
72 |
/** |
70 |
* @author Radek Matous |
73 |
* @author Radek Matous |
71 |
*/ |
74 |
*/ |
72 |
public final class FileBasedFileSystem extends FileSystem { |
75 |
public final class FileBasedFileSystem extends FileSystem { |
73 |
private static Map allInstances = new HashMap(); |
76 |
private static Map<File, FileBasedFileSystem> fileToFileSystems = new HashMap<File, FileBasedFileSystem>(); |
74 |
|
77 |
|
75 |
private transient final FileObjectFactory factory; |
78 |
private transient final FileObjectFactory factory; |
76 |
transient private final StatusImpl status = new StatusImpl(); |
79 |
transient private final StatusImpl status = new StatusImpl(); |
77 |
public static boolean WARNINGS = true; |
80 |
public static boolean WARNINGS = true; |
78 |
private ThreadLocal<Boolean> refreshIsOn = new ThreadLocal<Boolean>(); |
81 |
private ThreadLocal<Boolean> refreshIsOn = new ThreadLocal<Boolean>(); |
79 |
|
82 |
private static Repository repo; |
|
|
83 |
|
80 |
public boolean isWarningEnabled() { |
84 |
public boolean isWarningEnabled() { |
81 |
Boolean isRefreshOn = refreshIsOn.get(); |
85 |
Boolean isRefreshOn = refreshIsOn.get(); |
82 |
return WARNINGS && (isRefreshOn == null || !isRefreshOn.booleanValue()); |
86 |
return WARNINGS && (isRefreshOn == null || !isRefreshOn.booleanValue()); |
Lines 84-90
public final class FileBasedFileSystem e
Link Here
|
84 |
|
88 |
|
85 |
//only for tests purposes |
89 |
//only for tests purposes |
86 |
public static void reinitForTests() { |
90 |
public static void reinitForTests() { |
87 |
FileBasedFileSystem.allInstances = new HashMap(); |
91 |
FileBasedFileSystem.fileToFileSystems = new HashMap(); |
88 |
} |
92 |
} |
89 |
|
93 |
|
90 |
public static FileBasedFileSystem getInstance(final File file) { |
94 |
public static FileBasedFileSystem getInstance(final File file) { |
Lines 96-116
public final class FileBasedFileSystem e
Link Here
|
96 |
final FileInfo rootInfo = new FileInfo(file).getRoot(); |
100 |
final FileInfo rootInfo = new FileInfo(file).getRoot(); |
97 |
final File rootFile = rootInfo.getFile(); |
101 |
final File rootFile = rootInfo.getFile(); |
98 |
|
102 |
|
99 |
synchronized (FileBasedFileSystem.allInstances) { |
103 |
synchronized (FileBasedFileSystem.fileToFileSystems) { |
100 |
retVal = (FileBasedFileSystem) FileBasedFileSystem.allInstances.get(rootFile); |
104 |
retVal = fileToFileSystems.get(rootFile); |
101 |
} |
105 |
} |
102 |
if (retVal == null && addMising) { |
106 |
if (retVal == null && addMising) { |
103 |
if (rootInfo.isConvertibleToFileObject()) { |
107 |
if (rootInfo.isConvertibleToFileObject()) { |
104 |
synchronized (FileBasedFileSystem.allInstances) { |
108 |
boolean changed =false; |
105 |
retVal = (FileBasedFileSystem) FileBasedFileSystem.allInstances.get(rootFile); |
109 |
synchronized (fileToFileSystems) { |
|
|
110 |
retVal = FileBasedFileSystem.fileToFileSystems.get(rootFile); |
106 |
if (retVal == null) { |
111 |
if (retVal == null) { |
107 |
retVal = new FileBasedFileSystem(rootFile); |
112 |
retVal = new FileBasedFileSystem(rootFile); |
108 |
FileBasedFileSystem.allInstances.put(rootFile, retVal); |
113 |
fileToFileSystems.put(rootFile, retVal); |
|
|
114 |
changed = true; |
109 |
} |
115 |
} |
|
|
116 |
} |
117 |
if (changed) { |
118 |
getRepository().fireChange(); |
110 |
} |
119 |
} |
111 |
} |
120 |
} |
112 |
} |
121 |
} |
113 |
return retVal; |
122 |
return retVal; |
|
|
123 |
} |
124 |
|
125 |
private static Repository getRepository() { |
126 |
synchronized(FileBasedFileSystem.class) { |
127 |
if (repo != null) { |
128 |
return repo; |
129 |
} |
130 |
} |
131 |
Repository tmp = (Repository)Lookup.getDefault().lookup(FileBasedFileSystemsSPI.class); |
132 |
synchronized(FileBasedFileSystem.class) { |
133 |
repo = Repository.getDefault(); |
134 |
} |
135 |
assert repo != null; |
136 |
return repo; |
114 |
} |
137 |
} |
115 |
|
138 |
|
116 |
public static final FileObject getFileObject(final File file) { |
139 |
public static final FileObject getFileObject(final File file) { |
Lines 119-137
public final class FileBasedFileSystem e
Link Here
|
119 |
} |
142 |
} |
120 |
|
143 |
|
121 |
|
144 |
|
122 |
static Collection getInstances() { |
145 |
static Collection<FileBasedFileSystem> getInstances() { |
123 |
synchronized (FileBasedFileSystem.allInstances) { |
146 |
synchronized (FileBasedFileSystem.fileToFileSystems) { |
124 |
return new ArrayList(allInstances.values()); |
147 |
return new ArrayList(fileToFileSystems.values()); |
125 |
} |
148 |
} |
126 |
} |
149 |
} |
127 |
|
150 |
|
|
|
151 |
public static Map<File, ? extends FileBasedFileSystem> getFileSystems() { |
152 |
return new HashMap<File, FileBasedFileSystem>(fileToFileSystems); |
153 |
} |
154 |
|
128 |
public Status getStatus() { |
155 |
public Status getStatus() { |
129 |
return status; |
156 |
return status; |
130 |
} |
157 |
} |
131 |
|
158 |
|
132 |
static int getSize () { |
159 |
static int getSize () { |
133 |
synchronized (FileBasedFileSystem.allInstances) { |
160 |
synchronized (FileBasedFileSystem.fileToFileSystems) { |
134 |
return allInstances.size(); |
161 |
return fileToFileSystems.size(); |
135 |
} |
162 |
} |
136 |
} |
163 |
} |
137 |
|
164 |
|
Lines 214-220
public final class FileBasedFileSystem e
Link Here
|
214 |
Statistics.REFRESH_FILE.reset(); |
241 |
Statistics.REFRESH_FILE.reset(); |
215 |
} |
242 |
} |
216 |
|
243 |
|
217 |
public final void refreshFor(final File file) { |
244 |
public final void refreshFor(final File... files) { |
218 |
Statistics.StopWatch stopWatch = Statistics.getStopWatch(Statistics.REFRESH_FS); |
245 |
Statistics.StopWatch stopWatch = Statistics.getStopWatch(Statistics.REFRESH_FS); |
219 |
stopWatch.start(); |
246 |
stopWatch.start(); |
220 |
try { |
247 |
try { |
Lines 222-228
public final class FileBasedFileSystem e
Link Here
|
222 |
refreshIsOn.set(true); |
249 |
refreshIsOn.set(true); |
223 |
this.runAtomicAction(new FileSystem.AtomicAction() { |
250 |
this.runAtomicAction(new FileSystem.AtomicAction() { |
224 |
public void run() throws IOException { |
251 |
public void run() throws IOException { |
225 |
getFactory().refreshFor(file); |
252 |
getFactory().refreshFor(files); |
226 |
} |
253 |
} |
227 |
}); |
254 |
}); |
228 |
} finally { |
255 |
} finally { |