SVN 1.7: auto-update [affected] Subversion roots after commit option - valuable for 1.7, but let it be for any wc version

This commit is contained in:
irengrig
2012-02-16 20:06:29 +04:00
parent 5eca9d7755
commit 0ccc014c5b
5 changed files with 265 additions and 2 deletions
+1
View File
@@ -115,6 +115,7 @@
</actions>
<extensions defaultExtensionNs="com.intellij">
<vcsCheckinHandlerFactory implementation="org.jetbrains.idea.svn17.checkin.SvnCheckinHandlerFactory"/>
<errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
<checkoutProvider implementation="org.jetbrains.idea.svn17.checkout.SvnCheckoutProvider"/>
<applicationService serviceInterface="org.jetbrains.idea.svn17.SvnApplicationSettings17"
@@ -85,6 +85,7 @@ public class SvnConfiguration17 implements PersistentStateComponent<Element> {
private boolean myIsUseDefaultProxy;
private ISVNOptions myOptions;
private boolean myIsKeepLocks;
private boolean myAutoUpdateAfterCommit;
private boolean myRemoteStatus;
private final Project myProject;
private SvnAuthenticationManager myAuthManager;
@@ -402,6 +403,10 @@ public class SvnConfiguration17 implements PersistentStateComponent<Element> {
}
}
}
final Attribute autoUpdateAfterCommit = element.getAttribute("myAutoUpdateAfterCommit");
if (autoUpdateAfterCommit != null) {
myAutoUpdateAfterCommit = Boolean.parseBoolean(autoUpdateAfterCommit.getValue());
}
}
@SuppressWarnings({"HardCodedStringLiteral"})
@@ -435,6 +440,15 @@ public class SvnConfiguration17 implements PersistentStateComponent<Element> {
}
element.setAttribute("maxAnnotateRevisions", "" + myMaxAnnotateRevisions);
element.setAttribute("myUseAcceleration", "" + myUseAcceleration);
element.setAttribute("myAutoUpdateAfterCommit", "" + myAutoUpdateAfterCommit);
}
public boolean isAutoUpdateAfterCommit() {
return myAutoUpdateAfterCommit;
}
public void setAutoUpdateAfterCommit(boolean autoUpdateAfterCommit) {
myAutoUpdateAfterCommit = autoUpdateAfterCommit;
}
public boolean isKeepLocks() {
@@ -379,13 +379,16 @@ public class SvnCheckinEnvironment17 implements CheckinEnvironment {
private final JCheckBox myKeepLocksBox;
private boolean myIsKeepLocks;
private final JPanel myPanel;
private final JCheckBox myAutoUpdate;
public KeepLocksComponent(final Refreshable panel) {
myPanel = new JPanel(new BorderLayout());
myKeepLocksBox = new JCheckBox(SvnBundle.message("checkbox.chckin.keep.files.locked"));
myKeepLocksBox.setSelected(myIsKeepLocks);
myAutoUpdate = new JCheckBox("Auto-update after commit");
myPanel.add(myAutoUpdate, BorderLayout.NORTH);
myPanel.add(myKeepLocksBox, BorderLayout.CENTER);
}
@@ -397,15 +400,23 @@ public class SvnCheckinEnvironment17 implements CheckinEnvironment {
return myKeepLocksBox != null && myKeepLocksBox.isSelected();
}
public boolean isAutoUpdate() {
return myAutoUpdate != null && myAutoUpdate.isSelected();
}
public void refresh() {
}
public void saveState() {
mySvnVcs.getSvnConfiguration().setKeepLocks(isKeepLocks());
final SvnConfiguration17 configuration = mySvnVcs.getSvnConfiguration();
configuration.setKeepLocks(isKeepLocks());
configuration.setAutoUpdateAfterCommit(isAutoUpdate());
}
public void restoreState() {
myIsKeepLocks = mySvnVcs.getSvnConfiguration().isKeepLocks();
final SvnConfiguration17 configuration = mySvnVcs.getSvnConfiguration();
myIsKeepLocks = configuration.isKeepLocks();
myAutoUpdate.setSelected(configuration.isAutoUpdateAfterCommit());
}
}
@@ -0,0 +1,100 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.idea.svn17.checkin;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.checkin.CheckinHandler;
import com.intellij.openapi.vcs.checkin.VcsCheckinHandlerFactory;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
import com.intellij.openapi.vcs.update.ActionInfo;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.WindowManager;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.svn17.SvnConfiguration17;
import org.jetbrains.idea.svn17.SvnVcs17;
import org.jetbrains.idea.svn17.update.AutoSvnUpdater;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 2/16/12
* Time: 6:51 PM
*/
public class SvnCheckinHandlerFactory extends VcsCheckinHandlerFactory {
public SvnCheckinHandlerFactory() {
super(SvnVcs17.getKey());
}
@NotNull
@Override
protected CheckinHandler createVcsHandler(final CheckinProjectPanel panel) {
final Project project = panel.getProject();
final Collection<VirtualFile> commitRoots = panel.getRoots();
return new CheckinHandler() {
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
return null;
}
@Override
public void checkinSuccessful() {
if (SvnConfiguration17.getInstance(project).isAutoUpdateAfterCommit()) {
final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(SvnVcs17.getInstance(project));
final List<FilePath> paths = new ArrayList<FilePath>();
for (int i = 0; i < roots.length; i++) {
VirtualFile root = roots[i];
boolean take = false;
for (VirtualFile commitRoot : commitRoots) {
if (VfsUtil.isAncestor(root, commitRoot, false)) {
take = true;
break;
}
}
if (! take) continue;
paths.add(new FilePathImpl(root));
}
if (paths.isEmpty()) return;
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
final JComponent frame = WindowManager.getInstance().getIdeFrame(project).getComponent();
final AutoSvnUpdater updater = new AutoSvnUpdater(project, paths.toArray(new FilePath[paths.size()]));
updater.getTemplatePresentation().setText(ActionInfo.UPDATE.getActionName());
updater.actionPerformed(
new AnActionEvent(null, DataManager.getInstance().getDataContext(frame), ActionPlaces.UNKNOWN,
updater.getTemplatePresentation(), ActionManager.getInstance(), 0));
}
}, ModalityState.NON_MODAL);
}
}
};
}
}
@@ -0,0 +1,137 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.idea.svn17.update;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.actions.VcsContext;
import com.intellij.openapi.vcs.update.*;
import org.jetbrains.idea.svn17.SvnConfiguration17;
import org.jetbrains.idea.svn17.SvnVcs17;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.wc.SVNRevision;
import java.util.Arrays;
import java.util.LinkedHashMap;
/**
* Created with IntelliJ IDEA.
* User: Irina.Chernushina
* Date: 2/16/12
* Time: 5:05 PM
*/
public class AutoSvnUpdater extends AbstractCommonUpdateAction {
private final Project myProject;
private final FilePath[] myRoots;
public AutoSvnUpdater(final Project project, final FilePath[] roots) {
super(BlindUpdateAction.ourInstance, new AutoUpdateScope(roots), false);
myProject = project;
myRoots = roots;
}
@Override
protected void actionPerformed(VcsContext context) {
final SvnConfiguration17 configuration17 = SvnConfiguration17.getInstance(myProject);
configuration17.FORCE_UPDATE = false;
configuration17.UPDATE_LOCK_ON_DEMAND = false;
configuration17.UPDATE_DEPTH = SVNDepth.INFINITY;
final SvnVcs17 vcs = SvnVcs17.getInstance(myProject);
for (FilePath root : myRoots) {
final UpdateRootInfo info = configuration17.getUpdateRootInfo(root.getIOFile(), vcs);
info.setRevision(SVNRevision.HEAD);
info.setUpdateToRevision(false);
}
super.actionPerformed(context);
}
@Override
protected boolean filterRootsBeforeAction() {
return false;
}
private static class BlindUpdateAction implements ActionInfo {
private final static BlindUpdateAction ourInstance = new BlindUpdateAction();
@Override
public boolean showOptions(Project project) {
return false;
}
@Override
public UpdateEnvironment getEnvironment(AbstractVcs vcs) {
return vcs.getUpdateEnvironment();
}
@Override
public UpdateOrStatusOptionsDialog createOptionsDialog(Project project,
LinkedHashMap<Configurable, AbstractVcs> envToConfMap,
String scopeName) {
// should not be called
return null;
}
@Override
public String getActionName(String scopeName) {
return ActionInfo.UPDATE.getActionName(scopeName);
}
@Override
public String getActionName() {
return ActionInfo.UPDATE.getActionName();
}
@Override
public String getGroupName(FileGroup fileGroup) {
return ActionInfo.UPDATE.getGroupName(fileGroup);
}
@Override
public boolean canGroupByChangelist() {
return ActionInfo.UPDATE.canGroupByChangelist();
}
@Override
public boolean canChangeFileStatus() {
return ActionInfo.UPDATE.canChangeFileStatus();
}
}
private static class AutoUpdateScope implements ScopeInfo {
private final FilePath[] myRoots;
private AutoUpdateScope(final FilePath[] roots) {
myRoots = roots;
}
@Override
public FilePath[] getRoots(VcsContext context, ActionInfo actionInfo) {
return myRoots;
}
@Override
public String getScopeName(VcsContext dataContext, ActionInfo actionInfo) {
return "Subversion";
}
@Override
public boolean filterExistsInVcs() {
return false;
}
}
}