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 (-6 / +73 lines)
Lines 37-46 Link Here
37
37
38
	private static final String JOB_NAME = "Synchronizing repository tasks";
38
	private static final String JOB_NAME = "Synchronizing repository tasks";
39
39
40
	private static final String LAST_CONFIG_REFRESH = "config.lastupdate";
41
40
	private long scheduleDelay = 1000 * 60 * 20;// 20 minutes default
42
	private long scheduleDelay = 1000 * 60 * 20;// 20 minutes default
41
43
42
	private TaskList taskList = null;
44
	private TaskList taskList = null;
43
45
46
	/**
47
	 * for testing ONLY!
48
	 */
44
	private static long count = 0;
49
	private static long count = 0;
45
50
46
	private static Calendar lastRepositoryRefresh;
51
	private static Calendar lastRepositoryRefresh;
Lines 83-88 Link Here
83
					continue;
88
					continue;
84
				}
89
				}
85
90
91
92
				if(null == lastRepositoryRefresh) {
93
					getLastRefreshFromStore(repository);
94
				}
95
96
86
				final AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
97
				final AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
87
						.getRepositoryConnector(repository.getConnectorKind());
98
						.getRepositoryConnector(repository.getConnectorKind());
88
				if (connector == null) {
99
				if (connector == null) {
Lines 104-110 Link Here
104
							try {
115
							try {
105
								if (connector.isRepositoryConfigurationStale(repository)) {
116
								if (connector.isRepositoryConfigurationStale(repository)) {
106
									connector.updateAttributes(repository, new SubProgressMonitor(monitor, 1));
117
									connector.updateAttributes(repository, new SubProgressMonitor(monitor, 1));
107
									// HACK: A configuration update occurred. Save on behalf of connector which 
118
									// HACK: A configuration update occurred. Save on behalf of connector which
108
									// currently can't access the repository manager itself
119
									// currently can't access the repository manager itself
109
									TasksUiPlugin.getRepositoryManager().saveRepositories(
120
									TasksUiPlugin.getRepositoryManager().saveRepositories(
110
											TasksUiPlugin.getDefault().getRepositoriesFilePath());
121
											TasksUiPlugin.getDefault().getRepositoriesFilePath());
Lines 120-125 Link Here
120
					updateJob.schedule();
131
					updateJob.schedule();
121
					lastRepositoryRefresh = null;
132
					lastRepositoryRefresh = null;
122
				}
133
				}
134
				// only persist if actually changed
135
				if (null == lastRepositoryRefresh) {
136
					lastRepositoryRefresh = Calendar.getInstance();
137
					saveLastRefreshToStore(repository, lastRepositoryRefresh);
138
				}
123
139
124
				synchronizationManager.synchronize(connector, repository, queries, null, Job.DECORATE, 0, false);
140
				synchronizationManager.synchronize(connector, repository, queries, null, Job.DECORATE, 0, false);
125
141
Lines 127-135 Link Here
127
			}
143
			}
128
		} finally {
144
		} finally {
129
			count = count >= UPDATE_ATTRIBUTES_FREQUENCY ? 0 : count + 1;
145
			count = count >= UPDATE_ATTRIBUTES_FREQUENCY ? 0 : count + 1;
130
			if (lastRepositoryRefresh == null) {
131
				lastRepositoryRefresh = Calendar.getInstance();
132
			}
133
			if (monitor != null) {
146
			if (monitor != null) {
134
				monitor.done();
147
				monitor.done();
135
			}
148
			}
Lines 137-142 Link Here
137
		return Status.OK_STATUS;
150
		return Status.OK_STATUS;
138
	}
151
	}
139
152
153
154
	/**
155
	 * @param repository to save the last config update in the Repository persistent properties.
156
	 * To be called when doing manual update :-)
157
	 */
158
	public static void touch(TaskRepository repository) {
159
		saveLastRefreshToStore(repository, Calendar.getInstance());
160
	}
161
162
	/**
163
	 *	Save the last refresh date as <code>long</code> YYYYMMDD<br />
164
	 *	See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=207660">bug
165
	 *	207660: do not update repository configuration on every startup</a>
166
	 * @param repository
167
	 */
168
	private static void saveLastRefreshToStore(TaskRepository repository, Calendar lastRefresh) {
169
		// ignore
170
		long last = 10000L * lastRefresh.get(Calendar.YEAR) + 100L * lastRefresh.get(Calendar.MONTH)
171
				+ lastRefresh.get(Calendar.DAY_OF_MONTH);
172
		// TasksUiPlugin.getDefault().getPreferenceStore().setValue(LAST_REFRESH, last);
173
		repository.setProperty(LAST_CONFIG_REFRESH, Long.toString(last));
174
	}
175
176
	/**
177
	 *	Get the last refresh date as <code>long</code> YYYYMMDD between invocations.<br />
178
	 *	See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=207660">bug
179
	 *  207660: do not update repository configuration on every startup</a>
180
	 * @param repository
181
	 */
182
	private static void getLastRefreshFromStore(TaskRepository repository) {
183
		// Only DAY_OF_MONTH is used for the test, but lets save MONTH and YEAR as well
184
		// long lastRefresh = TasksUiPlugin.getDefault().getPreferenceStore().getLong(LAST_REFRESH);
185
		String value = repository.getProperty(LAST_CONFIG_REFRESH);
186
		if(null != value) {
187
			try {
188
				long lastRefresh = Long.parseLong(value);
189
				int year = (int) (lastRefresh / 10000L);
190
				int month = (int) ((lastRefresh - 100L * year) / 100L);
191
				int date = (int) (lastRefresh - 100L * month - 10000L * year);;
192
				// get new calendar...
193
				if( year > 0) {
194
					lastRepositoryRefresh = Calendar.getInstance();
195
					lastRepositoryRefresh.set(year, month, date);
196
				}
197
			} catch (NumberFormatException e) {
198
				// TODO Auto-generated catch block
199
				; // ignore e.printStackTrace();
200
			}
201
		}
202
203
	}
204
140
	public void setSchedule(long schedule) {
205
	public void setSchedule(long schedule) {
141
		this.scheduleDelay = schedule;
206
		this.scheduleDelay = schedule;
142
	}
207
	}
Lines 146-158 Link Here
146
	}
211
	}
147
212
148
	/**
213
	/**
149
	 * for testing purposes
214
	 * for testing purposes ONLY!
150
	 */
215
	 */
151
	public static long getCount() {
216
	public static long getCount() {
152
		return count;
217
		return count;
153
	}
218
	}
154
219
155
	/** for testing */
220
	/**
221
	 * for testing purposes ONLY!
222
	 */
156
	public static void resetCount() {
223
	public static void resetCount() {
157
		try {
224
		try {
158
			if (TasksUiPlugin.getSynchronizationScheduler().getRefreshJob() != null) {
225
			if (TasksUiPlugin.getSynchronizationScheduler().getRefreshJob() != null) {

Return to bug 207498