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.commons.lang3.Validate;
29 import org.apache.maven.settings.Settings;
30 import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
31 import org.codehaus.plexus.component.annotations.Component;
32 import org.codehaus.plexus.util.IOUtil;
33 import org.codehaus.plexus.util.ReaderFactory;
34 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
35
36
37
38
39
40
41 @Component( role = SettingsReader.class )
42 public class DefaultSettingsReader
43 implements SettingsReader
44 {
45
46 @Override
47 public Settings read( File input, Map<String, ?> options )
48 throws IOException
49 {
50 Validate.notNull( input, "input cannot be null" );
51
52 Settings settings = read( ReaderFactory.newXmlReader( input ), options );
53
54 return settings;
55 }
56
57 @Override
58 public Settings read( Reader input, Map<String, ?> options )
59 throws IOException
60 {
61 Validate.notNull( input, "input cannot be null" );
62
63 try
64 {
65 SettingsXpp3Reader r = new SettingsXpp3Reader();
66 return r.read( input, isStrict( options ) );
67 }
68 catch ( XmlPullParserException e )
69 {
70 throw new SettingsParseException( e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e );
71 }
72 finally
73 {
74 IOUtil.close( input );
75 }
76 }
77
78 @Override
79 public Settings read( InputStream input, Map<String, ?> options )
80 throws IOException
81 {
82 Validate.notNull( input, "input cannot be null" );
83
84 try
85 {
86 SettingsXpp3Reader r = new SettingsXpp3Reader();
87 return r.read( input, isStrict( options ) );
88 }
89 catch ( XmlPullParserException e )
90 {
91 throw new SettingsParseException( e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e );
92 }
93 finally
94 {
95 IOUtil.close( input );
96 }
97 }
98
99 private boolean isStrict( Map<String, ?> options )
100 {
101 Object value = ( options != null ) ? options.get( IS_STRICT ) : null;
102 return value == null || Boolean.parseBoolean( value.toString() );
103 }
104
105 }