1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.lifecycle.internal;
20
21 import java.util.List;
22
23 import org.apache.maven.execution.MavenSession;
24 import org.apache.maven.execution.ProjectDependencyGraph;
25 import org.apache.maven.lifecycle.LifecycleNotFoundException;
26 import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
27 import org.apache.maven.lifecycle.internal.builder.multithreaded.ConcurrencyDependencyGraph;
28 import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
29 import org.apache.maven.plugin.InvalidPluginDescriptorException;
30 import org.apache.maven.plugin.MojoNotFoundException;
31 import org.apache.maven.plugin.PluginDescriptorParsingException;
32 import org.apache.maven.plugin.PluginNotFoundException;
33 import org.apache.maven.plugin.PluginResolutionException;
34 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
35 import org.apache.maven.plugin.version.PluginVersionResolutionException;
36 import org.apache.maven.project.MavenProject;
37
38 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.*;
39
40
41
42
43 public class ConcurrencyDependencyGraphTest extends junit.framework.TestCase {
44 public void testConcurrencyGraphPrimaryVersion()
45 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
46 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException,
47 PluginResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException {
48 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
49 final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
50
51 ConcurrencyDependencyGraph graph =
52 new ConcurrencyDependencyGraph(getProjectBuildList(session), dependencyGraph);
53
54 final List<MavenProject> projectBuilds = graph.getRootSchedulableBuilds();
55 assertEquals(1, projectBuilds.size());
56 assertEquals(A, projectBuilds.iterator().next());
57
58 final List<MavenProject> subsequent = graph.markAsFinished(A);
59 assertEquals(2, subsequent.size());
60 assertEquals(ProjectDependencyGraphStub.B, subsequent.get(0));
61 assertEquals(C, subsequent.get(1));
62
63 final List<MavenProject> bDescendants = graph.markAsFinished(B);
64 assertEquals(1, bDescendants.size());
65 assertEquals(Y, bDescendants.get(0));
66
67 final List<MavenProject> cDescendants = graph.markAsFinished(C);
68 assertEquals(2, cDescendants.size());
69 assertEquals(X, cDescendants.get(0));
70 assertEquals(Z, cDescendants.get(1));
71 }
72
73 public void testConcurrencyGraphDifferentCompletionOrder()
74 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
75 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException,
76 PluginResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException {
77 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
78 final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
79 ConcurrencyDependencyGraph graph =
80 new ConcurrencyDependencyGraph(getProjectBuildList(session), dependencyGraph);
81
82 graph.markAsFinished(A);
83 final List<MavenProject> cDescendants = graph.markAsFinished(C);
84 assertEquals(1, cDescendants.size());
85 assertEquals(Z, cDescendants.get(0));
86
87 final List<MavenProject> bDescendants = graph.markAsFinished(B);
88 assertEquals(2, bDescendants.size());
89 assertEquals(X, bDescendants.get(0));
90 assertEquals(Y, bDescendants.get(1));
91 }
92 }