Skip to content

Commit

Permalink
incorparting review comments and fixing windows test issues
Browse files Browse the repository at this point in the history
Signed-off-by: Arun Venmany <[email protected]>
  • Loading branch information
arunvenmany-ibm committed Oct 16, 2024
1 parent a40e294 commit 7d31b7a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 84 deletions.
14 changes: 8 additions & 6 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,10 @@ class DevTask extends AbstractFeatureTask {

@TaskAction
void action() {
HashSet<Project> allProjects = new HashSet<>()
//all projects contain list of all gradle projects.
// this list of projects is passed to DevTaskUtil constructor
// to be used for recompileBuildFile, updateArtifcatPaths etc
Set<Project> allProjects = new HashSet<Project>()
initializeDefaultValues();

SourceSet mainSourceSet = project.sourceSets.main;
Expand Down Expand Up @@ -1264,8 +1267,10 @@ class DevTask extends AbstractFeatureTask {

File buildFile = project.getBuildFile();

List<Path> webResourceDirs = LooseWarApplication.getWebSourceDirectoriesToMonitor(project);
List<Path> webResourceDirs = DevTaskHelper.getWebSourceDirectoriesToMonitor(project);
// Instantiate util before any child gradle tasks launched so it can help find available port if needed
// 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<ProjectModule> projectModules = getProjectModules()
allProjects.add(project)
allProjects.addAll(DevTaskHelper.getAllUpstreamProjects(project))
Expand Down Expand Up @@ -1418,10 +1423,7 @@ class DevTask extends AbstractFeatureTask {

private List<ProjectModule> getProjectModules() {
List<ProjectModule> upstreamProjects = new ArrayList<ProjectModule>();

HashSet<Project> allProjects = new HashSet<>()
allProjects.addAll(DevTaskHelper.getAllUpstreamProjects(project))
for (Project dependencyProject : allProjects) {
for (Project dependencyProject : DevTaskHelper.getAllUpstreamProjects(project)) {
// TODO get compiler options for upstream project
// JavaCompilerOptions upstreamCompilerOptions = getMavenCompilerOptions(p);
JavaCompilerOptions upstreamCompilerOptions = new JavaCompilerOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
*/
package io.openliberty.tools.gradle.utils


import org.apache.commons.io.FilenameUtils
import org.apache.tools.ant.taskdefs.Jar
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.tasks.bundling.War
import org.gradle.plugins.ear.Ear

import java.nio.file.Path

public class DevTaskHelper {

/**
Expand Down Expand Up @@ -58,8 +61,8 @@ public class DevTaskHelper {
* @param project project
* @return
*/
public static HashMap<File, Dependency> getDeployDependencies(Project project) {
HashMap<File, Dependency> completeDeployDeps = new HashMap<File, Dependency>();
public static Map<File, Dependency> getDeployDependencies(Project project) {
Map<File, Dependency> completeDeployDeps = new HashMap<File, Dependency>();
File[] filesAsDeps = project.configurations.deploy.getFiles().toArray()
Dependency[] deployDeps = project.configurations.deploy.getAllDependencies().toArray()

Expand Down Expand Up @@ -94,4 +97,57 @@ public class DevTaskHelper {
}
return allDependentProjects;
}

/**
* get web app source directories
* @param project
* @return
*/
public static List<Path> getWebSourceDirectoriesToMonitor(Project project) {
List<Path> retVal = new ArrayList<Path>();
Task warTask = project.getTasks().findByName('war')
if (warTask != null) {
setWarSourceDir(warTask, retVal)
} else if (project.configurations.deploy != null) {
setWarSourceDirForDeployDependencies(project, retVal)
} else {
retVal.add("src/main/webapp")
}
return retVal;
}
/**
* find war deploy dependencies and add source dir
* @param project
* @param retVal
*/
private static void setWarSourceDirForDeployDependencies(Project project, ArrayList<Path> retVal) {
Task warTask
HashMap<File, Dependency> completeDeployDeps = DevTaskHelper.getDeployDependencies(project)
for (Map.Entry<File, Dependency> entry : completeDeployDeps) {
Dependency dependency = entry.getValue();
File dependencyFile = entry.getKey();

if (dependency instanceof ProjectDependency) {
Project dependencyProject = dependency.getDependencyProject()
String projectType = FilenameUtils.getExtension(dependencyFile.toString())
switch (projectType) {
case "war":
warTask = dependencyProject.getTasks().findByName('war')
if (warTask != null) {
setWarSourceDir(warTask, retVal)
}
break;
default:
break;
}
}
}
}

private static void setWarSourceDir(Task warTask, ArrayList<Path> retVal) {
War war = (War) warTask.getProject().war
if (war.getWebAppDirectory().getAsFile().get() != null) {
retVal.add(war.getWebAppDirectory().get().asFile.toPath())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,57 +37,4 @@ public class LooseWarApplication extends LooseApplication {
}
config.addDir(sourceDir, "/")
}

/**
* get web app source directories
* @param project
* @return
*/
public static List<Path> getWebSourceDirectoriesToMonitor(Project project) {
List<Path> retVal = new ArrayList<Path>();
Task warTask = project.getTasks().findByName('war')
if (warTask != null) {
setWarSourceDir(warTask, retVal)
} else if (project.configurations.deploy != null) {
setWarSourceDirForDeployDependencies(project, retVal)
} else {
retVal.add("src/main/webapp")
}
return retVal;
}
/**
* find war deploy dependencies and add source dir
* @param project
* @param retVal
*/
private static void setWarSourceDirForDeployDependencies(Project project, ArrayList<Path> retVal) {
Task warTask
HashMap<File, Dependency> completeDeployDeps = DevTaskHelper.getDeployDependencies(project)
for (Map.Entry<File, Dependency> entry : completeDeployDeps) {
Dependency dependency = entry.getValue();
File dependencyFile = entry.getKey();

if (dependency instanceof ProjectDependency) {
Project dependencyProject = dependency.getDependencyProject()
String projectType = FilenameUtils.getExtension(dependencyFile.toString())
switch (projectType) {
case "war":
warTask = dependencyProject.getTasks().findByName('war')
if (warTask != null) {
setWarSourceDir(warTask, retVal)
}
break;
default:
break;
}
}
}
}

private static void setWarSourceDir(Task warTask, ArrayList<Path> retVal) {
War war = (War) warTask.getProject().war
if (war.getWebAppDirectory().getAsFile().get() != null) {
retVal.add(war.getWebAppDirectory().get().asFile.toPath())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
* (C) Copyright IBM Corporation 2020, 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.openliberty.tools.gradle

import org.junit.AfterClass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.openliberty.tools.gradle


import org.junit.AfterClass
import org.junit.Assert
import org.junit.BeforeClass
Expand Down Expand Up @@ -91,18 +90,22 @@ public class TestMultiModuleLooseEarWithPages extends AbstractIntegrationTest{
nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET);
Assert.assertEquals("Number of <archive/> element ==>", 2, nodes.getLength());
if (OSUtil.isWindows()) {
ejbWar = "\\ejb-war-1.0-SNAPSHOT.war"
warWebappsFolder = "\\multi-module-loose-ear-pages-test\\war\\src\\main\\webapp"
ejbJar = "\\WEB-INF\\lib\\ejb-jar-1.0-SNAPSHOT.jar"
ejbWar = "//ejb-war-1.0-SNAPSHOT.war"
warWebappsFolder = "//multi-module-loose-ear-pages-test//war//src//main//webapp"
ejbJar = "//WEB-INF//lib//ejb-jar-1.0-SNAPSHOT.jar"
}
Assert.assertEquals(ejbWar, nodes.item(0).getAttributes()
.getNamedItem("targetInArchive").getNodeValue())
Assert.assertTrue(List.of(nodes.item(0).getAttributes()
.getNamedItem("targetInArchive").getNodeValue(),
nodes.item(0).getAttributes()
.getNamedItem("targetInArchive").getNodeValue()).contains(ejbWar))

expression = "/archive/archive/dir";
nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET);
Assert.assertEquals("Number of <archive/> element ==>", 3, nodes.getLength());

Assert.assertTrue(nodes.item(0).getAttributes().getNamedItem("sourceOnDisk").getNodeValue().contains(warWebappsFolder));
Assert.assertTrue(nodes.item(0).getAttributes().getNamedItem("sourceOnDisk").getNodeValue().contains(warWebappsFolder)
||nodes.item(1).getAttributes().getNamedItem("sourceOnDisk").getNodeValue().contains(warWebappsFolder)
||nodes.item(2).getAttributes().getNamedItem("sourceOnDisk").getNodeValue().contains(warWebappsFolder));

expression = "/archive/archive/archive";
nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET);
Expand Down

0 comments on commit 7d31b7a

Please sign in to comment.