author | aefimov |
Thu, 16 Feb 2017 13:14:39 +0300 | |
changeset 43852 | 93a527059d8a |
parent 42124 | 640a383428fb |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
43852
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
2 |
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.internal.ws.wscompile; |
|
27 |
||
28 |
import com.sun.codemodel.internal.CodeWriter; |
|
29 |
import com.sun.codemodel.internal.writer.ProgressCodeWriter; |
|
16791 | 30 |
import com.sun.istack.internal.tools.DefaultAuthenticator; |
12009 | 31 |
import com.sun.tools.internal.ws.ToolVersion; |
32 |
import com.sun.tools.internal.ws.api.TJavaGeneratorExtension; |
|
33 |
import com.sun.tools.internal.ws.processor.generator.CustomExceptionGenerator; |
|
34 |
import com.sun.tools.internal.ws.processor.generator.GeneratorBase; |
|
35 |
import com.sun.tools.internal.ws.processor.generator.SeiGenerator; |
|
36 |
import com.sun.tools.internal.ws.processor.generator.ServiceGenerator; |
|
37 |
import com.sun.tools.internal.ws.processor.generator.JwsImplGenerator; |
|
38 |
import com.sun.tools.internal.ws.processor.model.Model; |
|
39 |
import com.sun.tools.internal.ws.processor.modeler.wsdl.ConsoleErrorReporter; |
|
40 |
import com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler; |
|
41 |
import com.sun.tools.internal.ws.processor.util.DirectoryUtil; |
|
42 |
import com.sun.tools.internal.ws.resources.WscompileMessages; |
|
43 |
import com.sun.tools.internal.ws.resources.WsdlMessages; |
|
44 |
import com.sun.tools.internal.ws.util.WSDLFetcher; |
|
45 |
import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder; |
|
46 |
import com.sun.tools.internal.ws.wsdl.parser.WSDLInternalizationLogic; |
|
47 |
import com.sun.tools.internal.xjc.util.NullStream; |
|
48 |
import com.sun.xml.internal.ws.api.server.Container; |
|
49 |
import com.sun.xml.internal.ws.util.ServiceFinder; |
|
50 |
import org.xml.sax.EntityResolver; |
|
51 |
import org.xml.sax.SAXParseException; |
|
52 |
||
53 |
import javax.xml.stream.*; |
|
54 |
import java.io.*; |
|
55 |
import java.util.*; |
|
16791 | 56 |
import java.text.MessageFormat; |
12009 | 57 |
import java.util.jar.JarEntry; |
58 |
import java.util.jar.JarOutputStream; |
|
16791 | 59 |
import org.xml.sax.Locator; |
12009 | 60 |
import org.xml.sax.SAXException; |
61 |
||
62 |
/** |
|
63 |
* @author Vivek Pandey |
|
64 |
*/ |
|
65 |
public class WsimportTool { |
|
42124
640a383428fb
8164479: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
40297
diff
changeset
|
66 |
/** JAXWS module name. JAXWS dependency is mandatory in generated Java module. */ |
640a383428fb
8164479: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
40297
diff
changeset
|
67 |
private static final String JAXWS_MODULE = "java.xml.ws"; |
640a383428fb
8164479: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
40297
diff
changeset
|
68 |
|
12009 | 69 |
private static final String WSIMPORT = "wsimport"; |
70 |
private final PrintStream out; |
|
71 |
private final Container container; |
|
72 |
||
73 |
/** |
|
74 |
* Wsimport specific options |
|
75 |
*/ |
|
76 |
protected WsimportOptions options = new WsimportOptions(); |
|
77 |
||
78 |
public WsimportTool(OutputStream out) { |
|
79 |
this(out, null); |
|
80 |
} |
|
81 |
||
82 |
public WsimportTool(OutputStream logStream, Container container) { |
|
83 |
this.out = (logStream instanceof PrintStream)?(PrintStream)logStream:new PrintStream(logStream); |
|
84 |
this.container = container; |
|
85 |
} |
|
86 |
||
87 |
protected class Listener extends WsimportListener { |
|
88 |
ConsoleErrorReporter cer = new ConsoleErrorReporter(out == null ? new PrintStream(new NullStream()) : out); |
|
89 |
||
90 |
@Override |
|
91 |
public void generatedFile(String fileName) { |
|
92 |
message(fileName); |
|
93 |
} |
|
94 |
||
95 |
@Override |
|
96 |
public void message(String msg) { |
|
97 |
out.println(msg); |
|
98 |
} |
|
99 |
||
100 |
@Override |
|
101 |
public void error(SAXParseException exception) { |
|
102 |
cer.error(exception); |
|
103 |
} |
|
104 |
||
105 |
@Override |
|
106 |
public void fatalError(SAXParseException exception) { |
|
107 |
cer.fatalError(exception); |
|
108 |
} |
|
109 |
||
110 |
@Override |
|
111 |
public void warning(SAXParseException exception) { |
|
112 |
cer.warning(exception); |
|
113 |
} |
|
114 |
||
115 |
@Override |
|
116 |
public void debug(SAXParseException exception) { |
|
117 |
cer.debug(exception); |
|
118 |
} |
|
119 |
||
120 |
@Override |
|
121 |
public void info(SAXParseException exception) { |
|
122 |
cer.info(exception); |
|
123 |
} |
|
124 |
||
125 |
public void enableDebugging(){ |
|
126 |
cer.enableDebugging(); |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
protected class Receiver extends ErrorReceiverFilter { |
|
131 |
||
132 |
private Listener listener; |
|
133 |
||
134 |
public Receiver(Listener listener) { |
|
135 |
super(listener); |
|
136 |
this.listener = listener; |
|
137 |
} |
|
138 |
||
16791 | 139 |
@Override |
12009 | 140 |
public void info(SAXParseException exception) { |
141 |
if (options.verbose) |
|
142 |
super.info(exception); |
|
143 |
} |
|
144 |
||
16791 | 145 |
@Override |
12009 | 146 |
public void warning(SAXParseException exception) { |
147 |
if (!options.quiet) |
|
148 |
super.warning(exception); |
|
149 |
} |
|
150 |
||
151 |
@Override |
|
152 |
public void pollAbort() throws AbortException { |
|
153 |
if (listener.isCanceled()) |
|
154 |
throw new AbortException(); |
|
155 |
} |
|
156 |
||
157 |
@Override |
|
158 |
public void debug(SAXParseException exception){ |
|
159 |
if(options.debugMode){ |
|
160 |
listener.debug(exception); |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
||
165 |
public boolean run(String[] args) { |
|
166 |
Listener listener = new Listener(); |
|
167 |
Receiver receiver = new Receiver(listener); |
|
168 |
return run(args, listener, receiver); |
|
169 |
} |
|
170 |
||
171 |
protected boolean run(String[] args, Listener listener, |
|
172 |
Receiver receiver) { |
|
173 |
for (String arg : args) { |
|
174 |
if (arg.equals("-version")) { |
|
175 |
listener.message( |
|
176 |
WscompileMessages.WSIMPORT_VERSION(ToolVersion.VERSION.MAJOR_VERSION)); |
|
177 |
return true; |
|
178 |
} |
|
179 |
if (arg.equals("-fullversion")) { |
|
180 |
listener.message( |
|
181 |
WscompileMessages.WSIMPORT_FULLVERSION(ToolVersion.VERSION.toString())); |
|
182 |
return true; |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
try { |
|
187 |
parseArguments(args, listener, receiver); |
|
188 |
||
189 |
try { |
|
190 |
Model wsdlModel = buildWsdlModel(listener, receiver); |
|
191 |
if (wsdlModel == null) |
|
192 |
return false; |
|
193 |
||
194 |
if (!generateCode(listener, receiver, wsdlModel, true)) |
|
195 |
return false; |
|
196 |
||
197 |
/* Not so fast! |
|
198 |
} catch(AbortException e){ |
|
199 |
//error might have been reported |
|
200 |
* |
|
201 |
*/ |
|
202 |
}catch (IOException e) { |
|
203 |
receiver.error(e); |
|
204 |
return false; |
|
205 |
}catch (XMLStreamException e) { |
|
206 |
receiver.error(e); |
|
207 |
return false; |
|
208 |
} |
|
209 |
if (!options.nocompile){ |
|
210 |
if(!compileGeneratedClasses(receiver, listener)){ |
|
211 |
listener.message(WscompileMessages.WSCOMPILE_COMPILATION_FAILED()); |
|
212 |
return false; |
|
213 |
} |
|
214 |
} |
|
215 |
try { |
|
216 |
if (options.clientjar != null) { |
|
217 |
//add all the generated class files to the list of generated files |
|
218 |
addClassesToGeneratedFiles(); |
|
219 |
jarArtifacts(listener); |
|
220 |
||
221 |
} |
|
222 |
} catch (IOException e) { |
|
223 |
receiver.error(e); |
|
224 |
return false; |
|
225 |
} |
|
226 |
||
227 |
} catch (Options.WeAreDone done) { |
|
228 |
usage(done.getOptions()); |
|
229 |
} catch (BadCommandLineException e) { |
|
230 |
if (e.getMessage() != null) { |
|
231 |
System.out.println(e.getMessage()); |
|
232 |
System.out.println(); |
|
233 |
} |
|
234 |
usage(e.getOptions()); |
|
235 |
return false; |
|
236 |
} finally{ |
|
237 |
deleteGeneratedFiles(); |
|
238 |
if (!options.disableAuthenticator) { |
|
16791 | 239 |
DefaultAuthenticator.reset(); |
12009 | 240 |
} |
241 |
} |
|
242 |
if(receiver.hadError()) { |
|
243 |
return false; |
|
244 |
} |
|
245 |
return true; |
|
246 |
} |
|
247 |
||
248 |
private void deleteGeneratedFiles() { |
|
43852
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
249 |
Set<File> trackedRootPackages = new HashSet<>(); |
12009 | 250 |
|
251 |
if (options.clientjar != null) { |
|
252 |
//remove all non-java artifacts as they will packaged in jar. |
|
253 |
Iterable<File> generatedFiles = options.getGeneratedFiles(); |
|
254 |
synchronized (generatedFiles) { |
|
255 |
for (File file : generatedFiles) { |
|
256 |
if (!file.getName().endsWith(".java")) { |
|
16791 | 257 |
boolean deleted = file.delete(); |
258 |
if (options.verbose && !deleted) { |
|
259 |
System.out.println(MessageFormat.format("{0} could not be deleted.", file)); |
|
260 |
} |
|
12009 | 261 |
trackedRootPackages.add(file.getParentFile()); |
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
//remove empty package dirs |
|
266 |
for(File pkg:trackedRootPackages) { |
|
267 |
||
268 |
while(pkg.list() != null && pkg.list().length ==0 && !pkg.equals(options.destDir)) { |
|
269 |
File parentPkg = pkg.getParentFile(); |
|
16791 | 270 |
boolean deleted = pkg.delete(); |
271 |
if (options.verbose && !deleted) { |
|
272 |
System.out.println(MessageFormat.format("{0} could not be deleted.", pkg)); |
|
273 |
} |
|
12009 | 274 |
pkg = parentPkg; |
275 |
} |
|
276 |
} |
|
277 |
} |
|
278 |
if(!options.keep) { |
|
279 |
options.removeGeneratedFiles(); |
|
280 |
} |
|
281 |
} |
|
282 |
||
283 |
private void addClassesToGeneratedFiles() throws IOException { |
|
284 |
Iterable<File> generatedFiles = options.getGeneratedFiles(); |
|
43852
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
285 |
final List<File> trackedClassFiles = new ArrayList<>(); |
12009 | 286 |
for(File f: generatedFiles) { |
287 |
if(f.getName().endsWith(".java")) { |
|
288 |
String relativeDir = DirectoryUtil.getRelativePathfromCommonBase(f.getParentFile(),options.sourceDir); |
|
289 |
final String className = f.getName().substring(0,f.getName().indexOf(".java")); |
|
290 |
File classDir = new File(options.destDir,relativeDir); |
|
291 |
if(classDir.exists()) { |
|
292 |
classDir.listFiles(new FilenameFilter() { |
|
16791 | 293 |
@Override |
12009 | 294 |
public boolean accept(File dir, String name) { |
295 |
if(name.equals(className+".class") || (name.startsWith(className+"$") && name.endsWith(".class"))) { |
|
296 |
trackedClassFiles.add(new File(dir,name)); |
|
297 |
return true; |
|
298 |
} |
|
299 |
return false; |
|
300 |
} |
|
301 |
}); |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
305 |
for(File f: trackedClassFiles) { |
|
306 |
options.addGeneratedFile(f); |
|
307 |
} |
|
308 |
} |
|
309 |
||
310 |
private void jarArtifacts(WsimportListener listener) throws IOException { |
|
311 |
File zipFile = new File(options.clientjar); |
|
312 |
if(!zipFile.isAbsolute()) { |
|
313 |
zipFile = new File(options.destDir, options.clientjar); |
|
314 |
} |
|
315 |
||
16791 | 316 |
FileOutputStream fos; |
317 |
if (!options.quiet) { |
|
318 |
listener.message(WscompileMessages.WSIMPORT_ARCHIVING_ARTIFACTS(zipFile)); |
|
12009 | 319 |
} |
320 |
||
16791 | 321 |
BufferedInputStream bis = null; |
322 |
FileInputStream fi = null; |
|
12009 | 323 |
fos = new FileOutputStream(zipFile); |
324 |
JarOutputStream jos = new JarOutputStream(fos); |
|
16791 | 325 |
try { |
326 |
String base = options.destDir.getCanonicalPath(); |
|
327 |
for(File f: options.getGeneratedFiles()) { |
|
328 |
//exclude packaging the java files in the jar |
|
329 |
if(f.getName().endsWith(".java")) { |
|
330 |
continue; |
|
331 |
} |
|
332 |
if(options.verbose) { |
|
333 |
listener.message(WscompileMessages.WSIMPORT_ARCHIVE_ARTIFACT(f, options.clientjar)); |
|
334 |
} |
|
20591
6e54991851d5
8016271: wsimport -clientjar does not create portable jars on Windows due to hardcoded backslash
coffeys
parents:
20590
diff
changeset
|
335 |
String entry = f.getCanonicalPath().substring(base.length()+1).replace(File.separatorChar, '/'); |
16791 | 336 |
fi = new FileInputStream(f); |
337 |
bis = new BufferedInputStream(fi); |
|
338 |
JarEntry jarEntry = new JarEntry(entry); |
|
339 |
jos.putNextEntry(jarEntry); |
|
340 |
int bytesRead; |
|
341 |
byte[] buffer = new byte[1024]; |
|
342 |
while ((bytesRead = bis.read(buffer)) != -1) { |
|
343 |
jos.write(buffer, 0, bytesRead); |
|
344 |
} |
|
12009 | 345 |
} |
16791 | 346 |
} finally { |
347 |
try { |
|
348 |
if (bis != null) { |
|
349 |
bis.close(); |
|
350 |
} |
|
351 |
} finally { |
|
352 |
if (jos != null) { |
|
353 |
jos.close(); |
|
354 |
} |
|
355 |
if (fi != null) { |
|
356 |
fi.close(); |
|
357 |
} |
|
12009 | 358 |
} |
359 |
} |
|
360 |
} |
|
361 |
||
362 |
protected void parseArguments(String[] args, Listener listener, |
|
363 |
Receiver receiver) throws BadCommandLineException { |
|
364 |
options.parseArguments(args); |
|
365 |
options.validate(); |
|
366 |
if (options.debugMode) |
|
367 |
listener.enableDebugging(); |
|
368 |
options.parseBindings(receiver); |
|
369 |
} |
|
370 |
||
16791 | 371 |
protected Model buildWsdlModel(Listener listener, final Receiver receiver) |
372 |
throws BadCommandLineException, XMLStreamException, IOException { |
|
12009 | 373 |
//set auth info |
374 |
//if(options.authFile != null) |
|
375 |
if (!options.disableAuthenticator) { |
|
16791 | 376 |
class AuthListener implements DefaultAuthenticator.Receiver { |
377 |
||
378 |
private final boolean isFatal; |
|
379 |
||
380 |
AuthListener(boolean isFatal) { |
|
381 |
this.isFatal = isFatal; |
|
382 |
} |
|
383 |
||
384 |
@Override |
|
385 |
public void onParsingError(String text, Locator loc) { |
|
386 |
error(new SAXParseException(WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(text), loc)); |
|
387 |
} |
|
388 |
||
389 |
@Override |
|
390 |
public void onError(Exception e, Locator loc) { |
|
391 |
if (e instanceof FileNotFoundException) { |
|
392 |
error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_FILE_NOT_FOUND( |
|
393 |
loc.getSystemId(), WsimportOptions.defaultAuthfile), null)); |
|
394 |
} else { |
|
395 |
error(new SAXParseException(WscompileMessages.WSIMPORT_FAILED_TO_PARSE(loc.getSystemId(),e.getMessage()), loc)); |
|
396 |
} |
|
397 |
} |
|
398 |
||
399 |
private void error(SAXParseException e) { |
|
400 |
if (isFatal) { |
|
401 |
receiver.error(e); |
|
402 |
} else { |
|
403 |
receiver.debug(e); |
|
404 |
} |
|
405 |
} |
|
406 |
} |
|
407 |
||
408 |
DefaultAuthenticator da = DefaultAuthenticator.getAuthenticator(); |
|
409 |
if (options.proxyAuth != null) { |
|
410 |
da.setProxyAuth(options.proxyAuth); |
|
411 |
} |
|
412 |
if (options.authFile != null) { |
|
413 |
da.setAuth(options.authFile, new AuthListener(true)); |
|
414 |
} else { |
|
415 |
da.setAuth(new File(WsimportOptions.defaultAuthfile), new AuthListener(false)); |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
if (!options.quiet) { |
|
420 |
listener.message(WscompileMessages.WSIMPORT_PARSING_WSDL()); |
|
12009 | 421 |
} |
422 |
||
423 |
MetadataFinder forest = new MetadataFinder(new WSDLInternalizationLogic(), options, receiver); |
|
424 |
forest.parseWSDL(); |
|
425 |
if (forest.isMexMetadata) |
|
426 |
receiver.reset(); |
|
427 |
||
428 |
WSDLModeler wsdlModeler = new WSDLModeler(options, receiver,forest); |
|
429 |
Model wsdlModel = wsdlModeler.buildModel(); |
|
430 |
if (wsdlModel == null) { |
|
431 |
listener.message(WsdlMessages.PARSING_PARSE_FAILED()); |
|
432 |
} |
|
433 |
||
434 |
if(options.clientjar != null) { |
|
435 |
if( !options.quiet ) |
|
436 |
listener.message(WscompileMessages.WSIMPORT_FETCHING_METADATA()); |
|
437 |
options.wsdlLocation = new WSDLFetcher(options,listener).fetchWsdls(forest); |
|
438 |
} |
|
439 |
||
440 |
return wsdlModel; |
|
441 |
} |
|
442 |
||
443 |
protected boolean generateCode(Listener listener, Receiver receiver, |
|
444 |
Model wsdlModel, boolean generateService) |
|
445 |
throws IOException { |
|
446 |
//generated code |
|
447 |
if( !options.quiet ) |
|
448 |
listener.message(WscompileMessages.WSIMPORT_GENERATING_CODE()); |
|
449 |
||
450 |
TJavaGeneratorExtension[] genExtn = ServiceFinder.find(TJavaGeneratorExtension.class).toArray(); |
|
451 |
CustomExceptionGenerator.generate(wsdlModel, options, receiver); |
|
452 |
SeiGenerator.generate(wsdlModel, options, receiver, genExtn); |
|
453 |
if(receiver.hadError()){ |
|
454 |
throw new AbortException(); |
|
455 |
} |
|
456 |
if (generateService) |
|
457 |
{ |
|
458 |
ServiceGenerator.generate(wsdlModel, options, receiver); |
|
459 |
} |
|
460 |
for (GeneratorBase g : ServiceFinder.find(GeneratorBase.class)) { |
|
461 |
g.init(wsdlModel, options, receiver); |
|
462 |
g.doGeneration(); |
|
463 |
} |
|
464 |
||
465 |
List<String> implFiles = null; |
|
466 |
if (options.isGenerateJWS) { |
|
467 |
implFiles = JwsImplGenerator.generate(wsdlModel, options, receiver); |
|
468 |
} |
|
469 |
||
470 |
for (Plugin plugin: options.activePlugins) { |
|
471 |
try { |
|
472 |
plugin.run(wsdlModel, options, receiver); |
|
473 |
} catch (SAXException sex) { |
|
474 |
// fatal error. error should have been reported |
|
475 |
return false; |
|
476 |
} |
|
477 |
} |
|
478 |
||
42124
640a383428fb
8164479: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
40297
diff
changeset
|
479 |
if (options.getModuleName() != null) { |
640a383428fb
8164479: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
40297
diff
changeset
|
480 |
options.getCodeModel()._prepareModuleInfo(options.getModuleName(), JAXWS_MODULE); |
640a383428fb
8164479: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
40297
diff
changeset
|
481 |
} |
640a383428fb
8164479: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
40297
diff
changeset
|
482 |
|
12009 | 483 |
CodeWriter cw; |
484 |
if (options.filer != null) { |
|
42124
640a383428fb
8164479: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
40297
diff
changeset
|
485 |
cw = new FilerCodeWriter(options); |
12009 | 486 |
} else { |
487 |
cw = new WSCodeWriter(options.sourceDir, options); |
|
488 |
} |
|
489 |
||
490 |
if (options.verbose) |
|
491 |
cw = new ProgressCodeWriter(cw, out); |
|
492 |
options.getCodeModel().build(cw); |
|
493 |
||
494 |
if (options.isGenerateJWS) { |
|
495 |
//move Impl files to implDestDir |
|
496 |
return JwsImplGenerator.moveToImplDestDir(implFiles, options, receiver); |
|
497 |
} |
|
498 |
||
499 |
return true; |
|
500 |
} |
|
501 |
||
502 |
public void setEntityResolver(EntityResolver resolver){ |
|
503 |
this.options.entityResolver = resolver; |
|
504 |
} |
|
505 |
||
506 |
protected boolean compileGeneratedClasses(ErrorReceiver receiver, WsimportListener listener){ |
|
43852
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
507 |
List<String> sourceFiles = new ArrayList<>(); |
12009 | 508 |
|
509 |
for (File f : options.getGeneratedFiles()) { |
|
510 |
if (f.exists() && f.getName().endsWith(".java")) { |
|
511 |
sourceFiles.add(f.getAbsolutePath()); |
|
512 |
} |
|
513 |
} |
|
514 |
||
515 |
if (sourceFiles.size() > 0) { |
|
516 |
String classDir = options.destDir.getAbsolutePath(); |
|
517 |
String classpathString = createClasspathString(); |
|
43852
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
518 |
List<String> args = new ArrayList<>(); |
42124
640a383428fb
8164479: Update JAX-WS RI integration to latest version (2.3.0-SNAPSHOT)
aefimov
parents:
40297
diff
changeset
|
519 |
|
20590
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
520 |
args.add("-d"); |
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
521 |
args.add(classDir); |
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
522 |
args.add("-classpath"); |
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
523 |
args.add(classpathString); |
12009 | 524 |
|
525 |
if (options.debug) { |
|
20590
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
526 |
args.add("-g"); |
12009 | 527 |
} |
528 |
||
529 |
if (options.encoding != null) { |
|
20590
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
530 |
args.add("-encoding"); |
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
531 |
args.add(options.encoding); |
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
532 |
} |
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
533 |
|
43852
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
534 |
boolean addModules = true; |
20590
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
535 |
if (options.javacOptions != null) { |
43852
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
536 |
List<String> javacOptions = options.getJavacOptions(args, listener); |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
537 |
for (int i = 0; i < javacOptions.size(); i++) { |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
538 |
String opt = javacOptions.get(i); |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
539 |
if ("-source".equals(opt) && 9 >= getVersion(javacOptions.get(i + 1))) { |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
540 |
addModules = false; |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
541 |
} |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
542 |
if ("-target".equals(opt) && 9 >= getVersion(javacOptions.get(i + 1))) { |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
543 |
addModules = false; |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
544 |
} |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
545 |
if ("--release".equals(opt) && 9 >= getVersion(javacOptions.get(i + 1))) { |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
546 |
addModules = false; |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
547 |
} |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
548 |
args.add(opt); |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
549 |
} |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
550 |
} |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
551 |
if (addModules) { |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
552 |
args.add("--add-modules"); |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
553 |
args.add("java.xml.ws"); |
12009 | 554 |
} |
555 |
||
556 |
for (int i = 0; i < sourceFiles.size(); ++i) { |
|
20590
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
557 |
args.add(sourceFiles.get(i)); |
12009 | 558 |
} |
559 |
||
27837
86d4f46e622a
8065870: Update JAX-WS RI integration to latest version (2.2.11-b141124.1933)
mkos
parents:
25871
diff
changeset
|
560 |
if (!options.quiet) listener.message(WscompileMessages.WSIMPORT_COMPILING_CODE()); |
86d4f46e622a
8065870: Update JAX-WS RI integration to latest version (2.2.11-b141124.1933)
mkos
parents:
25871
diff
changeset
|
561 |
|
12009 | 562 |
if(options.verbose){ |
16791 | 563 |
StringBuilder argstr = new StringBuilder(); |
12009 | 564 |
for(String arg:args){ |
565 |
argstr.append(arg).append(" "); |
|
566 |
} |
|
567 |
listener.message("javac "+ argstr.toString()); |
|
568 |
} |
|
569 |
||
20590
b3b34e4344ce
8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
mkos
parents:
16791
diff
changeset
|
570 |
return JavaCompilerHelper.compile(args.toArray(new String[args.size()]), out, receiver); |
12009 | 571 |
} |
572 |
//there are no files to compile, so return true? |
|
573 |
return true; |
|
574 |
} |
|
575 |
||
576 |
private String createClasspathString() { |
|
577 |
StringBuilder classpathStr = new StringBuilder(System.getProperty("java.class.path")); |
|
578 |
for(String s: options.cmdlineJars) { |
|
579 |
classpathStr.append(File.pathSeparator); |
|
580 |
classpathStr.append(new File(s).toString()); |
|
581 |
} |
|
582 |
return classpathStr.toString(); |
|
583 |
} |
|
584 |
||
585 |
protected void usage(Options options) { |
|
586 |
System.out.println(WscompileMessages.WSIMPORT_HELP(WSIMPORT)); |
|
587 |
System.out.println(WscompileMessages.WSIMPORT_USAGE_EXTENSIONS()); |
|
588 |
System.out.println(WscompileMessages.WSIMPORT_USAGE_EXAMPLES()); |
|
589 |
} |
|
43852
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
590 |
|
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
591 |
private float getVersion(String s) { |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
592 |
return Float.parseFloat(s); |
93a527059d8a
8174735: Update JAX-WS RI integration to latest version
aefimov
parents:
42124
diff
changeset
|
593 |
} |
12009 | 594 |
} |