src/share/jaxws_classes/com/sun/tools/internal/jxc/SchemaGenerator.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
child 1011
70d4d5435eb4
     1.1 --- a/src/share/jaxws_classes/com/sun/tools/internal/jxc/SchemaGenerator.java	Thu Apr 04 19:05:24 2013 -0700
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/jxc/SchemaGenerator.java	Tue Apr 09 14:51:13 2013 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2011, 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,8 +27,6 @@
    1.11  
    1.12  import com.sun.tools.internal.jxc.ap.Options;
    1.13  import com.sun.tools.internal.xjc.BadCommandLineException;
    1.14 -import com.sun.tools.internal.xjc.api.util.ApClassLoader;
    1.15 -import com.sun.tools.internal.xjc.api.util.ToolsJarNotFoundException;
    1.16  import com.sun.xml.internal.bind.util.Which;
    1.17  
    1.18  import javax.lang.model.SourceVersion;
    1.19 @@ -45,7 +43,9 @@
    1.20  import java.net.MalformedURLException;
    1.21  import java.net.URISyntaxException;
    1.22  import java.net.URL;
    1.23 +import java.net.URLClassLoader;
    1.24  import java.util.ArrayList;
    1.25 +import java.util.Collection;
    1.26  import java.util.Collections;
    1.27  import java.util.List;
    1.28  import java.util.logging.Level;
    1.29 @@ -70,7 +70,6 @@
    1.30              if (cl==null) {
    1.31                  cl = SecureLoader.getSystemClassLoader();
    1.32              }
    1.33 -//            ClassLoader classLoader = new ApClassLoader(cl, packagePrefixes); // todo: check if can be removed
    1.34              return run(args, cl);
    1.35          } catch(Exception e) {
    1.36              System.err.println(e.getMessage());
    1.37 @@ -79,19 +78,6 @@
    1.38      }
    1.39  
    1.40      /**
    1.41 -     * List of package prefixes we want to load in the same package
    1.42 -     */
    1.43 -    private static final String[] packagePrefixes = {
    1.44 -        "com.sun.tools.internal.jxc.",
    1.45 -        "com.sun.tools.internal.xjc.",
    1.46 -        "com.sun.istack.internal.tools.",
    1.47 -        "com.sun.tools.javac.",
    1.48 -        "com.sun.tools.javadoc.",
    1.49 -        "javax.annotation.processing.",
    1.50 -        "javax.lang.model."
    1.51 -    };
    1.52 -
    1.53 -    /**
    1.54       * Runs the schema generator.
    1.55       *
    1.56       * @param classLoader
    1.57 @@ -148,18 +134,8 @@
    1.58              aptargs.add(options.encoding);
    1.59          }
    1.60  
    1.61 -        // make jaxb-api.jar visible to classpath
    1.62 -        File jaxbApi = findJaxbApiJar();
    1.63 -        if(jaxbApi!=null) {
    1.64 -            if(options.classpath!=null) {
    1.65 -                options.classpath = options.classpath+File.pathSeparatorChar+jaxbApi;
    1.66 -            } else {
    1.67 -                options.classpath = jaxbApi.getPath();
    1.68 -            }
    1.69 -        }
    1.70 -
    1.71          aptargs.add("-cp");
    1.72 -        aptargs.add(options.classpath);
    1.73 +        aptargs.add(setClasspath(options.classpath)); // set original classpath + jaxb-api to be visible to annotation processor
    1.74  
    1.75          if(options.targetDir!=null) {
    1.76              aptargs.add("-d");
    1.77 @@ -172,6 +148,31 @@
    1.78          return ((Boolean) compileMethod.invoke(null, argsarray, options.episodeFile)) ? 0 : 1;
    1.79      }
    1.80  
    1.81 +    private static String setClasspath(String givenClasspath) {
    1.82 +        StringBuilder cp = new StringBuilder();
    1.83 +        appendPath(cp, givenClasspath);
    1.84 +        ClassLoader cl = Thread.currentThread().getContextClassLoader();
    1.85 +        while (cl != null) {
    1.86 +            if (cl instanceof URLClassLoader) {
    1.87 +                for (URL url : ((URLClassLoader) cl).getURLs()) {
    1.88 +                    appendPath(cp, url.getPath());
    1.89 +                }
    1.90 +            }
    1.91 +            cl = cl.getParent();
    1.92 +        }
    1.93 +
    1.94 +        appendPath(cp, findJaxbApiJar());
    1.95 +        return cp.toString();
    1.96 +    }
    1.97 +
    1.98 +    private static void appendPath(StringBuilder cp, String url) {
    1.99 +        if (url == null || url.trim().isEmpty())
   1.100 +            return;
   1.101 +        if (cp.length() != 0)
   1.102 +            cp.append(File.pathSeparatorChar);
   1.103 +        cp.append(url);
   1.104 +    }
   1.105 +
   1.106      /**
   1.107       * Computes the file system path of <tt>jaxb-api.jar</tt> so that
   1.108       * Annotation Processing will see them in the <tt>-cp</tt> option.
   1.109 @@ -183,7 +184,7 @@
   1.110       * @return
   1.111       *      null if failed to locate it.
   1.112       */
   1.113 -    private static File findJaxbApiJar() {
   1.114 +    private static String findJaxbApiJar() {
   1.115          String url = Which.which(JAXBContext.class);
   1.116          if(url==null)       return null;    // impossible, but hey, let's be defensive
   1.117  
   1.118 @@ -198,11 +199,11 @@
   1.119          try {
   1.120              File f = new File(new URL(jarFileUrl).toURI());
   1.121              if (f.exists() && f.getName().endsWith(".jar")) { // see 6510966
   1.122 -                return f;
   1.123 +                return f.getPath();
   1.124              }
   1.125              f = new File(new URL(jarFileUrl).getFile());
   1.126              if (f.exists() && f.getName().endsWith(".jar")) { // this is here for potential backw. compatibility issues
   1.127 -                return f;
   1.128 +                return f.getPath();
   1.129              }
   1.130          } catch (URISyntaxException ex) {
   1.131              Logger.getLogger(SchemaGenerator.class.getName()).log(Level.SEVERE, null, ex);
   1.132 @@ -212,18 +213,6 @@
   1.133          return null;
   1.134      }
   1.135  
   1.136 -    /**
   1.137 -     * Returns true if the list of arguments have an argument
   1.138 -     * that looks like a class name.
   1.139 -     */
   1.140 -    private static boolean hasClass(List<String> args) {
   1.141 -        for (String arg : args) {
   1.142 -            if(!arg.endsWith(".java"))
   1.143 -                return true;
   1.144 -        }
   1.145 -        return false;
   1.146 -    }
   1.147 -
   1.148      private static void usage( ) {
   1.149          System.out.println(Messages.USAGE.format());
   1.150      }

mercurial