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/internal/tasks/ui/ScheduledTaskListSynchJob.java (-15 / +12 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 41-50 Link Here
41
40
42
	private TaskList taskList = null;
41
	private TaskList taskList = null;
43
42
43
	/**
44
	 * for testing ONLY!
45
	 */
44
	private static long count = 0;
46
	private static long count = 0;
45
47
46
	private static Calendar lastRepositoryRefresh;
47
48
	private TaskListManager taskListManager;
48
	private TaskListManager taskListManager;
49
49
50
	private List<TaskRepository> repositories = null;
50
	private List<TaskRepository> repositories = null;
Lines 94-102 Link Here
94
				Set<AbstractRepositoryQuery> queries = taskList.getRepositoryQueries(repository.getUrl());
94
				Set<AbstractRepositoryQuery> queries = taskList.getRepositoryQueries(repository.getUrl());
95
95
96
				// Occasionally request update of repository configuration attributes
96
				// Occasionally request update of repository configuration attributes
97
				if ((lastRepositoryRefresh == null || lastRepositoryRefresh.get(Calendar.DAY_OF_MONTH) != Calendar.getInstance()
97
				if (repository.configUpdateNeeded() && queries != null && queries.size() > 0) {
98
						.get(Calendar.DAY_OF_MONTH))
99
						&& queries != null && queries.size() > 0) {
100
					Job updateJob = new Job("Updating attributes for " + repository.getUrl()) {
98
					Job updateJob = new Job("Updating attributes for " + repository.getUrl()) {
101
99
102
						@Override
100
						@Override
Lines 104-116 Link Here
104
							try {
102
							try {
105
								if (connector.isRepositoryConfigurationStale(repository)) {
103
								if (connector.isRepositoryConfigurationStale(repository)) {
106
									connector.updateAttributes(repository, new SubProgressMonitor(monitor, 1));
104
									connector.updateAttributes(repository, new SubProgressMonitor(monitor, 1));
107
									// HACK: A configuration update occurred. Save on behalf of connector which 
105
									// HACK: A configuration update occurred. Save on behalf of connector which
108
									// currently can't access the repository manager itself
106
									// currently can't access the repository manager itself
109
									TasksUiPlugin.getRepositoryManager().saveRepositories(
107
									TasksUiPlugin.getRepositoryManager().saveRepositories(
108
											// ignore, since we might not be connected
110
											TasksUiPlugin.getDefault().getRepositoriesFilePath());
109
											TasksUiPlugin.getDefault().getRepositoriesFilePath());
111
								}
110
								}
112
							} catch (Exception e) {
111
							} catch (Exception e) {
113
								// ignore, since we might not be connected
114
							}
112
							}
115
							return Status.OK_STATUS;
113
							return Status.OK_STATUS;
116
						}
114
						}
Lines 118-135 Link Here
118
					//updateJob.setSystem(true);
116
					//updateJob.setSystem(true);
119
					updateJob.setPriority(Job.LONG);
117
					updateJob.setPriority(Job.LONG);
120
					updateJob.schedule();
118
					updateJob.schedule();
121
					lastRepositoryRefresh = null;
119
					// only persist if actually changed
120
					repository.touchConfigurationTimestamp();
122
				}
121
				}
123
124
				synchronizationManager.synchronize(connector, repository, queries, null, Job.DECORATE, 0, false);
122
				synchronizationManager.synchronize(connector, repository, queries, null, Job.DECORATE, 0, false);
125
123
126
				monitor.worked(1);
124
				monitor.worked(1);
127
			}
125
			}
128
		} finally {
126
		} finally {
129
			count = count >= UPDATE_ATTRIBUTES_FREQUENCY ? 0 : count + 1;
127
			count = count >= UPDATE_ATTRIBUTES_FREQUENCY ? 0 : count + 1;
130
			if (lastRepositoryRefresh == null) {
131
				lastRepositoryRefresh = Calendar.getInstance();
132
			}
133
			if (monitor != null) {
128
			if (monitor != null) {
134
				monitor.done();
129
				monitor.done();
135
			}
130
			}
Lines 146-158 Link Here
146
	}
141
	}
147
142
148
	/**
143
	/**
149
	 * for testing purposes
144
	 * for testing purposes ONLY!
150
	 */
145
	 */
151
	public static long getCount() {
146
	public static long getCount() {
152
		return count;
147
		return count;
153
	}
148
	}
154
149
155
	/** for testing */
150
	/**
151
	 * for testing purposes ONLY!
152
	 */
156
	public static void resetCount() {
153
	public static void resetCount() {
157
		try {
154
		try {
158
			if (TasksUiPlugin.getSynchronizationScheduler().getRefreshJob() != null) {
155
			if (TasksUiPlugin.getSynchronizationScheduler().getRefreshJob() != null) {
(-)src/org/eclipse/mylyn/tasks/core/TaskRepository.java (-2 / +59 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 34-40 Link Here
34
 * <li>The solution we have come up with thus far is not to interpret the date as a DATE object but rather simply use
35
 * <li>The solution we have come up with thus far is not to interpret the date as a DATE object but rather simply use
35
 * the date string given to us by the repository itself.</li>
36
 * the date string given to us by the repository itself.</li>
36
 * </ul>
37
 * </ul>
37
 * 
38
 *
38
 * @author Mik Kersten
39
 * @author Mik Kersten
39
 * @author Rob Elves
40
 * @author Rob Elves
40
 * @author Eugene Kuleshov
41
 * @author Eugene Kuleshov
Lines 144-153 Link Here
144
	private Map<String, String> transientProperties = new HashMap<String, String>();
145
	private Map<String, String> transientProperties = new HashMap<String, String>();
145
146
146
	/*
147
	/*
147
	 * TODO: should be externalized and added to extension point, see bug 183606 
148
	 * TODO: should be externalized and added to extension point, see bug 183606
148
	 */
149
	 */
149
	private boolean isBugRepository = false;
150
	private boolean isBugRepository = false;
150
151
152
	public static final String LAST_CONFIG_REFRESH = "config.lastupdate";
153
154
	private static final long LONG_AGO = 1000L * 3600L * 24L; // 24 hrs ago
155
151
	/**
156
	/**
152
	 * for testing purposes
157
	 * for testing purposes
153
	 */
158
	 */
Lines 569-572 Link Here
569
		return transientProperties.get(authType + PASSWORD);
574
		return transientProperties.get(authType + PASSWORD);
570
	}
575
	}
571
576
577
578
	/**
579
	 *	Get the last refresh date as initialized {@link Date} object.<br />
580
	 *  Internal representation is {@link String} determined by {@link TimestampUtils}.<br />
581
	 *	See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=207660">bug
582
	 *  207660: do not update repository configuration on every startup</a>
583
	 * @return {@link Date} set to last config update OR LONG_AGO if not found
584
	 */
585
	final public Date getConfigurationTimestamp() {
586
		String value = this.getProperty(LAST_CONFIG_REFRESH);
587
		Date stamp = null;
588
		if(null != value) {
589
			stamp = TimestampUtils.stringToDate(value);
590
		} else {
591
			stamp = new Date((new Date()).getTime() - LONG_AGO);
592
		}
593
		return stamp;
594
	}
595
596
	/**
597
	 * Utility method, set the Configuration Timestamp to now AND return it.
598
	 */
599
	final public Date touchConfigurationTimestamp() {
600
		Date now = new Date();
601
		this.setConfigurationTimestamp(now);
602
		return now;
603
	}
604
605
	/**
606
	 * set the Configuration Timestamp to the {@link Date} indicated.
607
	 *
608
	 * 	The last config update day is persisted as {@link String} determined in {@link TimestampUtils}.<br />
609
	 *	See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=207660">bug
610
	 *	207660: do not update repository configuration on every startup</a>
611
	 * @param {@link {@link Date}} setting the day
612
	 */
613
	final public void setConfigurationTimestamp(final Date timeStamp) {
614
		this.setProperty(LAST_CONFIG_REFRESH, TimestampUtils.dateToString(timeStamp));
615
		//  should persist here, but that can only be done by the TaskRepositoryManager
616
		// However this is also included when persisting ordinary sync time
617
	}
618
619
620
	/**
621
	 * This determines the configuration update policy of this repository.<br />
622
	 * This says yes when it is more than 24 hours ago. Future update policies may be set on a per repository basis.
623
	 * @return true when configuration update needed.
624
	 */
625
	public boolean configUpdateNeeded() {
626
		return TimestampUtils.moreThanAgo(getConfigurationTimestamp(), TimestampUtils.DAY);
627
	}
628
572
}
629
}
(-)src/org/eclipse/mylyn/tasks/tests/TaskRepositoryTest.java (-8 / +24 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 38-51 Link Here
38
		taskRepository.setCredentials(TaskRepository.AUTH_DEFAULT, "user", "pwd");
39
		taskRepository.setCredentials(TaskRepository.AUTH_DEFAULT, "user", "pwd");
39
		assertEquals("user", taskRepository.getUserName());
40
		assertEquals("user", taskRepository.getUserName());
40
		assertEquals("pwd", taskRepository.getPassword());
41
		assertEquals("pwd", taskRepository.getPassword());
41
		
42
42
		assertEquals(null, taskRepository.getHttpUser());
43
		assertEquals(null, taskRepository.getHttpUser());
43
		assertEquals(null, taskRepository.getHttpPassword());
44
		assertEquals(null, taskRepository.getHttpPassword());
44
	}
45
	}
45
	
46
46
	public void testHttpPassword() throws Exception {
47
	public void testHttpPassword() throws Exception {
47
		password(TaskRepository.AUTH_HTTP);
48
		password(TaskRepository.AUTH_HTTP);
48
		
49
49
		TaskRepository taskRepository = new TaskRepository("kind", "url");
50
		TaskRepository taskRepository = new TaskRepository("kind", "url");
50
		taskRepository.setCredentials(TaskRepository.AUTH_HTTP, "user", "pwd");
51
		taskRepository.setCredentials(TaskRepository.AUTH_HTTP, "user", "pwd");
51
		assertEquals("user", taskRepository.getHttpUser());
52
		assertEquals("user", taskRepository.getHttpUser());
Lines 66-88 Link Here
66
		TaskRepository taskRepository = new TaskRepository("kind", url.toString());
67
		TaskRepository taskRepository = new TaskRepository("kind", url.toString());
67
		assertNull(taskRepository.getPassword(authType));
68
		assertNull(taskRepository.getPassword(authType));
68
		assertTrue(taskRepository.getSavePassword(authType));
69
		assertTrue(taskRepository.getSavePassword(authType));
69
		
70
70
		taskRepository.setCredentials(authType, "user", "pwd");
71
		taskRepository.setCredentials(authType, "user", "pwd");
71
		assertEquals("user", taskRepository.getUserName(authType));
72
		assertEquals("user", taskRepository.getUserName(authType));
72
		assertEquals("pwd", taskRepository.getPassword(authType));
73
		assertEquals("pwd", taskRepository.getPassword(authType));
73
		
74
74
		Map<?, ?> map = Platform.getAuthorizationInfo(url, "", "Basic");
75
		Map<?, ?> map = Platform.getAuthorizationInfo(url, "", "Basic");
75
		assertNotNull(map);
76
		assertNotNull(map);
76
		assertTrue(map.containsValue("user"));
77
		assertTrue(map.containsValue("user"));
77
		assertTrue(map.containsValue("pwd"));
78
		assertTrue(map.containsValue("pwd"));
78
		
79
79
		// test not saving password
80
		// test not saving password
80
		taskRepository.setSavePassword(authType, false);
81
		taskRepository.setSavePassword(authType, false);
81
		assertFalse(taskRepository.getSavePassword(authType));
82
		assertFalse(taskRepository.getSavePassword(authType));
82
		taskRepository.setCredentials(authType, "user1", "pwd1");
83
		taskRepository.setCredentials(authType, "user1", "pwd1");
83
		assertEquals("user1", taskRepository.getUserName(authType));
84
		assertEquals("user1", taskRepository.getUserName(authType));
84
		assertEquals("pwd1", taskRepository.getPassword(authType));
85
		assertEquals("pwd1", taskRepository.getPassword(authType));
85
		
86
86
		// make sure not old passwords are in the key ring
87
		// make sure not old passwords are in the key ring
87
		map = Platform.getAuthorizationInfo(url, "", "Basic");
88
		map = Platform.getAuthorizationInfo(url, "", "Basic");
88
		assertNotNull(map);
89
		assertNotNull(map);
Lines 90-96 Link Here
90
		assertFalse(map.containsValue("pwd1"));
91
		assertFalse(map.containsValue("pwd1"));
91
		assertFalse(map.containsValue("user"));
92
		assertFalse(map.containsValue("user"));
92
		assertFalse(map.containsValue("pwd"));
93
		assertFalse(map.containsValue("pwd"));
93
		
94
94
		taskRepository.setSavePassword(authType, true);
95
		taskRepository.setSavePassword(authType, true);
95
		assertTrue(taskRepository.getSavePassword(authType));
96
		assertTrue(taskRepository.getSavePassword(authType));
96
		taskRepository.setCredentials(authType, "user2", "pwd2");
97
		taskRepository.setCredentials(authType, "user2", "pwd2");
Lines 98-101 Link Here
98
		assertEquals("pwd2", taskRepository.getPassword(authType));
99
		assertEquals("pwd2", taskRepository.getPassword(authType));
99
	}
100
	}
100
101
102
	public void testConfigUpdateStoring() throws Exception {
103
		URL url = new URL("http://url");
104
		TaskRepository taskRepository = new TaskRepository("kind", url.toString());
105
106
		Date stamp = taskRepository.getConfigurationTimestamp();
107
		assertTrue("unset stap returns long ago", stamp.before(new Date()));
108
109
		stamp = taskRepository.touchConfigurationTimestamp();
110
		assertEquals("Time stamp touched", stamp.getTime(),  taskRepository.getConfigurationTimestamp().getTime());
111
112
		stamp.setTime(stamp.getTime() - 1000000L);
113
		taskRepository.setConfigurationTimestamp(stamp);
114
		assertEquals("Time stamp set", stamp.getTime(), taskRepository.getConfigurationTimestamp().getTime());
115
	}
116
101
}
117
}
(-)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.touchConfigurationTimestamp();
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