Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 184022
Collapse All | Expand All

(-)src/org/eclipse/update/search/UpdateSearchRequest.java (-91 / +95 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Paul Foreman (IBM Corp.) - bug 184022 (Divide by Zero when updating)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.update.search;
12
package org.eclipse.update.search;
12
13
Lines 263-373 Link Here
263
			int ntasks = nsearchsites + queries.length * candidates.length;
264
			int ntasks = nsearchsites + queries.length * candidates.length;
264
			if (updateMapURL!=null) ntasks++;
265
			if (updateMapURL!=null) ntasks++;
265
266
266
			monitor.beginTask(Messages.UpdateSearchRequest_searching, ntasks); 
267
			//	bug 184022 If ntasks is zero we have a divide by zero error when creating the monitor
268
			if (ntasks > 0) {
269
				monitor.beginTask(Messages.UpdateSearchRequest_searching, ntasks); 
267
			
270
			
268
			try {
271
				try {
269
				UpdatePolicy updatePolicy=null;
272
					UpdatePolicy updatePolicy=null;
270
				if (updateMapURL!=null) {
273
					if (updateMapURL!=null) {
271
					updatePolicy = new UpdatePolicy();
274
						updatePolicy = new UpdatePolicy();
272
					IStatus status =UpdateUtils.loadUpdatePolicy(updatePolicy, updateMapURL, new SubProgressMonitor(monitor, 1));
275
						IStatus status =UpdateUtils.loadUpdatePolicy(updatePolicy, updateMapURL, new SubProgressMonitor(monitor, 1));
273
					if (status != null)
274
						statusList.add(status);
275
				}
276
				
277
				List combinedAssociateSites = new ArrayList();
278
				for (int i = 0; i < queries.length; i++) {
279
					IUpdateSearchQuery query = queries[i];
280
					IQueryUpdateSiteAdapter qsite = query.getQuerySearchSite();
281
					// currently, the next conditional is only executed (qsite!=null) when
282
					// running an update search. 
283
					if (qsite != null && searchFeatureProvidedSites) {
284
						// do not update features that are installed in read-only locations
285
						if (query instanceof UpdatesSearchCategory.UpdateQuery) {
286
							IFeature feature = ((UpdatesSearchCategory.UpdateQuery)query).getFeature();
287
							if (feature != null && !feature.getSite().getCurrentConfiguredSite().verifyUpdatableStatus().isOK())
288
								continue;
289
						}
290
						// check for mapping
291
						IUpdateSiteAdapter mappedSite = getMappedSite(updatePolicy, qsite);
292
						// when there is no mapped site the feature is not updatable
293
						if (mappedSite == null || mappedSite.getURL() == null)
294
							continue;
295
						SubProgressMonitor subMonitor =
296
							new SubProgressMonitor(monitor, 1);
297
						List associateSites = new ArrayList();
298
						IStatus status =
299
							searchOneSite(
300
								mappedSite,
301
								null,
302
								query,
303
								collector,
304
								associateSites,
305
								subMonitor,
306
								true);
307
						if (status != null)
276
						if (status != null)
308
							statusList.add(status);
277
							statusList.add(status);
309
						if (monitor.isCanceled())
310
							break;
311
						combinedAssociateSites = combineAssociateSites( combinedAssociateSites, associateSites, visitedSitesURL, visitedSites);
312
					}
278
					}
313
					
279
				
314
					for (int j = 0; j < candidates.length; j++) {
280
					List combinedAssociateSites = new ArrayList();
315
						if (monitor.isCanceled()) {
281
					for (int i = 0; i < queries.length; i++) {
316
							break;
282
						IUpdateSearchQuery query = queries[i];
283
						IQueryUpdateSiteAdapter qsite = query.getQuerySearchSite();
284
						// currently, the next conditional is only executed (qsite!=null) when
285
						// running an update search. 
286
						if (qsite != null && searchFeatureProvidedSites) {
287
							// do not update features that are installed in read-only locations
288
							if (query instanceof UpdatesSearchCategory.UpdateQuery) {
289
								IFeature feature = ((UpdatesSearchCategory.UpdateQuery)query).getFeature();
290
								if (feature != null && !feature.getSite().getCurrentConfiguredSite().verifyUpdatableStatus().isOK())
291
									continue;
292
							}
293
							// check for mapping
294
							IUpdateSiteAdapter mappedSite = getMappedSite(updatePolicy, qsite);
295
							// when there is no mapped site the feature is not updatable
296
							if (mappedSite == null || mappedSite.getURL() == null)
297
								continue;
298
							SubProgressMonitor subMonitor =
299
								new SubProgressMonitor(monitor, 1);
300
							List associateSites = new ArrayList();
301
							IStatus status =
302
								searchOneSite(
303
										mappedSite,
304
										null,
305
										query,
306
										collector,
307
										associateSites,
308
										subMonitor,
309
										true);
310
							if (status != null)
311
								statusList.add(status);
312
							if (monitor.isCanceled())
313
								break;
314
							combinedAssociateSites = combineAssociateSites( combinedAssociateSites, associateSites, visitedSitesURL, visitedSites);
317
						}
315
						}
318
						IUpdateSearchSite source = candidates[j];
319
						SubProgressMonitor subMonitor =
320
							new SubProgressMonitor(monitor, 1);
321
						List associateSites = new ArrayList();
322
						IStatus status =
323
							searchOneSite(
324
								source,
325
								source.getCategoriesToSkip(),
326
								query,
327
								collector,
328
								associateSites,
329
								subMonitor,
330
								true);
331
						if (status != null)
332
							statusList.add(status);
333
						combinedAssociateSites = combineAssociateSites( combinedAssociateSites, associateSites, visitedSitesURL, visitedSites);
334
					}
335
					if (monitor.isCanceled())
336
						break;
337
					
316
					
338
					
317
						for (int j = 0; j < candidates.length; j++) {
339
					for(int associateSitesDepth = 0; associateSitesDepth < 5; associateSitesDepth++) {
318
							if (monitor.isCanceled()) {
340
						List tempCombinedSites = new ArrayList();
319
								break;
341
						Iterator combinedAssociateSitesIterator = combinedAssociateSites.iterator();
320
							}
342
						while(combinedAssociateSitesIterator.hasNext()) {
321
							IUpdateSearchSite source = candidates[j];
343
							
322
							SubProgressMonitor subMonitor =
344
							IUpdateSearchSite source = (IUpdateSearchSite)combinedAssociateSitesIterator.next();
323
								new SubProgressMonitor(monitor, 1);
345
							
346
							List associateSites = new ArrayList();
324
							List associateSites = new ArrayList();
347
							SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
348
							IStatus status =
325
							IStatus status =
349
								searchOneSite(
326
								searchOneSite(
350
									source,
327
										source,
351
									source.getCategoriesToSkip(),
328
										source.getCategoriesToSkip(),
352
									query,
329
										query,
353
									collector,
330
										collector,
354
									associateSites,
331
										associateSites,
355
									subMonitor,
332
										subMonitor,
356
									true);
333
										true);
357
							combinedAssociateSites = combineAssociateSites( tempCombinedSites, associateSites, visitedSitesURL, visitedSites);
358
							if (status != null)
334
							if (status != null)
359
								statusList.add(status);
335
								statusList.add(status);
360
						}	
336
							combinedAssociateSites = combineAssociateSites( combinedAssociateSites, associateSites, visitedSitesURL, visitedSites);
361
						combinedAssociateSites = tempCombinedSites;
337
						}
338
						if (monitor.isCanceled())
339
							break;
340
					
341
					
342
						for(int associateSitesDepth = 0; associateSitesDepth < 5; associateSitesDepth++) {
343
							List tempCombinedSites = new ArrayList();
344
							Iterator combinedAssociateSitesIterator = combinedAssociateSites.iterator();
345
							while(combinedAssociateSitesIterator.hasNext()) {
346
							
347
								IUpdateSearchSite source = (IUpdateSearchSite)combinedAssociateSitesIterator.next();
348
							
349
								List associateSites = new ArrayList();
350
								SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
351
								IStatus status =
352
									searchOneSite(
353
											source,
354
											source.getCategoriesToSkip(),
355
											query,
356
											collector,
357
										associateSites,
358
										subMonitor,
359
										true);
360
								combinedAssociateSites = combineAssociateSites( tempCombinedSites, associateSites, visitedSitesURL, visitedSites);
361
								if (status != null)
362
									statusList.add(status);
363
							}	
364
							combinedAssociateSites = tempCombinedSites;
362
						
365
						
366
						}
367
						if (monitor.isCanceled())
368
							break;
363
					}
369
					}
364
					if (monitor.isCanceled())
370
				} catch (CoreException e) {
365
						break;
371
					searchInProgress = false;
372
					monitor.done();
373
					throw e;
366
				}
374
				}
367
			} catch (CoreException e) {
368
				searchInProgress = false;
369
				monitor.done();
370
				throw e;
371
			}
375
			}
372
		}
376
		}
373
		searchInProgress = false;
377
		searchInProgress = false;

Return to bug 184022