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  
24  import org.apache.maven.model.Build;
25  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
26  
27  /**
28   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
29   */
30  public class FixMavenProjectStub
31      extends MavenProjectStub
32  {
33      public FixMavenProjectStub()
34      {
35          readModel( new File( getBasedir(), "pom.xml" ) );
36  
37          addCompileSourceRoot( getBasedir().getAbsolutePath() + "/target/classes" );
38          addCompileSourceRoot( getBasedir().getAbsolutePath() + "/src/main/java" );
39  
40          Build build = new Build();
41          build.setDirectory( getBasedir().getAbsolutePath() + "/target" );
42          build.setSourceDirectory( getBasedir().getAbsolutePath() + "/src/main/java" );
43          build.setOutputDirectory( getBasedir().getAbsolutePath() + "/target/classes" );
44          build.setTestSourceDirectory( getBasedir().getAbsolutePath() + "/src/test/java" );
45          build.setTestOutputDirectory( getBasedir().getAbsolutePath() + "/target/test-classes" );
46          setBuild( build );
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public String getArtifactId()
52      {
53          return getModel().getArtifactId();
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public String getGroupId()
59      {
60          String groupId = getModel().getGroupId();
61  
62          if ( ( groupId == null ) && ( getModel().getParent() != null ) )
63          {
64              groupId = getModel().getParent().getGroupId();
65          }
66  
67          return groupId;
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public String getVersion()
73      {
74          String version = getModel().getVersion();
75  
76          if ( ( version == null ) && ( getModel().getParent() != null ) )
77          {
78              version = getModel().getParent().getVersion();
79          }
80  
81          return version;
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public String getPackaging()
87      {
88          return getModel().getPackaging();
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      public File getBasedir()
94      {
95          // Using unit test dir
96          return new File( super.getBasedir() + "/target/test/unit/fix-test/" );
97      }
98  
99      /** {@inheritDoc} */
100     @Override
101     public File getFile()
102     {
103         return new File( getBasedir(), "pom.xml" );
104     }
105 }