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.source.stubs;
20  
21  import java.io.File;
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.maven.model.Build;
26  import org.apache.maven.model.Model;
27  import org.apache.maven.model.Resource;
28  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
29  
30  import static org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
31  
32  public class Project010Stub extends MavenProjectStub {
33      private Build build;
34  
35      private List<Resource> resources;
36  
37      private List<Resource> testResources;
38  
39      public Project010Stub() {
40          Model model;
41  
42          try {
43              model = readModelFromFile(new File(getBasedir(), "target/test-classes/unit/project-010/pom.xml"));
44              setModel(model);
45  
46              setFile(new File(getBasedir(), "target/test-classes/unit/project-010/pom.xml"));
47  
48              setGroupId(model.getGroupId());
49              setArtifactId(model.getArtifactId());
50              setVersion(model.getVersion());
51              setName(model.getName());
52              setUrl(model.getUrl());
53              setPackaging(model.getPackaging());
54  
55              Build build = new Build();
56              build.setFinalName(getArtifactId() + "-" + getVersion());
57              build.setDirectory(getBasedir() + "/target/test/unit/project-010/target");
58  
59              setBuild(build);
60  
61              String basedir = getBasedir().getAbsolutePath();
62              List<String> compileSourceRoots = new ArrayList<>();
63              compileSourceRoots.add(basedir + "/target/test-classes/unit/project-010/src/main/java");
64              setCompileSourceRoots(compileSourceRoots);
65  
66              List<String> testCompileSourceRoots = new ArrayList<>();
67              testCompileSourceRoots.add(basedir + "/target/test-classes/unit/project-010/src/test/java");
68              setTestCompileSourceRoots(testCompileSourceRoots);
69  
70              setResources(model.getBuild().getResources());
71              setTestResources(model.getBuild().getTestResources());
72  
73              SourcePluginArtifactStub artifact =
74                      new SourcePluginArtifactStub(getGroupId(), getArtifactId(), getVersion(), getPackaging(), null);
75              artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
76              artifact.setType("jar");
77              artifact.setBaseVersion("1.0-SNAPSHOT");
78              setArtifact(artifact);
79  
80          } catch (Exception e) {
81              e.printStackTrace();
82          }
83      }
84  
85      public Build getBuild() {
86          return build;
87      }
88  
89      public void setBuild(Build build) {
90          this.build = build;
91      }
92  
93      public List<Resource> getResources() {
94          return resources;
95      }
96  
97      public void setResources(List<Resource> resources) {
98          this.resources = resources;
99      }
100 
101     public List<Resource> getTestResources() {
102         return testResources;
103     }
104 
105     public void setTestResources(List<Resource> testResources) {
106         this.testResources = testResources;
107     }
108 }