|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.debug.core.efs; |
|
6 |
|
7 import java.net.URI; |
|
8 import java.net.URISyntaxException; |
|
9 |
|
10 import org.chromium.debug.core.ChromiumDebugPlugin; |
|
11 import org.eclipse.core.filesystem.IFileStore; |
|
12 import org.eclipse.core.filesystem.provider.FileSystem; |
|
13 import org.eclipse.core.runtime.IPath; |
|
14 import org.eclipse.core.runtime.Path; |
|
15 |
|
16 /** |
|
17 * An in-memory filesystem for remote scripts. |
|
18 * The supported URLs are {@code chromiumdebug:///resource_path}. |
|
19 */ |
|
20 public class ChromiumScriptFileSystem extends FileSystem { |
|
21 |
|
22 /** All file URLs in this filesystem have this scheme. */ |
|
23 private static final String CHROMIUMDEBUG_SCHEME = "chromiumdebug"; //$NON-NLS-1$ |
|
24 |
|
25 @Override |
|
26 public IFileStore getStore(URI uri) { |
|
27 return new ChromiumScriptFileStore(this, toPath(uri)); |
|
28 } |
|
29 |
|
30 /** |
|
31 * Constructs a URI by a path. |
|
32 * |
|
33 * @param path of a filesystem resource |
|
34 * @return a URI corresponding to the given {@code path} |
|
35 */ |
|
36 public static URI getFileStoreUri(IPath path) { |
|
37 try { |
|
38 return new URI(CHROMIUMDEBUG_SCHEME, null, path.toPortableString(), null); |
|
39 } catch (URISyntaxException e) { |
|
40 ChromiumDebugPlugin.log(e); |
|
41 return null; |
|
42 } |
|
43 } |
|
44 |
|
45 /** |
|
46 * Converts a chromiumdebug FS FileStore URI into a path relative to the FS root. |
|
47 * |
|
48 * @param uri to convert |
|
49 * @return the path corresponding to the uri |
|
50 */ |
|
51 static IPath toPath(URI uri) { |
|
52 return Path.fromPortableString(uri.getPath()).setDevice(null); |
|
53 } |
|
54 |
|
55 /** |
|
56 * Converts a chromiumdebug FS FileStore path into a FS URI. |
|
57 * |
|
58 * @param path to convert |
|
59 * @return the URI corresponding to the given path |
|
60 */ |
|
61 static URI toUri(IPath path) { |
|
62 try { |
|
63 return new URI(CHROMIUMDEBUG_SCHEME, null, path.toPortableString(), null); |
|
64 } catch (URISyntaxException e) { |
|
65 return null; |
|
66 } |
|
67 } |
|
68 |
|
69 } |