From a5398f4c8b40219a9230badf22ee7c5a68c12eff Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Tue, 16 Jan 2024 15:37:06 +0530 Subject: [PATCH 1/3] FISH-8152 Micro Maven - Devmode - Store session state --- .../plugins/micro/AutoDeployHandler.java | 1 + .../payara/maven/plugins/micro/DevMojo.java | 3 +- .../maven/plugins/micro/ReloadMojo.java | 28 +++++++++++++++---- .../payara/maven/plugins/micro/StartMojo.java | 3 ++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/AutoDeployHandler.java b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/AutoDeployHandler.java index d1fac575..13828a38 100644 --- a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/AutoDeployHandler.java +++ b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/AutoDeployHandler.java @@ -305,6 +305,7 @@ private void executeBuildReloadTask(List goalsList, boolean rebootRequir } else { updateTitle("Reloading"); ReloadMojo reloadMojo = new ReloadMojo(project, log); + reloadMojo.setKeepState(start.keepState); if (start.hotDeploy) { Path rootPath = project.getBasedir().toPath(); List sourcesChanged = new ArrayList<>(); diff --git a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/DevMojo.java b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/DevMojo.java index d025da76..6f200832 100644 --- a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/DevMojo.java +++ b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/DevMojo.java @@ -48,7 +48,7 @@ */ @Mojo(name = "dev") public class DevMojo extends StartMojo { - + @Override public void execute() throws MojoExecutionException { liveReload = true; @@ -58,6 +58,7 @@ public void execute() throws MojoExecutionException { if (trimLog == null) { trimLog = !getLog().isDebugEnabled(); } + keepState = true; super.execute(); } } diff --git a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/ReloadMojo.java b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/ReloadMojo.java index 18839b8f..e1ce8b7c 100644 --- a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/ReloadMojo.java +++ b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/ReloadMojo.java @@ -71,6 +71,9 @@ public class ReloadMojo extends BasePayaraMojo { @Parameter(property = "metadataChanged") private boolean metadataChanged; + + @Parameter(property = "keepState", defaultValue = "false") + protected boolean keepState; public ReloadMojo(MavenProject mavenProject, Log log) { this.mavenProject = mavenProject; @@ -95,14 +98,19 @@ public void execute() throws MojoExecutionException { } File reloadFile = new File(explodedDir, RELOAD_FILE); getLog().info("Reloading " + explodedDir); - if (hotDeploy) { + if (hotDeploy || keepState) { Properties props = new Properties(); - props.setProperty("hotdeploy", "true"); - if (metadataChanged) { - props.setProperty("metadatachanged", "true"); + if (keepState) { + props.setProperty("keepState", Boolean.TRUE.toString()); } - if (sourcesChanged != null && !sourcesChanged.isEmpty()) { - props.setProperty("sourceschanged", sourcesChanged); + if (hotDeploy) { + props.setProperty("hotdeploy", Boolean.TRUE.toString()); + if (metadataChanged) { + props.setProperty("metadatachanged", Boolean.TRUE.toString()); + } + if (sourcesChanged != null && !sourcesChanged.isEmpty()) { + props.setProperty("sourceschanged", sourcesChanged); + } } try (FileOutputStream outputStrem = new FileOutputStream(reloadFile)) { props.store(outputStrem, null); @@ -133,6 +141,14 @@ public void setHotDeploy(boolean hotDeploy) { this.hotDeploy = hotDeploy; } + public boolean isKeepState() { + return keepState; + } + + public void setKeepState(boolean keepState) { + this.keepState = keepState; + } + public String getSourcesChanged() { return sourcesChanged; } diff --git a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java index 84e5b93e..0aa3456b 100644 --- a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java +++ b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java @@ -111,6 +111,9 @@ public class StartMojo extends BasePayaraMojo { @Parameter(property = "autoDeploy", defaultValue = "false") protected boolean autoDeploy; + + @Parameter(property = "keepState", defaultValue = "false") + protected boolean keepState; @Parameter(property = "liveReload", defaultValue = "false") protected boolean liveReload; From d85a48d04659af66b547e0495e314c0e85e79e0c Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Fri, 19 Jan 2024 12:42:53 +0530 Subject: [PATCH 2/3] FISH-8139 set default value --- .../payara/maven/plugins/micro/DevMojo.java | 17 ++++++++++----- .../payara/maven/plugins/micro/StartMojo.java | 21 +++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/DevMojo.java b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/DevMojo.java index 6f200832..2fe99a3a 100644 --- a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/DevMojo.java +++ b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/DevMojo.java @@ -40,6 +40,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; /** * Run mojo that executes payara-micro in dev mode @@ -48,17 +49,23 @@ */ @Mojo(name = "dev") public class DevMojo extends StartMojo { - + @Override public void execute() throws MojoExecutionException { - liveReload = true; deployWar = true; exploded = true; - autoDeploy = true; + if (autoDeploy == null) { + autoDeploy = true; + } + if (liveReload == null) { + liveReload = true; + } + if (keepState == null) { + keepState = true; + } if (trimLog == null) { - trimLog = !getLog().isDebugEnabled(); + trimLog = true; } - keepState = true; super.execute(); } } diff --git a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java index 0aa3456b..85f6bd55 100644 --- a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java +++ b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java @@ -109,14 +109,14 @@ public class StartMojo extends BasePayaraMojo { @Parameter(property = "exploded", defaultValue = "false") protected boolean exploded; - @Parameter(property = "autoDeploy", defaultValue = "false") - protected boolean autoDeploy; + @Parameter(property = "autoDeploy") + protected Boolean autoDeploy; - @Parameter(property = "keepState", defaultValue = "false") - protected boolean keepState; + @Parameter(property = "keepState") + protected Boolean keepState; - @Parameter(property = "liveReload", defaultValue = "false") - protected boolean liveReload; + @Parameter(property = "liveReload") + protected Boolean liveReload; @Parameter(property = "browser") protected String browser; @@ -184,6 +184,15 @@ public void execute() throws MojoExecutionException { if(trimLog == null) { trimLog = false; } + if (autoDeploy == null) { + autoDeploy = false; + } + if (liveReload == null) { + liveReload = false; + } + if (keepState == null) { + keepState = false; + } if (autoDeploy && autoDeployHandler == null) { autoDeployHandler = new AutoDeployHandler(this, webappDirectory); Thread devModeThread = new Thread(autoDeployHandler); From edd15c807e9874794599de6c21d78ddf17cbe795 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Mon, 22 Jan 2024 11:28:12 +0530 Subject: [PATCH 3/3] FISH-8152 Show WebDriver warning in debug mood if Browser closed --- .../maven/plugins/micro/AutoDeployHandler.java | 7 +++---- .../fish/payara/maven/plugins/micro/StartMojo.java | 6 +++--- .../maven/plugins/micro/WebDriverFactory.java | 13 +++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/AutoDeployHandler.java b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/AutoDeployHandler.java index 13828a38..c57f51f2 100644 --- a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/AutoDeployHandler.java +++ b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/AutoDeployHandler.java @@ -63,6 +63,7 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.List; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -345,11 +346,9 @@ public void deleteBuildDir(String filePath) { log.error("Error occurred while deleting the file: ", e); } } - + private void updateTitle(String state) { - if (start.getDriver() != null) { - ((JavascriptExecutor) start.getDriver()).executeScript(String.format("document.title = '%s %s';", state, project.getName())); - } + WebDriverFactory.executeScript(String.format("document.title = '%s %s';", state, project.getName()), start.getDriver(), log); } class DeleteFileVisitor extends SimpleFileVisitor { diff --git a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java index 85f6bd55..b1e9fbe2 100644 --- a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java +++ b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/StartMojo.java @@ -530,13 +530,13 @@ private void redirectStreamToGivenOutputStream(final InputStream inputStream, fi driver = WebDriverFactory.createWebDriver(browser); driver.get(PropertiesUtils.getProperty(payaraMicroURL, payaraMicroURL)); } catch (Exception ex) { - getLog().error("Error in running WebDriver:" + ex.getMessage()); + getLog().error("Error in running WebDriver" , ex); try { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { Desktop.getDesktop().browse(new URI(payaraMicroURL)); } } catch (IOException | URISyntaxException e) { - getLog().error("Error in running Desktop browse:" + e.getMessage()); + getLog().error("Error in running Desktop browse", e); } finally { driver = null; } @@ -550,7 +550,7 @@ private void redirectStreamToGivenOutputStream(final InputStream inputStream, fi try { driver.navigate().refresh(); } catch (Exception ex) { - getLog().error("Error in refreshing with WebDriver:" + ex.getMessage()); + getLog().debug("Error in refreshing with WebDriver", ex); } } else if (autoDeploy && line.contains(INOTIFY_USER_LIMIT_REACHED_MESSAGE)) { diff --git a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/WebDriverFactory.java b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/WebDriverFactory.java index 26fafaaa..0fbc2f8a 100644 --- a/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/WebDriverFactory.java +++ b/payara-micro-maven-plugin/src/main/java/fish/payara/maven/plugins/micro/WebDriverFactory.java @@ -51,6 +51,9 @@ import org.openqa.selenium.safari.SafariDriver; import io.github.bonigarcia.wdm.WebDriverManager; import java.io.File; +import org.apache.maven.plugin.logging.Log; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriverException; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.ie.InternetExplorerOptions; @@ -165,4 +168,14 @@ public static boolean isChromeBrowserInstalled() { return false; } } + + public static void executeScript(String script, WebDriver driver, Log log) { + if (driver != null && driver instanceof JavascriptExecutor) { + try { + ((JavascriptExecutor) driver).executeScript(script); + } catch(WebDriverException ex) { + log.debug(ex); + } + } + } }