3
3
import java .io .File ;
4
4
import java .io .IOException ;
5
5
import java .net .URISyntaxException ;
6
- import java .net . URL ;
6
+ import java .nio . file . Path ;
7
7
import java .nio .file .Paths ;
8
8
9
- import org .codechecker .eclipse .plugin .utils .Utils ;
10
- import org .eclipse .core .resources .IProject ;
11
- import org .eclipse .core .resources .IProjectDescription ;
9
+ import org .codechecker .eclipse .plugin .utils .ProjectImporter ;
10
+ import org .codechecker .eclipse .rcp .shared .utils .Utils ;
12
11
import org .eclipse .core .resources .ResourcesPlugin ;
13
12
import org .eclipse .core .runtime .CoreException ;
14
- import org .eclipse .core .runtime .FileLocator ;
15
- import org .eclipse .core .runtime .Path ;
16
- import org .eclipse .core .runtime .Platform ;
17
13
import org .eclipse .swtbot .eclipse .finder .SWTWorkbenchBot ;
18
14
import org .eclipse .swtbot .swt .finder .exceptions .WidgetNotFoundException ;
19
- import org .eclipse .swtbot .swt .finder .finders .UIThreadRunnable ;
20
- import org .eclipse .swtbot .swt .finder .results .VoidResult ;
21
15
import org .eclipse .swtbot .swt .finder .widgets .SWTBotMenu ;
22
- import org .eclipse .swtbot .swt .finder .widgets .SWTBotShell ;
23
16
import org .eclipse .swtbot .swt .finder .widgets .SWTBotTreeItem ;
24
- import org .eclipse .ui .PlatformUI ;
25
17
import org .junit .BeforeClass ;
26
18
import org .junit .Rule ;
27
19
import org .junit .Test ;
28
20
import org .junit .rules .ExpectedException ;
29
- import org .osgi .framework .Bundle ;
30
21
31
22
import static org .hamcrest .MatcherAssert .assertThat ;
32
23
import static org .hamcrest .Matchers .containsString ;
38
29
public class PluginTest {
39
30
40
31
private static final String CPP_PROJ = "cppTest" ;
41
- private static final String WINDOW_MENU = "Window" ;
42
- private static final String PERSP_MENU = "Perspective" ;
43
- private static final String OPEN_PERSP = "Open Perspective" ;
44
- private static final String OTHER_MENU = "Other..." ;
45
32
private static final String ADD_NATURE_MENU = "Add CodeChecker Nature" ;
46
33
47
34
private static SWTWorkbenchBot bot ;
@@ -51,56 +38,30 @@ public class PluginTest {
51
38
52
39
/**
53
40
* Import cpp project into workspace, and setup SWTBot.
54
- *
55
41
*/
56
42
@ BeforeClass
57
43
public static void setup () {
58
44
59
- // http://blog.vogella.com/2010/07/06/reading-resources-from-plugin/
60
- Bundle bundle = Platform .getBundle ("org.codechecker.eclipse.rcp.it.tests" );
61
- URL fileURL = bundle .getEntry ("resources/cppTest" );
62
- File file = null ;
45
+ bot = new SWTWorkbenchBot ();
46
+
47
+ Path file = null ;
63
48
try {
64
- file = new File (FileLocator .resolve (fileURL ).toURI ());
65
- } catch (URISyntaxException e1 ) {
66
- e1 .printStackTrace ();
67
- } catch (IOException e1 ) {
68
- e1 .printStackTrace ();
49
+ file = Utils .loadFileFromBundle ("org.codechecker.eclipse.rcp.it.tests" ,
50
+ Utils .RES + CPP_PROJ );
51
+ } catch (URISyntaxException | IOException e ) {
52
+ e .printStackTrace ();
69
53
}
70
- assertThat ( "File not exists." , file . exists ());
71
- Utils .copyFolder (file . toPath () ,
54
+
55
+ Utils .copyFolder (file ,
72
56
Paths .get (ResourcesPlugin .getWorkspace ().getRoot ().getLocation ().toOSString () + File .separator ));
73
57
74
58
File project = new File (ResourcesPlugin .getWorkspace ().getRoot ().getLocation ().toOSString () + File .separator
75
59
+ CPP_PROJ + File .separator + ".project" );
76
60
try {
77
- importProject (project , CPP_PROJ );
61
+ ProjectImporter . importProject (project . toPath () , CPP_PROJ );
78
62
} catch (CoreException e1 ) {
79
63
e1 .printStackTrace ();
80
64
}
81
-
82
- bot = new SWTWorkbenchBot ();
83
- UIThreadRunnable .syncExec (new VoidResult () {
84
- public void run () {
85
- PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell ().forceActive ();
86
- }
87
- });
88
-
89
- try {
90
- bot .viewByTitle ("Welcome" ).close ();
91
- } catch (WidgetNotFoundException e ) {
92
- System .out .println ("Welcome Screen wasn't present." );
93
- }
94
-
95
- // Change the perspective via the Open Perspective dialog
96
- bot .menu (WINDOW_MENU ).menu (PERSP_MENU ).menu (OPEN_PERSP ).menu (OTHER_MENU ).click ();
97
- SWTBotShell openPerspectiveShell = bot .shell (OPEN_PERSP );
98
- openPerspectiveShell .activate ();
99
-
100
- // select the dialog
101
- bot .table ().select ("C/C++" );
102
- bot .button ("Open" ).click ();
103
-
104
65
}
105
66
106
67
/**
@@ -121,37 +82,4 @@ public void testAddNatureDisappears() {
121
82
thrown .expectMessage (containsString ("Could not find" ));
122
83
project .contextMenu (ADD_NATURE_MENU );
123
84
}
124
-
125
-
126
- /**
127
- * Imports a project into workspace.
128
- * https://www.eclipse.org/forums/index.php/t/560903/
129
- *
130
- * @param projectFile
131
- * The project file to be imported.
132
- * @param projectName
133
- * The project name that will be used to create the project
134
- * @throws CoreException
135
- * Project cannot be created: if this method fails. Reasons include:
136
- * - This project already exists in the workspace. - The name of
137
- * this resource is not valid (according to
138
- * IWorkspace.validateName). - The project location is not valid
139
- * (according to IWorkspace.validateProjectLocation). - The project
140
- * description file could not be created in the project content
141
- * area. - Resource changes are disallowed during certain types of
142
- * resource change event notification. See IResourceChangeEvent for
143
- * more details. .project file has troubles. Reasons include: - The
144
- * project description file does not exist. - The file cannot be
145
- * opened or read. - The file cannot be parsed as a legal project
146
- * description. or during opening - Resource changes are disallowed
147
- * during certain types of resource change event notification. See
148
- * IResourceChangeEvent for more details.
149
- */
150
- private static void importProject (final File projectFile , final String projectName ) throws CoreException {
151
- IProjectDescription description = ResourcesPlugin .getWorkspace ()
152
- .loadProjectDescription (new Path (projectFile .getAbsolutePath ()));
153
- IProject project = ResourcesPlugin .getWorkspace ().getRoot ().getProject (description .getName ());
154
- project .create (description , null );
155
- project .open (null );
156
- }
157
- }
85
+ }
0 commit comments