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 org.apache.maven.artifact.manager.WagonManager; |
23 | |
import org.apache.maven.plugin.AbstractMojo; |
24 | |
import org.apache.maven.plugin.MojoExecutionException; |
25 | |
import org.apache.maven.plugin.MojoFailureException; |
26 | |
import org.apache.maven.wagon.authentication.AuthenticationInfo; |
27 | |
|
28 | |
import java.io.File; |
29 | |
import java.io.FileOutputStream; |
30 | |
import java.io.IOException; |
31 | |
import java.io.OutputStream; |
32 | |
import java.util.Properties; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class DumpAuthMojo |
44 | |
extends AbstractMojo |
45 | |
{ |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
private File basedir; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
private WagonManager wagonManager; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
private File propertiesFile; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
private String[] serverIds; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public void execute() |
82 | |
throws MojoExecutionException, MojoFailureException |
83 | |
{ |
84 | 0 | Properties authProperties = new Properties(); |
85 | |
|
86 | 0 | for ( int i = 0; i < serverIds.length; i++ ) |
87 | |
{ |
88 | 0 | String serverId = serverIds[i]; |
89 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Getting authentication info for server " + serverId ); |
90 | |
|
91 | 0 | AuthenticationInfo authInfo = wagonManager.getAuthenticationInfo( serverId ); |
92 | 0 | if ( authInfo != null ) |
93 | |
{ |
94 | 0 | if ( authInfo.getUserName() != null ) |
95 | |
{ |
96 | 0 | authProperties.setProperty( serverId + ".username", authInfo.getUserName() ); |
97 | |
} |
98 | 0 | if ( authInfo.getPassword() != null ) |
99 | |
{ |
100 | 0 | authProperties.setProperty( serverId + ".password", authInfo.getPassword() ); |
101 | |
} |
102 | 0 | if ( authInfo.getPrivateKey() != null ) |
103 | |
{ |
104 | 0 | authProperties.setProperty( serverId + ".privateKey", authInfo.getPrivateKey() ); |
105 | |
} |
106 | 0 | if ( authInfo.getPassphrase() != null ) |
107 | |
{ |
108 | 0 | authProperties.setProperty( serverId + ".passphrase", authInfo.getPassphrase() ); |
109 | |
} |
110 | |
|
111 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] username = " + authInfo.getUserName() ); |
112 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] password = " + authInfo.getPassword() ); |
113 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] private key = " + authInfo.getPrivateKey() ); |
114 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] passphrase = " + authInfo.getPassphrase() ); |
115 | |
} |
116 | |
else |
117 | |
{ |
118 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] (no authentication info available)" ); |
119 | |
} |
120 | |
} |
121 | |
|
122 | 0 | if ( !propertiesFile.isAbsolute() ) |
123 | |
{ |
124 | 0 | propertiesFile = new File( basedir, propertiesFile.getPath() ); |
125 | |
} |
126 | |
|
127 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + propertiesFile ); |
128 | |
|
129 | 0 | OutputStream out = null; |
130 | |
try |
131 | |
{ |
132 | 0 | propertiesFile.getParentFile().mkdirs(); |
133 | 0 | out = new FileOutputStream( propertiesFile ); |
134 | 0 | authProperties.store( out, "MAVEN-CORE-IT-LOG" ); |
135 | |
} |
136 | 0 | catch ( IOException e ) |
137 | |
{ |
138 | 0 | throw new MojoExecutionException( "Output file could not be created: " + propertiesFile, e ); |
139 | |
} |
140 | |
finally |
141 | |
{ |
142 | 0 | if ( out != null ) |
143 | |
{ |
144 | |
try |
145 | |
{ |
146 | 0 | out.close(); |
147 | |
} |
148 | 0 | catch ( IOException e ) |
149 | |
{ |
150 | |
|
151 | 0 | } |
152 | |
} |
153 | |
} |
154 | |
|
155 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Created output file " + propertiesFile ); |
156 | 0 | } |
157 | |
|
158 | |
} |