View Javadoc
1   package org.apache.maven.plugins.source.stubs;
2   
3   import static org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
4   
5   import java.io.File;
6   import java.util.ArrayList;
7   import java.util.List;
8   
9   /*
10   * Licensed to the Apache Software Foundation (ASF) under one
11   * or more contributor license agreements.  See the NOTICE file
12   * distributed with this work for additional information
13   * regarding copyright ownership.  The ASF licenses this file
14   * to you under the Apache License, Version 2.0 (the
15   * "License"); you may not use this file except in compliance
16   * with the License.  You may obtain a copy of the License at
17   *
18   *   http://www.apache.org/licenses/LICENSE-2.0
19   *
20   * Unless required by applicable law or agreed to in writing,
21   * software distributed under the License is distributed on an
22   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23   * KIND, either express or implied.  See the License for the
24   * specific language governing permissions and limitations
25   * under the License.
26   */
27  
28  import org.apache.maven.model.Build;
29  import org.apache.maven.model.Model;
30  import org.apache.maven.model.Resource;
31  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
32  
33  /**
34   * @author Dennis Lundberg
35   */
36  public class Project009Stub
37      extends MavenProjectStub
38  {
39      private Build build;
40  
41      private List<Resource> resources;
42  
43      private List<Resource> testResources;
44  
45      public Project009Stub()
46      {
47          Model model;
48  
49          try
50          {
51              final File pomFile = new File( getBasedir(), "target/test-classes/unit/project-009/pom.xml" );
52              model = readModelFromFile( pomFile );
53              setModel( model );
54              setFile( pomFile );
55  
56              setGroupId( model.getGroupId() );
57              setArtifactId( model.getArtifactId() );
58              setVersion( model.getVersion() );
59              setName( model.getName() );
60              setUrl( model.getUrl() );
61              setPackaging( model.getPackaging() );
62  
63              Build build = new Build();
64              build.setFinalName( getArtifactId() + "-" + getVersion() );
65              build.setDirectory( getBasedir() + "/target/test/unit/project-009/target" );
66              setBuild( build );
67  
68              String basedir = getBasedir().getAbsolutePath();
69              List<String> compileSourceRoots = new ArrayList<String>();
70              compileSourceRoots.add( basedir + "/target/test-classes/unit/project-009/src/main/java" );
71              setCompileSourceRoots( compileSourceRoots );
72  
73              List<String> testCompileSourceRoots = new ArrayList<String>();
74              testCompileSourceRoots.add( basedir + "/target/test-classes/unit/project-009/src/test/java" );
75              setTestCompileSourceRoots( testCompileSourceRoots );
76  
77              setResources( model.getBuild().getResources() );
78              setTestResources( model.getBuild().getTestResources() );
79  
80              SourcePluginArtifactStub artifact =
81                  new SourcePluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging(), null );
82              artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
83              artifact.setType( "jar" );
84              artifact.setBaseVersion( "1.0-SNAPSHOT" );
85              setArtifact( artifact );
86          }
87          catch ( Exception e )
88          {
89              e.printStackTrace();
90          }
91      }
92  
93      public Build getBuild()
94      {
95          return build;
96      }
97  
98      public void setBuild( Build build )
99      {
100         this.build = build;
101     }
102 
103     public List<Resource> getResources()
104     {
105         return resources;
106     }
107 
108     public void setResources( List<Resource> resources )
109     {
110         this.resources = resources;
111     }
112 
113     public List<Resource> getTestResources()
114     {
115         return testResources;
116     }
117 
118     public void setTestResources( List<Resource> testResources )
119     {
120         this.testResources = testResources;
121     }
122 }