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 374516
Collapse All | Expand All

(-)a/bundles/org.eclipse.team.cvs.ui/META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 2-8 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.team.cvs.ui; singleton:=true
4
Bundle-SymbolicName: org.eclipse.team.cvs.ui; singleton:=true
5
Bundle-Version: 3.3.302.qualifier
5
Bundle-Version: 3.3.303.qualifier
6
Bundle-Activator: org.eclipse.team.internal.ccvs.ui.CVSUIPlugin
6
Bundle-Activator: org.eclipse.team.internal.ccvs.ui.CVSUIPlugin
7
Bundle-Vendor: %providerName
7
Bundle-Vendor: %providerName
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
(-)a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/RemoteFolderElement.java (-9 / +41 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 57-79 Link Here
57
    public Object[] fetchChildren(Object o, IProgressMonitor monitor) throws TeamException {
57
    public Object[] fetchChildren(Object o, IProgressMonitor monitor) throws TeamException {
58
        if (!(o instanceof ICVSRemoteFolder))
58
        if (!(o instanceof ICVSRemoteFolder))
59
            return new Object[0];
59
            return new Object[0];
60
        return ((ICVSRemoteFolder) o).members(monitor);
60
		try {
61
    }
61
			monitor = Policy.monitorFor(monitor);
62
			monitor.beginTask(NLS.bind(
63
					CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
64
					new String[] { getLabel(o) }), 100);
65
			ICVSRemoteFolder folder = (ICVSRemoteFolder) o;
66
			ICVSRemoteResource[] cachedChildren = CVSUIPlugin
67
					.getPlugin()
68
					.getRepositoryManager()
69
					.getCachedChildrenForTag(folder.getRepository(), folder,
70
							folder.getTag(), Policy.subMonitorFor(monitor, 50));
71
			if (cachedChildren.length > 0) {
72
				return cachedChildren;
73
			}
74
			return folder.members(Policy.subMonitorFor(monitor, 50));
75
		} finally {
76
			monitor.done();
77
		}
78
	}
62
79
63
    public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) {
80
    public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) {
64
    	// If it's not a folder, return an empty array
81
    	// If it's not a folder, return an empty array
65
		if (!(o instanceof ICVSRemoteFolder)) {
82
		if (!(o instanceof ICVSRemoteFolder)) {
66
			collector.add(new Object[0], monitor);
83
			collector.add(new Object[0], monitor);
67
		}
84
		}
68
        try {
85
		try {
69
            monitor = Policy.monitorFor(monitor);
86
			monitor = Policy.monitorFor(monitor);
70
            monitor.beginTask(NLS.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren, new String[] { getLabel(o) }), 100); 
87
			monitor.beginTask(NLS.bind(
71
			FetchMembersOperation operation = new FetchMembersOperation(null, (ICVSRemoteFolder)o, collector);
88
					CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
72
			operation.run(Policy.subMonitorFor(monitor, 100));
89
					new String[] { getLabel(o) }), 100);
73
        } catch (InvocationTargetException e) {
90
			ICVSRemoteFolder folder = (ICVSRemoteFolder) o;
91
			ICVSRemoteResource[] cachedChildren = CVSUIPlugin
92
					.getPlugin()
93
					.getRepositoryManager()
94
					.getCachedChildrenForTag(folder.getRepository(), folder,
95
							folder.getTag(), Policy.subMonitorFor(monitor, 50));
96
			if (cachedChildren.length > 0) {
97
				collector.add(cachedChildren, monitor);
98
				return;
99
			}
100
			FetchMembersOperation operation = new FetchMembersOperation(null,
101
					folder, collector);
102
			operation.run(Policy.subMonitorFor(monitor, 50));
103
		} catch (InvocationTargetException e) {
74
            handle(collector, e);
104
            handle(collector, e);
75
		} catch (InterruptedException e) {
105
		} catch (InterruptedException e) {
76
			// Cancelled by the user;
106
			// Cancelled by the user;
107
		} catch (CVSException e) {
108
			handle(collector, e);
77
		} finally {
109
		} finally {
78
            monitor.done();
110
            monitor.done();
79
        }
111
        }
(-)a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java (-16 / +64 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 142-156 Link Here
142
		Set result = new HashSet();
142
		Set result = new HashSet();
143
		RepositoryRoot root = (RepositoryRoot)repositoryRoots.get(location.getLocation(false));
143
		RepositoryRoot root = (RepositoryRoot)repositoryRoots.get(location.getLocation(false));
144
		if (root != null) {
144
		if (root != null) {
145
			String[] paths = root.getKnownRemotePaths();
145
			CVSTag[] tags = root.getAllKnownTags();
146
			for (int i = 0; i < paths.length; i++) {
146
			for (int i = 0; i < tags.length; i++) {
147
				String path = paths[i];
147
				CVSTag tag = tags[i];
148
				CVSTag[] tags = root.getAllKnownTags(path);
148
				if (tag.getType() == tagType)
149
				for (int j = 0; j < tags.length; j++) {
149
					result.add(tag);
150
					CVSTag tag = tags[j];
151
					if (tag.getType() == tagType)
152
						result.add(tag);
153
				}
154
			}
150
			}
155
		}
151
		}
156
		return (CVSTag[])result.toArray(new CVSTag[0]);
152
		return (CVSTag[])result.toArray(new CVSTag[0]);
Lines 225-244 Link Here
225
			Set result = new HashSet();
221
			Set result = new HashSet();
226
			// Get the tags for the location
222
			// Get the tags for the location
227
			RepositoryRoot root = getRepositoryRootFor(location);
223
			RepositoryRoot root = getRepositoryRootFor(location);
228
			String[] paths = root.getKnownRemotePaths();
224
			String[] paths = root.getRemoteChildrenForTag(null, tag);
229
			for (int i = 0; i < paths.length; i++) {
225
			for (int i = 0; i < paths.length; i++) {
230
				String path = paths[i];
226
				String path = paths[i];
231
				List tags = Arrays.asList(root.getAllKnownTags(path));
227
				ICVSRemoteFolder remote = root.getRemoteFolder(path, tag,
232
				if (tags.contains(tag)) {
228
						Policy.subMonitorFor(monitor, 100));
233
					ICVSRemoteFolder remote = root.getRemoteFolder(path, tag, Policy.subMonitorFor(monitor, 100));
229
				result.add(remote);
234
					result.add(remote);
235
				}
236
			}
230
			}
237
			return (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[result.size()]);
231
			return (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[result.size()]);
238
		} finally {
232
		} finally {
239
			monitor.done();
233
			monitor.done();
240
		}
234
		}
241
	}
235
	}
236
237
	/**
238
	 * Returns a list of child resources for given folder that are known to
239
	 * contain given tag. If the return list is empty than given tag exists
240
	 * directly in given folder and its children should be retrieved directly
241
	 * from the repository.
242
	 *
243
	 * NOTE: Resources are cached only for tags of type CVSTag.Branch and
244
	 * CVSTag.Version. Other types of tags will always return empty list.
245
	 *
246
	 * @param location
247
	 *            CVS repository location
248
	 * @param parentFolder
249
	 *            folder to check tags for
250
	 * @param tag
251
	 * @param monitor
252
	 * @return a list of remote resources that are known to contain given tag or
253
	 *         empty list if resources should be retrieved from the repository
254
	 * @throws CVSException
255
	 */
256
	public ICVSRemoteResource[] getCachedChildrenForTag(
257
			ICVSRepositoryLocation location, ICVSRemoteFolder parentFolder,
258
			CVSTag tag, IProgressMonitor monitor) throws CVSException {
259
		if (tag == null || tag.getType() == CVSTag.HEAD
260
				|| tag.getType() == CVSTag.DATE) {
261
			// folders are kept in cache only for tags and versions
262
			return new ICVSRemoteResource[0];
263
		}
264
		monitor = Policy.monitorFor(monitor);
265
		Set result = new HashSet();
266
		RepositoryRoot root = getRepositoryRootFor(location);
267
		// if remote folder is null return the subfolders of repository root
268
		String[] paths = root.getRemoteChildrenForTag(
269
				parentFolder == null ? null : RepositoryRoot
270
						.getRemotePathFor(parentFolder), tag);
271
		monitor.beginTask(NLS
272
				.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
273
						new String[] { NLS.bind(
274
								CVSUIMessages.RemoteFolderElement_nameAndTag,
275
								new String[] { parentFolder.getName(),
276
										tag.getName() }) }), 10 * paths.length);
277
		try {
278
			for (int i = 0; i < paths.length; i++) {
279
				String path = paths[i];
280
				ICVSRemoteFolder remote = root.getRemoteFolder(path, tag,
281
						Policy.subMonitorFor(monitor, 10));
282
				result.add(remote);
283
			}
284
			return (ICVSRemoteResource[]) result
285
					.toArray(new ICVSRemoteResource[result.size()]);
286
		} finally {
287
			monitor.done();
288
		}
289
	}
242
		
290
		
243
	/*
291
	/*
244
	 * Fetches tags from auto-refresh files if they exist. Then fetches tags from the user defined auto-refresh file
292
	 * Fetches tags from auto-refresh files if they exist. Then fetches tags from the user defined auto-refresh file
(-)a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryRoot.java (-95 / +274 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 33-40 Link Here
33
	
33
	
34
	ICVSRepositoryLocation root;
34
	ICVSRepositoryLocation root;
35
	String name;
35
	String name;
36
	// Map of String (remote folder path) -> TagCacheEntry
36
	TagCacheEntry rootTagCacheEntry = new TagCacheEntry(Path.ROOT, null);
37
	Map versionAndBranchTags = new HashMap();
38
	// Map of String (remote folder path) -> Set (file paths that are project relative)
37
	// Map of String (remote folder path) -> Set (file paths that are project relative)
39
	Map autoRefreshFiles = new HashMap();
38
	Map autoRefreshFiles = new HashMap();
40
	// Map of String (module name) -> ICVSRemoteFolder (that is a defined module)
39
	// Map of String (module name) -> ICVSRemoteFolder (that is a defined module)
Lines 44-55 Link Here
44
	List dateTags = new ArrayList();
43
	List dateTags = new ArrayList();
45
	
44
	
46
	public static class TagCacheEntry {
45
	public static class TagCacheEntry {
47
	    Set tags = new HashSet();
46
		IPath path;
48
	    long lastAccessTime;
47
		// Set of tags found for this path
49
        private static final int CACHE_LIFESPAN_IN_DAYS = 7;
48
		private Set tags = new HashSet();
50
        public TagCacheEntry() {
49
		// String(last path segment) -> TagCacheEntry for child paths
51
            accessed();
50
		Map children = new HashMap();
52
        }
51
		TagCacheEntry parent;
52
		long lastAccessTime;
53
		private static final int CACHE_LIFESPAN_IN_DAYS = 7;
54
55
		public TagCacheEntry(IPath path, TagCacheEntry parent) {
56
			this.path = path;
57
			this.parent = parent;
58
			accessed();
59
		}
60
61
		public Set getTags() {
62
			accessed();
63
			return tags;
64
		}
65
66
		public Iterator getChildrenIterator() {
67
			return this.children.values().iterator();
68
		}
69
70
		public boolean isEmpty() {
71
			return getTags().isEmpty() && children.isEmpty();
72
		}
73
53
        public boolean isExpired() {
74
        public boolean isExpired() {
54
            long currentTime = System.currentTimeMillis();
75
            long currentTime = System.currentTimeMillis();
55
            long ms = currentTime - lastAccessTime;
76
            long ms = currentTime - lastAccessTime;
Lines 58-66 Link Here
58
            int days = hours / 24;
79
            int days = hours / 24;
59
            return days > CACHE_LIFESPAN_IN_DAYS;
80
            return days > CACHE_LIFESPAN_IN_DAYS;
60
        }
81
        }
61
        public void accessed() {
82
62
            lastAccessTime = System.currentTimeMillis();
83
		private void accessed() {
63
        }
84
			lastAccessTime = System.currentTimeMillis();
85
		}
64
	}
86
	}
65
	
87
	
66
	public RepositoryRoot(ICVSRepositoryLocation root) {
88
	public RepositoryRoot(ICVSRepositoryLocation root) {
Lines 189-195 Link Here
189
	 * 
211
	 * 
190
	 * It is the responsibility of the caller to ensure that the given remote path is valid.
212
	 * It is the responsibility of the caller to ensure that the given remote path is valid.
191
	 */
213
	 */
192
	public void addTags(String remotePath, CVSTag[] tags) {	
214
	public void addTags(String remotePath, CVSTag[] tags) {
215
		if (tags.length == 0) {
216
			return;
217
		}
193
		addDateTags(tags);
218
		addDateTags(tags);
194
		addVersionAndBranchTags(remotePath, tags);
219
		addVersionAndBranchTags(remotePath, tags);
195
	}
220
	}
Lines 201-223 Link Here
201
			}
226
			}
202
		}
227
		}
203
	}
228
	}
229
204
	private void addVersionAndBranchTags(String remotePath, CVSTag[] tags) {
230
	private void addVersionAndBranchTags(String remotePath, CVSTag[] tags) {
205
		// Get the name to cache the version tags with
231
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, true);
206
		String name = getCachePathFor(remotePath);
232
207
		
208
		// Make sure there is a table for the ancestor that holds the tags
209
		TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(name);
210
		if (entry == null) {
211
		    entry = new TagCacheEntry();
212
			versionAndBranchTags.put(name, entry);
213
		} else {
214
		    entry.accessed();
215
		}
216
		
217
		// Store the tag with the appropriate ancestor
233
		// Store the tag with the appropriate ancestor
218
		for (int i = 0; i < tags.length; i++) {
234
		for (int i = 0; i < tags.length; i++) {
219
			if(tags[i].getType() != CVSTag.DATE){
235
			if (tags[i].getType() != CVSTag.DATE) {
220
				entry.tags.add(tags[i]);
236
				Set parentTags = new HashSet();
237
				addAllKnownTagsForParents(entry, parentTags);
238
				if (!parentTags.contains(tags[i])) {
239
					entry.getTags().add(tags[i]);
240
					removeTagFromChildrenCacheEntries(entry, tags[i]);
241
				}
221
			}
242
			}
222
		}
243
		}
223
	}
244
	}
Lines 263-282 Link Here
263
	}
284
	}
264
285
265
	private void removeVersionAndBranchTags(String remotePath, CVSTag[] tags) {
286
	private void removeVersionAndBranchTags(String remotePath, CVSTag[] tags) {
266
		// Get the name to cache the version tags with
287
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
267
		String name = getCachePathFor(remotePath);
288
		// remove tags from this path and its children
268
		
289
		if (entry != null) {
269
		// Make sure there is a table for the ancestor that holds the tags
290
			removeTagsFromChildrenCacheEntries(entry, tags);
270
		TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(name);
271
		if (entry == null) {
272
			return;
273
		}
291
		}
274
		
292
275
		// Store the tag with the appropriate ancestor
293
		// remove tags from all parents of this path
294
		entry = getKnownParentTagCacheEntryFor(remotePath);
276
		for (int i = 0; i < tags.length; i++) {
295
		for (int i = 0; i < tags.length; i++) {
277
			entry.tags.remove(tags[i]);
296
			if (entry.getTags().contains(tags[i])) {
297
				entry.getTags().remove(tags[i]);
298
				continue;
299
			}
300
			TagCacheEntry currentEntry = entry;
301
			while (currentEntry.parent != null) {
302
				if (currentEntry.parent.getTags().contains(tags[i])) {
303
					// remove tag from parent and add it to siblings
304
					currentEntry.parent.getTags().remove(tags[i]);
305
					Iterator siblingIterator = currentEntry.parent
306
							.getChildrenIterator();
307
					while (siblingIterator.hasNext()) {
308
						TagCacheEntry sibling = (TagCacheEntry) siblingIterator
309
								.next();
310
						if (!sibling.equals(currentEntry)) {
311
							sibling.getTags().add(tags[i]);
312
						}
313
					}
314
					break;
315
				} else {
316
					currentEntry = currentEntry.parent;
317
				}
318
			}
278
		}
319
		}
279
		entry.accessed();
320
		if (entry.isEmpty()) {
321
			removeTagCacheEntry(entry);
322
		}
280
	}
323
	}
281
324
282
	/**
325
	/**
Lines 286-293 Link Here
286
	 * @return String[]
329
	 * @return String[]
287
	 */
330
	 */
288
	public String[] getAutoRefreshFiles(String remotePath) {
331
	public String[] getAutoRefreshFiles(String remotePath) {
289
		String name = getCachePathFor(remotePath);
332
		Set files = (Set) autoRefreshFiles.get(remotePath);
290
		Set files = (Set)autoRefreshFiles.get(name);
291
		if (files == null || files.isEmpty()) {
333
		if (files == null || files.isEmpty()) {
292
			// convert the default relative file paths to full paths
334
			// convert the default relative file paths to full paths
293
			if (isDefinedModuleName(remotePath)) {
335
			if (isDefinedModuleName(remotePath)) {
Lines 323-365 Link Here
323
				}
365
				}
324
			}
366
			}
325
			if (isDefault) {
367
			if (isDefault) {
326
				this.autoRefreshFiles.remove(getCachePathFor(remotePath));
368
				this.autoRefreshFiles.remove(remotePath);
327
				return;
369
				return;
328
			}
370
			}
329
		}
371
		}
330
		this.autoRefreshFiles.put(getCachePathFor(remotePath), newFiles);
372
		this.autoRefreshFiles.put(remotePath, newFiles);
331
	}
373
	}
332
374
333
	/**
375
	/**
334
	 * Fetches tags from auto-refresh files.
376
	 * Fetches tags from auto-refresh files.
335
	 */
377
	 */
336
	public CVSTag[] refreshDefinedTags(ICVSFolder folder, boolean recurse, IProgressMonitor monitor) throws TeamException {
378
	public CVSTag[] refreshDefinedTags(ICVSFolder folder, boolean recurse,
337
	    monitor.beginTask(null, 100);
379
			IProgressMonitor monitor) throws TeamException {
338
	    CVSTag[] tags = null;
380
		monitor = Policy.monitorFor(monitor);
339
	    if (!recurse && !folder.getFolderSyncInfo().isVirtualDirectory()) {
381
		monitor.beginTask(null, recurse ? 210 : 100);
340
	        // Only try the auto-refresh file(s) if we are not recursing into sub-folders
382
		try {
341
	        tags = fetchTagsUsingAutoRefreshFiles(folder, Policy.subMonitorFor(monitor, 50));
383
			CVSTag[] tags = null;
342
	    }
384
			if (!folder.getFolderSyncInfo().isVirtualDirectory()) {
343
        if (tags == null || tags.length == 0) {
385
				// Only try the auto-refresh file(s) if we are not recursing
344
            // There we're no tags found on the auto-refresh files or we we're aksed to go deep
386
				// into sub-folders
345
            // Try using the log command
387
				tags = fetchTagsUsingAutoRefreshFiles(folder,
346
            tags = fetchTagsUsingLog(folder, recurse, Policy.subMonitorFor(monitor, 50));
388
						Policy.subMonitorFor(monitor, 50));
347
        }
389
			}
348
		if (tags != null && tags.length > 0) {
390
			if (tags == null || tags.length == 0) {
349
		    String remotePath = getRemotePathFor(folder);
391
				// There we're no tags found on the auto-refresh files or we
350
			addTags(remotePath, tags);
392
				// we're asked to go deep
393
				// Try using the log command
394
				tags = fetchTagsUsingLog(folder,
395
						Policy.subMonitorFor(monitor, 50));
396
			}
397
			if (tags != null && tags.length > 0) {
398
				String remotePath = getRemotePathFor(folder);
399
				addTags(remotePath, tags);
400
				return tags;
401
			}
402
			if (recurse) {
403
				Set tagsSet = new HashSet();
404
				folder.fetchChildren(Policy.subMonitorFor(monitor, 10));
405
				ICVSResource[] children = folder
406
						.members(ICVSFolder.FOLDER_MEMBERS);
407
				for (int i = 0; i < children.length; i++) {
408
					tagsSet.addAll(Arrays.asList(refreshDefinedTags(
409
							(ICVSFolder) children[i], recurse, Policy
410
									.subMonitorFor(monitor,
411
											100 / children.length))));
412
				}
413
				tags = (CVSTag[]) tagsSet.toArray(new CVSTag[tagsSet.size()]);
414
			}
415
			return tags;
416
		} finally {
417
			monitor.done();
351
		}
418
		}
352
		monitor.done();
353
		return tags;
354
	}
419
	}
355
	
420
356
    private CVSTag[] fetchTagsUsingLog(ICVSFolder folder, final boolean recurse, IProgressMonitor monitor) throws CVSException {
421
    private CVSTag[] fetchTagsUsingLog(ICVSFolder folder, IProgressMonitor monitor) throws CVSException {
357
        LogEntryCache logEntries = new LogEntryCache();
422
        LogEntryCache logEntries = new LogEntryCache();
358
        RemoteLogOperation operation = new RemoteLogOperation(null, new ICVSRemoteResource[] { asRemoteResource(folder) }, null, null, logEntries) {
423
        RemoteLogOperation operation = new RemoteLogOperation(null, new ICVSRemoteResource[] { asRemoteResource(folder) }, null, null, logEntries) {
359
            protected Command.LocalOption[] getLocalOptions(CVSTag tag1,CVSTag tag2) {
424
            protected Command.LocalOption[] getLocalOptions(CVSTag tag1,CVSTag tag2) {
360
                Command.LocalOption[] options = new Command.LocalOption[] {};
425
                Command.LocalOption[] options = new Command.LocalOption[] {};
361
                if (recurse) 
362
                    return options;
363
                Command.LocalOption[] newOptions = new Command.LocalOption[options.length + 1];
426
                Command.LocalOption[] newOptions = new Command.LocalOption[options.length + 1];
364
                System.arraycopy(options, 0, newOptions, 0, options.length);
427
                System.arraycopy(options, 0, newOptions, 0, options.length);
365
                newOptions[options.length] = Command.DO_NOT_RECURSE;
428
                newOptions[options.length] = Command.DO_NOT_RECURSE;
Lines 441-456 Link Here
441
		}
504
		}
442
		return (CVSTag[])tagSet.toArray(new CVSTag[0]);
505
		return (CVSTag[])tagSet.toArray(new CVSTag[0]);
443
	}
506
	}
444
	
507
445
	/*
508
	private TagCacheEntry getTagCacheEntryFor(String remotePath, boolean create) {
446
	 * Return the cache key (path) for the given folder path.
509
		String[] segments = new Path(null, remotePath).segments();
447
	 * This has been changed to cache the tags directly 
510
		TagCacheEntry currentTagCacheEntry = rootTagCacheEntry;
448
	 * with the folder to better support non-root projects.
511
		for (int i = 0; i < segments.length; i++) {
449
	 * However, resources in the local workspace use the folder
512
			String segment = segments[i];
450
	 * the project is mapped to as the tag source (see TagSource)
513
			if (currentTagCacheEntry.children.containsKey(segment)) {
451
	 */
514
				currentTagCacheEntry = (TagCacheEntry) currentTagCacheEntry.children
452
	private String getCachePathFor(String remotePath) {
515
						.get(segment);
453
		return remotePath;
516
				continue;
517
			}
518
			if (!create) {
519
				return null;
520
			}
521
			TagCacheEntry newTagCacheEntry = new TagCacheEntry(new Path(null,
522
					remotePath).removeLastSegments(segments.length - (i + 1)),
523
					currentTagCacheEntry);
524
			currentTagCacheEntry.children.put(segment, newTagCacheEntry);
525
			currentTagCacheEntry = newTagCacheEntry;
526
		}
527
		return currentTagCacheEntry;
528
	}
529
530
	private TagCacheEntry getKnownParentTagCacheEntryFor(String remotePath) {
531
		String[] segments = new Path(null, remotePath).segments();
532
		TagCacheEntry currentTagCacheEntry = rootTagCacheEntry;
533
		for (int i = 0; i < segments.length; i++) {
534
			String segment = segments[i];
535
			if (currentTagCacheEntry.children.containsKey(segment)) {
536
				currentTagCacheEntry = (TagCacheEntry) currentTagCacheEntry.children
537
						.get(segment);
538
			} else {
539
				break; // we reached the last existing parent
540
			}
541
		}
542
		return currentTagCacheEntry;
543
	}
544
545
	private void removeTagsFromChildrenCacheEntries(TagCacheEntry entry,
546
			CVSTag[] tags) {
547
		for (int i = 0; i < tags.length; i++) {
548
			removeTagFromChildrenCacheEntries(entry, tags[i]);
549
		}
550
		entry.getTags().removeAll(Arrays.asList(tags));
551
		if (entry.isEmpty()) {
552
			// remove this entry when the last tags where removed
553
			// keep the entry if there are any children that have tags
554
			removeTagCacheEntry(entry);
555
		}
556
	}
557
558
	private void removeTagCacheEntry(TagCacheEntry entry) {
559
		if (entry.parent == null) {
560
			// We cannot remove root tag cache entry
561
			return;
562
		}
563
		Map newParentChildren = new HashMap();
564
		newParentChildren.putAll(entry.parent.children);
565
		newParentChildren.remove(entry.path.lastSegment());
566
		entry.parent.children = newParentChildren;
567
		if (entry.parent.isEmpty()) {
568
			// remove parents if they no longer carry any value
569
			removeTagCacheEntry(entry.parent);
570
		}
571
	}
572
573
	private void removeTagFromChildrenCacheEntries(TagCacheEntry entry,
574
			CVSTag tag) {
575
		Iterator childrenIterator = entry.getChildrenIterator();
576
		while (childrenIterator.hasNext()) {
577
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
578
			removeTagFromChildrenCacheEntries(child, tag);
579
			child.getTags().remove(tag);
580
			if (child.isEmpty()) {
581
				// remove this entry when the last tag was removed
582
				// keep the entry if there are any children that have tags
583
				removeTagCacheEntry(child);
584
			}
585
		}
454
	}
586
	}
455
	
587
	
456
	/**
588
	/**
Lines 495-507 Link Here
495
				attributes.put(RepositoriesViewContentHandler.TYPE_ATTRIBUTE, RepositoriesViewContentHandler.DEFINED_MODULE_TYPE);
627
				attributes.put(RepositoriesViewContentHandler.TYPE_ATTRIBUTE, RepositoriesViewContentHandler.DEFINED_MODULE_TYPE);
496
			}
628
			}
497
			attributes.put(RepositoriesViewContentHandler.PATH_ATTRIBUTE, name);
629
			attributes.put(RepositoriesViewContentHandler.PATH_ATTRIBUTE, name);
498
			TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(path);
630
			TagCacheEntry entry = getTagCacheEntryFor(path, false);
499
			boolean writeOutTags = entry != null && !entry.isExpired();
631
			boolean writeOutTags = entry != null && !entry.isExpired();
500
			if (writeOutTags)
632
			if (writeOutTags)
501
			    attributes.put(RepositoriesViewContentHandler.LAST_ACCESS_TIME_ATTRIBUTE, Long.toString(entry.lastAccessTime));
633
			    attributes.put(RepositoriesViewContentHandler.LAST_ACCESS_TIME_ATTRIBUTE, Long.toString(entry.lastAccessTime));
502
			writer.startTag(RepositoriesViewContentHandler.MODULE_TAG, attributes, true);
634
			writer.startTag(RepositoriesViewContentHandler.MODULE_TAG, attributes, true);
503
			if (writeOutTags) {
635
			if (writeOutTags) {
504
				Iterator tagIt = entry.tags.iterator();
636
				Iterator tagIt = entry.getTags().iterator();
505
				while (tagIt.hasNext()) {
637
				while (tagIt.hasNext()) {
506
					CVSTag tag = (CVSTag)tagIt.next();
638
					CVSTag tag = (CVSTag)tagIt.next();
507
					writeATag(writer, attributes, tag, RepositoriesViewContentHandler.TAG_TAG);
639
					writeATag(writer, attributes, tag, RepositoriesViewContentHandler.TAG_TAG);
Lines 529-562 Link Here
529
		writer.startAndEndTag(s, attributes, true);
661
		writer.startAndEndTag(s, attributes, true);
530
	}
662
	}
531
663
664
	private void addAllKnownTagsForParents(TagCacheEntry entry, Set tags) {
665
		if (entry.parent != null) {
666
			addAllKnownTagsForParents(entry.parent, tags);
667
		}
668
		tags.addAll(entry.getTags());
669
	}
670
671
	private void addAllKnownTagsForChildren(TagCacheEntry entry, Set tags) {
672
		Iterator childrenIterator = entry.getChildrenIterator();
673
		while (childrenIterator.hasNext()) {
674
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
675
			addAllKnownTagsForChildren(child, tags);
676
		}
677
		tags.addAll(entry.getTags());
678
	}
679
532
	/**
680
	/**
533
	 * Method getKnownTags.
681
	 * Method getKnownTags.
534
	 * @param remotePath
682
	 * @param remotePath
535
	 * @return CVSTag[]
683
	 * @return CVSTag[]
536
	 */
684
	 */
537
	public CVSTag[] getAllKnownTags(String remotePath) {
685
	public CVSTag[] getAllKnownTags(String remotePath) {
538
	    TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(getCachePathFor(remotePath));
686
		Set tags = new HashSet();
539
		if(entry != null){
687
		addAllKnownTagsForParents(getKnownParentTagCacheEntryFor(remotePath),
540
		    entry.accessed();
688
				tags);
541
			CVSTag [] tags1 = (CVSTag[]) entry.tags.toArray(new CVSTag[entry.tags.size()]);
689
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
542
			CVSTag[] tags2 = getDateTags();
690
		if (entry != null) {
543
			int len = tags1.length + tags2.length;
691
			addAllKnownTagsForChildren(entry, tags);
544
			CVSTag[] tags = new CVSTag[len];
545
			for(int i = 0; i < len; i++){
546
				if(i < tags1.length){
547
					tags[i] = tags1[i];
548
				}else{
549
					tags[i] = tags2[i-tags1.length];
550
				}
551
			}
552
			return tags;
553
		}
692
		}
554
		return getDateTags();
693
		return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]);
694
	}
695
696
	public CVSTag[] getAllKnownTags() {
697
		Set tags = new HashSet();
698
		addAllKnownTagsForChildren(rootTagCacheEntry, tags);
699
		return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]);
700
	}
701
702
	public String[] getRemoteChildrenForTag(String remotePath, CVSTag tag) {
703
		TagCacheEntry entry;
704
		if (remotePath == null) {
705
			entry = rootTagCacheEntry;
706
		} else {
707
			entry = getTagCacheEntryFor(remotePath, false);
708
		}
709
		if (entry == null) {
710
			return new String[0];
711
		}
712
713
		Set paths = new HashSet();
714
		Iterator childrenIterator = entry.getChildrenIterator();
715
		while (childrenIterator.hasNext()) {
716
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
717
			Set childTags = new HashSet();
718
			addAllKnownTagsForChildren(child, childTags);
719
			if (childTags.contains(tag)) {
720
				paths.add(child.path.toString());
721
			}
722
		}
723
		return (String[]) paths.toArray(new String[paths.size()]);
724
	}
725
726
	private Set getKnownRemotePaths(TagCacheEntry entry) {
727
		Set paths = new HashSet();
728
		Iterator childrenIterator = entry.getChildrenIterator();
729
		while (childrenIterator.hasNext()) {
730
			paths.addAll(getKnownRemotePaths((TagCacheEntry) childrenIterator
731
					.next()));
732
		}
733
		paths.add(entry.path.toString());
734
		return paths;
555
	}
735
	}
556
736
557
	public String[] getKnownRemotePaths() {
737
	public String[] getKnownRemotePaths() {
558
		Set paths = new HashSet();
738
		Set paths = getKnownRemotePaths(rootTagCacheEntry);
559
		paths.addAll(versionAndBranchTags.keySet());
560
		paths.addAll(autoRefreshFiles.keySet());
739
		paths.addAll(autoRefreshFiles.keySet());
561
		return (String[]) paths.toArray(new String[paths.size()]);
740
		return (String[]) paths.toArray(new String[paths.size()]);
562
	}
741
	}
Lines 576-582 Link Here
576
	public boolean tagIsKnown(ICVSRemoteResource remoteResource) {
755
	public boolean tagIsKnown(ICVSRemoteResource remoteResource) {
577
		if (remoteResource instanceof ICVSRemoteFolder) {
756
		if (remoteResource instanceof ICVSRemoteFolder) {
578
			ICVSRemoteFolder folder = (ICVSRemoteFolder) remoteResource;
757
			ICVSRemoteFolder folder = (ICVSRemoteFolder) remoteResource;
579
			String path = getCachePathFor(folder.getRepositoryRelativePath());
758
			String path = folder.getRepositoryRelativePath();
580
			CVSTag[] tags = getAllKnownTags(path);
759
			CVSTag[] tags = getAllKnownTags(path);
581
			CVSTag tag = folder.getTag();
760
			CVSTag tag = folder.getTag();
582
			for (int i = 0; i < tags.length; i++) {
761
			for (int i = 0; i < tags.length; i++) {
Lines 611-617 Link Here
611
     * as it was read from the persistent store.
790
     * as it was read from the persistent store.
612
     */
791
     */
613
    /* package */ void setLastAccessedTime(String remotePath, long lastAccessTime) {
792
    /* package */ void setLastAccessedTime(String remotePath, long lastAccessTime) {
614
	    TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(getCachePathFor(remotePath));
793
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
615
		if(entry != null){
794
		if(entry != null){
616
		    entry.lastAccessTime = lastAccessTime;
795
		    entry.lastAccessTime = lastAccessTime;
617
		}
796
		}
(-)a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/AllTestsProvider.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 34-39 Link Here
34
		suite.addTest(WatchEditTest.suite());
34
		suite.addTest(WatchEditTest.suite());
35
		suite.addTest(LinkResourcesTest.suite());
35
		suite.addTest(LinkResourcesTest.suite());
36
		suite.addTest(IsModifiedTests.suite());
36
		suite.addTest(IsModifiedTests.suite());
37
		suite.addTest(RepositoryRootTest.suite());
37
		return new CVSTestSetup(suite);
38
		return new CVSTestSetup(suite);
38
	}
39
	}
39
}
40
}
(-)a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/RepositoryRootTest.java (+397 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.core.provider;
12
13
import java.util.Arrays;
14
import java.util.List;
15
16
import junit.framework.Test;
17
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFolder;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.team.core.TeamException;
24
import org.eclipse.team.internal.ccvs.core.CVSException;
25
import org.eclipse.team.internal.ccvs.core.CVSTag;
26
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
27
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
28
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
29
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
30
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot;
31
import org.eclipse.team.tests.ccvs.core.EclipseTest;
32
33
public class RepositoryRootTest extends EclipseTest {
34
35
	private RepositoryRoot repositoryRoot;
36
	private RepositoryManager repositoryManager;
37
38
	protected void setUp() throws Exception {
39
		super.setUp();
40
		repositoryManager = CVSUIPlugin.getPlugin().getRepositoryManager();
41
		repositoryRoot = repositoryManager
42
				.getRepositoryRootFor(getRepository());
43
		clearRepositoryRootCache();
44
	}
45
46
	public static Test suite() {
47
		return suite(RepositoryRootTest.class);
48
	}
49
50
	private void clearRepositoryRootCache() {
51
		String remotePaths[] = repositoryRoot.getKnownRemotePaths();
52
		for (int i = 0; i < remotePaths.length; i++) {
53
			repositoryRoot.removeTags(remotePaths[i],
54
					repositoryRoot.getAllKnownTags(remotePaths[i]));
55
		}
56
		assertEquals("Repository cache was not cleaned.", 0,
57
				repositoryRoot.getAllKnownTags().length);
58
	}
59
60
	private CVSTag[] refreshTags(IProject project) throws TeamException {
61
		return refreshTags(CVSWorkspaceRoot.getCVSFolderFor(project));
62
	}
63
64
	private CVSTag[] refreshTags(ICVSFolder folder) throws TeamException {
65
		return repositoryManager.refreshDefinedTags(folder, true, true,
66
				DEFAULT_MONITOR);
67
	}
68
69
	private IProject createProject(String baseName, String repoPrefix)
70
			throws CoreException {
71
		// create project
72
		IProject project = getUniqueTestProject(baseName);
73
		// share project under module
74
		shareProject(getRepository(), project,
75
				repoPrefix == null ? project.getName()
76
						: (repoPrefix + "/" + project.getName()),
77
				DEFAULT_MONITOR);
78
		assertValidCheckout(project);
79
		// add some files
80
		addResources(project, new String[] { "file1.txt" }, true);
81
		return project;
82
	}
83
84
	private void assertTags(List knownTags, CVSTag[] tagsToHave,
85
			CVSTag[] tagsNotToHave) {
86
		for (int i = 0; i < tagsToHave.length; i++) {
87
			assertTrue("Missing tag " + tagsToHave[i].getName(),
88
					knownTags.contains(tagsToHave[i]));
89
		}
90
		for (int i = 0; i < tagsNotToHave.length; i++) {
91
			assertFalse("Extraneous tag " + tagsNotToHave[i].getName(),
92
					knownTags.contains(tagsNotToHave[i]));
93
		}
94
	}
95
96
	private void assertProjectTags(CVSCacheTestData data) throws CVSException {
97
		// Root should contain all known tags
98
		List knownTags = Arrays.asList(repositoryRoot.getAllKnownTags());
99
		assertTags(knownTags,
100
				new CVSTag[] { data.branch_1, data.branch_2, data.branch_3,
101
						data.version_1, data.version_2, data.version_3 },
102
				new CVSTag[0]);
103
104
		// Project_1 should contain Branch_1 and Branch_2
105
		knownTags = Arrays.asList(repositoryManager
106
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(data.project1)));
107
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_2,
108
				data.version_1, data.version_2 }, new CVSTag[] { data.branch_3,
109
				data.version_3 });
110
		// Project_2 should contain Branch_1 and Branch_3
111
		knownTags = Arrays.asList(repositoryManager
112
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(data.project2)));
113
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_3,
114
				data.version_1, data.version_3 }, new CVSTag[] { data.branch_2,
115
				data.version_2 });
116
	}
117
118
	private class CVSCacheTestData {
119
		IProject project1; // tagged with Branch_1 and Branch_2
120
		IProject project2; // tagged with Branch_1 and Branch_3
121
		CVSTag branch_1;
122
		CVSTag branch_2;
123
		CVSTag branch_3;
124
		CVSTag version_1;
125
		CVSTag version_2;
126
		CVSTag version_3;
127
128
		private void init(String project1Path, String project2Path)
129
				throws CoreException {
130
			project1 = createProject("Project_1", project1Path);
131
			project2 = createProject("Project_2", project2Path);
132
			branch_1 = new CVSTag("Branch_1" + System.currentTimeMillis(),
133
					CVSTag.BRANCH);
134
			version_1 = new CVSTag("Root_" + branch_1.getName(), CVSTag.VERSION);
135
			branch_2 = new CVSTag("Branch_2" + System.currentTimeMillis(),
136
					CVSTag.BRANCH);
137
			version_2 = new CVSTag("Root_" + branch_2.getName(), CVSTag.VERSION);
138
			branch_3 = new CVSTag("Branch_3" + System.currentTimeMillis(),
139
					CVSTag.BRANCH);
140
			version_3 = new CVSTag("Root_" + branch_3.getName(), CVSTag.VERSION);
141
142
			makeBranch(new IResource[] { project1, project2 }, version_1,
143
					branch_1, true);
144
			makeBranch(new IResource[] { project1 }, version_2, branch_2, true);
145
			makeBranch(new IResource[] { project2 }, version_3, branch_3, true);
146
		}
147
148
		public CVSCacheTestData(String project1Path, String project2Path)
149
				throws CoreException {
150
			init(project1Path, project2Path);
151
		}
152
	}
153
154
	public void testProjectsAtRoot() throws CoreException {
155
		CVSCacheTestData data = new CVSCacheTestData(null, null);
156
157
		// verify that tags are correct after creating branches
158
		assertProjectTags(data);
159
160
		clearRepositoryRootCache();
161
		refreshTags(data.project1);
162
		refreshTags(data.project2);
163
		assertProjectTags(data);
164
	}
165
166
	public void testProjectsInSubmodule() throws CoreException {
167
		String submodule = "Submodule_1" + System.currentTimeMillis();
168
		CVSCacheTestData data = new CVSCacheTestData(submodule, submodule);
169
		ICVSFolder submoduleFolder = repositoryRoot.getRemoteFolder(submodule,
170
				null, getMonitor());
171
172
		// verify that tags are correct after creating branches
173
		assertProjectTags(data);
174
175
		clearRepositoryRootCache();
176
		refreshTags(data.project1);
177
		refreshTags(data.project2);
178
		assertProjectTags(data);
179
		// verify that parent module has tags from both projects
180
		List knownTags = Arrays.asList(repositoryManager
181
				.getKnownTags(submoduleFolder));
182
		assertTags(knownTags,
183
				new CVSTag[] { data.branch_1, data.branch_2, data.branch_3,
184
						data.version_1, data.version_2, data.version_3 },
185
				new CVSTag[0]);
186
187
		clearRepositoryRootCache();
188
		refreshTags(submoduleFolder);
189
		assertProjectTags(data);
190
		// verify that parent module has tags from both projects
191
		knownTags = Arrays.asList(repositoryManager
192
				.getKnownTags(submoduleFolder));
193
		assertTags(knownTags,
194
				new CVSTag[] { data.branch_1, data.branch_2, data.branch_3,
195
						data.version_1, data.version_2, data.version_3 },
196
				new CVSTag[0]);
197
	}
198
199
	public void testProjectsInTwoSubmodules() throws CoreException {
200
		String submodule1 = "Submodule_1" + System.currentTimeMillis();
201
		String submodule2 = "Submodule_2" + System.currentTimeMillis();
202
		CVSCacheTestData data = new CVSCacheTestData(submodule1, submodule2);
203
		ICVSFolder submoduleFolder1 = repositoryRoot.getRemoteFolder(
204
				submodule1, null, getMonitor());
205
		ICVSFolder submoduleFolder2 = repositoryRoot.getRemoteFolder(
206
				submodule2, null, getMonitor());
207
208
		// verify that tags are correct after creating branches
209
		assertProjectTags(data);
210
211
		clearRepositoryRootCache();
212
		refreshTags(data.project1);
213
		refreshTags(data.project2);
214
		assertProjectTags(data);
215
		// verify that parent modules have tags from subordinate project, but
216
		// not the other project
217
		List knownTags = Arrays.asList(repositoryManager
218
				.getKnownTags(submoduleFolder1));
219
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_2,
220
				data.version_1, data.version_2 }, new CVSTag[] { data.branch_3,
221
				data.version_3 });
222
		knownTags = Arrays.asList(repositoryManager
223
				.getKnownTags(submoduleFolder2));
224
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_3,
225
				data.version_1, data.version_3 }, new CVSTag[] { data.branch_2,
226
				data.version_2 });
227
		// clear the cache, refresh it only one for submodule and verify if tags
228
		// are correct
229
		clearRepositoryRootCache();
230
		refreshTags(submoduleFolder1);
231
232
		// verify that correct tags where added to this submodule
233
		knownTags = Arrays.asList(repositoryManager
234
				.getKnownTags(submoduleFolder1));
235
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_2,
236
				data.version_1, data.version_2 }, new CVSTag[] { data.branch_3,
237
				data.version_3 });
238
		// verify if only tags from the first submodule are known
239
		knownTags = Arrays.asList(repositoryRoot.getAllKnownTags());
240
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_2,
241
				data.version_1, data.version_2 }, new CVSTag[] { data.branch_3,
242
				data.version_3 });
243
244
		refreshTags(submoduleFolder2);
245
		// verify tags for the second submodule
246
		knownTags = Arrays.asList(repositoryManager
247
				.getKnownTags(submoduleFolder2));
248
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_3,
249
				data.version_1, data.version_3 }, new CVSTag[] { data.branch_2,
250
				data.version_2 });
251
		// verify if tags are merged correctly
252
		assertProjectTags(data);
253
	}
254
255
	public void testNestedProjects() throws CoreException {
256
		IProject superProject = createProject("SuperProject", (String) null);
257
		CVSTag superProjectBranch = new CVSTag("Branch_"
258
				+ superProject.getName(), CVSTag.BRANCH);
259
		CVSTag superProjectVersion = new CVSTag("Root_"
260
				+ superProjectBranch.getName(), CVSTag.VERSION);
261
		makeBranch(new IResource[] { superProject }, superProjectVersion,
262
				superProjectBranch, true);
263
		// subProject1 and subProject2 are nested in superProject
264
		// each of them has its own tags
265
		IProject subProject1 = createProject("SubProject_1",
266
				superProject.getName());
267
		CVSTag subProject1Branch = new CVSTag(
268
				"Branch_" + subProject1.getName(), CVSTag.BRANCH);
269
		CVSTag subProject1Version = new CVSTag("Root_"
270
				+ subProject1Branch.getName(), CVSTag.VERSION);
271
		makeBranch(new IResource[] { subProject1 }, subProject1Version,
272
				subProject1Branch, true);
273
		IProject subProject2 = createProject("SubProject_2",
274
				superProject.getName());
275
		CVSTag subProject2Branch = new CVSTag(
276
				"Branch_" + subProject2.getName(), CVSTag.BRANCH);
277
		CVSTag subProject2Version = new CVSTag("Root_"
278
				+ subProject2Branch.getName(), CVSTag.VERSION);
279
		makeBranch(new IResource[] { subProject2 }, subProject2Version,
280
				subProject2Branch, true);
281
		// check if subProjects have tags from superProject but not tags from
282
		// each other, check if superProject has tags from all subProjects
283
		List knownTags = Arrays.asList(repositoryManager
284
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(superProject)));
285
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
286
				superProjectVersion, subProject1Branch, subProject1Version,
287
				subProject2Branch, subProject2Version }, new CVSTag[0]);
288
		knownTags = Arrays.asList(repositoryManager
289
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(subProject1)));
290
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
291
				superProjectVersion, subProject1Branch, subProject1Version },
292
				new CVSTag[] { subProject2Branch, subProject2Version });
293
		knownTags = Arrays.asList(repositoryManager
294
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(subProject2)));
295
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
296
				superProjectVersion, subProject2Branch, subProject2Version },
297
				new CVSTag[] { subProject1Branch, subProject1Version });
298
		// remove tag from one of the subProjects, check if it was not removed
299
		// from the other subProject, check if superProject still has this tag
300
		repositoryManager.removeTags(
301
				CVSWorkspaceRoot.getCVSFolderFor(subProject1), new CVSTag[] {
302
						superProjectBranch, superProjectVersion });
303
		knownTags = Arrays.asList(repositoryManager
304
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(superProject)));
305
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
306
				superProjectVersion, subProject1Branch, subProject1Version,
307
				subProject2Branch, subProject2Version }, new CVSTag[0]);
308
		knownTags = Arrays.asList(repositoryManager
309
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(subProject1)));
310
		assertTags(knownTags, new CVSTag[] { subProject1Branch,
311
				subProject1Version }, new CVSTag[] { subProject2Branch,
312
				subProject2Version });
313
		knownTags = Arrays.asList(repositoryManager
314
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(subProject2)));
315
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
316
				superProjectVersion, subProject2Branch, subProject2Version },
317
				new CVSTag[] { subProject1Branch, subProject1Version });
318
	}
319
320
	public void testTagsForSubfolder() throws TeamException, CoreException {
321
		IProject project = createProject("Project_1", (String) null);
322
		String folderName = "testFolder";
323
		addResources(project, new String[] { folderName + "/",
324
				folderName + "/testFile.txt" }, true);
325
		IFolder folder = project.getFolder(folderName);
326
		CVSTag branch1 = new CVSTag("Branch_1" + System.currentTimeMillis(),
327
				CVSTag.BRANCH);
328
		CVSTag version1 = new CVSTag("Root_" + branch1.getName(),
329
				CVSTag.VERSION);
330
		makeBranch(new IResource[] { project }, version1, branch1, true);
331
		// verify if project's tags are known for subfolder
332
		ICVSFolder cvsFolder = CVSWorkspaceRoot.getCVSFolderFor(folder);
333
		List knownTags = Arrays.asList(repositoryManager
334
				.getKnownTags(cvsFolder));
335
		assertTags(knownTags, new CVSTag[] { branch1, version1 }, new CVSTag[0]);
336
		// verify if removing tags from subfolder is correctly handled
337
		repositoryManager.removeTags(cvsFolder, new CVSTag[] { branch1,
338
				version1 });
339
		knownTags = Arrays.asList(repositoryManager.getKnownTags(cvsFolder));
340
		assertTags(knownTags, new CVSTag[0], new CVSTag[] { branch1, version1 });
341
		// verify if after refreshing tags are back for both project and its
342
		// subfolder
343
		refreshTags(cvsFolder);
344
		knownTags = Arrays.asList(repositoryManager.getKnownTags(cvsFolder));
345
		assertTags(knownTags, new CVSTag[] { branch1, version1 }, new CVSTag[0]);
346
		knownTags = Arrays.asList(repositoryManager
347
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(project)));
348
		assertTags(knownTags, new CVSTag[] { branch1, version1 }, new CVSTag[0]);
349
	}
350
351
	public void testRefreshProjectUsingAutoRefreshFile() throws CoreException {
352
		IProject project = createProject("Project_1", (String) null);
353
		String autoRefreshFileName = "sampleAuthoRefresh.txt";
354
		String notAutoRefreshFileName = "notAutoRefresh.txt";
355
		addResources(project, new String[] { autoRefreshFileName,
356
				notAutoRefreshFileName }, true);
357
		IFile autoRefreshFile = project.getFile(autoRefreshFileName);
358
		IFile notAutoRefreshFile = project.getFile(notAutoRefreshFileName);
359
		repositoryManager.setAutoRefreshFiles(
360
				CVSWorkspaceRoot.getCVSFolderFor(project),
361
				new String[] { CVSWorkspaceRoot.getCVSResourceFor(
362
						autoRefreshFile).getRepositoryRelativePath() });
363
		CVSTag branch1 = new CVSTag("Branch_1" + System.currentTimeMillis(),
364
				CVSTag.BRANCH);
365
		CVSTag version1 = new CVSTag("Root_" + branch1.getName(),
366
				CVSTag.VERSION);
367
		// branch the auto refresh file
368
		makeBranch(new IResource[] { autoRefreshFile }, version1, branch1, true);
369
		CVSTag branch2 = new CVSTag("Branch_2" + System.currentTimeMillis(),
370
				CVSTag.BRANCH);
371
		CVSTag version2 = new CVSTag("Root_" + branch2.getName(),
372
				CVSTag.VERSION);
373
		// branch not auto refresh file
374
		makeBranch(new IResource[] { notAutoRefreshFile }, version2, branch2,
375
				true);
376
377
		clearRepositoryRootCache();
378
		refreshTags(project);
379
380
		// cache should contain branches from auto refresh file, but no branches
381
		// from other files
382
		List knownTags = Arrays.asList(repositoryManager
383
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(project)));
384
		assertTags(knownTags, new CVSTag[] { branch1, version1 }, new CVSTag[] {
385
				branch2, version2 });
386
	}
387
388
	public void testProjectWithNoTags() throws CoreException {
389
		IProject project = createProject("Project_1", (String) null);
390
		CVSTag knownTags[] = repositoryManager.getKnownTags(CVSWorkspaceRoot
391
				.getCVSFolderFor(project));
392
		assertEquals(0, knownTags.length);
393
		knownTags = refreshTags(project);
394
		assertEquals(0, knownTags.length);
395
	}
396
397
}
(-)a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/RepositoriesViewTests.java (+254 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.ui;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.team.core.TeamException;
20
import org.eclipse.team.internal.ccvs.core.CVSTag;
21
import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
22
import org.eclipse.team.internal.ccvs.core.resources.RemoteResource;
23
import org.eclipse.team.internal.ccvs.ui.model.AllRootsElement;
24
import org.eclipse.team.internal.ccvs.ui.model.BranchCategory;
25
import org.eclipse.team.internal.ccvs.ui.model.CVSTagElement;
26
import org.eclipse.team.internal.ccvs.ui.model.RemoteContentProvider;
27
import org.eclipse.team.internal.ccvs.ui.model.RemoteModule;
28
import org.eclipse.team.internal.ccvs.ui.model.VersionCategory;
29
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot;
30
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;
31
import org.eclipse.team.tests.ccvs.core.EclipseTest;
32
33
public class RepositoriesViewTests extends EclipseTest {
34
35
	public RepositoriesViewTests(String testName) {
36
		super(testName);
37
	}
38
39
	protected void setUp() throws Exception {
40
		super.setUp();
41
		// clear repository root cache
42
		RepositoryRoot repositoryRoot = getRepositoryRoot();
43
		String remotePaths[] = repositoryRoot.getKnownRemotePaths();
44
		for (int i = 0; i < remotePaths.length; i++) {
45
			repositoryRoot.removeTags(remotePaths[i],
46
					repositoryRoot.getAllKnownTags(remotePaths[i]));
47
		}
48
	}
49
50
	private RepositoryRoot getRepositoryRoot() {
51
		RemoteContentProvider rcp = new RemoteContentProvider();
52
		AllRootsElement are = new AllRootsElement();
53
		Object[] repositoryRoots = rcp.getElements(are);
54
		for (int i = 0; i < repositoryRoots.length; i++) {
55
			RepositoryRoot repositoryRoot = (RepositoryRoot) repositoryRoots[i];
56
			if (getRepository().equals(repositoryRoot.getRoot())) {
57
				return repositoryRoot;
58
			}
59
		}
60
		fail(getRepository() + " not found");
61
		return null;
62
	}
63
64
	public static Test suite() {
65
		String testName = System.getProperty("eclipse.cvs.testName");
66
		if (testName == null) {
67
			TestSuite suite = new TestSuite(RepositoriesViewTests.class);
68
			return new CVSTestSetup(suite);
69
		} else {
70
			return new CVSTestSetup(new RepositoriesViewTests(testName));
71
		}
72
	}
73
74
	public void testBranchSubmoduleChildren() throws TeamException,
75
			CoreException {
76
77
		String time = Long.toString(System.currentTimeMillis());
78
		String moduleName = "TestBranchSubmoduleChildrenTestModule" + time;
79
		String branchName = "TestBranchSubmoduleChildrenBranch" + time;
80
		String versionName = "Root_" + branchName;
81
82
		// create project
83
		IProject project = getUniqueTestProject("TestBranchSubmoduleChildrenProject");
84
		// share project under module
85
		shareProject(getRepository(), project,
86
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
87
		assertValidCheckout(project);
88
89
		// add some files
90
		addResources(project, new String[] { "file1.txt" }, true);
91
92
		// make branch
93
		CVSTag version = new CVSTag(versionName, CVSTag.VERSION);
94
		CVSTag branch = new CVSTag(branchName, CVSTag.BRANCH);
95
96
		makeBranch(new IResource[] { project }, version, branch, true);
97
98
		// check if module is the only branch child
99
		RemoteContentProvider rcp = new RemoteContentProvider();
100
		Object[] categories = rcp.getChildren(getRepositoryRoot());
101
		assertEquals(4, categories.length);
102
		assertTrue(categories[1] instanceof BranchCategory);
103
		Object[] branches = rcp.getChildren(categories[1]);
104
		assertEquals(1, branches.length);
105
		assertEquals(branchName, ((CVSTagElement) (branches[0])).getTag()
106
				.getName());
107
		Object[] modules = rcp.getChildren(branches[0]);
108
		assertEquals(1, modules.length);
109
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
110
111
		// check if after refresh module is still the only branch child
112
		branches = rcp.getChildren(categories[1]);
113
		assertEquals(1, branches.length);
114
		assertEquals(branchName, ((CVSTagElement) (branches[0])).getTag()
115
				.getName());
116
		modules = rcp.getChildren(branches[0]);
117
		assertEquals(1, modules.length);
118
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
119
	}
120
121
	public void testTagSubmoduleChildren() throws TeamException, CoreException {
122
123
		String time = Long.toString(System.currentTimeMillis());
124
		String moduleName = "TestTagSubmoduleChildrenTestModule" + time;
125
		String versionName = "TestTagSubmoduleChildrenBranch" + time;
126
127
		// create project
128
		IProject project = getUniqueTestProject("TestTagSubmoduleChildrenProject");
129
		// share project under module
130
		shareProject(getRepository(), project,
131
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
132
		assertValidCheckout(project);
133
134
		// make some changes
135
		addResources(project, new String[] { "file1.txt" }, true);
136
137
		// tag project
138
		CVSTag tag = new CVSTag(versionName, CVSTag.VERSION);
139
140
		tagProject(project, tag, true);
141
142
143
		RemoteContentProvider rcp = new RemoteContentProvider();
144
		Object[] categories = rcp.getChildren(getRepositoryRoot());
145
		assertEquals(4, categories.length);
146
147
		// check if version exists for module
148
		assertTrue(categories[2] instanceof VersionCategory);
149
		Object[] modules = rcp.getChildren(categories[2]);
150
		for (int i = 0; i < modules.length; i++) {
151
			if (modules[i] instanceof RemoteModule
152
					&& ((RemoteModule) (modules[i])).getCVSResource().getName()
153
							.equals(moduleName)) {
154
				Object folders[] = rcp.getChildren(modules[i]);
155
				assertEquals(1, folders.length);
156
				assertEquals(versionName, ((RemoteFolder) folders[0]).getTag()
157
						.getName());
158
				return;
159
			}
160
		}
161
		fail(moduleName + " not found");
162
	}
163
164
	public void testTagsOnDifferentLevels() throws CoreException {
165
		String time = Long.toString(System.currentTimeMillis());
166
		String firstModule = "Module_1" + time;
167
		String secondModule = "Module_2" + time;
168
		String secondModulePath = firstModule + "/" + secondModule;
169
		// Create repository data
170
		// Module_1/Project_1
171
		IProject project1 = getUniqueTestProject("Project_1");
172
		shareProject(getRepository(), project1,
173
				firstModule + "/" + project1.getName(), DEFAULT_MONITOR);
174
		// Module_1/Module_2/Project_2
175
		IProject project2 = getUniqueTestProject("Project_2");
176
		shareProject(getRepository(), project2, secondModulePath + "/"
177
				+ project2.getName(), DEFAULT_MONITOR);
178
		// Module_1/Module_2/Project_3
179
		IProject project3 = getUniqueTestProject("Project_3");
180
		shareProject(getRepository(), project3, secondModulePath + "/"
181
				+ project3.getName(), DEFAULT_MONITOR);
182
		// Module_1/Project_4
183
		IProject project4 = getUniqueTestProject("Project_4");
184
		shareProject(getRepository(), project4,
185
				firstModule + "/" + project4.getName(), DEFAULT_MONITOR);
186
187
		// Create branches
188
		String branch1 = "Branch_1" + time;
189
		String version1 = "Root_" + branch1;
190
		String branch2 = "Branch_2" + time;
191
		String version2 = "Root_" + branch2;
192
193
		// Tag projects:
194
		// Module_1/Project_1 -> [Branch_1][Branch_2]
195
		// Module_1/Module_2/Project_2 -> [Branch_1][Branch_2]
196
		// Module_1/Module_2/Project_3 -> [Branch_2]
197
		// Module_1/Project_4 -> [Branch_4]
198
		makeBranch(new IResource[] { project1, project2 }, new CVSTag(version1,
199
				CVSTag.VERSION), new CVSTag(branch1, CVSTag.BRANCH), true);
200
		makeBranch(new IResource[] { project1, project2, project2, project4 },
201
				new CVSTag(version2, CVSTag.VERSION), new CVSTag(branch2,
202
						CVSTag.BRANCH), true);
203
204
		// verify if tree structure is built from cache
205
		RemoteContentProvider rcp = new RemoteContentProvider();
206
		Object[] categories = rcp.getChildren(getRepositoryRoot());
207
		assertEquals(4, categories.length);
208
		assertTrue(categories[1] instanceof BranchCategory);
209
		Object[] branches = rcp.getChildren(categories[1]);
210
		assertEquals(2, branches.length); // should be [Branch_1] and [Branch_2]
211
		CVSTagElement branch1Element;
212
		CVSTagElement branch2Element;
213
		if (((CVSTagElement) branches[0]).getTag().getName().equals(branch1)) {
214
			branch1Element = (CVSTagElement) branches[0];
215
			branch2Element = (CVSTagElement) branches[1];
216
		} else {
217
			branch1Element = (CVSTagElement) branches[1];
218
			branch2Element = (CVSTagElement) branches[0];
219
		}
220
		Object[] modules = rcp.getChildren(branch1Element);
221
		assertEquals(1, modules.length); // should be [Branch_1]/Module_1
222
		assertEquals(firstModule, ((RemoteResource) modules[0]).getName());
223
		modules = rcp.getChildren(modules[0]);
224
		// should contain:
225
		// [Branch_1]/Module_1/Project_1
226
		// [Branch_1]/Module_1/Module_2
227
		assertEquals(2, modules.length);
228
		for (int i = 0; i < modules.length; i++) {
229
			if (((RemoteResource) (modules[i])).getName().equals(
230
					project1.getName())) {
231
				// Project_1 should have contents retrieved from CVS
232
				assertTrue(rcp.hasChildren(modules[i]));
233
			} else if (((RemoteResource) (modules[i])).getName().equals(
234
					secondModule)) {
235
				// should be only [Branch_1]/Module_1/Module_2/Project_2.
236
				// [Branch_1]/Module_1/Module_2/Project_3 should NOT be on the
237
				// list, it is not branched with Branch_1
238
				Object[] module2Children = rcp.getChildren(modules[i]);
239
				assertEquals(1, module2Children.length);
240
				assertEquals(project2.getName(),
241
						((RemoteResource) module2Children[0]).getName());
242
			}
243
		}
244
		modules = rcp.getChildren(branch2Element);
245
		assertEquals(1, modules.length); // should be [Branch_2]/Module_1
246
		assertEquals(firstModule, ((RemoteResource) modules[0]).getName());
247
		// should contain:
248
		// [Branch_2]/Module_1/Project_1
249
		// [Branch_2]/Module_1/Module_2
250
		// [Branch_2]/Module_1/Project_4
251
		modules = rcp.getChildren(modules[0]);
252
		assertEquals(3, modules.length);
253
	}
254
}

Return to bug 374516