Skip to content

Commit a9412e2

Browse files
committed
Improve progress reporting in ClasspathContainerState
Updated the run method to drain the workQueue into a local list at the start. This allows for an accurate count of pending tasks and prevents the performance penalty of calling ConcurrentLinkedQueue.size() (which is O(n)) inside the loop. Removed the repeated monitor.setWorkRemaining(WORK) call inside the loop, which was causing the progress bar to reset and appear stuck. Implemented logic to estimate work: count * 2 ticks are allocated initially (assuming 1 tick for checking and 1 tick for potential update). This seems a bit too much for the classpath update in my test environment but is much better then before and it is difficult to judge how long the classpath update will actually take. Updated monitor.worked(1) to happen for every processed request. Adjusted the remaining work for the final phase (setProjectContainers) based on the actual number of projects requiring updates. In a small / fast environment you may want to a Thread.sleep() to the loop, in my client environment with > 900 bundles the process is not much better visible.
1 parent df29a67 commit a9412e2

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathContainerState.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public void resourceChanged(IResourceChangeEvent event) {
7878
*/
7979
private static final class UpdateClasspathsJob extends Job {
8080

81-
private static final int WORK = 10_000;
8281
private final Queue<UpdateRequest> workQueue = new ConcurrentLinkedQueue<>();
8382

8483
/**
@@ -98,15 +97,25 @@ public boolean belongsTo(Object family) {
9897

9998
@Override
10099
protected IStatus run(IProgressMonitor jobMonitor) {
101-
SubMonitor monitor = SubMonitor.convert(jobMonitor, PDECoreMessages.PluginModelManager_1, WORK);
102-
PluginModelManager.getInstance().initialize(monitor.split(10));
100+
SubMonitor monitor = SubMonitor.convert(jobMonitor, PDECoreMessages.PluginModelManager_1, 100);
101+
PluginModelManager.getInstance().initialize(monitor.split(1));
103102
PluginModelManager modelManager = PluginModelManager.getInstance();
104103
Map<IJavaProject, IClasspathContainer> updateProjects = new LinkedHashMap<>();
105104
Map<IProject, IStatus> errorsPerProject = new LinkedHashMap<>();
105+
106+
java.util.List<UpdateRequest> requests = new java.util.ArrayList<>();
106107
UpdateRequest request;
107-
while (!monitor.isCanceled() && (request = workQueue.poll()) != null) {
108-
monitor.setWorkRemaining(WORK);
109-
IProject project = request.project();
108+
while ((request = workQueue.poll()) != null) {
109+
requests.add(request);
110+
}
111+
int count = requests.size();
112+
monitor.setWorkRemaining(count * 2);
113+
114+
for (UpdateRequest req : requests) {
115+
if (monitor.isCanceled()) {
116+
break;
117+
}
118+
IProject project = req.project();
110119
if (project.exists() && project.isOpen()) {
111120
monitor.subTask(project.getName());
112121
IPluginModelBase model = modelManager.findModel(project);
@@ -115,17 +124,17 @@ protected IStatus run(IProgressMonitor jobMonitor) {
115124
try {
116125
IClasspathEntry[] entries = ClasspathComputer.computeClasspathEntries(model,
117126
javaProject.getProject());
118-
if (!isUpToDate(project, entries, request.container())) {
127+
if (!isUpToDate(project, entries, req.container())) {
119128
updateProjects.put(javaProject, PDEClasspathContainerSaveHelper.containerOf(entries));
120129
errorsPerProject.remove(project);
121130
saveState(project, entries);
122131
}
123132
} catch (CoreException e) {
124133
errorsPerProject.put(project, e.getStatus());
125134
}
126-
monitor.worked(1);
127135
}
128136
}
137+
monitor.worked(1);
129138
}
130139
if (monitor.isCanceled()) {
131140
return Status.CANCEL_STATUS;
@@ -151,7 +160,8 @@ protected IStatus run(IProgressMonitor jobMonitor) {
151160
i++;
152161
}
153162
try {
154-
setProjectContainers(javaProjects, container, monitor);
163+
monitor.setWorkRemaining(n);
164+
setProjectContainers(javaProjects, container, monitor.split(n));
155165
} catch (JavaModelException e) {
156166
return e.getStatus();
157167
}

0 commit comments

Comments
 (0)