1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.toolchain.io;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.Reader;
25 import java.util.Map;
26 import java.util.Objects;
27 import javax.inject.Named;
28 import javax.inject.Singleton;
29 import org.apache.maven.api.toolchain.PersistedToolchains;
30 import org.apache.maven.toolchain.v4.MavenToolchainsXpp3Reader;
31 import org.codehaus.plexus.util.ReaderFactory;
32 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
33
34
35
36
37
38
39
40 @Named
41 @Singleton
42 public class DefaultToolchainsReader implements ToolchainsReader {
43
44 @Override
45 public PersistedToolchains read(File input, Map<String, ?> options) throws IOException {
46 Objects.requireNonNull(input, "input cannot be null");
47
48 return read(ReaderFactory.newXmlReader(input), options);
49 }
50
51 @Override
52 public PersistedToolchains read(Reader input, Map<String, ?> options) throws IOException {
53 Objects.requireNonNull(input, "input cannot be null");
54
55 try (Reader in = input) {
56 return new MavenToolchainsXpp3Reader().read(in, isStrict(options));
57 } catch (XmlPullParserException e) {
58 throw new ToolchainsParseException(e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e);
59 }
60 }
61
62 @Override
63 public PersistedToolchains read(InputStream input, Map<String, ?> options) throws IOException {
64 Objects.requireNonNull(input, "input cannot be null");
65
66 try (InputStream in = input) {
67 return new MavenToolchainsXpp3Reader().read(in, isStrict(options));
68 } catch (XmlPullParserException e) {
69 throw new ToolchainsParseException(e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e);
70 }
71 }
72
73 private boolean isStrict(Map<String, ?> options) {
74 Object value = (options != null) ? options.get(IS_STRICT) : null;
75 return value == null || Boolean.parseBoolean(value.toString());
76 }
77 }