Skip to content

Commit

Permalink
Merge pull request #68 from jGauravGupta/FISH-7326
Browse files Browse the repository at this point in the history
FISH-7326 Eclipse support Payara Server running on WSL
  • Loading branch information
jGauravGupta authored Jun 27, 2023
2 parents 7b000d6 + 3ab32a9 commit be9522a
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void createControl(Composite parent) {
createUI(composite);
validate();
createAdvancedSettings(composite, new GridData(SWT.FILL, SWT.TOP, false, false, 3, 1));
resolverConfigurationComponent.setModifyListener(e -> validate());
// resolverConfigurationComponent.setModifyListener(e -> validate());
setControl(composite);
}

Expand Down
21 changes: 17 additions & 4 deletions bundles/fish.payara.eclipse.tools.server/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@
class="fish.payara.eclipse.tools.server.handlers.PayaraStateTester"
id="fish.payara.eclipse.tools.server.PayaraStateTester"
namespace="fish.payara.eclipse.tools.server"
properties="isRunning,isRemote"
properties="isRunning,isRemote,isWSLInstance"
type="org.eclipse.wst.server.core.IServer">
</propertyTester>
<propertyTester
Expand Down Expand Up @@ -739,6 +739,16 @@
</and>
</adapt>
</definition>
<definition id="fish.payara.eclipse.tools.server.isWSLInstance">
<and>
<count value="1"/>
<iterate ifEmpty="false">
<and>
<test property="fish.payara.eclipse.tools.server.isWSLInstance"/>
</and>
</iterate>
</and>
</definition>

<definition id="fish.payara.eclipse.tools.server.moreGlassfishSelected">
<iterate ifEmpty="false">
Expand Down Expand Up @@ -969,9 +979,12 @@
>
<enabledWhen>
<and>
<not>
<reference definitionId="fish.payara.eclipse.tools.server.isRemoteGlassfish"/>
</not>
<or>
<reference definitionId="fish.payara.eclipse.tools.server.isWSLInstance"/>
<not>
<reference definitionId="fish.payara.eclipse.tools.server.isRemoteGlassfish"/>
</not>
</or>
<reference definitionId="fish.payara.eclipse.tools.server.oneGlassfishSelected"/>
</and>
</enabledWhen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public final class PayaraServer extends ServerDelegate implements IURLProvider {
public static final String DEFAULT_HOT_DEPLOY = "false";
public static final String DEFAULT_TYPE = "";
public static final String DOCKER_TYPE = "Docker";
public static final String WSL_TYPE = "WSL";
protected static final String PROP_INSTANCE_TYPE = "instance.type";
protected static final String PROP_HOST_PATH = "host.path";
protected static final String PROP_CONTAINER_PATH = "container.path";
Expand Down Expand Up @@ -238,16 +239,14 @@ private static String lastSegment(String path) {

public boolean isRemote() {
return getServer().getServerType().supportsRemoteHosts()
&& (DOCKER_TYPE.equals(getInstanceType()) || !isLocalhost(getServer().getHost()));
&& (DOCKER_TYPE.equals(getInstanceType()) || WSL_TYPE.equals(getInstanceType()) || !isLocalhost(getServer().getHost()));
}

public String getDebugOptions(int debugPort) {
public String getDebugOptions(int debugPort) {
Version version = getVersion();

if (version.matches("[4")) {
return "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=" + debugPort;
}

return "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=" + debugPort;
}

Expand Down Expand Up @@ -536,7 +535,7 @@ public void setAdminUser(String value) {
}

public String getDomainsFolder() {
if (!isRemote()) {
if (!isRemote() || isWSLInstance()) {
return new File(getDomainPath()).getParent();
}

Expand All @@ -559,6 +558,10 @@ public boolean isDockerInstance() {
return DOCKER_TYPE.equals(getAttribute(PROP_INSTANCE_TYPE, (String) null));
}

public boolean isWSLInstance() {
return WSL_TYPE.equals(getAttribute(PROP_INSTANCE_TYPE, (String) null));
}

public String getInstanceType() {
return this.getAttribute(PROP_INSTANCE_TYPE, (String) null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,10 @@ private void publishModuleForPayara(int kind, int deltaKind, IModule[] module, I

boolean isRemote = getPayaraServerDelegate().isRemote();
boolean isDockerInstance = getPayaraServerDelegate().isDockerInstance();
boolean isWSLInstance = getPayaraServerDelegate().isWSLInstance();
boolean isJarDeploy = getPayaraServerDelegate().getJarDeploy();

if ((!isRemote && !isJarDeploy) || isDockerInstance) {
if ((!isRemote && !isJarDeploy) || isDockerInstance || isWSLInstance) {
publishDeployedDirectory(kind, deltaKind, publishProperties, module, monitor);
} else {
publishJarFile(kind, deltaKind, publishProperties, module, monitor);
Expand Down Expand Up @@ -612,6 +613,7 @@ private void publishDeployedDirectory(int kind, int deltaKind, Properties publis
// the deployed apps
// so that the move operation Eclipse is doing sometimes can work.
boolean dockerInstance = getPayaraServerDelegate().isDockerInstance();
boolean wslInstance = getPayaraServerDelegate().isWSLInstance();
String hostPath = getPayaraServerDelegate().getHostPath();
String containerPath = getPayaraServerDelegate().getContainerPath();

Expand Down Expand Up @@ -680,7 +682,7 @@ private void publishDeployedDirectory(int kind, int deltaKind, Properties publis
CommandTarget command = null;
if (deltaKind == ADDED) {
command = new CommandDeploy(name, null, new File("" + path), contextRoot, properties, new File[0],
dockerInstance, hostPath, containerPath, hotDeploy);
dockerInstance, wslInstance, hostPath, containerPath, hotDeploy);
} else {
command = new CommandRedeploy(name, null, contextRoot, properties, new File[0], keepSession,
hotDeploy, metadataChanged, sourcesChanged);
Expand Down Expand Up @@ -724,6 +726,7 @@ private void publishJarFile(int kind, int deltaKind, Properties p, IModule[] mod
String contextRoot = null;

boolean dockerInstance = getPayaraServerDelegate().isDockerInstance();
boolean wslInstance = getPayaraServerDelegate().isWSLInstance();
String hostPath = getPayaraServerDelegate().getHostPath();
String containerPath = getPayaraServerDelegate().getContainerPath();

Expand All @@ -738,7 +741,7 @@ private void publishJarFile(int kind, int deltaKind, Properties p, IModule[] mod
try {
ServerAdmin.executeOn(getPayaraServerDelegate())
.command(new CommandDeploy(name, null, archivePath, contextRoot, getDeploymentProperties(),
new File[0], dockerInstance, hostPath, containerPath, hotDeploy))
new File[0], dockerInstance, wslInstance, hostPath, containerPath, hotDeploy))
.timeout(520).onNotCompleted(result -> {
logMessage("deploy is failing=" + result.getValue());
throw new IllegalStateException("deploy is failing=" + result.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public boolean test(Object receiver, String property, Object[] args, Object expe
}
}

if (property.equals("isWSLInstance")) {
PayaraServer payaraServer = load(server, PayaraServer.class);

if (payaraServer != null) {
return payaraServer.isWSLInstance();
}
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static ResultString deploy(PayaraServer server, File application, TaskSta
throws PayaraIdeException {
try {
return ServerAdmin.<ResultString>exec(server, new CommandDeploy(null, null, application, null, null, null,
server.isDockerInstance(), server.getHostPath(), server.getContainerPath(), false), listener).get();
server.isDockerInstance(), server.isWSLInstance(), server.getHostPath(), server.getContainerPath(), false), listener).get();
} catch (InterruptedException | ExecutionException | CancellationException ie) {
throw new PayaraIdeException(ERROR_MESSAGE, ie);
}
Expand Down Expand Up @@ -100,6 +100,9 @@ public static ResultString deploy(PayaraServer server, File application, TaskSta
/** Docker Instance. */
final boolean dockerInstance;

/** WSL Instance. */
final boolean wslInstance;

/** Host Path. */
final String hostPath;

Expand All @@ -122,10 +125,13 @@ public static ResultString deploy(PayaraServer server, File application, TaskSta
* @param properties Deployment properties.
* @param libraries Not used in actual deploy command.
* @param dockerInstance Docker Instance.
* @param wslInstance WSL Instance
* @param hostPath
* @param containerPath
* @param hotDeploy Hot Deploy.
*/
public CommandDeploy(String name, String target, File path, String contextRoot, Map<String, String> properties,
File[] libraries, final boolean dockerInstance, final String hostPath, final String containerPath,
File[] libraries, final boolean dockerInstance, final boolean wslInstance, final String hostPath, final String containerPath,
final boolean hotDeploy) {
super(COMMAND, name, target);

Expand All @@ -135,9 +141,10 @@ public CommandDeploy(String name, String target, File path, String contextRoot,
this.libraries = libraries;
this.dirDeploy = path.isDirectory();
this.dockerInstance = dockerInstance;
this.wslInstance = wslInstance;
this.hostPath = hostPath;
this.containerPath = containerPath;
this.hotDeploy = hotDeploy;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ private static String query(final Command command) {
throw new CommandException(CommandException.DOCKER_HOST_APPLICATION_PATH);
}
}
if (deploy.wslInstance) {
// Replace backslashes with forward slashes
path = path.replace("\\", "/");
// Add "mnt" prefix and drive letter
path = "/mnt/" + path.substring(0, 1).toLowerCase() + path.substring(2);
}
// Calculate StringBuilder initial length to avoid resizing
StringBuilder sb = new StringBuilder(DEFAULT_PARAM.length() + 1 + path.length() + 1 + FORCE_PARAM.length() + 1
+ force.length() + queryPropertiesLength(deploy.properties, PROPERTIES_PARAM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ protected void handleSend(HttpURLConnection hconn) throws IOException {
throw new CommandException(CommandException.DOCKER_HOST_APPLICATION_PATH);
}
}
if (command.wslInstance) {
// Replace backslashes with forward slashes
path = path.replace("\\", "/");
// Add "mnt" prefix and drive letter
path = "/mnt/" + path.substring(0, 1).toLowerCase() + path.substring(2);
}
OutputStreamWriter wr = new OutputStreamWriter(hconn.getOutputStream());
if (!command.dirDeploy) {
writeParam(wr, "path", path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class NewPayaraServerWizardFragment extends WizardFragment {

private Combo instanceTypeCombo;

private String[] instanceTypes = { PayaraServer.DEFAULT_TYPE, PayaraServer.DOCKER_TYPE };
private String[] instanceTypes = { PayaraServer.DEFAULT_TYPE, PayaraServer.DOCKER_TYPE, PayaraServer.WSL_TYPE };

private Label hostLocationLabel;

Expand Down

0 comments on commit be9522a

Please sign in to comment.