jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wscompile/WsimportTool.java
changeset 42124 640a383428fb
parent 40297 3cdb35bf8c36
child 43852 93a527059d8a
equal deleted inserted replaced
42002:3ee4e7827413 42124:640a383428fb
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    45 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
    45 import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
    46 import com.sun.tools.internal.ws.wsdl.parser.WSDLInternalizationLogic;
    46 import com.sun.tools.internal.ws.wsdl.parser.WSDLInternalizationLogic;
    47 import com.sun.tools.internal.xjc.util.NullStream;
    47 import com.sun.tools.internal.xjc.util.NullStream;
    48 import com.sun.xml.internal.ws.api.server.Container;
    48 import com.sun.xml.internal.ws.api.server.Container;
    49 import com.sun.xml.internal.ws.util.ServiceFinder;
    49 import com.sun.xml.internal.ws.util.ServiceFinder;
    50 import com.sun.istack.internal.tools.ParallelWorldClassLoader;
       
    51 import org.xml.sax.EntityResolver;
    50 import org.xml.sax.EntityResolver;
    52 import org.xml.sax.SAXParseException;
    51 import org.xml.sax.SAXParseException;
    53 
    52 
    54 import javax.xml.bind.JAXBPermission;
       
    55 import javax.xml.stream.*;
    53 import javax.xml.stream.*;
    56 import javax.xml.ws.EndpointContext;
       
    57 import java.io.*;
    54 import java.io.*;
    58 import java.util.*;
    55 import java.util.*;
    59 import java.text.MessageFormat;
    56 import java.text.MessageFormat;
    60 import java.util.jar.JarEntry;
    57 import java.util.jar.JarEntry;
    61 import java.util.jar.JarOutputStream;
    58 import java.util.jar.JarOutputStream;
    64 
    61 
    65 /**
    62 /**
    66  * @author Vivek Pandey
    63  * @author Vivek Pandey
    67  */
    64  */
    68 public class WsimportTool {
    65 public class WsimportTool {
       
    66     /** JAXWS module name. JAXWS dependency is mandatory in generated Java module. */
       
    67     private static final String JAXWS_MODULE = "java.xml.ws";
       
    68 
    69     private static final String WSIMPORT = "wsimport";
    69     private static final String WSIMPORT = "wsimport";
    70     private final PrintStream out;
    70     private final PrintStream out;
    71     private final Container container;
    71     private final Container container;
    72 
    72 
    73     /**
    73     /**
   474                 // fatal error. error should have been reported
   474                 // fatal error. error should have been reported
   475                 return false;
   475                 return false;
   476             }
   476             }
   477         }
   477         }
   478 
   478 
       
   479         if (options.getModuleName() != null) {
       
   480             options.getCodeModel()._prepareModuleInfo(options.getModuleName(), JAXWS_MODULE);
       
   481         }
       
   482 
   479         CodeWriter cw;
   483         CodeWriter cw;
   480         if (options.filer != null) {
   484         if (options.filer != null) {
   481             cw = new FilerCodeWriter(options.sourceDir, options);
   485             cw = new FilerCodeWriter(options);
   482         } else {
   486         } else {
   483             cw = new WSCodeWriter(options.sourceDir, options);
   487             cw = new WSCodeWriter(options.sourceDir, options);
   484         }
   488         }
   485 
   489 
   486         if (options.verbose)
   490         if (options.verbose)
   497 
   501 
   498     public void setEntityResolver(EntityResolver resolver){
   502     public void setEntityResolver(EntityResolver resolver){
   499         this.options.entityResolver = resolver;
   503         this.options.entityResolver = resolver;
   500     }
   504     }
   501 
   505 
   502     /*
       
   503      * To take care of JDK6-JDK6u3, where 2.1 API classes are not there
       
   504      */
       
   505     private static boolean useBootClasspath(Class clazz) {
       
   506         try {
       
   507             ParallelWorldClassLoader.toJarUrl(clazz.getResource('/'+clazz.getName().replace('.','/')+".class"));
       
   508             return true;
       
   509         } catch(Exception e) {
       
   510             return false;
       
   511         }
       
   512     }
       
   513 
       
   514     protected boolean compileGeneratedClasses(ErrorReceiver receiver, WsimportListener listener){
   506     protected boolean compileGeneratedClasses(ErrorReceiver receiver, WsimportListener listener){
   515         List<String> sourceFiles = new ArrayList<String>();
   507         List<String> sourceFiles = new ArrayList<String>();
   516 
   508 
   517         for (File f : options.getGeneratedFiles()) {
   509         for (File f : options.getGeneratedFiles()) {
   518             if (f.exists() && f.getName().endsWith(".java")) {
   510             if (f.exists() && f.getName().endsWith(".java")) {
   521         }
   513         }
   522 
   514 
   523         if (sourceFiles.size() > 0) {
   515         if (sourceFiles.size() > 0) {
   524             String classDir = options.destDir.getAbsolutePath();
   516             String classDir = options.destDir.getAbsolutePath();
   525             String classpathString = createClasspathString();
   517             String classpathString = createClasspathString();
   526             boolean bootCP = useBootClasspath(EndpointContext.class) || useBootClasspath(JAXBPermission.class);
       
   527             List<String> args = new ArrayList<String>();
   518             List<String> args = new ArrayList<String>();
       
   519 
   528             args.add("--add-modules");
   520             args.add("--add-modules");
   529             args.add("java.xml.ws");
   521             args.add("java.xml.ws");
       
   522 
   530             args.add("-d");
   523             args.add("-d");
   531             args.add(classDir);
   524             args.add(classDir);
   532             args.add("-classpath");
   525             args.add("-classpath");
   533             args.add(classpathString);
   526             args.add(classpathString);
   534             //javac is not working in osgi as the url starts with a bundle
       
   535             if (bootCP) {
       
   536                 args.add("-Xbootclasspath/p:"
       
   537                         + JavaCompilerHelper.getJarFile(EndpointContext.class)
       
   538                         + File.pathSeparator
       
   539                         + JavaCompilerHelper.getJarFile(JAXBPermission.class));
       
   540             }
       
   541 
   527 
   542             if (options.debug) {
   528             if (options.debug) {
   543                 args.add("-g");
   529                 args.add("-g");
   544             }
   530             }
   545 
   531