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
26 import java.io.File;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.OutputStream;
31 import java.util.Properties;
32
33
34
35
36
37
38
39
40
41 public class DumpVersionMojo
42 extends AbstractMojo
43 {
44
45
46
47
48
49
50
51 private File basedir;
52
53
54
55
56
57
58 private WagonManager wagonManager;
59
60
61
62
63
64
65 private File propertiesFile;
66
67
68
69
70
71
72 private String providerHint;
73
74
75
76
77
78
79 private String providerGroupId;
80
81
82
83
84
85
86 private String providerArtifactId;
87
88
89
90
91
92
93 public void execute()
94 throws MojoExecutionException
95 {
96 Properties wagonProperties = new Properties();
97
98 Object wagon;
99 try
100 {
101 wagon = wagonManager.getWagon( providerHint );
102
103 String resource = "/META-INF/maven/" + providerGroupId + "/" + providerArtifactId + "/pom.properties";
104 InputStream is = wagon.getClass().getResourceAsStream( resource );
105 wagonProperties.load( is );
106 }
107 catch ( IOException e )
108 {
109 throw new MojoExecutionException( "Wagon properties could not be read: " + e.getMessage(), e );
110 }
111 catch ( Exception e )
112 {
113 getLog().info( "[MAVEN-CORE-IT-LOG] No wagon available for " + providerHint );
114 wagonProperties.setProperty( "missing", "true" );
115 }
116
117 if ( !propertiesFile.isAbsolute() )
118 {
119 propertiesFile = new File( basedir, propertiesFile.getPath() );
120 }
121
122 getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + propertiesFile );
123
124 OutputStream out = null;
125 try
126 {
127 propertiesFile.getParentFile().mkdirs();
128 out = new FileOutputStream( propertiesFile );
129 wagonProperties.store( out, "MAVEN-CORE-IT-LOG" );
130 }
131 catch ( IOException e )
132 {
133 throw new MojoExecutionException( "Output file could not be created: " + propertiesFile, e );
134 }
135 finally
136 {
137 if ( out != null )
138 {
139 try
140 {
141 out.close();
142 }
143 catch ( IOException e )
144 {
145
146 }
147 }
148 }
149
150 getLog().info( "[MAVEN-CORE-IT-LOG] Created output file " + propertiesFile );
151 }
152
153 }