1   /**
2    * 
3    */
4   package org.apache.maven.project;
5   
6   import java.io.File;
7   import java.io.FileNotFoundException;
8   import java.util.Collections;
9   
10  import org.apache.maven.artifact.Artifact;
11  import org.apache.maven.artifact.repository.ArtifactRepository;
12  import org.codehaus.plexus.component.annotations.Component;
13  
14  @Component(role=ProjectBuilder.class,hint="classpath")
15  public class TestProjectBuilder
16      extends DefaultProjectBuilder
17  {    
18      
19      @Override
20      public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request )
21          throws ProjectBuildingException
22      {                       
23          if ( "maven-test".equals( artifact.getGroupId() ) )
24          {
25              String scope = artifact.getArtifactId().substring( "scope-".length() );
26              
27              try
28              {
29                  artifact.setFile( ProjectClasspathTest.getFileForClasspathResource( ProjectClasspathTest.dir + "transitive-" + scope + "-dep.xml" ) );
30              }
31              catch ( FileNotFoundException e )
32              {
33                  throw new IllegalStateException( "Missing test POM for " + artifact );
34              }
35          }
36          if ( artifact.getFile() == null )
37          {
38              MavenProject project = new MavenProject();
39              project.setArtifact( artifact );
40              return new DefaultProjectBuildingResult( project, null, null );
41          }
42          return build( artifact.getFile(), request );
43      }
44  
45      @Override
46      public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest configuration )
47          throws ProjectBuildingException
48      {
49          ProjectBuildingResult result = super.build( pomFile, configuration );
50  
51          result.getProject().setRemoteArtifactRepositories( Collections.<ArtifactRepository> emptyList() );
52  
53          return result;
54      }
55  
56  }