|
Lines 7-21
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* University Of British Columbia - initial API and implementation |
9 |
* University Of British Columbia - initial API and implementation |
|
|
10 |
* Eike Stepper - template based commit templates |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
|
|
|
| 12 |
package org.eclipse.mylar.internal.team; |
12 |
package org.eclipse.mylar.internal.team; |
| 13 |
|
13 |
|
| 14 |
import java.util.ArrayList; |
|
|
| 15 |
import java.util.Arrays; |
| 16 |
import java.util.HashSet; |
| 17 |
import java.util.List; |
| 18 |
import java.util.Set; |
| 19 |
|
14 |
|
| 20 |
import org.eclipse.core.resources.IResource; |
15 |
import org.eclipse.core.resources.IResource; |
| 21 |
import org.eclipse.core.resources.ResourcesPlugin; |
16 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
Lines 25-30
Link Here
|
| 25 |
import org.eclipse.mylar.context.core.InteractionEvent; |
20 |
import org.eclipse.mylar.context.core.InteractionEvent; |
| 26 |
import org.eclipse.mylar.resources.MylarResourcesPlugin; |
21 |
import org.eclipse.mylar.resources.MylarResourcesPlugin; |
| 27 |
import org.eclipse.mylar.tasks.core.ITask; |
22 |
import org.eclipse.mylar.tasks.core.ITask; |
|
|
23 |
import org.eclipse.mylar.team.ITemplateHandlersManager; |
| 28 |
import org.eclipse.mylar.team.MylarTeamPlugin; |
24 |
import org.eclipse.mylar.team.MylarTeamPlugin; |
| 29 |
import org.eclipse.team.core.TeamException; |
25 |
import org.eclipse.team.core.TeamException; |
| 30 |
import org.eclipse.team.core.diff.IDiff; |
26 |
import org.eclipse.team.core.diff.IDiff; |
|
Lines 35-279
Link Here
|
| 35 |
import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager; |
31 |
import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager; |
| 36 |
import org.osgi.service.prefs.Preferences; |
32 |
import org.osgi.service.prefs.Preferences; |
| 37 |
|
33 |
|
|
|
34 |
import java.util.ArrayList; |
| 35 |
import java.util.Arrays; |
| 36 |
import java.util.HashSet; |
| 37 |
import java.util.List; |
| 38 |
import java.util.Set; |
| 39 |
|
| 40 |
|
| 38 |
/** |
41 |
/** |
| 39 |
* @author Mik Kersten |
42 |
* @author Mik Kersten |
| 40 |
*/ |
43 |
*/ |
| 41 |
public class ContextChangeSet extends CVSActiveChangeSet implements IAdaptable { |
44 |
public class ContextChangeSet extends CVSActiveChangeSet implements IAdaptable |
|
|
45 |
{ |
| 42 |
|
46 |
|
| 43 |
private static final String PREFIX_HTTP = "http://"; |
47 |
private static final String PREFIX_HTTP = "http://"; |
| 44 |
|
48 |
|
| 45 |
private static final String PREFIX_HTTPS = "https://"; |
49 |
private static final String PREFIX_HTTPS = "https://"; |
| 46 |
|
50 |
|
| 47 |
private static final String PREFIX_DELIM = ": "; |
51 |
private static final String PREFIX_DELIM = ": "; |
| 48 |
|
52 |
|
| 49 |
// HACK: copied from super |
53 |
// HACK: copied from super |
| 50 |
private static final String CTX_TITLE = "title"; |
54 |
private static final String CTX_TITLE = "title"; |
| 51 |
|
55 |
|
| 52 |
public static final String SOURCE_ID = "org.eclipse.mylar.java.context.changeset.add"; |
56 |
public static final String SOURCE_ID = "org.eclipse.mylar.java.context.changeset.add"; |
| 53 |
|
57 |
|
| 54 |
private boolean suppressInterestContribution = false; |
58 |
private boolean suppressInterestContribution = false; |
| 55 |
|
59 |
|
| 56 |
private ITask task; |
60 |
private ITask task; |
| 57 |
|
61 |
|
| 58 |
public ContextChangeSet(ITask task, ActiveChangeSetManager manager) { |
62 |
public ContextChangeSet(ITask task, ActiveChangeSetManager manager) |
| 59 |
super(manager, task.getDescription()); |
63 |
{ |
| 60 |
this.task = task; |
64 |
super(manager, task.getDescription()); |
| 61 |
initTitle(); |
65 |
this.task = task; |
| 62 |
} |
66 |
initTitle(); |
| 63 |
|
67 |
} |
| 64 |
@Override |
68 |
|
| 65 |
public boolean isUserCreated() { |
69 |
@Override |
| 66 |
return true; |
70 |
public boolean isUserCreated() |
| 67 |
} |
71 |
{ |
| 68 |
|
72 |
return true; |
| 69 |
public void initTitle() { |
73 |
} |
| 70 |
super.setName(task.getDescription()); |
74 |
|
| 71 |
super.setTitle(task.getDescription()); |
75 |
public void initTitle() |
| 72 |
} |
76 |
{ |
| 73 |
|
77 |
super.setName(task.getDescription()); |
| 74 |
/** |
78 |
super.setTitle(task.getDescription()); |
| 75 |
* Encodes the handle in the title, since init won't get called on this |
79 |
} |
| 76 |
* class. |
80 |
|
| 77 |
*/ |
81 |
/** |
| 78 |
@Override |
82 |
* Encodes the handle in the title, since init won't get called on this |
| 79 |
public void save(Preferences prefs) { |
83 |
* class. |
| 80 |
super.save(prefs); |
84 |
*/ |
| 81 |
prefs.put(CTX_TITLE, getTitleForPersistance()); |
85 |
@Override |
| 82 |
} |
86 |
public void save(Preferences prefs) |
| 83 |
|
87 |
{ |
| 84 |
private String getTitleForPersistance() { |
88 |
super.save(prefs); |
| 85 |
return getTitle() + " (" + task.getHandleIdentifier() + ")"; |
89 |
prefs.put(CTX_TITLE, getTitleForPersistance()); |
| 86 |
} |
90 |
} |
| 87 |
|
91 |
|
| 88 |
public static String getHandleFromPersistedTitle(String title) { |
92 |
private String getTitleForPersistance() |
| 89 |
int delimStart = title.lastIndexOf('('); |
93 |
{ |
| 90 |
int delimEnd = title.lastIndexOf(')'); |
94 |
return getTitle() + " (" + task.getHandleIdentifier() + ")"; |
| 91 |
if (delimStart != -1 && delimEnd != -1) { |
95 |
} |
| 92 |
return title.substring(delimStart + 1, delimEnd); |
96 |
|
| 93 |
} else { |
97 |
public static String getHandleFromPersistedTitle(String title) |
| 94 |
return null; |
98 |
{ |
| 95 |
} |
99 |
int delimStart = title.lastIndexOf('('); |
| 96 |
} |
100 |
int delimEnd = title.lastIndexOf(')'); |
| 97 |
|
101 |
if (delimStart != -1 && delimEnd != -1) |
| 98 |
@Override |
102 |
{ |
| 99 |
public String getComment() { |
103 |
return title.substring(delimStart + 1, delimEnd); |
| 100 |
String completedPrefix = MylarTeamPlugin.getDefault().getPreferenceStore().getString( |
104 |
} |
| 101 |
MylarTeamPlugin.COMMIT_PREFIX_COMPLETED); |
105 |
else |
| 102 |
String progressPrefix = MylarTeamPlugin.getDefault().getPreferenceStore().getString( |
106 |
{ |
| 103 |
MylarTeamPlugin.COMMIT_PREFIX_PROGRESS); |
107 |
return null; |
| 104 |
String comment = ""; |
108 |
} |
| 105 |
comment = generateComment(task, completedPrefix, progressPrefix); |
109 |
} |
| 106 |
return comment; |
110 |
|
| 107 |
} |
111 |
@Override |
| 108 |
|
112 |
public String getComment() |
| 109 |
@Override |
113 |
{ |
| 110 |
public void remove(IResource resource) { |
114 |
String completedTemplate = MylarTeamPlugin.getDefault().getPreferenceStore().getString( |
| 111 |
super.remove(resource); |
115 |
MylarTeamPlugin.COMMIT_TEMPLATE_COMPLETED); |
| 112 |
} |
116 |
String progressTemplate = MylarTeamPlugin.getDefault().getPreferenceStore().getString( |
| 113 |
|
117 |
MylarTeamPlugin.COMMIT_TEMPLATE_PROGRESS); |
| 114 |
@Override |
118 |
return ITemplateHandlersManager.INSTANCE.generateComment(task, completedTemplate, |
| 115 |
public void remove(IResource[] newResources) { |
119 |
progressTemplate); |
| 116 |
super.remove(newResources); |
120 |
} |
| 117 |
} |
121 |
|
| 118 |
|
122 |
@Override |
| 119 |
@Override |
123 |
public void remove(IResource resource) |
| 120 |
public void add(IDiff diff) { |
124 |
{ |
| 121 |
super.add(diff); |
125 |
super.remove(resource); |
| 122 |
IResource resource = getResourceFromDiff(diff); |
126 |
} |
| 123 |
if (!suppressInterestContribution && resource != null) { |
127 |
|
| 124 |
Set<IResource> resources = new HashSet<IResource>(); |
128 |
@Override |
| 125 |
resources.add(resource); |
129 |
public void remove(IResource[] newResources) |
| 126 |
if (MylarResourcesPlugin.getDefault() != null) { |
130 |
{ |
| 127 |
MylarResourcesPlugin.getDefault().getInterestUpdater().addResourceToContext(resources, InteractionEvent.Kind.SELECTION); |
131 |
super.remove(newResources); |
| 128 |
} |
132 |
} |
| 129 |
} |
133 |
|
| 130 |
} |
134 |
@Override |
| 131 |
|
135 |
public void add(IDiff diff) |
| 132 |
private IResource getResourceFromDiff(IDiff diff) { |
136 |
{ |
| 133 |
if (diff instanceof ResourceDiff) { |
137 |
super.add(diff); |
| 134 |
return ((ResourceDiff)diff).getResource(); |
138 |
IResource resource = getResourceFromDiff(diff); |
| 135 |
} else if (diff instanceof ThreeWayDiff) { |
139 |
if (!suppressInterestContribution && resource != null) |
| 136 |
ThreeWayDiff threeWayDiff = (ThreeWayDiff)diff; |
140 |
{ |
| 137 |
return ResourcesPlugin.getWorkspace().getRoot().findMember(threeWayDiff.getPath()); |
141 |
Set<IResource> resources = new HashSet<IResource>(); |
| 138 |
} else { |
142 |
resources.add(resource); |
| 139 |
return null; |
143 |
if (MylarResourcesPlugin.getDefault() != null) |
| 140 |
} |
144 |
{ |
| 141 |
} |
145 |
MylarResourcesPlugin.getDefault().getInterestUpdater().addResourceToContext(resources, |
| 142 |
|
146 |
InteractionEvent.Kind.SELECTION); |
| 143 |
@Override |
147 |
} |
| 144 |
public void add(IDiff[] diffs) { |
148 |
} |
| 145 |
super.add(diffs); |
149 |
} |
| 146 |
} |
150 |
|
| 147 |
|
151 |
private IResource getResourceFromDiff(IDiff diff) |
| 148 |
@Override |
152 |
{ |
| 149 |
public void add(IResource[] newResources) throws CoreException { |
153 |
if (diff instanceof ResourceDiff) |
| 150 |
super.add(newResources); |
154 |
{ |
| 151 |
} |
155 |
return ((ResourceDiff)diff).getResource(); |
| 152 |
|
156 |
} |
| 153 |
public void restoreResources(IResource[] newResources) throws CoreException { |
157 |
else if (diff instanceof ThreeWayDiff) |
| 154 |
suppressInterestContribution = true; |
158 |
{ |
| 155 |
try { |
159 |
ThreeWayDiff threeWayDiff = (ThreeWayDiff)diff; |
| 156 |
super.add(newResources); |
160 |
return ResourcesPlugin.getWorkspace().getRoot().findMember(threeWayDiff.getPath()); |
| 157 |
setComment(getComment()); |
161 |
} |
| 158 |
} catch (TeamException e) { |
162 |
else |
| 159 |
throw e; |
163 |
{ |
| 160 |
} finally { |
164 |
return null; |
| 161 |
suppressInterestContribution = false; |
165 |
} |
| 162 |
} |
166 |
} |
| 163 |
} |
167 |
|
| 164 |
|
168 |
@Override |
| 165 |
@Override |
169 |
public void add(IDiff[] diffs) |
| 166 |
public IResource[] getResources() { |
170 |
{ |
| 167 |
List<IResource> allResources = getAllResourcesInChangeContext(); |
171 |
super.add(diffs); |
| 168 |
return allResources.toArray(new IResource[allResources.size()]); |
172 |
} |
| 169 |
} |
173 |
|
| 170 |
|
174 |
@Override |
| 171 |
public List<IResource> getAllResourcesInChangeContext() { |
175 |
public void add(IResource[] newResources) throws CoreException |
| 172 |
Set<IResource> allResources = new HashSet<IResource>(); |
176 |
{ |
| 173 |
allResources.addAll(Arrays.asList(super.getResources())); |
177 |
super.add(newResources); |
| 174 |
if (MylarResourcesPlugin.getDefault() != null && task.isActive()) { |
178 |
} |
| 175 |
// TODO: if super is always managed correctly should remove following line |
179 |
|
| 176 |
allResources.addAll(MylarResourcesPlugin.getDefault().getInterestingResources()); |
180 |
public void restoreResources(IResource[] newResources) throws CoreException |
| 177 |
} |
181 |
{ |
| 178 |
return new ArrayList<IResource>(allResources); |
182 |
suppressInterestContribution = true; |
| 179 |
} |
183 |
try |
| 180 |
|
184 |
{ |
| 181 |
/** |
185 |
super.add(newResources); |
| 182 |
* TODO: unnessary check context? |
186 |
setComment(getComment()); |
| 183 |
*/ |
187 |
} |
| 184 |
public boolean contains(IResource local) { |
188 |
catch (TeamException e) |
| 185 |
return getAllResourcesInChangeContext().contains(local); |
189 |
{ |
| 186 |
} |
190 |
throw e; |
| 187 |
|
191 |
} |
| 188 |
public static String generateComment(ITask task, String completedPrefix, String progressPrefix) { |
192 |
finally |
| 189 |
String comment; |
193 |
{ |
| 190 |
completedPrefix = fixUpDelimIfPresent(completedPrefix); |
194 |
suppressInterestContribution = false; |
| 191 |
progressPrefix = fixUpDelimIfPresent(progressPrefix); |
195 |
} |
| 192 |
if (task.isCompleted()) { |
196 |
} |
| 193 |
comment = completedPrefix + PREFIX_DELIM; |
197 |
|
| 194 |
} else { |
198 |
@Override |
| 195 |
comment = progressPrefix + PREFIX_DELIM; |
199 |
public IResource[] getResources() |
| 196 |
} |
200 |
{ |
| 197 |
comment += task.getDescription(); |
201 |
List<IResource> allResources = getAllResourcesInChangeContext(); |
| 198 |
String url = task.getUrl(); |
202 |
return allResources.toArray(new IResource[allResources.size()]); |
| 199 |
if (url != null && !url.equals("") && !url.endsWith("//")) { |
203 |
} |
| 200 |
comment += " \n" + url; |
204 |
|
| 201 |
} |
205 |
public List<IResource> getAllResourcesInChangeContext() |
| 202 |
return comment; |
206 |
{ |
| 203 |
} |
207 |
Set<IResource> allResources = new HashSet<IResource>(); |
| 204 |
|
208 |
allResources.addAll(Arrays.asList(super.getResources())); |
| 205 |
private static String fixUpDelimIfPresent(String prefix) { |
209 |
if (MylarResourcesPlugin.getDefault() != null && task.isActive()) |
| 206 |
if (prefix.endsWith(":") || prefix.endsWith(PREFIX_DELIM)) { |
210 |
{ |
| 207 |
prefix = prefix.substring(0, prefix.lastIndexOf(':')); |
211 |
// TODO: if super is always managed correctly should remove following line |
| 208 |
} |
212 |
allResources.addAll(MylarResourcesPlugin.getDefault().getInterestingResources()); |
| 209 |
return prefix; |
213 |
} |
| 210 |
} |
214 |
return new ArrayList<IResource>(allResources); |
| 211 |
|
215 |
} |
| 212 |
public static String getTaskIdFromCommentOrLabel(String comment) { |
216 |
|
| 213 |
int firstDelimIndex = comment.indexOf(PREFIX_DELIM); |
217 |
/** |
| 214 |
if (firstDelimIndex != -1) { |
218 |
* TODO: unnessary check context? |
| 215 |
int idStart = firstDelimIndex + PREFIX_DELIM.length(); |
219 |
*/ |
| 216 |
int idEnd = comment.indexOf(PREFIX_DELIM, firstDelimIndex + PREFIX_DELIM.length());// comment.indexOf(PREFIX_DELIM); |
220 |
public boolean contains(IResource local) |
| 217 |
if (idEnd != -1 && idStart < idEnd) { |
221 |
{ |
| 218 |
String id = comment.substring(idStart, idEnd); |
222 |
return getAllResourcesInChangeContext().contains(local); |
| 219 |
if (id != null) |
223 |
} |
| 220 |
return id.trim(); |
224 |
|
| 221 |
} else { |
225 |
/** |
| 222 |
// change set label |
226 |
* @deprecated Use {@link ITemplateHandlersManager#generateComment(ITask, String, String)} instead. |
| 223 |
return comment.substring(0, firstDelimIndex); |
227 |
*/ |
| 224 |
} |
228 |
public static String generateComment(ITask task, String completedPrefix, String progressPrefix) |
| 225 |
} |
229 |
{ |
| 226 |
return null; |
230 |
String comment; |
| 227 |
} |
231 |
completedPrefix = fixUpDelimIfPresent(completedPrefix); |
| 228 |
|
232 |
progressPrefix = fixUpDelimIfPresent(progressPrefix); |
| 229 |
public static String getUrlFromComment(String comment) { |
233 |
if (task.isCompleted()) |
| 230 |
int httpIndex = comment.indexOf(PREFIX_HTTP); |
234 |
{ |
| 231 |
int httpsIndex = comment.indexOf(PREFIX_HTTPS); |
235 |
comment = completedPrefix + PREFIX_DELIM; |
| 232 |
int idStart = -1; |
236 |
} |
| 233 |
if (httpIndex != -1) { |
237 |
else |
| 234 |
idStart = httpIndex; |
238 |
{ |
| 235 |
} else if (httpsIndex != -1) { |
239 |
comment = progressPrefix + PREFIX_DELIM; |
| 236 |
idStart = httpsIndex; |
240 |
} |
| 237 |
} |
241 |
comment += task.getDescription(); |
| 238 |
if (idStart != -1) { |
242 |
String url = task.getUrl(); |
| 239 |
int idEnd = comment.indexOf(' ', idStart); |
243 |
if (url != null && !url.equals("") && !url.endsWith("//")) |
| 240 |
if (idEnd == -1) { |
244 |
{ |
| 241 |
return comment.substring(idStart); |
245 |
comment += " \n" + url; |
| 242 |
} else if (idEnd != -1 && idStart < idEnd) { |
246 |
} |
| 243 |
return comment.substring(idStart, idEnd); |
247 |
return comment; |
| 244 |
} |
248 |
} |
| 245 |
} |
249 |
|
| 246 |
return null; |
250 |
private static String fixUpDelimIfPresent(String prefix) |
| 247 |
} |
251 |
{ |
| 248 |
|
252 |
if (prefix.endsWith(":") || prefix.endsWith(PREFIX_DELIM)) |
| 249 |
@Override |
253 |
{ |
| 250 |
public boolean equals(Object object) { |
254 |
prefix = prefix.substring(0, prefix.lastIndexOf(':')); |
| 251 |
if (object instanceof ContextChangeSet && task != null) { |
255 |
} |
| 252 |
ContextChangeSet changeSet = (ContextChangeSet) object; |
256 |
return prefix; |
| 253 |
return task.equals(changeSet.getTask()); |
257 |
} |
| 254 |
} else { |
258 |
|
| 255 |
return super.equals(object); |
259 |
public static String getTaskIdFromCommentOrLabel(String comment) |
| 256 |
} |
260 |
{ |
| 257 |
} |
261 |
int firstDelimIndex = comment.indexOf(PREFIX_DELIM); |
| 258 |
|
262 |
if (firstDelimIndex != -1) |
| 259 |
@Override |
263 |
{ |
| 260 |
public int hashCode() { |
264 |
int idStart = firstDelimIndex + PREFIX_DELIM.length(); |
| 261 |
if (task != null) { |
265 |
int idEnd = comment.indexOf(PREFIX_DELIM, firstDelimIndex + PREFIX_DELIM.length());// comment.indexOf(PREFIX_DELIM); |
| 262 |
return task.hashCode(); |
266 |
if (idEnd != -1 && idStart < idEnd) |
| 263 |
} else { |
267 |
{ |
| 264 |
return super.hashCode(); |
268 |
String id = comment.substring(idStart, idEnd); |
| 265 |
} |
269 |
if (id != null) return id.trim(); |
| 266 |
} |
270 |
} |
| 267 |
|
271 |
else |
| 268 |
public ITask getTask() { |
272 |
{ |
| 269 |
return task; |
273 |
// change set label |
| 270 |
} |
274 |
return comment.substring(0, firstDelimIndex); |
| 271 |
|
275 |
} |
| 272 |
public Object getAdapter(Class adapter) { |
276 |
} |
| 273 |
if (adapter == ResourceMapping.class) { |
277 |
return null; |
| 274 |
return new ChangeSetResourceMapping(this); |
278 |
} |
| 275 |
} else { |
279 |
|
| 276 |
return null; |
280 |
public static String getUrlFromComment(String comment) |
| 277 |
} |
281 |
{ |
| 278 |
} |
282 |
int httpIndex = comment.indexOf(PREFIX_HTTP); |
|
|
283 |
int httpsIndex = comment.indexOf(PREFIX_HTTPS); |
| 284 |
int idStart = -1; |
| 285 |
if (httpIndex != -1) |
| 286 |
{ |
| 287 |
idStart = httpIndex; |
| 288 |
} |
| 289 |
else if (httpsIndex != -1) |
| 290 |
{ |
| 291 |
idStart = httpsIndex; |
| 292 |
} |
| 293 |
if (idStart != -1) |
| 294 |
{ |
| 295 |
int idEnd = comment.indexOf(' ', idStart); |
| 296 |
if (idEnd == -1) |
| 297 |
{ |
| 298 |
return comment.substring(idStart); |
| 299 |
} |
| 300 |
else if (idEnd != -1 && idStart < idEnd) |
| 301 |
{ |
| 302 |
return comment.substring(idStart, idEnd); |
| 303 |
} |
| 304 |
} |
| 305 |
return null; |
| 306 |
} |
| 307 |
|
| 308 |
@Override |
| 309 |
public boolean equals(Object object) |
| 310 |
{ |
| 311 |
if (object instanceof ContextChangeSet && task != null) |
| 312 |
{ |
| 313 |
ContextChangeSet changeSet = (ContextChangeSet)object; |
| 314 |
return task.equals(changeSet.getTask()); |
| 315 |
} |
| 316 |
else |
| 317 |
{ |
| 318 |
return super.equals(object); |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
@Override |
| 323 |
public int hashCode() |
| 324 |
{ |
| 325 |
if (task != null) |
| 326 |
{ |
| 327 |
return task.hashCode(); |
| 328 |
} |
| 329 |
else |
| 330 |
{ |
| 331 |
return super.hashCode(); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
public ITask getTask() |
| 336 |
{ |
| 337 |
return task; |
| 338 |
} |
| 339 |
|
| 340 |
public Object getAdapter(Class adapter) |
| 341 |
{ |
| 342 |
if (adapter == ResourceMapping.class) |
| 343 |
{ |
| 344 |
return new ChangeSetResourceMapping(this); |
| 345 |
} |
| 346 |
else |
| 347 |
{ |
| 348 |
return null; |
| 349 |
} |
| 350 |
} |
| 279 |
} |
351 |
} |