Skip to content

Commit

Permalink
fix some checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shruti0085 committed Sep 26, 2024
1 parent e10afd4 commit fba32da
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package software.aws.toolkits.eclipse.amazonq.views;

import java.nio.file.Path;

import org.eclipse.jetty.server.Server;
import org.eclipse.swt.browser.BrowserFunction;
import org.eclipse.swt.widgets.Composite;
Expand Down Expand Up @@ -58,12 +57,12 @@ public Object function(final Object[] arguments) {
}

private String getContent() {
String jsFile = PluginUtils.getAwsDirectory(LspConstants.LSP_SUBDIRECTORY).resolve("amazonq-ui.js").toString();
String jsFile = PluginUtils.getAwsDirectory(LspConstants.LSP_SUBDIRECTORY).resolve("amazonq-ui.js").toString();
var jsParent = Path.of(jsFile).getParent();
var jsDirectoryPath = Path.of(jsParent.toUri()).normalize().toString();

server = setupVirtualServer(jsDirectoryPath);
if(server == null) {
if (server == null) {
return "Failed to load JS";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,70 +104,70 @@ private void setupActions(final Browser browser, final boolean isLoggedIn) {
amazonQCommonActions = new AmazonQCommonActions(browser, isLoggedIn, getViewSite());
}

private void setupAuthStatusListeners() {
authStatusChangedListener = this::handleAuthStatusChange;
AuthUtils.addAuthStatusChangeListener(amazonQCommonActions.getSignoutAction());
AuthUtils.addAuthStatusChangeListener(amazonQCommonActions.getFeedbackDialogContributionAction());
}

/**
* Sets up virtual host mapping for the given path using jetty server
*
* @param jsPath
* @return server launched
*/
protected Server setupVirtualServer(String jsPath) {
Server server = null;
try {
server = new Server(0);
var servletContext = new ContextHandler();
servletContext.setContextPath("/");
servletContext.addVirtualHosts(new String[] { "localhost" });

var handler = new ResourceHandler();

ResourceFactory resourceFactory = ResourceFactory.of(server);
handler.setBaseResource(resourceFactory.newResource(jsPath));
handler.setDirAllowed(true);
servletContext.setHandler(handler);

server.setHandler(servletContext);
server.start();

return server;

} catch (Exception e) {
stopVirtualServer(server);
PluginLogger.error("Error occurred while attempting to start a virtual server for " + jsPath, e);
return null;
}
}

protected void stopVirtualServer(Server server) {
if (server != null) {
try {
server.stop();
} catch (Exception e) {
PluginLogger.error("Error occurred when attempting to stop the virtual server", e);
}
}
}

@Override
public final void setFocus() {
browser.setFocus();
}

/**
* Disposes of the resources associated with this view.
*
* This method is called when the view is closed. It removes the authentication
* status change listener and the selection listener from the page.
*/
@Override
public void dispose() {
AuthUtils.removeAuthStatusChangeListener(authStatusChangedListener);
super.dispose();
}
private void setupAuthStatusListeners() {
authStatusChangedListener = this::handleAuthStatusChange;
AuthUtils.addAuthStatusChangeListener(amazonQCommonActions.getSignoutAction());
AuthUtils.addAuthStatusChangeListener(amazonQCommonActions.getFeedbackDialogContributionAction());
}

/**
* Sets up virtual host mapping for the given path using jetty server
*
* @param jsPath
* @return server launched
*/
protected Server setupVirtualServer(String jsPath) {
Server server = null;
try {
server = new Server(0);
var servletContext = new ContextHandler();
servletContext.setContextPath("/");
servletContext.addVirtualHosts(new String[] { "localhost" });

var handler = new ResourceHandler();

ResourceFactory resourceFactory = ResourceFactory.of(server);
handler.setBaseResource(resourceFactory.newResource(jsPath));
handler.setDirAllowed(true);
servletContext.setHandler(handler);

server.setHandler(servletContext);
server.start();

return server;

} catch (Exception e) {
stopVirtualServer(server);
PluginLogger.error("Error occurred while attempting to start a virtual server for " + jsPath, e);
return null;
}
}

protected void stopVirtualServer(Server server) {
if (server != null) {
try {
server.stop();
} catch (Exception e) {
PluginLogger.error("Error occurred when attempting to stop the virtual server", e);
}
}
}

@Override
public final void setFocus() {
browser.setFocus();
}

/**
* Disposes of the resources associated with this view.
*
* This method is called when the view is closed. It removes the authentication
* status change listener and the selection listener from the page.
*/
@Override
public void dispose() {
AuthUtils.removeAuthStatusChangeListener(authStatusChangedListener);
super.dispose();
}

}

0 comments on commit fba32da

Please sign in to comment.