View Javadoc
1   package org.apache.maven.doxia.tools.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 java.io.File;
23  import java.io.FileReader;
24  import java.util.ArrayList;
25  import java.util.Collections;
26  import java.util.List;
27  
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.artifact.repository.DefaultArtifactRepository;
30  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
31  import org.apache.maven.model.Build;
32  import org.apache.maven.model.Model;
33  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
34  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
35  
36  /**
37   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
38   * @version $Id: SiteToolMavenProjectStub.html 914485 2014-06-30 19:54:45Z hboutemy $
39   */
40  public class SiteToolMavenProjectStub
41      extends MavenProjectStub
42  {
43      private Build build;
44  
45      private File basedir;
46  
47      public SiteToolMavenProjectStub( String projectName )
48      {
49          basedir = new File( super.getBasedir() + "/src/test/resources/unit/" + projectName );
50  
51          MavenXpp3Reader pomReader = new MavenXpp3Reader();
52          Model model = null;
53  
54          try
55          {
56              model = pomReader.read( new FileReader( new File( getBasedir(), "pom.xml" ) ) );
57              setModel( model );
58          }
59          catch ( Exception e )
60          {
61              throw new RuntimeException( e );
62          }
63  
64          setGroupId( model.getGroupId() );
65          setArtifactId( model.getArtifactId() );
66          setVersion( model.getVersion() );
67          setName( model.getName() );
68          setUrl( model.getUrl() );
69          setPackaging( model.getPackaging() );
70  
71          build = new Build();
72          build.setFinalName( model.getArtifactId() );
73          build.setDirectory( super.getBasedir() + "/target/test/unit/" + projectName + "/target" );
74          build.setSourceDirectory( getBasedir() + "/src/main/java" );
75          build.setOutputDirectory( build.getDirectory() + "/classes" );
76          build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
77          build.setTestOutputDirectory( build.getDirectory() + "/test-classes" );
78  
79          List<String> compileSourceRoots = new ArrayList<String>();
80          compileSourceRoots.add( getBasedir() + "/src/main/java" );
81          setCompileSourceRoots( compileSourceRoots );
82  
83          List<String> testCompileSourceRoots = new ArrayList<String>();
84          testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
85          setTestCompileSourceRoots( testCompileSourceRoots );
86      }
87  
88      /** {@inheritDoc} */
89      public Build getBuild()
90      {
91          return build;
92      }
93  
94      /** {@inheritDoc} */
95      public void setBuild( Build build )
96      {
97          this.build = build;
98      }
99  
100     /** {@inheritDoc} */
101     public File getBasedir()
102     {
103         return basedir;
104     }
105 
106     public void setBasedir( File basedir )
107     {
108         this.basedir = basedir;
109     }
110 
111     /** {@inheritDoc} */
112     public List<ArtifactRepository> getRemoteArtifactRepositories()
113     {
114         ArtifactRepository repository = new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
115                                                                        new DefaultRepositoryLayout() );
116 
117         return Collections.singletonList( repository );
118     }
119 }