01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.tests.harness.util;
11:
12: import java.io.ByteArrayInputStream;
13: import java.io.InputStream;
14:
15: import org.eclipse.core.resources.IFile;
16: import org.eclipse.core.resources.IProject;
17: import org.eclipse.core.resources.IWorkspace;
18: import org.eclipse.core.resources.IWorkspaceRoot;
19: import org.eclipse.core.resources.ResourcesPlugin;
20: import org.eclipse.core.runtime.CoreException;
21:
22: /**
23: * <code>FileUtil</code> contains methods to create and
24: * delete files and projects.
25: */
26: public class FileUtil {
27:
28: /**
29: * Creates a new project.
30: *
31: * @param name the project name
32: */
33: public static IProject createProject(String name)
34: throws CoreException {
35: IWorkspace ws = ResourcesPlugin.getWorkspace();
36: IWorkspaceRoot root = ws.getRoot();
37: IProject proj = root.getProject(name);
38: if (!proj.exists())
39: proj.create(null);
40: if (!proj.isOpen())
41: proj.open(null);
42: return proj;
43: }
44:
45: /**
46: * Deletes a project.
47: *
48: * @param proj the project
49: */
50: public static void deleteProject(IProject proj)
51: throws CoreException {
52: proj.delete(true, null);
53: }
54:
55: /**
56: * Creates a new file in a project.
57: *
58: * @param name the new file name
59: * @param proj the existing project
60: * @return the new file
61: */
62: public static IFile createFile(String name, IProject proj)
63: throws CoreException {
64: IFile file = proj.getFile(name);
65: if (!file.exists()) {
66: String str = " ";
67: InputStream in = new ByteArrayInputStream(str.getBytes());
68: file.create(in, true, null);
69: }
70: return file;
71: }
72:
73: }
|