langtools/src/share/classes/javax/tools/ToolProvider.java
changeset 8032 e1aa25ccdabb
parent 7681 1f0819a3341f
child 14545 2e7bab0639b8
equal deleted inserted replaced
8031:d5fe2c1cecfc 8032:e1aa25ccdabb
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2011, 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
   170     private Class<?> findSystemToolClass(String toolClassName)
   170     private Class<?> findSystemToolClass(String toolClassName)
   171         throws MalformedURLException, ClassNotFoundException
   171         throws MalformedURLException, ClassNotFoundException
   172     {
   172     {
   173         // try loading class directly, in case tool is on the bootclasspath
   173         // try loading class directly, in case tool is on the bootclasspath
   174         try {
   174         try {
   175             return enableAsserts(Class.forName(toolClassName, false, null));
   175             return Class.forName(toolClassName, false, null);
   176         } catch (ClassNotFoundException e) {
   176         } catch (ClassNotFoundException e) {
   177             trace(FINE, e);
   177             trace(FINE, e);
   178 
   178 
   179             // if tool not on bootclasspath, look in default tools location (tools.jar)
   179             // if tool not on bootclasspath, look in default tools location (tools.jar)
   180             ClassLoader cl = (refToolClassLoader == null ? null : refToolClassLoader.get());
   180             ClassLoader cl = (refToolClassLoader == null ? null : refToolClassLoader.get());
   192 
   192 
   193                 URL[] urls = { file.toURI().toURL() };
   193                 URL[] urls = { file.toURI().toURL() };
   194                 trace(FINE, urls[0].toString());
   194                 trace(FINE, urls[0].toString());
   195 
   195 
   196                 cl = URLClassLoader.newInstance(urls);
   196                 cl = URLClassLoader.newInstance(urls);
   197                 cl.setPackageAssertionStatus("com.sun.tools.javac", true);
       
   198                 refToolClassLoader = new WeakReference<ClassLoader>(cl);
   197                 refToolClassLoader = new WeakReference<ClassLoader>(cl);
   199             }
   198             }
   200 
   199 
   201             return Class.forName(toolClassName, false, cl);
   200             return Class.forName(toolClassName, false, cl);
   202         }
   201         }
   203 
   202     }
   204     }
       
   205 
       
   206     private static Class<?> enableAsserts(Class<?> cls) {
       
   207         try {
       
   208             ClassLoader loader = cls.getClassLoader();
       
   209             if (loader != null)
       
   210                 loader.setPackageAssertionStatus("com.sun.tools.javac", true);
       
   211             else
       
   212                 trace(FINE, "loader == null");
       
   213         } catch (SecurityException ex) {
       
   214             trace(FINE, ex);
       
   215         }
       
   216         return cls;
       
   217     }
       
   218 
       
   219 
       
   220 }
   203 }