1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.toolchain;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.io.File;
25 import java.io.InputStream;
26 import java.nio.file.Files;
27
28 import org.apache.maven.toolchain.model.PersistedToolchains;
29 import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36 @Deprecated
37 @Named("default")
38 @Singleton
39 public class DefaultToolchainsBuilder implements ToolchainsBuilder {
40 private final Logger logger = LoggerFactory.getLogger(getClass());
41
42 public PersistedToolchains build(File userToolchainsFile) throws MisconfiguredToolchainException {
43 PersistedToolchains toolchains = null;
44
45 if (userToolchainsFile != null && userToolchainsFile.isFile()) {
46 try (InputStream in = Files.newInputStream(userToolchainsFile.toPath())) {
47 toolchains = new PersistedToolchains(new MavenToolchainsStaxReader().read(in));
48 } catch (Exception e) {
49 throw new MisconfiguredToolchainException(
50 "Cannot read toolchains file at " + userToolchainsFile.getAbsolutePath(), e);
51 }
52
53 } else if (userToolchainsFile != null) {
54 logger.debug("Toolchains configuration was not found at {}", userToolchainsFile);
55 }
56
57 return toolchains;
58 }
59 }