1 19 20 package org.netbeans.modules.subversion.ui.update; 21 22 import java.util.Iterator ; 23 import org.netbeans.modules.subversion.ui.actions.ContextAction; 24 import org.netbeans.modules.subversion.util.Context; 25 import org.netbeans.modules.subversion.*; 26 import java.io.File ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 import org.netbeans.modules.subversion.client.SvnClient; 30 import org.netbeans.modules.subversion.client.SvnProgressSupport; 31 import org.netbeans.modules.subversion.util.SvnUtils; 32 import org.netbeans.modules.versioning.util.Utils; 33 import org.openide.ErrorManager; 34 import org.openide.nodes.Node; 35 import org.openide.awt.StatusDisplayer; 36 import org.openide.util.RequestProcessor; 37 import org.tigris.subversion.svnclientadapter.ISVNStatus; 38 import org.tigris.subversion.svnclientadapter.SVNClientException; 39 import org.tigris.subversion.svnclientadapter.SVNRevision; 40 import org.tigris.subversion.svnclientadapter.SVNUrl; 41 import org.tigris.subversion.svnclientadapter.utils.SVNStatusUtils; 42 43 48 public class UpdateAction extends ContextAction { 49 50 protected String getBaseName(Node[] nodes) { 51 return "CTL_MenuItem_Update"; } 53 54 protected int getFileEnabledStatus() { 55 return FileInformation.STATUS_IN_REPOSITORY; 56 } 57 58 protected int getDirectoryEnabledStatus() { 59 return FileInformation.STATUS_MANAGED 60 & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED 61 & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY; 62 } 63 64 protected void performContextAction(Node[] nodes) { 65 performUpdate(nodes); 66 } 67 68 public void performUpdate(final Node[] nodes) { 69 final Context ctx = getContext(nodes); 78 ContextAction.ProgressSupport support = new ContextAction.ProgressSupport(this, nodes) { 79 public void perform() { 80 update(ctx, this); 81 } 82 }; 83 support.start(createRequestProcessor(nodes)); 84 } 85 86 private static void update(Context ctx, SvnProgressSupport progress) { 87 88 File [] roots = ctx.getRootFiles(); 89 final SVNUrl repositoryUrl = SvnUtils.getRepositoryRootUrl(roots[0]); 90 91 FileStatusCache cache = Subversion.getInstance().getStatusCache(); 92 cache.refreshCached(ctx); 93 File [][] split = Utils.splitFlatOthers(roots); 94 final List <File > recursiveFiles = new ArrayList <File >(); 95 final List <File > flatFiles = new ArrayList <File >(); 96 97 for (int i = 0; i<split[1].length; i++) { 99 recursiveFiles.add(split[1][i]); 100 } 101 for (int i= 0; i<split[0].length; i++) { 104 flatFiles.add(split[0][i]); 105 } 106 107 108 SvnClient client; 109 try { 110 client = Subversion.getInstance().getClient(repositoryUrl); 111 } catch (SVNClientException ex) { 112 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); return; 114 } 115 116 try { 117 updateRoots(recursiveFiles, progress, client, true); 118 if(progress.isCanceled()) { 119 return; 120 } 121 updateRoots(flatFiles, progress, client, false); 122 } catch (SVNClientException e1) { 123 progress.annotate(e1); 124 } 125 } 126 127 private static void updateRoots(List <File > roots, SvnProgressSupport support, SvnClient client, boolean recursive) throws SVNClientException { 128 boolean conflict = false; 129 roots_loop: 130 for (Iterator <File > it = roots.iterator(); it.hasNext();) { 131 File root = it.next(); 132 if(support.isCanceled()) { 133 break; 134 } 135 client.update(root, SVNRevision.HEAD, recursive); 136 ISVNStatus status[] = client.getStatus(root, true, false); 137 for (int k = 0; k<status.length; k++) { 138 ISVNStatus s = status[k]; 139 if (SVNStatusUtils.isTextConflicted(s) || SVNStatusUtils.isPropConflicted(s)) { 140 conflict = true; 141 break roots_loop; 142 } 143 } 144 } 145 if (conflict) { 146 StatusDisplayer.getDefault().setStatusText(org.openide.util.NbBundle.getMessage(UpdateAction.class, "MSG_Update_Conflicts")); } else { 148 StatusDisplayer.getDefault().setStatusText(org.openide.util.NbBundle.getMessage(UpdateAction.class, "MSG_Update_Completed")); } 150 return; 151 } 152 153 public static void performUpdate(final Context context) { 154 if (context == null || context.getRoots().size() == 0) { 155 return; 156 } 157 SVNUrl repository = getSvnUrl(context); 158 RequestProcessor rp = Subversion.getInstance().getRequestProcessor(repository); 159 SvnProgressSupport support = new SvnProgressSupport() { 160 public void perform() { 161 update(context, this); 162 } 163 }; 164 support.start(rp, repository, org.openide.util.NbBundle.getMessage(UpdateAction.class, "MSG_Update_Progress")); } 166 167 } 168 | Popular Tags |