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.plugin.AbstractMojo;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25
26 import java.io.File;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29 import java.io.OutputStream;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Properties;
33
34
35
36
37
38
39
40
41 public class DumpRepoLayoutsMojo
42 extends AbstractMojo
43 {
44
45
46
47
48
49
50
51 private File basedir;
52
53
54
55
56
57
58 private Map repositoryLayouts;
59
60
61
62
63
64
65 private List repoLayouts;
66
67
68
69
70
71
72 private File layoutsFile;
73
74
75
76
77
78
79 public void execute()
80 throws MojoExecutionException, MojoFailureException
81 {
82 Properties layoutProperties = new Properties();
83
84 getLog().info( "[MAVEN-CORE-IT-LOG] Dumping repository layouts" );
85
86 layoutProperties.setProperty( "layouts", Integer.toString( repositoryLayouts.size() ) );
87
88 for ( Object o : repositoryLayouts.keySet() )
89 {
90 String roleHint = (String) o;
91 Object repoLayout = repositoryLayouts.get( roleHint );
92 if ( repoLayout != null )
93 {
94 layoutProperties.setProperty( "layouts." + roleHint, repoLayout.getClass().getName() );
95 }
96 else
97 {
98 layoutProperties.setProperty( "layouts." + roleHint, "" );
99 }
100 getLog().info( "[MAVEN-CORE-IT-LOG] " + roleHint + " = " + repoLayout );
101 }
102
103 if ( repoLayouts.size() != repositoryLayouts.size() )
104 {
105 throw new MojoExecutionException( "Inconsistent collection: " + repoLayouts + " vs " + repositoryLayouts );
106 }
107
108 if ( !layoutsFile.isAbsolute() )
109 {
110 layoutsFile = new File( basedir, layoutsFile.getPath() );
111 }
112
113 getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + layoutsFile );
114
115 OutputStream out = null;
116 try
117 {
118 layoutsFile.getParentFile().mkdirs();
119 out = new FileOutputStream( layoutsFile );
120 layoutProperties.store( out, "MAVEN-CORE-IT-LOG" );
121 }
122 catch ( IOException e )
123 {
124 throw new MojoExecutionException( "Output file could not be created: " + layoutsFile, e );
125 }
126 finally
127 {
128 if ( out != null )
129 {
130 try
131 {
132 out.close();
133 }
134 catch ( IOException e )
135 {
136
137 }
138 }
139 }
140
141 getLog().info( "[MAVEN-CORE-IT-LOG] Created output file " + layoutsFile );
142 }
143
144 }