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  
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.artifact.repository.DefaultArtifactRepository;
30  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
31  import org.apache.maven.model.Build;
32  import org.apache.maven.model.Model;
33  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
34  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
35  
36  /**
37   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
38   * @version $Id: TagletArtifactsMavenProjectStub.html 829389 2012-08-19 17:23:07Z hboutemy $
39   */
40  public class TagletArtifactsMavenProjectStub
41      extends MavenProjectStub
42  {
43      private Build build;
44  
45      /**
46       * Default constructor.
47       */
48      public TagletArtifactsMavenProjectStub()
49      {
50          MavenXpp3Reader pomReader = new MavenXpp3Reader();
51          Model model = null;
52  
53          try
54          {
55              model =
56                  pomReader.read( new FileReader( new File( getBasedir(), "tagletArtifacts-test-plugin-config.xml" ) ) );
57              setModel( model );
58          }
59          catch ( Exception e )
60          {
61              throw new RuntimeException( e );
62          }
63  
64          setGroupId( model.getGroupId() );
65          setArtifactId( model.getArtifactId() );
66          setVersion( model.getVersion() );
67          setName( model.getName() );
68          setUrl( model.getUrl() );
69          setPackaging( model.getPackaging() );
70  
71          Build build = new Build();
72          build.setFinalName( model.getArtifactId() );
73          build.setSourceDirectory( getBasedir() + "/src/main/java" );
74          build.setDirectory( super.getBasedir() + "/target/test/unit/tagletArtifacts-test/target" );
75          setBuild( build );
76  
77          List compileSourceRoots = new ArrayList();
78          compileSourceRoots.add( getBasedir() + "/src/main/java" );
79          setCompileSourceRoots( compileSourceRoots );
80      }
81  
82      /** {@inheritDoc} */
83      public Build getBuild()
84      {
85          return build;
86      }
87  
88      /** {@inheritDoc} */
89      public void setBuild( Build build )
90      {
91          this.build = build;
92      }
93  
94      /** {@inheritDoc} */
95      public List getRemoteArtifactRepositories()
96      {
97          ArtifactRepository repository =
98              new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
99                                             new DefaultRepositoryLayout() );
100 
101         return Collections.singletonList( repository );
102     }
103 
104     /**
105      * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBasedir()
106      */
107     public File getBasedir()
108     {
109         return new File( super.getBasedir() + "/src/test/resources/unit/tagletArtifacts-test" );
110     }
111 }