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.io.FileReader;
24  import java.util.ArrayList;
25  import java.util.Collections;
26  import java.util.List;
27  import java.util.Set;
28  
29  import org.apache.maven.artifact.Artifact;
30  import org.apache.maven.artifact.DefaultArtifact;
31  import org.apache.maven.artifact.factory.ArtifactFactory;
32  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
33  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
34  import org.apache.maven.artifact.versioning.VersionRange;
35  import org.apache.maven.model.Build;
36  import org.apache.maven.model.Model;
37  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
38  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
39  import org.apache.maven.project.MavenProject;
40  import org.apache.maven.project.artifact.InvalidDependencyVersionException;
41  
42  /**
43   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
44   */
45  public class TestJavadocMavenProjectStub
46      extends MavenProjectStub
47  {
48      private Build build;
49  
50      public TestJavadocMavenProjectStub()
51      {
52          MavenXpp3Reader pomReader = new MavenXpp3Reader();
53          Model model = null;
54  
55          try
56          {
57              model = pomReader.read( new FileReader( new File( getBasedir(), "test-javadoc-test-plugin-config.xml" ) ) );
58              setModel( model );
59          }
60          catch ( Exception e )
61          {
62              throw new RuntimeException( e );
63          }
64  
65          setGroupId( model.getGroupId() );
66          setArtifactId( model.getArtifactId() );
67          setVersion( model.getVersion() );
68          setName( model.getName() );
69          setUrl( model.getUrl() );
70          setPackaging( model.getPackaging() );
71  
72          Artifact junit = new DefaultArtifact( "junit", "junit", VersionRange.createFromVersion( "3.8.1" ),
73                                                Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler( "jar" ),
74                                                false );
75          junit.setFile( new File( getBasedir() + "/junit/junit/3.8.1/junit-3.8.1.jar" ) );
76          setTestArtifacts( Collections.singletonList( junit ) );
77  
78          Build build = new Build();
79          build.setFinalName( model.getArtifactId() );
80          build.setDirectory( super.getBasedir() + "/target/test/unit/test-javadoc-test/target" );
81          build.setSourceDirectory( getBasedir() + "/src/main/java" );
82          build.setOutputDirectory( super.getBasedir() + "/target/test/unit/test-javadoc-test/target/classes" );
83          build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
84          build.setTestOutputDirectory( super.getBasedir() + "/target/test/unit/test-javadoc-test/target/test-classes" );
85          setBuild( build );
86  
87          List compileSourceRoots = new ArrayList();
88          compileSourceRoots.add( getBasedir() + "/src/main/java" );
89          setCompileSourceRoots( compileSourceRoots );
90  
91          List testCompileSourceRoots = new ArrayList();
92          testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
93          setTestCompileSourceRoots( testCompileSourceRoots );
94      }
95  
96      /**
97       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBuild()
98       */
99      public Build getBuild()
100     {
101         return build;
102     }
103 
104     /**
105      * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#setBuild(org.apache.maven.model.Build)
106      */
107     public void setBuild( Build build )
108     {
109         this.build = build;
110     }
111 
112     /**
113      * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBasedir()
114      */
115     public File getBasedir()
116     {
117         return new File( super.getBasedir() + "/src/test/resources/unit/test-javadoc-test" );
118     }
119 
120     /**
121      * @see org.apache.maven.project.MavenProject#createArtifacts(org.apache.maven.artifact.factory.ArtifactFactory,
122      *      java.lang.String, org.apache.maven.artifact.resolver.filter.ArtifactFilter)
123      */
124     public Set createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter )
125         throws InvalidDependencyVersionException
126     {
127         return Collections.EMPTY_SET;
128     }
129 
130     /**
131      * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getExecutionProject()
132      */
133     public MavenProject getExecutionProject()
134     {
135         return this;
136     }
137 }