You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/04/04 00:53:55 UTC
svn commit: r644546 -
/maven/plugin-testing/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java
Author: bentmann
Date: Thu Apr 3 15:53:54 2008
New Revision: 644546
URL: http://svn.apache.org/viewvc?rev=644546&view=rev
Log:
[MPLUGINTESTING-1] Add convenience methods to MavenProjectStub to easily populate model from test resource
Modified:
maven/plugin-testing/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java
Modified: maven/plugin-testing/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugin-testing/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java?rev=644546&r1=644545&r2=644546&view=diff
==============================================================================
--- maven/plugin-testing/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java (original)
+++ maven/plugin-testing/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java Thu Apr 3 15:53:54 2008
@@ -51,10 +51,13 @@
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* Very simple stub of <code>MavenProject<code> object, going to take a lot of work to make it
@@ -171,6 +174,33 @@
{
super( (Model) null );
this.model = model;
+ }
+
+ /**
+ * Loads the model for this stub from the specified POM. For convenience, any checked exception caused by I/O or
+ * parser errors will be wrapped into an unchecked exception.
+ *
+ * @param pomFile The path to the POM file to load, must not be <code>null</code>. If this path is relative, it
+ * is resolved against the return value of {@link #getBasedir()}.
+ */
+ protected void readModel( File pomFile )
+ {
+ if ( !pomFile.isAbsolute() )
+ {
+ pomFile = new File( getBasedir(), pomFile.getPath() );
+ }
+ try
+ {
+ setModel( new MavenXpp3Reader().read( ReaderFactory.newXmlReader( pomFile ) ) );
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( "Failed to read POM file: " + pomFile, e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new RuntimeException( "Failed to parse POM file: " + pomFile, e );
+ }
}
/**