1 package org.apache.maven.plugin.coreit;
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.FileOutputStream;
24 import java.io.IOException;
25 import java.io.OutputStream;
26 import java.util.Properties;
27
28 import org.apache.maven.execution.MavenSession;
29 import org.apache.maven.plugin.AbstractMojo;
30 import org.apache.maven.plugin.MojoExecutionException;
31 import org.apache.maven.toolchain.Toolchain;
32 import org.apache.maven.toolchain.ToolchainManager;
33
34
35
36
37
38
39
40
41 public class FindToolMojo
42 extends AbstractMojo
43 {
44
45
46
47
48 private ToolchainManager toolchainManager;
49
50
51
52
53
54
55
56
57 private MavenSession session;
58
59
60
61
62
63
64 private File outputFile;
65
66
67
68
69
70
71 private String type;
72
73
74
75
76
77
78 private String tool;
79
80 public void execute()
81 throws MojoExecutionException
82 {
83 Toolchain toolchain = toolchainManager.getToolchainFromBuildContext( type, session );
84
85 getLog().info( "[MAVEN-CORE-IT-LOG] Toolchain in session: " + toolchain );
86
87 Properties properties = new Properties();
88
89 if ( toolchain != null )
90 {
91 properties.setProperty( "toolchain.type", toolchain.getType() );
92
93 String path = toolchain.findTool( tool );
94 if ( path != null )
95 {
96 properties.setProperty( "tool." + tool, path );
97 }
98 }
99
100 OutputStream out = null;
101 try
102 {
103 outputFile.getParentFile().mkdirs();
104 out = new FileOutputStream( outputFile );
105 properties.store( out, "MAVEN-CORE-IT-LOG" );
106 }
107 catch ( IOException e )
108 {
109 throw new MojoExecutionException( e.getMessage(), e );
110 }
111 finally
112 {
113 if ( out != null )
114 {
115 try
116 {
117 out.close();
118 }
119 catch ( IOException e )
120 {
121
122 }
123 }
124 }
125 }
126 }