001    /**
002     * 
003     */
004    package org.apache.maven.project;
005    
006    import java.io.File;
007    import java.io.FileNotFoundException;
008    import java.util.Collections;
009    
010    import org.apache.maven.artifact.Artifact;
011    import org.apache.maven.artifact.repository.ArtifactRepository;
012    import org.codehaus.plexus.component.annotations.Component;
013    
014    @Component(role=ProjectBuilder.class,hint="classpath")
015    public class TestProjectBuilder
016        extends DefaultProjectBuilder
017    {    
018        
019        @Override
020        public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request )
021            throws ProjectBuildingException
022        {                       
023            if ( "maven-test".equals( artifact.getGroupId() ) )
024            {
025                String scope = artifact.getArtifactId().substring( "scope-".length() );
026                
027                try
028                {
029                    artifact.setFile( ProjectClasspathTest.getFileForClasspathResource( ProjectClasspathTest.dir + "transitive-" + scope + "-dep.xml" ) );
030                }
031                catch ( FileNotFoundException e )
032                {
033                    throw new IllegalStateException( "Missing test POM for " + artifact );
034                }
035            }
036            if ( artifact.getFile() == null )
037            {
038                MavenProject project = new MavenProject();
039                project.setArtifact( artifact );
040                return new DefaultProjectBuildingResult( project, null, null );
041            }
042            return build( artifact.getFile(), request );
043        }
044    
045        @Override
046        public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest configuration )
047            throws ProjectBuildingException
048        {
049            ProjectBuildingResult result = super.build( pomFile, configuration );
050    
051            result.getProject().setRemoteArtifactRepositories( Collections.<ArtifactRepository> emptyList() );
052    
053            return result;
054        }
055    
056    }