View Javadoc
1   package org.apache.maven.plugins.pdf.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.util.List;
24  
25  import org.apache.maven.model.Developer;
26  import org.apache.maven.model.Model;
27  import org.apache.maven.model.Organization;
28  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
29  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
30  import org.apache.commons.io.input.XmlStreamReader;
31  
32  /**
33   * @author ltheussl
34   */
35  public class ModelBuilderMavenProjectStub
36      extends MavenProjectStub
37  {
38      /**
39       * Stub to test the DocumentModelBuilder.
40       */
41      public ModelBuilderMavenProjectStub()
42      {
43          try ( XmlStreamReader reader = new XmlStreamReader( getFile() ) )
44          {
45              final Model model = new MavenXpp3Reader().read( reader );
46              setModel( model );
47  
48              setGroupId( model.getGroupId() );
49              setArtifactId( model.getArtifactId() );
50              setVersion( model.getVersion() );
51              setName( model.getName() );
52              setDescription( model.getDescription() );
53              setDevelopers( model.getDevelopers() );
54              setOrganization( model.getOrganization() );
55          }
56          catch ( Exception e )
57          {
58              throw new RuntimeException( e );
59          }
60      }
61  
62      /** {@inheritDoc} */
63      public File getBasedir()
64      {
65          return new File( super.getBasedir(), "target/test-classes/unit/pdf/" );
66      }
67  
68      /** {@inheritDoc} */
69      public void addDeveloper( Developer developer )
70      {
71          getModel().addDeveloper( developer );
72      }
73  
74      /** {@inheritDoc} */
75      public List<Developer> getDevelopers()
76      {
77          return getModel().getDevelopers();
78      }
79  
80      /** {@inheritDoc} */
81      public Organization getOrganization()
82      {
83          return getModel().getOrganization();
84      }
85  
86      /** {@inheritDoc} */
87      public void setDevelopers( List<Developer> list )
88      {
89          getModel().setDevelopers( list );
90      }
91  
92      /** {@inheritDoc} */
93      public void setOrganization( Organization organization )
94      {
95          getModel().setOrganization( organization );
96      }
97  
98      /** {@inheritDoc} */
99      public File getFile()
100     {
101         return new File( getBasedir(), "pom_model_builder.xml" );
102     }
103 }