Skip to content

Commit

Permalink
Version 0.0.4
Browse files Browse the repository at this point in the history
More tests, code tidy up, and reviewed the docs / comments.
  • Loading branch information
guy-keller committed Aug 2, 2014
1 parent 738c395 commit 8eba05c
Show file tree
Hide file tree
Showing 16 changed files with 589 additions and 199 deletions.
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

426 changes: 259 additions & 167 deletions .idea/workspace.xml

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
<idea-plugin version="2">
<id>JettyRunner-By-GuiKeller</id>
<id>JettyRunner-GK</id>
<name>IDEA Jetty Runner</name>
<version>0.0.3</version>
<version>0.0.4</version>
<vendor email="[email protected]" url="https://github.com/guikeller/jetty-runner">IntelliJ Jetty Runner</vendor>

<description><![CDATA[
A plugin that allows you to quickly run Jetty from IntelliJ IDEA. <br>
If you require full Jetty support please consider buying the IntelliJ IDEA Enterprise Edition. <br>
This plugin should be Win / Mac / Linux compatible - min req: JVM 5.0 <br>
If you require full support please consider buying the IntelliJ IDEA Enterprise Edition. <br>
This plugin should be Win / Mac / Linux compatible - min req: JVM6 <br>
tags: jetty, container, webapp, runner, tomcat
]]></description>

<change-notes><![CDATA[
<b>0.0.4</b> - Fourth release; <br>
What's new: <br>
<b>1)</b> More unit tests - important bits tested (some felt in the too hard basket). <br>
<b>2)</b> Compiled to be compatible with JVM6. <br>
<b>3)</b> Tidied up the code and docs a bit more. <br>
<br>
<b>0.0.3</b> - Third release; <br>
<br>
What's new: <br>
<b>1)</b> Run and Debug Configurations working out-of-the-box! <br>
<b>1)</b> Run and Debug Configurations now work! <br>
<b>2)</b> Internal code refactoring and documentation. <br>
<b>3)</b> UI Layout created using IntelliJ. <br>
<b>4)</b> Some Unit Tests - a starting point. <br>
Expand All @@ -30,16 +36,16 @@ What's new:<br>
<br>
I'm going to start writing those unit tests, soon..<br>
<br><br>
<b>0.0.1</b> - First release; Runs Jetty 8.1.<br>
<b>0.0.1</b> - First release; Uses jetty-runner-8.1.9 <br>
<b>*Note</b>: Debugging is available through 'Remote', on port 5007.<br>
<br>
<br>
<b>TODO:</b> <br>
<b>1)</b> Debugger port selector; for now its fixed on 5007. [DONE]<br>
<b>2)</b> Figure out why the debugger doesn't work out of the box; JetBrains? [DONE]<br>
<b>3)</b> Better UI Layout- BoxLayout is not the greatest; GridBag? [DONE]<br>
<b>4)</b> Unit Tests - sorry guys I got a bit lazy here.[SOME]<br>
<b>5)</b> Bug fixes / Improvements / Requests [?]<br>
<b>4)</b> Unit Tests - Important bits.[DONE]<br>
<b>5)</b> Bug fixes / Improvements [?]<br>
<br>
Thanks for dropping by.
]]>
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ Jetty-Runner
============

A plugin that allows you to quickly run Jetty from IntelliJ IDEA. <br>
If you require full Jetty support please consider buying the IntelliJ IDEA Enterprise Edition. <br>
This plugin should be Win / Mac / Linux compatible - min req: JVM 5.0 <br>
If you require full support please consider buying the IntelliJ IDEA Enterprise Edition. <br>
This plugin should be Win / Mac / Linux compatible - min req: JVM6 <br>
<br>
<b>0.0.4</b> - Fourth release; <br>
What's new: <br>
<b>1)</b> More unit tests - important bits tested (some felt in the too hard basket). <br>
<b>2)</b> Compiled to be compatible with JVM6. <br>
<b>3)</b> Tidied up the code and docs a bit more. <br>
<br>
<b>0.0.3</b> - Third release; <br>
<br>
Expand All @@ -23,15 +29,15 @@ What's new:<br>
<br>
I'm going to start writing those unit tests, soon..<br>
<br><br>
<b>0.0.1</b> - First release; Runs Jetty 8.1.<br>
<b>0.0.1</b> - First release; Uses jetty-runner-8.1.9 <br>
<b>*Note</b>: Debugging is available through 'Remote', on port 5007.<br>
<br>
<br>
<b>TODO:</b> <br>
<b>1)</b> Debugger port selector; for now its fixed on 5007. [DONE]<br>
<b>2)</b> Figure out why the debugger doesn't work out of the box; JetBrains? [DONE]<br>
<b>3)</b> Better UI Layout- BoxLayout is not the greatest; GridBag? [DONE]<br>
<b>4)</b> Unit Tests - sorry guys I got a bit lazy here.[SOME]<br>
<b>5)</b> Bug fixes / Improvements (?)<br>
<b>4)</b> Unit Tests - Important bits.[DONE]<br>
<b>5)</b> Bug fixes / Improvements [?]<br>
<br>
Thanks for dropping by.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class JettyRunnerConfiguration extends LocatableConfigurationBase {

public static final String PREFIX = "JettyRunnerV03-";
public static final String PREFIX = "JettyRunnerV04-";

private static final String WEBAPP_PATHS = PREFIX+"webappPaths";
private static final String WEBAPP_FOLDERS = PREFIX+"webappFolders";
Expand Down Expand Up @@ -58,12 +58,12 @@ public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEn
return new JettyRunnerCommandLine(executionEnvironment, this);
}

// Persistence of values
// Persistence of values in disk

@Override
public void readExternal(Element element) throws InvalidDataException {
super.readExternal(element);
// Reads the values from disk
// Reads the values from the disk
Project project = super.getProject();
PropertiesComponent storedValues = PropertiesComponent.getInstance(project);
this.webappPaths = storedValues.getValue(WEBAPP_PATHS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ public boolean canRun(@NotNull String value, @NotNull RunProfile runProfile) {
@Override
protected RunContentDescriptor createContentDescriptor(Project project, RunProfileState state, RunContentDescriptor contentToReuse, ExecutionEnvironment env)
throws ExecutionException {
// Now we figure out if it the run or debug button has been hit
// Now we figure out if it the Debug button has been hit
Executor executor = env.getExecutor();
String id = executor.getId();
// If it was the debug, then we do some extra magic
if(executor instanceof DefaultDebugExecutor) {
// Get hold of the JavaParameters
JavaCommandLine javaCommandLine = (JavaCommandLine) state;
JavaParameters javaParameters = javaCommandLine.getJavaParameters();
// Making the assumption that JVM is 5.0 onwards
// Making the assumption that JVM is 6.0 onwards
javaParameters.getVMParametersList().addParametersString(XDEBUG);
// Debugger port
String debuggerPort = DebuggerUtils.getInstance().findAvailableDebugAddress(true);
Expand All @@ -63,7 +62,7 @@ protected RunContentDescriptor createContentDescriptor(Project project, RunProfi
// Attaches the remote configuration to the VM and then starts it up
return attachVirtualMachine(project, state, contentToReuse, env, connection, true);
}else{
// If it was run, then don't do anything special
// If it was somethings else, then we don't do anything special
return super.createContentDescriptor(project,state,contentToReuse,env);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.jetbrains.annotations.NotNull;

/**
* Jetty Program Runner - Boilerplate
* Jetty Program Runner
* @see com.intellij.execution.runners.DefaultProgramRunner
* @author Gui Keller
*/
Expand All @@ -32,6 +32,7 @@ public boolean canRun(@NotNull String value, @NotNull RunProfile runProfile) {
if(!(runProfile instanceof JettyRunnerConfiguration)){
return false;
}
// Values passed are: Run or Debug
if(!RUN.equals(value)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public JavaParameters createJavaParameters() throws ExecutionException {
* Jetty expects: /Path1 /path/to/WebApps
* @return String value
*/
private String getWebAppPath() {
protected String getWebAppPath() {
String paths = model.getWebappPaths();
String folders = model.getWebappFolders();
// Multiple values allowed - CSV
Expand All @@ -104,18 +104,18 @@ private String getWebAppPath() {
for(int i=0; i<pathsArray.length; i++){
String path = pathsArray[i];
String folderPath = PathUtil.toPresentableUrl(foldersArray[i]);
value.append(path).append(" ").append(folderPath);
value.append(path).append(" ").append(folderPath).append(" ");
}
return value.toString();
}
throw new IllegalArgumentException("Numer of Path(s) and Folder(s) must math: "+paths+" / "+folders);
throw new IllegalArgumentException("Number of Path(s) and Folder(s) must math: "+paths+" / "+folders);
}

/**
* Retrieves the "classes" parameter
* @return String
*/
private String getClassesDirectory() {
protected String getClassesDirectory() {
String classesDirectories = model.getClassesDirectories();
// Multiple values allowed - CSV
String[] classesFolders = null;
Expand All @@ -138,7 +138,7 @@ private String getClassesDirectory() {
* Using the specified jetty XML files
* @return String
*/
private String getJettyXmlPaths() {
protected String getJettyXmlPaths() {
String xmls = model.getJettyXml();
// Multiple values allowed - CSV
String[] xmlArray = null;
Expand All @@ -160,7 +160,7 @@ private String getJettyXmlPaths() {
* Retrieves the "port" parameter
* @return String
*/
private String getPort() {
protected String getPort() {
String runningOnPort = model.getRunningOnPort();
//Single value - not optional
if(runningOnPort != null && !runningOnPort.isEmpty()){
Expand All @@ -169,4 +169,8 @@ private String getPort() {
throw new IllegalArgumentException("Invalid port: "+runningOnPort);
}

public void setModel(JettyRunnerConfiguration model) {
this.model = model;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@ public class JettyRunnerConfPanel {
private JButton browseButton;

public JettyRunnerConfPanel() {
// Action executed when clicked on browse
browseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Shows a file chooser
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(Boolean.TRUE);
// Checking whether the user clicked okay
int result = fileChooser.showOpenDialog(new JFrame());
if (result == JFileChooser.APPROVE_OPTION) {
String paths = new String();
StringBuffer paths = new StringBuffer();
File[] selectedFiles = fileChooser.getSelectedFiles();
if (selectedFiles != null && selectedFiles.length > 0) {
for (File selectedFile : selectedFiles) {
paths += selectedFile.getAbsolutePath() + ",";
// Selected files in CSV format
paths.append(selectedFile.getAbsolutePath() + ",");
}
paths = paths.substring(0, (paths.length() - 1));
// Removing the comma at the end
String value = paths.substring(0, (paths.length() - 1));
xmlField.setText(value);
}
xmlField.setText(paths);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected void applyEditorTo(JettyRunnerConfiguration jettyRunnerConfiguration)
jettyRunnerConfiguration.setRunningOnPort(this.configurationPanel.getRunOnPortField().getText());
jettyRunnerConfiguration.setJettyXml(this.configurationPanel.getXmlField().getText());
try {
// Not entirely sure if 'I have' to do this - the framework could do
// Not entirely sure if 'I have' to do this - the IntelliJ framework may do
jettyRunnerConfiguration.writeExternal(new Element(JettyRunnerConfiguration.PREFIX + UUID.randomUUID().toString()));
} catch (WriteExternalException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -150,4 +150,8 @@ private String getWebAppsFolder(Project project) {
VirtualFile virtualFile = webappFolder.getVirtualFile();
return virtualFile.getPresentableUrl();
}

public void setConfigurationPanel(JettyRunnerConfPanel configurationPanel) {
this.configurationPanel = configurationPanel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.github.guikeller.jettyrunner.model;

import com.github.guikeller.jettyrunner.runner.JettyRunnerCommandLine;
import com.github.guikeller.jettyrunner.ui.JettyRunnerEditor;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.options.SettingsEditor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;

import static org.junit.Assert.assertNotNull;

@RunWith(PowerMockRunner.class)
@PrepareForTest({JettyRunnerConfiguration.class})
public class JettyRunnerConfigurationTest {

@Test
public void testGetConfigurationEditor() throws Exception {
JettyRunnerEditor runEditor = Mockito.mock(JettyRunnerEditor.class);
PowerMockito.whenNew(JettyRunnerEditor.class).withAnyArguments().thenReturn(runEditor);

JettyRunnerConfiguration runnerConf = Whitebox.newInstance(JettyRunnerConfiguration.class);
SettingsEditor<JettyRunnerConfiguration> editor = runnerConf.getConfigurationEditor();
assertNotNull(editor);

PowerMockito.verifyNew(JettyRunnerEditor.class).withArguments(runnerConf);
}

@Test
public void testGetState() throws Exception {
JettyRunnerCommandLine commandLine = Mockito.mock(JettyRunnerCommandLine.class);
PowerMockito.whenNew(JettyRunnerCommandLine.class).withAnyArguments().thenReturn(commandLine);

Executor executor = Mockito.mock(Executor.class);
ExecutionEnvironment environment = Mockito.mock(ExecutionEnvironment.class);

JettyRunnerConfiguration runnerConf = Whitebox.newInstance(JettyRunnerConfiguration.class);
RunProfileState state = runnerConf.getState(executor, environment);
assertNotNull(state);

PowerMockito.verifyNew(JettyRunnerCommandLine.class).withArguments(environment, runnerConf);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.guikeller.jettyrunner.runner;

import com.github.guikeller.jettyrunner.model.JettyRunnerConfiguration;
import com.intellij.execution.configurations.RunProfile;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;

import static org.junit.Assert.*;

@RunWith(PowerMockRunner.class)
public class JettyProgramDebuggerTest {

@Test
public void testGetRunnerId() throws Exception {
JettyProgramDebugger debugger = Whitebox.newInstance(JettyProgramDebugger.class);
String runnerId = debugger.getRunnerId();
assertEquals("JettyRunner-By-GuiKeller", runnerId);
}

@Test
public void testCanRun() throws Exception {
RunProfile profile = Mockito.mock(JettyRunnerConfiguration.class);

JettyProgramDebugger debugger = Whitebox.newInstance(JettyProgramDebugger.class);
boolean canRun = debugger.canRun("Debug", profile);
assertTrue(canRun);

RunProfile wrongProfile = Mockito.mock(RunProfile.class);
boolean cannotRun = debugger.canRun("Debug", wrongProfile);
assertFalse(cannotRun);
}
}
Loading

0 comments on commit 8eba05c

Please sign in to comment.