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