Skip to content

Commit 1cddd83

Browse files
authored
chore: fix sonar issues (#333)
* chore: fix sonar issues Signed-off-by: Stephane Bouchet <[email protected]>
1 parent 4bb5c14 commit 1cddd83

File tree

34 files changed

+227
-283
lines changed

34 files changed

+227
-283
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131

3232
run_on_linux:
3333
runs-on: ubuntu-latest
34+
3435
steps:
3536
- uses: actions/checkout@v4
3637
- name: Set up JDK 11 # Java 11 is only used for test NewProjectDialogTest/setProjectSdkIfAvailableTest
@@ -45,30 +46,10 @@ jobs:
4546
java-version: 17
4647
distribution: 'temurin'
4748
cache: 'gradle'
48-
- name: Run mainidewindow_idestatusbar_screenshot integration tests
49-
run: |
50-
cd src/test-project
51-
xvfb-run --server-args="-screen 0 1920x1080x24" ./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.utils.* --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.idestatusbar.*
52-
- name: Run dialogs_information_settings integration tests
53-
run: |
54-
cd src/test-project
55-
xvfb-run --server-args="-screen 0 1920x1080x24" ./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.information.* --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.settings.*
56-
- name: Run dialogs_project_manipulation integration tests
57-
run: |
58-
cd src/test-project
59-
xvfb-run --server-args="-screen 0 1920x1080x24" ./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.project_manipulation.*
60-
- name: Run dialogs integration tests
61-
run: |
62-
cd src/test-project
63-
xvfb-run --server-args="-screen 0 1920x1080x24" ./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.FlatWelcomeFrameTest
64-
- name: Run mainidewindow-menubar integration tests
65-
run: |
66-
cd src/test-project
67-
xvfb-run --server-args="-screen 0 1920x1080x24" ./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.menubar.*
68-
- name: Run mainidewindow-toolwindowspane integration tests
49+
- name: Run integration tests
6950
run: |
7051
cd src/test-project
71-
xvfb-run --server-args="-screen 0 1920x1080x24" ./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.toolwindowspane.*
52+
xvfb-run --server-args="-screen 0 1920x1080x24" ./gradlew integrationUITest --warning-mode none
7253
- name: Archiving tests reports
7354
uses: actions/upload-artifact@v4
7455
with:
@@ -113,30 +94,10 @@ jobs:
11394
java-version: 17
11495
distribution: 'temurin'
11596
cache: 'gradle'
116-
- name: Run mainidewindow_idestatusbar_screenshot integration tests
117-
run: |
118-
cd src/test-project
119-
./gradlew.bat integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.utils.* --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.idestatusbar.*
120-
- name: Run dialogs_information_settings integration tests
121-
run: |
122-
cd src/test-project
123-
./gradlew.bat integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.information.* --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.settings.*
124-
- name: Run dialogs_project_manipulation integration tests
97+
- name: Run integration tests
12598
run: |
12699
cd src/test-project
127-
./gradlew.bat integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.project_manipulation.*
128-
- name: Run dialogs integration tests
129-
run: |
130-
cd src/test-project
131-
./gradlew.bat integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.FlatWelcomeFrameTest
132-
- name: Run mainidewindow-menubar integration tests
133-
run: |
134-
cd src/test-project
135-
./gradlew.bat integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.menubar.*
136-
- name: Run mainidewindow-toolwindowspane integration tests
137-
run: |
138-
cd src/test-project
139-
./gradlew.bat integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.toolwindowspane.*
100+
./gradlew.bat integrationUITest --warning-mode none
140101
- name: Archiving tests reports
141102
uses: actions/upload-artifact@v4
142103
with:
@@ -173,30 +134,10 @@ jobs:
173134
java-version: 17
174135
distribution: 'temurin'
175136
cache: 'gradle'
176-
- name: Run mainidewindow_idestatusbar_screenshot integration tests
177-
run: |
178-
cd src/test-project
179-
./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.utils.* --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.idestatusbar.*
180-
- name: Run dialogs_information_settings integration tests
181-
run: |
182-
cd src/test-project
183-
./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.information.* --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.settings.*
184-
- name: Run dialogs_project_manipulation integration tests
185-
run: |
186-
cd src/test-project
187-
./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.project_manipulation.*
188-
- name: Run dialogs integration tests
189-
run: |
190-
cd src/test-project
191-
./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.dialogs.FlatWelcomeFrameTest
192-
- name: Run mainidewindow-menubar integration tests
193-
run: |
194-
cd src/test-project
195-
./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.menubar.*
196-
- name: Run mainidewindow-toolwindowspane integration tests
137+
- name: Run integration tests
197138
run: |
198139
cd src/test-project
199-
./gradlew integrationUITest --warning-mode none --tests com.redhat.devtools.intellij.commonuitest.fixtures.test.mainidewindow.toolwindowspane.*
140+
./gradlew integrationUITest --warning-mode none
200141
- name: Archiving tests reports
201142
uses: actions/upload-artifact@v4
202143
with:

build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id("java-library")
33
id("maven-publish")
44
alias(libs.plugins.gradleNexusPublishPlugin)
5+
id("jacoco") // Code coverage
56
alias(libs.plugins.sonarqube) // SonarQube
67
}
78

@@ -40,6 +41,14 @@ tasks {
4041
useJUnitPlatform()
4142
}
4243

44+
jacocoTestReport {
45+
executionData.setFrom(fileTree(layout.buildDirectory).include("/jacoco/*.exec"))
46+
//classDirectories.setFrom(instrumentCode)
47+
reports {
48+
xml.required = true
49+
}
50+
}
51+
4352
sonar {
4453
properties {
4554
property("sonar.projectKey", "redhat-developer_intellij-common-ui-test-library")

src/main/java/com/redhat/devtools/intellij/commonuitest/UITestRunner.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
package com.redhat.devtools.intellij.commonuitest;
1212

1313
import com.intellij.remoterobot.RemoteRobot;
14+
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
1415
import com.intellij.remoterobot.stepsProcessing.StepLogger;
1516
import com.intellij.remoterobot.stepsProcessing.StepWorker;
16-
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
1717
import com.redhat.devtools.intellij.commonuitest.exceptions.UITestException;
18-
import com.redhat.devtools.intellij.commonuitest.fixtures.dialogs.FlatWelcomeFrame;
18+
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
1919
import com.redhat.devtools.intellij.commonuitest.utils.runner.IntelliJVersion;
2020

2121
import java.io.File;
@@ -35,6 +35,7 @@
3535

3636
import static com.intellij.remoterobot.stepsProcessing.StepWorkerKt.step;
3737
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor;
38+
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
3839

3940
/**
4041
* Basic methods for starting and quiting the IntelliJ Idea IDE for UI tests
@@ -96,7 +97,6 @@ public static RemoteRobot runIde(IntelliJVersion ideaVersion, int port) {
9697
LOGGER.log(Level.SEVERE, e.getMessage(), e);
9798
}
9899

99-
remoteRobot.find(FlatWelcomeFrame.class, Duration.ofSeconds(10)).clearWorkspace();
100100
return remoteRobot;
101101
});
102102
}
@@ -154,19 +154,7 @@ public static RemoteRobot getRemoteRobot() {
154154
public static RemoteRobot getRemoteRobotConnection(int port) {
155155
return step("Create an instance of the RemoteRobot listening on port " + port, () -> {
156156
RemoteRobot remoteRobot = new RemoteRobot("http://127.0.0.1:" + port);
157-
for (int i = 0; i < 60; i++) {
158-
try {
159-
remoteRobot.find(FlatWelcomeFrame.class);
160-
} catch (WaitForConditionTimeoutException e) {
161-
try {
162-
Thread.sleep(1000);
163-
} catch (InterruptedException e2) {
164-
LOGGER.log(Level.SEVERE, e2.getMessage(), e2);
165-
Thread.currentThread().interrupt();
166-
}
167-
}
168-
}
169-
157+
waitFor(Duration.ofSeconds(30), Duration.ofMillis(500), () -> remoteRobot.find(CommonContainerFixture.class, byXpath(XPathDefinitions.FLAT_WELCOME_FRAME)).isShowing());
170158
return remoteRobot;
171159
});
172160
}
@@ -253,15 +241,15 @@ private static void acceptAllTermsAndConditions() {
253241
}
254242

255243
private static void waitUntilIntelliJStarts(int port) {
256-
waitFor(Duration.ofSeconds(600), Duration.ofSeconds(3), "The IntelliJ Idea did not start in 10 minutes.", () -> isIntelliJUIVisible(port));
244+
waitFor(Duration.ofSeconds(600), Duration.ofSeconds(3), "IntelliJ to start for 10 minutes.", () -> isIntelliJUIVisible(port));
257245
}
258246

259247
private static boolean isIntelliJUIVisible(int port) {
260-
return isHostOnIpAndPortAccessible("127.0.0.1", port);
248+
return isHostOnIpAndPortAccessible(port);
261249
}
262250

263-
private static boolean isHostOnIpAndPortAccessible(String ip, int port) {
264-
SocketAddress sockaddr = new InetSocketAddress(ip, port);
251+
private static boolean isHostOnIpAndPortAccessible(int port) {
252+
SocketAddress sockaddr = new InetSocketAddress("127.0.0.1", port);
265253
try (Socket socket = new Socket()) {
266254
connectToHost(socket, sockaddr);
267255
} catch (IOException e) {

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/FlatWelcomeFrame.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,16 @@ public void openSettingsDialog() {
162162
JTreeFixture jTreeFixture = remoteRobot.find(JTreeFixture.class, byXpath(XPathDefinitions.TREE));
163163
jTreeFixture.findText("Customize").click();
164164
if (remoteRobot.isMac()) {
165-
resizeWelcomeWindow(900);
165+
resizeWelcomeWindow();
166166
}
167167
remoteRobot.find(ContainerFixture.class, byXpath(XPathDefinitions.DIALOG_PANEL)).findText("All settings" + '\u2026').click();
168168
}
169169
}
170170

171171
/**
172172
* Resize the Welcome to IntelliJ IDEA window
173-
*
174-
* @param newHeight Integer of new height to use
175173
*/
176-
private void resizeWelcomeWindow(int newHeight) {
174+
private void resizeWelcomeWindow() {
177175
try {
178176
remoteRobot.callJs(String.format("""
179177
importClass(java.awt.Frame);
@@ -192,7 +190,7 @@ private void resizeWelcomeWindow(int newHeight) {
192190
}
193191
}
194192
resized;
195-
""", newHeight));
193+
""", 900));
196194
Thread.sleep(5000);
197195
} catch (Exception e) {
198196
LOGGER.log(Level.WARNING, "Failed to resize the Welcome window: {0}", e.getMessage());

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/project/pages/NewProjectFirstPage.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.intellij.remoterobot.data.RemoteComponent;
1515
import com.intellij.remoterobot.fixtures.ComboBoxFixture;
1616
import com.intellij.remoterobot.fixtures.CommonContainerFixture;
17-
import com.intellij.remoterobot.fixtures.ContainerFixture;
1817
import com.intellij.remoterobot.fixtures.DefaultXpath;
1918
import com.intellij.remoterobot.fixtures.FixtureName;
2019
import com.intellij.remoterobot.fixtures.HeavyWeightWindowFixture;
@@ -167,10 +166,13 @@ public void setProjectSdkIfAvailable(String targetSdkName) {
167166
String label = foundItems.values().stream().findFirst().get();
168167
projectSdkList.jList().clickItem(label, true);
169168
// wait for 'resolving JDK' progressmonitor to end
169+
// TODO for now don't know what kind of dialog is the 'resolving' so just pausing thread
170170
try {
171171
Thread.sleep(5000);
172172
} catch (InterruptedException e) {
173-
throw new RuntimeException(e);
173+
ScreenshotUtils.takeScreenshot(remoteRobot, "interrupted while waiting for " + targetSdkName);
174+
/* Clean up whatever needs to be handled before interrupting */
175+
Thread.currentThread().interrupt();
174176
}
175177
} else {
176178
ScreenshotUtils.takeScreenshot(remoteRobot, "No SDK found starting with " + targetSdkName);

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/idestatusbar/IdeStatusBar.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616
import com.intellij.remoterobot.fixtures.ComponentFixture;
1717
import com.intellij.remoterobot.fixtures.DefaultXpath;
1818
import com.intellij.remoterobot.fixtures.FixtureName;
19-
import com.intellij.remoterobot.fixtures.dataExtractor.RemoteText;
2019
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
2120
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
2221
import org.jetbrains.annotations.NotNull;
2322

2423
import java.time.Duration;
25-
import java.util.List;
26-
import java.util.logging.Level;
27-
import java.util.logging.Logger;
2824

2925
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
3026
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitFor;
@@ -37,7 +33,6 @@
3733
@DefaultXpath(by = "IdeStatusBarImpl type", xpath = XPathDefinitions.IDE_STATUS_BAR)
3834
@FixtureName(name = "Ide Status Bar")
3935
public class IdeStatusBar extends CommonContainerFixture {
40-
private static final Logger LOGGER = Logger.getLogger(IdeStatusBar.class.getName());
4136
private final RemoteRobot remoteRobot;
4237

4338
public IdeStatusBar(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
@@ -85,20 +80,7 @@ private boolean didProjectImportFinish() {
8580
}
8681

8782
private boolean didAllBgTasksFinish() {
88-
for (int i = 0; i < 5; i++) {
89-
IdeStatusBar ideStatusBar = remoteRobot.find(IdeStatusBar.class);
90-
List<RemoteText> inlineProgressPanelContent = ideStatusBar.inlineProgressPanel().findAllText();
91-
if (!inlineProgressPanelContent.isEmpty()) {
92-
return false;
93-
}
94-
95-
try {
96-
Thread.sleep(1000);
97-
} catch (InterruptedException e) {
98-
LOGGER.log(Level.SEVERE, e.getMessage(), e);
99-
Thread.currentThread().interrupt();
100-
}
101-
}
102-
return true;
83+
waitFor(Duration.ofSeconds(5), Duration.ofMillis(500), () -> remoteRobot.find(IdeStatusBar.class).isShowing());
84+
return remoteRobot.find(IdeStatusBar.class).inlineProgressPanel().findAllText().isEmpty();
10385
}
10486
}

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/AbstractToolWinPane.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ protected AbstractToolWinPane(@NotNull RemoteRobot remoteRobot, @NotNull RemoteC
4343

4444
/**
4545
* Open project explorer
46-
*
47-
* @return the Project Explorer fixture
4846
*/
49-
public ProjectExplorer openProjectExplorer() {
50-
return togglePane(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL, ProjectExplorer.class, true);
47+
public void openProjectExplorer() {
48+
togglePane(ButtonLabels.PROJECT_STRIPE_BUTTON_LABEL, ProjectExplorer.class, true);
5149
}
5250

5351
/**
@@ -59,11 +57,9 @@ public void closeProjectExplorer() {
5957

6058
/**
6159
* Open maven build tool pane
62-
*
63-
* @return the Maven Build Tool Pane fixture
6460
*/
65-
public MavenBuildToolPane openMavenBuildToolPane() {
66-
return togglePane(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL, MavenBuildToolPane.class, true);
61+
public void openMavenBuildToolPane() {
62+
togglePane(ButtonLabels.MAVEN_STRIPE_BUTTON_LABEL, MavenBuildToolPane.class, true);
6763
}
6864

6965
/**
@@ -75,11 +71,9 @@ public void closeMavenBuildToolPane() {
7571

7672
/**
7773
* Open gradle build tool pane
78-
*
79-
* @return the Gradle Build Tool Pane fixture
8074
*/
81-
public GradleBuildToolPane openGradleBuildToolPane() {
82-
return togglePane(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL, GradleBuildToolPane.class, true);
75+
public void openGradleBuildToolPane() {
76+
togglePane(ButtonLabels.GRADLE_STRIPE_BUTTON_LABEL, GradleBuildToolPane.class, true);
8377
}
8478

8579
/**
@@ -111,14 +105,12 @@ public JButtonFixture stripeButton(String label, boolean isPaneOpened) {
111105
return button(byXpath(XPathDefinitions.label(label)), Duration.ofSeconds(2));
112106
}
113107

114-
protected <T extends Fixture> T togglePane(String label, Class<T> fixtureClass, boolean openPane) {
108+
protected void togglePane(String label, Class<? extends Fixture> fixtureClass, boolean openPane) {
115109
if ((!isPaneOpened(fixtureClass) && openPane)) {
116110
clickOnStripeButton(label, false);
117-
return find(fixtureClass, Duration.ofSeconds(10));
118111
} else if (isPaneOpened(fixtureClass) && !openPane) {
119112
clickOnStripeButton(label, true);
120113
}
121-
return null;
122114
}
123115

124116
private boolean isPaneOpened(Class<? extends Fixture> fixtureClass) {

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/buildtoolpane/GradleBuildToolPane.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ public JTreeFixture gradleTaskTree() {
109109

110110
private boolean isGradleTreeVisible() {
111111
String treeContent = TextUtils.listOfRemoteTextToString(gradleTaskTree().findAllText());
112-
return !treeContent.toLowerCase(Locale.ROOT).contains("nothing") && !treeContent.equals("");
112+
return !treeContent.toLowerCase(Locale.ROOT).contains("nothing") && !treeContent.isEmpty();
113113
}
114114
}

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/mainidewindow/toolwindowspane/buildtoolpane/MavenBuildToolPane.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ public JTreeFixture mavenTargetTree() {
9393

9494
private boolean isMavenTreeVisible() {
9595
String treeContent = TextUtils.listOfRemoteTextToString(mavenTargetTree().findAllText());
96-
return !treeContent.toLowerCase(Locale.ROOT).contains("nothing") && !treeContent.equals("");
96+
return !treeContent.toLowerCase(Locale.ROOT).contains("nothing") && !treeContent.isEmpty();
9797
}
9898
}

0 commit comments

Comments
 (0)