1.1 --- a/src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/WsimportTool.java Thu Apr 04 19:05:24 2013 -0700 1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/WsimportTool.java Tue Apr 09 14:51:13 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -27,6 +27,7 @@ 1.11 1.12 import com.sun.codemodel.internal.CodeWriter; 1.13 import com.sun.codemodel.internal.writer.ProgressCodeWriter; 1.14 +import com.sun.istack.internal.tools.DefaultAuthenticator; 1.15 import com.sun.tools.internal.ws.ToolVersion; 1.16 import com.sun.tools.internal.ws.api.TJavaGeneratorExtension; 1.17 import com.sun.tools.internal.ws.processor.generator.CustomExceptionGenerator; 1.18 @@ -55,9 +56,10 @@ 1.19 import javax.xml.ws.EndpointContext; 1.20 import java.io.*; 1.21 import java.util.*; 1.22 -import java.net.Authenticator; 1.23 +import java.text.MessageFormat; 1.24 import java.util.jar.JarEntry; 1.25 import java.util.jar.JarOutputStream; 1.26 +import org.xml.sax.Locator; 1.27 import org.xml.sax.SAXException; 1.28 1.29 /** 1.30 @@ -134,11 +136,13 @@ 1.31 this.listener = listener; 1.32 } 1.33 1.34 + @Override 1.35 public void info(SAXParseException exception) { 1.36 if (options.verbose) 1.37 super.info(exception); 1.38 } 1.39 1.40 + @Override 1.41 public void warning(SAXParseException exception) { 1.42 if (!options.quiet) 1.43 super.warning(exception); 1.44 @@ -179,13 +183,10 @@ 1.45 } 1.46 } 1.47 1.48 - Authenticator orig = null; 1.49 try { 1.50 parseArguments(args, listener, receiver); 1.51 1.52 try { 1.53 - orig = DefaultAuthenticator.getCurrentAuthenticator(); 1.54 - 1.55 Model wsdlModel = buildWsdlModel(listener, receiver); 1.56 if (wsdlModel == null) 1.57 return false; 1.58 @@ -235,7 +236,7 @@ 1.59 } finally{ 1.60 deleteGeneratedFiles(); 1.61 if (!options.disableAuthenticator) { 1.62 - Authenticator.setDefault(orig); 1.63 + DefaultAuthenticator.reset(); 1.64 } 1.65 } 1.66 if(receiver.hadError()) { 1.67 @@ -253,11 +254,12 @@ 1.68 synchronized (generatedFiles) { 1.69 for (File file : generatedFiles) { 1.70 if (!file.getName().endsWith(".java")) { 1.71 - file.delete(); 1.72 + boolean deleted = file.delete(); 1.73 + if (options.verbose && !deleted) { 1.74 + System.out.println(MessageFormat.format("{0} could not be deleted.", file)); 1.75 + } 1.76 trackedRootPackages.add(file.getParentFile()); 1.77 - 1.78 } 1.79 - 1.80 } 1.81 } 1.82 //remove empty package dirs 1.83 @@ -265,7 +267,10 @@ 1.84 1.85 while(pkg.list() != null && pkg.list().length ==0 && !pkg.equals(options.destDir)) { 1.86 File parentPkg = pkg.getParentFile(); 1.87 - pkg.delete(); 1.88 + boolean deleted = pkg.delete(); 1.89 + if (options.verbose && !deleted) { 1.90 + System.out.println(MessageFormat.format("{0} could not be deleted.", pkg)); 1.91 + } 1.92 pkg = parentPkg; 1.93 } 1.94 } 1.95 @@ -273,7 +278,6 @@ 1.96 if(!options.keep) { 1.97 options.removeGeneratedFiles(); 1.98 } 1.99 - 1.100 } 1.101 1.102 private void addClassesToGeneratedFiles() throws IOException { 1.103 @@ -286,7 +290,7 @@ 1.104 File classDir = new File(options.destDir,relativeDir); 1.105 if(classDir.exists()) { 1.106 classDir.listFiles(new FilenameFilter() { 1.107 - 1.108 + @Override 1.109 public boolean accept(File dir, String name) { 1.110 if(name.equals(className+".class") || (name.startsWith(className+"$") && name.endsWith(".class"))) { 1.111 trackedClassFiles.add(new File(dir,name)); 1.112 @@ -309,42 +313,50 @@ 1.113 zipFile = new File(options.destDir, options.clientjar); 1.114 } 1.115 1.116 - if (zipFile.exists()) { 1.117 - //TODO 1.118 + FileOutputStream fos; 1.119 + if (!options.quiet) { 1.120 + listener.message(WscompileMessages.WSIMPORT_ARCHIVING_ARTIFACTS(zipFile)); 1.121 } 1.122 - FileOutputStream fos = null; 1.123 - if( !options.quiet ) 1.124 - listener.message(WscompileMessages.WSIMPORT_ARCHIVING_ARTIFACTS(zipFile)); 1.125 1.126 - 1.127 + BufferedInputStream bis = null; 1.128 + FileInputStream fi = null; 1.129 fos = new FileOutputStream(zipFile); 1.130 JarOutputStream jos = new JarOutputStream(fos); 1.131 - 1.132 - String base = options.destDir.getCanonicalPath(); 1.133 - for(File f: options.getGeneratedFiles()) { 1.134 - //exclude packaging the java files in the jar 1.135 - if(f.getName().endsWith(".java")) { 1.136 - continue; 1.137 + try { 1.138 + String base = options.destDir.getCanonicalPath(); 1.139 + for(File f: options.getGeneratedFiles()) { 1.140 + //exclude packaging the java files in the jar 1.141 + if(f.getName().endsWith(".java")) { 1.142 + continue; 1.143 + } 1.144 + if(options.verbose) { 1.145 + listener.message(WscompileMessages.WSIMPORT_ARCHIVE_ARTIFACT(f, options.clientjar)); 1.146 + } 1.147 + String entry = f.getCanonicalPath().substring(base.length()+1); 1.148 + fi = new FileInputStream(f); 1.149 + bis = new BufferedInputStream(fi); 1.150 + JarEntry jarEntry = new JarEntry(entry); 1.151 + jos.putNextEntry(jarEntry); 1.152 + int bytesRead; 1.153 + byte[] buffer = new byte[1024]; 1.154 + while ((bytesRead = bis.read(buffer)) != -1) { 1.155 + jos.write(buffer, 0, bytesRead); 1.156 + } 1.157 } 1.158 - if(options.verbose) { 1.159 - listener.message(WscompileMessages.WSIMPORT_ARCHIVE_ARTIFACT(f, options.clientjar)); 1.160 + } finally { 1.161 + try { 1.162 + if (bis != null) { 1.163 + bis.close(); 1.164 + } 1.165 + } finally { 1.166 + if (jos != null) { 1.167 + jos.close(); 1.168 + } 1.169 + if (fi != null) { 1.170 + fi.close(); 1.171 + } 1.172 } 1.173 - String entry = f.getCanonicalPath().substring(base.length()+1); 1.174 - BufferedInputStream bis = new BufferedInputStream( 1.175 - new FileInputStream(f)); 1.176 - JarEntry jarEntry = new JarEntry(entry); 1.177 - jos.putNextEntry(jarEntry); 1.178 - int bytesRead; 1.179 - byte[] buffer = new byte[1024]; 1.180 - while ((bytesRead = bis.read(buffer)) != -1) { 1.181 - jos.write(buffer, 0, bytesRead); 1.182 - } 1.183 - bis.close(); 1.184 - 1.185 } 1.186 - 1.187 - jos.close(); 1.188 - 1.189 } 1.190 1.191 protected void parseArguments(String[] args, Listener listener, 1.192 @@ -356,15 +368,56 @@ 1.193 options.parseBindings(receiver); 1.194 } 1.195 1.196 - protected Model buildWsdlModel(Listener listener, 1.197 - Receiver receiver) throws BadCommandLineException, XMLStreamException, IOException { 1.198 - if( !options.quiet ) 1.199 - listener.message(WscompileMessages.WSIMPORT_PARSING_WSDL()); 1.200 - 1.201 + protected Model buildWsdlModel(Listener listener, final Receiver receiver) 1.202 + throws BadCommandLineException, XMLStreamException, IOException { 1.203 //set auth info 1.204 //if(options.authFile != null) 1.205 if (!options.disableAuthenticator) { 1.206 - Authenticator.setDefault(new DefaultAuthenticator(receiver, options.authFile)); 1.207 + class AuthListener implements DefaultAuthenticator.Receiver { 1.208 + 1.209 + private final boolean isFatal; 1.210 + 1.211 + AuthListener(boolean isFatal) { 1.212 + this.isFatal = isFatal; 1.213 + } 1.214 + 1.215 + @Override 1.216 + public void onParsingError(String text, Locator loc) { 1.217 + error(new SAXParseException(WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(text), loc)); 1.218 + } 1.219 + 1.220 + @Override 1.221 + public void onError(Exception e, Locator loc) { 1.222 + if (e instanceof FileNotFoundException) { 1.223 + error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_FILE_NOT_FOUND( 1.224 + loc.getSystemId(), WsimportOptions.defaultAuthfile), null)); 1.225 + } else { 1.226 + error(new SAXParseException(WscompileMessages.WSIMPORT_FAILED_TO_PARSE(loc.getSystemId(),e.getMessage()), loc)); 1.227 + } 1.228 + } 1.229 + 1.230 + private void error(SAXParseException e) { 1.231 + if (isFatal) { 1.232 + receiver.error(e); 1.233 + } else { 1.234 + receiver.debug(e); 1.235 + } 1.236 + } 1.237 + } 1.238 + 1.239 + DefaultAuthenticator da = DefaultAuthenticator.getAuthenticator(); 1.240 + if (options.proxyAuth != null) { 1.241 + da.setProxyAuth(options.proxyAuth); 1.242 + } 1.243 + if (options.authFile != null) { 1.244 + da.setAuth(options.authFile, new AuthListener(true)); 1.245 + } else { 1.246 + da.setAuth(new File(WsimportOptions.defaultAuthfile), new AuthListener(false)); 1.247 + } 1.248 + } 1.249 + 1.250 + if (!options.quiet) { 1.251 + listener.message(WscompileMessages.WSIMPORT_PARSING_WSDL()); 1.252 } 1.253 1.254 MetadataFinder forest = new MetadataFinder(new WSDLInternalizationLogic(), options, receiver); 1.255 @@ -498,7 +551,7 @@ 1.256 1.257 listener.message(WscompileMessages.WSIMPORT_COMPILING_CODE()); 1.258 if(options.verbose){ 1.259 - StringBuffer argstr = new StringBuffer(); 1.260 + StringBuilder argstr = new StringBuilder(); 1.261 for(String arg:args){ 1.262 argstr.append(arg).append(" "); 1.263 }