View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.javadoc.stubs;
20  
21  import java.io.File;
22  import java.util.ArrayList;
23  import java.util.List;
24  import java.util.Objects;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.model.Build;
28  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
29  import org.apache.maven.project.MavenProject;
30  
31  /**
32   * @author <a href="mailto:reto.weiss@axonivy.com">Reto Weiss</a>
33   */
34  public class AbstractAggregateChildMavenProjectStub extends MavenProjectStub {
35      private String baseDir;
36  
37      public AbstractAggregateChildMavenProjectStub(String baseDir, String pomFileName, String targetDirectory) {
38          this.baseDir = baseDir;
39          readModel(new File(getBasedir(), pomFileName));
40  
41          setGroupId(
42                  Objects.toString(getModel().getGroupId(), getModel().getParent().getGroupId()));
43          setArtifactId(getModel().getArtifactId());
44          setVersion(
45                  Objects.toString(getModel().getVersion(), getModel().getParent().getVersion()));
46          setName(getModel().getName());
47          setUrl(getModel().getUrl());
48          setPackaging(getModel().getPackaging());
49  
50          setExecutionRoot(true);
51  
52          Artifact artifact = new JavadocPluginArtifactStub(getGroupId(), getArtifactId(), getVersion(), getPackaging());
53          artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
54          setArtifact(artifact);
55  
56          Build build = new Build();
57          build.setFinalName(getModel().getArtifactId());
58          build.setSourceDirectory(getBasedir() + "/src/main/java");
59          build.setDirectory(super.getBasedir() + targetDirectory);
60          setBuild(build);
61  
62          List<String> compileSourceRoots = new ArrayList<>();
63          compileSourceRoots.add(getBasedir().getAbsolutePath() + "/src/main/java");
64          setCompileSourceRoots(compileSourceRoots);
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public File getBasedir() {
70          return new File(super.getBasedir() + baseDir);
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public MavenProject getExecutionProject() {
76          return this;
77      }
78  }