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.Wagon;
27 import org.apache.maven.wagon.repository.Repository;
28
29 import java.io.File;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.OutputStream;
33 import java.util.Properties;
34
35
36
37
38
39
40
41
42
43
44
45 public class LookupWagonMojo
46 extends AbstractMojo
47 {
48
49
50
51
52
53
54 private WagonManager wagonManager;
55
56
57
58
59
60
61 private File outputFile;
62
63
64
65
66
67
68 private String[] urls;
69
70
71
72
73
74
75 public void execute()
76 throws MojoExecutionException, MojoFailureException
77 {
78 Properties loaderProperties = new Properties();
79
80 if ( urls != null )
81 {
82 for ( int i = 0; i < urls.length; i++ )
83 {
84 String url = urls[i];
85 getLog().info( "[MAVEN-CORE-IT-LOG] Looking up wagon for URL " + url );
86
87 try
88 {
89 Repository repo = new Repository( "repo-" + i, url );
90 Wagon wagon = wagonManager.getWagon( repo );
91 getLog().info( "[MAVEN-CORE-IT-LOG] " + wagon );
92
93 loaderProperties.setProperty( url + ".hash", Integer.toString( System.identityHashCode( wagon ) ) );
94 loaderProperties.setProperty( url + ".class", wagon.getClass().getName() );
95 }
96 catch ( Exception e )
97 {
98 getLog().warn( "[MAVEN-CORE-IT-LOG] Failed to lookp up wagon for URL " + url, e );
99 }
100 }
101 }
102
103 getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + outputFile );
104
105 OutputStream out = null;
106 try
107 {
108 outputFile.getParentFile().mkdirs();
109 out = new FileOutputStream( outputFile );
110 loaderProperties.store( out, "MAVEN-CORE-IT-LOG" );
111 }
112 catch ( IOException e )
113 {
114 throw new MojoExecutionException( "Output file could not be created: " + outputFile, e );
115 }
116 finally
117 {
118 if ( out != null )
119 {
120 try
121 {
122 out.close();
123 }
124 catch ( IOException e )
125 {
126
127 }
128 }
129 }
130
131 getLog().info( "[MAVEN-CORE-IT-LOG] Created output file " + outputFile );
132 }
133
134 }