1 package org.apache.maven.lifecycle.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import org.apache.maven.execution.MavenSession;
19 import org.apache.maven.execution.ProjectDependencyGraph;
20 import org.apache.maven.lifecycle.LifecycleNotFoundException;
21 import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
22 import org.apache.maven.lifecycle.internal.builder.multithreaded.ConcurrencyDependencyGraph;
23 import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
24 import org.apache.maven.plugin.InvalidPluginDescriptorException;
25 import org.apache.maven.plugin.MojoNotFoundException;
26 import org.apache.maven.plugin.PluginDescriptorParsingException;
27 import org.apache.maven.plugin.PluginNotFoundException;
28 import org.apache.maven.plugin.PluginResolutionException;
29 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
30 import org.apache.maven.plugin.version.PluginVersionResolutionException;
31 import org.apache.maven.project.MavenProject;
32
33 import java.util.List;
34
35 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.*;
36
37
38
39
40 public class ConcurrencyDependencyGraphTest
41 extends junit.framework.TestCase
42 {
43 public void testConcurrencyGraphPrimaryVersion()
44 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
45 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
46 LifecyclePhaseNotFoundException, LifecycleNotFoundException
47 {
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.get( 0 ) );
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, PluginResolutionException,
76 LifecyclePhaseNotFoundException, LifecycleNotFoundException
77 {
78 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
79 final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
80 ConcurrencyDependencyGraph graph =
81 new ConcurrencyDependencyGraph( getProjectBuildList( session ), dependencyGraph );
82
83 graph.markAsFinished( A );
84 final List<MavenProject> cDescendants = graph.markAsFinished( C );
85 assertEquals( 1, cDescendants.size() );
86 assertEquals( Z, cDescendants.get( 0 ) );
87
88 final List<MavenProject> bDescendants = graph.markAsFinished( B );
89 assertEquals( 2, bDescendants.size() );
90 assertEquals( X, bDescendants.get( 0 ) );
91 assertEquals( Y, bDescendants.get( 1 ) );
92 }
93
94 }