Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwolf committed Oct 28, 2014
0 parents commit 5f8bdc4
Show file tree
Hide file tree
Showing 7 changed files with 603 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
*.iml
out/
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<idea-plugin version="2">
<id>com.wayneandlayne.runaftertests</id>
<name>Run After Tests</name>
<version>0.1</version>
<vendor email="[email protected]" url="http://www.wayneandlayne.com">Wayne and Layne, LLC</vendor>

<description><![CDATA[
Run After Tests is a simple plugin that allows you to run a command after the test suite completes. A different
command can be run after all the tests succeeded than when some of the tests fail.
]]></description>

<change-notes><![CDATA[
v0.1 - Initial release.
]]>
</change-notes>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
<idea-version since-build="131"/>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
on how to target different products -->
<!-- enable plugin in all products -->
<depends>com.intellij.modules.lang</depends>

<extensions defaultExtensionNs="com.intellij">
<testStatusListener implementation="com.wayneandlayne.runaftertests.MyTestStatusListener" />
<applicationConfigurable implementation="com.wayneandlayne.runaftertests.Configuration"></applicationConfigurable>
</extensions>

<application-components>
<!-- Add your application components here -->
</application-components>

<project-components>
<!-- Add your project components here -->
</project-components>

<actions>
<!-- Add your actions here -->
</actions>

</idea-plugin>
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Run After Tests
===============

Adam Wolf
Wayne and Layne, LLC
http://www.wayneandlayne.com
v0.1: October 27th 2014

Run After Tests is a small IntelliJ plugin that works with PyCharm and other JetBrains IDEs that runs a command after
a test suite completes. It runs one command if all the tests passed, and another if any of the tests fail.

The commands are configured in Preferences->Run After Tests.

Installation
============
I need to make sure this works for more than just me before submitting to the JetBrains plugin repository, so for now,
download the RunAfterTests.jar, and install it through your IDE in Preferences->Plugins.

Let me know if it works (or doesn't!) for you.

Developing
==========
I do not know Java beyond writing Android apps, and I do not know hardly anything about IntelliJ, but I was able to
write the first version of this plugin in about one hour.

I was unable to follow the official documentation with regards to getting my development environment set up, simply
because I knew so little about modern Java development or IntelliJ. However, I was able to follow these instructions:
http://bjorn.tipling.com/how-to-make-an-intellij-idea-plugin-in-30-minutes.

After that, I read a few of the pages here: http://confluence.jetbrains.com/display/IDEADEV/PluginDevelopment, and
did code searches for various APIs that appeared to be useful.

Roadmap
=======
I will probably add a feature to send the total number of tests, passed and failed, and perhaps the name of the failed
tests to the command.

Let me know if there's something you need, and I'll see about adding it.

Licensing
=========
This program is licensed as GPL2. Please contact me if you are interested in alternate licensing options.
59 changes: 59 additions & 0 deletions src/com/wayneandlayne/runaftertests/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.wayneandlayne.runaftertests;


import com.intellij.ide.ui.LafManager;
import com.intellij.ide.ui.UISettings;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.options.Configurable;

import javax.swing.*;


public class Configuration implements Configurable {
private JComponent myComponent;
private JPanel myPanel;
private JTextField passTextField;
private JTextField failTextField;

public String getDisplayName() {
return "Run After Tests";
}

public boolean isModified() {
return true;
}

public JComponent createComponent() {
myComponent = (JComponent) myPanel;
return myComponent;
}

public void apply() {
//Notifications.Bus.notify(new Notification("wnl", "Run After Tests", "Applying!", NotificationType.INFORMATION));

PropertiesComponent properties = PropertiesComponent.getInstance();
String passCommand = passTextField.getText();
String failCommand = failTextField.getText();
properties.setValue("com.wayneandlayne.runaftertests.passcommand", passCommand);
properties.setValue("com.wayneandlayne.runaftertests.failcommand", failCommand);
}

public void disposeUIResources() {
myComponent = null;
}

public String getHelpTopic() {
return "";
}

public void reset() {
PropertiesComponent properties = PropertiesComponent.getInstance();
properties.setValue("com.wayneandlayne.runaftertests.passcommand", "");
properties.setValue("com.wayneandlayne.runaftertests.failcommand", "");
passTextField.setText("");
failTextField.setText("");
}
}
66 changes: 66 additions & 0 deletions src/com/wayneandlayne/runaftertests/MyTestStatusListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.wayneandlayne.runaftertests;

import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.execution.testframework.TestStatusListener;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;

import java.io.IOException;

public class MyTestStatusListener extends TestStatusListener{
private PropertiesComponent properties;

public MyTestStatusListener() {
properties = PropertiesComponent.getInstance();

}

private void runCommand(String command) {
if ("".equals(command)) {
Notifications.Bus.notify(new Notification("wnl", "Run After Tests", "Would have ran a command, if it were configured.", NotificationType.INFORMATION));
} else
Notifications.Bus.notify(new Notification("wnl", "Run After Tests", "Running command: " + command, NotificationType.INFORMATION));
try {
Process proc = Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}

}

private void runPassCommand() {
String passCommand = properties.getValue("com.wayneandlayne.runaftertests.passcommand");
runCommand(passCommand);
}

private void runFailCommand() {
String failCommand = properties.getValue("com.wayneandlayne.runaftertests.failcommand");
runCommand(failCommand);
}

@Override
public void testSuiteFinished(AbstractTestProxy root) {
long testsRun = 0;
long testsSucceeded = 0;

for (AbstractTestProxy test : root.getAllTests()) {
if(test.isLeaf()) {
testsRun++;

if(test.isPassed()) {
testsSucceeded++;
}
}
}

if (testsRun == testsSucceeded)
{
runPassCommand();
} else
{
runFailCommand();
}
}
}
52 changes: 52 additions & 0 deletions src/com/wayneandlayne/runaftertests/MyUIForm.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.wayneandlayne.runaftertests.Configuration">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" 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="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="e99c">
<constraints>
<grid row="2" 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="20f5e" class="javax.swing.JLabel">
<constraints>
<grid row="0" 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>
<properties>
<text value="Command to run when all tests pass:"/>
</properties>
</component>
<component id="defdb" class="javax.swing.JLabel">
<constraints>
<grid row="1" 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>
<properties>
<text value="Command to run when some tests fail:"/>
</properties>
</component>
<component id="7d6e7" class="javax.swing.JTextField" binding="passTextField">
<constraints>
<grid row="0" column="1" 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>
<text value=""/>
</properties>
</component>
<component id="4894c" class="javax.swing.JTextField" binding="failTextField">
<constraints>
<grid row="1" column="1" 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/>
</component>
</children>
</grid>
</form>

0 comments on commit 5f8bdc4

Please sign in to comment.