From 0df581724c505c7b74f82cf001c4382a524b867e Mon Sep 17 00:00:00 2001 From: Waqar Ali Khan Date: Fri, 29 Jan 2016 17:39:10 +0500 Subject: [PATCH] Fixed issue when using rbtools "rbt command not found error" by letting user select path of rbtools command on settings page --- review-board-idea-plugin.iml | 4 +- .../idea/plugin/diff/RbToolsDiffProvider.java | 9 ++- .../plugin/diff/VcsDiffProviderFactory.java | 2 +- .../idea/plugin/messages/PluginBundle.java | 2 + .../plugin/messages/reviewboard.properties | 2 + .../idea/plugin/state/Configuration.java | 13 +++- .../idea/plugin/state/SettingsPage.java | 74 ++++++++++++++++++- .../idea/plugin/ui/panels/LoginPanel.form | 63 +++++++++++++--- .../idea/plugin/ui/panels/LoginPanel.java | 32 ++++++++ 9 files changed, 179 insertions(+), 22 deletions(-) diff --git a/review-board-idea-plugin.iml b/review-board-idea-plugin.iml index 07b2621..d86dd82 100644 --- a/review-board-idea-plugin.iml +++ b/review-board-idea-plugin.iml @@ -1,13 +1,13 @@ - + - + diff --git a/src/com/ritesh/idea/plugin/diff/RbToolsDiffProvider.java b/src/com/ritesh/idea/plugin/diff/RbToolsDiffProvider.java index 7902fd5..ab81214 100644 --- a/src/com/ritesh/idea/plugin/diff/RbToolsDiffProvider.java +++ b/src/com/ritesh/idea/plugin/diff/RbToolsDiffProvider.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; /** * Created by ritesh on 18/12/15. @@ -42,12 +43,14 @@ public class RbToolsDiffProvider implements IVcsDiffProvider { private static final Logger LOG = Logger.getInstance(RbToolsDiffProvider.class); + private String rbtPath; private String userName; private String password; private String url; private AbstractVcs vcs; - public RbToolsDiffProvider(String url, String userName, String password, AbstractVcs vcs) { + public RbToolsDiffProvider(String rbtPath, String url, String userName, String password, AbstractVcs vcs) { + this.rbtPath = rbtPath; this.userName = userName; this.password = password; this.url = url; @@ -91,7 +94,7 @@ public String generateDiff(Project project, AnActionEvent action) throws VcsExce private String generateDiff(VcsRevision revision, String rootPath, List additionalOptions) throws IOException { List commands = new ArrayList<>(); - commands.addAll(Arrays.asList("rbt", "diff", "--server", url, "--username", userName, "--password", password)); + commands.addAll(Arrays.asList(rbtPath, "diff", "--server", url, "--username", userName, "--password", password)); commands.addAll(additionalOptions); if (revision != null) { @@ -105,6 +108,8 @@ private String generateDiff(VcsRevision revision, String rootPath, List ProcessBuilder builder = new ProcessBuilder(commands); builder.directory(new File(rootPath)); builder.redirectErrorStream(true); + Map processEnv = builder.environment(); + processEnv.putAll(System.getenv()); Process process = builder.start(); String stdInput = CharStreams.toString(new InputStreamReader(process.getInputStream())); diff --git a/src/com/ritesh/idea/plugin/diff/VcsDiffProviderFactory.java b/src/com/ritesh/idea/plugin/diff/VcsDiffProviderFactory.java index d496c91..07c6e59 100644 --- a/src/com/ritesh/idea/plugin/diff/VcsDiffProviderFactory.java +++ b/src/com/ritesh/idea/plugin/diff/VcsDiffProviderFactory.java @@ -30,7 +30,7 @@ public class VcsDiffProviderFactory { public static IVcsDiffProvider getVcsDiffProvider(Project project, Configuration configuration) { AbstractVcs vcsFor = ProjectLevelVcsManager.getInstance(project).getVcsFor(project.getProjectFile()); if (configuration.useRbTools == Boolean.TRUE) { - return new RbToolsDiffProvider(configuration.url, configuration.username, configuration.password, vcsFor); + return new RbToolsDiffProvider(configuration.rbToolsPath, configuration.url, configuration.username, configuration.password, vcsFor); } if (vcsFor instanceof SvnVcs) { return new SvnDiffProvider(); diff --git a/src/com/ritesh/idea/plugin/messages/PluginBundle.java b/src/com/ritesh/idea/plugin/messages/PluginBundle.java index 3d9fd13..543d5a8 100644 --- a/src/com/ritesh/idea/plugin/messages/PluginBundle.java +++ b/src/com/ritesh/idea/plugin/messages/PluginBundle.java @@ -35,6 +35,8 @@ public class PluginBundle { public static final String NOTIFICATION_TITLE = "reviewboard.notification.title"; public static final String UNSUPPORTED_VCS_TITLE = "reviewboard.unsupported.vcs.title"; public static final String UNSUPPORTED_VCS_MESSAGE = "reviewboard.unsupported.vcs.message"; + public static final String RBTOOLS_PATH_TITLE = "reviewboard.message.rbtools.error.title"; + public static final String RBTOOLS_PATH_ERROR_MESSAGE = "reviewboard.message.rbtools.error"; public static String message(@NotNull String key, @NotNull Object... params) { return getBundle().getString(key); diff --git a/src/com/ritesh/idea/plugin/messages/reviewboard.properties b/src/com/ritesh/idea/plugin/messages/reviewboard.properties index f039c60..3f9b8c4 100644 --- a/src/com/ritesh/idea/plugin/messages/reviewboard.properties +++ b/src/com/ritesh/idea/plugin/messages/reviewboard.properties @@ -17,9 +17,11 @@ reviewboard.message.login.success=Connection established successfully. reviewboard.message.connection.status.title=Login Status reviewboard.message.connection.title=Testing Connection +reviewboard.message.rbtools.error.title=RBTools Path reviewboard.notification.title=ReviewBoard reviewboard.message.connection.error=Unable to connect to server +reviewboard.message.rbtools.error=Please specify correct path to RBTools reviewboard.unsupported.vcs.title=Unsupported VCS reviewboard.unsupported.vcs.message=Plugin doesnot supports current VCS diff --git a/src/com/ritesh/idea/plugin/state/Configuration.java b/src/com/ritesh/idea/plugin/state/Configuration.java index 57a6d45..b55d681 100644 --- a/src/com/ritesh/idea/plugin/state/Configuration.java +++ b/src/com/ritesh/idea/plugin/state/Configuration.java @@ -24,6 +24,7 @@ public class Configuration { public String username; public String password; public Boolean useRbTools; + public String rbToolsPath; public Configuration(String url, String username, String password, Boolean useRbTools) { this.url = url; @@ -32,13 +33,18 @@ public Configuration(String url, String username, String password, Boolean useRb this.useRbTools = useRbTools; } + public Configuration(String url, String username, String password, Boolean useRbTools, String rbToolsFilePath) { + this(url, username, password, useRbTools); + this.rbToolsPath = rbToolsFilePath; + } + public Configuration() { } @Override protected Object clone() throws CloneNotSupportedException { super.clone(); - return new Configuration(url, username, password, useRbTools); + return new Configuration(url, username, password, useRbTools, rbToolsPath); } @Override @@ -47,6 +53,7 @@ public String toString() { "username='" + username + '\'' + ", url='" + url + '\'' + ", useRbTools='" + useRbTools + '\'' + + ", rbToolsPath='" + rbToolsPath + '\'' + '}'; } @@ -60,7 +67,8 @@ public boolean equals(Object o) { return !(url != null ? !url.equals(that.url) : that.url != null) && !(username != null ? !username.equals(that.username) : that.username != null) && !(password != null ? !password.equals(that.password) : that.password != null) - && !(useRbTools != null ? !useRbTools.equals(that.useRbTools) : that.useRbTools != null); + && !(useRbTools != null ? !useRbTools.equals(that.useRbTools) : that.useRbTools != null) + && !(rbToolsPath != null ? !rbToolsPath.equals(that.rbToolsPath) : that.rbToolsPath != null); } @@ -70,6 +78,7 @@ public int hashCode() { result = 31 * result + (username != null ? username.hashCode() : 0); result = 31 * result + (password != null ? password.hashCode() : 0); result = 31 * result + (useRbTools != null ? useRbTools.hashCode() : 0); + result = 31 * result + (rbToolsPath != null ? rbToolsPath.hashCode() : 0); return result; } } diff --git a/src/com/ritesh/idea/plugin/state/SettingsPage.java b/src/com/ritesh/idea/plugin/state/SettingsPage.java index 40735d0..76a7ff2 100644 --- a/src/com/ritesh/idea/plugin/state/SettingsPage.java +++ b/src/com/ritesh/idea/plugin/state/SettingsPage.java @@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Comparing; +import com.intellij.ui.components.JBCheckBox; import com.ritesh.idea.plugin.exception.InvalidConfigurationException; import com.ritesh.idea.plugin.messages.PluginBundle; import com.ritesh.idea.plugin.reviewboard.ReviewDataProvider; @@ -35,8 +36,15 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileNameExtensionFilter; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; /** * @author Ritesh @@ -74,6 +82,8 @@ public JComponent createComponent() { loginPanel.setUsername(oldConfigurationState.username); loginPanel.setPassword(oldConfigurationState.password); loginPanel.setUseRbTools(oldConfigurationState.useRbTools); + loginPanel.setRBToolsFilePath(oldConfigurationState.rbToolsPath); + loginPanel.toggleRBToolsPathVisibility(oldConfigurationState.useRbTools); } loginPanel.addActionListener(new ActionListener() { @Override @@ -81,24 +91,44 @@ public void actionPerformed(ActionEvent e) { testConnection(); } }); + loginPanel.addRBToolsFilePathListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + showRBToolsFileChooser(); + } + }); + loginPanel.addUseRBToolsListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + loginPanel.toggleRBToolsPathVisibility(loginPanel.useRbTools()); + } + }); return loginPanel.getPanel(); } @Override public boolean isModified() { if (oldConfigurationState == null) { - return !loginPanel.getUrl().isEmpty() || !loginPanel.getUsername().isEmpty() || !loginPanel.getPassword().isEmpty(); + return !loginPanel.getUrl().isEmpty() || !loginPanel.getUsername().isEmpty() || !loginPanel.getPassword().isEmpty() + || !loginPanel.getRBToolsFilePath().isEmpty(); } return !Comparing.equal(loginPanel.getUrl(), oldConfigurationState.url) || !Comparing.equal(loginPanel.getUsername(), oldConfigurationState.username) || !Comparing.equal(loginPanel.useRbTools(), oldConfigurationState.useRbTools) || - !Comparing.equal(loginPanel.getPassword(), oldConfigurationState.password); + !Comparing.equal(loginPanel.getPassword(), oldConfigurationState.password) || + !Comparing.equal(loginPanel.getRBToolsFilePath(), oldConfigurationState.rbToolsPath); } @Override public void apply() throws ConfigurationException { + if(loginPanel.useRbTools() && loginPanel.getRBToolsFilePath().trim().length() <= 0) { + Messages.showErrorDialog(PluginBundle.message(PluginBundle.RBTOOLS_PATH_ERROR_MESSAGE), + PluginBundle.message(PluginBundle.RBTOOLS_PATH_TITLE)); + return; + } + Configuration configuration = new Configuration( - loginPanel.getUrl(), loginPanel.getUsername(), loginPanel.getPassword(), loginPanel.useRbTools()); + loginPanel.getUrl(), loginPanel.getUsername(), loginPanel.getPassword(), loginPanel.useRbTools(), loginPanel.getRBToolsFilePath()); ConfigurationPersistance.getInstance(project).loadState(configuration); ReviewDataProvider.reset(); } @@ -112,6 +142,44 @@ public void reset() { public void disposeUIResources() { } + + private void showRBToolsFileChooser() { + JFileChooser chooser = new JFileChooser(); + FileFilter filter = new FileFilter() { + + @Override + public boolean accept(File f) { + // This will display only the files without "." or with ".cmd" + return !f.getName().contains(".") || f.getName().endsWith(".cmd"); + } + + @Override + public String getDescription() { + return "RBTools command file"; + } + }; + chooser.setDialogTitle("Select path to RBTools"); + chooser.setMultiSelectionEnabled(false); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setFileFilter(filter); + chooser.setAcceptAllFileFilterUsed(false); + chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); + if(loginPanel.getRBToolsFilePath() != null && loginPanel.getRBToolsFilePath().length() > 0) { + chooser.setSelectedFile(new File(loginPanel.getRBToolsFilePath())); + } + chooser.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY + .equals(evt.getPropertyName())) { + JFileChooser chooser = (JFileChooser)evt.getSource(); + File curFile = chooser.getSelectedFile(); + loginPanel.setRBToolsFilePath(curFile.getAbsolutePath()); + } + } + }) ; + + chooser.showDialog(loginPanel.getPanel(), "Select"); + } private void testConnection() { final MutableObject connException = new MutableObject(); diff --git a/src/com/ritesh/idea/plugin/ui/panels/LoginPanel.form b/src/com/ritesh/idea/plugin/ui/panels/LoginPanel.form index 18edfa7..afe9dd9 100644 --- a/src/com/ritesh/idea/plugin/ui/panels/LoginPanel.form +++ b/src/com/ritesh/idea/plugin/ui/panels/LoginPanel.form @@ -1,9 +1,9 @@
- + - + @@ -53,28 +53,67 @@ - + + + + + + - + - - + - + - + - - + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/ritesh/idea/plugin/ui/panels/LoginPanel.java b/src/com/ritesh/idea/plugin/ui/panels/LoginPanel.java index f6c5cd1..576d7fd 100644 --- a/src/com/ritesh/idea/plugin/ui/panels/LoginPanel.java +++ b/src/com/ritesh/idea/plugin/ui/panels/LoginPanel.java @@ -19,7 +19,10 @@ import com.intellij.ui.components.JBCheckBox; import javax.swing.*; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; /** * @author Ritesh @@ -31,9 +34,21 @@ public class LoginPanel { private JTextField username; private JButton testConnection; private JBCheckBox useRbTools; + private JTextField txtRBToolsPath; + private JButton btnRBToolsFileSelection; + private JLabel lblRBToolsPath; + private JPanel panelRBToolsPath; public LoginPanel() { } + + public void addUseRBToolsListener(ItemListener l) { + useRbTools.addItemListener(l); + } + + public void addRBToolsFilePathListener(ActionListener l) { + btnRBToolsFileSelection.addActionListener(l); + } public void addActionListener(ActionListener l) { testConnection.addActionListener(l); @@ -74,4 +89,21 @@ public Boolean useRbTools() { public void setUseRbTools(Boolean useRbTools) { this.useRbTools.setSelected(useRbTools == Boolean.TRUE); } + + public String getRBToolsFilePath() { + return txtRBToolsPath.getText().trim(); + } + + public void setRBToolsFilePath(String filePath) { + this.txtRBToolsPath.setText(filePath); + } + + public void toggleRBToolsPathVisibility(boolean show) { + lblRBToolsPath.setVisible(show); + panelRBToolsPath.setVisible(show); + + if(!show) { + setRBToolsFilePath(""); + } + } }