author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 07 Jun 2010 16:51:19 -0700 | |
changeset 355 | 8726e95bcbba |
parent 276 | f2f4a1259de8 |
permissions | -rw-r--r-- |
2 | 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.util; |
|
6 |
||
7 |
import java.io.ByteArrayInputStream; |
|
8 |
import java.io.File; |
|
9 |
import java.net.URI; |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
10 |
import java.util.ArrayList; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
11 |
import java.util.Arrays; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
12 |
import java.util.HashSet; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
13 |
import java.util.List; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
14 |
import java.util.Set; |
2 | 15 |
|
16 |
import org.chromium.debug.core.ChromiumDebugPlugin; |
|
17 |
import org.chromium.debug.core.efs.ChromiumScriptFileSystem; |
|
18 |
import org.eclipse.core.filesystem.EFS; |
|
19 |
import org.eclipse.core.filesystem.IFileStore; |
|
20 |
import org.eclipse.core.resources.IContainer; |
|
21 |
import org.eclipse.core.resources.IFile; |
|
22 |
import org.eclipse.core.resources.IProject; |
|
23 |
import org.eclipse.core.resources.IProjectDescription; |
|
24 |
import org.eclipse.core.resources.IWorkspace; |
|
25 |
import org.eclipse.core.resources.ResourceAttributes; |
|
26 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
27 |
import org.eclipse.core.runtime.CoreException; |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
28 |
import org.eclipse.core.runtime.IPath; |
2 | 29 |
import org.eclipse.core.runtime.IProgressMonitor; |
30 |
import org.eclipse.core.runtime.IStatus; |
|
31 |
import org.eclipse.core.runtime.Status; |
|
32 |
import org.eclipse.core.runtime.jobs.Job; |
|
33 |
import org.eclipse.swt.widgets.Display; |
|
34 |
import org.eclipse.ui.IWorkbench; |
|
35 |
import org.eclipse.ui.IWorkbenchWindow; |
|
36 |
import org.eclipse.ui.PartInitException; |
|
37 |
import org.eclipse.ui.PlatformUI; |
|
38 |
||
39 |
/** |
|
40 |
* A utility for interaction with the Eclipse workspace. |
|
41 |
*/ |
|
42 |
public class ChromiumDebugPluginUtil { |
|
43 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
44 |
private static final String CHROMIUM_EXTENSION = "chromium"; //$NON-NLS-1$ |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
45 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
46 |
public static final Set<String> SUPPORTED_EXTENSIONS = |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
47 |
new HashSet<String>(Arrays.asList(CHROMIUM_EXTENSION, "js", //$NON-NLS-1$ |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
48 |
"html", "htm")); //$NON-NLS-1$ //$NON-NLS-2$ |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
49 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
50 |
public static final List<String> SUPPORTED_EXTENSIONS_SUFFIX_LIST; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
51 |
static { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
52 |
SUPPORTED_EXTENSIONS_SUFFIX_LIST = new ArrayList<String>(SUPPORTED_EXTENSIONS.size()); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
53 |
for (String extension : SUPPORTED_EXTENSIONS) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
54 |
SUPPORTED_EXTENSIONS_SUFFIX_LIST.add("." + extension); //$NON-NLS-1$ |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
55 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
56 |
} |
2 | 57 |
|
58 |
public static final String JS_DEBUG_PROJECT_NATURE = "org.chromium.debug.core.jsnature"; //$NON-NLS-1$ |
|
59 |
||
60 |
public static final String CHROMIUM_EXTENSION_SUFFIX = "." + CHROMIUM_EXTENSION; //$NON-NLS-1$ |
|
61 |
||
62 |
private static final String PROJECT_EXPLORER_ID = "org.eclipse.ui.navigator.ProjectExplorer"; //$NON-NLS-1$ |
|
63 |
||
64 |
/** |
|
65 |
* Brings up the "Project Explorer" view in the active workbench window. |
|
66 |
*/ |
|
67 |
public static void openProjectExplorerView() { |
|
68 |
Display.getDefault().asyncExec(new Runnable() { |
|
69 |
public void run() { |
|
70 |
IWorkbench workbench = PlatformUI.getWorkbench(); |
|
71 |
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); |
|
72 |
if (window == null) { |
|
73 |
if (workbench.getWorkbenchWindowCount() == 1) { |
|
74 |
window = workbench.getWorkbenchWindows()[0]; |
|
75 |
} |
|
76 |
} |
|
77 |
if (window != null) { |
|
78 |
try { |
|
79 |
window.getActivePage().showView(PROJECT_EXPLORER_ID); |
|
80 |
} catch (PartInitException e) { |
|
81 |
// ignore |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
}); |
|
86 |
} |
|
87 |
||
88 |
/** |
|
89 |
* Creates an empty workspace project with the name starting with the given projectNameBase. |
|
90 |
* Created project is guaranteed to be new in EFS, but workspace may happen to |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
91 |
* already have project with such url (left uncleaned from previous runs). Such project |
2 | 92 |
* silently gets deleted. |
93 |
* @param projectNameBase project name template |
|
94 |
* @return the newly created project, or {@code null} if the creation failed |
|
95 |
*/ |
|
96 |
public static IProject createEmptyProject(String projectNameBase) { |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
97 |
ProjectCheckData projectProject; |
2 | 98 |
try { |
99 |
for (int uniqueNumber = 0; ; uniqueNumber++) { |
|
100 |
String projectNameTry; |
|
101 |
if (uniqueNumber == 0) { |
|
102 |
projectNameTry = projectNameBase; |
|
103 |
} else { |
|
104 |
projectNameTry = projectNameBase + " (" + uniqueNumber + ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
|
105 |
} |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
106 |
projectProject = checkProjectName(projectNameTry); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
107 |
if (projectProject != null) { |
2 | 108 |
break; |
109 |
} |
|
110 |
} |
|
111 |
} catch (CoreException e) { |
|
112 |
ChromiumDebugPlugin.log(e); |
|
113 |
return null; |
|
114 |
} |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
115 |
IProject project = projectProject.getProject(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
116 |
if (project.exists()) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
117 |
try { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
118 |
project.delete(true, null); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
119 |
} catch (CoreException e) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
120 |
ChromiumDebugPlugin.log(e); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
121 |
return null; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
122 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
123 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
124 |
|
2 | 125 |
IProjectDescription description = |
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
126 |
ResourcesPlugin.getWorkspace().newProjectDescription(project.getName()); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
127 |
description.setLocationURI(projectProject.getProjectUri()); |
2 | 128 |
description.setNatureIds(new String[] { JS_DEBUG_PROJECT_NATURE }); |
129 |
try { |
|
130 |
||
131 |
project.create(description, null); |
|
132 |
project.open(null); |
|
133 |
||
134 |
return project; |
|
135 |
} catch (CoreException e) { |
|
136 |
ChromiumDebugPlugin.log(e); |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
137 |
return null; |
2 | 138 |
} |
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
139 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
140 |
|
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
141 |
private interface ProjectCheckData { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
142 |
IProject getProject(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
143 |
URI getProjectUri(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
144 |
} |
2 | 145 |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
146 |
/** |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
147 |
* Checks whether debug virtual project can be created. |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
148 |
* @param projectNameTry desired project name |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
149 |
* @return project project with parameters data or null if project with desired name cannot be |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
150 |
* created |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
151 |
*/ |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
152 |
private static ProjectCheckData checkProjectName(String projectNameTry) throws CoreException { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
153 |
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectNameTry); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
154 |
if (project.exists()) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
155 |
URI projectURI = project.getLocationURI(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
156 |
if (!ChromiumScriptFileSystem.isChromiumDebugURI(projectURI)) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
157 |
// This is not our project. Do not touch it. |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
158 |
return null; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
159 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
160 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
161 |
IPath newPath = project.getFullPath(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
162 |
final URI projectUriTry = ChromiumScriptFileSystem.getFileStoreUri(newPath); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
163 |
IFileStore projectStore = EFS.getStore(projectUriTry); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
164 |
if (projectStore.fetchInfo().exists()) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
165 |
return null; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
166 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
167 |
return new ProjectCheckData() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
168 |
public IProject getProject() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
169 |
return project; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
170 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
171 |
public URI getProjectUri() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
172 |
return projectUriTry; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
173 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
174 |
}; |
2 | 175 |
} |
176 |
||
177 |
||
178 |
/** |
|
179 |
* Removes virtual project which was created for debug session. Does its job |
|
180 |
* asynchronously. |
|
181 |
*/ |
|
182 |
public static void deleteVirtualProjectAsync(final IProject debugProject) { |
|
183 |
Job job = new Job("Remove virtual project") { |
|
184 |
@Override |
|
185 |
protected IStatus run(IProgressMonitor monitor) { |
|
186 |
URI projectUri = debugProject.getLocationURI(); |
|
187 |
try { |
|
188 |
IFileStore projectStore = EFS.getStore(projectUri); |
|
189 |
if (projectStore.fetchInfo().exists()) { |
|
190 |
projectStore.delete(EFS.NONE, null); |
|
191 |
} |
|
192 |
debugProject.delete(true, null); |
|
193 |
} catch (CoreException e) { |
|
194 |
ChromiumDebugPlugin.log(e); |
|
195 |
return new Status(IStatus.ERROR, ChromiumDebugPlugin.PLUGIN_ID, |
|
196 |
"Failed to delete virtual project"); |
|
197 |
} |
|
198 |
return Status.OK_STATUS; |
|
199 |
} |
|
200 |
}; |
|
201 |
||
202 |
job.schedule(); |
|
203 |
} |
|
204 |
||
205 |
/** |
|
206 |
* @param projectName to check for existence |
|
207 |
* @return whether the project named projectName exists. |
|
208 |
*/ |
|
209 |
public static boolean projectExists(String projectName) { |
|
210 |
IWorkspace ws = ResourcesPlugin.getWorkspace(); |
|
211 |
IProject proj = ws.getRoot().getProject(projectName); |
|
212 |
return proj.exists(); |
|
213 |
} |
|
214 |
||
215 |
/** |
|
216 |
* Creates an empty file with the given filename in the given project. |
|
217 |
* |
|
218 |
* @param project to create the file in |
|
219 |
* @param filename the base file name to create (will be sanitized for |
|
220 |
* illegal chars and, in the case of a name clash, suffixed with "(N)") |
|
221 |
* @return the result of IFile.getName(), or {@code null} if the creation |
|
222 |
* has failed |
|
223 |
*/ |
|
224 |
public static IFile createFile(IProject project, String filename) { |
|
225 |
String patchedName = new File(filename).getName().replace('?', '_'); // simple name |
|
226 |
String uniqueName = patchedName; |
|
227 |
||
228 |
// TODO(apavlov): refactor this? |
|
229 |
for (int i = 1; i < 1000; ++i) { |
|
230 |
String filePathname = uniqueName + CHROMIUM_EXTENSION_SUFFIX; |
|
231 |
IFile file = project.getFile(filePathname); |
|
232 |
||
233 |
if (file.exists()) { |
|
234 |
uniqueName = new StringBuilder(patchedName) |
|
235 |
.append(" (") //$NON-NLS-1$ |
|
236 |
.append(i) |
|
237 |
.append(')') |
|
238 |
.toString(); |
|
239 |
} else { |
|
240 |
try { |
|
241 |
file.create(new ByteArrayInputStream("".getBytes()), false, null); //$NON-NLS-1$ |
|
242 |
} catch (CoreException e) { |
|
243 |
ChromiumDebugPlugin.log(e); |
|
244 |
return null; |
|
245 |
} |
|
246 |
return file; |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
// Can we have 1000 same-named files? |
|
251 |
return null; |
|
252 |
} |
|
253 |
||
254 |
/** |
|
255 |
* Writes data into a resource with the given resourceName residing in the |
|
256 |
* source folder of the given project. The previous file content is lost. |
|
257 |
* Temporarily resets the "read-only" file attribute if one is present. |
|
258 |
* |
|
259 |
* @param file to set contents for |
|
260 |
* @param data to write into the file |
|
261 |
* @throws CoreException |
|
262 |
*/ |
|
263 |
public static void writeFile(IFile file, String data) throws CoreException { |
|
264 |
if (file != null && file.exists()) { |
|
265 |
ResourceAttributes resourceAttributes = file.getResourceAttributes(); |
|
266 |
if (resourceAttributes.isReadOnly()) { |
|
267 |
resourceAttributes.setReadOnly(false); |
|
268 |
file.setResourceAttributes(resourceAttributes); |
|
269 |
} |
|
270 |
file.setContents(new ByteArrayInputStream(data.getBytes()), IFile.FORCE, null); |
|
271 |
resourceAttributes.setReadOnly(true); |
|
272 |
file.setResourceAttributes(resourceAttributes); |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
public static boolean isInteger(String value) { |
|
277 |
try { |
|
278 |
Integer.parseInt(value); |
|
279 |
return true; |
|
280 |
} catch (NumberFormatException e) { |
|
281 |
return false; |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
/** |
|
286 |
* The container where the script sources should be put. |
|
287 |
* |
|
288 |
* @param project where the launch configuration stores the scripts |
|
289 |
* @return the script source container |
|
290 |
*/ |
|
291 |
public static IContainer getSourceContainer(IProject project) { |
|
292 |
return project; |
|
293 |
} |
|
294 |
||
295 |
private ChromiumDebugPluginUtil() { |
|
296 |
// not instantiable |
|
297 |
} |
|
298 |
} |