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.dependency.testUtils.stubs;
20  
21  import java.io.File;
22  import java.io.FileInputStream;
23  import java.io.IOException;
24  
25  import org.apache.maven.model.Model;
26  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
27  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
28  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
29  
30  /**
31   * very simple stub of maven project, going to take a lot of work to make it useful as a stub though
32   */
33  public class DuplicateDependencies2ProjectStub extends MavenProjectStub {
34      public DuplicateDependencies2ProjectStub() {
35          File pom = new File(getBasedir(), "plugin-config2.xml");
36          MavenXpp3Reader pomReader = new MavenXpp3Reader();
37  
38          try (FileInputStream in = new FileInputStream(pom)) {
39              Model model = pomReader.read(in);
40              setModel(model);
41  
42              setGroupId(model.getGroupId());
43              setArtifactId(model.getArtifactId());
44              setVersion(model.getVersion());
45              setName(model.getName());
46              setUrl(model.getUrl());
47              setPackaging(model.getPackaging());
48              setFile(pom);
49          } catch (IOException | XmlPullParserException e) {
50              throw new RuntimeException(e);
51          }
52      }
53  
54      /**
55       * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBasedir()
56       */
57      public File getBasedir() {
58          return new File(super.getBasedir() + "/src/test/resources/unit/duplicate-dependencies");
59      }
60  }