mylyn-suite/depends-on-bugzilla/src/org/apidesign/netbinox/test/mylyn/TestBugzilla.java
author Jaroslav Tulach <jtulach@netbeans.org>
Fri Feb 05 18:38:28 2010 +0100
changeset 38 f368d0cf0ca8
parent 16 0867d5dd57ab
child 29 adfe0ad2c687
permissions -rw-r--r--
By default build and test the sample
jtulach@5
     1
/*
jtulach@5
     2
 *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@5
     3
 *
jtulach@5
     4
 *  This program is free software; you can redistribute it and/or
jtulach@5
     5
 *  modify it under the terms of the GNU General Public License
jtulach@5
     6
 *  as published by the Free Software Foundation; version 2
jtulach@5
     7
 *  of the License.
jtulach@5
     8
 *
jtulach@5
     9
 *  This program is distributed in the hope that it will be useful,
jtulach@5
    10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
jtulach@5
    11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jtulach@5
    12
 *  GNU General Public License for more details.
jtulach@5
    13
 *
jtulach@5
    14
 *  You should have received a copy of the GNU General Public License
jtulach@5
    15
 *  along with this program; if not, write to the Free Software
jtulach@5
    16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
jtulach@5
    17
 */
jtulach@5
    18
jtulach@5
    19
package org.apidesign.netbinox.test.mylyn;
jtulach@5
    20
jtulach@5
    21
import java.awt.event.ActionEvent;
jtulach@5
    22
import java.awt.event.ActionListener;
jtulach@5
    23
import java.util.ArrayList;
jtulach@5
    24
import java.util.List;
jtulach@5
    25
import javax.swing.JOptionPane;
jtulach@5
    26
import org.eclipse.core.runtime.NullProgressMonitor;
tstupka@15
    27
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
jtulach@5
    28
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector;
jtulach@5
    29
import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
jtulach@5
    30
import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
jtulach@5
    31
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
jtulach@5
    32
import org.eclipse.mylyn.tasks.core.TaskRepository;
tstupka@15
    33
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
jtulach@5
    34
import org.eclipse.mylyn.tasks.core.data.TaskData;
jtulach@5
    35
import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
jtulach@5
    36
jtulach@5
    37
public final class TestBugzilla implements ActionListener {
jtulach@5
    38
    
jtulach@5
    39
    public void actionPerformed(ActionEvent event) {
jtulach@17
    40
        String repoURL = "http://issues.apache.org/bugzilla";
jtulach@7
    41
        // BEGIN: netbinox.mylyn.bugzilla
jtulach@17
    42
        TaskRepository repository = new TaskRepository("bugzilla", repoURL);
jtulach@5
    43
jtulach@5
    44
        TaskRepositoryManager trm = new TaskRepositoryManager();
jtulach@5
    45
        BugzillaRepositoryConnector brc = new BugzillaRepositoryConnector();
jtulach@5
    46
jtulach@5
    47
        trm.addRepository(repository);
jtulach@5
    48
        trm.addRepositoryConnector(brc);
jtulach@5
    49
jtulach@8
    50
        String url = "/buglist.cgi?" +
tstupka@15
    51
                    "query_format=advanced" +
tstupka@15
    52
                    "&short_desc_type=allwordssubstr" +
tstupka@15
    53
                    "&limit=5";
jtulach@8
    54
        IRepositoryQuery query = new RepositoryQuery(
jtulach@8
    55
            repository.getConnectorKind(), ""
jtulach@8
    56
        );
jtulach@5
    57
        query.setUrl(url);
jtulach@5
    58
        final List<TaskData> collectedData = new ArrayList<TaskData>();
jtulach@5
    59
        TaskDataCollector collector = new TaskDataCollector() {
tstupka@15
    60
            public void accept(TaskData taskData) {
tstupka@15
    61
                collectedData.add(taskData);
tstupka@15
    62
            }
tstupka@15
    63
        };
jtulach@5
    64
        NullProgressMonitor nullProgressMonitor = new NullProgressMonitor();
jtulach@8
    65
        brc.performQuery(
jtulach@8
    66
            repository, query, collector, null, nullProgressMonitor
jtulach@8
    67
        );
jtulach@7
    68
        // END: netbinox.mylyn.bugzilla
jtulach@5
    69
jtulach@5
    70
        StringBuffer sb = new StringBuffer();
jtulach@5
    71
        int i = 0;
tstupka@15
    72
        sb.append("Info: listed 5 issues from ");
tstupka@15
    73
        sb.append(repository.getUrl());
tstupka@15
    74
        sb.append("\n\n");
jtulach@5
    75
        for (TaskData td : collectedData) {
tstupka@15
    76
            sb.append(td.getTaskId());
tstupka@15
    77
            sb.append(" - ");
tstupka@15
    78
            sb.append(getSummary(td));
tstupka@15
    79
            sb.append("\n");
jtulach@5
    80
            if (i++ > 5) {
jtulach@5
    81
                break;
jtulach@5
    82
            }
jtulach@5
    83
        }
jtulach@5
    84
jtulach@5
    85
        JOptionPane.showMessageDialog(null, sb.toString());
jtulach@5
    86
    }
tstupka@15
    87
tstupka@15
    88
    private String getSummary(TaskData td) {
tstupka@15
    89
        TaskAttribute a = td.getRoot().getMappedAttribute(BugzillaAttribute.SHORT_DESC.getKey());
tstupka@15
    90
        String ret = a.getValue();
tstupka@15
    91
        return ret;
tstupka@15
    92
    }
tstupka@15
    93
jtulach@5
    94
}