1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.felix.obrplugin;
20
21
22 import java.io.File;
23 import java.io.FileNotFoundException;
24 import java.io.FileReader;
25 import java.io.IOException;
26 import java.io.Reader;
27
28 import org.apache.maven.model.Model;
29 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
30 import org.apache.maven.plugin.MojoExecutionException;
31 import org.apache.maven.project.MavenProject;
32 import org.codehaus.plexus.util.IOUtil;
33 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
34
35
36
37
38
39
40
41 public final class PomHelper
42 {
43 public static MavenProject readPom( File pomFile ) throws MojoExecutionException
44 {
45 Reader reader = null;
46
47 try
48 {
49 reader = new FileReader( pomFile );
50 MavenXpp3Reader modelReader = new MavenXpp3Reader();
51 return new MavenProject( modelReader.read( reader ) );
52 }
53 catch ( FileNotFoundException e )
54 {
55 throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(), e );
56 }
57 catch ( IOException e )
58 {
59 throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(), e );
60 }
61 catch ( XmlPullParserException e )
62 {
63 throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(), e );
64 }
65 finally
66 {
67 IOUtil.close( reader );
68 }
69 }
70
71
72 public static MavenProject buildPom( String groupId, String artifactId, String version, String packaging )
73 {
74 Model model = new Model();
75
76 model.setModelVersion( "4.0.0" );
77 model.setGroupId( groupId );
78 model.setArtifactId( artifactId );
79 model.setVersion( version );
80 model.setPackaging( packaging );
81
82 return new MavenProject( model );
83 }
84 }