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