1   package org.apache.maven.plugin.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 java.io.File;
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  import java.util.Set;
27  
28  import org.apache.maven.artifact.Artifact;
29  import org.apache.maven.artifact.DefaultArtifact;
30  import org.apache.maven.artifact.factory.ArtifactFactory;
31  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
32  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
33  import org.apache.maven.artifact.versioning.VersionRange;
34  import org.apache.maven.model.Build;
35  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
36  import org.apache.maven.project.MavenProject;
37  import org.apache.maven.project.artifact.InvalidDependencyVersionException;
38  
39  /**
40   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
41   * @version $Id: TestJavadocMavenProjectStub.html 829392 2012-08-19 17:29:37Z hboutemy $
42   */
43  public class TestJavadocMavenProjectStub
44      extends MavenProjectStub
45  {
46      private Build build;
47  
48      public TestJavadocMavenProjectStub()
49      {
50          readModel( new File( getBasedir(), "test-javadoc-test-plugin-config.xml" ) );
51  
52          setGroupId( getModel().getGroupId() );
53          setArtifactId( getModel().getArtifactId() );
54          setVersion( getModel().getVersion() );
55          setName( getModel().getName() );
56          setUrl( getModel().getUrl() );
57          setPackaging( getModel().getPackaging() );
58  
59          Artifact junit = new DefaultArtifact( "junit", "junit", VersionRange.createFromVersion( "3.8.1" ),
60                                                Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler( "jar" ),
61                                                false );
62          junit.setFile( new File( getBasedir() + "/junit/junit/3.8.1/junit-3.8.1.jar" ) );
63          setTestArtifacts( Collections.singletonList( junit ) );
64  
65          Build build = new Build();
66          build.setFinalName( getModel().getArtifactId() );
67          build.setDirectory( super.getBasedir() + "/target/test/unit/test-javadoc-test/target" );
68          build.setSourceDirectory( getBasedir() + "/src/main/java" );
69          build.setOutputDirectory( super.getBasedir() + "/target/test/unit/test-javadoc-test/target/classes" );
70          build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
71          build.setTestOutputDirectory( super.getBasedir() + "/target/test/unit/test-javadoc-test/target/test-classes" );
72          setBuild( build );
73  
74          List compileSourceRoots = new ArrayList();
75          compileSourceRoots.add( getBasedir() + "/src/main/java" );
76          setCompileSourceRoots( compileSourceRoots );
77  
78          List testCompileSourceRoots = new ArrayList();
79          testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
80          setTestCompileSourceRoots( testCompileSourceRoots );
81      }
82  
83      /** {@inheritDoc} */
84      public Build getBuild()
85      {
86          return build;
87      }
88  
89      /** {@inheritDoc} */
90      public void setBuild( Build build )
91      {
92          this.build = build;
93      }
94  
95      /** {@inheritDoc} */
96      public File getBasedir()
97      {
98          return new File( super.getBasedir() + "/src/test/resources/unit/test-javadoc-test" );
99      }
100 
101     /** {@inheritDoc} */
102     public Set createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter )
103         throws InvalidDependencyVersionException
104     {
105         return Collections.EMPTY_SET;
106     }
107 
108     /** {@inheritDoc} */
109     public MavenProject getExecutionProject()
110     {
111         return this;
112     }
113 }