]> source.dussan.org Git - javassist.git/commitdiff
removes javassist.ModuleClassPath.
authorchibash <chiba@javassist.org>
Fri, 16 Dec 2016 14:22:18 +0000 (23:22 +0900)
committerchibash <chiba@javassist.org>
Fri, 16 Dec 2016 14:22:18 +0000 (23:22 +0900)
See #ClassFilesAsResources in JSR 376.  We don't need to hack the module system to read a class file in java.lang.

http://openjdk.java.net/projects/jigsaw/spec/issues/

src/main/javassist/ClassClassPath.java
src/main/javassist/ClassPool.java
src/main/javassist/ClassPoolTail.java
src/main/javassist/LoaderClassPath.java
src/main/javassist/ModuleClassPath.java [deleted file]

index c0a24d3527eafbaaeb8f91d221d22d6b4995beed..3befbf4c89a49975e14c425c810a0e555d202afb 100644 (file)
@@ -47,12 +47,8 @@ import javassist.bytecode.ClassFile;
  * @see ClassPool#insertClassPath(ClassPath)
  * @see ClassPool#appendClassPath(ClassPath)
  * @see LoaderClassPath
- * @see ModuleClassPath
  */
 public class ClassClassPath implements ClassPath {
-    private static final boolean useJigsaw
-        = ClassFile.MAJOR_VERSION >= ClassFile.JAVA_9;
-
     private Class thisClass;
 
     /** Creates a search path.
index c5d3c09aa2a9f1e892bed9a99a26757d1a964e40..36e0c33784e0e3a3330afc5bd7dc83d19841c475 100644 (file)
@@ -225,7 +225,6 @@ public class ClassPool {
      *
      * @see ClassClassPath
      * @see LoaderClassPath
-     * @see ModuleClassPath
      */
     public static synchronized ClassPool getDefault() {
         if (defaultPool == null) {
index 3e77f250ae189bc744471529ef6f7016dde89a42..13d22d77ab404dc0ad7edbb0f31d1a9b6df33f08 100644 (file)
@@ -240,13 +240,8 @@ final class ClassPoolTail {
     }
 
     public ClassPath appendSystemPath() {
-        if (javassist.bytecode.ClassFile.MAJOR_VERSION < javassist.bytecode.ClassFile.JAVA_9) {
-            return appendClassPath(new ClassClassPath());
-        }
-        else {
-            ClassLoader cl = Thread.currentThread().getContextClassLoader();
-            return appendClassPath(new LoaderClassPath(cl, true));
-        }
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        return appendClassPath(new LoaderClassPath(cl, true));
     }
 
     public ClassPath insertClassPath(String pathname)
index daf43c2069f998a73f71b6da79350d391517f751..6921ca6e757971e117e5d833b4667740547a49ad 100644 (file)
@@ -42,45 +42,15 @@ import java.lang.ref.WeakReference;
  * @see ClassPool#insertClassPath(ClassPath)
  * @see ClassPool#appendClassPath(ClassPath)
  * @see ClassClassPath
- * @see ModuleClassPath
  */
 public class LoaderClassPath implements ClassPath {
     private WeakReference clref;
 
-    /**
-     * If true, this search path implicitly includes
-     * a {@code ModuleClassPath} as a fallback.
-     * For backward compatibility, this field is set to true
-     * if the JVM is Java 9 or later.  It can be false in
-     * Java 9 but the behavior of {@code LoadClassPath} will
-     * be different from its behavior in Java 8 or older.
-     *
-     * <p>This field must be false if the JVM is Java 8 or older.
-     *
-     * @since 3.21
-     */
-    public static boolean fallbackOnModuleClassPath
-        = javassist.bytecode.ClassFile.MAJOR_VERSION >= javassist.bytecode.ClassFile.JAVA_9;
-
-    private static ModuleClassPath moduleClassPath = null;
-
-    private boolean doFallback;
-
     /**
      * Creates a search path representing a class loader.
      */
     public LoaderClassPath(ClassLoader cl) {
-        this(cl, fallbackOnModuleClassPath);
-    }
-
-    LoaderClassPath(ClassLoader cl, boolean fallback) {
         clref = new WeakReference(cl);
-        doFallback = fallback;
-        if (fallback)
-            synchronized (LoaderClassPath.class) {
-                if (moduleClassPath == null)
-                    moduleClassPath = new ModuleClassPath();
-            }
     }
 
     public String toString() {
@@ -103,10 +73,7 @@ public class LoaderClassPath implements ClassPath {
             return null;        // not found
         else {
             InputStream is = cl.getResourceAsStream(cname);
-            if (is == null && doFallback)
-                return moduleClassPath.openClassfile(classname);
-            else
-                return is;
+            return is;
         }
     }
 
@@ -124,10 +91,7 @@ public class LoaderClassPath implements ClassPath {
             return null;        // not found
         else {
             URL url = cl.getResource(cname);
-            if (url == null && doFallback)
-                return moduleClassPath.find(classname);
-            else
-                return url;
+            return url;
         }
     }
 
diff --git a/src/main/javassist/ModuleClassPath.java b/src/main/javassist/ModuleClassPath.java
deleted file mode 100644 (file)
index 30a7755..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Javassist, a Java-bytecode translator toolkit.
- * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License.  Alternatively, the contents of this file may be used under
- * the terms of the GNU Lesser General Public License Version 2.1 or later,
- * or the Apache License Version 2.0.
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- */
-
-package javassist;
-
-import java.io.InputStream;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A search-path for obtaining a class file
- * by <code>getResourceAsStream()</code> in <code>java.lang.reflect.Module</code>.
- *
- * @see ClassPool#insertClassPath(ClassPath)
- * @see ClassPool#appendClassPath(ClassPath)
- * @see LoaderClassPath
- * @see ClassClassPath
- * @since 3.21
- */
-public class ModuleClassPath implements ClassPath {
-    private HashMap packages = new HashMap();
-
-    ModuleClassPath() { this(Layer.boot()); }
-
-    /**
-     * Constructs a search path.
-     *
-     * @param layer         the layer used to obtain a class file.
-     */
-    public ModuleClassPath(Layer layer) {
-        while (layer != null) {
-            Set modules = layer.modules();
-            Iterator it = modules.iterator();
-            while (it.hasNext())
-                addPackages((Module)it.next());
-
-            layer = layer.parent().orElse(null);
-        }
-    }
-
-    /**
-     * Constructs a search path.
-     *
-     * @param m         the module used to obtain a class file.
-     */
-    public ModuleClassPath(Module m) {
-        addPackages(m);
-    }
-
-    private void addPackages(Module m) {
-        String[] names = m.getPackages();
-        for (int i = 0; i < names.length; i++)
-            packages.put(names[i], m);
-    }
-
-    /**
-     * Obtains a class file by <code>getResourceAsStream()</code>.
-     */
-    public InputStream openClassfile(String classname) throws NotFoundException {
-        String filename = classname.replace('.', '/') + ".class";
-        Module m = (Module)packages.get(getPackageName(classname));
-        if (m == null)
-            return null;
-        else
-            try {
-                return m.getResourceAsStream(filename);
-            }
-            catch (java.io.IOException e) {
-                throw new NotFoundException(classname, e);
-            }
-    }
-
-    /**
-     * Obtains the URL of the specified class file.
-     *
-     * @return null if the class file could not be found. 
-     */
-    public URL find(String classname) {
-        String filename = classname.replace('.', '/') + ".class";
-        Module m = (Module)packages.get(getPackageName(classname));
-        if (m == null)
-            return null;
-        else
-            try {
-                InputStream is = m.getResourceAsStream(filename);
-                if (is == null)
-                    return null;
-                else {
-                    is.close();
-                    return new URL("jar:file:unknown.jar!/" + filename);
-                }
-            }
-            catch (java.io.IOException e) {
-                return null;
-            }
-    }
-
-    private static String getPackageName(String name) {
-        int i = name.lastIndexOf('.');
-        if (i > 0)
-            return name.substring(0, i);
-        else
-            return "";
-    }
-
-    /**
-     * Does nothing.
-     */
-    public void close() {}
-}