33import java .io .File ;
44import java .io .IOException ;
55import java .net .URISyntaxException ;
6- import java .net . URL ;
6+ import java .nio . file . Path ;
77import java .nio .file .Paths ;
88
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 ;
1211import org .eclipse .core .resources .ResourcesPlugin ;
1312import 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 ;
1713import org .eclipse .swtbot .eclipse .finder .SWTWorkbenchBot ;
1814import 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 ;
2115import org .eclipse .swtbot .swt .finder .widgets .SWTBotMenu ;
22- import org .eclipse .swtbot .swt .finder .widgets .SWTBotShell ;
2316import org .eclipse .swtbot .swt .finder .widgets .SWTBotTreeItem ;
24- import org .eclipse .ui .PlatformUI ;
2517import org .junit .BeforeClass ;
2618import org .junit .Rule ;
2719import org .junit .Test ;
2820import org .junit .rules .ExpectedException ;
29- import org .osgi .framework .Bundle ;
3021
3122import static org .hamcrest .MatcherAssert .assertThat ;
3223import static org .hamcrest .Matchers .containsString ;
3829public class PluginTest {
3930
4031 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..." ;
4532 private static final String ADD_NATURE_MENU = "Add CodeChecker Nature" ;
4633
4734 private static SWTWorkbenchBot bot ;
@@ -51,56 +38,30 @@ public class PluginTest {
5138
5239 /**
5340 * Import cpp project into workspace, and setup SWTBot.
54- *
5541 */
5642 @ BeforeClass
5743 public static void setup () {
5844
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 ;
6348 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 ();
6953 }
70- assertThat ( "File not exists." , file . exists ());
71- Utils .copyFolder (file . toPath () ,
54+
55+ Utils .copyFolder (file ,
7256 Paths .get (ResourcesPlugin .getWorkspace ().getRoot ().getLocation ().toOSString () + File .separator ));
7357
7458 File project = new File (ResourcesPlugin .getWorkspace ().getRoot ().getLocation ().toOSString () + File .separator
7559 + CPP_PROJ + File .separator + ".project" );
7660 try {
77- importProject (project , CPP_PROJ );
61+ ProjectImporter . importProject (project . toPath () , CPP_PROJ );
7862 } catch (CoreException e1 ) {
7963 e1 .printStackTrace ();
8064 }
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-
10465 }
10566
10667 /**
@@ -121,37 +82,4 @@ public void testAddNatureDisappears() {
12182 thrown .expectMessage (containsString ("Could not find" ));
12283 project .contextMenu (ADD_NATURE_MENU );
12384 }
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