View Javadoc
1   package org.apache.maven.plugins.javadoc.stubs;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.mockito.Mockito.mock;
23  import static org.mockito.Mockito.when;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.model.Build;
27  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
28  
29  import java.io.File;
30  import java.util.ArrayList;
31  import java.util.HashSet;
32  import java.util.List;
33  import java.util.Set;
34  
35  /**
36   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
37   * @version $Id: ProxyTestMavenProjectStub.java 1747937 2016-06-11 21:26:59Z rfscholte $
38   */
39  public class ProxyTestMavenProjectStub
40      extends MavenProjectStub
41  {
42      private Set<Artifact> dependencyArtifacts = new HashSet<>();
43  
44      public ProxyTestMavenProjectStub()
45      {
46          readModel( new File( getBasedir(), "proxy-test-plugin-config.xml" ) );
47  
48          setGroupId( getModel().getGroupId() );
49          setArtifactId( getModel().getArtifactId() );
50          setVersion( getModel().getVersion() );
51          setName( getModel().getName() );
52          setUrl( getModel().getUrl() );
53          setPackaging( getModel().getPackaging() );
54  
55          Build build = new Build();
56          build.setFinalName( getModel().getArtifactId() );
57          build.setSourceDirectory( getBasedir() + "/src/main/java" );
58          build.setDirectory( super.getBasedir() + "/target/test/unit/proxy-test/target" );
59          setBuild( build );
60  
61          List<String> compileSourceRoots = new ArrayList<>();
62          compileSourceRoots.add( getBasedir() + "/src/main/java" );
63          setCompileSourceRoots( compileSourceRoots );
64  
65          
66          Artifact artifact = mock( Artifact.class );
67          when( artifact.getGroupId()).thenReturn( "commons-logging" );
68          when( artifact.getArtifactId()).thenReturn( "commons-logging" );
69          when( artifact.getVersion()).thenReturn( "1.1.1" );
70          when( artifact.getScope()).thenReturn( Artifact.SCOPE_RUNTIME );
71          when( artifact.getType()).thenReturn( "jar" );
72          when( artifact.getFile()).thenReturn( getBasedir() );
73          DefaultArtifactHandlerStub artifactHandler = new DefaultArtifactHandlerStub();
74          artifactHandler.setExtension( "jar" );
75          when( artifact.getArtifactHandler()).thenReturn( artifactHandler );
76  
77          dependencyArtifacts.add( artifact );
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public File getBasedir()
83      {
84          return new File( super.getBasedir() + "/src/test/resources/unit/proxy-test" );
85      }
86  
87      @Override
88      public Set<Artifact> getDependencyArtifacts()
89      {
90          return dependencyArtifacts;
91      }
92  }