Skip to content

Commit

Permalink
add boost:package to dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
awisniew90 committed Sep 3, 2019
1 parent c490e9f commit 499c759
Showing 1 changed file with 114 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -283,62 +292,70 @@ public boolean recompileBuildFile(File buildFile, List<String> artifactPaths, Th

if (!allDifferences.isEmpty()) {
log.info("Pom has been modified");
MavenProject updatedProject = loadProject(buildFile);
List<Dependency> dependencies = updatedProject.getDependencies();
log.debug("Dependencies size: " + dependencies.size());
log.debug("Existing dependencies size: " + this.existingDependencies.size());

List<String> dependencyIds = new ArrayList<String>();
List<Artifact> 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<String> addToClassPath = new ArrayList<String>();
DependencyRequest depRequest = new DependencyRequest(collectRequest, null);
try {
DependencyResult dependencyResult = repositorySystem.resolveDependencies(repoSession,
depRequest);
org.eclipse.aether.graph.DependencyNode root = dependencyResult.getRoot();
List<File> artifactsList = new ArrayList<File>();
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<Dependency> dependencies = updatedProject.getDependencies();
log.debug("Dependencies size: " + dependencies.size());
log.debug("Existing dependencies size: " + this.existingDependencies.size());

List<String> dependencyIds = new ArrayList<String>();
List<Artifact> 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<String> addToClassPath = new ArrayList<String>();
DependencyRequest depRequest = new DependencyRequest(collectRequest, null);
try {
DependencyResult dependencyResult = repositorySystem.resolveDependencies(repoSession,
depRequest);
org.eclipse.aether.graph.DependencyNode root = dependencyResult.getRoot();
List<File> artifactsList = new ArrayList<File>();
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.");
}
}
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<File> resourceDirs = new ArrayList<File>();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 499c759

Please sign in to comment.