-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginProjectHelper.xtend
107 lines (97 loc) · 3.44 KB
/
PluginProjectHelper.xtend
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
package org.eclipse.emf.parsley.dsl.tests.util.ui
import com.google.inject.Inject
import java.io.File
import java.io.FileFilter
import java.io.FileNotFoundException
import java.util.List
import org.eclipse.core.resources.IMarker
import org.eclipse.core.resources.IProject
import org.eclipse.core.resources.IResource
import org.eclipse.core.runtime.NullProgressMonitor
import org.eclipse.emf.parsley.dsl.additional.builder.builder.EmfParsleyDslPluginXmlBuilder
import org.eclipse.emf.parsley.dsl.additional.builder.builder.EmfParsleyDslPluginXmlNature
import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.JavaCore
import org.eclipse.xtext.junit4.ui.util.JavaProjectSetupUtil
import org.eclipse.xtext.ui.XtextProjectHelper
import org.eclipse.xtext.ui.util.PluginProjectFactory
import static org.eclipse.xtext.junit4.ui.util.IResourcesSetupUtil.*
import static org.junit.Assert.*
/**
* Utility class for creating a Plug-in project for testing.
*
* @author Lorenzo Bettini - Initial contribution and API
*
*/
class PluginProjectHelper {
@Inject PluginProjectFactory projectFactory
def IProject createSimpleProject(String projectName) {
projectFactory.setProjectName(projectName);
projectFactory.addFolders(newArrayList("src"));
projectFactory.addBuilderIds(
EmfParsleyDslPluginXmlBuilder.BUILDER_ID);
projectFactory.addProjectNatures(
EmfParsleyDslPluginXmlNature.NATURE_ID
);
projectFactory.createProject(new NullProgressMonitor(), null);
}
def IJavaProject createJavaPluginProject(String projectName, List<String> requiredBundles) {
projectFactory.setProjectName(projectName);
projectFactory.addFolders(newArrayList("src"));
projectFactory.addBuilderIds(
JavaCore.BUILDER_ID,
"org.eclipse.pde.ManifestBuilder",
"org.eclipse.pde.SchemaBuilder",
XtextProjectHelper.BUILDER_ID);
projectFactory.addProjectNatures(
JavaCore.NATURE_ID,
"org.eclipse.pde.PluginNature",
XtextProjectHelper.NATURE_ID
);
projectFactory.addRequiredBundles(requiredBundles);
val result = projectFactory.createProject(new NullProgressMonitor(), null);
JavaProjectSetupUtil.makeJava5Compliant(JavaCore.create(result));
return JavaProjectSetupUtil.findJavaProject(projectName);
}
def assertNoErrors() {
val markers = root.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE).
filter[
getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR
]
assertEquals(
"unexpected errors:\n" +
markers.map[getAttribute(IMarker.LOCATION) +
", " + getAttribute(IMarker.MESSAGE)].join("\n"),
0,
markers.size
)
}
def void clearJdtIndex() {
val jdtMetadata = JavaCore.getPlugin().getStateLocation().toFile();
var success = false;
try {
cleanFolder(jdtMetadata);
success = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.err.println("Clean up index " + jdtMetadata.getAbsolutePath() + ": " + success);
}
def void cleanFolder(File parentFolder) throws FileNotFoundException {
cleanFolder(parentFolder, [true]);
}
def void cleanFolder(File parentFolder, FileFilter myFilter) throws FileNotFoundException {
if (!parentFolder.exists()) {
throw new FileNotFoundException(parentFolder.getAbsolutePath());
}
val File[] contents = parentFolder.listFiles(myFilter);
for (var j = 0; j < contents.length; j++) {
val File file = contents.get(j);
if (file.isDirectory()) {
cleanFolder(file, myFilter);
} else {
file.delete();
}
}
}
}