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/bugzilla/core/BugzillaRepositoryConnector.java (-14 / +16 lines)
Lines 465-488 Link Here
465
	}
465
	}
466
466
467
	public boolean isRepositoryConfigurationStale(TaskRepository repository) throws CoreException {
467
	public boolean isRepositoryConfigurationStale(TaskRepository repository) throws CoreException {
468
468
		if (super.isRepositoryConfigurationStale(repository)) {
469
		boolean result = true;
469
			boolean result = true;
470
		try {
470
			try {
471
			BugzillaClient client = getClientManager().getClient(repository);
471
				BugzillaClient client = getClientManager().getClient(repository);
472
			if (client != null) {
472
				if (client != null) {
473
				String timestamp = client.getConfigurationTimestamp();
473
					String timestamp = client.getConfigurationTimestamp();
474
				if (timestamp != null) {
474
					if (timestamp != null) {
475
					String oldTimestamp = repository.getProperty(IBugzillaConstants.PROPERTY_CONFIGTIMESTAMP);
475
						String oldTimestamp = repository.getProperty(IBugzillaConstants.PROPERTY_CONFIGTIMESTAMP);
476
					if (oldTimestamp != null) {
476
						if (oldTimestamp != null) {
477
						result = !timestamp.equals(oldTimestamp);
477
							result = !timestamp.equals(oldTimestamp);
478
						}
479
						repository.setProperty(IBugzillaConstants.PROPERTY_CONFIGTIMESTAMP, timestamp);
478
					}
480
					}
479
					repository.setProperty(IBugzillaConstants.PROPERTY_CONFIGTIMESTAMP, timestamp);
480
				}
481
				}
482
			} catch (MalformedURLException e) {
483
				StatusHandler.fail(e, "Error retrieving configuration timestamp for " + repository.getUrl(), false);
481
			}
484
			}
482
		} catch (MalformedURLException e) {
485
			return result;
483
			StatusHandler.fail(e, "Error retrieving configuration timestamp for " + repository.getUrl(), false);
484
		}
486
		}
485
		return result;
487
		return false;
486
	}
488
	}
487
489
488
	public void updateAttributeOptions(TaskRepository taskRepository, RepositoryTaskData existingReport)
490
	public void updateAttributeOptions(TaskRepository taskRepository, RepositoryTaskData existingReport)
(-)src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java (-1 / +17 lines)
Lines 33-38 Link Here
33
33
34
	protected Set<RepositoryTemplate> templates = new LinkedHashSet<RepositoryTemplate>();
34
	protected Set<RepositoryTemplate> templates = new LinkedHashSet<RepositoryTemplate>();
35
35
36
	private static final long HOUR = 1000L * 3600L;
37
38
	private static final long DAY = HOUR * 24L;
39
36
	protected TaskList taskList;
40
	protected TaskList taskList;
37
41
38
	private boolean userManaged = true;
42
	private boolean userManaged = true;
Lines 313-323 Link Here
313
	public abstract void updateAttributes(TaskRepository repository, IProgressMonitor monitor) throws CoreException;
317
	public abstract void updateAttributes(TaskRepository repository, IProgressMonitor monitor) throws CoreException;
314
318
315
	/**
319
	/**
320
	 * Default implementation returns true every 24hrs
321
	 * 
316
	 * @return true to indicate that the repository configuration is stale and requires update
322
	 * @return true to indicate that the repository configuration is stale and requires update
317
	 * @throws CoreException
323
	 * @throws CoreException
318
	 */
324
	 */
319
	public boolean isRepositoryConfigurationStale(TaskRepository repository) throws CoreException {
325
	public boolean isRepositoryConfigurationStale(TaskRepository repository) throws CoreException {
320
		return true;
326
		boolean isStale = true;
327
		Date configDate = repository.getConfigurationDate();
328
		if (configDate != null) {
329
			isStale = (new Date().getTime() - configDate.getTime()) > DAY;
330
		}
331
332
		if (isStale) {
333
			repository.setConfigurationDate(new Date());
334
		}
335
336
		return isStale;
321
	}
337
	}
322
338
323
	public void setUserManaged(boolean userManaged) {
339
	public void setUserManaged(boolean userManaged) {
(-)src/org/eclipse/mylyn/tasks/core/TaskRepository.java (-2 / +34 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 89-94 Link Here
89
90
90
	private static final URL DEFAULT_URL;
91
	private static final URL DEFAULT_URL;
91
92
93
	private static final String PROPERTY_CONFIG_TIMESTAMP = "org.eclipse.mylyn.tasklist.repositories.configuration.timestamp";
94
92
	public static final String PROXY_USEDEFAULT = "org.eclipse.mylyn.tasklist.repositories.proxy.usedefault";
95
	public static final String PROXY_USEDEFAULT = "org.eclipse.mylyn.tasklist.repositories.proxy.usedefault";
93
96
94
	public static final String PROXY_HOSTNAME = "org.eclipse.mylyn.tasklist.repositories.proxy.hostname";
97
	public static final String PROXY_HOSTNAME = "org.eclipse.mylyn.tasklist.repositories.proxy.hostname";
Lines 139-145 Link Here
139
	private Map<String, String> transientProperties = new HashMap<String, String>();
142
	private Map<String, String> transientProperties = new HashMap<String, String>();
140
143
141
	/*
144
	/*
142
	 * TODO: should be externalized and added to extension point, see bug 183606 
145
	 * TODO: should be externalized and added to extension point, see bug 183606
143
	 */
146
	 */
144
	private boolean isBugRepository = false;
147
	private boolean isBugRepository = false;
145
148
Lines 300-306 Link Here
300
	public void flushAuthenticationCredentials() {
303
	public void flushAuthenticationCredentials() {
301
		synchronized (LOCK) {
304
		synchronized (LOCK) {
302
			isCachedUserName = false;
305
			isCachedUserName = false;
303
		
306
304
			transientProperties.clear();
307
			transientProperties.clear();
305
308
306
			// API30: legacy support for versions prior to 2.2 that did not set the enable flag, remove for 3.0
309
			// API30: legacy support for versions prior to 2.2 that did not set the enable flag, remove for 3.0
Lines 698-701 Link Here
698
		return (credentials != null) ? credentials.getPassword() : null;
701
		return (credentials != null) ? credentials.getPassword() : null;
699
	}
702
	}
700
703
704
	/**
705
	 * Get the last refresh date as initialized {@link Date} object, null if not set<br />
706
	 * 
707
	 * @return {@link Date} configuration date, null if not set
708
	 */
709
	final public Date getConfigurationDate() {
710
		Date configDate = null;
711
		String value = this.getProperty(PROPERTY_CONFIG_TIMESTAMP);
712
		try {
713
			configDate = new Date(Long.valueOf(value).longValue());
714
715
		} catch (Exception e) {
716
717
		}
718
		return configDate;
719
	}
720
721
	/**
722
	 * Set the Configuration date to the {@link Date} indicated.
723
	 * 
724
	 * @param configuration
725
	 *            date {@link {@link Date}}
726
	 */
727
	final public void setConfigurationDate(final Date date) {
728
		this.setProperty(PROPERTY_CONFIG_TIMESTAMP, String.valueOf(date.getTime()));
729
		//  should persist here, but that can only be done by the TaskRepositoryManager
730
		// However this is also included when persisting ordinary sync time
731
	}
732
701
}
733
}
(-)src/org/eclipse/mylyn/tasks/tests/TaskRepositoryTest.java (+13 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
		Date stamp = taskRepository.getConfigurationDate();
125
		assertNull("unset configuration date returns null", stamp);
126
		stamp = new Date();
127
		stamp.setTime(stamp.getTime() - 35000L);
128
129
		taskRepository.setConfigurationDate(stamp);
130
		assertEquals("Time stamp set", stamp.getTime(), taskRepository.getConfigurationDate().getTime());
131
	}
132
120
}
133
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/ScheduledTaskListSynchJob.java (-29 / +25 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 45-52 Link Here
45
44
46
	private static long count = 0;
45
	private static long count = 0;
47
46
48
	private static Calendar lastRepositoryRefresh;
49
50
	private TaskListManager taskListManager;
47
	private TaskListManager taskListManager;
51
48
52
	private List<TaskRepository> repositories = null;
49
	private List<TaskRepository> repositories = null;
Lines 110-142 Link Here
110
107
111
				RepositorySynchronizationManager synchronizationManager = TasksUiPlugin.getSynchronizationManager();
108
				RepositorySynchronizationManager synchronizationManager = TasksUiPlugin.getSynchronizationManager();
112
				Set<AbstractRepositoryQuery> queries = taskList.getRepositoryQueries(repository.getUrl());
109
				Set<AbstractRepositoryQuery> queries = taskList.getRepositoryQueries(repository.getUrl());
113
110
				try {
114
				// Occasionally request update of repository configuration attributes
111
					// Occasionally request update of repository configuration attributes
115
				if ((lastRepositoryRefresh == null || lastRepositoryRefresh.get(Calendar.DAY_OF_MONTH) != Calendar.getInstance()
112
					if (queries != null && queries.size() > 0 && connector.isRepositoryConfigurationStale(repository)) {
116
						.get(Calendar.DAY_OF_MONTH))
113
						Job updateJob = new Job("Updating attributes for " + repository.getUrl()) {
117
						&& queries != null && queries.size() > 0) {
114
118
					Job updateJob = new Job("Updating attributes for " + repository.getUrl()) {
115
							@Override
119
116
							protected IStatus run(IProgressMonitor monitor) {
120
						@Override
117
								try {
121
						protected IStatus run(IProgressMonitor monitor) {
122
							try {
123
								if (connector.isRepositoryConfigurationStale(repository)) {
124
									connector.updateAttributes(repository, new SubProgressMonitor(monitor, 1));
118
									connector.updateAttributes(repository, new SubProgressMonitor(monitor, 1));
125
									// HACK: A configuration update occurred. Save on behalf of connector which 
119
									// HACK: A configuration update occurred. Save on behalf of connector which
126
									// currently can't access the repository manager itself
120
									// currently can't access the repository manager itself
127
									TasksUiPlugin.getRepositoryManager().saveRepositories(
121
									TasksUiPlugin.getRepositoryManager().saveRepositories(
122
									// ignore, since we might not be connected
128
											TasksUiPlugin.getDefault().getRepositoriesFilePath());
123
											TasksUiPlugin.getDefault().getRepositoriesFilePath());
124
125
								} catch (Exception e) {
126
									// ignore, since we might not be connected
129
								}
127
								}
130
							} catch (Exception e) {
128
								return Status.OK_STATUS;
131
								// ignore, since we might not be connected
132
							}
129
							}
133
							return Status.OK_STATUS;
130
						};
134
						}
131
						//updateJob.setSystem(true);
135
					};
132
						updateJob.setPriority(Job.LONG);
136
					//updateJob.setSystem(true);
133
						updateJob.schedule();
137
					updateJob.setPriority(Job.LONG);
134
					}
138
					updateJob.schedule();
135
				} catch (Exception e) {
139
					lastRepositoryRefresh = null;
136
					// ignore, since we might not be connected
140
				}
137
				}
141
138
142
				synchronizationManager.synchronize(connector, repository, queries, null, Job.DECORATE, 0, false,
139
				synchronizationManager.synchronize(connector, repository, queries, null, Job.DECORATE, 0, false,
Lines 146-154 Link Here
146
			}
143
			}
147
		} finally {
144
		} finally {
148
			count = count >= UPDATE_ATTRIBUTES_FREQUENCY ? 0 : count + 1;
145
			count = count >= UPDATE_ATTRIBUTES_FREQUENCY ? 0 : count + 1;
149
			if (lastRepositoryRefresh == null) {
150
				lastRepositoryRefresh = Calendar.getInstance();
151
			}
152
			if (monitor != null) {
146
			if (monitor != null) {
153
				monitor.done();
147
				monitor.done();
154
			}
148
			}
Lines 165-177 Link Here
165
	}
159
	}
166
160
167
	/**
161
	/**
168
	 * for testing purposes
162
	 * for testing purposes ONLY!
169
	 */
163
	 */
170
	public static long getCount() {
164
	public static long getCount() {
171
		return count;
165
		return count;
172
	}
166
	}
173
167
174
	/** for testing */
168
	/**
169
	 * for testing purposes ONLY!
170
	 */
175
	public static void resetCount() {
171
	public static void resetCount() {
176
		try {
172
		try {
177
			if (TasksUiPlugin.getSynchronizationScheduler().getRefreshJob() != null) {
173
			if (TasksUiPlugin.getSynchronizationScheduler().getRefreshJob() != null) {

Return to bug 207498