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