IDEA-112179 "Set property" action implemented

This commit is contained in:
Konstantin Kolosovsky
2013-09-09 20:54:50 +04:00
parent 5154748c0f
commit a5ca071f89
6 changed files with 100 additions and 35 deletions
@@ -28,9 +28,9 @@ import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.idea.svn.SvnBundle;
import org.jetbrains.idea.svn.SvnVcs;
import org.jetbrains.idea.svn.dialogs.SetPropertyDialog;
import org.tmatesoft.svn.core.SVNException;
import org.jetbrains.idea.svn.properties.PropertyClient;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNPropertyValue;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import java.io.File;
@@ -73,15 +73,13 @@ public class SetPropertyAction extends BasicAction {
String value = dialog.getPropertyValue();
boolean recursive = dialog.isRecursive();
SVNWCClient wcClient = activeVcs.createWCClient();
for (int i = 0; i < ioFiles.length; i++) {
File ioFile = ioFiles[i];
try {
wcClient.doSetProperty(ioFile, name, SVNPropertyValue.create(value), false, recursive, null);
}
catch (SVNException e) {
throw new VcsException(e);
}
PropertyClient client = activeVcs.getFactory(ioFile).createPropertyClient();
// TODO: most likely SVNDepth.getInfinityOrEmptyDepth should be used instead of SVNDepth.fromRecursive - to have either "infinity"
// TODO: or "empty" depth, and not "infinity" or "files" depth. But previous logic used SVNDepth.fromRecursive implicitly
client.setProperty(ioFile, name, SVNPropertyValue.create(value), SVNDepth.fromRecurse(recursive), false);
}
for(int i = 0; i < file.length; i++) {
if (recursive && file[i].isDirectory()) {
@@ -41,6 +41,8 @@ public enum SvnCommandName {
resolve("resolve", true),
propget("propget", false),
proplist("proplist", false),
propset("propset", true),
propdel("propdel", true),
blame("blame", false),
merge("merge", true),
changelist("changelist", true),
@@ -15,22 +15,26 @@
*/
package org.jetbrains.idea.svn.dialogs;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.ui.DocumentAdapter;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.svn.SvnBundle;
import org.jetbrains.idea.svn.SvnPropertyKeys;
import org.jetbrains.idea.svn.SvnVcs;
import org.tmatesoft.svn.core.SVNException;
import org.jetbrains.idea.svn.properties.PropertyClient;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNPropertyValue;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.ISVNPropertyHandler;
import org.tmatesoft.svn.core.wc.SVNPropertyData;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc2.SvnTarget;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@@ -47,6 +51,9 @@ import java.util.TreeSet;
* @author alex
*/
public class SetPropertyDialog extends DialogWrapper {
private static final Logger LOG = Logger.getInstance("org.jetbrains.idea.svn.dialogs.SetPropertyDialog");
private final String myPropertyName;
private final File[] myFiles;
@@ -147,14 +154,8 @@ public class SetPropertyDialog extends DialogWrapper {
return;
}
File file = myFiles[0];
SVNPropertyData property;
try {
SVNWCClient client = myVCS.createWCClient();
property = client.doGetProperty(file, name, SVNRevision.WORKING, SVNRevision.WORKING);
}
catch (SVNException e) {
property = null;
}
SVNPropertyData property = !StringUtil.isEmpty(name) ? getProperty(file, name) : null;
if (property != null) {
myValueText.setText(SVNPropertyValue.getPropertyAsString(property.getValue()));
myValueText.selectAll();
@@ -164,6 +165,21 @@ public class SetPropertyDialog extends DialogWrapper {
}
}
private SVNPropertyData getProperty(@NotNull File file, @NotNull String name) {
SVNPropertyData property;
try {
PropertyClient client = myVCS.getFactory(file).createPropertyClient();
property = client.getProperty(SvnTarget.fromFile(file, SVNRevision.WORKING), name, false, SVNRevision.WORKING);
}
catch (VcsException e) {
LOG.info(e);
property = null;
}
return property;
}
protected JComponent createCenterPanel() {
fillPropertyNames(myFiles);
if (myPropertyName != null) {
@@ -189,23 +205,26 @@ public class SetPropertyDialog extends DialogWrapper {
if (files.length == 1) {
File file = files[0];
try {
SVNWCClient client = myVCS.createWCClient();
client.doGetProperty(file, null, SVNRevision.WORKING, SVNRevision.WORKING, false,
new ISVNPropertyHandler() {
public void handleProperty(File path, SVNPropertyData property) {
String name = property.getName();
if (name != null) {
names.add(name);
}
}
public void handleProperty(SVNURL url, SVNPropertyData property) {
}
public void handleProperty(long revision, SVNPropertyData property) {
}
});
ISVNPropertyHandler handler = new ISVNPropertyHandler() {
public void handleProperty(File path, SVNPropertyData property) {
String name = property.getName();
if (name != null) {
names.add(name);
}
}
public void handleProperty(SVNURL url, SVNPropertyData property) {
}
public void handleProperty(long revision, SVNPropertyData property) {
}
};
PropertyClient client = myVCS.getFactory(file).createPropertyClient();
client.list(SvnTarget.fromFile(file, SVNRevision.WORKING), SVNRevision.WORKING, SVNDepth.EMPTY, handler);
}
catch (SVNException e) {
//
catch (VcsException e) {
LOG.info(e);
}
}
@@ -88,6 +88,27 @@ public class CmdPropertyClient extends BaseSvnClient implements PropertyClient {
parseOutput(target, command.getOutput(), handler);
}
@Override
public void setProperty(@NotNull File file,
@NotNull String property,
@Nullable SVNPropertyValue value,
@Nullable SVNDepth depth,
boolean force) throws VcsException {
List<String> parameters = new ArrayList<String>();
boolean isDelete = value == null;
parameters.add(property);
if (!isDelete) {
parameters.add(SVNPropertyValue.getPropertyAsString(value));
// --force could only be used in "propset" command, but not in "propdel" command
CommandUtil.put(parameters, force, "--force");
}
CommandUtil.put(parameters, file);
CommandUtil.put(parameters, depth);
CommandUtil.execute(myVcs, isDelete ? SvnCommandName.propdel : SvnCommandName.propset, parameters, null);
}
private void fillListParameters(@NotNull SvnTarget target,
@Nullable SVNRevision revision,
@Nullable SVNDepth depth,
@@ -5,11 +5,14 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.api.SvnClient;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNPropertyValue;
import org.tmatesoft.svn.core.wc.ISVNPropertyHandler;
import org.tmatesoft.svn.core.wc.SVNPropertyData;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc2.SvnTarget;
import java.io.File;
/**
* @author Konstantin Kolosovsky.
*/
@@ -30,4 +33,10 @@ public interface PropertyClient extends SvnClient {
@Nullable SVNRevision revision,
@Nullable SVNDepth depth,
@Nullable ISVNPropertyHandler handler) throws VcsException;
void setProperty(@NotNull File file,
@NotNull String property,
@Nullable SVNPropertyValue value,
@Nullable SVNDepth depth,
boolean force) throws VcsException;
}
@@ -4,8 +4,10 @@ import com.intellij.openapi.vcs.VcsException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.api.BaseSvnClient;
import org.jetbrains.idea.svn.commandLine.SvnBindException;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNPropertyValue;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.ISVNPropertyHandler;
import org.tmatesoft.svn.core.wc.SVNPropertyData;
@@ -59,6 +61,20 @@ public class SvnKitPropertyClient extends BaseSvnClient implements PropertyClien
runGetProperty(target, null, revision, depth, handler);
}
@Override
public void setProperty(@NotNull File file,
@NotNull String property,
@Nullable SVNPropertyValue value,
@Nullable SVNDepth depth,
boolean force) throws VcsException {
try {
myVcs.createWCClient().doSetProperty(file, property, value, force, depth, null, null);
}
catch (SVNException e) {
throw new SvnBindException(e);
}
}
private void runGetProperty(@NotNull SvnTarget target,
@Nullable String property,
@Nullable SVNRevision revision,