< prev index next >

jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wscompile/WsimportTool.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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

@@ -61,12 +61,12 @@
 
 /**
  * @author Vivek Pandey
  */
 public class WsimportTool {
-    /** JAXWS module name. JAXWS dependency is mandatory in generated Java module. */
-    private static final String JAXWS_MODULE = "java.xml.ws";
+    /** JAXB module name. JAXB dependency is mandatory in generated Java module. */
+    private static final String JAXWS_PACKAGE = "java.xml.ws";
 
     private static final String WSIMPORT = "wsimport";
     private final PrintStream out;
     private final Container container;
 

@@ -244,11 +244,11 @@
         }
         return true;
     }
 
     private void deleteGeneratedFiles() {
-        Set<File> trackedRootPackages = new HashSet<File>();
+        Set<File> trackedRootPackages = new HashSet<>();
 
         if (options.clientjar != null) {
             //remove all non-java artifacts as they will packaged in jar.
             Iterable<File> generatedFiles = options.getGeneratedFiles();
             synchronized (generatedFiles) {

@@ -280,11 +280,11 @@
         }
     }
 
     private void addClassesToGeneratedFiles() throws IOException {
         Iterable<File> generatedFiles = options.getGeneratedFiles();
-        final List<File> trackedClassFiles = new ArrayList<File>();
+        final List<File> trackedClassFiles = new ArrayList<>();
         for(File f: generatedFiles) {
             if(f.getName().endsWith(".java")) {
                 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);

@@ -475,11 +475,11 @@
                 return false;
             }
         }
 
         if (options.getModuleName() != null) {
-            options.getCodeModel()._prepareModuleInfo(options.getModuleName(), JAXWS_MODULE);
+            options.getCodeModel()._prepareModuleInfo(options.getModuleName(), JAXWS_PACKAGE);
         }
 
         CodeWriter cw;
         if (options.filer != null) {
             cw = new FilerCodeWriter(options);

@@ -502,25 +502,22 @@
     public void setEntityResolver(EntityResolver resolver){
         this.options.entityResolver = resolver;
     }
 
     protected boolean compileGeneratedClasses(ErrorReceiver receiver, WsimportListener listener){
-        List<String> sourceFiles = new ArrayList<String>();
+        List<String> sourceFiles = new ArrayList<>();
 
         for (File f : options.getGeneratedFiles()) {
             if (f.exists() && f.getName().endsWith(".java")) {
                 sourceFiles.add(f.getAbsolutePath());
             }
         }
 
         if (sourceFiles.size() > 0) {
             String classDir = options.destDir.getAbsolutePath();
             String classpathString = createClasspathString();
-            List<String> args = new ArrayList<String>();
-
-            args.add("--add-modules");
-            args.add("java.xml.ws");
+            List<String> args = new ArrayList<>();
 
             args.add("-d");
             args.add(classDir);
             args.add("-classpath");
             args.add(classpathString);

@@ -532,12 +529,30 @@
             if (options.encoding != null) {
                 args.add("-encoding");
                 args.add(options.encoding);
             }
 
+            boolean addModules = true;
             if (options.javacOptions != null) {
-                args.addAll(options.getJavacOptions(args, listener));
+                List<String> javacOptions = options.getJavacOptions(args, listener);
+                for (int i = 0; i < javacOptions.size(); i++) {
+                    String opt = javacOptions.get(i);
+                    if ("-source".equals(opt) && 9 >= getVersion(javacOptions.get(i + 1))) {
+                        addModules = false;
+                    }
+                    if ("-target".equals(opt) && 9 >= getVersion(javacOptions.get(i + 1))) {
+                        addModules = false;
+                    }
+                    if ("-release".equals(opt) && 9 >= getVersion(javacOptions.get(i + 1))) {
+                        addModules = false;
+                    }
+                    args.add(opt);
+                }
+            }
+            if (addModules) {
+                args.add("--add-modules");
+                args.add("java.xml.ws");
             }
 
             for (int i = 0; i < sourceFiles.size(); ++i) {
                 args.add(sourceFiles.get(i));
             }

@@ -570,6 +585,10 @@
     protected void usage(Options options) {
         System.out.println(WscompileMessages.WSIMPORT_HELP(WSIMPORT));
         System.out.println(WscompileMessages.WSIMPORT_USAGE_EXTENSIONS());
         System.out.println(WscompileMessages.WSIMPORT_USAGE_EXAMPLES());
     }
+
+    private float getVersion(String s) {
+        return Float.parseFloat(s);
+    }
 }
< prev index next >