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.doap.stubs;
20  
21  import java.io.File;
22  import java.io.IOException;
23  import java.util.Collections;
24  import java.util.List;
25  
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.artifact.repository.DefaultArtifactRepository;
28  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
29  import org.apache.maven.model.Developer;
30  import org.apache.maven.model.DistributionManagement;
31  import org.apache.maven.model.IssueManagement;
32  import org.apache.maven.model.License;
33  import org.apache.maven.model.Model;
34  import org.apache.maven.model.Organization;
35  import org.apache.maven.model.Scm;
36  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
37  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
38  import org.codehaus.plexus.util.ReaderFactory;
39  import org.codehaus.plexus.util.xml.XmlStreamReader;
40  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
41  
42  /**
43   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
44   */
45  public class DoapProjectStub extends MavenProjectStub {
46      private Model model;
47  
48      /**
49       * Default constructor
50       */
51      public DoapProjectStub() {
52          MavenXpp3Reader pomReader = new MavenXpp3Reader();
53          try (XmlStreamReader reader = ReaderFactory.newXmlReader(new File(
54                  new File(super.getBasedir(), "/src/test/resources/unit/doap-configuration/"),
55                  "doap-configuration-plugin-config.xml"))) {
56              model = pomReader.read(reader);
57              setModel(model);
58          } catch (IOException | XmlPullParserException e) {
59              throw new RuntimeException(e);
60          }
61  
62          setGroupId(model.getGroupId());
63          setArtifactId(model.getArtifactId());
64          setVersion(model.getVersion());
65          setName(model.getName());
66          setDescription(model.getDescription());
67          setUrl(model.getUrl());
68          setPackaging(model.getPackaging());
69          setDevelopers(model.getDevelopers());
70      }
71  
72      @Override
73      public List<Developer> getDevelopers() {
74          return model.getDevelopers();
75      }
76  
77      @Override
78      public String getDescription() {
79          return model.getDescription();
80      }
81  
82      @Override
83      public String getInceptionYear() {
84          return model.getInceptionYear();
85      }
86  
87      @Override
88      public List<License> getLicenses() {
89          return model.getLicenses();
90      }
91  
92      @Override
93      public Scm getScm() {
94          return model.getScm();
95      }
96  
97      @Override
98      public IssueManagement getIssueManagement() {
99          return model.getIssueManagement();
100     }
101 
102     @Override
103     public DistributionManagement getDistributionManagement() {
104         return model.getDistributionManagement();
105     }
106 
107     @Override
108     public Organization getOrganization() {
109         return model.getOrganization();
110     }
111 
112     @Override
113     public List<ArtifactRepository> getRemoteArtifactRepositories() {
114         ArtifactRepository repository = new DefaultArtifactRepository(
115                 "central", "https://repo.maven.apache.org/maven2", new DefaultRepositoryLayout());
116 
117         return Collections.singletonList(repository);
118     }
119 }