blob: d11c776cf2521f57e8dd4f94c79f7487fcb6b72a [file] [log] [blame]
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Stuart McCullochc792b372008-02-17 16:12:24 +000019package org.apache.felix.obrplugin;
Stuart McCullochbb8b9fa2008-02-17 16:07:14 +000020
21
22import java.io.File;
23import java.io.FileNotFoundException;
24import java.io.FileReader;
25import java.io.IOException;
26import java.io.Reader;
27
28import org.apache.maven.model.Model;
29import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
30import org.apache.maven.plugin.MojoExecutionException;
31import org.apache.maven.project.MavenProject;
32import org.codehaus.plexus.util.IOUtil;
33import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
34
35
36/**
37 * Maven POM helper methods.
38 *
39 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
40 */
41public 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}