src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/WsimportTool.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   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;

  30 import com.sun.tools.internal.ws.ToolVersion;
  31 import com.sun.tools.internal.ws.api.TJavaGeneratorExtension;
  32 import com.sun.tools.internal.ws.processor.generator.CustomExceptionGenerator;
  33 import com.sun.tools.internal.ws.processor.generator.GeneratorBase;
  34 import com.sun.tools.internal.ws.processor.generator.SeiGenerator;
  35 import com.sun.tools.internal.ws.processor.generator.ServiceGenerator;
  36 import com.sun.tools.internal.ws.processor.generator.JwsImplGenerator;
  37 import com.sun.tools.internal.ws.processor.model.Model;
  38 import com.sun.tools.internal.ws.processor.modeler.wsdl.ConsoleErrorReporter;
  39 import com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler;
  40 import com.sun.tools.internal.ws.processor.util.DirectoryUtil;
  41 import com.sun.tools.internal.ws.resources.WscompileMessages;
  42 import com.sun.tools.internal.ws.resources.WsdlMessages;
  43 import com.sun.tools.internal.ws.util.WSDLFetcher;
  44 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
  45 import com.sun.tools.internal.ws.wsdl.parser.WSDLInternalizationLogic;
  46 import com.sun.tools.internal.xjc.util.NullStream;
  47 import com.sun.xml.internal.ws.api.server.Container;
  48 import com.sun.xml.internal.ws.util.ServiceFinder;
  49 import com.sun.istack.internal.tools.ParallelWorldClassLoader;
  50 import org.xml.sax.EntityResolver;
  51 import org.xml.sax.SAXParseException;
  52 
  53 import javax.xml.bind.JAXBPermission;
  54 import javax.xml.stream.*;
  55 import javax.xml.ws.EndpointContext;
  56 import java.io.*;
  57 import java.util.*;
  58 import java.net.Authenticator;
  59 import java.util.jar.JarEntry;
  60 import java.util.jar.JarOutputStream;

  61 import org.xml.sax.SAXException;
  62 
  63 /**
  64  * @author Vivek Pandey
  65  */
  66 public class WsimportTool {
  67     private static final String WSIMPORT = "wsimport";
  68     private final PrintStream out;
  69     private final Container container;
  70 
  71     /**
  72      * Wsimport specific options
  73      */
  74     protected WsimportOptions options = new WsimportOptions();
  75 
  76     public WsimportTool(OutputStream out) {
  77         this(out, null);
  78     }
  79 
  80     public WsimportTool(OutputStream logStream, Container container) {


 117 
 118         @Override
 119         public void info(SAXParseException exception) {
 120             cer.info(exception);
 121         }
 122 
 123         public void enableDebugging(){
 124             cer.enableDebugging();
 125         }
 126     }
 127 
 128     protected class Receiver extends ErrorReceiverFilter {
 129 
 130         private Listener listener;
 131 
 132         public Receiver(Listener listener) {
 133             super(listener);
 134             this.listener = listener;
 135         }
 136 

 137         public void info(SAXParseException exception) {
 138             if (options.verbose)
 139                 super.info(exception);
 140         }
 141 

 142         public void warning(SAXParseException exception) {
 143             if (!options.quiet)
 144                 super.warning(exception);
 145         }
 146 
 147         @Override
 148         public void pollAbort() throws AbortException {
 149             if (listener.isCanceled())
 150                 throw new AbortException();
 151         }
 152 
 153         @Override
 154         public void debug(SAXParseException exception){
 155             if(options.debugMode){
 156                 listener.debug(exception);
 157             }
 158         }
 159     }
 160 
 161     public boolean run(String[] args) {
 162         Listener listener = new Listener();
 163         Receiver receiver = new Receiver(listener);
 164         return run(args, listener, receiver);
 165     }
 166 
 167     protected boolean run(String[] args, Listener listener,
 168                        Receiver receiver) {
 169         for (String arg : args) {
 170             if (arg.equals("-version")) {
 171                 listener.message(
 172                         WscompileMessages.WSIMPORT_VERSION(ToolVersion.VERSION.MAJOR_VERSION));
 173                 return true;
 174             }
 175             if (arg.equals("-fullversion")) {
 176                 listener.message(
 177                         WscompileMessages.WSIMPORT_FULLVERSION(ToolVersion.VERSION.toString()));
 178                 return true;
 179             }
 180         }
 181 
 182         Authenticator orig = null;
 183         try {
 184             parseArguments(args, listener, receiver);
 185 
 186             try {
 187                 orig = DefaultAuthenticator.getCurrentAuthenticator();
 188 
 189                 Model wsdlModel = buildWsdlModel(listener, receiver);
 190                 if (wsdlModel == null)
 191                    return false;
 192 
 193                 if (!generateCode(listener, receiver, wsdlModel, true))
 194                    return false;
 195 
 196                 /* Not so fast!
 197             } catch(AbortException e){
 198                 //error might have been reported
 199                  *
 200                  */
 201             }catch (IOException e) {
 202                 receiver.error(e);
 203                 return false;
 204             }catch (XMLStreamException e) {
 205                 receiver.error(e);
 206                 return false;
 207             }
 208             if (!options.nocompile){


 218                     jarArtifacts(listener);
 219 
 220                 }
 221             } catch (IOException e) {
 222                 receiver.error(e);
 223                 return false;
 224             }
 225 
 226         } catch (Options.WeAreDone done) {
 227             usage(done.getOptions());
 228         } catch (BadCommandLineException e) {
 229             if (e.getMessage() != null) {
 230                 System.out.println(e.getMessage());
 231                 System.out.println();
 232             }
 233             usage(e.getOptions());
 234             return false;
 235         } finally{
 236             deleteGeneratedFiles();
 237             if (!options.disableAuthenticator) {
 238                 Authenticator.setDefault(orig);
 239             }
 240         }
 241         if(receiver.hadError()) {
 242             return false;
 243         }
 244         return true;
 245     }
 246 
 247     private void deleteGeneratedFiles() {
 248         Set<File> trackedRootPackages = new HashSet<File>();
 249 
 250         if (options.clientjar != null) {
 251             //remove all non-java artifacts as they will packaged in jar.
 252             Iterable<File> generatedFiles = options.getGeneratedFiles();
 253             synchronized (generatedFiles) {
 254                 for (File file : generatedFiles) {
 255                     if (!file.getName().endsWith(".java")) {
 256                         file.delete();



 257                         trackedRootPackages.add(file.getParentFile());
 258 
 259                     }
 260 
 261                 }
 262             }
 263             //remove empty package dirs
 264             for(File pkg:trackedRootPackages) {
 265 
 266                 while(pkg.list() != null && pkg.list().length ==0 && !pkg.equals(options.destDir)) {
 267                     File parentPkg = pkg.getParentFile();
 268                     pkg.delete();



 269                     pkg = parentPkg;
 270                 }
 271             }
 272         }
 273         if(!options.keep) {
 274             options.removeGeneratedFiles();
 275         }
 276 
 277     }
 278 
 279     private void addClassesToGeneratedFiles() throws IOException {
 280         Iterable<File> generatedFiles = options.getGeneratedFiles();
 281         final List<File> trackedClassFiles = new ArrayList<File>();
 282         for(File f: generatedFiles) {
 283             if(f.getName().endsWith(".java")) {
 284                 String relativeDir = DirectoryUtil.getRelativePathfromCommonBase(f.getParentFile(),options.sourceDir);
 285                 final String className = f.getName().substring(0,f.getName().indexOf(".java"));
 286                 File classDir = new File(options.destDir,relativeDir);
 287                 if(classDir.exists()) {
 288                     classDir.listFiles(new FilenameFilter() {
 289 
 290                         public boolean accept(File dir, String name) {
 291                             if(name.equals(className+".class") || (name.startsWith(className+"$") && name.endsWith(".class"))) {
 292                                 trackedClassFiles.add(new File(dir,name));
 293                                 return true;
 294                             }
 295                             return false;
 296                         }
 297                     });
 298                 }
 299             }
 300         }
 301         for(File f: trackedClassFiles) {
 302             options.addGeneratedFile(f);
 303         }
 304     }
 305 
 306     private void jarArtifacts(WsimportListener listener) throws IOException {
 307         File zipFile = new File(options.clientjar);
 308         if(!zipFile.isAbsolute()) {
 309             zipFile = new File(options.destDir, options.clientjar);
 310         }
 311 
 312         if (zipFile.exists()) {
 313             //TODO
 314         }
 315         FileOutputStream fos = null;
 316         if( !options.quiet )
 317             listener.message(WscompileMessages.WSIMPORT_ARCHIVING_ARTIFACTS(zipFile));

 318 
 319 

 320         fos = new FileOutputStream(zipFile);
 321         JarOutputStream jos = new JarOutputStream(fos);
 322 
 323         String base = options.destDir.getCanonicalPath();
 324         for(File f: options.getGeneratedFiles()) {
 325             //exclude packaging the java files in the jar
 326             if(f.getName().endsWith(".java")) {
 327                 continue;
 328             }
 329             if(options.verbose) {
 330                 listener.message(WscompileMessages.WSIMPORT_ARCHIVE_ARTIFACT(f, options.clientjar));
 331             }
 332             String entry = f.getCanonicalPath().substring(base.length()+1);
 333             BufferedInputStream bis = new BufferedInputStream(
 334                             new FileInputStream(f));
 335             JarEntry jarEntry = new JarEntry(entry);
 336             jos.putNextEntry(jarEntry);
 337             int bytesRead;
 338             byte[] buffer = new byte[1024];
 339             while ((bytesRead = bis.read(buffer)) != -1) {
 340                 jos.write(buffer, 0, bytesRead);
 341             }




 342             bis.close();
 343 
 344         }
 345 

 346         jos.close();
 347 





 348     }
 349 
 350     protected void parseArguments(String[] args, Listener listener,
 351                                   Receiver receiver) throws BadCommandLineException {
 352         options.parseArguments(args);
 353         options.validate();
 354         if (options.debugMode)
 355             listener.enableDebugging();
 356         options.parseBindings(receiver);
 357     }
 358 
 359     protected Model buildWsdlModel(Listener listener,
 360                                    Receiver receiver) throws BadCommandLineException, XMLStreamException, IOException {
 361         if( !options.quiet )
 362             listener.message(WscompileMessages.WSIMPORT_PARSING_WSDL());
 363 
 364         //set auth info
 365         //if(options.authFile != null)
 366         if (!options.disableAuthenticator) {
 367             Authenticator.setDefault(new DefaultAuthenticator(receiver, options.authFile));












































 368         }
 369 
 370         MetadataFinder forest = new MetadataFinder(new WSDLInternalizationLogic(), options, receiver);
 371         forest.parseWSDL();
 372         if (forest.isMexMetadata)
 373             receiver.reset();
 374 
 375         WSDLModeler wsdlModeler = new WSDLModeler(options, receiver,forest);
 376         Model wsdlModel = wsdlModeler.buildModel();
 377         if (wsdlModel == null) {
 378             listener.message(WsdlMessages.PARSING_PARSE_FAILED());
 379         }
 380 
 381         if(options.clientjar != null) {
 382             if( !options.quiet )
 383                 listener.message(WscompileMessages.WSIMPORT_FETCHING_METADATA());
 384             options.wsdlLocation = new WSDLFetcher(options,listener).fetchWsdls(forest);
 385         }
 386 
 387         return wsdlModel;


 481             //javac is not working in osgi as the url starts with a bundle
 482             if (bootCP) {
 483                 args[baseIndex++] = "-Xbootclasspath/p:"+JavaCompilerHelper.getJarFile(EndpointContext.class)+File.pathSeparator+JavaCompilerHelper.getJarFile(JAXBPermission.class);
 484             }
 485 
 486             if (options.debug) {
 487                 args[baseIndex++] = "-g";
 488             }
 489 
 490             if (options.encoding != null) {
 491                 args[baseIndex++] = "-encoding";
 492                 args[baseIndex++] = options.encoding;
 493             }
 494 
 495             for (int i = 0; i < sourceFiles.size(); ++i) {
 496                 args[baseIndex + i] = sourceFiles.get(i);
 497             }
 498 
 499             listener.message(WscompileMessages.WSIMPORT_COMPILING_CODE());
 500             if(options.verbose){
 501                 StringBuffer argstr = new StringBuffer();
 502                 for(String arg:args){
 503                     argstr.append(arg).append(" ");
 504                 }
 505                 listener.message("javac "+ argstr.toString());
 506             }
 507 
 508             return JavaCompilerHelper.compile(args, out, receiver);
 509         }
 510         //there are no files to compile, so return true?
 511         return true;
 512     }
 513 
 514     private String createClasspathString() {
 515         StringBuilder classpathStr = new StringBuilder(System.getProperty("java.class.path"));
 516         for(String s: options.cmdlineJars) {
 517             classpathStr.append(File.pathSeparator);
 518             classpathStr.append(new File(s).toString());
 519         }
 520         return classpathStr.toString();
 521     }
   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   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;
  30 import com.sun.istack.internal.tools.DefaultAuthenticator;
  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 com.sun.istack.internal.tools.ParallelWorldClassLoader;
  51 import org.xml.sax.EntityResolver;
  52 import org.xml.sax.SAXParseException;
  53 
  54 import javax.xml.bind.JAXBPermission;
  55 import javax.xml.stream.*;
  56 import javax.xml.ws.EndpointContext;
  57 import java.io.*;
  58 import java.util.*;
  59 import java.text.MessageFormat;
  60 import java.util.jar.JarEntry;
  61 import java.util.jar.JarOutputStream;
  62 import org.xml.sax.Locator;
  63 import org.xml.sax.SAXException;
  64 
  65 /**
  66  * @author Vivek Pandey
  67  */
  68 public class WsimportTool {
  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) {


 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 
 139         @Override
 140         public void info(SAXParseException exception) {
 141             if (options.verbose)
 142                 super.info(exception);
 143         }
 144 
 145         @Override
 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){


 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) {
 239                 DefaultAuthenticator.reset();
 240             }
 241         }
 242         if(receiver.hadError()) {
 243             return false;
 244         }
 245         return true;
 246     }
 247 
 248     private void deleteGeneratedFiles() {
 249         Set<File> trackedRootPackages = new HashSet<File>();
 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")) {
 257                         boolean deleted = file.delete();
 258                         if (options.verbose && !deleted) {
 259                             System.out.println(MessageFormat.format("{0} could not be deleted.", file));
 260                         }
 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();
 270                     boolean deleted = pkg.delete();
 271                     if (options.verbose && !deleted) {
 272                         System.out.println(MessageFormat.format("{0} could not be deleted.", pkg));
 273                     }
 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();
 285         final List<File> trackedClassFiles = new ArrayList<File>();
 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() {
 293                         @Override
 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 
 316         FileOutputStream fos;
 317         if (!options.quiet) {



 318             listener.message(WscompileMessages.WSIMPORT_ARCHIVING_ARTIFACTS(zipFile));
 319         }
 320 
 321         BufferedInputStream bis = null;
 322         FileInputStream fi = null;
 323         fos = new FileOutputStream(zipFile);
 324         JarOutputStream jos = new JarOutputStream(fos);
 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                 }
 335                 String entry = f.getCanonicalPath().substring(base.length()+1);
 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                 }
 345             }
 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                 }
 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 
 371     protected Model buildWsdlModel(Listener listener, final Receiver receiver)
 372             throws BadCommandLineException, XMLStreamException, IOException {



 373         //set auth info
 374         //if(options.authFile != null)
 375         if (!options.disableAuthenticator) {
 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());
 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;


 534             //javac is not working in osgi as the url starts with a bundle
 535             if (bootCP) {
 536                 args[baseIndex++] = "-Xbootclasspath/p:"+JavaCompilerHelper.getJarFile(EndpointContext.class)+File.pathSeparator+JavaCompilerHelper.getJarFile(JAXBPermission.class);
 537             }
 538 
 539             if (options.debug) {
 540                 args[baseIndex++] = "-g";
 541             }
 542 
 543             if (options.encoding != null) {
 544                 args[baseIndex++] = "-encoding";
 545                 args[baseIndex++] = options.encoding;
 546             }
 547 
 548             for (int i = 0; i < sourceFiles.size(); ++i) {
 549                 args[baseIndex + i] = sourceFiles.get(i);
 550             }
 551 
 552             listener.message(WscompileMessages.WSIMPORT_COMPILING_CODE());
 553             if(options.verbose){
 554                 StringBuilder argstr = new StringBuilder();
 555                 for(String arg:args){
 556                     argstr.append(arg).append(" ");
 557                 }
 558                 listener.message("javac "+ argstr.toString());
 559             }
 560 
 561             return JavaCompilerHelper.compile(args, out, receiver);
 562         }
 563         //there are no files to compile, so return true?
 564         return true;
 565     }
 566 
 567     private String createClasspathString() {
 568         StringBuilder classpathStr = new StringBuilder(System.getProperty("java.class.path"));
 569         for(String s: options.cmdlineJars) {
 570             classpathStr.append(File.pathSeparator);
 571             classpathStr.append(new File(s).toString());
 572         }
 573         return classpathStr.toString();
 574     }