1 package org.apache.maven.settings.io;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.Reader;
26 import java.util.Map;
27
28 import org.apache.maven.settings.Settings;
29 import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
30 import org.codehaus.plexus.component.annotations.Component;
31 import org.codehaus.plexus.util.IOUtil;
32 import org.codehaus.plexus.util.ReaderFactory;
33 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
34
35
36
37
38
39
40 @Component( role = SettingsReader.class )
41 public class DefaultSettingsReader
42 implements SettingsReader
43 {
44
45 public Settings read( File input, Map<String, ?> options )
46 throws IOException
47 {
48 if ( input == null )
49 {
50 throw new IllegalArgumentException( "input file missing" );
51 }
52
53 Settings settings = read( ReaderFactory.newXmlReader( input ), options );
54
55 return settings;
56 }
57
58 public Settings read( Reader input, Map<String, ?> options )
59 throws IOException
60 {
61 if ( input == null )
62 {
63 throw new IllegalArgumentException( "input reader missing" );
64 }
65
66 try
67 {
68 SettingsXpp3Reader r = new SettingsXpp3Reader();
69 return r.read( input, isStrict( options ) );
70 }
71 catch ( XmlPullParserException e )
72 {
73 throw new SettingsParseException( e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e );
74 }
75 finally
76 {
77 IOUtil.close( input );
78 }
79 }
80
81 public Settings read( InputStream input, Map<String, ?> options )
82 throws IOException
83 {
84 if ( input == null )
85 {
86 throw new IllegalArgumentException( "input stream missing" );
87 }
88
89 try
90 {
91 SettingsXpp3Reader r = new SettingsXpp3Reader();
92 return r.read( input, isStrict( options ) );
93 }
94 catch ( XmlPullParserException e )
95 {
96 throw new SettingsParseException( e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e );
97 }
98 finally
99 {
100 IOUtil.close( input );
101 }
102 }
103
104 private boolean isStrict( Map<String, ?> options )
105 {
106 Object value = ( options != null ) ? options.get( IS_STRICT ) : null;
107 return value == null || Boolean.parseBoolean( value.toString() );
108 }
109
110 }