View Javadoc
1   package org.apache.maven.project;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  
18  import java.io.File;
19  import java.io.FileNotFoundException;
20  import java.util.Collections;
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.repository.ArtifactRepository;
24  import org.codehaus.plexus.component.annotations.Component;
25  
26  @Component(role=ProjectBuilder.class,hint="classpath")
27  public class TestProjectBuilder
28      extends DefaultProjectBuilder
29  {
30  
31      @Override
32      public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request )
33          throws ProjectBuildingException
34      {
35          if ( "maven-test".equals( artifact.getGroupId() ) )
36          {
37              String scope = artifact.getArtifactId().substring( "scope-".length() );
38  
39              try
40              {
41                  artifact.setFile( ProjectClasspathTest.getFileForClasspathResource( ProjectClasspathTest.dir + "transitive-" + scope + "-dep.xml" ) );
42              }
43              catch ( FileNotFoundException e )
44              {
45                  throw new IllegalStateException( "Missing test POM for " + artifact );
46              }
47          }
48          if ( artifact.getFile() == null )
49          {
50              MavenProject project = new MavenProject();
51              project.setArtifact( artifact );
52              return new DefaultProjectBuildingResult( project, null, null );
53          }
54          return build( artifact.getFile(), request );
55      }
56  
57      @Override
58      public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest configuration )
59          throws ProjectBuildingException
60      {
61          ProjectBuildingResult result = super.build( pomFile, configuration );
62  
63          result.getProject().setRemoteArtifactRepositories( Collections.<ArtifactRepository> emptyList() );
64  
65          return result;
66      }
67  
68  }