/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java

https://github.com/tobrien/maven-plugins · Java · 90 lines · 55 code · 9 blank · 26 comment · 0 complexity · 6a83c676ddadd9843079c2e5cfc279f3 MD5 · raw file

  1. package org.apache.maven.plugins.pdf.stubs;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import java.io.File;
  21. import java.io.Reader;
  22. import java.util.Collections;
  23. import java.util.List;
  24. import org.apache.maven.artifact.repository.ArtifactRepository;
  25. import org.apache.maven.artifact.repository.DefaultArtifactRepository;
  26. import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
  27. import org.apache.maven.model.Model;
  28. import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
  29. import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
  30. import org.codehaus.plexus.util.IOUtil;
  31. import org.codehaus.plexus.util.ReaderFactory;
  32. /**
  33. * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
  34. * @version $Id$
  35. */
  36. public class DefaultMavenProjectStub
  37. extends MavenProjectStub
  38. {
  39. public DefaultMavenProjectStub()
  40. {
  41. MavenXpp3Reader pomReader = new MavenXpp3Reader();
  42. Reader reader = null;
  43. try
  44. {
  45. reader = ReaderFactory.newXmlReader( getFile() );
  46. Model model = pomReader.read( reader );
  47. setModel( model );
  48. }
  49. catch ( Exception e )
  50. {
  51. throw new RuntimeException( e );
  52. }
  53. finally
  54. {
  55. IOUtil.close( reader );
  56. }
  57. }
  58. /** {@inheritDoc} */
  59. public String getName()
  60. {
  61. return getModel().getName();
  62. }
  63. /** {@inheritDoc} */
  64. public File getBasedir()
  65. {
  66. return new File( super.getBasedir(), "target/test-classes/unit/pdf/" );
  67. }
  68. /** {@inheritDoc} */
  69. public List getRemoteArtifactRepositories()
  70. {
  71. ArtifactRepository repository =
  72. new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
  73. new DefaultRepositoryLayout() );
  74. return Collections.singletonList( repository );
  75. }
  76. /** {@inheritDoc} */
  77. public File getFile()
  78. {
  79. return new File( getBasedir(), "pom.xml" );
  80. }
  81. }