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.List;
25  import java.util.Objects;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.model.Build;
29  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
30  import org.apache.maven.project.MavenProject;
31  
32  /**
33   * @author <a href="mailto:reto.weiss@axonivy.com">Reto Weiss</a>
34   */
35  public class AbstractAggregateChildMavenProjectStub
36      extends MavenProjectStub
37  {
38      private String baseDir;
39  
40      public AbstractAggregateChildMavenProjectStub(String baseDir, String pomFileName, String targetDirectory)
41      {
42          this.baseDir = baseDir;
43          readModel( new File( getBasedir(), pomFileName ) );
44  
45          setGroupId( Objects.toString( getModel().getGroupId(), getModel().getParent().getGroupId() ) );
46          setArtifactId( getModel().getArtifactId() );
47          setVersion( Objects.toString( getModel().getVersion(), getModel().getParent().getVersion() ) );
48          setName( getModel().getName() );
49          setUrl( getModel().getUrl() );
50          setPackaging( getModel().getPackaging() );
51  
52          setExecutionRoot( true );
53  
54          Artifact artifact = new JavadocPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
55          artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
56          setArtifact( artifact );
57  
58          Build build = new Build();
59          build.setFinalName( getModel().getArtifactId() );
60          build.setSourceDirectory( getBasedir() + "/src/main/java" );
61          build.setDirectory( super.getBasedir() + targetDirectory );
62          setBuild( build );
63  
64          List<String> compileSourceRoots = new ArrayList<>();
65          compileSourceRoots.add( getBasedir().getAbsolutePath() + "/src/main/java" );
66          setCompileSourceRoots( compileSourceRoots );
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public File getBasedir()
72      {
73          return new File( super.getBasedir() + baseDir );
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public MavenProject getExecutionProject()
79      {
80          return this;
81      }
82  }