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