diff options
author | freva <valerijf@yahoo-inc.com> | 2017-02-07 15:24:22 +0100 |
---|---|---|
committer | freva <valerijf@yahoo-inc.com> | 2017-02-07 15:24:22 +0100 |
commit | 8cd43ecbf44111e9694d65286e09c2b7d9d72ebb (patch) | |
tree | ffc8edfaba4685223c313d71904702049dedc18b /docker-api | |
parent | 8d1bf01f6bba9d20a808c746bbcfc11cba846274 (diff) |
Build dependencies of module for local systemtest
Diffstat (limited to 'docker-api')
-rw-r--r-- | docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java | 85 |
1 files changed, 80 insertions, 5 deletions
diff --git a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java index 51928b232a5..46a1ab259ad 100644 --- a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java +++ b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java @@ -5,6 +5,8 @@ import com.github.dockerjava.api.command.ExecCreateCmdResponse; import com.github.dockerjava.api.command.ExecStartCmd; import com.github.dockerjava.api.command.InspectExecResponse; import com.github.dockerjava.core.command.ExecStartResultCallback; +import com.yahoo.collections.Pair; +import com.yahoo.system.ProcessExecuter; import java.io.IOException; import java.net.InetAddress; @@ -12,11 +14,20 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; @@ -107,21 +118,31 @@ public class RunSystemTests { startSystemTestNodeIfNeeded(containerName); for (String module : modules) { - Path pathToModule = pathToVespaRepoInContainer.resolve(module); Path pathToTargetInHost = pathToVespaRepoInHost.resolve(module).resolve("target"); Path pathToTargetBackupInHost = pathToVespaRepoInHost.resolve(module).resolve("target_bcp"); if (Files.exists(pathToTargetInHost)) { Files.move(pathToTargetInHost, pathToTargetBackupInHost, StandardCopyOption.REPLACE_EXISTING); } + } - try { - executeInContainer(containerName, "mvn", "-DskipTests", "-Dmaven.javadoc.skip=true", "-e", - "-f=" + pathToModule.resolve("pom.xml"), "install"); + try { + String projects = Arrays.stream(modules) + .collect(Collectors.joining(",")); + executeInContainer(containerName, + "/bin/sh", "-c", "cd /vespa; mvn -DskipTests -Dmaven.javadoc.skip=true -e " + + "-pl=" + projects + " install"); + for (String module : modules) { + Path pathToModule = pathToVespaRepoInContainer.resolve(module); executeInContainer(containerName, "rsync", "--archive", "--existing", "--update", pathToModule.resolve("target").toString() + "/", pathToLibJars.toString() + "/"); - } finally { + } + } finally { + for (String module : modules) { + Path pathToModule = pathToVespaRepoInContainer.resolve(module); + Path pathToTargetInHost = pathToVespaRepoInHost.resolve(module).resolve("target"); + Path pathToTargetBackupInHost = pathToVespaRepoInHost.resolve(module).resolve("target_bcp"); executeInContainer(containerName, "rm", "-rf", pathToModule.resolve("target").toString()); if (Files.exists(pathToTargetBackupInHost)) { @@ -131,6 +152,60 @@ public class RunSystemTests { } } + /** + * Builds all modules that depend on 'modules' and 'modules' themselves in the order they need to be built + */ + void mavenInstallModulesThatDependOn(ContainerName containerName, String... modules) throws IOException, ExecutionException, InterruptedException { + logger.info("Building dependency graph..."); + Path outputFile = Paths.get("/tmp/vespa-maven-dependencies"); + if (Files.exists(outputFile)) { + Files.delete(outputFile); + } + + String[] command = new String[]{"mvn", "dependency:tree", "-Dincludes=com.yahoo.vespa", + "-DoutputFile=" + outputFile, "-DoutputType=dot", "-DappendOutput=true"}; + ProcessExecuter processExecuter = new ProcessExecuter(); + Pair<Integer, String> result = processExecuter.exec(command); + if (result.getFirst() != 0) { + throw new RuntimeException("Failed to get maven dependency tree: " + result.getSecond()); + } + + String modulePattern = "[a-z-]+"; + Pattern dependencyPattern = Pattern.compile("com\\.yahoo\\.vespa:(" + modulePattern + "):.* -> " + + ".*com\\.yahoo\\.vespa:(" + modulePattern + "):.*", Pattern.CASE_INSENSITIVE); + String dependenciesRaw = new String(Files.readAllBytes(outputFile)); + Matcher m = dependencyPattern.matcher(dependenciesRaw); + + Map<String, Set<String>> dependencyGraph = new HashMap<>(); + while (m.find()) { + if (! dependencyGraph.containsKey(m.group(2))) { + dependencyGraph.put(m.group(2), new HashSet<>()); + } + + dependencyGraph.get(m.group(2)).add(m.group(1)); + } + + List<String> buildOrder = new ArrayList<>(); + for (String module: modules) { + dfs(module, dependencyGraph, buildOrder); + } + + Collections.reverse(buildOrder); + mavenInstallModules(containerName, buildOrder.stream().toArray(String[]::new)); + } + + private static void dfs(String root, Map<String, Set<String>> dependencies, List<String> order) { + if (! order.contains(root)) { + if (dependencies.containsKey(root)) { + for (String child : dependencies.get(root)) { + dfs(child, dependencies, order); + } + } + + order.add(root); + } + } + private void startSystemTestNodeIfNeeded(ContainerName containerName) throws IOException, InterruptedException, ExecutionException { logger.info("Building " + SYSTEMTESTS_DOCKER_IMAGE.asString()); buildVespaSystestDockerImage(docker, vespaBaseImage); |