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.factory.ArtifactFactory;
31  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
32  import org.apache.maven.model.Build;
33  import org.apache.maven.model.Model;
34  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
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   */
42  public class AggregateResourcesProject1TestMavenProjectStub
43      extends MavenProjectStub
44  {
45      private Build build;
46  
47      public AggregateResourcesProject1TestMavenProjectStub()
48      {
49          MavenXpp3Reader pomReader = new MavenXpp3Reader();
50          Model model = null;
51  
52          try
53          {
54              model = pomReader.read( new FileReader( new File( getBasedir(), "pom.xml" ) ) );
55              setModel( model );
56          }
57          catch ( Exception e )
58          {
59              throw new RuntimeException( e );
60          }
61  
62          setGroupId( model.getGroupId() );
63          setArtifactId( model.getArtifactId() );
64          setVersion( model.getVersion() );
65          setName( model.getName() );
66          setUrl( model.getUrl() );
67          setPackaging( model.getPackaging() );
68  
69          setExecutionRoot( true );
70  
71          Artifact artifact = new JavadocPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
72          artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
73          setArtifact( artifact );
74  
75          Build build = new Build();
76          build.setFinalName( model.getArtifactId() );
77          build.setSourceDirectory( getBasedir() + "/src/main/java" );
78          build.setDirectory( super.getBasedir() + "/target/test/unit/aggregate-resources-test/project1/target" );
79          setBuild( build );
80  
81          List compileSourceRoots = new ArrayList();
82          compileSourceRoots.add( getBasedir() + "/src/main/java" );
83          setCompileSourceRoots( compileSourceRoots );
84      }
85  
86      /**
87       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBuild()
88       */
89      public Build getBuild()
90      {
91          return build;
92      }
93  
94      /**
95       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#setBuild(org.apache.maven.model.Build)
96       */
97      public void setBuild( Build build )
98      {
99          this.build = build;
100     }
101 
102     /**
103      * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBasedir()
104      */
105     public File getBasedir()
106     {
107         return new File( super.getBasedir() + "/src/test/resources/unit/aggregate-resources-test/project1" );
108     }
109 
110     /**
111      * @see org.apache.maven.project.MavenProject#createArtifacts(org.apache.maven.artifact.factory.ArtifactFactory,
112      *      java.lang.String, org.apache.maven.artifact.resolver.filter.ArtifactFilter)
113      */
114     public Set createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter )
115         throws InvalidDependencyVersionException
116     {
117         return Collections.EMPTY_SET;
118     }
119 
120     /**
121      * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getExecutionProject()
122      */
123     public MavenProject getExecutionProject()
124     {
125         return this;
126     }
127 }