diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 6cd7b9760..04afdd6e2 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit; import org.apache.maven.artifact.Artifact; +import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; @@ -52,6 +53,9 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.ProjectBuildingResult; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.custommonkey.xmlunit.DetailedDiff; @@ -108,9 +112,14 @@ public class DevMojo extends StartDebugMojoSupport { private int runId = 0; private ServerTask serverTask = null; + + private boolean usingBoost = false; @Component private BuildPluginManager pluginManager; + + @Component + protected ProjectBuilder mavenProjectBuilder; /** * Time in seconds to wait while verifying that the server has started. @@ -283,62 +292,70 @@ public boolean recompileBuildFile(File buildFile, List artifactPaths, Th if (!allDifferences.isEmpty()) { log.info("Pom has been modified"); - MavenProject updatedProject = loadProject(buildFile); - List dependencies = updatedProject.getDependencies(); - log.debug("Dependencies size: " + dependencies.size()); - log.debug("Existing dependencies size: " + this.existingDependencies.size()); - - List dependencyIds = new ArrayList(); - List updatedArtifacts = getNewDependencies(dependencies, this.existingDependencies); - - if (!updatedArtifacts.isEmpty()) { - for (Artifact artifact : updatedArtifacts) { - if (("esa").equals(artifact.getType())) { - dependencyIds.add(artifact.getArtifactId()); - } - - org.eclipse.aether.artifact.Artifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact( - artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), - artifact.getVersion()); - org.eclipse.aether.graph.Dependency dependency = new org.eclipse.aether.graph.Dependency( - aetherArtifact, null, true); - - CollectRequest collectRequest = new CollectRequest(); - collectRequest.setRoot(dependency); - collectRequest.setRepositories(repositories); - - List addToClassPath = new ArrayList(); - DependencyRequest depRequest = new DependencyRequest(collectRequest, null); - try { - DependencyResult dependencyResult = repositorySystem.resolveDependencies(repoSession, - depRequest); - org.eclipse.aether.graph.DependencyNode root = dependencyResult.getRoot(); - List artifactsList = new ArrayList(); - addArtifacts(root, artifactsList); - for (File a : artifactsList) { - log.debug("Artifact: " + a); - if (a.getCanonicalPath().endsWith(".jar")) { - addToClassPath.add(a.getCanonicalPath()); - } - } - } catch (DependencyResolutionException e) { - throw new MojoExecutionException(e.getMessage(), e); - } - artifactPaths.addAll(addToClassPath); - } - - if (!dependencyIds.isEmpty()) { - runLibertyMavenPlugin("install-feature", serverName, dependencyIds); - dependencyIds.clear(); - } - - // update dependencies - this.existingDependencies = dependencies; - this.existingPom = modifiedPom; - - return true; + if (usingBoost) { + log.info("Running boost:package"); + runBoostMojo("package", true); + this.existingPom = modifiedPom; + return true; } else { - log.info("Unhandled change detected in pom.xml. Restart liberty:dev mode for it to take effect."); + MavenProject updatedProject = loadProject(buildFile); + List dependencies = updatedProject.getDependencies(); + log.debug("Dependencies size: " + dependencies.size()); + log.debug("Existing dependencies size: " + this.existingDependencies.size()); + + List dependencyIds = new ArrayList(); + List updatedArtifacts = getNewDependencies(dependencies, this.existingDependencies); + + if (!updatedArtifacts.isEmpty()) { + + for (Artifact artifact : updatedArtifacts) { + if (("esa").equals(artifact.getType())) { + dependencyIds.add(artifact.getArtifactId()); + } + + org.eclipse.aether.artifact.Artifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact( + artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), + artifact.getVersion()); + org.eclipse.aether.graph.Dependency dependency = new org.eclipse.aether.graph.Dependency( + aetherArtifact, null, true); + + CollectRequest collectRequest = new CollectRequest(); + collectRequest.setRoot(dependency); + collectRequest.setRepositories(repositories); + + List addToClassPath = new ArrayList(); + DependencyRequest depRequest = new DependencyRequest(collectRequest, null); + try { + DependencyResult dependencyResult = repositorySystem.resolveDependencies(repoSession, + depRequest); + org.eclipse.aether.graph.DependencyNode root = dependencyResult.getRoot(); + List artifactsList = new ArrayList(); + addArtifacts(root, artifactsList); + for (File a : artifactsList) { + log.debug("Artifact: " + a); + if (a.getCanonicalPath().endsWith(".jar")) { + addToClassPath.add(a.getCanonicalPath()); + } + } + } catch (DependencyResolutionException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + artifactPaths.addAll(addToClassPath); + } + + if (!dependencyIds.isEmpty()) { + runLibertyMavenPlugin("install-feature", serverName, dependencyIds); + dependencyIds.clear(); + } + + // update dependencies + this.existingDependencies = dependencies; + this.existingPom = modifiedPom; + + return true; + } else { + log.info("Unhandled change detected in pom.xml. Restart liberty:dev mode for it to take effect."); + } } } @@ -432,6 +449,12 @@ protected void doExecute() throws Exception { skipUTs = true; } + // Check if this is a Boost application + Plugin boostPlugin = project.getPlugin("boost:boost-maven-plugin"); + if (boostPlugin != null) { + usingBoost = true; + } + // look for a .sRunning file to check if the server has already started if (serverDirectory.exists()) { File sRunning = new File(serverDirectory.getCanonicalPath() + "/workarea/.sRunning"); @@ -467,12 +490,17 @@ protected void doExecute() throws Exception { log.debug("Test Source directory: " + testSourceDirectory); log.debug("Test Output directory: " + testOutputDirectory); - log.info("Running goal: create"); - runLibertyMavenPlugin("create", serverName, null); - log.info("Running goal: install-feature"); - runLibertyMavenPlugin("install-feature", serverName, null); - log.info("Running goal: install-apps"); - runLibertyMavenPlugin("install-apps", serverName, null); + if (usingBoost) { + log.info("Running boost:package"); + runBoostMojo("package", false); + } else { + log.info("Running goal: create"); + runLibertyMavenPlugin("create", serverName, null); + log.info("Running goal: install-feature"); + runLibertyMavenPlugin("install-feature", serverName, null); + log.info("Running goal: install-apps"); + runLibertyMavenPlugin("install-apps", serverName, null); + } // resource directories List resourceDirs = new ArrayList(); @@ -779,6 +807,31 @@ private void runMojo(String groupId, String artifactId, String defaultVersion, S configuration(getPluginConfigurationElements(goal, serverName, dependencies)), executionEnvironment(project, session, pluginManager)); } + + private void runBoostMojo(String goal, boolean rebuildProject) + throws MojoExecutionException, ProjectBuildingException { + + Plugin boostPlugin = project.getPlugin(Plugin.constructKey("boost", "boost-maven-plugin")); + + MavenProject boostProject = this.project; + MavenSession boostSession = this.session; + + if (rebuildProject) { + // Reload pom + File pomFile = new File(project.getFile().getAbsolutePath()); + ProjectBuildingResult build = mavenProjectBuilder.build(pomFile, session.getProjectBuildingRequest().setResolveDependencies(true)); + boostProject = build.getProject(); + boostSession.setCurrentProject(boostProject); + } + + log.debug("plugin version: " + boostPlugin.getVersion()); + executeMojo(boostPlugin, goal(goal), + configuration(), + executionEnvironment(boostProject, boostSession, pluginManager)); + + + } + private static MavenProject loadProject(File pomFile) throws IOException, XmlPullParserException { MavenProject ret = null;