Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b0ad81daaad8f584f2cb3a9a1e9c4b60f9f8307f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*******************************************************************************
 * Copyright (c) 2008, 2018 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.tests.launching;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.provider.FileSystem;
import org.eclipse.core.runtime.Path;

/**
 * A simple in memory file system to test launch configurations in EFS
 */
public class DebugFileSystem extends FileSystem {

	/**
	 * represents a directory
	 */
	public static final byte[] DIRECTORY_BYTES = new byte[] {1, 2, 3, 4};

	private static DebugFileSystem system;

	/**
	 * Keys URIs to file stores for existing files
	 */
	private final Map<URI, byte[]> files = new HashMap<>();

	/**
	 * Constructs the singleton
	 */
	public DebugFileSystem() {
		system = this;
		// create root of the file system
		try {
			setContents(new URI("debug", Path.ROOT.toString(), null), DIRECTORY_BYTES); //$NON-NLS-1$
		} catch (URISyntaxException e) {}
	}

	/**
	 * Returns the Debug files system.
	 *
	 * @return file system
	 */
	static DebugFileSystem getDefault() {
		return system;
	}

	@Override
	public IFileStore getStore(URI uri) {
		return new DebugFileStore(uri);
	}

	@Override
	public boolean canDelete() {
		return true;
	}

	@Override
	public boolean canWrite() {
		return true;
	}

	/**
	 * Returns whether contents of the file or <code>null</code> if none.
	 *
	 * @param uri
	 * @return bytes or <code>null</code>
	 */
	public byte[] getContents(URI uri) {
		return files.get(uri);
	}

	/**
	 * Deletes the file.
	 *
	 * @param uri
	 */
	public void delete(URI uri) {
		files.remove(uri);
	}

	/**
	 * Sets the content of the given file.
	 *
	 * @param uri
	 * @param bytes
	 */
	public void setContents(URI uri, byte[] bytes) {
		files.put(uri, bytes);
	}

	/**
	 * Returns URIs of all existing files.
	 *
	 * @return
	 */
	public URI[] getFileURIs() {
		return files.keySet().toArray(new URI[files.size()]);
	}

}

Back to the top