View Javadoc
1   package org.apache.maven.plugin.jxr.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.List;
26  
27  import org.apache.maven.model.Build;
28  import org.apache.maven.model.Model;
29  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
30  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
31  
32  /**
33   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
34   */
35  public class PomMavenProjectStub
36      extends MavenProjectStub
37  {
38      private Build build;
39  
40      public PomMavenProjectStub()
41      {
42          MavenXpp3Reader pomReader = new MavenXpp3Reader();
43          Model model = null;
44  
45          try
46          {
47              model = pomReader.read( new FileReader( new File( getBasedir(), "pom-test-plugin-config.xml" ) ) );
48              setModel( model );
49          }
50          catch ( Exception e )
51          {
52              throw new RuntimeException( e );
53          }
54  
55          setGroupId( model.getGroupId() );
56          setArtifactId( model.getArtifactId() );
57          setVersion( model.getVersion() );
58          setName( model.getName() );
59          setUrl( model.getUrl() );
60          setPackaging( model.getPackaging() );
61  
62          Build build = new Build();
63          build.setFinalName( model.getArtifactId() );
64          build.setDirectory( super.getBasedir() + "/target/test/unit/pom-test/target" );
65          build.setSourceDirectory( getBasedir() + "/src/main/java" );
66          build.setOutputDirectory( super.getBasedir() + "/target/test/unit/pom-test/target/classes" );
67          build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
68          build.setTestOutputDirectory( super.getBasedir() + "/target/test/unit/pom-test/target/test-classes" );
69          setBuild( build );
70  
71          List compileSourceRoots = new ArrayList();
72          compileSourceRoots.add( getBasedir() + "/src/main/java" );
73          setCompileSourceRoots( compileSourceRoots );
74  
75          List testCompileSourceRoots = new ArrayList();
76          testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
77          setTestCompileSourceRoots( testCompileSourceRoots );
78      }
79  
80      /**
81       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBuild()
82       */
83      public Build getBuild()
84      {
85          return build;
86      }
87  
88      /**
89       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#setBuild(org.apache.maven.model.Build)
90       */
91      public void setBuild( Build build )
92      {
93          this.build = build;
94      }
95  
96      /**
97       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBasedir()
98       */
99      public File getBasedir()
100     {
101         return new File( super.getBasedir() + "/src/test/resources/unit/pom-test" );
102     }
103 }