Skip to content

Commit

Permalink
STS-2768: tc server instances outside of installation directory
Browse files Browse the repository at this point in the history
Allow creation and usage of tc server instances outside of installation
directory.
  • Loading branch information
zaza committed Nov 27, 2012
1 parent 1a55291 commit e139344
Show file tree
Hide file tree
Showing 11 changed files with 547 additions and 100 deletions.
Expand Up @@ -13,6 +13,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springsource.ide.eclipse.commons.core.process.OutputWriter;
Expand All @@ -21,10 +22,10 @@
import org.springsource.ide.eclipse.commons.core.process.SystemErrOutputWriter;
import org.springsource.ide.eclipse.commons.core.process.SystemOutOutputWriter;


/**
* @author Christian Dupuis
* @author Steffen Pingel
* @author Tomasz Zarna
* @since 2.5.2
*/
public final class ServerInstanceCommand {
Expand Down Expand Up @@ -67,9 +68,7 @@ public String getOutput() {
public int execute(String... arguments) {
List<String> allArguments = new ArrayList<String>(arguments.length + 1);
allArguments.add(this.script.getAbsolutePath());
for (String argument : arguments) {
allArguments.add(argument);
}
allArguments.addAll(Arrays.asList(arguments));

try {
return this.processRunner.run(this.script.getParentFile(),
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.server.tomcat.core.internal.ITomcatServer;
Expand All @@ -41,6 +42,7 @@
* @author Steffen Pingel
* @author Christian Dupuis
* @author Leo Dos Santos
* @author Tomasz Zarna
*/
public class TcServer extends TomcatServer {

Expand Down Expand Up @@ -159,6 +161,10 @@ public IPath getInstanceBase(IRuntime runtime) {
return getTomcatRuntime().getTomcatLocation();
}
else {
String instanceDir = getInstanceDirectory();
if (instanceDir != null) {
path = Path.fromOSString(instanceDir);
}
String serverName = getAttribute(KEY_SERVER_NAME, (String) null);
if (serverName != null) {
path = path.append(serverName);
Expand Down
Expand Up @@ -26,9 +26,9 @@
import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
import org.springsource.ide.eclipse.commons.core.StatusHandler;


/**
* @author Steffen Pingel
* @author Tomasz Zarna
*/
public class TcServerUtil {

Expand Down Expand Up @@ -73,29 +73,42 @@ public static IStatus validateInstance(File instanceDirectory, boolean tcServer2
return Status.OK_STATUS;
}

public static void executeInstanceCreation(IPath installLocation, String instanceName, String[] arguments)
public static void executeInstanceCreation(IPath runtimeLocation, String instanceName, String[] arguments)
throws CoreException {
ServerInstanceCommand command = new ServerInstanceCommand(installLocation.toFile());
ServerInstanceCommand command = new ServerInstanceCommand(runtimeLocation.toFile());

// execute
int returnCode;
try {
returnCode = command.execute(arguments);
}
catch (Exception e) {
throw handleResult(installLocation, command, new Status(IStatus.ERROR, ITcServerConstants.PLUGIN_ID,
throw handleResult(runtimeLocation, command, new Status(IStatus.ERROR, ITcServerConstants.PLUGIN_ID,
"The instance creation command resulted in an exception", e));
}

if (returnCode != 0) {
throw handleResult(installLocation, command, null);
throw handleResult(runtimeLocation, command, null);
}

// verify result
IStatus status = validateInstance(new File(installLocation.toFile(), instanceName), true);
File instanceDirectory = getInstanceDirectory(arguments, instanceName);
if (instanceDirectory == null) {
instanceDirectory = new File(runtimeLocation.toFile(), instanceName);
}
IStatus status = validateInstance(instanceDirectory, true);
if (!status.isOK()) {
throw handleResult(installLocation, command, status);
throw handleResult(runtimeLocation, command, status);
}
}

private static File getInstanceDirectory(String[] arguments, String instanceName) {
for (int i = 0; i < arguments.length; i++) {
if (arguments[i].equals("-i") && arguments[i + 1] != null) {
return new File(arguments[i + 1], instanceName);
}
}
return null;
}

private static CoreException handleResult(IPath installLocation, ServerInstanceCommand command, IStatus result) {
Expand Down
Expand Up @@ -16,6 +16,8 @@
import java.util.Calendar;

import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;

import com.vmware.vfabric.ide.eclipse.tcserver.internal.ui.TcServerInstanceConfiguratorPage;
Expand All @@ -26,11 +28,10 @@
* @author Kaitlin Duck Sherwood
* @author Tomasz Zarna
*/
public class CreateTcServerInstancePage {
private final SWTBotShell shell;
public class CreateTcServerInstancePage extends AbstractTcServerPage {

CreateTcServerInstancePage(SWTBotShell shell) {
this.shell = shell;
super(shell);
shell.bot().waitUntil(Conditions.waitForWidget(withText("Create tc Server Instance")));
}

Expand Down Expand Up @@ -63,12 +64,36 @@ void selectTemplate(String... templateNames) {
}
}

void assertErrorMessage(String errorMessage) {
assertMessage(" " + errorMessage);
private SWTBotCheckBox getUseDefaultLocationCheckbox() {
return shell.bot().checkBox("Use default instance location");
}

void assertMessage(String message) {
shell.bot().text(message);
void selectTemplate(String templateName) {
shell.bot().table().getTableItem(templateName).toggleCheck();
shell.bot().table().getTableItem(templateName).click();
}

void assertUseDefaultServerLocationChecked(boolean isChecked) {
assertEquals(isChecked, getUseDefaultLocationCheckbox().isChecked());
}

private SWTBotCombo getServerLocationCombobox() {
return shell.bot().comboBox(0);
}

void assertServerLocationEnabled(boolean isEnabled) {
assertEquals(isEnabled, shell.bot().label("Location:").isEnabled());
assertEquals(isEnabled, getServerLocationCombobox().isEnabled());
}

void selectUseDefaultServerLocation(boolean select) {
SWTBotCheckBox checkbox = getUseDefaultLocationCheckbox();
if (select) {
checkbox.select();
}
else {
checkbox.deselect();
}
}

void assertNextButtonEnabled(boolean isEnabled) {
Expand All @@ -79,9 +104,13 @@ void setInstanceName(String instanceName) {
shell.bot().textWithLabel("Name:").setText(instanceName);
}

void setServerLocation(String location) {
selectUseDefaultServerLocation(false);
getServerLocationCombobox().setText(location);
}

public TcServerTemplatePropertiesPage nextToTcServerTemplatePropertiesPage() {
shell.bot().button("Next >").click();
return new TcServerTemplatePropertiesPage(shell);
}

}
Expand Up @@ -93,12 +93,16 @@ void pressFinish(boolean errorDialogExpected, String errorMessageRegex) {
assertNotNull(label);
serverErrorDialog.close();
// an error occurred, cancel the wizard
bot.button("Cancel").click();
pressCancel();
}
bot.waitUntil(SWTBotUtils.widgetIsDisposed(shell), 10000);
}
finally {
ErrorDialog.AUTOMATED_MODE = errorDialogAutomatedMode;
}
}

void pressCancel() {
bot.button("Cancel").click();
}
}
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
import org.eclipse.swtbot.swt.finder.matchers.WithStyle;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
Expand All @@ -39,21 +38,15 @@
* @author Kaitlin Duck Sherwood
* @author Tomasz Zarna
*/
public class TcServerConfigurationPage {

private final SWTBotShell shell;
public class TcServerConfigurationPage extends AbstractTcServerPage {

TcServerConfigurationPage(SWTBotShell shell) {
this.shell = shell;
super(shell);
shell.bot().waitUntil(Conditions.waitForWidget(withText("tc Server Configuration")));
}

/**
* Moved from TcServerNewServerWizardUiTest#selectTcServerExistingInstance()
*/
void selectExistingInstance(String existingInstanceName) {
void selectExistingInstance() {
SWTBotCombo instanceCombo = shell.bot().comboBox(0);
// bot.Screenshot("/tmp/select.png");
assertFalse(instanceCombo.isEnabled());

SWTBotRadio newInstanceButton = shell.bot().radio("Create new instance");
Expand All @@ -64,8 +57,20 @@ void selectExistingInstance(String existingInstanceName) {

deselectDefaultSelection();

shell.bot().radio(1).click(); // existingInstanceButton;
existingInstanceButton.click();
assertTrue(instanceCombo.isEnabled());
}

private SWTBotCombo getExistingInstanceCombo() {
return shell.bot().comboBox(0);
}

/**
* Moved from TcServerNewServerWizardUiTest#selectTcServerExistingInstance()
*/
void selectExistingInstance(String existingInstanceName) {
selectExistingInstance();
SWTBotCombo instanceCombo = getExistingInstanceCombo();

shell.bot().text(TcServer21WizardFragment.SPECIFY_TC_SERVER_INSTANCE_MESSAGE);

Expand All @@ -89,7 +94,6 @@ void selectExistingInstance(String existingInstanceName) {
shell.bot().text(TcServer21WizardFragment.SPECIFY_TC_SERVER_INSTANCE_MESSAGE);

instanceCombo.setSelection(existingInstanceName);

}

/**
Expand Down Expand Up @@ -125,43 +129,13 @@ public void run() {
});
}

private SWTBotCheckBox getUseDefaultLocationCheckbox() {
return shell.bot().checkBox("Use default server location");
}

void assertUseDefaultServerLocationChecked(boolean isChecked) {
assertEquals(isChecked, getUseDefaultLocationCheckbox().isChecked());
}

private SWTBotCombo getServerLocationCombobox() {
return shell.bot().comboBox(0);
}

void assertServerLocationEnabled(boolean isEnabled) {
assertEquals(isEnabled, shell.bot().label("Location:").isEnabled());
assertEquals(isEnabled, getServerLocationCombobox().isEnabled());
}

void selectUseDefaultServerLocation(boolean select) {
SWTBotCheckBox checkbox = getUseDefaultLocationCheckbox();
if (select) {
checkbox.select();
}
else {
checkbox.deselect();
}
}

void assertErrorMessage(String errorMessage) {
shell.bot().text(" " + errorMessage);
}

void assertNextButtonEnabled(boolean isEnabled) {
assertEquals(isEnabled, shell.bot().button("Next >").isEnabled());
void assertServerBrowseButtonEnabled(boolean enabled) {
assertEquals(enabled, shell.bot().button("Browse...").isEnabled());
}

void setServerLocation(String location) {
getServerLocationCombobox().setText(location);
public void setInstanceLocation(String location) {
SWTBotCombo instanceCombo = getExistingInstanceCombo();
instanceCombo.setText(location);
}

public CreateTcServerInstancePage nextToCreateTcServerInstancePage() {
Expand Down

0 comments on commit e139344

Please sign in to comment.