1 package org.apache.maven.archiva.consumers;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.maven.archiva.common.utils.BaseFile;
23 import org.apache.maven.model.Model;
24 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
25 import org.codehaus.plexus.util.IOUtil;
26 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
28 import java.io.FileReader;
29 import java.io.IOException;
30 import java.io.Reader;
31 import java.util.ArrayList;
32 import java.util.List;
35 * GenericModelConsumer - consumer for pom files.
37 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
40 public abstract class GenericModelConsumer
41 extends AbstractConsumer
44 public abstract void processModel( Model model, BaseFile file );
46 private static final List includePatterns;
50 includePatterns = new ArrayList();
51 includePatterns.add( "**/*.pom" );
54 public List getIncludePatterns()
56 return includePatterns;
59 public boolean isEnabled()
64 public void processFile( BaseFile file )
65 throws ConsumerException
67 Model model = buildModel( file );
68 processModel( model, file );
71 private Model buildModel( BaseFile file )
72 throws ConsumerException
78 reader = new FileReader( file );
79 MavenXpp3Reader modelReader = new MavenXpp3Reader();
81 model = modelReader.read( reader );
83 catch ( XmlPullParserException e )
85 throw new ConsumerException( file, "Error parsing metadata file: " + e.getMessage(), e );
87 catch ( IOException e )
89 throw new ConsumerException( file, "Error reading metadata file: " + e.getMessage(), e );
93 IOUtil.close( reader );