1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 package org.codehaus.mojo.jaxws;
38
39 import java.io.File;
40 import java.io.IOException;
41 import org.apache.maven.model.Plugin;
42 import org.apache.maven.model.PluginExecution;
43 import org.apache.maven.plugin.MojoExecutionException;
44 import org.apache.maven.plugin.MojoFailureException;
45 import org.apache.maven.plugins.annotations.LifecyclePhase;
46 import org.apache.maven.plugins.annotations.Mojo;
47 import org.apache.maven.plugins.annotations.Parameter;
48 import org.apache.maven.plugins.annotations.ResolutionScope;
49 import org.codehaus.plexus.util.FileUtils;
50 import org.codehaus.plexus.util.xml.Xpp3Dom;
51
52
53
54
55
56 @Mojo( name = "wsgen", defaultPhase = LifecyclePhase.PROCESS_CLASSES,
57 requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true )
58 public class MainWsGenMojo
59 extends AbstractWsGenMojo
60 {
61
62
63
64
65
66 @Parameter( defaultValue = "${project.build.outputDirectory}" )
67 private File destDir;
68
69
70
71
72 @Parameter( defaultValue = "${project.build.directory}/generated-sources/wsgen" )
73 private File sourceDestDir;
74
75
76
77
78 @Parameter( defaultValue = "${project.build.directory}/generated-sources/wsdl" )
79 private File resourceDestDir;
80
81
82
83
84 @Override
85 protected File getDestDir()
86 {
87 return destDir;
88 }
89
90 @Override
91 protected File getSourceDestDir()
92 {
93 return sourceDestDir;
94 }
95
96 @Override
97 protected File getResourceDestDir()
98 {
99 return resourceDestDir;
100 }
101
102 @Override
103 protected File getDefaultSrcOut()
104 {
105 return new File( project.getBuild().getDirectory(), "generated-sources/wsgen" );
106 }
107
108 @Override
109 protected File getClassesDir()
110 {
111 return new File( project.getBuild().getOutputDirectory() );
112 }
113
114 @Override
115 public void executeJaxws()
116 throws MojoExecutionException, MojoFailureException
117 {
118 super.executeJaxws();
119 if ( genWsdl )
120 {
121 try
122 {
123 attachWsdl();
124 }
125 catch ( IOException ex )
126 {
127 throw new MojoExecutionException( "Failed to execute wsgen", ex );
128 }
129 }
130
131 }
132
133 private void attachWsdl()
134 throws IOException
135 {
136 File target = new File( project.getBuild().getDirectory() );
137 if ( !"war".equalsIgnoreCase( project.getPackaging() ) )
138 {
139
140 target = new File( project.getBuild().getOutputDirectory(), "META-INF/wsdl" );
141 }
142 else
143 {
144
145 String targetPath = null;
146 Plugin war = project.getBuild().getPluginsAsMap().get( "org.apache.maven.plugins:maven-war-plugin" );
147 for ( PluginExecution exec : war.getExecutions() )
148 {
149
150 String s = getWebappDirectory( exec.getConfiguration() );
151 if ( s != null )
152 {
153 targetPath = s;
154 break;
155 }
156 }
157 if ( targetPath == null )
158 {
159
160 targetPath = getWebappDirectory( war.getConfiguration() );
161 }
162 target =
163 targetPath != null ? new File( targetPath ) : new File( target, project.getBuild().getFinalName() );
164 target = new File( target, "WEB-INF/wsdl" );
165 }
166 if ( !target.mkdirs() && !target.exists() )
167 {
168 getLog().warn( "Cannot create directory: " + target.getAbsolutePath() );
169 }
170 getLog().debug( "Packaging WSDL(s) to: " + target );
171 FileUtils.copyDirectory( getResourceDestDir(), target );
172 }
173
174 private String getWebappDirectory( Object conf )
175 {
176 if ( conf == null )
177 {
178 return null;
179 }
180 Xpp3Dom el = ( (Xpp3Dom) conf ).getChild( "webappDirectory" );
181 return el != null ? el.getValue() : null;
182 }
183 }