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 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.handler.DefaultArtifactHandler;
31  import org.apache.maven.artifact.versioning.VersionRange;
32  import org.apache.maven.model.Build;
33  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
34  import org.apache.maven.project.MavenProject;
35  
36  /**
37   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
38   */
39  public class TestJavadocMavenProjectStub
40      extends MavenProjectStub
41  {
42      public TestJavadocMavenProjectStub()
43      {
44          readModel( new File( getBasedir(), "test-javadoc-test-plugin-config.xml" ) );
45  
46          setGroupId( getModel().getGroupId() );
47          setArtifactId( getModel().getArtifactId() );
48          setVersion( getModel().getVersion() );
49          setName( getModel().getName() );
50          setUrl( getModel().getUrl() );
51          setPackaging( getModel().getPackaging() );
52  
53          Build build = new Build();
54          build.setFinalName( getModel().getArtifactId() );
55          build.setDirectory( super.getBasedir() + "/target/test/unit/test-javadoc-test/target" );
56          build.setSourceDirectory( getBasedir() + "/src/main/java" );
57          build.setOutputDirectory( super.getBasedir() + "/target/test/unit/test-javadoc-test/target/classes" );
58          build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
59          build.setTestOutputDirectory( super.getBasedir() + "/target/test/unit/test-javadoc-test/target/test-classes" );
60          setBuild( build );
61  
62          List<String> compileSourceRoots = new ArrayList<>();
63          compileSourceRoots.add( getBasedir() + "/src/main/java" );
64          setCompileSourceRoots( compileSourceRoots );
65  
66          List<String> testCompileSourceRoots = new ArrayList<>();
67          testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
68          setTestCompileSourceRoots( testCompileSourceRoots );
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public File getBasedir()
74      {
75          return new File( super.getBasedir() + "/src/test/resources/unit/test-javadoc-test" );
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public MavenProject getExecutionProject()
81      {
82          return this;
83      }
84      
85      @Override
86      public Set<Artifact> getArtifacts()
87      {
88          Artifact junit = new DefaultArtifact( "junit", "junit", VersionRange.createFromVersion( "3.8.1" ),
89                                                Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler( "jar" ),
90                                                false );
91          junit.setFile( new File( getBasedir() + "/junit/junit/3.8.1/junit-3.8.1.jar" ) );
92          return Collections.singleton( junit );
93      }
94  }