001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 003 * agreements. See the NOTICE file distributed with this work for additional information regarding 004 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the 005 * "License"); you may not use this file except in compliance with the License. You may obtain a 006 * copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software distributed under the License 011 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing permissions and limitations under 013 * the License. 014 */ 015 package org.apache.maven.lifecycle.internal; 016 017 import org.apache.maven.execution.MavenSession; 018 import org.apache.maven.execution.ProjectDependencyGraph; 019 import org.apache.maven.lifecycle.LifecycleNotFoundException; 020 import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException; 021 import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; 022 import org.apache.maven.plugin.InvalidPluginDescriptorException; 023 import org.apache.maven.plugin.MojoNotFoundException; 024 import org.apache.maven.plugin.PluginDescriptorParsingException; 025 import org.apache.maven.plugin.PluginNotFoundException; 026 import org.apache.maven.plugin.PluginResolutionException; 027 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; 028 import org.apache.maven.plugin.version.PluginVersionResolutionException; 029 import org.apache.maven.project.MavenProject; 030 031 import java.util.List; 032 033 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.*; 034 035 /** 036 * @author Kristian Rosenvold 037 */ 038 public class ConcurrencyDependencyGraphTest 039 extends junit.framework.TestCase 040 { 041 public void testConcurrencyGraphPrimaryVersion() 042 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException, 043 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException, 044 LifecyclePhaseNotFoundException, LifecycleNotFoundException 045 { 046 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub(); 047 final MavenSession session = ProjectDependencyGraphStub.getMavenSession(); 048 049 ConcurrencyDependencyGraph graph = 050 new ConcurrencyDependencyGraph( getProjectBuildList( session ), dependencyGraph ); 051 052 final List<MavenProject> projectBuilds = graph.getRootSchedulableBuilds(); 053 assertEquals( 1, projectBuilds.size() ); 054 assertEquals( A, projectBuilds.get( 0 ) ); 055 056 final List<MavenProject> subsequent = graph.markAsFinished( A ); 057 assertEquals( 2, subsequent.size() ); 058 assertEquals( ProjectDependencyGraphStub.B, subsequent.get( 0 ) ); 059 assertEquals( C, subsequent.get( 1 ) ); 060 061 final List<MavenProject> bDescendants = graph.markAsFinished( B ); 062 assertEquals( 1, bDescendants.size() ); 063 assertEquals( Y, bDescendants.get( 0 ) ); 064 065 final List<MavenProject> cDescendants = graph.markAsFinished( C ); 066 assertEquals( 2, cDescendants.size() ); 067 assertEquals( X, cDescendants.get( 0 ) ); 068 assertEquals( Z, cDescendants.get( 1 ) ); 069 } 070 071 public void testConcurrencyGraphDifferentCompletionOrder() 072 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException, 073 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException, 074 LifecyclePhaseNotFoundException, LifecycleNotFoundException 075 { 076 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub(); 077 final MavenSession session = ProjectDependencyGraphStub.getMavenSession(); 078 ConcurrencyDependencyGraph graph = 079 new ConcurrencyDependencyGraph( getProjectBuildList( session ), dependencyGraph ); 080 081 graph.markAsFinished( A ); 082 final List<MavenProject> cDescendants = graph.markAsFinished( C ); 083 assertEquals( 1, cDescendants.size() ); 084 assertEquals( Z, cDescendants.get( 0 ) ); 085 086 final List<MavenProject> bDescendants = graph.markAsFinished( B ); 087 assertEquals( 2, bDescendants.size() ); 088 assertEquals( X, bDescendants.get( 0 ) ); 089 assertEquals( Y, bDescendants.get( 1 ) ); 090 } 091 092 }