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  import java.util.Properties;
28  
29  import org.apache.maven.artifact.repository.ArtifactRepository;
30  import org.apache.maven.artifact.repository.DefaultArtifactRepository;
31  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
32  import org.apache.maven.model.Build;
33  import org.apache.maven.model.DistributionManagement;
34  import org.apache.maven.model.Model;
35  import org.apache.maven.model.Site;
36  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
37  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
38  
39  /**
40   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
41   */
42  public class SiteToolMavenProjectStub
43      extends MavenProjectStub
44  {
45      private Build build;
46  
47      private File basedir;
48  
49      private DistributionManagement distributionManagement;
50  
51      private Properties properties;
52  
53      public SiteToolMavenProjectStub( String projectName )
54      {
55          basedir = new File( super.getBasedir() + "/src/test/resources/unit/" + projectName );
56  
57          Model model = null;
58  
59          try
60          {
61              model = new MavenXpp3Reader().read( new FileReader( new File( getBasedir(), "pom.xml" ) ) );
62              setModel( model );
63          }
64          catch ( Exception e )
65          {
66              throw new RuntimeException( e );
67          }
68  
69          setGroupId( model.getGroupId() );
70          setArtifactId( model.getArtifactId() );
71          setVersion( model.getVersion() );
72          setName( model.getName() );
73          setUrl( model.getUrl() );
74          setPackaging( model.getPackaging() );
75          setProperties( model.getProperties() );
76  
77          build = new Build();
78          build.setFinalName( model.getArtifactId() );
79          build.setDirectory( super.getBasedir() + "/target/test/unit/" + projectName + "/target" );
80          build.setSourceDirectory( getBasedir() + "/src/main/java" );
81          build.setOutputDirectory( build.getDirectory() + "/classes" );
82          build.setTestSourceDirectory( getBasedir() + "/src/test/java" );
83          build.setTestOutputDirectory( build.getDirectory() + "/test-classes" );
84  
85          List<String> compileSourceRoots = new ArrayList<String>();
86          compileSourceRoots.add( getBasedir() + "/src/main/java" );
87          setCompileSourceRoots( compileSourceRoots );
88  
89          List<String> testCompileSourceRoots = new ArrayList<String>();
90          testCompileSourceRoots.add( getBasedir() + "/src/test/java" );
91          setTestCompileSourceRoots( testCompileSourceRoots );
92      }
93  
94      /** {@inheritDoc} */
95      public Build getBuild()
96      {
97          return build;
98      }
99  
100     /** {@inheritDoc} */
101     public void setBuild( Build build )
102     {
103         this.build = build;
104     }
105 
106     /** {@inheritDoc} */
107     public File getBasedir()
108     {
109         return basedir;
110     }
111 
112     /** {@inheritDoc} */
113     public void setBasedir( File basedir )
114     {
115         this.basedir = basedir;
116     }
117 
118     /** {@inheritDoc} */
119     public List<ArtifactRepository> getRemoteArtifactRepositories()
120     {
121         ArtifactRepository repository = new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
122                                                                        new DefaultRepositoryLayout() );
123 
124         return Collections.singletonList( repository );
125     }
126 
127     /** {@inheritDoc} */
128     public Properties getProperties()
129     {
130         return properties;
131     }
132 
133     /** {@inheritDoc} */
134     public void setProperties( Properties properties )
135     {
136         this.properties = properties;
137     }
138 
139     public void setDistgributionManagementSiteUrl( String url )
140     {
141         Site site = new Site();
142         site.setUrl( url );
143         distributionManagement = new DistributionManagement();
144         distributionManagement.setSite( site );
145     }
146 
147     /** {@inheritDoc} */
148     public DistributionManagement getDistributionManagement()
149     {
150         return distributionManagement;
151     }
152 }