Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 16d5b2a33156f4272ef689fc2370654cd270c1f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
/*
 * Copyright (c) 2013, 2014 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 *    Julian Enoch - Add authentication to build server
 */
package org.eclipse.emf.cdo.releng.setup.impl;

import org.eclipse.emf.cdo.releng.setup.MylynQueriesTask;
import org.eclipse.emf.cdo.releng.setup.Query;
import org.eclipse.emf.cdo.releng.setup.SetupFactory;
import org.eclipse.emf.cdo.releng.setup.SetupPackage;
import org.eclipse.emf.cdo.releng.setup.SetupTaskContainer;
import org.eclipse.emf.cdo.releng.setup.SetupTaskContext;
import org.eclipse.emf.cdo.releng.setup.Trigger;

import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.StringUtil;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.TasksUi;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Mylyn Queries Task</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.eclipse.emf.cdo.releng.setup.impl.MylynQueriesTaskImpl#getConnectorKind <em>Connector Kind</em>}</li>
 *   <li>{@link org.eclipse.emf.cdo.releng.setup.impl.MylynQueriesTaskImpl#getRepositoryURL <em>Repository URL</em>}</li>
 *   <li>{@link org.eclipse.emf.cdo.releng.setup.impl.MylynQueriesTaskImpl#getUserID <em>User ID</em>}</li>
 *   <li>{@link org.eclipse.emf.cdo.releng.setup.impl.MylynQueriesTaskImpl#getPassword <em>Password</em>}</li>
 *   <li>{@link org.eclipse.emf.cdo.releng.setup.impl.MylynQueriesTaskImpl#getQueries <em>Queries</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
@SuppressWarnings("restriction")
public class MylynQueriesTaskImpl extends SetupTaskImpl implements MylynQueriesTask
{
  /**
   * The default value of the '{@link #getConnectorKind() <em>Connector Kind</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getConnectorKind()
   * @generated
   * @ordered
   */
  protected static final String CONNECTOR_KIND_EDEFAULT = "bugzilla";

  /**
   * The cached value of the '{@link #getConnectorKind() <em>Connector Kind</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getConnectorKind()
   * @generated
   * @ordered
   */
  protected String connectorKind = CONNECTOR_KIND_EDEFAULT;

  /**
   * The default value of the '{@link #getRepositoryURL() <em>Repository URL</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRepositoryURL()
   * @generated
   * @ordered
   */
  protected static final String REPOSITORY_URL_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getRepositoryURL() <em>Repository URL</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRepositoryURL()
   * @generated
   * @ordered
   */
  protected String repositoryURL = REPOSITORY_URL_EDEFAULT;

  /**
   * The default value of the '{@link #getUserID() <em>User ID</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getUserID()
   * @generated
   * @ordered
   */
  protected static final String USER_ID_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getUserID() <em>User ID</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getUserID()
   * @generated
   * @ordered
   */
  protected String userID = USER_ID_EDEFAULT;

  /**
   * The default value of the '{@link #getPassword() <em>Password</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getPassword()
   * @generated
   * @ordered
   */
  protected static final String PASSWORD_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getPassword() <em>Password</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getPassword()
   * @generated
   * @ordered
   */
  protected String password = PASSWORD_EDEFAULT;

  /**
   * The cached value of the '{@link #getQueries() <em>Queries</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getQueries()
   * @generated
   * @ordered
   */
  protected EList<Query> queries;

  private transient MylynHelper mylynHelper;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected MylynQueriesTaskImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return SetupPackage.Literals.MYLYN_QUERIES_TASK;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getConnectorKind()
  {
    return connectorKind;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setConnectorKind(String newConnectorKind)
  {
    String oldConnectorKind = connectorKind;
    connectorKind = newConnectorKind;
    if (eNotificationRequired())
    {
      eNotify(new ENotificationImpl(this, Notification.SET, SetupPackage.MYLYN_QUERIES_TASK__CONNECTOR_KIND,
          oldConnectorKind, connectorKind));
    }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getRepositoryURL()
  {
    return repositoryURL;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setRepositoryURL(String newRepositoryURL)
  {
    String oldRepositoryURL = repositoryURL;
    repositoryURL = newRepositoryURL;
    if (eNotificationRequired())
    {
      eNotify(new ENotificationImpl(this, Notification.SET, SetupPackage.MYLYN_QUERIES_TASK__REPOSITORY_URL,
          oldRepositoryURL, repositoryURL));
    }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Query> getQueries()
  {
    if (queries == null)
    {
      queries = new EObjectContainmentWithInverseEList.Resolving<Query>(Query.class, this,
          SetupPackage.MYLYN_QUERIES_TASK__QUERIES, SetupPackage.QUERY__TASK);
    }
    return queries;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getUserID()
  {
    return userID;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setUserID(String newUserID)
  {
    String oldUserID = userID;
    userID = newUserID;
    if (eNotificationRequired())
    {
      eNotify(new ENotificationImpl(this, Notification.SET, SetupPackage.MYLYN_QUERIES_TASK__USER_ID, oldUserID, userID));
    }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getPassword()
  {
    return password;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setPassword(String newPassword)
  {
    String oldPassword = password;
    password = newPassword;
    if (eNotificationRequired())
    {
      eNotify(new ENotificationImpl(this, Notification.SET, SetupPackage.MYLYN_QUERIES_TASK__PASSWORD, oldPassword,
          password));
    }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
    case SetupPackage.MYLYN_QUERIES_TASK__QUERIES:
      return ((InternalEList<InternalEObject>)(InternalEList<?>)getQueries()).basicAdd(otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
    case SetupPackage.MYLYN_QUERIES_TASK__QUERIES:
      return ((InternalEList<?>)getQueries()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
    case SetupPackage.MYLYN_QUERIES_TASK__CONNECTOR_KIND:
      return getConnectorKind();
    case SetupPackage.MYLYN_QUERIES_TASK__REPOSITORY_URL:
      return getRepositoryURL();
    case SetupPackage.MYLYN_QUERIES_TASK__USER_ID:
      return getUserID();
    case SetupPackage.MYLYN_QUERIES_TASK__PASSWORD:
      return getPassword();
    case SetupPackage.MYLYN_QUERIES_TASK__QUERIES:
      return getQueries();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
    case SetupPackage.MYLYN_QUERIES_TASK__CONNECTOR_KIND:
      setConnectorKind((String)newValue);
      return;
    case SetupPackage.MYLYN_QUERIES_TASK__REPOSITORY_URL:
      setRepositoryURL((String)newValue);
      return;
    case SetupPackage.MYLYN_QUERIES_TASK__USER_ID:
      setUserID((String)newValue);
      return;
    case SetupPackage.MYLYN_QUERIES_TASK__PASSWORD:
      setPassword((String)newValue);
      return;
    case SetupPackage.MYLYN_QUERIES_TASK__QUERIES:
      getQueries().clear();
      getQueries().addAll((Collection<? extends Query>)newValue);
      return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
    case SetupPackage.MYLYN_QUERIES_TASK__CONNECTOR_KIND:
      setConnectorKind(CONNECTOR_KIND_EDEFAULT);
      return;
    case SetupPackage.MYLYN_QUERIES_TASK__REPOSITORY_URL:
      setRepositoryURL(REPOSITORY_URL_EDEFAULT);
      return;
    case SetupPackage.MYLYN_QUERIES_TASK__USER_ID:
      setUserID(USER_ID_EDEFAULT);
      return;
    case SetupPackage.MYLYN_QUERIES_TASK__PASSWORD:
      setPassword(PASSWORD_EDEFAULT);
      return;
    case SetupPackage.MYLYN_QUERIES_TASK__QUERIES:
      getQueries().clear();
      return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
    case SetupPackage.MYLYN_QUERIES_TASK__CONNECTOR_KIND:
      return CONNECTOR_KIND_EDEFAULT == null ? connectorKind != null : !CONNECTOR_KIND_EDEFAULT.equals(connectorKind);
    case SetupPackage.MYLYN_QUERIES_TASK__REPOSITORY_URL:
      return REPOSITORY_URL_EDEFAULT == null ? repositoryURL != null : !REPOSITORY_URL_EDEFAULT.equals(repositoryURL);
    case SetupPackage.MYLYN_QUERIES_TASK__USER_ID:
      return USER_ID_EDEFAULT == null ? userID != null : !USER_ID_EDEFAULT.equals(userID);
    case SetupPackage.MYLYN_QUERIES_TASK__PASSWORD:
      return PASSWORD_EDEFAULT == null ? password != null : !PASSWORD_EDEFAULT.equals(password);
    case SetupPackage.MYLYN_QUERIES_TASK__QUERIES:
      return queries != null && !queries.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy())
    {
      return super.toString();
    }

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (connectorKind: ");
    result.append(connectorKind);
    result.append(", repositoryURL: ");
    result.append(repositoryURL);
    result.append(", userID: ");
    result.append(userID);
    result.append(", password: ");
    result.append(password);
    result.append(')');
    return result.toString();
  }

  @Override
  public Set<Trigger> getValidTriggers()
  {
    return Trigger.IDE_TRIGGERS;
  }

  public boolean isNeeded(SetupTaskContext context) throws Exception
  {
    mylynHelper = MylynHelperImpl.create();
    return mylynHelper.isNeeded(context, this);
  }

  public void perform(SetupTaskContext context) throws Exception
  {
    mylynHelper.perform(context, this);
  }

  @Override
  public void collectSniffers(List<Sniffer> sniffers)
  {
    sniffers.add(new BasicSniffer(this, "Creates one or several tasks for the queries in the Mylyn task list.")
    {
      public void sniff(SetupTaskContainer container, List<Sniffer> dependencies, IProgressMonitor monitor)
          throws Exception
      {
        MylynHelper mylynHelper = MylynHelperImpl.create();
        mylynHelper.sniff(container, null, monitor);
      }
    });
  }

  /**
   * @author Eike Stepper
   */
  protected interface MylynHelper
  {
    public boolean isNeeded(SetupTaskContext context, MylynQueriesTask task) throws Exception;

    public void perform(SetupTaskContext context, MylynQueriesTask task) throws Exception;

    public void sniff(SetupTaskContainer container, List<Sniffer> dependencies, IProgressMonitor monitor);
  }

  /**
   * @author Eike Stepper
   */
  private static class MylynHelperImpl implements MylynHelper
  {
    private TaskRepository repository;

    private Map<Query, RepositoryQuery> repositoryQueries = new HashMap<Query, RepositoryQuery>();

    public boolean isNeeded(SetupTaskContext context, MylynQueriesTask task) throws Exception
    {
      String connectorKind = task.getConnectorKind();
      String repositoryURL = task.getRepositoryURL();
      repository = TasksUi.getRepositoryManager().getRepository(connectorKind, repositoryURL);

      for (Query query : task.getQueries())
      {
        context.checkCancelation();

        RepositoryQuery repositoryQuery = getRepositoryQuery(query);
        if (repositoryQuery == null || isQueryDifferent(query, repositoryQuery))
        {
          repositoryQueries.put(query, repositoryQuery);
        }
      }

      if (repository == null)
      {
        return true;
      }

      if (!repositoryQueries.isEmpty())
      {
        return true;
      }

      return false;
    }

    public void perform(SetupTaskContext context, MylynQueriesTask task) throws Exception
    {
      String connectorKind = task.getConnectorKind();
      String repositoryURL = task.getRepositoryURL();

      if (repository == null)
      {
        context.log("Adding " + connectorKind + " repository: " + repositoryURL);
        repository = new TaskRepository(connectorKind, repositoryURL);

        String userID = task.getUserID();
        String password = context.expandString(task.getPassword(), true);
        if (!StringUtil.isEmpty(userID) && !StringUtil.isEmpty(password))
        {
          AuthenticationCredentials credentials = new AuthenticationCredentials(userID, password);
          repository.setCredentials(AuthenticationType.REPOSITORY, credentials, true);
        }

        TasksUi.getRepositoryManager().addRepository(repository);
      }

      for (Map.Entry<Query, RepositoryQuery> entry : repositoryQueries.entrySet())
      {
        Query query = entry.getKey();
        RepositoryQuery repositoryQuery = entry.getValue();

        String summary = query.getSummary();

        if (repositoryQuery == null)
        {
          context.log("Adding " + connectorKind + " query: " + summary);
          String handle = TasksUiPlugin.getTaskList().getUniqueHandleIdentifier();
          repositoryQuery = new RepositoryQuery(connectorKind, handle);
          repositoryQuery.setSummary(summary);
          entry.setValue(repositoryQuery);

          repositoryQuery.setRepositoryUrl(repositoryURL);
          configureQuery(context, query, repositoryQuery);

          TasksUiPlugin.getTaskList().addQuery(repositoryQuery);
        }
        else
        {
          context.log("Changing " + connectorKind + " query: " + summary);

          repositoryQuery.setRepositoryUrl(repositoryURL);
          configureQuery(context, query, repositoryQuery);
        }
      }

      Set<RepositoryQuery> queries = new HashSet<RepositoryQuery>(repositoryQueries.values());
      TasksUiPlugin.getTaskList().notifyElementsChanged(queries);

      AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector(connectorKind);
      TasksUiInternal.synchronizeQueries(connector, repository, queries, null, true);
    }

    private RepositoryQuery getRepositoryQuery(Query query) throws Exception
    {
      for (RepositoryQuery repositoryQuery : TasksUiPlugin.getTaskList().getQueries())
      {
        if (ObjectUtil.equals(repositoryQuery.getSummary(), query.getSummary()))
        {
          return repositoryQuery;
        }
      }

      return null;
    }

    private boolean isQueryDifferent(Query query, RepositoryQuery repositoryQuery) throws Exception
    {
      String url = query.getURL();
      if (!ObjectUtil.equals(repositoryQuery.getUrl(), url))
      {
        return true;
      }

      Map<String, String> attributes = query.getAttributes().map();
      if (!ObjectUtil.equals(repositoryQuery.getAttributes(), attributes))
      {
        return true;
      }

      return false;
    }

    private void configureQuery(SetupTaskContext context, Query query, RepositoryQuery repositoryQuery)
    {
      String url = query.getURL();
      if (!ObjectUtil.equals(url, repositoryQuery.getUrl()))
      {
        context.log("Setting query URL = " + url);
        repositoryQuery.setUrl(url);
      }

      Map<String, String> repositoryAttributes = repositoryQuery.getAttributes();
      Map<String, String> attributes = query.getAttributes().map();

      for (Entry<String, String> entry : attributes.entrySet())
      {
        String key = entry.getKey();
        String value = entry.getValue();

        String repositoryValue = repositoryAttributes.get(key);
        if (!ObjectUtil.equals(value, repositoryValue))
        {
          context.log("Setting query attribute " + key + " = " + value);
          repositoryQuery.setAttribute(key, value);
        }
      }

      for (String key : new ArrayList<String>(repositoryAttributes.keySet()))
      {
        if (!attributes.containsKey(key))
        {
          context.log("Removing query attribute " + key);
          repositoryQuery.setAttribute(key, null);
        }
      }
    }

    public void sniff(SetupTaskContainer container, List<Sniffer> dependencies, IProgressMonitor monitor)
    {
      Map<String, MylynQueriesTask> tasks = new HashMap<String, MylynQueriesTask>();
      for (RepositoryQuery repositoryQuery : TasksUiPlugin.getTaskList().getQueries())
      {
        String repositoryURL = repositoryQuery.getRepositoryUrl();
        MylynQueriesTask task = tasks.get(repositoryURL);
        if (task == null)
        {
          task = SetupFactory.eINSTANCE.createMylynQueriesTask();
          task.setRepositoryURL(repositoryURL);
          task.setConnectorKind(repositoryQuery.getConnectorKind());
          container.getSetupTasks().add(task);
          tasks.put(repositoryURL, task);
        }

        Query query = SetupFactory.eINSTANCE.createQuery();
        query.setSummary(repositoryQuery.getSummary());
        query.setURL(repositoryQuery.getUrl());
        task.getQueries().add(query);

        for (Map.Entry<String, String> entry : repositoryQuery.getAttributes().entrySet())
        {
          query.getAttributes().put(entry.getKey(), entry.getValue());
        }
      }
    }

    public static MylynHelper create()
    {
      return new MylynHelperImpl();
    }
  }
} // MylynQueriesTaskImpl

Back to the top