Lines 71-76
Link Here
|
71 |
import java.util.logging.Level; |
71 |
import java.util.logging.Level; |
72 |
import java.util.logging.Logger; |
72 |
import java.util.logging.Logger; |
73 |
import java.util.zip.ZipException; |
73 |
import java.util.zip.ZipException; |
|
|
74 |
import org.openide.util.Exceptions; |
74 |
import org.openide.util.NbBundle; |
75 |
import org.openide.util.NbBundle; |
75 |
import org.openide.util.RequestProcessor; |
76 |
import org.openide.util.RequestProcessor; |
76 |
import org.openide.util.Utilities; |
77 |
import org.openide.util.Utilities; |
Lines 88-94
Link Here
|
88 |
static final long serialVersionUID = -98124752801761145L; |
89 |
static final long serialVersionUID = -98124752801761145L; |
89 |
|
90 |
|
90 |
/** One request proccesor shared for all instances of JarFileSystem*/ |
91 |
/** One request proccesor shared for all instances of JarFileSystem*/ |
91 |
private static RequestProcessor req = new RequestProcessor("JarFs - modification watcher", 1, false, false); // NOI18N |
92 |
private static final RequestProcessor req = new RequestProcessor("JarFs - modification watcher", 1, false, false); // NOI18N |
92 |
|
93 |
|
93 |
/** Controlls the LocalFileSystem's automatic refresh. |
94 |
/** Controlls the LocalFileSystem's automatic refresh. |
94 |
* If the refresh time interval is set from the System.property, than this value is used. |
95 |
* If the refresh time interval is set from the System.property, than this value is used. |
Lines 171-176
Link Here
|
171 |
setCapability(cap); |
172 |
setCapability(cap); |
172 |
} |
173 |
} |
173 |
|
174 |
|
|
|
175 |
/** Creates new JAR for a given JAR file. This constructor |
176 |
* behaves basically like: |
177 |
* <pre> |
178 |
* JarFileSystem fs = new JarFileSystem(); |
179 |
* fs.setJarFile(jar); |
180 |
* </pre> |
181 |
* but it is more effective in some situations. It does not open and |
182 |
* read the content of the jar file immediately. Instead |
183 |
* it waits until somebody asks for resources from inside the JAR. |
184 |
* |
185 |
* @param jar location of the JAR file |
186 |
* @since 7.34 |
187 |
*/ |
188 |
public JarFileSystem(File jar) throws IOException { |
189 |
this(); |
190 |
try { |
191 |
setJarFile(jar, true, false); |
192 |
} catch (PropertyVetoException ex) { |
193 |
// cannot happen, setSystemName can throw the exception only |
194 |
// if the filesystem is already in Repository, which this one |
195 |
// is not. |
196 |
throw (IOException)new IOException().initCause(ex); |
197 |
} |
198 |
} |
199 |
|
174 |
/* Creates Reference. In FileSystem, which subclasses AbstractFileSystem, you can overload method |
200 |
/* Creates Reference. In FileSystem, which subclasses AbstractFileSystem, you can overload method |
175 |
* createReference(FileObject fo) to achieve another type of Reference (weak, strong etc.) |
201 |
* createReference(FileObject fo) to achieve another type of Reference (weak, strong etc.) |
176 |
* @param fo is FileObject. It`s reference yourequire to get. |
202 |
* @param fo is FileObject. It`s reference yourequire to get. |
Lines 233-239
Link Here
|
233 |
* @throws IOException if the file is not valid |
259 |
* @throws IOException if the file is not valid |
234 |
*/ |
260 |
*/ |
235 |
public void setJarFile(final File aRoot) throws IOException, PropertyVetoException { |
261 |
public void setJarFile(final File aRoot) throws IOException, PropertyVetoException { |
236 |
setJarFile(aRoot, true); |
262 |
setJarFile(aRoot, true, true); |
237 |
} |
263 |
} |
238 |
|
264 |
|
239 |
@SuppressWarnings("deprecation") // need to set it for compat |
265 |
@SuppressWarnings("deprecation") // need to set it for compat |
Lines 241-247
Link Here
|
241 |
setSystemName(s); |
267 |
setSystemName(s); |
242 |
} |
268 |
} |
243 |
|
269 |
|
244 |
private void setJarFile(final File aRoot, boolean refreshRoot) |
270 |
private void setJarFile(final File aRoot, boolean refreshRoot, boolean openJar) |
245 |
throws IOException, PropertyVetoException { |
271 |
throws IOException, PropertyVetoException { |
246 |
if (!aRoot.equals(FileUtil.normalizeFile(aRoot))) { |
272 |
if (!aRoot.equals(FileUtil.normalizeFile(aRoot))) { |
247 |
throw new IllegalArgumentException( |
273 |
throw new IllegalArgumentException( |
Lines 279-296
Link Here
|
279 |
|
305 |
|
280 |
JarFile tempJar = null; |
306 |
JarFile tempJar = null; |
281 |
|
307 |
|
282 |
try { |
308 |
if (openJar) { |
283 |
tempJar = new JarFile(s); |
309 |
try { |
284 |
LOGGER.log(Level.FINE, "opened: "+ System.currentTimeMillis()+ " " + s);//NOI18N |
310 |
tempJar = new JarFile(s); |
285 |
} catch (ZipException e) { |
311 |
LOGGER.log(Level.FINE, "opened: "+ System.currentTimeMillis()+ " " + s);//NOI18N |
286 |
throw new FSException(NbBundle.getMessage(JarFileSystem.class, "EXC_NotValidJarFile2", e.getLocalizedMessage(), s)); |
312 |
} catch (ZipException e) { |
|
|
313 |
throw new FSException(NbBundle.getMessage(JarFileSystem.class, "EXC_NotValidJarFile2", e.getLocalizedMessage(), s)); |
314 |
} |
287 |
} |
315 |
} |
288 |
|
316 |
|
289 |
synchronized (closeSync) { |
317 |
synchronized (closeSync) { |
290 |
_setSystemName(s); |
318 |
_setSystemName(s); |
291 |
|
319 |
|
292 |
closeCurrentRoot(false); |
320 |
closeCurrentRoot(false); |
293 |
jar = tempJar; |
321 |
setJar(tempJar); |
294 |
openRequestTime = System.currentTimeMillis(); |
322 |
openRequestTime = System.currentTimeMillis(); |
295 |
root = new File(s); |
323 |
root = new File(s); |
296 |
|
324 |
|
Lines 328-334
Link Here
|
328 |
|
356 |
|
329 |
if ((f != null) && !f.equals(aRoot)) { |
357 |
if ((f != null) && !f.equals(aRoot)) { |
330 |
try { |
358 |
try { |
331 |
setJarFile(f, false); |
359 |
setJarFile(f, false, true); |
332 |
} catch (IOException iex) { |
360 |
} catch (IOException iex) { |
333 |
ExternalUtil.exception(iex); |
361 |
ExternalUtil.exception(iex); |
334 |
} catch (PropertyVetoException pvex) { |
362 |
} catch (PropertyVetoException pvex) { |
Lines 688-705
Link Here
|
688 |
// 150% of time from last open request, but between CLOSE_DELAY_MIN and CLOSE_DELAY_MAX |
716 |
// 150% of time from last open request, but between CLOSE_DELAY_MIN and CLOSE_DELAY_MAX |
689 |
closeDelay = (int) Math.min(CLOSE_DELAY_MAX, Math.max(CLOSE_DELAY_MIN, (1.5 * requestPeriod))); |
717 |
closeDelay = (int) Math.min(CLOSE_DELAY_MAX, Math.max(CLOSE_DELAY_MIN, (1.5 * requestPeriod))); |
690 |
|
718 |
|
691 |
JarFile j = jar; |
719 |
return getJar(true); |
692 |
|
|
|
693 |
if (j != null) { |
694 |
return j; |
695 |
} |
696 |
|
697 |
if ((jar == null) && (root != null)) { |
698 |
jar = new JarFile(root); |
699 |
LOGGER.log(Level.FINE, "opened: "+ System.currentTimeMillis()+ " " + root.getAbsolutePath());//NOI18N |
700 |
} |
701 |
|
702 |
return jar; |
703 |
} |
720 |
} |
704 |
} |
721 |
} |
705 |
|
722 |
|
Lines 724-738
Link Here
|
724 |
return new Runnable() { |
741 |
return new Runnable() { |
725 |
public void run() { |
742 |
public void run() { |
726 |
synchronized (closeSync) { |
743 |
synchronized (closeSync) { |
727 |
if (jar != null) { |
744 |
final JarFile jarFile = getJar(false); |
|
|
745 |
if (jarFile != null) { |
728 |
try { |
746 |
try { |
729 |
jar.close(); |
747 |
jarFile.close(); |
730 |
LOGGER.log(Level.FINE, "closed: "+ System.currentTimeMillis()+ " " + root.getAbsolutePath());//NOI18N |
748 |
LOGGER.log(Level.FINE, "closed: "+ System.currentTimeMillis()+ " " + root.getAbsolutePath());//NOI18N |
731 |
} catch (Exception exc) { |
749 |
} catch (Exception exc) { |
732 |
// ignore exception during closing, just log it |
750 |
// ignore exception during closing, just log it |
733 |
ExternalUtil.exception(exc); |
751 |
ExternalUtil.exception(exc); |
734 |
} finally { |
752 |
} finally { |
735 |
jar = null; |
753 |
setJar(null); |
736 |
closeTask = null; |
754 |
closeTask = null; |
737 |
} |
755 |
} |
738 |
} |
756 |
} |
Lines 895-901
Link Here
|
895 |
synchronized (closeSync) { |
913 |
synchronized (closeSync) { |
896 |
j = reOpenJarFile(); |
914 |
j = reOpenJarFile(); |
897 |
|
915 |
|
898 |
JarEntry je = j.getJarEntry(file); |
916 |
JarEntry je = null; |
|
|
917 |
if (j != null) { |
918 |
je = j.getJarEntry(file); |
919 |
} |
899 |
|
920 |
|
900 |
if (je != null) { |
921 |
if (je != null) { |
901 |
return je; |
922 |
return je; |
Lines 907-912
Link Here
|
907 |
return new JarEntry(file); |
928 |
return new JarEntry(file); |
908 |
} |
929 |
} |
909 |
|
930 |
|
|
|
931 |
/** |
932 |
* @return the jar |
933 |
*/ |
934 |
private JarFile getJar(boolean create) { |
935 |
assert Thread.holdsLock(closeSync); |
936 |
if (jar == null && create) { |
937 |
try { |
938 |
jar = new JarFile(root); |
939 |
LOGGER.log(Level.FINE, "opened: {0} {1}", new Object[]{System.currentTimeMillis(), root.getAbsolutePath()}); //NOI18N |
940 |
} catch (IOException ex) { |
941 |
Exceptions.printStackTrace(ex); |
942 |
} |
943 |
} |
944 |
return jar; |
945 |
} |
946 |
|
947 |
/** |
948 |
* @param jar the jar to set |
949 |
*/ |
950 |
private void setJar(JarFile jar) { |
951 |
this.jar = jar; |
952 |
} |
953 |
|
910 |
/** Use soft-references to not throw away the data that quickly. |
954 |
/** Use soft-references to not throw away the data that quickly. |
911 |
* JarFS if often queried for its FOs e.g. by java parser, which |
955 |
* JarFS if often queried for its FOs e.g. by java parser, which |
912 |
* leaves the references immediately. |
956 |
* leaves the references immediately. |