NPE in BranchesLoader http://ea.jetbrains.com/browser/ea_problems/18350
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / branchConfig / BranchesLoader.java
blobe09c352edf172b520889c617a19df64ff211cb18
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.svn.branchConfig;
18 import com.intellij.lifecycle.PeriodicalTasksCloser;
19 import com.intellij.openapi.diagnostic.Logger;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.openapi.vcs.ProjectLevelVcsManager;
22 import org.jetbrains.idea.svn.SvnVcs;
23 import org.jetbrains.idea.svn.integrate.SvnBranchItem;
24 import org.tmatesoft.svn.core.ISVNDirEntryHandler;
25 import org.tmatesoft.svn.core.SVNDirEntry;
26 import org.tmatesoft.svn.core.SVNException;
27 import org.tmatesoft.svn.core.SVNURL;
28 import org.tmatesoft.svn.core.wc.SVNLogClient;
29 import org.tmatesoft.svn.core.wc.SVNRevision;
31 import java.util.Collections;
32 import java.util.LinkedList;
33 import java.util.List;
35 public class BranchesLoader {
36 private static Logger LOG = Logger.getInstance("#org.jetbrains.idea.svn.branchConfig.BranchesLoader");
38 private BranchesLoader() {
41 public static List<SvnBranchItem> loadBranches(final Project project, final String url) throws SVNException {
42 final List<SvnBranchItem> result = new LinkedList<SvnBranchItem>();
43 final ProjectLevelVcsManager vcsManager = PeriodicalTasksCloser.safeGetComponent(project, ProjectLevelVcsManager.class);
44 final SvnVcs svnVcs = (SvnVcs) vcsManager.findVcsByName(SvnVcs.VCS_NAME);
45 final SVNLogClient logClient = svnVcs.createLogClient();
46 final SVNURL branchesUrl = SVNURL.parseURIEncoded(url);
47 logClient.doList(branchesUrl, SVNRevision.UNDEFINED, SVNRevision.HEAD, false, false, new ISVNDirEntryHandler() {
48 public void handleDirEntry(final SVNDirEntry dirEntry) throws SVNException {
49 final SVNURL currentUrl = dirEntry.getURL();
50 if (! branchesUrl.equals(currentUrl)) {
51 final String url = currentUrl.toString();
52 // if have permissions
53 if (dirEntry.getDate() != null) {
54 result.add(new SvnBranchItem(url, dirEntry.getDate(), dirEntry.getRevision()));
58 });
59 Collections.sort(result);
60 return result;