001package org.apache.maven.project;
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 java.io.File;
019import java.io.FileNotFoundException;
020import java.util.Collections;
021
022import org.apache.maven.artifact.Artifact;
023import org.apache.maven.artifact.repository.ArtifactRepository;
024import org.codehaus.plexus.component.annotations.Component;
025
026@Component(role=ProjectBuilder.class,hint="classpath")
027public class TestProjectBuilder
028    extends DefaultProjectBuilder
029{
030
031    @Override
032    public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request )
033        throws ProjectBuildingException
034    {
035        if ( "maven-test".equals( artifact.getGroupId() ) )
036        {
037            String scope = artifact.getArtifactId().substring( "scope-".length() );
038
039            try
040            {
041                artifact.setFile( ProjectClasspathTest.getFileForClasspathResource( ProjectClasspathTest.dir + "transitive-" + scope + "-dep.xml" ) );
042            }
043            catch ( FileNotFoundException e )
044            {
045                throw new IllegalStateException( "Missing test POM for " + artifact );
046            }
047        }
048        if ( artifact.getFile() == null )
049        {
050            MavenProject project = new MavenProject();
051            project.setArtifact( artifact );
052            return new DefaultProjectBuildingResult( project, null, null );
053        }
054        return build( artifact.getFile(), request );
055    }
056
057    @Override
058    public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest configuration )
059        throws ProjectBuildingException
060    {
061        ProjectBuildingResult result = super.build( pomFile, configuration );
062
063        result.getProject().setRemoteArtifactRepositories( Collections.<ArtifactRepository> emptyList() );
064
065        return result;
066    }
067
068}