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