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  
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.artifact.repository.DefaultArtifactRepository;
29  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
30  import org.apache.maven.model.Model;
31  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
32  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
33  import org.codehaus.plexus.util.IOUtil;
34  import org.codehaus.plexus.util.ReaderFactory;
35  
36  /**
37   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
38   * @version $Id: DefaultMavenProjectStub.java 803108 2009-08-11 13:14:33Z vsiveton $
39   */
40  public class DefaultMavenProjectStub
41      extends MavenProjectStub
42  {
43      public DefaultMavenProjectStub()
44      {
45          MavenXpp3Reader pomReader = new MavenXpp3Reader();
46          Reader reader = null;
47          try
48          {
49              reader = ReaderFactory.newXmlReader( getFile() );
50              Model model = pomReader.read( reader );
51              setModel( model );
52          }
53          catch ( Exception e )
54          {
55              throw new RuntimeException( e );
56          }
57          finally
58          {
59              IOUtil.close( reader );
60          }
61      }
62  
63      /** {@inheritDoc} */
64      public String getName()
65      {
66          return getModel().getName();
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 getRemoteArtifactRepositories()
77      {
78          ArtifactRepository repository =
79              new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
80                                             new DefaultRepositoryLayout() );
81  
82          return Collections.singletonList( repository );
83      }
84  
85      /** {@inheritDoc} */
86      public File getFile()
87      {
88          return new File( getBasedir(), "pom.xml" );
89      }
90  }