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.artifact.Artifact;
28  import org.apache.maven.model.Model;
29  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
30  
31  /**
32   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
33   */
34  public class TestSourceDirMavenProjectStub extends JxrProjectStub {
35  
36      public TestSourceDirMavenProjectStub() {
37          MavenXpp3Reader pomReader = new MavenXpp3Reader();
38          Model model = null;
39  
40          try (InputStream is = new FileInputStream(new File(getBasedir() + "/" + getPOM()))) {
41              model = pomReader.read(is);
42              setModel(model);
43          } catch (Exception ignored) {
44          }
45  
46          setArtifactId(model.getArtifactId());
47          setGroupId(model.getGroupId());
48          setVersion(model.getVersion());
49          setPackaging(model.getPackaging());
50          setInceptionYear(model.getInceptionYear());
51  
52          String basedir = getBasedir().getAbsolutePath();
53          List<String> compileSourceRoots = new ArrayList<>();
54          compileSourceRoots.add(basedir);
55          setCompileSourceRoots(compileSourceRoots);
56  
57          Artifact artifact = new JxrPluginArtifactStub(getGroupId(), getArtifactId(), getVersion(), getPackaging());
58          artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
59          setArtifact(artifact);
60      }
61  
62      @Override
63      public File getBasedir() {
64          return new File(super.getBasedir() + "/testsourcedir-test");
65      }
66  
67      @Override
68      protected String getPOM() {
69          return "testsourcedir-test-plugin-config.xml";
70      }
71  }