Skip to content

Commit 8cf05b8

Browse files
committed
SLE-1020: Only show new version hint every two weeks
Prior to this change it was shown every day until the user updated to a new version or when the internal system property was not used.
1 parent 8ea26be commit 8cf05b8

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/preferences/SonarLintGlobalConfiguration.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
import java.nio.file.Path;
2424
import java.nio.file.Paths;
2525
import java.text.SimpleDateFormat;
26+
import java.time.LocalDate;
27+
import java.time.ZoneId;
2628
import java.util.ArrayList;
2729
import java.util.Arrays;
2830
import java.util.Calendar;
2931
import java.util.Collection;
3032
import java.util.Collections;
33+
import java.util.Date;
3134
import java.util.HashSet;
3235
import java.util.LinkedHashMap;
3336
import java.util.List;
@@ -472,22 +475,38 @@ public static boolean sonarLintVersionHintHidden() {
472475
: Boolean.parseBoolean(property);
473476
}
474477

475-
public static boolean isSonarLintVersionHintDateToday() {
478+
/**
479+
* Check whether it was already two weeks ago that the user got a hint about the new SonarQube
480+
* for Eclipse version. If it has not yet been two weeks, we don't want to show it again.
481+
*/
482+
public static boolean isNextSonarLintVersionHintDateToday() {
476483
var date = getPreferenceString(PREF_SONARLINT_VERSION_HINT_DATE);
477484
if (date.isBlank()) {
478-
return false;
485+
return true;
479486
}
480487

481488
try {
482-
var today = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
483-
return date.equals(today);
489+
var savedDate = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).parse(date);
490+
var todayDate = Calendar.getInstance().getTime();
491+
492+
return todayDate.after(savedDate);
484493
} catch (Exception ignored) {
485494
return false;
486495
}
487496
}
488497

489-
public static void setSonarLintVersionHintDate() {
490-
var date = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
498+
/**
499+
* Only show hint about the new SonarQube for Eclipse version every two weeks in order to not
500+
* annoy users with a daily notification.
501+
*/
502+
public static void setNextSonarLintVersionHintDate() {
503+
var date = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH)
504+
.format(Date.from(
505+
LocalDate.now().plusDays(14)
506+
.atStartOfDay()
507+
.atZone(ZoneId.systemDefault())
508+
.toInstant()));
509+
491510
setPreferenceString(getApplicationLevelPreferenceNode(), PREF_SONARLINT_VERSION_HINT_DATE, date);
492511
}
493512
}

org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/SonarLintUiPlugin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public IStatus run(IProgressMonitor monitor) {
280280
// Check if newer version is available and then show a notification raising awareness about it. The
281281
// notification will only be displayed once a day in order to not annoy the user!
282282
if (!SonarLintGlobalConfiguration.sonarLintVersionHintHidden()
283-
&& !SonarLintGlobalConfiguration.isSonarLintVersionHintDateToday()) {
283+
&& SonarLintGlobalConfiguration.isNextSonarLintVersionHintDateToday()) {
284284
var newestSonarLintVersion = EclipseUpdateSite.getNewestVersion();
285285
var currentSonarLintVersion = BundleUtils.getBundleVersion();
286286
SonarLintLogger.get().debug("Current version (" + currentSonarLintVersion + "), newest version ("
@@ -294,12 +294,13 @@ public IStatus run(IProgressMonitor monitor) {
294294
} else if (newestSonarLintVersion.isNewerThan(currentSonarLintVersion)) {
295295
NewerVersionAvailablePopup.displayPopupIfNotAlreadyShown(newestSonarLintVersion.toString());
296296
}
297+
298+
SonarLintGlobalConfiguration.setNextSonarLintVersionHintDate();
297299
}
298300
}
299301

300302
// We want to update the locally saved SonarLint version reference once everything is done!
301303
SonarLintGlobalConfiguration.setSonarLintVersion();
302-
SonarLintGlobalConfiguration.setSonarLintVersionHintDate();
303304

304305
// Display user survey pop-up (comment out if not needed, comment in again if needed and replace link)
305306
// Display.getDefault().syncExec(() -> SurveyPopup.displaySurveyPopupIfNotAlreadyAccessed(""));

0 commit comments

Comments
 (0)