1 package org.apache.maven.project.inheritance.t02; 2 3 18 19 import java.io.File ; 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.apache.maven.model.Build; 27 import org.apache.maven.model.MailingList; 28 import org.apache.maven.model.Plugin; 29 import org.apache.maven.project.MavenProject; 30 import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; 31 32 44 public class ProjectInheritanceTest 45 extends AbstractProjectInheritanceTestCase 46 { 47 61 public void testProjectInheritance() 62 throws Exception 63 { 64 File localRepo = getLocalRepositoryPath(); 65 66 System.out.println( "Local repository is at: " + localRepo.getAbsolutePath() ); 67 68 File pom0 = new File ( localRepo, "p0/pom.xml" ); 69 File pom1 = new File ( pom0.getParentFile(), "p1/pom.xml" ); 70 File pom2 = new File ( pom1.getParentFile(), "p2/pom.xml" ); 71 File pom3 = new File ( pom2.getParentFile(), "p3/pom.xml" ); 72 File pom4 = new File ( pom3.getParentFile(), "p4/pom.xml" ); 73 File pom5 = new File ( pom4.getParentFile(), "p5/pom.xml" ); 74 75 System.out.println( "Location of project-4's POM: " + pom4.getPath() ); 76 77 MavenProject project0 = getProject( pom0 ); 79 MavenProject project1 = getProject( pom1 ); 80 MavenProject project2 = getProject( pom2 ); 81 MavenProject project3 = getProject( pom3 ); 82 MavenProject project4 = getProject( pom4 ); 83 MavenProject project5 = getProject( pom5 ); 84 85 assertEquals( "p4", project4.getName() ); 86 87 91 assertEquals( "2000", project4.getInceptionYear() ); 92 93 97 assertEquals( "mailing-list", ( (MailingList) project4.getMailingLists().get( 0 ) ).getName() ); 98 99 103 assertEquals( "scm-url/p2/p3/p4", project4.getScm().getUrl() ); 104 105 109 assertEquals( "Codehaus", project4.getOrganization().getName() ); 110 111 115 assertEquals( "4.0.0", project4.getModelVersion() ); 116 117 Build build = project4.getBuild(); 118 List plugins = build.getPlugins(); 119 120 Map validPluginCounts = new HashMap (); 121 122 String testPluginArtifactId = "maven-compiler-plugin"; 123 124 validPluginCounts.put( testPluginArtifactId, new Integer ( 0 ) ); 126 127 validPluginCounts.put( "maven-deploy-plugin", new Integer ( 0 ) ); 129 validPluginCounts.put( "maven-javadoc-plugin", new Integer ( 0 ) ); 130 validPluginCounts.put( "maven-source-plugin", new Integer ( 0 ) ); 131 132 Plugin testPlugin = null; 133 134 for ( Iterator it = plugins.iterator(); it.hasNext(); ) 135 { 136 Plugin plugin = (Plugin) it.next(); 137 138 String pluginArtifactId = plugin.getArtifactId(); 139 140 if ( !validPluginCounts.containsKey( pluginArtifactId ) ) 141 { 142 fail( "Illegal plugin found: " + pluginArtifactId ); 143 } 144 else 145 { 146 if ( pluginArtifactId.equals( testPluginArtifactId ) ) 147 { 148 testPlugin = plugin; 149 } 150 151 Integer count = (Integer ) validPluginCounts.get( pluginArtifactId ); 152 153 if ( count.intValue() > 0 ) 154 { 155 fail( "Multiple copies of plugin: " + pluginArtifactId + " found in POM." ); 156 } 157 else 158 { 159 count = new Integer ( count.intValue() + 1 ); 160 161 validPluginCounts.put( pluginArtifactId, count ); 162 } 163 } 164 } 165 166 List executions = testPlugin.getExecutions(); 167 168 assertEquals( 1, executions.size() ); 169 } 170 } 171 | Popular Tags |