jaxws/src/jdk.xml.ws/share/classes/com/sun/tools/internal/ws/wscompile/WsimportTool.java
changeset 43852 93a527059d8a
parent 42124 640a383428fb
equal deleted inserted replaced
43752:3c68ef249093 43852:93a527059d8a
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2017, 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
   244         }
   244         }
   245         return true;
   245         return true;
   246     }
   246     }
   247 
   247 
   248     private void deleteGeneratedFiles() {
   248     private void deleteGeneratedFiles() {
   249         Set<File> trackedRootPackages = new HashSet<File>();
   249         Set<File> trackedRootPackages = new HashSet<>();
   250 
   250 
   251         if (options.clientjar != null) {
   251         if (options.clientjar != null) {
   252             //remove all non-java artifacts as they will packaged in jar.
   252             //remove all non-java artifacts as they will packaged in jar.
   253             Iterable<File> generatedFiles = options.getGeneratedFiles();
   253             Iterable<File> generatedFiles = options.getGeneratedFiles();
   254             synchronized (generatedFiles) {
   254             synchronized (generatedFiles) {
   280         }
   280         }
   281     }
   281     }
   282 
   282 
   283     private void addClassesToGeneratedFiles() throws IOException {
   283     private void addClassesToGeneratedFiles() throws IOException {
   284         Iterable<File> generatedFiles = options.getGeneratedFiles();
   284         Iterable<File> generatedFiles = options.getGeneratedFiles();
   285         final List<File> trackedClassFiles = new ArrayList<File>();
   285         final List<File> trackedClassFiles = new ArrayList<>();
   286         for(File f: generatedFiles) {
   286         for(File f: generatedFiles) {
   287             if(f.getName().endsWith(".java")) {
   287             if(f.getName().endsWith(".java")) {
   288                 String relativeDir = DirectoryUtil.getRelativePathfromCommonBase(f.getParentFile(),options.sourceDir);
   288                 String relativeDir = DirectoryUtil.getRelativePathfromCommonBase(f.getParentFile(),options.sourceDir);
   289                 final String className = f.getName().substring(0,f.getName().indexOf(".java"));
   289                 final String className = f.getName().substring(0,f.getName().indexOf(".java"));
   290                 File classDir = new File(options.destDir,relativeDir);
   290                 File classDir = new File(options.destDir,relativeDir);
   502     public void setEntityResolver(EntityResolver resolver){
   502     public void setEntityResolver(EntityResolver resolver){
   503         this.options.entityResolver = resolver;
   503         this.options.entityResolver = resolver;
   504     }
   504     }
   505 
   505 
   506     protected boolean compileGeneratedClasses(ErrorReceiver receiver, WsimportListener listener){
   506     protected boolean compileGeneratedClasses(ErrorReceiver receiver, WsimportListener listener){
   507         List<String> sourceFiles = new ArrayList<String>();
   507         List<String> sourceFiles = new ArrayList<>();
   508 
   508 
   509         for (File f : options.getGeneratedFiles()) {
   509         for (File f : options.getGeneratedFiles()) {
   510             if (f.exists() && f.getName().endsWith(".java")) {
   510             if (f.exists() && f.getName().endsWith(".java")) {
   511                 sourceFiles.add(f.getAbsolutePath());
   511                 sourceFiles.add(f.getAbsolutePath());
   512             }
   512             }
   513         }
   513         }
   514 
   514 
   515         if (sourceFiles.size() > 0) {
   515         if (sourceFiles.size() > 0) {
   516             String classDir = options.destDir.getAbsolutePath();
   516             String classDir = options.destDir.getAbsolutePath();
   517             String classpathString = createClasspathString();
   517             String classpathString = createClasspathString();
   518             List<String> args = new ArrayList<String>();
   518             List<String> args = new ArrayList<>();
   519 
       
   520             args.add("--add-modules");
       
   521             args.add("java.xml.ws");
       
   522 
   519 
   523             args.add("-d");
   520             args.add("-d");
   524             args.add(classDir);
   521             args.add(classDir);
   525             args.add("-classpath");
   522             args.add("-classpath");
   526             args.add(classpathString);
   523             args.add(classpathString);
   532             if (options.encoding != null) {
   529             if (options.encoding != null) {
   533                 args.add("-encoding");
   530                 args.add("-encoding");
   534                 args.add(options.encoding);
   531                 args.add(options.encoding);
   535             }
   532             }
   536 
   533 
       
   534             boolean addModules = true;
   537             if (options.javacOptions != null) {
   535             if (options.javacOptions != null) {
   538                 args.addAll(options.getJavacOptions(args, listener));
   536                 List<String> javacOptions = options.getJavacOptions(args, listener);
       
   537                 for (int i = 0; i < javacOptions.size(); i++) {
       
   538                     String opt = javacOptions.get(i);
       
   539                     if ("-source".equals(opt) && 9 >= getVersion(javacOptions.get(i + 1))) {
       
   540                         addModules = false;
       
   541                     }
       
   542                     if ("-target".equals(opt) && 9 >= getVersion(javacOptions.get(i + 1))) {
       
   543                         addModules = false;
       
   544                     }
       
   545                     if ("--release".equals(opt) && 9 >= getVersion(javacOptions.get(i + 1))) {
       
   546                         addModules = false;
       
   547                     }
       
   548                     args.add(opt);
       
   549                 }
       
   550             }
       
   551             if (addModules) {
       
   552                 args.add("--add-modules");
       
   553                 args.add("java.xml.ws");
   539             }
   554             }
   540 
   555 
   541             for (int i = 0; i < sourceFiles.size(); ++i) {
   556             for (int i = 0; i < sourceFiles.size(); ++i) {
   542                 args.add(sourceFiles.get(i));
   557                 args.add(sourceFiles.get(i));
   543             }
   558             }
   570     protected void usage(Options options) {
   585     protected void usage(Options options) {
   571         System.out.println(WscompileMessages.WSIMPORT_HELP(WSIMPORT));
   586         System.out.println(WscompileMessages.WSIMPORT_HELP(WSIMPORT));
   572         System.out.println(WscompileMessages.WSIMPORT_USAGE_EXTENSIONS());
   587         System.out.println(WscompileMessages.WSIMPORT_USAGE_EXTENSIONS());
   573         System.out.println(WscompileMessages.WSIMPORT_USAGE_EXAMPLES());
   588         System.out.println(WscompileMessages.WSIMPORT_USAGE_EXAMPLES());
   574     }
   589     }
       
   590 
       
   591     private float getVersion(String s) {
       
   592         return Float.parseFloat(s);
       
   593     }
   575 }
   594 }