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 306508 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ccvs/ui/subscriber/SafeUpdateOperation.java (-14 / +77 lines)
Lines 11-43 Link Here
11
package org.eclipse.team.internal.ccvs.ui.subscriber;
11
package org.eclipse.team.internal.ccvs.ui.subscriber;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
14
import java.util.*;
15
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Set;
18
15
19
import org.eclipse.compare.structuremergeviewer.IDiffElement;
16
import org.eclipse.compare.structuremergeviewer.IDiffElement;
20
import org.eclipse.core.resources.*;
17
import org.eclipse.core.resources.*;
18
import org.eclipse.core.resources.mapping.ResourceMapping;
19
import org.eclipse.core.resources.mapping.ResourceMappingContext;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.jobs.ISchedulingRule;
23
import org.eclipse.core.runtime.jobs.MultiRule;
22
import org.eclipse.jface.dialogs.MessageDialog;
24
import org.eclipse.jface.dialogs.MessageDialog;
23
import org.eclipse.osgi.util.NLS;
25
import org.eclipse.osgi.util.NLS;
24
import org.eclipse.team.core.TeamException;
26
import org.eclipse.team.core.TeamException;
25
import org.eclipse.team.core.synchronize.FastSyncInfoFilter;
27
import org.eclipse.team.core.mapping.provider.SynchronizationScopeManager;
26
import org.eclipse.team.core.synchronize.SyncInfo;
28
import org.eclipse.team.core.synchronize.*;
27
import org.eclipse.team.core.synchronize.SyncInfoSet;
29
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.*;
28
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.AndSyncInfoFilter;
29
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.OrSyncInfoFilter;
30
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
31
import org.eclipse.team.core.variants.IResourceVariant;
30
import org.eclipse.team.core.variants.IResourceVariant;
32
import org.eclipse.team.internal.ccvs.core.CVSException;
31
import org.eclipse.team.internal.ccvs.core.*;
33
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
34
import org.eclipse.team.internal.ccvs.core.ICVSFile;
35
import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
32
import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
36
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
33
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
34
import org.eclipse.team.internal.ccvs.core.resources.EclipseSynchronizer;
37
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
35
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
38
import org.eclipse.team.internal.ccvs.ui.*;
36
import org.eclipse.team.internal.ccvs.ui.*;
39
import org.eclipse.team.internal.ccvs.ui.operations.UpdateOnlyMergableOperation;
37
import org.eclipse.team.internal.ccvs.ui.Policy;
38
import org.eclipse.team.internal.ccvs.ui.operations.*;
40
import org.eclipse.team.internal.ui.TeamUIPlugin;
39
import org.eclipse.team.internal.ui.TeamUIPlugin;
40
import org.eclipse.team.internal.ui.Utils;
41
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
41
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
42
42
43
/**
43
/**
Lines 64-69 Link Here
64
	public boolean shouldRun() {
64
	public boolean shouldRun() {
65
		return promptIfNeeded();
65
		return promptIfNeeded();
66
	}
66
	}
67
68
	/**
69
	 * Run the operation for the sync infos from the given project. By default, a lock
70
	 * is acquired on the project.
71
	 * @param projectSyncInfos the project syncInfos
72
	 * @param project the project
73
	 * @param monitor a progress monitor
74
	 * @throws InvocationTargetException
75
	 */
76
	protected void run(final Map projectSyncInfos, final IProject project,
77
			IProgressMonitor monitor) throws InvocationTargetException {
78
		try {
79
			IResource[] resources = getIResourcesFrom(((SyncInfoSet) projectSyncInfos
80
					.get(project)).getSyncInfos());
81
			ResourceMapping[] selectedMappings = Utils
82
					.getResourceMappings(resources);
83
			ResourceMappingContext context = new SingleProjectSubscriberContext(
84
					CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber(),
85
					false, project);
86
			SynchronizationScopeManager manager = new SingleProjectScopeManager(
87
					getJobName(), selectedMappings, context, true, project);
88
			manager.initialize(null);
89
			ISchedulingRule updateRule = getUpdateRule(manager);
90
91
			// Pass the scheduling rule to the synchronizer so that sync change
92
			// events
93
			// and cache commits to disk are batched
94
			EclipseSynchronizer.getInstance().run(updateRule,
95
					new ICVSRunnable() {
96
						public void run(IProgressMonitor monitor)
97
								throws CVSException {
98
							try {
99
								runWithProjectRule(project,
100
										(SyncInfoSet) projectSyncInfos
101
												.get(project), monitor);
102
							} catch (TeamException e) {
103
								throw CVSException.wrapException(e);
104
							}
105
						}
106
					}, Policy.subMonitorFor(monitor, 100));
107
		} catch (TeamException e) {
108
			throw new InvocationTargetException(e);
109
		} catch (CoreException e) {
110
			throw new InvocationTargetException(e);
111
		}
112
	}
113
114
	private ISchedulingRule getUpdateRule(SynchronizationScopeManager manager) {
115
		ISchedulingRule rule = null;
116
		ResourceMapping[] mappings = manager.getScope().getMappings();
117
		for (int i = 0; i < mappings.length; i++) {
118
			ResourceMapping mapping = mappings[i];
119
			IProject[] mappingProjects = mapping.getProjects();
120
			for (int j = 0; j < mappingProjects.length; j++) {
121
				if (rule == null) {
122
					rule = mappingProjects[j];
123
				} else {
124
					rule = MultiRule.combine(rule, mappingProjects[j]);
125
				}
126
			}
127
		}
128
		return rule;
129
	}
67
	
130
	
68
	/* (non-Javadoc)
131
	/* (non-Javadoc)
69
	 * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#run(org.eclipse.core.runtime.IProgressMonitor)
132
	 * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#run(org.eclipse.core.runtime.IProgressMonitor)
(-)src/org/eclipse/team/tests/ccvs/core/subscriber/TestUpdateOperation.java (-1 / +45 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 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 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.core.subscriber;
11
package org.eclipse.team.tests.ccvs.core.subscriber;
12
12
13
import java.lang.reflect.InvocationTargetException;
14
13
import org.eclipse.compare.structuremergeviewer.IDiffElement;
15
import org.eclipse.compare.structuremergeviewer.IDiffElement;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.team.core.TeamException;
20
import org.eclipse.team.core.mapping.ISynchronizationScope;
14
import org.eclipse.team.core.synchronize.SyncInfoSet;
21
import org.eclipse.team.core.synchronize.SyncInfoSet;
22
import org.eclipse.team.internal.ccvs.core.CVSException;
23
import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
24
import org.eclipse.team.internal.ccvs.ui.Policy;
25
import org.eclipse.team.internal.ccvs.ui.operations.UpdateOnlyMergableOperation;
15
import org.eclipse.team.internal.ccvs.ui.subscriber.WorkspaceUpdateOperation;
26
import org.eclipse.team.internal.ccvs.ui.subscriber.WorkspaceUpdateOperation;
27
import org.eclipse.team.internal.ui.mapping.BuildScopeOperation;
16
import org.eclipse.team.tests.ccvs.core.EclipseTest;
28
import org.eclipse.team.tests.ccvs.core.EclipseTest;
29
import org.eclipse.team.tests.ccvs.ui.ReflectionUtils;
17
30
18
class TestUpdateOperation extends WorkspaceUpdateOperation {
31
class TestUpdateOperation extends WorkspaceUpdateOperation {
19
32
Lines 42-45 Link Here
42
		EclipseTest.fail("Should never prompt on update, simply update nodes that are valid.");
55
		EclipseTest.fail("Should never prompt on update, simply update nodes that are valid.");
43
		return false;
56
		return false;
44
	}
57
	}
58
	
59
	protected void safeUpdate(IProject project, IResource[] resources, LocalOption[] localOptions, IProgressMonitor monitor) throws TeamException {
60
		try {
61
			UpdateOnlyMergableOperation operation = new UpdateOnlyMergableOperation(getPart(), project, resources, localOptions) {
62
				public ISynchronizationScope buildScope(IProgressMonitor monitor) throws InterruptedException, CVSException {
63
			    	if (getScopeManager() == null) {
64
			    		// manager = createScopeManager(consultModelsWhenBuildingScope && consultModelsForMappings());
65
			    		ReflectionUtils.setField(this, "manager", createScopeManager(consultModelsWhenBuildingScope && consultModelsForMappings()));
66
			    		BuildScopeOperation op = new BuildScopeOperation(getPart(), getScopeManager()) {
67
							protected boolean promptForInputChange(String requestPreviewMessage, IProgressMonitor monitor) {
68
								return false; // do not prompt
69
							}
70
						};
71
						try {
72
							op.run(monitor);
73
						} catch (InvocationTargetException e) {
74
							throw CVSException.wrapException(e);
75
						}
76
			    	}
77
			    	return getScope();
78
				}
79
			};
80
			operation.run(monitor);
81
			// addSkippedFiles(operation.getSkippedFiles());
82
			ReflectionUtils.callMethod(this, "addSkippedFiles", new Object[] {operation.getSkippedFiles()});
83
		} catch (InvocationTargetException e) {
84
			throw CVSException.wrapException(e);
85
		} catch (InterruptedException e) {
86
			Policy.cancelOperation();
87
		}
88
	}
45
}
89
}
(-)src/org/eclipse/team/tests/ccvs/core/subscriber/CVSWorkspaceSubscriberTest.java (-4 / +86 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 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 13-36 Link Here
13
import java.io.ByteArrayInputStream;
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.lang.reflect.InvocationTargetException;
15
import java.lang.reflect.InvocationTargetException;
16
import java.util.*;
16
import java.util.Arrays;
17
import java.util.HashSet;
18
import java.util.Set;
17
19
18
import junit.framework.Test;
20
import junit.framework.Test;
19
import junit.framework.TestSuite;
21
import junit.framework.TestSuite;
20
22
21
import org.eclipse.core.resources.*;
23
import org.eclipse.core.resources.IContainer;
24
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.IFolder;
26
import org.eclipse.core.resources.IProject;
27
import org.eclipse.core.resources.IProjectDescription;
28
import org.eclipse.core.resources.IResource;
29
import org.eclipse.core.resources.IResourceVisitor;
30
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.core.runtime.Path;
33
import org.eclipse.core.runtime.Path;
24
import org.eclipse.team.core.RepositoryProvider;
34
import org.eclipse.team.core.RepositoryProvider;
25
import org.eclipse.team.core.TeamException;
35
import org.eclipse.team.core.TeamException;
26
import org.eclipse.team.core.subscribers.ISubscriberChangeEvent;
36
import org.eclipse.team.core.subscribers.ISubscriberChangeEvent;
27
import org.eclipse.team.core.synchronize.SyncInfo;
37
import org.eclipse.team.core.synchronize.SyncInfo;
28
import org.eclipse.team.internal.ccvs.core.*;
38
import org.eclipse.team.internal.ccvs.core.CVSException;
39
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
40
import org.eclipse.team.internal.ccvs.core.CVSSyncTreeSubscriber;
41
import org.eclipse.team.internal.ccvs.core.CVSTag;
42
import org.eclipse.team.internal.ccvs.core.CVSTeamProvider;
43
import org.eclipse.team.internal.ccvs.core.ICVSFile;
44
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
45
import org.eclipse.team.internal.ccvs.core.ICVSResource;
29
import org.eclipse.team.internal.ccvs.core.client.Command;
46
import org.eclipse.team.internal.ccvs.core.client.Command;
30
import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption;
47
import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption;
31
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
48
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
32
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
49
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
50
import org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation;
33
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;
51
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;
52
import org.eclipse.team.tests.ccvs.core.mappings.model.ModelProject;
53
import org.eclipse.team.tests.ccvs.core.mappings.model.mapping.ModelResourceMapping;
54
import org.eclipse.team.tests.ccvs.ui.ModelParticipantSyncInfoSource;
34
55
35
/**
56
/**
36
 * This class tests the CVSWorkspaceSubscriber
57
 * This class tests the CVSWorkspaceSubscriber
Lines 277-282 Link Here
277
	 * Tests
298
	 * Tests
278
	 ******************************************************************/
299
	 ******************************************************************/
279
	
300
	
301
	public void testBug302163WithoutModel() throws CoreException {
302
		// Create a test project
303
		IProject modelProject = getUniqueTestProject("test1");
304
		buildResources(modelProject, new String[] { "file.mod", "f1.moe" }, true);
305
		modelProject.getFile("file.mod").setContents(new ByteArrayInputStream(("\nf1.moe").getBytes()), false, true, null);
306
		shareProject(modelProject);
307
		assertValidCheckout(modelProject);
308
		
309
		// Checkout and modify a copy
310
		IProject copyModelProject = checkoutCopy(modelProject, "-copy");	
311
		copyModelProject.getFile("file.mod").setContents(new ByteArrayInputStream(("\nf1.moe\nf2.moe").getBytes()), false, true, null);
312
		commitProject(copyModelProject);
313
314
		refresh(getSubscriber(), modelProject);
315
		
316
		RepositoryProviderOperation.consultModelsWhenBuildingScope = true;
317
		setSyncSource(new SyncInfoSource());
318
		// Update
319
		try {
320
			update(modelProject, new String[] { "file.mod" });
321
		} catch (CVSException e) {
322
			fail("Update without models failed", e);
323
		}
324
		// Reset settings
325
		RepositoryProviderOperation.consultModelsWhenBuildingScope = false;
326
		setSyncSource(new ModelParticipantSyncInfoSource());
327
	}
328
	
329
	public void testBug302163WithModel() throws CoreException {
330
		// Create a test project
331
		IProject project = createProject("test", new String[] { "file1.txt" });
332
		ModelResourceMapping.projectName = project.getName();
333
		
334
		// Create a test model project
335
		IProject modelProject = getUniqueTestProject("test1");
336
		buildResources(modelProject, new String[] { "file.mod", "f1.moe" }, true);
337
		modelProject.getFile("file.mod").setContents(new ByteArrayInputStream(("\nf1.moe").getBytes()), false, true, null);
338
		ModelProject.makeModProject(modelProject, new NullProgressMonitor());
339
		shareProject(modelProject);
340
		assertValidCheckout(modelProject);
341
		
342
		// Checkout and modify a copy of the model project
343
		IProject copyModelProject = checkoutCopy(modelProject, "-copy");	
344
		copyModelProject.getFile("file.mod").setContents(new ByteArrayInputStream(("\nf1.moe\nf2.moe").getBytes()), false, true, null);
345
		commitProject(copyModelProject);
346
347
		refresh(getSubscriber(), modelProject);
348
		
349
		RepositoryProviderOperation.consultModelsWhenBuildingScope = true;
350
		setSyncSource(new SyncInfoSource());
351
		// Update
352
		try {
353
			update(modelProject, new String[] { "file.mod" });
354
		} catch (CVSException e) {
355
			fail("Update without models failed", e);
356
		}
357
		// Reset settings		
358
		RepositoryProviderOperation.consultModelsWhenBuildingScope = false;
359
		setSyncSource(new ModelParticipantSyncInfoSource());
360
	}
361
	
280
	/*
362
	/*
281
	 * Perform a simple test that checks for the different types of incoming changes
363
	 * Perform a simple test that checks for the different types of incoming changes
282
	 */
364
	 */
(-)src/org/eclipse/team/tests/ccvs/ui/ReflectionUtils.java (-30 / +98 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 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 14-56 Link Here
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
import java.lang.reflect.Method;
15
import java.lang.reflect.Method;
16
16
17
import org.eclipse.team.tests.ccvs.core.EclipseTest;
18
17
public class ReflectionUtils {
19
public class ReflectionUtils {
18
20
19
	public static Object callMethod(Object object, String name, Object args[])
21
	public static Object callMethod(Object object, String name, Object args[]) {
20
			throws IllegalArgumentException, IllegalAccessException,
22
		try {
21
			InvocationTargetException, NoSuchMethodException {
23
			Class types[] = new Class[args.length];
22
		Class types[] = new Class[args.length];
24
			for (int i = 0; i < args.length; i++) {
23
		for (int i = 0; i < args.length; i++) {
25
				types[i] = args[i].getClass();
24
			types[i] = args[i].getClass();
26
			}
25
		}
27
			Method method = null;
26
		Method method = null;
28
			Class clazz = object.getClass();
27
		Class clazz = object.getClass();
29
			NoSuchMethodException ex = null;
28
		NoSuchMethodException ex = null;
30
			while (method == null && clazz != null) {
29
		while (method == null && clazz != null) {
31
				try {
30
			try {
32
					method = clazz.getDeclaredMethod(name, types);
31
				method = clazz.getDeclaredMethod(name, types);
33
				} catch (NoSuchMethodException e) {
32
			} catch (NoSuchMethodException e) {
34
					if (ex == null) {
33
				if (ex == null) {
35
						ex = e;
34
					ex = e;
36
					}
37
					clazz = clazz.getSuperclass();
35
				}
38
				}
36
				clazz = clazz.getSuperclass();
37
			}
39
			}
40
			if (method == null) {
41
				throw ex;
42
			}
43
			method.setAccessible(true);
44
			Object ret = method.invoke(object, args);
45
			return ret;
46
		} catch (IllegalArgumentException e) {
47
			EclipseTest.fail(e.getMessage());
48
		} catch (IllegalAccessException e) {
49
			EclipseTest.fail(e.getMessage());
50
		} catch (SecurityException e) {
51
			EclipseTest.fail(e.getMessage());
52
		} catch (NoSuchMethodException e) {
53
			EclipseTest.fail(e.getMessage());
54
		} catch (InvocationTargetException e) {
55
			EclipseTest.fail(e.getMessage());
38
		}
56
		}
39
		if (method == null) {
57
		return null;
40
			throw ex;
58
	}
59
60
	public static Object getField(Object object, String name) {
61
		try {
62
			Field field = null;
63
			Class clazz = object.getClass();
64
			NoSuchFieldException ex = null;
65
			while (field == null && clazz != null) {
66
				try {
67
					field = clazz.getDeclaredField(name);
68
				} catch (NoSuchFieldException e) {
69
					if (ex == null) {
70
						ex = e;
71
					}
72
					clazz = clazz.getSuperclass();
73
				}
74
			}
75
			if (field == null) {
76
				throw ex;
77
			}
78
			field.setAccessible(true);
79
			Object ret = field.get(object);
80
			return ret;
81
		} catch (IllegalArgumentException e) {
82
			EclipseTest.fail(e.getMessage());
83
		} catch (IllegalAccessException e) {
84
			EclipseTest.fail(e.getMessage());
85
		} catch (SecurityException e) {
86
			EclipseTest.fail(e.getMessage());
87
		} catch (NoSuchFieldException e) {
88
			EclipseTest.fail(e.getMessage());
41
		}
89
		}
42
		method.setAccessible(true);
90
		return null;
43
		Object ret = method.invoke(object, args);
44
		return ret;
45
	}
91
	}
46
92
47
	public static Object getField(Object object, String name)
93
	public static void setField(Object object, String name, Object value) {
48
			throws IllegalArgumentException, IllegalAccessException,
94
		try {
49
			SecurityException, NoSuchFieldException {
95
			Field field = null;
50
		Field field = object.getClass().getDeclaredField(name);
96
			Class clazz = object.getClass();
51
		field.setAccessible(true);
97
			NoSuchFieldException ex = null;
52
		Object ret = field.get(object);
98
			while (field == null && clazz != null) {
53
		return ret;
99
				try {
100
					field = clazz.getDeclaredField(name);
101
				} catch (NoSuchFieldException e) {
102
					if (ex == null) {
103
						ex = e;
104
					}
105
					clazz = clazz.getSuperclass();
106
				}
107
			}
108
			if (field == null) {
109
				throw ex;
110
			}
111
			field.setAccessible(true);
112
			field.set(object, value);
113
		} catch (IllegalArgumentException e) {
114
			EclipseTest.fail(e.getMessage());
115
		} catch (IllegalAccessException e) {
116
			EclipseTest.fail(e.getMessage());
117
		} catch (SecurityException e) {
118
			EclipseTest.fail(e.getMessage());
119
		} catch (NoSuchFieldException e) {
120
			EclipseTest.fail(e.getMessage());
121
		}
54
	}
122
	}
55
123
56
}
124
}
(-)src/org/eclipse/team/tests/ccvs/ui/CreatePatchTest.java (-37 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 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 14-20 Link Here
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.io.InputStream;
15
import java.io.InputStream;
16
import java.io.InputStreamReader;
16
import java.io.InputStreamReader;
17
import java.lang.reflect.InvocationTargetException;
18
import java.net.URL;
17
import java.net.URL;
19
18
20
import junit.framework.Test;
19
import junit.framework.Test;
Lines 241-287 Link Here
241
	}
240
	}
242
241
243
	private Text getText(Object object, String name) {
242
	private Text getText(Object object, String name) {
244
		return (Text) getField(object, name);
243
		return (Text) ReflectionUtils.getField(object, name);
245
	}
244
	}
246
245
247
	private Button getButton(Object object, String name) {
246
	private Button getButton(Object object, String name) {
248
		return (Button) getField(object, name);
247
		return (Button) ReflectionUtils.getField(object, name);
249
	}
250
251
	private Object getField(Object object, String name) {
252
		Object ret = null;
253
		try {
254
			ret = ReflectionUtils.getField(object, name);
255
		} catch (IllegalArgumentException e) {
256
			fail(e.getMessage());
257
		} catch (SecurityException e) {
258
			fail(e.getMessage());
259
		} catch (IllegalAccessException e) {
260
			fail(e.getMessage());
261
		} catch (NoSuchFieldException e) {
262
			fail(e.getMessage());
263
		}
264
		return ret;
265
	}
248
	}
266
249
267
	private Object callMethod(Object object, String name) {
250
	private Object callMethod(Object object, String name) {
268
		return callMethod(object, name, new Object[] {});
251
		return ReflectionUtils.callMethod(object, name, new Object[] {});
269
	}
270
271
	private Object callMethod(Object object, String name, Object args[]) {
272
		Object ret = null;
273
		try {
274
			ret = ReflectionUtils.callMethod(object, name, args);
275
		} catch (IllegalArgumentException e) {
276
			fail(e.getMessage());
277
		} catch (IllegalAccessException e) {
278
			fail(e.getMessage());
279
		} catch (InvocationTargetException e) {
280
			fail(e.getMessage());
281
		} catch (NoSuchMethodException e) {
282
			fail(e.getMessage());
283
		}
284
		return ret;
285
	}
252
	}
286
253
287
	private Shell getShell() {
254
	private Shell getShell() {
(-)plugin.xml (+24 lines)
Lines 49-52 Link Here
49
            name="CVS Test Editor">
49
            name="CVS Test Editor">
50
      </editor>
50
      </editor>
51
   </extension>
51
   </extension>
52
53
<!-- Other declarations -->
54
   
55
   <!-- ***** Nature that identifies model projects used in tests for bug 302163 ***** -->
56
   <extension
57
         id="bug302163_ModelNature"
58
         name="Project nature for bug 302163"
59
         point="org.eclipse.core.resources.natures">
60
     <runtime>
61
        <run class="org.eclipse.team.tests.ccvs.core.mappings.model.ModelNature"/>
62
     </runtime>
63
   </extension>
64
 
65
   <!-- ***** Model provider for the model used in tests for bug 302163 ***** -->
66
   <extension
67
         id="bug302163_ModelProvider"
68
         name="Model Provider for bug 302163"
69
         point="org.eclipse.core.resources.modelProviders">
70
      <modelProvider class="org.eclipse.team.tests.ccvs.core.mappings.model.mapping.CustomModelProvider"/>
71
      <extends-model id="org.eclipse.core.resources.modelProvider"/>
72
      <enablement>
73
          <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.team.tests.cvs.core.bug302163_ModelNature" />
74
      </enablement>
75
   </extension>
52
</plugin>
76
</plugin>
(-)src/org/eclipse/team/tests/ccvs/core/mappings/model/mapping/CustomModelProvider.java (+45 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.mappings.model.mapping;
12
13
import org.eclipse.core.resources.*;
14
import org.eclipse.core.resources.mapping.*;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.team.tests.ccvs.core.mappings.model.*;
17
18
/**
19
 * The model provider for our example
20
 */
21
public class CustomModelProvider extends
22
		org.eclipse.core.resources.mapping.ModelProvider {
23
24
	public static final String ID = "org.eclipse.team.tests.cvs.core.bug302163_ModelProvider";
25
26
	public CustomModelProvider() {
27
		super();
28
	}
29
30
	public IStatus validateChange(IResourceDelta delta, IProgressMonitor monitor) {
31
		return super.validateChange(delta, monitor);
32
	}
33
34
	public ResourceMapping[] getMappings(IResource resource,
35
			ResourceMappingContext context, IProgressMonitor monitor)
36
			throws CoreException {
37
		if (ModelProject.isModProject(resource.getProject())) {
38
			ModelObject object = ModelObject.create(resource);
39
			if (object != null)
40
				return new ResourceMapping[] { ModelResourceMapping
41
						.create(object) };
42
		}
43
		return super.getMappings(resource, context, monitor);
44
	}
45
}
(-)src/org/eclipse/team/tests/ccvs/core/mappings/model/ModelFile.java (+54 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.mappings.model;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.core.resources.*;
17
import org.eclipse.core.runtime.*;
18
19
public class ModelFile extends ModelObject {
20
21
	public static final String MODEL_FILE_EXTENSION = "mod";
22
23
	public static boolean isModFile(IResource resource) {
24
		if (resource instanceof IFile) {
25
			String fileExtension = resource.getFileExtension();
26
			if (fileExtension != null)
27
				return fileExtension.equals(MODEL_FILE_EXTENSION);
28
		}
29
		return false;
30
	}
31
32
	public static IResource[] getReferencedResources(String projectName,
33
			IStorage storage) {
34
		if (storage == null)
35
			return new IResource[0];
36
		List result = new ArrayList();
37
		return (IResource[]) result.toArray(new IResource[result.size()]);
38
	}
39
40
	public ModelFile(IFile file) {
41
		super(file);
42
	}
43
44
	public ModelObject[] getChildren() throws CoreException {
45
		return null;
46
	}
47
48
	public String getName() {
49
		String name = super.getName();
50
		int index = name.lastIndexOf(".");
51
		return name.substring(0, index);
52
	}
53
54
}
(-)src/org/eclipse/team/tests/ccvs/core/mappings/model/mapping/ModelResourceMapping.java (+76 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.mappings.model.mapping;
12
13
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.resources.mapping.ResourceMapping;
17
import org.eclipse.core.resources.mapping.ResourceMappingContext;
18
import org.eclipse.core.resources.mapping.ResourceTraversal;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.team.tests.ccvs.core.mappings.model.*;
22
23
public class ModelResourceMapping extends ResourceMapping {
24
25
	public static String projectName = "";
26
	private final ModelObject object;
27
28
	public static ResourceMapping create(ModelObject object) {
29
		if (object instanceof ModelProject) {
30
			return new ModelResourceMapping(object);
31
		}
32
		if (object instanceof ModelFile) {
33
			return new ModelResourceMapping(object);
34
		}
35
		return null;
36
	}
37
38
	public ResourceTraversal[] getTraversals(ResourceMappingContext context,
39
			IProgressMonitor monitor) throws CoreException {
40
		return new ResourceTraversal[] { new ResourceTraversal(
41
				new IResource[] { ResourcesPlugin.getWorkspace().getRoot()
42
						.getProject(projectName).getFile("file1.txt") },
43
				IResource.DEPTH_ZERO, IResource.NONE) };
44
	}
45
46
	protected ModelResourceMapping(ModelObject object) {
47
		this.object = object;
48
	}
49
50
	public Object getModelObject() {
51
		return object;
52
	}
53
54
	public String getModelProviderId() {
55
		return CustomModelProvider.ID;
56
	}
57
58
	public IProject[] getProjects() {
59
		return new IProject[] { (IProject) object.getProject().getResource() };
60
	}
61
62
	public boolean contains(ResourceMapping mapping) {
63
		if (mapping instanceof ModelResourceMapping) {
64
			ModelObject object = (ModelObject) mapping.getModelObject();
65
			IResource resource = object.getResource();
66
			return getResource().getFullPath().isPrefixOf(
67
					resource.getFullPath());
68
		}
69
		return false;
70
	}
71
72
	private IResource getResource() {
73
		return ((ModelProject) getModelObject()).getResource();
74
	}
75
76
}
(-)src/org/eclipse/team/tests/ccvs/core/mappings/model/ModelNature.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.mappings.model;
12
13
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IProjectNature;
15
16
/**
17
 * Nature used to identify a model project
18
 */
19
public class ModelNature implements IProjectNature {
20
21
	public static final String NATURE_ID = "org.eclipse.team.tests.cvs.core.bug302163_ModelNature";
22
23
	private IProject project;
24
25
	public void configure() {
26
		// Nothing to do
27
	}
28
29
	public void deconfigure() {
30
		// Nothing to do
31
	}
32
33
	public IProject getProject() {
34
		return project;
35
	}
36
37
	public void setProject(IProject project) {
38
		this.project = project;
39
	}
40
41
}
(-)src/org/eclipse/team/tests/ccvs/core/mappings/model/ModelObject.java (+74 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.mappings.model;
12
13
import org.eclipse.core.resources.*;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.PlatformObject;
16
17
public abstract class ModelObject extends PlatformObject {
18
19
	private final IResource resource;
20
21
	public static ModelObject create(IResource resource) {
22
		switch (resource.getType()) {
23
		case IResource.PROJECT:
24
			return new ModelProject((IProject) resource);
25
		case IResource.FILE:
26
			if (ModelFile.isModFile(resource)) {
27
				return new ModelFile((IFile) resource);
28
			}
29
		}
30
		return null;
31
	}
32
33
	protected ModelObject(IResource resource) {
34
		this.resource = resource;
35
	}
36
37
	public abstract ModelObject[] getChildren() throws CoreException;
38
39
	public IResource getResource() {
40
		return resource;
41
	}
42
43
	public String getName() {
44
		return getResource().getName();
45
	}
46
47
	public String getPath() {
48
		return getResource().getFullPath().makeRelative().toString();
49
	}
50
51
	public ModelObject getParent() {
52
		return ModelObject.create(getResource().getParent());
53
	}
54
55
	public boolean equals(Object obj) {
56
		if (obj instanceof ModelObject) {
57
			ModelObject mr = (ModelObject) obj;
58
			return getResource().equals(mr.getResource());
59
		}
60
		return super.equals(obj);
61
	}
62
63
	public int hashCode() {
64
		return getResource().hashCode();
65
	}
66
67
	public void delete() throws CoreException {
68
		getResource().delete(false, null);
69
	}
70
71
	public ModelProject getProject() {
72
		return (ModelProject) ModelObject.create(getResource().getProject());
73
	}
74
}
(-)src/org/eclipse/team/tests/ccvs/core/mappings/model/ModelProject.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.mappings.model;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.core.resources.IContainer;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IProjectDescription;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
24
public class ModelProject extends ModelObject {
25
26
	public static boolean isModProject(IProject project) throws CoreException {
27
		if (!project.isOpen())
28
			return false;
29
		IProjectDescription description = project.getDescription();
30
		return description.hasNature(ModelNature.NATURE_ID);
31
	}
32
33
	public static void makeModProject(IProject project, IProgressMonitor monitor)
34
			throws CoreException {
35
		IProjectDescription description = project.getDescription();
36
		String[] natureIds = description.getNatureIds();
37
		List result = new ArrayList();
38
		for (int i = 0; i < natureIds.length; i++) {
39
			result.add(natureIds[i]);
40
		}
41
		result.add(ModelNature.NATURE_ID);
42
		description.setNatureIds((String[]) result.toArray(new String[result
43
				.size()]));
44
		project.setDescription(description, monitor);
45
	}
46
47
	public ModelProject(IProject project) {
48
		super(project);
49
	}
50
51
	protected IContainer getContainer() {
52
		return (IContainer) getResource();
53
	}
54
55
	public ModelObject[] getChildren() throws CoreException {
56
		IResource[] members = getContainer().members();
57
		List result = new ArrayList();
58
		for (int i = 0; i < members.length; i++) {
59
			IResource resource = members[i];
60
			if (ModelFile.isModFile(resource)) {
61
				result.add(new ModelFile((IFile) resource));
62
			} else if (resource instanceof IProject
63
					&& ModelProject.isModProject((IProject) resource)) {
64
				result.add(new ModelProject((IProject) resource));
65
			}
66
		}
67
		return (ModelObject[]) result.toArray(new ModelObject[result.size()]);
68
	}
69
70
}

Return to bug 306508