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

Collapse All | Expand All

(-)src/org/eclipse/mylyn/tasks/core/TaskRepository.java (-17 / +77 lines)
Lines 11-16 Link Here
11
import java.net.MalformedURLException;
11
import java.net.MalformedURLException;
12
import java.net.Proxy;
12
import java.net.Proxy;
13
import java.net.URL;
13
import java.net.URL;
14
import java.util.Date;
14
import java.util.HashMap;
15
import java.util.HashMap;
15
import java.util.LinkedHashMap;
16
import java.util.LinkedHashMap;
16
import java.util.Map;
17
import java.util.Map;
Lines 20-25 Link Here
20
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.core.runtime.PlatformObject;
22
import org.eclipse.core.runtime.PlatformObject;
22
import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants;
23
import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants;
24
import org.eclipse.mylyn.internal.tasks.core.TaskActivityUtil;
23
import org.eclipse.mylyn.monitor.core.StatusHandler;
25
import org.eclipse.mylyn.monitor.core.StatusHandler;
24
import org.eclipse.mylyn.web.core.WebClientUtil;
26
import org.eclipse.mylyn.web.core.WebClientUtil;
25
import org.eclipse.mylyn.web.core.WebCredentials;
27
import org.eclipse.mylyn.web.core.WebCredentials;
Lines 36-42 Link Here
36
 * <li>The solution we have come up with thus far is not to interpret the date as a DATE object but rather simply use
38
 * <li>The solution we have come up with thus far is not to interpret the date as a DATE object but rather simply use
37
 * the date string given to us by the repository itself.</li>
39
 * the date string given to us by the repository itself.</li>
38
 * </ul>
40
 * </ul>
39
 * 
41
 *
40
 * @author Mik Kersten
42
 * @author Mik Kersten
41
 * @author Rob Elves
43
 * @author Rob Elves
42
 * @author Eugene Kuleshov
44
 * @author Eugene Kuleshov
Lines 139-148 Link Here
139
	private Map<String, String> transientProperties = new HashMap<String, String>();
141
	private Map<String, String> transientProperties = new HashMap<String, String>();
140
142
141
	/*
143
	/*
142
	 * TODO: should be externalized and added to extension point, see bug 183606 
144
	 * TODO: should be externalized and added to extension point, see bug 183606
143
	 */
145
	 */
144
	private boolean isBugRepository = false;
146
	private boolean isBugRepository = false;
145
147
148
	public static final String LAST_CONFIG_REFRESH = "config.lastupdate";
149
150
	private static final long LONG_AGO = 1000L * 3600L * 24L; // 24 hrs ago
151
146
	/**
152
	/**
147
	 * for testing purposes
153
	 * for testing purposes
148
	 */
154
	 */
Lines 194-200 Link Here
194
200
195
	/**
201
	/**
196
	 * <b>Note: </b> This method will be deprecated in 2.3.
202
	 * <b>Note: </b> This method will be deprecated in 2.3.
197
	 * 
203
	 *
198
	 * @see #getCredentials(Type)
204
	 * @see #getCredentials(Type)
199
	 */
205
	 */
200
	public boolean hasCredentials() {
206
	public boolean hasCredentials() {
Lines 221-227 Link Here
221
227
222
	/**
228
	/**
223
	 * <b>Note: </b> This method will be deprecated in 2.3.
229
	 * <b>Note: </b> This method will be deprecated in 2.3.
224
	 * 
230
	 *
225
	 * @see #getCredentials(Type)
231
	 * @see #getCredentials(Type)
226
	 */
232
	 */
227
	public String getProxyUsername() {
233
	public String getProxyUsername() {
Lines 230-236 Link Here
230
236
231
	/**
237
	/**
232
	 * <b>Note: </b> This method will be deprecated in 2.3.
238
	 * <b>Note: </b> This method will be deprecated in 2.3.
233
	 * 
239
	 *
234
	 * @see #getCredentials(Type)
240
	 * @see #getCredentials(Type)
235
	 */
241
	 */
236
	public String getProxyPassword() {
242
	public String getProxyPassword() {
Lines 239-245 Link Here
239
245
240
	/**
246
	/**
241
	 * <b>Note: </b> This method will be deprecated in 2.3.
247
	 * <b>Note: </b> This method will be deprecated in 2.3.
242
	 * 
248
	 *
243
	 * @see #getCredentials(Type)
249
	 * @see #getCredentials(Type)
244
	 */
250
	 */
245
	public String getHttpUser() {
251
	public String getHttpUser() {
Lines 248-254 Link Here
248
254
249
	/**
255
	/**
250
	 * <b>Note: </b> This method will be deprecated in 2.3.
256
	 * <b>Note: </b> This method will be deprecated in 2.3.
251
	 * 
257
	 *
252
	 * @see #getCredentials(Type)
258
	 * @see #getCredentials(Type)
253
	 */
259
	 */
254
	public String getHttpPassword() {
260
	public String getHttpPassword() {
Lines 257-263 Link Here
257
263
258
	/**
264
	/**
259
	 * <b>Note: </b> This method will be deprecated in 2.3.
265
	 * <b>Note: </b> This method will be deprecated in 2.3.
260
	 * 
266
	 *
261
	 * @see #setCredentials(Type, WebCredentials, boolean)
267
	 * @see #setCredentials(Type, WebCredentials, boolean)
262
	 */
268
	 */
263
	public void setAuthenticationCredentials(String username, String password) {
269
	public void setAuthenticationCredentials(String username, String password) {
Lines 266-272 Link Here
266
272
267
	/**
273
	/**
268
	 * <b>Note: </b> This method will be deprecated in 2.3.
274
	 * <b>Note: </b> This method will be deprecated in 2.3.
269
	 * 
275
	 *
270
	 * @see #setCredentials(Type, WebCredentials, boolean)
276
	 * @see #setCredentials(Type, WebCredentials, boolean)
271
	 */
277
	 */
272
	public void setProxyAuthenticationCredentials(String username, String password) {
278
	public void setProxyAuthenticationCredentials(String username, String password) {
Lines 275-281 Link Here
275
281
276
	/**
282
	/**
277
	 * <b>Note: </b> This method will be deprecated in 2.3.
283
	 * <b>Note: </b> This method will be deprecated in 2.3.
278
	 * 
284
	 *
279
	 * @see #setCredentials(Type, WebCredentials, boolean)
285
	 * @see #setCredentials(Type, WebCredentials, boolean)
280
	 */
286
	 */
281
	public void setHttpAuthenticationCredentials(String username, String password) {
287
	public void setHttpAuthenticationCredentials(String username, String password) {
Lines 300-306 Link Here
300
	public void flushAuthenticationCredentials() {
306
	public void flushAuthenticationCredentials() {
301
		synchronized (LOCK) {
307
		synchronized (LOCK) {
302
			isCachedUserName = false;
308
			isCachedUserName = false;
303
		
309
304
			transientProperties.clear();
310
			transientProperties.clear();
305
311
306
			// API30: legacy support for versions prior to 2.2 that did not set the enable flag, remove for 3.0
312
			// API30: legacy support for versions prior to 2.2 that did not set the enable flag, remove for 3.0
Lines 533-539 Link Here
533
539
534
	/**
540
	/**
535
	 * <b>Note: </b> This method will be deprecated in 2.3.
541
	 * <b>Note: </b> This method will be deprecated in 2.3.
536
	 * 
542
	 *
537
	 * @see #setCredentials(Type, WebCredentials, boolean)
543
	 * @see #setCredentials(Type, WebCredentials, boolean)
538
	 */
544
	 */
539
	public void setAnonymous(boolean b) {
545
	public void setAnonymous(boolean b) {
Lines 542-548 Link Here
542
548
543
	/**
549
	/**
544
	 * <b>Note: </b> This method will be deprecated in 2.3.
550
	 * <b>Note: </b> This method will be deprecated in 2.3.
545
	 * 
551
	 *
546
	 * @see #getCredentials(Type)
552
	 * @see #getCredentials(Type)
547
	 */
553
	 */
548
	public boolean isAnonymous() {
554
	public boolean isAnonymous() {
Lines 571-577 Link Here
571
	public boolean getSavePassword(Type authType) {
577
	public boolean getSavePassword(Type authType) {
572
		String value = getProperty(getKeyPrefix(authType) + SAVE_PASSWORD);
578
		String value = getProperty(getKeyPrefix(authType) + SAVE_PASSWORD);
573
		return value != null && "true".equals(value);
579
		return value != null && "true".equals(value);
574
	}
580
		}
575
581
576
	private static String getKeyPrefix(Type type) {
582
	private static String getKeyPrefix(Type type) {
577
		switch (type) {
583
		switch (type) {
Lines 587-593 Link Here
587
593
588
	/**
594
	/**
589
	 * Returns the credentials for an authentication type.
595
	 * Returns the credentials for an authentication type.
590
	 * 
596
	 *
591
	 * @param authType
597
	 * @param authType
592
	 *            the type of authentication
598
	 *            the type of authentication
593
	 * @return null, if no credentials are set for <code>authType</code>
599
	 * @return null, if no credentials are set for <code>authType</code>
Lines 628-634 Link Here
628
634
629
	/**
635
	/**
630
	 * Sets the credentials for <code>authType</code>.
636
	 * Sets the credentials for <code>authType</code>.
631
	 * 
637
	 *
632
	 * @param authType
638
	 * @param authType
633
	 *            the type of authentication
639
	 *            the type of authentication
634
	 * @param credentials
640
	 * @param credentials
Lines 688-694 Link Here
688
	private String getUserName(WebCredentials.Type authType) {
694
	private String getUserName(WebCredentials.Type authType) {
689
		WebCredentials credentials = getCredentials(authType);
695
		WebCredentials credentials = getCredentials(authType);
690
		return (credentials != null) ? credentials.getUserName() : null;
696
		return (credentials != null) ? credentials.getUserName() : null;
691
	}
697
		}
698
692
699
693
	/**
700
	/**
694
	 * Legacy support for < 2.2. Remove in 2.3.
701
	 * Legacy support for < 2.2. Remove in 2.3.
Lines 698-701 Link Here
698
		return (credentials != null) ? credentials.getPassword() : null;
705
		return (credentials != null) ? credentials.getPassword() : null;
699
	}
706
	}
700
707
708
709
	/**
710
	 *	Get the last refresh date as initialized {@link Date} object.<br />
711
	 *  Internal representation is {@link String} determined by {@link TimestampUtils}.<br />
712
	 *	See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=207660">bug
713
	 *  207660: do not update repository configuration on every startup</a>
714
	 * @return {@link Date} set to last config update OR LONG_AGO if not found
715
	 */
716
	final public Date getConfigurationTimestamp() {
717
		String value = this.getProperty(LAST_CONFIG_REFRESH);
718
		Date stamp = null;
719
		if(null != value) {
720
			stamp = TaskActivityUtil.stringToDate(value);
721
		} else {
722
			stamp = new Date((new Date()).getTime() - LONG_AGO);
723
		}
724
		return stamp;
725
	}
726
727
	/**
728
	 * Utility method, set the Configuration Timestamp to now AND return it.
729
	 */
730
	final public Date updateConfigurationTimestamp() {
731
		Date now = new Date();
732
		this.setConfigurationTimestamp(now);
733
		return now;
734
	}
735
736
	/**
737
	 * set the Configuration Timestamp to the {@link Date} indicated.
738
	 *
739
	 * 	The last config update day is persisted as {@link String} determined in {@link TimestampUtils}.<br />
740
	 *	See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=207660">bug
741
	 *	207660: do not update repository configuration on every startup</a>
742
	 * @param {@link {@link Date}} setting the day
743
	 */
744
	final public void setConfigurationTimestamp(final Date timeStamp) {
745
		this.setProperty(LAST_CONFIG_REFRESH, TaskActivityUtil.dateToString(timeStamp));
746
		//  should persist here, but that can only be done by the TaskRepositoryManager
747
		// However this is also included when persisting ordinary sync time
748
	}
749
750
751
	/**
752
	 * This determines the configuration update policy of this repository.<br />
753
	 * This says yes when it is more than 24 hours ago. Future update policies may be set on a per repository basis.
754
	 * @return true when configuration update needed.
755
	 */
756
	public boolean configUpdateNeeded() {
757
		return TaskActivityUtil.moreThanAgo(getConfigurationTimestamp(), TaskActivityUtil.DAY);
758
	}
759
760
701
}
761
}
(-)src/org/eclipse/mylyn/internal/tasks/core/TaskActivityUtil.java (+34 lines)
Lines 8-14 Link Here
8
8
9
package org.eclipse.mylyn.internal.tasks.core;
9
package org.eclipse.mylyn.internal.tasks.core;
10
10
11
import java.text.ParseException;
12
import java.text.SimpleDateFormat;
11
import java.util.Calendar;
13
import java.util.Calendar;
14
import java.util.Date;
15
import java.util.Locale;
12
16
13
/**
17
/**
14
 * @author Rob Elves
18
 * @author Rob Elves
Lines 159-162 Link Here
159
		return (time.compareTo(start) >= 0 && time.compareTo(end) <= 0);
163
		return (time.compareTo(start) >= 0 && time.compareTo(end) <= 0);
160
	}
164
	}
161
165
166
	// copied from Jira
167
	public static final String TIMESTAMP_DATE_FORMAT = "dd MMM yyyy HH:mm:ss:S z";
168
	public static final long HOUR = 1000L * 3600L;
169
	public static final long DAY = HOUR * 24L;
170
	public static final long WEEK = DAY * 7L;
171
	public static String dateToString(Date date) {
172
		if (date == null) {
173
			return "";
174
		} else {
175
			return new SimpleDateFormat(TIMESTAMP_DATE_FORMAT, Locale.US).format(date);
176
		}
177
	}
178
179
	public static Date stringToDate(String dateString) {
180
		if (dateString == null || dateString.length() == 0) {
181
			return null;
182
		}
183
		try {
184
			return new SimpleDateFormat(TIMESTAMP_DATE_FORMAT, Locale.US).parse(dateString);
185
		} catch (ParseException e) {
186
			return null;
187
		}
188
	}
189
190
	public static boolean moreThanAgo(Date stamp, long interval) {
191
		if(null == stamp)
192
			return true;
193
		return new Date().getTime() - stamp.getTime() > interval;
194
	}
195
162
}
196
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/ScheduledTaskListSynchJob.java (-14 / +13 lines)
Lines 8-14 Link Here
8
8
9
package org.eclipse.mylyn.internal.tasks.ui;
9
package org.eclipse.mylyn.internal.tasks.ui;
10
10
11
import java.util.Calendar;
12
import java.util.List;
11
import java.util.List;
13
import java.util.Set;
12
import java.util.Set;
14
13
Lines 43-57 Link Here
43
42
44
	private TaskList taskList = null;
43
	private TaskList taskList = null;
45
44
45
	/**
46
	 * for testing ONLY!
47
	 */
46
	private static long count = 0;
48
	private static long count = 0;
47
49
48
	private static Calendar lastRepositoryRefresh;
49
50
	private TaskListManager taskListManager;
50
	private TaskListManager taskListManager;
51
51
52
	private List<TaskRepository> repositories = null;
52
	private List<TaskRepository> repositories = null;
53
53
54
	private boolean fullSynchronization;
54
	private boolean fullSynchronization = true;
55
55
56
	public ScheduledTaskListSynchJob(long schedule, TaskListManager taskListManager) {
56
	public ScheduledTaskListSynchJob(long schedule, TaskListManager taskListManager) {
57
		super(JOB_NAME);
57
		super(JOB_NAME);
Lines 112-120 Link Here
112
				Set<AbstractRepositoryQuery> queries = taskList.getRepositoryQueries(repository.getUrl());
112
				Set<AbstractRepositoryQuery> queries = taskList.getRepositoryQueries(repository.getUrl());
113
113
114
				// Occasionally request update of repository configuration attributes
114
				// Occasionally request update of repository configuration attributes
115
				if ((lastRepositoryRefresh == null || lastRepositoryRefresh.get(Calendar.DAY_OF_MONTH) != Calendar.getInstance()
115
				if (repository.configUpdateNeeded() && queries != null && queries.size() > 0) {
116
						.get(Calendar.DAY_OF_MONTH))
117
						&& queries != null && queries.size() > 0) {
118
					Job updateJob = new Job("Updating attributes for " + repository.getUrl()) {
116
					Job updateJob = new Job("Updating attributes for " + repository.getUrl()) {
119
117
120
						@Override
118
						@Override
Lines 122-130 Link Here
122
							try {
120
							try {
123
								if (connector.isRepositoryConfigurationStale(repository)) {
121
								if (connector.isRepositoryConfigurationStale(repository)) {
124
									connector.updateAttributes(repository, new SubProgressMonitor(monitor, 1));
122
									connector.updateAttributes(repository, new SubProgressMonitor(monitor, 1));
125
									// HACK: A configuration update occurred. Save on behalf of connector which 
123
									// HACK: A configuration update occurred. Save on behalf of connector which
126
									// currently can't access the repository manager itself
124
									// currently can't access the repository manager itself
127
									TasksUiPlugin.getRepositoryManager().saveRepositories(
125
									TasksUiPlugin.getRepositoryManager().saveRepositories(
126
											// ignore, since we might not be connected
128
											TasksUiPlugin.getDefault().getRepositoriesFilePath());
127
											TasksUiPlugin.getDefault().getRepositoriesFilePath());
129
								}
128
								}
130
							} catch (Exception e) {
129
							} catch (Exception e) {
Lines 136-142 Link Here
136
					//updateJob.setSystem(true);
135
					//updateJob.setSystem(true);
137
					updateJob.setPriority(Job.LONG);
136
					updateJob.setPriority(Job.LONG);
138
					updateJob.schedule();
137
					updateJob.schedule();
139
					lastRepositoryRefresh = null;
138
					// only persist if actually changed
139
					repository.updateConfigurationTimestamp();
140
				}
140
				}
141
141
142
				synchronizationManager.synchronize(connector, repository, queries, null, Job.DECORATE, 0, false,
142
				synchronizationManager.synchronize(connector, repository, queries, null, Job.DECORATE, 0, false,
Lines 146-154 Link Here
146
			}
146
			}
147
		} finally {
147
		} finally {
148
			count = count >= UPDATE_ATTRIBUTES_FREQUENCY ? 0 : count + 1;
148
			count = count >= UPDATE_ATTRIBUTES_FREQUENCY ? 0 : count + 1;
149
			if (lastRepositoryRefresh == null) {
150
				lastRepositoryRefresh = Calendar.getInstance();
151
			}
152
			if (monitor != null) {
149
			if (monitor != null) {
153
				monitor.done();
150
				monitor.done();
154
			}
151
			}
Lines 165-177 Link Here
165
	}
162
	}
166
163
167
	/**
164
	/**
168
	 * for testing purposes
165
	 * for testing purposes ONLY!
169
	 */
166
	 */
170
	public static long getCount() {
167
	public static long getCount() {
171
		return count;
168
		return count;
172
	}
169
	}
173
170
174
	/** for testing */
171
	/**
172
	 * for testing purposes ONLY!
173
	 */
175
	public static void resetCount() {
174
	public static void resetCount() {
176
		try {
175
		try {
177
			if (TasksUiPlugin.getSynchronizationScheduler().getRefreshJob() != null) {
176
			if (TasksUiPlugin.getSynchronizationScheduler().getRefreshJob() != null) {
(-)src/org/eclipse/mylyn/tasks/tests/TaskRepositoryTest.java (+16 lines)
Lines 9-14 Link Here
9
package org.eclipse.mylyn.tasks.tests;
9
package org.eclipse.mylyn.tasks.tests;
10
10
11
import java.net.URL;
11
import java.net.URL;
12
import java.util.Date;
12
import java.util.Map;
13
import java.util.Map;
13
14
14
import junit.framework.TestCase;
15
import junit.framework.TestCase;
Lines 117-120 Link Here
117
		assertEquals("pwd2", credentials.getPassword());
118
		assertEquals("pwd2", credentials.getPassword());
118
	}
119
	}
119
120
121
	public void testConfigUpdateStoring() throws Exception {
122
		URL url = new URL("http://url");
123
		TaskRepository taskRepository = new TaskRepository("kind", url.toString());
124
125
		Date stamp = taskRepository.getConfigurationTimestamp();
126
		assertTrue("unset stap returns long ago", stamp.before(new Date()));
127
128
		stamp = taskRepository.updateConfigurationTimestamp();
129
		assertEquals("Time stamp touched", stamp.getTime(),  taskRepository.getConfigurationTimestamp().getTime());
130
131
		stamp.setTime(stamp.getTime() - 1000000L);
132
		taskRepository.setConfigurationTimestamp(stamp);
133
		assertEquals("Time stamp set", stamp.getTime(), taskRepository.getConfigurationTimestamp().getTime());
134
	}
135
120
}
136
}
(-)src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java (-4 / +5 lines)
Lines 141-148 Link Here
141
				RepositoryConfiguration config = client.getRepositoryConfiguration();
141
				RepositoryConfiguration config = client.getRepositoryConfiguration();
142
				if (config != null) {
142
				if (config != null) {
143
					addRepositoryConfiguration(config);
143
					addRepositoryConfiguration(config);
144
					// remember just updated, bug 207498
145
					repository.updateConfigurationTimestamp();
144
				}
146
				}
145
146
			}
147
			}
147
			return repositoryConfigurations.get(repository.getUrl());
148
			return repositoryConfigurations.get(repository.getUrl());
148
		} catch (IOException e) {
149
		} catch (IOException e) {
Lines 245-251 Link Here
245
246
246
	/**
247
	/**
247
	 * Convenience method for logging statuses to the plugin log
248
	 * Convenience method for logging statuses to the plugin log
248
	 * 
249
	 *
249
	 * @param status
250
	 * @param status
250
	 *            the status to log
251
	 *            the status to log
251
	 */
252
	 */
Lines 255-261 Link Here
255
256
256
	/**
257
	/**
257
	 * Convenience method for logging exceptions to the plugin log
258
	 * Convenience method for logging exceptions to the plugin log
258
	 * 
259
	 *
259
	 * @param e
260
	 * @param e
260
	 *            the exception to log
261
	 *            the exception to log
261
	 */
262
	 */
Lines 394-400 Link Here
394
395
395
	private static void readBugzillaLanguageSettingsFile() {
396
	private static void readBugzillaLanguageSettingsFile() {
396
		setDefaultBugzillaLanguageSettings();
397
		setDefaultBugzillaLanguageSettings();
397
//		
398
//
398
//		if (!languageSettingsFile.exists()) {
399
//		if (!languageSettingsFile.exists()) {
399
//			setDefaultBugzillaLanguageSettings();
400
//			setDefaultBugzillaLanguageSettings();
400
//			return;
401
//			return;

Return to bug 207498