src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/WsimportTool.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 25,34 ****
--- 25,35 ----
package com.sun.tools.internal.ws.wscompile;
import com.sun.codemodel.internal.CodeWriter;
import com.sun.codemodel.internal.writer.ProgressCodeWriter;
+ import com.sun.istack.internal.tools.DefaultAuthenticator;
import com.sun.tools.internal.ws.ToolVersion;
import com.sun.tools.internal.ws.api.TJavaGeneratorExtension;
import com.sun.tools.internal.ws.processor.generator.CustomExceptionGenerator;
import com.sun.tools.internal.ws.processor.generator.GeneratorBase;
import com.sun.tools.internal.ws.processor.generator.SeiGenerator;
*** 53,65 ****
import javax.xml.bind.JAXBPermission;
import javax.xml.stream.*;
import javax.xml.ws.EndpointContext;
import java.io.*;
import java.util.*;
! import java.net.Authenticator;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import org.xml.sax.SAXException;
/**
* @author Vivek Pandey
*/
--- 54,67 ----
import javax.xml.bind.JAXBPermission;
import javax.xml.stream.*;
import javax.xml.ws.EndpointContext;
import java.io.*;
import java.util.*;
! import java.text.MessageFormat;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
+ import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/**
* @author Vivek Pandey
*/
*** 132,146 ****
--- 134,150 ----
public Receiver(Listener listener) {
super(listener);
this.listener = listener;
}
+ @Override
public void info(SAXParseException exception) {
if (options.verbose)
super.info(exception);
}
+ @Override
public void warning(SAXParseException exception) {
if (!options.quiet)
super.warning(exception);
}
*** 177,193 ****
WscompileMessages.WSIMPORT_FULLVERSION(ToolVersion.VERSION.toString()));
return true;
}
}
- Authenticator orig = null;
try {
parseArguments(args, listener, receiver);
try {
- orig = DefaultAuthenticator.getCurrentAuthenticator();
-
Model wsdlModel = buildWsdlModel(listener, receiver);
if (wsdlModel == null)
return false;
if (!generateCode(listener, receiver, wsdlModel, true))
--- 181,194 ----
*** 233,243 ****
usage(e.getOptions());
return false;
} finally{
deleteGeneratedFiles();
if (!options.disableAuthenticator) {
! Authenticator.setDefault(orig);
}
}
if(receiver.hadError()) {
return false;
}
--- 234,244 ----
usage(e.getOptions());
return false;
} finally{
deleteGeneratedFiles();
if (!options.disableAuthenticator) {
! DefaultAuthenticator.reset();
}
}
if(receiver.hadError()) {
return false;
}
*** 251,281 ****
//remove all non-java artifacts as they will packaged in jar.
Iterable<File> generatedFiles = options.getGeneratedFiles();
synchronized (generatedFiles) {
for (File file : generatedFiles) {
if (!file.getName().endsWith(".java")) {
! file.delete();
trackedRootPackages.add(file.getParentFile());
-
}
-
}
}
//remove empty package dirs
for(File pkg:trackedRootPackages) {
while(pkg.list() != null && pkg.list().length ==0 && !pkg.equals(options.destDir)) {
File parentPkg = pkg.getParentFile();
! pkg.delete();
pkg = parentPkg;
}
}
}
if(!options.keep) {
options.removeGeneratedFiles();
}
-
}
private void addClassesToGeneratedFiles() throws IOException {
Iterable<File> generatedFiles = options.getGeneratedFiles();
final List<File> trackedClassFiles = new ArrayList<File>();
--- 252,285 ----
//remove all non-java artifacts as they will packaged in jar.
Iterable<File> generatedFiles = options.getGeneratedFiles();
synchronized (generatedFiles) {
for (File file : generatedFiles) {
if (!file.getName().endsWith(".java")) {
! boolean deleted = file.delete();
! if (options.verbose && !deleted) {
! System.out.println(MessageFormat.format("{0} could not be deleted.", file));
! }
trackedRootPackages.add(file.getParentFile());
}
}
}
//remove empty package dirs
for(File pkg:trackedRootPackages) {
while(pkg.list() != null && pkg.list().length ==0 && !pkg.equals(options.destDir)) {
File parentPkg = pkg.getParentFile();
! boolean deleted = pkg.delete();
! if (options.verbose && !deleted) {
! System.out.println(MessageFormat.format("{0} could not be deleted.", pkg));
! }
pkg = parentPkg;
}
}
}
if(!options.keep) {
options.removeGeneratedFiles();
}
}
private void addClassesToGeneratedFiles() throws IOException {
Iterable<File> generatedFiles = options.getGeneratedFiles();
final List<File> trackedClassFiles = new ArrayList<File>();
*** 284,294 ****
String relativeDir = DirectoryUtil.getRelativePathfromCommonBase(f.getParentFile(),options.sourceDir);
final String className = f.getName().substring(0,f.getName().indexOf(".java"));
File classDir = new File(options.destDir,relativeDir);
if(classDir.exists()) {
classDir.listFiles(new FilenameFilter() {
!
public boolean accept(File dir, String name) {
if(name.equals(className+".class") || (name.startsWith(className+"$") && name.endsWith(".class"))) {
trackedClassFiles.add(new File(dir,name));
return true;
}
--- 288,298 ----
String relativeDir = DirectoryUtil.getRelativePathfromCommonBase(f.getParentFile(),options.sourceDir);
final String className = f.getName().substring(0,f.getName().indexOf(".java"));
File classDir = new File(options.destDir,relativeDir);
if(classDir.exists()) {
classDir.listFiles(new FilenameFilter() {
! @Override
public boolean accept(File dir, String name) {
if(name.equals(className+".class") || (name.startsWith(className+"$") && name.endsWith(".class"))) {
trackedClassFiles.add(new File(dir,name));
return true;
}
*** 307,352 ****
File zipFile = new File(options.clientjar);
if(!zipFile.isAbsolute()) {
zipFile = new File(options.destDir, options.clientjar);
}
! if (zipFile.exists()) {
! //TODO
! }
! FileOutputStream fos = null;
! if( !options.quiet )
listener.message(WscompileMessages.WSIMPORT_ARCHIVING_ARTIFACTS(zipFile));
!
fos = new FileOutputStream(zipFile);
JarOutputStream jos = new JarOutputStream(fos);
!
String base = options.destDir.getCanonicalPath();
for(File f: options.getGeneratedFiles()) {
//exclude packaging the java files in the jar
if(f.getName().endsWith(".java")) {
continue;
}
if(options.verbose) {
listener.message(WscompileMessages.WSIMPORT_ARCHIVE_ARTIFACT(f, options.clientjar));
}
String entry = f.getCanonicalPath().substring(base.length()+1);
! BufferedInputStream bis = new BufferedInputStream(
! new FileInputStream(f));
JarEntry jarEntry = new JarEntry(entry);
jos.putNextEntry(jarEntry);
int bytesRead;
byte[] buffer = new byte[1024];
while ((bytesRead = bis.read(buffer)) != -1) {
jos.write(buffer, 0, bytesRead);
}
bis.close();
-
}
!
jos.close();
!
}
protected void parseArguments(String[] args, Listener listener,
Receiver receiver) throws BadCommandLineException {
options.parseArguments(args);
--- 311,364 ----
File zipFile = new File(options.clientjar);
if(!zipFile.isAbsolute()) {
zipFile = new File(options.destDir, options.clientjar);
}
! FileOutputStream fos;
! if (!options.quiet) {
listener.message(WscompileMessages.WSIMPORT_ARCHIVING_ARTIFACTS(zipFile));
+ }
! BufferedInputStream bis = null;
! FileInputStream fi = null;
fos = new FileOutputStream(zipFile);
JarOutputStream jos = new JarOutputStream(fos);
! try {
String base = options.destDir.getCanonicalPath();
for(File f: options.getGeneratedFiles()) {
//exclude packaging the java files in the jar
if(f.getName().endsWith(".java")) {
continue;
}
if(options.verbose) {
listener.message(WscompileMessages.WSIMPORT_ARCHIVE_ARTIFACT(f, options.clientjar));
}
String entry = f.getCanonicalPath().substring(base.length()+1);
! fi = new FileInputStream(f);
! bis = new BufferedInputStream(fi);
JarEntry jarEntry = new JarEntry(entry);
jos.putNextEntry(jarEntry);
int bytesRead;
byte[] buffer = new byte[1024];
while ((bytesRead = bis.read(buffer)) != -1) {
jos.write(buffer, 0, bytesRead);
}
+ }
+ } finally {
+ try {
+ if (bis != null) {
bis.close();
}
! } finally {
! if (jos != null) {
jos.close();
! }
! if (fi != null) {
! fi.close();
! }
! }
! }
}
protected void parseArguments(String[] args, Listener listener,
Receiver receiver) throws BadCommandLineException {
options.parseArguments(args);
*** 354,372 ****
if (options.debugMode)
listener.enableDebugging();
options.parseBindings(receiver);
}
! protected Model buildWsdlModel(Listener listener,
! Receiver receiver) throws BadCommandLineException, XMLStreamException, IOException {
! if( !options.quiet )
! listener.message(WscompileMessages.WSIMPORT_PARSING_WSDL());
!
//set auth info
//if(options.authFile != null)
if (!options.disableAuthenticator) {
! Authenticator.setDefault(new DefaultAuthenticator(receiver, options.authFile));
}
MetadataFinder forest = new MetadataFinder(new WSDLInternalizationLogic(), options, receiver);
forest.parseWSDL();
if (forest.isMexMetadata)
--- 366,425 ----
if (options.debugMode)
listener.enableDebugging();
options.parseBindings(receiver);
}
! protected Model buildWsdlModel(Listener listener, final Receiver receiver)
! throws BadCommandLineException, XMLStreamException, IOException {
//set auth info
//if(options.authFile != null)
if (!options.disableAuthenticator) {
! class AuthListener implements DefaultAuthenticator.Receiver {
!
! private final boolean isFatal;
!
! AuthListener(boolean isFatal) {
! this.isFatal = isFatal;
! }
!
! @Override
! public void onParsingError(String text, Locator loc) {
! error(new SAXParseException(WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(text), loc));
! }
!
! @Override
! public void onError(Exception e, Locator loc) {
! if (e instanceof FileNotFoundException) {
! error(new SAXParseException(WscompileMessages.WSIMPORT_AUTH_FILE_NOT_FOUND(
! loc.getSystemId(), WsimportOptions.defaultAuthfile), null));
! } else {
! error(new SAXParseException(WscompileMessages.WSIMPORT_FAILED_TO_PARSE(loc.getSystemId(),e.getMessage()), loc));
! }
! }
!
! private void error(SAXParseException e) {
! if (isFatal) {
! receiver.error(e);
! } else {
! receiver.debug(e);
! }
! }
! }
!
! DefaultAuthenticator da = DefaultAuthenticator.getAuthenticator();
! if (options.proxyAuth != null) {
! da.setProxyAuth(options.proxyAuth);
! }
! if (options.authFile != null) {
! da.setAuth(options.authFile, new AuthListener(true));
! } else {
! da.setAuth(new File(WsimportOptions.defaultAuthfile), new AuthListener(false));
! }
! }
!
! if (!options.quiet) {
! listener.message(WscompileMessages.WSIMPORT_PARSING_WSDL());
}
MetadataFinder forest = new MetadataFinder(new WSDLInternalizationLogic(), options, receiver);
forest.parseWSDL();
if (forest.isMexMetadata)
*** 496,506 ****
args[baseIndex + i] = sourceFiles.get(i);
}
listener.message(WscompileMessages.WSIMPORT_COMPILING_CODE());
if(options.verbose){
! StringBuffer argstr = new StringBuffer();
for(String arg:args){
argstr.append(arg).append(" ");
}
listener.message("javac "+ argstr.toString());
}
--- 549,559 ----
args[baseIndex + i] = sourceFiles.get(i);
}
listener.message(WscompileMessages.WSIMPORT_COMPILING_CODE());
if(options.verbose){
! StringBuilder argstr = new StringBuilder();
for(String arg:args){
argstr.append(arg).append(" ");
}
listener.message("javac "+ argstr.toString());
}