-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathWorkingProject.java
More file actions
82 lines (62 loc) · 2.41 KB
/
WorkingProject.java
File metadata and controls
82 lines (62 loc) · 2.41 KB
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
package domain;
import java.io.ByteArrayInputStream;
import java.net.URI;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import code2code.utils.FileUtils;
public class WorkingProject {
private static IProject project;
public static IProject create() throws Exception{
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String projectName = "code2code.TestProject";
project = root.getProject(projectName);
int index = 0;
while(project.exists()){
project = root.getProject(projectName + "_" + (++index));
}
project.create(null);
project.open(null);
return project;
}
public static void copyGenerator(String generator) throws Exception {
URI example = FileLocator.resolve(Platform.getBundle("code2code.tests")
.getResource(Fixtures.exampleGeneratorDir(generator))).toURI();
URI destination = project.getProject().getFolder("generators").getFolder(generator + ".generator").getLocationURI();
IFileStore sourceStore = EFS.getStore(example);
IFileStore destinationStore = EFS.getStore(destination);
sourceStore.copy(destinationStore, 0, null);
project.getProject().getFolder("generators").refreshLocal(IResource.DEPTH_INFINITE, null);
}
public static IProject project() {
return project;
}
public static void delete() throws Exception {
if(project != null){
project.delete(true, true, null);
}
}
public static void createFolder(String folderName) throws Exception {
FileUtils.createFolderWithParents(project.getFolder(folderName));
}
public static void createFileWithContents(String filePath, String content) throws Exception {
IFile file = project.getFile(filePath);
FileUtils.createParentFolders(file);
file.create(new ByteArrayInputStream(content.getBytes()) , true, null);
}
public static void createFile(String filePath) throws Exception {
createFileWithContents(filePath, "");
}
public static boolean fileExists(String file) {
return project.getFile(file).exists();
}
public static String read(String file) throws Exception {
return FileUtils.read(project.getFile(file).getContents());
}
}