[hg] main-silver: better way of registering repository connector...

  • From: Ondrej Vrabec < >
  • To:
  • Subject: [hg] main-silver: better way of registering repository connector...
  • Date: Thu, 01 Aug 2013 17:58:56 -0700

changeset 045b19e03b98 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/045b19e03b98
description:
        better way of registering repository connectors in mylyn.
        All connectors (even team server connectors) must be unconditionally 
registered before mylyn tasklist is loaded from disk. Otherwise number of 
queries will grow in tasklist and will never be removed.

diffstat:

 bugzilla/nbproject/project.xml                                               
    |   2 +-
 bugzilla/src/org/netbeans/modules/bugzilla/Bugzilla.java                     
    |   2 +-
 
bugzilla/src/org/netbeans/modules/bugzilla/MylynRepositoryConnectorProvider.java
 |  80 ++++++++++
 mylyn.util/manifest.mf                                                       
    |   2 +-
 mylyn.util/nbproject/project.xml                                             
    |   8 +
 mylyn.util/src/org/netbeans/modules/mylyn/util/MylynSupport.java             
    |  38 ++++
 
mylyn.util/src/org/netbeans/modules/mylyn/util/RepositoryConnectorProvider.java
  |  58 +++++++
 7 files changed, 187 insertions(+), 3 deletions(-)

diffs (317 lines):

diff --git a/bugzilla/nbproject/project.xml b/bugzilla/nbproject/project.xml
--- a/bugzilla/nbproject/project.xml
+++ b/bugzilla/nbproject/project.xml
@@ -83,7 +83,7 @@
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <specification-version>1.10</specification-version>
+                        <specification-version>1.12</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git a/bugzilla/src/org/netbeans/modules/bugzilla/Bugzilla.java 
b/bugzilla/src/org/netbeans/modules/bugzilla/Bugzilla.java
--- a/bugzilla/src/org/netbeans/modules/bugzilla/Bugzilla.java
+++ b/bugzilla/src/org/netbeans/modules/bugzilla/Bugzilla.java
@@ -81,7 +81,7 @@
     private IssueNode.ChangesProvider<BugzillaIssue> bcp;
 
     private Bugzilla() {
-        brc = new BugzillaRepositoryConnector();
+        brc = MylynRepositoryConnectorProvider.getInstance().getConnector();
         clientManager = brc.getClientManager();
         MylynSupport.getInstance().addRepositoryListener(clientManager);
     }
diff --git 
a/bugzilla/src/org/netbeans/modules/bugzilla/MylynRepositoryConnectorProvider.java
 
b/bugzilla/src/org/netbeans/modules/bugzilla/MylynRepositoryConnectorProvider.java
new file mode 100644
--- /dev/null
+++ 
b/bugzilla/src/org/netbeans/modules/bugzilla/MylynRepositoryConnectorProvider.java
@@ -0,0 +1,80 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2013 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.bugzilla;
+
+import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector;
+import org.netbeans.modules.mylyn.util.RepositoryConnectorProvider;
+import org.openide.util.Lookup;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+/**
+ *
+ * @author Ondrej Vrabec
+ */
+@ServiceProviders({
+    @ServiceProvider(service = RepositoryConnectorProvider.class),
+    @ServiceProvider(service = MylynRepositoryConnectorProvider.class)
+})
+public final class MylynRepositoryConnectorProvider implements 
RepositoryConnectorProvider {
+
+    private static MylynRepositoryConnectorProvider INSTANCE;
+    
+    private final BugzillaRepositoryConnector rc;
+
+    public MylynRepositoryConnectorProvider () {
+        rc = new BugzillaRepositoryConnector();
+    }
+
+    static MylynRepositoryConnectorProvider getInstance () {
+        if (INSTANCE == null) {
+            INSTANCE = 
Lookup.getDefault().lookup(MylynRepositoryConnectorProvider.class);
+        }
+        return INSTANCE;
+    }
+    
+    @Override
+    public BugzillaRepositoryConnector getConnector () {
+        return rc;
+    }
+    
+}
diff --git a/mylyn.util/manifest.mf b/mylyn.util/manifest.mf
--- a/mylyn.util/manifest.mf
+++ b/mylyn.util/manifest.mf
@@ -2,6 +2,6 @@
 AutoUpdate-Show-In-Client: false
 OpenIDE-Module: org.netbeans.modules.mylyn.util
 OpenIDE-Module-Localizing-Bundle: 
org/netbeans/modules/mylyn/util/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.11
+OpenIDE-Module-Specification-Version: 1.12
 OpenIDE-Module-Install: 
org/netbeans/modules/mylyn/util/internal/ModuleLifecycleManager.class
 
diff --git a/mylyn.util/nbproject/project.xml 
b/mylyn.util/nbproject/project.xml
--- a/mylyn.util/nbproject/project.xml
+++ b/mylyn.util/nbproject/project.xml
@@ -98,6 +98,14 @@
                         <specification-version>8.0</specification-version>
                     </run-dependency>
                 </dependency>
+                <dependency>
+                    <code-name-base>org.openide.util.lookup</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>8.22</specification-version>
+                    </run-dependency>
+                </dependency>
             </module-dependencies>
             <test-dependencies/>
             <friend-packages>
diff --git a/mylyn.util/src/org/netbeans/modules/mylyn/util/MylynSupport.java 
b/mylyn.util/src/org/netbeans/modules/mylyn/util/MylynSupport.java
--- a/mylyn.util/src/org/netbeans/modules/mylyn/util/MylynSupport.java
+++ b/mylyn.util/src/org/netbeans/modules/mylyn/util/MylynSupport.java
@@ -97,6 +97,9 @@
 import org.netbeans.modules.mylyn.util.internal.CommandsAccessor;
 import org.netbeans.modules.mylyn.util.internal.TaskListener;
 import org.openide.modules.Places;
+import org.openide.util.Lookup;
+import org.openide.util.LookupEvent;
+import org.openide.util.LookupListener;
 import org.openide.util.NbBundle;
 import org.openide.util.NbPreferences;
 import org.openide.util.RequestProcessor;
@@ -135,6 +138,7 @@
     private final Map<ITask, List<TaskListener>> taskListeners;
     private final Map<ITask, Reference<NbTask>> tasks = new 
WeakHashMap<ITask, Reference<NbTask>>();
     private final Map<TaskListener, ITask> taskPerList = new 
HashMap<TaskListener, ITask>();
+    private Lookup.Result<RepositoryConnectorProvider> result;
 
     public static synchronized MylynSupport getInstance () {
         if (instance == null) {
@@ -189,6 +193,8 @@
      */
     public Collection<NbTask> getTasks (TaskRepository taskRepository) 
throws CoreException {
         ensureTaskListLoaded();
+        assert 
taskRepositoryManager.getRepositoryConnector(taskRepository.getConnectorKind())
 != null
+                : "Did you forget to implement RepositoryConnectorProvider?";
         return toNbTasks(taskList.getTasks(taskRepository.getUrl()));
     }
 
@@ -196,6 +202,8 @@
         assert query instanceof RepositoryQuery;
         if (query instanceof RepositoryQuery) {
             ensureTaskListLoaded();
+            assert 
taskRepositoryManager.getRepositoryConnector(query.getConnectorKind()) != null
+                : "Did you forget to implement RepositoryConnectorProvider?";
             return toNbTasks(((RepositoryQuery) query).getChildren());
         } else {
             return Collections.<NbTask>emptyList();
@@ -213,6 +221,8 @@
             cont = unsubmittedTaskContainers.get(taskRepository);
             if (cont == null) {
                 ensureTaskListLoaded();
+                assert 
taskRepositoryManager.getRepositoryConnector(taskRepository.getConnectorKind())
 != null
+                    : "Did you forget to implement 
RepositoryConnectorProvider?";
                 cont = new UnsubmittedTasksContainer(taskRepository, 
taskList);
                 unsubmittedTaskContainers.put(taskRepository, cont);
             }
@@ -268,6 +278,8 @@
 
     public Set<IRepositoryQuery> getRepositoryQueries (TaskRepository 
taskRepository) throws CoreException {
         ensureTaskListLoaded();
+        assert 
taskRepositoryManager.getRepositoryConnector(taskRepository.getConnectorKind())
 != null
+                : "Did you forget to implement RepositoryConnectorProvider?";
         return new 
HashSet<IRepositoryQuery>(taskList.getRepositoryQueries(taskRepository.getUrl()));
     }
 
@@ -276,6 +288,8 @@
             throw new IllegalArgumentException("Query must be instance of 
RepositoryQuery: " + query);
         }
         ensureTaskListLoaded();
+        assert 
taskRepositoryManager.getRepositoryConnector(taskRepository.getConnectorKind())
 != null
+                : "Did you forget to implement RepositoryConnectorProvider?";
         taskList.addQuery((RepositoryQuery) query);
     }
 
@@ -347,6 +361,8 @@
 
     public IRepositoryQuery createNewQuery (TaskRepository taskRepository, 
String queryName) throws CoreException {
         ensureTaskListLoaded();
+        assert 
taskRepositoryManager.getRepositoryConnector(taskRepository.getConnectorKind())
 != null
+                : "Did you forget to implement RepositoryConnectorProvider?";
         IRepositoryQuery query = 
repositoryModel.createRepositoryQuery(taskRepository);
         assert query instanceof RepositoryQuery;
         query.setSummary(queryName);
@@ -389,6 +405,8 @@
         String oldUrl = repository.getRepositoryUrl();
         if (!url.equals(oldUrl)) {
             ensureTaskListLoaded();
+            assert 
taskRepositoryManager.getRepositoryConnector(repository.getConnectorKind()) 
!= null
+                : "Did you forget to implement RepositoryConnectorProvider?";
             for (ITask task : taskList.getAllTasks()) {
                 if 
(url.equals(task.getAttribute(ITasksCoreConstants.ATTRIBUTE_OUTGOING_NEW_REPOSITORY_URL)))
 {
                     taskDataManager.refactorRepositoryUrl(task, 
task.getRepositoryUrl(), url);
@@ -469,6 +487,17 @@
 
     private synchronized void ensureTaskListLoaded () throws CoreException {
         if (!taskListInitialized) {
+            if (result == null) {
+                LookupListener lookupListener = new LookupListener() {
+                    @Override
+                    public void resultChanged (LookupEvent ev) {
+                        registerConnectors();
+                    }
+                };
+                result = 
Lookup.getDefault().lookupResult(RepositoryConnectorProvider.class);
+                result.addLookupListener(lookupListener);
+            }
+            registerConnectors();
             try {
                 if (taskListStorageFile.length() > 0) {
                     taskListWriter.readTaskList(taskList, 
taskListStorageFile);
@@ -716,4 +745,13 @@
             return null;
         }
     }
+
+    private void registerConnectors () {
+        for (RepositoryConnectorProvider provider : result.allInstances()) {
+            AbstractRepositoryConnector connector = provider.getConnector();
+            if (connector != null) {
+                taskRepositoryManager.addRepositoryConnector(connector);
 }
+        }
+    }
+}
diff --git 
a/mylyn.util/src/org/netbeans/modules/mylyn/util/RepositoryConnectorProvider.java
 
b/mylyn.util/src/org/netbeans/modules/mylyn/util/RepositoryConnectorProvider.java
new file mode 100644
--- /dev/null
+++ 
b/mylyn.util/src/org/netbeans/modules/mylyn/util/RepositoryConnectorProvider.java
@@ -0,0 +1,58 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2013 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.mylyn.util;
+
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+
+/**
+ * Mylyn TaskList requires that when it's loading all the connectors ruling 
over
+ * the tasklist's element are already registered inside mylyn. Every NetBeans
+ * connector build upon mylyn must implement this. The implementation is 
queried
+ * right before the tasklist starts loading from disk.
+ *
+ * @author Ondrej Vrabec
+ */
+public interface RepositoryConnectorProvider {
+
+    AbstractRepositoryConnector getConnector ();
+
+}

[hg] main-silver: better way of registering repository connector...

Ondrej Vrabec 08/02/2013

Project Features

About this Project

ConnectedDeveloper was started in November 2009, is owned by tpavek, and has 66 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close