Skip to content

Commit e4a33b9

Browse files
committed
refactoring update check
1 parent e265f6c commit e4a33b9

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/Builder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public Builder() {
5252
project = null;
5353
console = Console.getInstance();
5454
problemReporter = new ProblemReporter();
55-
UpdateCheck.startUpdateCheck(true);
55+
UpdateCheck.startUpdateCheck();
5656
}
5757

5858
public class DeltaVisitor implements IResourceDeltaVisitor {
@@ -247,7 +247,7 @@ protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
247247
project = null;
248248

249249
// check update with each build (since the same builder is reused)
250-
UpdateCheck.startUpdateCheck(true);
250+
UpdateCheck.startUpdateCheck();
251251
if (kind == FULL_BUILD) {
252252
fullBuild(monitor);
253253
} else {

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/UpdateCheck.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.eclipse.core.runtime.IProgressMonitor;
1010
import org.eclipse.core.runtime.IStatus;
1111
import org.eclipse.core.runtime.Status;
12+
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
13+
import org.eclipse.core.runtime.jobs.IJobChangeListener;
1214
import org.eclipse.core.runtime.jobs.Job;
1315
import org.eclipse.jface.dialogs.IDialogConstants;
1416
import org.eclipse.jface.dialogs.MessageDialog;
@@ -36,6 +38,10 @@ public class UpdateCheck {
3638

3739
private final boolean isSilent;
3840

41+
/**
42+
*
43+
* @param isSilent true, if notification should only be shown, if there is an update available
44+
*/
3945
public UpdateCheck(boolean isSilent) {
4046
this.isSilent = isSilent;
4147
}
@@ -86,9 +92,9 @@ private static boolean needUpdateCheck() {
8692
return false;
8793
}
8894

89-
public static boolean startUpdateCheck(boolean isSilent) {
95+
public static boolean startUpdateCheck() {
96+
// do not start another update check, if one is already running
9097
if (UpdateCheck.needUpdateCheck()) {
91-
9298
String binaryPath = CppcheclipsePlugin.getConfigurationPreferenceStore()
9399
.getString(IPreferenceConstants.P_BINARY_PATH);
94100
new UpdateCheck(true).check(binaryPath);
@@ -123,7 +129,7 @@ protected IStatus run(IProgressMonitor monitor) {
123129
.format(new Date()));
124130
configuration.save();
125131
Display display = Display.getDefault();
126-
display.asyncExec(new UpdateCheckNotifier(newVersion));
132+
display.syncExec(new UpdateCheckNotifier(newVersion));
127133
} catch (Exception e) {
128134
if (!isSilent) {
129135
CppcheclipsePlugin
@@ -147,7 +153,7 @@ public UpdateCheckNotifier(Version newVersion) {
147153
public void run() {
148154
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
149155
.getShell();
150-
156+
// if no new version found, just display a dialog if not in silent mode
151157
if (newVersion == null) {
152158
if (!isSilent) {
153159
MessageDialog.openInformation(shell,
@@ -201,7 +207,10 @@ public void run() {
201207
public Job check(String binaryPath) {
202208
Job job = new UpdateCheckJob(binaryPath);
203209
job.setUser(true);
210+
// execute job asynchronously
204211
job.schedule();
205212
return job;
206213
}
214+
215+
207216
}

0 commit comments

Comments
 (0)