View Javadoc
1   package org.apache.maven.lifecycle.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
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   * @author Kristian Rosenvold
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  }