|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2006 IBM Corporation and others. |
2 |
* Copyright (c) 2006, 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* James Blackburn (Broadcom Corp.) |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.core.tests.internal.filesystem.wrapper; |
12 |
package org.eclipse.core.tests.internal.filesystem.wrapper; |
| 12 |
|
13 |
|
|
Lines 22-48
Link Here
|
| 22 |
/** |
23 |
/** |
| 23 |
* A simple file system implementation that acts as a wrapper around the |
24 |
* A simple file system implementation that acts as a wrapper around the |
| 24 |
* local file system. |
25 |
* local file system. |
|
|
26 |
* <p> |
| 27 |
* Also allows tests to inject a custom FileStore template class (derived from |
| 28 |
* {@link WrapperFileStore}). Tests can use {@link #setCustomFileStore(Class)} |
| 29 |
* to override default {@link WrapperFileStore} behaviour. |
| 30 |
* </p> |
| 25 |
*/ |
31 |
*/ |
| 26 |
public class WrapperFileSystem extends FileSystem { |
32 |
public class WrapperFileSystem extends FileSystem { |
| 27 |
|
33 |
|
| 28 |
private static final IFileStore NULL_ROOT = EFS.getNullFileSystem().getStore(Path.ROOT); |
34 |
protected static final IFileStore NULL_ROOT = EFS.getNullFileSystem().getStore(Path.ROOT); |
| 29 |
|
35 |
|
| 30 |
private static final String SCHEME_WRAPPED = "wrapped"; |
36 |
private static final String SCHEME_WRAPPED = "wrapped"; |
| 31 |
|
37 |
|
| 32 |
private static WrapperFileSystem instance; |
38 |
private static volatile WrapperFileSystem instance; |
|
|
39 |
|
| 40 |
/** Custom file-store wrapper */ |
| 41 |
private static volatile Class<? extends WrapperFileStore> customFS = WrapperFileStore.class; |
| 33 |
|
42 |
|
| 34 |
public static URI getBasicURI(URI wrappedURI) { |
43 |
public static URI getBasicURI(URI wrappedURI) { |
| 35 |
Assert.isLegal(SCHEME_WRAPPED.equals(wrappedURI.getScheme())); |
44 |
Assert.isLegal(SCHEME_WRAPPED.equals(wrappedURI.getScheme())); |
| 36 |
return URI.create(wrappedURI.getQuery()); |
45 |
return URI.create(wrappedURI.getQuery()); |
| 37 |
} |
46 |
} |
| 38 |
|
47 |
|
| 39 |
public static WrapperFileSystem getInstance() { |
48 |
public static synchronized WrapperFileSystem getInstance() { |
| 40 |
WrapperFileSystem tmpInstance = instance; |
49 |
if (instance != null) |
| 41 |
if (tmpInstance != null) |
50 |
return instance; |
| 42 |
return tmpInstance; |
|
|
| 43 |
return instance = new WrapperFileSystem(); |
51 |
return instance = new WrapperFileSystem(); |
| 44 |
} |
52 |
} |
| 45 |
|
53 |
|
|
|
54 |
/** |
| 55 |
* Use fs as the WrapperFileStore to use in this filesystem. |
| 56 |
* Allows tests to easily override existing IFileStore behaviour. |
| 57 |
* By extending {@link WrapperFileStore} conditions difficult to simulate |
| 58 |
* on the LocalFileSystem can be provoked. |
| 59 |
* |
| 60 |
* @param fs filestore, or null to use default {@link WrapperFileStore} |
| 61 |
* based implementation. |
| 62 |
*/ |
| 63 |
public static void setCustomFileStore(Class<? extends WrapperFileStore> fs) { |
| 64 |
if (fs == null) |
| 65 |
customFS = WrapperFileStore.class; |
| 66 |
else |
| 67 |
customFS = fs; |
| 68 |
} |
| 69 |
|
| 46 |
public static URI getWrappedURI(URI baseURI) { |
70 |
public static URI getWrappedURI(URI baseURI) { |
| 47 |
try { |
71 |
try { |
| 48 |
return new URI(SCHEME_WRAPPED, null, baseURI.getPath(), baseURI.toString(), null); |
72 |
return new URI(SCHEME_WRAPPED, null, baseURI.getPath(), baseURI.toString(), null); |
|
Lines 69-74
Link Here
|
| 69 |
CoreTest.log(ResourceTest.PI_RESOURCES_TESTS, e); |
93 |
CoreTest.log(ResourceTest.PI_RESOURCES_TESTS, e); |
| 70 |
return NULL_ROOT; |
94 |
return NULL_ROOT; |
| 71 |
} |
95 |
} |
| 72 |
return new WrapperFileStore(baseStore); |
96 |
return WrapperFileStore.newInstance(customFS, baseStore); |
| 73 |
} |
97 |
} |
| 74 |
} |
98 |
} |