From 92ca1b857f96703068f3794e0063eaf773aa0e29 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 4 Nov 2024 12:08:35 +0530 Subject: [PATCH 01/12] changes for picking skipTests gradle.property argument passed for sub modules in multi module Signed-off-by: Arun Venmany --- .../tools/gradle/tasks/DevTask.groovy | 46 +++++-------------- .../tools/gradle/utils/DevTaskHelper.groovy | 12 +++++ .../TestMultiModuleLooseEarAppDevMode.groovy | 19 +++++++- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy index 938d04cc..25e0ee67 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy @@ -28,7 +28,6 @@ import io.openliberty.tools.common.plugins.util.ServerFeatureUtil import io.openliberty.tools.common.plugins.util.ServerFeatureUtil.FeaturesPlatforms import io.openliberty.tools.common.plugins.util.ServerStatusUtil import io.openliberty.tools.gradle.utils.DevTaskHelper -import io.openliberty.tools.gradle.utils.LooseWarApplication import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.artifacts.Configuration @@ -1416,8 +1415,10 @@ class DevTask extends AbstractFeatureTask { private List getProjectModules() { List upstreamProjects = new ArrayList(); for (Project dependencyProject : DevTaskHelper.getAllUpstreamProjects(project)) { - // TODO get compiler options for upstream project - // JavaCompilerOptions upstreamCompilerOptions = getMavenCompilerOptions(p); + // In Maven , there is a step to set compiler options for upstream project + // Gradle does not need to manually inject compiler options because + // we are directly calling compileJava task, which internally takes the compiler options + // from task definition or command line arguments JavaCompilerOptions upstreamCompilerOptions = new JavaCompilerOptions(); SourceSet mainSourceSet = dependencyProject.sourceSets.main; SourceSet testSourceSet = dependencyProject.sourceSets.test; @@ -1431,40 +1432,15 @@ class DevTask extends AbstractFeatureTask { File upstreamTestOutputDir = testOutputDirectory.asFile.get(); // resource directories List upstreamResourceDirs = mainSourceSet.resources.srcDirs.toList(); - /* TODO all gradle items - // properties that are set in the pom file - Properties props = dependencyProject.getProperties(); - - // properties that are set by user via CLI parameters - Properties userProps = session.getUserProperties(); - - Plugin libertyPlugin = getLibertyPluginForProject(p); - // use "dev" goal, although we don't expect the skip tests flags to be bound to any goal - Xpp3Dom config = ExecuteMojoUtil.getPluginGoalConfig(libertyPlugin, "dev", getLog()); - - boolean upstreamSkipTests = DevHelper.getBooleanFlag(config, userProps, props, "skipTests"); - boolean upstreamSkipITs = DevHelper.getBooleanFlag(config, userProps, props, "skipITs"); - boolean upstreamSkipUTs = DevHelper.getBooleanFlag(config, userProps, props, "skipUTs"); - - // only force skipping unit test for ear modules otherwise honour existing skip - // test params - - - // build list of dependent modules - List dependentProjects = graph.getDownstreamProjects(p, true); - List dependentModules = new ArrayList(); - for (MavenProject depProj : dependentProjects) { - dependentModules.add(depProj.getFile()); - } - */ - boolean upstreamSkipTests = false - boolean upstreamSkipITs = false - boolean upstreamSkipUTs = false + //get gradle project properties. It is observed that project properties contain all gradle properties + // properties are overridden automatically with the highest precedence + // in gradle, we are only using skopTests + boolean upstreamSkipTests = dependencyProject.hasProperty("skipTests") ? DevTaskHelper.parseBooleanIfDefined(dependencyProject.properties.get("skipTests")) : skipTests if (DevTaskHelper.getPackagingType(dependencyProject).equals("ear")) { upstreamSkipUTs = true; } - // build list of dependent modules + // build list of dependent modules -> can be kept as empty list in ci.gradle as gradle itself is evaluating other project module dependencies List dependentModules = new ArrayList(); ProjectModule upstreamProject = new ProjectModule(dependencyProject.getBuildFile(), dependencyProject.getName(), @@ -1477,8 +1453,8 @@ class DevTask extends AbstractFeatureTask { upstreamTestOutputDir, upstreamResourceDirs, upstreamSkipTests, - upstreamSkipUTs, - upstreamSkipITs, + false, + false, upstreamCompilerOptions, dependentModules); diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy index ec71de0d..6ff212d2 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy @@ -150,4 +150,16 @@ public class DevTaskHelper { retVal.add(war.getWebAppDirectory().get().asFile.toPath().toAbsolutePath()) } } + + /** + * Parses a Boolean from a Object if the Object is not null. Otherwise returns null. + * @param value the Object to parse + * @return a Boolean, or null if value is null + */ + public static Boolean parseBooleanIfDefined(Object value) { + if (value != null) { + return Boolean.parseBoolean(value as String); + } + return null; + } } diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy index 1891c79f..76a0b223 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy @@ -16,7 +16,7 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { createDir(buildDir); createTestProject(buildDir, resourceDir, buildFilename); new File(buildDir, "build").createNewFile(); - runDevMode(buildDir) + runDevMode("--skipTests",buildDir) } @Test @@ -39,6 +39,23 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { assertTrue(waitForCompilation(targetHelloWorld, lastModified, 6000)); } + @Test + public void manualTestsInvocationTest() throws Exception { + + writer.write("\n"); + writer.flush(); + if (!verifyLogMessage(2000, "Tests will not run on demand for ear because skipTests is set to true")) { + assertTrue(verifyLogMessage(2000, "Tests will not run on demand for ear because skipTests is set to true")); + } + if (!verifyLogMessage(2000, "Tests will not run on demand for jar because skipTests is set to true")) { + assertTrue(verifyLogMessage(2000, "Tests will not run on demand for jar because skipTests is set to true")); + } + if (!verifyLogMessage(2000, "Tests will not run on demand for war because skipTests is set to true")) { + assertTrue(verifyLogMessage(2000, "Tests will not run on demand for war because skipTests is set to true")); + } + + } + @AfterClass public static void cleanUpAfterClass() throws Exception { String stdout = getContents(logFile, "Dev mode std output"); From 8a321b4fa1f0a15d4b2867d874deee31132b3ec3 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 4 Nov 2024 12:13:56 +0530 Subject: [PATCH 02/12] changes for picking parent build.gradle Signed-off-by: Arun Venmany --- .../tools/gradle/tasks/DevTask.groovy | 11 ++++++++--- .../tools/gradle/utils/DevTaskHelper.groovy | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy index 25e0ee67..f162c045 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy @@ -377,14 +377,14 @@ class DevTask extends AbstractFeatureTask { boolean libertyDebug, boolean pollingTest, boolean container, File containerfile, File containerBuildContext, String containerRunOpts, int containerBuildTimeout, boolean skipDefaultPorts, boolean keepTempContainerfile, String mavenCacheLocation, String packagingType, File buildFile, boolean generateFeatures, List webResourceDirs, - List projectModuleList + List projectModuleList, Map> parentBuildGradle ) throws IOException, PluginExecutionException { super(buildDir, serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, projectDirectory, /* multi module project directory */ projectDirectory, resourceDirs, changeOnDemandTestsAction, hotTests, skipTests, false /* skipUTs */, false /* skipITs */, skipInstallFeature, artifactId, serverStartTimeout, verifyAppStartTimeout, appUpdateTimeout, ((long) (compileWait * 1000L)), libertyDebug, true /* useBuildRecompile */, true /* gradle */, pollingTest, container, containerfile, containerBuildContext, containerRunOpts, containerBuildTimeout, skipDefaultPorts, null /* compileOptions not needed since useBuildRecompile is true */, keepTempContainerfile, mavenCacheLocation, projectModuleList /* multi module upstream projects */, - false /* recompileDependencies only supported in ci.maven */, packagingType, buildFile, null /* parent build files */, generateFeatures, null /* compileArtifactPaths */, null /* testArtifactPaths */, webResourceDirs /* webResources */ + false /* recompileDependencies only supported in ci.maven */, packagingType, buildFile, parentBuildGradle /* parent build files */, generateFeatures, null /* compileArtifactPaths */, null /* testArtifactPaths */, webResourceDirs /* webResources */ ); this.libertyDirPropertyFiles = AbstractServerTask.getLibertyDirectoryPropertyFiles(installDirectory, userDirectory, serverDirectory); ServerFeatureUtil servUtil = getServerFeatureUtil(true, libertyDirPropertyFiles); @@ -1265,6 +1265,11 @@ class DevTask extends AbstractFeatureTask { // Project modules contain all child modules. This project modules will be present only for multi-module // used to watch sub project src and test source files List projectModules = getProjectModules() + // get parent build.gradle to register + Map> parentBuildGradle = new HashMap>(); + if(projectModules.size()>0) { + DevTaskHelper.updateParentBuildFiles(parentBuildGradle, project) + } try { this.util = new DevTaskUtil(project.getLayout().getBuildDirectory().getAsFile().get(), serverInstallDir, getUserDir(project, serverInstallDir), serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, project.getRootDir(), @@ -1272,7 +1277,7 @@ class DevTask extends AbstractFeatureTask { verifyAppStartTimeout.intValue(), verifyAppStartTimeout.intValue(), compileWait.doubleValue(), libertyDebug.booleanValue(), pollingTest.booleanValue(), container.booleanValue(), containerfile, containerBuildContext, containerRunOpts, containerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempContainerfile.booleanValue(), localMavenRepoForFeatureUtility, - DevTaskHelper.getPackagingType(project), buildFile, generateFeatures.booleanValue(), webResourceDirs, projectModules + DevTaskHelper.getPackagingType(project), buildFile, generateFeatures.booleanValue(), webResourceDirs, projectModules, parentBuildGradle ); } catch (IOException | PluginExecutionException e) { throw new GradleException("Error initializing dev mode.", e) diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy index 6ff212d2..70281cb9 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy @@ -162,4 +162,20 @@ public class DevTaskHelper { } return null; } + + /** + * Update map with list of parent build files and their subsequent child build files + * + * @param parentBuildFiles Map of parent build files and subsequent child build files + * @param proj GradleProject + */ + public static void updateParentBuildFiles(Map> parentBuildFiles, Project proj) { + String parentBuildGradle = proj.getRootProject().getBuildFile().getAbsolutePath().toString() + List childBuildFiles = new ArrayList<>(); + childBuildFiles.add(proj.getBuildFile().getAbsolutePath()) + for (Project dependencyProject : getAllUpstreamProjects(proj)) { + childBuildFiles.add(dependencyProject.getBuildFile().getAbsolutePath().toString()) + } + parentBuildFiles.put(parentBuildGradle, childBuildFiles) + } } From 30a0cc44088ea4817148a5191d83a59278f41509 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Mon, 4 Nov 2024 12:57:58 +0530 Subject: [PATCH 03/12] changes for showing option to restart or recompile when a change is detected in build.gradle Signed-off-by: Arun Venmany --- .../tools/gradle/tasks/DevTask.groovy | 21 +++++++++++++++++-- .../TestMultiModuleLooseEarAppDevMode.groovy | 19 +++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy index f162c045..fb2075e6 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy @@ -499,13 +499,23 @@ class DevTask extends AbstractFeatureTask { @Override public boolean updateArtifactPaths(ProjectModule projectModule, boolean redeployCheck, boolean generateFeatures, ThreadPoolExecutor executor) throws PluginExecutionException { - // not supported for Gradle, only used for multi module Maven projects + // unable to identify the changes made, showing option for user. always return false because action is invoked manually + if (isMultiModuleProject()) { + info("We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change"); + info("r - to restart server, type 'r' and press Enter."); + info("Press Enter to recompile the project and run tests manually"); + } return false; } @Override public boolean updateArtifactPaths(File parentBuildFile) { - // not supported for Gradle, only used for multi module Maven projects + // unable to identify the changes made, showing option for user. always return false because action is invoked manually + if (isMultiModuleProject()) { + info("We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change"); + info("r - to restart server, type 'r' and press Enter."); + info("Press Enter to recompile the project and run tests manually"); + } return false; } @@ -535,6 +545,13 @@ class DevTask extends AbstractFeatureTask { boolean installFeatures = false; boolean optimizeGenerateFeatures = false; + if (isMultiModuleProject()) { + info("We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change"); + info("r - to restart server, type 'r' and press Enter."); + info("Press Enter to recompile the project and run tests manually"); + return false; + } + ProjectBuilder builder = ProjectBuilder.builder(); Project newProject; try { diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy index 76a0b223..8f21e1fc 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy @@ -56,6 +56,24 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { } + @Test + public void modifyUpdateGradleTest() throws Exception { + + // modify a java file + File srcHelloWorld = new File(buildDir, "build.gradle"); + assertTrue(srcHelloWorld.exists()); + + waitLongEnough(); + String str = "// testing"; + BufferedWriter javaWriter = new BufferedWriter(new FileWriter(srcHelloWorld, true)); + javaWriter.append(' '); + javaWriter.append(str); + javaWriter.close(); + if (!verifyLogMessage(2000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")) { + assertTrue(verifyLogMessage(2000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")); + } + } + @AfterClass public static void cleanUpAfterClass() throws Exception { String stdout = getContents(logFile, "Dev mode std output"); @@ -64,4 +82,5 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { System.out.println(stderr); cleanUpAfterClass(true); } + } From 9e6cada87c771d226ebc55bc03aac692c0fdfcaa Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 5 Nov 2024 11:35:48 +0530 Subject: [PATCH 04/12] Changing absolutePath to cannoicalPath to see whether java 21 windows test issues are resolving Signed-off-by: Arun Venmany --- .../io/openliberty/tools/gradle/utils/DevTaskHelper.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy b/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy index 70281cb9..e3957b6a 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/utils/DevTaskHelper.groovy @@ -170,11 +170,11 @@ public class DevTaskHelper { * @param proj GradleProject */ public static void updateParentBuildFiles(Map> parentBuildFiles, Project proj) { - String parentBuildGradle = proj.getRootProject().getBuildFile().getAbsolutePath().toString() + String parentBuildGradle = proj.getRootProject().getBuildFile().getCanonicalPath() List childBuildFiles = new ArrayList<>(); - childBuildFiles.add(proj.getBuildFile().getAbsolutePath()) + childBuildFiles.add(proj.getBuildFile().getCanonicalPath()) for (Project dependencyProject : getAllUpstreamProjects(proj)) { - childBuildFiles.add(dependencyProject.getBuildFile().getAbsolutePath().toString()) + childBuildFiles.add(dependencyProject.getBuildFile().getCanonicalPath()) } parentBuildFiles.put(parentBuildGradle, childBuildFiles) } From 319ef845ad7f0f0a2b39a55c3ef896d780604b0e Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 5 Nov 2024 13:05:12 +0530 Subject: [PATCH 05/12] Changing timeouts Signed-off-by: Arun Venmany --- .../TestMultiModuleLooseEarAppDevMode.groovy | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy index 8f21e1fc..b39ea5eb 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy @@ -16,7 +16,8 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { createDir(buildDir); createTestProject(buildDir, resourceDir, buildFilename); new File(buildDir, "build").createNewFile(); - runDevMode("--skipTests",buildDir) + runDevMode("--skipTests", buildDir) + Thread.wait(20000) } @Test @@ -44,14 +45,14 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { writer.write("\n"); writer.flush(); - if (!verifyLogMessage(2000, "Tests will not run on demand for ear because skipTests is set to true")) { - assertTrue(verifyLogMessage(2000, "Tests will not run on demand for ear because skipTests is set to true")); + if (!verifyLogMessage(6000, "Tests will not run on demand for ear because skipTests is set to true")) { + assertTrue(verifyLogMessage(6000, "Tests will not run on demand for ear because skipTests is set to true")); } - if (!verifyLogMessage(2000, "Tests will not run on demand for jar because skipTests is set to true")) { - assertTrue(verifyLogMessage(2000, "Tests will not run on demand for jar because skipTests is set to true")); + if (!verifyLogMessage(6000, "Tests will not run on demand for jar because skipTests is set to true")) { + assertTrue(verifyLogMessage(6000, "Tests will not run on demand for jar because skipTests is set to true")); } - if (!verifyLogMessage(2000, "Tests will not run on demand for war because skipTests is set to true")) { - assertTrue(verifyLogMessage(2000, "Tests will not run on demand for war because skipTests is set to true")); + if (!verifyLogMessage(6000, "Tests will not run on demand for war because skipTests is set to true")) { + assertTrue(verifyLogMessage(6000, "Tests will not run on demand for war because skipTests is set to true")); } } @@ -63,14 +64,13 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { File srcHelloWorld = new File(buildDir, "build.gradle"); assertTrue(srcHelloWorld.exists()); - waitLongEnough(); String str = "// testing"; BufferedWriter javaWriter = new BufferedWriter(new FileWriter(srcHelloWorld, true)); javaWriter.append(' '); javaWriter.append(str); javaWriter.close(); - if (!verifyLogMessage(2000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")) { - assertTrue(verifyLogMessage(2000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")); + if (!verifyLogMessage(6000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")) { + assertTrue(verifyLogMessage(6000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")); } } From 51dedffd40d1e76119f5ba96e4b523ab80439f96 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 5 Nov 2024 14:31:14 +0530 Subject: [PATCH 06/12] Changing timeouts Signed-off-by: Arun Venmany --- .../tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy index b39ea5eb..01a729bb 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy @@ -17,7 +17,6 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { createTestProject(buildDir, resourceDir, buildFilename); new File(buildDir, "build").createNewFile(); runDevMode("--skipTests", buildDir) - Thread.wait(20000) } @Test @@ -42,7 +41,7 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { @Test public void manualTestsInvocationTest() throws Exception { - + waitLongEnough(); writer.write("\n"); writer.flush(); if (!verifyLogMessage(6000, "Tests will not run on demand for ear because skipTests is set to true")) { @@ -59,7 +58,7 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { @Test public void modifyUpdateGradleTest() throws Exception { - + waitLongEnough(); // modify a java file File srcHelloWorld = new File(buildDir, "build.gradle"); assertTrue(srcHelloWorld.exists()); @@ -69,6 +68,7 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { javaWriter.append(' '); javaWriter.append(str); javaWriter.close(); + if (!verifyLogMessage(6000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")) { assertTrue(verifyLogMessage(6000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")); } From 19c0f0cb61b9d197037c87ec9e70ce9d68d68850 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 5 Nov 2024 15:59:22 +0530 Subject: [PATCH 07/12] Changing timeouts Signed-off-by: Arun Venmany --- .../io/openliberty/tools/gradle/tasks/DevTask.groovy | 6 +++--- .../gradle/TestMultiModuleLooseEarAppDevMode.groovy | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy index fb2075e6..c088764f 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy @@ -501,7 +501,7 @@ class DevTask extends AbstractFeatureTask { throws PluginExecutionException { // unable to identify the changes made, showing option for user. always return false because action is invoked manually if (isMultiModuleProject()) { - info("We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change"); + info("We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change"); info("r - to restart server, type 'r' and press Enter."); info("Press Enter to recompile the project and run tests manually"); } @@ -512,7 +512,7 @@ class DevTask extends AbstractFeatureTask { public boolean updateArtifactPaths(File parentBuildFile) { // unable to identify the changes made, showing option for user. always return false because action is invoked manually if (isMultiModuleProject()) { - info("We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change"); + info("We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change"); info("r - to restart server, type 'r' and press Enter."); info("Press Enter to recompile the project and run tests manually"); } @@ -546,7 +546,7 @@ class DevTask extends AbstractFeatureTask { boolean optimizeGenerateFeatures = false; if (isMultiModuleProject()) { - info("We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change"); + info("We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change"); info("r - to restart server, type 'r' and press Enter."); info("Press Enter to recompile the project and run tests manually"); return false; diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy index 01a729bb..05462dfd 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy @@ -36,7 +36,7 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { javaWriter.append(str); javaWriter.close(); - assertTrue(waitForCompilation(targetHelloWorld, lastModified, 6000)); + assertTrue(waitForCompilation(targetHelloWorld, lastModified, 123000)); } @Test @@ -44,8 +44,8 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { waitLongEnough(); writer.write("\n"); writer.flush(); - if (!verifyLogMessage(6000, "Tests will not run on demand for ear because skipTests is set to true")) { - assertTrue(verifyLogMessage(6000, "Tests will not run on demand for ear because skipTests is set to true")); + if (!verifyLogMessage(123000, "Tests will not run on demand for ear because skipTests is set to true")) { + assertTrue(verifyLogMessage(123000, "Tests will not run on demand for ear because skipTests is set to true")); } if (!verifyLogMessage(6000, "Tests will not run on demand for jar because skipTests is set to true")) { assertTrue(verifyLogMessage(6000, "Tests will not run on demand for jar because skipTests is set to true")); @@ -69,8 +69,8 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { javaWriter.append(str); javaWriter.close(); - if (!verifyLogMessage(6000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")) { - assertTrue(verifyLogMessage(6000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")); + if (!verifyLogMessage(123000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")) { + assertTrue(verifyLogMessage(123000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")); } } From 5c6d2b92c1ced182472801ce3fd40ad4a6629518 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 5 Nov 2024 16:10:36 +0530 Subject: [PATCH 08/12] Changing workflow yaml to test only failed class Signed-off-by: Arun Venmany --- .github/workflows/gradle.yml | 2 +- .../tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f5797de1..979bc89d 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -160,7 +160,7 @@ jobs: working-directory: C:/ci.gradle # LibertyTest is excluded because test0_run hangs # For Java 8, TestCreateWithConfigDir is excluded because test_micro_clean_liberty_plugin_variable_config runs out of memory - run: ./gradlew clean install check -P"test.exclude"="${{env.TEST_EXCLUDE}}" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" --stacktrace --info --no-daemon + run: ./gradlew clean install check -P"test.include"="**/TestMultiModuleLooseEarAppDev*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" --stacktrace --info --no-daemon timeout-minutes: 75 # Copy build reports and upload artifact if build failed - name: Copy build/report/tests/test for upload diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy index 05462dfd..11f94b54 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy @@ -69,8 +69,8 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { javaWriter.append(str); javaWriter.close(); - if (!verifyLogMessage(123000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")) { - assertTrue(verifyLogMessage(123000, "We detected a change in build.gradle, but we cannot identify whether it’s a runtime or dependency change")); + if (!verifyLogMessage(123000, "We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change")) { + assertTrue(verifyLogMessage(123000, "We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change")); } } From 8a5d5513a452439770597a8c2f618305b9cd84bb Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 5 Nov 2024 17:14:24 +0530 Subject: [PATCH 09/12] rolling back workflow yaml since all new tests are success Signed-off-by: Arun Venmany --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 979bc89d..f5797de1 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -160,7 +160,7 @@ jobs: working-directory: C:/ci.gradle # LibertyTest is excluded because test0_run hangs # For Java 8, TestCreateWithConfigDir is excluded because test_micro_clean_liberty_plugin_variable_config runs out of memory - run: ./gradlew clean install check -P"test.include"="**/TestMultiModuleLooseEarAppDev*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" --stacktrace --info --no-daemon + run: ./gradlew clean install check -P"test.exclude"="${{env.TEST_EXCLUDE}}" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" --stacktrace --info --no-daemon timeout-minutes: 75 # Copy build reports and upload artifact if build failed - name: Copy build/report/tests/test for upload From 1a7a7fc46aac8f55a085ac825db7aed78ba6f694 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Thu, 7 Nov 2024 08:55:47 +0530 Subject: [PATCH 10/12] incorparating review comments Signed-off-by: Arun Venmany --- .../tools/gradle/tasks/DevTask.groovy | 22 +++++++++---------- .../TestMultiModuleLooseEarAppDevMode.groovy | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy index c088764f..a5244081 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy @@ -501,9 +501,8 @@ class DevTask extends AbstractFeatureTask { throws PluginExecutionException { // unable to identify the changes made, showing option for user. always return false because action is invoked manually if (isMultiModuleProject()) { - info("We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change"); - info("r - to restart server, type 'r' and press Enter."); - info("Press Enter to recompile the project and run tests manually"); + info("A change was detected in a build file. The libertyDev task could not determine if a server restart is required."); + info("To restart the server, type 'r' and press Enter."); } return false; } @@ -512,9 +511,8 @@ class DevTask extends AbstractFeatureTask { public boolean updateArtifactPaths(File parentBuildFile) { // unable to identify the changes made, showing option for user. always return false because action is invoked manually if (isMultiModuleProject()) { - info("We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change"); - info("r - to restart server, type 'r' and press Enter."); - info("Press Enter to recompile the project and run tests manually"); + info("A change was detected in a build file. The libertyDev task could not determine if a server restart is required."); + info("To restart the server, type 'r' and press Enter."); } return false; } @@ -546,9 +544,8 @@ class DevTask extends AbstractFeatureTask { boolean optimizeGenerateFeatures = false; if (isMultiModuleProject()) { - info("We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change"); - info("r - to restart server, type 'r' and press Enter."); - info("Press Enter to recompile the project and run tests manually"); + info("A change was detected in a build file. The libertyDev task could not determine if a server restart is required."); + info("To restart the server, type 'r' and press Enter."); return false; } @@ -1456,13 +1453,16 @@ class DevTask extends AbstractFeatureTask { List upstreamResourceDirs = mainSourceSet.resources.srcDirs.toList(); //get gradle project properties. It is observed that project properties contain all gradle properties // properties are overridden automatically with the highest precedence - // in gradle, we are only using skopTests + // in gradle, we are only using skipTests boolean upstreamSkipTests = dependencyProject.hasProperty("skipTests") ? DevTaskHelper.parseBooleanIfDefined(dependencyProject.properties.get("skipTests")) : skipTests if (DevTaskHelper.getPackagingType(dependencyProject).equals("ear")) { upstreamSkipUTs = true; } - // build list of dependent modules -> can be kept as empty list in ci.gradle as gradle itself is evaluating other project module dependencies + // build list of dependent modules -> can be kept as empty list for gradle + // In gradle multi module project, we are calling compileJava for ear + // Then gradle internally identifies other transitive project dependencies and calls compileJava for each of them + // gradle checks whether the task is UP TO DATE, if its already UP TO DATE, it wont be triggered again List dependentModules = new ArrayList(); ProjectModule upstreamProject = new ProjectModule(dependencyProject.getBuildFile(), dependencyProject.getName(), diff --git a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy index 11f94b54..95489554 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarAppDevMode.groovy @@ -69,8 +69,8 @@ class TestMultiModuleLooseEarAppDevMode extends BaseDevTest { javaWriter.append(str); javaWriter.close(); - if (!verifyLogMessage(123000, "We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change")) { - assertTrue(verifyLogMessage(123000, "We detected a change in build.gradle, but we cannot identify whether it's a runtime or dependency change")); + if (!verifyLogMessage(123000, "A change was detected in a build file. The libertyDev task could not determine if a server restart is required.")) { + assertTrue(verifyLogMessage(123000, "A change was detected in a build file. The libertyDev task could not determine if a server restart is required.")); } } From 36ba635b1a7a47a6288866b1e6a15f31a2b8c1a3 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Thu, 7 Nov 2024 20:36:46 +0530 Subject: [PATCH 11/12] changes in workflow to build custom ci common branch to run tests Signed-off-by: Arun Venmany --- .github/workflows/gradle.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f5797de1..b09a4de1 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -39,8 +39,9 @@ jobs: - name: Checkout ci.common uses: actions/checkout@v3 with: - repository: OpenLiberty/ci.common + repository: arunvenmany-ibm/ci.common path: ci.common + ref: varProcessing - name: Checkout ci.ant uses: actions/checkout@v3 with: @@ -124,7 +125,7 @@ jobs: - name: Clone ci.ant, ci.common, ci.gradle repos to C drive run: | cp -r D:/a/ci.gradle/ci.gradle C:/ci.gradle - git clone https://github.com/OpenLiberty/ci.common.git C:/ci.common + git clone https://github.com/arunvenmany-ibm/ci.common.git --branch varProcessing --single-branch C:/ci.common git clone https://github.com/OpenLiberty/ci.ant.git C:/ci.ant # Cache mvn/gradle packages - name: Cache Maven packages From 85b8432ac1925f73002bf52ca134a32816b67ed8 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Fri, 8 Nov 2024 11:58:00 +0530 Subject: [PATCH 12/12] workflow yaml changes to test ci comon varProcessing branch with ci.maven integration tests Signed-off-by: Arun Venmany --- build.gradle | 2 +- .../tools/gradle/tasks/AbstractServerTask.groovy | 10 ++++------ .../openliberty/tools/gradle/tasks/DeployTask.groovy | 3 +-- .../io/openliberty/tools/gradle/tasks/StartTask.groovy | 3 +-- .../openliberty/tools/gradle/tasks/UndeployTask.groovy | 3 +-- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index cc5e19e3..c1dd63c8 100644 --- a/build.gradle +++ b/build.gradle @@ -57,7 +57,7 @@ compileTestGroovy { } def libertyAntVersion = "1.9.16" -def libertyCommonVersion = "1.8.35" +def libertyCommonVersion = "1.8.36-SNAPSHOT" dependencies { implementation gradleApi() diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy index aa22c6d2..51004969 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy @@ -505,10 +505,9 @@ abstract class AbstractServerTask extends AbstractLibertyTask { configureMultipleAppsConfigDropins(serverNode) } - protected ServerConfigDocument getServerConfigDocument(CommonLogger log, File serverXML, File configDir, File bootstrapFile, - Map bootstrapProp, File serverEnvFile, boolean giveConfigDirPrecedence, Map libertyDirPropertyFiles) throws IOException { - if (scd == null || !scd.getServerXML().getCanonicalPath().equals(serverXML.getCanonicalPath())) { - scd = new ServerConfigDocument(log, serverXML, configDir, bootstrapFile, bootstrapProp, serverEnvFile, giveConfigDirPrecedence, libertyDirPropertyFiles) + protected ServerConfigDocument getServerConfigDocument(CommonLogger log, Map libertyDirPropertyFiles) throws IOException { + if (scd == null) { + scd = new ServerConfigDocument(log, libertyDirPropertyFiles) } return scd @@ -520,8 +519,7 @@ abstract class AbstractServerTask extends AbstractLibertyTask { if (serverConfigFile != null && serverConfigFile.exists()) { try { Map props = combinedBootstrapProperties == null ? convertPropertiesToMap(server.bootstrapProperties) : combinedBootstrapProperties; - getServerConfigDocument(new CommonLogger(project), serverConfigFile, server.configDirectory, server.bootstrapPropertiesFile, props, server.serverEnvFile, - false, getLibertyDirectoryPropertyFiles(null)); + scd = getServerConfigDocument(new CommonLogger(project), getLibertyDirectoryPropertyFiles(null)); if (scd != null && isLocationFound( scd.getLocations(), fileName)) { logger.debug("Application configuration is found in server.xml : " + fileName) configured = true diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy index 92313838..0022edef 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DeployTask.groovy @@ -682,8 +682,7 @@ class DeployTask extends AbstractServerTask { File serverXML = new File(getServerDir(project).getCanonicalPath(), "server.xml") try { - scd = getServerConfigDocument(new CommonLogger(project), serverXML, server.configDirectory, - server.bootstrapPropertiesFile, combinedBootstrapProperties, server.serverEnvFile, false, getLibertyDirectoryPropertyFiles(null)) + scd = getServerConfigDocument(new CommonLogger(project), getLibertyDirectoryPropertyFiles(null)) //appName will be set to a name derived from appFile if no name can be found. appName = scd.findNameForLocation(appFile) diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/StartTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/StartTask.groovy index 244d24b3..fc8ae70c 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/StartTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/StartTask.groovy @@ -86,8 +86,7 @@ class StartTask extends AbstractServerTask { if (serverConfigFile != null && serverConfigFile.exists()) { try { Map props = combinedBootstrapProperties == null ? convertPropertiesToMap(server.bootstrapProperties) : combinedBootstrapProperties; - getServerConfigDocument(new CommonLogger(project), serverConfigFile, server.configDirectory, server.bootstrapPropertiesFile, props, server.serverEnvFile, - false, getLibertyDirectoryPropertyFiles(null)); + scd = getServerConfigDocument(new CommonLogger(project), getLibertyDirectoryPropertyFiles(null)); if (scd != null) { appNames = scd.getNames() appNames += scd.getNamelessLocations().collect { String location -> diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/UndeployTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/UndeployTask.groovy index 3b66e588..9c2e8712 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/UndeployTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/UndeployTask.groovy @@ -79,8 +79,7 @@ class UndeployTask extends AbstractServerTask { File serverXML = new File(getServerDir(project).getCanonicalPath(), "server.xml") try { - getServerConfigDocument(new CommonLogger(project), serverXML, server.configDirectory, - server.bootstrapPropertiesFile, combinedBootstrapProperties, server.serverEnvFile, false, getLibertyDirectoryPropertyFiles(null)) + scd= getServerConfigDocument(new CommonLogger(project), getLibertyDirectoryPropertyFiles(null)) //appName will be set to a name derived from appFile if no name can be found. appName = scd.findNameForLocation(file)