Skip to content

Commit

Permalink
Fixed issue when using rbtools "rbt command not found error" by letti…
Browse files Browse the repository at this point in the history
…ng user select path of rbtools command on settings page
  • Loading branch information
waqarkhan88 committed Jan 29, 2016
1 parent 35969af commit 0df5817
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 22 deletions.
4 changes: 2 additions & 2 deletions review-board-idea-plugin.iml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PLUGIN_MODULE" version="4">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/META-INF/plugin.xml" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="jdk" jdkName="IntelliJ IDEA IU-141.1532.4" jdkType="IDEA JDK" />
<orderEntry type="jdk" jdkName="IntelliJ IDEA IU-143.381.42" jdkType="IDEA JDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="PROVIDED">
<library>
Expand Down
9 changes: 7 additions & 2 deletions src/com/ritesh/idea/plugin/diff/RbToolsDiffProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
* Created by ritesh on 18/12/15.
*/
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;
Expand Down Expand Up @@ -91,7 +94,7 @@ public String generateDiff(Project project, AnActionEvent action) throws VcsExce

private String generateDiff(VcsRevision revision, String rootPath, List<String> additionalOptions) throws IOException {
List<String> 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) {
Expand All @@ -105,6 +108,8 @@ private String generateDiff(VcsRevision revision, String rootPath, List<String>
ProcessBuilder builder = new ProcessBuilder(commands);
builder.directory(new File(rootPath));
builder.redirectErrorStream(true);
Map<String, String> processEnv = builder.environment();
processEnv.putAll(System.getenv());
Process process = builder.start();

String stdInput = CharStreams.toString(new InputStreamReader(process.getInputStream()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/com/ritesh/idea/plugin/messages/PluginBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/com/ritesh/idea/plugin/messages/reviewboard.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions src/com/ritesh/idea/plugin/state/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -47,6 +53,7 @@ public String toString() {
"username='" + username + '\'' +
", url='" + url + '\'' +
", useRbTools='" + useRbTools + '\'' +
", rbToolsPath='" + rbToolsPath + '\'' +
'}';
}

Expand All @@ -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);

}

Expand All @@ -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;
}
}
74 changes: 71 additions & 3 deletions src/com/ritesh/idea/plugin/state/SettingsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -74,31 +82,53 @@ 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
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();
}
Expand All @@ -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();
Expand Down
63 changes: 51 additions & 12 deletions src/com/ritesh/idea/plugin/ui/panels/LoginPanel.form
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.ritesh.idea.plugin.ui.panels.LoginPanel">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="19" width="573" height="172"/>
<xy x="20" y="19" width="573" height="214"/>
</constraints>
<properties/>
<border type="none"/>
Expand Down Expand Up @@ -53,28 +53,67 @@
</constraints>
<properties/>
</component>
<component id="cdad6" class="javax.swing.JButton" binding="testConnection">
<vspacer id="88601">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="ad41e" class="com.intellij.ui.components.JBCheckBox" binding="useRbTools">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalAlignment value="0"/>
<text value="Test Connection"/>
<text value="Use RBTools"/>
</properties>
</component>
<vspacer id="88601">
<component id="f1e0a" class="javax.swing.JLabel" binding="lblRBToolsPath">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="ad41e" class="com.intellij.ui.components.JBCheckBox" binding="useRbTools">
<properties>
<text value="RBTools Path :"/>
</properties>
</component>
<component id="cdad6" class="javax.swing.JButton" binding="testConnection">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Use RBTools (Ensure it is installed)"/>
<horizontalAlignment value="0"/>
<text value="Test Connection"/>
</properties>
</component>
<grid id="f6e9" binding="panelRBToolsPath" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<focusable value="false"/>
</properties>
<border type="none"/>
<children>
<component id="8cfbc" class="javax.swing.JTextField" binding="txtRBToolsPath">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
<enabled value="true"/>
</properties>
</component>
<component id="c8b2e" class="javax.swing.JButton" binding="btnRBToolsFileSelection">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="..."/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
Loading

0 comments on commit 0df5817

Please sign in to comment.