Skip to content

Commit

Permalink
fix plugin checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shruti0085 committed Sep 26, 2024
1 parent 1121839 commit 3051346
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public LspInstallation getLspInstallation() {
}
}

private static void makeExecutable(final Path filePath, PluginPlatform platform) throws IOException {
private static void makeExecutable(final Path filePath, final PluginPlatform platform) throws IOException {
// don't set file permissions for windows as it has issues using the executable
// otherwise
if (platform == PluginPlatform.WINDOWS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,25 @@ 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) {
return "Failed to load JS";
return "Failed to load JS";
}
var chatJsPath = server.getURI().toString()+"amazonq-ui.js";

var chatJsPath = server.getURI().toString() + "amazonq-ui.js";
return String.format("<!DOCTYPE html>\n"
+ "<html lang=\"en\">\n"
+ "<head>\n"
+ " <meta charset=\"UTF-8\">\n"
+ " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
+ " <meta \n"
+ " http-equiv=\"\"Content-Security-Policy\"\" \n"
+ " content=\"\"default-src 'none'; script-src %s 'unsafe-inline'; style-src {javascriptFilePath} 'unsafe-inline'; img-src 'self' data:; object-src 'none'; base-uri 'none'; upgrade-insecure-requests;\"\"\n"
+ " content=\"\"default-src 'none'; script-src %s 'unsafe-inline'; style-src {javascriptFilePath} 'unsafe-inline';"
+ " img-src 'self' data:; object-src 'none'; base-uri 'none'; upgrade-insecure-requests;\"\"\n"
+ " >"
+ " <title>Chat UI</title>\n"
+ " %s\n"
Expand Down Expand Up @@ -129,11 +130,10 @@ protected final void handleAuthStatusChange(final boolean isLoggedIn) {
}
});
}

@Override
public void dispose() {
public final void dispose() {
stopVirtualServer(server);
super.dispose();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ private void setupAuthStatusListeners() {
}

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

var handler = new ResourceHandler();

Expand All @@ -143,7 +142,7 @@ protected Server setupVirtualServer(String jsPath) {
}
}

protected void stopVirtualServer(Server server) {
protected final void stopVirtualServer(final Server server) {
if (server != null) {
try {
server.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void handleAuthStatusChange(final boolean isLoggedIn) {
Display.getDefault().asyncExec(() -> {
amazonQCommonActions.updateActionVisibility(isLoggedIn, getViewSite());
if (!isLoggedIn) {
browser.setText(getContent());
browser.setText(getContent());
} else {
browser.setText("Signed in");
AmazonQView.showView(AmazonQChatWebview.ID);
Expand All @@ -70,13 +70,13 @@ private String getContent() {
URL jsFile = PluginUtils.getResource("webview/build/assets/js/getStart.js");
var jsParent = Path.of(jsFile.toURI()).getParent();
var jsDirectoryPath = Path.of(jsParent.toUri()).normalize().toString();

server = setupVirtualServer(jsDirectoryPath);
if (server == null) {
return "Failed to load JS";
return "Failed to load JS";
}
var loginJsPath = server.getURI().toString()+"getStart.js";
var loginJsPath = server.getURI().toString() + "getStart.js";

return String.format("<!DOCTYPE html>\n"
+ "<html>\n"
+ " <head>\n"
Expand All @@ -101,7 +101,7 @@ private String getContent() {
return "Failed to load JS";
}
}

@Override
public void dispose() {
stopVirtualServer(server);
Expand Down

0 comments on commit 3051346

Please sign in to comment.