Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-dev] How to programmatically uncheck "Create module-info.java" in NewJavaProjectWizardPageOne?

I did not want to clone our wizard class embedding
NewJavaProjectWizardPageOne just for the test. What I ended up doing was
to reflectively get access to

  SelectionButtonDialogField fCreateModuleInfo

and instead of calling only

  fCreateModuleInfo.setSelection(false);

like before, now calling

  fCreateModuleInfo.setEnabled(true);
  fCreateModuleInfo.setSelection(false);

This fixes the problem without further need for wait loops or SWT mouse
click emulations. It seems that setting the selection without enabling
the field first was not enough. Usually, that input field should be
active when using JDK 9+, but for some reason it is not - at least not
at the time I am trying to access it.

I am very grateful for the valuable input from both you and Läubi.

If anyone ever considers refactoring AJDT including its test suite, I
think that SWTBot or RedDeer are the ways to go for UI tests. Can anyone
comment on those two frameworks with regard to questions like:
  -- Are they both actively maintained?
  -- Which target audiences do they serve?
  -- Does one deprecate the other? iIf not, why are there two UI test
     frameworks?

-- 
Alexander Kriegisch


Martin D'Aloia schrieb am 09.02.2022 19:25 (GMT +07:00):
> 
> 
> What worked for us was extend NewJavaProjectWizardPageOne and override
> getCreateModuleInfoFile() like:
> 
> 
> @Override
> public boolean getCreateModuleInfoFile() {
> // Avoids the display of the Dialog to decide to create or not the
> module-info.java file.
> return false;
> }
> 
> 
> but we use that extended page in another custom Wizard so maybe it is not
> directly useful for you.
> 
> 
> On Tue, Feb 8, 2022 at 10:56 PM Alexander Kriegisch
> <alexander@xxxxxxxxxxxxxx <mailto:alexander@xxxxxxxxxxxxxx>
> > wrote:
> 
>> The "new Java project" wizard contains class
>> NewJavaProjectWizardPageOne. In commit [1], a new checkbox "Create
>> module-info.java" was added by Kalyan Prasad Tatavarthi. This causes
>> some trouble in an AspectJ UI test which basically creates a few
>> projects and verifies something. In doing so, it also sets a few field
>> values via reflection, because the necessary fields and methods are
>> private. This is ugly, but it works and is better than copy-pasting the
>> whole class in order to create a 95% duplicate with some accessible
>> members.
>> 
>> In our use case, we want to explicitly uncheck the checkbox, because we
>> do not want to create a modular project. We also want to avoid the
>> asynchronous pop-up dialogue asking for the module name. Even though
>> executing the reflective equivalent of
>> 
>> fFirstPage.fModuleGroup.fCreateModuleInfo.setSelection(false);
>> 
>> in the wizard extension used for our test before calling
>> 'super.finishPressed()', the pop-up appears and makes the whole test
>> suite time out. I tried waiting for 1 up to 10 seconds both before and
>> after setting the value, which helps on my local Windows workstation but
>> still seems to be not enough in a GitHub workflow running the same test.
>> I also tried the reflective equivalent of
>> 
>> fFirstPage.fModuleGroup.fCreateModuleInfo.setSelection(false);
>> fFirstPage.fModuleGroup.savePreference = true;
>> 
>> to no avail. Actually, I am just trying to fix an old test which works
>> nicely on Linux and MacOS (maybe by chance). I have no experience
>> whatsoever with Eclipse UI programming (JFace, SWT) and would welcome
>> hints about how to reliably and without ugly wait loops uncheck that box
>> before clicking "Finish" right from wizard page 1.
>> 
>> [1]
>> https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java?id=39b14df0a8be80c7fbc8f9cddab4bf1217626fda
>> 
>> --
>> Alexander Kriegisch
>> https://scrum-master.de
>> _______________________________________________
>> jdt-dev mailing list
>> jdt-dev@xxxxxxxxxxx <mailto:jdt-dev@xxxxxxxxxxx> 
>> To unsubscribe from this list, visit
>> https://www.eclipse.org/mailman/listinfo/jdt-dev
> 



Back to the top