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.io.Reader;
24  import java.util.Collections;
25  import java.util.List;
26  import java.util.Properties;
27  
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.artifact.repository.MavenArtifactRepository;
30  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
31  import org.apache.maven.model.Developer;
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  import org.codehaus.plexus.util.ReaderFactory;
36  
37  /**
38   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
39   */
40  public class FilteringMavenProjectStub
41      extends MavenProjectStub
42  {
43      public FilteringMavenProjectStub()
44      {
45          MavenXpp3Reader pomReader = new MavenXpp3Reader();
46          try ( Reader reader = ReaderFactory.newXmlReader( getFile() ) )
47          {
48              final Model model = pomReader.read( reader );
49              setModel( model );
50          }
51          catch ( Exception e )
52          {
53              throw new RuntimeException( e );
54          }
55      }
56  
57      /** {@inheritDoc} */
58      public String getName()
59      {
60          return getModel().getName();
61      }
62  
63      /** {@inheritDoc} */
64      public String getVersion()
65      {
66          return getModel().getVersion();
67      }
68  
69      /** {@inheritDoc} */
70      public File getBasedir()
71      {
72          return new File( super.getBasedir(), "target/test-classes/unit/pdf/" );
73      }
74  
75      /** {@inheritDoc} */
76      public List<Developer> getDevelopers()
77      {
78          return getModel().getDevelopers();
79      }
80  
81      /** {@inheritDoc} */
82      public Properties getProperties()
83      {
84          return getModel().getProperties();
85      }
86  
87      /** {@inheritDoc} */
88      public List<ArtifactRepository> getRemoteArtifactRepositories()
89      {
90          ArtifactRepository repository =
91              new MavenArtifactRepository( "central", "https://repo.maven.apache.org/maven2",
92                      new DefaultRepositoryLayout(), null,null );
93  
94          return Collections.singletonList( repository );
95      }
96  
97      /** {@inheritDoc} */
98      public File getFile()
99      {
100         return new File( getBasedir(), "pom_filtering.xml" );
101     }
102 }