Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLE-1020: Only show new version hint every two weeks #790

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -472,22 +475,38 @@ public static boolean sonarLintVersionHintHidden() {
: Boolean.parseBoolean(property);
}

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

try {
var today = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
return date.equals(today);
var savedDate = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).parse(date);
var todayDate = Calendar.getInstance().getTime();

return todayDate.after(savedDate);
} catch (Exception ignored) {
return false;
}
}

public static void setSonarLintVersionHintDate() {
var date = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH).format(Calendar.getInstance().getTime());
/**
* Only show hint about the new SonarQube for Eclipse version every two weeks in order to not
* annoy users with a daily notification.
*/
public static void setNextSonarLintVersionHintDate() {
var date = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH)
.format(Date.from(
LocalDate.now().plusDays(14)
.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant()));

setPreferenceString(getApplicationLevelPreferenceNode(), PREF_SONARLINT_VERSION_HINT_DATE, date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public IStatus run(IProgressMonitor monitor) {
// Check if newer version is available and then show a notification raising awareness about it. The
// notification will only be displayed once a day in order to not annoy the user!
if (!SonarLintGlobalConfiguration.sonarLintVersionHintHidden()
&& !SonarLintGlobalConfiguration.isSonarLintVersionHintDateToday()) {
&& SonarLintGlobalConfiguration.isNextSonarLintVersionHintDateToday()) {
var newestSonarLintVersion = EclipseUpdateSite.getNewestVersion();
var currentSonarLintVersion = BundleUtils.getBundleVersion();
SonarLintLogger.get().debug("Current version (" + currentSonarLintVersion + "), newest version ("
Expand All @@ -293,13 +293,13 @@ public IStatus run(IProgressMonitor monitor) {
+ SonarLintDocumentation.GITHUB_RELEASES + ")!");
} else if (newestSonarLintVersion.isNewerThan(currentSonarLintVersion)) {
NewerVersionAvailablePopup.displayPopupIfNotAlreadyShown(newestSonarLintVersion.toString());
SonarLintGlobalConfiguration.setNextSonarLintVersionHintDate();
}
}
}

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

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