View Javadoc

1   package org.apache.maven.plugin.source.stubs;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
23  import org.apache.maven.model.Build;
24  import org.apache.maven.model.Model;
25  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
26  import org.apache.maven.artifact.Artifact;
27  import org.codehaus.plexus.util.ReaderFactory;
28  
29  import java.util.List;
30  import java.util.ArrayList;
31  import java.io.File;
32  
33  /**
34   * @author <a href="mailto:oching@exist.com">Maria Odea Ching</a>
35   */
36  public class Project003Stub
37      extends MavenProjectStub
38  {
39      private Build build;
40  
41      private List resources;
42  
43      private List testResources;
44  
45      public Project003Stub()
46      {
47          MavenXpp3Reader pomReader = new MavenXpp3Reader();
48          Model model;
49  
50          try
51          {
52              model = pomReader.read(
53                  ReaderFactory.newXmlReader( new File( getBasedir(), "target/test-classes/unit/project-003/pom.xml" ) ) );
54              setModel( model );
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-003/target" );
66              setBuild( build );
67  
68              String basedir = getBasedir().getAbsolutePath();
69              List compileSourceRoots = new ArrayList();
70              compileSourceRoots.add( basedir + "/target/test-classes/unit/project-003/src/main/java" );
71              setCompileSourceRoots( compileSourceRoots );
72  
73              List testCompileSourceRoots = new ArrayList();
74              testCompileSourceRoots.add( basedir + "/target/test-classes/unit/project-003/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          }
88          catch ( Exception e )
89          {
90              e.printStackTrace();
91          }
92      }
93  
94      public Build getBuild()
95      {
96          return build;
97      }
98  
99      public void setBuild( Build build )
100     {
101         this.build = build;
102     }
103 
104     public List getResources()
105     {
106         return resources;
107     }
108 
109     public void setResources( List resources )
110     {
111         this.resources = resources;
112     }
113 
114     public List getTestResources()
115     {
116         return testResources;
117     }
118 
119     public void setTestResources( List testResources )
120     {
121         this.testResources = testResources;
122     }
123 
124 
125 }