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 import java.util.Objects;
28
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.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 @Override
46 public Settings read( File input, Map<String, ?> options )
47 throws IOException
48 {
49 Objects.requireNonNull( input, "input cannot be null" );
50
51 Settings settings = read( ReaderFactory.newXmlReader( input ), options );
52
53 return settings;
54 }
55
56 @Override
57 public Settings read( Reader input, Map<String, ?> options )
58 throws IOException
59 {
60 Objects.requireNonNull( input, "input cannot be null" );
61
62 try ( final Reader in = input )
63 {
64 return new SettingsXpp3Reader().read( in, isStrict( options ) );
65 }
66 catch ( XmlPullParserException e )
67 {
68 throw new SettingsParseException( e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e );
69 }
70 }
71
72 @Override
73 public Settings read( InputStream input, Map<String, ?> options )
74 throws IOException
75 {
76 Objects.requireNonNull( input, "input cannot be null" );
77
78 try ( final InputStream in = input )
79 {
80 return new SettingsXpp3Reader().read( in, isStrict( options ) );
81 }
82 catch ( XmlPullParserException e )
83 {
84 throw new SettingsParseException( e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e );
85 }
86 }
87
88 private boolean isStrict( Map<String, ?> options )
89 {
90 Object value = ( options != null ) ? options.get( IS_STRICT ) : null;
91 return value == null || Boolean.parseBoolean( value.toString() );
92 }
93
94 }