Lines 187-192
Link Here
|
187 |
static final private Integer REPOSITORY_VERSION = new Integer(1); |
187 |
static final private Integer REPOSITORY_VERSION = new Integer(1); |
188 |
private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ |
188 |
private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$ |
189 |
protected Set artifactDescriptors = new HashSet(); |
189 |
protected Set artifactDescriptors = new HashSet(); |
|
|
190 |
protected Map artifactMap = new HashMap(); |
190 |
private transient BlobStore blobStore; |
191 |
private transient BlobStore blobStore; |
191 |
transient private Mapper mapper = new Mapper(); |
192 |
transient private Mapper mapper = new Mapper(); |
192 |
|
193 |
|
Lines 255-260
Link Here
|
255 |
super(name, type, version, null, description, provider, properties); |
256 |
super(name, type, version, null, description, provider, properties); |
256 |
this.artifactDescriptors.addAll(artifacts); |
257 |
this.artifactDescriptors.addAll(artifacts); |
257 |
this.mappingRules = mappingRules; |
258 |
this.mappingRules = mappingRules; |
|
|
259 |
for (Iterator it = artifactDescriptors.iterator(); it.hasNext();) |
260 |
mapDescriptor((IArtifactDescriptor) it.next()); |
261 |
} |
262 |
|
263 |
private void mapDescriptor(IArtifactDescriptor descriptor) { |
264 |
IArtifactKey key = descriptor.getArtifactKey(); |
265 |
Collection descriptors = (Collection) artifactMap.get(key); |
266 |
if (descriptors == null) { |
267 |
descriptors = new ArrayList(); |
268 |
artifactMap.put(key, descriptors); |
269 |
} |
270 |
descriptors.add(descriptor); |
271 |
} |
272 |
|
273 |
private void unmapDescriptor(IArtifactDescriptor descriptor) { |
274 |
IArtifactKey key = descriptor.getArtifactKey(); |
275 |
Collection descriptors = (Collection) artifactMap.get(key); |
276 |
if (descriptors == null) |
277 |
return; |
278 |
|
279 |
descriptors.remove(descriptor); |
280 |
if (descriptors.isEmpty()) |
281 |
artifactMap.remove(key); |
258 |
} |
282 |
} |
259 |
|
283 |
|
260 |
public SimpleArtifactRepository(String repositoryName, URL location, Map properties) { |
284 |
public SimpleArtifactRepository(String repositoryName, URL location, Map properties) { |
Lines 282-287
Link Here
|
282 |
// TODO: here we may want to ensure that the artifact has not been added concurrently |
306 |
// TODO: here we may want to ensure that the artifact has not been added concurrently |
283 |
((ArtifactDescriptor) toAdd).setRepository(this); |
307 |
((ArtifactDescriptor) toAdd).setRepository(this); |
284 |
artifactDescriptors.add(toAdd); |
308 |
artifactDescriptors.add(toAdd); |
|
|
309 |
mapDescriptor(toAdd); |
285 |
save(); |
310 |
save(); |
286 |
} |
311 |
} |
287 |
|
312 |
|
Lines 290-295
Link Here
|
290 |
for (int i = 0; i < descriptors.length; i++) { |
315 |
for (int i = 0; i < descriptors.length; i++) { |
291 |
((ArtifactDescriptor) descriptors[i]).setRepository(this); |
316 |
((ArtifactDescriptor) descriptors[i]).setRepository(this); |
292 |
artifactDescriptors.add(descriptors[i]); |
317 |
artifactDescriptors.add(descriptors[i]); |
|
|
318 |
mapDescriptor(descriptors[i]); |
293 |
} |
319 |
} |
294 |
save(); |
320 |
save(); |
295 |
} |
321 |
} |
Lines 347-358
Link Here
|
347 |
} |
373 |
} |
348 |
|
374 |
|
349 |
public synchronized boolean contains(IArtifactKey key) { |
375 |
public synchronized boolean contains(IArtifactKey key) { |
350 |
for (Iterator iterator = artifactDescriptors.iterator(); iterator.hasNext();) { |
376 |
return artifactMap.containsKey(key); |
351 |
IArtifactDescriptor descriptor = (IArtifactDescriptor) iterator.next(); |
|
|
352 |
if (descriptor.getArtifactKey().equals(key)) |
353 |
return true; |
354 |
} |
355 |
return false; |
356 |
} |
377 |
} |
357 |
|
378 |
|
358 |
public synchronized String createLocation(ArtifactDescriptor descriptor) { |
379 |
public synchronized String createLocation(ArtifactDescriptor descriptor) { |
Lines 393-399
Link Here
|
393 |
if (file.exists()) |
414 |
if (file.exists()) |
394 |
return false; |
415 |
return false; |
395 |
} |
416 |
} |
396 |
return artifactDescriptors.remove(descriptor); |
417 |
boolean result = artifactDescriptors.remove(descriptor); |
|
|
418 |
if (result) |
419 |
unmapDescriptor(descriptor); |
420 |
|
421 |
return result; |
397 |
} |
422 |
} |
398 |
|
423 |
|
399 |
protected IStatus downloadArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { |
424 |
protected IStatus downloadArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { |
Lines 491-502
Link Here
|
491 |
} |
516 |
} |
492 |
|
517 |
|
493 |
public synchronized IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) { |
518 |
public synchronized IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) { |
494 |
ArrayList result = new ArrayList(); |
519 |
Collection result = (Collection) artifactMap.get(key); |
495 |
for (Iterator iterator = artifactDescriptors.iterator(); iterator.hasNext();) { |
520 |
if (result == null) |
496 |
IArtifactDescriptor descriptor = (IArtifactDescriptor) iterator.next(); |
521 |
return new IArtifactDescriptor[0]; |
497 |
if (descriptor.getArtifactKey().equals(key)) |
522 |
|
498 |
result.add(descriptor); |
|
|
499 |
} |
500 |
return (IArtifactDescriptor[]) result.toArray(new IArtifactDescriptor[result.size()]); |
523 |
return (IArtifactDescriptor[]) result.toArray(new IArtifactDescriptor[result.size()]); |
501 |
} |
524 |
} |
502 |
|
525 |
|
Lines 516-525
Link Here
|
516 |
|
539 |
|
517 |
public synchronized IArtifactKey[] getArtifactKeys() { |
540 |
public synchronized IArtifactKey[] getArtifactKeys() { |
518 |
// there may be more descriptors than keys to collect up the unique keys |
541 |
// there may be more descriptors than keys to collect up the unique keys |
519 |
HashSet result = new HashSet(artifactDescriptors.size()); |
542 |
return (IArtifactKey[]) artifactMap.keySet().toArray(new IArtifactKey[artifactMap.keySet().size()]); |
520 |
for (Iterator it = artifactDescriptors.iterator(); it.hasNext();) |
|
|
521 |
result.add(((IArtifactDescriptor) it.next()).getArtifactKey()); |
522 |
return (IArtifactKey[]) result.toArray(new IArtifactKey[result.size()]); |
523 |
} |
543 |
} |
524 |
|
544 |
|
525 |
public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) { |
545 |
public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) { |
Lines 564-570
Link Here
|
564 |
} |
584 |
} |
565 |
|
585 |
|
566 |
public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) { |
586 |
public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) { |
567 |
for (Iterator iterator = artifactDescriptors.iterator(); iterator.hasNext();) { |
587 |
Collection descriptors = (Collection) artifactMap.get(key); |
|
|
588 |
if (descriptors == null) |
589 |
return null; |
590 |
|
591 |
for (Iterator iterator = descriptors.iterator(); iterator.hasNext();) { |
568 |
IArtifactDescriptor desc = (IArtifactDescriptor) iterator.next(); |
592 |
IArtifactDescriptor desc = (IArtifactDescriptor) iterator.next(); |
569 |
// look for a descriptor that matches the key and is "complete" |
593 |
// look for a descriptor that matches the key and is "complete" |
570 |
if (desc.getArtifactKey().equals(key) && desc.getProcessingSteps().length == 0) |
594 |
if (desc.getArtifactKey().equals(key) && desc.getProcessingSteps().length == 0) |